feat: 添加电气专用bom的excel导入功能
This commit is contained in:
parent
8537b3f15d
commit
0c358b6887
|
|
@ -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<List<OperationErrorMsgVO>> 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));
|
||||
}
|
||||
}
|
||||
|
|
@ -34,7 +34,8 @@ public enum EBomExceptionStatusEnum implements ValueEnum<Integer> {
|
|||
EXCEPT_NO_11(11, "未填写变更原因和技术通知单"),
|
||||
EXCEPT_NO_12(12, "数量需要用户确认"),
|
||||
EXCEPT_NO_13(13, "项目类型需要用户确认") ,
|
||||
EXCEPT_NO_14(14,"黄色警告");
|
||||
EXCEPT_NO_14(14, "黄色警告"),
|
||||
EXCEPT_NO_15(15, "物料名称不一致");
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -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<BomNewDQbomChildEntity> {
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -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<BomNewDQbomParentEntity> {
|
||||
|
||||
@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<BomNewDQbomParentEntity> getWorkSheet(String materialNo);
|
||||
}
|
||||
|
|
@ -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;
|
||||
}
|
||||
|
|
@ -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;
|
||||
}
|
||||
|
|
@ -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;
|
||||
}
|
||||
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
@ -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<BomNewDQbomChildMapper, BomNewDQbomChildEntity> {
|
||||
|
||||
}
|
||||
|
|
@ -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<Integer> rowNum = new ThreadLocal<>();
|
||||
|
||||
public static final ThreadLocal<List<DQbomExcelVO>> excelContextTL = new ThreadLocal<>();
|
||||
|
||||
private static final List<String> TYPES = Arrays.asList("T", "L");
|
||||
|
||||
private static final Map<String, Pair<List<BomNewDQbomParentEntity>, List<BomNewDQbomChildEntity>>> BOMMAP = new HashMap<>();
|
||||
|
||||
@Resource
|
||||
DQBomParentService dQBomParentService;
|
||||
|
||||
@Resource
|
||||
DQBomChildService dQBomChildService;
|
||||
|
||||
@Resource
|
||||
UserRoleService userRoleService;
|
||||
|
||||
@Resource
|
||||
MaterialMainService materialMainService;
|
||||
|
||||
public List<OperationErrorMsgVO> 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<DQbomExcelVO> datas = excelContextTL.get();
|
||||
|
||||
List<OperationErrorMsgVO> errorMsg = checkExcel(datas);
|
||||
if (!errorMsg.isEmpty()) {
|
||||
return errorMsg;
|
||||
}
|
||||
|
||||
Pair<List<BomNewDQbomParentEntity>, List<BomNewDQbomChildEntity>> 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<BomNewDQbomParentEntity>, List<BomNewDQbomChildEntity>> pcs = BOMMAP.get(SessionUtil.getUserCode());
|
||||
VUtils.isTure(pcs == null).throwMessage("数据已丢失,请重新导入");
|
||||
save(pcs.getLeft(), pcs.getRight());
|
||||
BOMMAP.remove(SessionUtil.getUserCode());
|
||||
}
|
||||
|
||||
private void save(List<BomNewDQbomParentEntity> parents, List<BomNewDQbomChildEntity> children) {
|
||||
checkExceptionStatus(parents, children);
|
||||
dQBomParentService.saveBatch(parents);
|
||||
dQBomChildService.saveBatch(children);
|
||||
}
|
||||
|
||||
private void checkExceptionStatus(List<BomNewDQbomParentEntity> parents, List<BomNewDQbomChildEntity> children) {
|
||||
List<String> materialNos = children.stream().map(BomNewDQbomChildEntity::getMaterialNo).collect(Collectors.toList());
|
||||
List<BaseMaterialVO> materialVOS = materialMainService.getMaterialBaseInfo(materialNos);
|
||||
checkChildExceptionStatus(children.get(0), parents, children, materialVOS);
|
||||
}
|
||||
|
||||
private void checkChildExceptionStatus(BomNewDQbomChildEntity child, List<BomNewDQbomParentEntity> parents, List<BomNewDQbomChildEntity> children, List<BaseMaterialVO> 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<BomNewDQbomChildEntity> 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<BomNewDQbomParentEntity> parents, List<BomNewDQbomChildEntity> 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<String> cc = children.stream().filter(c -> c.getParentRowId().equals(parent.getRowId()))
|
||||
.map(BomNewDQbomChildEntity::getMaterialNo)
|
||||
.collect(Collectors.toList());
|
||||
List<BomNewDQbomParentEntity> ps = parents.stream().filter(p -> cc.contains(p.getMaterialNo()))
|
||||
.collect(Collectors.toList());
|
||||
for (BomNewDQbomParentEntity p : ps) {
|
||||
checkInconsistentData(p, parents, children);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private List<OperationErrorMsgVO> checkExcel(List<DQbomExcelVO> datas) {
|
||||
List<OperationErrorMsgVO> errorMsg = new ArrayList<>();
|
||||
|
||||
List<Integer> 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<Integer> 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<Integer> 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<BomNewDQbomParentEntity>, List<BomNewDQbomChildEntity>> convertToBom(List<DQbomExcelVO> datas) {
|
||||
List<BomNewDQbomParentEntity> parents = new ArrayList<>();
|
||||
List<BomNewDQbomChildEntity> children = new ArrayList<>();
|
||||
Map<Integer, Long> parentRowIdMap = new HashMap<>();
|
||||
Map<Integer, Integer> 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);
|
||||
}
|
||||
}
|
||||
|
|
@ -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<BomNewDQbomParentMapper, BomNewDQbomParentEntity> {
|
||||
|
||||
public List<BomNewDQbomParentEntity> getWorkSheet(String materialNo) {
|
||||
return this.getBaseMapper().getWorkSheet(materialNo);
|
||||
}
|
||||
}
|
||||
|
|
@ -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));
|
||||
}
|
||||
}
|
||||
|
|
@ -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<T> clazz) throws JsonProcessingException {
|
||||
ObjectMapper objectmapper = new ObjectMapper();
|
||||
return objectmapper.readValue(json, clazz);
|
||||
}
|
||||
}
|
||||
|
|
@ -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个长度。
|
||||
*
|
||||
|
|
|
|||
|
|
@ -39,7 +39,7 @@
|
|||
<logger name="com.alibaba.nacos" level="WARN" />
|
||||
|
||||
<!-- 日志输出级别 -->
|
||||
<root level="TRACE">
|
||||
<root level="DEBUG">
|
||||
<appender-ref ref="Console" />
|
||||
<appender-ref ref="RollingFileAll" />
|
||||
</root>
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Reference in New Issue