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

View File

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