From c1d88895501846c4ad1ba2b16f4a8ae10ca2b061 Mon Sep 17 00:00:00 2001
From: wu <731351411@qq.com>
Date: 星期二, 26 三月 2024 15:32:35 +0800
Subject: [PATCH] 代码更新

---
 springboot-vue3/src/main/java/com/example/springboot/service/HomeService.java |  150 +++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 149 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..54bf11e 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,157 @@
 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.entity.Queue;
+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;
+    }
+
+    // 鍖归厤閫昏緫
+    public boolean Normal(double width, double height, String line) {
+        List<Queue> ErrowQueues= QueueMapper.selectErrorQueues();
+        if (ErrowQueues.size()>0) {
+            //System.out.println("鏈夊尮閰嶅け璐ユ暟鎹湭鍘婚櫎");
+            return false;
+        }
+        List<GlassInfo> Result = NormalGlassInfo(width, height, "1");
+        if (Result.size() == 1) {
+            // 鍖归厤鎴愬姛 灏变竴绉嶇被鍨� 娣诲姞鏁版嵁
+            GlassInfo GlassInfo = Result.get(0);
+            QueueMapper.insert(GlassInfo.getGlassid(), width, height, 1);
+            GlassInfoMapper.updatemeasurenumber(GlassInfo.getId());
+            System.out.println("鍖归厤鎴愬姛");
+            System.out.println(GlassInfo.getGlassid());
+            return true;
+        } else if (Result.size() > 1) {
+            // 鍖归厤澶辫触 鍖归厤鍒板鏉$鍚堢殑鏁版嵁 娣诲姞鏁版嵁
+            QueueMapper.insertMatchFailure(width, height, 0);
+            System.out.println("鍖归厤澶辫触");
+            
+        } else {
+            // 鍖归厤澶辫触 鏈壘鍒扮鍚堢殑鏁版嵁 娣诲姞鏁版嵁
+            QueueMapper.insertMatchFailure(width, height, -1);
+            System.out.println("鏈壘鍒扮鍚堢殑鏁版嵁");
+        }
+        return false;
+    }
+
+    // Execl琛ㄦ牸 浼犲叆鏂囦欢璺緞
+    public List ReadExecl(String filename) {
+        try {
+            // 鍒涘缓鏂囦欢瀵硅薄
+            File file = new File(filename);
+            if (!file.exists()) {
+                System.out.println("鏂囦欢涓嶅瓨鍦紒 "+filename);
+                return new ArrayList<>();
+            }
+            // 鍒涘缓鏂囦欢杈撳叆娴佸璞�
+            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