From b1c757938b2dfa4a758a1ab91031b686363ceb12 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9B=B9=E9=B9=8F=E9=A3=9E?= Date: Mon, 22 Apr 2024 17:17:57 +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/api/user/DQBomApi.java | 19 +++++--- .../product/bomnew/pojo/vo/BomNewDQbomVO.java | 9 ++-- .../service/BomNewPbomParentService.java | 8 ++-- .../bomnew/service/DQBomImportService.java | 4 ++ .../product/bomnew/service/DQBomService.java | 43 ++++++++++--------- .../mapper/master/BomNewDQbomParentMapper.xml | 1 + 6 files changed, 52 insertions(+), 32 deletions(-) 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 e64e8bc2..66951508 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 @@ -1,5 +1,7 @@ package com.nflg.product.bomnew.api.user; +import cn.hutool.core.date.LocalDateTimeUtil; +import cn.hutool.core.util.StrUtil; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.google.common.collect.ImmutableList; import com.mzt.logapi.context.LogRecordContext; @@ -29,6 +31,7 @@ import javax.validation.Valid; import javax.validation.constraints.NotEmpty; import javax.validation.constraints.NotNull; import java.io.IOException; +import java.time.LocalDateTime; import java.util.List; /** @@ -99,6 +102,12 @@ public class DQBomApi extends BaseApi { @PostMapping("getPageList") @ApiOperation("分页查询数据") public ResultVO> getPageList(@Valid @RequestBody @NotNull BomNewDQbomPageQuery query) { + if (query.getStatus() == 2) { + if (StrUtil.isBlank(query.getStartDate()) && StrUtil.isBlank(query.getEndDate())) { + query.setStartDate(LocalDateTimeUtil.format(LocalDateTime.now().plusDays(-2), "yyyy-MM-dd")); + query.setEndDate(LocalDateTimeUtil.format(LocalDateTime.now().plusDays(1), "yyyy-MM-dd")); + } + } return ResultVO.success(dQBomService.getPageList(query)); } @@ -156,10 +165,9 @@ public class DQBomApi extends BaseApi { */ @PostMapping("exportBom") @ApiOperation("导出bom") - public ResultVO exportBom(@Valid @RequestBody @NotEmpty List rootBomRowIds) throws IOException { + public void exportBom(@Valid @RequestBody @NotEmpty List rootBomRowIds, HttpServletResponse response) throws IOException { List data = dQBomService.exportBom(rootBomRowIds.get(0)); - EecExcelUtil.export(response, data, DQbomExcelVO.class, "专用bom正式表"); - return ResultVO.success(); + EecExcelUtil.export(response, data, DQbomExcelVO.class, "电气专用bom"); } /** @@ -205,9 +213,8 @@ public class DQBomApi extends BaseApi { */ @PostMapping("importToSAP") @ApiOperation("导入到SAP") - public ResultVO importToSAP(@Valid @RequestBody @NotEmpty List rootBomRowIds) { - dQBomService.importToSAP(rootBomRowIds.get(0)); - return ResultVO.success(); + public ResultVO importToSAP(@Valid @RequestBody @NotEmpty List rootBomRowIds) { + return dQBomService.importToSAP(rootBomRowIds.get(0)); } /** diff --git a/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/pojo/vo/BomNewDQbomVO.java b/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/pojo/vo/BomNewDQbomVO.java index 397bc187..6230a13f 100644 --- a/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/pojo/vo/BomNewDQbomVO.java +++ b/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/pojo/vo/BomNewDQbomVO.java @@ -1,6 +1,5 @@ package com.nflg.product.bomnew.pojo.vo; -import com.baomidou.mybatisplus.annotation.TableField; import com.nflg.product.bomnew.pojo.entity.BomNewDQbomChildEntity; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; @@ -93,14 +92,18 @@ public class BomNewDQbomVO extends BomNewDQbomChildEntity implements Serializabl /** * 是否有子节点: 0-否 1-是 */ - @TableField(value = "bom_exist") @ApiModelProperty(value = "是否有子节点") private Integer bomExist; /** * 是否最新版:0-否 1-是 */ - @TableField(value = "last_version_is") @ApiModelProperty(value = "是否最新版") private Integer lastVersionIs = 1; + + /** + * 导入SAP状态,1-未导入;3-已导入 + */ + @ApiModelProperty(value = "导入SAP状态,1-未导入;3-已导入") + private Integer sapState; } diff --git a/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/service/BomNewPbomParentService.java b/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/service/BomNewPbomParentService.java index fd085379..676d8f82 100644 --- a/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/service/BomNewPbomParentService.java +++ b/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/service/BomNewPbomParentService.java @@ -256,9 +256,11 @@ public class BomNewPbomParentService extends ServiceImpl materialNos = parentChild.stream().map(BaseMaterialVO::getMaterialNo).collect(Collectors.toList()); if (CollUtil.isNotEmpty(materialNos)) { List list = this.lambdaQuery().in(BomNewPbomParentEntity::getMaterialNo, materialNos) - .eq(!PBomStatusEnum.PUBLISH.equalsValue(parent.getStatus()), BomNewPbomParentEntity::getLastVersionIs, 1) - .lt(!PBomStatusEnum.PUBLISH.equalsValue(parent.getStatus()),BomNewPbomParentEntity::getStatus,PBomStatusEnum.PUBLISH.getValue()) - .eq(PBomStatusEnum.PUBLISH.equalsValue(parent.getStatus()),BomNewPbomParentEntity::getStatus, PBomStatusEnum.PUBLISH.getValue()) + // .eq(PBomStatusEnum.PUBLISH.equalsValue(parent.getStatus()), BomNewPbomParentEntity::getLastVersionIs, 1) + // .lt(!PBomStatusEnum.PUBLISH.equalsValue(parent.getStatus()),BomNewPbomParentEntity::getStatus,PBomStatusEnum.PUBLISH.getValue()) + // .eq(PBomStatusEnum.PUBLISH.equalsValue(parent.getStatus()),BomNewPbomParentEntity::getStatus, PBomStatusEnum.PUBLISH.getValue()) + .eq(PBomStatusEnum.PUBLISH.getValue() > parent.getStatus(), BomNewPbomParentEntity::getLastVersionIs, 1) + .gt(PBomStatusEnum.PUBLISH.getValue() <= parent.getStatus(), BomNewPbomParentEntity::getStatus, PBomStatusEnum.PUBLISH.getValue()) .list(); Map bomListMap= list.parallelStream() 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 da31092c..bdc32901 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 @@ -92,6 +92,10 @@ public class DQBomImportService { } } + private void checkData(List datas) { + + } + public void save() { Pair, List> pcs = BOMMAP.get(SessionUtil.getUserCode()); VUtils.isTure(pcs == null).throwMessage("数据已丢失,请重新导入"); 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 d433df16..a935274f 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 @@ -39,6 +39,7 @@ import org.springframework.transaction.annotation.Transactional; import javax.annotation.Resource; import java.time.LocalDateTime; import java.util.*; +import java.util.concurrent.CompletableFuture; import java.util.stream.Collectors; /** @@ -223,11 +224,8 @@ public class DQBomService { public void save(BomNewDQbomSaveQuery query) { BomNewDQbomParentEntity parent = new BomNewDQbomParentEntity(); BeanUtil.copyProperties(query.getParent(), parent); - //BomNewDQbomChildEntity child; - List liParents = new ArrayList<>(); - - if (Objects.isNull(parent.getRowId())) { + if (Objects.isNull(parent.getRowId()) || parent.getRowId() == 0) { //新增父级节点 BomNewDQbomParentEntity oldParent = dQBomParentService.lambdaQuery().eq(BomNewDQbomParentEntity::getMaterialNo, parent.getMaterialNo()) .eq(BomNewDQbomParentEntity::getLastVersionIs, 1) @@ -247,7 +245,7 @@ public class DQBomService { parent.setCreatedName(SessionUtil.getRealName()); parent.setCreatedJob(userRoleService.technician() ? UserJobEnum.ENGINEER.getValue() : UserJobEnum.DESIGNER.getValue()); parent.setSource(2); - liParents.add(parent); + dQBomParentService.save(parent); } else { //修改数据 VUtils.isTure(!SessionUtil.getUserCode().equals(parent.getCreatedBy())).throwMessage("不能修改他人的数据"); @@ -257,16 +255,10 @@ public class DQBomService { return; } //删除 - // dQBomChildService.deleteNotIn(parent.getRowId(), - // query.getChildren().stream() - // .map(BomNewDQbomSaveVO::getRowId) - // .filter(d -> ObjectUtil.isNotNull(d) && d > 0L) - // .collect(Collectors.toList())); dQBomChildService.deleteAllChildren(parent.getRowId()); parent.setBomExist(1); parent.setModifyTime(LocalDateTime.now()); - - //child = dQBomChildService.getById(query.getParent().getBomChildRowId()); + dQBomParentService.updateById(parent); } //处理child List children = Convert.toList(BomNewDQbomChildEntity.class, query.getChildren()); @@ -383,7 +375,7 @@ public class DQBomService { } } - public void importToSAP(Long rootBomRowId) { + public ResultVO importToSAP(Long rootBomRowId) { BomNewDQbomParentEntity root = dQBomParentService.getById(rootBomRowId); VUtils.isTure(Objects.isNull(root)).throwMessage("数据不存在"); VUtils.isTure(root.getRootIs() == 0).throwMessage("请选择根节点"); @@ -416,6 +408,7 @@ public class DQBomService { parentEntity.setSapTime(LocalDateTimeUtil.now()); dQBomParentService.updateById(parentEntity); } + return resultVO; } public BomDQbomEditDetailVO editDetail(Long rowId, Long bomRowId) { @@ -475,7 +468,10 @@ public class DQBomService { dQBomChildService.updateBatchById(children); savePbomParents(parents); savePbomChildren(children, parents); - importToSAP(root.getRowId()); + + CompletableFuture.runAsync(() -> { + importToSAP(root.getRowId()); + }); } private void savePbomChildren(List children, List parents) { @@ -513,6 +509,8 @@ public class DQBomService { p.setFacCode(FactoryCodeEnum.FACTORY_1010.getValue()); p.setSourceRowId(p.getRowId()); p.setLevelNum(parents.stream().filter(ps -> Objects.equals(ps.getRowId(), p.getRowId())).findFirst().get().getLevel()); + p.setReleaseTime(LocalDateTime.now()); + p.setReleaseUserName(SessionUtil.getUserName()); }); bomNewPbomParentService.saveBatch(pparents); } @@ -520,12 +518,17 @@ public class DQBomService { private void buildPbom(BomNewDQbomParentEntity parent, List parents, List children) { parent.setStatus(2); parent.setConvertToPbomTime(LocalDateTime.now()); + parent.setModifyTime(LocalDateTime.now()); parents.add(parent); LambdaQueryWrapper wrapper = new LambdaQueryWrapper<>(); wrapper.eq(BomNewDQbomParentEntity::getMaterialNo, parent.getMaterialNo()); wrapper.ne(BomNewDQbomParentEntity::getRowId, parent.getRowId()); dQBomParentService.getBaseMapper().delete(wrapper); List cc = dQBomChildService.getByParentRowId(parent.getRowId()); + cc.forEach(c -> { + c.setStatus(2); + c.setModifyTime(LocalDateTime.now()); + }); children.addAll(cc); BomNewPbomParentEntity pp = bomNewPbomParentService.lambdaQuery().eq(BomNewPbomParentEntity::getMaterialNo, parent.getMaterialNo()) @@ -557,14 +560,14 @@ public class DQBomService { bomNewPbomChildService.getBaseMapper().delete(new LambdaQueryWrapper() .eq(BomNewPbomChildEntity::getParentRowId, pp.getRowId())); } - //处理子级 - dQBomParentService.lambdaQuery() - .in(BomNewDQbomParentEntity::getMaterialNo, cc.stream().map(BomNewDQbomChildEntity::getMaterialNo).collect(Collectors.toList())) - .eq(BomNewDQbomParentEntity::getStatus, 1) - .list() - .forEach(p -> buildPbom(p, parents, children)); } } + //处理子级 + dQBomParentService.lambdaQuery() + .in(BomNewDQbomParentEntity::getMaterialNo, cc.stream().map(BomNewDQbomChildEntity::getMaterialNo).collect(Collectors.toList())) + .eq(BomNewDQbomParentEntity::getStatus, 1) + .list() + .forEach(p -> buildPbom(p, parents, children)); } private int versionCompare(String version1, String version2) { 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 999c7542..19752668 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 @@ -65,6 +65,7 @@ if(c.exception_status = 1, ifnull(p.exception_status, 1), c.exception_status) exception_status, ifnull(p.exception_tag, c.exception_tag) exception_tag, ifnull(p.bom_exist, 0) bom_exist, + ifnull(p.sap_state, 1) sap_state, c.* FROM t_bom_new_dqbom_parent p RIGHT JOIN t_bom_new_dqbom_child c ON p.material_no = c.material_no