|
@@ -8,6 +8,7 @@ import java.math.RoundingMode;
|
|
|
import java.net.URLEncoder;
|
|
|
import java.text.SimpleDateFormat;
|
|
|
import java.util.*;
|
|
|
+import java.util.function.Function;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
import javax.servlet.ServletOutputStream;
|
|
@@ -1511,15 +1512,6 @@ public class SubInfoExportController extends BaseController {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- 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("、$", "。");
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
/**
|
|
|
* 导出重点项目储备明细表
|
|
|
*
|
|
@@ -1555,7 +1547,7 @@ public class SubInfoExportController extends BaseController {
|
|
|
writer.addHeaderAlias("content", "项目建设内容");
|
|
|
writer.addHeaderAlias("amtTotal", "计划总投资(万元)");
|
|
|
writer.addHeaderAlias("indusKind", "行业分类");
|
|
|
- writer.addHeaderAlias("cbStatus", "状态[正在谋划,正在洽谈,已签约,已备案/已核准]");
|
|
|
+ writer.addHeaderAlias("cbStatus", "状态[正在谋划,正在洽谈,\n已签约,已备案/已核准]");
|
|
|
writer.addHeaderAlias("beginDate", "计划开始日期");
|
|
|
writer.addHeaderAlias("endDate", "计划投产日期");
|
|
|
writer.addHeaderAlias("progress", "项目进展情况");
|
|
@@ -1570,15 +1562,28 @@ public class SubInfoExportController extends BaseController {
|
|
|
cellStyle.setAlignment(HorizontalAlignment.LEFT);
|
|
|
|
|
|
// 设置每列的默认宽度
|
|
|
- int defaultColumnWidth = 40; // 默认宽度为20个字符
|
|
|
- for (int i = 0; i < 11; i++) {
|
|
|
- if (i == 0) {
|
|
|
- sheet.setColumnWidth(i, 4 * 256); // 序号列宽度为20个字符
|
|
|
- continue;
|
|
|
- }
|
|
|
- sheet.setColumnWidth(i, defaultColumnWidth * 256); // 其他列保持默认宽度
|
|
|
- }
|
|
|
+ // int defaultColumnWidth = 40; // 默认宽度为20个字符
|
|
|
+ // for (int i = 0; i < 11; i++) {
|
|
|
+ // if (i == 0) {
|
|
|
+ // sheet.setColumnWidth(i, 4 * 256); // 序号列宽度为20个字符
|
|
|
+ // continue;
|
|
|
+ // }
|
|
|
+ // sheet.setColumnWidth(i, defaultColumnWidth * 256); // 其他列保持默认宽度
|
|
|
+ // }
|
|
|
|
|
|
+ sheet.setColumnWidth(0, 4 * 256);
|
|
|
+ sheet.setColumnWidth(1, 40 * 256);
|
|
|
+ sheet.setColumnWidth(2, 14 * 256);
|
|
|
+ sheet.setColumnWidth(3, 40 * 256);
|
|
|
+ sheet.setColumnWidth(4, 12 * 256);
|
|
|
+ sheet.setColumnWidth(5, 40 * 256);
|
|
|
+ sheet.setColumnWidth(6, 20 * 256);
|
|
|
+ sheet.setColumnWidth(7, 12 * 256);
|
|
|
+ sheet.setColumnWidth(8, 20 * 256);
|
|
|
+ sheet.setColumnWidth(9, 14 * 256);
|
|
|
+ sheet.setColumnWidth(10, 14 * 256);
|
|
|
+ sheet.setColumnWidth(11, 14 * 256);
|
|
|
+ sheet.setColumnWidth(12, 14 * 256);
|
|
|
|
|
|
|
|
|
//根据合并行进行合并
|
|
@@ -1586,8 +1591,19 @@ public class SubInfoExportController extends BaseController {
|
|
|
subInfoTotalExcel.get(i).setNumber(i);
|
|
|
}
|
|
|
|
|
|
+ List<Map<String, Object>> list = subInfoTotalExcel.stream().map(item -> {
|
|
|
+ Map<String, Object> map = BeanUtil.beanToMap(item);
|
|
|
+ if (map.get("beginDate") != null) {
|
|
|
+ map.put("beginDate", DateUtil.format(item.getBeginDate(), "yyyy-MM-dd"));
|
|
|
+ }
|
|
|
+ if (map.get("endDate") != null) {
|
|
|
+ map.put("endDate", DateUtil.format(item.getBeginDate(), "yyyy-MM-dd"));
|
|
|
+ }
|
|
|
+ return map;
|
|
|
+ }).collect(Collectors.toList());
|
|
|
+
|
|
|
//写入行业明细行
|
|
|
- writer.write(subInfoTotalExcel, true);
|
|
|
+ writer.write(list, true);
|
|
|
// 输出到客户端
|
|
|
writer.flush(out, true);
|
|
|
|
|
@@ -1710,13 +1726,10 @@ public class SubInfoExportController extends BaseController {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 4库导出总表
|
|
|
- *
|
|
|
- * @param response
|
|
|
- * @param vo
|
|
|
+ * 四库、总库导出总表
|
|
|
*/
|
|
|
@PostMapping("/exportTotalExcelByStatus")
|
|
|
- @Log("4库导出总表")
|
|
|
+ @Log("导出总表")
|
|
|
public void exportTotalExcelByStatus(@RequestBody SubInfoQueryTzVO vo) {
|
|
|
WebLogAspect.content.set(String.format("页面:【项目四库管理-%s库】,执行操作:导出汇总",
|
|
|
StringUtils.isBlank(vo.getStatus()) ? "项目总" : SubInfoStatusEnum.getDesc(vo.getStatus())));
|
|
@@ -1727,193 +1740,258 @@ public class SubInfoExportController extends BaseController {
|
|
|
Map<String, String> jsddMap = jsddDict.stream().collect(Collectors.toMap(TSystable::getCode, TSystable::getTitle));
|
|
|
Map<String, String> jsddTitleMap = jsddDict.stream().collect(Collectors.toMap(TSystable::getTitle, TSystable::getCode));
|
|
|
Map<String, String> hyflMap = subInduService.queryParentAll().stream().collect(Collectors.toMap(SubIndu::getCode, SubIndu::getTitle));
|
|
|
- // 0.项目总库导出总表
|
|
|
- if (StringUtils.isBlank(vo.getStatus())){
|
|
|
- // 0.1 按区域构建表头
|
|
|
- List<String> subjectIds = list.stream().map(SubInfoTotalExcel::getSubjectId).distinct().collect(Collectors.toList());
|
|
|
- // 创建主表头
|
|
|
- List<ExcelExportEntity> entityList = new ArrayList<>();
|
|
|
- // 添加表头
|
|
|
- ExcelExportEntity lbEntity = new ExcelExportEntity("项目类别", "subjectName");
|
|
|
- entityList.add(lbEntity);
|
|
|
-
|
|
|
- ExcelExportEntity hj = new ExcelExportEntity("合计", "hj");
|
|
|
- List<ExcelExportEntity> subHeadEntities = new ArrayList<>();
|
|
|
- subHeadEntities.add(getExcelExportEntity("项目个数", "count", 12));
|
|
|
- subHeadEntities.add(getExcelExportEntity("计划总投资(亿元)", "amt", 20));
|
|
|
- hj.setList(subHeadEntities);
|
|
|
- entityList.add(hj);
|
|
|
-
|
|
|
- // 创建for循环,循环5次
|
|
|
- List<String> newSubjectIds = new ArrayList<>();
|
|
|
- if (subjectIds.contains(jsddTitleMap.get("伊州区"))){
|
|
|
- newSubjectIds.add(jsddTitleMap.get("伊州区"));
|
|
|
- }
|
|
|
- if (subjectIds.contains(jsddTitleMap.get("巴里坤县"))){
|
|
|
- newSubjectIds.add(jsddTitleMap.get("巴里坤县"));
|
|
|
- }
|
|
|
- if (subjectIds.contains(jsddTitleMap.get("伊吾县"))){
|
|
|
- newSubjectIds.add(jsddTitleMap.get("伊吾县"));
|
|
|
- }
|
|
|
- if (subjectIds.contains(jsddTitleMap.get("高新区"))){
|
|
|
- newSubjectIds.add(jsddTitleMap.get("高新区"));
|
|
|
- }
|
|
|
- if (subjectIds.contains(jsddTitleMap.get("市本级"))){
|
|
|
- newSubjectIds.add(jsddTitleMap.get("市本级"));
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- for (String subjectId : newSubjectIds) {
|
|
|
- ExcelExportEntity jsdd = null;
|
|
|
- if (jsddMap.get(subjectId).equals("市本级")) {
|
|
|
- jsdd = new ExcelExportEntity("其他", subjectId);
|
|
|
- }else {
|
|
|
- jsdd = new ExcelExportEntity(jsddMap.get(subjectId), subjectId);
|
|
|
+ if (StringUtils.isBlank(vo.getStatus())) {
|
|
|
+ // 项目总库导出总表
|
|
|
+ exportZkTotal(list, jsddMap, jsddTitleMap);
|
|
|
+ } else {
|
|
|
+ // 四库导出总表
|
|
|
+ exportFourDbTotal(vo, list, jsddMap, hyflMap);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 项目总库导出总表
|
|
|
+ */
|
|
|
+ private void exportFourDbTotal(SubInfoQueryTzVO vo, List<SubInfoTotalExcel> list, Map<String, String> jsddMap, Map<String, String> hyflMap) {
|
|
|
+ // 处理数据
|
|
|
+ List<SubInfoTotalInfoVO> exportData = new ArrayList<>();
|
|
|
+ if (CollectionUtil.isNotEmpty(list)) {
|
|
|
+ // 1.按属地划分
|
|
|
+ List<SubInfoTotalInfoVO> ddList = new ArrayList<SubInfoTotalInfoVO>() {{
|
|
|
+ jsddMap.forEach((k, v) -> {
|
|
|
+ add(new SubInfoTotalInfoVO("按属地划分", v, 0, BigDecimal.ZERO));
|
|
|
+ });
|
|
|
+ }};
|
|
|
+ Map<String, SubInfoTotalInfoVO> ddGroup = 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.toMap(SubInfoTotalInfoVO::getTypeItem, Function.identity()));
|
|
|
+ ddList = ddList.stream().map(e -> {
|
|
|
+ if (ddGroup.get(e.getTypeItem()) != null) {
|
|
|
+ return ddGroup.get(e.getTypeItem());
|
|
|
+ } else {
|
|
|
+ return e;
|
|
|
}
|
|
|
- List<ExcelExportEntity> ddHead = new ArrayList<>();
|
|
|
- ddHead.add(getExcelExportEntity("项目个数", "count", 12));
|
|
|
- ddHead.add(getExcelExportEntity("计划总投资(亿元)", "amt", 20));
|
|
|
- jsdd.setList(ddHead);
|
|
|
- entityList.add(jsdd);
|
|
|
- }
|
|
|
- // 0.2 构建数据
|
|
|
- Map<String, List<SubInfoTotalExcel>> statusGroup = list.stream().collect(Collectors.groupingBy(SubInfoTotalExcel::getStatus));
|
|
|
- List<Map<String,Object>> dataList = new ArrayList<>();
|
|
|
- // 0.2.1 储备项目
|
|
|
- List<SubInfoTotalExcel> cb = statusGroup.getOrDefault(SubInfoStatusEnum.CB.getCode(),new ArrayList<>());
|
|
|
- List<SubInfoTotalExcel> xj = statusGroup.getOrDefault(SubInfoStatusEnum.XJ.getCode(),new ArrayList<>());
|
|
|
- List<SubInfoTotalExcel> zj = statusGroup.getOrDefault(SubInfoStatusEnum.ZJ.getCode(),new ArrayList<>());
|
|
|
- List<SubInfoTotalExcel> tc = statusGroup.getOrDefault(SubInfoStatusEnum.TC.getCode(),new ArrayList<>());
|
|
|
-
|
|
|
- fillRowData(subjectIds, dataList, cb, SubInfoStatusEnum.CB.getDesc() + "项目");
|
|
|
- fillRowData(subjectIds, dataList, xj, SubInfoStatusEnum.XJ.getDesc() + "项目");
|
|
|
- fillRowData(subjectIds, dataList, zj, SubInfoStatusEnum.ZJ.getDesc() + "项目");
|
|
|
- fillRowData(subjectIds, dataList, tc, SubInfoStatusEnum.TC.getDesc() + "项目");
|
|
|
- fillRowData(subjectIds, dataList, list, "合计");
|
|
|
-
|
|
|
-
|
|
|
- // 3.导出
|
|
|
- ExportParams exportParams = new ExportParams("哈密市“四个一批”工业项目库总体情况", "项目库总体情况", ExcelType.XSSF);
|
|
|
+ }).collect(Collectors.toList());
|
|
|
+
|
|
|
+ // 2.按金额划分 定义分组边界
|
|
|
+ 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 = new ArrayList<SubInfoTotalInfoVO>() {{
|
|
|
+ add(new SubInfoTotalInfoVO("按金额划分", "10亿元以下", 0, BigDecimal.ZERO));
|
|
|
+ add(new SubInfoTotalInfoVO("按金额划分", "10-50亿元", 0, BigDecimal.ZERO));
|
|
|
+ add(new SubInfoTotalInfoVO("按金额划分", "50-100亿元", 0, BigDecimal.ZERO));
|
|
|
+ add(new SubInfoTotalInfoVO("按金额划分", "100亿元以上", 0, BigDecimal.ZERO));
|
|
|
+ }};
|
|
|
+ Map<String, SubInfoTotalInfoVO> amtGroup = 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.toMap(SubInfoTotalInfoVO::getTypeItem, Function.identity()));
|
|
|
+ amtList = amtList.stream().map(e -> {
|
|
|
+ if (amtGroup.get(e.getTypeItem()) != null) {
|
|
|
+ return amtGroup.get(e.getTypeItem());
|
|
|
+ } else {
|
|
|
+ return e;
|
|
|
+ }
|
|
|
+ }).collect(Collectors.toList());
|
|
|
+
|
|
|
+ // 3.按行业划分
|
|
|
+ List<SubInfoTotalInfoVO> hyList = new ArrayList<SubInfoTotalInfoVO>() {{
|
|
|
+ hyflMap.forEach((k, v) -> {
|
|
|
+ add(new SubInfoTotalInfoVO("按行业划分", v, 0, BigDecimal.ZERO));
|
|
|
+ });
|
|
|
+ }};
|
|
|
+ Map<String, SubInfoTotalInfoVO> hyGroup = list.stream()
|
|
|
+ .collect(Collectors.groupingBy(transaction -> {
|
|
|
+ String code = transaction.getInduskind();
|
|
|
+ // 确保code不为空且长度至少为2
|
|
|
+ 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.toMap(SubInfoTotalInfoVO::getTypeItem, Function.identity()));
|
|
|
+ hyList = hyList.stream().map(e -> {
|
|
|
+ if (hyGroup.get(e.getTypeItem()) != null) {
|
|
|
+ return hyGroup.get(e.getTypeItem());
|
|
|
+ } else {
|
|
|
+ return e;
|
|
|
+ }
|
|
|
+ }).collect(Collectors.toList());
|
|
|
+ if (hyGroup.get("未知行业") != null) {
|
|
|
+ hyList.add(hyGroup.get("未知行业"));
|
|
|
+ }
|
|
|
+
|
|
|
+ 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)));
|
|
|
+ // 4.导出
|
|
|
+ ExportParams exportParams = null;
|
|
|
+ if (vo.getStatus().equals("1")){
|
|
|
+ exportParams = new ExportParams("“四个一批”储备项目库基本情况","“四个一批”储备项目库基本情况", ExcelType.XSSF);
|
|
|
+ }else if (vo.getStatus().equals("2")){
|
|
|
+ exportParams = new ExportParams("“四个一批”新建项目库基本情况","“四个一批”新建项目库基本情况", ExcelType.XSSF);
|
|
|
+ }else if (vo.getStatus().equals("3")){
|
|
|
+ exportParams = new ExportParams("“四个一批”在建项目库基本情况","“四个一批”在建项目库基本情况", ExcelType.XSSF);
|
|
|
+ }else if (vo.getStatus().equals("9")){
|
|
|
+ exportParams = new ExportParams("“四个一批”投产库基本情况","“四个一批”投产库基本情况", ExcelType.XSSF);
|
|
|
+ }else {
|
|
|
+ exportParams = new ExportParams("“四个一批”项目库基本情况","“四个一批”项目库基本情况", ExcelType.XSSF);
|
|
|
+ }
|
|
|
exportParams.setStyle(ExcelStyleUtil.class);
|
|
|
- Workbook workbook = ExcelExportUtil.exportExcel(exportParams, entityList, dataList);
|
|
|
+ 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");
|
|
|
+ response.setHeader("Content-Disposition", "attachment; filename=" + URLEncodeUtil.encode("项目明细表") + System.currentTimeMillis() + ".xlsx");
|
|
|
+ Sheet sheet = workbook.getSheetAt(0);
|
|
|
+ // 合并单元格
|
|
|
+ sheet.addMergedRegion(new CellRangeAddress(1, 1, 0, 1));
|
|
|
+
|
|
|
+ if (ddList.size() > 1){
|
|
|
+ sheet.addMergedRegion(new CellRangeAddress(2, ddList.size() + 1, 0, 0));
|
|
|
+ }
|
|
|
+ if (amtList.size() > 1){
|
|
|
+ sheet.addMergedRegion(new CellRangeAddress(ddList.size() + 2, ddList.size() + amtList.size() + 1, 0, 0));
|
|
|
+ }
|
|
|
+ if (hyList.size() > 1) {
|
|
|
+ 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();
|
|
|
- }finally {
|
|
|
- try {
|
|
|
- workbook.close();
|
|
|
- } catch (IOException e) {
|
|
|
- e.printStackTrace();
|
|
|
- }
|
|
|
}
|
|
|
- }else {
|
|
|
- // 处理数据
|
|
|
- List<SubInfoTotalInfoVO> exportData = new ArrayList<>();
|
|
|
- if (CollectionUtil.isNotEmpty(list)) {
|
|
|
- // 1.按属地分
|
|
|
- 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());
|
|
|
-
|
|
|
- // 2.按金额分 定义分组边界
|
|
|
- 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());
|
|
|
-
|
|
|
- // 3.按行业分
|
|
|
- List<SubInfoTotalInfoVO> hyList = list.stream()
|
|
|
- .collect(Collectors.groupingBy(transaction ->{
|
|
|
- String code = transaction.getInduskind();
|
|
|
- // 确保code不为空且长度至少为2
|
|
|
- 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)));
|
|
|
- // 4.导出
|
|
|
- ExportParams exportParams = null;
|
|
|
- if (vo.getStatus().equals("1")){
|
|
|
- exportParams = new ExportParams("“四个一批”储备项目库基本情况","“四个一批”储备项目库基本情况", ExcelType.XSSF);
|
|
|
- }else if (vo.getStatus().equals("2")){
|
|
|
- exportParams = new ExportParams("“四个一批”新建项目库基本情况","“四个一批”新建项目库基本情况", ExcelType.XSSF);
|
|
|
- }else if (vo.getStatus().equals("3")){
|
|
|
- exportParams = new ExportParams("“四个一批”在建项目库基本情况","“四个一批”在建项目库基本情况", ExcelType.XSSF);
|
|
|
- }else if (vo.getStatus().equals("9")){
|
|
|
- exportParams = new ExportParams("“四个一批”投产库基本情况","“四个一批”投产库基本情况", ExcelType.XSSF);
|
|
|
- }else {
|
|
|
- exportParams = new ExportParams("“四个一批”项目库基本情况","“四个一批”项目库基本情况", ExcelType.XSSF);
|
|
|
- }
|
|
|
- exportParams.setStyle(ExcelStyleUtil.class);
|
|
|
- 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();
|
|
|
- }
|
|
|
+ /**
|
|
|
+ * 四库导出总表
|
|
|
+ */
|
|
|
+ private void exportZkTotal(List<SubInfoTotalExcel> list, Map<String, String> jsddMap, Map<String, String> jsddTitleMap) {
|
|
|
+ // 0.1 按区域构建表头
|
|
|
+ List<String> subjectIds = list.stream().map(SubInfoTotalExcel::getSubjectId).distinct().collect(Collectors.toList());
|
|
|
+ // 创建主表头
|
|
|
+ List<ExcelExportEntity> entityList = new ArrayList<>();
|
|
|
+ // 添加表头
|
|
|
+ ExcelExportEntity lbEntity = new ExcelExportEntity("项目类别", "subjectName");
|
|
|
+ entityList.add(lbEntity);
|
|
|
+
|
|
|
+ ExcelExportEntity hj = new ExcelExportEntity("合计", "hj");
|
|
|
+ List<ExcelExportEntity> subHeadEntities = new ArrayList<>();
|
|
|
+ subHeadEntities.add(getExcelExportEntity("项目个数", "count", 12));
|
|
|
+ subHeadEntities.add(getExcelExportEntity("计划总投资(亿元)", "amt", 20));
|
|
|
+ hj.setList(subHeadEntities);
|
|
|
+ entityList.add(hj);
|
|
|
+
|
|
|
+ // 创建for循环,循环5次
|
|
|
+ List<String> newSubjectIds = new ArrayList<>();
|
|
|
+ if (subjectIds.contains(jsddTitleMap.get("伊州区"))){
|
|
|
+ newSubjectIds.add(jsddTitleMap.get("伊州区"));
|
|
|
+ }
|
|
|
+ if (subjectIds.contains(jsddTitleMap.get("巴里坤县"))){
|
|
|
+ newSubjectIds.add(jsddTitleMap.get("巴里坤县"));
|
|
|
+ }
|
|
|
+ if (subjectIds.contains(jsddTitleMap.get("伊吾县"))){
|
|
|
+ newSubjectIds.add(jsddTitleMap.get("伊吾县"));
|
|
|
+ }
|
|
|
+ if (subjectIds.contains(jsddTitleMap.get("高新区"))){
|
|
|
+ newSubjectIds.add(jsddTitleMap.get("高新区"));
|
|
|
+ }
|
|
|
+ if (subjectIds.contains(jsddTitleMap.get("市本级"))){
|
|
|
+ newSubjectIds.add(jsddTitleMap.get("市本级"));
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ for (String subjectId : newSubjectIds) {
|
|
|
+ ExcelExportEntity jsdd = null;
|
|
|
+ if (jsddMap.get(subjectId).equals("市本级")) {
|
|
|
+ jsdd = new ExcelExportEntity("其他", subjectId);
|
|
|
+ }else {
|
|
|
+ jsdd = new ExcelExportEntity(jsddMap.get(subjectId), subjectId);
|
|
|
+ }
|
|
|
+ List<ExcelExportEntity> ddHead = new ArrayList<>();
|
|
|
+ ddHead.add(getExcelExportEntity("项目个数", "count", 12));
|
|
|
+ ddHead.add(getExcelExportEntity("计划总投资(亿元)", "amt", 20));
|
|
|
+ jsdd.setList(ddHead);
|
|
|
+ entityList.add(jsdd);
|
|
|
+ }
|
|
|
+ // 0.2 构建数据
|
|
|
+ Map<String, List<SubInfoTotalExcel>> statusGroup = list.stream().collect(Collectors.groupingBy(SubInfoTotalExcel::getStatus));
|
|
|
+ List<Map<String,Object>> dataList = new ArrayList<>();
|
|
|
+ // 0.2.1 储备项目
|
|
|
+ List<SubInfoTotalExcel> cb = statusGroup.getOrDefault(SubInfoStatusEnum.CB.getCode(),new ArrayList<>());
|
|
|
+ List<SubInfoTotalExcel> xj = statusGroup.getOrDefault(SubInfoStatusEnum.XJ.getCode(),new ArrayList<>());
|
|
|
+ List<SubInfoTotalExcel> zj = statusGroup.getOrDefault(SubInfoStatusEnum.ZJ.getCode(),new ArrayList<>());
|
|
|
+ List<SubInfoTotalExcel> tc = statusGroup.getOrDefault(SubInfoStatusEnum.TC.getCode(),new ArrayList<>());
|
|
|
+
|
|
|
+ fillRowData(subjectIds, dataList, cb, SubInfoStatusEnum.CB.getDesc() + "项目");
|
|
|
+ fillRowData(subjectIds, dataList, xj, SubInfoStatusEnum.XJ.getDesc() + "项目");
|
|
|
+ fillRowData(subjectIds, dataList, zj, SubInfoStatusEnum.ZJ.getDesc() + "项目");
|
|
|
+ fillRowData(subjectIds, dataList, tc, SubInfoStatusEnum.TC.getDesc() + "项目");
|
|
|
+ fillRowData(subjectIds, dataList, list, "合计");
|
|
|
+
|
|
|
+
|
|
|
+ // 3.导出
|
|
|
+ ExportParams exportParams = new ExportParams("哈密市“四个一批”工业项目库总体情况", "项目库总体情况", ExcelType.XSSF);
|
|
|
+ exportParams.setStyle(ExcelStyleUtil.class);
|
|
|
+ Workbook workbook = ExcelExportUtil.exportExcel(exportParams, entityList, dataList);
|
|
|
+ response.setContentType("application/xlsx;charset=utf-8");
|
|
|
+ response.setHeader("Content-Disposition", "attachment; filename=" + URLEncodeUtil.encode("项目库总体情况") + System.currentTimeMillis() + ".xlsx");
|
|
|
+
|
|
|
+ try (OutputStream outputStream = response.getOutputStream()) {
|
|
|
+ workbook.write(outputStream);
|
|
|
+ } catch (IOException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }finally {
|
|
|
+ try {
|
|
|
+ workbook.close();
|
|
|
+ } catch (IOException e) {
|
|
|
+ e.printStackTrace();
|
|
|
}
|
|
|
}
|
|
|
}
|