|
@@ -1,46 +1,41 @@
|
|
|
package com.rtrh.projects.web.controller.subject;
|
|
|
|
|
|
import java.io.IOException;
|
|
|
+import java.io.InputStream;
|
|
|
import java.io.OutputStream;
|
|
|
import java.math.BigDecimal;
|
|
|
import java.math.RoundingMode;
|
|
|
import java.net.URLEncoder;
|
|
|
import java.text.SimpleDateFormat;
|
|
|
-import java.time.format.DateTimeFormatter;
|
|
|
import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
-import javax.annotation.Resource;
|
|
|
import javax.servlet.ServletOutputStream;
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
|
|
|
import cn.afterturn.easypoi.excel.ExcelExportUtil;
|
|
|
-import cn.afterturn.easypoi.handler.inter.IExcelExportServer;
|
|
|
-import cn.hutool.core.bean.BeanUtil;
|
|
|
+import cn.afterturn.easypoi.word.WordExportUtil;
|
|
|
+import cn.afterturn.easypoi.word.entity.MyXWPFDocument;
|
|
|
import cn.hutool.core.collection.CollUtil;
|
|
|
+import cn.hutool.core.date.DateUtil;
|
|
|
import cn.hutool.core.io.IoUtil;
|
|
|
-import cn.hutool.poi.excel.ExcelReader;
|
|
|
import cn.hutool.poi.excel.ExcelUtil;
|
|
|
-import cn.hutool.poi.excel.StyleSet;
|
|
|
import com.alibaba.excel.EasyExcel;
|
|
|
import com.alibaba.excel.EasyExcelFactory;
|
|
|
import com.alibaba.excel.ExcelWriter;
|
|
|
import com.alibaba.excel.write.metadata.WriteSheet;
|
|
|
-import com.alibaba.excel.write.metadata.style.WriteCellStyle;
|
|
|
-import com.alibaba.excel.write.metadata.style.WriteFont;
|
|
|
-import com.alibaba.excel.write.style.HorizontalCellStyleStrategy;
|
|
|
import com.alibaba.excel.write.style.column.LongestMatchColumnWidthStyleStrategy;
|
|
|
import com.google.common.collect.Lists;
|
|
|
import com.rtrh.common.util.StringUtil;
|
|
|
-import com.rtrh.core.vo.ListMessage;
|
|
|
-import com.rtrh.core.vo.Message;
|
|
|
import com.rtrh.projects.modules.projects.dao.SubSourceDao;
|
|
|
import com.rtrh.projects.modules.projects.enums.ProjectStatusEnum;
|
|
|
import com.rtrh.projects.modules.projects.enums.SubInfoStatusEnum;
|
|
|
+import com.rtrh.projects.modules.projects.po.LogOperate;
|
|
|
import com.rtrh.projects.modules.projects.po.SubIndu;
|
|
|
import com.rtrh.projects.modules.projects.po.SubInfoGxj;
|
|
|
+import com.rtrh.projects.modules.projects.service.ILogOperateService;
|
|
|
+import com.rtrh.projects.modules.projects.vo.StatusChangeCountersVO;
|
|
|
import com.rtrh.projects.modules.projects.vo.SubInfoTotalExcel;
|
|
|
-import com.rtrh.projects.modules.projects.vo.XmzhtjDetailVo;
|
|
|
import com.rtrh.projects.modules.projects.vo.export.*;
|
|
|
import com.rtrh.projects.modules.system.service.ISubInduService;
|
|
|
import com.rtrh.projects.modules.utils.CustomCellWriteWidthStrategy;
|
|
@@ -55,18 +50,18 @@ import com.rtrh.projects.web.util.ExcelStyleUtil;
|
|
|
import com.rtrh.projects.web.util.SheetData;
|
|
|
import com.rtrh.projects.web.util.SheetHead;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
-import org.apache.poi.ss.formula.functions.T;
|
|
|
import org.apache.poi.ss.usermodel.*;
|
|
|
import org.apache.poi.ss.util.CellRangeAddress;
|
|
|
import org.apache.poi.xssf.streaming.SXSSFSheet;
|
|
|
import org.apache.poi.xssf.streaming.SXSSFWorkbook;
|
|
|
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
|
|
+import org.apache.poi.xwpf.usermodel.XWPFDocument;
|
|
|
+import org.apache.poi.xwpf.usermodel.XWPFParagraph;
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Controller;
|
|
|
import org.springframework.ui.ModelMap;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
-import org.springframework.web.multipart.MultipartFile;
|
|
|
import org.springframework.web.servlet.ModelAndView;
|
|
|
|
|
|
import com.rtrh.common.util.CollectionUtil;
|
|
@@ -110,6 +105,8 @@ public class SubInfoExportController extends BaseController {
|
|
|
private ISubInduService subInduService;
|
|
|
@Autowired
|
|
|
private HttpServletResponse response;
|
|
|
+ @Autowired
|
|
|
+ private ILogOperateService logOperateService;
|
|
|
/**
|
|
|
* 导出汇总表
|
|
|
*
|
|
@@ -983,6 +980,217 @@ public class SubInfoExportController extends BaseController {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * “四个一批”工业项目情况分析报告
|
|
|
+ */
|
|
|
+ @PostMapping("/xmzkAnalysisExport")
|
|
|
+ public void xmzkAnalysisExport(@RequestBody SubInfoQueryTzVO vo) throws Exception {
|
|
|
+ InputStream inStream = this.getClass().getResourceAsStream("/template/analysis.docx");
|
|
|
+ XWPFDocument word = new MyXWPFDocument(inStream);
|
|
|
+ Map<String, Object> data = new HashMap<>();
|
|
|
+ List<SubInfoTotalExcel> list = subInfoService.exportTotalExcelByStatus(vo);
|
|
|
+ List<TSystable> jsddDict = tSysTableService.getByKind(SysTableKind.JSDD);
|
|
|
+ Map<String, String> jsddMap = jsddDict.stream().collect(Collectors.toMap(TSystable::getCode, TSystable::getTitle));
|
|
|
+ Map<String, String> hyflMap = subInduService.queryParentAll().stream().collect(Collectors.toMap(SubIndu::getCode, SubIndu::getTitle));
|
|
|
+
|
|
|
+ // 处理数据
|
|
|
+ if (CollectionUtil.isNotEmpty(list)) {
|
|
|
+ int year = DateUtil.year(new Date());
|
|
|
+ int month = DateUtil.month(DateUtil.date()) + 1;
|
|
|
+ int lastMonth = DateUtil.month(DateUtil.offsetMonth(DateUtil.date(), -1)) + 1;
|
|
|
+ data.put("year", year);
|
|
|
+ data.put("month", month);
|
|
|
+ data.put("lastMonth", lastMonth);
|
|
|
+ data.put("gyxmNum", list.size());
|
|
|
+
|
|
|
+ // 按4库状态划分
|
|
|
+ StringBuilder statusStrBuilder = new StringBuilder();
|
|
|
+ Map<String, List<SubInfoTotalExcel>> statusGroupList = list.stream().collect(Collectors.groupingBy(SubInfoTotalExcel::getStatus));
|
|
|
+ statusGroupList.forEach((key, value) -> {
|
|
|
+ SubInfoStatusEnum anEnum = SubInfoStatusEnum.getEnum(key);
|
|
|
+ String statusRate = new BigDecimal(value.size()).multiply(new BigDecimal(100)).divide(new BigDecimal(list.size()), 2, RoundingMode.HALF_UP) + "%";
|
|
|
+ BigDecimal totalAmt = value.stream().map(SubInfoTotalExcel::getAmtTotal).reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
+ String format = String.format("%s项目%s个,占工业项目总数的%s,计划总投资%s亿元;", anEnum.getDesc(), value.size(), statusRate, totalAmt);
|
|
|
+ statusStrBuilder.append(format);
|
|
|
+ });
|
|
|
+ String statusStr = statusStrBuilder.toString().replaceAll(";(?!.*;)", "。");
|
|
|
+ data.put("statusStr", statusStr);
|
|
|
+
|
|
|
+ // 按属地划分
|
|
|
+ StringBuilder subjectStrBuilder = new StringBuilder();
|
|
|
+ Map<String, List<SubInfoTotalExcel>> subjectGroupList = list.stream().collect(Collectors.groupingBy(SubInfoTotalExcel::getSubjectId));
|
|
|
+ subjectGroupList.forEach((key, value) -> {
|
|
|
+ String rate = new BigDecimal(value.size()).multiply(new BigDecimal(100)).divide(new BigDecimal(list.size()), 2, RoundingMode.HALF_UP) + "%";
|
|
|
+ BigDecimal totalAmt = value.stream().map(SubInfoTotalExcel::getAmtTotal).reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
+ String format = String.format("%s%s个,占工业项目总数的%s,计划总投资%s亿元;", jsddMap.get(key), value.size(), rate, totalAmt);
|
|
|
+ subjectStrBuilder.append(format);
|
|
|
+ });
|
|
|
+ String subjectStr = subjectStrBuilder.toString().replaceAll(";(?!.*;)", "。");
|
|
|
+ data.put("subjectStr", subjectStr);
|
|
|
+
|
|
|
+ // 按规模划分
|
|
|
+ StringBuilder scaleStrBuilder = new StringBuilder();
|
|
|
+ Map<String, BigDecimal> groupBoundaries = new LinkedHashMap<>();
|
|
|
+ groupBoundaries.put("10亿元以下", new BigDecimal("100000"));
|
|
|
+ groupBoundaries.put("10-50亿元", new BigDecimal("500000"));
|
|
|
+ groupBoundaries.put("50-100亿元", new BigDecimal("1000000"));
|
|
|
+ Map<String, List<SubInfoTotalExcel>> scaleGroupList = list.stream().collect(Collectors.groupingBy(transaction -> {
|
|
|
+ for (Map.Entry<String, BigDecimal> entry : groupBoundaries.entrySet()) {
|
|
|
+ if (transaction.getAmtTotal().compareTo(entry.getValue()) < 0) {
|
|
|
+ return entry.getKey();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return "100亿元以上";
|
|
|
+ }));
|
|
|
+ scaleGroupList.forEach((key, value) -> {
|
|
|
+ String rate = new BigDecimal(value.size()).multiply(new BigDecimal(100)).divide(new BigDecimal(list.size()), 2, RoundingMode.HALF_UP) + "%";
|
|
|
+ BigDecimal totalAmt = value.stream().map(SubInfoTotalExcel::getAmtTotal).reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
+ String format = String.format("计划总投资%s项目%s个,占工业项目总数的%s,计划总投资%s亿元;", key, value.size(), rate, totalAmt);
|
|
|
+ scaleStrBuilder.append(format);
|
|
|
+ });
|
|
|
+ String scaleStr = scaleStrBuilder.toString().replaceAll(";(?!.*;)", "。");
|
|
|
+ data.put("scaleStr", scaleStr);
|
|
|
+
|
|
|
+ // 3.按行业分
|
|
|
+ StringBuilder hyStrBuilder = new StringBuilder();
|
|
|
+ Map<String, List<SubInfoTotalExcel>> hyGroupList = list.stream()
|
|
|
+ .collect(Collectors.groupingBy(transaction -> {
|
|
|
+ String code = transaction.getInduskind();
|
|
|
+ // 确保code不为空且长度至少为2
|
|
|
+ if (code == null || code.length() < 2) {
|
|
|
+ return "未知行业"; // 默认未知行业
|
|
|
+ }
|
|
|
+ return code.substring(0, 2);
|
|
|
+ }));
|
|
|
+ hyGroupList.forEach((key, value) -> {
|
|
|
+ String rate = new BigDecimal(value.size()).multiply(new BigDecimal(100)).divide(new BigDecimal(list.size()), 2, RoundingMode.HALF_UP) + "%";
|
|
|
+ BigDecimal totalAmt = value.stream().map(SubInfoTotalExcel::getAmtTotal).reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
+ String format = String.format("%s项目%s个,占工业项目总数的%s,计划总投资%s亿元;", hyflMap.getOrDefault(key, key), value.size(), rate, totalAmt);
|
|
|
+ hyStrBuilder.append(format);
|
|
|
+ });
|
|
|
+ String hyStr = hyStrBuilder.toString().replaceAll(";(?!.*;)", "。");
|
|
|
+ data.put("hyStr", hyStr);
|
|
|
+
|
|
|
+ // 一、项目转化情况
|
|
|
+ List<LogOperate> logList = logOperateService.queryByYear(year);
|
|
|
+ StatusChangeCountersVO totalCounterVo = new StatusChangeCountersVO();
|
|
|
+ addNum(logList, totalCounterVo);
|
|
|
+ data.put("cbToXjNum", totalCounterVo.cbToXjNum);
|
|
|
+ data.put("xjToZjNum", totalCounterVo.xjToZjNum);
|
|
|
+ data.put("zjToTcNum", totalCounterVo.zjToTcNum);
|
|
|
+ data.put("tcToRgNum", totalCounterVo.tcToRgNum);
|
|
|
+ data.put("xjToCbNum", totalCounterVo.xjToCbNum);
|
|
|
+ data.put("rgToZjNum", totalCounterVo.rgToZjNum);
|
|
|
+
|
|
|
+ List<LogOperate> lastLogList = logList.stream().filter(logOperate -> DateUtil.month(logOperate.getCreateTime()) < DateUtil.month(new Date())).collect(Collectors.toList());
|
|
|
+ StatusChangeCountersVO lastCounterVo = new StatusChangeCountersVO();
|
|
|
+ addNum(lastLogList, lastCounterVo);
|
|
|
+ data.put("lastCbToXjNum", lastCounterVo.cbToXjNum);
|
|
|
+ data.put("lastXjToZjNum", lastCounterVo.xjToZjNum);
|
|
|
+ data.put("lastZjToTcNum", lastCounterVo.zjToTcNum);
|
|
|
+ data.put("lastTcToRgNum", lastCounterVo.tcToRgNum);
|
|
|
+ data.put("lastXjToCbNum", lastCounterVo.xjToCbNum);
|
|
|
+ data.put("lastRgToZjNum", lastCounterVo.rgToZjNum);
|
|
|
+
|
|
|
+ // 分属地看
|
|
|
+ String text = "%s年1-%s月,%s储备项目转新建%s个、新建项目转在建%s个、在建项目转投产%s个、投产项目转入规%s个,新建项目降级为储备%s个、入规项目转为在建%s个。" +
|
|
|
+ "其中,%s月当月,储备项目转新建%s个、新建项目转在建%s个、在建项目转投产%s个、投产项目转入规%s个,新建项目降级为储备%s个、入规项目转为在建%s个。" +
|
|
|
+ "1-%s月,项目开工率%s、投产率%s、入规率%s,较1-(%s)月,分别增长%s、%s、%s个百分点。";
|
|
|
+ String subjectZhStr = String.format(text,
|
|
|
+ year, month, "subjectName", totalCounterVo.cbToXjNum, totalCounterVo.xjToZjNum, totalCounterVo.zjToTcNum, totalCounterVo.tcToRgNum, totalCounterVo.xjToCbNum, totalCounterVo.rgToZjNum,
|
|
|
+ month, totalCounterVo.cbToXjNum, totalCounterVo.xjToZjNum, totalCounterVo.zjToTcNum, totalCounterVo.tcToRgNum, totalCounterVo.xjToCbNum, totalCounterVo.rgToZjNum,
|
|
|
+ month, "kgl", "tcl", "rgl", lastMonth, "1", "2", "3"
|
|
|
+ );
|
|
|
+ data.put("subjectZhStr", subjectZhStr);
|
|
|
+ // 分规模看
|
|
|
+ String scaleZhStr = String.format(text,
|
|
|
+ year, month, "计划总投资100亿元以上", totalCounterVo.cbToXjNum, totalCounterVo.xjToZjNum, totalCounterVo.zjToTcNum, totalCounterVo.tcToRgNum, totalCounterVo.xjToCbNum, totalCounterVo.rgToZjNum,
|
|
|
+ month, totalCounterVo.cbToXjNum, totalCounterVo.xjToZjNum, totalCounterVo.zjToTcNum, totalCounterVo.tcToRgNum, totalCounterVo.xjToCbNum, totalCounterVo.rgToZjNum,
|
|
|
+ month, "kgl", "tcl", "rgl", lastMonth, "1", "2", "3"
|
|
|
+ );
|
|
|
+ data.put("scaleZhStr", scaleZhStr);
|
|
|
+ // 分行业看
|
|
|
+ String hyZhStr = String.format(text,
|
|
|
+ year, month, "制造业", totalCounterVo.cbToXjNum, totalCounterVo.xjToZjNum, totalCounterVo.zjToTcNum, totalCounterVo.tcToRgNum, totalCounterVo.xjToCbNum, totalCounterVo.rgToZjNum,
|
|
|
+ month, totalCounterVo.cbToXjNum, totalCounterVo.xjToZjNum, totalCounterVo.zjToTcNum, totalCounterVo.tcToRgNum, totalCounterVo.xjToCbNum, totalCounterVo.rgToZjNum,
|
|
|
+ month, "kgl", "tcl", "rgl", lastMonth, "1", "2", "3"
|
|
|
+ );
|
|
|
+ data.put("hyZhStr", hyZhStr);
|
|
|
+ // 二、存在问题
|
|
|
+ // (一)项目落地方面
|
|
|
+ data.put("xmldSubNameStr", "a项目、b项目、c项目");
|
|
|
+ data.put("xmldNum", 3);
|
|
|
+ data.put("xmldMonthNum", 3);
|
|
|
+ // (二)前期手续方面
|
|
|
+ data.put("qqsxNum", 3);
|
|
|
+ data.put("qqsxHpNames", "a项目、b项目、c项目");
|
|
|
+ data.put("qqsxHpNum", 3);
|
|
|
+ data.put("qqsxNpNames", "a项目、b项目、c项目");
|
|
|
+ data.put("qqsxNpNum", 3);
|
|
|
+ data.put("qqsxYdNames", "a项目、b项目、c项目");
|
|
|
+ data.put("qqsxYdNum", 3);
|
|
|
+ // (三)工程建设方面
|
|
|
+ data.put("gcjsNum", 3);
|
|
|
+ data.put("gcjsZjzhNames", "a项目、b项目、c项目");
|
|
|
+ data.put("gcjsZjzhNum", 3);
|
|
|
+ data.put("gcjsAqsgNames", "a项目、b项目、c项目");
|
|
|
+ // (四)升规入统方面
|
|
|
+ data.put("sgrtNum", 3);
|
|
|
+ data.put("sgrtCqNames", "a项目、b项目、c项目");
|
|
|
+ data.put("sgrtCqNum", 3);
|
|
|
+ data.put("sgrtZlzhNames", "a项目、b项目、c项目");
|
|
|
+ data.put("sgrtZlzhNum", 3);
|
|
|
+
|
|
|
+ // Map<String, List<LogOperate>> collect = logList.stream().collect(Collectors.groupingBy(LogOperate::getTitle));
|
|
|
+ // String currentYearZhStr = buildZhData(collect);
|
|
|
+ // data.put("currentYearZhStr", currentYearZhStr);
|
|
|
+ // Map<String, List<LogOperate>> collect1 = logList.stream().filter(item -> DateUtil.month(item.getZhDate()) == DateUtil.month(new Date())).collect(Collectors.groupingBy(LogOperate::getTitle));
|
|
|
+ // String currentMonthZhStr = buildZhData(collect1);
|
|
|
+ // data.put("currentMonthZhStr", currentMonthZhStr);
|
|
|
+ // 开工率 = (在建+投产)/(在建+投产+新建)
|
|
|
+ // 投产率 = (投产)/(在建+投产+新建)
|
|
|
+ // 入规率 = 入规/(在建+投产+新建)
|
|
|
+ }
|
|
|
+
|
|
|
+ WordExportUtil.exportWord07(word, data);
|
|
|
+ response.setHeader("content-disposition","attachment;filename="+new String("analysis".getBytes(),"ISO8859-1"));
|
|
|
+ response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
|
|
|
+ word.write(response.getOutputStream());
|
|
|
+ }
|
|
|
+
|
|
|
+ private void addNum(List<LogOperate> lastLogList, StatusChangeCountersVO vo) {
|
|
|
+ for (LogOperate logOperate : lastLogList) {
|
|
|
+ if (SubInfoStatusEnum.CB.getCode().equals(logOperate.getStatusFirst()) && SubInfoStatusEnum.XJ.getCode().equals(logOperate.getStatusAfter())) {
|
|
|
+ ++vo.cbToXjNum;
|
|
|
+ }
|
|
|
+ if (SubInfoStatusEnum.XJ.getCode().equals(logOperate.getStatusFirst()) && SubInfoStatusEnum.ZJ.getCode().equals(logOperate.getStatusAfter())) {
|
|
|
+ ++vo.xjToZjNum;
|
|
|
+ }
|
|
|
+ if (SubInfoStatusEnum.ZJ.getCode().equals(logOperate.getStatusFirst()) && SubInfoStatusEnum.TC.getCode().equals(logOperate.getStatusAfter())) {
|
|
|
+ ++vo.zjToTcNum;
|
|
|
+ }
|
|
|
+ // if (SubInfoStatusEnum.TC.getCode().equals(logOperate.getStatusFirst()) && SubInfoStatusEnum.RG.getCode().equals(logOperate.getStatusAfter())) {
|
|
|
+ // ++vo.tcToRgNum;
|
|
|
+ // }
|
|
|
+ if (SubInfoStatusEnum.XJ.getCode().equals(logOperate.getStatusFirst()) && SubInfoStatusEnum.CB.getCode().equals(logOperate.getStatusAfter())) {
|
|
|
+ ++vo.xjToCbNum;
|
|
|
+ }
|
|
|
+ // if (SubInfoStatusEnum.RG.getCode().equals(logOperate.getStatusFirst()) && SubInfoStatusEnum.ZJ.getCode().equals(logOperate.getStatusAfter())) {
|
|
|
+ // ++vo.rgToZjNum;
|
|
|
+ // }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ private String buildZhData(Map<String, List<LogOperate>> collect) {
|
|
|
+ StringBuilder zhStrBuilder = new StringBuilder();
|
|
|
+ collect.forEach((key, value) -> {
|
|
|
+ zhStrBuilder.append(key).append(value.size()).append("个、");
|
|
|
+ });
|
|
|
+ return zhStrBuilder.toString().replaceAll("、$", "。");
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
/**
|
|
|
* 导出重点项目储备明细表
|
|
|
*
|