From affa1426b86a3d4bf069d0aa3be3751b24d72e5b 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 18:21:08 +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 | 11 +- .../product/bomnew/constant/BomConstant.java | 3 +- .../mapper/master/BomNewDQbomChildMapper.java | 2 + .../pojo/entity/BomNewDQbomBaseEntity.java | 64 +++++++ .../pojo/entity/BomNewDQbomChildEntity.java | 79 ++++---- .../pojo/entity/BomNewDQbomParentEntity.java | 79 ++++---- .../pojo/query/BomNewDQbomSaveQuery.java | 6 +- .../product/bomnew/pojo/vo/BomNewDQbomVO.java | 28 +++ .../product/bomnew/pojo/vo/DQbomExcelVO.java | 8 + .../BomNewDQbomExceptionCheckService.java | 4 +- .../bomnew/service/DQBomChildService.java | 4 + .../bomnew/service/DQBomImportService.java | 180 +++++++++++++----- .../bomnew/service/DQBomParentService.java | 5 +- .../product/bomnew/service/DQBomService.java | 47 ++--- .../service/domain/EBom/EBomToPBom.java | 7 +- .../mapper/master/BomNewDQbomChildMapper.xml | 8 + 16 files changed, 350 insertions(+), 185 deletions(-) create mode 100644 nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/pojo/entity/BomNewDQbomBaseEntity.java 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 66951508..1208a21e 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 @@ -87,10 +87,10 @@ public class DQBomApi extends BaseApi { * @return */ @ApiOperation("确认从excel导入数据") - @PostMapping("importBomSave") + @GetMapping("importBomConfirm") @LogRecord(success = "电气BOM-确认导入,操作结果:{{#_ret}}", bizNo = "", type = "电气BOM导入") - public ResultVO importBomSave() { - dqBomImportService.save(); + public ResultVO importBomConfirm(@Valid @RequestParam("save") @NotNull Boolean save) { + dqBomImportService.importBomConfirm(save); return ResultVO.success(); } @@ -129,9 +129,8 @@ public class DQBomApi extends BaseApi { */ @PostMapping("temporary") @ApiOperation("暂存") - public ResultVO temporary(@Valid @RequestBody @NotNull BomNewDQbomSaveQuery query) { - dQBomService.save(query); - return ResultVO.success(); + public ResultVO temporary(@Valid @RequestBody @NotNull BomNewDQbomSaveQuery query) { + return ResultVO.success(dQBomService.save(query)); } /** diff --git a/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/constant/BomConstant.java b/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/constant/BomConstant.java index 75424e1e..2c53a29f 100644 --- a/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/constant/BomConstant.java +++ b/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/constant/BomConstant.java @@ -9,6 +9,5 @@ public class BomConstant { public static final String SAP_YDBOM="1"; - public static final String MATERIAL_NO_TEMPORARY_PREFIX = "TN"; - public static final String DRAWING_NO_TEMPORARY_PREFIX = "TD"; + public static final String NO_TEMPORARY_PREFIX = "T"; } diff --git a/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/mapper/master/BomNewDQbomChildMapper.java b/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/mapper/master/BomNewDQbomChildMapper.java index 7786b78c..88ff4ef5 100644 --- a/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/mapper/master/BomNewDQbomChildMapper.java +++ b/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/mapper/master/BomNewDQbomChildMapper.java @@ -16,4 +16,6 @@ public interface BomNewDQbomChildMapper extends BaseMapper getBomsByParentRowId(Long rowId); + + List getBom(Long parentRowId, String materialNo); } diff --git a/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/pojo/entity/BomNewDQbomBaseEntity.java b/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/pojo/entity/BomNewDQbomBaseEntity.java new file mode 100644 index 00000000..19fc04cd --- /dev/null +++ b/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/pojo/entity/BomNewDQbomBaseEntity.java @@ -0,0 +1,64 @@ +package com.nflg.product.bomnew.pojo.entity; + +import com.baomidou.mybatisplus.annotation.IdType; +import com.baomidou.mybatisplus.annotation.TableField; +import com.baomidou.mybatisplus.annotation.TableId; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.experimental.Accessors; + +import java.io.Serializable; +import java.math.BigDecimal; + +/** + * @author 曹鹏飞 + * @date 2024/4/23 15:10:28 + */ +@Data +@Accessors(chain = true) +@ApiModel(value = "com-nflg-product-bomnew-pojo-new-entity-BomNewDQbomBaseEntity") +public class BomNewDQbomBaseEntity implements Serializable { + + /** + * 主键-雪花 + */ + @TableId(value = "row_id", type = IdType.ASSIGN_ID) + @ApiModelProperty(value = "主键-雪花") + protected Long rowId; + + /** + * 图号 + */ + @TableField(value = "drawing_no") + @ApiModelProperty(value = "图号") + protected String drawingNo; + + /** + * 物料编码 + */ + @TableField(value = "material_no") + @ApiModelProperty(value = "物料编码") + protected String materialNo; + + /** + * 单位 + */ + @TableField(value = "material_unit") + @ApiModelProperty(value = "单位") + protected String materialUnit; + + /** + * 数量 + */ + @TableField(value = "num") + @ApiModelProperty(value = "数量") + protected BigDecimal num; + + /** + * 材质 + */ + @TableField(value = "material_texture") + @ApiModelProperty(value = "材质") + protected String materialTexture; +} diff --git a/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/pojo/entity/BomNewDQbomChildEntity.java b/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/pojo/entity/BomNewDQbomChildEntity.java index 85124f1d..f5934e30 100644 --- a/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/pojo/entity/BomNewDQbomChildEntity.java +++ b/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/pojo/entity/BomNewDQbomChildEntity.java @@ -1,15 +1,12 @@ package com.nflg.product.bomnew.pojo.entity; -import com.baomidou.mybatisplus.annotation.IdType; import com.baomidou.mybatisplus.annotation.TableField; -import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableName; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; import lombok.Data; import lombok.experimental.Accessors; -import java.io.Serializable; import java.math.BigDecimal; import java.time.LocalDateTime; @@ -21,14 +18,14 @@ import java.time.LocalDateTime; @Accessors(chain = true) @ApiModel(value = "com-nflg-product-bomnew-pojo-new-entity-BomNewDQbomChildEntity") @TableName(value = "t_bom_new_dqbom_child") -public class BomNewDQbomChildEntity implements Serializable { +public class BomNewDQbomChildEntity extends BomNewDQbomBaseEntity { - /** - * 主键-雪花 - */ - @TableId(value = "row_id", type = IdType.ASSIGN_ID) - @ApiModelProperty(value = "主键-雪花") - private Long rowId; + // /** + // * 主键-雪花 + // */ + // @TableId(value = "row_id", type = IdType.ASSIGN_ID) + // @ApiModelProperty(value = "主键-雪花") + // private Long rowId; /** * 层次 @@ -65,19 +62,19 @@ public class BomNewDQbomChildEntity implements Serializable { @ApiModelProperty(value = "项目类别") private String projectType; - /** - * 图号 - */ - @TableField(value = "drawing_no") - @ApiModelProperty(value = "图号") - private String drawingNo; - - /** - * 物料编码 - */ - @TableField(value = "material_no") - @ApiModelProperty(value = "物料编码") - private String materialNo; + // /** + // * 图号 + // */ + // @TableField(value = "drawing_no") + // @ApiModelProperty(value = "图号") + // private String drawingNo; + // + // /** + // * 物料编码 + // */ + // @TableField(value = "material_no") + // @ApiModelProperty(value = "物料编码") + // private String materialNo; /** * 物料名称 @@ -86,19 +83,19 @@ public class BomNewDQbomChildEntity implements Serializable { @ApiModelProperty(value = "物料名称") private String materialName; - /** - * 材质 - */ - @TableField(value = "material_texture") - @ApiModelProperty(value = "材质") - private String materialTexture; + // /** + // * 材质 + // */ + // @TableField(value = "material_texture") + // @ApiModelProperty(value = "材质") + // private String materialTexture; - /** - * 单位 - */ - @TableField(value = "material_unit") - @ApiModelProperty(value = "单位") - private String materialUnit; + // /** + // * 单位 + // */ + // @TableField(value = "material_unit") + // @ApiModelProperty(value = "单位") + // private String materialUnit; /** * 单重 @@ -107,12 +104,12 @@ public class BomNewDQbomChildEntity implements Serializable { @ApiModelProperty(value = "单重") private BigDecimal unitWeight; - /** - * 数量 - */ - @TableField(value = "num") - @ApiModelProperty(value = "数量") - private BigDecimal num; + // /** + // * 数量 + // */ + // @TableField(value = "num") + // @ApiModelProperty(value = "数量") + // private BigDecimal num; /** * 总重 diff --git a/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/pojo/entity/BomNewDQbomParentEntity.java b/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/pojo/entity/BomNewDQbomParentEntity.java index c9af564d..2515cdb0 100644 --- a/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/pojo/entity/BomNewDQbomParentEntity.java +++ b/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/pojo/entity/BomNewDQbomParentEntity.java @@ -1,15 +1,12 @@ package com.nflg.product.bomnew.pojo.entity; -import com.baomidou.mybatisplus.annotation.IdType; import com.baomidou.mybatisplus.annotation.TableField; -import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableName; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; import lombok.Data; import lombok.experimental.Accessors; -import java.io.Serializable; import java.math.BigDecimal; import java.time.LocalDateTime; @@ -21,14 +18,14 @@ import java.time.LocalDateTime; @Accessors(chain = true) @ApiModel(value = "com-nflg-product-bomnew-pojo-new-entity-BomNewDQbomParentEntity") @TableName(value = "t_bom_new_dqbom_parent") -public class BomNewDQbomParentEntity implements Serializable { +public class BomNewDQbomParentEntity extends BomNewDQbomBaseEntity { - /** - * 主键-雪花 - */ - @TableId(value = "row_id", type = IdType.ASSIGN_ID) - @ApiModelProperty(value = "主键-雪花") - private Long rowId; + // /** + // * 主键-雪花 + // */ + // @TableId(value = "row_id", type = IdType.ASSIGN_ID) + // @ApiModelProperty(value = "主键-雪花") + // private Long rowId; /** * 层次 @@ -37,19 +34,19 @@ public class BomNewDQbomParentEntity implements Serializable { @ApiModelProperty(value = "层次") private Integer level; - /** - * 图号 - */ - @TableField(value = "drawing_no") - @ApiModelProperty(value = "图号") - private String drawingNo; - - /** - * 物料编码 - */ - @TableField(value = "material_no") - @ApiModelProperty(value = "物料编码") - private String materialNo; + // /** + // * 图号 + // */ + // @TableField(value = "drawing_no") + // @ApiModelProperty(value = "图号") + // private String drawingNo; + // + // /** + // * 物料编码 + // */ + // @TableField(value = "material_no") + // @ApiModelProperty(value = "物料编码") + // private String materialNo; /** * 物料名称 @@ -58,19 +55,19 @@ public class BomNewDQbomParentEntity implements Serializable { @ApiModelProperty(value = "物料名称") private String materialName; - /** - * 材质 - */ - @TableField(value = "material_texture") - @ApiModelProperty(value = "材质") - private String materialTexture; + // /** + // * 材质 + // */ + // @TableField(value = "material_texture") + // @ApiModelProperty(value = "材质") + // private String materialTexture; - /** - * 单位 - */ - @TableField(value = "material_unit") - @ApiModelProperty(value = "单位") - private String materialUnit; + // /** + // * 单位 + // */ + // @TableField(value = "material_unit") + // @ApiModelProperty(value = "单位") + // private String materialUnit; /** * 单重 @@ -79,12 +76,12 @@ public class BomNewDQbomParentEntity implements Serializable { @ApiModelProperty(value = "单重") private BigDecimal unitWeight; - /** - * 数量 - */ - @TableField(value = "num") - @ApiModelProperty(value = "数量") - private BigDecimal num; + // /** + // * 数量 + // */ + // @TableField(value = "num") + // @ApiModelProperty(value = "数量") + // private BigDecimal num; /** * 总重 diff --git a/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/pojo/query/BomNewDQbomSaveQuery.java b/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/pojo/query/BomNewDQbomSaveQuery.java index 443d3e5f..c0b0a5bc 100644 --- a/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/pojo/query/BomNewDQbomSaveQuery.java +++ b/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/pojo/query/BomNewDQbomSaveQuery.java @@ -1,6 +1,6 @@ package com.nflg.product.bomnew.pojo.query; -import com.nflg.product.bomnew.pojo.vo.BomNewDQbomSaveVO; +import com.nflg.product.bomnew.pojo.vo.BomNewDQbomVO; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; import lombok.Data; @@ -24,12 +24,12 @@ public class BomNewDQbomSaveQuery implements Serializable { */ @ApiModelProperty(value = "父级") @NotNull - private BomNewDQbomSaveVO parent; + private BomNewDQbomVO parent; /** * 子级数据 */ @ApiModelProperty(value = "子级数据") @NotNull - private List children; + private List children; } 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 6230a13f..d5d83c73 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,5 +1,7 @@ package com.nflg.product.bomnew.pojo.vo; +import cn.hutool.core.util.StrUtil; +import com.nflg.product.bomnew.constant.BomConstant; import com.nflg.product.bomnew.pojo.entity.BomNewDQbomChildEntity; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; @@ -106,4 +108,30 @@ public class BomNewDQbomVO extends BomNewDQbomChildEntity implements Serializabl */ @ApiModelProperty(value = "导入SAP状态,1-未导入;3-已导入") private Integer sapState; + + /** + * 图号(显示用) + */ + @ApiModelProperty(value = "图号(显示用)") + private String drawingNoDesc; + + public String getDrawingNoDesc() { + if (StrUtil.isNotBlank(getDrawingNo()) && getDrawingNo().startsWith(BomConstant.NO_TEMPORARY_PREFIX)) { + return ""; + } + return getDrawingNo(); + } + + /** + * 物料编码(显示用) + */ + @ApiModelProperty(value = "物料编码(显示用)") + private String materialNoDesc; + + public String getMaterialNoDesc() { + if (StrUtil.isNotBlank(getMaterialNo()) && getMaterialNo().startsWith(BomConstant.NO_TEMPORARY_PREFIX)) { + return ""; + } + return getMaterialNo(); + } } 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 64cd3893..c9ff2b2c 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 @@ -1,5 +1,6 @@ package com.nflg.product.bomnew.pojo.vo; +import cn.hutool.core.util.StrUtil; import com.nflg.product.bomnew.pojo.dto.BaseImportExcelDTO; import lombok.Data; import org.ttzero.excel.annotation.ExcelColumn; @@ -28,6 +29,13 @@ public class DQbomExcelVO extends BaseImportExcelDTO { @ExcelColumn("材料") private String materialTexture; + public String getMaterialTexture() { + if (StrUtil.isBlank(materialTexture)) { + return ""; + } + return materialTexture; + } + @ExcelColumn(value = "数量") private BigDecimal num; diff --git a/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/service/BomNewDQbomExceptionCheckService.java b/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/service/BomNewDQbomExceptionCheckService.java index bf2c0384..14bd07eb 100644 --- a/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/service/BomNewDQbomExceptionCheckService.java +++ b/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/service/BomNewDQbomExceptionCheckService.java @@ -126,7 +126,7 @@ public class BomNewDQbomExceptionCheckService { if (parent.getRootIs() == 1 || parent.getUserRootIs() == 1) { if ("T".equals(parent.getProjectType())) { parent.setExceptionStatus(EBomExceptionStatusEnum.OK.getValue()); - } else if (parent.getMaterialNo().startsWith(BomConstant.MATERIAL_NO_TEMPORARY_PREFIX)) { + } else if (parent.getMaterialNo().startsWith(BomConstant.NO_TEMPORARY_PREFIX)) { status = EBomExceptionStatusEnum.EXCEPT_NO_4; } else { BaseMaterialVO materialVO = materialVOS.stream().filter(v -> v.getMaterialNo().equals(parent.getMaterialNo())) @@ -164,7 +164,7 @@ public class BomNewDQbomExceptionCheckService { EBomExceptionStatusEnum status = EBomExceptionStatusEnum.OK; if ("T".equals(child.getProjectType())) { child.setExceptionStatus(EBomExceptionStatusEnum.OK.getValue()); - } else if (child.getMaterialNo().startsWith(BomConstant.MATERIAL_NO_TEMPORARY_PREFIX)) { + } else if (child.getMaterialNo().startsWith(BomConstant.NO_TEMPORARY_PREFIX)) { status = EBomExceptionStatusEnum.EXCEPT_NO_4; } else { BaseMaterialVO materialVO = materialVOS.stream().filter(v -> v.getMaterialNo().equals(child.getMaterialNo())) diff --git a/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/service/DQBomChildService.java b/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/service/DQBomChildService.java index d51eb892..8eb4d313 100644 --- a/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/service/DQBomChildService.java +++ b/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/service/DQBomChildService.java @@ -41,4 +41,8 @@ public class DQBomChildService extends ServiceImpl getBomsByParentRowId(Long rowId) { return this.getBaseMapper().getBomsByParentRowId(rowId); } + + public List getBom(Long parentRowId, String materialNo) { + return this.getBaseMapper().getBom(parentRowId, materialNo); + } } 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 01bd937b..76f9b2a2 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 @@ -1,6 +1,7 @@ package com.nflg.product.bomnew.service; import cn.hutool.core.collection.CollUtil; +import cn.hutool.core.util.NumberUtil; import cn.hutool.core.util.StrUtil; import com.alibaba.fastjson.JSON; import com.baomidou.mybatisplus.core.toolkit.IdWorker; @@ -8,10 +9,14 @@ 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.constant.BomConstant; +import com.nflg.product.bomnew.constant.DQBomStatusEnum; +import com.nflg.product.bomnew.constant.EBomExceptionStatusEnum; +import com.nflg.product.bomnew.constant.UserJobEnum; import com.nflg.product.bomnew.pojo.dto.BaseImportExcelDTO; import com.nflg.product.bomnew.pojo.entity.BomNewDQbomChildEntity; import com.nflg.product.bomnew.pojo.entity.BomNewDQbomParentEntity; +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.util.*; @@ -74,9 +79,10 @@ public class DQBomImportService { } Pair, List> pcs = convertToBom(datas); - VUtils.isTure(CollUtil.isEmpty(pcs.getLeft())).throwMessage("所有数据都已经导入过了,请勿重复导入"); + //VUtils.isTure(CollUtil.isEmpty(pcs.getLeft())).throwMessage("所有数据都已经导入过了,请勿重复导入"); try { - checkInconsistentData(pcs.getLeft().get(0), pcs.getLeft(), pcs.getRight()); + VUtils.isTure(checkInconsistentData(pcs.getLeft().get(0), pcs.getLeft(), pcs.getRight())) + .throwMessage("导入的数据已存在,请勿重复导入"); } catch (NflgBusinessException ex) { if (Objects.equals(ex.getState(), STATE.InconsistentDataError)) { BOMMAP.put(SessionUtil.getUserCode(), pcs); @@ -101,52 +107,118 @@ public class DQBomImportService { @Transactional(rollbackFor = Exception.class) public void save(List parents, List children) { - // checkExceptionStatus(parents, children); - dQBomParentService.setLastVersionIs0(parents.stream().map(BomNewDQbomParentEntity::getMaterialNo).collect(Collectors.toList())); + Set materialNos = parents.stream().map(BomNewDQbomParentEntity::getMaterialNo).collect(Collectors.toSet()); + List oldParents = dQBomParentService.getLatestByMaterialNo(materialNos); + parents.forEach(p -> { + BomNewDQbomParentEntity oldParent = oldParents.stream().filter(op -> op.getMaterialNo().equals(p.getMaterialNo())).findFirst().orElse(null); + if (!Objects.isNull(oldParent) && Objects.equals(oldParent.getStatus(), DQBomStatusEnum.WAIT_CONVERT.getValue())) { + dQBomParentService.getBaseMapper().deleteById(oldParent.getRowId()); + dQBomChildService.deleteAllChildren(oldParent.getRowId()); + } + }); + dQBomParentService.setLastVersionIs0(materialNos); dQBomParentService.saveBatch(parents); dQBomChildService.saveBatch(children); BomNewDQbomParentEntity root = parents.stream().filter(p -> p.getRootIs() == 1).findFirst().orElseThrow(() -> new NflgBusinessException(STATE.BusinessError, "根节点不存在")); dQBomService.checkException(root.getRowId()); } - // private void checkExceptionStatus(List parents, List children) { - // BomNewDQbomExceptionCheckService checkService = new BomNewDQbomExceptionCheckService(dQBomParentService, dQBomChildService, materialMainService); - // checkService.check(parents, children); - // } - - private void checkInconsistentData(BomNewDQbomParentEntity parent, List parents, - List children) throws JsonProcessingException { - log.debug("checkInconsistentData,parent:" + JsonUtil.toJson(parent)); + private boolean checkInconsistentData(BomNewDQbomParentEntity parent, List parents, + List children) throws JsonProcessingException { + log.debug("checkInconsistentData,entity:" + JsonUtil.toJson(parent)); 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.toSet()); - Set oc = dQBomChildService.lambdaQuery().eq(BomNewDQbomChildEntity::getParentRowId, oldParent.getRowId()) - .list() - .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 (parent.getRowId() > 0) { + // old = dQBomParentService.getLatestByMaterialNo(parent.getMaterialNo()); + // } else { + // old = dQBomChildService.lambdaQuery() + // .eq(BomNewDQbomChildEntity::getParentRowId, parent.getRowId()) + // .eq(BomNewDQbomChildEntity::getMaterialNo, parent.getMaterialNo()) + // .one(); + // } + //BomNewDQbomParentEntity oldParent = dQBomParentService.getLatestByMaterialNo(parent.getMaterialNo()); + boolean isSame = true; + if (Objects.isNull(oldParent)) { + return isSame; + } + isSame = Objects.equals(parent.getMaterialUnit(), oldParent.getMaterialUnit()) + && NumberUtil.equals(parent.getNum(), oldParent.getNum()) + && Objects.equals(parent.getMaterialTexture(), oldParent.getMaterialTexture()); - 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())) + if (isSame) { + List cc = children.stream() + .filter(c -> c.getParentRowId().equals(parent.getRowId())) .collect(Collectors.toList()); - for (BomNewDQbomParentEntity p : ps) { - checkInconsistentData(p, parents, children); + List oc = dQBomChildService.lambdaQuery() + .eq(BomNewDQbomChildEntity::getParentRowId, oldParent.getRowId()) + .list(); + + isSame = cc.size() == oc.size() + && cc.stream().filter(c -> c.getProjectType().equals("T")).count() == oc.stream().filter(c -> c.getProjectType().equals("T")).count() + && Sets.difference(cc.stream().map(BomNewDQbomChildEntity::getMaterialNo).collect(Collectors.toSet()), oc.stream().map(BomNewDQbomChildEntity::getMaterialNo).collect(Collectors.toSet())).isEmpty(); + //VUtils.isTure(isSame).throwMessage("导入的数据已存在,请勿重复导入"); + + for (BomNewDQbomChildEntity ccc : cc) { + if (!checkInconsistentData(parent.getRowId(), ccc, parents, children)) { + isSame = false; + } } } + if (!isSame && Objects.equals(oldParent.getStatus(), DQBomStatusEnum.WAIT_CONVERT.getValue())) { + VUtils.isTure(!Objects.equals(oldParent.getCreatedBy(), SessionUtil.getUserCode())) + .throwMessage(StrUtil.format("{}已由{}导入过,不能再次导入", oldParent.getMaterialNo(), oldParent.getCreatedName())); + throw new NflgBusinessException(STATE.InconsistentDataError, oldParent.getMaterialNo() + "和已存在的数据不一致,是否覆盖?"); + } + return isSame; + } + + private boolean checkInconsistentData(Long parentRowId, BomNewDQbomChildEntity child, List parents, + List children) throws JsonProcessingException { + log.debug("checkInconsistentData,entity:" + JsonUtil.toJson(child)); + List oldChildren = dQBomChildService.getBom(parentRowId, child.getMaterialNo()); + boolean isSame = true; + if (CollUtil.isEmpty(oldChildren)) return isSame; + 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; + } + } + isSame = Objects.equals(child.getMaterialUnit(), oldChild.getMaterialUnit()) + && NumberUtil.equals(child.getNum(), oldChild.getNum()) + && Objects.equals(child.getMaterialTexture(), oldChild.getMaterialTexture()); + + if (isSame) { + BomNewDQbomParentEntity 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 = dQBomChildService.lambdaQuery() + .eq(BomNewDQbomChildEntity::getParentRowId, oldChild.getBomRowId()) + .list(); + Set ccm = cc.stream().map(BomNewDQbomChildEntity::getMaterialNo).collect(Collectors.toSet()); + + isSame = cc.size() == oc.size() + && cc.stream().filter(c -> c.getProjectType().equals("T")).count() == oc.stream().filter(c -> c.getProjectType().equals("T")).count() + && Sets.difference(ccm, oc.stream().map(BomNewDQbomChildEntity::getMaterialNo).collect(Collectors.toSet())).isEmpty(); + //VUtils.isTure(isSame).throwMessage("导入的数据已存在,请勿重复导入"); + + for (BomNewDQbomChildEntity ccc : cc) { + if (!checkInconsistentData(cp.getRowId(), ccc, parents, children)) { + isSame = false; + } + } + } + } + if (!isSame && Objects.equals(oldChild.getStatus(), DQBomStatusEnum.WAIT_CONVERT.getValue())) { + VUtils.isTure(!Objects.equals(oldChild.getCreatedBy(), SessionUtil.getUserCode())) + .throwMessage(StrUtil.format("{}已由{}导入过,不能再次导入", oldChild.getMaterialNo(), oldChild.getCreatedName())); + throw new NflgBusinessException(STATE.InconsistentDataError, oldChild.getMaterialNo() + "和已存在的数据不一致,是否覆盖?"); + } + return isSame; } private List checkExcel(List datas) { @@ -226,7 +298,7 @@ public class DQBomImportService { parent.setNum(Objects.isNull(data.getNum()) ? BigDecimal.ZERO : data.getNum()); parent.setTotalWeight(BomUtil.calculateTotalWeight(data.getNum(), data.getUnitWeight())); parent.setProjectType(data.getProjectType()); - parent.setCurrentVersion(OriginalConstant.DEFAULT_BOM_VERSION); + //parent.setCurrentVersion(OriginalConstant.DEFAULT_BOM_VERSION); parent.setRootIs(index == 0 ? 1 : 0); parent.setUserRootIs(index == 0 ? 1 : 0); parent.setLastVersionIs(1); @@ -268,7 +340,7 @@ public class DQBomImportService { child.setTotalWeight(BomUtil.calculateTotalWeight(data.getNum(), data.getUnitWeight())); child.setOrderNumber(StrUtil.padPre(String.valueOf(orderMap.get(data.getLevel())), 3, '0')); child.setDrawingNo(data.getDrawingNo()); - child.setCurrentVersion(parent == null ? OriginalConstant.DEFAULT_BOM_VERSION : parent.getCurrentVersion()); + //child.setCurrentVersion(parent == null ? OriginalConstant.DEFAULT_BOM_VERSION : parent.getCurrentVersion()); child.setMaterialNo(data.getMaterialNo()); child.setExceptionStatus(EBomExceptionStatusEnum.INIT.getValue()); child.setNum(Objects.isNull(data.getNum()) ? BigDecimal.ZERO : data.getNum()); @@ -292,21 +364,25 @@ public class DQBomImportService { dQbomExcelVO.setRowNum(rowNum.get()); if (dQbomExcelVO.getProjectType().equals("T")) { - BomNewDQbomParentEntity p = dQBomParentService.lambdaQuery() - .eq(BomNewDQbomParentEntity::getMaterialName, dQbomExcelVO.getMaterialName()) - .orderByDesc(BomNewDQbomParentEntity::getRowId) - .last(" limit 1") - .one(); - if (p != null) { - dQbomExcelVO.setMaterialNo(p.getMaterialNo()); - dQbomExcelVO.setDrawingNo(p.getMaterialNo()); - } else { - String id = BomConstant.DRAWING_NO_TEMPORARY_PREFIX + System.currentTimeMillis(); - dQbomExcelVO.setMaterialNo(id); - dQbomExcelVO.setDrawingNo(id); + long id = System.currentTimeMillis(); + dQbomExcelVO.setMaterialNo(BomConstant.NO_TEMPORARY_PREFIX + id); + dQbomExcelVO.setDrawingNo(BomConstant.NO_TEMPORARY_PREFIX + id); + if (StrUtil.isBlank(dQbomExcelVO.getMaterialUnit())) { + dQbomExcelVO.setMaterialUnit("PC"); + } + if (Objects.isNull(dQbomExcelVO.getNum()) || NumberUtil.equals(dQbomExcelVO.getNum(), BigDecimal.ZERO)) { + dQbomExcelVO.setNum(BigDecimal.ONE); } } excelContextTL.get().add(dQbomExcelVO); } + + public void importBomConfirm(Boolean save) { + if (save) { + save(); + } else { + BOMMAP.remove(SessionUtil.getUserCode()); + } + } } 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 34c26d0c..4b4f5361 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 @@ -7,6 +7,7 @@ import com.nflg.product.bomnew.pojo.vo.BomNewDQbomVO; import org.springframework.stereotype.Service; import java.time.LocalDateTime; +import java.util.Collection; import java.util.List; /** @@ -24,7 +25,7 @@ public class DQBomParentService extends ServiceImpl materialNo) { + public void setLastVersionIs0(Collection materialNo) { this.lambdaUpdate().in(BomNewDQbomParentEntity::getMaterialNo, materialNo) .set(BomNewDQbomParentEntity::getLastVersionIs, 0) .set(BomNewDQbomParentEntity::getModifyTime, LocalDateTime.now()) @@ -42,7 +43,7 @@ public class DQBomParentService extends ServiceImpl getLatestByMaterialNo(List materialNos) { + public List getLatestByMaterialNo(Collection materialNos) { return this.lambdaQuery() .in(BomNewDQbomParentEntity::getMaterialNo, materialNos) .eq(BomNewDQbomParentEntity::getLastVersionIs, 1) 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 a935274f..1f01f992 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 @@ -5,6 +5,7 @@ import cn.hutool.core.collection.CollUtil; import cn.hutool.core.convert.Convert; import cn.hutool.core.date.DateUtil; import cn.hutool.core.date.LocalDateTimeUtil; +import cn.hutool.core.util.NumberUtil; import cn.hutool.core.util.RandomUtil; import cn.hutool.core.util.StrUtil; import cn.hutool.extra.spring.SpringUtil; @@ -37,6 +38,7 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import javax.annotation.Resource; +import java.math.BigDecimal; import java.time.LocalDateTime; import java.util.*; import java.util.concurrent.CompletableFuture; @@ -221,7 +223,7 @@ public class DQBomService { * @param query 请求参数 */ @Transactional(rollbackFor = Exception.class) - public void save(BomNewDQbomSaveQuery query) { + public BomNewDQbomSaveQuery save(BomNewDQbomSaveQuery query) { BomNewDQbomParentEntity parent = new BomNewDQbomParentEntity(); BeanUtil.copyProperties(query.getParent(), parent); @@ -246,13 +248,14 @@ public class DQBomService { parent.setCreatedJob(userRoleService.technician() ? UserJobEnum.ENGINEER.getValue() : UserJobEnum.DESIGNER.getValue()); parent.setSource(2); dQBomParentService.save(parent); + query.getParent().setRowId(parent.getRowId()); } else { //修改数据 - VUtils.isTure(!SessionUtil.getUserCode().equals(parent.getCreatedBy())).throwMessage("不能修改他人的数据"); + // VUtils.isTure(!SessionUtil.getUserCode().equals(parent.getCreatedBy())).throwMessage("不能修改他人的数据"); if (CollUtil.isEmpty(query.getChildren())) { dQBomChildService.deleteAllChildren(parent.getRowId()); - return; + return query; } //删除 dQBomChildService.deleteAllChildren(parent.getRowId()); @@ -271,6 +274,12 @@ public class DQBomService { } else { c.setModifyTime(LocalDateTime.now()); } + if (StrUtil.isBlank(c.getMaterialUnit())) { + c.setMaterialUnit("PC"); + } + if (Objects.isNull(c.getNum()) || NumberUtil.equals(c.getNum(), BigDecimal.ZERO)) { + c.setNum(BigDecimal.ONE); + } c.setLevel(parent.getLevel() + 1); c.setParentRowId(parent.getRowId()); c.setIdentityNo(c.getParentRowId() + "_" + c.getRowId()); @@ -278,36 +287,8 @@ public class DQBomService { c.setTotalWeight(BomUtil.calculateTotalWeight(c.getNum(), query.getChildren().get(index).getUnitWeight())); } dQBomChildService.saveBatch(children); - // //处理parent - // List parents = Convert.toList(BomNewDQbomParentEntity.class, query.getChildren()); - // List materialNos = dQBomParentService.lambdaQuery() - // .in(BomNewDQbomParentEntity::getMaterialNo, parents.stream().map(BomNewDQbomParentEntity::getMaterialNo).collect(Collectors.toList())) - // .eq(BomNewDQbomParentEntity::getStatus, DQBomStatusEnum.WAIT_CONVERT.getValue()) - // .list() - // .stream() - // .map(BomNewDQbomParentEntity::getMaterialNo).collect(Collectors.toList()); - // parents.removeIf(p -> materialNos.contains(p.getMaterialNo())); - // List materialNos1 = parents.stream().map(BomNewDQbomParentEntity::getMaterialNo).collect(Collectors.toList()); - // if (CollUtil.isNotEmpty(materialNos1)) { - // dQBomParentService.lambdaUpdate().in(BomNewDQbomParentEntity::getMaterialNo, materialNos1) - // .set(BomNewDQbomParentEntity::getLastVersionIs, 0) - // .set(BomNewDQbomParentEntity::getModifyTime, LocalDateTime.now()) - // .update(); - // } - // parents.stream().filter(p -> Objects.isNull(p.getRowId())).forEach(p -> { - // p.setRowId(IdWorker.getId()); - // p.setCreatedBy(SessionUtil.getUserCode()); - // p.setStatus(DQBomStatusEnum.WAIT_CONVERT.getValue()); - // p.setRootIs(0); - // p.setUserRootIs(0); - // p.setBomExist(0); - // p.setEditStatus(1); - // p.setCreatedName(SessionUtil.getRealName()); - // p.setCreatedJob(userRoleService.technician() ? UserJobEnum.ENGINEER.getValue() : UserJobEnum.DESIGNER.getValue()); - // p.setSource(2); - // }); - // liParents.addAll(parents); - // dQBomParentService.saveOrUpdateBatch(liParents); + query.setChildren(Convert.toList(BomNewDQbomVO.class, children)); + return query; } public void deleteBom(Long rowId) { diff --git a/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/service/domain/EBom/EBomToPBom.java b/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/service/domain/EBom/EBomToPBom.java index 9af8e09b..bade296c 100644 --- a/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/service/domain/EBom/EBomToPBom.java +++ b/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/service/domain/EBom/EBomToPBom.java @@ -137,10 +137,11 @@ public class EBomToPBom { */ private void check() { //动态判断异常 - CheckEBomExceptoinDynamic.check(allBomDetail); - List collect = allBomDetail.stream().filter(u -> !EBomExceptionStatusEnum.OK.getValue().equals(u.getExceptionStatus())).collect(Collectors.toList()); + // CheckEBomExceptoinDynamic.check(allBomDetail); + // List collect = allBomDetail.stream().filter(u -> !EBomExceptionStatusEnum.OK.getValue().equals(u.getExceptionStatus())).collect(Collectors.toList()); - VUtils.isTure(CollUtil.isNotEmpty(collect)).throwMessage("存在异常数据,请处理完再转换"); + // VUtils.isTure(CollUtil.isNotEmpty(collect)).throwMessage("存在异常数据,请处理完再转换"); + VUtils.isTure(!Objects.equals(parent.getExceptionStatus(), EBomExceptionStatusEnum.OK.getValue())).throwMessage("存在异常数据,请处理完再转换"); } diff --git a/nflg_project_dev/nflg-bom-new/src/main/resources/mapper/master/BomNewDQbomChildMapper.xml b/nflg_project_dev/nflg-bom-new/src/main/resources/mapper/master/BomNewDQbomChildMapper.xml index 79354341..583e062c 100644 --- a/nflg_project_dev/nflg-bom-new/src/main/resources/mapper/master/BomNewDQbomChildMapper.xml +++ b/nflg_project_dev/nflg-bom-new/src/main/resources/mapper/master/BomNewDQbomChildMapper.xml @@ -16,4 +16,12 @@ LEFT JOIN t_bom_new_dqbom_parent p ON p.material_no = c.material_no WHERE c.parent_row_id = #{rowId} + + \ No newline at end of file