From ef47083c90ff7e70362a32741a0a4d5770037e7f Mon Sep 17 00:00:00 2001
From: 严智鑫 <test>
Date: 星期一, 18 三月 2024 10:44:04 +0800
Subject: [PATCH] Merge branch 'master' of http://10.153.19.25:10101/r/Albania_Mes

---
 springboot-vue3/src/main/java/com/example/springboot/service/HomeService.java |  117 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 116 insertions(+), 1 deletions(-)

diff --git a/springboot-vue3/src/main/java/com/example/springboot/service/HomeService.java b/springboot-vue3/src/main/java/com/example/springboot/service/HomeService.java
index 0daec53..dda7048 100644
--- a/springboot-vue3/src/main/java/com/example/springboot/service/HomeService.java
+++ b/springboot-vue3/src/main/java/com/example/springboot/service/HomeService.java
@@ -1,9 +1,124 @@
 package com.example.springboot.service;
 
+import java.io.File;
+import java.io.FileInputStream;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.poi.ss.usermodel.Cell;
+import org.apache.poi.ss.usermodel.CellType;
+import org.apache.poi.ss.usermodel.CellValue;
+import org.apache.poi.ss.usermodel.FormulaEvaluator;
+import org.apache.poi.ss.usermodel.Row;
+import org.apache.poi.ss.usermodel.Sheet;
+import org.apache.poi.ss.usermodel.Workbook;
+import org.apache.poi.ss.usermodel.WorkbookFactory;
+import org.apache.poi.xssf.usermodel.XSSFWorkbook;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
+import com.example.springboot.entity.GlassInfo;
+import com.example.springboot.entity.MeasureSetting;
+import com.example.springboot.mapper.GlassInfoMapper;
+import com.example.springboot.mapper.MeasureSettingMapper;
+import com.example.springboot.mapper.QueueMapper;
 
 @Service
 public class HomeService {
-    
+
+    @Autowired
+    MeasureSettingMapper MeasureSettingMapper;
+    @Autowired
+    GlassInfoMapper GlassInfoMapper;
+    @Autowired
+    QueueMapper QueueMapper;
+
+    // 鍖归厤鐜荤拑 瀹斤紝楂橈紝绾胯矾
+    public List<GlassInfo> NormalGlassInfo(double width, double height, String line) {
+        //
+        List<GlassInfo> Results = new ArrayList<GlassInfo>();
+        // 鑾峰彇鍖归厤璁剧疆
+        MeasureSetting MeasureSetting = MeasureSettingMapper.SelectMeasureSetting(line);
+        if (height > 0 && width > 0 && MeasureSetting != null) {
+            // 鏈夋晥鍙傛暟 璇锋眰=1 闀�/瀹�>0
+            double maxheight = height + MeasureSetting.getErrorHeight();
+            double minheight = height - MeasureSetting.getErrorHeight();
+            double maxwidth = width + MeasureSetting.getErrorWidth();
+            double minwidth = width - MeasureSetting.getErrorWidth();
+            // 鏌ヨ褰撳墠娴嬮噺鏁版嵁
+            List<GlassInfo> GlassInfos = GlassInfoMapper.selectGlassInfos(maxwidth, minwidth, maxheight, minheight);
+            List types = new ArrayList<>();
+            for (int i = 0; i < GlassInfos.size(); i++) {
+                Integer glasstype = GlassInfos.get(i).getGlasstype();
+                if (!types.contains(glasstype)) {
+                    types.add(glasstype);
+                    Results.add(GlassInfos.get(i));
+                }
+            }
+        }
+        return Results;
+    }
+
+    //Execl琛ㄦ牸 浼犲叆鏂囦欢璺緞  
+    public List ReadExecl(String filename) {
+        try {
+             // 鍒涘缓鏂囦欢瀵硅薄
+        File file = new File(filename);
+        // 鍒涘缓鏂囦欢杈撳叆娴佸璞�
+        FileInputStream inputStream = new FileInputStream(file);
+        // 鍒涘缓宸ヤ綔绨垮璞�
+        Workbook workbook = WorkbookFactory.create(inputStream);
+        // 鑾峰彇绗竴涓伐浣滆〃瀵硅薄
+        Sheet sheet = workbook.getSheetAt(0);
+        // 鍒涘缓涓�涓疄浣撶被闆嗗悎锛岀敤浜庡瓨鍌‥xcel鏁版嵁
+        
+        List Results=new ArrayList();  
+        int i=0;  
+        // 閬嶅巻琛�
+        for (Row row : sheet) {
+            // 閬嶅巻鍗曞厓鏍�
+            List ResultRow=new ArrayList(); 
+            //System.out.println();
+            for (Cell cell : row) {
+                String LastCellvalue="";
+                // 鍒ゆ柇鍗曞厓鏍肩被鍨嬫槸鍚︿负鍏紡绫诲瀷
+                if (cell.getCellType() == CellType.FORMULA) {
+                    // 浣跨敤鍏紡璁$畻鍣ㄨ绠楀崟鍏冩牸鐨勫��
+                    FormulaEvaluator evaluator = workbook.getCreationHelper().createFormulaEvaluator();
+                    CellValue cellValue = evaluator.evaluate(cell);
+                    // 璁$畻鍚庣殑鍗曞厓鏍煎��
+                    LastCellvalue=cellValue.getNumberValue()+"";
+                }else if(cell.getCellType() == CellType.NUMERIC){
+                    double value = cell.getNumericCellValue();
+                    if (value%1==0) {
+                        LastCellvalue=Math.round(value)+"";
+                    }else{
+                        LastCellvalue=value+"";
+                    }
+                } else {
+                    // 鍗曞厓鏍煎��
+                    LastCellvalue=cell.toString(); 
+                }
+                ResultRow.add(LastCellvalue);
+                //System.out.print(LastCellvalue+"  ");
+            }
+            Results.add(ResultRow);
+            i++;
+        }
+        System.out.println(i);
+        // 鍏抽棴宸ヤ綔绨垮拰杈撳叆娴佸璞�
+        workbook.close();
+        inputStream.close();
+        return Results;
+        } catch (Exception e) {
+            // TODO: handle exception
+            System.out.println("寮傚父");
+            return new ArrayList();
+        }
+       
+    }
+
+
 }

--
Gitblit v1.8.0