From 8bcbb0b65dbb0a59f4c588be624912410fc1fcc9 Mon Sep 17 00:00:00 2001
From: zhanghl <253316343@qq.com>
Date: 星期五, 23 五月 2025 13:12:17 +0800
Subject: [PATCH] [焊缝统计表V2] add:导出功能
---
aps-modules/aps-core/src/main/java/com/aps/core/service/mainPlan/IApsWeldSeamStatisticsV2Service.java | 7 ++
aps-modules/aps-core/src/main/resources/bootstrap-int.yml | 3
aps-common/aps-common-core/src/main/java/com/aps/common/core/utils/poi/ExcelUtil.java | 2
aps-modules/aps-core/src/main/java/com/aps/core/service/mainPlan/impl/ApsWeldSeamStatisticsV2ServiceImpl.java | 141 ++++++++++++++++++++++++++++++++++++++++++++++-
aps-modules/aps-core/src/main/java/com/aps/core/controller/mainPlan/ApsWeldSeamStatisticsV2Controller.java | 8 +-
5 files changed, 150 insertions(+), 11 deletions(-)
diff --git a/aps-common/aps-common-core/src/main/java/com/aps/common/core/utils/poi/ExcelUtil.java b/aps-common/aps-common-core/src/main/java/com/aps/common/core/utils/poi/ExcelUtil.java
index 7a3a3c9..6f62c0a 100644
--- a/aps-common/aps-common-core/src/main/java/com/aps/common/core/utils/poi/ExcelUtil.java
+++ b/aps-common/aps-common-core/src/main/java/com/aps/common/core/utils/poi/ExcelUtil.java
@@ -1316,7 +1316,7 @@
/**
* 寰楀埌鎵�鏈夊畾涔夊瓧娈�
*/
- private void createExcelField()
+ public void createExcelField()
{
this.fields = getFields();
this.fields = this.fields.stream().sorted(Comparator.comparing(objects -> ((Excel) objects[1]).sort())).collect(Collectors.toList());
diff --git a/aps-modules/aps-core/src/main/java/com/aps/core/controller/mainPlan/ApsWeldSeamStatisticsV2Controller.java b/aps-modules/aps-core/src/main/java/com/aps/core/controller/mainPlan/ApsWeldSeamStatisticsV2Controller.java
index 597c4d9..001df24 100644
--- a/aps-modules/aps-core/src/main/java/com/aps/core/controller/mainPlan/ApsWeldSeamStatisticsV2Controller.java
+++ b/aps-modules/aps-core/src/main/java/com/aps/core/controller/mainPlan/ApsWeldSeamStatisticsV2Controller.java
@@ -14,6 +14,7 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
+import java.io.IOException;
import java.util.List;
/**
@@ -48,11 +49,8 @@
@RequiresPermissions("weldSeamStatistics:weldSeamStatisticsV2:export")
@Log(title = "鐒婄紳缁熻琛╒2", businessType = BusinessType.EXPORT)
@PostMapping("/export")
- public void export(HttpServletResponse response, ApsWeldSeamStatisticsV2 apsWeldSeamStatisticsV2)
- {
- List<ApsWeldSeamStatisticsV2> list = apsWeldSeamStatisticsV2Service.selectApsWeldSeamStatisticsV2List(apsWeldSeamStatisticsV2);
- ExcelUtil<ApsWeldSeamStatisticsV2> util = new ExcelUtil<ApsWeldSeamStatisticsV2>(ApsWeldSeamStatisticsV2.class);
- util.exportExcel(response, list, "鐒婄紳缁熻琛╒2鏁版嵁");
+ public void export(HttpServletResponse response, ApsWeldSeamStatisticsV2 apsWeldSeamStatisticsV2) throws IOException {
+ apsWeldSeamStatisticsV2Service.exportWeldSeamStatistics(response);
}
/**
diff --git a/aps-modules/aps-core/src/main/java/com/aps/core/service/mainPlan/IApsWeldSeamStatisticsV2Service.java b/aps-modules/aps-core/src/main/java/com/aps/core/service/mainPlan/IApsWeldSeamStatisticsV2Service.java
index e34d5bf..caaabdd 100644
--- a/aps-modules/aps-core/src/main/java/com/aps/core/service/mainPlan/IApsWeldSeamStatisticsV2Service.java
+++ b/aps-modules/aps-core/src/main/java/com/aps/core/service/mainPlan/IApsWeldSeamStatisticsV2Service.java
@@ -1,6 +1,9 @@
package com.aps.core.service.mainPlan;
import com.aps.core.domain.mainPlan.ApsWeldSeamStatisticsV2;
+import jakarta.servlet.http.HttpServletResponse;
+
+import java.io.IOException;
import java.util.List;
/**
@@ -32,4 +35,6 @@
* @return 鍙楀奖鍝嶇殑璁板綍鏁�
*/
public int refreshWeldSeamStatistics(String username);
-}
\ No newline at end of file
+
+ void exportWeldSeamStatistics(HttpServletResponse response) throws IOException;
+}
\ No newline at end of file
diff --git a/aps-modules/aps-core/src/main/java/com/aps/core/service/mainPlan/impl/ApsWeldSeamStatisticsV2ServiceImpl.java b/aps-modules/aps-core/src/main/java/com/aps/core/service/mainPlan/impl/ApsWeldSeamStatisticsV2ServiceImpl.java
index 77fd6f8..32599c0 100644
--- a/aps-modules/aps-core/src/main/java/com/aps/core/service/mainPlan/impl/ApsWeldSeamStatisticsV2ServiceImpl.java
+++ b/aps-modules/aps-core/src/main/java/com/aps/core/service/mainPlan/impl/ApsWeldSeamStatisticsV2ServiceImpl.java
@@ -1,22 +1,36 @@
package com.aps.core.service.mainPlan.impl;
+import com.aps.common.core.annotation.Excel;
import com.aps.common.core.utils.DateUtils;
+import com.aps.common.core.utils.poi.ExcelUtil;
import com.aps.common.core.utils.uuid.IdUtils;
import com.aps.common.core.web.page.TableDataInfo;
+import com.aps.common.security.utils.DictUtils;
import com.aps.common.security.utils.SecurityUtils;
import com.aps.core.controller.basicData.ApsGasPipelineCapacityPlanController;
import com.aps.core.domain.ApsGasPipelineCapacityPlan;
import com.aps.core.domain.mainPlan.ApsWeldSeamStatisticsV2;
import com.aps.core.mapper.mainPlan.ApsWeldSeamStatisticsV2Mapper;
-import com.aps.core.service.IApsGasPipelineCapacityPlanService;
import com.aps.core.service.mainPlan.IApsWeldSeamStatisticsV2Service;
+import com.aps.system.api.domain.SysDictData;
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.node.ObjectNode;
+import jakarta.servlet.http.HttpServletResponse;
+import org.apache.poi.ss.usermodel.CellStyle;
+import org.apache.poi.ss.util.CellRangeAddress;
+import org.apache.poi.xssf.streaming.SXSSFCell;
+import org.apache.poi.xssf.streaming.SXSSFRow;
+import org.apache.poi.xssf.streaming.SXSSFSheet;
+import org.apache.poi.xssf.streaming.SXSSFWorkbook;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
+import java.io.IOException;
import java.math.BigDecimal;
-import java.util.Date;
-import java.util.List;
+import java.util.*;
+import java.util.concurrent.atomic.AtomicInteger;
/**
* 鐒婄紳缁熻琛╒2Service涓氬姟灞傚鐞�
@@ -203,4 +217,125 @@
return count;
}
+ @Override
+ public void exportWeldSeamStatistics(HttpServletResponse response) throws IOException {
+ //1. 鑾峰彇鏁版嵁婧�
+ List<ApsWeldSeamStatisticsV2> list = apsWeldSeamStatisticsV2Mapper.selectApsWeldSeamStatisticsV2List(new ApsWeldSeamStatisticsV2());
+
+
+ List<SysDictData> isRequireDic = DictUtils.getDictCache("aps_task_is_require");
+ List<SysDictData> factoryDic = DictUtils.getDictCache("aps_factory");
+
+
+ //2. 鍒涘缓Excel宸ヤ綔绨�
+ SXSSFWorkbook wb = new SXSSFWorkbook(500);
+ ExcelUtil<ApsWeldSeamStatisticsV2> excelUtil = new ExcelUtil<>(ApsWeldSeamStatisticsV2.class);
+ excelUtil.init(list, "鐒婄紳缁熻琛�", "鐒婄紳缁熻琛�", Excel.Type.EXPORT);
+ excelUtil.createWorkbook();
+ excelUtil.createExcelField();
+
+ Map<String, CellStyle> cellStyleMap = excelUtil.createStyles(wb);
+ CellStyle titleStyle = cellStyleMap.get("header_WHITE_GREY_50_PERCENT");
+ CellStyle dataStyle = cellStyleMap.get("data_CENTER_BLACK_WHITE_STRING_false");
+
+ SXSSFSheet sheet = wb.createSheet("鐒婄紳缁熻琛�");
+ List<LinkedHashMap<String,String>> titleList= initRowTitle();
+ //3. 鏋勫缓琛ㄥご
+ for (int i = 0; i < titleList.size(); i++) {
+ SXSSFRow titleRow = sheet.createRow(i);
+ LinkedHashMap<String, String> map = titleList.get(i);
+ AtomicInteger index = new AtomicInteger();
+ titleList.get(i).forEach((key,value)->{
+ SXSSFCell cell = titleRow.createCell(index.get());
+ cell.setCellValue(value);
+ cell.setCellStyle(titleStyle);
+ index.getAndIncrement();
+ });
+ }
+ //5. 鏋勫缓鏁版嵁琛�
+ LinkedHashMap<String, String> first = titleList.get(0);
+ ArrayList<Map.Entry<String, String>> titles = new ArrayList<>(first.entrySet());
+ List<String> stringFiledKeys=Arrays.asList("productionBase","isSatisfy");
+ for (int rowInx = 0; rowInx < list.size(); rowInx++) {
+ SXSSFRow dataRow = sheet.createRow(rowInx + 2);
+ ApsWeldSeamStatisticsV2 statistics = list.get(rowInx);
+ ObjectMapper mapper = new ObjectMapper();
+ ObjectNode node = mapper.valueToTree(statistics);
+ for (int colInx = 0; colInx < titles.size(); colInx++) {
+ Map.Entry<String, String> entry = titles.get(colInx);
+ String filedKey = entry.getKey();
+ SXSSFCell cell = dataRow.createCell(colInx);
+ JsonNode jsonNode = node.get(filedKey);
+ if(filedKey.equals("productionBase")){
+ factoryDic.stream().filter(x->x.getDictValue().equals(jsonNode.textValue())).findFirst().ifPresent(
+ sysDictData -> cell.setCellValue(sysDictData.getDictLabel())
+ );
+ }else if(filedKey.equals("isSatisfy")){
+ isRequireDic.stream().filter(x->x.getDictValue().equals(jsonNode.textValue())).findFirst().ifPresent(
+ sysDictData -> cell.setCellValue(sysDictData.getDictLabel())
+ );
+ }else{
+ cell.setCellValue(jsonNode.longValue());
+ }
+ cell.setCellStyle(dataStyle);
+ }
+ }
+ for (int i = 0; i < sheet.getRow(0).getLastCellNum(); i++) {
+ sheet.setColumnWidth(i, 20 * 256);
+ }
+
+ //4.鍚堝苟琛ㄥご
+ sheet.addMergedRegion(new CellRangeAddress(0, 1, 0, 0));
+ sheet.addMergedRegion(new CellRangeAddress(0, 1, 1, 1));
+ sheet.addMergedRegion(new CellRangeAddress(0, 1, 2, 2));
+ sheet.addMergedRegion(new CellRangeAddress(0, 0, 3, 4));
+ sheet.addMergedRegion(new CellRangeAddress(0, 0, 5, 6));
+ sheet.addMergedRegion(new CellRangeAddress(0, 1, 7, 7));
+ sheet.addMergedRegion(new CellRangeAddress(0, 1, 8, 8));
+ sheet.addMergedRegion(new CellRangeAddress(0, 1, 9, 9));
+ sheet.addMergedRegion(new CellRangeAddress(0, 1, 10, 10));
+ sheet.addMergedRegion(new CellRangeAddress(0, 1, 11, 11));
+ sheet.addMergedRegion(new CellRangeAddress(0, 1, 12, 12));
+ //3. 璁剧疆鍝嶅簲澶�
+ response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
+ response.setCharacterEncoding("utf-8");
+ wb.write(response.getOutputStream());
+
+ }
+ private List<LinkedHashMap<String,String>> initRowTitle(){
+ List<LinkedHashMap<String,String>> list = new ArrayList<>();
+ LinkedHashMap<String,String> level1 = new LinkedHashMap<>();
+ level1.put("year","骞翠唤");
+ level1.put("month","鏈堜唤");
+ level1.put("productionBase","鐢熶骇鍩哄湴");
+ level1.put("pipingOrderRequirement","璁㈠崟闇�姹�");
+ level1.put("gasOrderRequirement","璁㈠崟闇�姹�");
+ level1.put("pipingPredictionRequirement","棰勬祴闇�姹�");
+ level1.put("gasPredictionRequirement","棰勬祴闇�姹�");
+ level1.put("reserveEmergencyOrderOutput","棰勭暀绱ф�ヨ鍗曚骇鍑�");
+ level1.put("total","鍚堣");
+ level1.put("days","澶╂暟");
+ level1.put("requirementDayWeldSeam","闇�姹傛棩鐒婄紳");
+ level1.put("productionDayWeldSeam","鐢熶骇鏃ョ剨缂�");
+ level1.put("isSatisfy","鏄惁婊¤冻");
+ list.add(level1);
+
+ LinkedHashMap<String,String> level2 = new LinkedHashMap<>();
+ level2.put("year","骞翠唤");
+ level2.put("month","鏈堜唤");
+ level2.put("productionBase","鐢熶骇鍩哄湴");
+ level2.put("pipingOrderRequirement","绠¤矾");
+ level2.put("gasOrderRequirement","姘旀煖");
+ level2.put("pipingPredictionRequirement","绠¤矾");
+ level2.put("gasPredictionRequirement","姘旀煖");
+ level2.put("reserveEmergencyOrderOutput","棰勭暀绱ф�ヨ鍗曚骇鍑�");
+ level2.put("total","鍚堣");
+ level2.put("days","澶╂暟");
+ level2.put("requirementDayWeldSeam","闇�姹傛棩鐒婄紳");
+ level2.put("productionDayWeldSeam","鐢熶骇鏃ョ剨缂�");
+ level2.put("isSatisfy","鏄惁婊¤冻");
+ list.add(level2);
+
+ return list;
+ }
}
\ No newline at end of file
diff --git a/aps-modules/aps-core/src/main/resources/bootstrap-int.yml b/aps-modules/aps-core/src/main/resources/bootstrap-int.yml
index 069ef63..fb1cdca 100644
--- a/aps-modules/aps-core/src/main/resources/bootstrap-int.yml
+++ b/aps-modules/aps-core/src/main/resources/bootstrap-int.yml
@@ -7,7 +7,8 @@
server-addr: 192.168.50.160:8848
namespace: aafcd57a-d0f7-43e3-a77d-1dc85aec1f0e
metadata:
- local: int
+ local: zhl
+ ip: 192.168.50.13
config:
# 閰嶇疆涓績鍦板潃
server-addr: 192.168.50.160:8848
--
Gitblit v1.9.3