1.PBom复制
This commit is contained in:
parent
e0073209ba
commit
60c8599401
|
|
@ -4,12 +4,14 @@ import cn.hutool.core.collection.CollUtil;
|
|||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.nflg.product.base.core.api.BaseApi;
|
||||
import com.nflg.product.bomnew.constant.PBomEditStatusEnum;
|
||||
import com.nflg.product.bomnew.pojo.dto.CopyPBomParam;
|
||||
import com.nflg.product.bomnew.pojo.dto.EditPBomDelDTO;
|
||||
import com.nflg.product.bomnew.pojo.dto.EditPBomParamDTO;
|
||||
import com.nflg.product.bomnew.pojo.dto.TechnologyPackageParam;
|
||||
import com.nflg.product.bomnew.pojo.entity.BomNewTechnologyPackageTypeEntity;
|
||||
import com.nflg.product.bomnew.pojo.query.BomNewPbomParentQuery;
|
||||
import com.nflg.product.bomnew.pojo.vo.BaseMaterialVO;
|
||||
import com.nflg.product.bomnew.pojo.vo.BomCopyCheckResultVO;
|
||||
import com.nflg.product.bomnew.pojo.vo.BomNewPbomParentVO;
|
||||
import com.nflg.product.bomnew.pojo.vo.BomNewTechnologyPackageTypeVO;
|
||||
import com.nflg.product.bomnew.service.BomNewPbomParentService;
|
||||
|
|
@ -25,6 +27,7 @@ import javax.servlet.http.HttpServletResponse;
|
|||
import javax.validation.Valid;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
|
||||
/**
|
||||
* t_bom_new_pbom_parent 表控制层
|
||||
|
|
@ -129,6 +132,25 @@ public class PBomApi extends BaseApi {
|
|||
}
|
||||
|
||||
|
||||
@GetMapping("copyBomCheck")
|
||||
@ApiOperation("复制前检查")
|
||||
public ResultVO<List<BomCopyCheckResultVO>> copyBomCheck(@RequestParam("sourceBomRowId") Long sourceBomRowId , @RequestParam("targetFacCode") String targetFacCode ) throws ExecutionException, InterruptedException {
|
||||
|
||||
return ResultVO.success(bomNewPbomParentService.copyBomCheck(sourceBomRowId,targetFacCode));
|
||||
|
||||
}
|
||||
|
||||
@PostMapping("copyFrom")
|
||||
@ApiOperation("复制从")
|
||||
public ResultVO<Boolean> copyFrom(@Valid @RequestBody CopyPBomParam param ) throws ExecutionException, InterruptedException {
|
||||
bomNewPbomParentService.copyFrom(param);
|
||||
return ResultVO.success(true);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -141,4 +141,10 @@ public class MasterDataSourceConfig {
|
|||
|
||||
}
|
||||
|
||||
@Bean("getPBomDetailPool")
|
||||
public ForkJoinPool getPBomDetailPool() {
|
||||
return new ForkJoinPool();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,4 +19,6 @@ public interface BomNewPbomChildMapper extends BaseMapper<BomNewPbomChildEntity>
|
|||
void delByRowId(@Param("rowIds")List<Long> rowIds);
|
||||
|
||||
void setVirtualPart(@Param("rowIds") List<Long> rowIds);
|
||||
|
||||
void delByParentRowId(@Param("parentRowId") Long parentRowId);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,26 @@
|
|||
package com.nflg.product.bomnew.pojo.dto;
|
||||
|
||||
import com.nflg.product.bomnew.pojo.vo.BomCopyCheckResultVO;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* PBom-复制参数
|
||||
*/
|
||||
@Data
|
||||
public class CopyPBomParam {
|
||||
|
||||
@ApiModelProperty("源Bom行ID")
|
||||
@NotNull(message = "源Bom行ID不能为空")
|
||||
private Long sourceBomRowId;
|
||||
|
||||
@ApiModelProperty("目标工厂编码")
|
||||
@NotNull(message = "目标工厂编码不能为空")
|
||||
private String targetFacCode;
|
||||
|
||||
@ApiModelProperty("用户确认结果")
|
||||
private List<BomCopyCheckResultVO> checkResult;
|
||||
}
|
||||
|
|
@ -0,0 +1,32 @@
|
|||
package com.nflg.product.bomnew.pojo.vo;
|
||||
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* PBOM复制检查结果VO
|
||||
*/
|
||||
@Data
|
||||
public class BomCopyCheckResultVO {
|
||||
@ApiModelProperty("Bom行ID")
|
||||
private Long bomRowId=0L;
|
||||
|
||||
@ApiModelProperty(value = "工厂编码")
|
||||
private String facCode;
|
||||
|
||||
@ApiModelProperty("物料编码")
|
||||
private String materialNo;
|
||||
|
||||
@ApiModelProperty("物料名称")
|
||||
private String materialName;
|
||||
|
||||
@ApiModelProperty("物料描述")
|
||||
private String materialDesc;
|
||||
|
||||
@ApiModelProperty(value = "版本号")
|
||||
private String currentVersion;
|
||||
|
||||
@ApiModelProperty("用户确认结果 0-无需处理 1-覆盖")
|
||||
private Integer checkResult=0;
|
||||
|
||||
}
|
||||
|
|
@ -5,16 +5,15 @@ import cn.hutool.core.collection.CollUtil;
|
|||
import cn.hutool.core.convert.Convert;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.nflg.product.base.core.conmon.util.SessionUtil;
|
||||
import com.nflg.product.base.core.exception.NflgBusinessException;
|
||||
import com.nflg.product.bomnew.constant.OriginalConstant;
|
||||
import com.nflg.product.bomnew.constant.PBomEditStatusEnum;
|
||||
import com.nflg.product.bomnew.constant.PBomStatusEnum;
|
||||
import com.nflg.product.bomnew.mapper.master.BomNewPbomParentMapper;
|
||||
import com.nflg.product.bomnew.pojo.dto.CopyPBomParam;
|
||||
import com.nflg.product.bomnew.pojo.dto.EditPBomDelDTO;
|
||||
import com.nflg.product.bomnew.pojo.dto.EditPBomParamDTO;
|
||||
import com.nflg.product.bomnew.pojo.dto.TechnologyPackageParam;
|
||||
|
|
@ -23,13 +22,16 @@ import com.nflg.product.bomnew.pojo.entity.BomNewPbomParentEntity;
|
|||
import com.nflg.product.bomnew.pojo.entity.BomNewTechnologyPackageTypeEntity;
|
||||
import com.nflg.product.bomnew.pojo.entity.MaterialMainEntity;
|
||||
import com.nflg.product.bomnew.pojo.query.BomNewPbomParentQuery;
|
||||
import com.nflg.product.bomnew.pojo.vo.BaseMaterialVO;
|
||||
import com.nflg.product.bomnew.pojo.vo.BomNewPbomEditExcelVO;
|
||||
import com.nflg.product.bomnew.pojo.vo.BomNewPbomParentVO;
|
||||
import com.nflg.product.bomnew.pojo.vo.*;
|
||||
import com.nflg.product.bomnew.service.domain.PBom.BomCopy;
|
||||
import com.nflg.product.bomnew.service.domain.PBom.PBomDetailTask;
|
||||
import com.nflg.product.bomnew.service.domain.PBom.TechnologyPackageParamBuilder;
|
||||
import com.nflg.product.bomnew.util.*;
|
||||
import com.nflg.product.bomnew.util.EecExcelUtil;
|
||||
import com.nflg.product.bomnew.util.ListCommonUtil;
|
||||
import com.nflg.product.bomnew.util.MaterialshouldBomExistUtil;
|
||||
import com.nflg.product.bomnew.util.VUtils;
|
||||
import nflg.product.common.constant.STATE;
|
||||
import org.apache.tomcat.util.http.ResponseUtil;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.ttzero.excel.entity.Workbook;
|
||||
|
|
@ -37,12 +39,12 @@ import org.ttzero.excel.entity.Workbook;
|
|||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.ForkJoinPool;
|
||||
import java.util.concurrent.ForkJoinTask;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
|
||||
|
|
@ -71,6 +73,10 @@ public class BomNewPbomParentService extends ServiceImpl<BomNewPbomParentMapper,
|
|||
@Resource
|
||||
MaterialService materialService;
|
||||
|
||||
@Resource
|
||||
@Qualifier(value = "getPBomDetailPool")
|
||||
private ForkJoinPool bomDetailPool;
|
||||
|
||||
/**
|
||||
* pbom-工作列表
|
||||
*
|
||||
|
|
@ -209,11 +215,12 @@ public class BomNewPbomParentService extends ServiceImpl<BomNewPbomParentMapper,
|
|||
|
||||
/**
|
||||
* 编辑-导出EXCEL
|
||||
*
|
||||
* @param bomRowId
|
||||
* @param response
|
||||
*/
|
||||
public void editExport(Long bomRowId, HttpServletResponse response) throws IOException {
|
||||
EecExcelUtil.setResponseExcelHeader(response,"bom明细列表");
|
||||
public void editExport(Long bomRowId, HttpServletResponse response) throws IOException {
|
||||
EecExcelUtil.setResponseExcelHeader(response, "bom明细列表");
|
||||
List<BomNewPbomParentVO> child = this.getChild(bomRowId);
|
||||
List<BomNewPbomEditExcelVO> result = Convert.toList(BomNewPbomEditExcelVO.class, child);
|
||||
|
||||
|
|
@ -221,41 +228,44 @@ public class BomNewPbomParentService extends ServiceImpl<BomNewPbomParentMapper,
|
|||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 创建工艺包
|
||||
*
|
||||
* @param packageParam
|
||||
* @return
|
||||
*/
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public BaseMaterialVO createTechnologyPackage(TechnologyPackageParam packageParam) throws IOException {
|
||||
VUtils.isTure(Objects.isNull(packageParam.getTechnologyPackageTypeRowId())).throwMessage("请选择工艺包类型");
|
||||
BomNewTechnologyPackageTypeEntity technologyPackageTypeEntity = technologyPackageTypeService.getById(packageParam.getTechnologyPackageTypeRowId());
|
||||
//单条物料
|
||||
String drawingNo="";
|
||||
String materialName="";
|
||||
String materialDesc="";
|
||||
BomNewPbomParentVO result=null;
|
||||
if(packageParam.getRowIds().size()==1){
|
||||
String drawingNo = "";
|
||||
String materialName = "";
|
||||
String materialDesc = "";
|
||||
BomNewPbomParentVO result = null;
|
||||
if (packageParam.getRowIds().size() == 1) {
|
||||
BomNewPbomChildEntity child = pbomChildService.getById(packageParam.getRowIds().get(0));
|
||||
result=Convert.convert(BomNewPbomParentVO.class,child);
|
||||
result = Convert.convert(BomNewPbomParentVO.class, child);
|
||||
} else {
|
||||
BomNewPbomParentEntity parent = this.getById(packageParam.getBomRowId());
|
||||
result = Convert.convert(BomNewPbomParentVO.class, parent);
|
||||
}
|
||||
else {
|
||||
BomNewPbomParentEntity parent=this.getById(packageParam.getBomRowId());
|
||||
result=Convert.convert(BomNewPbomParentVO.class,parent);
|
||||
}
|
||||
materialMainService.intiMaterialInfo(ImmutableList.of(result) );
|
||||
VUtils.isTure(StrUtil.isBlank(result.getMaterialCategoryCode()) || !result.getMaterialCategoryCode().startsWith("20") ).throwMessage("插入工艺包的物料需时制作物料");
|
||||
materialMainService.intiMaterialInfo(ImmutableList.of(result));
|
||||
VUtils.isTure(StrUtil.isBlank(result.getMaterialCategoryCode()) || !result.getMaterialCategoryCode().startsWith("20")).throwMessage("插入工艺包的物料需时制作物料");
|
||||
|
||||
drawingNo=StrUtil.join("", result.getDrawingNo(),technologyPackageTypeEntity.getDrawingNoSuffix());
|
||||
drawingNo = StrUtil.join("", result.getDrawingNo(), technologyPackageTypeEntity.getDrawingNoSuffix());
|
||||
// 检查改图号是否已存在主数据中
|
||||
List<MaterialMainEntity> materials = materialMainService.lambdaQuery().eq(MaterialMainEntity::getDrawingNo, drawingNo).list();
|
||||
|
||||
if(CollUtil.isNotEmpty(materials)){
|
||||
return Convert.convert(BaseMaterialVO.class,materials.get(0));
|
||||
if (CollUtil.isNotEmpty(materials)) {
|
||||
return Convert.convert(BaseMaterialVO.class, materials.get(0));
|
||||
}
|
||||
|
||||
|
||||
materialName=StrUtil.join("",result.getMaterialName(),technologyPackageTypeEntity.getRemark());
|
||||
materialDesc=StrUtil.join(" ",materialName,drawingNo);
|
||||
materialName = StrUtil.join("", result.getMaterialName(), technologyPackageTypeEntity.getRemark());
|
||||
materialDesc = StrUtil.join(" ", materialName, drawingNo);
|
||||
|
||||
String materialNo = materialService.addMaterial(drawingNo, materialName, materialDesc, "201201");
|
||||
|
||||
|
|
@ -263,26 +273,76 @@ public class BomNewPbomParentService extends ServiceImpl<BomNewPbomParentMapper,
|
|||
}
|
||||
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void insertTechnologyPackage(TechnologyPackageParam technologyPackageParam){
|
||||
public void insertTechnologyPackage(TechnologyPackageParam technologyPackageParam) {
|
||||
VUtils.isTure(StrUtil.isBlank(technologyPackageParam.getTechnologyPackageMaterialNo())).throwMessage("工艺包物料编码不能为空");
|
||||
VUtils.isTure(CollUtil.isEmpty(technologyPackageParam.getRowIds()) ).throwMessage("请选择要插入工艺包的物料");
|
||||
if(technologyPackageParam.getRowIds().size()==1 && Objects.isNull(technologyPackageParam.getLevelBelong()) ){
|
||||
throw new NflgBusinessException(STATE.BusinessError,"单条物料时,请选择上下级");
|
||||
VUtils.isTure(CollUtil.isEmpty(technologyPackageParam.getRowIds())).throwMessage("请选择要插入工艺包的物料");
|
||||
if (technologyPackageParam.getRowIds().size() == 1 && Objects.isNull(technologyPackageParam.getLevelBelong())) {
|
||||
throw new NflgBusinessException(STATE.BusinessError, "单条物料时,请选择上下级");
|
||||
}
|
||||
TechnologyPackageParamBuilder builder = new TechnologyPackageParamBuilder(technologyPackageParam);
|
||||
if(CollUtil.isNotEmpty(builder.getPackageParent())){
|
||||
if (CollUtil.isNotEmpty(builder.getPackageParent())) {
|
||||
this.saveOrUpdateBatch(builder.getPackageParent());
|
||||
}
|
||||
if(CollUtil.isNotEmpty(builder.getPackageChildren())){
|
||||
if (CollUtil.isNotEmpty(builder.getPackageChildren())) {
|
||||
pbomChildService.saveOrUpdateBatch(builder.getPackageChildren());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void checkCopyBomParam(Long sourceBomRowId , String targetFacCode){
|
||||
BomNewPbomParentEntity parent = this.getById(sourceBomRowId);
|
||||
VUtils.isTure(Objects.isNull(parent)).throwMessage("参数错误,复制源BOM不存在");
|
||||
VUtils.isTure(!PBomStatusEnum.PUBLISH.equalsValue(parent.getStatus())).throwMessage("只有已发布版本,才能复制");
|
||||
VUtils.isTure(parent.getFacCode().equals(targetFacCode)).throwMessage("源工厂和目标工厂一致,无需复制");
|
||||
VUtils.isTure(parent.getMaterialNo().startsWith("31")).throwMessage("31物料不能进行复制");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 复制前检查
|
||||
* @param sourceBomRowId
|
||||
* @param targetFacCode
|
||||
* @return
|
||||
*/
|
||||
public List<BomCopyCheckResultVO> copyBomCheck(Long sourceBomRowId, String targetFacCode) throws ExecutionException, InterruptedException {
|
||||
checkCopyBomParam(sourceBomRowId,targetFacCode);
|
||||
BomCopy bomCopy=new BomCopy(sourceBomRowId,targetFacCode,getAllBom(sourceBomRowId));
|
||||
bomCopy.check();
|
||||
return Convert.toList(BomCopyCheckResultVO.class,bomCopy.getCheckList() ) ;
|
||||
|
||||
}
|
||||
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void copyFrom(CopyPBomParam param) throws ExecutionException, InterruptedException {
|
||||
checkCopyBomParam(param.getSourceBomRowId(),param.getTargetFacCode());
|
||||
BomCopy bomCopy=new BomCopy(param.getSourceBomRowId(),param.getTargetFacCode(),getAllBom(param.getSourceBomRowId()));
|
||||
bomCopy.copy(param.getCheckResult());
|
||||
|
||||
if(CollUtil.isNotEmpty(bomCopy.getParentResult())){
|
||||
this.saveOrUpdateBatch(bomCopy.getParentResult());
|
||||
}
|
||||
if(CollUtil.isNotEmpty(bomCopy.getChildResult())){
|
||||
pbomChildService.saveBatch(bomCopy.getChildResult());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取整颗树的BOM明细
|
||||
* @param rowId
|
||||
* @return
|
||||
* @throws ExecutionException
|
||||
* @throws InterruptedException
|
||||
*/
|
||||
public List<BomNewPbomParentVO> getAllBom(Long rowId) throws ExecutionException, InterruptedException {
|
||||
List<BomNewPbomParentVO> bomDetail = this.getBaseMapper().getParentChild(rowId);
|
||||
PBomDetailTask detailTask = new PBomDetailTask(bomDetail);
|
||||
ForkJoinTask<List<BomNewPbomParentVO>> submit = bomDetailPool.submit(detailTask);
|
||||
|
||||
List<BomNewPbomParentVO> result = submit.join();
|
||||
return result;
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,144 @@
|
|||
package com.nflg.product.bomnew.service.domain.PBom;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.extra.spring.SpringUtil;
|
||||
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
|
||||
import com.nflg.product.bomnew.constant.PBomStatusEnum;
|
||||
import com.nflg.product.bomnew.pojo.entity.BomNewPbomChildEntity;
|
||||
import com.nflg.product.bomnew.pojo.entity.BomNewPbomParentEntity;
|
||||
import com.nflg.product.bomnew.pojo.vo.BomCopyCheckResultVO;
|
||||
import com.nflg.product.bomnew.pojo.vo.BomNewPbomParentVO;
|
||||
import com.nflg.product.bomnew.service.BomNewPbomChildService;
|
||||
import com.nflg.product.bomnew.service.BomNewPbomParentService;
|
||||
import com.nflg.product.bomnew.util.ListCommonUtil;
|
||||
import com.nflg.product.bomnew.util.VersionUtil;
|
||||
import lombok.Getter;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 复制BOM
|
||||
*/
|
||||
public class BomCopy {
|
||||
|
||||
private Long sourceBomRowId;
|
||||
|
||||
private String targetFacCode;
|
||||
|
||||
//需用户确认的BOM
|
||||
@Getter
|
||||
private List<BomNewPbomParentVO> checkList = new ArrayList<>();
|
||||
|
||||
@Getter
|
||||
private List<BomNewPbomParentEntity> parentResult = new ArrayList<>();
|
||||
|
||||
@Getter
|
||||
private List<BomNewPbomChildEntity> childResult = new ArrayList<>();
|
||||
|
||||
private List<BomNewPbomParentVO> allBomDetail;
|
||||
|
||||
private BomNewPbomParentService pBomParentService = SpringUtil.getBean(BomNewPbomParentService.class);
|
||||
|
||||
public BomCopy(Long sourceBomRowId, String targetFacCode, List<BomNewPbomParentVO> allBomDetail) {
|
||||
this.sourceBomRowId = sourceBomRowId;
|
||||
this.targetFacCode = targetFacCode;
|
||||
this.allBomDetail = allBomDetail;
|
||||
}
|
||||
|
||||
/**
|
||||
* 数据检查返回需确认的数据
|
||||
*/
|
||||
public void check() {
|
||||
List<BomNewPbomParentVO> parents = getAllParents();
|
||||
for (BomNewPbomParentVO parent : parents) {
|
||||
BomNewPbomParentEntity oldBom = getOldBom(parent);
|
||||
if (Objects.nonNull(oldBom)) {
|
||||
//版本相同
|
||||
if (VersionUtil.compare(parent.getCurrentVersion(), oldBom.getCurrentVersion()) == 0) {
|
||||
//非已发布,需确认
|
||||
if (!PBomStatusEnum.PUBLISH.equalsValue(oldBom.getStatus())) {
|
||||
checkList.add(parent);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void copy(List<BomCopyCheckResultVO> checkResult) {
|
||||
//获取所有单层BOM
|
||||
List<BomNewPbomParentVO> parents = getAllParents();
|
||||
Map<Long, BomCopyCheckResultVO> checkMap=new HashMap<>();
|
||||
if(CollUtil.isNotEmpty(checkResult)){
|
||||
checkMap= ListCommonUtil.listToMap(checkResult,BomCopyCheckResultVO::getBomRowId);
|
||||
}
|
||||
for (BomNewPbomParentVO parent : parents) {
|
||||
//目标工厂历史版本
|
||||
BomNewPbomParentEntity oldBom = getOldBom(parent);;
|
||||
if (Objects.nonNull(oldBom)) {
|
||||
//版本相同
|
||||
if (VersionUtil.compare(parent.getCurrentVersion(), oldBom.getCurrentVersion()) == 0) {
|
||||
//非已发布 且用户确认为覆盖
|
||||
if (!PBomStatusEnum.PUBLISH.equalsValue(oldBom.getStatus()) && checkMap.containsKey(parent.getBomRowId()) && checkMap.get(parent.getBomRowId()).getCheckResult().equals(1)) {
|
||||
SpringUtil.getBean(BomNewPbomChildService.class).getBaseMapper().delByParentRowId(oldBom.getRowId());
|
||||
buildChildren(oldBom.getRowId(),parent.getBomRowId());
|
||||
}
|
||||
}
|
||||
//版本大于已有版本,升级一个新版
|
||||
else if (VersionUtil.compare(parent.getCurrentVersion(), oldBom.getCurrentVersion()) > 0) {
|
||||
buildBom(parent, oldBom.getCurrentVersion());
|
||||
//旧版是否最新改为0
|
||||
oldBom.setLastVersionIs(0);
|
||||
this.parentResult.add(oldBom);
|
||||
}
|
||||
} else {
|
||||
buildBom(parent, "");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private BomNewPbomParentEntity getOldBom(BomNewPbomParentVO parent) {
|
||||
//目标工厂历史版本
|
||||
return pBomParentService.lambdaQuery().eq(BomNewPbomParentEntity::getMaterialNo, parent.getMaterialNo())
|
||||
.eq(BomNewPbomParentEntity::getLastVersionIs, 1)
|
||||
.eq(BomNewPbomParentEntity::getFacCode, targetFacCode).one();
|
||||
}
|
||||
|
||||
private List<BomNewPbomParentVO> getAllParents() {
|
||||
return allBomDetail.stream().filter(u -> u.getBomRowId() > 0).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
private void buildBom(BomNewPbomParentVO parent, String preVersion) {
|
||||
Long oldBomRowId = parent.getBomRowId();
|
||||
BomNewPbomParentEntity newBom = new BomNewPbomParentEntity();
|
||||
BeanUtil.copyProperties(parent, newBom);
|
||||
newBom.setRowId(IdWorker.getId());
|
||||
newBom.setCurrentVersion(VersionUtil.getNextVersion(preVersion));
|
||||
newBom.setFacCode(targetFacCode);
|
||||
parentResult.add(newBom);
|
||||
//子级
|
||||
buildChildren(newBom.getRowId(),oldBomRowId);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 构建子级
|
||||
* @param newParentRowId
|
||||
* @param sourceParentRowId
|
||||
*/
|
||||
|
||||
private void buildChildren(Long newParentRowId, Long sourceParentRowId ){
|
||||
List<BomNewPbomChildEntity> children = SpringUtil.getBean(BomNewPbomChildService.class).lambdaQuery().eq(BomNewPbomChildEntity::getParentRowId, sourceParentRowId).list();
|
||||
for (BomNewPbomChildEntity child : children) {
|
||||
child.setRowId(IdWorker.getId());
|
||||
child.setFacCode(targetFacCode);
|
||||
child.setParentRowId(newParentRowId);
|
||||
childResult.add(child);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,103 @@
|
|||
package com.nflg.product.bomnew.service.domain.PBom;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.convert.Convert;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.extra.spring.SpringUtil;
|
||||
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.vo.BomNewEbomParentVO;
|
||||
import com.nflg.product.bomnew.pojo.vo.BomNewPbomParentVO;
|
||||
import com.nflg.product.bomnew.service.BomNewEbomParentService;
|
||||
import com.nflg.product.bomnew.service.BomNewPbomChildService;
|
||||
import com.nflg.product.bomnew.service.BomNewPbomParentService;
|
||||
import com.nflg.product.bomnew.util.ListCommonUtil;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.RecursiveTask;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* @author 大米
|
||||
* @descreption
|
||||
* @date 2023/7/8 9:18
|
||||
*/
|
||||
public class PBomDetailTask extends RecursiveTask<List<BomNewPbomParentVO>> {
|
||||
|
||||
private List<BomNewPbomParentVO> bomDetail;
|
||||
|
||||
|
||||
List<BomNewPbomParentVO> result = new ArrayList<>();
|
||||
|
||||
|
||||
|
||||
|
||||
public PBomDetailTask(List<BomNewPbomParentVO> inBomDetail) {
|
||||
bomDetail = inBomDetail;
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理BOM明细中未选择Bom版本的明细;使用最新版
|
||||
*/
|
||||
public void handlerChildBomVersionDetail() {
|
||||
List<String> materialNos = bomDetail.stream().filter(u -> StrUtil.isNotBlank(u.getMaterialNo()) ).map(BomNewPbomParentVO::getMaterialNo).collect(Collectors.toList());
|
||||
|
||||
if (CollUtil.isNotEmpty(materialNos)) {
|
||||
|
||||
List<BomNewPbomParentEntity> childBomlist = SpringUtil.getBean(BomNewPbomParentService.class).lambdaQuery().in(BomNewPbomParentEntity::getMaterialNo, materialNos).eq(BomNewPbomParentEntity::getLastVersionIs, 1).list();
|
||||
Map<String, BomNewPbomParentEntity> parentMap = ListCommonUtil.listToMap(childBomlist, BomNewPbomParentEntity::getMaterialNo);
|
||||
for (BomNewPbomParentVO detailVO : bomDetail) {
|
||||
if (parentMap.containsKey(detailVO.getMaterialNo())) {
|
||||
BomNewPbomParentEntity ebomParentEntity = parentMap.get(detailVO.getMaterialNo());
|
||||
detailVO.setBomRowId(ebomParentEntity.getRowId());
|
||||
detailVO.setSourceRowId(ebomParentEntity.getSourceRowId());
|
||||
detailVO.setCurrentVersion(ebomParentEntity.getCurrentVersion());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 递归调用零部件BOM
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
protected List<BomNewPbomParentVO> compute() {
|
||||
|
||||
handlerChildBomVersionDetail();
|
||||
// 最新 BOM 版本
|
||||
|
||||
result.addAll(bomDetail);
|
||||
|
||||
if (CollUtil.isNotEmpty(bomDetail)) {
|
||||
List<Long> childBowIds = bomDetail.stream().filter(u-> u.getBomRowId() > 0).map(u->u.getBomRowId()).collect(Collectors.toList());
|
||||
if(CollUtil.isNotEmpty(childBowIds)) {
|
||||
List<BomNewPbomChildEntity> children = SpringUtil.getBean(BomNewPbomChildService.class).lambdaQuery().in(BomNewPbomChildEntity::getParentRowId, childBowIds).list();
|
||||
List<BomNewPbomParentVO> bom = Convert.toList(BomNewPbomParentVO.class,children);
|
||||
|
||||
PBomDetailTask task = new PBomDetailTask(bom);
|
||||
task.fork();
|
||||
bomDetail.addAll(task.join());
|
||||
return bomDetail;
|
||||
}
|
||||
|
||||
}
|
||||
return result;
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -3,10 +3,11 @@ package com.nflg.product.bomnew.util;
|
|||
|
||||
import cn.hutool.core.convert.Convert;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import org.springframework.data.util.Version;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Arrays;
|
||||
import java.util.Objects;
|
||||
|
||||
import static org.apache.naming.SelectorContext.prefix;
|
||||
|
||||
/**
|
||||
* 版本 工具类
|
||||
|
|
@ -74,4 +75,18 @@ public class VersionUtil {
|
|||
return nextVersion;
|
||||
}
|
||||
|
||||
/**
|
||||
* 版本比较
|
||||
* @param version1
|
||||
* @param version2
|
||||
* @return version1>version2 返回>0,version1<version2返回 <0,version1=version2返回0
|
||||
*/
|
||||
public static int compare(String version1, String version2) {
|
||||
version1=StrUtil.replace(version1,versionPrefix,"");
|
||||
version1=StrUtil.replace(version2,versionPrefix,"");
|
||||
Version v1 = Version.parse(version1);
|
||||
Version v2 = Version.parse(version2);
|
||||
return v1.compareTo(v2);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -51,4 +51,9 @@
|
|||
#{item}
|
||||
</foreach>
|
||||
</update>
|
||||
|
||||
<delete id="delByParentRowId">
|
||||
delete from t_bom_new_pbom_child where parent_row_id =#{parentRowId}
|
||||
|
||||
</delete>
|
||||
</mapper>
|
||||
|
|
|
|||
Loading…
Reference in New Issue