Browse Source

批量导入发货通知单

java8
han\hanst 9 months ago
parent
commit
f5bcf44f96
  1. 18
      src/main/java/com/xujie/sys/modules/ecss/controller/CoDelController.java
  2. 3
      src/main/java/com/xujie/sys/modules/ecss/mapper/CoDelMapper.java
  3. 6
      src/main/java/com/xujie/sys/modules/ecss/service/CoDelService.java
  4. 99
      src/main/java/com/xujie/sys/modules/ecss/service/impl/CoDelServiceImpl.java
  5. 18
      src/main/resources/mapper/ecss/CoDelMapper.xml
  6. BIN
      src/main/resources/templates/declaration-all-seal-template.xlsx
  7. BIN
      src/main/resources/templates/declaration-all-template.xlsx
  8. BIN
      src/main/resources/templates/declaration-packingList-template.xlsx

18
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<Map<String, Object>> 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<String, List<String>> resultMap = coDelService.saveEcssCoDelNotifyByExcel(file, data);
public R saveEcssCoDelNotifyByExcel(@RequestParam(value = "file") MultipartFile file, @ModelAttribute EcssCoDelNotifyHeaderData data, HttpServletRequest request){
Map<String, List<String>> 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<String, Object> params) {
List<Map<String, Object>> templateList = coDelService.getCustomerTemplateList(params);
return R.ok().put("rows", templateList);
}
}

3
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<Map<String, Object>> getCustomerTemplateList(Map<String, Object> params);
}

6
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<EcssCoDelNotifyDetailData> searchEcssCoDelNotifyDetail(EcssCoDelNotifyHeaderData data);
Map<String, List<String>> saveEcssCoDelNotifyByExcel(MultipartFile file, EcssCoDelNotifyHeaderData data);
List<Map<String, Object>> previewExcel(MultipartFile file, EcssCoDelNotifyHeaderData data);
Map<String, List<String>> 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<Map<String, Object>> getCustomerTemplateList(Map<String, Object> params);
}

99
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<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);
}
}

18
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}
</if>
</select>
<!-- 获取客户模板列表 -->
<select id="getCustomerTemplateList" resultType="java.util.Map">
SELECT
template_no,
template_name,
ccuscode,
ccusname,
caddcode1,
localShipAddress,
salesArea,
caddcode2,
overseasAddress,
cnative,
overseasShipper
FROM ecss_Customer_template
ORDER BY template_name
</select>
</mapper>

BIN
src/main/resources/templates/declaration-all-seal-template.xlsx

BIN
src/main/resources/templates/declaration-all-template.xlsx

BIN
src/main/resources/templates/declaration-packingList-template.xlsx

Loading…
Cancel
Save