From faafd7295f73246a4ff5895e9fdf79deb543f35d Mon Sep 17 00:00:00 2001
From: bluejay <253316343@qq.com>
Date: 星期一, 14 四月 2025 13:07:49 +0800
Subject: [PATCH] 零件工单计划:上传后删除旧的计划数据
---
aps-modules/aps-core/src/main/java/com/aps/core/service/impl/ApsPartRouteStatServiceImpl.java | 108 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 108 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..e4e515b 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,15 +8,27 @@
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;
import com.aps.core.domain.ApsPartRouteStat;
import com.aps.core.service.IApsPartRouteStatService;
+import org.springframework.transaction.annotation.Transactional;
import static java.util.stream.Collectors.groupingBy;
@@ -26,9 +38,11 @@
* @author zhl
* @date 2025-04-11
*/
+@Slf4j
@Service
public class ApsPartRouteStatServiceImpl implements IApsPartRouteStatService
{
+
@Autowired
private ApsPartRouteStatMapper apsPartRouteStatMapper;
@Autowired
@@ -112,6 +126,7 @@
/**
* 鏌ヨ闆朵欢宸ュ簭骞舵洿鏂拌鍒掑紑宸ユ棩鏈�
* */
+ @Transactional
@Override
public void updatePartRoutPlanDate() {
List<ApsPartRouteStat> tempList = apsPartRouteStatMapper.selectPartRoutStat();
@@ -210,4 +225,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) 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