From a54533effa355753fedbd53508d8f29964320a6a Mon Sep 17 00:00:00 2001
From: 于杰 <1210123631@qq.com>
Date: 星期一, 20 十月 2025 16:47:28 +0800
Subject: [PATCH] 提交 实现优化结果报告预览打印功能

---
 north-glass-erp/src/main/resources/mapper/pp/GlassOptimize.xml                           |   10 
 north-glass-erp/src/main/java/com/example/erp/controller/pp/GlassOptimizeController.java |   79 +++++++++
 north-glass-erp/src/main/java/com/example/erp/service/pp/GlassOptimizeService.java       |   80 +++++-----
 north-glass-erp/northglass-erp/src/views/pp/glassOptimize/OptimizationRectPrint.vue      |  284 +++++++++++++++++++++++++++++++++-
 north-glass-erp/northglass-erp/src/views/pp/glassOptimize/page/OptimizeCompute.vue       |    3 
 5 files changed, 398 insertions(+), 58 deletions(-)

diff --git a/north-glass-erp/northglass-erp/src/views/pp/glassOptimize/OptimizationRectPrint.vue b/north-glass-erp/northglass-erp/src/views/pp/glassOptimize/OptimizationRectPrint.vue
index 5aa0ca4..db11bd2 100644
--- a/north-glass-erp/northglass-erp/src/views/pp/glassOptimize/OptimizationRectPrint.vue
+++ b/north-glass-erp/northglass-erp/src/views/pp/glassOptimize/OptimizationRectPrint.vue
@@ -1,11 +1,11 @@
 <template>
   <div>
-    <el-button id="button" type="primary" @click="printReports" style="background: #409eff; position: fixed; top: 90px; right: 90px; padding: 20px; color: white; border: none; cursor: pointer; margin-right: 10px;">
+    <el-button id="button" type="primary" @click="previewReport" style="position: fixed; top: 90px; right: 40px; padding: 20px; background: #409eff; color: white; border: none; border-radius: 5px; cursor: pointer;">
       棰勮
     </el-button>
-    <el-button id="button" type="primary" @click="handlePrint" style="position: fixed; top: 90px; right: 20px; padding: 20px; background: #409eff; color: white; border: none; border-radius: 5px; cursor: pointer;">
-      鎵撳嵃
-    </el-button>
+<!--    <el-button id="button" type="primary" @click="printReport" style="position: fixed; top: 90px; right: 20px; padding: 20px; background: #409eff; color: white; border: none; border-radius: 5px; cursor: pointer;">-->
+<!--      鎵撳嵃-->
+<!--    </el-button>-->
 
     <div style="display: flex; align-items: center; gap: 20px; margin-bottom: 20px;">
       <span>宸ョ▼缂栧彿锛�</span>
@@ -36,10 +36,18 @@
       </el-select>
     </div>
 
+    <div v-if="pdfUrl" style="margin-top: 20px;">
+      <iframe
+          :src="pdfUrl"
+          style="width: 100%; height: 800px; border: 1px solid #ddd;"
+          title="PDF棰勮">
+      </iframe>
+    </div>
+
     <div ref="printContainer" style="position: relative;">
-      <RectRenderer 
+      <RectRenderer
         ref="rectRenderer"
-        :layoutData="layoutData" 
+        :layoutData="layoutData"
         :gw="currentGw"
         :gh="currentGh"
         :printLayout="printLayout"
@@ -81,10 +89,13 @@
 const materialDetails = ref();
 const injectedProjectNo = inject('projectNo', null);
 const state = ref();
-const columnTypes = ['涓�鍒�', '涓ゅ垪', '涓夊垪', '鍥涘垪']
-const rowTypes = ['涓�琛�', '涓よ']
+const columnTypes = ['涓�鍒�', '涓ゅ垪']
+const rowTypes = ['涓�琛�', '涓よ', '涓夎', '鍥涜']
 const glassInfo = ['涓嶆樉绀�', '鏄剧ず鍦ㄥ彸渚�', '鏄剧ず鍦ㄤ笅渚�']
 const cutInfo = ['涓嶆樉绀�', '鏄剧ず']
+const filePath = ref('');
+
+const pdfUrl = ref('');
 
 // 瀹氫箟涓嶅悓甯冨眬瀵瑰簲鐨勫昂瀵�
 const layoutDimensions = {
@@ -180,7 +191,7 @@
       });
 };
 
-const printReports = async() => {
+const generateReport = async() => {
   try {
     // 纭繚鏈夋暟鎹彲浠ユ彁浜�
     if (!processId) {
@@ -191,15 +202,15 @@
     // 鏄犲皠 rowTypes 鍒� layoutRows
     const layoutRowsMap = {
       '涓�琛�': 1,
-      '涓よ': 2
+      '涓よ': 2,
+      '涓夎': 3,
+      '鍥涜': 4
     };
 
     // 鏄犲皠 columnTypes 鍒� layoutColumns
     const layoutColumnsMap = {
       '涓�鍒�': 1,
       '涓ゅ垪': 2,
-      '涓夊垪': 3,
-      '鍥涘垪': 4
     };
 
     // 鏄犲皠 glassInfo 鍒� glassInfoShow
@@ -248,13 +259,260 @@
       }
     });
 
+    if (response.code == 200) {
+      ElMessage.success('淇濆瓨鎴愬姛');
+      filePath.value = response.data[0];
+      console.log('filePath:', filePath.value);
+    } else {
+      ElMessage.error('淇濆瓨澶辫触锛岃绋嶅悗鍐嶈瘯');
+    }
+
   } catch (error) {
     console.error('淇濆瓨澶辫触:', error);
     ElMessage.error('淇濆瓨澶辫触锛岃绋嶅悗鍐嶈瘯');
   }
 };
 
+const printReport = async () => {
+  try {
+    await generateReport();
+    if (!filePath.value) {
+      ElMessage.error('鏈敹鍒版湁鏁堢殑PDF鏂囦欢璺緞');
+      return;
+    }
+    const encodedFilePath = encodeURIComponent(filePath.value);
 
+    const response = await request.get('/glassOptimize/reports/pdf', {
+      params: { filePath: encodedFilePath },
+      responseType: 'blob',
+      headers: {
+        'Accept': 'application/pdf'
+      }
+    });
+
+    // 妫�鏌ュ搷搴旀暟鎹槸鍚﹀瓨鍦ㄤ笖鏈夋晥
+    if (!response) {
+      ElMessage.error('鏈兘鑾峰彇鍒癙DF鏁版嵁');
+      return;
+    }
+
+    const blob = new Blob([response], { type: 'application/pdf' });
+
+    // 妫�鏌� blob 鏄惁鏈夋晥
+    if (blob.size === 0) {
+      ElMessage.error('鎺ユ敹鍒扮┖鐨凱DF鏂囦欢');
+      return;
+    }
+
+    const url = URL.createObjectURL(blob);
+
+    // 鍒涘缓闅愯棌鐨� iframe
+    const iframe = document.createElement('iframe');
+    iframe.style.position = 'fixed';
+    iframe.style.left = '0';
+    iframe.style.top = '0';
+    iframe.style.width = '0';
+    iframe.style.height = '0';
+    iframe.style.border = 'none';
+    iframe.src = url;
+
+    // 鏍囪鏄惁宸茬粡娓呯悊杩囪祫婧�
+    let isCleanedUp = false;
+    // 娓呯悊璧勬簮鍑芥暟
+    const cleanup = () => {
+      if (isCleanedUp) return;
+      isCleanedUp = true;
+      URL.revokeObjectURL(url);
+      if (iframe.parentNode) {
+        iframe.parentNode.removeChild(iframe);
+      }
+    };
+
+    iframe.onload = () => {
+      setTimeout(() => {
+        try {
+          // 纭繚 iframe 鍐呭宸插姞杞藉畬鎴�
+          if (iframe.contentWindow) {
+            iframe.contentWindow.focus();
+
+            // 鐩戝惉鎵撳嵃浜嬩欢锛堟煇浜涙祻瑙堝櫒鏀寔锛�
+            const handleAfterPrint = () => {
+              window.removeEventListener('afterprint', handleAfterPrint);
+              // 寤惰繜娓呯悊锛岀‘淇濇墦鍗板畬鎴�
+              setTimeout(cleanup, 3000);
+            };
+
+            window.addEventListener('afterprint', handleAfterPrint);
+
+            // 鎵ц鎵撳嵃
+            iframe.contentWindow.print();
+            ElMessage.success('鎶ュ憡鐢熸垚鎴愬姛锛屽凡鍚姩鎵撳嵃...');
+
+            // 濡傛灉娴忚鍣ㄤ笉鏀寔 afterprint 浜嬩欢锛岃缃秴鏃舵竻鐞�
+            setTimeout(cleanup, 10000);
+          }
+        } catch (printError) {
+          console.error('鎵撳嵃杩囩▼涓嚭閿�:', printError);
+          // 濡傛灉绋嬪簭鍖栨墦鍗板け璐ワ紝鑷冲皯鎵撳紑 PDF 渚涚敤鎴锋墜鍔ㄦ墦鍗�
+          window.open(url, '_blank');
+          ElMessage.info('宸叉墦寮�PDF鏂囦欢锛岃鎵嬪姩鎵撳嵃');
+          cleanup();
+        }
+      }, 1000); // 缁欐洿澶氭椂闂寸‘淇漃DF瀹屽叏娓叉煋
+    };
+
+    iframe.onerror = () => {
+      console.error('PDF 鍔犺浇澶辫触');
+      ElMessage.error('PDF 鏂囦欢鍔犺浇澶辫触锛岃閲嶈瘯');
+      cleanup();
+    };
+
+    document.body.appendChild(iframe);
+
+  } catch (error) {
+    console.error('鎵撳嵃娴佺▼寮傚父:', error);
+
+    if (error.response) {
+      const status = error.response.status;
+      if (status === 400) {
+        ElMessage.error('鏂囦欢璺緞鏃犳晥鎴栦笉鏄疨DF');
+      } else if (status === 404) {
+        ElMessage.error('PDF 鏂囦欢涓嶅瓨鍦�');
+      } else {
+        ElMessage.error(`鏈嶅姟鍣ㄩ敊璇� (${status})锛岃绋嶅悗鍐嶈瘯`);
+      }
+    } else if (error.request) {
+      ElMessage.error('缃戠粶閿欒锛岃妫�鏌ヨ繛鎺�');
+    } else {
+      ElMessage.error('鎵撳嵃澶辫触锛岃绋嶅悗鍐嶈瘯');
+    }
+  }
+};
+
+
+
+const previewReport = async () => {
+  try {
+    await generateReport();
+    if (!filePath.value) {
+      ElMessage.error('鏈敹鍒版湁鏁堢殑PDF鏂囦欢璺緞');
+      return;
+    }
+    const encodedFilePath = encodeURIComponent(filePath.value);
+
+    const response = await request.get('/glassOptimize/reports/pdf', {
+      params: { filePath: encodedFilePath },
+      responseType: 'blob',
+      headers: {
+        'Accept': 'application/pdf'
+      }
+    });
+
+    // 妫�鏌ュ搷搴旀暟鎹槸鍚﹀瓨鍦ㄤ笖鏈夋晥
+    if (!response) {
+      ElMessage.error('鏈兘鑾峰彇鍒癙DF鏁版嵁');
+      return;
+    }
+
+    const blob = new Blob([response], { type: 'application/pdf' });
+
+    // 妫�鏌� blob 鏄惁鏈夋晥
+    if (blob.size === 0) {
+      ElMessage.error('鎺ユ敹鍒扮┖鐨凱DF鏂囦欢');
+      return;
+    }
+
+    // 鍒涘缓PDF URL骞惰祴鍊肩粰pdfUrl鐢ㄤ簬鐣岄潰鏄剧ず
+    const url = URL.createObjectURL(blob);
+    pdfUrl.value = url;
+
+    ElMessage.success('鎶ュ憡鐢熸垚鎴愬姛锛屾鍦ㄩ瑙�...');
+
+    // 鍙�夛細娣诲姞娓呯悊鏈哄埗锛屽綋缁勪欢鍗歌浇鏃舵竻鐞哢RL
+    // 杩欓噷鍙互浣跨敤 onUnmounted 閽╁瓙杩涜娓呯悊
+  } catch (error) {
+    console.error('棰勮娴佺▼寮傚父:', error);
+
+    if (error.response) {
+      const status = error.response.status;
+      if (status === 400) {
+        ElMessage.error('鏂囦欢璺緞鏃犳晥鎴栦笉鏄疨DF');
+      } else if (status === 404) {
+        ElMessage.error('PDF 鏂囦欢涓嶅瓨鍦�');
+      } else {
+        ElMessage.error(`鏈嶅姟鍣ㄩ敊璇� (${status})锛岃绋嶅悗鍐嶈瘯`);
+      }
+    } else if (error.request) {
+      ElMessage.error('缃戠粶閿欒锛岃妫�鏌ヨ繛鎺�');
+    } else {
+      ElMessage.error('棰勮澶辫触锛岃绋嶅悗鍐嶈瘯');
+    }
+  }
+};
+
+const autoPreviewReport = async () => {
+  try {
+    await generateReport();
+    if (!filePath.value) {
+      // 濡傛灉娌℃湁鏂囦欢璺緞锛屼笉鎵ц棰勮
+      return;
+    }
+    const encodedFilePath = encodeURIComponent(filePath.value);
+
+    const response = await request.get('/glassOptimize/reports/pdf', {
+      params: { filePath: encodedFilePath },
+      responseType: 'blob',
+      headers: {
+        'Accept': 'application/pdf'
+      }
+    });
+
+    // 妫�鏌ュ搷搴旀暟鎹槸鍚﹀瓨鍦ㄤ笖鏈夋晥
+    if (!response) {
+      ElMessage.error('鏈兘鑾峰彇鍒癙DF鏁版嵁');
+      return;
+    }
+
+    const blob = new Blob([response], { type: 'application/pdf' });
+
+    // 妫�鏌� blob 鏄惁鏈夋晥
+    if (blob.size === 0) {
+      ElMessage.error('鎺ユ敹鍒扮┖鐨凱DF鏂囦欢');
+      return;
+    }
+
+    // 鍒涘缓PDF URL骞惰祴鍊肩粰 pdfUrl 鐢ㄤ簬鐣岄潰鏄剧ず
+    const url = URL.createObjectURL(blob);
+    pdfUrl.value = url;
+
+  } catch (error) {
+    console.error('鑷姩棰勮娴佺▼寮傚父:', error);
+  }
+};
+
+onMounted(() => {
+  // 浼樺厛浣跨敤娉ㄥ叆鐨� projectNo锛屽叾娆′娇鐢� props锛屾渶鍚庝娇鐢� localStorage
+  if (injectedProjectNo) {
+    processId.value = injectedProjectNo.value || injectedProjectNo;
+  } else if (props.project) {
+    processId.value = props.project.projectNumber || '';
+    state.value = props.state;
+  } else if (savedProjectNo) {
+    processId.value = savedProjectNo;
+  }
+
+  if (processId.value) {
+    selectLayout();
+    selectReportData();
+    selectMaterialData();
+    selectProductData();
+
+    // 鏁版嵁鍔犺浇瀹屾垚鍚庤嚜鍔ㄩ瑙�
+    setTimeout(() => {
+      autoPreviewReport();
+    }, 1000); // 寤惰繜1绉掔‘淇濇墍鏈夋暟鎹姞杞藉畬鎴�
+  }
+});
 
 const config = reactive({
   columnTypes: '涓ゅ垪',
@@ -299,7 +557,7 @@
   currentGh.value = dimensions.height;
   currentPrintWidth.value = dimensions.width;
   currentPrintHeight.value = dimensions.height;
-  
+
   if (rectRenderer.value) {
     rectRenderer.value.updateLayout();
   }
diff --git a/north-glass-erp/northglass-erp/src/views/pp/glassOptimize/page/OptimizeCompute.vue b/north-glass-erp/northglass-erp/src/views/pp/glassOptimize/page/OptimizeCompute.vue
index 687e082..9334bd7 100644
--- a/north-glass-erp/northglass-erp/src/views/pp/glassOptimize/page/OptimizeCompute.vue
+++ b/north-glass-erp/northglass-erp/src/views/pp/glassOptimize/page/OptimizeCompute.vue
@@ -109,6 +109,9 @@
                   leftTrim: items.leftTrim,
                   rightTrim: items.rightTrim,
                   stockCode: items.stockCode,
+                  glassArea: items.glassArea,
+                  glassQuantity: items.glassQuantity,
+                  usageRate: items.usageRate,
                   count: 1
                 });
               }
diff --git a/north-glass-erp/src/main/java/com/example/erp/controller/pp/GlassOptimizeController.java b/north-glass-erp/src/main/java/com/example/erp/controller/pp/GlassOptimizeController.java
index bdee6f6..c4c586a 100644
--- a/north-glass-erp/src/main/java/com/example/erp/controller/pp/GlassOptimizeController.java
+++ b/north-glass-erp/src/main/java/com/example/erp/controller/pp/GlassOptimizeController.java
@@ -1,6 +1,6 @@
 package com.example.erp.controller.pp;
 
-import cn.dev33.satoken.annotation.SaCheckPermission;
+import org.springframework.core.io.InputStreamResource;
 import com.example.erp.common.Constants;
 import com.example.erp.common.Result;
 import com.example.erp.entity.pp.LayoutsData;
@@ -10,7 +10,6 @@
 import com.example.erp.service.pp.JsonToOptConverter;
 import com.example.erp.service.userInfo.UserService;
 import com.fasterxml.jackson.core.JsonProcessingException;
-import com.fasterxml.jackson.databind.ObjectMapper;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -19,7 +18,11 @@
 import org.springframework.http.ResponseEntity;
 import org.springframework.web.bind.annotation.*;
 
+import java.io.File;
+import java.io.FileInputStream;
 import java.io.IOException;
+import java.nio.file.Path;
+import java.nio.file.Paths;
 import java.sql.Date;
 import java.util.Map;
 
@@ -335,6 +338,78 @@
     }
 
 
+    @CrossOrigin(origins = "*")
+    @ApiOperation("PDF鏂囦欢涓嬭浇鎺ュ彛")
+    @GetMapping("/reports/pdf")
+    public ResponseEntity<InputStreamResource> downloadPdf(@RequestParam String filePath) {
+        try {
+            String decodedPath = java.net.URLDecoder.decode(filePath, "UTF-8");
+            System.out.println("鎺ユ敹鍒扮殑鏂囦欢璺緞: " + decodedPath);
+
+            // 鏀惧楠岃瘉鏉′欢锛屼粎妫�鏌ュ繀瑕佹潯浠�
+            if (decodedPath == null || decodedPath.trim().isEmpty()) {
+                System.out.println("鏂囦欢璺緞涓虹┖");
+                return ResponseEntity.badRequest().build();
+            }
+
+            // 妫�鏌ユ槸鍚︿负PDF鏂囦欢锛堜笉涓ユ牸妫�鏌ュ紑澶达級
+            if (!decodedPath.trim().toLowerCase().endsWith(".pdf")) {
+                System.out.println("鏂囦欢涓嶆槸PDF鏍煎紡: " + decodedPath);
+                return ResponseEntity.badRequest().build();
+            }
+
+            // 澶勭悊璺緞锛屾纭鐞哤indows缃戠粶璺緞
+            String processedPath = decodedPath.trim();
+            // 纭繚缃戠粶璺緞鏍煎紡姝g‘
+            if (processedPath.startsWith("\\\\")) {
+                // 宸茬粡鏄纭殑缃戠粶璺緞鏍煎紡
+                System.out.println("妫�娴嬪埌Windows缃戠粶璺緞: " + processedPath);
+            } else if (processedPath.startsWith("\\")) {
+                // 琛ュ叏缃戠粶璺緞
+                processedPath = "\\" + processedPath;
+                System.out.println("琛ュ叏缃戠粶璺緞涓�: " + processedPath);
+            }
+
+            System.out.println("澶勭悊鍚庣殑鏂囦欢璺緞: " + processedPath);
+
+            // 鏋勯�犳枃浠惰矾寰�
+            File file = new File(processedPath);
+            System.out.println("鏋勯�犵殑鏂囦欢缁濆璺緞: " + file.getAbsolutePath());
+            System.out.println("鏂囦欢瑙勮寖璺緞: " + file.getCanonicalPath());
+
+            // 妫�鏌ユ枃浠舵槸鍚﹀瓨鍦�
+            if (!file.exists()) {
+                System.out.println("鏂囦欢涓嶅瓨鍦�: " + file.getAbsolutePath());
+                return ResponseEntity.notFound().build();
+            }
+
+            // 妫�鏌ユ槸鍚︿负鏂囦欢锛堣�岄潪鐩綍锛�
+            if (!file.isFile()) {
+                System.out.println("璺緞涓嶆槸鏂囦欢: " + file.getAbsolutePath());
+                return ResponseEntity.badRequest().build();
+            }
+
+            // 鍒涘缓Resource
+            InputStreamResource resource = new InputStreamResource(new FileInputStream(file));
+
+            // 璁剧疆鍝嶅簲澶�
+            HttpHeaders headers = new HttpHeaders();
+            headers.add(HttpHeaders.CONTENT_DISPOSITION, "inline; filename=\"" + file.getName() + "\"");
+            headers.add(HttpHeaders.CONTENT_TYPE, "application/pdf");
+            headers.add(HttpHeaders.CONTENT_LENGTH, String.valueOf(file.length()));
+            headers.add(HttpHeaders.ACCESS_CONTROL_EXPOSE_HEADERS, HttpHeaders.CONTENT_DISPOSITION);
+
+            return ResponseEntity.ok()
+                    .headers(headers)
+                    .contentType(org.springframework.http.MediaType.APPLICATION_PDF)
+                    .body(resource);
+
+        } catch (Exception e) {
+            e.printStackTrace();
+            return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
+        }
+    }
+
 
 
 
diff --git a/north-glass-erp/src/main/java/com/example/erp/service/pp/GlassOptimizeService.java b/north-glass-erp/src/main/java/com/example/erp/service/pp/GlassOptimizeService.java
index deb63ae..dabfe6f 100644
--- a/north-glass-erp/src/main/java/com/example/erp/service/pp/GlassOptimizeService.java
+++ b/north-glass-erp/src/main/java/com/example/erp/service/pp/GlassOptimizeService.java
@@ -1245,49 +1245,49 @@
 
     public Map<String, Object> getMaterialInfoSv(String processId) {
         Map<String, Object> map = new HashMap<>();
-        List<Map<String, Object>> materialList = glassOptimizeMapper.getMaterialInfoSv(processId);
+//        List<Map<String, Object>> materialList = glassOptimizeMapper.getMaterialInfoSv(processId);
         List<Map<String, Object>> layoutSet = glassOptimizeMapper.getLayoutSetSv(processId);
 
-        // 鍒涘缓涓�涓狹ap鏉ュ瓨鍌ㄦ瘡涓猻tock_code鐨勬�婚潰绉�
-        Map<String, Double> stockCodeAreaMap = new HashMap<>();
+//        // 鍒涘缓涓�涓狹ap鏉ュ瓨鍌ㄦ瘡涓猻tock_code鐨勬�婚潰绉�
+//        Map<String, Double> stockCodeAreaMap = new HashMap<>();
+//
+//        // 閬嶅巻layoutSet璁$畻姣忎釜stock_code鐨勬�婚潰绉�(闈㈢Н*浣跨敤鐜�)
+//        for (Map<String, Object> layout : layoutSet) {
+//            Object stockCodeObj = layout.get("stock_code");
+//            Object widthObj = layout.get("width");
+//            Object heightObj = layout.get("height");
+//            Object usageRateObj = layout.get("usage_rate");
+//
+//            if (stockCodeObj != null && widthObj != null && heightObj != null && usageRateObj != null) {
+//                try {
+//                    String stockCode = stockCodeObj.toString();
+//                    double width = Double.parseDouble(widthObj.toString());
+//                    double height = Double.parseDouble(heightObj.toString());
+//                    double usageRate = Double.parseDouble(usageRateObj.toString());
+//
+//                    // 璁$畻鍗曟潯鏁版嵁鐨勯潰绉�(骞虫柟绫�)
+//                    double area = (width * height * usageRate) / 1000000.0;
+//
+//                    // 绱姞鍒板搴攕tock_code鐨勬�婚潰绉�
+//                    stockCodeAreaMap.put(stockCode, stockCodeAreaMap.getOrDefault(stockCode, 0.0) + area);
+//                } catch (NumberFormatException e) {
+//                    System.err.println("鏁版嵁杞崲閿欒: " + e.getMessage());
+//                }
+//            }
+//        }
+//
+//        // 灏嗚绠楀嚭鐨勬�婚潰绉坊鍔犲埌materialList涓搴旂殑鐗╂枡鏁版嵁
+//        for (Map<String, Object> material : materialList) {
+//            Object stockCodeObj = material.get("code");
+//            if (stockCodeObj != null) {
+//                String stockCode = stockCodeObj.toString();
+//                if (stockCodeAreaMap.containsKey(stockCode)) {
+//                    material.put("totalArea", stockCodeAreaMap.get(stockCode));
+//                }
+//            }
+//        }
 
-        // 閬嶅巻layoutSet璁$畻姣忎釜stock_code鐨勬�婚潰绉�(闈㈢Н*浣跨敤鐜�)
-        for (Map<String, Object> layout : layoutSet) {
-            Object stockCodeObj = layout.get("stock_code");
-            Object widthObj = layout.get("width");
-            Object heightObj = layout.get("height");
-            Object usageRateObj = layout.get("usage_rate");
-
-            if (stockCodeObj != null && widthObj != null && heightObj != null && usageRateObj != null) {
-                try {
-                    String stockCode = stockCodeObj.toString();
-                    double width = Double.parseDouble(widthObj.toString());
-                    double height = Double.parseDouble(heightObj.toString());
-                    double usageRate = Double.parseDouble(usageRateObj.toString());
-
-                    // 璁$畻鍗曟潯鏁版嵁鐨勯潰绉�(骞虫柟绫�)
-                    double area = (width * height * usageRate) / 1000000.0;
-
-                    // 绱姞鍒板搴攕tock_code鐨勬�婚潰绉�
-                    stockCodeAreaMap.put(stockCode, stockCodeAreaMap.getOrDefault(stockCode, 0.0) + area);
-                } catch (NumberFormatException e) {
-                    System.err.println("鏁版嵁杞崲閿欒: " + e.getMessage());
-                }
-            }
-        }
-
-        // 灏嗚绠楀嚭鐨勬�婚潰绉坊鍔犲埌materialList涓搴旂殑鐗╂枡鏁版嵁
-        for (Map<String, Object> material : materialList) {
-            Object stockCodeObj = material.get("code");
-            if (stockCodeObj != null) {
-                String stockCode = stockCodeObj.toString();
-                if (stockCodeAreaMap.containsKey(stockCode)) {
-                    material.put("totalArea", stockCodeAreaMap.get(stockCode));
-                }
-            }
-        }
-
-        map.put("materialList", materialList);
+        map.put("materialList", layoutSet);
         return map;
     }
 
diff --git a/north-glass-erp/src/main/resources/mapper/pp/GlassOptimize.xml b/north-glass-erp/src/main/resources/mapper/pp/GlassOptimize.xml
index 5e9e4e8..d879ee7 100644
--- a/north-glass-erp/src/main/resources/mapper/pp/GlassOptimize.xml
+++ b/north-glass-erp/src/main/resources/mapper/pp/GlassOptimize.xml
@@ -2051,9 +2051,13 @@
     <select id="getLayoutSetSv" resultType="java.util.Map">
         SELECT
             project_no,
-            width,height,
-            usage_rate,
-            stock_code
+            stock_code as code,
+            realwidth AS width,
+            realheight AS height,
+            usage_rate as usageRate,
+            glass_count as polyQuantity,
+            glass_area AS glassArea
+
         FROM
             pp.optimize_layout
         WHERE

--
Gitblit v1.8.0