From 8a5c47a1f457f9fc4e6a1a6b36abd9b9e3c2c807 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9B=B9=E9=B9=8F=E9=A3=9E?= Date: Tue, 7 May 2024 16:22:32 +0800 Subject: [PATCH 01/14] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E4=B8=80?= =?UTF-8?q?=E4=B8=AAsql=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mapper/master/BomNewEbomParentMapper.xml | 38 ++++++++++--------- 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/nflg_project_dev/nflg-bom-new/src/main/resources/mapper/master/BomNewEbomParentMapper.xml b/nflg_project_dev/nflg-bom-new/src/main/resources/mapper/master/BomNewEbomParentMapper.xml index e391f8da..eac96296 100644 --- a/nflg_project_dev/nflg-bom-new/src/main/resources/mapper/master/BomNewEbomParentMapper.xml +++ b/nflg_project_dev/nflg-bom-new/src/main/resources/mapper/master/BomNewEbomParentMapper.xml @@ -393,24 +393,26 @@ SELECT *,row_id as bomRowId FROM t_bom_new_ebom_parent - - AND created_by = #{userCode} - - - WHERE status IN (1,3) AND (user_root_is=1 OR root_is_for_wait_review=1) AND created_by=#{userCode} - - - WHERE root_is=1 AND status=2 - - - WHERE root_is=1 AND status=4 - - - AND devise_name=#{query.deviseName} - - - AND created_time BETWEEN #{query.startDate} AND DATE_ADD(#{query.endDate}, INTERVAL 1 DAY) - + + + AND created_by = #{userCode} + + + AND status IN (1,3) AND (user_root_is=1 OR root_is_for_wait_review=1) AND created_by=#{userCode} + + + AND root_is=1 AND status=2 + + + AND root_is=1 AND status=4 + + + AND devise_name=#{query.deviseName} + + + AND created_time BETWEEN #{query.startDate} AND DATE_ADD(#{query.endDate}, INTERVAL 1 DAY) + + order by row_id desc From b2ce1def5a6d2ea222b21d20b4ce0bd0905edcad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9B=B9=E9=B9=8F=E9=A3=9E?= Date: Tue, 7 May 2024 16:36:30 +0800 Subject: [PATCH 02/14] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E4=B8=80?= =?UTF-8?q?=E4=B8=AAsql=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../product/bomnew/mapper/master/BomNewEbomParentMapper.java | 2 +- .../nflg/product/bomnew/service/BomNewEbomParentService.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/mapper/master/BomNewEbomParentMapper.java b/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/mapper/master/BomNewEbomParentMapper.java index 395736e3..fd4efe03 100644 --- a/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/mapper/master/BomNewEbomParentMapper.java +++ b/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/mapper/master/BomNewEbomParentMapper.java @@ -38,7 +38,7 @@ public interface BomNewEbomParentMapper extends BaseMapper formalWorksheet(Page page, @Param("query") BomNewEbomParentQuery query); + Page formalWorksheet(Page page, @Param("query") BomNewEbomParentQuery query, String userCode); Page getUpgradeChangeList(Page page, @Param("query") BomNewEbomParentQuery query); /** diff --git a/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/service/BomNewEbomParentService.java b/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/service/BomNewEbomParentService.java index 7d149143..ea2b49ec 100644 --- a/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/service/BomNewEbomParentService.java +++ b/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/service/BomNewEbomParentService.java @@ -302,7 +302,7 @@ public class BomNewEbomParentService extends ServiceImpl formalWorksheet(BomNewEbomParentQuery query) { - Page result = this.getBaseMapper().formalWorksheet(new Page<>(query.getPage(), query.getPageSize()), query); + Page result = this.getBaseMapper().formalWorksheet(new Page<>(query.getPage(), query.getPageSize()), query, SessionUtil.getUserCode()); if (CollUtil.isNotEmpty(result.getRecords())) { From a60cae3d6ad8811844721f3fcfda391e9a998eab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9B=B9=E9=B9=8F=E9=A3=9E?= Date: Wed, 8 May 2024 09:46:12 +0800 Subject: [PATCH 03/14] =?UTF-8?q?fix:=20=E5=8D=95=E4=BD=8D=E4=B8=8D?= =?UTF-8?q?=E4=B8=80=E8=87=B4=EF=BC=8C=E4=B8=94exceptionTag=E4=B8=BA?= =?UTF-8?q?=E7=A9=BA=E6=88=96=E4=B8=8D=E5=8C=85=E5=90=AB16=E6=97=B6?= =?UTF-8?q?=EF=BC=8C=E8=AE=BE=E7=BD=AE=E5=BC=82=E5=B8=B8=E7=8A=B6=E6=80=81?= =?UTF-8?q?=E4=B8=BA16?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../bomnew/service/domain/EBom/CheckEBomException.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/service/domain/EBom/CheckEBomException.java b/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/service/domain/EBom/CheckEBomException.java index 4ad075c2..19f20661 100644 --- a/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/service/domain/EBom/CheckEBomException.java +++ b/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/service/domain/EBom/CheckEBomException.java @@ -135,8 +135,8 @@ public class CheckEBomException { vo.setExceptionStatus(EBomExceptionStatusEnum.EXCEPT_NO_12.getValue()); } else if (StrUtil.isNotBlank(vo.getNoticeNums()) && EBomExceptionStatusEnum.EXCEPT_NO_11.equalsValue(vo.getExceptionStatus())) { vo.setExceptionStatus(EBomExceptionStatusEnum.OK.getValue()); - } - else if (!StrUtil.equals(vo.getMaterialUnit(), vo.getMaterialOriginalUnit()) && StrUtil.isBlank(vo.getExceptionTag())){ + } else if (!StrUtil.equals(vo.getMaterialUnit(), vo.getMaterialOriginalUnit()) + && (StrUtil.isBlank(vo.getExceptionTag()) || !vo.getExceptionTag().contains("16"))) { vo.setExceptionStatus(EBomExceptionStatusEnum.EXCEPT_NO_16.getValue()); } From a92926857239880310807d0a242f80223c78ed9c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A4=A7=E7=B1=B3?= <470431449@qq.com> Date: Wed, 8 May 2024 14:54:26 +0800 Subject: [PATCH 04/14] =?UTF-8?q?1=E3=80=81=E4=BF=AE=E5=A4=8D=E5=88=9D?= =?UTF-8?q?=E5=A7=8B=E5=8C=96=E5=BC=82=E5=B8=B8=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../product/bomnew/service/domain/EBom/CheckEBomException.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/service/domain/EBom/CheckEBomException.java b/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/service/domain/EBom/CheckEBomException.java index 4ad075c2..0ae3d088 100644 --- a/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/service/domain/EBom/CheckEBomException.java +++ b/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/service/domain/EBom/CheckEBomException.java @@ -215,7 +215,7 @@ public class CheckEBomException { k.setExceptionStatus(EBomExceptionStatusEnum.EXCEPT_NO_14.getValue()); } } - List root = allBomDetail.stream().filter(u -> u.getLevelNumber().compareTo(BigDecimal.ZERO) == 0 && EBomExceptionStatusEnum.OK.equalsValue(u.getExceptionStatus())).collect(Collectors.toList()); + List root = allBomDetail.stream().filter(u -> Objects.nonNull(u.getLevelNumber()) && u.getLevelNumber().compareTo(BigDecimal.ZERO) == 0 && EBomExceptionStatusEnum.OK.equalsValue(u.getExceptionStatus())).collect(Collectors.toList()); root.forEach(k->{ k.setExceptionStatus(EBomExceptionStatusEnum.EXCEPT_NO_14.getValue()); }); From 158dc0db424fd92d82bac13cbb16bf405c81e543 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9B=B9=E9=B9=8F=E9=A3=9E?= Date: Wed, 8 May 2024 15:34:20 +0800 Subject: [PATCH 05/14] =?UTF-8?q?fix:=20ebom=E5=BC=82=E5=B8=B8=E6=A3=80?= =?UTF-8?q?=E6=9F=A5=E9=80=BB=E8=BE=91=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/domain/EBom/CheckEBomException.java | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/service/domain/EBom/CheckEBomException.java b/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/service/domain/EBom/CheckEBomException.java index b7ee4e03..bf870735 100644 --- a/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/service/domain/EBom/CheckEBomException.java +++ b/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/service/domain/EBom/CheckEBomException.java @@ -113,10 +113,10 @@ public class CheckEBomException { && unCheckExcept.contains(vo.getExceptionStatus())) { continue; } - BaseMaterialVO mainVO = materialBaseInfo.stream() - .filter(u -> StrUtil.equals(u.getMaterialNo(), vo.getMaterialNo())) - .findFirst() - .orElse(null); + // BaseMaterialVO mainVO = materialBaseInfo.stream() + // .filter(u -> StrUtil.equals(u.getMaterialNo(), vo.getMaterialNo())) + // .findFirst() + // .orElse(null); vo.setExceptionStatus(EBomExceptionStatusEnum.OK.getValue()); // } if (StrUtil.isNotBlank(vo.getMaterialNo()) @@ -130,8 +130,9 @@ public class CheckEBomException { } else if (StrUtil.isBlank(vo.getProjectType()) && !Objects.equals(vo.getRootIs(), 1) && !Objects.equals(vo.getUserRootIs(), 1) && !Objects.equals(vo.getRootIsForWaitReview(), 1)) { vo.setExceptionStatus(EBomExceptionStatusEnum.EXCEPT_NO_8.getValue()); - } else if ((StrUtil.equals("KG", StringUtil.toUpperCase(vo.getMaterialUnit())) && !StrUtil.equals(StringUtil.toUpperCase(vo.getMaterialUnit()), "PC")) - || (!Objects.isNull(mainVO) && !StrUtil.equals(vo.getMaterialUnit(), mainVO.getMaterialUnit()))) { + } else if ((!StrUtil.equals("KG", StringUtil.toUpperCase(vo.getMaterialUnit())) && !StrUtil.equals(StringUtil.toUpperCase(vo.getMaterialUnit()), "PC")) + //|| (!Objects.isNull(mainVO) && !StrUtil.equals(vo.getMaterialUnit(), mainVO.getMaterialUnit()))) { + && (StrUtil.isBlank(vo.getExceptionTag()) || (!vo.getExceptionTag().contains("16")) && !vo.getExceptionTag().contains("12"))) { vo.setExceptionStatus(EBomExceptionStatusEnum.EXCEPT_NO_12.getValue()); } else if (StrUtil.isNotBlank(vo.getNoticeNums()) && EBomExceptionStatusEnum.EXCEPT_NO_11.equalsValue(vo.getExceptionStatus())) { vo.setExceptionStatus(EBomExceptionStatusEnum.OK.getValue()); From 70dd9d0211e3686545b0f70e343109e17b8329be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9B=B9=E9=B9=8F=E9=A3=9E?= Date: Wed, 8 May 2024 15:35:15 +0800 Subject: [PATCH 06/14] =?UTF-8?q?feat:=20ebom=E4=BB=8Eexcel=E5=AF=BC?= =?UTF-8?q?=E5=85=A5=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mapper/master/BomNewEbomChildMapper.java | 2 + .../product/bomnew/pojo/dto/EbomExcelDTO.java | 73 +++++ .../bomnew/service/EBomImportService.java | 286 ++++++++++++++++++ .../mapper/master/BomNewEbomChildMapper.xml | 12 + 4 files changed, 373 insertions(+) create mode 100644 nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/pojo/dto/EbomExcelDTO.java create mode 100644 nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/service/EBomImportService.java diff --git a/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/mapper/master/BomNewEbomChildMapper.java b/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/mapper/master/BomNewEbomChildMapper.java index a723b7d6..fca209eb 100644 --- a/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/mapper/master/BomNewEbomChildMapper.java +++ b/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/mapper/master/BomNewEbomChildMapper.java @@ -24,4 +24,6 @@ public interface BomNewEbomChildMapper extends BaseMapper void updateEBomMaterialUse(); List getChildMaxExceptionState(@Param("bomRowIds") List bomRowIds); + + Integer shouldSetRootIs(String materialNo); } diff --git a/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/pojo/dto/EbomExcelDTO.java b/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/pojo/dto/EbomExcelDTO.java new file mode 100644 index 00000000..35eb6479 --- /dev/null +++ b/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/pojo/dto/EbomExcelDTO.java @@ -0,0 +1,73 @@ +package com.nflg.product.bomnew.pojo.dto; + +import lombok.Data; +import org.ttzero.excel.annotation.ExcelColumn; + +import java.math.BigDecimal; + +/** + * @author 曹鹏飞 + * @date 2024/5/8 09:07:23 + */ +@Data +public class EbomExcelDTO extends BaseImportExcelDTO { + + /** + * 父级物料编号 + */ + @ExcelColumn("抬头物料") + private String parentMaterialNo; + + /** + * 父级物料描述 + */ + @ExcelColumn("物料描述") + private String parentMaterialDesc; + + /** + * 项目类别 + */ + @ExcelColumn("项目类别") + private String projectType; + + /** + * 物料编号 + */ + @ExcelColumn("项目物料") + private String materialNo; + + /** + * 物料描述 + */ + @ExcelColumn("项目物料描述") + private String materialDesc; + + /** + * 数量 + */ + @ExcelColumn("数量") + private BigDecimal num; + + /** + * 物料单位 + */ + @ExcelColumn("单位") + private String unit; + + /** + * 排序顺序 + */ + @ExcelColumn("排序顺序") + private String orderNum; + + /** + * 备注 + */ + @ExcelColumn("备注") + private String remark; + + /** + * 图号 + */ + private String drawingNo; +} diff --git a/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/service/EBomImportService.java b/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/service/EBomImportService.java new file mode 100644 index 00000000..7d56ecaf --- /dev/null +++ b/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/service/EBomImportService.java @@ -0,0 +1,286 @@ +package com.nflg.product.bomnew.service; + +import cn.hutool.core.convert.Convert; +import cn.hutool.core.util.StrUtil; +import com.alibaba.fastjson.JSON; +import com.baomidou.mybatisplus.core.toolkit.IdWorker; +import com.nflg.product.base.core.conmon.util.SessionUtil; +import com.nflg.product.bomnew.constant.*; +import com.nflg.product.bomnew.pojo.dto.BaseImportExcelDTO; +import com.nflg.product.bomnew.pojo.dto.EbomExcelDTO; +import com.nflg.product.bomnew.pojo.entity.BomNewEbomChildEntity; +import com.nflg.product.bomnew.pojo.entity.BomNewEbomParentEntity; +import com.nflg.product.bomnew.pojo.vo.BaseMaterialVO; +import com.nflg.product.bomnew.pojo.vo.OperationErrorMsgVO; +import com.nflg.product.bomnew.util.BomUtil; +import com.nflg.product.bomnew.util.EecExcelUtil; +import com.nflg.product.bomnew.util.StringUtil; +import com.nflg.product.bomnew.util.VUtils; +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.tuple.Pair; +import org.springframework.stereotype.Service; +import org.springframework.web.multipart.MultipartFile; + +import javax.annotation.Resource; +import java.io.IOException; +import java.math.BigDecimal; +import java.time.LocalDateTime; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.Objects; +import java.util.stream.Collectors; + +/** + * @author 曹鹏飞 + * @date 2024/5/8 09:02:12 + */ +@Service +@Slf4j +public class EBomImportService { + + public static final ThreadLocal rowNum = new ThreadLocal<>(); + + public static final ThreadLocal> excelContextTL = new ThreadLocal<>(); + + @Resource + private MaterialMainService materialMainService; + + @Resource + private UserRoleService userRoleService; + + @Resource + private BomNewEbomParentService bomNewEbomParentService; + + @Resource + private BomNewEbomChildService bomNewEbomChildService; + + public List importBom(MultipartFile file) throws IOException { + try { + rowNum.set(1); + excelContextTL.set(new ArrayList<>()); + EecExcelUtil.handlerExcel(file.getInputStream(), EbomExcelDTO.class, this::handlerExcelRow); + + List datas = excelContextTL.get(); + + List errorMsg = checkExcel(datas); + if (!errorMsg.isEmpty()) { + return errorMsg; + } + + Pair, List> pcs = convertToBom(datas); + VUtils.isTure(pcs.getLeft().stream().filter(p -> p.getRootIs() == 1).count() > 1) + .throwMessage("文件中存在多个根节点"); + //VUtils.isTure(checkInconsistentData(pcs.getLeft().get(0), pcs.getLeft(), pcs.getRight())) + // .throwMessage("导入的数据已存在,请勿重复导入"); + + //save(pcs.getLeft(), pcs.getRight()); + + return Collections.emptyList(); + } finally { + excelContextTL.remove(); + } + } + + private void handlerExcelRow(EbomExcelDTO dQbomExcelVO) { + rowNum.set(rowNum.get() + 1); + log.debug("ebom导入excel,第{}行,处理前:{}", rowNum.get(), JSON.toJSONString(dQbomExcelVO)); + + dQbomExcelVO.setRowNum(rowNum.get()); + + excelContextTL.get().add(dQbomExcelVO); + } + + private List checkExcel(List datas) { + List errorMsg = new ArrayList<>(); + + List numError = datas.stream().filter(u -> StrUtil.isBlank(u.getParentMaterialNo())) + .map(BaseImportExcelDTO::getRowNum) + .collect(Collectors.toList()); + if (!numError.isEmpty()) { + errorMsg.addAll(numError.stream().map(n -> OperationErrorMsgVO.create("第" + n + "行", "抬头物料为空")) + .collect(Collectors.toList()) + ); + } + + numError = datas.stream().filter(u -> StrUtil.isBlank(u.getMaterialNo())) + .map(BaseImportExcelDTO::getRowNum) + .collect(Collectors.toList()); + if (!numError.isEmpty()) { + errorMsg.addAll(numError.stream().map(n -> OperationErrorMsgVO.create("第" + n + "行", "项目物料为空")) + .collect(Collectors.toList()) + ); + } + + numError = datas.stream().filter(u -> Objects.isNull(u.getNum()) || BigDecimal.ZERO.compareTo(u.getNum()) >= 0) + .map(BaseImportExcelDTO::getRowNum) + .collect(Collectors.toList()); + + if (!numError.isEmpty()) { + errorMsg.addAll(numError.stream().map(n -> OperationErrorMsgVO.create("第" + n + "行", "数量不正确")) + .collect(Collectors.toList()) + ); + } + + numError = datas.stream().filter(u -> StringUtil.CountForMysql(u.getRemark()) > 200) + .map(BaseImportExcelDTO::getRowNum) + .collect(Collectors.toList()); + if (!numError.isEmpty()) { + errorMsg.addAll(numError.stream().map(n -> OperationErrorMsgVO.create("第" + n + "行", "备注超出200字")) + .collect(Collectors.toList()) + ); + } + + return errorMsg; + } + + private Pair, List> convertToBom(List datas) { + List parents = new ArrayList<>(); + List children = new ArrayList<>(); + + List materialNos = datas.stream().map(EbomExcelDTO::getMaterialNo).collect(Collectors.toList()); + materialNos.addAll(datas.stream().map(EbomExcelDTO::getParentMaterialNo).collect(Collectors.toList())); + materialNos = materialNos.stream().distinct().collect(Collectors.toList()); + List materialBaseInfos = materialMainService.getMaterialBaseInfo(materialNos); + + BomNewEbomParentEntity parent; + for (EbomExcelDTO data : datas) { + parent = parents.stream().filter(p -> p.getMaterialNo().equals(data.getParentMaterialNo())) + .findFirst() + .orElse(null); + if (Objects.isNull(parent)) { + parents.add(buildRoot(materialBaseInfos, data.getParentMaterialNo(), data.getParentMaterialDesc())); + } + + parent = parents.stream().filter(p -> p.getMaterialNo().equals(data.getMaterialNo())) + .findFirst() + .orElse(null); + if (Objects.isNull(parent)) { + parent = buildParent(materialBaseInfos, data); + children.add(buildChild(materialBaseInfos, parent, data.getProjectType())); + parents.add(parent); + } + } + return Pair.of(parents, children); + } + + private BomNewEbomChildEntity buildChild(List materialBaseInfos, BomNewEbomParentEntity parent, String projectType) { + BomNewEbomChildEntity child = Convert.convert(BomNewEbomChildEntity.class, parent); + parent.setOrderNumber(""); + child.setRowId(IdWorker.getId()); + child.setParentRowId(parent.getRowId()); + child.setProjectType(projectType); + child.setProjectTypeInputType(ProjectTypeInputTypeEnum.MANUAL_INPUT.getValue()); + child.setIdentityNo(child.getParentRowId() + "_" + child.getRowId()); + BaseMaterialVO vo = materialBaseInfos.stream() + .filter(m -> m.getMaterialNo().equals(child.getMaterialNo())) + .findFirst() + .orElse(null); + if (!Objects.isNull(vo)) { + child.setMaterialCategoryCode(vo.getMaterialCategoryCode()); + } + return child; + } + + private BomNewEbomParentEntity buildParent(List materialBaseInfos, EbomExcelDTO data) { + BomNewEbomParentEntity parent = new BomNewEbomParentEntity(); + parent.setRowId(IdWorker.getId()); + + BaseMaterialVO vo = materialBaseInfos.stream() + .filter(m -> m.getMaterialNo().equals(data.getMaterialNo())) + .findFirst() + .orElse(null); + if (!Objects.isNull(vo)) { + parent.setDrawingNo(vo.getDrawingNo()); + parent.setUnitWeight(vo.getMaterialWeight()); + } + + parent.setMaterialNo(data.getMaterialNo()); + parent.setMaterialDesc(data.getMaterialDesc()); + parent.setMaterialTexture(""); + parent.setMaterialUnit(data.getUnit()); + parent.setNum(data.getNum()); + parent.setTotalWeight(BomUtil.calculateTotalWeight(parent.getNum(), parent.getUnitWeight())); + //parent.setCurrentVersion(OriginalConstant.DEFAULT_BOM_VERSION); + parent.setUserRootIs(0); + parent.setRootIs(0); + if (userRoleService.technician()) { + //工艺人员 + parent.setStatus(EBomStatusEnum.CHECKED.getValue()); + parent.setCreatedJob(UserJobEnum.ENGINEER.getValue()); + parent.setAuditUserName(SessionUtil.getUserCode()); + parent.setAuditTime(LocalDateTime.now()); + } else { + //设计人员 + parent.setStatus(EBomStatusEnum.WAIT_CHECK.getValue()); + parent.setCreatedJob(UserJobEnum.DESIGNER.getValue()); + parent.setRootIsForWaitReview(1); + } + parent.setDeviseName(SessionUtil.getRealName()); + parent.setDeviseUserCode(SessionUtil.getUserCode()); + parent.setLastVersionIs(1); + parent.setEditStatus(EbomEditStatusEnum.HANDLER_CREATED.getValue()); + parent.setExceptionStatus(EBomExceptionStatusEnum.INIT.getValue()); + parent.setCreatedBy(SessionUtil.getUserCode()); + parent.setRemark(data.getRemark()); + parent.setOrderNumber(data.getOrderNum()); + parent.setDeptName(SessionUtil.getDepartName()); + parent.setSource(EBomSourceEnum.FROM_EXCE.getValue()); + return parent; + } + + /** + * 构建顶级 + * @param materialBaseInfos 主物料数据 + * @param materialNo 物料编号 + * @param materialDesc 物料描述 + * @return 父级 + */ + private BomNewEbomParentEntity buildRoot(List materialBaseInfos, String materialNo, String materialDesc) { + BomNewEbomParentEntity parent = new BomNewEbomParentEntity(); + parent.setRowId(IdWorker.getId()); + + BaseMaterialVO vo = materialBaseInfos.stream() + .filter(m -> m.getMaterialNo().equals(materialNo)) + .findFirst() + .orElse(null); + if (!Objects.isNull(vo)) { + parent.setDrawingNo(vo.getDrawingNo()); + parent.setUnitWeight(vo.getMaterialWeight()); + } + + parent.setMaterialNo(materialNo); + parent.setMaterialDesc(materialDesc); + parent.setMaterialTexture(""); + parent.setMaterialUnit("PC"); + //parent.setUnitWeight(BigDecimal.ZERO); + parent.setNum(BigDecimal.ONE); + //parent.setTotalWeight(BomUtil.calculateTotalWeight(data.getNum(), data.getUnitWeight())); + //parent.setCurrentVersion(OriginalConstant.DEFAULT_BOM_VERSION); + parent.setUserRootIs(1); + if (userRoleService.technician()) { + //工艺人员 + parent.setStatus(EBomStatusEnum.CHECKED.getValue()); + parent.setCreatedJob(UserJobEnum.ENGINEER.getValue()); + parent.setAuditUserName(SessionUtil.getUserCode()); + parent.setAuditTime(LocalDateTime.now()); + parent.setRootIs(bomNewEbomChildService.getBaseMapper().shouldSetRootIs(materialNo)); + } else { + //设计人员 + parent.setRootIs(1); + parent.setStatus(EBomStatusEnum.WAIT_CHECK.getValue()); + parent.setCreatedJob(UserJobEnum.DESIGNER.getValue()); + parent.setRootIsForWaitReview(1); + } + parent.setDeviseName(SessionUtil.getRealName()); + parent.setDeviseUserCode(SessionUtil.getUserCode()); + parent.setLastVersionIs(1); + parent.setEditStatus(EbomEditStatusEnum.HANDLER_CREATED.getValue()); + parent.setExceptionStatus(EBomExceptionStatusEnum.INIT.getValue()); + parent.setCreatedBy(SessionUtil.getUserCode()); + parent.setRemark(""); + parent.setDeptName(SessionUtil.getDepartName()); + parent.setSource(EBomSourceEnum.FROM_EXCE.getValue()); + return parent; + } +} diff --git a/nflg_project_dev/nflg-bom-new/src/main/resources/mapper/master/BomNewEbomChildMapper.xml b/nflg_project_dev/nflg-bom-new/src/main/resources/mapper/master/BomNewEbomChildMapper.xml index 65e5b549..df5dd0ec 100644 --- a/nflg_project_dev/nflg-bom-new/src/main/resources/mapper/master/BomNewEbomChildMapper.xml +++ b/nflg_project_dev/nflg-bom-new/src/main/resources/mapper/master/BomNewEbomChildMapper.xml @@ -73,4 +73,16 @@ group by parent_row_id + + From d88a87c3e30b433ebe77b37acfe78c6c55250f88 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9B=B9=E9=B9=8F=E9=A3=9E?= Date: Wed, 8 May 2024 15:57:19 +0800 Subject: [PATCH 07/14] =?UTF-8?q?Revert=20"feat:=20ebom=E4=BB=8Eexcel?= =?UTF-8?q?=E5=AF=BC=E5=85=A5=E6=95=B0=E6=8D=AE"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit 70dd9d0211e3686545b0f70e343109e17b8329be. --- .../mapper/master/BomNewEbomChildMapper.java | 2 - .../product/bomnew/pojo/dto/EbomExcelDTO.java | 73 ----- .../bomnew/service/EBomImportService.java | 286 ------------------ .../mapper/master/BomNewEbomChildMapper.xml | 12 - 4 files changed, 373 deletions(-) delete mode 100644 nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/pojo/dto/EbomExcelDTO.java delete mode 100644 nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/service/EBomImportService.java diff --git a/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/mapper/master/BomNewEbomChildMapper.java b/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/mapper/master/BomNewEbomChildMapper.java index fca209eb..a723b7d6 100644 --- a/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/mapper/master/BomNewEbomChildMapper.java +++ b/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/mapper/master/BomNewEbomChildMapper.java @@ -24,6 +24,4 @@ public interface BomNewEbomChildMapper extends BaseMapper void updateEBomMaterialUse(); List getChildMaxExceptionState(@Param("bomRowIds") List bomRowIds); - - Integer shouldSetRootIs(String materialNo); } diff --git a/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/pojo/dto/EbomExcelDTO.java b/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/pojo/dto/EbomExcelDTO.java deleted file mode 100644 index 35eb6479..00000000 --- a/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/pojo/dto/EbomExcelDTO.java +++ /dev/null @@ -1,73 +0,0 @@ -package com.nflg.product.bomnew.pojo.dto; - -import lombok.Data; -import org.ttzero.excel.annotation.ExcelColumn; - -import java.math.BigDecimal; - -/** - * @author 曹鹏飞 - * @date 2024/5/8 09:07:23 - */ -@Data -public class EbomExcelDTO extends BaseImportExcelDTO { - - /** - * 父级物料编号 - */ - @ExcelColumn("抬头物料") - private String parentMaterialNo; - - /** - * 父级物料描述 - */ - @ExcelColumn("物料描述") - private String parentMaterialDesc; - - /** - * 项目类别 - */ - @ExcelColumn("项目类别") - private String projectType; - - /** - * 物料编号 - */ - @ExcelColumn("项目物料") - private String materialNo; - - /** - * 物料描述 - */ - @ExcelColumn("项目物料描述") - private String materialDesc; - - /** - * 数量 - */ - @ExcelColumn("数量") - private BigDecimal num; - - /** - * 物料单位 - */ - @ExcelColumn("单位") - private String unit; - - /** - * 排序顺序 - */ - @ExcelColumn("排序顺序") - private String orderNum; - - /** - * 备注 - */ - @ExcelColumn("备注") - private String remark; - - /** - * 图号 - */ - private String drawingNo; -} diff --git a/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/service/EBomImportService.java b/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/service/EBomImportService.java deleted file mode 100644 index 7d56ecaf..00000000 --- a/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/service/EBomImportService.java +++ /dev/null @@ -1,286 +0,0 @@ -package com.nflg.product.bomnew.service; - -import cn.hutool.core.convert.Convert; -import cn.hutool.core.util.StrUtil; -import com.alibaba.fastjson.JSON; -import com.baomidou.mybatisplus.core.toolkit.IdWorker; -import com.nflg.product.base.core.conmon.util.SessionUtil; -import com.nflg.product.bomnew.constant.*; -import com.nflg.product.bomnew.pojo.dto.BaseImportExcelDTO; -import com.nflg.product.bomnew.pojo.dto.EbomExcelDTO; -import com.nflg.product.bomnew.pojo.entity.BomNewEbomChildEntity; -import com.nflg.product.bomnew.pojo.entity.BomNewEbomParentEntity; -import com.nflg.product.bomnew.pojo.vo.BaseMaterialVO; -import com.nflg.product.bomnew.pojo.vo.OperationErrorMsgVO; -import com.nflg.product.bomnew.util.BomUtil; -import com.nflg.product.bomnew.util.EecExcelUtil; -import com.nflg.product.bomnew.util.StringUtil; -import com.nflg.product.bomnew.util.VUtils; -import lombok.extern.slf4j.Slf4j; -import org.apache.commons.lang3.tuple.Pair; -import org.springframework.stereotype.Service; -import org.springframework.web.multipart.MultipartFile; - -import javax.annotation.Resource; -import java.io.IOException; -import java.math.BigDecimal; -import java.time.LocalDateTime; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import java.util.Objects; -import java.util.stream.Collectors; - -/** - * @author 曹鹏飞 - * @date 2024/5/8 09:02:12 - */ -@Service -@Slf4j -public class EBomImportService { - - public static final ThreadLocal rowNum = new ThreadLocal<>(); - - public static final ThreadLocal> excelContextTL = new ThreadLocal<>(); - - @Resource - private MaterialMainService materialMainService; - - @Resource - private UserRoleService userRoleService; - - @Resource - private BomNewEbomParentService bomNewEbomParentService; - - @Resource - private BomNewEbomChildService bomNewEbomChildService; - - public List importBom(MultipartFile file) throws IOException { - try { - rowNum.set(1); - excelContextTL.set(new ArrayList<>()); - EecExcelUtil.handlerExcel(file.getInputStream(), EbomExcelDTO.class, this::handlerExcelRow); - - List datas = excelContextTL.get(); - - List errorMsg = checkExcel(datas); - if (!errorMsg.isEmpty()) { - return errorMsg; - } - - Pair, List> pcs = convertToBom(datas); - VUtils.isTure(pcs.getLeft().stream().filter(p -> p.getRootIs() == 1).count() > 1) - .throwMessage("文件中存在多个根节点"); - //VUtils.isTure(checkInconsistentData(pcs.getLeft().get(0), pcs.getLeft(), pcs.getRight())) - // .throwMessage("导入的数据已存在,请勿重复导入"); - - //save(pcs.getLeft(), pcs.getRight()); - - return Collections.emptyList(); - } finally { - excelContextTL.remove(); - } - } - - private void handlerExcelRow(EbomExcelDTO dQbomExcelVO) { - rowNum.set(rowNum.get() + 1); - log.debug("ebom导入excel,第{}行,处理前:{}", rowNum.get(), JSON.toJSONString(dQbomExcelVO)); - - dQbomExcelVO.setRowNum(rowNum.get()); - - excelContextTL.get().add(dQbomExcelVO); - } - - private List checkExcel(List datas) { - List errorMsg = new ArrayList<>(); - - List numError = datas.stream().filter(u -> StrUtil.isBlank(u.getParentMaterialNo())) - .map(BaseImportExcelDTO::getRowNum) - .collect(Collectors.toList()); - if (!numError.isEmpty()) { - errorMsg.addAll(numError.stream().map(n -> OperationErrorMsgVO.create("第" + n + "行", "抬头物料为空")) - .collect(Collectors.toList()) - ); - } - - numError = datas.stream().filter(u -> StrUtil.isBlank(u.getMaterialNo())) - .map(BaseImportExcelDTO::getRowNum) - .collect(Collectors.toList()); - if (!numError.isEmpty()) { - errorMsg.addAll(numError.stream().map(n -> OperationErrorMsgVO.create("第" + n + "行", "项目物料为空")) - .collect(Collectors.toList()) - ); - } - - numError = datas.stream().filter(u -> Objects.isNull(u.getNum()) || BigDecimal.ZERO.compareTo(u.getNum()) >= 0) - .map(BaseImportExcelDTO::getRowNum) - .collect(Collectors.toList()); - - if (!numError.isEmpty()) { - errorMsg.addAll(numError.stream().map(n -> OperationErrorMsgVO.create("第" + n + "行", "数量不正确")) - .collect(Collectors.toList()) - ); - } - - numError = datas.stream().filter(u -> StringUtil.CountForMysql(u.getRemark()) > 200) - .map(BaseImportExcelDTO::getRowNum) - .collect(Collectors.toList()); - if (!numError.isEmpty()) { - errorMsg.addAll(numError.stream().map(n -> OperationErrorMsgVO.create("第" + n + "行", "备注超出200字")) - .collect(Collectors.toList()) - ); - } - - return errorMsg; - } - - private Pair, List> convertToBom(List datas) { - List parents = new ArrayList<>(); - List children = new ArrayList<>(); - - List materialNos = datas.stream().map(EbomExcelDTO::getMaterialNo).collect(Collectors.toList()); - materialNos.addAll(datas.stream().map(EbomExcelDTO::getParentMaterialNo).collect(Collectors.toList())); - materialNos = materialNos.stream().distinct().collect(Collectors.toList()); - List materialBaseInfos = materialMainService.getMaterialBaseInfo(materialNos); - - BomNewEbomParentEntity parent; - for (EbomExcelDTO data : datas) { - parent = parents.stream().filter(p -> p.getMaterialNo().equals(data.getParentMaterialNo())) - .findFirst() - .orElse(null); - if (Objects.isNull(parent)) { - parents.add(buildRoot(materialBaseInfos, data.getParentMaterialNo(), data.getParentMaterialDesc())); - } - - parent = parents.stream().filter(p -> p.getMaterialNo().equals(data.getMaterialNo())) - .findFirst() - .orElse(null); - if (Objects.isNull(parent)) { - parent = buildParent(materialBaseInfos, data); - children.add(buildChild(materialBaseInfos, parent, data.getProjectType())); - parents.add(parent); - } - } - return Pair.of(parents, children); - } - - private BomNewEbomChildEntity buildChild(List materialBaseInfos, BomNewEbomParentEntity parent, String projectType) { - BomNewEbomChildEntity child = Convert.convert(BomNewEbomChildEntity.class, parent); - parent.setOrderNumber(""); - child.setRowId(IdWorker.getId()); - child.setParentRowId(parent.getRowId()); - child.setProjectType(projectType); - child.setProjectTypeInputType(ProjectTypeInputTypeEnum.MANUAL_INPUT.getValue()); - child.setIdentityNo(child.getParentRowId() + "_" + child.getRowId()); - BaseMaterialVO vo = materialBaseInfos.stream() - .filter(m -> m.getMaterialNo().equals(child.getMaterialNo())) - .findFirst() - .orElse(null); - if (!Objects.isNull(vo)) { - child.setMaterialCategoryCode(vo.getMaterialCategoryCode()); - } - return child; - } - - private BomNewEbomParentEntity buildParent(List materialBaseInfos, EbomExcelDTO data) { - BomNewEbomParentEntity parent = new BomNewEbomParentEntity(); - parent.setRowId(IdWorker.getId()); - - BaseMaterialVO vo = materialBaseInfos.stream() - .filter(m -> m.getMaterialNo().equals(data.getMaterialNo())) - .findFirst() - .orElse(null); - if (!Objects.isNull(vo)) { - parent.setDrawingNo(vo.getDrawingNo()); - parent.setUnitWeight(vo.getMaterialWeight()); - } - - parent.setMaterialNo(data.getMaterialNo()); - parent.setMaterialDesc(data.getMaterialDesc()); - parent.setMaterialTexture(""); - parent.setMaterialUnit(data.getUnit()); - parent.setNum(data.getNum()); - parent.setTotalWeight(BomUtil.calculateTotalWeight(parent.getNum(), parent.getUnitWeight())); - //parent.setCurrentVersion(OriginalConstant.DEFAULT_BOM_VERSION); - parent.setUserRootIs(0); - parent.setRootIs(0); - if (userRoleService.technician()) { - //工艺人员 - parent.setStatus(EBomStatusEnum.CHECKED.getValue()); - parent.setCreatedJob(UserJobEnum.ENGINEER.getValue()); - parent.setAuditUserName(SessionUtil.getUserCode()); - parent.setAuditTime(LocalDateTime.now()); - } else { - //设计人员 - parent.setStatus(EBomStatusEnum.WAIT_CHECK.getValue()); - parent.setCreatedJob(UserJobEnum.DESIGNER.getValue()); - parent.setRootIsForWaitReview(1); - } - parent.setDeviseName(SessionUtil.getRealName()); - parent.setDeviseUserCode(SessionUtil.getUserCode()); - parent.setLastVersionIs(1); - parent.setEditStatus(EbomEditStatusEnum.HANDLER_CREATED.getValue()); - parent.setExceptionStatus(EBomExceptionStatusEnum.INIT.getValue()); - parent.setCreatedBy(SessionUtil.getUserCode()); - parent.setRemark(data.getRemark()); - parent.setOrderNumber(data.getOrderNum()); - parent.setDeptName(SessionUtil.getDepartName()); - parent.setSource(EBomSourceEnum.FROM_EXCE.getValue()); - return parent; - } - - /** - * 构建顶级 - * @param materialBaseInfos 主物料数据 - * @param materialNo 物料编号 - * @param materialDesc 物料描述 - * @return 父级 - */ - private BomNewEbomParentEntity buildRoot(List materialBaseInfos, String materialNo, String materialDesc) { - BomNewEbomParentEntity parent = new BomNewEbomParentEntity(); - parent.setRowId(IdWorker.getId()); - - BaseMaterialVO vo = materialBaseInfos.stream() - .filter(m -> m.getMaterialNo().equals(materialNo)) - .findFirst() - .orElse(null); - if (!Objects.isNull(vo)) { - parent.setDrawingNo(vo.getDrawingNo()); - parent.setUnitWeight(vo.getMaterialWeight()); - } - - parent.setMaterialNo(materialNo); - parent.setMaterialDesc(materialDesc); - parent.setMaterialTexture(""); - parent.setMaterialUnit("PC"); - //parent.setUnitWeight(BigDecimal.ZERO); - parent.setNum(BigDecimal.ONE); - //parent.setTotalWeight(BomUtil.calculateTotalWeight(data.getNum(), data.getUnitWeight())); - //parent.setCurrentVersion(OriginalConstant.DEFAULT_BOM_VERSION); - parent.setUserRootIs(1); - if (userRoleService.technician()) { - //工艺人员 - parent.setStatus(EBomStatusEnum.CHECKED.getValue()); - parent.setCreatedJob(UserJobEnum.ENGINEER.getValue()); - parent.setAuditUserName(SessionUtil.getUserCode()); - parent.setAuditTime(LocalDateTime.now()); - parent.setRootIs(bomNewEbomChildService.getBaseMapper().shouldSetRootIs(materialNo)); - } else { - //设计人员 - parent.setRootIs(1); - parent.setStatus(EBomStatusEnum.WAIT_CHECK.getValue()); - parent.setCreatedJob(UserJobEnum.DESIGNER.getValue()); - parent.setRootIsForWaitReview(1); - } - parent.setDeviseName(SessionUtil.getRealName()); - parent.setDeviseUserCode(SessionUtil.getUserCode()); - parent.setLastVersionIs(1); - parent.setEditStatus(EbomEditStatusEnum.HANDLER_CREATED.getValue()); - parent.setExceptionStatus(EBomExceptionStatusEnum.INIT.getValue()); - parent.setCreatedBy(SessionUtil.getUserCode()); - parent.setRemark(""); - parent.setDeptName(SessionUtil.getDepartName()); - parent.setSource(EBomSourceEnum.FROM_EXCE.getValue()); - return parent; - } -} diff --git a/nflg_project_dev/nflg-bom-new/src/main/resources/mapper/master/BomNewEbomChildMapper.xml b/nflg_project_dev/nflg-bom-new/src/main/resources/mapper/master/BomNewEbomChildMapper.xml index 18caca7e..bae349f2 100644 --- a/nflg_project_dev/nflg-bom-new/src/main/resources/mapper/master/BomNewEbomChildMapper.xml +++ b/nflg_project_dev/nflg-bom-new/src/main/resources/mapper/master/BomNewEbomChildMapper.xml @@ -74,16 +74,4 @@ group by parent_row_id - - From ac19a53988abf779f668b8d850b02aa9594eb94c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9B=B9=E9=B9=8F=E9=A3=9E?= Date: Wed, 8 May 2024 16:02:07 +0800 Subject: [PATCH 08/14] =?UTF-8?q?feat:=20ebom=E4=BB=8Eexcel=E5=AF=BC?= =?UTF-8?q?=E5=85=A5=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../product/bomnew/api/user/EbomV2Api.java | 34 ++- .../mapper/master/BomNewEbomChildMapper.java | 2 + .../product/bomnew/pojo/dto/EbomExcelDTO.java | 73 +++++ .../bomnew/service/EBomImportService.java | 286 ++++++++++++++++++ .../mapper/master/BomNewEbomChildMapper.xml | 12 + 5 files changed, 401 insertions(+), 6 deletions(-) create mode 100644 nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/pojo/dto/EbomExcelDTO.java create mode 100644 nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/service/EBomImportService.java diff --git a/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/api/user/EbomV2Api.java b/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/api/user/EbomV2Api.java index 3cc083a8..22d7c692 100644 --- a/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/api/user/EbomV2Api.java +++ b/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/api/user/EbomV2Api.java @@ -1,25 +1,26 @@ package com.nflg.product.bomnew.api.user; +import com.mzt.logapi.context.LogRecordContext; +import com.mzt.logapi.starter.annotation.LogRecord; import com.nflg.product.base.core.api.BaseApi; import com.nflg.product.base.core.conmon.util.SessionUtil; -import com.nflg.product.bomnew.constant.OriginalStatusEnum; import com.nflg.product.bomnew.mapper.master.BomNewEbomChildMapper; import com.nflg.product.bomnew.pojo.vo.ImportOriginalBomVO; +import com.nflg.product.bomnew.pojo.vo.OperationErrorMsgVO; import com.nflg.product.bomnew.service.BomNewEbomParentService; import com.nflg.product.bomnew.service.BomNewOriginalParentService; import com.nflg.product.bomnew.service.BomNewOriginalParentV2Service; +import com.nflg.product.bomnew.service.EBomImportService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import nflg.product.common.vo.ResultVO; import org.springframework.transaction.annotation.Transactional; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.*; +import org.springframework.web.multipart.MultipartFile; import javax.annotation.Resource; +import java.io.IOException; import java.util.List; -import java.util.concurrent.CompletableFuture; import java.util.concurrent.ExecutionException; @@ -42,6 +43,8 @@ public class EbomV2Api extends BaseApi { BomNewOriginalParentService originalParentService; @Resource BomNewEbomParentService ebomParentService; + @Resource + EBomImportService eBomImportService; @GetMapping("pullFromCadAndToEBom") @@ -63,4 +66,23 @@ public class EbomV2Api extends BaseApi { return ResultVO.success(result); } + @ApiOperation("导入") + @PostMapping("importBom") + @Transactional(rollbackFor = Exception.class) + @LogRecord(success = "原始BOM-导入:文件名:{{#fileNme}},操作结果:{{#_ret}}", + bizNo = "", type = "原始BOM导入") + public ResultVO> importBom(@RequestParam(value = "file") MultipartFile file) throws IOException { + if (file != null && !file.getOriginalFilename().endsWith("xls") && !file.getOriginalFilename().endsWith("xlsx")) { + return ResultVO.error("请上传Excel文件"); + } + LogRecordContext.putVariable("fileNme", file.getOriginalFilename()); + List result = eBomImportService.importBom(file); + + //计算层级 + originalParentService.computeLevelNumAndRootState(); + + //更新物料使用 + originalParentService.getBaseMapper().upOriginalMaterialUse(); + return ResultVO.success(result); + } } diff --git a/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/mapper/master/BomNewEbomChildMapper.java b/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/mapper/master/BomNewEbomChildMapper.java index a723b7d6..fca209eb 100644 --- a/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/mapper/master/BomNewEbomChildMapper.java +++ b/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/mapper/master/BomNewEbomChildMapper.java @@ -24,4 +24,6 @@ public interface BomNewEbomChildMapper extends BaseMapper void updateEBomMaterialUse(); List getChildMaxExceptionState(@Param("bomRowIds") List bomRowIds); + + Integer shouldSetRootIs(String materialNo); } diff --git a/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/pojo/dto/EbomExcelDTO.java b/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/pojo/dto/EbomExcelDTO.java new file mode 100644 index 00000000..35eb6479 --- /dev/null +++ b/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/pojo/dto/EbomExcelDTO.java @@ -0,0 +1,73 @@ +package com.nflg.product.bomnew.pojo.dto; + +import lombok.Data; +import org.ttzero.excel.annotation.ExcelColumn; + +import java.math.BigDecimal; + +/** + * @author 曹鹏飞 + * @date 2024/5/8 09:07:23 + */ +@Data +public class EbomExcelDTO extends BaseImportExcelDTO { + + /** + * 父级物料编号 + */ + @ExcelColumn("抬头物料") + private String parentMaterialNo; + + /** + * 父级物料描述 + */ + @ExcelColumn("物料描述") + private String parentMaterialDesc; + + /** + * 项目类别 + */ + @ExcelColumn("项目类别") + private String projectType; + + /** + * 物料编号 + */ + @ExcelColumn("项目物料") + private String materialNo; + + /** + * 物料描述 + */ + @ExcelColumn("项目物料描述") + private String materialDesc; + + /** + * 数量 + */ + @ExcelColumn("数量") + private BigDecimal num; + + /** + * 物料单位 + */ + @ExcelColumn("单位") + private String unit; + + /** + * 排序顺序 + */ + @ExcelColumn("排序顺序") + private String orderNum; + + /** + * 备注 + */ + @ExcelColumn("备注") + private String remark; + + /** + * 图号 + */ + private String drawingNo; +} diff --git a/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/service/EBomImportService.java b/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/service/EBomImportService.java new file mode 100644 index 00000000..7d56ecaf --- /dev/null +++ b/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/service/EBomImportService.java @@ -0,0 +1,286 @@ +package com.nflg.product.bomnew.service; + +import cn.hutool.core.convert.Convert; +import cn.hutool.core.util.StrUtil; +import com.alibaba.fastjson.JSON; +import com.baomidou.mybatisplus.core.toolkit.IdWorker; +import com.nflg.product.base.core.conmon.util.SessionUtil; +import com.nflg.product.bomnew.constant.*; +import com.nflg.product.bomnew.pojo.dto.BaseImportExcelDTO; +import com.nflg.product.bomnew.pojo.dto.EbomExcelDTO; +import com.nflg.product.bomnew.pojo.entity.BomNewEbomChildEntity; +import com.nflg.product.bomnew.pojo.entity.BomNewEbomParentEntity; +import com.nflg.product.bomnew.pojo.vo.BaseMaterialVO; +import com.nflg.product.bomnew.pojo.vo.OperationErrorMsgVO; +import com.nflg.product.bomnew.util.BomUtil; +import com.nflg.product.bomnew.util.EecExcelUtil; +import com.nflg.product.bomnew.util.StringUtil; +import com.nflg.product.bomnew.util.VUtils; +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.tuple.Pair; +import org.springframework.stereotype.Service; +import org.springframework.web.multipart.MultipartFile; + +import javax.annotation.Resource; +import java.io.IOException; +import java.math.BigDecimal; +import java.time.LocalDateTime; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.Objects; +import java.util.stream.Collectors; + +/** + * @author 曹鹏飞 + * @date 2024/5/8 09:02:12 + */ +@Service +@Slf4j +public class EBomImportService { + + public static final ThreadLocal rowNum = new ThreadLocal<>(); + + public static final ThreadLocal> excelContextTL = new ThreadLocal<>(); + + @Resource + private MaterialMainService materialMainService; + + @Resource + private UserRoleService userRoleService; + + @Resource + private BomNewEbomParentService bomNewEbomParentService; + + @Resource + private BomNewEbomChildService bomNewEbomChildService; + + public List importBom(MultipartFile file) throws IOException { + try { + rowNum.set(1); + excelContextTL.set(new ArrayList<>()); + EecExcelUtil.handlerExcel(file.getInputStream(), EbomExcelDTO.class, this::handlerExcelRow); + + List datas = excelContextTL.get(); + + List errorMsg = checkExcel(datas); + if (!errorMsg.isEmpty()) { + return errorMsg; + } + + Pair, List> pcs = convertToBom(datas); + VUtils.isTure(pcs.getLeft().stream().filter(p -> p.getRootIs() == 1).count() > 1) + .throwMessage("文件中存在多个根节点"); + //VUtils.isTure(checkInconsistentData(pcs.getLeft().get(0), pcs.getLeft(), pcs.getRight())) + // .throwMessage("导入的数据已存在,请勿重复导入"); + + //save(pcs.getLeft(), pcs.getRight()); + + return Collections.emptyList(); + } finally { + excelContextTL.remove(); + } + } + + private void handlerExcelRow(EbomExcelDTO dQbomExcelVO) { + rowNum.set(rowNum.get() + 1); + log.debug("ebom导入excel,第{}行,处理前:{}", rowNum.get(), JSON.toJSONString(dQbomExcelVO)); + + dQbomExcelVO.setRowNum(rowNum.get()); + + excelContextTL.get().add(dQbomExcelVO); + } + + private List checkExcel(List datas) { + List errorMsg = new ArrayList<>(); + + List numError = datas.stream().filter(u -> StrUtil.isBlank(u.getParentMaterialNo())) + .map(BaseImportExcelDTO::getRowNum) + .collect(Collectors.toList()); + if (!numError.isEmpty()) { + errorMsg.addAll(numError.stream().map(n -> OperationErrorMsgVO.create("第" + n + "行", "抬头物料为空")) + .collect(Collectors.toList()) + ); + } + + numError = datas.stream().filter(u -> StrUtil.isBlank(u.getMaterialNo())) + .map(BaseImportExcelDTO::getRowNum) + .collect(Collectors.toList()); + if (!numError.isEmpty()) { + errorMsg.addAll(numError.stream().map(n -> OperationErrorMsgVO.create("第" + n + "行", "项目物料为空")) + .collect(Collectors.toList()) + ); + } + + numError = datas.stream().filter(u -> Objects.isNull(u.getNum()) || BigDecimal.ZERO.compareTo(u.getNum()) >= 0) + .map(BaseImportExcelDTO::getRowNum) + .collect(Collectors.toList()); + + if (!numError.isEmpty()) { + errorMsg.addAll(numError.stream().map(n -> OperationErrorMsgVO.create("第" + n + "行", "数量不正确")) + .collect(Collectors.toList()) + ); + } + + numError = datas.stream().filter(u -> StringUtil.CountForMysql(u.getRemark()) > 200) + .map(BaseImportExcelDTO::getRowNum) + .collect(Collectors.toList()); + if (!numError.isEmpty()) { + errorMsg.addAll(numError.stream().map(n -> OperationErrorMsgVO.create("第" + n + "行", "备注超出200字")) + .collect(Collectors.toList()) + ); + } + + return errorMsg; + } + + private Pair, List> convertToBom(List datas) { + List parents = new ArrayList<>(); + List children = new ArrayList<>(); + + List materialNos = datas.stream().map(EbomExcelDTO::getMaterialNo).collect(Collectors.toList()); + materialNos.addAll(datas.stream().map(EbomExcelDTO::getParentMaterialNo).collect(Collectors.toList())); + materialNos = materialNos.stream().distinct().collect(Collectors.toList()); + List materialBaseInfos = materialMainService.getMaterialBaseInfo(materialNos); + + BomNewEbomParentEntity parent; + for (EbomExcelDTO data : datas) { + parent = parents.stream().filter(p -> p.getMaterialNo().equals(data.getParentMaterialNo())) + .findFirst() + .orElse(null); + if (Objects.isNull(parent)) { + parents.add(buildRoot(materialBaseInfos, data.getParentMaterialNo(), data.getParentMaterialDesc())); + } + + parent = parents.stream().filter(p -> p.getMaterialNo().equals(data.getMaterialNo())) + .findFirst() + .orElse(null); + if (Objects.isNull(parent)) { + parent = buildParent(materialBaseInfos, data); + children.add(buildChild(materialBaseInfos, parent, data.getProjectType())); + parents.add(parent); + } + } + return Pair.of(parents, children); + } + + private BomNewEbomChildEntity buildChild(List materialBaseInfos, BomNewEbomParentEntity parent, String projectType) { + BomNewEbomChildEntity child = Convert.convert(BomNewEbomChildEntity.class, parent); + parent.setOrderNumber(""); + child.setRowId(IdWorker.getId()); + child.setParentRowId(parent.getRowId()); + child.setProjectType(projectType); + child.setProjectTypeInputType(ProjectTypeInputTypeEnum.MANUAL_INPUT.getValue()); + child.setIdentityNo(child.getParentRowId() + "_" + child.getRowId()); + BaseMaterialVO vo = materialBaseInfos.stream() + .filter(m -> m.getMaterialNo().equals(child.getMaterialNo())) + .findFirst() + .orElse(null); + if (!Objects.isNull(vo)) { + child.setMaterialCategoryCode(vo.getMaterialCategoryCode()); + } + return child; + } + + private BomNewEbomParentEntity buildParent(List materialBaseInfos, EbomExcelDTO data) { + BomNewEbomParentEntity parent = new BomNewEbomParentEntity(); + parent.setRowId(IdWorker.getId()); + + BaseMaterialVO vo = materialBaseInfos.stream() + .filter(m -> m.getMaterialNo().equals(data.getMaterialNo())) + .findFirst() + .orElse(null); + if (!Objects.isNull(vo)) { + parent.setDrawingNo(vo.getDrawingNo()); + parent.setUnitWeight(vo.getMaterialWeight()); + } + + parent.setMaterialNo(data.getMaterialNo()); + parent.setMaterialDesc(data.getMaterialDesc()); + parent.setMaterialTexture(""); + parent.setMaterialUnit(data.getUnit()); + parent.setNum(data.getNum()); + parent.setTotalWeight(BomUtil.calculateTotalWeight(parent.getNum(), parent.getUnitWeight())); + //parent.setCurrentVersion(OriginalConstant.DEFAULT_BOM_VERSION); + parent.setUserRootIs(0); + parent.setRootIs(0); + if (userRoleService.technician()) { + //工艺人员 + parent.setStatus(EBomStatusEnum.CHECKED.getValue()); + parent.setCreatedJob(UserJobEnum.ENGINEER.getValue()); + parent.setAuditUserName(SessionUtil.getUserCode()); + parent.setAuditTime(LocalDateTime.now()); + } else { + //设计人员 + parent.setStatus(EBomStatusEnum.WAIT_CHECK.getValue()); + parent.setCreatedJob(UserJobEnum.DESIGNER.getValue()); + parent.setRootIsForWaitReview(1); + } + parent.setDeviseName(SessionUtil.getRealName()); + parent.setDeviseUserCode(SessionUtil.getUserCode()); + parent.setLastVersionIs(1); + parent.setEditStatus(EbomEditStatusEnum.HANDLER_CREATED.getValue()); + parent.setExceptionStatus(EBomExceptionStatusEnum.INIT.getValue()); + parent.setCreatedBy(SessionUtil.getUserCode()); + parent.setRemark(data.getRemark()); + parent.setOrderNumber(data.getOrderNum()); + parent.setDeptName(SessionUtil.getDepartName()); + parent.setSource(EBomSourceEnum.FROM_EXCE.getValue()); + return parent; + } + + /** + * 构建顶级 + * @param materialBaseInfos 主物料数据 + * @param materialNo 物料编号 + * @param materialDesc 物料描述 + * @return 父级 + */ + private BomNewEbomParentEntity buildRoot(List materialBaseInfos, String materialNo, String materialDesc) { + BomNewEbomParentEntity parent = new BomNewEbomParentEntity(); + parent.setRowId(IdWorker.getId()); + + BaseMaterialVO vo = materialBaseInfos.stream() + .filter(m -> m.getMaterialNo().equals(materialNo)) + .findFirst() + .orElse(null); + if (!Objects.isNull(vo)) { + parent.setDrawingNo(vo.getDrawingNo()); + parent.setUnitWeight(vo.getMaterialWeight()); + } + + parent.setMaterialNo(materialNo); + parent.setMaterialDesc(materialDesc); + parent.setMaterialTexture(""); + parent.setMaterialUnit("PC"); + //parent.setUnitWeight(BigDecimal.ZERO); + parent.setNum(BigDecimal.ONE); + //parent.setTotalWeight(BomUtil.calculateTotalWeight(data.getNum(), data.getUnitWeight())); + //parent.setCurrentVersion(OriginalConstant.DEFAULT_BOM_VERSION); + parent.setUserRootIs(1); + if (userRoleService.technician()) { + //工艺人员 + parent.setStatus(EBomStatusEnum.CHECKED.getValue()); + parent.setCreatedJob(UserJobEnum.ENGINEER.getValue()); + parent.setAuditUserName(SessionUtil.getUserCode()); + parent.setAuditTime(LocalDateTime.now()); + parent.setRootIs(bomNewEbomChildService.getBaseMapper().shouldSetRootIs(materialNo)); + } else { + //设计人员 + parent.setRootIs(1); + parent.setStatus(EBomStatusEnum.WAIT_CHECK.getValue()); + parent.setCreatedJob(UserJobEnum.DESIGNER.getValue()); + parent.setRootIsForWaitReview(1); + } + parent.setDeviseName(SessionUtil.getRealName()); + parent.setDeviseUserCode(SessionUtil.getUserCode()); + parent.setLastVersionIs(1); + parent.setEditStatus(EbomEditStatusEnum.HANDLER_CREATED.getValue()); + parent.setExceptionStatus(EBomExceptionStatusEnum.INIT.getValue()); + parent.setCreatedBy(SessionUtil.getUserCode()); + parent.setRemark(""); + parent.setDeptName(SessionUtil.getDepartName()); + parent.setSource(EBomSourceEnum.FROM_EXCE.getValue()); + return parent; + } +} diff --git a/nflg_project_dev/nflg-bom-new/src/main/resources/mapper/master/BomNewEbomChildMapper.xml b/nflg_project_dev/nflg-bom-new/src/main/resources/mapper/master/BomNewEbomChildMapper.xml index bae349f2..18caca7e 100644 --- a/nflg_project_dev/nflg-bom-new/src/main/resources/mapper/master/BomNewEbomChildMapper.xml +++ b/nflg_project_dev/nflg-bom-new/src/main/resources/mapper/master/BomNewEbomChildMapper.xml @@ -74,4 +74,16 @@ group by parent_row_id + + From 3ded3ba819a3853ce416255536dff6816af319d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A4=A7=E7=B1=B3?= <470431449@qq.com> Date: Wed, 8 May 2024 16:25:09 +0800 Subject: [PATCH 09/14] =?UTF-8?q?1=E3=80=81=E7=94=9F=E6=88=90=E8=99=9A?= =?UTF-8?q?=E6=8B=9F=E5=8C=85=E5=8A=A0=E5=8E=9F=E5=A7=8B=E5=8D=95=E4=BD=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../product/bomnew/service/domain/EBom/VirtualPackageBase.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/service/domain/EBom/VirtualPackageBase.java b/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/service/domain/EBom/VirtualPackageBase.java index d92ce572..81f81847 100644 --- a/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/service/domain/EBom/VirtualPackageBase.java +++ b/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/service/domain/EBom/VirtualPackageBase.java @@ -190,6 +190,7 @@ public abstract class VirtualPackageBase { parent.setShouldBomExist(1); parent.setBomExist(1); parent.setMaterialUnit("PC"); + parent.setMaterialOriginalUnit("PC"); parent.setSourceRowId(0L); parent.setLastVersionIs(1); parent.setNum(new BigDecimal(1)); @@ -223,6 +224,7 @@ public abstract class VirtualPackageBase { childEntity.setVirtualPartType(virtualPackageTypeEnum.getValue()); childEntity.setProjectType("L"); childEntity.setMaterialUnit("PC"); + childEntity.setMaterialOriginalUnit("PC"); childEntity.setProjectTypeInputType(ProjectTypeInputTypeEnum.AUTO_MATCH.getValue()); childEntity.setVirtualPartRootMaterialNo(rootMaterialNo); this.childResult.add(childEntity); From 1e7cd5bdcc86ee3d8935a197a4e39787eeee6aae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9B=B9=E9=B9=8F=E9=A3=9E?= Date: Wed, 8 May 2024 16:26:04 +0800 Subject: [PATCH 10/14] =?UTF-8?q?feat:=20=E4=BF=AE=E5=A4=8D=E7=94=9F?= =?UTF-8?q?=E6=88=90=E8=99=9A=E6=8B=9F=E5=8C=85=E5=90=8E=E5=BC=82=E5=B8=B8?= =?UTF-8?q?=E6=A3=80=E6=9F=A5=E6=97=B6=E6=8F=90=E7=A4=BA=E5=8D=95=E4=BD=8D?= =?UTF-8?q?=E4=B8=8D=E4=B8=80=E8=87=B4=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../product/bomnew/service/domain/EBom/VirtualPackageBase.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/service/domain/EBom/VirtualPackageBase.java b/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/service/domain/EBom/VirtualPackageBase.java index d92ce572..e0c11711 100644 --- a/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/service/domain/EBom/VirtualPackageBase.java +++ b/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/service/domain/EBom/VirtualPackageBase.java @@ -17,7 +17,6 @@ import com.nflg.product.bomnew.service.MaterialMainService; import com.nflg.product.bomnew.service.MaterialService; import com.nflg.product.bomnew.util.VersionUtil; import lombok.Getter; -import org.ttzero.excel.reader.Col; import java.io.IOException; import java.math.BigDecimal; @@ -190,6 +189,7 @@ public abstract class VirtualPackageBase { parent.setShouldBomExist(1); parent.setBomExist(1); parent.setMaterialUnit("PC"); + parent.setMaterialOriginalUnit("PC"); parent.setSourceRowId(0L); parent.setLastVersionIs(1); parent.setNum(new BigDecimal(1)); From 862a88dbf69fcc933f3d6d16201a19c0b281d43a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9B=B9=E9=B9=8F=E9=A3=9E?= Date: Wed, 8 May 2024 17:30:38 +0800 Subject: [PATCH 11/14] =?UTF-8?q?feat:=20ebom=E4=BB=8Eexcel=E5=AF=BC?= =?UTF-8?q?=E5=85=A5=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mapper/master/BomNewEbomChildMapper.java | 5 + .../service/BomNewEbomChildService.java | 10 ++ .../service/BomNewEbomParentService.java | 22 +++ .../bomnew/service/EBomImportService.java | 140 ++++++++++++++++-- .../mapper/master/BomNewEbomChildMapper.xml | 17 +++ 5 files changed, 183 insertions(+), 11 deletions(-) diff --git a/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/mapper/master/BomNewEbomChildMapper.java b/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/mapper/master/BomNewEbomChildMapper.java index fca209eb..96a104a1 100644 --- a/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/mapper/master/BomNewEbomChildMapper.java +++ b/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/mapper/master/BomNewEbomChildMapper.java @@ -2,6 +2,7 @@ package com.nflg.product.bomnew.mapper.master; import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.nflg.product.bomnew.pojo.entity.BomNewEbomChildEntity; +import com.nflg.product.bomnew.pojo.vo.BomNewEbomParentVO; import com.nflg.product.bomnew.pojo.vo.ChildMaxExceptionStateVO; import org.apache.ibatis.annotations.Param; @@ -26,4 +27,8 @@ public interface BomNewEbomChildMapper extends BaseMapper List getChildMaxExceptionState(@Param("bomRowIds") List bomRowIds); Integer shouldSetRootIs(String materialNo); + + List getBom(Long parentRowId, String materialNo); + + void deleteAllChildren(Long rowId); } diff --git a/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/service/BomNewEbomChildService.java b/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/service/BomNewEbomChildService.java index 4e6741ee..5049338a 100644 --- a/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/service/BomNewEbomChildService.java +++ b/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/service/BomNewEbomChildService.java @@ -3,8 +3,11 @@ package com.nflg.product.bomnew.service; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.nflg.product.bomnew.mapper.master.BomNewEbomChildMapper; import com.nflg.product.bomnew.pojo.entity.BomNewEbomChildEntity; +import com.nflg.product.bomnew.pojo.vo.BomNewEbomParentVO; import org.springframework.stereotype.Service; +import java.util.List; + /** * t_bom_new_ebom_child 表服务实现类 @@ -16,4 +19,11 @@ import org.springframework.stereotype.Service; @Service public class BomNewEbomChildService extends ServiceImpl { + public List getBom(Long parentRowId, String materialNo) { + return baseMapper.getBom(parentRowId, materialNo); + } + + public void deleteAllChildren(Long parentRowId) { + baseMapper.deleteAllChildren(parentRowId); + } } diff --git a/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/service/BomNewEbomParentService.java b/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/service/BomNewEbomParentService.java index cfca73b8..ebfd6fa6 100644 --- a/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/service/BomNewEbomParentService.java +++ b/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/service/BomNewEbomParentService.java @@ -2313,4 +2313,26 @@ public class BomNewEbomParentService extends ServiceImpl getLatestByMaterialNo(Collection materialNos) { + return this.lambdaQuery() + .in(BomNewEbomParentEntity::getMaterialNo, materialNos) + .eq(BomNewEbomParentEntity::getLastVersionIs, 1) + .list(); + } + + public void setLastVersionIs0(Set pMaterialNos) { + this.lambdaUpdate().in(BomNewEbomParentEntity::getMaterialNo, pMaterialNos) + .set(BomNewEbomParentEntity::getLastVersionIs, 0) + .set(BomNewEbomParentEntity::getModifyTime, LocalDateTime.now()) + .update(); + } } diff --git a/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/service/EBomImportService.java b/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/service/EBomImportService.java index 7d56ecaf..2ef5c6c0 100644 --- a/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/service/EBomImportService.java +++ b/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/service/EBomImportService.java @@ -1,34 +1,36 @@ package com.nflg.product.bomnew.service; +import cn.hutool.core.collection.CollUtil; import cn.hutool.core.convert.Convert; +import cn.hutool.core.util.NumberUtil; import cn.hutool.core.util.StrUtil; import com.alibaba.fastjson.JSON; import com.baomidou.mybatisplus.core.toolkit.IdWorker; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.google.common.collect.Sets; import com.nflg.product.base.core.conmon.util.SessionUtil; +import com.nflg.product.base.core.exception.NflgBusinessException; import com.nflg.product.bomnew.constant.*; import com.nflg.product.bomnew.pojo.dto.BaseImportExcelDTO; import com.nflg.product.bomnew.pojo.dto.EbomExcelDTO; import com.nflg.product.bomnew.pojo.entity.BomNewEbomChildEntity; import com.nflg.product.bomnew.pojo.entity.BomNewEbomParentEntity; import com.nflg.product.bomnew.pojo.vo.BaseMaterialVO; +import com.nflg.product.bomnew.pojo.vo.BomNewEbomParentVO; import com.nflg.product.bomnew.pojo.vo.OperationErrorMsgVO; -import com.nflg.product.bomnew.util.BomUtil; -import com.nflg.product.bomnew.util.EecExcelUtil; -import com.nflg.product.bomnew.util.StringUtil; -import com.nflg.product.bomnew.util.VUtils; +import com.nflg.product.bomnew.util.*; import lombok.extern.slf4j.Slf4j; +import nflg.product.common.constant.STATE; import org.apache.commons.lang3.tuple.Pair; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; import org.springframework.web.multipart.MultipartFile; import javax.annotation.Resource; import java.io.IOException; import java.math.BigDecimal; import java.time.LocalDateTime; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import java.util.Objects; +import java.util.*; import java.util.stream.Collectors; /** @@ -71,10 +73,10 @@ public class EBomImportService { Pair, List> pcs = convertToBom(datas); VUtils.isTure(pcs.getLeft().stream().filter(p -> p.getRootIs() == 1).count() > 1) .throwMessage("文件中存在多个根节点"); - //VUtils.isTure(checkInconsistentData(pcs.getLeft().get(0), pcs.getLeft(), pcs.getRight())) - // .throwMessage("导入的数据已存在,请勿重复导入"); + VUtils.isTure(checkInconsistentData(pcs.getLeft().get(0), pcs.getLeft(), pcs.getRight())) + .throwMessage("导入的数据已存在,请勿重复导入"); - //save(pcs.getLeft(), pcs.getRight()); + save(pcs.getLeft(), pcs.getRight()); return Collections.emptyList(); } finally { @@ -82,6 +84,122 @@ public class EBomImportService { } } + @Transactional(rollbackFor = Exception.class) + public void save(List parents, List children) { + BomNewEbomParentEntity root = parents.stream() + .filter(p -> p.getRootIs() == 1) + .findFirst() + .orElseThrow(() -> new NflgBusinessException(STATE.BusinessError, "根节点不存在")); + Set pMaterialNos = parents.stream().map(BomNewEbomParentEntity::getMaterialNo).collect(Collectors.toSet()); + List oldParents = bomNewEbomParentService.getLatestByMaterialNo(pMaterialNos); + parents.forEach(p -> { + BomNewEbomParentEntity oldParent = oldParents.stream() + .filter(op -> op.getMaterialNo().equals(p.getMaterialNo())) + .findFirst() + .orElse(null); + if (!Objects.isNull(oldParent) && !Objects.equals(oldParent.getStatus(), EBomStatusEnum.PUBLISHED.getValue())) { + bomNewEbomParentService.getBaseMapper().deleteById(oldParent.getRowId()); + bomNewEbomChildService.deleteAllChildren(oldParent.getRowId()); + } + }); + bomNewEbomParentService.setLastVersionIs0(pMaterialNos); + bomNewEbomParentService.saveBatch(parents); + bomNewEbomChildService.saveBatch(children); + } + + private boolean checkInconsistentData(BomNewEbomParentEntity parent, List parents, + List children) throws JsonProcessingException { + log.debug("checkInconsistentData,entity:" + JsonUtil.toJson(parent)); + BomNewEbomParentEntity oldParent = bomNewEbomParentService.getLatestByMaterialNo(parent.getMaterialNo()); + boolean isSame = true; + if (Objects.isNull(oldParent)) { + return false; + } + isSame = Objects.equals(parent.getMaterialUnit(), oldParent.getMaterialUnit()) + && NumberUtil.equals(parent.getNum(), oldParent.getNum()) + && Objects.equals(parent.getMaterialTexture(), oldParent.getMaterialTexture()); + + if (isSame) { + List cc = children.stream() + .filter(c -> c.getParentRowId().equals(parent.getRowId())) + .collect(Collectors.toList()); + List oc = bomNewEbomChildService.lambdaQuery() + .eq(BomNewEbomChildEntity::getParentRowId, oldParent.getRowId()) + .list(); + + isSame = cc.size() == oc.size() + && Sets.difference(cc.stream().map(BomNewEbomChildEntity::getMaterialNo).collect(Collectors.toSet()) + , oc.stream().map(BomNewEbomChildEntity::getMaterialNo).collect(Collectors.toSet())).isEmpty(); + for (BomNewEbomChildEntity ccc : cc) { + if (!checkInconsistentData(parent.getRowId(), ccc, parents, children)) { + isSame = false; + } + } + } + if (!isSame) { + if (Objects.equals(oldParent.getStatus(), EBomStatusEnum.PUBLISHED.getValue())) { + parent.setCurrentVersion(VersionUtil.getNextVersion(oldParent.getCurrentVersion())); + } else { + VUtils.isTure(!Objects.equals(oldParent.getCreatedBy(), SessionUtil.getUserCode())) + .throwMessage(StrUtil.format("{}正由{}编辑中,请联系Ta处理", oldParent.getMaterialNo(), oldParent.getCreatedBy())); + } + } else { + parents.remove(parent); + children.removeIf(c -> c.getParentRowId().equals(parent.getRowId())); + } + return isSame; + } + + private boolean checkInconsistentData(Long parentRowId, BomNewEbomChildEntity child, List parents, + List children) throws JsonProcessingException { + log.debug("checkInconsistentData,entity:" + JsonUtil.toJson(child)); + List oldChildren = bomNewEbomChildService.getBom(parentRowId, child.getMaterialNo()); + boolean isSame = true; + if (CollUtil.isEmpty(oldChildren)) return false; + BomNewEbomParentVO oldChild; + if (oldChildren.size() == 1) { + oldChild = oldChildren.get(0); + } else { + oldChild = oldChildren.stream().filter(c -> Objects.equals(c.getOrderNumber(), child.getOrderNumber())).findFirst().orElse(null); + if (Objects.isNull(oldChild)) { + return false; + } + } + isSame = Objects.equals(child.getMaterialUnit(), oldChild.getMaterialUnit()) + && NumberUtil.equals(child.getNum(), oldChild.getNum()) + && Objects.equals(child.getMaterialTexture(), oldChild.getMaterialTexture()); + + if (isSame) { + BomNewEbomParentEntity cp = parents.stream().filter(p -> p.getMaterialNo().equals(child.getMaterialNo())).findFirst().orElse(null); + if (!Objects.isNull(cp)) { + List cc = children.stream() + .filter(c -> c.getParentRowId().equals(cp.getRowId())) + .collect(Collectors.toList()); + List oc = bomNewEbomChildService.lambdaQuery() + .eq(BomNewEbomChildEntity::getParentRowId, oldChild.getBomRowId()) + .list(); + Set ccm = cc.stream().map(BomNewEbomChildEntity::getMaterialNo).collect(Collectors.toSet()); + + isSame = cc.size() == oc.size() + && Sets.difference(ccm, oc.stream().map(BomNewEbomChildEntity::getMaterialNo).collect(Collectors.toSet())).isEmpty(); + //VUtils.isTure(isSame).throwMessage("导入的数据已存在,请勿重复导入"); + + for (BomNewEbomChildEntity ccc : cc) { + if (!checkInconsistentData(cp.getRowId(), ccc, parents, children)) { + isSame = false; + } + } + } + } + if (!isSame) { + if (!Objects.equals(oldChild.getStatus(), EBomStatusEnum.PUBLISHED.getValue())) { + VUtils.isTure(!Objects.equals(oldChild.getCreatedBy(), SessionUtil.getUserCode())) + .throwMessage(StrUtil.format("{}正由{}编辑中,请联系Ta处理", oldChild.getMaterialNo(), oldChild.getCreatedBy())); + } + } + return isSame; + } + private void handlerExcelRow(EbomExcelDTO dQbomExcelVO) { rowNum.set(rowNum.get() + 1); log.debug("ebom导入excel,第{}行,处理前:{}", rowNum.get(), JSON.toJSONString(dQbomExcelVO)); diff --git a/nflg_project_dev/nflg-bom-new/src/main/resources/mapper/master/BomNewEbomChildMapper.xml b/nflg_project_dev/nflg-bom-new/src/main/resources/mapper/master/BomNewEbomChildMapper.xml index 18caca7e..70c3f343 100644 --- a/nflg_project_dev/nflg-bom-new/src/main/resources/mapper/master/BomNewEbomChildMapper.xml +++ b/nflg_project_dev/nflg-bom-new/src/main/resources/mapper/master/BomNewEbomChildMapper.xml @@ -86,4 +86,21 @@ ELSE 0 END AS result; + + + + + DELETE + FROM t_bom_new_ebom_child + WHERE parent_row_id = #{parentRowId}; + UPDATE t_bom_new_ebom_parent + SET bom_exist=0 + WHERE row_id = #{parentRowId}; + From a7c1b7427299615ea7b3a99a14d8aa38d461c937 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9B=B9=E9=B9=8F=E9=A3=9E?= Date: Thu, 9 May 2024 08:11:05 +0800 Subject: [PATCH 12/14] =?UTF-8?q?feat(=E7=94=B5=E6=B0=94bom):=20=E5=AF=BC?= =?UTF-8?q?=E5=85=A5=E6=95=B0=E6=8D=AE=E6=97=B6=EF=BC=8C=E5=A6=82=E6=9E=9C?= =?UTF-8?q?=E7=B1=BB=E5=9E=8B=E4=B8=BA=E7=A9=BA=EF=BC=8C=E5=88=99=E8=AE=BE?= =?UTF-8?q?=E7=BD=AE=E4=B8=BAL?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/nflg/product/bomnew/service/DQBomImportService.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/service/DQBomImportService.java b/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/service/DQBomImportService.java index 7bc5d559..69642e0c 100644 --- a/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/service/DQBomImportService.java +++ b/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/service/DQBomImportService.java @@ -379,6 +379,9 @@ public class DQBomImportService { dQbomExcelVO.setProjectType(BomConstant.PROJECT_TYPE_TEMPORARY); } dQbomExcelVO.setCurrentVersion(""); + if (StrUtil.isBlank(dQbomExcelVO.getProjectType())) { + dQbomExcelVO.setProjectType("L"); + } excelContextTL.get().add(dQbomExcelVO); } From 4251feac9ba548636730d3712e2546c15fc7d174 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9B=B9=E9=B9=8F=E9=A3=9E?= Date: Thu, 9 May 2024 08:15:17 +0800 Subject: [PATCH 13/14] =?UTF-8?q?feat(=E5=AF=BC=E5=85=A5=E5=88=B0sap):=20?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E8=AE=BE=E7=BD=AE=E5=AF=BC=E5=85=A5sap?= =?UTF-8?q?=E7=8A=B6=E6=80=81=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../product/bomnew/service/BomNewEbomParentService.java | 6 ++++-- .../product/bomnew/service/BomNewMbomParentService.java | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/service/BomNewEbomParentService.java b/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/service/BomNewEbomParentService.java index ea2b49ec..241cb170 100644 --- a/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/service/BomNewEbomParentService.java +++ b/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/service/BomNewEbomParentService.java @@ -405,6 +405,7 @@ public class BomNewEbomParentService extends ServiceImpl Date: Thu, 9 May 2024 08:34:04 +0800 Subject: [PATCH 14/14] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0sap=E7=8A=B6?= =?UTF-8?q?=E6=80=81=E5=AD=97=E6=AE=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/nflg/product/bomnew/pojo/vo/BomNewEbomParentVO.java | 3 +++ .../com/nflg/product/bomnew/pojo/vo/BomNewPbomParentVO.java | 3 +++ 2 files changed, 6 insertions(+) diff --git a/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/pojo/vo/BomNewEbomParentVO.java b/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/pojo/vo/BomNewEbomParentVO.java index bb0cc756..e0e45eb4 100644 --- a/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/pojo/vo/BomNewEbomParentVO.java +++ b/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/pojo/vo/BomNewEbomParentVO.java @@ -328,6 +328,9 @@ public class BomNewEbomParentVO extends BaseMaterialVO implements Serializable { @ApiModelProperty(value = "待复核根节点") private Integer rootIsForWaitReview; + @ApiModelProperty(value = "导入SAP状态") + private Integer sapState; + private List childNodes = Collections.emptyList(); private static final long serialVersionUID = 1L; diff --git a/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/pojo/vo/BomNewPbomParentVO.java b/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/pojo/vo/BomNewPbomParentVO.java index 0a9daed6..147bb8d0 100644 --- a/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/pojo/vo/BomNewPbomParentVO.java +++ b/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/pojo/vo/BomNewPbomParentVO.java @@ -263,6 +263,9 @@ public class BomNewPbomParentVO extends BaseMaterialVO implements Serializable { @ApiModelProperty("层级数字") private BigDecimal levelNumber; + @ApiModelProperty(value = "导入SAP状态") + private Integer sapState; + private String levelNo;