|
@@ -1,6 +1,8 @@
|
|
|
package com.fjhx.sale.service.documents.impl;
|
|
|
|
|
|
+import cn.hutool.core.lang.func.Func;
|
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
import com.baomidou.dynamic.datasource.toolkit.DynamicDataSourceContextHolder;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
@@ -10,9 +12,12 @@ import com.fjhx.common.entity.corporation.po.Corporation;
|
|
|
import com.fjhx.common.service.corporation.CorporationService;
|
|
|
import com.fjhx.customer.entity.customer.po.Customer;
|
|
|
import com.fjhx.customer.service.customer.CustomerService;
|
|
|
+import com.fjhx.item.service.product.ProductInfoService;
|
|
|
+import com.fjhx.purchase.entity.arrival.po.ArrivalDetail;
|
|
|
import com.fjhx.sale.entity.contract.po.Contract;
|
|
|
import com.fjhx.sale.entity.contract.vo.ContractVo;
|
|
|
import com.fjhx.sale.entity.documents.po.Documents;
|
|
|
+import com.fjhx.sale.entity.documents.po.DocumentsPdf;
|
|
|
import com.fjhx.sale.entity.documents.po.DocumentsProduct;
|
|
|
import com.fjhx.sale.entity.documents.po.DocumentsTransport;
|
|
|
import com.fjhx.sale.entity.pack.po.PackDetail;
|
|
@@ -20,6 +25,7 @@ import com.fjhx.sale.entity.pack.po.PackDetailGoods;
|
|
|
import com.fjhx.sale.entity.pack.po.PackShipment;
|
|
|
import com.fjhx.sale.mapper.documents.DocumentsMapper;
|
|
|
import com.fjhx.sale.service.contract.ContractService;
|
|
|
+import com.fjhx.sale.service.documents.DocumentsPdfService;
|
|
|
import com.fjhx.sale.service.documents.DocumentsProductService;
|
|
|
import com.fjhx.sale.service.documents.DocumentsService;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
@@ -28,6 +34,8 @@ import com.fjhx.sale.service.pack.PackDetailGoodsService;
|
|
|
import com.fjhx.sale.service.pack.PackDetailService;
|
|
|
import com.fjhx.sale.service.pack.PackShipmentService;
|
|
|
import com.obs.services.internal.ServiceException;
|
|
|
+import org.apache.commons.collections4.CollectionUtils;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
@@ -77,6 +85,12 @@ public class DocumentsServiceImpl extends ServiceImpl<DocumentsMapper, Documents
|
|
|
@Autowired
|
|
|
private CustomerService customerService;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private DocumentsPdfService documentsPdfService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private ProductInfoService productInfoService;
|
|
|
+
|
|
|
private static final SimpleDateFormat sdf = new SimpleDateFormat("dd/MMM/yyyy", Locale.ENGLISH);
|
|
|
|
|
|
/**
|
|
@@ -178,6 +192,13 @@ public class DocumentsServiceImpl extends ServiceImpl<DocumentsMapper, Documents
|
|
|
Corporation corporation = corporationService.getById(contractVo.getSellCorporationId());
|
|
|
//查询单证货物
|
|
|
List<DocumentsProduct> documentsProducts = documentsProductService.list(Wrappers.<DocumentsProduct>query().lambda().eq(DocumentsProduct::getDocumentsId,documents.getId()));
|
|
|
+ // 赋值产品属性
|
|
|
+ productInfoService.attributeAssign(documentsProducts, DocumentsProduct::getBusinessId, (item, product) -> {
|
|
|
+ item.setProductCode(product.getCode());
|
|
|
+ item.setProductUnit(product.getUnit());
|
|
|
+ item.setProductName(product.getName());
|
|
|
+ item.setProductSpec(product.getSpec());
|
|
|
+ });
|
|
|
//查询包装出货主合同
|
|
|
PackShipment packShipment = packShipmentService.getById(documents.getPackShipmentId());
|
|
|
//装箱单
|
|
@@ -188,6 +209,8 @@ public class DocumentsServiceImpl extends ServiceImpl<DocumentsMapper, Documents
|
|
|
BigDecimal sumNetWeight = BigDecimal.ZERO;
|
|
|
//总体积
|
|
|
BigDecimal sumBomVolume = BigDecimal.ZERO;
|
|
|
+ //总件数
|
|
|
+ BigDecimal sumPackQuantity = BigDecimal.ZERO;
|
|
|
//装箱商品明细
|
|
|
List<PackDetailGoods> packDetailGoodsList = new ArrayList<>();
|
|
|
if(ObjectUtil.isNotEmpty(packShipment)){//查询装箱单
|
|
@@ -198,23 +221,176 @@ public class DocumentsServiceImpl extends ServiceImpl<DocumentsMapper, Documents
|
|
|
for(PackDetail p:packDetailList){
|
|
|
p.setPackDetailGoodsList(packGoodMap.getOrDefault(p.getId(),null));
|
|
|
}
|
|
|
+ sumPackQuantity = packDetailList.stream().map(PackDetail::getPackQuantity).reduce(BigDecimal.ZERO,BigDecimal::add);
|
|
|
sumRoughWeight = packDetailList.stream().map(PackDetail::getRoughWeight).reduce(BigDecimal.ZERO,BigDecimal::add);
|
|
|
sumNetWeight = packDetailList.stream().map(PackDetail::getNetWeight).reduce(BigDecimal.ZERO,BigDecimal::add);
|
|
|
sumBomVolume = packDetailList.stream().map(PackDetail::getBomVolume).reduce(BigDecimal.ZERO,BigDecimal::add);
|
|
|
}
|
|
|
- map.put("contract",contract);//合同信息
|
|
|
- map.put("date",sdf.format(contract.getCreateTime()));//日期
|
|
|
+ map.put("contract",contractVo);//合同信息
|
|
|
+ map.put("date",sdf.format(contractVo.getCreateTime()));//日期
|
|
|
map.put("documents",documents);//单证信息
|
|
|
map.put("documentsProducts",documentsProducts);//单证信息货物
|
|
|
map.put("packDetailList",packDetailList);//单证信息货物
|
|
|
map.put("sumRoughWeight",sumRoughWeight);//总毛重
|
|
|
map.put("sumNetWeight",sumNetWeight);//总净重
|
|
|
map.put("sumBomVolume",sumBomVolume);//总体积
|
|
|
+ map.put("sumPackQuantity",sumPackQuantity);//总箱数
|
|
|
map.put("customer",customer);//买方信息
|
|
|
map.put("corporation",corporation);//卖方信息
|
|
|
// map.put("packDetailGoodsList",packDetailGoodsList);//装箱商品明细
|
|
|
return map;
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 生成pdf----报关单
|
|
|
+ * @param id
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public DocumentsPdf generateClearanceePdf(Long id) {
|
|
|
+ //获取单证PDF数据
|
|
|
+ DocumentsPdf pdfData = documentsPdfService.getOne(Wrappers.<DocumentsPdf>query().lambda()
|
|
|
+ .eq(DocumentsPdf::getDocumentId,id).eq(DocumentsPdf::getDataType,0));
|
|
|
+ if (ObjectUtil.isEmpty(pdfData)) {
|
|
|
+ JSONObject data = new JSONObject();
|
|
|
+ List<JSONObject> productData = new ArrayList<>();
|
|
|
+ pdfData = new DocumentsPdf();
|
|
|
+ //获取初始数据
|
|
|
+ Map<String, Object> dataMap = generateInvoiceAPackPdf(id);
|
|
|
+
|
|
|
+ //单证信息
|
|
|
+ Documents documents = (Documents) dataMap.get("documents");
|
|
|
+ //合同信息
|
|
|
+ ContractVo contract = (ContractVo) dataMap.get("contract");
|
|
|
+ //产品信息
|
|
|
+ List<DocumentsProduct> products = (List<DocumentsProduct>) dataMap.get("documentsProducts");
|
|
|
+ //卖方信息
|
|
|
+ Corporation corporation = (Corporation) dataMap.get("corporation");
|
|
|
+ //买方信息
|
|
|
+ Customer customer = (Customer) dataMap.get("customer");
|
|
|
+ //箱子的总毛重、净重
|
|
|
+ Map<String, BigDecimal> packingWeightMap = (Map<String, BigDecimal>) dataMap.get("packingWeightMap");
|
|
|
+ //总箱数
|
|
|
+ BigDecimal sumPackQuantity = (BigDecimal) dataMap.get("sumPackQuantity");
|
|
|
+
|
|
|
+ //------------------ 封装页面展示数据 ------------------
|
|
|
+ //发件公司清关负责人
|
|
|
+ data.put("contacts", contract.getSellContactName());
|
|
|
+ //发件公司清关负责人联系电话/手机
|
|
|
+ data.put("contactsMobile",contract.getSellContactNumber());
|
|
|
+ //联系人邮箱
|
|
|
+ data.put("contactsEmail", "");
|
|
|
+ //境内发货人名称(填写发货公司中文名称)
|
|
|
+ data.put("companyNameChinese", corporation.getName());
|
|
|
+ //境内发货人代码(填写18位统一社会信用代码,没有信用证代码填报10位海关备案编码)
|
|
|
+ data.put("organizationCode", corporation.getIaeeCode());
|
|
|
+ //出境关别(不用填写)
|
|
|
+ data.put("exitCustoms", "");
|
|
|
+ //备案号(如是手册的请填写)
|
|
|
+ data.put("recordNo", "");
|
|
|
+ //境外收货人(指合同买方或合同指定的收货人公司英文名称)
|
|
|
+ data.put("customerCompanyName", customer.getName());
|
|
|
+ //境外收货人代码(AEO互认企业需填报AEO编码;不填默认非AEO互认)
|
|
|
+ data.put("overseasConsigneeCode", "");
|
|
|
+ //运输方式(不用填写)
|
|
|
+ data.put("typeOfShipping", "");
|
|
|
+ //运输工具名称及航次号(不用填写)
|
|
|
+ data.put("meansOfTransport", "");
|
|
|
+ //提运单号(指12位快递运单号码)
|
|
|
+ data.put("waybillCode", "");
|
|
|
+ //生产销售单位(指生产该产品的公司名称)
|
|
|
+ data.put("productCompanyNameChinese", corporation.getName());
|
|
|
+ //生产销售单位代码(填写18位统一社会信用代码,没有信用证代码填写“NO”)
|
|
|
+ data.put("productOrganizationCode", corporation.getIaeeCode());
|
|
|
+ //监管方式
|
|
|
+ data.put("supervisionMode", "");
|
|
|
+ //征免性质(与监管方式对应填写)
|
|
|
+ data.put("exemptionNature", "");
|
|
|
+ //许可证号(如需许可证的请填写)
|
|
|
+ data.put("licenseKey", "");
|
|
|
+ //合同协议号(根据合同填写)
|
|
|
+ data.put("contractCode", contract.getCode());
|
|
|
+ //贸易国(合同买方所在国)
|
|
|
+ data.put("tradingCountry", documents.getCountryName());
|
|
|
+ //运抵国
|
|
|
+ data.put("arrivalCountry", documents.getCountryName());
|
|
|
+ //指运港(不用填写)
|
|
|
+ data.put("portOfDestination", "");
|
|
|
+ //离境口岸(不用填写)
|
|
|
+ data.put("departurePort", "");
|
|
|
+ //包装种类
|
|
|
+ data.put("packageType", "");
|
|
|
+ //件数(运单和装箱单一致)
|
|
|
+ data.put("sumPackQuantity", sumPackQuantity);
|
|
|
+ //毛重(千克)
|
|
|
+ data.put("sumRoughWeight", packingWeightMap.get("sumRoughWeight"));
|
|
|
+ //净重(千克)
|
|
|
+ data.put("sumNetWeight", packingWeightMap.get("sumNetWeight"));
|
|
|
+ //总体积 立方米
|
|
|
+ data.put("sumBomVolume", packingWeightMap.get("sumBomVolume"));
|
|
|
+ //成交方式
|
|
|
+ data.put("tradeModeName", contract.getPaymentMethod());
|
|
|
+ //运费
|
|
|
+ data.put("freightPrice", BigDecimal.ZERO);//暂无
|
|
|
+ // 保费
|
|
|
+ data.put("premiumPrice", BigDecimal.ZERO);//暂无
|
|
|
+ // 杂费(如有请填写)
|
|
|
+ data.put("incidentalPrice", "");
|
|
|
+ // 随附单证及编号(常见如通关单号、原进口报关单号)
|
|
|
+ data.put("documentsAttached", "");
|
|
|
+ // 标记唛码及备注
|
|
|
+ data.put("shippingMark", documents.getRemark());
|
|
|
+ // 境内货源地
|
|
|
+ data.put("cityChinese", contract.getSellCountryName());
|
|
|
+ // 产品数据
|
|
|
+ if (CollectionUtils.isNotEmpty(products)) {
|
|
|
+ Integer num = 1;
|
|
|
+ for (DocumentsProduct product : products) {
|
|
|
+ JSONObject object = new JSONObject();
|
|
|
+ // 项号
|
|
|
+ object.put("num", num);
|
|
|
+ // 商品编号(13位)原10位海关编码+3位检验检疫附加编码
|
|
|
+ object.put("customsCode", product.getCustomsCode());
|
|
|
+ // 商品名称
|
|
|
+ object.put("productName", product.getProductName());
|
|
|
+ //品牌
|
|
|
+ object.put("brand", "");
|
|
|
+ //品牌类型
|
|
|
+ object.put("brandType", "");
|
|
|
+ //出口享惠情况(不填写则默认不享受)
|
|
|
+ object.put("exportBenefits", "");
|
|
|
+ //型号
|
|
|
+ object.put("productModelChinese", "");
|
|
|
+ //税号所需申报要素(如:用途、材质等)
|
|
|
+ object.put("declareRemark", "");
|
|
|
+ //各项净重
|
|
|
+ object.put("netWeight", "");//暂无
|
|
|
+ //成交数量
|
|
|
+ object.put("quantity", product.getQuantity());
|
|
|
+ //成交单位
|
|
|
+ object.put("unit", product.getProductUnit());
|
|
|
+ //原产国(地区)
|
|
|
+ object.put("countryChinese", corporation.getName());
|
|
|
+ //总价与币制
|
|
|
+ object.put("sumPrice", "");
|
|
|
+ //成交单价
|
|
|
+ object.put("declaredPrice", "");//暂无
|
|
|
+ //EXW单价
|
|
|
+ object.put("exwPrice", "");//暂无
|
|
|
+ productData.add(object);
|
|
|
+ num++;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ data.put("products", productData);
|
|
|
+
|
|
|
+ pdfData.setDocumentId(documents.getId());
|
|
|
+ pdfData.setContractCode(contract.getCode());
|
|
|
+ pdfData.setDataType(0);//报关单
|
|
|
+ pdfData.setContent(data.toJSONString());
|
|
|
+ }
|
|
|
+ return pdfData;
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 赋值买卖公司国家省市区名称
|
|
|
*/
|