diff --git a/src/main/java/com/xujie/sys/common/utils/DateUtils.java b/src/main/java/com/xujie/sys/common/utils/DateUtils.java index 4b743b97..70ba2938 100644 --- a/src/main/java/com/xujie/sys/common/utils/DateUtils.java +++ b/src/main/java/com/xujie/sys/common/utils/DateUtils.java @@ -298,7 +298,23 @@ public class DateUtils { } - public static void main(String[] args) throws ParseException{ - System.out.println(differentDays(DateUtil.parse("2022-11-17 12:00:00"),DateUtil.parse("2022-11-15"))); + public static void main(String[] args) { + try { + try { + getDateByParten("777","yyyy-MM-dd"); + }catch (ParseException e){ + throw new RuntimeException("格式有误!"); + } + }catch (Exception e){ + System.out.println(e.getMessage()+"66666"); + } + + + } + + public static Date getDateByParten(String date, String parten) + throws ParseException { + SimpleDateFormat sdf = new SimpleDateFormat(parten); + return sdf.parse(date); } } 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 new file mode 100644 index 00000000..91bf6bfa --- /dev/null +++ b/src/main/java/com/xujie/sys/modules/ecss/controller/CoDelController.java @@ -0,0 +1,34 @@ +package com.xujie.sys.modules.ecss.controller; + +import com.xujie.sys.common.utils.PageUtils; +import com.xujie.sys.common.utils.R; +import com.xujie.sys.modules.ecss.data.EcssCoDelNotifyData; +import com.xujie.sys.modules.ecss.data.EcssCoDelNotifyHeaderData; +import com.xujie.sys.modules.ecss.entity.EcssCoDelNotify; +import com.xujie.sys.modules.ecss.service.CoDelService; +import com.xujie.sys.modules.orderIssure.entity.SOIssueNotifyHeaderData; +import com.xujie.sys.modules.part.vo.BomComponentVo; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.*; +import org.springframework.web.multipart.MultipartFile; + +@RestController +@RequestMapping("/ecss/coDel") +public class CoDelController { + @Autowired + private CoDelService coDelService; + + + @PostMapping(value="/searchEcssCoDelNotifyHeader") + @ResponseBody + public R searchEcssCoDelNotifyHeader(@RequestBody EcssCoDelNotifyHeaderData data) { + PageUtils page = coDelService.searchEcssCoDelNotifyHeader(data); + return R.ok().put("page", page); + } + + @PostMapping("/saveEcssCoDelNotifyByExcel") + public R saveEcssCoDelNotifyByExcel(@RequestParam(value = "file") MultipartFile file, @ModelAttribute EcssCoDelNotifyHeaderData data){ + coDelService.saveEcssCoDelNotifyByExcel(file, data); + return R.ok(); + } +} diff --git a/src/main/java/com/xujie/sys/modules/ecss/data/EcssCoDelNotifyData.java b/src/main/java/com/xujie/sys/modules/ecss/data/EcssCoDelNotifyData.java new file mode 100644 index 00000000..beb175b9 --- /dev/null +++ b/src/main/java/com/xujie/sys/modules/ecss/data/EcssCoDelNotifyData.java @@ -0,0 +1,26 @@ +package com.xujie.sys.modules.ecss.data; + +import com.fasterxml.jackson.annotation.JsonFormat; +import com.xujie.sys.modules.ecss.entity.EcssCoDelNotify; +import lombok.Data; +import org.apache.ibatis.type.Alias; +import org.springframework.format.annotation.DateTimeFormat; + +import java.util.Date; + +@Data +@Alias("EcssCoDelNotifyData") +public class EcssCoDelNotifyData extends EcssCoDelNotify { + + @DateTimeFormat(pattern = "yyyy-MM-dd") + @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8") + private Date startDate; + + @DateTimeFormat(pattern = "yyyy-MM-dd") + @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8") + private Date endDate; + + private String username; + + private String buDesc; +} diff --git a/src/main/java/com/xujie/sys/modules/ecss/data/EcssCoDelNotifyDetailData.java b/src/main/java/com/xujie/sys/modules/ecss/data/EcssCoDelNotifyDetailData.java new file mode 100644 index 00000000..795fda28 --- /dev/null +++ b/src/main/java/com/xujie/sys/modules/ecss/data/EcssCoDelNotifyDetailData.java @@ -0,0 +1,10 @@ +package com.xujie.sys.modules.ecss.data; + +import com.xujie.sys.modules.ecss.entity.EcssCoDelNotifyDetail; +import lombok.Data; +import org.apache.ibatis.type.Alias; + +@Data +@Alias("EcssCoDelNotifyDetailData") +public class EcssCoDelNotifyDetailData extends EcssCoDelNotifyDetail { +} diff --git a/src/main/java/com/xujie/sys/modules/ecss/data/EcssCoDelNotifyHeaderData.java b/src/main/java/com/xujie/sys/modules/ecss/data/EcssCoDelNotifyHeaderData.java new file mode 100644 index 00000000..bb551931 --- /dev/null +++ b/src/main/java/com/xujie/sys/modules/ecss/data/EcssCoDelNotifyHeaderData.java @@ -0,0 +1,12 @@ +package com.xujie.sys.modules.ecss.data; + +import com.xujie.sys.modules.ecss.entity.EcssCoDelNotifyHeader; +import lombok.Data; +import org.apache.ibatis.type.Alias; + +@Data +@Alias("EcssCoDelNotifyHeaderData") +public class EcssCoDelNotifyHeaderData extends EcssCoDelNotifyHeader { + private String buDesc; + private String username; +} diff --git a/src/main/java/com/xujie/sys/modules/ecss/entity/EcssCoDelNotify.java b/src/main/java/com/xujie/sys/modules/ecss/entity/EcssCoDelNotify.java new file mode 100644 index 00000000..f38d8bea --- /dev/null +++ b/src/main/java/com/xujie/sys/modules/ecss/entity/EcssCoDelNotify.java @@ -0,0 +1,198 @@ +package com.xujie.sys.modules.ecss.entity; + +import com.fasterxml.jackson.annotation.JsonFormat; +import com.xujie.sys.common.utils.QueryPage; +import lombok.Data; +import org.springframework.format.annotation.DateTimeFormat; + +import java.math.BigDecimal; +import java.util.Date; +@Data +public class EcssCoDelNotify extends QueryPage { + /** + * + */ + private String site; + + /** + * + */ + private String buNo; + + /** + * + */ + private String delNo; + + /** + * + */ + private Integer itemNo; + + /** + * + */ + @DateTimeFormat(pattern = "yyyy-MM-dd") + @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8") + private Date notifyDate; + + /** + * + */ + private String salesOrder; + private Integer salesOrderItemNo; + /** + * + */ + @DateTimeFormat(pattern = "yyyy-MM-dd") + @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8") + private Date readyDate; + + /** + * + */ + private String customerName; + + /** + * + */ + private String customerPO; + + /** + * + */ + private String line; + + /** + * + */ + private String version; + + /** + * + */ + private String status; + + /** + * + */ + private String family; + + /** + * + */ + private String partNo; + + /** + * + */ + private String partDescription; + + /** + * + */ + private BigDecimal qty; + + /** + * + */ + private BigDecimal lt; + + /** + * + */ + private String cmcInvoice; + + /** + * + */ + private String cmcComment; + + /** + * + */ + private String destination; + + /** + * + */ + private String saleType; + + /** + * + */ + private String awbBl; + + /** + * + */ + private String shippingNumber; + + /** + * + */ + private String shippingMode; + + /** + * + */ + private String forwarderInfo; + + /** + * + */ + private String currency; + + /** + * + */ + private BigDecimal tp; + + /** + * + */ + private BigDecimal ttlAmount; + + /** + * + */ + private BigDecimal sumPrice; + + /** + * + */ + private String so; + + /** + * + */ + private String upc; + + /** + * + */ + private String remark; + + /** + * + */ + private String erpFlag; + + /** + * + */ + private String notifyStatus; + + /** + * + */ + private String erpDelNo; + + /** + * + */ + private String erpDelItemNo; + + +} + diff --git a/src/main/java/com/xujie/sys/modules/ecss/entity/EcssCoDelNotifyDetail.java b/src/main/java/com/xujie/sys/modules/ecss/entity/EcssCoDelNotifyDetail.java new file mode 100644 index 00000000..5589709e --- /dev/null +++ b/src/main/java/com/xujie/sys/modules/ecss/entity/EcssCoDelNotifyDetail.java @@ -0,0 +1,385 @@ +package com.xujie.sys.modules.ecss.entity; + +import com.xujie.sys.common.utils.QueryPage; + +import java.math.BigDecimal; + +public class EcssCoDelNotifyDetail extends QueryPage { + /** + * + */ + private String site; + + /** + * + */ + private String buNo; + + /** + * + */ + private String delNo; + + /** + * + */ + private Integer itemNo; + + /** + * + */ + private String salesOrder; + + /** + * + */ + private Integer salesOrderItemNo; + + /** + * + */ + private String customerPO; + + /** + * + */ + private String line; + + /** + * + */ + private String version; + + /** + * + */ + private String status; + + /** + * + */ + private String family; + + /** + * + */ + private String partNo; + + /** + * + */ + private String partDescription; + + /** + * + */ + private BigDecimal qty; + + /** + * + */ + private BigDecimal lt; + + /** + * + */ + private String cmcInvoice; + + /** + * + */ + private String cmcComment; + + /** + * + */ + private String saleType; + + /** + * + */ + private String awbBl; + + /** + * + */ + private String shippingNumber; + + /** + * + */ + private String forwarderInfo; + + /** + * + */ + private String currency; + + /** + * + */ + private BigDecimal tp; + + /** + * + */ + private BigDecimal ttlAmount; + + /** + * + */ + private BigDecimal sumPrice; + + /** + * + */ + private String so; + + /** + * + */ + private String upc; + + /** + * + */ + private String remark; + + /** + * + */ + private Integer erpDelItemNo; + + public String getSite() { + return site; + } + + public void setSite(String site) { + this.site = site; + } + + public String getBuNo() { + return buNo; + } + + public void setBuNo(String buNo) { + this.buNo = buNo; + } + + public String getDelNo() { + return delNo; + } + + public void setDelNo(String delNo) { + this.delNo = delNo; + } + + public Integer getItemNo() { + return itemNo; + } + + public void setItemNo(Integer itemNo) { + this.itemNo = itemNo; + } + + public String getSalesOrder() { + return salesOrder; + } + + public void setSalesOrder(String salesOrder) { + this.salesOrder = salesOrder; + } + + public Integer getSalesOrderItemNo() { + return salesOrderItemNo; + } + + public void setSalesOrderItemNo(Integer salesOrderItemNo) { + this.salesOrderItemNo = salesOrderItemNo; + } + + public String getCustomerPO() { + return customerPO; + } + + public void setCustomerPO(String customerPO) { + this.customerPO = customerPO; + } + + public String getLine() { + return line; + } + + public void setLine(String line) { + this.line = line; + } + + public String getVersion() { + return version; + } + + public void setVersion(String version) { + this.version = version; + } + + public String getStatus() { + return status; + } + + public void setStatus(String status) { + this.status = status; + } + + public String getFamily() { + return family; + } + + public void setFamily(String family) { + this.family = family; + } + + public String getPartNo() { + return partNo; + } + + public void setPartNo(String partNo) { + this.partNo = partNo; + } + + public String getPartDescription() { + return partDescription; + } + + public void setPartDescription(String partDescription) { + this.partDescription = partDescription; + } + + public BigDecimal getQty() { + return qty; + } + + public void setQty(BigDecimal qty) { + this.qty = qty; + } + + public BigDecimal getLt() { + return lt; + } + + public void setLt(BigDecimal lt) { + this.lt = lt; + } + + public String getCmcInvoice() { + return cmcInvoice; + } + + public void setCmcInvoice(String cmcInvoice) { + this.cmcInvoice = cmcInvoice; + } + + public String getCmcComment() { + return cmcComment; + } + + public void setCmcComment(String cmcComment) { + this.cmcComment = cmcComment; + } + + public String getSaleType() { + return saleType; + } + + public void setSaleType(String saleType) { + this.saleType = saleType; + } + + public String getAwbBl() { + return awbBl; + } + + public void setAwbBl(String awbBl) { + this.awbBl = awbBl; + } + + public String getShippingNumber() { + return shippingNumber; + } + + public void setShippingNumber(String shippingNumber) { + this.shippingNumber = shippingNumber; + } + + public String getForwarderInfo() { + return forwarderInfo; + } + + public void setForwarderInfo(String forwarderInfo) { + this.forwarderInfo = forwarderInfo; + } + + public String getCurrency() { + return currency; + } + + public void setCurrency(String currency) { + this.currency = currency; + } + + public BigDecimal getTp() { + return tp; + } + + public void setTp(BigDecimal tp) { + this.tp = tp; + } + + public BigDecimal getTtlAmount() { + return ttlAmount; + } + + public void setTtlAmount(BigDecimal ttlAmount) { + this.ttlAmount = ttlAmount; + } + + public BigDecimal getSumPrice() { + return sumPrice; + } + + public void setSumPrice(BigDecimal sumPrice) { + this.sumPrice = sumPrice; + } + + public String getSo() { + return so; + } + + public void setSo(String so) { + this.so = so; + } + + public String getUpc() { + return upc; + } + + public void setUpc(String upc) { + this.upc = upc; + } + + public String getRemark() { + return remark; + } + + public void setRemark(String remark) { + this.remark = remark; + } + + public Integer getErpDelItemNo() { + return erpDelItemNo; + } + + public void setErpDelItemNo(Integer erpDelItemNo) { + this.erpDelItemNo = erpDelItemNo; + } +} + diff --git a/src/main/java/com/xujie/sys/modules/ecss/entity/EcssCoDelNotifyHeader.java b/src/main/java/com/xujie/sys/modules/ecss/entity/EcssCoDelNotifyHeader.java new file mode 100644 index 00000000..65442a6b --- /dev/null +++ b/src/main/java/com/xujie/sys/modules/ecss/entity/EcssCoDelNotifyHeader.java @@ -0,0 +1,199 @@ +package com.xujie.sys.modules.ecss.entity; + +import com.fasterxml.jackson.annotation.JsonFormat; +import com.xujie.sys.common.utils.PageUtils; +import com.xujie.sys.common.utils.QueryPage; +import org.springframework.format.annotation.DateTimeFormat; + +import java.util.Date; + +public class EcssCoDelNotifyHeader extends QueryPage { + /** + * + */ + private String site; + + /** + * + */ + private String buNo; + + /** + * + */ + private String delNo; + + /** + * + */ + private String erpDelNo; + + /** + * + */ + @DateTimeFormat(pattern = "yyyy-MM-dd") + @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8") + private Date readyDate; + + /** + * + */ + @DateTimeFormat(pattern = "yyyy-MM-dd") + @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8") + private Date notifyDate; + + /** + * + */ + private String customerName; + + /** + * + */ + private String destination; + + /** + * + */ + private String shippingMode; + + /** + * + */ + private String erpFlag; + + /** + * + */ + private String notifyStatus; + private String cmcInvoice; + /** + * + */ + private String remark; + @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") + @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") + private Date createDate; + private String createBy; + + public String getSite() { + return site; + } + + public void setSite(String site) { + this.site = site; + } + + public String getBuNo() { + return buNo; + } + + public void setBuNo(String buNo) { + this.buNo = buNo; + } + + public String getDelNo() { + return delNo; + } + + public void setDelNo(String delNo) { + this.delNo = delNo; + } + + public String getErpDelNo() { + return erpDelNo; + } + + public void setErpDelNo(String erpDelNo) { + this.erpDelNo = erpDelNo; + } + + public Date getReadyDate() { + return readyDate; + } + + public void setReadyDate(Date readyDate) { + this.readyDate = readyDate; + } + + public Date getNotifyDate() { + return notifyDate; + } + + public void setNotifyDate(Date notifyDate) { + this.notifyDate = notifyDate; + } + + public String getCustomerName() { + return customerName; + } + + public void setCustomerName(String customerName) { + this.customerName = customerName; + } + + public String getDestination() { + return destination; + } + + public void setDestination(String destination) { + this.destination = destination; + } + + public String getShippingMode() { + return shippingMode; + } + + public void setShippingMode(String shippingMode) { + this.shippingMode = shippingMode; + } + + public String getErpFlag() { + return erpFlag; + } + + public void setErpFlag(String erpFlag) { + this.erpFlag = erpFlag; + } + + public String getNotifyStatus() { + return notifyStatus; + } + + public void setNotifyStatus(String notifyStatus) { + this.notifyStatus = notifyStatus; + } + + public String getRemark() { + return remark; + } + + public void setRemark(String remark) { + this.remark = remark; + } + + public Date getCreateDate() { + return createDate; + } + + public void setCreateDate(Date createDate) { + this.createDate = createDate; + } + + public String getCreateBy() { + return createBy; + } + + public void setCreateBy(String createBy) { + this.createBy = createBy; + } + + public String getCmcInvoice() { + return cmcInvoice; + } + + public void setCmcInvoice(String cmcInvoice) { + this.cmcInvoice = cmcInvoice; + } +} + 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 new file mode 100644 index 00000000..948e8671 --- /dev/null +++ b/src/main/java/com/xujie/sys/modules/ecss/mapper/CoDelMapper.java @@ -0,0 +1,30 @@ +package com.xujie.sys.modules.ecss.mapper; + +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.xujie.sys.modules.ecss.data.EcssCoDelNotifyData; +import com.xujie.sys.modules.ecss.data.EcssCoDelNotifyHeaderData; +import com.xujie.sys.modules.ecss.entity.EcssCoDelNotifyDetail; +import com.xujie.sys.modules.ecss.entity.EcssCoDelNotifyHeader; +import com.xujie.sys.modules.orderIssure.entity.PartData; +import com.xujie.sys.modules.orderIssure.entity.SOIssueNotifyHeaderData; +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; + +import java.util.List; + +@Mapper +public interface CoDelMapper { + + IPage searchEcssCoDelNotifyHeader(Page ecssCoDelNotifyDataPage, @Param("query") EcssCoDelNotifyHeaderData data); + + String getSiteByBu(String buNo); + + List checkIfHasHeader(String inVoice); + + void updateTransNo(@Param("site") String site,@Param("transType") String transType); + String getTransNo(@Param("site") String site,@Param("transType") String transType); + void saveEcssCoDelNotifyHeader(EcssCoDelNotifyHeader inData); + void batchSaveEcssCoDelNotifyDetail(List list ); + List checkPart(@Param("site") String site, @Param("partNo") String partNo); +} 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 new file mode 100644 index 00000000..ce9b0a48 --- /dev/null +++ b/src/main/java/com/xujie/sys/modules/ecss/service/CoDelService.java @@ -0,0 +1,15 @@ +package com.xujie.sys.modules.ecss.service; + +import com.xujie.sys.common.utils.PageUtils; +import com.xujie.sys.modules.ecss.data.EcssCoDelNotifyData; +import com.xujie.sys.modules.ecss.data.EcssCoDelNotifyHeaderData; +import com.xujie.sys.modules.orderIssure.entity.SOIssueNotifyHeaderData; + +import org.springframework.web.multipart.MultipartFile; + +public interface CoDelService { + + PageUtils searchEcssCoDelNotifyHeader(EcssCoDelNotifyHeaderData data); + + void saveEcssCoDelNotifyByExcel(MultipartFile file, EcssCoDelNotifyHeaderData data); +} 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 new file mode 100644 index 00000000..aa2fd471 --- /dev/null +++ b/src/main/java/com/xujie/sys/modules/ecss/service/impl/CoDelServiceImpl.java @@ -0,0 +1,235 @@ +package com.xujie.sys.modules.ecss.service.impl; + +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.xujie.sys.common.utils.DateUtils; +import com.xujie.sys.common.utils.PageUtils; +import com.xujie.sys.modules.ecss.data.EcssCoDelNotifyData; +import com.xujie.sys.modules.ecss.data.EcssCoDelNotifyHeaderData; +import com.xujie.sys.modules.ecss.entity.EcssCoDelNotify; +import com.xujie.sys.modules.ecss.entity.EcssCoDelNotifyDetail; +import com.xujie.sys.modules.ecss.entity.EcssCoDelNotifyHeader; +import com.xujie.sys.modules.ecss.mapper.CoDelMapper; +import com.xujie.sys.modules.ecss.service.CoDelService; +import com.xujie.sys.modules.orderIssure.entity.PartData; +import com.xujie.sys.modules.orderIssure.entity.SOIssueNotifyHeaderData; +import com.xujie.sys.modules.part.entity.PartInformationEntity; +import com.xujie.sys.modules.part.entity.RoutingComponentEntity; +import com.xujie.sys.modules.part.vo.BomComponentVo; +import com.xujie.sys.modules.pms.mapper.EamMapper; +import com.xujie.sys.modules.sys.entity.SysUserEntity; +import org.apache.poi.ss.usermodel.Cell; +import org.apache.poi.ss.usermodel.CellType; +import org.apache.poi.ss.usermodel.DataFormatter; +import org.apache.poi.xssf.usermodel.XSSFRow; +import org.apache.poi.xssf.usermodel.XSSFSheet; +import org.apache.poi.xssf.usermodel.XSSFWorkbook; +import org.apache.shiro.SecurityUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; +import org.springframework.web.multipart.MultipartFile; + +import java.io.InputStream; +import java.math.BigDecimal; +import java.math.RoundingMode; +import java.text.ParseException; +import java.util.ArrayList; +import java.util.Date; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; + +@Service +public class CoDelServiceImpl implements CoDelService { + @Autowired + private CoDelMapper coDelMapper; + @Autowired + private EamMapper eamMapper; + @Override + public PageUtils searchEcssCoDelNotifyHeader(EcssCoDelNotifyHeaderData data){ + IPage resultList = coDelMapper.searchEcssCoDelNotifyHeader(new Page(data.getPage(), data.getLimit()), data); + return new PageUtils(resultList); + + } + + @Override + @Transactional + public void saveEcssCoDelNotifyByExcel(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); + // 读取工作表 + XSSFSheet sheet = workbook.getSheetAt(0); + // 获取行数 + int rows = sheet.getPhysicalNumberOfRows(); + // 遍历每一行(从第二行开始) + for (int j = 1; j < rows; j++) { + // 创建对象 + EcssCoDelNotifyData task = new EcssCoDelNotifyData(); + // 获得该行 + XSSFRow row = sheet.getRow(j); + if (row.getCell(0) == null) { + throw new RuntimeException("第"+j+"行的Ready Date不能为空!"); + } + if (row.getCell(3) == null) { + throw new RuntimeException("第"+j+"行的SalesOrder不能为空!"); + } + if (row.getCell(4) == null) { + throw new RuntimeException("第"+j+"行的销售订单行号不能为空!"); + } + if (row.getCell(10) == null) { + throw new RuntimeException("第"+j+"行的PN不能为空!"); + } + if (row.getCell(12) == null) { + throw new RuntimeException("第"+j+"行的Qty不能为空!"); + } + + // 为对象赋值 + task.setSite(site); // site + task.setBuNo(inData.getBuNo()); // bu + Date readDate; + try { + String date=getStringCellValue(row, 0); + readDate= DateUtils.getDateByParten(date,"yyyy-MM-dd"); + }catch (ParseException e){ + throw new RuntimeException("第"+j+"行的ReadyDate格式有误!"); + } + task.setReadyDate(readDate); + task.setCustomerName(getStringCellValue(row, 1)); + task.setCustomerPO(getStringCellValue(row, 2)); + task.setSalesOrder(getStringCellValue(row, 3)); + task.setSalesOrderItemNo(getIntegerCellValue(row,4)); + task.setUpc(getStringCellValue(row,5)); + task.setLine(getStringCellValue(row,6)); + task.setVersion(getStringCellValue(row,7)); + task.setStatus(getStringCellValue(row,8)); + task.setFamily(getStringCellValue(row,9)); + task.setPartNo(getStringCellValue(row,10)); + task.setPartDescription(getStringCellValue(row,11)); + task.setQty(getNumericCellValueOrDefault(row,12)); + task.setLt(getNumericCellValueOrDefault(row,13)); + task.setCmcInvoice(getStringCellValue(row,14)); + task.setCmcComment(getStringCellValue(row,15)); + task.setDestination(getStringCellValue(row,16)); + task.setSaleType(getStringCellValue(row,17)); + task.setAwbBl(getStringCellValue(row,18)); + task.setShippingNumber(getStringCellValue(row,19)); + task.setShippingMode(getStringCellValue(row,20)); + task.setForwarderInfo(getStringCellValue(row,21)); + task.setCurrency(getStringCellValue(row,22)); + task.setTp(getNumericCellValueOrDefault(row,23)); + task.setTtlAmount(getNumericCellValueOrDefault(row,24)); + task.setSumPrice(getNumericCellValueOrDefault(row,25)); + task.setSo(getStringCellValue(row,26)); + task.setRemark(getStringCellValue(row,27)); + task.setErpFlag("N"); + task.setNotifyStatus("已计划"); + List checkPart=coDelMapper.checkPart(task.getSite(),task.getPartNo()); + if(checkPart.size()==0){ + throw new RuntimeException("导入失败:物料:"+task.getPartNo()+"在当前工厂不存在!"); + } + excelList.add(task); + } + + } catch (Exception e) { + throw new RuntimeException("导入失败:"+e.getMessage()); + } + // 使用 groupingBy 进行分组 + Map> groupedByReadyDateAndCmcInvoice = excelList.stream() + .collect(Collectors.groupingBy(data -> data.getReadyDate() + "-" + data.getCmcInvoice())); + + // 每个分组创建一个销售发货单 + groupedByReadyDateAndCmcInvoice.forEach((key, list) -> { + String transNo; + //测试下有没有发票号已经录入并且转化了 + List checkIfHasHeader=coDelMapper.checkIfHasHeader(list.get(0).getCmcInvoice()); + if(checkIfHasHeader.size()==0){ + EcssCoDelNotifyHeader headerList=new EcssCoDelNotifyHeader(); + coDelMapper.updateTransNo(list.get(0).getSite(),"EC"); + transNo=coDelMapper.getTransNo(list.get(0).getSite(),"EC"); + headerList.setDelNo(transNo); + headerList.setSite(list.get(0).getSite()); + headerList.setBuNo(list.get(0).getBuNo()); + headerList.setCustomerName(list.get(0).getCustomerName()); + headerList.setDestination(list.get(0).getDestination()); + headerList.setNotifyStatus(list.get(0).getNotifyStatus()); + headerList.setReadyDate(list.get(0).getReadyDate()); + headerList.setShippingMode(list.get(0).getShippingMode()); + + headerList.setCustomerName(currentUser.getUsername()); + headerList.setCmcInvoice(list.get(0).getCmcInvoice()); + coDelMapper.saveEcssCoDelNotifyHeader(headerList); + }else { + // if("Y".equals(checkIfHasHeader.get(0).getErpFlag())){ + throw new RuntimeException("发票号:"+list.get(0).getCmcInvoice()+"已经生成了发货通知单,请先删除!"); + // } + + } + + for (int i = 0; i < list.size(); i++) { + list.get(i).setDelNo(transNo); + list.get(i).setItemNo(i+1); + } + coDelMapper.batchSaveEcssCoDelNotifyDetail(list); + }); + + } + + private String getStringCellValue(XSSFRow row, int columnIndex) { + Cell cell = row.getCell(columnIndex); + if (cell == null || cell.getCellType() == CellType.BLANK) { + return ""; + } + DataFormatter formatter = new DataFormatter(); + return formatter.formatCellValue(cell); + } + + public static Integer getIntegerCellValue(XSSFRow row, int columnIndex) { + Cell cell = row.getCell(columnIndex); + if (cell == null || cell.getCellType() == CellType.BLANK) { + return -1; + } + DataFormatter formatter = new DataFormatter(); + String cellValueAsString = formatter.formatCellValue(cell); + try { + // 尝试将字符串转换为整数 + return Integer.parseInt(cellValueAsString); + } catch (NumberFormatException e) { + // 如果转换失败,尝试将数字值四舍五入到最接近的整数 + if (cell.getCellType() == CellType.NUMERIC) { + return (int) Math.round(cell.getNumericCellValue()); + } + // 如果单元格既不是数字也不是可解析的字符串,则返回-1 + return -1; + } + } + + private BigDecimal getNumericCellValueOrDefault(XSSFRow row, int columnIndex) { + Cell cell = row.getCell(columnIndex); + if (cell == null || cell.getCellType() == CellType.BLANK) { + return BigDecimal.ZERO; + } + switch (cell.getCellType()) { + case NUMERIC: + BigDecimal value = BigDecimal.valueOf(cell.getNumericCellValue()); + return value.setScale(4, RoundingMode.HALF_UP); // 四舍五入保留四位小数 + case STRING: + try { + BigDecimal stringValue = new BigDecimal(cell.getStringCellValue()); + return stringValue.setScale(4, RoundingMode.HALF_UP); // 四舍五入保留四位小数 + } catch (NumberFormatException e) { + throw new RuntimeException("无效的数值格式: " + cell.getStringCellValue()); + } + default: + throw new RuntimeException("不支持的单元格类型: " + cell.getCellType()); + } + } + +} diff --git a/src/main/resources/mapper/ecss/CoDelMapper.xml b/src/main/resources/mapper/ecss/CoDelMapper.xml new file mode 100644 index 00000000..6868ae49 --- /dev/null +++ b/src/main/resources/mapper/ecss/CoDelMapper.xml @@ -0,0 +1,77 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + EXEC UpdateTransNo #{site}, #{transType} + + + + + insert into ecss_CoDelNotifyHeader(site,bu_no,delNo,ready_date,customer_name,Destination,shipping_mode,erp_flag,notify_status, +remark,createDate,createBy,cmc_invoice) + values(#{site},#{buNo},#{delNo},#{readyDate},#{customerName},#{destination},#{shippingMode},'N',#{notifyStatus},#{remark},GetDate(), + #{createBy},#{cmcInvoice}) + + + insert into ecss_CoDelNotifyDetail (site,bu_no,delNo,item_no,salesOrder,salesOrder_item_no,customerPO,line,version, + status,family,part_no,part_description,qty,lt,cmc_invoice,cmc_comment,saleType, + awb_bl,shipping_number,forwarder_info,currency,tp,ttl_amount,sum_price, + so,upc,remark) + values + + (#{item.site},#{item.buNo},#{item.delNo},#{item.itemNo,jdbcType=INTEGER},#{item.salesOrder},#{item.salesOrderItemNo},#{item.customerPO},#{item.line},#{item.version}, + #{item.status},#{item.family},#{item.partNo},#{item.partDescription},#{item.qty,jdbcType=DECIMAL},#{item.lt,jdbcType=DECIMAL},#{item.cmcInvoice},#{item.cmcComment},#{item.saleType}, + #{item.awbBl},#{item.shippingNumber},#{item.forwarderInfo},#{item.currency},#{item.tp,jdbcType=DECIMAL},#{item.ttlAmount,jdbcType=DECIMAL},#{item.sumPrice,jdbcType=DECIMAL}, + #{item.so},#{item.upc},#{item.remark}) + + + + + \ No newline at end of file