批量替代BOM
This commit is contained in:
parent
a40c73a9ee
commit
04503f8c26
|
|
@ -1,12 +1,16 @@
|
|||
package com.nflg.product.bomnew.api.user;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import com.nflg.product.base.core.api.BaseApi;
|
||||
import com.nflg.product.bomnew.pojo.query.BatchBomQuery;
|
||||
import com.nflg.product.bomnew.pojo.query.PbomImportToSAPQuery;
|
||||
import com.nflg.product.bomnew.pojo.vo.BaseBomVO;
|
||||
import com.nflg.product.bomnew.pojo.vo.BaseMaterialVO;
|
||||
import com.nflg.product.bomnew.service.BatchBomService;
|
||||
import com.nflg.product.bomnew.service.BomNewEbomExportToSAP;
|
||||
import com.nflg.product.bomnew.service.BomNewPbomParentService;
|
||||
import com.nflg.product.bomnew.service.MaterialMainService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
|
|
@ -33,6 +37,8 @@ public class BatchBomApi extends BaseApi {
|
|||
private MaterialMainService materialMainService;
|
||||
@Resource
|
||||
private BatchBomService batchBomService;
|
||||
@Resource
|
||||
private BomNewPbomParentService bomNewPbomParentService;
|
||||
|
||||
@GetMapping("getMaterialInfo")
|
||||
@ApiOperation("查询物料信息")
|
||||
|
|
@ -53,4 +59,33 @@ public class BatchBomApi extends BaseApi {
|
|||
return ResultVO.success(batchBomService.getParentBomList(batchBomQuery));
|
||||
}
|
||||
|
||||
@PostMapping("updateEBom")
|
||||
@ApiOperation("更新EBOM并导入SAP")
|
||||
public ResultVO<List<BaseBomVO>> updateEBom(@RequestBody List<BaseBomVO> baseBomVOList) {
|
||||
List<Long> addRowIds = batchBomService.updateEBom(baseBomVOList);
|
||||
// 导入SAP
|
||||
if (CollUtil.isNotEmpty(addRowIds)) {
|
||||
addRowIds.forEach(rootRowId -> {
|
||||
BomNewEbomExportToSAP exportToSAP = new BomNewEbomExportToSAP();
|
||||
exportToSAP.export(rootRowId);
|
||||
});
|
||||
}
|
||||
return ResultVO.success();
|
||||
}
|
||||
|
||||
@PostMapping("updatePBom")
|
||||
@ApiOperation("更新PBOM并导入SAP")
|
||||
public ResultVO<List<BaseBomVO>> updatePBom(@RequestBody List<BaseBomVO> baseBomVOList) {
|
||||
List<Long> addRowIds = batchBomService.updatePBom(baseBomVOList);
|
||||
// 导入SAP
|
||||
if (CollUtil.isNotEmpty(addRowIds)) {
|
||||
addRowIds.forEach(rootRowId -> {
|
||||
PbomImportToSAPQuery query = new PbomImportToSAPQuery();
|
||||
query.setRootBomRowId(rootRowId);
|
||||
query.setIsForSale(false);
|
||||
bomNewPbomParentService.importToSAP2(query);
|
||||
});
|
||||
}
|
||||
return ResultVO.success();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -36,6 +36,9 @@ public class BaseBomVO {
|
|||
@ApiModelProperty("父级BOM版本号")
|
||||
private String parentVersion;
|
||||
|
||||
@ApiModelProperty("子级BOM ID")
|
||||
private Long childRowId;
|
||||
|
||||
@ApiModelProperty("原物料编码")
|
||||
private String materialNo;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,10 +1,22 @@
|
|||
package com.nflg.product.bomnew.service;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
|
||||
import com.nflg.product.base.core.exception.NflgBusinessException;
|
||||
import com.nflg.product.bomnew.constant.EBomStatusEnum;
|
||||
import com.nflg.product.bomnew.constant.PBomStatusEnum;
|
||||
import com.nflg.product.bomnew.constant.SapStatusEnum;
|
||||
import com.nflg.product.bomnew.mapper.master.BomNewEbomChildMapper;
|
||||
import com.nflg.product.bomnew.mapper.master.BomNewEbomParentMapper;
|
||||
import com.nflg.product.bomnew.mapper.master.BomNewPbomChildMapper;
|
||||
import com.nflg.product.bomnew.mapper.master.BomNewPbomParentMapper;
|
||||
import com.nflg.product.bomnew.pojo.entity.BomNewEbomChildEntity;
|
||||
import com.nflg.product.bomnew.pojo.entity.BomNewEbomParentEntity;
|
||||
import com.nflg.product.bomnew.pojo.entity.BomNewPbomChildEntity;
|
||||
import com.nflg.product.bomnew.pojo.entity.BomNewPbomParentEntity;
|
||||
import com.nflg.product.bomnew.pojo.query.BatchBomQuery;
|
||||
import com.nflg.product.bomnew.pojo.vo.BaseBomVO;
|
||||
import com.nflg.product.bomnew.pojo.vo.BaseMaterialVO;
|
||||
|
|
@ -13,14 +25,13 @@ import com.nflg.product.bomnew.util.VersionUtil;
|
|||
import lombok.extern.slf4j.Slf4j;
|
||||
import nflg.product.common.constant.STATE;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.math.BigDecimal;
|
||||
import java.math.RoundingMode;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Service
|
||||
|
|
@ -32,10 +43,18 @@ public class BatchBomService {
|
|||
@Resource
|
||||
private BomNewEbomChildService bomNewEbomChildService;
|
||||
@Resource
|
||||
private BomNewEbomParentMapper bomNewEbomParentMapper;
|
||||
@Resource
|
||||
private BomNewEbomChildMapper bomNewEbomChildMapper;
|
||||
@Resource
|
||||
private BomNewPbomParentService bomNewPbomParentService;
|
||||
@Resource
|
||||
private BomNewPbomChildService bomNewPbomChildService;
|
||||
@Resource
|
||||
private BomNewPbomParentMapper bomNewPbomParentMapper;
|
||||
@Resource
|
||||
private BomNewPbomChildMapper bomNewPbomChildMapper;
|
||||
@Resource
|
||||
private MaterialMainService materialMainService;
|
||||
|
||||
public List<BaseBomVO> getParentBomList(BatchBomQuery batchBomQuery) {
|
||||
|
|
@ -74,6 +93,7 @@ public class BatchBomService {
|
|||
Optional<BomNewEbomChildEntity> first = ebomChildEntities.stream().filter(item -> item.getParentRowId().equals(parent.getRowId())).findFirst();
|
||||
if (first.isPresent()) {
|
||||
BomNewEbomChildEntity ebomChild = first.get();
|
||||
baseBomVO.setChildRowId(ebomChild.getRowId());
|
||||
baseBomVO.setMaterialNo(ebomChild.getMaterialNo());
|
||||
baseBomVO.setNum(ebomChild.getNum());
|
||||
baseBomVO.setUnit(ebomChild.getMaterialUnit());
|
||||
|
|
@ -87,7 +107,49 @@ public class BatchBomService {
|
|||
}
|
||||
}
|
||||
} else if ("pbom".equals(bomType)) {
|
||||
|
||||
String materialNo = batchBomQuery.getMaterialNo();
|
||||
// 查询出子级
|
||||
List<BomNewPbomChildEntity> pbomChildEntities = bomNewPbomChildService.lambdaQuery()
|
||||
.eq(BomNewPbomChildEntity::getMaterialNo, materialNo)
|
||||
.eq(BomNewPbomChildEntity::getFacCode, batchBomQuery.getFactory()) // 工厂查询
|
||||
.list();
|
||||
if (CollectionUtil.isNotEmpty(pbomChildEntities)) {
|
||||
// 根据子级的parentRowId查询父级(状态是>=已发布,即正式表数据)
|
||||
List<Long> parentRowIds = pbomChildEntities.stream().map(BomNewPbomChildEntity::getParentRowId).collect(Collectors.toList());
|
||||
List<BomNewPbomParentEntity> pbomParentEntities = bomNewPbomParentService.lambdaQuery()
|
||||
.in(BomNewPbomParentEntity::getRowId, parentRowIds)
|
||||
.ge(BomNewPbomParentEntity::getStatus, PBomStatusEnum.PUBLISH.getValue())
|
||||
.orderByDesc(BomNewPbomParentEntity::getCreatedTime)
|
||||
.list();
|
||||
if (CollectionUtil.isNotEmpty(pbomParentEntities)) {
|
||||
long counter = 0;
|
||||
for (BomNewPbomParentEntity parent : pbomParentEntities) {
|
||||
BaseBomVO baseBomVO = new BaseBomVO();
|
||||
baseBomVO.setOrderNum(++counter);
|
||||
baseBomVO.setParentRowId(parent.getRowId());
|
||||
baseBomVO.setParentMaterialNo(parent.getMaterialNo());
|
||||
baseBomVO.setParentVersion(parent.getCurrentVersion());
|
||||
baseBomVO.setCreatedBy(parent.getCreatedBy());
|
||||
baseBomVO.setCreatedTime(parent.getCreatedTime());
|
||||
baseBomVO.setExpireEndTime(parent.getExpireEndTime());
|
||||
baseBomVO.setDeviseUserCode(parent.getDeviseUserCode());
|
||||
baseBomVO.setDeviseName(parent.getDeviseName());
|
||||
Optional<BomNewPbomChildEntity> first = pbomChildEntities.stream().filter(item -> item.getParentRowId().equals(parent.getRowId())).findFirst();
|
||||
if (first.isPresent()) {
|
||||
BomNewPbomChildEntity pbomChild = first.get();
|
||||
baseBomVO.setChildRowId(pbomChild.getRowId());
|
||||
baseBomVO.setMaterialNo(pbomChild.getMaterialNo());
|
||||
baseBomVO.setNum(pbomChild.getNum());
|
||||
baseBomVO.setUnit(pbomChild.getMaterialUnit());
|
||||
}
|
||||
baseBomVO.setNewMaterialNo(batchBomQuery.getNewMaterialNo());
|
||||
baseBomVO.setNewNum(batchBomQuery.getNewReplaceTimes().divide(batchBomQuery.getReplaceTimes(), 3, RoundingMode.HALF_UP).multiply(baseBomVO.getNum()));
|
||||
baseBomVO.setNewUnit(batchBomQuery.getNewMaterialUnit());
|
||||
baseBomVO.setNewVersion(VersionUtil.getNextVersion(baseBomVO.getParentVersion()));
|
||||
resultList.add(baseBomVO);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (CollectionUtil.isEmpty(resultList)) {
|
||||
return null;
|
||||
|
|
@ -111,4 +173,215 @@ public class BatchBomService {
|
|||
return resultList;
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新BOM并导入SAP(但是EBOM的话,不生成PBOM工作表)
|
||||
* @param baseBomVOList
|
||||
*/
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public List<Long> updateEBom(List<BaseBomVO> baseBomVOList) {
|
||||
if (CollectionUtil.isEmpty(baseBomVOList)) {
|
||||
return null;
|
||||
}
|
||||
List<BaseMaterialVO> materialBaseInfo = materialMainService.getMaterialBaseInfo(Collections.singletonList(baseBomVOList.get(0).getNewMaterialNo()));
|
||||
if (CollectionUtil.isEmpty(materialBaseInfo)) {
|
||||
throw new NflgBusinessException(STATE.ParamErr, "新物料编码不存在");
|
||||
}
|
||||
BaseMaterialVO newMaterialInfo= materialBaseInfo.get(0);
|
||||
List<Long> addRowIds = new ArrayList<>(baseBomVOList.size()); // 需要加入历史表的父级BOM ID
|
||||
List<Long> delRowIds = new ArrayList<>(baseBomVOList.size()); // 需要从正式表删除的父级BOM ID
|
||||
for (BaseBomVO baseBomVO: baseBomVOList) {
|
||||
// 找到父级
|
||||
BomNewEbomParentEntity ebomParentEntity = bomNewEbomParentService.lambdaQuery().eq(BomNewEbomParentEntity::getRowId, baseBomVO.getParentRowId()).one();
|
||||
if (ObjectUtil.isNotEmpty(ebomParentEntity)) {
|
||||
LocalDateTime now = LocalDateTime.now();
|
||||
// 找到该父级的所有子级列表
|
||||
List<BomNewEbomChildEntity> ebomChildEntities = bomNewEbomChildService.lambdaQuery().eq(BomNewEbomChildEntity::getParentRowId, baseBomVO.getParentRowId()).list();
|
||||
// 在子级列表中找到要被替换的那条子级
|
||||
List<BomNewEbomChildEntity> collect = ebomChildEntities.stream().filter(item -> item.getRowId().equals(baseBomVO.getChildRowId())).collect(Collectors.toList());
|
||||
BomNewEbomChildEntity replaceChild = collect.get(0);
|
||||
// 其他子级
|
||||
List<BomNewEbomChildEntity> otherChildren = ebomChildEntities.stream().filter(item -> !item.getRowId().equals(baseBomVO.getChildRowId())).collect(Collectors.toList());
|
||||
// 构建新版的父级规则:大版本号+1(如果该BOM还有编辑中的草稿版本,则草稿版本号也+1)
|
||||
BomNewEbomParentEntity newParent = new BomNewEbomParentEntity();
|
||||
BeanUtil.copyProperties(ebomParentEntity, newParent);
|
||||
newParent.setRowId(IdWorker.getId());
|
||||
newParent.setCurrentVersion(baseBomVO.getNewVersion()); // 新版本号
|
||||
// 新版本创建时间要更新,创建人要不要更新待定(根据权限管理考虑)
|
||||
newParent.setCreatedTime(now);
|
||||
newParent.setModifyTime(now);
|
||||
newParent.setSapState(SapStatusEnum.UNPUB_SAP.getValue());
|
||||
newParent.setSapTime(null);
|
||||
// 构建新版的子级规则:其他子级复制一份,被替换的子级改物料编码,数量,单位等
|
||||
List<BomNewEbomChildEntity> newChildList = new ArrayList<>(ebomChildEntities.size());
|
||||
otherChildren.forEach(item -> {
|
||||
BomNewEbomChildEntity newChild = new BomNewEbomChildEntity();
|
||||
BeanUtil.copyProperties(item, newChild);
|
||||
newChild.setRowId(IdWorker.getId());
|
||||
newChild.setParentRowId(newParent.getRowId());
|
||||
newChild.setIdentityNo(newParent.getRowId() + "_" + newChild.getRowId());
|
||||
// 新版本创建时间要更新,创建人要不要更新待定(根据权限管理考虑)
|
||||
newChild.setCreatedTime(now);
|
||||
newChild.setModifyTime(now);
|
||||
newChildList.add(newChild);
|
||||
});
|
||||
BomNewEbomChildEntity newReplaceChild = new BomNewEbomChildEntity();
|
||||
BeanUtil.copyProperties(replaceChild, newReplaceChild);
|
||||
newReplaceChild.setRowId(IdWorker.getId());
|
||||
newReplaceChild.setParentRowId(newParent.getRowId());
|
||||
newReplaceChild.setIdentityNo(newParent.getRowId() + "_" + newReplaceChild.getRowId());
|
||||
newReplaceChild.setMaterialNo(baseBomVO.getNewMaterialNo()); // 新物料编码
|
||||
newReplaceChild.setDrawingNo(newMaterialInfo.getDrawingNo());
|
||||
newReplaceChild.setMaterialName(newMaterialInfo.getMaterialName());
|
||||
newReplaceChild.setMaterialDesc(newMaterialInfo.getMaterialDesc()); // 新物料描述
|
||||
newReplaceChild.setMaterialTexture(newMaterialInfo.getMaterialTexture());
|
||||
newReplaceChild.setMaterialUnit(baseBomVO.getNewUnit()); // 新单位
|
||||
newReplaceChild.setNum(baseBomVO.getNewNum()); // 新数量
|
||||
newReplaceChild.setMaterialCategoryCode(newMaterialInfo.getMaterialCategoryCode());
|
||||
// TODO 新单重?新总重?要不要更新
|
||||
// 新版本创建时间要更新,创建人要不要更新待定(根据权限管理考虑)
|
||||
newReplaceChild.setCreatedTime(now);
|
||||
newReplaceChild.setModifyTime(now);
|
||||
newReplaceChild.setRemark("【批量替代BOM】由" + baseBomVO.getMaterialNo() + "替代为" + baseBomVO.getNewMaterialNo());
|
||||
newChildList.add(newReplaceChild);
|
||||
bomNewEbomParentService.save(newParent);
|
||||
bomNewEbomChildService.saveBatch(newChildList);
|
||||
addRowIds.add(newParent.getRowId());
|
||||
}
|
||||
delRowIds.add(ebomParentEntity.getRowId());
|
||||
}
|
||||
// 转入历史表
|
||||
if (CollUtil.isNotEmpty(addRowIds)) {
|
||||
bomNewEbomParentMapper.insertEBomFormalParent(addRowIds);
|
||||
bomNewEbomParentMapper.insertEBomFormalChild(addRowIds);
|
||||
}
|
||||
if (CollUtil.isNotEmpty(delRowIds)){
|
||||
// 转移后删除
|
||||
bomNewEbomParentService.delEBomHistory(delRowIds);
|
||||
}
|
||||
// TODO 如果有草稿中数据,草稿版本+1
|
||||
for (BaseBomVO baseBomVO: baseBomVOList) {
|
||||
BomNewEbomParentEntity draftParent = bomNewEbomParentService.lambdaQuery()
|
||||
.eq(BomNewEbomParentEntity::getMaterialNo, baseBomVO.getParentMaterialNo())
|
||||
.lt(BomNewEbomParentEntity::getStatus, EBomStatusEnum.PUBLISHED.getValue())
|
||||
.one();
|
||||
if (ObjectUtil.isNotEmpty(draftParent)) {
|
||||
// 草稿版本 A01 -> A02,A01.1 -> A02.1
|
||||
String[] currentVersionArr = draftParent.getCurrentVersion().split(".");
|
||||
String newVersion = VersionUtil.getNextVersion(currentVersionArr[0]);
|
||||
if (currentVersionArr.length > 1) {
|
||||
newVersion += "." + currentVersionArr[1];
|
||||
}
|
||||
draftParent.setCurrentVersion(newVersion);
|
||||
draftParent.setModifyTime(LocalDateTime.now());
|
||||
bomNewEbomParentService.updateById(draftParent);
|
||||
}
|
||||
}
|
||||
return addRowIds;
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新BOM并导入SAP
|
||||
* @param baseBomVOList
|
||||
*/
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public List<Long> updatePBom(List<BaseBomVO> baseBomVOList) {
|
||||
if (CollectionUtil.isEmpty(baseBomVOList)) {
|
||||
return null;
|
||||
}
|
||||
List<BaseMaterialVO> materialBaseInfo = materialMainService.getMaterialBaseInfo(Collections.singletonList(baseBomVOList.get(0).getNewMaterialNo()));
|
||||
if (CollectionUtil.isEmpty(materialBaseInfo)) {
|
||||
throw new NflgBusinessException(STATE.ParamErr, "新物料编码不存在");
|
||||
}
|
||||
BaseMaterialVO newMaterialInfo= materialBaseInfo.get(0);
|
||||
List<Long> addRowIds = new ArrayList<>(baseBomVOList.size()); // 需要加入历史表的父级BOM ID
|
||||
List<Long> delRowIds = new ArrayList<>(baseBomVOList.size()); // 需要从正式表删除的父级BOM ID
|
||||
for (BaseBomVO baseBomVO: baseBomVOList) {
|
||||
// 找到父级
|
||||
BomNewPbomParentEntity pbomParentEntity = bomNewPbomParentService.lambdaQuery().eq(BomNewPbomParentEntity::getRowId, baseBomVO.getParentRowId()).one();
|
||||
if (ObjectUtil.isNotEmpty(pbomParentEntity)) {
|
||||
LocalDateTime now = LocalDateTime.now();
|
||||
// 找到该父级的所有子级列表
|
||||
List<BomNewPbomChildEntity> pbomChildEntities = bomNewPbomChildService.lambdaQuery().eq(BomNewPbomChildEntity::getParentRowId, baseBomVO.getParentRowId()).list();
|
||||
// 在子级列表中找到要被替换的那条子级
|
||||
List<BomNewPbomChildEntity> collect = pbomChildEntities.stream().filter(item -> item.getRowId().equals(baseBomVO.getChildRowId())).collect(Collectors.toList());
|
||||
BomNewPbomChildEntity replaceChild = collect.get(0);
|
||||
// 其他子级
|
||||
List<BomNewPbomChildEntity> otherChildren = pbomChildEntities.stream().filter(item -> !item.getRowId().equals(baseBomVO.getChildRowId())).collect(Collectors.toList());
|
||||
// 构建新版的父级规则:大版本号+1(如果该BOM还有编辑中的草稿版本,则草稿版本号也+1)
|
||||
BomNewPbomParentEntity newParent = new BomNewPbomParentEntity();
|
||||
BeanUtil.copyProperties(pbomParentEntity, newParent);
|
||||
newParent.setRowId(IdWorker.getId());
|
||||
newParent.setCurrentVersion(baseBomVO.getNewVersion()); // 新版本号
|
||||
// 新版本创建时间要更新,创建人要不要更新待定(根据权限管理考虑)
|
||||
newParent.setCreatedTime(now);
|
||||
newParent.setModifyTime(now);
|
||||
newParent.setSapState(SapStatusEnum.UNPUB_SAP.getValue());
|
||||
newParent.setSapTime(null);
|
||||
// 构建新版的子级规则:其他子级复制一份,被替换的子级改物料编码,数量,单位等
|
||||
List<BomNewPbomChildEntity> newChildList = new ArrayList<>(pbomChildEntities.size());
|
||||
otherChildren.forEach(item -> {
|
||||
BomNewPbomChildEntity newChild = new BomNewPbomChildEntity();
|
||||
BeanUtil.copyProperties(item, newChild);
|
||||
newChild.setRowId(IdWorker.getId());
|
||||
newChild.setParentRowId(newParent.getRowId());
|
||||
newChild.setIdentityNo(newParent.getRowId() + "_" + newChild.getRowId());
|
||||
// 新版本创建时间要更新,创建人要不要更新待定(根据权限管理考虑)
|
||||
newChild.setCreatedTime(now);
|
||||
newChild.setModifyTime(now);
|
||||
newChildList.add(newChild);
|
||||
});
|
||||
BomNewPbomChildEntity newReplaceChild = new BomNewPbomChildEntity();
|
||||
BeanUtil.copyProperties(replaceChild, newReplaceChild);
|
||||
newReplaceChild.setRowId(IdWorker.getId());
|
||||
newReplaceChild.setParentRowId(newParent.getRowId());
|
||||
newReplaceChild.setIdentityNo(newParent.getRowId() + "_" + newReplaceChild.getRowId());
|
||||
newReplaceChild.setMaterialNo(baseBomVO.getNewMaterialNo()); // 新物料编码
|
||||
newReplaceChild.setDrawingNo(newMaterialInfo.getDrawingNo());
|
||||
newReplaceChild.setMaterialName(newMaterialInfo.getMaterialName());
|
||||
newReplaceChild.setMaterialDesc(newMaterialInfo.getMaterialDesc()); // 新物料描述
|
||||
newReplaceChild.setMaterialTexture(newMaterialInfo.getMaterialTexture());
|
||||
newReplaceChild.setMaterialUnit(baseBomVO.getNewUnit()); // 新单位
|
||||
newReplaceChild.setNum(baseBomVO.getNewNum()); // 新数量
|
||||
newReplaceChild.setMaterialCategoryCode(newMaterialInfo.getMaterialCategoryCode());
|
||||
// TODO 新单重?新总重?要不要更新
|
||||
// 新版本创建时间要更新,创建人要不要更新待定(根据权限管理考虑)
|
||||
newReplaceChild.setCreatedTime(now);
|
||||
newReplaceChild.setModifyTime(now);
|
||||
newReplaceChild.setRemark("【批量替代BOM】由" + baseBomVO.getMaterialNo() + "替代为" + baseBomVO.getNewMaterialNo());
|
||||
newChildList.add(newReplaceChild);
|
||||
bomNewPbomParentService.save(newParent);
|
||||
bomNewPbomChildService.saveBatch(newChildList);
|
||||
addRowIds.add(newParent.getRowId());
|
||||
}
|
||||
delRowIds.add(pbomParentEntity.getRowId());
|
||||
}
|
||||
// 转入历史表
|
||||
if (CollUtil.isNotEmpty(addRowIds)) {
|
||||
bomNewPbomParentMapper.insertPBomParentToFormal(addRowIds);
|
||||
bomNewPbomParentMapper.insertPBomChildToFormal(addRowIds);
|
||||
}
|
||||
if (CollUtil.isNotEmpty(delRowIds)){
|
||||
// 转移后删除
|
||||
bomNewPbomParentService.delPBom(delRowIds);
|
||||
}
|
||||
// TODO 如果有草稿中数据,草稿版本+1
|
||||
for (BaseBomVO baseBomVO: baseBomVOList) {
|
||||
BomNewPbomParentEntity draftParent = bomNewPbomParentService.lambdaQuery()
|
||||
.eq(BomNewPbomParentEntity::getMaterialNo, baseBomVO.getParentMaterialNo())
|
||||
.lt(BomNewPbomParentEntity::getStatus, PBomStatusEnum.PUBLISH.getValue())
|
||||
.one();
|
||||
if (ObjectUtil.isNotEmpty(draftParent)) {
|
||||
// 草稿版本 A01 -> A02,A01.1 -> A02.1
|
||||
String[] currentVersionArr = draftParent.getCurrentVersion().split(".");
|
||||
String newVersion = VersionUtil.getNextVersion(currentVersionArr[0]);
|
||||
if (currentVersionArr.length > 1) {
|
||||
newVersion += "." + currentVersionArr[1];
|
||||
}
|
||||
draftParent.setCurrentVersion(newVersion);
|
||||
draftParent.setModifyTime(LocalDateTime.now());
|
||||
bomNewPbomParentService.updateById(draftParent);
|
||||
}
|
||||
}
|
||||
return addRowIds;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue