|  | @@ -4,7 +4,6 @@
 | 
												
													
														
															|  |  package com.jeeplus.modules.sg.balancedlibrary.onPassageMaterials.web;
 |  |  package com.jeeplus.modules.sg.balancedlibrary.onPassageMaterials.web;
 | 
												
													
														
															|  |  
 |  |  
 | 
												
													
														
															|  |  
 |  |  
 | 
												
													
														
															|  | -import com.fasterxml.jackson.databind.exc.InvalidFormatException;
 |  | 
 | 
												
													
														
															|  |  import com.jeeplus.common.json.AjaxJson;
 |  |  import com.jeeplus.common.json.AjaxJson;
 | 
												
													
														
															|  |  import com.jeeplus.common.utils.DateUtils;
 |  |  import com.jeeplus.common.utils.DateUtils;
 | 
												
													
														
															|  |  import com.jeeplus.common.utils.excel.ExportExcel;
 |  |  import com.jeeplus.common.utils.excel.ExportExcel;
 | 
												
											
												
													
														
															|  | @@ -17,6 +16,7 @@ import com.jeeplus.core.web.BaseController;
 | 
												
													
														
															|  |  import com.jeeplus.modules.sg.balancedlibrary.reportPerson.entity.ReportPerson;
 |  |  import com.jeeplus.modules.sg.balancedlibrary.reportPerson.entity.ReportPerson;
 | 
												
													
														
															|  |  import com.jeeplus.modules.sg.balancedlibrary.reportPerson.mapper.ReportPersonMapper;
 |  |  import com.jeeplus.modules.sg.balancedlibrary.reportPerson.mapper.ReportPersonMapper;
 | 
												
													
														
															|  |  import com.jeeplus.modules.sg.balancedlibrary.reportPerson.service.ReportPersonService;
 |  |  import com.jeeplus.modules.sg.balancedlibrary.reportPerson.service.ReportPersonService;
 | 
												
													
														
															|  | 
 |  | +import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
 | 
												
													
														
															|  |  import org.apache.shiro.authz.annotation.RequiresPermissions;
 |  |  import org.apache.shiro.authz.annotation.RequiresPermissions;
 | 
												
													
														
															|  |  import org.springframework.beans.factory.annotation.Autowired;
 |  |  import org.springframework.beans.factory.annotation.Autowired;
 | 
												
													
														
															|  |  import org.springframework.stereotype.Controller;
 |  |  import org.springframework.stereotype.Controller;
 | 
												
											
												
													
														
															|  | @@ -75,21 +75,7 @@ public class OnPassageMaterialsController extends BaseController {
 | 
												
													
														
															|  |      @PostMapping("import")
 |  |      @PostMapping("import")
 | 
												
													
														
															|  |      public AjaxJson importFile(@RequestParam("file") MultipartFile[] file, HttpServletResponse response, HttpServletRequest request) {
 |  |      public AjaxJson importFile(@RequestParam("file") MultipartFile[] file, HttpServletResponse response, HttpServletRequest request) {
 | 
												
													
														
															|  |          AjaxJson ajaxJson = new AjaxJson();
 |  |          AjaxJson ajaxJson = new AjaxJson();
 | 
												
													
														
															|  | -        List<String> goHeavy = new ArrayList<>();
 |  | 
 | 
												
													
														
															|  | -        //物料编码 计划编制人相同
 |  | 
 | 
												
													
														
															|  | -        List<OnPassageMaterials> sameList = new ArrayList<>();
 |  | 
 | 
												
													
														
															|  | -        //计划编制人为空
 |  | 
 | 
												
													
														
															|  | -        List<OnPassageMaterials> isEmptyList = new ArrayList<>();
 |  | 
 | 
												
													
														
															|  | -        //统计物料编码 部门
 |  | 
 | 
												
													
														
															|  | -        Map<String, String> materialCountMap = new HashMap<>();
 |  | 
 | 
												
													
														
															|  | -        //统计物料编码 计划编制人相同合同数量
 |  | 
 | 
												
													
														
															|  | -        Map<String, BigDecimal> sameMap = new HashMap<>();
 |  | 
 | 
												
													
														
															|  | -        //统计计划编制人为空合同数量
 |  | 
 | 
												
													
														
															|  | -        Map<String, BigDecimal> isEmptyMap = new HashMap<>();
 |  | 
 | 
												
													
														
															|  | -        //在途物资表J列
 |  | 
 | 
												
													
														
															|  | -        Map<String, BigDecimal> JMap = new HashMap<>();
 |  | 
 | 
												
													
														
															|  | -        //项目物资需求表H列
 |  | 
 | 
												
													
														
															|  | -        Map<String, BigDecimal> HMap = new HashMap<>();
 |  | 
 | 
												
													
														
															|  | 
 |  | +
 | 
												
													
														
															|  |          try {
 |  |          try {
 | 
												
													
														
															|  |              //获取两张excel表
 |  |              //获取两张excel表
 | 
												
													
														
															|  |              ImportExcel ei = new ImportExcel(file[0], 1, 0);
 |  |              ImportExcel ei = new ImportExcel(file[0], 1, 0);
 | 
												
											
												
													
														
															|  | @@ -97,129 +83,19 @@ public class OnPassageMaterialsController extends BaseController {
 | 
												
													
														
															|  |              //转换为集合
 |  |              //转换为集合
 | 
												
													
														
															|  |              List<OnPassageMaterials> onPassageMaterialsList = ei.getDataList(OnPassageMaterials.class);
 |  |              List<OnPassageMaterials> onPassageMaterialsList = ei.getDataList(OnPassageMaterials.class);
 | 
												
													
														
															|  |              List<MaterialInformation> materialInformationList = ie.getDataList(MaterialInformation.class);
 |  |              List<MaterialInformation> materialInformationList = ie.getDataList(MaterialInformation.class);
 | 
												
													
														
															|  | -            /**************************************************************************/
 |  | 
 | 
												
													
														
															|  | -            //循环比较找出 计划编制人为空添加isEmptyMap 根据计划编制人找出所在部门 物料编码-部门为去重条件
 |  | 
 | 
												
													
														
															|  | -            onPassageMaterialsList.forEach(opm -> {
 |  | 
 | 
												
													
														
															|  | -                String key = "";
 |  | 
 | 
												
													
														
															|  | -                if (!opm.getPlanner().isEmpty()) {
 |  | 
 | 
												
													
														
															|  | -                    //计划编制人不为空存放
 |  | 
 | 
												
													
														
															|  | -                    String temp = opm.getMaterialCode() + "-" + opm.getPlanner();
 |  | 
 | 
												
													
														
															|  | -                    //去重 物料编码-计划编制人
 |  | 
 | 
												
													
														
															|  | -                    if(!goHeavy.contains(temp)){
 |  | 
 | 
												
													
														
															|  | -                        goHeavy.add(temp);
 |  | 
 | 
												
													
														
															|  | -                        sameList.add(opm);
 |  | 
 | 
												
													
														
															|  | -                    }
 |  | 
 | 
												
													
														
															|  | -                    //创建提交人对象
 |  | 
 | 
												
													
														
															|  | -                    ReportPerson reportPerson = new ReportPerson();
 |  | 
 | 
												
													
														
															|  | -                    reportPerson.setReportPerson(opm.getPlanner());
 |  | 
 | 
												
													
														
															|  | -                    //根据名称查询
 |  | 
 | 
												
													
														
															|  | -                    List<ReportPerson> list = reportPersonService.findList(reportPerson);
 |  | 
 | 
												
													
														
															|  | -                    //如果不为空,出现重名情况默认取第一个
 |  | 
 | 
												
													
														
															|  | -                    if (!list.isEmpty()) {
 |  | 
 | 
												
													
														
															|  | -                        key = opm.getMaterialCode() + "-" + list.get(0).getReportDepartment();
 |  | 
 | 
												
													
														
															|  | -                    } else {
 |  | 
 | 
												
													
														
															|  | -                        key = opm.getMaterialCode()/* + "-"*/;
 |  | 
 | 
												
													
														
															|  | -                    }
 |  | 
 | 
												
													
														
															|  | -
 |  | 
 | 
												
													
														
															|  | -                    dataCount(sameMap, sameList, key);
 |  | 
 | 
												
													
														
															|  | -                } else {
 |  | 
 | 
												
													
														
															|  | -                    key = opm.getMaterialCode();
 |  | 
 | 
												
													
														
															|  | -                    isEmptyList.add(opm);
 |  | 
 | 
												
													
														
															|  | -                    dataCount(isEmptyMap, isEmptyList, key);
 |  | 
 | 
												
													
														
															|  | -                }
 |  | 
 | 
												
													
														
															|  | -            });
 |  | 
 | 
												
													
														
															|  | -            materialInformationList.forEach(m -> {
 |  | 
 | 
												
													
														
															|  | -                String key = "";
 |  | 
 | 
												
													
														
															|  | -                if(!m.getReportingDepartment().isEmpty()){
 |  | 
 | 
												
													
														
															|  | -                    key = m.getMaterialCode() + "-" + m.getReportingDepartment();
 |  | 
 | 
												
													
														
															|  | -                }else{
 |  | 
 | 
												
													
														
															|  | -                    key = m.getMaterialCode();
 |  | 
 | 
												
													
														
															|  | -                }
 |  | 
 | 
												
													
														
															|  | -                    //如果有相同的去重不加
 |  | 
 | 
												
													
														
															|  | -                    if (materialCountMap.containsKey(key)) {
 |  | 
 | 
												
													
														
															|  | -					/*BigDecimal temp = new BigDecimal(String.valueOf(materialCountMap.get(key)));
 |  | 
 | 
												
													
														
															|  | -					temp = new BigDecimal(m.getTotal()).add(temp);
 |  | 
 | 
												
													
														
															|  | -					materialCountMap.put(key, temp);*/
 |  | 
 | 
												
													
														
															|  | -                    } else {
 |  | 
 | 
												
													
														
															|  | -                        materialCountMap.put(key, m.getTotal());
 |  | 
 | 
												
													
														
															|  | -                    }
 |  | 
 | 
												
													
														
															|  | -            });
 |  | 
 | 
												
													
														
															|  | -
 |  | 
 | 
												
													
														
															|  | -            materialCountMap.forEach((k, v) -> {
 |  | 
 | 
												
													
														
															|  | -                String[] split = k.split("-");
 |  | 
 | 
												
													
														
															|  | -                //如果有该部门则增加
 |  | 
 | 
												
													
														
															|  | -                if(split.length==2){
 |  | 
 | 
												
													
														
															|  | -                    if (HMap.containsKey(split[1])) {
 |  | 
 | 
												
													
														
															|  | -                        BigDecimal temp = new BigDecimal(v).add(HMap.get(split[1]));
 |  | 
 | 
												
													
														
															|  | -                        HMap.put(split[1], temp);
 |  | 
 | 
												
													
														
															|  | -                    } else {
 |  | 
 | 
												
													
														
															|  | -                        HMap.put(split[1], new BigDecimal(v));
 |  | 
 | 
												
													
														
															|  | -                    }
 |  | 
 | 
												
													
														
															|  | -                }
 |  | 
 | 
												
													
														
															|  | -
 |  | 
 | 
												
													
														
															|  | -            });
 |  | 
 | 
												
													
														
															|  | -
 |  | 
 | 
												
													
														
															|  | -            sameMap.forEach((k, v) -> {
 |  | 
 | 
												
													
														
															|  | -                String[] split = k.split("-");
 |  | 
 | 
												
													
														
															|  | -                //如果有该部门则增加
 |  | 
 | 
												
													
														
															|  | -                if(split.length==2){
 |  | 
 | 
												
													
														
															|  | -                    if (JMap.containsKey(split[1])) {
 |  | 
 | 
												
													
														
															|  | -                        BigDecimal temp = v.add(JMap.get(split[1]));
 |  | 
 | 
												
													
														
															|  | -                        JMap.put(split[1], temp);
 |  | 
 | 
												
													
														
															|  | -                    } else {
 |  | 
 | 
												
													
														
															|  | -                        JMap.put(split[1], v);
 |  | 
 | 
												
													
														
															|  | -                    }
 |  | 
 | 
												
													
														
															|  | -                }
 |  | 
 | 
												
													
														
															|  | -            });
 |  | 
 | 
												
													
														
															|  | -
 |  | 
 | 
												
													
														
															|  | -
 |  | 
 | 
												
													
														
															|  | -
 |  | 
 | 
												
													
														
															|  | -            /******************两表比较*******************/
 |  | 
 | 
												
													
														
															|  | -
 |  | 
 | 
												
													
														
															|  | -            HMap.forEach((k, v) -> {
 |  | 
 | 
												
													
														
															|  | -                if (JMap.containsKey(k)) {
 |  | 
 | 
												
													
														
															|  | -                    if (JMap.get(k).compareTo(v) >= 0) {
 |  | 
 | 
												
													
														
															|  | -                        materialInformationList.forEach(m -> {
 |  | 
 | 
												
													
														
															|  | -                            if (m.getReportingDepartment().equals(k)) {
 |  | 
 | 
												
													
														
															|  | -                                m.setRemarkText("在途已有" + JMap.get(k) + "单位,请核实本次需求");
 |  | 
 | 
												
													
														
															|  | -                            }
 |  | 
 | 
												
													
														
															|  | -                        });
 |  | 
 | 
												
													
														
															|  | -                    }
 |  | 
 | 
												
													
														
															|  | -                }
 |  | 
 | 
												
													
														
															|  | -            });
 |  | 
 | 
												
													
														
															|  |  
 |  |  
 | 
												
													
														
															|  | 
 |  | +            service.comparativeData(onPassageMaterialsList,materialInformationList);
 | 
												
													
														
															|  |  
 |  |  
 | 
												
													
														
															|  |  
 |  |  
 | 
												
													
														
															|  |              /***********************************************/
 |  |              /***********************************************/
 | 
												
													
														
															|  |              String fileName = "项目物资需求表" + DateUtils.getDate("yyyyMMddHHmmss") + ".xlsx";
 |  |              String fileName = "项目物资需求表" + DateUtils.getDate("yyyyMMddHHmmss") + ".xlsx";
 | 
												
													
														
															|  |              new ExportExcel("", MaterialInformation.class).setDataList(materialInformationList).write(response, fileName).dispose();
 |  |              new ExportExcel("", MaterialInformation.class).setDataList(materialInformationList).write(response, fileName).dispose();
 | 
												
													
														
															|  |  
 |  |  
 | 
												
													
														
															|  | -        } catch (InvalidFormatException e) {
 |  | 
 | 
												
													
														
															|  | -            e.printStackTrace();
 |  | 
 | 
												
													
														
															|  | -        } catch (IOException e) {
 |  | 
 | 
												
													
														
															|  | -            e.printStackTrace();
 |  | 
 | 
												
													
														
															|  | -        } catch (IllegalAccessException e) {
 |  | 
 | 
												
													
														
															|  | -            e.printStackTrace();
 |  | 
 | 
												
													
														
															|  | -        } catch (InstantiationException e) {
 |  | 
 | 
												
													
														
															|  | -            e.printStackTrace();
 |  | 
 | 
												
													
														
															|  | -        } catch (org.apache.poi.openxml4j.exceptions.InvalidFormatException e) {
 |  | 
 | 
												
													
														
															|  | 
 |  | +        } catch (InvalidFormatException | IOException | InstantiationException | IllegalAccessException e) {
 | 
												
													
														
															|  |              e.printStackTrace();
 |  |              e.printStackTrace();
 | 
												
													
														
															|  |          }
 |  |          }
 | 
												
													
														
															|  |          return ajaxJson;
 |  |          return ajaxJson;
 | 
												
													
														
															|  |      }
 |  |      }
 | 
												
													
														
															|  |  
 |  |  
 | 
												
													
														
															|  | -    private void dataCount(Map<String, BigDecimal> map, List<OnPassageMaterials> list, String key) {
 |  | 
 | 
												
													
														
															|  | -        list.forEach(l -> {
 |  | 
 | 
												
													
														
															|  | -            //如果有相同就不加去重
 |  | 
 | 
												
													
														
															|  | -            if (map.containsKey(key)) {
 |  | 
 | 
												
													
														
															|  | -				BigDecimal temp = new BigDecimal(String.valueOf(map.get(key)));
 |  | 
 | 
												
													
														
															|  | -				temp = new BigDecimal(l.getContractCount()).add(temp);
 |  | 
 | 
												
													
														
															|  | -				map.put(key, temp);
 |  | 
 | 
												
													
														
															|  | -
 |  | 
 | 
												
													
														
															|  | -            } else {
 |  | 
 | 
												
													
														
															|  | -                map.put(key, new BigDecimal(l.getContractCount()));
 |  | 
 | 
												
													
														
															|  | -            }
 |  | 
 | 
												
													
														
															|  | -        });
 |  | 
 | 
												
													
														
															|  | -    }
 |  | 
 | 
												
													
														
															|  |  
 |  |  
 | 
												
													
														
															|  |  }
 |  |  }
 |