From c0f0e756e9d61c27e358c798c91042e35711028b Mon Sep 17 00:00:00 2001
From: MrShi <1878285526@qq.com>
Date: 星期一, 02 二月 2026 15:52:36 +0800
Subject: [PATCH] 优化

---
 server/services/src/main/java/com/doumee/core/annotation/excel/ExcelImporter.java |  143 ++++++++++++++++++++++++++++++-----------------
 1 files changed, 91 insertions(+), 52 deletions(-)

diff --git a/server/services/src/main/java/com/doumee/core/annotation/excel/ExcelImporter.java b/server/services/src/main/java/com/doumee/core/annotation/excel/ExcelImporter.java
index 56eb9a9..a19134d 100644
--- a/server/services/src/main/java/com/doumee/core/annotation/excel/ExcelImporter.java
+++ b/server/services/src/main/java/com/doumee/core/annotation/excel/ExcelImporter.java
@@ -4,6 +4,7 @@
 import org.apache.poi.hssf.usermodel.HSSFWorkbook;
 import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
 import org.apache.poi.ss.usermodel.*;
+import org.apache.poi.xssf.usermodel.XSSFPicture;
 import org.apache.poi.xssf.usermodel.XSSFPictureData;
 import org.apache.poi.xssf.usermodel.XSSFWorkbook;
 import org.slf4j.Logger;
@@ -329,64 +330,102 @@
             }
             StringBuilder sb = new StringBuilder();
             for (Object[] os : annotationList){
-                Object val = this.getCellValue(row, column++);
-                if (val != null){
-                    ExcelColumn ef = (ExcelColumn)os[0];
-                    // Get param type and type cast
-                    Class<?> valType = Class.class;
-                    if (os[1] instanceof Field){
-                        valType = ((Field)os[1]).getType();
-                    }else if(os[1] instanceof Method){
-                        Method method = ((Method)os[1]);
-                        if ("get".equals(method.getName().substring(0, 3))){
-                            valType = method.getReturnType();
-                        }else if("set".equals(method.getName().substring(0, 3))){
-                            valType = ((Method)os[1]).getParameterTypes()[0];
-                        }
+                int tcolumn = column++;
+                Object val = this.getCellValue(row, tcolumn);;
+                ExcelColumn ef = (ExcelColumn)os[0];
+                // Get param type and type cast
+                Class<?> valType = Class.class;
+                if (os[1] instanceof Field){
+                    valType = ((Field)os[1]).getType();
+                }else if(os[1] instanceof Method){
+                    Method method = ((Method)os[1]);
+                    if ("get".equals(method.getName().substring(0, 3))){
+                        valType = method.getReturnType();
+                    }else if("set".equals(method.getName().substring(0, 3))){
+                        valType = ((Method)os[1]).getParameterTypes()[0];
                     }
-                    //log.debug("Import value type: ["+i+","+column+"] " + valType);
-                    try {
-                        if (valType == String.class){
-                            String s = String.valueOf(val.toString());
-                            if(StringUtils.endsWith(s, ".0")){
-                                val = StringUtils.substringBefore(s, ".0");
-                            }else{
-                                val = String.valueOf(val.toString()).trim();
+                }
+                if(ef.fieldType()== XSSFPictureData.class){
+                    XSSFPictureData qrData = null;
+                    if(val !=null){
+                        String tid = String.valueOf(val.toString()).trim();
+                        int start = tid.indexOf("(\"")+2;
+                        int end = tid.indexOf("\",");
+                        if(start>=0&& end>=1 && end>start){
+                            String picId = tid.substring(start,end);
+                            XSSFPictureData data = this.pictureList.get(picId);
+                            if(data!= null && data.getData() != null){
+                                qrData =data;
                             }
                         }
-                        else if (valType == Integer.class){
-                            val = Double.valueOf(val.toString()).intValue();
-                        }else if (valType == Long.class){
-                            val = Double.valueOf(val.toString()).longValue();
-                        }else if (valType == Double.class){
-                            val = Double.valueOf(val.toString());
-                        }else if (valType == Float.class){
-                            val = Float.valueOf(val.toString());
-                        }else if (valType == Date.class){
-                            val = DateUtil.getJavaDate((Double)val);
-                        }else{
-                            if (ef.fieldType() != Class.class){
-                                val = ef.fieldType().getMethod("getValue", String.class).invoke(null, val.toString());
-                            }else{
-                                val = Class.forName(this.getClass().getName().replaceAll(this.getClass().getSimpleName(),
-                                    "fieldtype."+valType.getSimpleName()+"Type")).getMethod("getValue", String.class).invoke(null, val.toString());
+                    }
+                    val = null;
+                    //鎮诞鍥剧墖
+                    List<XSSFPictureData> xfData = ExcelPictureUtil.getPicturesFromCell(this.sheet,row.getCell(tcolumn));
+                    List<XSSFPictureData> valList =new ArrayList<>();
+                    if(qrData!=null){
+                        valList.add(qrData);
+                    }
+                    if(xfData!=null){
+                        valList.addAll(xfData);
+                    }
+                    if (valType==List.class){
+                        val =valList;
+                    } else if ( valType==XSSFPictureData.class){
+                        val = (valList!=null && valList.size()>0)?valList.get(0):null;
+                    }
+                }else{
+                    if (val != null){
+                        try {
+                            if (valType == String.class){
+                                String s = String.valueOf(val.toString());
+                                if(StringUtils.endsWith(s, ".0")){
+                                    val = StringUtils.substringBefore(s, ".0");
+                                }else{
+                                    val = String.valueOf(val.toString()).trim();
+                                }
                             }
+                            else if (valType == Integer.class){
+                                val = Double.valueOf(val.toString()).intValue();
+                            }else if (valType == Long.class){
+                                val = Double.valueOf(val.toString()).longValue();
+                            }else if (valType == Double.class){
+                                val = Double.valueOf(val.toString());
+                            }else if (valType == Float.class){
+                                val = Float.valueOf(val.toString());
+                            }else if (valType == Date.class){
+                                val = DateUtil.getJavaDate((Double)val);
+                            }else if (valType == XSSFPictureData.class){
+                            }else{
+                                if (ef.fieldType() != Class.class){
+                                    val = ef.fieldType().getMethod("getValue", String.class).invoke(null, val.toString());
+                                }else{
+                                    val = Class.forName(this.getClass().getName().replaceAll(this.getClass().getSimpleName(),
+                                            "fieldtype."+valType.getSimpleName()+"Type")).getMethod("getValue", String.class).invoke(null, val.toString());
+                                }
+                            }
+                        } catch (Exception ex) {
+                            log.info("Get cell value ["+i+","+column+"] error: " + ex.toString());
+                            val = null;
                         }
-
-                    } catch (Exception ex) {
-                        log.info("Get cell value ["+i+","+column+"] error: " + ex.toString());
-                        val = null;
                     }
-                    // set entity value
-                    if (os[1] instanceof Field){
-                        Reflections.invokeSetter(e, ((Field)os[1]).getName(), val);
-                    }else if (os[1] instanceof Method){
-                        String mthodName = ((Method)os[1]).getName();
-                        if ("get".equals(mthodName.substring(0, 3))){
-                            mthodName = "set"+StringUtils.substringAfter(mthodName, "get");
-                        }
-                        Reflections.invokeMethod(e, mthodName, new Class[] {valType}, new Object[] {val});
-                    }
+                }
+                 if (val != null){
+                     try {
+                         // set entity value
+                         if (os[1] instanceof Field){
+                             Reflections.invokeSetter(e, ((Field)os[1]).getName(), val);
+                         }else if (os[1] instanceof Method){
+                             String mthodName = ((Method)os[1]).getName();
+                             if ("get".equals(mthodName.substring(0, 3))){
+                                 mthodName = "set"+StringUtils.substringAfter(mthodName, "get");
+                             }
+                             Reflections.invokeMethod(e, mthodName, new Class[] {valType}, new Object[] {val});
+                         }
+                     }catch (Exception e1){
+                         val =null;
+                     }
+                }else{
                 }
                 sb.append(val+", ");
             }

--
Gitblit v1.9.3