|
@@ -39,6 +39,7 @@ 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;
|
|
|
+import com.rtrh.projects.modules.utils.StringUtils;
|
|
|
import com.rtrh.projects.outapi.result.JsonResult;
|
|
|
import com.rtrh.projects.web.util.SheetData;
|
|
|
import com.rtrh.projects.web.util.SheetHead;
|
|
@@ -637,11 +638,14 @@ public class SubInfoExportController extends BaseController {
|
|
|
|
|
|
try {
|
|
|
List<SubInfoTotalExcel> subInfoTotalExcel = subInfoService.getFixTotalExcel(vo);
|
|
|
+ if (subInfoTotalExcel == null) {
|
|
|
+ subInfoTotalExcel = new ArrayList<>();
|
|
|
+ }
|
|
|
|
|
|
//获取属地字典
|
|
|
List<TSystable> jsddList = tSysTableService.getByKind(SysTableKind.JSDD);
|
|
|
- //获取行业字典
|
|
|
- List<TSystable> gxjHyfl = tSysTableService.getGxjHyfl(SysTableKind.HYFL);
|
|
|
+ //获取行业
|
|
|
+ List<SubIndu> subInduList = subInduService.queryTreeALl();
|
|
|
//遍历subInfoTotalExcel,将subjectId替换为jsddList中code=subjectId的title
|
|
|
for (SubInfoTotalExcel data : subInfoTotalExcel) {
|
|
|
if (data == null) {
|
|
@@ -650,15 +654,42 @@ public class SubInfoExportController extends BaseController {
|
|
|
String subjectId = data.getSubjectId();
|
|
|
String induskind = data.getInduskind();
|
|
|
if (StringUtil.isNotEmpty(induskind)) {
|
|
|
- Optional<TSystable> first = gxjHyfl.stream().filter(item -> item.getId().equals(induskind)).findFirst();
|
|
|
- first.ifPresent(tSystable -> data.setInduskind(tSystable.getTitle()));
|
|
|
+ //这是新的行业列表subInduList,subInduList中有children里面装的子行业,我需要将induskind替换为subInduList中的一级行业title
|
|
|
+ Optional<SubIndu> first = subInduList.stream().filter(item -> item.getCode().equals(induskind)).findFirst();
|
|
|
+ if (first.isPresent()) {
|
|
|
+ //判断上级名称是否存在,如果存在将induskind替换为上级名称,否则将induskind替换为名称
|
|
|
+ if (StringUtil.isNotEmpty(first.get().getParentTitle())) {
|
|
|
+ data.setInduskind(first.get().getParentTitle());
|
|
|
+ } else {
|
|
|
+ data.setInduskind(first.get().getTitle());
|
|
|
+ }
|
|
|
+ }else {
|
|
|
+ data.setInduskind("");
|
|
|
+ }
|
|
|
+ }else {
|
|
|
+ data.setInduskind("");
|
|
|
}
|
|
|
if (StringUtil.isNotEmpty(subjectId)) {
|
|
|
Optional<TSystable> first = jsddList.stream().filter(item -> item.getCode().equals(subjectId)).findFirst();
|
|
|
+ if (!first.isPresent()) {
|
|
|
+ data.setSubjectId("");
|
|
|
+ }
|
|
|
first.ifPresent(tSystable -> data.setSubjectId(tSystable.getTitle()));
|
|
|
+ }else{
|
|
|
+ data.setSubjectId("");
|
|
|
}
|
|
|
+ //将金额由万元为单位转换为亿元为单位,并且保留两位小数,避免空指针异常
|
|
|
+ if (data.getAmtTotal() == null) {
|
|
|
+ data.setAmtTotal(new BigDecimal("0"));
|
|
|
+ }
|
|
|
+ data.setAmtTotal(data.getAmtTotal().divide(new BigDecimal("10000")).setScale(2, RoundingMode.HALF_UP));
|
|
|
}
|
|
|
|
|
|
+ //对subInfoTotalExcel按照金额进行由小到大进行排序
|
|
|
+ subInfoTotalExcel.sort((o1, o2) -> {
|
|
|
+ return o1.getAmtTotal().compareTo(o2.getAmtTotal());
|
|
|
+ });
|
|
|
+
|
|
|
//通过ExcelUtil.getBigWriter()创建Writer对象,BigExcelWriter用于大数据量的导出,不会引起溢出;
|
|
|
cn.hutool.poi.excel.ExcelWriter writer = ExcelUtil.getBigWriter();
|
|
|
|
|
@@ -686,11 +717,11 @@ public class SubInfoExportController extends BaseController {
|
|
|
LinkedHashMap<String, List<SubInfoTotalExcel>> subjectIdList = subInfoTotalExcel.stream().collect(Collectors.groupingBy(SubInfoTotalExcel::getSubjectId, LinkedHashMap::new, Collectors.toList()));
|
|
|
//5、对数据按照金额1000-3000,3000-5000,5000-10000进行分组
|
|
|
LinkedHashMap<String, List<SubInfoTotalExcel>> moneyList = subInfoTotalExcel.stream().collect(Collectors.groupingBy(data -> {
|
|
|
- if (data.getAmtTotal().compareTo(new BigDecimal(1000000)) >= 0) {
|
|
|
+ if (data.getAmtTotal().compareTo(new BigDecimal(100)) >= 0) {
|
|
|
return "100亿元以上";
|
|
|
- } else if (data.getAmtTotal().compareTo(new BigDecimal(500000)) >= 0 && data.getAmtTotal().compareTo(new BigDecimal(1000000)) < 0) {
|
|
|
+ } else if (data.getAmtTotal().compareTo(new BigDecimal(50)) >= 0 && data.getAmtTotal().compareTo(new BigDecimal(100)) < 0) {
|
|
|
return "50-100亿元";
|
|
|
- } else if (data.getAmtTotal().compareTo(new BigDecimal(100000)) >= 0 && data.getAmtTotal().compareTo(new BigDecimal(500000)) < 0) {
|
|
|
+ } else if (data.getAmtTotal().compareTo(new BigDecimal(10)) >= 0 && data.getAmtTotal().compareTo(new BigDecimal(50)) < 0) {
|
|
|
return "10-50亿元";
|
|
|
} else {
|
|
|
return "10亿元以下";
|
|
@@ -717,16 +748,18 @@ public class SubInfoExportController extends BaseController {
|
|
|
}
|
|
|
finalDataMap.put("按属地划分", areaData);
|
|
|
|
|
|
- List<List<String>> moneyData = CollUtil.newArrayList();
|
|
|
- for (Map.Entry<String, List<SubInfoTotalExcel>> subInfoListEntry : moneyList.entrySet()) {
|
|
|
- List<String> data = CollUtil.newArrayList();
|
|
|
- data.add("按金额分");
|
|
|
- data.add(subInfoListEntry.getKey());
|
|
|
- data.add(String.valueOf(subInfoListEntry.getValue().size()));
|
|
|
- data.add(String.valueOf(subInfoListEntry.getValue().stream().map(SubInfoTotalExcel::getAmtTotal).reduce(BigDecimal.ZERO, BigDecimal::add)));
|
|
|
- moneyData.add(data);
|
|
|
+ if (!"9".equals(vo.getStateFix())) {
|
|
|
+ List<List<String>> moneyData = CollUtil.newArrayList();
|
|
|
+ for (Map.Entry<String, List<SubInfoTotalExcel>> subInfoListEntry : moneyList.entrySet()) {
|
|
|
+ List<String> data = CollUtil.newArrayList();
|
|
|
+ data.add("按规模划分");
|
|
|
+ data.add(subInfoListEntry.getKey());
|
|
|
+ data.add(String.valueOf(subInfoListEntry.getValue().size()));
|
|
|
+ data.add(String.valueOf(subInfoListEntry.getValue().stream().map(SubInfoTotalExcel::getAmtTotal).reduce(BigDecimal.ZERO, BigDecimal::add)));
|
|
|
+ moneyData.add(data);
|
|
|
+ }
|
|
|
+ finalDataMap.put("按规模划分", moneyData);
|
|
|
}
|
|
|
- finalDataMap.put("按金额划分", moneyData);
|
|
|
|
|
|
List<List<String>> industryData = CollUtil.newArrayList();
|
|
|
for (Map.Entry<String, List<SubInfoTotalExcel>> subInfoListEntry : industryList.entrySet()) {
|
|
@@ -976,6 +1009,14 @@ public class SubInfoExportController extends BaseController {
|
|
|
|
|
|
// 获取数据
|
|
|
List<SubInfoFixDetail> subInfoTotalExcel = subInfoService.exportFixDetailExcel(vo);
|
|
|
+ if (CollUtil.isEmpty(subInfoTotalExcel)){
|
|
|
+ subInfoTotalExcel = CollUtil.newArrayList();
|
|
|
+ }
|
|
|
+
|
|
|
+ //遍历subInfoTotalExcel将万元转换为亿元
|
|
|
+ subInfoTotalExcel.forEach(item -> {
|
|
|
+ item.setAmtTotal(item.getAmtTotal().divide(new BigDecimal("10000"), 2, RoundingMode.HALF_UP));
|
|
|
+ });
|
|
|
|
|
|
// 写入标题行
|
|
|
List<String> titleRow = CollUtil.newArrayList("四个一批工业项目表");
|
|
@@ -989,6 +1030,15 @@ public class SubInfoExportController extends BaseController {
|
|
|
sheet.setColumnWidth(i, defaultColumnWidth * 256); // 其他列保持默认宽度
|
|
|
}
|
|
|
|
|
|
+ //写入合计行数据
|
|
|
+ String total = "合计(" + subInfoTotalExcel.size() + ")";
|
|
|
+ //计算总金额
|
|
|
+ BigDecimal totalAmt = subInfoTotalExcel.stream().map(SubInfoFixDetail::getAmtTotal).reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
+ List<String> totalRow = CollUtil.newArrayList(total,total,total,total,totalAmt.toString(),"","","","");
|
|
|
+ writer.write(totalRow, true);
|
|
|
+ writer.merge(1, 1, 0, 7, null, true);
|
|
|
+
|
|
|
+
|
|
|
// 自定义标题别名
|
|
|
writer.addHeaderAlias("id", "序号");
|
|
|
writer.addHeaderAlias("subName", "项目名称");
|
|
@@ -1018,6 +1068,104 @@ public class SubInfoExportController extends BaseController {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 导出重点项目储备明细表
|
|
|
+ *
|
|
|
+ * @param response
|
|
|
+ * @param vo
|
|
|
+ */
|
|
|
+ @PostMapping("/exportFixCbDetailExcel")
|
|
|
+ public void exportFixCbDetailExcel(HttpServletResponse response, @RequestBody SubInfoQueryTzVO vo) throws IOException {
|
|
|
+
|
|
|
+ // 设置响应头
|
|
|
+ response.setContentType("application/vnd.ms-excel;charset=utf-8");
|
|
|
+ response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode("重点项目调度-项目数据.xlsx", "UTF-8"));
|
|
|
+
|
|
|
+ try (cn.hutool.poi.excel.ExcelWriter writer = ExcelUtil.getBigWriter();
|
|
|
+ ServletOutputStream out = response.getOutputStream()) {
|
|
|
+
|
|
|
+ // 获取数据
|
|
|
+ List<SubInfoFixCbDetail> subInfoTotalExcel = subInfoService.exportFixCbDetailExcel(vo);
|
|
|
+
|
|
|
+ // 写入标题行
|
|
|
+ writer.writeHeadRow(CollUtil.newArrayList("四个一批工业项目表"));
|
|
|
+ writer.merge(0, 0, 0, 6, "四个一批工业项目表(储备项目库)", true);
|
|
|
+
|
|
|
+ // 写入子标题行
|
|
|
+ writer.writeHeadRow(CollUtil.newArrayList("序号", "项目名称", "项目所在地", "项目建设内容", "计划总投资(亿元)", "进展情况", "备注"));
|
|
|
+
|
|
|
+ // 设置每列的默认宽度
|
|
|
+ SXSSFSheet sheet = ((SXSSFWorkbook) writer.getWorkbook()).getSheetAt(0);
|
|
|
+ int defaultColumnWidth = 40; // 默认宽度为20个字符
|
|
|
+ for (int i = 0; i < 7; i++) {
|
|
|
+ sheet.setColumnWidth(i, defaultColumnWidth * 256); // 其他列保持默认宽度
|
|
|
+ }
|
|
|
+
|
|
|
+ // 写入合计行
|
|
|
+ BigDecimal totalAmt = subInfoTotalExcel.stream()
|
|
|
+ .map(SubInfoFixCbDetail::getAmtTotal)
|
|
|
+ .reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
+ writer.writeRow(CollUtil.newArrayList(
|
|
|
+ "合计(" + subInfoTotalExcel.size() + ")", "", "", "", totalAmt.toString(), "", ""));
|
|
|
+ writer.merge(2, 2, 0, 3, null, true);
|
|
|
+
|
|
|
+
|
|
|
+ //对数据根据行业进行分组
|
|
|
+ Map<String, List<SubInfoFixCbDetail>> hyflGroupData = subInfoTotalExcel.stream().collect(Collectors.groupingBy(SubInfoFixCbDetail::getIndusKind));
|
|
|
+ int startRow = 3;
|
|
|
+ int titleNumber = 1;
|
|
|
+ //初始化值
|
|
|
+ List<List<String>> valueList = new ArrayList<>();
|
|
|
+ //需要合并行的集合
|
|
|
+ List<Integer> mergeRowList = new ArrayList<>();
|
|
|
+ for (Map.Entry<String, List<SubInfoFixCbDetail>> entry : hyflGroupData.entrySet()) {
|
|
|
+ String key = entry.getKey();
|
|
|
+ List<SubInfoFixCbDetail> value = entry.getValue();
|
|
|
+
|
|
|
+ //我需要将key进行拼接,例如这是第1个key,前面就加一个中文一
|
|
|
+ String newKey = StringUtils.toChineseNumber(titleNumber++) + "、" + key + "(" + value.size() + ")";
|
|
|
+
|
|
|
+ //遍历value将id设置为从1开始的值,并计算总金额
|
|
|
+ BigDecimal hyflTotalAmt = BigDecimal.ZERO;
|
|
|
+ for (int i = 0; i < value.size(); i++) {
|
|
|
+ value.get(i).setId(String.valueOf(i + 1));
|
|
|
+ hyflTotalAmt = hyflTotalAmt.add(value.get(i).getAmtTotal());
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ //写入行业标题行
|
|
|
+ List<String> hyflTitleRow = CollUtil.newArrayList(newKey,newKey,newKey,newKey,hyflTotalAmt.toString(),"","");
|
|
|
+ valueList.add(hyflTitleRow);
|
|
|
+ mergeRowList.add(startRow);
|
|
|
+ startRow++;
|
|
|
+
|
|
|
+ //将value转换为
|
|
|
+ List<List<String>> data = value.stream().map(subInfoFixCbDetail -> {
|
|
|
+ return CollUtil.newArrayList(subInfoFixCbDetail.getId(), subInfoFixCbDetail.getSubName(), subInfoFixCbDetail.getSubjectId(), subInfoFixCbDetail.getContent(), subInfoFixCbDetail.getAmtTotal().toString(), subInfoFixCbDetail.getProgress(), subInfoFixCbDetail.getRemark());
|
|
|
+ }).collect(Collectors.toList());
|
|
|
+ valueList.addAll(data);
|
|
|
+ startRow += value.size();
|
|
|
+ }
|
|
|
+
|
|
|
+ //根据合并行进行合并
|
|
|
+ for (int i = 0; i < mergeRowList.size(); i++) {
|
|
|
+ writer.merge(mergeRowList.get(i), mergeRowList.get(i), 0, 3, null, true);
|
|
|
+ }
|
|
|
+
|
|
|
+ //写入行业明细行
|
|
|
+ writer.write(valueList, true);
|
|
|
+ // 输出到客户端
|
|
|
+ writer.flush(out, true);
|
|
|
+
|
|
|
+ } catch (IOException e) {
|
|
|
+ // 处理 IO 异常
|
|
|
+ handleErrorResponse(response, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "导出 Excel 文件时出现错误:" + e.getMessage());
|
|
|
+ } catch (Exception e) {
|
|
|
+ // 处理其他异常
|
|
|
+ handleErrorResponse(response, HttpServletResponse.SC_BAD_REQUEST, "请求参数错误或发生其他错误:" + e.getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
private void handleErrorResponse(HttpServletResponse response, int statusCode, String errorMessage) throws IOException {
|
|
|
response.setStatus(statusCode);
|
|
|
response.setContentType("text/plain;charset=UTF-8");
|