From 0c358b68870cb79b582d1dd7a43ff1205d4d06a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9B=B9=E9=B9=8F=E9=A3=9E?= Date: Sun, 7 Apr 2024 20:44:22 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=E7=94=B5=E6=B0=94?= =?UTF-8?q?=E4=B8=93=E7=94=A8bom=E7=9A=84excel=E5=AF=BC=E5=85=A5=E5=8A=9F?= =?UTF-8?q?=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../product/bomnew/api/user/DQBomApi.java | 45 +++ .../constant/EBomExceptionStatusEnum.java | 3 +- .../mapper/master/BomNewDQbomChildMapper.java | 13 + .../master/BomNewDQbomParentMapper.java | 17 ++ .../pojo/entity/BomNewDQbomChildEntity.java | 143 ++++++++++ .../pojo/entity/BomNewDQbomParentEntity.java | 179 ++++++++++++ .../product/bomnew/pojo/vo/DQbomExcelVO.java | 48 ++++ .../bomnew/pojo/vo/OperationErrorMsgVO.java | 24 ++ .../bomnew/service/DQBomChildService.java | 15 + .../bomnew/service/DQBomImportService.java | 262 ++++++++++++++++++ .../bomnew/service/DQBomParentService.java | 20 ++ .../com/nflg/product/bomnew/util/BomUtil.java | 38 +++ .../nflg/product/bomnew/util/JsonUtil.java | 22 ++ .../nflg/product/bomnew/util/StringUtil.java | 17 ++ .../src/main/resources/logback-sit.xml | 2 +- .../nflg/product/common/constant/STATE.java | 5 +- 16 files changed, 848 insertions(+), 5 deletions(-) create mode 100644 nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/api/user/DQBomApi.java create mode 100644 nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/mapper/master/BomNewDQbomChildMapper.java create mode 100644 nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/mapper/master/BomNewDQbomParentMapper.java create mode 100644 nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/pojo/entity/BomNewDQbomChildEntity.java create mode 100644 nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/pojo/entity/BomNewDQbomParentEntity.java create mode 100644 nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/pojo/vo/DQbomExcelVO.java create mode 100644 nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/pojo/vo/OperationErrorMsgVO.java create mode 100644 nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/service/DQBomChildService.java create mode 100644 nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/service/DQBomImportService.java create mode 100644 nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/service/DQBomParentService.java create mode 100644 nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/util/BomUtil.java create mode 100644 nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/util/JsonUtil.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 new file mode 100644 index 00000000..382b8b71 --- /dev/null +++ b/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/api/user/DQBomApi.java @@ -0,0 +1,45 @@ +package com.nflg.product.bomnew.api.user; + +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.vo.OperationErrorMsgVO; +import com.nflg.product.bomnew.service.DQBomImportService; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import nflg.product.common.vo.ResultVO; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.multipart.MultipartFile; + +import javax.annotation.Resource; +import java.io.IOException; +import java.util.List; + +/** + * @author 曹鹏飞 + * @date 2024/4/7 09:28:03 + */ +@Api(tags = "电气专用BOM") +@RestController +@RequestMapping("bom/new/dqbom") +public class DQBomApi extends BaseApi { + + @Resource + DQBomImportService dqBomImportService; + + @ApiOperation("导入") + @PostMapping("importBom") + @LogRecord(success = "电气BOM-导入:文件名:{{#fileNme}},操作结果:{{#_ret}}", bizNo = "", type = "电气BOM导入") + public ResultVO> importBom(@RequestParam(value = "file") MultipartFile file) throws IOException { + String type = file.getContentType();//application/vnd.openxmlformats-officedocument.spreadsheetml.sheet + if (!"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet".equals(type) && !"application/vnd.ms-excel".equals(type)) { + return ResultVO.error("请上传Excel文件"); + } + LogRecordContext.putVariable("fileNme", file.getOriginalFilename()); + + return ResultVO.success(dqBomImportService.importBom(file)); + } +} diff --git a/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/constant/EBomExceptionStatusEnum.java b/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/constant/EBomExceptionStatusEnum.java index 2de71e30..180fa8a8 100644 --- a/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/constant/EBomExceptionStatusEnum.java +++ b/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/constant/EBomExceptionStatusEnum.java @@ -34,7 +34,8 @@ public enum EBomExceptionStatusEnum implements ValueEnum { EXCEPT_NO_11(11, "未填写变更原因和技术通知单"), EXCEPT_NO_12(12, "数量需要用户确认"), EXCEPT_NO_13(13, "项目类型需要用户确认") , - EXCEPT_NO_14(14,"黄色警告"); + EXCEPT_NO_14(14, "黄色警告"), + EXCEPT_NO_15(15, "物料名称不一致"); 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 new file mode 100644 index 00000000..774db0b9 --- /dev/null +++ b/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/mapper/master/BomNewDQbomChildMapper.java @@ -0,0 +1,13 @@ +package com.nflg.product.bomnew.mapper.master; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.nflg.product.bomnew.pojo.entity.BomNewDQbomChildEntity; + +/** + * @author 曹鹏飞 + * @date 2024/4/7 11:09:47 + */ +public interface BomNewDQbomChildMapper extends BaseMapper { + + +} diff --git a/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/mapper/master/BomNewDQbomParentMapper.java b/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/mapper/master/BomNewDQbomParentMapper.java new file mode 100644 index 00000000..4bcb0f0c --- /dev/null +++ b/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/mapper/master/BomNewDQbomParentMapper.java @@ -0,0 +1,17 @@ +package com.nflg.product.bomnew.mapper.master; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.nflg.product.bomnew.pojo.entity.BomNewDQbomParentEntity; +import org.apache.ibatis.annotations.Select; + +import java.util.List; + +/** + * @author 曹鹏飞 + * @date 2024/4/7 10:54:59 + */ +public interface BomNewDQbomParentMapper extends BaseMapper { + + @Select("SELECT p.* FROM t_bom_new_dqbom_parent p INNER JOIN t_bom_new_dqbom_child c ON p.material_no = c.material_no WHERE c.status=1 AND p.material_no='#{materialNo}' ORDER BY p.row_id DESC") + List getWorkSheet(String materialNo); +} 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 new file mode 100644 index 00000000..55e2b0f7 --- /dev/null +++ b/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/pojo/entity/BomNewDQbomChildEntity.java @@ -0,0 +1,143 @@ +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; + +/** + * @author 曹鹏飞 + * @date 2024/4/7 10:58:12 + */ +@Data +@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 { + + /** + * 主键-雪花 + */ + @TableId(value = "row_id", type = IdType.ASSIGN_ID) + @ApiModelProperty(value = "主键-雪花") + private Long rowId; + + /** + * 父行ID + */ + @TableField(value = "parent_row_id") + @ApiModelProperty(value = "父行ID") + private Long parentRowId; + + /** + * 父级id_子级ID(原父节点ID) + */ + @TableField(value = "identity_no") + @ApiModelProperty(value = "父级id_子级ID") + private String identityNo; + + /** + * 排序号 + */ + @TableField(value = "order_number") + @ApiModelProperty(value = "排序号") + private String orderNumber; + + /** + * 图号 + */ + @TableField(value = "drawing_no") + @ApiModelProperty(value = "图号") + private String drawingNo; + + /** + * 物料编码 + */ + @TableField(value = "material_no") + @ApiModelProperty(value = "物料编码") + private String materialNo; + + /** + * 数量 + */ + @TableField(value = "num") + @ApiModelProperty(value = "数量") + private BigDecimal num; + + /** + * 总重 + */ + @TableField(value = "total_weight") + @ApiModelProperty(value = "总重") + private BigDecimal totalWeight; + /** + * 创建人名称 + */ + @TableField(value = "created_name") + @ApiModelProperty(value = "创建人名称") + private String createdName; + + /** + * 创建人编码 + */ + @TableField(value = "created_by") + @ApiModelProperty(value = "创建人编码") + private String createdBy; + + /** + * 创建时间 + */ + @TableField(value = "created_time") + @ApiModelProperty(value = "创建时间") + private LocalDateTime createdTime = LocalDateTime.now(); + + /** + * 修改时间 + */ + @TableField(value = "modify_time") + @ApiModelProperty(value = "修改时间") + private LocalDateTime modifyTime; + + /** + * 处理状态:1=待处理、2=已处理 + */ + @TableField(value = "edit_status") + @ApiModelProperty(value = "处理状态") + private Integer editStatus = 1; + + /** + * 转换状态:1=待转换、2=已转换(已发布PBOM) + */ + @TableField(value = "status") + @ApiModelProperty(value = "转换状态") + private Integer status = 1; + + /** + * 异常状态 + */ + @TableField(value = "exception_status") + @ApiModelProperty(value = "异常状态") + private Integer exceptionStatus = -1; + + /** + * 异常标记 + */ + @TableField(value = "exception_tag") + @ApiModelProperty(value = "异常标记") + private String exceptionTag; + + /** + * 来源 1-EXCE导入 2-MDM创建 + */ + @TableField(value = "source") + @ApiModelProperty(value = "来源") + private Integer source; +} 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 new file mode 100644 index 00000000..ca752dcc --- /dev/null +++ b/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/pojo/entity/BomNewDQbomParentEntity.java @@ -0,0 +1,179 @@ +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; + +/** + * @author 曹鹏飞 + * @date 2024/4/7 10:26:35 + */ +@Data +@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 { + + /** + * 主键-雪花 + */ + @TableId(value = "row_id", type = IdType.ASSIGN_ID) + @ApiModelProperty(value = "主键-雪花") + private Long rowId; + + /** + * 层次 + */ + @TableField(value = "level") + @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 = "material_name") + @ApiModelProperty(value = "物料名称") + private String materialName; + + /** + * 材质 + */ + @TableField(value = "material_texture") + @ApiModelProperty(value = "材质") + private String materialTexture; + + /** + * 单位 + */ + @TableField(value = "material_unit") + @ApiModelProperty(value = "单位") + private String materialUnit; + + /** + * 单重 + */ + @TableField(value = "unit_weight") + @ApiModelProperty(value = "单重") + private BigDecimal unitWeight; + + /** + * 项目类别 + */ + @TableField(value = "project_type") + @ApiModelProperty(value = "项目类别") + private String projectType; + + /** + * 版本号 + */ + @TableField(value = "current_version") + @ApiModelProperty(value = "版本号") + private String currentVersion; + + /** + * 是否跟节点 0-否 1-是 + */ + @TableField(value = "root_is") + @ApiModelProperty(value = "是否跟节点") + private Integer rootIs; + + /** + * 是否用户跟节点 0-否 1-是 + */ + @TableField(value = "user_root_is") + @ApiModelProperty(value = "是否用户跟节点") + private Integer userRootIs; + + /** + * 是否有子节点: 0-否 1-是 + */ + @TableField(value = "bom_exist") + @ApiModelProperty(value = "是否有子节点") + private Integer bomExist; + + /** + * 是否最新版:0-否 1-是 + */ + @TableField(value = "last_version_is") + @ApiModelProperty(value = "是否最新版") + private Integer lastVersionIs = 1; + + /** + * 创建人名称 + */ + @TableField(value = "created_name") + @ApiModelProperty(value = "创建人名称") + private String createdName; + + /** + * 创建人编码 + */ + @TableField(value = "created_by") + @ApiModelProperty(value = "创建人编码") + private String createdBy; + + /** + * 创建时间 + */ + @TableField(value = "created_time") + @ApiModelProperty(value = "创建时间") + private LocalDateTime createdTime = LocalDateTime.now(); + + /** + * 创建人员所属岗位 0-设计人员 1-工艺人员 2-其他 + */ + @TableField(value = "created_job") + @ApiModelProperty(value = "创建人员所属岗位") + private Integer createdJob; + + /** + * 版本过期时间(下个版本的创建时间) + */ + @TableField(value = "expire_end_time") + @ApiModelProperty(value = "版本过期时间") + private LocalDateTime expireEndTime; + + /** + * 转换pbom时间 + */ + @TableField(value = "convert_to_pbom_time") + @ApiModelProperty(value = "转换pbom时间") + private LocalDateTime convertToPbomTime; + + /** + * 备注 + */ + @TableField(value = "remark") + @ApiModelProperty(value = "备注") + private String remark; + + /** + * 修改时间 + */ + @TableField(value = "modify_time") + @ApiModelProperty(value = "修改时间") + private LocalDateTime modifyTime; +} 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 new file mode 100644 index 00000000..84b6b43a --- /dev/null +++ b/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/pojo/vo/DQbomExcelVO.java @@ -0,0 +1,48 @@ +package com.nflg.product.bomnew.pojo.vo; + +import com.nflg.product.bomnew.pojo.dto.BaseImportExcelDTO; +import lombok.Data; +import org.ttzero.excel.annotation.ExcelColumn; + +import java.math.BigDecimal; + +/** + * @author 曹鹏飞 + * @date 2024/4/7 09:32:40 + */ +@Data +public class DQbomExcelVO extends BaseImportExcelDTO { + + @ExcelColumn("层次") + private Integer level; + + @ExcelColumn("物料编码") + private String materialNo; + + @ExcelColumn("图号") + private String drawingNo; + + @ExcelColumn("名称") + private String materialName; + + @ExcelColumn("材料") + private String materialTexture; + + @ExcelColumn(value = "数量") + private BigDecimal num; + + @ExcelColumn("单位") + private String unit; + + @ExcelColumn("项目类别") + private String projectType; + + @ExcelColumn("版本") + private String currentVersion; + + @ExcelColumn("单重") + private BigDecimal unitWeight; + + @ExcelColumn("备注") + private String remark; +} diff --git a/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/pojo/vo/OperationErrorMsgVO.java b/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/pojo/vo/OperationErrorMsgVO.java new file mode 100644 index 00000000..64870d44 --- /dev/null +++ b/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/pojo/vo/OperationErrorMsgVO.java @@ -0,0 +1,24 @@ +package com.nflg.product.bomnew.pojo.vo; + +import io.swagger.annotations.ApiModelProperty; +import lombok.AllArgsConstructor; +import lombok.Data; + +/** + * @author 曹鹏飞 + * @date 2024-03-21 14:49:05 + */ +@Data +@AllArgsConstructor +public class OperationErrorMsgVO { + + @ApiModelProperty("主键数据") + private String primaryKey; + + @ApiModelProperty("错误描述") + private String msg; + + public static OperationErrorMsgVO create(String primaryKey, String msg) { + return new OperationErrorMsgVO(primaryKey, msg); + } +} 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 new file mode 100644 index 00000000..bf25311e --- /dev/null +++ b/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/service/DQBomChildService.java @@ -0,0 +1,15 @@ +package com.nflg.product.bomnew.service; + +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.nflg.product.bomnew.mapper.master.BomNewDQbomChildMapper; +import com.nflg.product.bomnew.pojo.entity.BomNewDQbomChildEntity; +import org.springframework.stereotype.Service; + +/** + * @author 曹鹏飞 + * @date 2024/4/7 11:10:58 + */ +@Service +public class DQBomChildService extends ServiceImpl { + +} 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 new file mode 100644 index 00000000..ed56e85d --- /dev/null +++ b/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/service/DQBomImportService.java @@ -0,0 +1,262 @@ +package com.nflg.product.bomnew.service; + +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.nflg.product.base.core.conmon.util.SessionUtil; +import com.nflg.product.base.core.exception.NflgBusinessException; +import com.nflg.product.bomnew.constant.EBomExceptionStatusEnum; +import com.nflg.product.bomnew.constant.MaterialGetEnum; +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.BaseMaterialVO; +import com.nflg.product.bomnew.pojo.vo.DQbomExcelVO; +import com.nflg.product.bomnew.pojo.vo.OperationErrorMsgVO; +import com.nflg.product.bomnew.util.*; +import lombok.extern.slf4j.Slf4j; +import nflg.product.common.constant.STATE; +import org.apache.commons.lang3.tuple.Pair; +import org.springframework.stereotype.Service; +import org.springframework.web.multipart.MultipartFile; + +import javax.annotation.Resource; +import java.io.IOException; +import java.util.*; +import java.util.stream.Collectors; + +/** + * @author 曹鹏飞 + * @date 2024/4/7 09:45:37 + */ +@Service +@Slf4j +public class DQBomImportService { + + public static final ThreadLocal rowNum = new ThreadLocal<>(); + + public static final ThreadLocal> excelContextTL = new ThreadLocal<>(); + + private static final List TYPES = Arrays.asList("T", "L"); + + private static final Map, List>> BOMMAP = new HashMap<>(); + + @Resource + DQBomParentService dQBomParentService; + + @Resource + DQBomChildService dQBomChildService; + + @Resource + UserRoleService userRoleService; + + @Resource + MaterialMainService materialMainService; + + public List importBom(MultipartFile file) throws IOException { + try { + BOMMAP.remove(SessionUtil.getUserCode()); + rowNum.set(1); + excelContextTL.set(new ArrayList<>()); + EecExcelUtil.handlerExcel(file.getInputStream(), DQbomExcelVO.class, this::handlerExcelRow); + + List datas = excelContextTL.get(); + + List errorMsg = checkExcel(datas); + if (!errorMsg.isEmpty()) { + return errorMsg; + } + + Pair, List> pcs = convertToBom(datas); + try { + checkInconsistentData(pcs.getLeft().get(0), pcs.getLeft(), pcs.getRight()); + } catch (NflgBusinessException ex) { + BOMMAP.put(SessionUtil.getUserCode(), pcs); + throw ex; + } + + save(pcs.getLeft(), pcs.getRight()); + + return Collections.emptyList(); + } finally { + excelContextTL.remove(); + } + } + + public void save() { + Pair, List> pcs = BOMMAP.get(SessionUtil.getUserCode()); + VUtils.isTure(pcs == null).throwMessage("数据已丢失,请重新导入"); + save(pcs.getLeft(), pcs.getRight()); + BOMMAP.remove(SessionUtil.getUserCode()); + } + + private void save(List parents, List children) { + checkExceptionStatus(parents, children); + dQBomParentService.saveBatch(parents); + dQBomChildService.saveBatch(children); + } + + private void checkExceptionStatus(List parents, List children) { + List materialNos = children.stream().map(BomNewDQbomChildEntity::getMaterialNo).collect(Collectors.toList()); + List materialVOS = materialMainService.getMaterialBaseInfo(materialNos); + checkChildExceptionStatus(children.get(0), parents, children, materialVOS); + } + + private void checkChildExceptionStatus(BomNewDQbomChildEntity child, List parents, List children, List materialVOS) { + BomNewDQbomParentEntity parent = parents.stream().filter(p -> p.getMaterialNo().equals(child.getMaterialNo())).findFirst().get(); + if (parent.getProjectType().equals("T")) { + child.setExceptionStatus(EBomExceptionStatusEnum.OK.getValue()); + } else { + BaseMaterialVO materialVO = materialVOS.stream().filter(v -> v.getMaterialNo().equals(child.getMaterialNo())).findFirst().orElse(null); + if (materialVO == null) { + child.setExceptionStatus(EBomExceptionStatusEnum.EXCEPT_NO_7.getValue()); + } else if (materialVO.getMaterialState().equals(MaterialGetEnum.MaterialStateEnum.STATE_NO_4.getValue())) { + child.setExceptionStatus(EBomExceptionStatusEnum.EXCEPT_NO_2.getValue()); + } else if (!materialVO.getMaterialName().equals(parent.getMaterialName())) { + child.setExceptionStatus(EBomExceptionStatusEnum.EXCEPT_NO_15.getValue()); + } else { + child.setExceptionStatus(EBomExceptionStatusEnum.OK.getValue()); + } + } + List cc = children.stream().filter(c -> c.getParentRowId().equals(parent.getRowId())).collect(Collectors.toList()); + for (BomNewDQbomChildEntity c : cc) { + checkChildExceptionStatus(c, parents, children, materialVOS); + } + } + + private void checkInconsistentData(BomNewDQbomParentEntity parent, List parents, List children) throws JsonProcessingException { + log.debug("checkInconsistentData,parent:" + JsonUtil.toJson(parent)); + BomNewDQbomParentEntity oldParent = dQBomParentService.getWorkSheet(parent.getMaterialNo()).stream().findFirst().orElse(null); + 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())) + .map(BomNewDQbomChildEntity::getMaterialNo) + .collect(Collectors.toList()); + List ps = parents.stream().filter(p -> cc.contains(p.getMaterialNo())) + .collect(Collectors.toList()); + for (BomNewDQbomParentEntity p : ps) { + checkInconsistentData(p, parents, children); + } + } + } + + private List checkExcel(List datas) { + List errorMsg = new ArrayList<>(); + + List noLevelNo = datas.stream().filter(u -> Objects.isNull(u.getLevel())) + .map(BaseImportExcelDTO::getRowNum) + .collect(Collectors.toList()); + if (!noLevelNo.isEmpty()) { + errorMsg.addAll(noLevelNo.stream().map(n -> OperationErrorMsgVO.create("第" + n + "行", "层次为空")) + .collect(Collectors.toList()) + ); + } + + List noProjectType = datas.stream().filter(u -> !TYPES.contains(u.getProjectType())) + .map(BaseImportExcelDTO::getRowNum) + .collect(Collectors.toList()); + if (!noProjectType.isEmpty()) { + errorMsg.addAll(noProjectType.stream().map(n -> OperationErrorMsgVO.create("第" + n + "行", "项目类别不正确")) + .collect(Collectors.toList()) + ); + } + + List remarkTooLong = datas.stream().filter(u -> StringUtil.CountForMysql(u.getRemark()) > 200) + .map(BaseImportExcelDTO::getRowNum) + .collect(Collectors.toList()); + if (!remarkTooLong.isEmpty()) { + errorMsg.addAll(remarkTooLong.stream().map(n -> OperationErrorMsgVO.create("第" + n + "行", "备注超出200字")) + .collect(Collectors.toList()) + ); + } + + return errorMsg; + } + + private Pair, List> convertToBom(List datas) { + List parents = new ArrayList<>(); + List children = new ArrayList<>(); + Map parentRowIdMap = new HashMap<>(); + Map orderMap = new HashMap<>(); + for (int index = 0; index < datas.size(); index++) { + DQbomExcelVO data = datas.get(index); + + BomNewDQbomParentEntity parent = parents.stream().filter(p -> p.getMaterialNo().equals(data.getMaterialNo())) + .findFirst() + .orElse(dQBomParentService.lambdaQuery().eq(BomNewDQbomParentEntity::getMaterialNo, data.getMaterialNo()) + .orderByDesc(BomNewDQbomParentEntity::getRowId).list().stream().findFirst().orElse(null) + ); + if (parent == null) { + parent = new BomNewDQbomParentEntity(); + parent.setRowId(IdWorker.getId()); + parent.setLevel(data.getLevel()); + parent.setDrawingNo(data.getDrawingNo()); + parent.setMaterialNo(data.getMaterialNo()); + parent.setMaterialName(data.getMaterialName()); + parent.setMaterialUnit(data.getUnit()); + parent.setUnitWeight(data.getUnitWeight()); + parent.setProjectType(data.getProjectType()); + parent.setRootIs(parentRowIdMap.containsKey(data.getLevel() - 1) ? 0 : 1); + parent.setUserRootIs(parentRowIdMap.containsKey(data.getLevel() - 1) ? 0 : 1); + parent.setLastVersionIs(1); + parent.setCreatedBy(SessionUtil.getUserCode()); + parent.setCreatedName(SessionUtil.getRealName()); + parent.setCreatedJob(userRoleService.technician() ? UserJobEnum.ENGINEER.getValue() : UserJobEnum.DESIGNER.getValue()); + parent.setRemark(data.getRemark()); + if (index == datas.size() - 1 || datas.get(index + 1).getLevel() <= data.getLevel()) { + parent.setBomExist(0); + } else { + parent.setBomExist(1); + } + parents.add(parent); + } + parentRowIdMap.put(data.getLevel(), parent.getRowId()); + + BomNewDQbomChildEntity child = new BomNewDQbomChildEntity(); + child.setRowId(IdWorker.getId()); + child.setParentRowId(parentRowIdMap.getOrDefault(data.getLevel() - 1, 0L)); + child.setIdentityNo(child.getParentRowId() + "_" + child.getRowId()); + if (index == 0) { + orderMap.put(data.getLevel(), 1); + } else { + orderMap.put(data.getLevel(), orderMap.getOrDefault(data.getLevel(), 0) + 1); + } + child.setOrderNumber(StrUtil.padPre(String.valueOf(orderMap.get(data.getLevel())), 3, '0')); + child.setDrawingNo(data.getDrawingNo()); + child.setMaterialNo(data.getMaterialNo()); + child.setNum(data.getNum()); + child.setTotalWeight(BomUtil.calculateTotalWeight(data.getNum(), data.getUnitWeight())); + child.setCreatedName(SessionUtil.getRealName()); + child.setCreatedBy(SessionUtil.getUserCode()); + child.setSource(1); + children.add(child); + } + return Pair.of(parents, children); + } + + private void handlerExcelRow(DQbomExcelVO dQbomExcelVO) { + rowNum.set(rowNum.get() + 1); + log.debug("电气bom导入excel,第" + rowNum.get() + "行,处理前:" + JSON.toJSONString(dQbomExcelVO)); + + dQbomExcelVO.setRowNum(rowNum.get()); + if (StrUtil.isBlank(dQbomExcelVO.getMaterialNo())) { + BomNewDQbomParentEntity p = dQBomParentService.lambdaQuery() + .eq(BomNewDQbomParentEntity::getMaterialName, dQbomExcelVO.getMaterialName()) + .orderByDesc(BomNewDQbomParentEntity::getRowId) + .list() + .stream().findFirst().orElse(null); + if (p != null) { + dQbomExcelVO.setMaterialNo(p.getMaterialNo()); + } else { + dQbomExcelVO.setMaterialNo("T" + IdWorker.getIdStr()); + } + } + + excelContextTL.get().add(dQbomExcelVO); + } +} 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 new file mode 100644 index 00000000..23e2c8f0 --- /dev/null +++ b/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/service/DQBomParentService.java @@ -0,0 +1,20 @@ +package com.nflg.product.bomnew.service; + +import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import com.nflg.product.bomnew.mapper.master.BomNewDQbomParentMapper; +import com.nflg.product.bomnew.pojo.entity.BomNewDQbomParentEntity; +import org.springframework.stereotype.Service; + +import java.util.List; + +/** + * @author 曹鹏飞 + * @date 2024/4/7 10:24:49 + */ +@Service +public class DQBomParentService extends ServiceImpl { + + public List getWorkSheet(String materialNo) { + return this.getBaseMapper().getWorkSheet(materialNo); + } +} diff --git a/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/util/BomUtil.java b/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/util/BomUtil.java new file mode 100644 index 00000000..59af87b7 --- /dev/null +++ b/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/util/BomUtil.java @@ -0,0 +1,38 @@ +package com.nflg.product.bomnew.util; + +import cn.hutool.core.util.NumberUtil; + +import java.math.BigDecimal; +import java.util.Objects; + +/** + * @author 曹鹏飞 + * @date 2024-04-02 10:26:21 + */ +public class BomUtil { + + /** + * 计算总重量(四舍五入小数点后4位) + * @param num 数量 + * @param unitWeight 单重 + * @return 总重,精度:四舍五入小数点后4位 + */ + public static BigDecimal calculateTotalWeight(BigDecimal num, BigDecimal unitWeight) { + if (Objects.isNull(num) || Objects.isNull(unitWeight)) { + return null; + } + return NumberUtil.round(NumberUtil.mul(num, unitWeight), 4); + } + + /** + * 去除末尾多余的0 + * @param old 待转换的数据 + * @return 去除末尾多余的0后的数据 + */ + public static BigDecimal totalWeightToDisplay(BigDecimal old) { + if (Objects.isNull(old)) { + return null; + } + return new BigDecimal(NumberUtil.toStr(old)); + } +} diff --git a/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/util/JsonUtil.java b/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/util/JsonUtil.java new file mode 100644 index 00000000..1c66a69f --- /dev/null +++ b/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/util/JsonUtil.java @@ -0,0 +1,22 @@ +package com.nflg.product.bomnew.util; + +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import org.apache.poi.ss.formula.functions.T; + +/** + * @author 曹鹏飞 + * @date 2024-04-02 19:10:49 + */ +public class JsonUtil { + + public static String toJson(Object object) throws JsonProcessingException { + ObjectMapper objectmapper = new ObjectMapper(); + return objectmapper.writeValueAsString(object); + } + + public static T fromJson(String json, Class clazz) throws JsonProcessingException { + ObjectMapper objectmapper = new ObjectMapper(); + return objectmapper.readValue(json, clazz); + } +} diff --git a/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/util/StringUtil.java b/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/util/StringUtil.java index e477ef0f..262c6d46 100644 --- a/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/util/StringUtil.java +++ b/nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/util/StringUtil.java @@ -50,6 +50,23 @@ public class StringUtil { return sb.toString(); } + public static int CountForMysql(String text) { + if (text == null || text.isEmpty()) { + return 0; + } + int lengthCount = 0; + for (char c : text.toCharArray()) { + if (isChineseCharacter(c)) { + // 如果是中文字符 + lengthCount += 3; + } else { + // 非中文字符 + lengthCount++; + } + } + return lengthCount; + } + /** * 截取文本,只取30个有效长度,每个中文占用3个长度,其余字符占用1个长度。 * diff --git a/nflg_project_dev/nflg-bom-new/src/main/resources/logback-sit.xml b/nflg_project_dev/nflg-bom-new/src/main/resources/logback-sit.xml index 9127e28e..1dad47bf 100644 --- a/nflg_project_dev/nflg-bom-new/src/main/resources/logback-sit.xml +++ b/nflg_project_dev/nflg-bom-new/src/main/resources/logback-sit.xml @@ -39,7 +39,7 @@ - + diff --git a/nflg_project_dev/nflg-boot-base/nflg-common/src/main/java/nflg/product/common/constant/STATE.java b/nflg_project_dev/nflg-boot-base/nflg-common/src/main/java/nflg/product/common/constant/STATE.java index a897b452..8add801b 100644 --- a/nflg_project_dev/nflg-boot-base/nflg-common/src/main/java/nflg/product/common/constant/STATE.java +++ b/nflg_project_dev/nflg-boot-base/nflg-common/src/main/java/nflg/product/common/constant/STATE.java @@ -10,8 +10,6 @@ import lombok.Getter; */ @AllArgsConstructor public enum STATE { - - SystemErr(0, "系统错误"), Success(200, "操作成功"), ParamErr(101, "参数错误"), @@ -29,7 +27,8 @@ public enum STATE { Redirect(113, "页面跳转"), PageError(114, "页面异常"), BusinessError(115, "业务异常"), - RequestMethodError(116, "请求方式错误") + RequestMethodError(116, "请求方式错误"), + InconsistentDataError(117, "数据不一致") ; @Getter private final Integer state;