|
|
|
@ -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<Map<String, Object>> previewExcel(MultipartFile file, EcssCoDelNotifyHeaderData inData) { |
|
|
|
SysUserEntity currentUser = (SysUserEntity) SecurityUtils.getSubject().getPrincipal(); |
|
|
|
String site = coDelMapper.getSiteByBu(inData.getBuNo()); |
|
|
|
List<EcssCoDelNotifyData> 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<String, List<EcssCoDelNotifyData>> groupedByInvoice = excelList.stream() |
|
|
|
.collect(Collectors.groupingBy(EcssCoDelNotifyData::getCmcInvoice)); |
|
|
|
|
|
|
|
List<Map<String, Object>> previewList = new ArrayList<>(); |
|
|
|
|
|
|
|
groupedByInvoice.forEach((invoice, dataList) -> { |
|
|
|
// 检查是否已存在,如果已存在则跳过 |
|
|
|
List<EcssCoDelNotifyHeaderData> existingHeaders = coDelMapper.checkIfHasHeader(invoice); |
|
|
|
if (!existingHeaders.isEmpty()) { |
|
|
|
return; // 跳过已存在的发票号 |
|
|
|
} |
|
|
|
|
|
|
|
Map<String, Object> 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<String, List<String>> saveEcssCoDelNotifyByExcel(MultipartFile file, EcssCoDelNotifyHeaderData inData) { |
|
|
|
public Map<String, List<String>> saveEcssCoDelNotifyByExcel(MultipartFile file, EcssCoDelNotifyHeaderData inData, HttpServletRequest request) { |
|
|
|
SysUserEntity currentUser = (SysUserEntity) SecurityUtils.getSubject().getPrincipal(); |
|
|
|
String site = coDelMapper.getSiteByBu(inData.getBuNo()); |
|
|
|
List<EcssCoDelNotifyData> 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<Map> palletDetailList = coDelMapper.exportCoDelPalletDetail(notifyHeader); |
|
|
|
int totalQty=palletDetailList.stream().mapToInt(o -> Integer.parseInt(o.get("total_qty").toString())).sum(); |
|
|
|
Map<Object, 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<Object, Object> poNoMap = new HashMap<>(); |
|
|
|
BigDecimal ttlAmount = BigDecimal.ZERO; |
|
|
|
@ -2615,4 +2679,9 @@ public class CoDelServiceImpl implements CoDelService { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public List<Map<String, Object>> getCustomerTemplateList(Map<String, Object> params) { |
|
|
|
return coDelMapper.getCustomerTemplateList(params); |
|
|
|
} |
|
|
|
|
|
|
|
} |