This commit is contained in:
oneao committed 2025-08-20 17:30:03 +08:00
1 parent 74ee8b2c64
commit 76a6c81af2
32 files changed
-606

No files matched your search

-38
View File
@@ -1,38 +0,0 @@
target/
!.mvn/wrapper/maven-wrapper.jar
!**/src/main/**/target/
!**/src/test/**/target/
### IntelliJ IDEA ###
.idea/modules.xml
.idea/jarRepositories.xml
.idea/compiler.xml
.idea/libraries/
*.iws
*.iml
*.ipr
### Eclipse ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache
### NetBeans ###
/nbproject/private/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/
build/
!**/src/main/**/build/
!**/src/test/**/build/
### VS Code ###
.vscode/
### Mac OS ###
.DS_Store
Whitespace-only changes.
-10
View File
@@ -1,10 +0,0 @@
# Default ignored files
/shelf/
/workspace.xml
# Editor-based HTTP Client requests
/httpRequests/
# Environment-dependent path to Maven home directory
/mavenHomeManager.xml
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml
@@ -1,5 +0,0 @@
<component name="ProjectCodeStyleConfiguration">
<state>
<option name="PREFERRED_PROJECT_CODE_STYLE" value="Default" />
</state>
</component>
-25
View File
@@ -1,25 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Encoding">
<file url="file://$PROJECT_DIR$/crane-api-common/src/main/java" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/crane-api-common/src/main/resources" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/crane-api-web/src/main/java" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/crane-api-web/src/main/resources" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/crane-app/src/main/java" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/crane-app/src/main/resources" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/crane-boot/src/main/java" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/crane-boot/src/main/resources" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/crane-common/src/main/java" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/crane-common/src/main/resources" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/crane-doc/src/main/java" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/crane-doc/src/main/resources" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/crane-log/src/main/java" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/crane-log/src/main/resources" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/crane-test/src/main/java" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/crane-test/src/main/resources" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/crane-web/src/main/java" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/crane-web/src/main/resources" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/src/main/java" charset="UTF-8" />
<file url="file://$PROJECT_DIR$/src/main/resources" charset="UTF-8" />
</component>
</project>
-21
View File
@@ -1,21 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ExternalStorageConfigurationManager" enabled="true" />
<component name="MavenProjectsManager">
<option name="originalFiles">
<list>
<option value="$PROJECT_DIR$/pom.xml" />
</list>
</option>
<option name="ignoredFiles">
<set>
<option value="$PROJECT_DIR$/crane-api-common/pom.xml" />
<option value="$PROJECT_DIR$/crane-api-web/pom.xml" />
<option value="$PROJECT_DIR$/crane-doc/pom.xml" />
</set>
</option>
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_21" project-jdk-name="21" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" />
</component>
</project>
-6
View File
@@ -1,6 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$/../../.." vcs="Git" />
</component>
</project>
-30
View File
@@ -1,30 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<groupId>com.crane</groupId>
<artifactId>crane-api</artifactId>
<version>1.0.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>crane-boot</artifactId>
<packaging>jar</packaging>
<description>
主项目启动类
</description>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>com.crane</groupId>
<artifactId>crane-log</artifactId>
</dependency>
</dependencies>
</project>
@@ -1,12 +0,0 @@
package com.crane.boot;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication(scanBasePackages = {"com.crane"})
public class CraneBootApplication {
public static void main(String[] args) {
SpringApplication.run(CraneBootApplication.class, args);
System.out.println("CraneBoot项目启动成功 ლ(´ڡ`ლ)゙");
}
}
@@ -1,6 +0,0 @@
server:
port: 8082
tomcat:
uri-encoding: UTF-8
logging:
module-name: 启动模块
-21
View File
@@ -1,21 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.crane</groupId>
<artifactId>crane-api</artifactId>
<version>1.0.0</version>
</parent>
<artifactId>crane-common</artifactId>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
</dependency>
</dependencies>
</project>
@@ -1,2 +0,0 @@
logging:
module-name: common模块
-15
View File
@@ -1,15 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.crane</groupId>
<artifactId>crane-api</artifactId>
<version>1.0.0</version>
</parent>
<artifactId>crane-log</artifactId>
<description>日志模块</description>
</project>
Binary file not shown.

Before

Width:  |  Height:  |  Size: 643 KiB

-34
View File
@@ -1,34 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.crane</groupId>
<artifactId>crane-api</artifactId>
<version>1.0.0</version>
</parent>
<artifactId>crane-test</artifactId>
<dependencies>
<dependency>
<groupId>com.crane</groupId>
<artifactId>crane-common</artifactId>
</dependency>
<dependency>
<groupId>com.crane</groupId>
<artifactId>crane-log</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
</dependency>
<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>okhttp</artifactId>
</dependency>
</dependencies>
</project>
Binary file not shown.

Before

Width:  |  Height:  |  Size: 256 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 298 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 183 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 224 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 146 KiB

@@ -1,53 +0,0 @@
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");
}
}
@@ -1,127 +0,0 @@
package com.crane.test;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.*;
import java.util.Base64;
import javax.imageio.*;
import javax.imageio.stream.ImageOutputStream;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ObjectNode;
import okhttp3.*;
public class Test {
public static byte[] compressImageToTargetSize(BufferedImage image, float initialQuality, int maxSizeKB) throws IOException {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
float quality = initialQuality;
int maxBytes = maxSizeKB * 1024;
while (quality > 0.05f) {
baos.reset();
ImageWriter jpgWriter = ImageIO.getImageWritersByFormatName("jpg").next();
ImageWriteParam jpgWriteParam = jpgWriter.getDefaultWriteParam();
jpgWriteParam.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
jpgWriteParam.setCompressionQuality(quality); // 0.0 ~ 1.0
ImageOutputStream ios = ImageIO.createImageOutputStream(baos);
jpgWriter.setOutput(ios);
jpgWriter.write(null, new IIOImage(image, null, null), jpgWriteParam);
jpgWriter.dispose();
ios.close();
if (baos.size() <= maxBytes) {
break;
}
quality -= 0.05f;
}
return baos.toByteArray();
}
public static void saveCompressedImageToFile(byte[] imageBytes, String outputPath) throws IOException {
try (FileOutputStream fos = new FileOutputStream(outputPath)) {
fos.write(imageBytes);
}
System.out.println("✅ 压缩图像已保存到: " + outputPath);
}
public static void main(String[] args) throws IOException {
String API_URL = "http://localhost:8866/ocr";
String imagePath = "D:\\workspace\\code\\crane\\crane-api\\crane-test\\src\\main\\java\\com\\crane\\test\\bd88d3c9-2cb9-462a-b5b2-afb2fa0cda8c.jpg";
String compressedImagePath = "D:\\workspace\\code\\crane\\crane-api\\crane-test\\compressed.jpg";
long base64StartTime = System.nanoTime();
// 1. 加载原始图像
BufferedImage originalImage = ImageIO.read(new File(imagePath));
BufferedImage resizedImage = originalImage; // 保持原图尺寸不变
// 3. 压缩图片到小于 500KB
byte[] compressedBytes = compressImageToTargetSize(resizedImage, 1f, 5000);
System.out.println("压缩后图片大小: " + (compressedBytes.length / 1024) + " KB");
// 👉 保存压缩图像到本地
saveCompressedImageToFile(compressedBytes, compressedImagePath);
// 4. 转为 Base64 编码
String base64Image = Base64.getEncoder().encodeToString(compressedBytes);
long base64EndTime = System.nanoTime();
long durationMs1 = (base64EndTime - base64StartTime) / 1_000_000;
System.out.println("图片压缩 + BASE64 编码耗时: " + durationMs1 + " ms");
// 5. 构建请求
ObjectMapper objectMapper = new ObjectMapper();
ObjectNode payload = objectMapper.createObjectNode();
payload.put("file", base64Image);
payload.put("fileType", 1);
OkHttpClient client = new OkHttpClient.Builder()
.connectTimeout(300, java.util.concurrent.TimeUnit.SECONDS)
.writeTimeout(300, java.util.concurrent.TimeUnit.SECONDS)
.readTimeout(300, java.util.concurrent.TimeUnit.SECONDS)
.build();
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();
long startTime = System.nanoTime();
try (Response response = client.newCall(request).execute()) {
long endTime = System.nanoTime();
long durationMs = (endTime - startTime) / 1_000_000;
System.out.println("⏱️ 请求耗时: " + durationMs + " ms");
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(prunedResult);
JsonNode recTexts = prunedResult.get("rec_texts");
if (recTexts != null && recTexts.isArray()) {
System.out.println("📦 rec_texts:");
for (JsonNode text : recTexts) {
System.out.println(" ➤ " + text.asText());
}
} else {
System.out.println("❗ 未检测到 rec_texts 字段");
}
}
} else {
System.err.println("Request failed with HTTP code: " + response.code());
}
}
}
}
@@ -1,40 +0,0 @@
package com.crane.test;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;
import java.io.IOException;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
public class Test2 {
public static void main(String[] args) {
String lon = "116.37304";
String lat = "39.92594";
String tk = "f1dbb4a15e82006fca57d3286bbc410a"; // 替换为你的真实 key
String postStrJson = String.format("{\"lon\":%s,\"lat\":%s,\"ver\":1}", lon, lat);
String encodedPostStr = URLEncoder.encode(postStrJson, StandardCharsets.UTF_8);
String url = String.format(
"https://api.tianditu.gov.cn/geocoder?postStr=%s&type=geocode&tk=%s",
encodedPostStr, tk
);
System.out.println(url);
OkHttpClient client = new OkHttpClient();
Request request = new Request.Builder()
.url(url)
.header("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.36")
.build();
try (Response response = client.newCall(request).execute()) {
if (response.isSuccessful() && response.body() != null) {
String result = response.body().string();
System.out.println("响应内容:\n" + result);
} else {
System.out.println("请求失败,状态码:" + response.code());
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
Binary file not shown.

Before

Width:  |  Height:  |  Size: 225 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 187 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.6 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 9.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 49 KiB

@@ -1,2 +0,0 @@
logging:
module-name: 测试模块
-139
View File
@@ -1,139 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.crane</groupId>
<artifactId>crane-api</artifactId>
<version>1.0.0</version>
<!-- 项目打包方式 -->
<packaging>pom</packaging>
<!-- 子模块 -->
<modules>
<module>crane-common</module>
<module>crane-boot</module>
<module>crane-log</module>
<module>crane-test</module>
</modules>
<!-- 版本信息 -->
<properties>
<crane.version>1.0.0</crane.version>
<maven.compiler.source>21</maven.compiler.source>
<maven.compiler.target>21</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<spring.boot.version>3.2.6</spring.boot.version>
<spring.framework.version>6.1.8</spring.framework.version>
<smart.doc.version>3.0.5</smart.doc.version>
</properties>
<!-- 依赖管理 -->
<dependencyManagement>
<dependencies>
<!-- Spring Boot Dependencies:当使用该依赖时,Maven就会自动使用该pom中定义的依赖版本 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>${spring.boot.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<!-- SpringFramework的依赖配置
作用:在maven的pom.xml中无需指定具体的类库版本,直接使用,即默认使用bom中指定的版本。
查询方式:https://docs.spring.io/spring-boot/docs/3.0.2/reference/html/getting-started.html#getting
查询时切换版本号即可
所有SpringBoot版本号:https://docs.spring.io/spring-boot/docs/
-->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-framework-bom</artifactId>
<version>${spring.framework.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>com.crane</groupId>
<artifactId>crane-boot</artifactId>
<version>${crane.version}</version>
</dependency>
<dependency>
<groupId>com.crane</groupId>
<artifactId>crane-common</artifactId>
<version>${crane.version}</version>
</dependency>
<dependency>
<groupId>com.crane</groupId>
<artifactId>crane-doc</artifactId>
<version>${crane.version}</version>
</dependency>
<dependency>
<groupId>com.crane</groupId>
<artifactId>crane-log</artifactId>
<version>${crane.version}</version>
</dependency>
<dependency>
<groupId>com.crane</groupId>
<artifactId>crane-test</artifactId>
<version>${crane.version}</version>
</dependency>
</dependencies>
</dependencyManagement>
<!-- 构建插件 -->
<build>
<!-- 统一插件管理 -->
<pluginManagement>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<!-- 排除lombok依赖,该依赖只作用于编译阶段。 -->
<configuration>
<excludes>
<exclude>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
<repositories>
<repository>
<id>public</id>
<name>aliyun nexus</name>
<url>https://maven.aliyun.com/repository/public</url>
<releases>
<enabled>true</enabled>
</releases>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>public</id>
<name>aliyun nexus</name>
<url>https://maven.aliyun.com/repository/public</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>
</project>
-20
View File
@@ -1,20 +0,0 @@
# 1 项目结构
该项目是多模块项目结构,当前结构如下:
## 1.3 crane-doc
> 如不需要该模块,可直接移除
该模块是生成 Api 文档的模块,采用的技术是:`smart-doc` .
### 1.3.1 全局使用
配置文件:`smart-doc/src/main/resources/smart-doc.json`
### 1.3.2 单模块使用
在对应的模块下引入 `smart-doc` 模块