This commit is contained in:
oneao committed 2025-06-30 17:29:28 +08:00
1 parent 9d7bf97823
commit 7c64e29ffb
16 files changed
+784 -35

No files matched your search

@@ -0,0 +1,53 @@
package com.crane.test;
import org.springframework.web.bind.annotation.*;
import java.util.HashMap;
import java.util.Map;
/**
* 通用数据接口
*/
@RestController
@RequestMapping("/api/data")
public class DataController {
/**
* 查询数据接口
* @param table 表名
* @param filters 查询过滤条件(JSON字符串)
* @return 查询结果
*/
@GetMapping("/load")
public Map<String, Object> loadData(
@RequestParam String table,
@RequestParam(required = false) String filters
) {
Map<String, Object> result = new HashMap<>();
result.put("code", 0);
result.put("data", "模拟查询结果");
return result;
}
/**
* 保存数据接口
* @param table 表名
* @param data 要保存的数据(键值对)
* @return 保存结果
*/
@PostMapping("/save")
public Map<String, Object> saveData(
@RequestParam String table,
@RequestBody Map<String, Object> data
) {
Map<String, Object> result = new HashMap<>();
result.put("code", 0);
result.put("msg", "保存成功");
return result;
}
public void test(){
System.out.println("test");
}
}
@@ -0,0 +1,61 @@
package com.crane.test;
import okhttp3.*;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Base64;
public class Test{
public static void main(String[] args) throws IOException {
String API_URL = "http://localhost:8080/ocr";
String imagePath = "./demo.jpg";
File file = new File(imagePath);
byte[] fileContent = java.nio.file.Files.readAllBytes(file.toPath());
String base64Image = Base64.getEncoder().encodeToString(fileContent);
ObjectMapper objectMapper = new ObjectMapper();
ObjectNode payload = objectMapper.createObjectNode();
payload.put("file", base64Image);
payload.put("fileType", 1);
OkHttpClient client = new OkHttpClient();
MediaType JSON = MediaType.get("application/json; charset=utf-8");
RequestBody body = RequestBody.create(JSON, payload.toString());
Request request = new Request.Builder()
.url(API_URL)
.post(body)
.build();
try (Response response = client.newCall(request).execute()) {
if (response.isSuccessful()) {
String responseBody = response.body().string();
JsonNode root = objectMapper.readTree(responseBody);
JsonNode result = root.get("result");
JsonNode ocrResults = result.get("ocrResults");
for (int i = 0; i < ocrResults.size(); i++) {
JsonNode item = ocrResults.get(i);
JsonNode prunedResult = item.get("prunedResult");
System.out.println("Pruned Result [" + i + "]: " + prunedResult.toString());
String ocrImageBase64 = item.get("ocrImage").asText();
byte[] ocrImageBytes = Base64.getDecoder().decode(ocrImageBase64);
String ocrImgPath = "ocr_result_" + i + ".jpg";
try (FileOutputStream fos = new FileOutputStream(ocrImgPath)) {
fos.write(ocrImageBytes);
System.out.println("Saved OCR image to: " + ocrImgPath);
}
}
} else {
System.err.println("Request failed with HTTP code: " + response.code());
}
}
}
}
@@ -0,0 +1,2 @@
logging:
module-name: 测试模块