zhanghl
2025-04-24 55aa346da75b77ced451b2fe456a144ac107813e
钣金计划大表-导出接口
已修改3个文件
185 ■■■■■ 文件已修改
aps-modules/aps-core/src/main/java/com/aps/core/controller/mainPlan/ApsPlateProcessShopStatController.java 4 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
aps-modules/aps-core/src/main/java/com/aps/core/service/IApsPlateProcessShopStatService.java 3 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
aps-modules/aps-core/src/main/java/com/aps/core/service/impl/ApsPlateProcessShopStatServiceImpl.java 178 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
aps-modules/aps-core/src/main/java/com/aps/core/controller/mainPlan/ApsPlateProcessShopStatController.java
@@ -42,9 +42,7 @@
    @PostMapping("/export")
    public void export(HttpServletResponse response, ApsPlateProcessShopStat apsPlateProcessShopStat)
    {
        List<ApsPlateProcessShopStat> list = apsPlateProcessShopStatService.selectApsPlateProcessShopStatList(apsPlateProcessShopStat);
        ExcelUtil<ApsPlateProcessShopStat> util = new ExcelUtil<ApsPlateProcessShopStat>(ApsPlateProcessShopStat.class);
        util.exportExcel(response, list, "钣金车间统计数据");
        apsPlateProcessShopStatService.exportExcel(response);
    }
aps-modules/aps-core/src/main/java/com/aps/core/service/IApsPlateProcessShopStatService.java
@@ -4,6 +4,7 @@
import com.aps.common.core.web.domain.AjaxResult;
import com.aps.core.domain.ApsPlateProcessShopStat;
import jakarta.servlet.http.HttpServletResponse;
/**
 * 钣金车间统计Service接口
@@ -64,4 +65,6 @@
    void saveShopStat();
    AjaxResult getShopPlanStat();
    void exportExcel(HttpServletResponse response);
}
aps-modules/aps-core/src/main/java/com/aps/core/service/impl/ApsPlateProcessShopStatServiceImpl.java
@@ -7,11 +7,20 @@
import com.aps.common.core.utils.DateUtils;
import com.aps.common.core.utils.bean.BeanUtils;
import com.aps.common.core.web.domain.AjaxResult;
import com.aps.common.security.utils.DictUtils;
import com.aps.common.security.utils.SecurityUtils;
import com.aps.core.domain.*;
import com.aps.core.mapper.*;
import com.aps.system.api.domain.SysDictData;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletResponse;
import lombok.extern.slf4j.Slf4j;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.util.IOUtils;
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 com.aps.core.service.IApsPlateProcessShopStatService;
@@ -260,6 +269,10 @@
        Map<String, List<ApsPlateProcessShopStat>> shopStatesByDocNo = shopStates.stream()
                .collect(Collectors.groupingBy(ApsPlateProcessShopStat::getDocNo));
        List<SysDictData> businessTypeDic = DictUtils.getDictCache("aps_business_type");
        List<SysDictData> documentStatusDic = DictUtils.getDictCache("aps_document_status");
        // 构建结果列表
        List<ApsPlateProcessShopPlanStat> shopPlanStats = planList.stream()
                .map(plan -> {
@@ -269,15 +282,174 @@
                    // 根据 docNo 获取对应的 shopStatList
                    List<ApsPlateProcessShopStat> shopStatList = shopStatesByDocNo.getOrDefault(plan.getDocumentNumber(), Collections.emptyList());
                    shopPlanStat.setDeptPlans(shopStatList);
                    if (businessTypeDic != null) {
                        businessTypeDic.stream().filter(x -> x.getDictValue().equals(plan.getBusinessType())).findFirst()
                                .ifPresent(sysDictData -> shopPlanStat.setBusinessType(sysDictData.getDictLabel()));
                    }
                    if (documentStatusDic != null) {
                        documentStatusDic.stream().filter(x->x.getDictValue().equals(plan.getDocumentStatus()))
                                .findFirst().ifPresent(sysDictData -> shopPlanStat.setDocumentStatus(sysDictData.getDictLabel()));
                    }
                    return shopPlanStat;
                })
                .toList();
                }).toList();
        // 构建返回结果
        AjaxResult success = AjaxResult.success(shopPlanStats);
        success.put("shopNames", shopList);
        return success;
    }
    @Override
    public void exportExcel(HttpServletResponse response) {
        SXSSFWorkbook wb = new SXSSFWorkbook(500);
        wb.createSheet();
        wb.setSheetName(0, "钣金计划表");
        response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
        response.setCharacterEncoding("utf-8");
        Map<String, CellStyle> styles = createStyles(wb);
        CellStyle title = styles.get("title");
        try
        {
            AjaxResult stat = getShopPlanStat();
            List<String> shopNames = (List<String>) stat.get("shopNames");
            List<ApsPlateProcessShopPlanStat>  table= (List<ApsPlateProcessShopPlanStat>)stat.get("data");
            SXSSFSheet sheet = wb.getSheetAt(0);
            /*填写日期列 和 工时列*/
            SXSSFRow rowTitle = sheet.createRow(0);
            SXSSFCell mainPartNumberTitle = rowTitle.createCell(0);
            mainPartNumberTitle.setCellValue("主件料号");
            mainPartNumberTitle.setCellStyle(title);
            SXSSFCell businessTypeTitle = rowTitle.createCell(1);
            businessTypeTitle.setCellValue("业务类型");
            businessTypeTitle.setCellStyle(title);
            SXSSFCell documentNumberTitle = rowTitle.createCell(2);
            documentNumberTitle.setCellValue("单据号");
            documentNumberTitle.setCellStyle(title);
            SXSSFCell requirementTypeTitle = rowTitle.createCell(3);
            requirementTypeTitle.setCellValue("需求分类");
            requirementTypeTitle.setCellStyle(title);
            SXSSFCell documentStatusTitle = rowTitle.createCell(4);
            documentStatusTitle.setCellValue("单据状态");
            documentStatusTitle.setCellStyle(title);
            SXSSFCell workCenterTitle = rowTitle.createCell(5);
            workCenterTitle.setCellValue("当前工序");
            workCenterTitle.setCellStyle(title);
            SXSSFCell itemNumberTitle = rowTitle.createCell(6);
            itemNumberTitle.setCellValue("料号");
            itemNumberTitle.setCellStyle(title);
            SXSSFCell drawingNoTitle = rowTitle.createCell(7);
            drawingNoTitle.setCellValue("图号");
            drawingNoTitle.setCellStyle(title);
            SXSSFCell versionNumberTitle = rowTitle.createCell(8);
            versionNumberTitle.setCellValue("版本号");
            versionNumberTitle.setCellStyle(title);
            SXSSFCell productionQuantityTitle = rowTitle.createCell(9);
            productionQuantityTitle.setCellValue("生产数量");
            productionQuantityTitle.setCellStyle(title);
            SXSSFCell planEndDayTitle = rowTitle.createCell(10);
            planEndDayTitle.setCellValue("计划完工日");
            planEndDayTitle.setCellStyle(title);
            for (int i = 0; i < shopNames.size(); i++) {
                String shopName = shopNames.get(i);
                SXSSFCell beginDateCell = rowTitle.createCell(i * 2 + 11);
                SXSSFCell endDateCell = rowTitle.createCell(i * 2 + 12);
                beginDateCell.setCellValue(shopName+"开工时间");
                endDateCell.setCellValue(shopName+"完工时间");
                beginDateCell.setCellStyle(title);
                endDateCell.setCellStyle(title);
            }
            for (int i = 0; i < table.size(); i++) {
                ApsPlateProcessShopPlanStat plan = table.get(i);
                /*创建数据行*/
                SXSSFRow dataRow  = sheet.createRow(i+1);
                SXSSFCell mainPartNumberCell = dataRow.createCell(0);
                mainPartNumberTitle.setCellValue(plan.getMainPartNumber());
                //mainPartNumberTitle.setCellStyle(title);
                SXSSFCell businessTypeCell= dataRow.createCell(1);
                businessTypeCell.setCellValue(plan.getBusinessType());
                //businessTypeCell.setCellStyle(title);
                SXSSFCell documentNumberCell = dataRow.createCell(2);
                documentNumberCell.setCellValue(plan.getDocumentNumber());
               // documentNumberCell.setCellStyle(title);
                SXSSFCell requirementTypeCell = dataRow.createCell(3);
                requirementTypeCell.setCellValue(plan.getRequirementType());
               // requirementTypeCell.setCellStyle(title);
                SXSSFCell documentStatusCell = dataRow.createCell(4);
                documentStatusCell.setCellValue(plan.getDocumentStatus());
               // documentStatusCell.setCellStyle(title);
                SXSSFCell workCenterCell = dataRow.createCell(5);
                workCenterCell.setCellValue(plan.getWorkCenter());
               // workCenterCell.setCellStyle(title);
                SXSSFCell itemNumberCell = dataRow.createCell(6);
                itemNumberCell.setCellValue(plan.getItemNumber());
               // itemNumberCell.setCellStyle(title);
                SXSSFCell drawingNoCell = dataRow.createCell(7);
                drawingNoCell.setCellValue(plan.getDrawingNo());
               // drawingNoCell.setCellStyle(title);
                SXSSFCell versionNumberCell = dataRow.createCell(8);
                versionNumberCell.setCellValue(plan.getVersionNumber());
              //  versionNumberCell.setCellStyle(title);
                SXSSFCell productionQuantityCell = dataRow.createCell(9);
                productionQuantityCell.setCellValue(plan.getProductionQuantity().toString());
              //  productionQuantityCell.setCellStyle(title);
                SXSSFCell planEndDayCell = dataRow.createCell(10);
                planEndDayCell.setCellValue(plan.getPlanEndDay());
              //  planEndDayCell.setCellStyle(title);
            }
            wb.write(response.getOutputStream());
        }
        catch (Exception e)
        {
            log.error("导出Excel异常{}", e.getMessage());
        }
        finally
        {
            IOUtils.closeQuietly(wb);
        }
    }
    private Map<String,CellStyle> createStyles(SXSSFWorkbook wb)
    {
        Map<String,CellStyle> styles=new HashMap<>();
        CellStyle style = wb.createCellStyle();
        style.setAlignment(HorizontalAlignment.CENTER);
        style.setVerticalAlignment(VerticalAlignment.CENTER);
        Font titleFont = wb.createFont();
        titleFont.setFontName("Arial");
        titleFont.setFontHeightInPoints((short) 12);
        titleFont.setBold(true);
        style.setFont(titleFont);
        DataFormat dataFormat = wb.createDataFormat();
        style.setDataFormat(dataFormat.getFormat("@"));
        styles.put("title", style);
        return styles;
    }
}