|
@@ -1,14 +1,135 @@
|
|
|
package com.jeeplus.modules.sg.balancedlibrary.planSummary.service;
|
|
|
|
|
|
+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.core.service.CrudService;
|
|
|
import com.jeeplus.modules.sg.balancedlibrary.planSummary.entity.AgriculturalDistributionNetwork;
|
|
|
+import com.jeeplus.modules.sg.balancedlibrary.planSummary.entity.ProcessTracking;
|
|
|
import com.jeeplus.modules.sg.balancedlibrary.planSummary.mapper.PlanSummaryMapper;
|
|
|
|
|
|
+import com.jeeplus.modules.sg.balancedlibrary.planSummary.vo.PlanSummary;
|
|
|
+import com.jeeplus.modules.sg.balancedlibrary.reportPerson.entity.ReportPerson;
|
|
|
+import com.jeeplus.modules.sg.balancedlibrary.reportPerson.service.ReportPersonService;
|
|
|
+import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
+import org.springframework.web.bind.annotation.RequestParam;
|
|
|
+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.ArrayList;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
|
|
|
@Service
|
|
|
@Transactional(readOnly = true)
|
|
|
public class PlanSummaryService extends CrudService<PlanSummaryMapper, AgriculturalDistributionNetwork> {
|
|
|
+ @Autowired
|
|
|
+ private ReportPersonService reportPersonService;
|
|
|
+ /**
|
|
|
+ * 导入Excel数据
|
|
|
+ */
|
|
|
+ public AjaxJson importFile(@RequestParam("file") MultipartFile[] file, HttpServletRequest request, HttpServletResponse response) {
|
|
|
+ AjaxJson ajaxJson = new AjaxJson();
|
|
|
+ //保存提报人和物料编码
|
|
|
+ Map<String, BigDecimal> PNWMap = new HashMap<>();
|
|
|
+ //去重统计配农网物料编码 提报人
|
|
|
+ List<String> PNWSameList = new ArrayList<>();
|
|
|
+ Map<String, BigDecimal> GZMap = new HashMap<>();
|
|
|
+ //跟踪去重
|
|
|
+ List<String> GZSameList = new ArrayList<>();
|
|
|
+ List<PlanSummary> planSummaryList = new ArrayList<>();
|
|
|
+
|
|
|
+ try {
|
|
|
+ ImportExcel ei = new ImportExcel(file[1], 1, 0);
|
|
|
+ ImportExcel ie = new ImportExcel(file[0], 1, 0);
|
|
|
+ //将excel表转换成集合
|
|
|
+ List<AgriculturalDistributionNetwork> PNWList = ei.getDataList(AgriculturalDistributionNetwork.class);
|
|
|
+ List<ProcessTracking> GZList = ie.getDataList(ProcessTracking.class);
|
|
|
+
|
|
|
+ // 去重统计各个部门需求数量
|
|
|
+ PNWList.forEach(l -> {
|
|
|
+ String person = l.getRequiredMaterialCode() + "-" + l.getPlanSubmitter();
|
|
|
+ if (!PNWSameList.contains(person)) {
|
|
|
+ PNWSameList.add(person);
|
|
|
+ //创建提交人对象l
|
|
|
+ ReportPerson reportPerson = new ReportPerson();
|
|
|
+ reportPerson.setReportPerson(l.getPlanSubmitter());
|
|
|
+
|
|
|
+ //根据名称查询
|
|
|
+ List<ReportPerson> getPlanSubmitterList = reportPersonService.findList(reportPerson);
|
|
|
+ //如果不为空,出现重名情况默认取第一个
|
|
|
+ String key = "";
|
|
|
+ if(getPlanSubmitterList!=null && getPlanSubmitterList.size()!=0){
|
|
|
+ key = getPlanSubmitterList.get(0).getReportDepartment();
|
|
|
+ }
|
|
|
+ //根据部门增加需求数量
|
|
|
+ if(PNWMap.containsKey(key)){
|
|
|
+ BigDecimal temp = PNWMap.get(key).add(new BigDecimal(l.getDemandQuantity()));
|
|
|
+ PNWMap.put(key, temp);
|
|
|
+ }else{
|
|
|
+ PNWMap.put(key, new BigDecimal(l.getDemandQuantity()));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ });
|
|
|
+
|
|
|
+
|
|
|
+ //去重统计各个部门需求数量
|
|
|
+ GZList.forEach(l -> {
|
|
|
+ String parson = l.getMaterialCode() + "-" + l.getApplicant();
|
|
|
+ if (!GZSameList.contains(parson)) {
|
|
|
+ GZSameList.add(parson);
|
|
|
+ //创建提交人对象l
|
|
|
+ ReportPerson reportPerson = new ReportPerson();
|
|
|
+ reportPerson.setReportPerson(l.getApplicant());
|
|
|
+ //根据名称查询
|
|
|
+ List<ReportPerson> getPlanSubmitterList = reportPersonService.findList(reportPerson);
|
|
|
+ //如果不为空,出现重名情况默认取第一个
|
|
|
+ String key = "";
|
|
|
+ if(getPlanSubmitterList!=null&&getPlanSubmitterList.size()!=0){
|
|
|
+
|
|
|
+ key = getPlanSubmitterList.get(0).getReportDepartment();
|
|
|
+ }
|
|
|
+ if(GZMap.containsKey(key)){
|
|
|
+ BigDecimal temp = GZMap.get(key).add(new BigDecimal(l.getDemandQuantity()));
|
|
|
+ GZMap.put(key, temp);
|
|
|
+ }else{
|
|
|
+ GZMap.put(key, new BigDecimal(l.getDemandQuantity()));
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ });
|
|
|
+ //Q
|
|
|
+ GZMap.forEach((k,v)->{
|
|
|
+ planSummaryList.add(new PlanSummary(null,k,null,null,v.toString(),PNWMap.containsKey(k)?PNWMap.get(k).toString():null,
|
|
|
+ //需求数量是否为0 如果不为0 计算执行进度 如果为0则显示未上报
|
|
|
+ PNWMap.containsKey(k)&&PNWMap.get(k)!=null?PNWMap.get(k).compareTo(new BigDecimal(0))==0?"未上报需求":(PNWMap.get(k).divide(v,1,BigDecimal.ROUND_HALF_DOWN))+ "%":"未上报需求"
|
|
|
+ ));
|
|
|
+ });
|
|
|
+
|
|
|
+
|
|
|
+ /***********************************************/
|
|
|
+ String fileName = "执行计划汇总" + DateUtils.getDate("yyyy-MM-dd-HHmmss") + ".xlsx";
|
|
|
+ new ExportExcel("", PlanSummary.class).setDataList(planSummaryList).write(response, fileName).dispose();
|
|
|
|
|
|
+ } catch (IOException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ } catch (InstantiationException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ } catch (IllegalAccessException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ } catch (InvalidFormatException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ return ajaxJson;
|
|
|
+ }
|
|
|
}
|