From cbb41e2519413c5b5449c9b4fc063460b437fbcb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9B=B9=E9=B9=8F=E9=A3=9E?= Date: Tue, 23 Apr 2024 10:59:15 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E7=94=B5=E6=B0=94=E4=B8=93=E7=94=A8bom?= =?UTF-8?q?=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../product/bomnew/pojo/vo/DQbomExcelVO.java | 2 +- .../bomnew/service/DQBomImportService.java | 92 +++++++++++-------- .../bomnew/service/DQBomParentService.java | 9 +- 3 files changed, 62 insertions(+), 41 deletions(-) diff --git a/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/pojo/vo/DQbomExcelVO.java b/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/pojo/vo/DQbomExcelVO.java index 5ac7dbd7..64cd3893 100644 --- a/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/pojo/vo/DQbomExcelVO.java +++ b/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/pojo/vo/DQbomExcelVO.java @@ -32,7 +32,7 @@ public class DQbomExcelVO extends BaseImportExcelDTO { private BigDecimal num; @ExcelColumn("单位") - private String material_unit; + private String materialUnit; @ExcelColumn("项目类别") private String projectType; 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 bdc32901..01bd937b 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 @@ -5,12 +5,10 @@ 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.BomConstant; -import com.nflg.product.bomnew.constant.EBomExceptionStatusEnum; -import com.nflg.product.bomnew.constant.OriginalConstant; -import com.nflg.product.bomnew.constant.UserJobEnum; +import com.nflg.product.bomnew.constant.*; import com.nflg.product.bomnew.pojo.dto.BaseImportExcelDTO; import com.nflg.product.bomnew.pojo.entity.BomNewDQbomChildEntity; import com.nflg.product.bomnew.pojo.entity.BomNewDQbomParentEntity; @@ -80,7 +78,9 @@ public class DQBomImportService { try { checkInconsistentData(pcs.getLeft().get(0), pcs.getLeft(), pcs.getRight()); } catch (NflgBusinessException ex) { - BOMMAP.put(SessionUtil.getUserCode(), pcs); + if (Objects.equals(ex.getState(), STATE.InconsistentDataError)) { + BOMMAP.put(SessionUtil.getUserCode(), pcs); + } throw ex; } @@ -92,10 +92,6 @@ public class DQBomImportService { } } - private void checkData(List datas) { - - } - public void save() { Pair, List> pcs = BOMMAP.get(SessionUtil.getUserCode()); VUtils.isTure(pcs == null).throwMessage("数据已丢失,请重新导入"); @@ -118,23 +114,31 @@ public class DQBomImportService { // checkService.check(parents, children); // } - private void checkInconsistentData(BomNewDQbomParentEntity parent, List parents, List children) throws JsonProcessingException { + private void checkInconsistentData(BomNewDQbomParentEntity parent, List parents, + List children) throws JsonProcessingException { log.debug("checkInconsistentData,parent:" + JsonUtil.toJson(parent)); - BomNewDQbomParentEntity oldParent = dQBomParentService.getLastVersion(parent.getMaterialNo()); - if (oldParent != null) { - if (!parent.getMaterialUnit().equals(oldParent.getMaterialUnit()) - || !parent.getMaterialTexture().equals(oldParent.getMaterialTexture())) { - throw new NflgBusinessException(STATE.InconsistentDataError, "物料信息不一致"); - } - - List cc = children.stream().filter(c -> c.getParentRowId().equals(parent.getRowId())) + BomNewDQbomParentEntity oldParent = dQBomParentService.getLatestByMaterialNo(parent.getMaterialNo()); + if (!Objects.isNull(oldParent)) { + Set cc = children.stream().filter(c -> c.getParentRowId().equals(parent.getRowId())) .map(BomNewDQbomChildEntity::getMaterialNo) - .collect(Collectors.toList()); - List oc = dQBomChildService.lambdaQuery().eq(BomNewDQbomChildEntity::getParentRowId, oldParent.getRowId()) + .collect(Collectors.toSet()); + Set oc = dQBomChildService.lambdaQuery().eq(BomNewDQbomChildEntity::getParentRowId, oldParent.getRowId()) .list() - .stream().map(BomNewDQbomChildEntity::getMaterialNo).collect(Collectors.toList()); - if (cc.size() != oc.size()) { - throw new NflgBusinessException(STATE.InconsistentDataError, "子级节点数量不一致"); + .stream().map(BomNewDQbomChildEntity::getMaterialNo) + .collect(Collectors.toSet()); + // if (!Sets.difference(cc, oc).isEmpty()) { + // throw new NflgBusinessException(STATE.InconsistentDataError, "导入的数据和已存在的数据不一致,是否覆盖?"); + // } + boolean isSame = Sets.difference(cc, oc).isEmpty() + && Objects.equals(parent.getMaterialUnit(), oldParent.getMaterialUnit()) + && Objects.equals(parent.getNum(), oldParent.getNum()) + && Objects.equals(parent.getMaterialTexture(), oldParent.getMaterialTexture()); + VUtils.isTure(isSame).throwMessage("导入的数据已存在,请勿重复导入"); + + if (Objects.equals(oldParent.getStatus(), DQBomStatusEnum.WAIT_CONVERT.getValue())) { + VUtils.isTure(!Objects.equals(oldParent.getCreatedBy(), SessionUtil.getUserCode())) + .throwMessage(StrUtil.format("此物料已由{}导入过,不能再次导入", oldParent.getCreatedName())); + throw new NflgBusinessException(STATE.InconsistentDataError, "导入的数据和已存在的数据不一致,是否覆盖?"); } List ps = parents.stream().filter(p -> cc.contains(p.getMaterialNo())) @@ -188,15 +192,28 @@ public class DQBomImportService { BomNewDQbomParentEntity parent = parents.stream().filter(p -> p.getMaterialNo().equals(data.getMaterialNo())) .findFirst() - .orElse(dQBomParentService.lambdaQuery() - .eq(BomNewDQbomParentEntity::getLastVersionIs, 1) - .eq(BomNewDQbomParentEntity::getMaterialNo, data.getMaterialNo()) - .orderByDesc(BomNewDQbomParentEntity::getRowId) - .list() - .stream().findFirst().orElse(null) - ); + .orElse(null); //if (parent == null && (count - 1 != index || datas.get(index + 1).getLevel() > data.getLevel())) { if (parent == null && count - 1 > index && datas.get(index + 1).getLevel() > data.getLevel()) { + // if (index == 0) { + // BomNewDQbomParentEntity old = dQBomParentService.lambdaQuery() + // .eq(data.getProjectType().equals("L"), BomNewDQbomParentEntity::getMaterialNo, data.getMaterialNo()) + // .eq(data.getProjectType().equals("T"), BomNewDQbomParentEntity::getMaterialName, data.getMaterialName()) + // .orderByDesc(BomNewDQbomParentEntity::getRowId) + // .last(" limit 1") + // .one(); + // if (!Objects.isNull(old)) { + // VUtils.isTure(Objects.equals(data.getMaterialUnit(), old.getMaterialUnit()) + // || Objects.equals(data.getNum(), old.getNum()) + // || Objects.equals(data.getMaterialTexture(), old.getMaterialTexture())) + // .throwMessage("导入的数据已存在,请勿重复导入"); + // if (Objects.equals(old.getStatus(), DQBomStatusEnum.WAIT_CONVERT.getValue())) { + // VUtils.isTure(!Objects.equals(old.getCreatedBy(), SessionUtil.getUserCode())) + // .throwMessage(StrUtil.format("此物料已由{}导入过,不能再次导入", old.getCreatedName())); + // } + // } + // } + parent = new BomNewDQbomParentEntity(); parent.setRowId(IdWorker.getId()); parent.setLevel(data.getLevel()); @@ -204,7 +221,7 @@ public class DQBomImportService { parent.setMaterialNo(data.getMaterialNo()); parent.setMaterialName(data.getMaterialName()); parent.setMaterialTexture(data.getMaterialTexture()); - parent.setMaterialUnit(data.getMaterial_unit()); + parent.setMaterialUnit(data.getMaterialUnit()); parent.setUnitWeight(data.getUnitWeight()); parent.setNum(Objects.isNull(data.getNum()) ? BigDecimal.ZERO : data.getNum()); parent.setTotalWeight(BomUtil.calculateTotalWeight(data.getNum(), data.getUnitWeight())); @@ -246,7 +263,7 @@ public class DQBomImportService { child.setLevel(data.getLevel()); child.setMaterialName(data.getMaterialName()); child.setMaterialTexture(data.getMaterialTexture()); - child.setMaterialUnit(data.getMaterial_unit()); + child.setMaterialUnit(data.getMaterialUnit()); child.setUnitWeight(data.getUnitWeight()); child.setTotalWeight(BomUtil.calculateTotalWeight(data.getNum(), data.getUnitWeight())); child.setOrderNumber(StrUtil.padPre(String.valueOf(orderMap.get(data.getLevel())), 3, '0')); @@ -274,16 +291,19 @@ public class DQBomImportService { log.debug("电气bom导入excel,第{}行,处理前:{}", rowNum.get(), JSON.toJSONString(dQbomExcelVO)); dQbomExcelVO.setRowNum(rowNum.get()); - if (StrUtil.isBlank(dQbomExcelVO.getMaterialNo())) { + if (dQbomExcelVO.getProjectType().equals("T")) { BomNewDQbomParentEntity p = dQBomParentService.lambdaQuery() .eq(BomNewDQbomParentEntity::getMaterialName, dQbomExcelVO.getMaterialName()) .orderByDesc(BomNewDQbomParentEntity::getRowId) - .list() - .stream().findFirst().orElse(null); + .last(" limit 1") + .one(); if (p != null) { dQbomExcelVO.setMaterialNo(p.getMaterialNo()); + dQbomExcelVO.setDrawingNo(p.getMaterialNo()); } else { - dQbomExcelVO.setMaterialNo(BomConstant.DRAWING_NO_TEMPORARY_PREFIX + IdWorker.getIdStr()); + String id = BomConstant.DRAWING_NO_TEMPORARY_PREFIX + System.currentTimeMillis(); + dQbomExcelVO.setMaterialNo(id); + dQbomExcelVO.setDrawingNo(id); } } diff --git a/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/service/DQBomParentService.java b/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/service/DQBomParentService.java index 410000ae..34c26d0c 100644 --- a/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/service/DQBomParentService.java +++ b/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/service/DQBomParentService.java @@ -16,11 +16,12 @@ import java.util.List; @Service public class DQBomParentService extends ServiceImpl { - public BomNewDQbomParentEntity getLastVersion(String materialNo) { - return this.lambdaQuery().eq(BomNewDQbomParentEntity::getLastVersionIs, 1) + public BomNewDQbomParentEntity getLatestByMaterialNo(String materialNo) { + return this.lambdaQuery() .eq(BomNewDQbomParentEntity::getMaterialNo, materialNo) - .list() - .stream().findFirst().orElse(null); + .orderByDesc(BomNewDQbomParentEntity::getRowId) + .last("limit 1") + .one(); } public void setLastVersionIs0(List materialNo) {