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