Browse Source

在途物资

chenyuesheng 3 years atrás
parent
commit
b8c6e7dbe2

+ 181 - 142
src/main/java/com/jeeplus/modules/sg/balancedlibrary/onPassageMaterials/web/OnPassageMaterialsController.java

@@ -32,6 +32,7 @@ import java.util.*;
 
 
 /**
 /**
  * 在途物资Controller
  * 在途物资Controller
+ *
  * @author 徐滕
  * @author 徐滕
  * @version 1.0
  * @version 1.0
  */
  */
@@ -39,150 +40,188 @@ import java.util.*;
 @RequestMapping(value = "${adminPath}/onPassageMaterials")
 @RequestMapping(value = "${adminPath}/onPassageMaterials")
 public class OnPassageMaterialsController extends BaseController {
 public class OnPassageMaterialsController extends BaseController {
 
 
-	@Autowired
-	private OnPassageMaterialsService service;
-	@Autowired
-	private ReportPersonService reportPersonService;
-	
-	@ModelAttribute
-	public OnPassageMaterials get(@RequestParam(required=false) String id) {
-		OnPassageMaterials entity = null;
-		if (StringUtils.isNotBlank(id)){
-			entity = service.get(id);
-		}
-		if (entity == null){
-			entity = new OnPassageMaterials();
-		}
-		return entity;
-	}
-	
-	/**
-	 * 物料替换列表页面
-	 */
-	@RequiresPermissions("sg:balancedlibrary:ReplaceMaterial:list")
-	@RequestMapping(value = "list")
-	public String list(OnPassageMaterials entity, Model model) {
-		model.addAttribute("entity", entity);
-		return "modules/sg/balancedlibrary/onPassageMaterials/onPassageMaterialsList";
-	}
-
-
-
-	/**
-	 * 在途物资-导入Excel数据
-	 */
-	@ResponseBody
-	@PostMapping("import")
-	public AjaxJson importFile(@RequestParam("file") MultipartFile[] file, HttpServletResponse response, HttpServletRequest request) {
-		AjaxJson ajaxJson = new AjaxJson();
-		//物料编码 计划编制人相同
-		List<OnPassageMaterials> sameList = new ArrayList<>();
-		//计划编制人为空
-		List<OnPassageMaterials> isEmptyList = new ArrayList<>();
-		//统计物料编码 部门
-		Map<String, BigDecimal> materialCountMap = new HashMap<>();
-		//统计物料编码 计划编制人相同合同数量
-		Map<String, BigDecimal> sameMap = new HashMap<>();
-		//统计计划编制人为空合同数量
-		Map<String, BigDecimal> isEmptyMap = new HashMap<>();
-		try {
-			ImportExcel ei = new ImportExcel(file[0], 1, 0);
-			ImportExcel ie = new ImportExcel(file[1], 1, 0);
-			List<OnPassageMaterials> onPassageMaterialsList = ei.getDataList(OnPassageMaterials.class);
-			List<MaterialInformation> materialInformationList = ie.getDataList(MaterialInformation.class);
-			/**************************************************************************/
-
-			onPassageMaterialsList.forEach(opm -> {
-				String key = "";
-				if (!opm.getPlanner().isEmpty()) {
-					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 = m.getMaterialCode() + "-" + m.getReportingDepartment();
-				if (materialCountMap.containsKey(key)) {
-					BigDecimal temp = new BigDecimal(String.valueOf(materialCountMap.get(key)));
+    @Autowired
+    private OnPassageMaterialsService service;
+    @Autowired
+    private ReportPersonService reportPersonService;
+
+    @ModelAttribute
+    public OnPassageMaterials get(@RequestParam(required = false) String id) {
+        OnPassageMaterials entity = null;
+        if (StringUtils.isNotBlank(id)) {
+            entity = service.get(id);
+        }
+        if (entity == null) {
+            entity = new OnPassageMaterials();
+        }
+        return entity;
+    }
+
+    /**
+     * 物料替换列表页面
+     */
+    @RequiresPermissions("sg:balancedlibrary:ReplaceMaterial:list")
+    @RequestMapping(value = "list")
+    public String list(OnPassageMaterials entity, Model model) {
+        model.addAttribute("entity", entity);
+        return "modules/sg/balancedlibrary/onPassageMaterials/onPassageMaterialsList";
+    }
+
+
+    /**
+     * 在途物资-导入Excel数据
+     */
+    @ResponseBody
+    @PostMapping("import")
+    public AjaxJson importFile(@RequestParam("file") MultipartFile[] file, HttpServletResponse response, HttpServletRequest request) {
+        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, String> sameMap = new HashMap<>();
+        //统计计划编制人为空合同数量
+        Map<String, String> isEmptyMap = new HashMap<>();
+        //在途物资表J列
+        Map<String, BigDecimal> JMap = new HashMap<>();
+        //项目物资需求表H列
+        Map<String, BigDecimal> HMap = new HashMap<>();
+        try {
+            //获取两张excel表
+            ImportExcel ei = new ImportExcel(file[0], 1, 0);
+            ImportExcel ie = new ImportExcel(file[1], 1, 0);
+            //转换为集合
+            List<OnPassageMaterials> onPassageMaterialsList = ei.getDataList(OnPassageMaterials.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);
 					temp = new BigDecimal(m.getTotal()).add(temp);
-					materialCountMap.put(key, temp);
-
-
-				} else {
-					materialCountMap.put(key, new BigDecimal(m.getTotal()));
-				}
-			});
-
-
-
-
-			/******************两表比较*******************/
-
-			materialCountMap.forEach((k, v) -> {
-				if (sameMap.containsKey(k)) {
-					if (sameMap.get(k).compareTo(v)>0){
-						String[] split = k.split("-");
-						materialInformationList.forEach(m->{
-							if(split.length==2){
-								if(m.getMaterialCode().equals(split[0])&&m.getReportingDepartment().equals(split[1])){
-									m.setRemarkText("在途已有"+sameMap.get(k)+"单位,请核实本次需求");
-								}
-							}else{
-								if(m.getMaterialCode().equals(split[0])){
-									m.setRemarkText("在途已有"+sameMap.get(k)+"单位,请核实本次需求");
-								}
-							}
-
-						});
-					}
-				}
-			});
-
-
-			/***********************************************/
-			String fileName = "项目物资需求表" + DateUtils.getDate("yyyyMMddHHmmss") + ".xlsx";
-			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) {
-			e.printStackTrace();
-		}
-		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)));
+					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 = new BigDecimal(v).add(JMap.get(split[1]));
+                        JMap.put(split[1], temp);
+                    } else {
+                        JMap.put(split[1], new BigDecimal(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) + "单位,请核实本次需求");
+                            }
+                        });
+                    }
+                }
+            });
+
+            System.out.println(HMap);
+            System.out.println("***********************************");
+            System.out.println(JMap);
+
+            /***********************************************/
+            String fileName = "项目物资需求表" + DateUtils.getDate("yyyyMMddHHmmss") + ".xlsx";
+            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) {
+            e.printStackTrace();
+        }
+        return ajaxJson;
+    }
+
+    private void dataCount(Map<String, String> 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);
 				temp = new BigDecimal(l.getContractCount()).add(temp);
-				map.put(key, temp);
+				map.put(key, temp);*/
 
 
-			} else {
-				map.put(key, new BigDecimal(l.getContractCount()));
-			}
-		});
-	}
+            } else {
+                map.put(key, l.getContractCount());
+            }
+        });
+    }
 
 
 }
 }

+ 90 - 36
src/main/webapp/webpage/modules/sg/balancedlibrary/onPassageMaterials/onPassageMaterialsList.jsp

@@ -5,43 +5,89 @@
     <title>在途物资统计</title>
     <title>在途物资统计</title>
     <meta http-equiv="Content-type" content="text/html; charset=utf-8">
     <meta http-equiv="Content-type" content="text/html; charset=utf-8">
     <meta name="decorator" content="ani"/>
     <meta name="decorator" content="ani"/>
-    <%@ include file="/webpage/include/bootstraptable.jsp"%>
-    <%@include file="/webpage/include/treeview.jsp" %>
+    <%@ include file="/webpage/include/bootstraptable.jsp" %>
     <script type="text/javascript">
     <script type="text/javascript">
 
 
 
 
-        function fileUpload(){
+
+        function fileUpload() {
 
 
             var onPassageMaterialsFile = $('#onPassageMaterials').get(0).files[0];
             var onPassageMaterialsFile = $('#onPassageMaterials').get(0).files[0];
             var materialInformationFile = $('#materialInformation').get(0).files[0];
             var materialInformationFile = $('#materialInformation').get(0).files[0];
+            var onPassageMaterialsFileName = onPassageMaterialsFile.name.split(".");
+            var materialInformationFileName = materialInformationFile.name.split(".");
+            if(onPassageMaterialsFile==null||onPassageMaterialsFileName[0]!="附件4在途物资统计表"){
+                var file  = $('#onPassageMaterials');
+                file.after(file.clone()).val("");
+                file.remove();
+                alert("在途物资统计表为空,或文件不正确")
+                return
+            }
+            if(materialInformationFile==null||materialInformationFileName[0]!="项目物资需求表"){
+                var file  = $('#materialInformation');
+                file.after(file.clone()).val("");
+                file.remove();
+                alert("项目物资需求表,或文件不正确")
+                return
+            }
             var formData = new FormData();
             var formData = new FormData();
-            formData.append("file",onPassageMaterialsFile);
-            formData.append("file",materialInformationFile);
-            $.ajax({
-                url: "http://localhost:8080/jeeplus/a/onPassageMaterials/import",
-                type: "POST",
-                data:formData,
-                cache: false,
-                processData: false,
-                contentType: false,
-                success: function (result) {
-
-                    var eleLink = document.createElement('a');
-                    eleLink.download = materialInformationFile.name;
-                    eleLink.style.display = 'none';
-                    var blob = new Blob([result]);
-                    eleLink.href = URL.createObjectURL(blob);
-                    document.body.appendChild(eleLink);
-                    eleLink.click();
-                    document.body.removeChild(eleLink);
-
-
-                },
-                error:function () {
+            formData.append("file", onPassageMaterialsFile);
+            formData.append("file", materialInformationFile);
+
+            // 构造XMLHttpRequest对象
+            var xmlRequest = new XMLHttpRequest();
+            // 发送get请求
+            xmlRequest.open("POST", "${ctx}/onPassageMaterials/import", true);
+            // 设置响应类型
+            xmlRequest.responseType = "blob";
+            // 发送请求
+            xmlRequest.send(formData);
+
+            // 请求获得响应之后,触发下面的回调函数
+            xmlRequest.onload = function (oEvent) {
+                // 当时满足下面的状态码的时候,视为下载成功
+                if ((xmlRequest.status >= 200 && xmlRequest.status < 300) || xmlRequest.status === 304) {
+
+                    // 从xmlRequest对象中获取响应的内容
+                    var content = xmlRequest.response;
+
+
+                    var dispositionStr = xmlRequest.getResponseHeader('Content-Disposition');
+                    if (dispositionStr == null || dispositionStr === "") {
+                        alert("下载失败!");
+                        return;
+                    }
+                    // 获取文件名
+                    let dispositionArr = dispositionStr.split(";");
+                    let fileName = decodeURIComponent(dispositionArr[1]);
+                    var name = fileName.split("=");
+                    fileName = name[1];
+                    console.log(fileName);
+                    var blob = new Blob([content]);
+                    var elink = document.createElement('a');
+                    elink.download = fileName;
+                    elink.style.display = 'none';
+                    const src = URL.createObjectURL(blob);
+                    elink.href = src;
+                    document.body.appendChild(elink);
+                    elink.click();
+                    document.body.removeChild(elink);
+                    URL.revokeObjectURL(src);
+
                 }
                 }
-            });
+            }
+
+
         }
         }
     </script>
     </script>
+    <style>
+        .div-btn {
+            margin: 0 10px 20px 10px;
+        }
+        .file-upload{
+            margin: 10px 0 0 0 ;
+        }
+    </style>
 </head>
 </head>
 <body>
 <body>
 <div class="wrapper wrapper-content">
 <div class="wrapper wrapper-content">
@@ -51,17 +97,25 @@
         </div>
         </div>
         <div class="panel-body">
         <div class="panel-body">
         </div>
         </div>
-        <form:form id="inputForm"  method="post" action="${ctx}/onPassageMaterials/import" enctype="multipart/form-data" class="form-horizontal layui-form">
-            <div class="file-upload">
-                <input type="file" name="onPassageMaterials" id="onPassageMaterials">
-            </div>
-            <div class="file-upload">
-                <input type="file" name="materialInformation" id="materialInformation">
-            </div>
+        <input type="file" name="onPassageMaterials" id="onPassageMaterials" style="display: none;">
+        <input type="file" name="materialInformation" id="materialInformation" style="display: none;">
+        <div class="div-btn">
+            <button class="btn btn-info" onclick="onPassageMaterials.click()">
+                <i class="fa fa-folder-open-o"></i> 导入在途物资统计表
+            </button>
+
+            <button class="btn btn-info" onclick="materialInformation.click()">
+                <i class="fa fa-folder-open-o"></i> 导入项目物资需求表
+            </button>
+
             <div class="file-upload">
             <div class="file-upload">
-                <input type="button" value="提交" id="submit" onclick="fileUpload()">
+                <button class="btn btn-primary btn-block btn-lg btn-parsley" onclick="fileUpload()">提交</button>
             </div>
             </div>
-        </form:form>
+
+        </div>
+
+
+
     </div>
     </div>
 </div>
 </div>
 </body>
 </body>