zhanghl
2025-05-23 8bcbb0b65dbb0a59f4c588be624912410fc1fcc9
[焊缝统计表V2] add:导出功能
已修改5个文件
161 ■■■■■ 文件已修改
aps-common/aps-common-core/src/main/java/com/aps/common/core/utils/poi/ExcelUtil.java 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
aps-modules/aps-core/src/main/java/com/aps/core/controller/mainPlan/ApsWeldSeamStatisticsV2Controller.java 8 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
aps-modules/aps-core/src/main/java/com/aps/core/service/mainPlan/IApsWeldSeamStatisticsV2Service.java 7 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
aps-modules/aps-core/src/main/java/com/aps/core/service/mainPlan/impl/ApsWeldSeamStatisticsV2ServiceImpl.java 141 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
aps-modules/aps-core/src/main/resources/bootstrap-int.yml 3 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
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());
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 = "焊缝统计表V2", 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, "焊缝统计表V2数据");
    public void export(HttpServletResponse response, ApsWeldSeamStatisticsV2 apsWeldSeamStatisticsV2) throws IOException {
        apsWeldSeamStatisticsV2Service.exportWeldSeamStatistics(response);
    }
    /**
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);
}
    void exportWeldSeamStatistics(HttpServletResponse response) throws IOException;
}
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;
/**
 * 焊缝统计表V2Service业务层处理
@@ -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;
    }
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