From 202ca0f62257d108e95ca2e5912b86cf7b407906 Mon Sep 17 00:00:00 2001
From: wu <731351411@qq.com>
Date: 星期一, 25 三月 2024 08:09:49 +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 | 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