chenyuesheng преди 3 години
родител
ревизия
1aeb6bd273

+ 95 - 315
src/main/java/com/jeeplus/modules/sg/balancedlibrary/materialReportDetails/service/MaterialReportDetailsService.java

@@ -106,7 +106,6 @@ public class MaterialReportDetailsService extends CrudService<MaterialReportDeta
             return j;
         }
 
-
         //循环初始化
         liKuPoolList.forEach(liKuResourcePool -> {
             //初始化剩余数量
@@ -115,7 +114,7 @@ public class MaterialReportDetailsService extends CrudService<MaterialReportDeta
             liKuResourcePool.setNumberOfNiches("0");
 
 
-            //添加枚举标识
+            //添加地区枚举标识
             if (liKuResourcePool.getInvLocation().equals(AreaCodeFlagEnum.HLA2.getCode())) {
                 liKuResourcePool.setLiKuFlag(AreaCodeFlagEnum.HLA2);
             } else if (liKuResourcePool.getInvLocation().equals(AreaCodeFlagEnum.HLB1.getCode())) {
@@ -128,29 +127,8 @@ public class MaterialReportDetailsService extends CrudService<MaterialReportDeta
                 liKuResourcePool.setLiKuFlag(AreaCodeFlagEnum.NO_PLACE);
             }
 
-            //添加标识 分组 段长数据 非段长数据 单位转换
+            //添加标识 分组 段长数据 非段长数据 单位转换 先把千米转换为米
             if (liKuResourcePool.getUnitOfMeasurement().equals(MaterialsUnitFlagEnum.M.getUnit()) || liKuResourcePool.getUnitOfMeasurement().equals(MaterialsUnitFlagEnum.KM.getUnit())) {
-                /*if (StringUtils.isNotBlank(liKuResourcePool.getLengthOfCable())) {
-                    String[] split = liKuResourcePool.getLengthOfCable().split(";");
-                    for (int i = 0; i < split.length; i++) {
-                        //拆分成新的对象添加集合中 拆分段长为剩余
-                        LiKuResourcePool ResourcePool = new LiKuResourcePool();
-                        if (liKuResourcePool.getUnitOfMeasurement().equals(MaterialsUnitFlagEnum.KM.getUnit())) {
-                            BeanUtils.copyProperties(liKuResourcePool, ResourcePool);
-                            ResourcePool.setUnitOfMeasurement(MaterialsUnitFlagEnum.M.getUnit());
-                            ResourcePool.setInventoryAmount(new BigDecimal(liKuResourcePool.getInventoryAmount()).multiply(new BigDecimal(1000)).toString());
-                            ResourcePool.setRemaining(liKuResourcePool.getInventoryAmount());
-                            ResourcePool.setRemaining(new BigDecimal(split[i]).multiply(new BigDecimal(1000)).toString());
-                            ResourcePool.setLengthOfCable(new BigDecimal(split[i]).multiply(new BigDecimal(1000)).toString());
-                        } else {
-                            liKuResourcePool.setRemaining(split[i]);
-                            liKuResourcePool.setLengthOfCable(split[i]);
-                            BeanUtils.copyProperties(liKuResourcePool, ResourcePool);
-                        }
-
-                        liKuIsSegmentPoolList.add(ResourcePool);
-
-                } else {}*/
                 if (liKuResourcePool.getUnitOfMeasurement().equals(MaterialsUnitFlagEnum.KM.getUnit())) {
                     liKuResourcePool.setInventoryAmount(new BigDecimal(liKuResourcePool.getInventoryAmount()).multiply(new BigDecimal(1000)).toString());
                     liKuResourcePool.setLengthOfCable(liKuResourcePool.getInventoryAmount());
@@ -167,13 +145,6 @@ public class MaterialReportDetailsService extends CrudService<MaterialReportDeta
         List<LiKuResourcePool> liKuIsSegmentPoolSortList = getSortLiKuPool(liKuIsSegmentPoolList);
         List<LiKuResourcePool> liKuIsNotSegmentPoolSortList = getSortLiKuPool(liKuIsNotSegmentPoolList);
 
-
-
-        /*liKuIsNotSegmentPoolSortList.forEach(l -> {
-            System.out.println(l.getLiKuFlag().getArea() + "---" + l.getMonthStorage() + "---" + l.getDaysStorage() + "---" + l.getInventoryAmount() + "---" + l.getBatch() + "---" + l.getExtendedCoding());
-        });*/
-
-
         /*************************************************物资上报明细***************************************/
         //物资上报 段长物资
         List<MaterialReportDetails> materialIsSegmentList = new ArrayList<>();
@@ -185,6 +156,7 @@ public class MaterialReportDetailsService extends CrudService<MaterialReportDeta
             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())) {
@@ -212,86 +184,56 @@ public class MaterialReportDetailsService extends CrudService<MaterialReportDeta
         List<MaterialReportDetails> materialIsSegmentSortList = getSortMaterialReport(materialIsSegmentList);
         List<MaterialReportDetails> materialIsNotSegmentSortList = getSortMaterialReport(materialIsNotSegmentList);
 
-        /*materialIsNotSegmentSortList.forEach(m->{
-            System.out.println(m.getAreaCodeFlagEnum().getArea() + "-----" + m.getTotal() +"-------"+ m.getExtendedCoding());
-        });*/
-
-        /********************************************物资利库比较***************************************************/
+        /********************************************物资匹配利库比较***************************************************/
 
         //非段长物资比较 本地库 物资匹配利库
         materialIsNotSegmentSortList.forEach(l -> {
-            //优先匹配最佳
-            /*liKuIsNotSegmentPoolSortList.stream().filter(liKu -> liKu.getLiKuFlag().getArea().equals(l.getReportingArea())
-                    && Double.valueOf(liKu.getRemaining()).compareTo(l.getTotal()) >= 0
-                    && l.getMaterialCode().equals(liKu.getMaterialCode())
-                    && l.getExtendedCoding().equals(liKu.getExtendedCoding())).forEach(liKuResourcePool -> {
-                liKuCompareMaterial(l, liKuResourcePool, AreaTypeFlagEnum.LOCAL, null, MaterialsUnitFlagEnum.IS_SEGMENT);
-            });*/
             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_SEGMENT);
+                    //上报物资对象,利库池对象,地区标识, 地区替换标识,段长非段长标识
+                    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())
-                        && Double.valueOf(liKu.getRemaining()).compareTo(l.getTotal()) >= 0
-                        && l.getMaterialCode().equals(liKu.getMaterialCode())
-                        && l.getExtendedCoding().equals(liKu.getExtendedCoding())).forEach(liKuResourcePool -> {
-                    liKuCompareMaterial(l, liKuResourcePool, AreaTypeFlagEnum.SPAN, null, MaterialsUnitFlagEnum.IS_SEGMENT);
-                });
-            }*/
+            //如果总量与利库数量不同
             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_SEGMENT);
+                    //上报物资对象,利库池对象,地区标识, 地区替换标识,段长非段长标识
+                    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())
-                        && Double.valueOf(liKu.getRemaining()).compareTo(l.getTotal()) >= 0
-                        && l.getMaterialCode().equals(liKu.getMaterialCode())).forEach(liKuResourcePool -> {
-                    liKuCompareMaterial(l, liKuResourcePool, AreaTypeFlagEnum.LOCAL, AreaTypeFlagEnum.LOCAL_REPLACEMENT, MaterialsUnitFlagEnum.IS_SEGMENT);
-                });
-            }*/
+            //如果总量与利库数量不同
             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_SEGMENT);
+                    //上报物资对象,利库池对象,地区标识, 地区替换标识,段长非段长标识
+                    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())
-                        && Double.valueOf(liKu.getRemaining()).compareTo(l.getTotal()) >= 0
-                        && l.getMaterialCode().equals(liKu.getMaterialCode())).forEach(liKuResourcePool -> {
-                    liKuCompareMaterial(l, liKuResourcePool, AreaTypeFlagEnum.SPAN, AreaTypeFlagEnum.SPAN_REPLACEMENT, MaterialsUnitFlagEnum.IS_SEGMENT);
-                });
-            }*/
+            //如果总量与利库数量不同
             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_SEGMENT);
+                    //上报物资对象,利库池对象,地区标识, 地区替换标识,段长非段长标识
+                    liKuCompareMaterial(l, liKuResourcePool, AreaTypeFlagEnum.SPAN, AreaTypeFlagEnum.SPAN_REPLACEMENT, MaterialsUnitFlagEnum.IS_NOT_SEGMENT);
                 });
             }
         });
@@ -299,270 +241,133 @@ public class MaterialReportDetailsService extends CrudService<MaterialReportDeta
         /***********************************************本地库 段长匹配**********************************************************/
         //段长物资 本地库比较 最优 上报物资匹配利库池
         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());
+                            && 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_NOT_SEGMENT);
+                //上报物资对象,利库池对象,地区标识, 地区替换标识,段长非段长标识
+                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());
+            //相同地区进行比较 过滤出 地区相同 物料编码相同,扩展编码相同数据 根据筛选出结果直接调用计算利库做处理
+            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_NOT_SEGMENT);
+                //上报物资对象,利库池对象,地区标识, 地区替换标识,段长非段长标识
+                liKuCompareMaterial(m, l, AreaTypeFlagEnum.LOCAL, null, MaterialsUnitFlagEnum.IS_SEGMENT);
             });
         });
-        //段长物资比较 本地库 利库匹配物资
-        liKuIsSegmentPoolSortList.forEach(l -> {
-            if (new BigDecimal(l.getRemaining()).compareTo(BigDecimal.ZERO) > 0) {
-                materialIsSegmentSortList.stream().filter(material -> material.getReportingArea().equals(l.getLiKuFlag().getArea())
-                        && material.getMaterialCode().equals(l.getMaterialCode())
-                        && material.getExtendedCoding().equals(l.getExtendedCoding())
-                        && new BigDecimal(l.getLengthOfCable()).compareTo(BigDecimal.valueOf(material.getTotal())) > 0).forEach(materialReportDetails -> {
-                            if (new BigDecimal(l.getRemaining()).compareTo(BigDecimal.valueOf(materialReportDetails.getTotal())) >= 0) {
-                                liKuCompareMaterial(materialReportDetails, l, AreaTypeFlagEnum.LOCAL, null, 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.SPAN, null, MaterialsUnitFlagEnum.IS_NOT_SEGMENT);
+                //上报物资对象,利库池对象,地区标识, 地区替换标识,段长非段长标识
+                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());
+                            && 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_NOT_SEGMENT);
+                //上报物资对象,利库池对象,地区标识, 地区替换标识,段长非段长标识
+                liKuCompareMaterial(m, l, AreaTypeFlagEnum.SPAN, null, MaterialsUnitFlagEnum.IS_SEGMENT);
             });
         });
-        //段长物资比较 跨区库 利库匹配物资
-        liKuIsSegmentPoolSortList.forEach(l -> {
-            if (new BigDecimal(l.getRemaining()).compareTo(BigDecimal.ZERO) > 0) {
-                materialIsSegmentSortList.stream().filter(material -> !material.getReportingArea().equals(l.getLiKuFlag().getArea())
-                        && material.getMaterialCode().equals(l.getMaterialCode())
-                        && material.getExtendedCoding().equals(l.getExtendedCoding())
-                        && new BigDecimal(l.getLengthOfCable()).compareTo(BigDecimal.valueOf(material.getTotal())) > 0).forEach(materialReportDetails -> {
-                            if (new BigDecimal(l.getRemaining()).compareTo(BigDecimal.valueOf(materialReportDetails.getTotal())) >= 0) {
-                                liKuCompareMaterial(materialReportDetails, l, AreaTypeFlagEnum.SPAN, null, 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());
+                            && !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_NOT_SEGMENT);
+                //上报物资对象,利库池对象,地区标识, 地区替换标识,段长非段长标识
+                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());
+            //同地区进行比较 过滤出 地区相同 物料编码相同,扩展编码不相同数据 根据筛选出结果直接调用计算利库做处理
+            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_NOT_SEGMENT);
+                //上报物资对象,利库池对象,地区标识, 地区替换标识,段长非段长标识
+                liKuCompareMaterial(m, l, AreaTypeFlagEnum.LOCAL, AreaTypeFlagEnum.LOCAL_REPLACEMENT, MaterialsUnitFlagEnum.IS_SEGMENT);
             });
         });
-        //段长物资比较 本地库 利库匹配物资
-        liKuIsSegmentPoolSortList.forEach(l -> {
-            if (new BigDecimal(l.getRemaining()).compareTo(BigDecimal.ZERO) > 0) {
-                materialIsSegmentSortList.stream().filter(material -> material.getReportingArea().equals(l.getLiKuFlag().getArea())
-                        && material.getMaterialCode().equals(l.getMaterialCode())
-                        && !material.getExtendedCoding().equals(l.getExtendedCoding())
-                        && new BigDecimal(l.getLengthOfCable()).compareTo(BigDecimal.valueOf(material.getTotal())) > 0).forEach(materialReportDetails -> {
-                            if (new BigDecimal(l.getRemaining()).compareTo(BigDecimal.valueOf(materialReportDetails.getTotal())) >= 0) {
-                                liKuCompareMaterial(materialReportDetails, l, AreaTypeFlagEnum.LOCAL,  AreaTypeFlagEnum.LOCAL_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());
+                            && !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_NOT_SEGMENT);
+                //上报物资对象,利库池对象,地区标识, 地区替换标识,段长非段长标识
+                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());
+                            && !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_NOT_SEGMENT);
+                //上报物资对象,利库池对象,地区标识, 地区替换标识,段长非段长标识
+                liKuCompareMaterial(m, l, AreaTypeFlagEnum.SPAN, AreaTypeFlagEnum.SPAN_REPLACEMENT, MaterialsUnitFlagEnum.IS_SEGMENT);
             });
         });
-        //段长物资比较 跨区库 利库匹配物资
-        liKuIsSegmentPoolSortList.forEach(l -> {
-            if (new BigDecimal(l.getRemaining()).compareTo(BigDecimal.ZERO) > 0) {
-                materialIsSegmentSortList.stream().filter(material -> !material.getReportingArea().equals(l.getLiKuFlag().getArea())
-                        && material.getMaterialCode().equals(l.getMaterialCode())
-                        && !material.getExtendedCoding().equals(l.getExtendedCoding())
-                        && new BigDecimal(l.getLengthOfCable()).compareTo(BigDecimal.valueOf(material.getTotal())) > 0).forEach(materialReportDetails -> {
-                            if (new BigDecimal(l.getRemaining()).compareTo(BigDecimal.valueOf(materialReportDetails.getTotal())) >= 0) {
-                                liKuCompareMaterial(materialReportDetails, l, AreaTypeFlagEnum.SPAN, AreaTypeFlagEnum.SPAN_REPLACEMENT, MaterialsUnitFlagEnum.IS_NOT_SEGMENT);
-                            }
-                        }
-                );
-            }
-        });
-        //段长物资比较 跨区库
-        /*liKuIsSegmentPoolSortList.forEach(l -> {
-            //最优选择 过滤本地库  物料编码  扩展编码 段长大于上报物资
-            materialIsSegmentSortList.stream().filter(material -> !material.getReportingArea().equals(l.getLiKuFlag().getArea())
-                    && material.getMaterialCode().equals(l.getMaterialCode())
-                    && material.getExtendedCoding().equals(l.getExtendedCoding())
-                    && new BigDecimal(l.getLengthOfCable()).compareTo(BigDecimal.valueOf(material.getTotal())) == 0).forEach(materialReportDetails -> {
-                        if (new BigDecimal(l.getRemaining()).compareTo(BigDecimal.ZERO) > 0) {
-                            liKuCompareMaterial(materialReportDetails, l, AreaTypeFlagEnum.SPAN, null, MaterialsUnitFlagEnum.IS_NOT_SEGMENT);
-                        }
-                    }
-            );
-            if (new BigDecimal(l.getRemaining()).compareTo(BigDecimal.ZERO) > 0) {
-                materialIsSegmentSortList.stream().filter(material -> !material.getReportingArea().equals(l.getLiKuFlag().getArea())
-                        && material.getMaterialCode().equals(l.getMaterialCode())
-                        && material.getExtendedCoding().equals(l.getExtendedCoding())
-                        && new BigDecimal(l.getLengthOfCable()).compareTo(BigDecimal.valueOf(material.getTotal())) > 0).forEach(materialReportDetails -> {
-                            if (new BigDecimal(l.getRemaining()).compareTo(BigDecimal.valueOf(materialReportDetails.getTotal())) >= 0) {
-                                liKuCompareMaterial(materialReportDetails, l, AreaTypeFlagEnum.SPAN, null, MaterialsUnitFlagEnum.IS_NOT_SEGMENT);
-                            }
-                        }
-                );
-            }
-        });
-        //段长物资替换 本地库
-        liKuIsSegmentPoolSortList.forEach(l -> {
-            //最优选择 过滤本地库  物料编码  扩展编码 段长大于上报物资
-            materialIsSegmentSortList.stream().filter(material -> material.getReportingArea().equals(l.getLiKuFlag().getArea())
-                    && material.getMaterialCode().equals(l.getMaterialCode())
-                    && new BigDecimal(l.getLengthOfCable()).compareTo(BigDecimal.valueOf(material.getTotal())) == 0).forEach(materialReportDetails -> {
-                        if (new BigDecimal(l.getRemaining()).compareTo(BigDecimal.ZERO) > 0) {
-                            liKuCompareMaterial(materialReportDetails, l, AreaTypeFlagEnum.LOCAL, AreaTypeFlagEnum.LOCAL_REPLACEMENT, MaterialsUnitFlagEnum.IS_NOT_SEGMENT);
-                        }
-                    }
-            );
-            if (new BigDecimal(l.getRemaining()).compareTo(BigDecimal.ZERO) > 0) {
-                materialIsSegmentSortList.stream().filter(material -> material.getReportingArea().equals(l.getLiKuFlag().getArea())
-                        && material.getMaterialCode().equals(l.getMaterialCode())
-                        && new BigDecimal(l.getLengthOfCable()).compareTo(BigDecimal.valueOf(material.getTotal())) > 0).forEach(materialReportDetails -> {
-                            if (new BigDecimal(l.getRemaining()).compareTo(BigDecimal.valueOf(materialReportDetails.getTotal())) >= 0) {
-                                liKuCompareMaterial(materialReportDetails, l, AreaTypeFlagEnum.LOCAL, AreaTypeFlagEnum.LOCAL_REPLACEMENT, MaterialsUnitFlagEnum.IS_NOT_SEGMENT);
-                            }
-                        }
-                );
-            }
-        });
-        //段长物资替换 跨区库
-        liKuIsSegmentPoolSortList.forEach(l -> {
-            //最优选择 过滤本地库  物料编码  扩展编码 段长大于上报物资
-            materialIsSegmentSortList.stream().filter(material -> !material.getReportingArea().equals(l.getLiKuFlag().getArea())
-                    && material.getMaterialCode().equals(l.getMaterialCode())
-                    && new BigDecimal(l.getLengthOfCable()).compareTo(BigDecimal.valueOf(material.getTotal())) == 0
-                    && !l.getExtendedCoding().equals(material.getExtendedCoding())).forEach(materialReportDetails -> {
-                        if (new BigDecimal(l.getRemaining()).compareTo(BigDecimal.ZERO) > 0) {
-                            liKuCompareMaterial(materialReportDetails, l, AreaTypeFlagEnum.SPAN, AreaTypeFlagEnum.SPAN_REPLACEMENT, MaterialsUnitFlagEnum.IS_NOT_SEGMENT);
-                        }
-                    }
-            );
-            if (new BigDecimal(l.getRemaining()).compareTo(BigDecimal.ZERO) > 0) {
-                materialIsSegmentSortList.stream().filter(material -> !material.getReportingArea().equals(l.getLiKuFlag().getArea())
-                        && material.getMaterialCode().equals(l.getMaterialCode())
-                        && new BigDecimal(l.getLengthOfCable()).compareTo(BigDecimal.valueOf(material.getTotal())) > 0
-                        && !l.getExtendedCoding().equals(material.getExtendedCoding())).forEach(materialReportDetails -> {
-                            if (new BigDecimal(l.getRemaining()).compareTo(BigDecimal.valueOf(materialReportDetails.getTotal())) >= 0) {
-                                liKuCompareMaterial(materialReportDetails, l, AreaTypeFlagEnum.SPAN, AreaTypeFlagEnum.SPAN_REPLACEMENT, MaterialsUnitFlagEnum.IS_NOT_SEGMENT);
-                            }
-                        }
-                );
-            }
-        });*/
 
-        //段长非段长合并 排序 处理拆分段长
-        /*List<LiKuResourcePool> tempList = new ArrayList<>();
-        liKuIsSegmentPoolSortList.stream().map(m -> {
-            m.setLengthOfCable(m.getRemaining() + ";");
-            return m;
-        }).forEach(l -> {
-            if (tempList.size() != 0) {
-                boolean flag = true;
-                for (LiKuResourcePool temp : tempList) {
-                    if (l.getExtendedCoding().equals(temp.getExtendedCoding())
-                            && l.getMaterialCode().equals(temp.getMaterialCode())
-                            && l.getInventoryAmount().equals(temp.getInventoryAmount())
-                            && l.getInvLocation().equals(temp.getInvLocation())
-                            && l.getBatch().equals(temp.getBatch())
-                            && l.getFactory().equals(temp.getFactory())
-                            && l.getPlanner().equals(temp.getPlanner())) {
-                        //段长拼接
-                        temp.setLengthOfCable(temp.getLengthOfCable() + l.getRemaining() + ";");
-                        //修改 剩余总量
-                        temp.setRemaining((new BigDecimal(temp.getRemaining()).add(new BigDecimal(l.getRemaining()))).toString());
-                        //修改 利库数量
-                        temp.setNumberOfNiches((new BigDecimal(temp.getNumberOfNiches()).add(new BigDecimal(l.getNumberOfNiches()))).toString());
-                        flag = false;
-                        break;
-                    }
-                }
-                if (flag) {
-                    tempList.add(l);
-                }
-            } else {
-                tempList.add(l);
-            }
-        });*/
-
-        //利库合并 并排序
+        //利库合并 并排序 将利库段长/非段长集合转换为流的形式进行合并,在此基础上对该流进行处理数据,把处理完的流转换为集合进行排序
         List<LiKuResourcePool> sortLiKuPoolList = getSortLiKuPool(Stream.concat(liKuIsNotSegmentPoolSortList.stream(), liKuIsSegmentPoolSortList.stream()).map(m -> {
+            //如过单位为千米 说明该对象物资被转换为米进行操作,重新转换为千米
             if (m.getUnitOfMeasurement().equals(MaterialsUnitFlagEnum.KM.getUnit())) {
                 if (StringUtils.isNotBlank(m.getNumberOfNiches())) {
                     m.setNumberOfNiches(new BigDecimal(m.getNumberOfNiches()).divide(new BigDecimal(1000)).toString());
@@ -573,9 +378,10 @@ public class MaterialReportDetailsService extends CrudService<MaterialReportDeta
             }
             return m;
         }).collect(Collectors.toList()));
-        //上报资源合并
-        List<MaterialReportDetails> materialResultList = Stream.concat(materialIsNotSegmentList.stream(), materialIsSegmentList.stream()).map(m -> {
-            //处理上报资源中多余,
+
+        //上报资源合并 段长/非段长集合转换为流进行合并,在此基础上对该流进行数据处理,把处理完的流转换为集合进行排序
+        List<MaterialReportDetails> materialResultList = getSortMaterialReport(Stream.concat(materialIsNotSegmentList.stream(), materialIsSegmentList.stream()).map(m -> {
+            //调用字符串处理方法,处理上报资源中多余,
             m.setLocalWareBatch(interceptString(m.getLocalWareBatch()));
             m.setLocalWareHouse(interceptString(m.getLocalWareHouse()));
             m.setNumberOfLocal(interceptString(m.getNumberOfLocal()));
@@ -595,6 +401,7 @@ public class MaterialReportDetailsService extends CrudService<MaterialReportDeta
             m.setRegionalReplacementBatch(interceptString(m.getRegionalReplacementBatch()));
             m.setRegionalReplacementHouse(interceptString(m.getRegionalReplacementHouse()));
             m.setRegionalReplacementNumber(interceptString(m.getRegionalReplacementNumber()));
+            //如过单位为千米 说明该对象物资被转换为米进行操作,重新转换为千米
             if (m.getUnit().equals(MaterialsUnitFlagEnum.KM.getUnit())) {
                 BigDecimal convert = new BigDecimal(1000);
                 if (m.getTotal() != null) {
@@ -608,14 +415,14 @@ public class MaterialReportDetailsService extends CrudService<MaterialReportDeta
                 }
             }
             return m;
-        }).collect(Collectors.toList());
+        }).collect(Collectors.toList()));
 
         /***************************************存储数据库************************************************/
-        //清除利库池
-        materialReportDetailsMapper.delAll();
-
+        //更新利库池
         liKuResourcePoolMapper.updateAllList(sortLiKuPoolList);
-
+        //如果有新的上报物资导入 删除原有上报物资
+        materialReportDetailsMapper.delAll();
+        //将处理结果上报物资重新添加进数据库中
         materialResultList.forEach(DataEntity::preInsert);
         materialReportDetailsMapper.insertList(materialResultList);
         j.setSuccess(true);
@@ -673,11 +480,7 @@ public class MaterialReportDetailsService extends CrudService<MaterialReportDeta
         //物资  申请数量
         materialReportDetails.setNumberOfApplications(material_ApplicationCount.subtract(temp).doubleValue());
         //物资  利库量
-        //if (judgingSegment == MaterialsUnitFlagEnum.IS_NOT_SEGMENT) {
         materialReportDetails.setNumberOfNiches(material_liKuCount.add(temp).doubleValue());
-        /*} else {
-            materialReportDetails.setNumberOfNiches(material_liKuCount.add(temp).doubleValue());
-        }*/
         if (materialReportDetails.getUnit().equals(MaterialsUnitFlagEnum.KM.getUnit())) {
             temp = temp.divide(new BigDecimal(1000));
         }
@@ -688,27 +491,29 @@ public class MaterialReportDetailsService extends CrudService<MaterialReportDeta
                 //拼接本地库批次号
                 materialReportDetails.setLocalWareBatch(materialReportDetails.getLocalWareBatch() + liKuResourcePool.getBatch() + ",");
                 materialReportDetails.setLocalWareHouse(materialReportDetails.getLocalWareHouse() + liKuResourcePool.getInvLocation() + ",");
-                materialReportDetails.setNumberOfLocal(materialReportDetails.getNumberOfLocal() + temp.setScale(2, BigDecimal.ROUND_HALF_UP) + ",");
+                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(2, BigDecimal.ROUND_HALF_UP) + ",");
+                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(2, BigDecimal.ROUND_HALF_UP) + ",");
+                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(2, BigDecimal.ROUND_HALF_UP) + ",");
+                materialReportDetails.setRegionalReplacementNumber(materialReportDetails.getRegionalReplacementNumber() + temp.setScale(3, BigDecimal.ROUND_HALF_UP) + ",");
             }
         }
     }
@@ -758,8 +563,11 @@ public class MaterialReportDetailsService extends CrudService<MaterialReportDeta
      */
     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) {
+                    //扩展编码比较
                     return new BigDecimal(material1.getExtendedCoding()).compareTo(new BigDecimal(material2.getExtendedCoding()));
                 } else {
                     return material2.getTotal().compareTo(material1.getTotal());
@@ -770,32 +578,4 @@ public class MaterialReportDetailsService extends CrudService<MaterialReportDeta
         }).collect(Collectors.toList());
     }
 
-    /**
-     * 贪心算法 递归组合
-     * @param total
-     * @param value
-     * @param resultMap
-     * @return
-     */
-    private Map<Integer, List<Integer>> GreedyAlgorithmRecursion(int total, List<Integer> value, Map<Integer, List<Integer>> resultMap) {
-        if (value.size() == 0 || resultMap.containsKey(total)) {
-            return resultMap;
-        }
-        int result = 0;
-        List<Integer> list = new ArrayList<>();
-        int temp = total;
-        for (int i = value.size() - 1; i >= 0; i--) {
-            if (temp >= value.get(i)) {
-                temp -= value.get(i);
-                if (temp >= 0) {
-                    list.add(i);
-                    result += value.get(i);
-                }
-            }
-        }
-        resultMap.put(result, list);
-        return GreedyAlgorithmRecursion(total, value.stream().limit(value.size() - 1).collect(Collectors.toList()), resultMap);
-    }
-
-
 }

+ 46 - 5
src/main/java/com/jeeplus/modules/sg/balancedlibrary/materialReportDetails/utils/ExportUtil.java

@@ -56,7 +56,6 @@ public class ExportUtil {
                     Double likuAmount = report.getNumberOfNiches();
                     int color = 0;
                     if(likuAmount>0) color=1;
-
                     Row row = sheet1.createRow(rowNum+i);
                     Cell cell0 = crateCell(workbook,row,0,color); //上报地区
                     Cell cell1 = crateCell(workbook,row,1,color); //储备项目名称
@@ -73,6 +72,51 @@ public class ExportUtil {
                     Cell cell12 = crateCell(workbook,row,12,color);//提报部门
                     Cell cell13 = crateCell(workbook,row,13,color); //利库数量
                     Cell cell14 = crateCell(workbook,row,14,color); //申请数量
+
+                    cell0.setCellValue(getString(report.getReportingArea()));
+                    cell1.setCellValue(getString(report.getNameOfReserve()));
+                    cell2.setCellValue(getString(report.getMaterialCode()));
+                    cell3.setCellValue(getString(report.getMaterialName()));
+                    cell4.setCellValue(getString(report.getExtendedCoding()));
+                    cell5.setCellValue(getString(report.getExtendedDescription()));
+                    cell6.setCellValue(getString(report.getUnit()));
+                    cell7.setCellValue(getDouble(report.getTotal()));
+                    cell8.setCellValue(getString(report.getUnitWeight()));
+                    cell9.setCellValue(getString(report.getTotalWeight()));
+                    cell10.setCellValue(getString(report.getSupplied()));
+                    cell11.setCellValue(getString(report.getReportPerson()));//提报人
+                    cell12.setCellValue(getString(report.getReportDepartment()));//提报部门
+                    cell13.setCellValue(getDouble(report.getNumberOfNiches()));
+                    cell14.setCellValue(getDouble(report.getNumberOfApplications()));
+
+                }
+            }
+            //利库明细情况
+            Sheet sheet2 = workbook.getSheetAt(1);
+            if(reportList!=null&&reportList.size()>0){
+                for(int i=0;i<reportList.size();i++){
+                    MaterialReportDetails report = reportList.get(i);
+                    //当利库数量不为0时 标红
+                    Double likuAmount = report.getNumberOfNiches();
+                    int color = 0;
+                    if(likuAmount>0) color=1;
+
+                    Row row = sheet2.createRow(rowNum+i);
+                    Cell cell0 = crateCell(workbook,row,0,color); //上报地区
+                    Cell cell1 = crateCell(workbook,row,1,color); //储备项目名称
+                    Cell cell2 = crateCell(workbook,row,2,color); //物料编码
+                    Cell cell3 = crateCell(workbook,row,3,color); //物料名称
+                    Cell cell4 = crateCell(workbook,row,4,color); //扩展编码
+                    Cell cell5 = crateCell(workbook,row,5,color); //扩展描述
+                    Cell cell6 = crateCell(workbook,row,6,color); //单位
+                    Cell cell7 = crateCell(workbook,row,7,color); //总量
+                    Cell cell8 = crateCell(workbook,row,8,color); //单重
+                    Cell cell9 = crateCell(workbook,row,9,color); //总重
+                    Cell cell10 = crateCell(workbook,row,10,color); //甲乙供
+                    Cell cell11 = crateCell(workbook,row,11,color);//提报人
+                    Cell cell12 = crateCell(workbook,row,12,color);//提报部门
+                    Cell cell13 = crateCell(workbook,row,13,color); //利库数量
+                    Cell cell14 = crateCell(workbook,row,14,color); //申请数量
                     Cell cell15 = crateCell(workbook,row,15,color); //本地利库批次号
                     Cell cell16 = crateCell(workbook,row,16,color); //本地利库库存地
                     Cell cell17 = crateCell(workbook,row,17,color); //本地利库数量
@@ -124,13 +168,10 @@ public class ExportUtil {
                     cell30.setCellValue(getString(report.getRegionalReplacementNumber()));
                 }
             }
-            /*//利库明细情况
-            Sheet sheet2 = workbook.getSheetAt(1);
-            if(likuList!=null&&likuList.size()>0){
+            /*if(likuList!=null&&likuList.size()>0){
                 for(int i=0;i<likuList.size();i++){
                     LikuDetail liku = likuList.get(i);
                     int color = 0;
-
                     Row row = sheet2.createRow(rowNum+i);
                     Cell cell0 = crateCell(workbook,row,0,color); //上报地区
                     Cell cell1 = crateCell(workbook,row,1,color); //储备项目名称

+ 15 - 26
src/main/java/com/jeeplus/modules/sg/balancedlibrary/materialReportDetails/web/MaterialReportDetailsControllerTest.java

@@ -243,17 +243,6 @@ public class MaterialReportDetailsControllerTest extends BaseController {
             if(!j.isSuccess()){
                 return j;
             }
-            /*String fileName = "项目物资需求表" + DateUtils.getDate("yyyyMMddHHmmss") + ".xlsx";
-            new ExportExcel("", MaterialReportDetails.class).setDataList(list).write(response, fileName).dispose();*/
-
-            //利库基础数据更新库存
-            //poolService.updateAllList(poolList);
-
-            /*if (list.size() > 0) {
-                service.delAll();
-                service.insertList(list);
-            }
-            */
         } catch (Exception e) {
             j.setMsg("导入物资上报明细失败!失败信息:" + e.getMessage());
             e.printStackTrace();
@@ -264,9 +253,9 @@ public class MaterialReportDetailsControllerTest extends BaseController {
     /**
      * 物资上报明细-导入Excel数据
      */
-    /*@ResponseBody
-    @RequestMapping(value = "import")
-    public AjaxJson importFile(@RequestParam("file") MultipartFile file, HttpServletResponse response, HttpServletRequest request) {
+    @ResponseBody
+    @RequestMapping(value = "oldImport")
+    public AjaxJson oldImportFile(@RequestParam("file") MultipartFile file, HttpServletResponse response, HttpServletRequest request) {
         AjaxJson j = new AjaxJson();
         //记录物资上报明细比对利库资源明细详细情况
         List<CompareHistory> compareHistories = new ArrayList<>();
@@ -290,7 +279,7 @@ public class MaterialReportDetailsControllerTest extends BaseController {
             ImportExcel ei = new ImportExcel(file, 1, 0);
             //物资上报明细数据列表
             List<MaterialReportDetails> list = ei.getDataList(MaterialReportDetails.class);
-            *//*****************************物资上报明细*********************************************//*
+            /*****************************物资上报明细*********************************************/
             //根据段长非段长、区域 分到不同list,同时设置初始利库数量及申请数量
             for (MaterialReportDetails details : list) {
                 details.preInsert(); //先给个Id
@@ -360,7 +349,7 @@ public class MaterialReportDetailsControllerTest extends BaseController {
             }
 
             //先根据
-            *//*****************************利库资源数据*********************************************//*
+            /*****************************利库资源数据*********************************************/
             //利库资源池数据,根据本部>扬中>丹阳>句容分组
             List<LiKuResourcePool> poolList = poolService.findLiKuList(null,null);
             if(poolList==null||poolList.size()==0){
@@ -387,7 +376,7 @@ public class MaterialReportDetailsControllerTest extends BaseController {
             List<LiKuResourcePool> jRPoolList = new ArrayList<>();
             //资源池分类同时每次设置初始利库数和剩余数
             for(LiKuResourcePool pool:poolList){
-                pool.setNumberOfNiches(0.0);
+                pool.setNumberOfNiches("0");
                 Integer isSectionLength = pool.getIsSectionLength();
                 Integer whereFrom = pool.getWhereFrom();
                 if(isSectionLength.equals(LiKuUtils.NO)){
@@ -467,7 +456,7 @@ public class MaterialReportDetailsControllerTest extends BaseController {
                 poolSegSort(jRPoolList);
             }
 
-            *//*****************************************非段长比对*****************************************************//*
+            /*****************************************非段长比对*****************************************************/
             //非段长比对顺序,由物资上报数据比对利库资源池数据
             //本部-本部
             if (bBNonSegmentList.size() > 0 && bBNonPoolList.size() > 0) {
@@ -536,7 +525,7 @@ public class MaterialReportDetailsControllerTest extends BaseController {
                 AdjustUtil.nonSegAdjust(jRNonSegmentList,dYNonPoolList,compareHistories,AdjustUtil.SPAN_ADJUST);
             }
 
-            *//*************************************非段长以大代小******************************************************//*
+            /*************************************非段长以大代小******************************************************/
             //查找库中所有的以大代小的数据list
             List<ReplaceMaterial> replaceList = replaceMaterialService.findAll();
             if (replaceList.size() > 0) {
@@ -616,7 +605,7 @@ public class MaterialReportDetailsControllerTest extends BaseController {
 
             /****************************************段长比对*****************************************************/
             //本部-本部
-            /*if (bBPoolList.size() > 0 && bBSegmentList.size() > 0) {
+            if (bBPoolList.size() > 0 && bBSegmentList.size() > 0) {
                 AdjustUtil.segAdjustReverse(bBSegmentList,bBPoolList,compareHistories,AdjustUtil.LOCAL_ADJUST);
                 AdjustUtil.segAdjust(bBSegmentList,bBPoolList,compareHistories,AdjustUtil.LOCAL_ADJUST);
             }
@@ -701,7 +690,7 @@ public class MaterialReportDetailsControllerTest extends BaseController {
                 AdjustUtil.segAdjust(dYSegmentList,jRPoolList,compareHistories,AdjustUtil.SPAN_ADJUST);
             }
 
-            *//******************************************合并利库************************************//*
+            /******************************************合并利库************************************/
             //将4个区域的段长物资数据合并,使用各个区域的
             List<MaterialReportDetails> fourAreaList = new ArrayList<>();
             if (bBSegmentList.size() > 0) {
@@ -766,7 +755,7 @@ public class MaterialReportDetailsControllerTest extends BaseController {
             }
 
             //本部-扬中-丹阳-句容
-            *//****************************************段长以大代小********************************************//*
+            /****************************************段长以大代小********************************************/
             if (replaceList.size() > 0) {
                 //本部-本部-段长以大代小
                 if (bBPoolList.size() > 0 && bBSegmentList.size() > 0) {
@@ -853,7 +842,7 @@ public class MaterialReportDetailsControllerTest extends BaseController {
                     AdjustUtil.segRepAdjustReverse(yZSegmentList,jRPoolList,compareHistories,AdjustUtil.REP_SPAN_ADJUST,replaceList);
                     AdjustUtil.segRepAdjust(yZSegmentList,jRPoolList,compareHistories,AdjustUtil.REP_SPAN_ADJUST,replaceList);
                 }
-                *//******************************************以大代小合并利库************************************//*
+                /******************************************以大代小合并利库************************************/
                 //以大代小合并利库
 
                 //本部-所有
@@ -893,12 +882,12 @@ public class MaterialReportDetailsControllerTest extends BaseController {
             }
 
 
-            *//*****************************************调整记录保存**************************************************//*
+            /*****************************************调整记录保存**************************************************/
             if (compareHistories.size() > 0) {
                 compareHistoryService.delAll();
                 compareHistoryService.insertList(compareHistories);
             }
-            *//**********************************更新利库资源池,插入申请物资数据**************************************//*
+            /**********************************更新利库资源池,插入申请物资数据**************************************/
 
             //利库基础数据更新库存
             poolService.updateAllList(poolList);
@@ -914,7 +903,7 @@ public class MaterialReportDetailsControllerTest extends BaseController {
             j.setMsg("导入物资上报明细失败!失败信息:" + e.getMessage());
         }
         return j;
-    }*/
+    }
 
 
     /**

BIN
src/main/resources/freemarker/excelmodel/materialReport.xlsx


+ 0 - 242
src/main/webapp/webpage/modules/sg/balancedlibrary/materialReportDetails/MaterialReportDetailsList.js

@@ -263,248 +263,6 @@ $(document).ready(function() {
                        sortName: 'numberOfApplications'
 
 				   }
-
-
-				   ,{
-					   field: 'localWareBatch',
-					   title: '本地利库批次号',
-					   width: '10%',
-					   sortable: true,
-					   formatter:function(value, row , index){
-						   if(row.numberOfNiches > 0&&value){
-							   return "<a style='color:red'>" + value + "</a>";
-						   }else{
-							   return value;
-						   }
-					   },
-					   sortName: 'localWareBatch'
-
-				   }
-				   ,{
-					   field: 'localWareHouse',
-					   title: '本地利库库存地',
-					   width: '10%',
-					   sortable: true,
-					   formatter:function(value, row , index){
-						   if(row.numberOfNiches > 0&&value){
-							   return "<a style='color:red'>" + value + "</a>";
-						   }else{
-							   return value;
-						   }
-					   },
-					   sortName: 'localWareHouse'
-
-				   }
-				   ,{
-					   field: 'numberOfLocal',
-					   title: '本地利库数量',
-					   width: '10%',
-					   sortable: true,
-					   formatter:function(value, row , index){
-						   if(row.numberOfNiches > 0&&value){
-							   return "<a style='color:red'>" + value + "</a>";
-						   }else{
-							   return value;
-						   }
-					   },
-					   sortName: 'numberOfLocal'
-
-				   }
-				   ,{
-					   field: 'regionalBatch',
-					   title: '跨区利库批次号',
-					   width: '10%',
-					   sortable: true,
-					   formatter:function(value, row , index){
-						   if(row.numberOfNiches > 0&&value){
-							   return "<a style='color:red'>" + value + "</a>";
-						   }else{
-							   return value;
-						   }
-					   },
-					   sortName: 'regionalBatch'
-
-				   }
-				   ,{
-					   field: 'regionalHouse',
-					   title: '跨区利库库存地',
-					   width: '10%',
-					   sortable: true,
-					   formatter:function(value, row , index){
-						   if(row.numberOfNiches > 0&&value){
-							   return "<a style='color:red'>" + value + "</a>";
-						   }else{
-							   return value;
-						   }
-					   },
-					   sortName: 'regionalHouse'
-
-				   }
-				   ,{
-					   field: 'numberOfRegional',
-					   title: '跨区利库数量',
-					   width: '10%',
-					   sortable: true,
-					   formatter:function(value, row , index){
-						   if(row.numberOfNiches > 0&&value){
-							   return "<a style='color:red'>" + value + "</a>";
-						   }else{
-							   return value;
-						   }
-					   },
-					   sortName: 'numberOfRegional'
-
-				   }
-				   ,{
-					   field: 'localReplacementExtendedCoding',
-					   title: '本地替代利库利库扩展编码',
-					   width: '10%',
-					   sortable: true,
-					   formatter:function(value, row , index){
-						   if(row.numberOfNiches > 0&&value){
-							   return "<a style='color:red'>" + value + "</a>";
-						   }else{
-							   return value;
-						   }
-					   },
-					   sortName: 'localReplacementExtendedCoding'
-
-				   }
-				   ,{
-					   field: 'localReplacementExtendedDescription',
-					   title: '本地替代利库利库扩展描述',
-					   width: '10%',
-					   sortable: true,
-					   formatter:function(value, row , index){
-						   if(row.numberOfNiches > 0&&value){
-							   return "<a style='color:red'>" + value + "</a>";
-						   }else{
-							   return value;
-						   }
-					   },
-					   sortName: 'localReplacementExtendedDescription'
-
-				   }
-				   ,{
-					   field: 'localReplacementBatch',
-					   title: '本地替代利库利库批次号',
-					   width: '10%',
-					   sortable: true,
-					   formatter:function(value, row , index){
-						   if(row.numberOfNiches > 0&&value){
-							   return "<a style='color:red'>" + value + "</a>";
-						   }else{
-							   return value;
-						   }
-					   },
-					   sortName: 'localReplacementBatch'
-
-				   }
-				   ,{
-					   field: 'localReplacementHouse',
-					   title: '本地替代利库利库库存地',
-					   width: '10%',
-					   sortable: true,
-					   formatter:function(value, row , index){
-						   if(row.numberOfNiches > 0&&value){
-							   return "<a style='color:red'>" + value + "</a>";
-						   }else{
-							   return value;
-						   }
-					   },
-					   sortName: 'localReplacementHouse'
-
-				   }
-				   ,{
-					   field: 'localReplacementNumber',
-					   title: '本地替代利库利库数量',
-					   width: '10%',
-					   sortable: true,
-					   formatter:function(value, row , index){
-						   if(row.numberOfNiches > 0&&value){
-							   return "<a style='color:red'>" + value + "</a>";
-						   }else{
-							   return value;
-						   }
-					   },
-					   sortName: 'localReplacementNumber'
-
-				   }
-				   ,{
-					   field: 'regionalReplacementExtendedCoding',
-					   title: '跨区替代利库利库扩展编码',
-					   width: '10%',
-					   sortable: true,
-					   formatter:function(value, row , index){
-						   if(row.numberOfNiches > 0&&value){
-							   return "<a style='color:red'>" + value + "</a>";
-						   }else{
-							   return value;
-						   }
-					   },
-					   sortName: 'regionalReplacementExtendedCoding'
-
-				   }
-				   ,{
-					   field: 'regionalReplacementExtendedDescription',
-					   title: '跨区替代利库利库扩展描述',
-					   width: '10%',
-					   sortable: true,
-					   formatter:function(value, row , index){
-						   if(row.numberOfNiches > 0&&value){
-							   return "<a style='color:red'>" + value + "</a>";
-						   }else{
-							   return value;
-						   }
-					   },
-					   sortName: 'regionalReplacementExtendedDescription'
-
-				   }
-				   ,{
-					   field: 'regionalReplacementBatch',
-					   title: '跨区替代利库利库批次号',
-					   width: '10%',
-					   sortable: true,
-					   formatter:function(value, row , index){
-						   if(row.numberOfNiches > 0&&value){
-							   return "<a style='color:red'>" + value + "</a>";
-						   }else{
-							   return value;
-						   }
-					   },
-					   sortName: 'regionalReplacementBatch'
-
-				   }
-				   ,{
-					   field: 'regionalReplacementHouse',
-					   title: '跨区替代利库利库库存地',
-					   width: '10%',
-					   sortable: true,
-					   formatter:function(value, row , index){
-						   if(row.numberOfNiches > 0&&value){
-							   return "<a style='color:red'>" + value + "</a>";
-						   }else{
-							   return value;
-						   }
-					   },
-					   sortName: 'regionalReplacementHouse'
-
-				   }
-				   ,{
-					   field: 'regionalReplacementNumber',
-					   title: '跨区替代利库利库数量',
-					   width: '10%',
-					   sortable: true,
-					   formatter:function(value, row , index){
-						   if(row.numberOfNiches > 0&&value){
-							   return "<a style='color:red'>" + value + "</a>";
-						   }else{
-							   return value;
-						   }
-					   },
-					   sortName: 'regionalReplacementNumber'
-
-				   }
 		     ]
 
 		});