From 55aa346da75b77ced451b2fe456a144ac107813e Mon Sep 17 00:00:00 2001 From: zhanghl <253316343@qq.com> Date: 星期四, 24 四月 2025 13:34:55 +0800 Subject: [PATCH] 钣金计划大表-导出接口 --- aps-modules/aps-core/src/main/java/com/aps/core/service/impl/ApsPlateProcessShopStatServiceImpl.java | 178 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 files changed, 175 insertions(+), 3 deletions(-) diff --git a/aps-modules/aps-core/src/main/java/com/aps/core/service/impl/ApsPlateProcessShopStatServiceImpl.java b/aps-modules/aps-core/src/main/java/com/aps/core/service/impl/ApsPlateProcessShopStatServiceImpl.java index a46d13c..c627314 100644 --- a/aps-modules/aps-core/src/main/java/com/aps/core/service/impl/ApsPlateProcessShopStatServiceImpl.java +++ b/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, "閽i噾璁″垝琛�"); + 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; + } + } -- Gitblit v1.9.3