Merge branch 'DM/10月需求' into test

# Conflicts:
#	nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/constant/BomConstant.java
#	nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/pojo/entity/BomNewPbomParentEntity.java
#	nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/pojo/vo/BomNewPbomParentVO.java
#	nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/pojo/vo/UpdateLogVO.java
#	nflg_project_dev/nflg-bom-new/src/main/java/com/nflg/product/bomnew/service/ForwardReportService.java
#	nflg_project_dev/nflg-bom-new/src/main/resources/mapper/master/BomNewPbomParentMapper.xml
This commit is contained in:
大米 2024-09-27 08:31:20 +08:00
commit 5f11a53c81
13 changed files with 351 additions and 4 deletions

View File

@ -150,6 +150,12 @@ public class BomReportApi extends BaseApi {
return ResultVO.success(forwardReportService.getUpdateLog(bomRowId));
}
@PostMapping("getUpdateLog")
@ApiOperation("bom-变更记录(和上一版本对比)")
public ResultVO<List<UpdateLogVO>> getUpdateLog(@ApiParam("bom版本RowId") @RequestParam("bomRowId") Long bomRowId , @ApiParam("BOM 类型 1-EBom 2-PBom") @RequestParam("bomType") Integer bomType) {
return ResultVO.success(forwardReportService.getUpdateLog(bomRowId,bomType));
}
@PostMapping("compareReport")
@ApiOperation("bom-比对")

View File

@ -25,6 +25,7 @@ import com.nflg.product.bomnew.util.EecExcelUtil;
import com.nflg.product.bomnew.util.VUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import nflg.product.common.vo.ResultVO;
import org.apache.commons.compress.utils.Lists;
import org.springframework.transaction.annotation.Transactional;
@ -439,4 +440,13 @@ public class PBomApi extends BaseApi {
}
@PostMapping("checkException")
@ApiOperation("PBOM-数据异常检查")
public ResultVO<Boolean> checkException(@RequestBody PBomCheckExceptionDTO checkExceptionDTO) {
bomNewPbomParentService.checkException(checkExceptionDTO.getBomRowId(),checkExceptionDTO.getPBomType());
return ResultVO.success(true);
}
}

View File

@ -19,4 +19,8 @@ public class BomConstant {
//工艺包物料类别编码
public static final String ART_PACKAGE_MATERIAL_CATEGORY_CODE="201201";
public static final String ADD="新增";
public static final String UP="修改";
public static final String DEL="删除";
}

View File

@ -0,0 +1,16 @@
package com.nflg.product.bomnew.pojo.dto;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
@Data
public class PBomCheckExceptionDTO {
@ApiModelProperty("BOM版本ID")
private Long bomRowId;
@ApiModelProperty("pbom类型 0- pBom工作表 1-pBOM正式表")
private Integer pBomType;
}

View File

@ -256,6 +256,10 @@ public class BomNewPbomChildEntity implements Serializable {
@ApiModelProperty(value = "原始项目类别-来自ebom(不会变)")
private String originalProjectType;
@TableField(value = "exception_status")
@ApiModelProperty(value = "异常状态1=正常、2=冻结/完全弃用异常、3=递归异常、4=数据不完整异常、5=超级物料异常、6=重复异常")
private Integer exceptionStatus;
private static final long serialVersionUID = -76633783850936076L;
}

View File

@ -378,6 +378,10 @@ public class BomNewPbomParentEntity implements Serializable {
@ApiModelProperty(value = "ebom-发布后的版本")
private String ebomVersion;
@TableField(value = "exception_status")
@ApiModelProperty(value = "异常状态1=正常、2=冻结/完全弃用异常、3=递归异常、4=数据不完整异常、5=超级物料异常、6=重复异常")
private Integer exceptionStatus;
private static final long serialVersionUID = -31999878274445137L;
}

View File

@ -348,6 +348,10 @@ public class BomNewPbomParentVO extends BaseMaterialVO implements Serializable {
@ApiModelProperty(value = "ebom-发布后的版本")
private String ebomVersion;
@ApiModelProperty(value = "异常状态1=正常、2=冻结/完全弃用异常、3=递归异常、4=数据不完整异常、5=超级物料异常、6=重复异常 7=物料主数据不存在 8=项目类别为空 9=项目赋值异常(父级物料的项目类型为Q时子级中不能存在项目类别为Q的物料) 10=项目赋值异常(当父级物料的项目类型为F时子级中不能存在项目类型为F的物料) 11=未填写变更原因和技术通知单 12=数量需要用户确认 13=项目类型需要用户确认")
private Integer exceptionStatus=1;
private static final long serialVersionUID = 1L;
@Override

View File

@ -14,6 +14,10 @@ public class UpdateLogVO {
@ApiModelProperty(value = "序号")
private String orderNumber;
@ApiModelProperty(value = "版本号")
private String currentVersion;
@ApiModelProperty("项目类别")
private String projectType;
@ -38,5 +42,8 @@ public class UpdateLogVO {
@ApiModelProperty("操作类型")
private String opType;
@ApiModelProperty("旧版或新版 0-旧版 1-新版")
private Integer oldOrNewVersion=0;
}

View File

@ -29,6 +29,7 @@ import com.nflg.product.bomnew.pojo.query.BomNewPbomParentQuery;
import com.nflg.product.bomnew.pojo.query.CopyPBomV2Query;
import com.nflg.product.bomnew.pojo.query.PbomImportToSAPQuery;
import com.nflg.product.bomnew.pojo.vo.*;
import com.nflg.product.bomnew.service.domain.EBom.CheckPBomException;
import com.nflg.product.bomnew.service.domain.PBom.*;
import com.nflg.product.bomnew.service.domain.Sap;
import com.nflg.product.bomnew.util.*;
@ -771,6 +772,24 @@ public class BomNewPbomParentService extends ServiceImpl<BomNewPbomParentMapper,
}
/**
* 获取正式版-bom
* @param rowId
* @param countLevelNum
* @return
*/
public List<BomNewPbomParentVO> getFormalAllBom(Long rowId, Integer countLevelNum) {
List<BomNewPbomParentVO> bomDetail = this.getBaseMapper().getParentChild(rowId);
AtomicInteger levelNum = new AtomicInteger(1);
BomNewPbomParentEntity parent = this.getBaseMapper().selectById(rowId);
PBomFormalTreeTask detailTask = new PBomFormalTreeTask(bomDetail, countLevelNum, levelNum,parent.getFacCode());
ForkJoinTask<List<BomNewPbomParentVO>> submit = bomDetailPool.submit(detailTask);
List<BomNewPbomParentVO> result = submit.join();
return result.stream().distinct().collect(Collectors.toList());
}
public List<BomNewPbomParentVO> getAllBom(Long rowId, Integer countLevelNum, Boolean generateDrawingNumberFalg) throws ExecutionException, InterruptedException {
List<BomNewPbomParentVO> bomDetail = this.getBaseMapper().getParentChild(rowId);
AtomicInteger levelNum = new AtomicInteger(1);
@ -2041,5 +2060,58 @@ public class BomNewPbomParentService extends ServiceImpl<BomNewPbomParentMapper,
}
/**
* PBOM-数据异常检查
* @param rowId
*/
public void checkException(Long rowId,Integer bomType){
BomNewPbomParentEntity parent = this.getById(rowId);
VUtils.isTure(parent==null).throwMessage("PBom不存在");
List<BomNewPbomParentVO> allBom =new ArrayList<>();
if(bomType==0){
allBom= this.getAllBom(rowId, 0);
}else {
this.getFormalAllBom(rowId,0);
}
BomNewPbomParentVO convert = Convert.convert(BomNewPbomParentVO.class, parent);
convert.setBomRowId(convert.getRowId());
convert.setParentRowId(0L);
allBom.add(convert);
CheckPBomException checkException=new CheckPBomException(allBom);
checkException.initException();
savePBomException(allBom);
}
public void savePBomException(List<BomNewPbomParentVO> allBom){
//父级
List<BomNewPbomParentVO> parents = allBom.stream().filter(u -> u.getBomRowId() != null && u.getBomRowId() > 0 && u.getExceptionStatus()>1).collect(Collectors.toList());
if (CollUtil.isNotEmpty(parents)) {
List<BomNewPbomParentEntity> pentList = new ArrayList<>();
parents.forEach(k -> {
BomNewPbomParentEntity pEnt = new BomNewPbomParentEntity();
pEnt.setRowId(k.getBomRowId());
pEnt.setExceptionStatus(k.getExceptionStatus());
pentList.add(pEnt);
});
if (CollUtil.isNotEmpty(pentList)) {
this.updateBatchById(pentList);
}
}
//子级
List<BomNewPbomParentVO> child = allBom.stream().filter(u -> u.getRowId() != null && u.getRowId() > 0 && u.getExceptionStatus()>1).collect(Collectors.toList());
if (CollUtil.isNotEmpty(parents)) {
List<BomNewPbomChildEntity> childList = new ArrayList<>();
child.forEach(k -> {
BomNewPbomChildEntity pEnt = new BomNewPbomChildEntity();
pEnt.setRowId(k.getRowId());
pEnt.setExceptionStatus(k.getExceptionStatus());
childList.add(pEnt);
});
if (CollUtil.isNotEmpty(childList)) {
pbomChildService.updateBatchById(childList);
}
}
}
}

View File

@ -1,10 +1,13 @@
package com.nflg.product.bomnew.service;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.convert.Convert;
import cn.hutool.core.lang.TypeReference;
import cn.hutool.core.util.StrUtil;
import cn.hutool.extra.spring.SpringUtil;
import com.google.common.collect.Sets;
import com.nflg.product.base.core.exception.NflgBusinessException;
import com.nflg.product.bomnew.constant.*;
import com.nflg.product.bomnew.mapper.master.BomNewPbomParentMapper;
import com.nflg.product.bomnew.pojo.entity.*;
@ -19,9 +22,12 @@ 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.ibatis.builder.ParameterExpression;
import org.springframework.stereotype.Service;
import org.ttzero.excel.entity.ListSheet;
import javax.annotation.Resource;
import java.io.IOException;
import java.io.OutputStream;
import java.util.*;
@ -32,6 +38,19 @@ import java.util.stream.Collectors;
@Service
public class ForwardReportService {
@Resource
private BomNewEbomParentFormalService ebomParentFormalService;
@Resource
private BomNewEbomChildFormalService ebomChildFormalService;
@Resource
private BomNewPbomParentFormalService pbomParentFormalService;
@Resource
private BomNewPbomChildFormalService pbomChildFormalService;
public ReportBomVersionVO factoryVersion(ReverseReportQuery query) {
//原始BOM
@ -401,9 +420,99 @@ public class ForwardReportService {
return mBomForwardReport.genReport();
}
/**
* 获取BOM变更记录
* @param bomRowId bom版本rowId
* @param bomType BOM 类型 0-原始BOM 1-EBom 2-PBom
* @return
*/
public List<UpdateLogVO> getUpdateLog(Long bomRowId ,Integer bomType){
//结果
List<UpdateLogVO> result=new ArrayList<>();
//eBom
if(bomType==1){
BomNewEbomParentFormalEntity ebomVersion = ebomParentFormalService.getById(bomRowId);
if(Objects.nonNull(ebomVersion)){
//上一个BOM版本
BomNewEbomParentFormalEntity preBomVersion = ebomParentFormalService.lambdaQuery().eq(BomNewEbomParentFormalEntity::getMaterialNo, ebomVersion.getMaterialNo())
.lt(BomNewEbomParentFormalEntity::getCurrentVersion, ebomVersion.getCurrentVersion()).orderByDesc(BomNewEbomParentFormalEntity::getCurrentVersion).last(" limit 1").one();
if(Objects.nonNull(preBomVersion)) {
List<BomNewEbomChildFormalEntity> newBomDetail = ebomChildFormalService.lambdaQuery().eq(BomNewEbomChildFormalEntity::getParentRowId, bomRowId).list();
public List<UpdateLogVO> getUpdateLog(Long bomRowId){
return null;
List<BomNewEbomChildFormalEntity> oldBomDetail = ebomChildFormalService.lambdaQuery().eq(BomNewEbomChildFormalEntity::getParentRowId, preBomVersion.getRowId()).list();
List<UpdateLogVO> newBomChild = Convert.toList(UpdateLogVO.class, newBomDetail);
List<UpdateLogVO> oldBomChild = Convert.toList(UpdateLogVO.class, oldBomDetail);
newBomChild.forEach(item->{item.setCurrentVersion(ebomVersion.getCurrentVersion()); item.setOldOrNewVersion(1);});
oldBomChild.forEach(item->item.setCurrentVersion(preBomVersion.getCurrentVersion()));
result=compare(oldBomChild,newBomChild);
}
}
}//pBom
else if(bomType==2){
BomNewPbomParentFormalEntity pbomVersion = pbomParentFormalService.getById(bomRowId);
if(Objects.nonNull(pbomVersion)){
//上一个BOM版本
BomNewPbomParentFormalEntity preBomVersion = pbomParentFormalService.lambdaQuery().eq(BomNewPbomParentFormalEntity::getMaterialNo, pbomVersion.getMaterialNo())
.lt(BomNewPbomParentFormalEntity::getCurrentVersion, pbomVersion.getCurrentVersion()).orderByDesc(BomNewPbomParentFormalEntity::getCurrentVersion).last(" limit 1").one();
if(Objects.nonNull(preBomVersion)) {
List<BomNewPbomChildFormalEntity> newBomDetail = pbomChildFormalService.lambdaQuery().eq(BomNewPbomChildFormalEntity::getParentRowId, bomRowId).list();
List<BomNewPbomChildFormalEntity> oldBomDetail = pbomChildFormalService.lambdaQuery().eq(BomNewPbomChildFormalEntity::getParentRowId, preBomVersion.getRowId()).list();
List<UpdateLogVO> newBomChild = Convert.toList(UpdateLogVO.class, newBomDetail);
List<UpdateLogVO> oldBomChild = Convert.toList(UpdateLogVO.class, oldBomDetail);
newBomChild.forEach(item->{item.setCurrentVersion(pbomVersion.getCurrentVersion()); item.setOldOrNewVersion(1);});
oldBomChild.forEach(item->item.setCurrentVersion(preBomVersion.getCurrentVersion()));
result=compare(oldBomChild,newBomChild);
}
}
}
else {
throw new NflgBusinessException(STATE.ParamErr ,"bomType参数错误暂不支持该类型BOM");
}
return result;
}
/**
* bom-对比变更记录
* @param oldBom
* @param newBom
* @return
*/
private List<UpdateLogVO> compare(List<UpdateLogVO> oldBom, List<UpdateLogVO> newBom){
List<UpdateLogVO> result =new ArrayList<>();
Set<String> oldSet = oldBom.stream().map(u -> u.getOrderNumber()).collect(Collectors.toSet());
Set<String> newSet =newBom.stream().map(u->u.getOrderNumber()).collect(Collectors.toSet());
//删除的
Set<String> del = Sets.difference(oldSet, newSet);
for (String item: del) {
UpdateLogVO oldEnd=oldBom.stream().filter(u->u.getOrderNumber().equals(item)).findFirst().get();
result.add(oldEnd);
UpdateLogVO newEnt =new UpdateLogVO();
BeanUtil.copyProperties(oldEnd,newEnt);
newEnt.setOpType(BomConstant.DEL);
}
//新增
Set<String> add= Sets.difference(newSet,oldSet);
for (String item: add) {
UpdateLogVO updateLogVO=newBom.stream().filter(u->u.getOrderNumber().equals(item)).findFirst().get();
updateLogVO.setOpType(BomConstant.ADD);
result.add(updateLogVO);
}
//都有比较编辑字段
Set<String> intersection = Sets.intersection(oldSet,newSet);
for (String item: intersection) {
UpdateLogVO oldEnt = oldBom.stream().filter(u -> u.getOrderNumber().equals(item)).findFirst().get();
UpdateLogVO newEnt = newBom.stream().filter(u -> u.getOrderNumber().equals(item)).findFirst().get();
if(!oldEnt.getMaterialNo().equals(newEnt.getMaterialNo()) || ! oldEnt.getNum().equals(newEnt.getNum()) || oldEnt.getProjectType().equals(newEnt.getProjectType())){
result.add(oldEnt);
newEnt.setOpType(BomConstant.UP);
result.add(newEnt);
}
}
return result;
}

View File

@ -0,0 +1,109 @@
package com.nflg.product.bomnew.service.domain.EBom;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.convert.Convert;
import cn.hutool.core.util.StrUtil;
import cn.hutool.extra.spring.SpringUtil;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Sets;
import com.nflg.product.base.core.exception.NflgBusinessException;
import com.nflg.product.bomnew.constant.*;
import com.nflg.product.bomnew.pojo.entity.BomNewEbomChildEntity;
import com.nflg.product.bomnew.pojo.entity.BomNewEbomParentEntity;
import com.nflg.product.bomnew.pojo.vo.BaseMaterialVO;
import com.nflg.product.bomnew.pojo.vo.BomNewEbomParentVO;
import com.nflg.product.bomnew.pojo.vo.BomNewPbomParentVO;
import com.nflg.product.bomnew.service.BomNewEbomChildService;
import com.nflg.product.bomnew.service.BomNewEbomParentService;
import com.nflg.product.bomnew.service.MaterialMainService;
import com.nflg.product.bomnew.util.*;
import lombok.Getter;
import lombok.Setter;
import nflg.product.common.constant.STATE;
import java.math.BigDecimal;
import java.util.*;
import java.util.stream.Collectors;
/**
* 检查BOM 异常
*/
public class CheckPBomException {
@Getter
List<BomNewPbomParentVO> allBomDetail;
/**
* @param allBom 整颗BOM树包含跟节点
*/
public CheckPBomException(List<BomNewPbomParentVO> allBom) {
allBomDetail = allBom;
}
/**
* 初始化异常
*/
public void initException() {
//初始化物料信息
SpringUtil.getBean(MaterialMainService.class).intiMaterialInfo(allBomDetail, EBomConstant.EBOM_IGNORED_FIELDS_INIT_MATERIAL_DEFAULT);
checkException();
}
public void checkException() {
for (BomNewPbomParentVO vo : allBomDetail) {
vo.setExceptionStatus(EBomExceptionStatusEnum.OK.getValue());
if (StrUtil.isNotBlank(vo.getMaterialNo())
&& (MaterialGetEnum.MaterialStateEnum.STATE_NO_4.equalsValue(vo.getMaterialState())
|| MaterialGetEnum.MaterialStateEnum.STATE_NO_5.equalsValue(vo.getMaterialState()))) {
vo.setExceptionStatus(EBomExceptionStatusEnum.EXCEPT_NO_2.getValue());
}
}
}
/**
* 黄色警号异常
*
* @param
*/
public void initExceptionYellowWarn() {
Set<BomNewPbomParentVO> exceptionItems = allBomDetail.stream().filter(u -> EBomExceptionStatusEnum.EXCEPT_NO_2.equals(u.getExceptionStatus())).collect(Collectors.toSet());
for (BomNewPbomParentVO vo : exceptionItems) {
initExceptionParent(vo);
}
}
/**
* 初始化上级警告
* @param vo
* @return
*/
protected void initExceptionParent(BomNewPbomParentVO vo) {
List<BomNewPbomParentVO> parentEnts = initExceptionParentDo(ImmutableList.of(vo));
while (CollUtil.isNotEmpty(parentEnts) ) {
parentEnts = initExceptionParentDo(parentEnts);
}
}
private List<BomNewPbomParentVO> initExceptionParentDo(List<BomNewPbomParentVO> vos) {
Set<Long> parentRowIds = vos.stream().filter(u->u.getParentRowId()>0).map(u -> u.getParentRowId()).collect(Collectors.toSet());
List<BomNewPbomParentVO> parents = allBomDetail.stream().filter(u ->parentRowIds.contains(u.getBomRowId())).collect(Collectors.toList());
parents.forEach(u->u.setExceptionStatus(EBomExceptionStatusEnum.EXCEPT_NO_14.getValue()));
return parents;
}
}

View File

@ -38,11 +38,12 @@
<result column="original_material_no" property="originalMaterialNo" jdbcType="VARCHAR"/>
<result column="original_num" property="orderNumber" jdbcType="DECIMAL" />
<result column="original_project_type" property="originalProjectType" jdbcType="VARCHAR"/>
<result column="exception_status" property="exceptionStatus" jdbcType="INTEGER"/>
</resultMap>
<sql id="Base_Column_List">
<!--@mbg.generated-->
row_id, parent_row_id, identity_no, fac_code, order_number, drawing_no, material_no, material_name, material_desc, material_texture, material_unit, material_category_code, unit_weight, num, total_weight, project_type, production_factory_code,production_factory_code_input_type, set_production_factory_time, super_material_status, virtual_part_is, created_by, created_time, modify_time, source_row_id, remark, source_parent_material_no ,virtual_part_type ,virtual_part_root_material_no ,bom_version_row_id ,original_material_no , original_num, original_project_type </sql>
row_id, parent_row_id, identity_no, fac_code, order_number, drawing_no, material_no, material_name, material_desc, material_texture, material_unit, material_category_code, unit_weight, num, total_weight, project_type, production_factory_code,production_factory_code_input_type, set_production_factory_time, super_material_status, virtual_part_is, created_by, created_time, modify_time, source_row_id, remark, source_parent_material_no ,virtual_part_type ,virtual_part_root_material_no ,bom_version_row_id ,original_material_no , original_num, original_project_type ,exception_status</sql>
<delete id="delByRowId">

View File

@ -49,6 +49,7 @@
<result column="order_no" property="orderNo" jdbcType="VARCHAR"/>
<result column="modify_time" property="modifyTime" jdbcType="TIMESTAMP"/>
<result column="ebom_version" property="ebomVersion" jdbcType="VARCHAR"/>
<result column="exception_status" property="exceptionStatus" jdbcType="INTEGER"/>
</resultMap>
<sql id="Base_Column_List">
@ -58,7 +59,7 @@
should_bom_exist, super_material_status, bom_exist, last_version_is, edit_status, status, user_root_is,
virtual_package_is, source_row_id, devise_user_code, devise_name,technology_user_code,technology_user_name, created_by, created_time, created_job,
release_time, release_user_name,last_convert_mbom_user_name,last_convert_mbom_time, expire_end_time, remark, dept_name, level_num, change_desc, notice_nums,
order_no, modify_time,ebom_version
order_no, modify_time,ebom_version,exception_status
</sql>
<sql id="whr">