From 128f28de7eac9bf585f0909e9bdc8e299670f58c Mon Sep 17 00:00:00 2001
From: whycxzp <glperry@163.com>
Date: 星期四, 26 六月 2025 20:29:50 +0800
Subject: [PATCH] 设备器件excel导入

---
 src/main/java/com/whyc/service/DeviceSpareService.java |   51 ++++++++++++++++++++++++++++++++++++++++++++++-----
 1 files changed, 46 insertions(+), 5 deletions(-)

diff --git a/src/main/java/com/whyc/service/DeviceSpareService.java b/src/main/java/com/whyc/service/DeviceSpareService.java
index 72a0fea..f00e1ec 100644
--- a/src/main/java/com/whyc/service/DeviceSpareService.java
+++ b/src/main/java/com/whyc/service/DeviceSpareService.java
@@ -12,7 +12,9 @@
 import com.whyc.util.CommonUtil;
 import com.whyc.util.ThreadLocalUtil;
 import org.apache.commons.lang.StringUtils;
+import org.apache.poi.openxml4j.opc.OPCPackage;
 import org.apache.poi.ss.usermodel.*;
+import org.apache.poi.xssf.usermodel.*;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
@@ -20,6 +22,7 @@
 
 import javax.annotation.Resource;
 import java.io.File;
+import java.io.FileOutputStream;
 import java.io.IOException;
 import java.util.ArrayList;
 import java.util.Date;
@@ -229,12 +232,50 @@
             spare.setSupplier(supplier);
 
             spareList.add(spare);
-            //绗竷鍒椾负鍥剧墖 TODO 寰呭鐞�
-            /*Cell cell = row.getCell(7);
-            CellType cellType = cell.getCellType();
-            System.out.println("-");*/
+
         }
-        addBatch(spareList);
+
+        //绗竷鍒椾负鍥剧墖-娴姩寮忓浘鐗� TODO 寰呭鐞� 澶勭悊宸插瓨鍦ㄧ殑鐗╂枡
+        //鑾峰彇缁樺浘瀵硅薄涓殑鎵�鏈夊浘褰�
+        XSSFDrawing drawing = (XSSFDrawing) sheet.getDrawingPatriarch();
+        if (drawing == null) {
+            drawing = (XSSFDrawing) sheet.createDrawingPatriarch();
+        }
+        List<XSSFShape> shapes = drawing.getShapes();
+        for (XSSFShape shape : shapes) {
+            if (shape instanceof XSSFPicture) {
+                XSSFPicture pic = (XSSFPicture) shape;
+                XSSFClientAnchor anchor = pic.getClientAnchor();
+                //鑾峰彇鍥剧墖鎵�鍦ㄧ殑璧峰琛�
+                int rowIndex = anchor.getRow1();
+                byte[] data = pic.getPictureData().getData();
+
+                DeviceSpare spare = spareList.get(rowIndex - 1);
+                //瀵瑰瓨鍌ㄨ矾寰勮繘琛屽畾涔�
+                Date now = new Date();
+                String timeFormat = ThreadLocalUtil.format(ThreadLocalUtil.TIME_YYYY_MM_DD_HH_MM_SS_UNION, now);
+                String dirMonth = ThreadLocalUtil.format(ThreadLocalUtil.TIME_YYYY_MM, now);
+                String fileDirPath = CommonUtil.getRootFile() + "deviceSpare" + File.separator + dirMonth;
+                File fileDir = new File(fileDirPath);
+                //濡傛灉鏂囦欢澶逛笉瀛樺湪鍒欏垱寤�
+                if (!fileDir.exists()) {
+                    fileDir.mkdirs();
+                }
+                String filePath = fileDirPath + File.separator + timeFormat+"_"+spare.getName()+"_"+spare.getModel()+"_"+spare.getVersion()+".png";
+
+                // 淇濆瓨鍥剧墖鍒版湰鍦�
+                try (FileOutputStream fos = new FileOutputStream(filePath)) {
+                    fos.write(data);
+                }
+                String split = "pis_file"+File.separator+"deviceSpare";
+                String picUrl = File.separator + filePath.substring(filePath.indexOf(split));
+                spare.setPictureUrl(picUrl);
+            }
+
+        }
+
+
+        //addBatch(spareList);
 
         return null;
     }

--
Gitblit v1.9.1