【批量替代BOM】新增功能

This commit is contained in:
10001392 2024-10-10 17:09:26 +08:00
parent bad832b9dc
commit a40c73a9ee
4 changed files with 261 additions and 5 deletions

View File

@ -3,17 +3,19 @@ package com.nflg.product.bomnew.api.user;
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.vo.BaseBomVO;
import com.nflg.product.bomnew.pojo.vo.BaseMaterialVO;
import com.nflg.product.bomnew.service.BatchBomService;
import com.nflg.product.bomnew.service.MaterialMainService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import nflg.product.common.vo.ResultVO;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import javax.validation.Valid;
import javax.validation.constraints.NotNull;
import java.util.Collections;
import java.util.List;
@ -21,7 +23,6 @@ import java.util.List;
* 批量替代BOM
*
* @author makejava
* @since 2023-11-17 16:55:08
*/
@Api(tags = "批量替代BOM接口")
@RestController
@ -30,6 +31,8 @@ public class BatchBomApi extends BaseApi {
@Resource
private MaterialMainService materialMainService;
@Resource
private BatchBomService batchBomService;
@GetMapping("getMaterialInfo")
@ApiOperation("查询物料信息")
@ -44,4 +47,10 @@ public class BatchBomApi extends BaseApi {
return ResultVO.success(materialBaseInfo.get(0));
}
@PostMapping("getParentBomList")
@ApiOperation("获取指定物料号的所有父级BOM列表")
public ResultVO<List<BaseBomVO>> getParentBomList(@Valid @RequestBody @NotNull BatchBomQuery batchBomQuery) {
return ResultVO.success(batchBomService.getParentBomList(batchBomQuery));
}
}

View File

@ -0,0 +1,43 @@
package com.nflg.product.bomnew.pojo.query;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import javax.validation.constraints.NotNull;
import java.io.Serializable;
import java.math.BigDecimal;
@Data
public class BatchBomQuery implements Serializable {
@ApiModelProperty(value = "原物料号")
@NotNull
private String materialNo;
@ApiModelProperty(value = "新物料号")
@NotNull
private String newMaterialNo;
@ApiModelProperty(value = "原物料单位")
@NotNull
private String materialUnit;
@ApiModelProperty(value = "新物料单位")
@NotNull
private String newMaterialUnit;
@ApiModelProperty(value = "换算前")
@NotNull
private BigDecimal replaceTimes;
@ApiModelProperty(value = "换算后")
@NotNull
private BigDecimal newReplaceTimes;
@ApiModelProperty(value = "BOM类型")
@NotNull
private String bomType;
@ApiModelProperty(value = "工厂")
private String factory;
}

View File

@ -0,0 +1,90 @@
package com.nflg.product.bomnew.pojo.vo;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.math.BigDecimal;
import java.time.LocalDateTime;
@Data
public class BaseBomVO {
@ApiModelProperty("序号")
private Long orderNum;
@ApiModelProperty("父级BOM ID")
private Long parentRowId;
@ApiModelProperty("父级物料主数据行ID")
private Long parentMaterialRowId;
@ApiModelProperty("父级物料编码")
private String parentMaterialNo;
@ApiModelProperty("父级物料描述")
private String parentMaterialDesc;
@ApiModelProperty("物料大类别")
private String relCategoryCode;
@ApiModelProperty("物料类别代码")
private String categoryCode;
@ApiModelProperty("物料类别")
private String categoryName;
@ApiModelProperty("父级BOM版本号")
private String parentVersion;
@ApiModelProperty("原物料编码")
private String materialNo;
@ApiModelProperty("原数量")
private BigDecimal num;
@ApiModelProperty("原单位")
private String unit;
@ApiModelProperty("新物料编码")
private String newMaterialNo;
@ApiModelProperty("新数量")
private BigDecimal newNum;
@ApiModelProperty("新单位")
private String newUnit;
@ApiModelProperty("新版本号")
private String newVersion;
/**
* 设计人员编码
*/
@ApiModelProperty(value = "设计人员编码")
private String deviseUserCode;
/**
* 设计人员名称
*/
@ApiModelProperty(value = "设计人员名称")
private String deviseName;
/**
* 创建人编码
*/
@ApiModelProperty(value = "创建人编码")
private String createdBy;
/**
* 创建时间
*/
@ApiModelProperty(value = "创建时间")
private LocalDateTime createdTime;
/**
* 版本过期时间
*/
@ApiModelProperty(value = "版本过期时间")
private LocalDateTime expireEndTime;
}

View File

@ -0,0 +1,114 @@
package com.nflg.product.bomnew.service;
import cn.hutool.core.collection.CollectionUtil;
import com.nflg.product.base.core.exception.NflgBusinessException;
import com.nflg.product.bomnew.constant.EBomStatusEnum;
import com.nflg.product.bomnew.pojo.entity.BomNewEbomChildEntity;
import com.nflg.product.bomnew.pojo.entity.BomNewEbomParentEntity;
import com.nflg.product.bomnew.pojo.query.BatchBomQuery;
import com.nflg.product.bomnew.pojo.vo.BaseBomVO;
import com.nflg.product.bomnew.pojo.vo.BaseMaterialVO;
import com.nflg.product.bomnew.util.ListCommonUtil;
import com.nflg.product.bomnew.util.VersionUtil;
import lombok.extern.slf4j.Slf4j;
import nflg.product.common.constant.STATE;
import org.springframework.stereotype.Service;
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.util.stream.Collectors;
@Service
@Slf4j
public class BatchBomService {
@Resource
private BomNewEbomParentService bomNewEbomParentService;
@Resource
private BomNewEbomChildService bomNewEbomChildService;
@Resource
private BomNewPbomParentService bomNewPbomParentService;
@Resource
private BomNewPbomChildService bomNewPbomChildService;
@Resource
private MaterialMainService materialMainService;
public List<BaseBomVO> getParentBomList(BatchBomQuery batchBomQuery) {
if (batchBomQuery.getReplaceTimes().compareTo(BigDecimal.ZERO) == 0 || batchBomQuery.getNewReplaceTimes().compareTo(BigDecimal.ZERO) == 0) {
throw new NflgBusinessException(STATE.ParamErr, "参数错误换算关系不能为0");
}
List<BaseBomVO> resultList = new ArrayList<>();
String bomType = batchBomQuery.getBomType();
if ("ebom".equals(bomType)) {
String materialNo = batchBomQuery.getMaterialNo();
// 查询出子级
List<BomNewEbomChildEntity> ebomChildEntities = bomNewEbomChildService.lambdaQuery()
.eq(BomNewEbomChildEntity::getMaterialNo, materialNo)
.list();
if (CollectionUtil.isNotEmpty(ebomChildEntities)) {
// 根据子级的parentRowId查询父级状态是已发布PBOM即正式表数据
List<Long> parentRowIds = ebomChildEntities.stream().map(BomNewEbomChildEntity::getParentRowId).collect(Collectors.toList());
List<BomNewEbomParentEntity> ebomParentEntities = bomNewEbomParentService.lambdaQuery()
.in(BomNewEbomParentEntity::getRowId, parentRowIds)
.eq(BomNewEbomParentEntity::getStatus, EBomStatusEnum.PUBLISHED.getValue())
.orderByDesc(BomNewEbomParentEntity::getCreatedTime)
.list();
if (CollectionUtil.isNotEmpty(ebomParentEntities)) {
long counter = 0;
for (BomNewEbomParentEntity parent : ebomParentEntities) {
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<BomNewEbomChildEntity> first = ebomChildEntities.stream().filter(item -> item.getParentRowId().equals(parent.getRowId())).findFirst();
if (first.isPresent()) {
BomNewEbomChildEntity ebomChild = first.get();
baseBomVO.setMaterialNo(ebomChild.getMaterialNo());
baseBomVO.setNum(ebomChild.getNum());
baseBomVO.setUnit(ebomChild.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);
}
}
}
} else if ("pbom".equals(bomType)) {
}
if (CollectionUtil.isEmpty(resultList)) {
return null;
}
// 实时查询物料的物料描述物料类别等字段
List<BaseMaterialVO> tempList = new ArrayList<>();
resultList.forEach(result -> {
BaseMaterialVO parent = new BaseMaterialVO();
parent.setMaterialNo(result.getParentMaterialNo());
tempList.add(parent);
});
materialMainService.intiMaterialInfo(tempList);
Map<String, BaseMaterialVO> materialMp = ListCommonUtil.listToMap(tempList, BaseMaterialVO::getMaterialNo);
resultList.forEach(result -> {
result.setParentMaterialRowId(materialMp.get(result.getParentMaterialNo()).getMaterialRowId());
result.setParentMaterialDesc(materialMp.get(result.getParentMaterialNo()).getMaterialDesc());
result.setCategoryCode(materialMp.get(result.getParentMaterialNo()).getMaterialCategoryCode());
result.setRelCategoryCode(materialMp.get(result.getParentMaterialNo()).getRelCategoryCode());
result.setCategoryName(materialMp.get(result.getParentMaterialNo()).getCategoryName());
});
return resultList;
}
}