|
@@ -1,7 +1,9 @@
|
|
|
package com.rtrh.projects.web.controller.subject;
|
|
|
|
|
|
import java.io.IOException;
|
|
|
+import java.io.OutputStream;
|
|
|
import java.math.BigDecimal;
|
|
|
+import java.math.RoundingMode;
|
|
|
import java.net.URLEncoder;
|
|
|
import java.text.SimpleDateFormat;
|
|
|
import java.util.*;
|
|
@@ -11,6 +13,7 @@ import javax.servlet.ServletOutputStream;
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
|
|
|
import cn.afterturn.easypoi.excel.ExcelExportUtil;
|
|
|
+import cn.hutool.core.bean.BeanUtil;
|
|
|
import cn.hutool.core.collection.CollUtil;
|
|
|
import cn.hutool.core.io.IoUtil;
|
|
|
import cn.hutool.poi.excel.ExcelUtil;
|
|
@@ -27,8 +30,12 @@ import com.rtrh.common.util.StringUtil;
|
|
|
import com.rtrh.core.vo.ListMessage;
|
|
|
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.SubIndu;
|
|
|
+import com.rtrh.projects.modules.projects.po.SubInfoGxj;
|
|
|
import com.rtrh.projects.modules.projects.vo.SubInfoTotalExcel;
|
|
|
import com.rtrh.projects.modules.projects.vo.export.*;
|
|
|
+import com.rtrh.projects.modules.system.service.ISubInduService;
|
|
|
import com.rtrh.projects.modules.utils.CustomCellWriteWidthStrategy;
|
|
|
import com.rtrh.projects.modules.utils.DateUtils;
|
|
|
import com.rtrh.projects.modules.utils.QualificationsDeclareCellWriteHandler;
|
|
@@ -36,6 +43,7 @@ import com.rtrh.projects.outapi.result.JsonResult;
|
|
|
import com.rtrh.projects.web.util.SheetData;
|
|
|
import com.rtrh.projects.web.util.SheetHead;
|
|
|
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;
|
|
@@ -86,6 +94,8 @@ public class SubInfoExportController extends BaseController {
|
|
|
private TSysTableService tSysTableService;
|
|
|
@Autowired
|
|
|
private SubSourceDao subSourceDao;
|
|
|
+ @Autowired
|
|
|
+ private ISubInduService subInduService;
|
|
|
|
|
|
|
|
|
* 导出汇总表
|
|
@@ -617,7 +627,8 @@ public class SubInfoExportController extends BaseController {
|
|
|
}
|
|
|
|
|
|
|
|
|
- * 导出重点项目汇总表
|
|
|
+ * 导出总表
|
|
|
+ *
|
|
|
* @param response
|
|
|
* @param vo
|
|
|
*/
|
|
@@ -633,13 +644,13 @@ public class SubInfoExportController extends BaseController {
|
|
|
List<TSystable> gxjHyfl = tSysTableService.getGxjHyfl(SysTableKind.HYFL);
|
|
|
|
|
|
for (SubInfoTotalExcel data : subInfoTotalExcel) {
|
|
|
- if (data == null){
|
|
|
+ if (data == null) {
|
|
|
continue;
|
|
|
}
|
|
|
String subjectId = data.getSubjectId();
|
|
|
String induskind = data.getInduskind();
|
|
|
if (StringUtil.isNotEmpty(induskind)) {
|
|
|
- Optional<TSystable> first = gxjHyfl.stream().filter(item -> item.getCode().equals(induskind)).findFirst();
|
|
|
+ Optional<TSystable> first = gxjHyfl.stream().filter(item -> item.getId().equals(induskind)).findFirst();
|
|
|
first.ifPresent(tSystable -> data.setInduskind(tSystable.getTitle()));
|
|
|
}
|
|
|
if (StringUtil.isNotEmpty(subjectId)) {
|
|
@@ -658,7 +669,7 @@ public class SubInfoExportController extends BaseController {
|
|
|
|
|
|
writer.merge(0, 0, 0, 3, null, true);
|
|
|
|
|
|
- List<String> rowHead2 = CollUtil.newArrayList("项目分类","项目分类","项目个数","计划总投资(亿元)");
|
|
|
+ List<String> rowHead2 = CollUtil.newArrayList("项目分类", "项目分类", "项目个数", "计划总投资(亿元)");
|
|
|
writer.writeHeadRow(rowHead2);
|
|
|
writer.merge(1, 1, 0, 1, null, true);
|
|
|
|
|
@@ -738,9 +749,9 @@ public class SubInfoExportController extends BaseController {
|
|
|
for (Map.Entry<String, List<List<String>>> dataListEntry : finalDataMap.entrySet()) {
|
|
|
List<List<String>> dataList = dataListEntry.getValue();
|
|
|
int dataSize = dataList.size();
|
|
|
- if (dataSize == 1){
|
|
|
+ if (dataSize == 1) {
|
|
|
indexStart += dataSize;
|
|
|
- }else{
|
|
|
+ } else {
|
|
|
writer.merge(indexStart, indexStart + dataSize - 1, 0, 0, null, true);
|
|
|
indexStart += dataSize;
|
|
|
}
|
|
@@ -762,7 +773,7 @@ public class SubInfoExportController extends BaseController {
|
|
|
response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode("重点项目调度-项目数据.xlsx", "UTF-8"));
|
|
|
out = response.getOutputStream();
|
|
|
writer.flush(out, true);
|
|
|
- }finally {
|
|
|
+ } finally {
|
|
|
|
|
|
IoUtil.close(out);
|
|
|
|
|
@@ -789,8 +800,172 @@ public class SubInfoExportController extends BaseController {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ * 导出明细
|
|
|
+ *
|
|
|
+ * @param response
|
|
|
+ */
|
|
|
+ @PostMapping("/exportDetailExcel")
|
|
|
+ public void exportDetailExcel(HttpServletResponse response, @RequestBody SubInfoQueryTzVO queryVO) {
|
|
|
+ List<SubInfoGxj> list = subInfoQueryService.queryAll(getCurUser().getLoginUser(), queryVO);
|
|
|
+ Workbook workbook;
|
|
|
+ if (SubInfoStatusEnum.CB.getCode().equals(queryVO.getStatus())) {
|
|
|
+ workbook = exportExcel(list, SubInfoCbVO.class, "“四个一批”工业项目表(储备项目库)", "储备项目库");
|
|
|
+ } else if (SubInfoStatusEnum.XJ.getCode().equals(queryVO.getStatus())) {
|
|
|
+ workbook = exportExcel(list, SubInfoXjVO.class, "“四个一批”工业项目表(新建项目库)", "新建项目库");
|
|
|
+ } else if (SubInfoStatusEnum.ZJ.getCode().equals(queryVO.getStatus())) {
|
|
|
+ workbook = exportExcel(list, SubInfoZjVO.class, "“四个一批”工业项目表(在建项目库)", "在建项目库");
|
|
|
+ } else if (SubInfoStatusEnum.TC.getCode().equals(queryVO.getStatus())) {
|
|
|
+ workbook = exportExcel(list, SubInfoTcVO.class, "“四个一批”工业项目表(投产项目库)", "投产项目库");
|
|
|
+ } else {
|
|
|
+ workbook = exportExcel(list, SubInfoZkVO.class, "“四个一批”工业项目表(项目总库)", "项目总库");
|
|
|
+ }
|
|
|
+ response.setContentType("application/xlsx;charset=utf-8");
|
|
|
+ response.setHeader("Content-Disposition", "attachment; filename=" + URLEncodeUtil.encode("项目明细表") + System.currentTimeMillis() + ".xlsx");
|
|
|
+
|
|
|
+ Sheet sheet = workbook.getSheetAt(0);
|
|
|
+
|
|
|
+ for (int i = 2; i <= list.size() + 1; i++) {
|
|
|
+ sheet.getRow(i).setHeight((short) -1);
|
|
|
+ }
|
|
|
+ try (OutputStream outputStream = response.getOutputStream()) {
|
|
|
+ workbook.write(outputStream);
|
|
|
+ } catch (IOException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private <T> Workbook exportExcel(List<SubInfoGxj> list, Class<T> clazz, String title, String sheetName) {
|
|
|
+ ExportParams exportParams = new ExportParams();
|
|
|
+ exportParams.setTitle(title);
|
|
|
+ exportParams.setSheetName(sheetName);
|
|
|
+ exportParams.setType(ExcelType.XSSF);
|
|
|
+
|
|
|
+ List<T> voList = list.stream()
|
|
|
+ .map(e -> {
|
|
|
+ T vo = BeanUtils.instantiateClass(clazz);
|
|
|
+ BeanUtils.copyProperties(e, vo);
|
|
|
+ return vo;
|
|
|
+ })
|
|
|
+ .collect(Collectors.toList());
|
|
|
+
|
|
|
+ return ExcelExportUtil.exportExcel(exportParams, clazz, voList);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ * 4库导出
|
|
|
+ *
|
|
|
+ * @param response
|
|
|
+ * @param vo
|
|
|
+ */
|
|
|
+ @PostMapping("/exportTotalExcelByStatus")
|
|
|
+ public void exportTotalExcelByStatus(HttpServletResponse response, @RequestBody SubInfoQueryTzVO vo) {
|
|
|
+
|
|
|
+ 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));
|
|
|
+
|
|
|
+ List<SubInfoTotalInfoVO> exportData = new ArrayList<>();
|
|
|
+ if (CollectionUtil.isNotEmpty(list)) {
|
|
|
+
|
|
|
+ List<SubInfoTotalInfoVO> ddList = list.stream()
|
|
|
+ .collect(Collectors.groupingBy(SubInfoTotalExcel::getSubjectId))
|
|
|
+ .entrySet().stream()
|
|
|
+ .map(entry -> new SubInfoTotalInfoVO(
|
|
|
+ "按属地分",
|
|
|
+ jsddMap.getOrDefault(entry.getKey(), entry.getKey()),
|
|
|
+ entry.getValue().size(),
|
|
|
+ entry.getValue().stream()
|
|
|
+ .map(SubInfoTotalExcel::getAmtTotal)
|
|
|
+ .reduce(BigDecimal.ZERO, BigDecimal::add)
|
|
|
+ .divide(new BigDecimal("10000"), 2, RoundingMode.HALF_UP)
|
|
|
+ ))
|
|
|
+ .collect(Collectors.toList());
|
|
|
+
|
|
|
+
|
|
|
+ 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"));
|
|
|
+ List<SubInfoTotalInfoVO> amtList = 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亿元以上";
|
|
|
+ }))
|
|
|
+ .entrySet().stream()
|
|
|
+ .map(entry -> new SubInfoTotalInfoVO(
|
|
|
+ "按金额分",
|
|
|
+ entry.getKey(),
|
|
|
+ entry.getValue().size(),
|
|
|
+ entry.getValue().stream()
|
|
|
+ .map(SubInfoTotalExcel::getAmtTotal)
|
|
|
+ .reduce(BigDecimal.ZERO, BigDecimal::add)
|
|
|
+ .divide(new BigDecimal("10000"), 2, RoundingMode.HALF_UP)
|
|
|
+ ))
|
|
|
+ .collect(Collectors.toList());
|
|
|
+
|
|
|
+
|
|
|
+ List<SubInfoTotalInfoVO> hyList = list.stream()
|
|
|
+ .collect(Collectors.groupingBy(transaction ->{
|
|
|
+ String code = transaction.getInduskind();
|
|
|
+
|
|
|
+ if (code == null || code.length() < 2) {
|
|
|
+ return "未知行业";
|
|
|
+ }
|
|
|
+ return code.substring(0, 2);
|
|
|
+ }))
|
|
|
+ .entrySet().stream()
|
|
|
+ .map(entry -> new SubInfoTotalInfoVO(
|
|
|
+ "按行业分",
|
|
|
+ hyflMap.getOrDefault(entry.getKey(),entry.getKey()),
|
|
|
+ entry.getValue().size(),
|
|
|
+ entry.getValue().stream()
|
|
|
+ .map(SubInfoTotalExcel::getAmtTotal)
|
|
|
+ .reduce(BigDecimal.ZERO, BigDecimal::add)
|
|
|
+ .divide(new BigDecimal("10000"), 2, RoundingMode.HALF_UP)
|
|
|
+ )
|
|
|
+ )
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ exportData.addAll(ddList);
|
|
|
+ exportData.addAll(amtList);
|
|
|
+ exportData.addAll(hyList);
|
|
|
+ BigDecimal reduce = list.stream().map(SubInfoTotalExcel::getAmtTotal).reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
+ exportData.add(new SubInfoTotalInfoVO("合计", "合计", list.size(), reduce.divide(new BigDecimal("10000"), 2, RoundingMode.HALF_UP)));
|
|
|
+
|
|
|
+ ExportParams exportParams = new ExportParams();
|
|
|
+ exportParams.setTitle("项目库基本情况");
|
|
|
+ exportParams.setSheetName("项目库基本情况");
|
|
|
+ exportParams.setType(ExcelType.XSSF);
|
|
|
+ int mergeTotalStartRow = exportData.size() + 1;
|
|
|
+ Workbook workbook = ExcelExportUtil.exportExcel(exportParams, SubInfoTotalInfoVO.class, exportData);
|
|
|
+ response.setContentType("application/xlsx;charset=utf-8");
|
|
|
+ response.setHeader("Content-Disposition", "attachment; filename=" + URLEncodeUtil.encode("项目明细表") + System.currentTimeMillis() + ".xlsx");
|
|
|
+ Sheet sheet = workbook.getSheetAt(0);
|
|
|
+
|
|
|
+ sheet.addMergedRegion(new CellRangeAddress(1, 1, 0, 1));
|
|
|
+ sheet.addMergedRegion(new CellRangeAddress(2, ddList.size() + 1, 0, 0));
|
|
|
+ sheet.addMergedRegion(new CellRangeAddress(ddList.size() + 2, ddList.size() + amtList.size() + 1, 0, 0));
|
|
|
+ sheet.addMergedRegion(new CellRangeAddress(ddList.size() + amtList.size() + 2, ddList.size() + amtList.size() + hyList.size() + 1, 0, 0));
|
|
|
+ sheet.addMergedRegion(new CellRangeAddress(mergeTotalStartRow, mergeTotalStartRow, 0, 1));
|
|
|
+
|
|
|
+ try (OutputStream outputStream = response.getOutputStream()) {
|
|
|
+ workbook.write(outputStream);
|
|
|
+ workbook.close();
|
|
|
+ } catch (IOException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
* 导出重点项目明细表
|
|
|
+ *
|
|
|
* @param response
|
|
|
* @param vo
|
|
|
*/
|
|
@@ -988,7 +1163,7 @@ public class SubInfoExportController extends BaseController {
|
|
|
listMain.get(i).put("statusSource", "3");
|
|
|
}
|
|
|
for (int j = 0; j < tableList.size(); j++) {
|
|
|
- if (listMain.get(i).get("propKind")!=null&&listMain.get(i).get("propKind").equals(tableList.get(j).getCode())) {
|
|
|
+ if (listMain.get(i).get("propKind") != null && listMain.get(i).get("propKind").equals(tableList.get(j).getCode())) {
|
|
|
listMain.get(i).put("propKindName", tableList.get(j).getTitle());
|
|
|
}
|
|
|
}
|
|
@@ -1093,7 +1268,6 @@ public class SubInfoExportController extends BaseController {
|
|
|
}
|
|
|
|
|
|
|
|
|
-
|
|
|
|
|
|
* 导出调度表
|
|
|
*
|
|
@@ -1217,9 +1391,4 @@ public class SubInfoExportController extends BaseController {
|
|
|
}
|
|
|
|
|
|
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
}
|