Merge branch 'feature/DM/nflg-bom' of http://112.74.186.154:3000/nflj/nflg_project into feature/DM/nflg-bom

This commit is contained in:
jing's 2024-01-02 16:25:10 +08:00
commit 277adf8582
4 changed files with 200 additions and 8 deletions

View File

@ -108,7 +108,7 @@ public class PBomApi extends BaseApi {
@PostMapping("insertTechnologyPackage")
@ApiOperation("编辑-插入工艺包")
public ResultVO<Boolean> insertTechnologyPackage(@Valid @RequestBody TechnologyPackageParam packageParam){
bomNewPbomParentService.insertTechnologyPackage(packageParam);
return ResultVO.success(true);
}

View File

@ -5,9 +5,12 @@ 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;
@ -23,10 +26,9 @@ 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.util.EecExcelUtil;
import com.nflg.product.bomnew.util.ListCommonUtil;
import com.nflg.product.bomnew.util.MaterialshouldBomExistUtil;
import com.nflg.product.bomnew.util.VUtils;
import com.nflg.product.bomnew.service.domain.PBom.TechnologyPackageParamBuilder;
import com.nflg.product.bomnew.util.*;
import nflg.product.common.constant.STATE;
import org.apache.tomcat.util.http.ResponseUtil;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@ -36,6 +38,8 @@ 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;
@ -209,7 +213,7 @@ public class BomNewPbomParentService extends ServiceImpl<BomNewPbomParentMapper,
* @param response
*/
public void editExport(Long bomRowId, HttpServletResponse response) throws IOException {
EecExcelUtil.setResponseExcelHeader(response,"缺价物料列表");
EecExcelUtil.setResponseExcelHeader(response,"bom明细列表");
List<BomNewPbomParentVO> child = this.getChild(bomRowId);
List<BomNewPbomEditExcelVO> result = Convert.toList(BomNewPbomEditExcelVO.class, child);
@ -253,11 +257,32 @@ public class BomNewPbomParentService extends ServiceImpl<BomNewPbomParentMapper,
materialName=StrUtil.join("",result.getMaterialName(),technologyPackageTypeEntity.getRemark());
materialDesc=StrUtil.join(" ",materialName,drawingNo);
String materialNo = materialService.addMaterial(drawingNo, materialName, materialDesc, "");
String materialNo = materialService.addMaterial(drawingNo, materialName, materialDesc, "201201");
return materialMainService.getMaterialBaseInfo(ImmutableList.of(materialNo)).get(0);
}
@Transactional(rollbackFor = Exception.class)
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,"单条物料时,请选择上下级");
}
TechnologyPackageParamBuilder builder = new TechnologyPackageParamBuilder(technologyPackageParam);
if(CollUtil.isNotEmpty(builder.getPackageParent())){
this.saveOrUpdateBatch(builder.getPackageParent());
}
if(CollUtil.isNotEmpty(builder.getPackageChildren())){
pbomChildService.saveOrUpdateBatch(builder.getPackageChildren());
}
}
}

View File

@ -0,0 +1,167 @@
package com.nflg.product.bomnew.service.domain.PBom;
import cn.hutool.core.util.StrUtil;
import cn.hutool.extra.spring.SpringUtil;
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
import com.google.common.collect.ImmutableList;
import com.nflg.product.base.core.conmon.util.SessionUtil;
import com.nflg.product.bomnew.constant.PBomStatusEnum;
import com.nflg.product.bomnew.pojo.dto.TechnologyPackageParam;
import com.nflg.product.bomnew.pojo.entity.BomNewPbomChildEntity;
import com.nflg.product.bomnew.pojo.entity.BomNewPbomParentEntity;
import com.nflg.product.bomnew.pojo.vo.BaseMaterialVO;
import com.nflg.product.bomnew.service.BomNewPbomChildService;
import com.nflg.product.bomnew.service.BomNewPbomParentService;
import com.nflg.product.bomnew.service.MaterialMainService;
import com.nflg.product.bomnew.util.VUtils;
import com.nflg.product.bomnew.util.VersionUtil;
import lombok.Getter;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
/**
* 工艺包构建
*
*/
public class TechnologyPackageParamBuilder {
TechnologyPackageParam packageParam;
BaseMaterialVO packageMaterial=null;
BomNewPbomParentEntity parent;
@Getter
List<BomNewPbomParentEntity> packageParent=null;
@Getter
List<BomNewPbomChildEntity> packageChildren=new ArrayList<>();
public TechnologyPackageParamBuilder(TechnologyPackageParam technologyPackageParam) {
this.packageParam =technologyPackageParam;
List<BaseMaterialVO> materialBaseInfo = SpringUtil.getBean(MaterialMainService.class).getMaterialBaseInfo(ImmutableList.of(packageParam.getTechnologyPackageMaterialNo()));
packageMaterial = materialBaseInfo.get(0);
parent = SpringUtil.getBean(BomNewPbomParentService.class).getById(packageParam.getBomRowId());
if(technologyPackageParam.getRowIds().size()>1){
technologyPackageParam.setLevelBelong(0);
}
}
/**
* 构建
*/
public void builder(){
List<BomNewPbomChildEntity> children = SpringUtil.getBean(BomNewPbomChildService.class).getBaseMapper().selectBatchIds(packageParam.getRowIds());
//虚拟包作为上级
if(packageParam.getLevelBelong().equals(0)){
//构建虚拟包-parent
BomNewPbomParentEntity parent1 = buildParentForTechnologyPackage();
//构建虚拟包子级
buildPbomChildForTechnologyPackage(parent);
//将children 作为虚拟包子级
children.forEach(k->{
k.setParentRowId(parent1.getRowId());
this.packageChildren.add(k);
});
}
else { //虚拟包作为下级
BomNewPbomParentEntity childParent = buildParentByChild(children.get(0));
buildPbomChildForTechnologyPackage(childParent);
this.packageParent.add(childParent);
}
}
//通过子级构建父级
private BomNewPbomParentEntity buildParentByChild(BomNewPbomChildEntity child){
BomNewPbomParentEntity oldBom =SpringUtil.getBean(BomNewPbomParentService.class).lambdaQuery().eq(BomNewPbomParentEntity::getMaterialNo, child.getMaterialNo()).eq(BomNewPbomParentEntity::getLastVersionIs, 1).one();
if(Objects.nonNull(oldBom)){
return oldBom;
}
BomNewPbomParentEntity newBom=new BomNewPbomParentEntity();
newBom.setRowId(IdWorker.getId());
newBom.setDrawingNo(child.getDrawingNo());
newBom.setFacCode(parent.getFacCode());
newBom.setMaterialNo(child.getMaterialNo());
newBom.setMaterialName(child.getMaterialName());
newBom.setMaterialDesc(child.getMaterialDesc());
newBom.setMaterialTexture(child.getMaterialTexture());
newBom.setMaterialUnit(child.getMaterialUnit());
newBom.setNum(new BigDecimal(1));
newBom.setProjectType(child.getProjectType());
newBom.setBomExist(1);
newBom.setLastVersionIs(1);
newBom.setCurrentVersion( VersionUtil.getNextVersion(""));
newBom.setDeviseUserCode(SessionUtil.getUserCode());
newBom.setDeviseName(SessionUtil.getRealName());
newBom.setDeptName(SessionUtil.getDepartName());
newBom.setCreatedBy(SessionUtil.getUserCode());
newBom.setCreatedTime(LocalDateTime.now());
return newBom;
}
private BomNewPbomParentEntity buildParentForTechnologyPackage(){
BomNewPbomParentEntity oldBom =SpringUtil.getBean(BomNewPbomParentService.class).lambdaQuery().eq(BomNewPbomParentEntity::getMaterialNo, packageParam.getTechnologyPackageMaterialNo()).eq(BomNewPbomParentEntity::getLastVersionIs, 1).one();
VUtils.isTure(Objects.nonNull(oldBom) && oldBom.getStatus()< PBomStatusEnum.PUBLISH.getValue()).throwMessage("该工艺包存在未发布的BOM版本");
BomNewPbomParentEntity newBom=new BomNewPbomParentEntity();
newBom.setRowId(IdWorker.getId());
newBom.setDrawingNo(packageMaterial.getDrawingNo());
newBom.setFacCode(parent.getFacCode());
newBom.setMaterialNo(packageMaterial.getMaterialNo());
newBom.setMaterialName(packageMaterial.getMaterialName());
newBom.setMaterialDesc(packageMaterial.getMaterialDesc());
newBom.setMaterialTexture(packageMaterial.getMaterialTexture());
newBom.setMaterialUnit(packageMaterial.getMaterialUnit());
newBom.setNum(new BigDecimal(1));
newBom.setProjectType("L");
newBom.setBomExist(packageParam.getLevelBelong().equals(0)?1:0);
newBom.setLastVersionIs(1);
newBom.setCurrentVersion(Objects.isNull(oldBom)? VersionUtil.getNextVersion(""):VersionUtil.getNextVersion(oldBom.getCurrentVersion()));
newBom.setDeviseUserCode(SessionUtil.getUserCode());
newBom.setDeviseName(SessionUtil.getRealName());
newBom.setDeptName(SessionUtil.getDepartName());
newBom.setCreatedBy(SessionUtil.getUserCode());
newBom.setCreatedTime(LocalDateTime.now());
if(Objects.isNull(oldBom)){
oldBom.setLastVersionIs(0);
SpringUtil.getBean(BomNewPbomParentService.class).updateById(oldBom);
}
this.packageParent.add(newBom);
return newBom;
}
private void buildPbomChildForTechnologyPackage(BomNewPbomParentEntity parent){
BomNewPbomChildEntity child = new BomNewPbomChildEntity();
List<BomNewPbomChildEntity> parentChildren =SpringUtil.getBean(BomNewPbomChildService.class).lambdaQuery().eq(BomNewPbomChildEntity::getParentRowId, parent.getRowId()).list();
child.setRowId(IdWorker.getId());
child.setParentRowId(parent.getRowId());
child.setFacCode(parent.getFacCode());
child.setOrderNumber(StrUtil.padPre (String.valueOf(parentChildren.size()+1),3,"0"));
child.setDrawingNo(packageMaterial.getDrawingNo());
child.setMaterialNo(packageMaterial.getMaterialNo());
child.setMaterialName(packageMaterial.getMaterialName());
child.setMaterialDesc(packageMaterial.getMaterialDesc());
child.setMaterialTexture(packageMaterial.getMaterialTexture());
child.setMaterialUnit(packageMaterial.getMaterialUnit());
child.setMaterialCategoryCode(packageMaterial.getMaterialCategoryCode());
child.setNum(new BigDecimal(1));
child.setProjectType("L");
child.setCreatedBy(SessionUtil.getUserCode());
child.setCreatedTime(LocalDateTime.now());
child.setModifyTime(LocalDateTime.now());
this.packageChildren.add(child);
}
}

View File

@ -26,7 +26,7 @@ public class VersionUtil {
return versionPrefix + "00";
}
Integer versionNum = Convert.toInt(StrUtil.replace(preVersion, "A", "")) + 1;
Integer versionNum = Convert.toInt(StrUtil.replace(preVersion, versionPrefix, "")) + 1;
return versionPrefix + StrUtil.padPre(versionNum.toString(), 2, '0');
}