feat(pbom): 重写复制功能

This commit is contained in:
曹鹏飞 2024-06-06 08:34:03 +08:00
parent dfbcad0649
commit e823ed6e53
1 changed files with 33 additions and 14 deletions

View File

@ -34,6 +34,7 @@ import com.nflg.product.bomnew.util.*;
import lombok.extern.slf4j.Slf4j;
import nflg.product.common.constant.STATE;
import nflg.product.common.vo.ResultVO;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@ -1240,6 +1241,7 @@ public class BomNewPbomParentService extends ServiceImpl<BomNewPbomParentMapper,
BomNewPbomParentEntity source = getById(param.getSourceBomRowId());
VUtils.isTure(Objects.isNull(source)).throwMessage("来源bom不存在");
VUtils.isTure(source.getStatus() < PBomStatusEnum.PUBLISH.getValue()).throwMessage("此bom未发布正式版");
VUtils.isTure(StrUtil.equals(source.getFacCode(), param.getTargetFacCode())).throwMessage("目标工厂不能与原工厂相同");
PbomSaveDTO<BomNewPbomParentEntity> dtoParent = new PbomSaveDTO<>();
PbomSaveDTO<BomNewPbomChildEntity> dtoChild = new PbomSaveDTO<>();
@ -1267,7 +1269,7 @@ public class BomNewPbomParentService extends ServiceImpl<BomNewPbomParentMapper,
throw new NflgBusinessException(STATE.InconsistentDataError, "你已在工作表创建了该记录,请选择是否覆盖?");
} else if (param.getReplaceIfExistDraft()) {
dtoParent.addToDelete(old.getRowId());
BomNewPbomParentEntity top = buildPbomParent(source, param.getTargetFacCode(), old.getCurrentVersion());
BomNewPbomParentEntity top = buildPbomParent(source, param.getTargetFacCode(), old.getCurrentVersion(), 1);
dtoParent.addToAdd(top);
//删除原数据的下级
dtoChild.addToDelete(pbomChildService.lambdaQuery()
@ -1279,18 +1281,17 @@ public class BomNewPbomParentService extends ServiceImpl<BomNewPbomParentMapper,
.collect(Collectors.toSet()));
//复制子级
List<BomNewPbomChildEntity> cs = copyChildren(source.getRowId(), param.getTargetFacCode(), top.getRowId());
top.setBomExist(CollUtil.isNotEmpty(cs) ? 1 : 0);
if (CollUtil.isNotEmpty(cs)) {
dtoChild.addToAdd(cs);
if (param.getCopyType() == 1) {
//多层复制模式
copy(cs, param.getTargetFacCode(), dtoParent, dtoChild);
}
copy(cs, source.getFacCode(), param.getTargetFacCode(), dtoParent, dtoChild);
}
}
}
} else {
//正式表已存在记录
BomNewPbomParentEntity top = buildPbomParent(source, param.getTargetFacCode(), VersionUtil.getNextVersion(old.getCurrentVersion()));
BomNewPbomParentEntity top = buildPbomParent(source, param.getTargetFacCode(), "A00", 1);
dtoParent.addToAdd(top);
//复制子级
List<BomNewPbomChildEntity> cs = copyChildren(source.getRowId(), param.getTargetFacCode(), top.getRowId());
@ -1298,7 +1299,23 @@ public class BomNewPbomParentService extends ServiceImpl<BomNewPbomParentMapper,
dtoChild.addToAdd(cs);
if (param.getCopyType() == 1) {
//多层复制模式
copy(cs, param.getTargetFacCode(), dtoParent, dtoChild);
copy(cs, source.getFacCode(), param.getTargetFacCode(), dtoParent, dtoChild);
}
}
}
} else {
//正式表已存在记录
BomNewPbomParentEntity top = buildPbomParent(source, param.getTargetFacCode(), VersionUtil.getNextVersion(old.getCurrentVersion()), 1);
dtoParent.addToAdd(top);
old.setLastVersionIs(0);
dtoParent.addToUpdate(old);
//复制子级
List<BomNewPbomChildEntity> cs = copyChildren(source.getRowId(), param.getTargetFacCode(), top.getRowId());
if (CollUtil.isNotEmpty(cs)) {
dtoChild.addToAdd(cs);
if (param.getCopyType() == 1) {
//多层复制模式
copy(cs, source.getFacCode(), param.getTargetFacCode(), dtoParent, dtoChild);
}
}
}
@ -1330,19 +1347,20 @@ public class BomNewPbomParentService extends ServiceImpl<BomNewPbomParentMapper,
}
}
private void copy(List<BomNewPbomChildEntity> cs, String targetFacCode
private void copy(List<BomNewPbomChildEntity> cs, String sourceFacCode, String targetFacCode
, PbomSaveDTO<BomNewPbomParentEntity> dtoParent, PbomSaveDTO<BomNewPbomChildEntity> dtoChild) {
List<BomNewPbomParentEntity> ps = getLatestParents(cs.stream().map(BomNewPbomChildEntity::getMaterialNo).collect(Collectors.toSet())
, targetFacCode);
, sourceFacCode);
if (CollUtil.isNotEmpty(ps)) {
ps.forEach(p -> {
BomNewPbomParentEntity np = copyParent(p, targetFacCode);
if (Objects.nonNull(np)) {
dtoParent.addToAdd(np);
List<BomNewPbomChildEntity> ccs = copyChildren(p.getRowId(), targetFacCode, np.getRowId());
np.setBomExist(CollUtil.isNotEmpty(ccs) ? 1 : 0);
if (CollUtil.isNotEmpty(ccs)) {
dtoChild.addToAdd(ccs);
copy(ccs, targetFacCode, dtoParent, dtoChild);
copy(ccs, sourceFacCode, targetFacCode, dtoParent, dtoChild);
}
}
});
@ -1350,12 +1368,12 @@ public class BomNewPbomParentService extends ServiceImpl<BomNewPbomParentMapper,
}
private BomNewPbomParentEntity copyParent(BomNewPbomParentEntity parent, String targetFacCode) {
if (lambdaQuery()
if (!lambdaQuery()
.eq(BomNewPbomParentEntity::getMaterialNo, parent.getMaterialNo())
.eq(BomNewPbomParentEntity::getStatus, PBomStatusEnum.WAIT_PUBLISH.getValue())
.exists()) {
//工作表不存在记录则添加
return buildPbomParent(parent, targetFacCode, parent.getCurrentVersion());
return buildPbomParent(parent, targetFacCode, parent.getCurrentVersion(), 0);
}
return null;
}
@ -1382,8 +1400,9 @@ public class BomNewPbomParentService extends ServiceImpl<BomNewPbomParentMapper,
return cc;
}
private BomNewPbomParentEntity buildPbomParent(BomNewPbomParentEntity source, String targetFacCode, String currentVersion) {
BomNewPbomParentEntity newP = Convert.convert(BomNewPbomParentEntity.class, source);
private BomNewPbomParentEntity buildPbomParent(BomNewPbomParentEntity source, String targetFacCode, String currentVersion, Integer isUserRoot) {
BomNewPbomParentEntity newP = new BomNewPbomParentEntity();
BeanUtils.copyProperties(source, newP);
newP.setRowId(IdWorker.getId());
newP.setExpireEndTime(null);
newP.setLastConvertMbomTime(null);
@ -1391,7 +1410,7 @@ public class BomNewPbomParentService extends ServiceImpl<BomNewPbomParentMapper,
newP.setNoticeNums("");
newP.setOrderNo("");
newP.setRemark("");
newP.setSapState(1);
newP.setSapState(isUserRoot == 1 ? 1 : null);
newP.setSapTime(null);
newP.setSuperMaterialStatus(0);
newP.setCreatedBy(SessionUtil.getUserCode());
@ -1405,7 +1424,7 @@ public class BomNewPbomParentService extends ServiceImpl<BomNewPbomParentMapper,
newP.setSource(4);
newP.setEditStatus(PBomEditStatusEnum.HANDLER_CREATED.getValue());
newP.setStatus(PBomStatusEnum.WAIT_PUBLISH.getValue());
newP.setUserRootIs(1);
newP.setUserRootIs(isUserRoot);
newP.setRootIs(newP.getMaterialNo().startsWith("31") ? 1 : 0);
newP.setReleaseUserName("");
newP.setReleaseTime(null);
@ -1413,7 +1432,7 @@ public class BomNewPbomParentService extends ServiceImpl<BomNewPbomParentMapper,
newP.setFacCode(targetFacCode);
newP.setModifyTime(null);
newP.setChangeDesc("");
newP.setLastVersionIs(0);
newP.setLastVersionIs(1);
newP.setBomExist(1);
newP.setCurrentVersion(currentVersion);
newP.setDeviseName("");