|
@@ -6,8 +6,15 @@ package com.jeeplus.modules.sg.balancedlibrary.materialReportDetails.utils;
|
|
|
import com.google.common.collect.Lists;
|
|
|
import com.jeeplus.common.utils.Reflections;
|
|
|
import com.jeeplus.common.utils.excel.annotation.ExcelField;
|
|
|
+import com.jeeplus.modules.sg.balancedlibrary.liKuResourcePool.entity.LiKuResourcePool;
|
|
|
+import com.jeeplus.modules.sg.balancedlibrary.liKuResourcePool.utils.OptimalUtil;
|
|
|
import com.jeeplus.modules.sg.balancedlibrary.materialQuota.entity.MaterialQuota;
|
|
|
+import com.jeeplus.modules.sg.balancedlibrary.materialReportDetails.constant.AreaCodeFlagEnum;
|
|
|
+import com.jeeplus.modules.sg.balancedlibrary.materialReportDetails.constant.AreaTypeFlagEnum;
|
|
|
+import com.jeeplus.modules.sg.balancedlibrary.materialReportDetails.constant.MaterialsUnitFlagEnum;
|
|
|
+import com.jeeplus.modules.sg.balancedlibrary.materialReportDetails.entity.MaterialReportDetails;
|
|
|
import com.jeeplus.modules.sg.balancedlibrary.onPassageMaterials.entity.MaterialInformation;
|
|
|
+import com.jeeplus.modules.sg.balancedlibrary.reportPerson.entity.ReportPerson;
|
|
|
import com.jeeplus.modules.sg.balancedlibrary.standardMaterials.entity.StandardMaterials;
|
|
|
import com.jeeplus.modules.sg.balancedlibrary.transitMaterialGoods.entity.TransitMaterialGoods;
|
|
|
import com.jeeplus.modules.sys.entity.Area;
|
|
@@ -35,6 +42,8 @@ import java.text.DecimalFormat;
|
|
|
import java.text.NumberFormat;
|
|
|
import java.text.SimpleDateFormat;
|
|
|
import java.util.*;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+import java.util.stream.Stream;
|
|
|
|
|
|
/**
|
|
|
* 专门处理导入项目物资后验证问题
|
|
@@ -528,6 +537,361 @@ public class ExcelUtil {
|
|
|
|
|
|
/**
|
|
|
* 在途验证项目需求物资
|
|
|
+ */
|
|
|
+ public void dealVerifyZtNew(List<MaterialReportDetails> materialReportDetailsList,
|
|
|
+ List<LiKuResourcePool> liKuPoolList,
|
|
|
+ List<ReportPerson> departmentByPerson){
|
|
|
+ //段长利库池
|
|
|
+ List<LiKuResourcePool> liKuIsSegmentPoolList = new ArrayList<>();
|
|
|
+ //非段长利库池
|
|
|
+ List<LiKuResourcePool> liKuIsNotSegmentPoolList = new ArrayList<>();
|
|
|
+
|
|
|
+// List<LiKuResourcePool> liKuPoolList = liKuResourcePoolMapper.findLiKuList(null, null);
|
|
|
+
|
|
|
+ //循环初始化
|
|
|
+ liKuPoolList.forEach(liKuResourcePool -> {
|
|
|
+ //如果总量为空
|
|
|
+ if (com.jeeplus.common.utils.StringUtils.isBlank(liKuResourcePool.getInventoryAmount())) {
|
|
|
+ liKuResourcePool.setInventoryAmount("0");
|
|
|
+ }
|
|
|
+ //初始化剩余数量
|
|
|
+ liKuResourcePool.setRemaining(liKuResourcePool.getInventoryAmount());
|
|
|
+ //初始化利库数量
|
|
|
+ liKuResourcePool.setNumberOfNiches("0");
|
|
|
+
|
|
|
+
|
|
|
+ //添加地区枚举标识
|
|
|
+ if (liKuResourcePool.getInvLocation().equals(AreaCodeFlagEnum.HLA2.getCode())) {
|
|
|
+ liKuResourcePool.setLiKuFlag(AreaCodeFlagEnum.HLA2);
|
|
|
+ } else if (liKuResourcePool.getInvLocation().equals(AreaCodeFlagEnum.HLB1.getCode())) {
|
|
|
+ liKuResourcePool.setLiKuFlag(AreaCodeFlagEnum.HLB1);
|
|
|
+ } else if (liKuResourcePool.getInvLocation().equals(AreaCodeFlagEnum.HLC1.getCode())) {
|
|
|
+ liKuResourcePool.setLiKuFlag(AreaCodeFlagEnum.HLC1);
|
|
|
+ } else if (liKuResourcePool.getInvLocation().equals(AreaCodeFlagEnum.HLD1.getCode())) {
|
|
|
+ liKuResourcePool.setLiKuFlag(AreaCodeFlagEnum.HLD1);
|
|
|
+ } else {
|
|
|
+ liKuResourcePool.setLiKuFlag(AreaCodeFlagEnum.NO_PLACE);
|
|
|
+ }
|
|
|
+
|
|
|
+ //添加标识 分组 段长数据 非段长数据 单位转换 先把千米转换为米
|
|
|
+ if (liKuResourcePool.getUnitOfMeasurement().equals(MaterialsUnitFlagEnum.M.getUnit()) || liKuResourcePool.getUnitOfMeasurement().equals(MaterialsUnitFlagEnum.KM.getUnit())) {
|
|
|
+ if (liKuResourcePool.getUnitOfMeasurement().equals(MaterialsUnitFlagEnum.KM.getUnit())) {
|
|
|
+ liKuResourcePool.setInventoryAmount(new BigDecimal(liKuResourcePool.getInventoryAmount()).multiply(new BigDecimal(1000)).toString());
|
|
|
+ }
|
|
|
+ liKuResourcePool.setLengthOfCable(liKuResourcePool.getInventoryAmount());
|
|
|
+ liKuResourcePool.setRemaining(liKuResourcePool.getInventoryAmount());
|
|
|
+ liKuIsSegmentPoolList.add(liKuResourcePool);
|
|
|
+ /*}*/
|
|
|
+ } else {
|
|
|
+ liKuIsNotSegmentPoolList.add(liKuResourcePool);
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ //排序 地区-》库龄降序-》数量大小降序-》批次号-》扩展编码升序
|
|
|
+ List<LiKuResourcePool> liKuIsSegmentPoolSortList = getSortLiKuPool(liKuIsSegmentPoolList);
|
|
|
+ List<LiKuResourcePool> liKuIsNotSegmentPoolSortList = getSortLiKuPool(liKuIsNotSegmentPoolList);
|
|
|
+
|
|
|
+ /*************************************************物资上报明细***************************************/
|
|
|
+ //物资上报 段长物资
|
|
|
+ List<MaterialReportDetails> materialIsSegmentList = new ArrayList<>();
|
|
|
+ //物资上报 非段长物资
|
|
|
+ List<MaterialReportDetails> materialIsNotSegmentList = new ArrayList<>();
|
|
|
+ //根据 段长非段长区分 初始化
|
|
|
+ materialReportDetailsList.forEach(l -> {
|
|
|
+
|
|
|
+
|
|
|
+ //如果申请数量为空
|
|
|
+ if (null == l.getTotal()) {
|
|
|
+ l.setTotal(0.0);
|
|
|
+ }
|
|
|
+ //初始化利库数量
|
|
|
+ l.setNumberOfNiches(0.0);
|
|
|
+ //初始化申请数量
|
|
|
+ l.setNumberOfApplications(l.getTotal());
|
|
|
+ //添加地区标识
|
|
|
+ if (l.getReportingArea().equals(AreaCodeFlagEnum.HLA2.getArea())) {
|
|
|
+ l.setAreaCodeFlagEnum(AreaCodeFlagEnum.HLA2);
|
|
|
+ } else if (l.getReportingArea().equals(AreaCodeFlagEnum.HLD1.getArea())) {
|
|
|
+ l.setAreaCodeFlagEnum(AreaCodeFlagEnum.HLD1);
|
|
|
+ } else if (l.getReportingArea().equals(AreaCodeFlagEnum.HLB1.getArea())) {
|
|
|
+ l.setAreaCodeFlagEnum(AreaCodeFlagEnum.HLB1);
|
|
|
+ } else if (l.getReportingArea().equals(AreaCodeFlagEnum.HLC1.getArea())) {
|
|
|
+ l.setAreaCodeFlagEnum(AreaCodeFlagEnum.HLC1);
|
|
|
+ } else {
|
|
|
+ l.setAreaCodeFlagEnum(AreaCodeFlagEnum.NO_PLACE);
|
|
|
+ }
|
|
|
+
|
|
|
+ //单位转换为米
|
|
|
+ if (l.getUnit().equals(MaterialsUnitFlagEnum.KM.getUnit())) {
|
|
|
+ l.setTotal((BigDecimal.valueOf(l.getTotal()).multiply(new BigDecimal(1000))).doubleValue());
|
|
|
+ }
|
|
|
+ if (l.getUnit().equals(MaterialsUnitFlagEnum.M.getUnit()) || l.getUnit().equals(MaterialsUnitFlagEnum.KM.getUnit())) {
|
|
|
+ l.setNumberOfApplications(l.getTotal());
|
|
|
+ materialIsSegmentList.add(l);
|
|
|
+ } else {
|
|
|
+ materialIsNotSegmentList.add(l);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ //排序
|
|
|
+ List<MaterialReportDetails> materialIsSegmentSortList = getSortMaterialReport(materialIsSegmentList);
|
|
|
+ List<MaterialReportDetails> materialIsNotSegmentSortList = getSortMaterialReport(materialIsNotSegmentList);
|
|
|
+
|
|
|
+ /********************************************物资匹配利库比较***************************************************/
|
|
|
+
|
|
|
+ //非段长物资比较 本地库 物资匹配利库
|
|
|
+ materialIsNotSegmentSortList.forEach(l -> {
|
|
|
+ if (l.getTotal().compareTo(l.getNumberOfNiches()) != 0) {
|
|
|
+ //相同地区进行比较 过滤出 地区相同 物料编码相同,扩展编码相同数据 根据筛选出结果直接调用计算利库做处理
|
|
|
+ liKuIsNotSegmentPoolSortList.stream().filter(liKu -> liKu.getLiKuFlag().getArea().equals(l.getReportingArea())
|
|
|
+ && l.getMaterialCode().equals(liKu.getMaterialCode())
|
|
|
+ && l.getExtendedCoding().equals(liKu.getExtendedCoding())).forEach(liKuResourcePool -> {
|
|
|
+ //上报物资对象,利库池对象,地区标识, 地区替换标识,段长非段长标识
|
|
|
+ liKuCompareMaterial(l, liKuResourcePool, AreaTypeFlagEnum.LOCAL, null, MaterialsUnitFlagEnum.IS_NOT_SEGMENT);
|
|
|
+ });
|
|
|
+ }
|
|
|
+ });
|
|
|
+ //非段长物资比较 跨区库 物资匹配利库
|
|
|
+ materialIsNotSegmentSortList.forEach(l -> {
|
|
|
+ //如果总量与利库数量不同
|
|
|
+ if (l.getTotal().compareTo(l.getNumberOfNiches()) != 0) {
|
|
|
+ //不同地区比较 过滤出 不地区相同 物料编码相同,扩展编码相同数据 根据筛选出结果直接调用计算利库做处理
|
|
|
+ liKuIsNotSegmentPoolSortList.stream().filter(liKu -> !liKu.getLiKuFlag().getArea().equals(l.getReportingArea())
|
|
|
+ && l.getMaterialCode().equals(liKu.getMaterialCode())
|
|
|
+ && l.getExtendedCoding().equals(liKu.getExtendedCoding())).forEach(liKuResourcePool -> {
|
|
|
+ //上报物资对象,利库池对象,地区标识, 地区替换标识,段长非段长标识
|
|
|
+ liKuCompareMaterial(l, liKuResourcePool, AreaTypeFlagEnum.SPAN, null, MaterialsUnitFlagEnum.IS_NOT_SEGMENT);
|
|
|
+ });
|
|
|
+ }
|
|
|
+ });
|
|
|
+ //非段长物资替代 本地库
|
|
|
+ materialIsNotSegmentSortList.forEach(l -> {
|
|
|
+ //如果总量与利库数量不同
|
|
|
+ if (l.getTotal().compareTo(l.getNumberOfNiches()) != 0) {
|
|
|
+ //相同地区比较 过滤出相同地区 物料编码相同数据 扩展编码不同数据 根据筛选出结果直接调用计算利库做处理
|
|
|
+ liKuIsNotSegmentPoolSortList.stream().filter(liKu -> liKu.getLiKuFlag().getArea().equals(l.getReportingArea())
|
|
|
+ && l.getMaterialCode().equals(liKu.getMaterialCode())
|
|
|
+ && !l.getExtendedCoding().equals(liKu.getExtendedCoding())).forEach(liKuResourcePool -> {
|
|
|
+ //上报物资对象,利库池对象,地区标识, 地区替换标识,段长非段长标识
|
|
|
+ liKuCompareMaterial(l, liKuResourcePool, AreaTypeFlagEnum.LOCAL, AreaTypeFlagEnum.LOCAL_REPLACEMENT, MaterialsUnitFlagEnum.IS_NOT_SEGMENT);
|
|
|
+ });
|
|
|
+ }
|
|
|
+ });
|
|
|
+ //非段长物资代替 跨区库
|
|
|
+ materialIsNotSegmentSortList.forEach(l -> {
|
|
|
+ //如果总量与利库数量不同
|
|
|
+ if (l.getTotal().compareTo(l.getNumberOfNiches()) != 0) {
|
|
|
+ //不相同地区比较 过滤出不相同地区 物料编码相同数据 扩展编码不同数据 根据筛选出结果直接调用计算利库做处理
|
|
|
+ liKuIsNotSegmentPoolSortList.stream().filter(liKu -> !liKu.getLiKuFlag().getArea().equals(l.getReportingArea())
|
|
|
+ && l.getMaterialCode().equals(liKu.getMaterialCode())
|
|
|
+ && !l.getExtendedCoding().equals(liKu.getExtendedCoding())).forEach(liKuResourcePool -> {
|
|
|
+ //上报物资对象,利库池对象,地区标识, 地区替换标识,段长非段长标识
|
|
|
+ liKuCompareMaterial(l, liKuResourcePool, AreaTypeFlagEnum.SPAN, AreaTypeFlagEnum.SPAN_REPLACEMENT, MaterialsUnitFlagEnum.IS_NOT_SEGMENT);
|
|
|
+ });
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ /***********************************************本地库 段长匹配**********************************************************/
|
|
|
+ //段长物资 本地库比较 最优 上报物资匹配利库池
|
|
|
+ materialIsSegmentSortList.forEach(m -> {
|
|
|
+ //相同地区进行比较 过滤出 地区相同 物料编码相同,扩展编码相同数据 根据筛选出结果直接调用计算利库做处理
|
|
|
+ List<LiKuResourcePool> collect = liKuIsSegmentPoolSortList.stream().filter(liKu ->
|
|
|
+ liKu.getLiKuFlag().getArea().equals(m.getReportingArea())
|
|
|
+ && m.getMaterialCode().equals(liKu.getMaterialCode())
|
|
|
+ && m.getExtendedCoding().equals(liKu.getExtendedCoding()))
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ OptimalUtil optimalUtil = new OptimalUtil();
|
|
|
+ //返回最优解集合直接调用计算利库做处理
|
|
|
+ optimalUtil.getOptimalReverse(m.getTotal(), collect).forEach(l -> {
|
|
|
+ //上报物资对象,利库池对象,地区标识, 地区替换标识,段长非段长标识
|
|
|
+ liKuCompareMaterial(m, l, AreaTypeFlagEnum.LOCAL, null, MaterialsUnitFlagEnum.IS_SEGMENT);
|
|
|
+ });
|
|
|
+ });
|
|
|
+ //段长物资 本地库比较 最优 利库池匹配上报物资
|
|
|
+ liKuIsSegmentPoolSortList.forEach(l -> {
|
|
|
+ //相同地区进行比较 过滤出 地区相同 物料编码相同,扩展编码相同数据 根据筛选出结果直接调用计算利库做处理
|
|
|
+ List<MaterialReportDetails> collect = materialIsSegmentSortList.stream().filter(material ->
|
|
|
+ material.getReportingArea().equals(l.getLiKuFlag().getArea())
|
|
|
+ && material.getMaterialCode().equals(l.getMaterialCode())
|
|
|
+ && material.getExtendedCoding().equals(l.getExtendedCoding()))
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ OptimalUtil optimalUtil = new OptimalUtil();
|
|
|
+ //返回最优解集合直接调用计算利库做处理
|
|
|
+ optimalUtil.getOptimal(Double.parseDouble(l.getLengthOfCable()), collect).forEach(m -> {
|
|
|
+ //上报物资对象,利库池对象,地区标识, 地区替换标识,段长非段长标识
|
|
|
+ liKuCompareMaterial(m, l, AreaTypeFlagEnum.LOCAL, null, MaterialsUnitFlagEnum.IS_SEGMENT);
|
|
|
+ });
|
|
|
+ });
|
|
|
+
|
|
|
+ /***********************************************************跨区库 段长匹配***********************************************************************/
|
|
|
+ //段长物资 跨区库比较 最优 上报物资匹配利库池
|
|
|
+ materialIsSegmentSortList.forEach(m -> {
|
|
|
+ //不同地区进行比较 过滤出 地区不相同 物料编码相同,扩展编码相同数据 根据筛选出结果直接调用计算利库做处理
|
|
|
+ List<LiKuResourcePool> collect = liKuIsSegmentPoolSortList.stream().filter(liKu ->
|
|
|
+ !liKu.getLiKuFlag().getArea().equals(m.getReportingArea())
|
|
|
+ && m.getMaterialCode().equals(liKu.getMaterialCode())
|
|
|
+ && m.getExtendedCoding().equals(liKu.getExtendedCoding())
|
|
|
+ ).collect(Collectors.toList());
|
|
|
+ OptimalUtil optimalUtil = new OptimalUtil();
|
|
|
+ //返回最优解集合直接调用计算利库做处理
|
|
|
+ optimalUtil.getOptimalReverse(m.getTotal(), collect).forEach(l -> {
|
|
|
+ //上报物资对象,利库池对象,地区标识, 地区替换标识,段长非段长标识
|
|
|
+ liKuCompareMaterial(m, l, AreaTypeFlagEnum.SPAN, null, MaterialsUnitFlagEnum.IS_SEGMENT);
|
|
|
+ });
|
|
|
+ });
|
|
|
+ //段长物资 跨区库比较 最优 利库池匹配上报物资
|
|
|
+ liKuIsSegmentPoolSortList.forEach(l -> {
|
|
|
+ //不同地区进行比较 过滤出 地区不相同 物料编码相同,扩展编码相同数据 根据筛选出结果直接调用计算利库做处理
|
|
|
+ List<MaterialReportDetails> collect = materialIsSegmentSortList.stream().filter(material ->
|
|
|
+ !material.getReportingArea().equals(l.getLiKuFlag().getArea())
|
|
|
+ && material.getMaterialCode().equals(l.getMaterialCode())
|
|
|
+ && material.getExtendedCoding().equals(l.getExtendedCoding()))
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ OptimalUtil optimalUtil = new OptimalUtil();
|
|
|
+ //返回最优解集合直接调用计算利库做处理
|
|
|
+ optimalUtil.getOptimal(Double.parseDouble(l.getLengthOfCable()), collect).forEach(m -> {
|
|
|
+ //上报物资对象,利库池对象,地区标识, 地区替换标识,段长非段长标识
|
|
|
+ liKuCompareMaterial(m, l, AreaTypeFlagEnum.SPAN, null, MaterialsUnitFlagEnum.IS_SEGMENT);
|
|
|
+ });
|
|
|
+ });
|
|
|
+
|
|
|
+ /*************************************************************本地库-代替 段长*******************************************************************/
|
|
|
+ //段长物资 本地库比较 最优 上报物资匹配利库池 替代
|
|
|
+ materialIsSegmentSortList.forEach(m -> {
|
|
|
+ //同地区进行比较 过滤出 地区相同 物料编码相同,扩展编码不相同数据 根据筛选出结果直接调用计算利库做处理
|
|
|
+ List<LiKuResourcePool> collect = liKuIsSegmentPoolSortList.stream().filter(liKu ->
|
|
|
+ liKu.getLiKuFlag().getArea().equals(m.getReportingArea())
|
|
|
+ && m.getMaterialCode().equals(liKu.getMaterialCode())
|
|
|
+ && !m.getExtendedCoding().equals(liKu.getExtendedCoding()))
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ OptimalUtil optimalUtil = new OptimalUtil();
|
|
|
+ //返回最优解集合直接调用计算利库做处理
|
|
|
+ optimalUtil.getOptimalReverse(m.getTotal(), collect).forEach(l -> {
|
|
|
+ //上报物资对象,利库池对象,地区标识, 地区替换标识,段长非段长标识
|
|
|
+ liKuCompareMaterial(m, l, AreaTypeFlagEnum.LOCAL, AreaTypeFlagEnum.LOCAL_REPLACEMENT, MaterialsUnitFlagEnum.IS_SEGMENT);
|
|
|
+ });
|
|
|
+ });
|
|
|
+ //段长物资 本地库比较 最优 利库池匹配上报物资 替代
|
|
|
+ liKuIsSegmentPoolSortList.forEach(l -> {
|
|
|
+ //同地区进行比较 过滤出 地区相同 物料编码相同,扩展编码不相同数据 根据筛选出结果直接调用计算利库做处理
|
|
|
+ List<MaterialReportDetails> collect = materialIsSegmentSortList.stream().filter(material ->
|
|
|
+ material.getReportingArea().equals(l.getLiKuFlag().getArea())
|
|
|
+ && material.getMaterialCode().equals(l.getMaterialCode())
|
|
|
+ && !material.getExtendedCoding().equals(l.getExtendedCoding()))
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ OptimalUtil optimalUtil = new OptimalUtil();
|
|
|
+ optimalUtil.getOptimal(Double.parseDouble(l.getLengthOfCable()), collect).forEach(m -> {
|
|
|
+ //上报物资对象,利库池对象,地区标识, 地区替换标识,段长非段长标识
|
|
|
+ liKuCompareMaterial(m, l, AreaTypeFlagEnum.LOCAL, AreaTypeFlagEnum.LOCAL_REPLACEMENT, MaterialsUnitFlagEnum.IS_SEGMENT);
|
|
|
+ });
|
|
|
+ });
|
|
|
+
|
|
|
+ /*****************************************************跨区库 段长 替代 ****************************************************************/
|
|
|
+
|
|
|
+ //段长物资 跨区库比较 最优 上报物资匹配利库池 替代
|
|
|
+ materialIsSegmentSortList.forEach(m -> {
|
|
|
+ //不同地区进行比较 过滤出 地区不相同 物料编码相同,扩展编码不相同数据 根据筛选出结果直接调用计算利库做处理
|
|
|
+ List<LiKuResourcePool> collect = liKuIsSegmentPoolSortList.stream().filter(liKu ->
|
|
|
+ !liKu.getLiKuFlag().getArea().equals(m.getReportingArea())
|
|
|
+ && m.getMaterialCode().equals(liKu.getMaterialCode())
|
|
|
+ && !m.getExtendedCoding().equals(liKu.getExtendedCoding()))
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ OptimalUtil optimalUtil = new OptimalUtil();
|
|
|
+ //返回最优解
|
|
|
+ optimalUtil.getOptimalReverse(m.getTotal(), collect).forEach(l -> {
|
|
|
+ //上报物资对象,利库池对象,地区标识, 地区替换标识,段长非段长标识
|
|
|
+ liKuCompareMaterial(m, l, AreaTypeFlagEnum.SPAN, AreaTypeFlagEnum.SPAN_REPLACEMENT, MaterialsUnitFlagEnum.IS_SEGMENT);
|
|
|
+ });
|
|
|
+ });
|
|
|
+ //段长物资 跨区库比较 最优 利库池匹配上报物资
|
|
|
+ liKuIsSegmentPoolSortList.forEach(l -> {
|
|
|
+ //不同地区进行比较 过滤出 地区不相同 物料编码相同,扩展编码不相同数据 根据筛选出结果直接调用计算利库做处理
|
|
|
+ List<MaterialReportDetails> collect = materialIsSegmentSortList.stream().filter(material ->
|
|
|
+ !material.getReportingArea().equals(l.getLiKuFlag().getArea())
|
|
|
+ && material.getMaterialCode().equals(l.getMaterialCode())
|
|
|
+ && !material.getExtendedCoding().equals(l.getExtendedCoding()))
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ OptimalUtil optimalUtil = new OptimalUtil();
|
|
|
+ optimalUtil.getOptimal(Double.parseDouble(l.getLengthOfCable()), collect).forEach(m -> {
|
|
|
+ //上报物资对象,利库池对象,地区标识, 地区替换标识,段长非段长标识
|
|
|
+ liKuCompareMaterial(m, l, AreaTypeFlagEnum.SPAN, AreaTypeFlagEnum.SPAN_REPLACEMENT, MaterialsUnitFlagEnum.IS_SEGMENT);
|
|
|
+ });
|
|
|
+ });
|
|
|
+
|
|
|
+ //利库合并 并排序 将利库段长/非段长集合转换为流的形式进行合并,在此基础上对该流进行处理数据,把处理完的流转换为集合进行排序
|
|
|
+ List<LiKuResourcePool> sortLiKuPoolList = getSortLiKuPool(Stream.concat(liKuIsNotSegmentPoolSortList.stream(), liKuIsSegmentPoolSortList.stream()).map(m -> {
|
|
|
+ //如过单位为千米 说明该对象物资被转换为米进行操作,重新转换为千米
|
|
|
+ if (m.getUnitOfMeasurement().equals(MaterialsUnitFlagEnum.KM.getUnit())) {
|
|
|
+ if (com.jeeplus.common.utils.StringUtils.isNotBlank(m.getNumberOfNiches())) {
|
|
|
+ m.setNumberOfNiches(new BigDecimal(m.getNumberOfNiches()).divide(new BigDecimal(1000)).toString());
|
|
|
+ }
|
|
|
+ if (com.jeeplus.common.utils.StringUtils.isNotBlank(m.getRemaining())) {
|
|
|
+ m.setRemaining(new BigDecimal(m.getRemaining()).divide(new BigDecimal(1000)).toString());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return m;
|
|
|
+ }).collect(Collectors.toList()));
|
|
|
+
|
|
|
+ //上报资源合并 段长/非段长集合转换为流进行合并,在此基础上对该流进行数据处理,把处理完的流转换为集合进行排序
|
|
|
+ List<MaterialReportDetails> materialResultList = Stream.concat(materialIsNotSegmentList.stream(), materialIsSegmentList.stream()).map(m -> {
|
|
|
+
|
|
|
+
|
|
|
+ //调用字符串处理方法,处理上报资源中多余,
|
|
|
+ m.setLocalWareBatch(interceptString(m.getLocalWareBatch()));
|
|
|
+ m.setLocalWareHouse(interceptString(m.getLocalWareHouse()));
|
|
|
+ m.setNumberOfLocal(interceptString(m.getNumberOfLocal()));
|
|
|
+
|
|
|
+ m.setRegionalBatch(interceptString(m.getRegionalBatch()));
|
|
|
+ m.setRegionalHouse(interceptString(m.getRegionalHouse()));
|
|
|
+ m.setNumberOfRegional(interceptString(m.getNumberOfRegional()));
|
|
|
+
|
|
|
+ m.setLocalReplacementExtendedCoding(interceptString(m.getLocalReplacementExtendedCoding()));
|
|
|
+ m.setLocalReplacementExtendedDescription(interceptString(m.getLocalReplacementExtendedDescription()));
|
|
|
+ m.setLocalReplacementBatch(interceptString(m.getLocalReplacementBatch()));
|
|
|
+ m.setLocalReplacementHouse(interceptString(m.getLocalReplacementHouse()));
|
|
|
+ m.setLocalReplacementNumber(interceptString(m.getLocalReplacementNumber()));
|
|
|
+
|
|
|
+ m.setRegionalReplacementExtendedCoding(interceptString(m.getRegionalReplacementExtendedCoding()));
|
|
|
+ m.setRegionalReplacementExtendedDescription(interceptString(m.getRegionalReplacementExtendedDescription()));
|
|
|
+ m.setRegionalReplacementBatch(interceptString(m.getRegionalReplacementBatch()));
|
|
|
+ m.setRegionalReplacementHouse(interceptString(m.getRegionalReplacementHouse()));
|
|
|
+ m.setRegionalReplacementNumber(interceptString(m.getRegionalReplacementNumber()));
|
|
|
+
|
|
|
+ //设置提报人及提报部门
|
|
|
+ m.setReportPerson(m.getReportPerson());
|
|
|
+ if (m.getReportDepartment().equals("")) {
|
|
|
+ //根据提报人找到提报部门
|
|
|
+// List<ReportPerson> departmentByPerson = personMapper.getDepartmentByPerson();
|
|
|
+ departmentByPerson.forEach(de->{
|
|
|
+ if (de.getReportPerson().equals(m.getReportPerson())){
|
|
|
+ m.setReportDepartment(de.getReportDepartment());
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ }else {
|
|
|
+ m.setReportDepartment(m.getReportDepartment());
|
|
|
+ }
|
|
|
+ m.setRemark(m.getRemark());
|
|
|
+ m.setLiKuAmount(m.getLiKuAmount());
|
|
|
+
|
|
|
+ //如过单位为千米 说明该对象物资被转换为米进行操作,重新转换为千米
|
|
|
+ if (m.getUnit().equals(MaterialsUnitFlagEnum.KM.getUnit())) {
|
|
|
+ BigDecimal convert = new BigDecimal(1000);
|
|
|
+ if (m.getTotal() != null) {
|
|
|
+ m.setTotal(BigDecimal.valueOf(m.getTotal()).divide(convert).doubleValue());
|
|
|
+ }
|
|
|
+ if (m.getNumberOfNiches() != null) {
|
|
|
+ m.setNumberOfNiches(BigDecimal.valueOf(m.getNumberOfNiches()).divide(convert).doubleValue());
|
|
|
+ }
|
|
|
+ if (m.getNumberOfApplications() != null) {
|
|
|
+ m.setNumberOfApplications(BigDecimal.valueOf(m.getNumberOfApplications()).divide(convert).doubleValue());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return m;
|
|
|
+ }).collect(Collectors.toList());
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 在途验证项目需求物资
|
|
|
* @param standardList
|
|
|
* @param preferredCodes
|
|
|
* @param quotaList
|
|
@@ -714,5 +1078,151 @@ public class ExcelUtil {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 处理多余字符串
|
|
|
+ */
|
|
|
+ private String interceptString(String str) {
|
|
|
+ if (com.jeeplus.common.utils.StringUtils.isNotBlank(str)) {
|
|
|
+ return str.substring(0, str.length() - 1);
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 利库排序 地区-》库龄降序-》数量大小降序-》批次号-》物料编码升序
|
|
|
+ *
|
|
|
+ * @param liKuPoolList 利库池
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private List<LiKuResourcePool> getSortLiKuPool(List<LiKuResourcePool> liKuPoolList) {
|
|
|
+ return liKuPoolList.stream().sorted((liKuSort1, liKuSort2) -> {
|
|
|
+ if (liKuSort1.getLiKuFlag().getNum().compareTo(liKuSort2.getLiKuFlag().getNum()) == 0) {
|
|
|
+ //库龄按照月排序
|
|
|
+ if (liKuSort1.getMonthStorage().compareTo(liKuSort2.getMonthStorage()) == 0) {
|
|
|
+ //库龄按照日降序
|
|
|
+ if (liKuSort1.getDaysStorage().compareTo(liKuSort2.getDaysStorage()) == 0) {
|
|
|
+ //数量按大小降序
|
|
|
+ if (new BigDecimal(liKuSort1.getInventoryAmount()).compareTo(new BigDecimal(liKuSort2.getInventoryAmount())) == 0) {
|
|
|
+ //批次号自然顺序
|
|
|
+ if (liKuSort1.getBatch().compareTo(liKuSort2.getBatch()) == 0) {
|
|
|
+ //扩展编码升序
|
|
|
+ return new BigDecimal(liKuSort1.getExtendedCoding()).compareTo(new BigDecimal(liKuSort2.getExtendedCoding()));
|
|
|
+ } else {
|
|
|
+ return liKuSort1.getBatch().compareTo(liKuSort2.getBatch());
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ return new BigDecimal(liKuSort2.getInventoryAmount()).compareTo(new BigDecimal(liKuSort1.getInventoryAmount()));
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ return liKuSort2.getDaysStorage() - liKuSort1.getDaysStorage();
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ return liKuSort2.getMonthStorage() - (liKuSort1.getMonthStorage());
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ return liKuSort1.getLiKuFlag().getNum() - liKuSort2.getLiKuFlag().getNum();
|
|
|
+ }
|
|
|
+ }).collect(Collectors.toList());
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 上报资源排序 地区-》需求数量-》扩展编码
|
|
|
+ *
|
|
|
+ * @param materialReportDetailsList
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private List<MaterialReportDetails> getSortMaterialReport(List<MaterialReportDetails> materialReportDetailsList) {
|
|
|
+ return materialReportDetailsList.stream().sorted((material1, material2) -> {
|
|
|
+ //地区比较
|
|
|
+ if (material1.getAreaCodeFlagEnum() == material2.getAreaCodeFlagEnum()) {
|
|
|
+ //总量比较
|
|
|
+ if (material1.getTotal().compareTo(material2.getTotal()) == 0) {
|
|
|
+ //扩展编码比较 如果扩展编码为空值 为不影响排序比较 用Integer最大值来进行代替比较 排序到最后
|
|
|
+ return new BigDecimal(com.jeeplus.common.utils.StringUtils.isBlank(material1.getExtendedCoding()) ? String.valueOf(Integer.MAX_VALUE) : material1.getExtendedCoding())
|
|
|
+ .compareTo(new BigDecimal(com.jeeplus.common.utils.StringUtils.isBlank(material2.getExtendedCoding()) ? String.valueOf(Integer.MAX_VALUE) : material2.getExtendedCoding()));
|
|
|
+ } else {
|
|
|
+ return material2.getTotal().compareTo(material1.getTotal());
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ return material1.getAreaCodeFlagEnum().getNum() - material2.getAreaCodeFlagEnum().getNum();
|
|
|
+ }
|
|
|
+ }).collect(Collectors.toList());
|
|
|
+ }
|
|
|
|
|
|
+ /**
|
|
|
+ * 计算处理库
|
|
|
+ *
|
|
|
+ * @param materialReportDetails 上报资源
|
|
|
+ * @param liKuResourcePool 利库资源池
|
|
|
+ * @param areaTypeFlagEnum 地区类型
|
|
|
+ * @param replacement 地区替换类型
|
|
|
+ */
|
|
|
+ private void liKuCompareMaterial(MaterialReportDetails materialReportDetails, LiKuResourcePool liKuResourcePool, AreaTypeFlagEnum areaTypeFlagEnum, AreaTypeFlagEnum replacement, MaterialsUnitFlagEnum judgingSegment) {
|
|
|
+ //如果相等直接结束方法 利库数+总数
|
|
|
+ if (materialReportDetails.getTotal().compareTo(materialReportDetails.getNumberOfNiches()) == 0 || new BigDecimal(liKuResourcePool.getRemaining()).compareTo(BigDecimal.ZERO) == 0) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ //如果物料编码与扩展编码相同,说明是需要的物资
|
|
|
+ //利库池 利库数
|
|
|
+ BigDecimal liKu_liKuCount = new BigDecimal(liKuResourcePool.getNumberOfNiches());
|
|
|
+ //利库池剩余 量
|
|
|
+ BigDecimal liKu_remaining = new BigDecimal(liKuResourcePool.getRemaining());
|
|
|
+
|
|
|
+ //上报物资 申请数量
|
|
|
+ BigDecimal material_ApplicationCount = BigDecimal.valueOf(materialReportDetails.getNumberOfApplications());
|
|
|
+ //上报物资利库量
|
|
|
+ BigDecimal material_liKuCount = BigDecimal.valueOf(materialReportDetails.getNumberOfNiches());
|
|
|
+
|
|
|
+ //临时变量
|
|
|
+ BigDecimal temp = new BigDecimal(0);
|
|
|
+ if (material_ApplicationCount.compareTo(liKu_remaining) > 0) {
|
|
|
+ temp = liKu_remaining;//可能利库池剩余数量不够
|
|
|
+ } else {
|
|
|
+ temp = material_ApplicationCount;//利库池数量满足 上报需求
|
|
|
+ }
|
|
|
+
|
|
|
+ //利库池 剩余量
|
|
|
+ liKuResourcePool.setRemaining(liKu_remaining.subtract(temp).toString());
|
|
|
+ //利库量
|
|
|
+ liKuResourcePool.setNumberOfNiches(new BigDecimal(liKuResourcePool.getNumberOfNiches()).add(temp).toString());
|
|
|
+ //物资 申请数量
|
|
|
+ materialReportDetails.setNumberOfApplications(material_ApplicationCount.subtract(temp).doubleValue());
|
|
|
+ //物资 利库量
|
|
|
+ materialReportDetails.setNumberOfNiches(material_liKuCount.add(temp).doubleValue());
|
|
|
+ if (materialReportDetails.getUnit().equals(MaterialsUnitFlagEnum.KM.getUnit())) {
|
|
|
+ temp = temp.divide(new BigDecimal(1000));
|
|
|
+ }
|
|
|
+ //如果代替标识为空则
|
|
|
+ if (replacement == null) {
|
|
|
+ //传递标识,根据标识来判断本地/跨库 所有结束后统一处理多余,
|
|
|
+ if (AreaTypeFlagEnum.LOCAL == areaTypeFlagEnum) {
|
|
|
+ //拼接本地库批次号
|
|
|
+ materialReportDetails.setLocalWareBatch(materialReportDetails.getLocalWareBatch() + liKuResourcePool.getBatch() + ",");
|
|
|
+ materialReportDetails.setLocalWareHouse(materialReportDetails.getLocalWareHouse() + liKuResourcePool.getInvLocation() + ",");
|
|
|
+ materialReportDetails.setNumberOfLocal(materialReportDetails.getNumberOfLocal() + temp.setScale(3, BigDecimal.ROUND_HALF_UP) + ",");
|
|
|
+ } else {
|
|
|
+ //拼接跨区批次号
|
|
|
+ materialReportDetails.setRegionalBatch(materialReportDetails.getRegionalBatch() + liKuResourcePool.getBatch() + ",");
|
|
|
+ materialReportDetails.setRegionalHouse(materialReportDetails.getRegionalHouse() + liKuResourcePool.getInvLocation() + ",");
|
|
|
+ materialReportDetails.setNumberOfRegional(materialReportDetails.getNumberOfRegional() + temp.setScale(3, BigDecimal.ROUND_HALF_UP) + ",");
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ //区分本地利库与跨区利库替换
|
|
|
+ if (AreaTypeFlagEnum.LOCAL_REPLACEMENT == replacement) {
|
|
|
+ //拼接本地利库
|
|
|
+ materialReportDetails.setLocalReplacementExtendedCoding(materialReportDetails.getLocalReplacementExtendedCoding() + liKuResourcePool.getExtendedCoding() + ",");
|
|
|
+ materialReportDetails.setLocalReplacementExtendedDescription(materialReportDetails.getLocalReplacementExtendedDescription() + liKuResourcePool.getExtendedDescription() + ",");
|
|
|
+ materialReportDetails.setLocalReplacementBatch(materialReportDetails.getLocalReplacementBatch() + liKuResourcePool.getBatch() + ",");
|
|
|
+ materialReportDetails.setLocalReplacementHouse(materialReportDetails.getLocalReplacementHouse() + liKuResourcePool.getInvLocation() + ",");
|
|
|
+ materialReportDetails.setLocalReplacementNumber(materialReportDetails.getLocalReplacementNumber() + temp.setScale(3, BigDecimal.ROUND_HALF_UP) + ",");
|
|
|
+ } else {
|
|
|
+ //拼接跨区利库
|
|
|
+ materialReportDetails.setRegionalReplacementExtendedCoding(materialReportDetails.getRegionalReplacementExtendedCoding() + liKuResourcePool.getExtendedCoding() + ",");
|
|
|
+ materialReportDetails.setRegionalReplacementExtendedDescription(materialReportDetails.getRegionalReplacementExtendedDescription() + liKuResourcePool.getExtendedDescription() + ",");
|
|
|
+ materialReportDetails.setRegionalReplacementBatch(materialReportDetails.getRegionalReplacementBatch() + liKuResourcePool.getBatch() + ",");
|
|
|
+ materialReportDetails.setRegionalReplacementHouse(materialReportDetails.getRegionalReplacementHouse() + liKuResourcePool.getInvLocation() + ",");
|
|
|
+ materialReportDetails.setRegionalReplacementNumber(materialReportDetails.getRegionalReplacementNumber() + temp.setScale(3, BigDecimal.ROUND_HALF_UP) + ",");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|