diff --git a/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/api/user/DQBomApi.java b/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/api/user/DQBomApi.java index 1208a21e..5cd096c5 100644 --- a/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/api/user/DQBomApi.java +++ b/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/api/user/DQBomApi.java @@ -7,13 +7,11 @@ import com.google.common.collect.ImmutableList; 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.bomnew.pojo.query.BomExceptionQuery; import com.nflg.product.bomnew.pojo.query.BomNewDQbomPageQuery; import com.nflg.product.bomnew.pojo.query.BomNewDQbomQuery; import com.nflg.product.bomnew.pojo.query.BomNewDQbomSaveQuery; -import com.nflg.product.bomnew.pojo.vo.BomDQbomEditDetailVO; -import com.nflg.product.bomnew.pojo.vo.BomNewDQbomVO; -import com.nflg.product.bomnew.pojo.vo.DQbomExcelVO; -import com.nflg.product.bomnew.pojo.vo.OperationErrorMsgVO; +import com.nflg.product.bomnew.pojo.vo.*; import com.nflg.product.bomnew.service.DQBomImportService; import com.nflg.product.bomnew.service.DQBomService; import com.nflg.product.bomnew.util.EecExcelUtil; @@ -227,4 +225,15 @@ public class DQBomApi extends BaseApi { public ResultVO editDetail(@Valid @RequestParam("rowId") @NotNull Long rowId, @Valid @RequestParam("bomRowId") @NotNull Long bomRowId) { return ResultVO.success(dQBomService.editDetail(rowId, bomRowId)); } + + /** + * 获取节点异常状态 + * @param query query + * @return 节点异常状态 + */ + @PostMapping("getBomException") + @ApiOperation("获取节点异常状态") + public ResultVO> getBomException(@Valid @RequestBody @NotEmpty List query) { + return ResultVO.success(dQBomService.getBomException(query)); + } } diff --git a/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/pojo/query/BomExceptionQuery.java b/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/pojo/query/BomExceptionQuery.java new file mode 100644 index 00000000..85a9bd8a --- /dev/null +++ b/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/pojo/query/BomExceptionQuery.java @@ -0,0 +1,33 @@ +package com.nflg.product.bomnew.pojo.query; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.experimental.Accessors; + +import javax.validation.constraints.NotNull; +import java.io.Serializable; + +/** + * @author 曹鹏飞 + * @date 2024/4/24 14:24:21 + */ +@Data +@Accessors(chain = true) +@ApiModel(value = "com-nflg-product-bomnew-pojo-new-query-BomExceptionQuery") +public class BomExceptionQuery implements Serializable { + + /** + * bomRowId + */ + @ApiModelProperty(value = "bomRowId", required = true) + @NotNull + protected Long bomRowId; + + /** + * rowId + */ + @ApiModelProperty(value = "rowId", required = true) + @NotNull + protected Long rowId; +} diff --git a/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/pojo/vo/BomExceptionVO.java b/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/pojo/vo/BomExceptionVO.java new file mode 100644 index 00000000..688404fc --- /dev/null +++ b/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/pojo/vo/BomExceptionVO.java @@ -0,0 +1,37 @@ +package com.nflg.product.bomnew.pojo.vo; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.experimental.Accessors; + +import java.io.Serializable; + +/** + * @author 曹鹏飞 + * @date 2024/4/24 13:32:57 + */ +@Data +@Accessors(chain = true) +@ApiModel(value = "com-nflg-product-bomnew-pojo-new-vo-BomExceptionVO") +public class BomExceptionVO implements Serializable { + + /** + * bom行编号 + */ + @ApiModelProperty(value = "bom行编号") + public Long bomRowId; + + /** + * 物料编码 + */ + @ApiModelProperty(value = "物料编码") + public String materialNo; + + /** + * 异常状态 + * @see com.nflg.product.bomnew.constant.EBomExceptionStatusEnum + */ + @ApiModelProperty(value = "异常状态") + private Integer exceptionStatus = -1; +} 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 76f9b2a2..e73652b7 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 @@ -2,6 +2,7 @@ package com.nflg.product.bomnew.service; import cn.hutool.core.collection.CollUtil; import cn.hutool.core.util.NumberUtil; +import cn.hutool.core.util.RandomUtil; import cn.hutool.core.util.StrUtil; import com.alibaba.fastjson.JSON; import com.baomidou.mybatisplus.core.toolkit.IdWorker; @@ -138,7 +139,7 @@ public class DQBomImportService { //BomNewDQbomParentEntity oldParent = dQBomParentService.getLatestByMaterialNo(parent.getMaterialNo()); boolean isSame = true; if (Objects.isNull(oldParent)) { - return isSame; + return false; } isSame = Objects.equals(parent.getMaterialUnit(), oldParent.getMaterialUnit()) && NumberUtil.equals(parent.getNum(), oldParent.getNum()) @@ -176,14 +177,14 @@ public class DQBomImportService { log.debug("checkInconsistentData,entity:" + JsonUtil.toJson(child)); List oldChildren = dQBomChildService.getBom(parentRowId, child.getMaterialNo()); boolean isSame = true; - if (CollUtil.isEmpty(oldChildren)) return isSame; + if (CollUtil.isEmpty(oldChildren)) return false; BomNewDQbomVO 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 isSame; + return false; } } isSame = Objects.equals(child.getMaterialUnit(), oldChild.getMaterialUnit()) @@ -364,7 +365,7 @@ public class DQBomImportService { dQbomExcelVO.setRowNum(rowNum.get()); if (dQbomExcelVO.getProjectType().equals("T")) { - long id = System.currentTimeMillis(); + String id = RandomUtil.randomNumbers(9); dQbomExcelVO.setMaterialNo(BomConstant.NO_TEMPORARY_PREFIX + id); dQbomExcelVO.setDrawingNo(BomConstant.NO_TEMPORARY_PREFIX + id); if (StrUtil.isBlank(dQbomExcelVO.getMaterialUnit())) { diff --git a/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/service/DQBomService.java b/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/service/DQBomService.java index 1f01f992..885d1c0f 100644 --- a/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/service/DQBomService.java +++ b/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/service/DQBomService.java @@ -12,7 +12,6 @@ import cn.hutool.extra.spring.SpringUtil; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.toolkit.IdWorker; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; -import com.google.common.collect.Sets; import com.nflg.product.base.core.conmon.util.SessionUtil; import com.nflg.product.bomnew.constant.*; import com.nflg.product.bomnew.pojo.dto.sap.impart2.ImportSapParamDTO; @@ -21,13 +20,11 @@ import com.nflg.product.bomnew.pojo.entity.BomNewDQbomChildEntity; import com.nflg.product.bomnew.pojo.entity.BomNewDQbomParentEntity; import com.nflg.product.bomnew.pojo.entity.BomNewPbomChildEntity; import com.nflg.product.bomnew.pojo.entity.BomNewPbomParentEntity; +import com.nflg.product.bomnew.pojo.query.BomExceptionQuery; import com.nflg.product.bomnew.pojo.query.BomNewDQbomPageQuery; import com.nflg.product.bomnew.pojo.query.BomNewDQbomQuery; import com.nflg.product.bomnew.pojo.query.BomNewDQbomSaveQuery; -import com.nflg.product.bomnew.pojo.vo.BaseMaterialVO; -import com.nflg.product.bomnew.pojo.vo.BomDQbomEditDetailVO; -import com.nflg.product.bomnew.pojo.vo.BomNewDQbomVO; -import com.nflg.product.bomnew.pojo.vo.DQbomExcelVO; +import com.nflg.product.bomnew.pojo.vo.*; import com.nflg.product.bomnew.util.BomUtil; import com.nflg.product.bomnew.util.VUtils; import com.nflg.product.bomnew.util.VersionUtil; @@ -253,15 +250,17 @@ public class DQBomService { //修改数据 // VUtils.isTure(!SessionUtil.getUserCode().equals(parent.getCreatedBy())).throwMessage("不能修改他人的数据"); - if (CollUtil.isEmpty(query.getChildren())) { - dQBomChildService.deleteAllChildren(parent.getRowId()); - return query; - } //删除 dQBomChildService.deleteAllChildren(parent.getRowId()); - parent.setBomExist(1); parent.setModifyTime(LocalDateTime.now()); - dQBomParentService.updateById(parent); + if (CollUtil.isEmpty(query.getChildren())) { + //dQBomChildService.deleteAllChildren(parent.getRowId()); + parent.setBomExist(0); + dQBomParentService.saveOrUpdate(parent); + return query; + } + parent.setBomExist(1); + dQBomParentService.saveOrUpdate(parent); } //处理child List children = Convert.toList(BomNewDQbomChildEntity.class, query.getChildren()); @@ -271,6 +270,9 @@ public class DQBomService { c.setRowId(IdWorker.getId()); c.setCreatedBy(SessionUtil.getUserCode()); c.setCreatedName(SessionUtil.getRealName()); + String id = RandomUtil.randomNumbers(9); + c.setMaterialNo(BomConstant.NO_TEMPORARY_PREFIX + id); + c.setDrawingNo(BomConstant.NO_TEMPORARY_PREFIX + id); } else { c.setModifyTime(LocalDateTime.now()); } @@ -327,6 +329,11 @@ public class DQBomService { .set(BomNewDQbomParentEntity::getEditStatus, EbomEditStatusEnum.HANDLER_FINISHED.getValue()) .set(BomNewDQbomParentEntity::getModifyTime, LocalDateTime.now()) .update(); + dQBomChildService.lambdaUpdate() + .eq(BomNewDQbomChildEntity::getParentRowId, query.getParent().getRowId()) + .set(BomNewDQbomChildEntity::getEditStatus, EbomEditStatusEnum.HANDLER_FINISHED.getValue()) + .set(BomNewDQbomChildEntity::getModifyTime, LocalDateTime.now()) + .update(); //checkException(CollUtil.toList(query.getParent().getRowId())); } @@ -393,15 +400,23 @@ public class DQBomService { } public BomDQbomEditDetailVO editDetail(Long rowId, Long bomRowId) { + VUtils.isTure(Objects.isNull(rowId) && Objects.isNull(bomRowId)).throwMessage("无效的数据"); + BomDQbomEditDetailVO vo = new BomDQbomEditDetailVO(); - BomNewDQbomParentEntity parent = dQBomParentService.getById(bomRowId); - BomNewDQbomChildEntity child = dQBomChildService.getById(rowId); - VUtils.isTure(Objects.isNull(parent) && Objects.isNull(child)).throwMessage("无效的数据"); - if (!Objects.isNull(parent)) { + if (bomRowId == 0) { + BomNewDQbomChildEntity child = dQBomChildService.getById(rowId); + BomNewDQbomVO p = Convert.convert(BomNewDQbomVO.class, child); + p.setRootIs(0); + p.setUserRootIs(0); + p.setRowId(IdWorker.getId()); + p.setCreatedTime(LocalDateTime.now()); + p.setCreatedBy(SessionUtil.getUserCode()); + p.setModifyTime(null); + vo.setParent(p); + } else { + BomNewDQbomParentEntity parent = dQBomParentService.getById(bomRowId); vo.setParent(Convert.convert(BomNewDQbomVO.class, parent)); vo.setDatas(getChild(bomRowId)); - } else if (!Objects.isNull(child)) { - vo.setParent(Convert.convert(BomNewDQbomVO.class, child)); } return vo; } @@ -438,13 +453,17 @@ public class DQBomService { BomNewDQbomParentEntity root = dQBomParentService.getById(rootBomRowId); VUtils.isTure(Objects.isNull(root)).throwMessage("未找到数据"); + VUtils.isTure(root.getStatus() == 2).throwMessage("已转pbom不能再次转换"); + if (Objects.equals(root.getExceptionStatus(), EBomExceptionStatusEnum.OK.getValue())) { + //如果没有异常,则再进行一次异常检查,避免手动添加数据后没做异常检查就转pbom + checkException(rootBomRowId); + } VUtils.isTure(!Objects.equals(root.getExceptionStatus(), EBomExceptionStatusEnum.OK.getValue())) .throwMessage("异常状态不能转pbom"); - VUtils.isTure(root.getStatus() == 2).throwMessage("已转pbom不能再次转换"); List parents = new ArrayList<>(); List children = new ArrayList<>(); - buildPbom(root, parents, children); + buildTree(root, parents, children); dQBomParentService.updateBatchById(parents); dQBomChildService.updateBatchById(children); savePbomParents(parents); @@ -467,12 +486,18 @@ public class DQBomService { c.setModifyTime(null); c.setIdentityNo(c.getParentRowId() + "_" + c.getRowId()); if (CollUtil.isNotEmpty(materialBaseInfos)) { - BaseMaterialVO materialVO = materialBaseInfos.stream().filter(m -> m.getMaterialNo().equals(c.getMaterialNo())).findFirst().orElse(null); + BaseMaterialVO materialVO = materialBaseInfos.stream() + .filter(m -> m.getMaterialNo().equals(c.getMaterialNo())) + .findFirst() + .orElse(null); if (!Objects.isNull(materialVO)) { c.setMaterialCategoryCode(materialVO.getMaterialCategoryCode()); } } - BomNewDQbomParentEntity parent = parents.stream().filter(p -> p.getMaterialNo().equals(c.getMaterialNo())).findFirst().orElse(null); + BomNewDQbomParentEntity parent = parents.stream() + .filter(p -> p.getMaterialNo().equals(c.getMaterialNo())) + .findFirst() + .orElse(null); if (!Objects.isNull(parent)) { c.setBomVersionRowId(parent.getRowId()); } @@ -496,7 +521,7 @@ public class DQBomService { bomNewPbomParentService.saveBatch(pparents); } - private void buildPbom(BomNewDQbomParentEntity parent, List parents, List children) { + private void buildTree(BomNewDQbomParentEntity parent, List parents, List children) { parent.setStatus(2); parent.setConvertToPbomTime(LocalDateTime.now()); parent.setModifyTime(LocalDateTime.now()); @@ -521,24 +546,25 @@ public class DQBomService { VUtils.isTure(true).throwMessage(StrUtil.format("{}的当前版本为{},比pbom中版本{}低", parent.getMaterialNo() , parent.getCurrentVersion(), pp.getCurrentVersion())); } else { - if (pp.getStatus() == 4) { - List dqChildren = getChild(parent.getRowId()); - Set pChildren = bomNewPbomChildService.lambdaQuery() - .select(BomNewPbomChildEntity::getMaterialNo) - .eq(BomNewPbomChildEntity::getParentRowId, pp.getRowId()) - .list() - .stream() - .map(BomNewPbomChildEntity::getMaterialNo) - .collect(Collectors.toSet()); - if (dqChildren.size() != pChildren.size() - || !Sets.difference(dqChildren.stream().map(BomNewDQbomVO::getMaterialNo).collect(Collectors.toSet()), pChildren).isEmpty()) { - parent.setCurrentVersion(VersionUtil.getNextVersion(parent.getCurrentVersion())); - pp.setLastVersionIs(0); - bomNewPbomParentService.updateById(pp); - } + if (pp.getStatus() >= 4) { + // List dqChildren = getChild(parent.getRowId()); + // Set pChildren = bomNewPbomChildService.lambdaQuery() + // .select(BomNewPbomChildEntity::getMaterialNo) + // .eq(BomNewPbomChildEntity::getParentRowId, pp.getRowId()) + // .list() + // .stream() + // .map(BomNewPbomChildEntity::getMaterialNo) + // .collect(Collectors.toSet()); + // if (dqChildren.size() != pChildren.size() + // || !Sets.difference(dqChildren.stream().map(BomNewDQbomVO::getMaterialNo).collect(Collectors.toSet()), pChildren).isEmpty()) { + parent.setCurrentVersion(VersionUtil.getNextVersion(pp.getCurrentVersion())); + pp.setLastVersionIs(0); + bomNewPbomParentService.updateById(pp); + // } } else { + parent.setCurrentVersion(pp.getCurrentVersion()); bomNewPbomParentService.getBaseMapper().deleteById(pp.getRowId()); - bomNewPbomChildService.getBaseMapper().delete(new LambdaQueryWrapper() + bomNewPbomChildService.getBaseMapper().delete(bomNewPbomChildService.lambdaQuery() .eq(BomNewPbomChildEntity::getParentRowId, pp.getRowId())); } } @@ -548,7 +574,7 @@ public class DQBomService { .in(BomNewDQbomParentEntity::getMaterialNo, cc.stream().map(BomNewDQbomChildEntity::getMaterialNo).collect(Collectors.toList())) .eq(BomNewDQbomParentEntity::getStatus, 1) .list() - .forEach(p -> buildPbom(p, parents, children)); + .forEach(p -> buildTree(p, parents, children)); } private int versionCompare(String version1, String version2) { @@ -556,4 +582,34 @@ public class DQBomService { if (StrUtil.isBlank(version2)) return -1; return Integer.parseInt(version1.substring(1)) - Integer.parseInt(version2.substring(1)); } + + public List getBomException(List query) { + List datas = new ArrayList<>(); + for (int index = 0, count = query.size(); index < count; index++) { + BomExceptionQuery bom = query.get(index); + if (index == 0) { + checkException(bom.getBomRowId()); + + BomNewDQbomParentEntity parent = dQBomParentService.getById(bom.getBomRowId()); + BomExceptionVO vo = new BomExceptionVO(); + vo.setBomRowId(bom.getBomRowId()); + vo.setMaterialNo(parent.getMaterialNo()); + vo.setExceptionStatus(parent.getExceptionStatus()); + datas.add(vo); + } else { + BomExceptionVO vo = new BomExceptionVO(); + vo.setBomRowId(bom.getBomRowId()); + BomNewDQbomChildEntity child = dQBomChildService.getById(bom.getRowId()); + vo.setMaterialNo(child.getMaterialNo()); + if (Objects.equals(child.getExceptionStatus(), EBomExceptionStatusEnum.OK.getValue())) { + BomNewDQbomParentEntity parent = dQBomParentService.getById(bom.getBomRowId()); + vo.setExceptionStatus(parent.getExceptionStatus()); + } else { + vo.setExceptionStatus(child.getExceptionStatus()); + } + } + } + return datas; + } + } diff --git a/nflg_project_dev/nflg-bom-new/src/main/resources/mapper/master/BomNewDQbomParentMapper.xml b/nflg_project_dev/nflg-bom-new/src/main/resources/mapper/master/BomNewDQbomParentMapper.xml index 19752668..6f5b2fe6 100644 --- a/nflg_project_dev/nflg-bom-new/src/main/resources/mapper/master/BomNewDQbomParentMapper.xml +++ b/nflg_project_dev/nflg-bom-new/src/main/resources/mapper/master/BomNewDQbomParentMapper.xml @@ -30,7 +30,7 @@