|
@@ -1,6 +1,7 @@
|
|
|
package com.jeeplus.assess.programAuditAi.service;
|
|
package com.jeeplus.assess.programAuditAi.service;
|
|
|
|
|
|
|
|
import com.alibaba.fastjson.JSON;
|
|
import com.alibaba.fastjson.JSON;
|
|
|
|
|
+import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.jeeplus.assess.programAuditAi.client.WeKnoraAgentClient;
|
|
import com.jeeplus.assess.programAuditAi.client.WeKnoraAgentClient;
|
|
@@ -45,9 +46,18 @@ public class ProgramAuditAiAsyncService {
|
|
|
"jpg", "jpeg", "png", "bmp", "gif", "tif", "tiff", "webp"
|
|
"jpg", "jpeg", "png", "bmp", "gif", "tif", "tiff", "webp"
|
|
|
));
|
|
));
|
|
|
|
|
|
|
|
|
|
+ /** 图片解析每批数量,固定 4 张。 */
|
|
|
|
|
+ private static final int IMAGE_BATCH_SIZE = 4;
|
|
|
|
|
+
|
|
|
private static final String IMAGE_PARSE_QUERY =
|
|
private static final String IMAGE_PARSE_QUERY =
|
|
|
- "请解析本会话中的图片资料,输出结构化解析文字。保留项目名称、金额、日期、单位、结论、表格数据等与资产评估校审相关的信息;"
|
|
|
|
|
- + "不要编造,无法识别的写“无法识别”。只输出解析文字,不要输出解释。";
|
|
|
|
|
|
|
+ "请逐张解析本会话中的全部图片资料,只输出一个 JSON 对象,不要输出 Markdown 代码块、解释或其他文字。\n"
|
|
|
|
|
+ + "JSON 格式固定为:\n"
|
|
|
|
|
+ + "{\"images\":[{\"file_name\":\"图片文件名\",\"picture_content\":\"解析出的文字描述\"}]}\n"
|
|
|
|
|
+ + "要求:\n"
|
|
|
|
|
+ + "1. 必须为每一张上传的图片输出且只输出一条记录,不得合并、遗漏或重复;\n"
|
|
|
|
|
+ + "2. file_name 必须与上传时的原始文件名完全一致;\n"
|
|
|
|
|
+ + "3. picture_content 填写从图片识别到的内容,如:项目名称、金额、等信息;无法识别的写“无法识别”;\n"
|
|
|
|
|
+ + "4. 不得编造,只输出 JSON;所有字符串必须使用双引号。";
|
|
|
|
|
|
|
|
@Resource(name = "programAuditAiExecutor")
|
|
@Resource(name = "programAuditAiExecutor")
|
|
|
private Executor executor;
|
|
private Executor executor;
|
|
@@ -151,14 +161,34 @@ public class ProgramAuditAiAsyncService {
|
|
|
|
|
|
|
|
String imageTexts = "";
|
|
String imageTexts = "";
|
|
|
if (!imageItems.isEmpty()) {
|
|
if (!imageItems.isEmpty()) {
|
|
|
- imageTexts = parseImages(imageItems);
|
|
|
|
|
|
|
+ try {
|
|
|
|
|
+ imageTexts = parseImages(imageItems);
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ String message = StringUtils.abbreviate(
|
|
|
|
|
+ StringUtils.defaultIfBlank(e.getMessage(), "图片解析失败"), 1000);
|
|
|
|
|
+ log.warn("校审AI图片解析失败,降级使用非图片附件继续生成 generationId={} err={}",
|
|
|
|
|
+ generationId, message);
|
|
|
|
|
+ // 图片未纳入本次校审时,标记对应图片失败;只要还有非图片附件,任务继续。
|
|
|
|
|
+ for (ImageItem item : imageItems) {
|
|
|
|
|
+ if (!"failed".equalsIgnoreCase(StringUtils.defaultString(item.file.getParseStatus()))) {
|
|
|
|
|
+ markFileFailed(item.file, "图片解析失败:" + message);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
if (uploadedCount == 0 && StringUtils.isBlank(imageTexts)) {
|
|
if (uploadedCount == 0 && StringUtils.isBlank(imageTexts)) {
|
|
|
throw new ProgramAuditAiException("ATTACHMENT_PARSE_FAILED", "附件均未能成功上传或解析,请检查文件后重试");
|
|
throw new ProgramAuditAiException("ATTACHMENT_PARSE_FAILED", "附件均未能成功上传或解析,请检查文件后重试");
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- String query = buildQuery(generation, files, imageTexts);
|
|
|
|
|
|
|
+ // 只把真正可用的文件列入校审附件清单,避免把解析失败的图片/文件误报为已读取。
|
|
|
|
|
+ List<ProgramAuditAiGenerationFile> queryFiles = new ArrayList<>();
|
|
|
|
|
+ for (ProgramAuditAiGenerationFile file : files) {
|
|
|
|
|
+ if (!"failed".equalsIgnoreCase(StringUtils.defaultString(file.getParseStatus()))) {
|
|
|
|
|
+ queryFiles.add(file);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ String query = buildQuery(generation, queryFiles, imageTexts);
|
|
|
String answer = weKnoraAgentClient.chat(auditSessionId, query, properties.getAgentId(), auditAttachmentIds);
|
|
String answer = weKnoraAgentClient.chat(auditSessionId, query, properties.getAgentId(), auditAttachmentIds);
|
|
|
ParsedResult parsed = parseResult(answer);
|
|
ParsedResult parsed = parseResult(answer);
|
|
|
|
|
|
|
@@ -249,19 +279,52 @@ public class ProgramAuditAiAsyncService {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
private String parseImages(List<ImageItem> imageItems) {
|
|
private String parseImages(List<ImageItem> imageItems) {
|
|
|
|
|
+ int batchSize = IMAGE_BATCH_SIZE;
|
|
|
|
|
+ List<ImageText> allParsed = new ArrayList<>();
|
|
|
|
|
+ int batchIndex = 0;
|
|
|
|
|
+ for (int start = 0; start < imageItems.size(); start += batchSize) {
|
|
|
|
|
+ int end = Math.min(start + batchSize, imageItems.size());
|
|
|
|
|
+ List<ImageItem> batch = new ArrayList<>(imageItems.subList(start, end));
|
|
|
|
|
+ batchIndex++;
|
|
|
|
|
+ try {
|
|
|
|
|
+ allParsed.addAll(parseImageBatch(batch, batchIndex));
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ String message = StringUtils.abbreviate(
|
|
|
|
|
+ StringUtils.defaultIfBlank(e.getMessage(), "图片解析失败"), 1000);
|
|
|
|
|
+ log.warn("校审AI图片批次解析失败,降级继续 batch={} size={} err={}",
|
|
|
|
|
+ batchIndex, batch.size(), message);
|
|
|
|
|
+ // 只标记当前批次,其他批次和非图片附件继续处理。
|
|
|
|
|
+ for (ImageItem item : batch) {
|
|
|
|
|
+ if (!"failed".equalsIgnoreCase(StringUtils.defaultString(item.file.getParseStatus()))) {
|
|
|
|
|
+ markFileFailed(item.file, "图片解析失败:" + message);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ if (allParsed.isEmpty()) {
|
|
|
|
|
+ return "";
|
|
|
|
|
+ }
|
|
|
|
|
+ return buildImageTextsJson(allParsed);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 单个图片批次:独立会话、独立解析、独立校验,避免多批图片互相污染上下文。
|
|
|
|
|
+ */
|
|
|
|
|
+ private List<ImageText> parseImageBatch(List<ImageItem> batch, int batchIndex) {
|
|
|
if (StringUtils.isBlank(properties.getImageAgentId())) {
|
|
if (StringUtils.isBlank(properties.getImageAgentId())) {
|
|
|
throw new ProgramAuditAiException("AGENT_NOT_CONFIGURED", "图片解析 Agent 未配置");
|
|
throw new ProgramAuditAiException("AGENT_NOT_CONFIGURED", "图片解析 Agent 未配置");
|
|
|
}
|
|
}
|
|
|
- String imageSessionId = weKnoraAgentClient.createSession("校审图片-" + System.currentTimeMillis());
|
|
|
|
|
- List<String> imageAttachmentIds = new ArrayList<>();
|
|
|
|
|
- for (ImageItem item : imageItems) {
|
|
|
|
|
|
|
+ String imageSessionId = weKnoraAgentClient.createSession(
|
|
|
|
|
+ "校审图片-" + batchIndex + "-" + System.currentTimeMillis());
|
|
|
|
|
+ List<ImageItem> uploadedCandidates = new ArrayList<>();
|
|
|
|
|
+ List<String> candidateAttachmentIds = new ArrayList<>();
|
|
|
|
|
+ for (ImageItem item : batch) {
|
|
|
try {
|
|
try {
|
|
|
WeKnoraAgentClient.AttachmentResult result = weKnoraAgentClient.uploadAttachment(
|
|
WeKnoraAgentClient.AttachmentResult result = weKnoraAgentClient.uploadAttachment(
|
|
|
imageSessionId, item.file.getFileName(), item.bytes, properties.getImageAgentId());
|
|
imageSessionId, item.file.getFileName(), item.bytes, properties.getImageAgentId());
|
|
|
if (StringUtils.isNotBlank(result.getId())) {
|
|
if (StringUtils.isNotBlank(result.getId())) {
|
|
|
- result = weKnoraAgentClient.waitAttachmentReady(imageSessionId, result.getId());
|
|
|
|
|
- imageAttachmentIds.add(result.getId());
|
|
|
|
|
- markFileUploaded(item.file, result);
|
|
|
|
|
|
|
+ uploadedCandidates.add(item);
|
|
|
|
|
+ candidateAttachmentIds.add(result.getId());
|
|
|
} else {
|
|
} else {
|
|
|
markFileFailed(item.file, "WeKnora 未返回图片附件ID");
|
|
markFileFailed(item.file, "WeKnora 未返回图片附件ID");
|
|
|
}
|
|
}
|
|
@@ -269,12 +332,217 @@ public class ProgramAuditAiAsyncService {
|
|
|
markFileFailed(item.file, e.getMessage());
|
|
markFileFailed(item.file, e.getMessage());
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
+ // 同一批先全部上传,再统一等待解析,避免逐张串行等待。
|
|
|
|
|
+ List<ImageItem> uploadedItems = new ArrayList<>();
|
|
|
|
|
+ List<String> imageAttachmentIds = new ArrayList<>();
|
|
|
|
|
+ for (int i = 0; i < uploadedCandidates.size(); i++) {
|
|
|
|
|
+ ImageItem item = uploadedCandidates.get(i);
|
|
|
|
|
+ try {
|
|
|
|
|
+ WeKnoraAgentClient.AttachmentResult ready = weKnoraAgentClient.waitAttachmentReady(
|
|
|
|
|
+ imageSessionId, candidateAttachmentIds.get(i));
|
|
|
|
|
+ if (StringUtils.isNotBlank(ready.getId())) {
|
|
|
|
|
+ imageAttachmentIds.add(ready.getId());
|
|
|
|
|
+ markFileUploaded(item.file, ready);
|
|
|
|
|
+ uploadedItems.add(item);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ markFileFailed(item.file, "WeKnora 图片解析完成但未返回附件ID");
|
|
|
|
|
+ }
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ markFileFailed(item.file, e.getMessage());
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
if (imageAttachmentIds.isEmpty()) {
|
|
if (imageAttachmentIds.isEmpty()) {
|
|
|
- return "";
|
|
|
|
|
|
|
+ return new ArrayList<>();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ String answer = weKnoraAgentClient.chat(imageSessionId, IMAGE_PARSE_QUERY,
|
|
|
|
|
+ properties.getImageAgentId(), imageAttachmentIds);
|
|
|
|
|
+ List<ImageText> parsedImages = parseImageAnswer(answer, uploadedItems);
|
|
|
|
|
+ if (parsedImages.isEmpty()) {
|
|
|
|
|
+ throw new ProgramAuditAiException("IMAGE_JSON_INVALID",
|
|
|
|
|
+ "图片解析结果没有有效的 file_name/picture_content");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ Set<String> parsedFileIds = new HashSet<>();
|
|
|
|
|
+ for (ImageText imageText : parsedImages) {
|
|
|
|
|
+ markImageParsed(imageText.file, imageText.pictureContent);
|
|
|
|
|
+ parsedFileIds.add(imageText.file.getId());
|
|
|
|
|
+ }
|
|
|
|
|
+ // Agent 少返回的图片没有可用解析文字,按失败处理,避免状态显示为 ready 但无内容。
|
|
|
|
|
+ for (ImageItem item : uploadedItems) {
|
|
|
|
|
+ if (!parsedFileIds.contains(item.file.getId())) {
|
|
|
|
|
+ markFileFailed(item.file, "图片解析结果缺少该图片的 picture_content");
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ return parsedImages;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 解析图片 Agent 返回的 JSON,并按 file_name 与本次上传的图片逐条匹配。
|
|
|
|
|
+ */
|
|
|
|
|
+ private List<ImageText> parseImageAnswer(String answer, List<ImageItem> expected) {
|
|
|
|
|
+ JSONArray imageArray = extractImageArray(answer);
|
|
|
|
|
+ List<ImageText> results = new ArrayList<>();
|
|
|
|
|
+ Set<Integer> matchedIndexes = new HashSet<>();
|
|
|
|
|
+ for (int i = 0; i < imageArray.size(); i++) {
|
|
|
|
|
+ Object value = imageArray.get(i);
|
|
|
|
|
+ if (!(value instanceof JSONObject)) {
|
|
|
|
|
+ log.warn("校审AI图片解析结果第{}项不是JSON对象,已忽略", i + 1);
|
|
|
|
|
+ continue;
|
|
|
|
|
+ }
|
|
|
|
|
+ JSONObject imageObject = (JSONObject) value;
|
|
|
|
|
+ String fileName = StringUtils.trimToEmpty(imageObject.getString("file_name"));
|
|
|
|
|
+ String pictureContent = StringUtils.trimToEmpty(imageObject.getString("picture_content"));
|
|
|
|
|
+ if (StringUtils.isBlank(fileName) || StringUtils.isBlank(pictureContent)) {
|
|
|
|
|
+ log.warn("校审AI图片解析结果第{}项缺少 file_name 或 picture_content,已忽略", i + 1);
|
|
|
|
|
+ continue;
|
|
|
|
|
+ }
|
|
|
|
|
+ int matchedIndex = findImageIndex(expected, matchedIndexes, fileName);
|
|
|
|
|
+ if (matchedIndex < 0) {
|
|
|
|
|
+ log.warn("校审AI图片解析结果中的 file_name 未匹配到上传图片: {}", fileName);
|
|
|
|
|
+ continue;
|
|
|
|
|
+ }
|
|
|
|
|
+ matchedIndexes.add(matchedIndex);
|
|
|
|
|
+ ImageItem imageItem = expected.get(matchedIndex);
|
|
|
|
|
+ ImageText imageText = new ImageText();
|
|
|
|
|
+ imageText.file = imageItem.file;
|
|
|
|
|
+ imageText.fileName = imageItem.file.getFileName();
|
|
|
|
|
+ imageText.pictureContent = limitPictureContent(pictureContent);
|
|
|
|
|
+ results.add(imageText);
|
|
|
}
|
|
}
|
|
|
- String text = weKnoraAgentClient.chat(imageSessionId, IMAGE_PARSE_QUERY, properties.getImageAgentId(), imageAttachmentIds);
|
|
|
|
|
- int totalLimit = properties.getImageTextTotalMaxChars() == null ? 30000 : Math.max(1000, properties.getImageTextTotalMaxChars());
|
|
|
|
|
- return StringUtils.left(StringUtils.trimToEmpty(text), totalLimit);
|
|
|
|
|
|
|
+ return results;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 从 Agent 回答中提取图片解析 JSON。兼容根对象 {"images":[...]} 和根数组 [...].
|
|
|
|
|
+ */
|
|
|
|
|
+ private JSONArray extractImageArray(String answer) {
|
|
|
|
|
+ String text = stripCodeFence(answer);
|
|
|
|
|
+ int start = text.indexOf('{');
|
|
|
|
|
+ int arrayStart = text.indexOf('[');
|
|
|
|
|
+ if (arrayStart >= 0 && (start < 0 || arrayStart < start)) {
|
|
|
|
|
+ start = arrayStart;
|
|
|
|
|
+ }
|
|
|
|
|
+ int end = text.lastIndexOf('}');
|
|
|
|
|
+ int arrayEnd = text.lastIndexOf(']');
|
|
|
|
|
+ if (arrayEnd >= 0 && arrayEnd > end) {
|
|
|
|
|
+ end = arrayEnd;
|
|
|
|
|
+ }
|
|
|
|
|
+ if (start < 0 || end <= start) {
|
|
|
|
|
+ throw new ProgramAuditAiException("IMAGE_JSON_INVALID",
|
|
|
|
|
+ "图片解析 Agent 返回内容不是有效 JSON");
|
|
|
|
|
+ }
|
|
|
|
|
+ Object parsed;
|
|
|
|
|
+ try {
|
|
|
|
|
+ parsed = JSON.parse(text.substring(start, end + 1));
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ throw new ProgramAuditAiException("IMAGE_JSON_INVALID",
|
|
|
|
|
+ "图片解析 Agent 返回 JSON 解析失败");
|
|
|
|
|
+ }
|
|
|
|
|
+ if (parsed instanceof JSONArray) {
|
|
|
|
|
+ return (JSONArray) parsed;
|
|
|
|
|
+ }
|
|
|
|
|
+ if (parsed instanceof JSONObject) {
|
|
|
|
|
+ JSONObject root = (JSONObject) parsed;
|
|
|
|
|
+ Object images = root.get("images");
|
|
|
|
|
+ if (images instanceof JSONArray) {
|
|
|
|
|
+ return (JSONArray) images;
|
|
|
|
|
+ }
|
|
|
|
|
+ Object imageTexts = root.get("image_texts");
|
|
|
|
|
+ if (imageTexts instanceof JSONArray) {
|
|
|
|
|
+ return (JSONArray) imageTexts;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ throw new ProgramAuditAiException("IMAGE_JSON_INVALID",
|
|
|
|
|
+ "图片解析 Agent 返回 JSON 缺少 images 数组");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private int findImageIndex(List<ImageItem> expected, Set<Integer> matchedIndexes, String fileName) {
|
|
|
|
|
+ String target = normalizeFileName(fileName);
|
|
|
|
|
+ int baseNameMatch = -1;
|
|
|
|
|
+ for (int i = 0; i < expected.size(); i++) {
|
|
|
|
|
+ if (matchedIndexes.contains(i)) {
|
|
|
|
|
+ continue;
|
|
|
|
|
+ }
|
|
|
|
|
+ String current = normalizeFileName(expected.get(i).file.getFileName());
|
|
|
|
|
+ if (current.equals(target)) {
|
|
|
|
|
+ return i;
|
|
|
|
|
+ }
|
|
|
|
|
+ if (baseNameMatch < 0 && stripExtension(current).equals(stripExtension(target))) {
|
|
|
|
|
+ baseNameMatch = i;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ return baseNameMatch;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private String normalizeFileName(String fileName) {
|
|
|
|
|
+ String value = StringUtils.trimToEmpty(fileName).replace('\\', '/');
|
|
|
|
|
+ int slash = value.lastIndexOf('/');
|
|
|
|
|
+ if (slash >= 0) {
|
|
|
|
|
+ value = value.substring(slash + 1);
|
|
|
|
|
+ }
|
|
|
|
|
+ return StringUtils.lowerCase(value);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private String stripExtension(String fileName) {
|
|
|
|
|
+ int dot = fileName.lastIndexOf('.');
|
|
|
|
|
+ return dot > 0 ? fileName.substring(0, dot) : fileName;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private String limitPictureContent(String content) {
|
|
|
|
|
+ int max = properties.getImageTextMaxChars() == null ? 4000
|
|
|
|
|
+ : Math.max(200, properties.getImageTextMaxChars());
|
|
|
|
|
+ return truncateContent(content, max, "(图片解析文字超长,已截断)");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private String truncateContent(String content, int max, String suffix) {
|
|
|
|
|
+ if (StringUtils.length(content) <= max) {
|
|
|
|
|
+ return content;
|
|
|
|
|
+ }
|
|
|
|
|
+ String safeSuffix = StringUtils.defaultString(suffix);
|
|
|
|
|
+ int keep = Math.max(1, max - safeSuffix.length());
|
|
|
|
|
+ return StringUtils.left(content, keep) + safeSuffix;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 生成传给校审 Agent 的 image_texts JSON。数据库保留每张图片的 picture_content,
|
|
|
|
|
+ * 这里只对本次 query 的总长度做预算,避免总文本过长。
|
|
|
|
|
+ */
|
|
|
|
|
+ private String buildImageTextsJson(List<ImageText> images) {
|
|
|
|
|
+ int totalLimit = properties.getImageTextTotalMaxChars() == null ? 30000
|
|
|
|
|
+ : Math.max(1000, properties.getImageTextTotalMaxChars());
|
|
|
|
|
+ int total = 0;
|
|
|
|
|
+ for (ImageText image : images) {
|
|
|
|
|
+ total += StringUtils.length(image.pictureContent);
|
|
|
|
|
+ }
|
|
|
|
|
+ JSONArray imageArray = new JSONArray();
|
|
|
|
|
+ int remaining = totalLimit;
|
|
|
|
|
+ for (int i = 0; i < images.size(); i++) {
|
|
|
|
|
+ ImageText image = images.get(i);
|
|
|
|
|
+ String content = image.pictureContent;
|
|
|
|
|
+ if (total > totalLimit) {
|
|
|
|
|
+ int remainingImages = images.size() - i;
|
|
|
|
|
+ int maxForThis = Math.max(200, remaining / Math.max(1, remainingImages));
|
|
|
|
|
+ content = truncateContent(content, maxForThis, "(因图片文字总量限制,已截断)");
|
|
|
|
|
+ remaining -= StringUtils.length(content);
|
|
|
|
|
+ }
|
|
|
|
|
+ JSONObject item = new JSONObject();
|
|
|
|
|
+ item.put("file_name", image.fileName);
|
|
|
|
|
+ item.put("picture_content", content);
|
|
|
|
|
+ imageArray.add(item);
|
|
|
|
|
+ }
|
|
|
|
|
+ JSONObject root = new JSONObject();
|
|
|
|
|
+ root.put("image_texts", imageArray);
|
|
|
|
|
+ return root.toJSONString();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private void markImageParsed(ProgramAuditAiGenerationFile file, String pictureContent) {
|
|
|
|
|
+ file.setPictureContent(pictureContent);
|
|
|
|
|
+ file.setParseStatus("ready");
|
|
|
|
|
+ file.setParseError(null);
|
|
|
|
|
+ file.setUpdateById(file.getCreateById());
|
|
|
|
|
+ file.setUpdateTime(new Date());
|
|
|
|
|
+ fileMapper.updateById(file);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
private String buildQuery(ProgramAuditAiGeneration generation, List<ProgramAuditAiGenerationFile> files, String imageTexts) {
|
|
private String buildQuery(ProgramAuditAiGeneration generation, List<ProgramAuditAiGenerationFile> files, String imageTexts) {
|
|
@@ -496,6 +764,13 @@ public class ProgramAuditAiAsyncService {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@Data
|
|
@Data
|
|
|
|
|
+ private static class ImageText {
|
|
|
|
|
+ private ProgramAuditAiGenerationFile file;
|
|
|
|
|
+ private String fileName;
|
|
|
|
|
+ private String pictureContent;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Data
|
|
|
public static class Segment {
|
|
public static class Segment {
|
|
|
private String key;
|
|
private String key;
|
|
|
private String status;
|
|
private String status;
|