feat: 电气专用bom功能

This commit is contained in:
曹鹏飞 2024-04-23 10:59:15 +08:00
parent a1666c26b4
commit cbb41e2519
3 changed files with 62 additions and 41 deletions

View File

@ -32,7 +32,7 @@ public class DQbomExcelVO extends BaseImportExcelDTO {
private BigDecimal num; private BigDecimal num;
@ExcelColumn("单位") @ExcelColumn("单位")
private String material_unit; private String materialUnit;
@ExcelColumn("项目类别") @ExcelColumn("项目类别")
private String projectType; private String projectType;

View File

@ -5,12 +5,10 @@ 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.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.conmon.util.SessionUtil;
import com.nflg.product.base.core.exception.NflgBusinessException; import com.nflg.product.base.core.exception.NflgBusinessException;
import com.nflg.product.bomnew.constant.BomConstant; import com.nflg.product.bomnew.constant.*;
import com.nflg.product.bomnew.constant.EBomExceptionStatusEnum;
import com.nflg.product.bomnew.constant.OriginalConstant;
import com.nflg.product.bomnew.constant.UserJobEnum;
import com.nflg.product.bomnew.pojo.dto.BaseImportExcelDTO; import com.nflg.product.bomnew.pojo.dto.BaseImportExcelDTO;
import com.nflg.product.bomnew.pojo.entity.BomNewDQbomChildEntity; import com.nflg.product.bomnew.pojo.entity.BomNewDQbomChildEntity;
import com.nflg.product.bomnew.pojo.entity.BomNewDQbomParentEntity; import com.nflg.product.bomnew.pojo.entity.BomNewDQbomParentEntity;
@ -80,7 +78,9 @@ public class DQBomImportService {
try { try {
checkInconsistentData(pcs.getLeft().get(0), pcs.getLeft(), pcs.getRight()); checkInconsistentData(pcs.getLeft().get(0), pcs.getLeft(), pcs.getRight());
} catch (NflgBusinessException ex) { } catch (NflgBusinessException ex) {
BOMMAP.put(SessionUtil.getUserCode(), pcs); if (Objects.equals(ex.getState(), STATE.InconsistentDataError)) {
BOMMAP.put(SessionUtil.getUserCode(), pcs);
}
throw ex; throw ex;
} }
@ -92,10 +92,6 @@ public class DQBomImportService {
} }
} }
private void checkData(List<DQbomExcelVO> datas) {
}
public void save() { public void save() {
Pair<List<BomNewDQbomParentEntity>, List<BomNewDQbomChildEntity>> pcs = BOMMAP.get(SessionUtil.getUserCode()); Pair<List<BomNewDQbomParentEntity>, List<BomNewDQbomChildEntity>> pcs = BOMMAP.get(SessionUtil.getUserCode());
VUtils.isTure(pcs == null).throwMessage("数据已丢失,请重新导入"); VUtils.isTure(pcs == null).throwMessage("数据已丢失,请重新导入");
@ -118,23 +114,31 @@ public class DQBomImportService {
// checkService.check(parents, children); // checkService.check(parents, children);
// } // }
private void checkInconsistentData(BomNewDQbomParentEntity parent, List<BomNewDQbomParentEntity> parents, List<BomNewDQbomChildEntity> children) throws JsonProcessingException { private void checkInconsistentData(BomNewDQbomParentEntity parent, List<BomNewDQbomParentEntity> parents,
List<BomNewDQbomChildEntity> children) throws JsonProcessingException {
log.debug("checkInconsistentDataparent" + JsonUtil.toJson(parent)); log.debug("checkInconsistentDataparent" + JsonUtil.toJson(parent));
BomNewDQbomParentEntity oldParent = dQBomParentService.getLastVersion(parent.getMaterialNo()); BomNewDQbomParentEntity oldParent = dQBomParentService.getLatestByMaterialNo(parent.getMaterialNo());
if (oldParent != null) { if (!Objects.isNull(oldParent)) {
if (!parent.getMaterialUnit().equals(oldParent.getMaterialUnit()) Set<String> cc = children.stream().filter(c -> c.getParentRowId().equals(parent.getRowId()))
|| !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) .map(BomNewDQbomChildEntity::getMaterialNo)
.collect(Collectors.toList()); .collect(Collectors.toSet());
List<String> oc = dQBomChildService.lambdaQuery().eq(BomNewDQbomChildEntity::getParentRowId, oldParent.getRowId()) Set<String> oc = dQBomChildService.lambdaQuery().eq(BomNewDQbomChildEntity::getParentRowId, oldParent.getRowId())
.list() .list()
.stream().map(BomNewDQbomChildEntity::getMaterialNo).collect(Collectors.toList()); .stream().map(BomNewDQbomChildEntity::getMaterialNo)
if (cc.size() != oc.size()) { .collect(Collectors.toSet());
throw new NflgBusinessException(STATE.InconsistentDataError, "子级节点数量不一致"); // if (!Sets.difference(cc, oc).isEmpty()) {
// throw new NflgBusinessException(STATE.InconsistentDataError, "导入的数据和已存在的数据不一致,是否覆盖?");
// }
boolean isSame = Sets.difference(cc, oc).isEmpty()
&& Objects.equals(parent.getMaterialUnit(), oldParent.getMaterialUnit())
&& Objects.equals(parent.getNum(), oldParent.getNum())
&& Objects.equals(parent.getMaterialTexture(), oldParent.getMaterialTexture());
VUtils.isTure(isSame).throwMessage("导入的数据已存在,请勿重复导入");
if (Objects.equals(oldParent.getStatus(), DQBomStatusEnum.WAIT_CONVERT.getValue())) {
VUtils.isTure(!Objects.equals(oldParent.getCreatedBy(), SessionUtil.getUserCode()))
.throwMessage(StrUtil.format("此物料已由{}导入过,不能再次导入", oldParent.getCreatedName()));
throw new NflgBusinessException(STATE.InconsistentDataError, "导入的数据和已存在的数据不一致,是否覆盖?");
} }
List<BomNewDQbomParentEntity> ps = parents.stream().filter(p -> cc.contains(p.getMaterialNo())) List<BomNewDQbomParentEntity> ps = parents.stream().filter(p -> cc.contains(p.getMaterialNo()))
@ -188,15 +192,28 @@ public class DQBomImportService {
BomNewDQbomParentEntity parent = parents.stream().filter(p -> p.getMaterialNo().equals(data.getMaterialNo())) BomNewDQbomParentEntity parent = parents.stream().filter(p -> p.getMaterialNo().equals(data.getMaterialNo()))
.findFirst() .findFirst()
.orElse(dQBomParentService.lambdaQuery() .orElse(null);
.eq(BomNewDQbomParentEntity::getLastVersionIs, 1)
.eq(BomNewDQbomParentEntity::getMaterialNo, data.getMaterialNo())
.orderByDesc(BomNewDQbomParentEntity::getRowId)
.list()
.stream().findFirst().orElse(null)
);
//if (parent == null && (count - 1 != index || datas.get(index + 1).getLevel() > data.getLevel())) { //if (parent == null && (count - 1 != index || datas.get(index + 1).getLevel() > data.getLevel())) {
if (parent == null && count - 1 > index && datas.get(index + 1).getLevel() > data.getLevel()) { if (parent == null && count - 1 > index && datas.get(index + 1).getLevel() > data.getLevel()) {
// if (index == 0) {
// BomNewDQbomParentEntity old = dQBomParentService.lambdaQuery()
// .eq(data.getProjectType().equals("L"), BomNewDQbomParentEntity::getMaterialNo, data.getMaterialNo())
// .eq(data.getProjectType().equals("T"), BomNewDQbomParentEntity::getMaterialName, data.getMaterialName())
// .orderByDesc(BomNewDQbomParentEntity::getRowId)
// .last(" limit 1")
// .one();
// if (!Objects.isNull(old)) {
// VUtils.isTure(Objects.equals(data.getMaterialUnit(), old.getMaterialUnit())
// || Objects.equals(data.getNum(), old.getNum())
// || Objects.equals(data.getMaterialTexture(), old.getMaterialTexture()))
// .throwMessage("导入的数据已存在,请勿重复导入");
// if (Objects.equals(old.getStatus(), DQBomStatusEnum.WAIT_CONVERT.getValue())) {
// VUtils.isTure(!Objects.equals(old.getCreatedBy(), SessionUtil.getUserCode()))
// .throwMessage(StrUtil.format("此物料已由{}导入过,不能再次导入", old.getCreatedName()));
// }
// }
// }
parent = new BomNewDQbomParentEntity(); parent = new BomNewDQbomParentEntity();
parent.setRowId(IdWorker.getId()); parent.setRowId(IdWorker.getId());
parent.setLevel(data.getLevel()); parent.setLevel(data.getLevel());
@ -204,7 +221,7 @@ public class DQBomImportService {
parent.setMaterialNo(data.getMaterialNo()); parent.setMaterialNo(data.getMaterialNo());
parent.setMaterialName(data.getMaterialName()); parent.setMaterialName(data.getMaterialName());
parent.setMaterialTexture(data.getMaterialTexture()); parent.setMaterialTexture(data.getMaterialTexture());
parent.setMaterialUnit(data.getMaterial_unit()); parent.setMaterialUnit(data.getMaterialUnit());
parent.setUnitWeight(data.getUnitWeight()); parent.setUnitWeight(data.getUnitWeight());
parent.setNum(Objects.isNull(data.getNum()) ? BigDecimal.ZERO : data.getNum()); parent.setNum(Objects.isNull(data.getNum()) ? BigDecimal.ZERO : data.getNum());
parent.setTotalWeight(BomUtil.calculateTotalWeight(data.getNum(), data.getUnitWeight())); parent.setTotalWeight(BomUtil.calculateTotalWeight(data.getNum(), data.getUnitWeight()));
@ -246,7 +263,7 @@ public class DQBomImportService {
child.setLevel(data.getLevel()); child.setLevel(data.getLevel());
child.setMaterialName(data.getMaterialName()); child.setMaterialName(data.getMaterialName());
child.setMaterialTexture(data.getMaterialTexture()); child.setMaterialTexture(data.getMaterialTexture());
child.setMaterialUnit(data.getMaterial_unit()); child.setMaterialUnit(data.getMaterialUnit());
child.setUnitWeight(data.getUnitWeight()); child.setUnitWeight(data.getUnitWeight());
child.setTotalWeight(BomUtil.calculateTotalWeight(data.getNum(), data.getUnitWeight())); child.setTotalWeight(BomUtil.calculateTotalWeight(data.getNum(), data.getUnitWeight()));
child.setOrderNumber(StrUtil.padPre(String.valueOf(orderMap.get(data.getLevel())), 3, '0')); child.setOrderNumber(StrUtil.padPre(String.valueOf(orderMap.get(data.getLevel())), 3, '0'));
@ -274,16 +291,19 @@ public class DQBomImportService {
log.debug("电气bom导入excel第{}行,处理前:{}", rowNum.get(), JSON.toJSONString(dQbomExcelVO)); log.debug("电气bom导入excel第{}行,处理前:{}", rowNum.get(), JSON.toJSONString(dQbomExcelVO));
dQbomExcelVO.setRowNum(rowNum.get()); dQbomExcelVO.setRowNum(rowNum.get());
if (StrUtil.isBlank(dQbomExcelVO.getMaterialNo())) { if (dQbomExcelVO.getProjectType().equals("T")) {
BomNewDQbomParentEntity p = dQBomParentService.lambdaQuery() BomNewDQbomParentEntity p = dQBomParentService.lambdaQuery()
.eq(BomNewDQbomParentEntity::getMaterialName, dQbomExcelVO.getMaterialName()) .eq(BomNewDQbomParentEntity::getMaterialName, dQbomExcelVO.getMaterialName())
.orderByDesc(BomNewDQbomParentEntity::getRowId) .orderByDesc(BomNewDQbomParentEntity::getRowId)
.list() .last(" limit 1")
.stream().findFirst().orElse(null); .one();
if (p != null) { if (p != null) {
dQbomExcelVO.setMaterialNo(p.getMaterialNo()); dQbomExcelVO.setMaterialNo(p.getMaterialNo());
dQbomExcelVO.setDrawingNo(p.getMaterialNo());
} else { } else {
dQbomExcelVO.setMaterialNo(BomConstant.DRAWING_NO_TEMPORARY_PREFIX + IdWorker.getIdStr()); String id = BomConstant.DRAWING_NO_TEMPORARY_PREFIX + System.currentTimeMillis();
dQbomExcelVO.setMaterialNo(id);
dQbomExcelVO.setDrawingNo(id);
} }
} }

View File

@ -16,11 +16,12 @@ import java.util.List;
@Service @Service
public class DQBomParentService extends ServiceImpl<BomNewDQbomParentMapper, BomNewDQbomParentEntity> { public class DQBomParentService extends ServiceImpl<BomNewDQbomParentMapper, BomNewDQbomParentEntity> {
public BomNewDQbomParentEntity getLastVersion(String materialNo) { public BomNewDQbomParentEntity getLatestByMaterialNo(String materialNo) {
return this.lambdaQuery().eq(BomNewDQbomParentEntity::getLastVersionIs, 1) return this.lambdaQuery()
.eq(BomNewDQbomParentEntity::getMaterialNo, materialNo) .eq(BomNewDQbomParentEntity::getMaterialNo, materialNo)
.list() .orderByDesc(BomNewDQbomParentEntity::getRowId)
.stream().findFirst().orElse(null); .last("limit 1")
.one();
} }
public void setLastVersionIs0(List<String> materialNo) { public void setLastVersionIs0(List<String> materialNo) {