chenyuesheng 3 سال پیش
والد
کامیت
a441d6679f

تفاوت فایلی نمایش داده نمی شود زیرا این فایل بسیار بزرگ است
+ 974 - 6
src/main/java/com/jeeplus/modules/sg/balancedlibrary/onPassageMaterials/entity/OnPassageMaterials.java


+ 139 - 5
src/main/java/com/jeeplus/modules/sg/balancedlibrary/onPassageMaterials/web/OnPassageMaterialsController.java

@@ -4,17 +4,31 @@
 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.utils.DateUtils;
+import com.jeeplus.common.utils.excel.ExportExcel;
+import com.jeeplus.common.utils.excel.ImportExcel;
+import com.jeeplus.modules.sg.balancedlibrary.onPassageMaterials.entity.MaterialInformation;
 import com.jeeplus.modules.sg.balancedlibrary.onPassageMaterials.entity.OnPassageMaterials;
 import com.jeeplus.modules.sg.balancedlibrary.onPassageMaterials.service.OnPassageMaterialsService;
 import com.jeeplus.common.utils.StringUtils;
 import com.jeeplus.core.web.BaseController;
+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.service.ReportPersonService;
 import org.apache.shiro.authz.annotation.RequiresPermissions;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Controller;
 import org.springframework.ui.Model;
-import org.springframework.web.bind.annotation.ModelAttribute;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RequestParam;
+import org.springframework.web.bind.annotation.*;
+import org.springframework.web.multipart.MultipartFile;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
+import java.math.BigDecimal;
+import java.util.*;
 
 /**
  * 在途物资Controller
@@ -27,6 +41,8 @@ public class OnPassageMaterialsController extends BaseController {
 
 	@Autowired
 	private OnPassageMaterialsService service;
+	@Autowired
+	private ReportPersonService reportPersonService;
 	
 	@ModelAttribute
 	public OnPassageMaterials get(@RequestParam(required=false) String id) {
@@ -47,8 +63,126 @@ public class OnPassageMaterialsController extends BaseController {
 	@RequestMapping(value = "list")
 	public String list(OnPassageMaterials entity, Model model) {
 		model.addAttribute("entity", entity);
-		return "";
+		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)));
+					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)));
+				temp = new BigDecimal(l.getContractCount()).add(temp);
+				map.put(key, temp);
+
+			} else {
+				map.put(key, new BigDecimal(l.getContractCount()));
+			}
+		});
 	}
-	
 
 }

+ 0 - 0
src/main/webapp/webpage/modules/sg/balancedlibrary/onPassageMaterials/onPassageMaterialsList.js


+ 68 - 0
src/main/webapp/webpage/modules/sg/balancedlibrary/onPassageMaterials/onPassageMaterialsList.jsp

@@ -0,0 +1,68 @@
+<%@ page contentType="text/html;charset=UTF-8" %>
+<%@ include file="/webpage/include/taglib.jsp" %>
+<html>
+<head>
+    <title>在途物资统计</title>
+    <meta http-equiv="Content-type" content="text/html; charset=utf-8">
+    <meta name="decorator" content="ani"/>
+    <%@ include file="/webpage/include/bootstraptable.jsp"%>
+    <%@include file="/webpage/include/treeview.jsp" %>
+    <script type="text/javascript">
+
+
+        function fileUpload(){
+
+            var onPassageMaterialsFile = $('#onPassageMaterials').get(0).files[0];
+            var materialInformationFile = $('#materialInformation').get(0).files[0];
+            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 () {
+                }
+            });
+        }
+    </script>
+</head>
+<body>
+<div class="wrapper wrapper-content">
+    <div class="panel panel-primary">
+        <div class="panel-heading">
+            <h3 class="panel-title">在途物资统计</h3>
+        </div>
+        <div class="panel-body">
+        </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>
+            <div class="file-upload">
+                <input type="button" value="提交" id="submit" onclick="fileUpload()">
+            </div>
+        </form:form>
+    </div>
+</div>
+</body>
+</html>