批量替代BOM

This commit is contained in:
10001392 2024-10-18 15:15:43 +08:00
parent 52530bee3b
commit 7f15b9b35a
5 changed files with 138 additions and 9 deletions

View File

@ -8,6 +8,8 @@ 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.pojo.vo.BomPageVO;
import com.nflg.product.bomnew.pojo.vo.BomTbHeaderVO;
import com.nflg.product.bomnew.service.BatchBomService;
import com.nflg.product.bomnew.service.BomNewEbomExportToSAP;
import com.nflg.product.bomnew.service.BomNewPbomParentService;
@ -22,6 +24,7 @@ import javax.validation.Valid;
import javax.validation.constraints.NotNull;
import java.util.Collections;
import java.util.List;
import java.util.Map;
/**
* 批量替代BOM
@ -55,7 +58,7 @@ public class BatchBomApi extends BaseApi {
@PostMapping("getParentBomList")
@ApiOperation("获取指定物料号的所有父级BOM列表")
public ResultVO<List<BaseBomVO>> getParentBomList(@Valid @RequestBody @NotNull BatchBomQuery batchBomQuery) {
public ResultVO<BomPageVO<Map<String, Object>, BomTbHeaderVO>> getParentBomList(@Valid @RequestBody @NotNull BatchBomQuery batchBomQuery) {
return ResultVO.success(batchBomService.getParentBomList(batchBomQuery));
}

View File

@ -27,15 +27,15 @@ public class BatchBomQuery implements Serializable {
private String newMaterialUnit;
@ApiModelProperty(value = "换算前")
@NotNull
// @NotNull
private BigDecimal replaceTimes;
@ApiModelProperty(value = "换算后")
@NotNull
// @NotNull
private BigDecimal newReplaceTimes;
@ApiModelProperty(value = "新数量小数位")
@NotNull
// @NotNull
private Integer decimalScale;
@ApiModelProperty(value = "BOM类型")

View File

@ -0,0 +1,69 @@
package com.nflg.product.bomnew.pojo.vo;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.nflg.product.base.core.vo.PageVO;
import lombok.Getter;
import lombok.Setter;
import java.util.List;
/**
* 分页带状态统计
*
* @author
* @Date 2021/6/16 10:02
*/
public class BomPageVO<T, U> extends PageVO<T> {
@Getter
@Setter
private List<U> tbHeaders;
public BomPageVO() {
super();
}
public BomPageVO(long page, long pageSize) {
super(page, pageSize);
}
public BomPageVO(long page, long pageSize, long total) {
super(page, pageSize, total);
}
public BomPageVO(long current, long size, boolean isSearchCount) {
super(current, size, isSearchCount);
}
public BomPageVO(long current, long size, long total, boolean isSearchCount) {
super(current, size, total, isSearchCount);
}
/**
* IPage 转换为 CountPageVO
*
* @param page 要转换的 IPage
* @param <T> 数据类型
* @return 转换后的 CountPageVO
*/
public static <T, U> BomPageVO<T, U> valueOf(IPage<T> page) {
return BomPageVO.valueOf(page, page.getRecords());
}
/**
* IPage 转换为 CountPageVO并且切换新的数据集合
* 应该保证原有的分页信息可以正确的应用在新的数据集合之中
*
* @param page 要转换的 IPage
* @param records 数据集合
* @param <T> 数据类型
* @return 转换后的 CountPageVO
*/
public static <T, U> BomPageVO<T, U> valueOf(IPage<?> page, List<T> records) {
BomPageVO<T, U> pageVO = new BomPageVO<>(page.getCurrent(), page.getSize(), page.getTotal(), page.searchCount());
pageVO.setRecords(records); // 应该保证原有的分页信息可以正确的应用在新的数据集中
return pageVO;
}
}

View File

@ -0,0 +1,23 @@
package com.nflg.product.bomnew.pojo.vo;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
/**
* @decription
* @Author 大米
* @Date 2022/9/25 9:25
**/
@Data
@AllArgsConstructor
public class BomTbHeaderVO {
@ApiModelProperty("表头显示名称")
private String displayHeaderName;
@ApiModelProperty("对应数据字段名称")
private String valueHeaderName;
// @ApiModelProperty("是否显示 0:不显示 1显示")
// private Integer displayState;
}

View File

@ -3,6 +3,7 @@ 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.convert.Convert;
import cn.hutool.core.date.DatePattern;
import cn.hutool.core.date.LocalDateTimeUtil;
import cn.hutool.core.util.ObjectUtil;
@ -23,6 +24,8 @@ 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;
import com.nflg.product.bomnew.pojo.vo.BomPageVO;
import com.nflg.product.bomnew.pojo.vo.BomTbHeaderVO;
import com.nflg.product.bomnew.util.DateUtils;
import com.nflg.product.bomnew.util.ListCommonUtil;
import com.nflg.product.bomnew.util.VersionUtil;
@ -63,14 +66,16 @@ public class BatchBomService {
@Resource
private MaterialMainService materialMainService;
public List<BaseBomVO> getParentBomList(BatchBomQuery batchBomQuery) {
public BomPageVO<Map<String, Object>, BomTbHeaderVO> getParentBomList(BatchBomQuery batchBomQuery) {
if (!(batchBomQuery.getMaterialUnit().equals(batchBomQuery.getNewMaterialUnit()))
&& (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();
Integer decimalScale = batchBomQuery.getDecimalScale();
int decimalScale = ObjectUtil.isNotEmpty(batchBomQuery.getDecimalScale()) ? batchBomQuery.getDecimalScale() : 3;
BigDecimal replaceTimes = ObjectUtil.isNotEmpty(batchBomQuery.getReplaceTimes()) ? batchBomQuery.getReplaceTimes() : BigDecimal.ONE;
BigDecimal newReplaceTimes = ObjectUtil.isNotEmpty(batchBomQuery.getNewReplaceTimes()) ? batchBomQuery.getNewReplaceTimes() : BigDecimal.ONE;
buildQueryCondition(batchBomQuery);
if ("ebom".equals(bomType)) {
String materialNo = batchBomQuery.getMaterialNo();
@ -121,7 +126,7 @@ public class BatchBomService {
baseBomVO.setUnit(ebomChild.getMaterialUnit());
}
baseBomVO.setNewMaterialNo(batchBomQuery.getNewMaterialNo());
baseBomVO.setNewNum(batchBomQuery.getNewReplaceTimes().divide(batchBomQuery.getReplaceTimes(), decimalScale, RoundingMode.HALF_UP).multiply(baseBomVO.getNum()));
baseBomVO.setNewNum(newReplaceTimes.divide(replaceTimes, decimalScale, RoundingMode.HALF_UP).multiply(baseBomVO.getNum()));
baseBomVO.setNewUnit(batchBomQuery.getNewMaterialUnit());
baseBomVO.setNewVersion(VersionUtil.getNextVersion(baseBomVO.getParentVersion()));
resultList.add(baseBomVO);
@ -178,7 +183,7 @@ public class BatchBomService {
baseBomVO.setUnit(pbomChild.getMaterialUnit());
}
baseBomVO.setNewMaterialNo(batchBomQuery.getNewMaterialNo());
baseBomVO.setNewNum(batchBomQuery.getNewReplaceTimes().divide(batchBomQuery.getReplaceTimes(), decimalScale, RoundingMode.HALF_UP).multiply(baseBomVO.getNum()));
baseBomVO.setNewNum(newReplaceTimes.divide(replaceTimes, decimalScale, RoundingMode.HALF_UP).multiply(baseBomVO.getNum()));
baseBomVO.setNewUnit(batchBomQuery.getNewMaterialUnit());
baseBomVO.setNewVersion(VersionUtil.getNextVersion(baseBomVO.getParentVersion()));
resultList.add(baseBomVO);
@ -205,7 +210,36 @@ public class BatchBomService {
result.setRelCategoryCode(materialMp.get(result.getParentMaterialNo()).getRelCategoryCode());
result.setCategoryName(materialMp.get(result.getParentMaterialNo()).getCategoryName());
});
return resultList;
BomPageVO<Map<String, Object>, BomTbHeaderVO> pageVO = new BomPageVO<>();
List<Map<String, Object>> records = new ArrayList<>(resultList.size());
resultList.forEach(result -> records.add(BeanUtil.beanToMap(result)));
pageVO.setRecords(records);
pageVO.setPages(records.size());
pageVO.setCurrent(1L);
pageVO.setPageSize(Long.MAX_VALUE);
pageVO.setTotal(records.size());
pageVO.setTbHeaders(getTbHeaders());
return pageVO;
}
private List<BomTbHeaderVO> getTbHeaders() {
List<BomTbHeaderVO> headerVOS = new ArrayList<>();
headerVOS.add(new BomTbHeaderVO("序号", "orderNum"));
headerVOS.add(new BomTbHeaderVO("父级物料编码", "parentMaterialNo"));
headerVOS.add(new BomTbHeaderVO("父级物料描述", "parentMaterialDesc"));
headerVOS.add(new BomTbHeaderVO("物料类别", "categoryName"));
headerVOS.add(new BomTbHeaderVO("父级BOM版本号", "parentVersion"));
headerVOS.add(new BomTbHeaderVO("原物料编码", "materialNo"));
headerVOS.add(new BomTbHeaderVO("原数量", "num"));
headerVOS.add(new BomTbHeaderVO("原单位", "unit"));
headerVOS.add(new BomTbHeaderVO("新物料编码", "newMaterialNo"));
headerVOS.add(new BomTbHeaderVO("新数量", "newNum"));
headerVOS.add(new BomTbHeaderVO("新单位", "newUnit"));
headerVOS.add(new BomTbHeaderVO("新版本号", "newVersion"));
headerVOS.add(new BomTbHeaderVO("创建时间", "createdTime"));
headerVOS.add(new BomTbHeaderVO("版本过期时间", "expireEndTime"));
headerVOS.add(new BomTbHeaderVO("设计人员", "deviseName"));
return headerVOS;
}
private void buildQueryCondition(BatchBomQuery query) {