From 643514ba15be4c373bfdf35e2d7c64e4cbda60a4 Mon Sep 17 00:00:00 2001 From: bluejay <253316343@qq.com> Date: 星期六, 12 四月 2025 15:18:26 +0800 Subject: [PATCH] 零件统计表导出功能 --- aps-modules/aps-core/src/main/java/com/aps/core/service/impl/ApsPartRouteStatServiceImpl.java | 106 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 106 insertions(+), 0 deletions(-) diff --git a/aps-modules/aps-core/src/main/java/com/aps/core/service/impl/ApsPartRouteStatServiceImpl.java b/aps-modules/aps-core/src/main/java/com/aps/core/service/impl/ApsPartRouteStatServiceImpl.java index db51a02..2a856cb 100644 --- a/aps-modules/aps-core/src/main/java/com/aps/core/service/impl/ApsPartRouteStatServiceImpl.java +++ b/aps-modules/aps-core/src/main/java/com/aps/core/service/impl/ApsPartRouteStatServiceImpl.java @@ -8,10 +8,21 @@ import java.util.*; import java.util.stream.Collectors; +import com.aps.common.core.utils.poi.ExcelUtil; import com.aps.common.core.utils.uuid.IdUtils; import com.aps.common.core.web.domain.AjaxResult; +import com.aps.core.domain.ApsPartPlan; import com.aps.core.domain.ApsResourceDateStat; import com.aps.core.mapper.ApsResourceGroupMapper; +import jakarta.servlet.http.HttpServletResponse; +import lombok.extern.slf4j.Slf4j; +import org.apache.poi.ss.usermodel.*; +import org.apache.poi.ss.util.CellRangeAddress; +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.mapper.ApsPartRouteStatMapper; @@ -26,9 +37,11 @@ * @author zhl * @date 2025-04-11 */ +@Slf4j @Service public class ApsPartRouteStatServiceImpl implements IApsPartRouteStatService { + @Autowired private ApsPartRouteStatMapper apsPartRouteStatMapper; @Autowired @@ -210,4 +223,97 @@ return result; } + @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 = selectResourceDateStat(); + List<String> days = (List<String>) stat.get("planTitle"); + List<Map<String, List<ApsResourceDateStat>>> table= (List<Map<String, List<ApsResourceDateStat>>>) stat.get("planTable"); + SXSSFSheet sheet = wb.getSheetAt(0); + /*濉啓鏃ユ湡鍒� 鍜� 宸ユ椂鍒�*/ + SXSSFRow rowDay = sheet.createRow(0); + SXSSFRow rowTitle = sheet.createRow(1); + + SXSSFCell daytitle = rowDay.createCell(0); + daytitle.setCellValue("鏃ユ湡"); + daytitle.setCellStyle(title); + SXSSFCell titleCell = rowTitle.createCell(0); + titleCell.setCellValue("璧勬簮缁�"); + titleCell.setCellStyle(title); + + for (int i = 0; i < days.size(); i++) { + SXSSFCell dateCell = rowDay.createCell(i * 3 + 1); + SXSSFCell designHoursCell = rowTitle.createCell(i * 3 + 1); + SXSSFCell requireHoursCell = rowTitle.createCell(i * 3 + 2); + SXSSFCell loadCell = rowTitle.createCell(i * 3 + 3); + dateCell.setCellValue(days.get(i)); + designHoursCell.setCellValue("璁捐宸ユ椂"); + requireHoursCell.setCellValue("闇�姹傚伐鏃�"); + loadCell.setCellValue("浜ц兘璐熻嵎"); + /*set cell style*/ + dateCell.setCellStyle(title); + designHoursCell.setCellStyle(title); + requireHoursCell.setCellStyle(title); + loadCell.setCellStyle(title); + + /*鍚堝苟鏃ユ湡鍗曞厓鏍�*/ + sheet.addMergedRegion( new CellRangeAddress(0, 0, i*3+1, i*3+3)); + } + for (int i = 0; i < table.size(); i++) { + Map<String, List<ApsResourceDateStat>> resourceList = table.get(i); + /*鍒涘缓鏁版嵁琛�*/ + SXSSFRow dataRow = sheet.createRow(i+2); + for( Map.Entry<String, List<ApsResourceDateStat>> entry : resourceList.entrySet()){ + String resourceName = entry.getKey(); + List<ApsResourceDateStat> resourceDateStats = entry.getValue(); + dataRow.createCell(0).setCellValue(resourceName); + for (int j = 0; j < resourceDateStats.size(); j++) { + ApsResourceDateStat apsResourceDateStat = resourceDateStats.get(j); + dataRow.createCell(j*3+1).setCellValue(apsResourceDateStat.getDesignTimes()); + dataRow.createCell(j*3+2).setCellValue(apsResourceDateStat.getRequireTimes()); + dataRow.createCell(j*3+3).setCellValue(apsResourceDateStat.getCapacityLoad().doubleValue()+"%"); + } + } + + } + 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) 16); + titleFont.setBold(true); + style.setFont(titleFont); + DataFormat dataFormat = wb.createDataFormat(); + style.setDataFormat(dataFormat.getFormat("@")); + styles.put("title", style); + return styles; + } + + } -- Gitblit v1.9.3