diff --git a/src/main/java/com/xujie/sys/modules/ecss/controller/CoDelController.java b/src/main/java/com/xujie/sys/modules/ecss/controller/CoDelController.java index 6e8aae1e..72de086b 100644 --- a/src/main/java/com/xujie/sys/modules/ecss/controller/CoDelController.java +++ b/src/main/java/com/xujie/sys/modules/ecss/controller/CoDelController.java @@ -15,6 +15,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; import org.springframework.web.multipart.MultipartFile; +import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.util.List; import java.util.Map; @@ -59,9 +60,15 @@ public class CoDelController { return R.ok().put("rows", rows); } + @PostMapping("/previewExcel") + public R previewExcel(@RequestParam(value = "file") MultipartFile file, @ModelAttribute EcssCoDelNotifyHeaderData data){ + List> previewData = coDelService.previewExcel(file, data); + return R.ok().put("data", previewData); + } + @PostMapping("/saveEcssCoDelNotifyByExcel") - public R saveEcssCoDelNotifyByExcel(@RequestParam(value = "file") MultipartFile file, @ModelAttribute EcssCoDelNotifyHeaderData data){ - Map> resultMap = coDelService.saveEcssCoDelNotifyByExcel(file, data); + public R saveEcssCoDelNotifyByExcel(@RequestParam(value = "file") MultipartFile file, @ModelAttribute EcssCoDelNotifyHeaderData data, HttpServletRequest request){ + Map> resultMap = coDelService.saveEcssCoDelNotifyByExcel(file, data, request); return R.ok().put("resultMap", resultMap); } @@ -533,4 +540,11 @@ public class CoDelController { return R.error("更新导出状态失败:" + e.getMessage()); } } + + @PostMapping("/getCustomerTemplateList") + @ResponseBody + public R getCustomerTemplateList(@RequestBody Map params) { + List> templateList = coDelService.getCustomerTemplateList(params); + return R.ok().put("rows", templateList); + } } diff --git a/src/main/java/com/xujie/sys/modules/ecss/mapper/CoDelMapper.java b/src/main/java/com/xujie/sys/modules/ecss/mapper/CoDelMapper.java index 60825c17..8d5397c0 100644 --- a/src/main/java/com/xujie/sys/modules/ecss/mapper/CoDelMapper.java +++ b/src/main/java/com/xujie/sys/modules/ecss/mapper/CoDelMapper.java @@ -248,4 +248,7 @@ public interface CoDelMapper { @Param("buNo") String buNo, @Param("delNo") String delNo, @Param("notifyDetailItemNo") Integer notifyDetailItemNo); + + // 获取客户模板列表 + List> getCustomerTemplateList(Map params); } diff --git a/src/main/java/com/xujie/sys/modules/ecss/service/CoDelService.java b/src/main/java/com/xujie/sys/modules/ecss/service/CoDelService.java index be45faa3..684c3346 100644 --- a/src/main/java/com/xujie/sys/modules/ecss/service/CoDelService.java +++ b/src/main/java/com/xujie/sys/modules/ecss/service/CoDelService.java @@ -11,6 +11,7 @@ import com.xujie.sys.modules.part.entity.PartSubPropertiesValueData; import org.apache.ibatis.annotations.Param; import org.springframework.web.multipart.MultipartFile; +import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.io.IOException; import java.util.List; @@ -22,7 +23,8 @@ public interface CoDelService { PageUtils searchEcssCoDelNotifyHeaderForCK(EcssCoDelNotifyHeaderData data); PageUtils searchEcssCoDelNotifyHeaderForDanZheng(EcssCoDelNotifyHeaderData data); List searchEcssCoDelNotifyDetail(EcssCoDelNotifyHeaderData data); - Map> saveEcssCoDelNotifyByExcel(MultipartFile file, EcssCoDelNotifyHeaderData data); + List> previewExcel(MultipartFile file, EcssCoDelNotifyHeaderData data); + Map> saveEcssCoDelNotifyByExcel(MultipartFile file, EcssCoDelNotifyHeaderData data, HttpServletRequest request); void updateEcssDelHeader(EcssCoDelNotifyHeaderData data); @@ -152,4 +154,6 @@ public interface CoDelService { PageUtils queryPartListAll(PartInformationEntity data); void modifyNotifyDetailByExcel(MultipartFile file, EcssCoDelNotifyHeaderData inData); + + List> getCustomerTemplateList(Map params); } diff --git a/src/main/java/com/xujie/sys/modules/ecss/service/impl/CoDelServiceImpl.java b/src/main/java/com/xujie/sys/modules/ecss/service/impl/CoDelServiceImpl.java index 94ac57e3..7c9ec3de 100644 --- a/src/main/java/com/xujie/sys/modules/ecss/service/impl/CoDelServiceImpl.java +++ b/src/main/java/com/xujie/sys/modules/ecss/service/impl/CoDelServiceImpl.java @@ -39,6 +39,7 @@ import org.springframework.web.multipart.MultipartFile; import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.ObjectMapper; +import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.io.IOException; import java.io.InputStream; @@ -89,9 +90,55 @@ public class CoDelServiceImpl implements CoDelService { return coDelMapper.searchEcssCoDelNotifyDetail(data); } + @Override + public List> previewExcel(MultipartFile file, EcssCoDelNotifyHeaderData inData) { + SysUserEntity currentUser = (SysUserEntity) SecurityUtils.getSubject().getPrincipal(); + String site = coDelMapper.getSiteByBu(inData.getBuNo()); + List excelList = new ArrayList<>(); + + try (InputStream is = file.getInputStream()) { + XSSFWorkbook workbook = new XSSFWorkbook(is); + importNotifyExcel(inData, workbook, site, currentUser, excelList); + } catch (Exception e) { + throw new RuntimeException("文件解析失败:" + e.getMessage()); + } + + // 按发票号分组并汇总数据 + Map> groupedByInvoice = excelList.stream() + .collect(Collectors.groupingBy(EcssCoDelNotifyData::getCmcInvoice)); + + List> previewList = new ArrayList<>(); + + groupedByInvoice.forEach((invoice, dataList) -> { + // 检查是否已存在,如果已存在则跳过 + List existingHeaders = coDelMapper.checkIfHasHeader(invoice); + if (!existingHeaders.isEmpty()) { + return; // 跳过已存在的发票号 + } + + Map summary = new HashMap<>(); + summary.put("cmcInvoice", invoice); + // 格式化日期为字符串 + Date readyDate = dataList.get(0).getReadyDate(); + String formattedDate = readyDate != null ? DateUtils.format(readyDate, "yyyy-MM-dd") : ""; + summary.put("readyDate", formattedDate); + summary.put("totalQty", dataList.stream() + .map(EcssCoDelNotifyData::getQty) + .reduce(BigDecimal.ZERO, BigDecimal::add)); + summary.put("totalItems", dataList.size()); + summary.put("destination", dataList.get(0).getDestination()); + summary.put("shippingMode", dataList.get(0).getShippingMode()); + summary.put("exists", false); // 已经过滤掉存在的,这里都是false + + previewList.add(summary); + }); + + return previewList; + } + @Override @Transactional - public Map> saveEcssCoDelNotifyByExcel(MultipartFile file, EcssCoDelNotifyHeaderData inData) { + public Map> saveEcssCoDelNotifyByExcel(MultipartFile file, EcssCoDelNotifyHeaderData inData, HttpServletRequest request) { SysUserEntity currentUser = (SysUserEntity) SecurityUtils.getSubject().getPrincipal(); String site = coDelMapper.getSiteByBu(inData.getBuNo()); List excelList = new ArrayList<>(); @@ -140,12 +187,30 @@ public class CoDelServiceImpl implements CoDelService { headerList.setNotifyStatus(list.get(0).getNotifyStatus()); headerList.setReadyDate(list.get(0).getReadyDate()); headerList.setShippingMode(list.get(0).getShippingMode()); - headerList.setCustomerName(inData.getCustomerName()); - headerList.setLocalShipAddress(inData.getLocalShipAddress()); - headerList.setOverseasShipper(inData.getOverseasShipper()); - headerList.setOverseasAddress(inData.getOverseasAddress()); - headerList.setCnative(inData.getCnative()); - headerList.setSalesArea(inData.getSalesArea()); + + // 如果有按发票号分别设置的客户信息,则使用该信息;否则使用全局信息 + String customerNameKey = "customerName_" + cmcInvoice; + String localShipAddressKey = "localShipAddress_" + cmcInvoice; + String overseasShipperKey = "overseasShipper_" + cmcInvoice; + String overseasAddressKey = "overseasAddress_" + cmcInvoice; + String cnativeKey = "cnative_" + cmcInvoice; + String salesAreaKey = "salesArea_" + cmcInvoice; + + // 从请求参数中获取按发票号设置的客户信息 + String customerName = request.getParameter(customerNameKey); + String localShipAddress = request.getParameter(localShipAddressKey); + String overseasShipper = request.getParameter(overseasShipperKey); + String overseasAddress = request.getParameter(overseasAddressKey); + String cnative = request.getParameter(cnativeKey); + String salesArea = request.getParameter(salesAreaKey); + + // 如果按发票号的信息不存在,则使用全局信息 + headerList.setCustomerName(customerName != null ? customerName : inData.getCustomerName()); + headerList.setLocalShipAddress(localShipAddress != null ? localShipAddress : inData.getLocalShipAddress()); + headerList.setOverseasShipper(overseasShipper != null ? overseasShipper : inData.getOverseasShipper()); + headerList.setOverseasAddress(overseasAddress != null ? overseasAddress : inData.getOverseasAddress()); + headerList.setCnative(cnative != null ? cnative : inData.getCnative()); + headerList.setSalesArea(salesArea != null ? salesArea : inData.getSalesArea()); headerList.setCmcInvoice(cmcInvoice); headerList.setCreateBy(inData.getUsername()); coDelMapper.saveEcssCoDelNotifyHeader(headerList); @@ -272,7 +337,7 @@ public class CoDelServiceImpl implements CoDelService { task.setUpc(getStringCellValue(row, 27)); task.setRemark(getStringCellValue(row, 28)); task.setRoll(getNumericCellValueOrDefault(row, 29)); - task.setCarton(Objects.requireNonNull(getNumericCellValueOrDefault(row, 30)).setScale(1, RoundingMode.HALF_UP)); + task.setCarton(getNumericCellValueOrDefault(row, 30)!=null? Objects.requireNonNull(getNumericCellValueOrDefault(row, 30)).setScale(1, RoundingMode.HALF_UP):null); task.setErpFlag("N"); task.setNotifyStatus("已计划"); task.setUsername(inData.getUsername()); @@ -1607,7 +1672,7 @@ public class CoDelServiceImpl implements CoDelService { eorder.put("net_weight", ""); eorder.put("weight_unit", ""); } - eorder.put("hs_code_desc", data.getHsCodeDescType()!=null&& data.getHsCodeDescType().equals("N")?eorder.get("hsCodeDescEn"):eorder.get("hs_code_desc")); + eorder.put("hs_code_desc", eorder.get("hs_code_desc")); } template.addListVarAll(detailList); } @@ -1847,8 +1912,9 @@ public class CoDelServiceImpl implements CoDelService { eorder.put("noCartons", isMiddleRow ? noCartons.setScale(0, RoundingMode.HALF_UP) : ""); eorder.put("gross_weight", isMiddleRow ? ((BigDecimal) list.get(m).get("gross_weight")).setScale(2, RoundingMode.HALF_UP) : ""); eorder.put("net_weight", isMiddleRow ? ((BigDecimal) list.get(m).get("net_weight")).setScale(2, RoundingMode.HALF_UP) : ""); - eorder.put("rolls", ((BigDecimal)eorder.get("rolls")).setScale(0, RoundingMode.HALF_UP)); - rolls = rolls.add(eorder.get("rolls") !=null?new BigDecimal(eorder.get("rolls").toString()):BigDecimal.valueOf(0.0)); + BigDecimal cuRolls = eorder.get("rolls") !=null?((BigDecimal)eorder.get("rolls")).setScale(0, RoundingMode.HALF_UP):BigDecimal.valueOf(0.0); + eorder.put("rolls", cuRolls); + rolls = rolls.add(cuRolls); EcssCoDelNotifyDetailData nodifyData = notifyDetailMap.get(partNo); // 只有RFID需要 String lossratio=""; @@ -1891,7 +1957,7 @@ public class CoDelServiceImpl implements CoDelService { // 下面是可选的或者手动维护的 // RFID需要的 if (notifyHeader.getBuNo().equals("01-Label") || notifyHeader.getBuNo().equals("03-RFID")) { - template.addVar("total_plt", totalPlt+"PLTS"); + template.addVar("total_plt", totalPlt); template.addVar("total:", "total:"); template.addVar("madein", stringInput(data.getOrigin())); template.addVar("shippingNo", "shipping no"); @@ -1954,9 +2020,7 @@ public class CoDelServiceImpl implements CoDelService { List palletDetailList = coDelMapper.exportCoDelPalletDetail(notifyHeader); int totalQty=palletDetailList.stream().mapToInt(o -> Integer.parseInt(o.get("total_qty").toString())).sum(); Map palletMap = palletDetailList.stream().collect(Collectors.toMap( o -> o.get("part_no"), o -> o)); - template.addVar("hs_code_desc", stringInput(data.getHsCodeDescType()!=null&& data.getHsCodeDescType().equals("N")? - (nodifyDetailList.get(0).get("hsCodeDescEn")!=null?sbEn.toString():""): - (nodifyDetailList.get(0).get("hsCodeDesc")!=null?sb.toString():""))); + template.addVar("hs_code_desc", stringInput(nodifyDetailList.get(0).get("hsCodeDescEn")!=null?sbEn.toString():"")); template.addVar("hs_code", stringInput(nodifyDetailList.get(0).get("hsCode").toString())); Map poNoMap = new HashMap<>(); BigDecimal ttlAmount = BigDecimal.ZERO; @@ -2615,4 +2679,9 @@ public class CoDelServiceImpl implements CoDelService { } } + @Override + public List> getCustomerTemplateList(Map params) { + return coDelMapper.getCustomerTemplateList(params); + } + } diff --git a/src/main/resources/mapper/ecss/CoDelMapper.xml b/src/main/resources/mapper/ecss/CoDelMapper.xml index 4db0113d..e53a5631 100644 --- a/src/main/resources/mapper/ecss/CoDelMapper.xml +++ b/src/main/resources/mapper/ecss/CoDelMapper.xml @@ -1141,4 +1141,22 @@ left join ecss_CoDelNotifyHeader noHeader on a.site=noHeader.site and a.delNo=no and a.seq_no=#{seqNo} + + + diff --git a/src/main/resources/templates/declaration-all-seal-template.xlsx b/src/main/resources/templates/declaration-all-seal-template.xlsx index 8cc588ed..ee600c4f 100644 Binary files a/src/main/resources/templates/declaration-all-seal-template.xlsx and b/src/main/resources/templates/declaration-all-seal-template.xlsx differ diff --git a/src/main/resources/templates/declaration-all-template.xlsx b/src/main/resources/templates/declaration-all-template.xlsx index 2b405989..45cb10df 100644 Binary files a/src/main/resources/templates/declaration-all-template.xlsx and b/src/main/resources/templates/declaration-all-template.xlsx differ diff --git a/src/main/resources/templates/declaration-packingList-template.xlsx b/src/main/resources/templates/declaration-packingList-template.xlsx index 3e69dc78..6a554584 100644 Binary files a/src/main/resources/templates/declaration-packingList-template.xlsx and b/src/main/resources/templates/declaration-packingList-template.xlsx differ