From 04d2803720568c1e7227e205d0f27cf9b83a2f00 Mon Sep 17 00:00:00 2001
From: zhanghl <253316343@qq.com>
Date: 星期二, 06 五月 2025 14:47:04 +0800
Subject: [PATCH] BOM 基础代码

---
 aps-modules/aps-core/src/main/java/com/aps/core/service/impl/ApsPlateProcessShopStatServiceImpl.java |  306 +++++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 298 insertions(+), 8 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 dcaec74..10103b4 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
@@ -1,5 +1,6 @@
 package com.aps.core.service.impl;
 
+import java.text.SimpleDateFormat;
 import java.util.*;
 import java.util.stream.Collectors;
 
@@ -7,11 +8,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;
@@ -121,7 +131,7 @@
 
             // 瀹氫箟璇ュ姛鑳戒娇鐢ㄦ暟鎹簮涓哄崡閫氱殑宸ュ巶
             final String plant = "FORTUNA";
-
+            final String major="閽i噾";
             // 鏌ヨ鐩稿叧鏁版嵁
             ApsPlatePlan platePlan = new ApsPlatePlan();
             platePlan.setPlant(plant);
@@ -135,6 +145,7 @@
 
             ApsStandardProcess process = new ApsStandardProcess();
             process.setPlant(plant);
+            process.setMajor(major);
             List<ApsStandardProcess> shopProcesses = standardProcessMapper.selectApsStandardProcessList(process);
             if (planList.isEmpty() || shopList.isEmpty() || shopProcesses.isEmpty()) {
                 log.warn("璁″垝鍒楄〃銆佽溅闂村垪琛ㄦ垨宸ュ簭鍒楄〃涓虹┖锛屾棤娉曠敓鎴愮粺璁′俊鎭�");
@@ -181,7 +192,8 @@
         stat.setDelFlag("0");
         stat.setCreateBy(SecurityUtils.getUsername());
         stat.setCreateTime(DateUtils.getNowDate());
-
+        stat.setWorkCenter(plan.getWorkCenter());
+        stat.setProcessNumber(plan.getProcessNumber());
         try {
 
 
@@ -189,8 +201,9 @@
             if (!processNames.isEmpty()) {
                 // 鏍规嵁宸ュ簭鍚嶇О锛屾煡璇㈣宸ュ崟涓嬫墍鏈夌殑宸ュ簭淇℃伅
                 List<ApsPlateProcessStat> processStats = statList.stream()
-                        .filter(x -> processNames.contains(x.getProcessName()) && x.getWorkOrderNo().equals(plan.getDocumentNumber()))
-                        .toList();
+                        .filter(x -> processNames.contains(x.getProcessName()) && x.getWorkOrderNo().equals(plan.getDocumentNumber())
+                            &&x.getProcessPlanStartDay()!=null&&x.getProcessPlanEndDay()!=null
+                        ).toList();
                 if (!processStats.isEmpty()) {
                     // 鍙栧嚭宸ュ崟涓嬪伐搴忕殑鏈�灏忓紑濮嬫椂闂村拰鏈�澶х粨鏉熸椂闂�
                     List<Date> startDayList = processStats.stream().map(ApsPlateProcessStat::getProcessPlanStartDay).filter(Objects::nonNull).toList();
@@ -259,6 +272,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 -> {
@@ -268,16 +285,289 @@
                     // 鏍规嵁 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 approveDateTitle = rowTitle.createCell(5);
+            approveDateTitle.setCellValue("瀹℃牳鏃堕棿");
+            approveDateTitle.setCellStyle(title);
+
+            SXSSFCell workCenterTitle = rowTitle.createCell(6);
+            workCenterTitle.setCellValue("褰撳墠宸ュ簭");
+            workCenterTitle.setCellStyle(title);
+
+            SXSSFCell departmentTitle = rowTitle.createCell(7);
+            departmentTitle.setCellValue("褰撳墠宸ュ簭璐熻矗浜�");
+            departmentTitle.setCellStyle(title);
+
+            SXSSFCell crtPcsStsTitle = rowTitle.createCell(8);
+            crtPcsStsTitle.setCellValue("褰撳墠宸ュ簭鐘舵��");
+            crtPcsStsTitle.setCellStyle(title);
+
+            SXSSFCell nextProcessTitle = rowTitle.createCell(9);
+            nextProcessTitle.setCellValue("涓嬩竴宸ュ簭");
+            nextProcessTitle.setCellStyle(title);
+
+
+            SXSSFCell nextProcessDeparmentTitle = rowTitle.createCell(10);
+            nextProcessDeparmentTitle.setCellValue("涓嬩竴宸ュ簭璐熻矗浜�");
+            nextProcessDeparmentTitle.setCellStyle(title);
+
+            SXSSFCell itemNumberTitle = rowTitle.createCell(11);
+            itemNumberTitle.setCellValue("鏂欏彿");
+            itemNumberTitle.setCellStyle(title);
+
+            SXSSFCell drawingNoTitle = rowTitle.createCell(12);
+            drawingNoTitle.setCellValue("鍥惧彿");
+            drawingNoTitle.setCellStyle(title);
+
+            SXSSFCell versionNumberTitle = rowTitle.createCell(13);
+            versionNumberTitle.setCellValue("鐗堟湰鍙�");
+            versionNumberTitle.setCellStyle(title);
+
+            SXSSFCell lowNumTitle = rowTitle.createCell(14);
+            lowNumTitle.setCellValue("浣庨樁鐮�");
+            lowNumTitle.setCellStyle(title);
+
+
+            SXSSFCell productionQuantityTitle = rowTitle.createCell(15);
+            productionQuantityTitle.setCellValue("鐢熶骇鏁伴噺");
+            productionQuantityTitle.setCellStyle(title);
+
+            SXSSFCell planSendDateTitle = rowTitle.createCell(16);
+            planSendDateTitle.setCellValue("宸ュ崟璁″垝涓嬪彂鏃堕棿");
+            planSendDateTitle.setCellStyle(title);
+
+
+
+            SXSSFCell planEndDayTitle = rowTitle.createCell(17);
+            planEndDayTitle.setCellValue("绯荤粺瀹屽伐鏃堕棿");
+            planEndDayTitle.setCellStyle(title);
+
+
+
+
+
+            String firstShopName = shopNames.get(0);
+            SXSSFCell firstShopBeginDateTitle = rowTitle.createCell(18);
+            firstShopBeginDateTitle.setCellValue(firstShopName+"寮�宸ユ椂闂�");
+            firstShopBeginDateTitle.setCellStyle(title);
+            SXSSFCell firstShopEndDateTitle = rowTitle.createCell(19);
+            firstShopEndDateTitle.setCellValue(firstShopName+"瀹屽伐鏃堕棿");
+            firstShopEndDateTitle.setCellStyle(title);
+
+            /*鐒婃帴浠堕綈濂�*/
+            SXSSFCell hanJieQiTaoTitle= rowTitle.createCell(20);
+            hanJieQiTaoTitle.setCellValue("鐒婃帴浠堕綈濂楀紑濮嬫椂闂�");
+            hanJieQiTaoTitle.setCellStyle(title);
+
+            int i1 = 19;
+
+            for (int i = 1; i < shopNames.size(); i++) {
+                String shopName = shopNames.get(i);
+                SXSSFCell beginDateCell = rowTitle.createCell(i * 2 + i1);
+                SXSSFCell endDateCell = rowTitle.createCell(i * 2 + i1+1);
+                beginDateCell.setCellValue(shopName+"寮�宸ユ椂闂�");
+                endDateCell.setCellValue(shopName+"瀹屽伐鏃堕棿");
+                beginDateCell.setCellStyle(title);
+                endDateCell.setCellStyle(title);
+            }
+            SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+            for (int i = 0; i < table.size(); i++) {
+                ApsPlateProcessShopPlanStat plan = table.get(i);
+
+                SXSSFRow dataRow  = sheet.createRow(i+1);
+                //涓讳欢鏂欏彿
+                SXSSFCell mainPartNumberCell = dataRow.createCell(0);
+                mainPartNumberCell.setCellValue(plan.getMainPartNumber());
+
+                //涓氬姟绫诲瀷;
+                SXSSFCell businessTypeCell= dataRow.createCell(1);
+                businessTypeCell.setCellValue(plan.getBusinessType());
+
+                //鍗曟嵁鍙�;
+                SXSSFCell documentNumberCell = dataRow.createCell(2);
+                documentNumberCell.setCellValue(plan.getDocumentNumber());
+
+                //闇�姹傚垎绫�;
+                SXSSFCell requirementTypeCell = dataRow.createCell(3);
+                requirementTypeCell.setCellValue(plan.getRequirementType());
+
+                // 鍗曟嵁鐘舵��
+                SXSSFCell documentStatusCell = dataRow.createCell(4);
+                documentStatusCell.setCellValue(plan.getDocumentStatus());
+
+
+                // 瀹℃牳鏃堕棿
+                SXSSFCell approveDateCell = dataRow.createCell(5);
+                approveDateCell.setCellValue("");
+
+                //褰撳墠宸ュ簭
+                SXSSFCell workCenterCell = dataRow.createCell(6);
+                workCenterCell.setCellValue(plan.getWorkCenter());
+
+                //褰撳墠宸ュ簭璐熻矗浜�;
+                SXSSFCell departmentCell = dataRow.createCell(7);
+                departmentCell.setCellValue(plan.getDepartment());
+
+                /*褰撳墠宸ュ簭鐘舵��*/
+                SXSSFCell crtPcsStsCell = dataRow.createCell(8);
+                crtPcsStsCell.setCellValue(plan.getOpStatus());
+
+
+                //涓嬩竴宸ュ簭
+                SXSSFCell nextProcessCell = dataRow.createCell(9);
+                nextProcessCell.setCellValue(plan.getNextOpName());
+
+                //涓嬩竴宸ュ簭宸ュ簭璐熻矗浜�
+                SXSSFCell nextProcessDeparmentCell = dataRow.createCell(10);
+                nextProcessDeparmentCell.setCellValue(plan.getNextProcessDeparment());
+
+                //鏂欏彿
+                SXSSFCell itemNumberCell = dataRow.createCell(11);
+                itemNumberCell.setCellValue(plan.getItemNumber());
+
+                // 鍥惧彿
+                SXSSFCell drawingNoCell = dataRow.createCell(12);
+                drawingNoCell.setCellValue(plan.getDrawingNo());
+
+               //鐗堟湰鍙�
+                SXSSFCell versionNumberCell = dataRow.createCell(13);
+                versionNumberCell.setCellValue(plan.getVersionNumber());
+
+                //浣庨樁鐮�
+                SXSSFCell lowNumCell = dataRow.createCell(14);
+                lowNumCell.setCellValue("");
+
+                //鐢熶骇鏁伴噺
+                SXSSFCell productionQuantityCell = dataRow.createCell(15);
+                productionQuantityCell.setCellValue(plan.getProductionQuantity().toString());
+
+                //宸ュ崟璁″垝涓嬪彂鏃堕棿
+                SXSSFCell planSendDateCell = dataRow.createCell(16);
+                planSendDateCell.setCellValue("");
+
+                //绯荤粺瀹屽伐鏃堕棿
+                SXSSFCell planEndDayCell = dataRow.createCell(17);
+                planEndDayCell.setCellValue(dateFormat.format(plan.getPlanEndDay()));
+
+
+
+
+                SXSSFCell firstShopBeginDateCell = dataRow.createCell(18);
+                SXSSFCell firstShopEndDateCell = dataRow.createCell(19);
+
+                plan.getDeptPlans().stream().filter(x->x.getShopName().equals(firstShopName)).findFirst().ifPresent(x->{
+                    firstShopBeginDateCell.setCellValue(x.getPlanStartDate());
+                    firstShopEndDateCell.setCellValue(x.getPlanEndDate());
+                });
+                /*鐒婃帴浠堕綈濂�*/
+                SXSSFCell hanJieQiTaoCell = dataRow.createCell(20);
+                hanJieQiTaoCell.setCellValue("");
+
+
+                for (int j = 1; j< shopNames.size(); j++) {
+                    String shopName = shopNames.get(j);
+                    SXSSFCell beginDateCell = dataRow.createCell(j * 2 + i1);
+                    SXSSFCell endDateCell = dataRow.createCell(j * 2 + i1+1);
+                    plan.getDeptPlans().stream().filter(x->x.getShopName().equals(shopName)).findFirst().ifPresent(x->{
+                        beginDateCell.setCellValue(x.getPlanStartDate());
+                        endDateCell.setCellValue(x.getPlanEndDate());
+                    });
+                }
+
+
+            }
+
+            for (int i = 0; i <  rowTitle.getLastCellNum(); i++) {
+
+                sheet.setColumnWidth(i, 20 * 256);
+            }
+            
+            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