Commit 7daf9de0cb8259b9332b4c423a76ca2ecc263c33

Authored by 房远帅
1 parent ac1d4465

订货单:打印模板增加目的地

@@ -459,6 +459,7 @@ public class PurchaseOrderInfoController extends DefaultBaseController { @@ -459,6 +459,7 @@ public class PurchaseOrderInfoController extends DefaultBaseController {
459 dataMap.put("performanceance", data.getPerformance()); 459 dataMap.put("performanceance", data.getPerformance());
460 dataMap.put("packaging", data.getPackaging()); 460 dataMap.put("packaging", data.getPackaging());
461 dataMap.put("shippingCost", data.getShippingCost()); 461 dataMap.put("shippingCost", data.getShippingCost());
  462 + dataMap.put("destination", ExcelUtil.buildPrintDestination(data.getContractType(), data.getDestination(), data.getForeignDestination()));
462 dataMap.put("remarks", data.getRemarks()); 463 dataMap.put("remarks", data.getRemarks());
463 dataMap.put("createUser", data.getCreateBy()); 464 dataMap.put("createUser", data.getCreateBy());
464 dataMap.put("element", data.getElement()); 465 dataMap.put("element", data.getElement());
@@ -258,6 +258,7 @@ public class BusinessDataExportHandler implements ExportHandler { @@ -258,6 +258,7 @@ public class BusinessDataExportHandler implements ExportHandler {
258 dataMap.put("performanceance", orderInfo.getPerformance()); 258 dataMap.put("performanceance", orderInfo.getPerformance());
259 dataMap.put("packaging", orderInfo.getPackaging()); 259 dataMap.put("packaging", orderInfo.getPackaging());
260 dataMap.put("shippingCost", orderInfo.getShippingCost()); 260 dataMap.put("shippingCost", orderInfo.getShippingCost());
  261 + dataMap.put("destination", ExcelUtil.buildPrintDestination(orderInfo.getContractType(), orderInfo.getDestination(), orderInfo.getForeignDestination()));
261 dataMap.put("remarks", orderInfo.getRemarks()); 262 dataMap.put("remarks", orderInfo.getRemarks());
262 dataMap.put("createUser", orderInfo.getCreateBy()); 263 dataMap.put("createUser", orderInfo.getCreateBy());
263 dataMap.put("element", orderInfo.getElement()); 264 dataMap.put("element", orderInfo.getElement());
@@ -131,8 +131,12 @@ public class PurchaseOrderInfoServiceImpl extends BaseMpServiceImpl<PurchaseOrde @@ -131,8 +131,12 @@ public class PurchaseOrderInfoServiceImpl extends BaseMpServiceImpl<PurchaseOrde
131 131
132 @Override 132 @Override
133 public PurchaseOrderInfo findById(String id) { 133 public PurchaseOrderInfo findById(String id) {
134 -  
135 - return getBaseMapper().findById(id); 134 + PurchaseOrderInfo data = getBaseMapper().findById(id);
  135 + if (data == null) {
  136 + return null;
  137 + }
  138 + fillContractDestination(data);
  139 + return data;
136 } 140 }
137 141
138 @Override 142 @Override
@@ -763,17 +767,46 @@ public class PurchaseOrderInfoServiceImpl extends BaseMpServiceImpl<PurchaseOrde @@ -763,17 +767,46 @@ public class PurchaseOrderInfoServiceImpl extends BaseMpServiceImpl<PurchaseOrde
763 } 767 }
764 Map<String, ContractDistributorStandard> contractMap = contractList.stream().collect(Collectors.toMap(ContractDistributorStandard::getId, Function.identity())); 768 Map<String, ContractDistributorStandard> contractMap = contractList.stream().collect(Collectors.toMap(ContractDistributorStandard::getId, Function.identity()));
765 for (PurchaseOrderInfo orderInfo : orderInfoList) { 769 for (PurchaseOrderInfo orderInfo : orderInfoList) {
766 - String contractId = orderInfo.getContractId();  
767 - ContractDistributorStandard contract = contractMap.get(contractId);  
768 - if (contract == null) {  
769 - continue;  
770 - }  
771 - orderInfo.setDestination(contract.getDestination());  
772 - orderInfo.setForeignDestination(contract.getForeignDestination()); 770 + fillContractDestination(orderInfo, contractMap);
773 } 771 }
774 return orderInfoList; 772 return orderInfoList;
775 } 773 }
776 774
  775 + /**
  776 + * 回填订货单上的合同目的地字段,供打印等场景使用。
  777 + *
  778 + * @param orderInfo 订货单
  779 + */
  780 + private void fillContractDestination(PurchaseOrderInfo orderInfo) {
  781 + if (orderInfo == null || StringUtils.isBlank(orderInfo.getContractId())) {
  782 + return;
  783 + }
  784 + ContractDistributorStandard contract = contractDistributorStandardService.findById(orderInfo.getContractId());
  785 + if (contract == null) {
  786 + return;
  787 + }
  788 + orderInfo.setDestination(contract.getDestination());
  789 + orderInfo.setForeignDestination(contract.getForeignDestination());
  790 + }
  791 +
  792 + /**
  793 + * 根据合同映射批量回填订货单上的合同目的地字段。
  794 + *
  795 + * @param orderInfo 订货单
  796 + * @param contractMap 合同映射
  797 + */
  798 + private void fillContractDestination(PurchaseOrderInfo orderInfo, Map<String, ContractDistributorStandard> contractMap) {
  799 + if (orderInfo == null || contractMap == null || StringUtils.isBlank(orderInfo.getContractId())) {
  800 + return;
  801 + }
  802 + ContractDistributorStandard contract = contractMap.get(orderInfo.getContractId());
  803 + if (contract == null) {
  804 + return;
  805 + }
  806 + orderInfo.setDestination(contract.getDestination());
  807 + orderInfo.setForeignDestination(contract.getForeignDestination());
  808 + }
  809 +
777 @Override 810 @Override
778 public List<PurchaseOrderInfo> listByCustomerIds(List<String> customerIds) { 811 public List<PurchaseOrderInfo> listByCustomerIds(List<String> customerIds) {
779 if (CollectionUtils.isEmpty(customerIds)) { 812 if (CollectionUtils.isEmpty(customerIds)) {
1 package com.lframework.xingyun.sc.utils; 1 package com.lframework.xingyun.sc.utils;
2 2
  3 +import com.lframework.starter.web.core.utils.ApplicationUtil;
  4 +import com.lframework.starter.web.inner.dto.dic.city.DicCityDto;
  5 +import com.lframework.starter.web.inner.service.DicCityService;
3 import lombok.extern.slf4j.Slf4j; 6 import lombok.extern.slf4j.Slf4j;
  7 +import org.apache.commons.lang3.StringUtils;
4 import org.apache.poi.ss.usermodel.*; 8 import org.apache.poi.ss.usermodel.*;
5 import org.apache.poi.ss.util.CellRangeAddress; 9 import org.apache.poi.ss.util.CellRangeAddress;
6 10
@@ -41,6 +45,76 @@ public class ExcelUtil { @@ -41,6 +45,76 @@ public class ExcelUtil {
41 } 45 }
42 } 46 }
43 47
  48 + /**
  49 + * 构建打印使用的目的地文本。
  50 + * 外贸合同直接展示外贸目的地,其他合同将层级地址中的斜杠替换为中文逗号。
  51 + *
  52 + * @param contractType 合同类型
  53 + * @param destination 普通目的地
  54 + * @param foreignDestination 外贸目的地
  55 + * @return 打印使用的目的地文本
  56 + */
  57 + public static String buildPrintDestination(String contractType, String destination, String foreignDestination) {
  58 + if (isForeignContractType(contractType)) {
  59 + return StringUtils.defaultString(foreignDestination).trim();
  60 + }
  61 +
  62 + String domesticDestination = buildDomesticDestination(destination);
  63 + if (StringUtils.isNotBlank(domesticDestination)) {
  64 + return domesticDestination;
  65 + } else {
  66 + return "";
  67 + }
  68 + }
  69 +
  70 + /**
  71 + * 将国内目的地城市ID转换为中文地址路径。
  72 + *
  73 + * @param destination 目的地ID
  74 + * @return 中文地址路径
  75 + */
  76 + private static String buildDomesticDestination(String destination) {
  77 + if (StringUtils.isBlank(destination)) {
  78 + return "";
  79 + }
  80 +
  81 + try {
  82 + DicCityService dicCityService = ApplicationUtil.getBean(DicCityService.class);
  83 + List<DicCityDto> allCity = dicCityService.getAll();
  84 + List<DicCityDto> fullPath = dicCityService.getFullPath(destination, allCity);
  85 + if (fullPath == null || fullPath.isEmpty()) {
  86 + return "";
  87 + }
  88 +
  89 + StringBuilder builder = new StringBuilder();
  90 + for (DicCityDto cityDto : fullPath) {
  91 + if (cityDto == null || StringUtils.isBlank(cityDto.getName())) {
  92 + continue;
  93 + }
  94 + if (builder.length() > 0) {
  95 + builder.append(",");
  96 + }
  97 + builder.append(cityDto.getName());
  98 + }
  99 + return builder.toString();
  100 + } catch (Exception e) {
  101 + log.warn("转换国内目的地失败, destination={}", destination, e);
  102 + return "";
  103 + }
  104 + }
  105 +
  106 + /**
  107 + * 判断是否为外贸合同类型。
  108 + *
  109 + * @param contractType 合同类型
  110 + * @return true=外贸合同
  111 + */
  112 + private static boolean isForeignContractType(String contractType) {
  113 + return "INTL_STD_CONTRACT".equals(contractType)
  114 + || "INTL_INVENTORY_AGMT".equals(contractType)
  115 + || "INTL_OPEN_SPEC_AGMT".equals(contractType);
  116 + }
  117 +
44 118
45 /** 119 /**
46 * 解析占位符 120 * 解析占位符