From 314aceba8ba6f1f6f5c3f54183d9bb9183f7b6c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9B=B9=E9=B9=8F=E9=A3=9E?= Date: Fri, 17 May 2024 13:38:06 +0800 Subject: [PATCH] =?UTF-8?q?fix(ebom):=20=E4=BC=98=E5=8C=96=E4=BB=8Eexcel?= =?UTF-8?q?=E5=AF=BC=E5=85=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../product/bomnew/api/user/EbomV2Api.java | 16 ++--- .../pojo/entity/BomNewEbomParentEntity.java | 3 + .../bomnew/service/EBomImportService.java | 66 ++++++++++++------- 3 files changed, 51 insertions(+), 34 deletions(-) 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 fa9dc693..476b4aea 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 @@ -11,10 +11,7 @@ import com.nflg.product.bomnew.pojo.query.GenerateVirtualPackageQuery; import com.nflg.product.bomnew.pojo.vo.ImportOriginalBomVO; import com.nflg.product.bomnew.pojo.vo.ListForGenerateVirtualPackageVO; 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 com.nflg.product.bomnew.service.*; import com.nflg.product.bomnew.util.EecExcelUtil; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; @@ -52,6 +49,8 @@ public class EbomV2Api extends BaseApi { @Resource BomNewEbomParentService ebomParentService; @Resource + BomNewEbomChildService ebomChildService; + @Resource EBomImportService eBomImportService; @@ -79,18 +78,17 @@ public class EbomV2Api extends BaseApi { @Transactional(rollbackFor = Exception.class) @LogRecord(success = "原始BOM-导入:文件名:{{#fileNme}},操作结果:{{#_ret}}", bizNo = "", type = "原始BOM导入") - public ResultVO> importBom(@RequestParam(value = "file") MultipartFile file) throws IOException { + public ResultVO> importBom(@RequestParam(value = "file") MultipartFile file) throws Exception { 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(); + ebomChildService.getBaseMapper().updateEBomMaterialUse(); + ebomParentService.compucteLevelNum(); - //更新物料使用 - originalParentService.getBaseMapper().upOriginalMaterialUse(); + ebomParentService.resetAllBomExist(); return ResultVO.success(result); } diff --git a/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/pojo/entity/BomNewEbomParentEntity.java b/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/pojo/entity/BomNewEbomParentEntity.java index 7223ff50..093ce6f2 100644 --- a/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/pojo/entity/BomNewEbomParentEntity.java +++ b/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/pojo/entity/BomNewEbomParentEntity.java @@ -385,5 +385,8 @@ public class BomNewEbomParentEntity implements Serializable { @ApiModelProperty(value = "导入SAP时间") private LocalDateTime sapTime; + @TableField(exist = false) + private boolean isImportRoot = false; + private static final long serialVersionUID = 265246823929418418L; } 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 1333b2e1..89fb0c33 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 @@ -7,7 +7,6 @@ import cn.hutool.core.util.RandomUtil; 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.bomnew.constant.*; @@ -70,7 +69,12 @@ public class EBomImportService { } Pair, List> pcs = convertToBom(datas); - VUtils.isTure(checkInconsistentData(pcs.getLeft().get(0), pcs.getLeft(), pcs.getRight())).throwMessage("导入的数据已存在,请勿重复导入"); + + List importRoots = pcs.getLeft().stream().filter(BomNewEbomParentEntity::isImportRoot).collect(Collectors.toList()); + //VUtils.isTure(importRoots.size() > 1).throwMessage("不支持一次导入多个bom"); + importRoots.forEach(it -> { + VUtils.isTure(checkInconsistentData(pcs.getLeft().get(0), pcs.getLeft(), pcs.getRight())).throwMessage("导入的数据已存在,请勿重复导入"); + }); save(pcs.getLeft(), pcs.getRight()); @@ -104,8 +108,8 @@ public class EBomImportService { } private boolean checkInconsistentData(BomNewEbomParentEntity parent, List parents, - List children) throws JsonProcessingException { - log.debug("checkInconsistentData,entity:" + JsonUtil.toJson(parent)); + List children) { + log.debug("checkInconsistentData,entity:" + JSON.toJSONString(parent)); BomNewEbomParentEntity oldParent = bomNewEbomParentService.getLatestByMaterialNo(parent.getMaterialNo()); boolean isSame = true; if (Objects.isNull(oldParent)) { @@ -155,8 +159,8 @@ public class EBomImportService { } private boolean checkInconsistentData(Long parentRowId, BomNewEbomChildEntity child, List parents, - List children) throws JsonProcessingException { - log.debug("checkInconsistentData,entity:" + JsonUtil.toJson(child)); + List children) { + log.debug("checkInconsistentData,entity:" + JSON.toJSONString(child)); List oldChildren = bomNewEbomChildService.getBom(parentRowId, child.getMaterialNo()); boolean isSame = true; if (CollUtil.isEmpty(oldChildren)) return false; @@ -301,24 +305,29 @@ public class EBomImportService { parent = parents.stream().filter(p -> p.getMaterialNo().equals(data.getParentMaterialNo())) .findFirst() .orElse(null); - if (Objects.isNull(parent)) { - parents.add(buildTop(materialBaseInfos, data.getParentMaterialNo(), data.getParentMaterialDesc())); + if (Objects.isNull(parent) && datas.stream().noneMatch(d -> d.getMaterialNo().equals(data.getParentMaterialNo()))) { + parents.add(buildRoot(materialBaseInfos, data.getParentMaterialNo(), data.getParentMaterialDesc())); } - + } + for (EbomExcelDTO data : datas) { parent = parents.stream().filter(p -> p.getMaterialNo().equals(data.getMaterialNo())) .findFirst() .orElse(null); if (Objects.isNull(parent)) { - parent = buildParent(materialBaseInfos, data); - buildChild(children, materialBaseInfos, parent, data.getProjectType() - , parents.stream().filter(p -> p.getMaterialNo().equals(data.getParentMaterialNo())).findFirst().get()); - parents.add(parent); + parents.add(buildParent(materialBaseInfos, data)); } } + for (EbomExcelDTO data : datas) { + parent = parents.stream().filter(p -> p.getMaterialNo().equals(data.getMaterialNo())) + .findFirst() + .get(); + buildChild(children, materialBaseInfos, parent, data + , parents.stream().filter(p -> p.getMaterialNo().equals(data.getParentMaterialNo())).findFirst().get()); + } return Pair.of(parents, children); } - private void buildChild(List children, List materialBaseInfos, BomNewEbomParentEntity parent, String projectType, BomNewEbomParentEntity p) { + private void buildChild(List children, List materialBaseInfos, BomNewEbomParentEntity parent, EbomExcelDTO data, BomNewEbomParentEntity p) { BomNewEbomChildEntity child = Convert.convert(BomNewEbomChildEntity.class, parent); child.setRowId(IdWorker.getId()); child.setParentRowId(p.getRowId()); @@ -335,11 +344,12 @@ public class EBomImportService { child.setDrawingNo(parent.getDrawingNo()); child.setMaterialDesc(parent.getMaterialDesc()); child.setUnitWeight(parent.getUnitWeight()); - child.setMaterialUnit(parent.getMaterialUnit()); + child.setMaterialUnit(data.getUnit()); child.setMaterialOriginalUnit(parent.getMaterialOriginalUnit()); - child.setNum(parent.getNum()); - child.setTotalWeight(parent.getTotalWeight()); - child.setProjectType(projectType); + child.setNum(data.getNum()); + child.setRemark(data.getRemark()); + child.setTotalWeight(BomUtil.calculateTotalWeight(child.getNum(), child.getUnitWeight())); + child.setProjectType(data.getProjectType()); child.setProjectTypeInputType(ProjectTypeInputTypeEnum.MANUAL_INPUT.getValue()); child.setIdentityNo(child.getParentRowId() + "_" + child.getRowId()); if (p.getMaterialNo().startsWith("31")) { @@ -378,10 +388,11 @@ public class EBomImportService { } } parent.setMaterialOriginalUnit(data.getUnit()); - parent.setNum(data.getNum()); - parent.setTotalWeight(BomUtil.calculateTotalWeight(parent.getNum(), parent.getUnitWeight())); + parent.setNum(BigDecimal.ONE); + parent.setTotalWeight(null); parent.setUserRootIs(0); parent.setRootIs(0); + parent.setRootIsForWaitReview(0); if (userRoleService.technician()) { //工艺人员 parent.setStatus(EBomStatusEnum.CHECKED.getValue()); @@ -392,7 +403,6 @@ public class EBomImportService { //设计人员 parent.setStatus(EBomStatusEnum.WAIT_CHECK.getValue()); parent.setCreatedJob(UserJobEnum.DESIGNER.getValue()); - parent.setRootIsForWaitReview(1); } parent.setDeviseName(SessionUtil.getRealName()); parent.setDeviseUserCode(SessionUtil.getUserCode()); @@ -400,7 +410,7 @@ public class EBomImportService { parent.setEditStatus(EbomEditStatusEnum.HANDLER_CREATED.getValue()); parent.setExceptionStatus(EBomExceptionStatusEnum.INIT.getValue()); parent.setCreatedBy(SessionUtil.getUserCode()); - parent.setRemark(data.getRemark()); + parent.setRemark(""); parent.setOrderNumber(data.getOrderNum()); parent.setDeptName(SessionUtil.getDepartName()); parent.setSource(EBomSourceEnum.FROM_EXCE.getValue()); @@ -416,10 +426,10 @@ public class EBomImportService { * @param materialDesc 物料描述 * @return 父级 */ - private BomNewEbomParentEntity buildTop(List materialBaseInfos, String materialNo, String materialDesc) { + private BomNewEbomParentEntity buildRoot(List materialBaseInfos, String materialNo, String materialDesc) { BomNewEbomParentEntity parent = new BomNewEbomParentEntity(); parent.setRowId(IdWorker.getId()); - + parent.setImportRoot(true); parent.setMaterialNo(materialNo); parent.setMaterialDesc(materialDesc); BaseMaterialVO vo = materialBaseInfos.stream() @@ -446,8 +456,8 @@ public class EBomImportService { // .stream() // .map(BomNewEbomChildEntity::getParentRowId) // .collect(Collectors.toList()); - parent.setUserRootIs(1); parent.setRootIs(bomNewEbomChildService.getBaseMapper().shouldSetRootIs(materialNo)); + parent.setUserRootIs(1); if (userRoleService.technician()) { //工艺人员 parent.setStatus(EBomStatusEnum.CHECKED.getValue()); @@ -476,6 +486,9 @@ public class EBomImportService { } private void setVirtualPackageType(BomNewEbomParentEntity parent) { + if (!parent.getMaterialNo().startsWith("22")) { + return; + } if (parent.getMaterialDesc().endsWith(")(发货)") || parent.getMaterialDesc().endsWith(")(制作)") || parent.getMaterialDesc().endsWith(")(直发)") || parent.getMaterialDesc().endsWith(")(发货前装配)")) { parent.setVirtualPackageIs(1); @@ -483,6 +496,9 @@ public class EBomImportService { } private void setVirtualPackageType(BomNewEbomChildEntity child) { + if (!child.getMaterialNo().startsWith("22")) { + return; + } if (child.getMaterialDesc().endsWith(")(发货)")) { child.setVirtualPartType(VirtualPackageTypeEnum.DELIVERY_PACKAGE.getValue()); } else if (child.getMaterialDesc().endsWith(")(制作)")) {