feat(ebom): 修复从excel导入数据的bug
This commit is contained in:
parent
95cec05802
commit
d92ecb727f
|
|
@ -9,7 +9,6 @@ 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.base.core.exception.NflgBusinessException;
|
||||
import com.nflg.product.bomnew.constant.*;
|
||||
import com.nflg.product.bomnew.pojo.dto.BaseImportExcelDTO;
|
||||
import com.nflg.product.bomnew.pojo.dto.EbomExcelDTO;
|
||||
|
|
@ -20,7 +19,6 @@ import com.nflg.product.bomnew.pojo.vo.BomNewEbomParentVO;
|
|||
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.transaction.annotation.Transactional;
|
||||
|
|
@ -71,13 +69,13 @@ public class EBomImportService {
|
|||
}
|
||||
|
||||
Pair<List<BomNewEbomParentEntity>, List<BomNewEbomChildEntity>> pcs = convertToBom(datas);
|
||||
VUtils.isTure(pcs.getLeft().stream().filter(p -> p.getRootIs() == 1).count() > 1)
|
||||
.throwMessage("文件中存在多个根节点");
|
||||
VUtils.isTure(checkInconsistentData(pcs.getLeft().get(0), pcs.getLeft(), pcs.getRight()))
|
||||
.throwMessage("导入的数据已存在,请勿重复导入");
|
||||
|
||||
save(pcs.getLeft(), pcs.getRight());
|
||||
|
||||
bomNewEbomParentService.resetAllBomExist();
|
||||
|
||||
return Collections.emptyList();
|
||||
} finally {
|
||||
excelContextTL.remove();
|
||||
|
|
@ -86,10 +84,6 @@ public class EBomImportService {
|
|||
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void save(List<BomNewEbomParentEntity> parents, List<BomNewEbomChildEntity> children) {
|
||||
BomNewEbomParentEntity root = parents.stream()
|
||||
.filter(p -> p.getRootIs() == 1)
|
||||
.findFirst()
|
||||
.orElseThrow(() -> new NflgBusinessException(STATE.BusinessError, "根节点不存在"));
|
||||
Set<String> pMaterialNos = parents.stream().map(BomNewEbomParentEntity::getMaterialNo).collect(Collectors.toSet());
|
||||
List<BomNewEbomParentEntity> oldParents = bomNewEbomParentService.getLatestByMaterialNo(pMaterialNos);
|
||||
parents.forEach(p -> {
|
||||
|
|
@ -267,7 +261,7 @@ public class EBomImportService {
|
|||
.findFirst()
|
||||
.orElse(null);
|
||||
if (Objects.isNull(parent)) {
|
||||
parents.add(buildRoot(materialBaseInfos, data.getParentMaterialNo(), data.getParentMaterialDesc()));
|
||||
parents.add(buildTop(materialBaseInfos, data.getParentMaterialNo(), data.getParentMaterialDesc()));
|
||||
}
|
||||
|
||||
parent = parents.stream().filter(p -> p.getMaterialNo().equals(data.getMaterialNo()))
|
||||
|
|
@ -275,18 +269,33 @@ public class EBomImportService {
|
|||
.orElse(null);
|
||||
if (Objects.isNull(parent)) {
|
||||
parent = buildParent(materialBaseInfos, data);
|
||||
children.add(buildChild(materialBaseInfos, parent, data.getProjectType()));
|
||||
buildChild(children, materialBaseInfos, parent, data.getProjectType()
|
||||
, parents.stream().filter(p -> p.getMaterialNo().equals(data.getParentMaterialNo())).findFirst().get());
|
||||
parents.add(parent);
|
||||
}
|
||||
}
|
||||
return Pair.of(parents, children);
|
||||
}
|
||||
|
||||
private BomNewEbomChildEntity buildChild(List<BaseMaterialVO> materialBaseInfos, BomNewEbomParentEntity parent, String projectType) {
|
||||
private void buildChild(List<BomNewEbomChildEntity> children, List<BaseMaterialVO> materialBaseInfos, BomNewEbomParentEntity parent, String projectType, BomNewEbomParentEntity p) {
|
||||
BomNewEbomChildEntity child = Convert.convert(BomNewEbomChildEntity.class, parent);
|
||||
parent.setOrderNumber("");
|
||||
child.setRowId(IdWorker.getId());
|
||||
child.setParentRowId(parent.getRowId());
|
||||
child.setParentRowId(p.getRowId());
|
||||
parent.setOrderNumber("");
|
||||
List<BomNewEbomChildEntity> pcs = children.stream()
|
||||
.filter(c -> Objects.equals(c.getParentRowId(), p.getRowId()))
|
||||
.collect(Collectors.toList());
|
||||
if (CollUtil.isEmpty(pcs)) {
|
||||
child.setOrderNumber("001");
|
||||
} else {
|
||||
String maxOrderNum = pcs.get(pcs.size() - 1).getOrderNumber();
|
||||
child.setOrderNumber(OrderNoUtil.next(maxOrderNum));
|
||||
}
|
||||
child.setDrawingNo(parent.getDrawingNo());
|
||||
child.setMaterialDesc(parent.getMaterialDesc());
|
||||
child.setUnitWeight(parent.getUnitWeight());
|
||||
child.setNum(parent.getNum());
|
||||
child.setTotalWeight(parent.getTotalWeight());
|
||||
child.setProjectType(projectType);
|
||||
child.setProjectTypeInputType(ProjectTypeInputTypeEnum.MANUAL_INPUT.getValue());
|
||||
child.setIdentityNo(child.getParentRowId() + "_" + child.getRowId());
|
||||
|
|
@ -297,13 +306,15 @@ public class EBomImportService {
|
|||
if (!Objects.isNull(vo)) {
|
||||
child.setMaterialCategoryCode(vo.getMaterialCategoryCode());
|
||||
}
|
||||
return child;
|
||||
children.add(child);
|
||||
}
|
||||
|
||||
private BomNewEbomParentEntity buildParent(List<BaseMaterialVO> materialBaseInfos, EbomExcelDTO data) {
|
||||
BomNewEbomParentEntity parent = new BomNewEbomParentEntity();
|
||||
parent.setRowId(IdWorker.getId());
|
||||
|
||||
parent.setMaterialNo(data.getMaterialNo());
|
||||
parent.setMaterialDesc(data.getMaterialDesc());
|
||||
BaseMaterialVO vo = materialBaseInfos.stream()
|
||||
.filter(m -> m.getMaterialNo().equals(data.getMaterialNo()))
|
||||
.findFirst()
|
||||
|
|
@ -311,15 +322,16 @@ public class EBomImportService {
|
|||
if (!Objects.isNull(vo)) {
|
||||
parent.setDrawingNo(vo.getDrawingNo());
|
||||
parent.setUnitWeight(vo.getMaterialWeight());
|
||||
parent.setMaterialName(vo.getMaterialName());
|
||||
parent.setMaterialTexture(vo.getMaterialTexture());
|
||||
if (StrUtil.isBlank(data.getMaterialDesc())) {
|
||||
parent.setMaterialDesc(vo.getMaterialDesc());
|
||||
}
|
||||
}
|
||||
|
||||
parent.setMaterialNo(data.getMaterialNo());
|
||||
parent.setMaterialDesc(data.getMaterialDesc());
|
||||
parent.setMaterialTexture("");
|
||||
parent.setMaterialUnit(data.getUnit());
|
||||
parent.setNum(data.getNum());
|
||||
parent.setTotalWeight(BomUtil.calculateTotalWeight(parent.getNum(), parent.getUnitWeight()));
|
||||
//parent.setCurrentVersion(OriginalConstant.DEFAULT_BOM_VERSION);
|
||||
parent.setCurrentVersion(OriginalConstant.DEFAULT_BOM_VERSION);
|
||||
parent.setUserRootIs(0);
|
||||
parent.setRootIs(0);
|
||||
if (userRoleService.technician()) {
|
||||
|
|
@ -344,6 +356,7 @@ public class EBomImportService {
|
|||
parent.setOrderNumber(data.getOrderNum());
|
||||
parent.setDeptName(SessionUtil.getDepartName());
|
||||
parent.setSource(EBomSourceEnum.FROM_EXCE.getValue());
|
||||
parent.setSourceRowId(0L);
|
||||
return parent;
|
||||
}
|
||||
|
||||
|
|
@ -354,10 +367,12 @@ public class EBomImportService {
|
|||
* @param materialDesc 物料描述
|
||||
* @return 父级
|
||||
*/
|
||||
private BomNewEbomParentEntity buildRoot(List<BaseMaterialVO> materialBaseInfos, String materialNo, String materialDesc) {
|
||||
private BomNewEbomParentEntity buildTop(List<BaseMaterialVO> materialBaseInfos, String materialNo, String materialDesc) {
|
||||
BomNewEbomParentEntity parent = new BomNewEbomParentEntity();
|
||||
parent.setRowId(IdWorker.getId());
|
||||
|
||||
parent.setMaterialNo(materialNo);
|
||||
parent.setMaterialDesc(materialDesc);
|
||||
BaseMaterialVO vo = materialBaseInfos.stream()
|
||||
.filter(m -> m.getMaterialNo().equals(materialNo))
|
||||
.findFirst()
|
||||
|
|
@ -365,27 +380,33 @@ public class EBomImportService {
|
|||
if (!Objects.isNull(vo)) {
|
||||
parent.setDrawingNo(vo.getDrawingNo());
|
||||
parent.setUnitWeight(vo.getMaterialWeight());
|
||||
parent.setMaterialName(vo.getMaterialName());
|
||||
parent.setMaterialTexture(vo.getMaterialTexture());
|
||||
if (StrUtil.isBlank(materialDesc)) {
|
||||
parent.setMaterialDesc(vo.getMaterialDesc());
|
||||
}
|
||||
}
|
||||
|
||||
parent.setMaterialNo(materialNo);
|
||||
parent.setMaterialDesc(materialDesc);
|
||||
parent.setMaterialTexture("");
|
||||
parent.setMaterialUnit("PC");
|
||||
//parent.setUnitWeight(BigDecimal.ZERO);
|
||||
parent.setNum(BigDecimal.ONE);
|
||||
//parent.setTotalWeight(BomUtil.calculateTotalWeight(data.getNum(), data.getUnitWeight()));
|
||||
//parent.setCurrentVersion(OriginalConstant.DEFAULT_BOM_VERSION);
|
||||
parent.setCurrentVersion(OriginalConstant.DEFAULT_BOM_VERSION);
|
||||
// List<Long> cps = bomNewEbomChildService.lambdaQuery().eq(BomNewEbomChildEntity::getMaterialNo, materialNo)
|
||||
// .list()
|
||||
// .stream()
|
||||
// .map(BomNewEbomChildEntity::getParentRowId)
|
||||
// .collect(Collectors.toList());
|
||||
parent.setUserRootIs(1);
|
||||
parent.setRootIs(bomNewEbomChildService.getBaseMapper().shouldSetRootIs(materialNo));
|
||||
if (userRoleService.technician()) {
|
||||
//工艺人员
|
||||
parent.setStatus(EBomStatusEnum.CHECKED.getValue());
|
||||
parent.setCreatedJob(UserJobEnum.ENGINEER.getValue());
|
||||
parent.setAuditUserName(SessionUtil.getUserCode());
|
||||
parent.setAuditTime(LocalDateTime.now());
|
||||
parent.setRootIs(bomNewEbomChildService.getBaseMapper().shouldSetRootIs(materialNo));
|
||||
parent.setRootIsForWaitReview(0);
|
||||
} else {
|
||||
//设计人员
|
||||
parent.setRootIs(1);
|
||||
parent.setStatus(EBomStatusEnum.WAIT_CHECK.getValue());
|
||||
parent.setCreatedJob(UserJobEnum.DESIGNER.getValue());
|
||||
parent.setRootIsForWaitReview(1);
|
||||
|
|
@ -399,6 +420,7 @@ public class EBomImportService {
|
|||
parent.setRemark("");
|
||||
parent.setDeptName(SessionUtil.getDepartName());
|
||||
parent.setSource(EBomSourceEnum.FROM_EXCE.getValue());
|
||||
parent.setSourceRowId(0L);
|
||||
return parent;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,10 +6,7 @@ import cn.hutool.core.util.StrUtil;
|
|||
import cn.hutool.extra.spring.SpringUtil;
|
||||
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
|
||||
import com.nflg.product.base.core.conmon.util.SessionUtil;
|
||||
import com.nflg.product.bomnew.constant.EBomSourceEnum;
|
||||
import com.nflg.product.bomnew.constant.EBomStatusEnum;
|
||||
import com.nflg.product.bomnew.constant.ProjectTypeInputTypeEnum;
|
||||
import com.nflg.product.bomnew.constant.VirtualPackageTypeEnum;
|
||||
import com.nflg.product.bomnew.constant.*;
|
||||
import com.nflg.product.bomnew.pojo.dto.AddVirtrualMaterialDTO;
|
||||
import com.nflg.product.bomnew.pojo.entity.BomNewEbomChildEntity;
|
||||
import com.nflg.product.bomnew.pojo.entity.BomNewEbomParentEntity;
|
||||
|
|
@ -20,8 +17,6 @@ import com.nflg.product.bomnew.service.MaterialMainService;
|
|||
import com.nflg.product.bomnew.service.MaterialService;
|
||||
import com.nflg.product.bomnew.util.VersionUtil;
|
||||
import lombok.Getter;
|
||||
import org.ttzero.excel.reader.Col;
|
||||
import org.bouncycastle.LICENSE;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.math.BigDecimal;
|
||||
|
|
|
|||
|
|
@ -15,4 +15,9 @@ public class OrderNoUtil {
|
|||
return StrUtil.format("{}",no);
|
||||
|
||||
}
|
||||
|
||||
public static String next(String orderNo) {
|
||||
int no = Integer.parseInt(orderNo) + 1;
|
||||
return orderNo2Str(no);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -82,8 +82,8 @@
|
|||
FROM t_bom_new_ebom_parent p
|
||||
INNER JOIN t_bom_new_ebom_child c ON p.row_id = c.parent_row_id
|
||||
AND p.STATUS < 4
|
||||
WHERE c.material_no = #{materialNo}) THEN 1
|
||||
ELSE 0
|
||||
WHERE c.material_no = #{materialNo}) THEN 0
|
||||
ELSE 1
|
||||
END AS result;
|
||||
</select>
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue