From 866a3e6cbd2df9841dfbbd733e1128938cef3e00 Mon Sep 17 00:00:00 2001
From: zouyu <2723363702@qq.com>
Date: 星期二, 09 十二月 2025 17:45:16 +0800
Subject: [PATCH] 采集器调整
---
src/main/java/com/chinaztt/mes/docx/service/impl/DocxServiceImpl.java | 100 +++++++++++++++
src/main/java/com/chinaztt/mes/docx/controller/DocxController.java | 7 +
pom.xml | 41 +++---
src/main/java/com/chinaztt/mes/docx/service/DocxService.java | 1
src/main/java/com/chinaztt/mes/docx/dto/GetFileDto.java | 4
src/main/java/com/chinaztt/mes/docx/util/TakeWords.java | 156 ++++++++-----------------
6 files changed, 174 insertions(+), 135 deletions(-)
diff --git a/pom.xml b/pom.xml
index b39de63..5881d1f 100644
--- a/pom.xml
+++ b/pom.xml
@@ -19,7 +19,11 @@
<artifactId>fastjson</artifactId>
<version>2.0.23</version>
</dependency>
-
+ <dependency>
+ <groupId>com.fazecast</groupId>
+ <artifactId>jSerialComm</artifactId>
+ <version>2.10.2</version> <!-- 妫�鏌ユ渶鏂扮増鏈� -->
+ </dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
@@ -39,13 +43,24 @@
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
- <version>5.2.3</version>
+ <version>5.2.5</version>
</dependency>
<!-- 澶勭悊 .xlsx (OOXML) 鏍煎紡 -->
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
- <version>5.2.3</version>
+ <version>5.2.5</version>
+ </dependency>
+ <!-- https://mvnrepository.com/artifact/org.apache.poi/poi-scratchpad -->
+ <dependency>
+ <groupId>org.apache.poi</groupId>
+ <artifactId>poi-scratchpad</artifactId>
+ <version>5.2.5</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.poi</groupId>
+ <artifactId>poi-ooxml-full</artifactId>
+ <version>5.2.5</version>
</dependency>
<dependency>
@@ -63,26 +78,6 @@
<groupId>net.sf.ucanaccess</groupId>
<artifactId>ucanaccess</artifactId>
<version>5.0.1</version>
- </dependency>
-
- <dependency>
- <groupId>org.apache.poi</groupId>
- <artifactId>poi</artifactId>
- <version>3.17</version>
- </dependency>
-
- <!-- https://mvnrepository.com/artifact/org.apache.poi/poi-ooxml -->
- <dependency>
- <groupId>org.apache.poi</groupId>
- <artifactId>poi-ooxml</artifactId>
- <version>3.17</version>
- </dependency>
-
- <!-- https://mvnrepository.com/artifact/org.apache.poi/poi-scratchpad -->
- <dependency>
- <groupId>org.apache.poi</groupId>
- <artifactId>poi-scratchpad</artifactId>
- <version>3.17</version>
</dependency>
<dependency>
diff --git a/src/main/java/com/chinaztt/mes/docx/controller/DocxController.java b/src/main/java/com/chinaztt/mes/docx/controller/DocxController.java
index bc31427..a031ec0 100644
--- a/src/main/java/com/chinaztt/mes/docx/controller/DocxController.java
+++ b/src/main/java/com/chinaztt/mes/docx/controller/DocxController.java
@@ -29,4 +29,11 @@
public R<?> moveFile(String startFilePath, String endFilePath, String fileType) {
return docxService.moveFile(startFilePath, endFilePath, fileType);
}
+
+
+ @GetMapping("/test")
+ public void test() {
+ docxService.test();
+ }
+
}
diff --git a/src/main/java/com/chinaztt/mes/docx/dto/GetFileDto.java b/src/main/java/com/chinaztt/mes/docx/dto/GetFileDto.java
index ea847b9..166b465 100644
--- a/src/main/java/com/chinaztt/mes/docx/dto/GetFileDto.java
+++ b/src/main/java/com/chinaztt/mes/docx/dto/GetFileDto.java
@@ -22,6 +22,10 @@
private String fiberOpticRibbonCode;
// 鍏夌氦甯︽暟鎹�
private String fiberOpticRibbon;
+ // 绠″鑹叉爣瀛楁
+ private String bushingColorField;
+ // 绠″鑹叉爣鏁版嵁
+ private String bushingColor;
//鏁版嵁搴撶敤鎴峰悕
private String dbUserName;
//鏁版嵁搴撳瘑鐮�
diff --git a/src/main/java/com/chinaztt/mes/docx/service/DocxService.java b/src/main/java/com/chinaztt/mes/docx/service/DocxService.java
index 1c51019..4029dd8 100644
--- a/src/main/java/com/chinaztt/mes/docx/service/DocxService.java
+++ b/src/main/java/com/chinaztt/mes/docx/service/DocxService.java
@@ -12,5 +12,6 @@
R<?> moveFile(String startFilePath, String endFilePath, String fileType);
+ void test();
}
diff --git a/src/main/java/com/chinaztt/mes/docx/service/impl/DocxServiceImpl.java b/src/main/java/com/chinaztt/mes/docx/service/impl/DocxServiceImpl.java
index c9dcdfd..a10f958 100644
--- a/src/main/java/com/chinaztt/mes/docx/service/impl/DocxServiceImpl.java
+++ b/src/main/java/com/chinaztt/mes/docx/service/impl/DocxServiceImpl.java
@@ -6,12 +6,16 @@
import com.chinaztt.mes.docx.service.DocxService;
import com.chinaztt.mes.docx.util.R;
import com.chinaztt.mes.docx.util.TakeWords;
+import com.fazecast.jSerialComm.SerialPort;
+import com.fazecast.jSerialComm.SerialPortDataListener;
+import com.fazecast.jSerialComm.SerialPortEvent;
import net.sourceforge.tess4j.TesseractException;
+import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import java.io.File;
-import java.io.FileNotFoundException;
import java.io.IOException;
+import java.nio.charset.StandardCharsets;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
@@ -22,20 +26,24 @@
@Override
public R<?> getFile(GetFileDto getFileDto) throws IOException, SQLException, ClassNotFoundException, InstantiationException, IllegalAccessException, TesseractException {
- File file = getFileStart(getFileDto.getFilePath(), getFileDto.getFileExtension());
+ String fileExtension = getFileDto.getFileExtension();
+ if(StringUtils.equals(".pngInExcel",getFileDto.getFileExtension())){
+ fileExtension = ".xls";
+ }
+ File file = getFileStart(getFileDto.getFilePath(), fileExtension);
if (file != null && !file.exists()) {
return R.failed("鏈煡璇㈠埌璇ヨ矾寰勶細" + getFileDto.getFilePath() + "涓嬪瓨鍦細" + getFileDto.getFileExtension() + "缁撳熬鐨勬枃浠讹紒");
}
switch (getFileDto.getFileExtension()) {
case ".docx":
return R.ok(TakeWords.readWordFile(file));
- //鍚庣紑涓�.xls鐨勬枃浠�
+ case ".pngInExcel":
+ return R.ok(TakeWords.readPngContextInExcel(file));
case ".xls":
- return R.ok(TakeWords.readExcelxlsFile(file));
case ".xlsx":
try {
return R.ok(TakeWords.readExcelFile(file));
- } catch (FileNotFoundException e) {
+ } catch (Exception e) {
return R.failed("鍙︿竴涓▼搴忔鍦ㄤ娇鐢ㄦ鏂囦欢锛屾棤娉曡繘琛屾暟鎹噰闆嗐��");
}
case ".txt":
@@ -130,4 +138,86 @@
});
return getLatestFile(list);
}
+
+ @Override
+ public void test(){
+ // 1. 鑾峰彇鎵�鏈夊彲鐢ㄧ殑涓插彛
+ SerialPort[] ports = SerialPort.getCommPorts();
+ if (ports.length == 0) {
+ System.err.println("鏈壘鍒板彲鐢ㄧ殑涓插彛锛�");
+ return;
+ }
+
+ // 鎵撳嵃鎵�鏈夊彲鐢ㄤ覆鍙o紙渚涚敤鎴烽�夋嫨锛�
+ System.out.println("鍙敤涓插彛鍒楄〃锛�");
+ SerialPort targetPort = null;
+ for (int i = 0; i < ports.length; i++) {
+ if(ports[i].getSystemPortName().equals("COM7")){
+ targetPort = ports[i];
+ }
+ System.out.printf("%d: %s (%s)\n", i + 1, ports[i].getSystemPortName(), ports[i].getPortDescription());
+ }
+
+ // 2. 閫夋嫨鐩爣涓插彛锛堢ず渚嬶細閫夋嫨绗竴涓覆鍙o級
+
+ System.out.println("\n閫夋嫨鐨勪覆鍙o細" + targetPort.getSystemPortName());
+
+ // 3. 閰嶇疆涓插彛鍙傛暟锛堝繀椤讳笌璁惧涓�鑷达紝鍚﹀垯閫氫俊澶辫触锛�
+ targetPort.setComPortParameters(
+ 9600, // 娉㈢壒鐜囷紙甯歌鍊硷細9600銆�19200銆�38400銆�115200锛�
+ 8, // 鏁版嵁浣嶏紙閫氬父涓� 8锛�
+ SerialPort.ONE_STOP_BIT, // 鍋滄浣嶏紙1 浣嶏級
+ SerialPort.NO_PARITY // 鏍¢獙浣嶏紙鏃犳牎楠岋級
+ );
+ targetPort.setComPortTimeouts(SerialPort.TIMEOUT_READ_SEMI_BLOCKING, 100, 0); // 璇诲彇瓒呮椂璁剧疆
+
+ // 4. 鎵撳紑涓插彛
+ if (!targetPort.openPort()) {
+ System.err.println("涓插彛鎵撳紑澶辫触锛佽妫�鏌ョ鍙f槸鍚﹁鍗犵敤鎴栨潈闄愭槸鍚﹁冻澶熴��");
+ return;
+ }
+ System.out.println("涓插彛鎵撳紑鎴愬姛锛�");
+
+ // 5. 娉ㄥ唽鏁版嵁鐩戝惉锛堝紓姝ヨ鍙栨暟鎹級
+ SerialPort finalTargetPort = targetPort;
+ targetPort.addDataListener(new SerialPortDataListener() {
+ @Override
+ public int getListeningEvents() {
+ return SerialPort.LISTENING_EVENT_DATA_AVAILABLE; // 鐩戝惉鏁版嵁鍙敤浜嬩欢
+ }
+
+ @Override
+ public void serialEvent(SerialPortEvent event) {
+ System.out.println("asasa"+event.toString());
+ if (event.getEventType() != SerialPort.LISTENING_EVENT_DATA_AVAILABLE) {
+ return;
+ }
+
+ // 璇诲彇鍙敤鏁版嵁
+ byte[] readBuffer = new byte[finalTargetPort.bytesAvailable()];
+ int bytesRead = finalTargetPort.readBytes(readBuffer, readBuffer.length);
+
+ if (bytesRead > 0) {
+ // 杞崲涓哄瓧绗︿覆锛堟牴鎹澶囩紪鐮佽皟鏁达紝甯歌锛歎TF-8銆丟BK锛�
+ String data = new String(readBuffer, 0, bytesRead, StandardCharsets.UTF_8);
+ System.out.printf("鏀跺埌鏁版嵁锛�%d 瀛楄妭锛夛細%s", bytesRead, data);
+ }
+ }
+ });
+
+ // 6. 淇濇寔绋嬪簭杩愯锛堥伩鍏嶄富绾跨▼閫�鍑猴級
+ try {
+ while (true) {
+ Thread.sleep(1000); // 涓荤嚎绋嬩紤鐪狅紝涓嶅奖鍝嶇洃鍚嚎绋�
+ }
+ } catch (InterruptedException e) {
+ Thread.currentThread().interrupt();
+ System.out.println("绋嬪簭琚腑鏂��");
+ } finally {
+ // 7. 鍏抽棴涓插彛锛堢▼搴忛��鍑烘椂閲婃斁璧勬簮锛�
+ targetPort.closePort();
+ System.out.println("涓插彛宸插叧闂��");
+ }
+ }
+
}
diff --git a/src/main/java/com/chinaztt/mes/docx/util/TakeWords.java b/src/main/java/com/chinaztt/mes/docx/util/TakeWords.java
index 301b47d..58fb34a 100644
--- a/src/main/java/com/chinaztt/mes/docx/util/TakeWords.java
+++ b/src/main/java/com/chinaztt/mes/docx/util/TakeWords.java
@@ -1,6 +1,8 @@
package com.chinaztt.mes.docx.util;
import cn.hutool.core.io.FileUtil;
+import cn.hutool.http.HttpRequest;
+import cn.hutool.json.JSONUtil;
import com.chinaztt.mes.docx.dto.GetFileDto;
import com.opencsv.CSVReader;
import com.opencsv.CSVReaderBuilder;
@@ -9,20 +11,19 @@
import net.sourceforge.tess4j.TesseractException;
import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils;
-import org.apache.poi.POIXMLDocument;
-import org.apache.poi.POIXMLTextExtractor;
import org.apache.poi.hssf.usermodel.HSSFPictureData;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.hwpf.extractor.WordExtractor;
+import org.apache.poi.ooxml.POIXMLDocument;
+import org.apache.poi.ooxml.extractor.POIXMLTextExtractor;
import org.apache.poi.openxml4j.opc.OPCPackage;
+import org.apache.poi.poifs.filesystem.POIFSFileSystem;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
-import org.apache.poi.xssf.usermodel.XSSFSheet;
-import org.apache.poi.xssf.usermodel.XSSFWorkbook;
+import org.apache.poi.ss.usermodel.WorkbookFactory;
import org.apache.poi.xwpf.extractor.XWPFWordExtractor;
import java.io.*;
-import java.nio.file.Files;
import java.sql.*;
import java.util.*;
import java.util.regex.Pattern;
@@ -57,19 +58,22 @@
return result;
}
- public static Object readExcelFile(File file) throws IOException {
+ /**
+ * 璇诲彇excel鏂囦欢,鍏煎.xlsx,.xls鏍煎紡
+ * @param file
+ * @return
+ */
+ public static Object readExcelFile(File file) {
StringBuilder result = new StringBuilder();
- //鍒涘缓宸ヤ綔绨垮璞�
- try {
- XSSFWorkbook xssfWorkbook = new XSSFWorkbook(Files.newInputStream(file.toPath()));
- //鑾峰彇宸ヤ綔绨夸笅sheet鐨勪釜鏁� 鍙鍙栫涓�涓猻heet
-// int sheetNum = xssfWorkbook.getNumberOfSheets();
+ try (
+ FileInputStream fis = new FileInputStream(file);
+ Workbook workbook = WorkbookFactory.create(fis)
+ ) {
//閬嶅巻宸ヤ綔绨夸腑鐨勬墍鏈夋暟鎹�
- XSSFSheet sheet = xssfWorkbook.getSheetAt(0);
+ Sheet sheet = workbook.getSheetAt(0);
//鑾峰彇鏈�鍚庝竴琛岀殑num锛屽嵆鎬昏鏁般�傛澶勪粠0寮�濮�
int maxRow = sheet.getLastRowNum();
- for (int row = 1; row <= maxRow; row++) {
- //鑾峰彇鏈�鍚庡崟鍏冩牸num锛屽嵆鎬诲崟鍏冩牸鏁� ***娉ㄦ剰锛氭澶勪粠1寮�濮嬭鏁�***
+ for (int row = 0; row <= maxRow; row++) {
int maxRol = sheet.getRow(row).getLastCellNum();
StringBuilder aLine = new StringBuilder();
for (int rol = 0; rol < maxRol; rol++) {
@@ -77,13 +81,19 @@
}
result.append(aLine).append("\n");
}
- }catch (Exception e){
+ } catch (Exception e) {
e.printStackTrace();
}
return result.toString();
}
- public static Object readExcelxlsFile(File file) throws IOException {
+ /**
+ * 璇诲彇excel鏂囦欢涓殑鍥剧墖鍐呭
+ * @param file
+ * @return
+ * @throws IOException
+ */
+ public static Object readPngContextInExcel(File file) throws IOException {
String result = "";
try (FileInputStream fis = new FileInputStream(file);
Workbook workbook = new HSSFWorkbook(fis)) {
@@ -104,100 +114,18 @@
try (FileOutputStream fos = new FileOutputStream(tempFile)) {
fos.write(pictureData);
}
- String ocrResult = "";
+ String ocrResult;
try {
- ocrResult = (String) readPngFile(tempFile);
- } catch (TesseractException e) {
- ocrResult = "OCR璇嗗埆澶辫触: " + e.getMessage();
+ ocrResult = ocrImageContext(tempFile.getAbsolutePath());
} finally {
// 鍒犻櫎涓存椂鏂囦欢
tempFile.delete();
}
result = ocrResult;
-// String ocrText = fixOcrText(ocrResult);
-// result.append("OCR Result:").append(ocrText).append(",");
-
-
-// for (HSSFPictureData picture : pictures) {
-// // 鑾峰彇鍥剧墖绫诲瀷
-// String pictureType = picture.suggestFileExtension();
-// // 鑾峰彇鍥剧墖鏁版嵁
-// byte[] pictureData = picture.getData();
-// // 鍒涘缓涓存椂鏂囦欢
-// File tempFile = File.createTempFile(UUID.randomUUID().toString(), "." + pictureType);
-// try (FileOutputStream fos = new FileOutputStream(tempFile)) {
-// fos.write(pictureData);
-// }
-// // 鍥剧墖棰勫鐞�
-//// File processedFile = preprocessImage(tempFile, pictureType);
-// // 璋冪敤 readPngFile1 鏂规硶璇诲彇鍥剧墖鏂囧瓧淇℃伅
-// String ocrResult = "";
-// try {
-// ocrResult = (String) readPngFile(tempFile);
-//// ocrResult = (String) readPngFile(tempFile);
-//// ocrResult = (String) readPngFile(processedFile);
-// } catch (TesseractException e) {
-// ocrResult = "OCR璇嗗埆澶辫触: " + e.getMessage();
-// } finally {
-// // 鍒犻櫎涓存椂鏂囦欢
-//// tempFile.delete();
-//// processedFile.delete();
-// }
-//
-// // 灏嗗浘鐗囦俊鎭坊鍔犲埌缁撴灉涓�
-//// result.append("Picture Type: ").append(pictureType)
-//// .append(", Picture Size: ").append(pictureData.length)
-//// .append(" bytes")
-//// .append(", OCR Result: ").append(ocrResult)
-//// .append(",");
-// String ocrText = fixOcrText(ocrResult);
-// result.append("OCR Result:").append(ocrText).append(",");
-// }
}
-//
-// // 閬嶅巻姣忎竴琛�
-// for (Row row : sheet) {
-// // 閬嶅巻姣忎竴鍒�
-// for (Cell cell : row) {
-// CellType cellType = CellType.forInt(cell.getCellType());
-// switch (cellType) {
-// case STRING:
-// result.append(cell.getStringCellValue());
-// break;
-// case NUMERIC:
-// if (DateUtil.isCellDateFormatted(cell)) {
-// result.append(cell.getDateCellValue());
-// } else {
-// result.append(cell.getNumericCellValue());
-// }
-// break;
-// case BOOLEAN:
-// result.append(cell.getBooleanCellValue());
-// break;
-// case FORMULA:
-// result.append(cell.getCellFormula());
-// break;
-// default:
-// result.append("");
-// }
-// result.append("\t");
-// }
-// result.append("\n");
-// }
}
return result;
- }
-
- // 淇 OCR 璇嗗埆鏂囨湰涓殑閿欒鍏抽敭璇�
- public static String fixOcrText(String ocrText) {
- // 瀹氫箟閿欒鍏抽敭璇嶅拰姝g‘鍐呭鐨勬槧灏勶紝杩欓噷澶勭悊鈥滃嚮 瀹� 寮� 搴炩�濅慨姝d负鈥滃嚮绌垮己搴︹��
- // 鑰冭檻鍒板彲鑳芥湁绌烘牸鍒嗛殧锛岀敤姝e垯鍖归厤鍖呭惈杩欎簺瀛楃殑鍐呭
- ocrText = ocrText.replaceAll("鍑籠\s*瀹嘰\s*寮篭\s*搴�", "鍑荤┛寮哄害");
- // 杩樺彲浠ョ户缁坊鍔犲叾浠栭敊璇慨姝o紝姣斿涓嬮潰鍋囪鈥滅數 鍘� \\(HV\\)鈥濋噷鐨勭┖鏍煎奖鍝嶏紝涔熶慨姝d笅
- ocrText = ocrText.replaceAll("鐢礬\s*鍘媆\s*\\(HV\\)", "鐢靛帇(KV)");
- ocrText = ocrText.replaceAll("鐢礬\s*娴乗\s*\\(nt\\)", "鐢垫祦(mA)");
- return ocrText;
}
public static Object readPngFile1(File file) throws IOException, TesseractException {
@@ -284,8 +212,8 @@
Properties prop = new Properties();
//璁剧疆缂栫爜
prop.put("charSet", "UTF-8");
- prop.put("user", "");
- prop.put("password", "");
+ prop.put("user", StringUtils.isNotBlank(getFileDto.getDbUserName())?getFileDto.getDbUserName():"");
+ prop.put("password", StringUtils.isNotBlank(getFileDto.getDbPassword())?getFileDto.getDbPassword():"");
//鏁版嵁鍦板潃
String dbUrl = "jdbc:ucanaccess://" + file.getPath();
//寮曞叆椹卞姩
@@ -299,8 +227,6 @@
try {
List<Object> list = new ArrayList<>();
//閬嶅巻鑾峰彇澶氬紶琛ㄦ暟鎹�
-// String s = "select * from " + getFileDto.getDbFileName() + " where 1=1" + getFileDto.getMdbEntrustCode() + " = '" + getFileDto.getEntrustCode() +
-// "' and " + getFileDto.getMdbSampleCode() + " = '" + getFileDto.getSampleCode() + "'";
String s = "select * from " + getFileDto.getDbFileName() + " where 1=1";
if(StringUtils.isNotBlank(getFileDto.getMdbEntrustCode())){
s+=" and " + getFileDto.getMdbEntrustCode() + " = '" + getFileDto.getEntrustCode()+ "'";
@@ -308,6 +234,10 @@
if(StringUtils.isNotBlank(getFileDto.getMdbSampleCode())){
s+=" and " + getFileDto.getMdbSampleCode() + " = '" + getFileDto.getSampleCode() + "'";
}
+ if(StringUtils.isNotBlank(getFileDto.getBushingColorField())){
+ s+=" and " + getFileDto.getBushingColorField() + " = '" + getFileDto.getBushingColor() + "'";
+ }
+
preparedStatement = conn.prepareStatement(s);
rs = preparedStatement.executeQuery();
ResultSetMetaData data = rs.getMetaData();
@@ -370,9 +300,9 @@
String sql = "SELECT * FROM "+table+" WHERE 1=1";
if(StringUtils.isNotBlank(getFileDto.getMdbEntrustCode()) ){
- sql+=" AND (" + getFileDto.getMdbEntrustCode() + " = '" + getFileDto.getEntrustCode()+ "'";
+ sql+=" AND (" + getFileDto.getMdbEntrustCode() + " = TRIM('" + getFileDto.getEntrustCode()+ "')";
if(StringUtils.isNotBlank(getFileDto.getLotBatchNo())){
- sql+=" OR "+ getFileDto.getMdbEntrustCode() + " = '" + getFileDto.getLotBatchNo()+ "'";
+ sql+=" OR "+ getFileDto.getMdbEntrustCode() + " = TRIM('" + getFileDto.getLotBatchNo()+ "')";
}
sql+=")";
}
@@ -382,7 +312,6 @@
if(StringUtils.isNotBlank(getFileDto.getCableTag())){
sql+=" AND Color = '" + getFileDto.getCableTag() + "'";
}
-
// 鍒涘缓 PreparedStatement 瀵硅薄鎵ц SQL
preparedStatement = connection.prepareStatement(sql);
resultSet = preparedStatement.executeQuery();
@@ -468,6 +397,19 @@
return tableMap;
}
+ /**
+ * ocr璇嗗埆鍥剧墖鍐呭
+ * @param imagePath 鍥剧墖璺緞
+ * @return
+ */
+ public static String ocrImageContext(String imagePath){
+ //璋冪敤ocr璇嗗埆鏈嶅姟
+ Map<String,Object> jsonMap = new HashMap<>();
+ jsonMap.put("imagePath",imagePath);
+ String requestBody = JSONUtil.toJsonStr(jsonMap);
+ return HttpRequest.post("localhost:8080/ocr/recognize").body(requestBody).execute().body();
+ }
+
public static Object readPngFile(File file) throws IOException, TesseractException {
String canonicalPath32 = FileUtil.file(".", "/jre_32/tessdata").getCanonicalPath();
String canonicalPath64 = FileUtil.file(".", "/jre_64/tessdata").getCanonicalPath();
--
Gitblit v1.9.3