fix(ebom): 优化从excel导入

This commit is contained in:
曹鹏飞 2024-05-17 13:38:06 +08:00
parent 00d7b093b0
commit 314aceba8b
3 changed files with 51 additions and 34 deletions

View File

@ -11,10 +11,7 @@ import com.nflg.product.bomnew.pojo.query.GenerateVirtualPackageQuery;
import com.nflg.product.bomnew.pojo.vo.ImportOriginalBomVO;
import com.nflg.product.bomnew.pojo.vo.ListForGenerateVirtualPackageVO;
import com.nflg.product.bomnew.pojo.vo.OperationErrorMsgVO;
import com.nflg.product.bomnew.service.BomNewEbomParentService;
import com.nflg.product.bomnew.service.BomNewOriginalParentService;
import com.nflg.product.bomnew.service.BomNewOriginalParentV2Service;
import com.nflg.product.bomnew.service.EBomImportService;
import com.nflg.product.bomnew.service.*;
import com.nflg.product.bomnew.util.EecExcelUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
@ -52,6 +49,8 @@ public class EbomV2Api extends BaseApi {
@Resource
BomNewEbomParentService ebomParentService;
@Resource
BomNewEbomChildService ebomChildService;
@Resource
EBomImportService eBomImportService;
@ -79,18 +78,17 @@ public class EbomV2Api extends BaseApi {
@Transactional(rollbackFor = Exception.class)
@LogRecord(success = "原始BOM-导入:文件名:{{#fileNme}},操作结果:{{#_ret}}",
bizNo = "", type = "原始BOM导入")
public ResultVO<List<OperationErrorMsgVO>> importBom(@RequestParam(value = "file") MultipartFile file) throws IOException {
public ResultVO<List<OperationErrorMsgVO>> importBom(@RequestParam(value = "file") MultipartFile file) throws Exception {
if (file != null && !file.getOriginalFilename().endsWith("xls") && !file.getOriginalFilename().endsWith("xlsx")) {
return ResultVO.error("请上传Excel文件");
}
LogRecordContext.putVariable("fileNme", file.getOriginalFilename());
List<OperationErrorMsgVO> result = eBomImportService.importBom(file);
//计算层级
originalParentService.computeLevelNumAndRootState();
ebomChildService.getBaseMapper().updateEBomMaterialUse();
ebomParentService.compucteLevelNum();
//更新物料使用
originalParentService.getBaseMapper().upOriginalMaterialUse();
ebomParentService.resetAllBomExist();
return ResultVO.success(result);
}

View File

@ -385,5 +385,8 @@ public class BomNewEbomParentEntity implements Serializable {
@ApiModelProperty(value = "导入SAP时间")
private LocalDateTime sapTime;
@TableField(exist = false)
private boolean isImportRoot = false;
private static final long serialVersionUID = 265246823929418418L;
}

View File

@ -7,7 +7,6 @@ import cn.hutool.core.util.RandomUtil;
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.google.common.collect.Sets;
import com.nflg.product.base.core.conmon.util.SessionUtil;
import com.nflg.product.bomnew.constant.*;
@ -70,7 +69,12 @@ public class EBomImportService {
}
Pair<List<BomNewEbomParentEntity>, List<BomNewEbomChildEntity>> pcs = convertToBom(datas);
VUtils.isTure(checkInconsistentData(pcs.getLeft().get(0), pcs.getLeft(), pcs.getRight())).throwMessage("导入的数据已存在,请勿重复导入");
List<BomNewEbomParentEntity> importRoots = pcs.getLeft().stream().filter(BomNewEbomParentEntity::isImportRoot).collect(Collectors.toList());
//VUtils.isTure(importRoots.size() > 1).throwMessage("不支持一次导入多个bom");
importRoots.forEach(it -> {
VUtils.isTure(checkInconsistentData(pcs.getLeft().get(0), pcs.getLeft(), pcs.getRight())).throwMessage("导入的数据已存在,请勿重复导入");
});
save(pcs.getLeft(), pcs.getRight());
@ -104,8 +108,8 @@ public class EBomImportService {
}
private boolean checkInconsistentData(BomNewEbomParentEntity parent, List<BomNewEbomParentEntity> parents,
List<BomNewEbomChildEntity> children) throws JsonProcessingException {
log.debug("checkInconsistentDataentity" + JsonUtil.toJson(parent));
List<BomNewEbomChildEntity> children) {
log.debug("checkInconsistentDataentity" + JSON.toJSONString(parent));
BomNewEbomParentEntity oldParent = bomNewEbomParentService.getLatestByMaterialNo(parent.getMaterialNo());
boolean isSame = true;
if (Objects.isNull(oldParent)) {
@ -155,8 +159,8 @@ public class EBomImportService {
}
private boolean checkInconsistentData(Long parentRowId, BomNewEbomChildEntity child, List<BomNewEbomParentEntity> parents,
List<BomNewEbomChildEntity> children) throws JsonProcessingException {
log.debug("checkInconsistentDataentity" + JsonUtil.toJson(child));
List<BomNewEbomChildEntity> children) {
log.debug("checkInconsistentDataentity" + JSON.toJSONString(child));
List<BomNewEbomParentVO> oldChildren = bomNewEbomChildService.getBom(parentRowId, child.getMaterialNo());
boolean isSame = true;
if (CollUtil.isEmpty(oldChildren)) return false;
@ -301,24 +305,29 @@ public class EBomImportService {
parent = parents.stream().filter(p -> p.getMaterialNo().equals(data.getParentMaterialNo()))
.findFirst()
.orElse(null);
if (Objects.isNull(parent)) {
parents.add(buildTop(materialBaseInfos, data.getParentMaterialNo(), data.getParentMaterialDesc()));
if (Objects.isNull(parent) && datas.stream().noneMatch(d -> d.getMaterialNo().equals(data.getParentMaterialNo()))) {
parents.add(buildRoot(materialBaseInfos, data.getParentMaterialNo(), data.getParentMaterialDesc()));
}
}
for (EbomExcelDTO data : datas) {
parent = parents.stream().filter(p -> p.getMaterialNo().equals(data.getMaterialNo()))
.findFirst()
.orElse(null);
if (Objects.isNull(parent)) {
parent = buildParent(materialBaseInfos, data);
buildChild(children, materialBaseInfos, parent, data.getProjectType()
, parents.stream().filter(p -> p.getMaterialNo().equals(data.getParentMaterialNo())).findFirst().get());
parents.add(parent);
parents.add(buildParent(materialBaseInfos, data));
}
}
for (EbomExcelDTO data : datas) {
parent = parents.stream().filter(p -> p.getMaterialNo().equals(data.getMaterialNo()))
.findFirst()
.get();
buildChild(children, materialBaseInfos, parent, data
, parents.stream().filter(p -> p.getMaterialNo().equals(data.getParentMaterialNo())).findFirst().get());
}
return Pair.of(parents, children);
}
private void buildChild(List<BomNewEbomChildEntity> children, List<BaseMaterialVO> materialBaseInfos, BomNewEbomParentEntity parent, String projectType, BomNewEbomParentEntity p) {
private void buildChild(List<BomNewEbomChildEntity> children, List<BaseMaterialVO> materialBaseInfos, BomNewEbomParentEntity parent, EbomExcelDTO data, BomNewEbomParentEntity p) {
BomNewEbomChildEntity child = Convert.convert(BomNewEbomChildEntity.class, parent);
child.setRowId(IdWorker.getId());
child.setParentRowId(p.getRowId());
@ -335,11 +344,12 @@ public class EBomImportService {
child.setDrawingNo(parent.getDrawingNo());
child.setMaterialDesc(parent.getMaterialDesc());
child.setUnitWeight(parent.getUnitWeight());
child.setMaterialUnit(parent.getMaterialUnit());
child.setMaterialUnit(data.getUnit());
child.setMaterialOriginalUnit(parent.getMaterialOriginalUnit());
child.setNum(parent.getNum());
child.setTotalWeight(parent.getTotalWeight());
child.setProjectType(projectType);
child.setNum(data.getNum());
child.setRemark(data.getRemark());
child.setTotalWeight(BomUtil.calculateTotalWeight(child.getNum(), child.getUnitWeight()));
child.setProjectType(data.getProjectType());
child.setProjectTypeInputType(ProjectTypeInputTypeEnum.MANUAL_INPUT.getValue());
child.setIdentityNo(child.getParentRowId() + "_" + child.getRowId());
if (p.getMaterialNo().startsWith("31")) {
@ -378,10 +388,11 @@ public class EBomImportService {
}
}
parent.setMaterialOriginalUnit(data.getUnit());
parent.setNum(data.getNum());
parent.setTotalWeight(BomUtil.calculateTotalWeight(parent.getNum(), parent.getUnitWeight()));
parent.setNum(BigDecimal.ONE);
parent.setTotalWeight(null);
parent.setUserRootIs(0);
parent.setRootIs(0);
parent.setRootIsForWaitReview(0);
if (userRoleService.technician()) {
//工艺人员
parent.setStatus(EBomStatusEnum.CHECKED.getValue());
@ -392,7 +403,6 @@ public class EBomImportService {
//设计人员
parent.setStatus(EBomStatusEnum.WAIT_CHECK.getValue());
parent.setCreatedJob(UserJobEnum.DESIGNER.getValue());
parent.setRootIsForWaitReview(1);
}
parent.setDeviseName(SessionUtil.getRealName());
parent.setDeviseUserCode(SessionUtil.getUserCode());
@ -400,7 +410,7 @@ public class EBomImportService {
parent.setEditStatus(EbomEditStatusEnum.HANDLER_CREATED.getValue());
parent.setExceptionStatus(EBomExceptionStatusEnum.INIT.getValue());
parent.setCreatedBy(SessionUtil.getUserCode());
parent.setRemark(data.getRemark());
parent.setRemark("");
parent.setOrderNumber(data.getOrderNum());
parent.setDeptName(SessionUtil.getDepartName());
parent.setSource(EBomSourceEnum.FROM_EXCE.getValue());
@ -416,10 +426,10 @@ public class EBomImportService {
* @param materialDesc 物料描述
* @return 父级
*/
private BomNewEbomParentEntity buildTop(List<BaseMaterialVO> materialBaseInfos, String materialNo, String materialDesc) {
private BomNewEbomParentEntity buildRoot(List<BaseMaterialVO> materialBaseInfos, String materialNo, String materialDesc) {
BomNewEbomParentEntity parent = new BomNewEbomParentEntity();
parent.setRowId(IdWorker.getId());
parent.setImportRoot(true);
parent.setMaterialNo(materialNo);
parent.setMaterialDesc(materialDesc);
BaseMaterialVO vo = materialBaseInfos.stream()
@ -446,8 +456,8 @@ public class EBomImportService {
// .stream()
// .map(BomNewEbomChildEntity::getParentRowId)
// .collect(Collectors.toList());
parent.setUserRootIs(1);
parent.setRootIs(bomNewEbomChildService.getBaseMapper().shouldSetRootIs(materialNo));
parent.setUserRootIs(1);
if (userRoleService.technician()) {
//工艺人员
parent.setStatus(EBomStatusEnum.CHECKED.getValue());
@ -476,6 +486,9 @@ public class EBomImportService {
}
private void setVirtualPackageType(BomNewEbomParentEntity parent) {
if (!parent.getMaterialNo().startsWith("22")) {
return;
}
if (parent.getMaterialDesc().endsWith(")(发货)") || parent.getMaterialDesc().endsWith(")(制作)")
|| parent.getMaterialDesc().endsWith(")(直发)") || parent.getMaterialDesc().endsWith(")(发货前装配)")) {
parent.setVirtualPackageIs(1);
@ -483,6 +496,9 @@ public class EBomImportService {
}
private void setVirtualPackageType(BomNewEbomChildEntity child) {
if (!child.getMaterialNo().startsWith("22")) {
return;
}
if (child.getMaterialDesc().endsWith(")(发货)")) {
child.setVirtualPartType(VirtualPackageTypeEnum.DELIVERY_PACKAGE.getValue());
} else if (child.getMaterialDesc().endsWith(")(制作)")) {