|
@@ -1,24 +1,31 @@
|
|
package com.trade.client.trade.salesorder.service.impl;
|
|
package com.trade.client.trade.salesorder.service.impl;
|
|
|
|
|
|
import cn.hutool.core.collection.CollectionUtil;
|
|
import cn.hutool.core.collection.CollectionUtil;
|
|
-import com.deepoove.poi.config.Configure;
|
|
|
|
-import com.deepoove.poi.plugin.table.LoopRowTableRenderPolicy;
|
|
|
|
|
|
+import com.alibaba.excel.EasyExcel;
|
|
|
|
+import com.alibaba.excel.ExcelWriter;
|
|
|
|
+import com.alibaba.excel.write.metadata.WriteSheet;
|
|
|
|
+import com.alibaba.excel.write.metadata.fill.FillConfig;
|
|
import com.github.pagehelper.PageInfo;
|
|
import com.github.pagehelper.PageInfo;
|
|
import com.trade.client.security.utils.UserUtils;
|
|
import com.trade.client.security.utils.UserUtils;
|
|
import com.trade.common.constant.HttpStatus;
|
|
import com.trade.common.constant.HttpStatus;
|
|
import com.trade.common.exception.ServiceException;
|
|
import com.trade.common.exception.ServiceException;
|
|
import com.trade.common.utils.ConstantUtil;
|
|
import com.trade.common.utils.ConstantUtil;
|
|
import com.trade.common.utils.StringUtils;
|
|
import com.trade.common.utils.StringUtils;
|
|
|
|
+import com.trade.common.utils.file.ASopUtil;
|
|
import com.trade.common.utils.uuid.BizNoUtil;
|
|
import com.trade.common.utils.uuid.BizNoUtil;
|
|
import com.trade.service.DictConstants;
|
|
import com.trade.service.DictConstants;
|
|
|
|
+import com.trade.service.contract.entity.SFileTemplate;
|
|
|
|
+import com.trade.service.contract.util.SignPubUtil;
|
|
import com.trade.service.enterprise.companyrelated.domain.ImporterEntity;
|
|
import com.trade.service.enterprise.companyrelated.domain.ImporterEntity;
|
|
import com.trade.service.enterprise.companyrelated.service.IImporterEntityService;
|
|
import com.trade.service.enterprise.companyrelated.service.IImporterEntityService;
|
|
import com.trade.service.enterprise.customer.domain.Enterprise;
|
|
import com.trade.service.enterprise.customer.domain.Enterprise;
|
|
import com.trade.service.enterprise.customer.domain.EnterpriseRelatedPerson;
|
|
import com.trade.service.enterprise.customer.domain.EnterpriseRelatedPerson;
|
|
import com.trade.service.enterprise.customer.service.EnterpriseBaseService;
|
|
import com.trade.service.enterprise.customer.service.EnterpriseBaseService;
|
|
import com.trade.service.enterprise.customer.service.EnterpriseRelatedPersonBaseService;
|
|
import com.trade.service.enterprise.customer.service.EnterpriseRelatedPersonBaseService;
|
|
|
|
+import com.trade.service.filestorage.entity.TFileStorage;
|
|
|
|
+import com.trade.service.filestorage.service.OSSFileService;
|
|
|
|
+import com.trade.service.filestorage.util.FileUtil;
|
|
import com.trade.service.system.service.ISysDictDataService;
|
|
import com.trade.service.system.service.ISysDictDataService;
|
|
-import com.trade.service.trade.purchaseorder.domain.PurchaseOrderCommodity;
|
|
|
|
import com.trade.service.trade.purchaseorder.dto.PurchaseOrderDto;
|
|
import com.trade.service.trade.purchaseorder.dto.PurchaseOrderDto;
|
|
import com.trade.service.trade.purchaseorder.service.PurchaseOrderService;
|
|
import com.trade.service.trade.purchaseorder.service.PurchaseOrderService;
|
|
import com.trade.service.trade.salescontract.domain.ContractTerms;
|
|
import com.trade.service.trade.salescontract.domain.ContractTerms;
|
|
@@ -32,9 +39,6 @@ import com.trade.service.trade.salesorder.dto.*;
|
|
import com.trade.client.trade.salesorder.service.SalesOrderCService;
|
|
import com.trade.client.trade.salesorder.service.SalesOrderCService;
|
|
import com.trade.service.filestorage.enums.FileTypeEnum;
|
|
import com.trade.service.filestorage.enums.FileTypeEnum;
|
|
import com.trade.service.TransStruct;
|
|
import com.trade.service.TransStruct;
|
|
-import com.trade.service.contract.dto.ContractGenInputItem;
|
|
|
|
-import com.trade.service.contract.dto.ContractGenOutputItem;
|
|
|
|
-import com.trade.service.contract.service.ContractService;
|
|
|
|
import com.trade.service.contract.service.ISFileTemplateService;
|
|
import com.trade.service.contract.service.ISFileTemplateService;
|
|
import com.trade.service.trade.salesorder.constant.SaleOrderConstant;
|
|
import com.trade.service.trade.salesorder.constant.SaleOrderConstant;
|
|
import com.trade.service.trade.salesorder.service.*;
|
|
import com.trade.service.trade.salesorder.service.*;
|
|
@@ -45,10 +49,16 @@ import com.trade.service.serialNum.service.SerialNumberGenerator;
|
|
import com.trade.service.tradingplatform.domain.TradingPlatform;
|
|
import com.trade.service.tradingplatform.domain.TradingPlatform;
|
|
import com.trade.service.tradingplatform.service.TradingPlatformBaseService;
|
|
import com.trade.service.tradingplatform.service.TradingPlatformBaseService;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
+import org.apache.poi.ss.usermodel.Workbook;
|
|
|
|
+import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
import javax.annotation.Resource;
|
|
|
|
+import java.io.File;
|
|
|
|
+import java.io.FileInputStream;
|
|
|
|
+import java.io.FileOutputStream;
|
|
|
|
+import java.io.IOException;
|
|
import java.math.BigDecimal;
|
|
import java.math.BigDecimal;
|
|
import java.time.LocalDate;
|
|
import java.time.LocalDate;
|
|
import java.util.*;
|
|
import java.util.*;
|
|
@@ -64,8 +74,6 @@ public class SalesOrderCServiceImpl implements SalesOrderCService {
|
|
private final ISalesOrderLogisticsService salesOrderLogisticsService;
|
|
private final ISalesOrderLogisticsService salesOrderLogisticsService;
|
|
private final ISalesOrderContainerService salesOrderContainerService;
|
|
private final ISalesOrderContainerService salesOrderContainerService;
|
|
@Resource
|
|
@Resource
|
|
- private ContractService contractService;
|
|
|
|
- @Resource
|
|
|
|
private SerialNumberGenerator serialNumberGenerator;
|
|
private SerialNumberGenerator serialNumberGenerator;
|
|
@Resource
|
|
@Resource
|
|
private TransStruct transStruct;
|
|
private TransStruct transStruct;
|
|
@@ -89,6 +97,8 @@ public class SalesOrderCServiceImpl implements SalesOrderCService {
|
|
private SalesCommodityService salesCommodityService;
|
|
private SalesCommodityService salesCommodityService;
|
|
@Resource
|
|
@Resource
|
|
private ISysDictDataService iSysDictDataService;
|
|
private ISysDictDataService iSysDictDataService;
|
|
|
|
+ @Resource
|
|
|
|
+ private OSSFileService ossFileStorageService;
|
|
|
|
|
|
public SalesOrderCServiceImpl(ISalesOrderService salesOrderService, ISalesOrderGoodsService salesOrderGoodsService,
|
|
public SalesOrderCServiceImpl(ISalesOrderService salesOrderService, ISalesOrderGoodsService salesOrderGoodsService,
|
|
ISalesOrderInvoiceService salesOrderInvoiceService, ISalesOrderLogisticsService salesOrderLogisticsService,
|
|
ISalesOrderInvoiceService salesOrderInvoiceService, ISalesOrderLogisticsService salesOrderLogisticsService,
|
|
@@ -105,7 +115,7 @@ public class SalesOrderCServiceImpl implements SalesOrderCService {
|
|
search.setCustomerUserId(UserUtils.getCustomerUserId());
|
|
search.setCustomerUserId(UserUtils.getCustomerUserId());
|
|
search.setPoint(true);
|
|
search.setPoint(true);
|
|
if (StringUtils.isNotEmpty(search.getStatus())
|
|
if (StringUtils.isNotEmpty(search.getStatus())
|
|
- && SaleOrderConstant.ORDER_STATUS_DELIVERING.equals(search.getStatus())) {
|
|
|
|
|
|
+ && String.valueOf(SaleOrderConstant.ORDER_STATUS_DELIVERING).equals(search.getStatus())) {
|
|
List<Integer> statusList = new ArrayList<>();
|
|
List<Integer> statusList = new ArrayList<>();
|
|
statusList.add(SaleOrderConstant.ORDER_STATUS_DELIVERING);
|
|
statusList.add(SaleOrderConstant.ORDER_STATUS_DELIVERING);
|
|
statusList.add(SaleOrderConstant.ORDER_STATUS_PARTIAL_COLLECTION);
|
|
statusList.add(SaleOrderConstant.ORDER_STATUS_PARTIAL_COLLECTION);
|
|
@@ -187,33 +197,72 @@ public class SalesOrderCServiceImpl implements SalesOrderCService {
|
|
log.info("提交销售订单Info:{}", salesOrderDTO.toString());
|
|
log.info("提交销售订单Info:{}", salesOrderDTO.toString());
|
|
save(salesOrderDTO, true);
|
|
save(salesOrderDTO, true);
|
|
SalesOrder salesOrder = salesOrderDTO.getSalesOrder();
|
|
SalesOrder salesOrder = salesOrderDTO.getSalesOrder();
|
|
- Long userId = salesOrder.getCustomerUserId();
|
|
|
|
SalesOrderInvoice salesOrderInvoice = new SalesOrderInvoice();
|
|
SalesOrderInvoice salesOrderInvoice = new SalesOrderInvoice();
|
|
salesOrderInvoice.setOrderId(salesOrder.getId());
|
|
salesOrderInvoice.setOrderId(salesOrder.getId());
|
|
salesOrderInvoice.setInvoiceNo(serialNumberGenerator.nextValue(SaleOrderConstant.ORDER_INVOICE_NO_PREFIX));
|
|
salesOrderInvoice.setInvoiceNo(serialNumberGenerator.nextValue(SaleOrderConstant.ORDER_INVOICE_NO_PREFIX));
|
|
salesOrderInvoice.setAmount(salesOrder.getAmount());
|
|
salesOrderInvoice.setAmount(salesOrder.getAmount());
|
|
// 生成发票文件并保存文件ID
|
|
// 生成发票文件并保存文件ID
|
|
- ContractGenInputItem item = initContractGenInputItem(salesOrder, salesOrderDTO.getSalesOrderGoodsList(),
|
|
|
|
|
|
+ Long fileId = generateInvoiceFile(salesOrder, salesOrderDTO.getSalesOrderGoodsList(),
|
|
salesOrderInvoice.getInvoiceNo());
|
|
salesOrderInvoice.getInvoiceNo());
|
|
- ContractGenOutputItem outputItem = contractService.generateSingleContract(item, userId);
|
|
|
|
- salesOrderInvoice.setFileId(outputItem.getFileId());
|
|
|
|
|
|
+ salesOrderInvoice.setFileId(fileId);
|
|
salesOrderInvoiceService.save(salesOrderInvoice);
|
|
salesOrderInvoiceService.save(salesOrderInvoice);
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
- * 初始化合同生成参数
|
|
|
|
|
|
+ * 生成形式发票文件
|
|
*
|
|
*
|
|
* @param salesOrder 订单信息
|
|
* @param salesOrder 订单信息
|
|
* @param salesOrderGoodsList 订单商品列表
|
|
* @param salesOrderGoodsList 订单商品列表
|
|
* @param invoiceNo 发票号
|
|
* @param invoiceNo 发票号
|
|
|
|
+ * @return 文件ID
|
|
|
|
+ */
|
|
|
|
+ public Long generateInvoiceFile(SalesOrder salesOrder, List<SalesOrderGoods> salesOrderGoodsList,
|
|
|
|
+ String invoiceNo) {
|
|
|
|
+ String transientFileName = FileUtil.getAbsoluteDir() + "/" + UUID.randomUUID() + ".xlsx";
|
|
|
|
+ String excelFileName = FileUtil.getAbsoluteDir() + "/" + invoiceNo + ".xlsx";
|
|
|
|
+ String pdfFilePath = FileUtil.getAbsoluteDir() + "/" + invoiceNo + ".pdf";
|
|
|
|
+ SFileTemplate fileTemplate = fileTemplateService.selectByFileType(FileTypeEnum.PROFORMA_INVOICE.getCode());
|
|
|
|
+ try {
|
|
|
|
+ Map<String, Object> titleData = initTemplateParams(salesOrder, invoiceNo);
|
|
|
|
+ List<GoodsInfo4TL> goodsList = transStruct.transOrder2GoodsInfo4TLList(salesOrderGoodsList);
|
|
|
|
+ // 写入Excel文件
|
|
|
|
+ try (ExcelWriter excelWriter = EasyExcel.write(transientFileName).withTemplate(fileTemplate.getSrcPath())
|
|
|
|
+ .build()) {
|
|
|
|
+ WriteSheet writeSheet = EasyExcel.writerSheet().build();
|
|
|
|
+ FillConfig fillConfig = FillConfig.builder().forceNewRow(Boolean.TRUE).build();
|
|
|
|
+ excelWriter.fill(goodsList, fillConfig, writeSheet);
|
|
|
|
+ excelWriter.fill(titleData, writeSheet);
|
|
|
|
+ }
|
|
|
|
+ // 此处需要用新的文件接收,否则转pdf会报错: java.util.zip.ZipException: invalid entry size
|
|
|
|
+ try (Workbook workbook = new XSSFWorkbook(new FileInputStream(transientFileName));
|
|
|
|
+ FileOutputStream fos = new FileOutputStream(excelFileName)) {
|
|
|
|
+ workbook.write(fos);
|
|
|
|
+ }
|
|
|
|
+ // 转换Excel为PDF
|
|
|
|
+ ASopUtil.excel2pdf(excelFileName, pdfFilePath);
|
|
|
|
+ } catch (IOException e) {
|
|
|
|
+ throw new ServiceException("生成形式发票文件失败: " + e.getMessage(), HttpStatus.ERROR);
|
|
|
|
+ } finally {
|
|
|
|
+ // 清理生成的文件
|
|
|
|
+ SignPubUtil.deleteFileWithPath(transientFileName, excelFileName);
|
|
|
|
+ }
|
|
|
|
+ // 上传文件并返回ID
|
|
|
|
+ TFileStorage fileStorage = ossFileStorageService.uploadAndSaveDBRecord(new File(pdfFilePath),
|
|
|
|
+ fileTemplate.getDestDir());
|
|
|
|
+ SignPubUtil.deleteFileWithPath(pdfFilePath);
|
|
|
|
+ return fileStorage.getId();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 初始化模板参数
|
|
|
|
+ *
|
|
|
|
+ * @param salesOrder 订单信息
|
|
|
|
+ * @param invoiceNo 发票号
|
|
* @return 合同生成参数
|
|
* @return 合同生成参数
|
|
*/
|
|
*/
|
|
- private ContractGenInputItem initContractGenInputItem(SalesOrder salesOrder,
|
|
|
|
- List<SalesOrderGoods> salesOrderGoodsList, String invoiceNo) {
|
|
|
|
- ContractGenInputItem item = new ContractGenInputItem();
|
|
|
|
- String templateCode = fileTemplateService.selectByFileType(FileTypeEnum.PROFORMA_INVOICE.getCode())
|
|
|
|
- .getTemplateCode();
|
|
|
|
|
|
+ private Map<String, Object> initTemplateParams(SalesOrder salesOrder, String invoiceNo) {
|
|
SalesContractDto salesContract = salesContractService.getSalesContractById(salesOrder.getSaleContractId());
|
|
SalesContractDto salesContract = salesContractService.getSalesContractById(salesOrder.getSaleContractId());
|
|
|
|
+ SalesOrderLogistics orderLogistics = salesOrderLogisticsService.getByOrderId(salesOrder.getId());
|
|
ContractTerms contractTerms = contractTermsService.getByContractIdAndType(salesContract.getId(),
|
|
ContractTerms contractTerms = contractTermsService.getByContractIdAndType(salesContract.getId(),
|
|
ConstantUtil.SALES_CONTRACT_NO_PREFIX);
|
|
ConstantUtil.SALES_CONTRACT_NO_PREFIX);
|
|
ImporterEntity importer = importerEntityService.getByEntityId(salesOrder.getImporterId());
|
|
ImporterEntity importer = importerEntityService.getByEntityId(salesOrder.getImporterId());
|
|
@@ -224,24 +273,29 @@ public class SalesOrderCServiceImpl implements SalesOrderCService {
|
|
String customerAddress = StringUtils.isEmpty(enterprise.getBusinessAddress()) ? enterprise.getRegisterAddress()
|
|
String customerAddress = StringUtils.isEmpty(enterprise.getBusinessAddress()) ? enterprise.getRegisterAddress()
|
|
: enterprise.getBusinessAddress();
|
|
: enterprise.getBusinessAddress();
|
|
String contractTel = contact.getMobile();
|
|
String contractTel = contact.getMobile();
|
|
|
|
+ String email = contact.getEmail();
|
|
|
|
+ String contactName = contact.getName();
|
|
if (DictConstants.EXPORT_TYPE_PROXY.equals(enterprise.getExportType())) {
|
|
if (DictConstants.EXPORT_TYPE_PROXY.equals(enterprise.getExportType())) {
|
|
TradingPlatform tradingPlatform = tradingPlatformBaseService.lambdaQuery()
|
|
TradingPlatform tradingPlatform = tradingPlatformBaseService.lambdaQuery()
|
|
.eq(TradingPlatform::getCertNo, salesContract.getAgencyCertNo()).one();
|
|
.eq(TradingPlatform::getCertNo, salesContract.getAgencyCertNo()).one();
|
|
customerName = tradingPlatform.getPlatformName();
|
|
customerName = tradingPlatform.getPlatformName();
|
|
customerAddress = tradingPlatform.getBusinessAddress();
|
|
customerAddress = tradingPlatform.getBusinessAddress();
|
|
contractTel = tradingPlatform.getContactMobile();
|
|
contractTel = tradingPlatform.getContactMobile();
|
|
|
|
+ email = tradingPlatform.getContactEmail();
|
|
|
|
+ contactName = tradingPlatform.getContactName();
|
|
}
|
|
}
|
|
// 支付方式 页面选其他,后台取不到值,默认"" PS: The final interpretation rights belong to the product manager who will never make
|
|
// 支付方式 页面选其他,后台取不到值,默认"" PS: The final interpretation rights belong to the product manager who will never make
|
|
// a mistake
|
|
// a mistake
|
|
String paymentWay = Optional
|
|
String paymentWay = Optional
|
|
.ofNullable(iSysDictDataService.selectDictLabel("payment_way_en", contractTerms.getPaymentWay()))
|
|
.ofNullable(iSysDictDataService.selectDictLabel("payment_way_en", contractTerms.getPaymentWay()))
|
|
.orElse("");
|
|
.orElse("");
|
|
- item.setTemplateCode(templateCode);
|
|
|
|
Map<String, Object> params = new HashMap<>();
|
|
Map<String, Object> params = new HashMap<>();
|
|
params.put("customerName", customerName);
|
|
params.put("customerName", customerName);
|
|
params.put("customerAddress", customerAddress);
|
|
params.put("customerAddress", customerAddress);
|
|
- params.put("date", LocalDate.now());
|
|
|
|
|
|
+ params.put("contactName", contactName);
|
|
|
|
+ params.put("date", LocalDate.now().toString());
|
|
params.put("tel", contractTel);
|
|
params.put("tel", contractTel);
|
|
|
|
+ params.put("email", email);
|
|
params.put("invoiceNo", invoiceNo);
|
|
params.put("invoiceNo", invoiceNo);
|
|
params.put("from", salesContract.getPortDeparture());
|
|
params.put("from", salesContract.getPortDeparture());
|
|
params.put("to", salesContract.getPortDestination());
|
|
params.put("to", salesContract.getPortDestination());
|
|
@@ -249,17 +303,27 @@ public class SalesOrderCServiceImpl implements SalesOrderCService {
|
|
params.put("payWay", paymentWay);
|
|
params.put("payWay", paymentWay);
|
|
params.put("importerName", importer.getEntityName());
|
|
params.put("importerName", importer.getEntityName());
|
|
params.put("importerAddress", importer.getBusinessAddress());
|
|
params.put("importerAddress", importer.getBusinessAddress());
|
|
|
|
+ params.put("importerContactName", importer.getContactName());
|
|
|
|
+ params.put("importerContactEmail", importer.getContactEmail());
|
|
|
|
+ params.put("importerContactPhone", importer.getContactMobile());
|
|
params.put("currency", contractTerms.getPaymentCurrency());
|
|
params.put("currency", contractTerms.getPaymentCurrency());
|
|
params.put("cardNo", contractTerms.getAccountNumber());
|
|
params.put("cardNo", contractTerms.getAccountNumber());
|
|
params.put("openBank", contractTerms.getOpeningBank());
|
|
params.put("openBank", contractTerms.getOpeningBank());
|
|
|
|
+ params.put("accountName", contractTerms.getAccountName());
|
|
params.put("swiftCode", contractTerms.getSwiftCode());
|
|
params.put("swiftCode", contractTerms.getSwiftCode());
|
|
- params.put("total", salesOrder.getAmount());
|
|
|
|
- List<GoodsInfo4TL> goodsList = transStruct.transOrder2GoodsInfo4TLList(salesOrderGoodsList);
|
|
|
|
- params.put(SaleOrderConstant.ORDER_INVOICE_GOODS_LIST_KEY, goodsList);
|
|
|
|
- item.setParams(params);
|
|
|
|
- LoopRowTableRenderPolicy policy = new LoopRowTableRenderPolicy();
|
|
|
|
- item.setConfig(Configure.builder().bind(SaleOrderConstant.ORDER_INVOICE_GOODS_LIST_KEY, policy).build());
|
|
|
|
- return item;
|
|
|
|
|
|
+ params.put("orderTotal", salesOrder.getAmount());
|
|
|
|
+ params.put("shippingMethod", orderLogistics.getShippingMethod());
|
|
|
|
+ BigDecimal total = salesOrder.getAmount();
|
|
|
|
+ if (orderLogistics.getShippingFee() != null) {
|
|
|
|
+ total = total.add(orderLogistics.getShippingFee());
|
|
|
|
+ params.put("shippingFee", orderLogistics.getShippingFee());
|
|
|
|
+ }
|
|
|
|
+ if (orderLogistics.getInsuranceFee() != null) {
|
|
|
|
+ total = total.add(orderLogistics.getInsuranceFee());
|
|
|
|
+ params.put("insuranceFee", orderLogistics.getInsuranceFee());
|
|
|
|
+ }
|
|
|
|
+ params.put("total", total);
|
|
|
|
+ return params;
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
@Override
|