适用于工作空间、文件类别、审核规则库均已配置完毕的场景。 *
依赖:OkHttp 4.x、Gson(见 pom.xml)
*/
public class ApReviewConfigured {
// ============================================================
// 配置项 — 请替换为您的实际值
// ============================================================
private static final String APP_ID = "your-app-id"; // x-ti-app-id
private static final String SECRET_CODE = "your-secret-code"; // x-ti-secret-code
private static final String WORKSPACE_ID = "your-workspace-id"; // 已创建的工作空间 ID
private static final String REPO_ID = "your-repo-id"; // 已配置的审核规则库 ID
private static final String BASE_URL = "https://docflow.textin.com";
// 待处理文件目录
private static final String FILES_DIR =
new File("../sample_files/ap_review").getAbsolutePath();
// ============================================================
// 全局工具对象
// ============================================================
private static final OkHttpClient HTTP = new OkHttpClient.Builder()
.connectTimeout(30, TimeUnit.SECONDS)
.readTimeout(60, TimeUnit.SECONDS)
.writeTimeout(60, TimeUnit.SECONDS)
.build();
private static final Gson GSON = new GsonBuilder().disableHtmlEscaping().create();
private static final MediaType JSON_TYPE = MediaType.get("application/json; charset=utf-8");
// ============================================================
// 工具辅助函数
// ============================================================
private static Headers authHeaders() {
return new Headers.Builder()
.add("x-ti-app-id", APP_ID)
.add("x-ti-secret-code", SECRET_CODE)
.build();
}
private static JsonObject checkResponse(String body, String action) {
JsonObject obj = JsonParser.parseString(body).getAsJsonObject();
if (obj.get("code").getAsInt() != 200) {
throw new RuntimeException(action + " 失败: " + body);
}
return obj;
}
private static String mimeType(String filename) {
String lower = filename.toLowerCase();
if (lower.endsWith(".png")) return "image/png";
if (lower.endsWith(".jpg") || lower.endsWith(".jpeg")) return "image/jpeg";
if (lower.endsWith(".pdf")) return "application/pdf";
if (lower.endsWith(".docx")) return "application/vnd.openxmlformats-officedocument.wordprocessingml.document";
if (lower.endsWith(".xlsx")) return "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
return "application/octet-stream";
}
public static void displayResult(JsonObject fileResult) {
System.out.println("\n" + "=".repeat(60));
System.out.println("文件名 : " + str(fileResult, "name"));
System.out.println("分类结果 : " + str(fileResult, "category", "未分类"));
if (!fileResult.has("data") || fileResult.get("data").isJsonNull()) return;
JsonObject data = fileResult.getAsJsonObject("data");
JsonArray fields = jsonArray(data, "fields");
if (fields != null && fields.size() > 0) {
System.out.println("\n── 基本信息字段 ────────────────────────");
for (JsonElement e : fields) {
JsonObject f = e.getAsJsonObject();
System.out.printf(" %-25s: %s%n", str(f, "key"), str(f, "value"));
}
}
JsonArray tables = jsonArray(data, "tables");
if (tables != null) {
for (JsonElement te : tables) {
JsonObject table = te.getAsJsonObject();
String tname = str(table, "tableName");
JsonArray tItems = jsonArray(table, "items");
if (tItems != null && tItems.size() > 0) {
System.out.println("\n── 表格[" + tname + "] ──────────────────────");
for (int i = 0; i < tItems.size(); i++) {
JsonArray row = tItems.get(i).getAsJsonArray();
StringBuilder sb = new StringBuilder(" 第").append(i + 1).append("行: ");
for (int j = 0; j < row.size(); j++) {
JsonObject cell = row.get(j).getAsJsonObject();
if (j > 0) sb.append(" | ");
sb.append(str(cell, "key")).append("=").append(str(cell, "value"));
}
System.out.println(sb);
}
}
}
}
}
public static void displayReviewResult(JsonObject reviewResult) {
Map
适用于工作空间、文件类别、审核规则库均已配置完毕的场景。 *
依赖:OkHttp 4.x、Gson(见 pom.xml)
*/
public class ContractReviewConfigured {
// ============================================================
// 配置项 — 请替换为您的实际值
// ============================================================
private static final String APP_ID = "your-app-id"; // x-ti-app-id
private static final String SECRET_CODE = "your-secret-code"; // x-ti-secret-code
private static final String WORKSPACE_ID = "your-workspace-id"; // 已创建的工作空间 ID
private static final String REPO_ID = "your-repo-id"; // 已配置的审核规则库 ID
private static final String BASE_URL = "https://docflow.textin.com";
// 待处理文件目录
private static final String FILES_DIR =
new File("../sample_files/contract_review").getAbsolutePath();
// ============================================================
// 全局工具对象
// ============================================================
private static final OkHttpClient HTTP = new OkHttpClient.Builder()
.connectTimeout(30, TimeUnit.SECONDS)
.readTimeout(90, TimeUnit.SECONDS)
.writeTimeout(60, TimeUnit.SECONDS)
.build();
private static final Gson GSON = new GsonBuilder().disableHtmlEscaping().create();
private static final MediaType JSON_TYPE = MediaType.get("application/json; charset=utf-8");
// ============================================================
// 工具辅助函数
// ============================================================
private static Headers authHeaders() {
return new Headers.Builder()
.add("x-ti-app-id", APP_ID)
.add("x-ti-secret-code", SECRET_CODE)
.build();
}
private static JsonObject checkResponse(String body, String action) {
JsonObject obj = JsonParser.parseString(body).getAsJsonObject();
if (obj.get("code").getAsInt() != 200) {
throw new RuntimeException(action + " 失败: " + body);
}
return obj;
}
private static String mimeType(String filename) {
String lower = filename.toLowerCase();
if (lower.endsWith(".png")) return "image/png";
if (lower.endsWith(".jpg") || lower.endsWith(".jpeg")) return "image/jpeg";
if (lower.endsWith(".pdf")) return "application/pdf";
if (lower.endsWith(".docx")) return "application/vnd.openxmlformats-officedocument.wordprocessingml.document";
if (lower.endsWith(".xlsx")) return "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
return "application/octet-stream";
}
public static void displayResult(JsonObject fileResult) {
System.out.println("\n" + "=".repeat(60));
System.out.println("文件名 : " + str(fileResult, "name"));
System.out.println("分类结果 : " + str(fileResult, "category", "未分类"));
if (!fileResult.has("data") || fileResult.get("data").isJsonNull()) return;
JsonObject data = fileResult.getAsJsonObject("data");
JsonArray fields = jsonArray(data, "fields");
if (fields != null && fields.size() > 0) {
System.out.println("\n── 基本信息字段 ────────────────────────");
for (JsonElement e : fields) {
JsonObject f = e.getAsJsonObject();
String val = str(f, "value");
String display = val.length() > 80 ? val.substring(0, 80) + "..." : val;
System.out.printf(" %-25s: %s%n", str(f, "key"), display);
}
}
}
public static void displayReviewResult(JsonObject reviewResult) {
Map
| 这是一个表格 |