历史记录优化
This commit is contained in:
@@ -1,34 +1,21 @@
|
||||
package com.gxwebsoft.ai.controller;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.gxwebsoft.ai.dto.AuditContentRequest;
|
||||
import com.gxwebsoft.ai.dto.export.PartyConductExportEntity;
|
||||
import com.gxwebsoft.ai.entity.AiCloudDoc;
|
||||
import com.gxwebsoft.ai.entity.AiCloudFile;
|
||||
import com.gxwebsoft.ai.service.AiHistoryService;
|
||||
import com.gxwebsoft.ai.utils.ExcelExportTool;
|
||||
import com.gxwebsoft.common.core.web.ApiResult;
|
||||
import com.gxwebsoft.common.core.web.BaseController;
|
||||
import com.gxwebsoft.common.system.entity.User;
|
||||
import com.gxwebsoft.pwl.entity.PwlProjectLibrary;
|
||||
import com.gxwebsoft.pwl.service.PwlProjectLibraryService;
|
||||
import com.gxwebsoft.ai.service.AiCloudDocService;
|
||||
import com.gxwebsoft.ai.service.AiCloudFileService;
|
||||
import com.gxwebsoft.ai.service.AuditContent10PartyConductService;
|
||||
import com.gxwebsoft.ai.service.KnowledgeBaseService;
|
||||
import com.gxwebsoft.common.core.web.ApiResult;
|
||||
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.crypto.digest.DigestUtil;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.util.*;
|
||||
import java.util.function.Function;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
@@ -38,29 +25,11 @@ import java.util.stream.Collectors;
|
||||
@Tag(name = "审计内容10-廉政情况")
|
||||
@RestController
|
||||
@RequestMapping("/api/ai/auditContent10")
|
||||
public class AuditContent10Controller extends BaseController {
|
||||
public class AuditContent10Controller extends BaseAuditContentController {
|
||||
|
||||
@Autowired
|
||||
private AuditContent10PartyConductService auditContent10PartyConductService;
|
||||
|
||||
@Autowired
|
||||
private AiCloudDocService aiCloudDocService;
|
||||
|
||||
@Autowired
|
||||
private AiCloudFileService aiCloudFileService;
|
||||
|
||||
@Autowired
|
||||
private KnowledgeBaseService knowledgeBaseService;
|
||||
|
||||
@Autowired
|
||||
private PwlProjectLibraryService pwlProjectLibraryService;
|
||||
|
||||
@Autowired
|
||||
private AiHistoryService aiHistoryService;
|
||||
|
||||
// 历史记录有效期(分钟)
|
||||
private static final int HISTORY_EXPIRE_MINUTES = 10;
|
||||
|
||||
/**
|
||||
* 生成党风廉政建设责任制审计表数据
|
||||
*/
|
||||
@@ -74,141 +43,6 @@ public class AuditContent10Controller extends BaseController {
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* 通用的表格数据生成方法
|
||||
*/
|
||||
private ApiResult<?> generateTableData(AuditContentRequest request, String interfaceName, Function<GenerateParams, JSONObject> generateFunction) {
|
||||
final User loginUser = getLoginUser();
|
||||
String requestHistory = request.getHistory();
|
||||
request.setHistory("");
|
||||
|
||||
// 检查历史记录
|
||||
String requestHash = generateRequestHash(request, interfaceName);
|
||||
var history = aiHistoryService.getValidHistory(requestHash, interfaceName, HISTORY_EXPIRE_MINUTES);
|
||||
if (history != null) {
|
||||
log.info("返回历史数据,请求哈希: {}", requestHash);
|
||||
return success(JSONObject.parseObject(history.getResponseData()));
|
||||
}
|
||||
request.setHistory(requestHistory);
|
||||
|
||||
String kbIdTmp = "";
|
||||
String libraryKbIds = "";
|
||||
|
||||
try {
|
||||
// 创建临时知识库(如果需要)
|
||||
if (hasUploadedFiles(request)) {
|
||||
kbIdTmp = createTempKnowledgeBase(request);
|
||||
}
|
||||
|
||||
// 查询项目库信息
|
||||
libraryKbIds = getLibraryKbIds(request.getLibraryIds());
|
||||
|
||||
// 生成数据
|
||||
String knowledgeBaseId = getKnowledgeBaseId(kbIdTmp, request.getKbIds());
|
||||
GenerateParams params = new GenerateParams(knowledgeBaseId, libraryKbIds, request.getProjectLibrary(), loginUser.getUsername(), request.getHistory(), request.getSuggestion());
|
||||
|
||||
JSONObject result = generateFunction.apply(params);
|
||||
|
||||
if(result.getBoolean("success")) {
|
||||
// 保存到历史记录
|
||||
saveToHistory(request, interfaceName, requestHash, result, loginUser);
|
||||
}
|
||||
|
||||
return success(result);
|
||||
} catch (Exception e) {
|
||||
log.error("生成表格数据失败,接口: {}", interfaceName, e);
|
||||
return fail("生成表格数据失败: " + e.getMessage());
|
||||
} finally {
|
||||
cleanupTempKnowledgeBase(kbIdTmp);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成请求哈希
|
||||
*/
|
||||
private String generateRequestHash(AuditContentRequest request, String interfaceName) {
|
||||
String requestJson = JSONObject.toJSONString(request);
|
||||
return DigestUtil.md5Hex(interfaceName + ":" + requestJson);
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存到历史记录
|
||||
*/
|
||||
private void saveToHistory(AuditContentRequest request, String interfaceName, String requestHash, JSONObject result, User loginUser) {
|
||||
try {
|
||||
aiHistoryService.saveHistory(requestHash, interfaceName, JSONObject.toJSONString(request), result.toJSONString(), loginUser.getUserId(), loginUser.getUsername(), loginUser.getTenantId());
|
||||
} catch (Exception e) {
|
||||
log.warn("保存历史记录失败", e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查是否有上传的文件
|
||||
*/
|
||||
private boolean hasUploadedFiles(AuditContentRequest request) {
|
||||
return !request.getDocList().isEmpty() || !request.getFileList().isEmpty();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取知识库ID
|
||||
*/
|
||||
private String getKnowledgeBaseId(String tempKbId, String requestKbIds) {
|
||||
return StrUtil.isNotBlank(tempKbId) ? tempKbId : requestKbIds;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取项目库KB IDs
|
||||
*/
|
||||
private String getLibraryKbIds(String libraryIds) {
|
||||
if (StrUtil.isBlank(libraryIds)) {
|
||||
return "";
|
||||
}
|
||||
List<String> idList = StrUtil.split(libraryIds, ',');
|
||||
List<PwlProjectLibrary> ret = pwlProjectLibraryService.list(new LambdaQueryWrapper<PwlProjectLibrary>().in(PwlProjectLibrary::getId, idList));
|
||||
return ret.stream().map(PwlProjectLibrary::getKbId).filter(StrUtil::isNotBlank).collect(Collectors.joining(","));
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建临时知识库并提交文档
|
||||
*/
|
||||
private String createTempKnowledgeBase(AuditContentRequest request) {
|
||||
String kbIdTmp = knowledgeBaseService.createKnowledgeBaseTemp();
|
||||
// 收集文档ID
|
||||
Set<Integer> docIds = request.getDocList().stream().flatMap(docId -> aiCloudDocService.getSelfAndChildren(docId).stream()).map(AiCloudDoc::getId).collect(Collectors.toSet());
|
||||
// 查询相关文件
|
||||
List<AiCloudFile> fileList = getRelatedFiles(docIds, request.getFileList());
|
||||
// 提取文件ID并提交到知识库
|
||||
Set<String> kbFileIds = fileList.stream().map(AiCloudFile::getFileId).collect(Collectors.toSet());
|
||||
if (!kbFileIds.isEmpty()) {
|
||||
knowledgeBaseService.submitDocuments(kbIdTmp, new ArrayList<>(kbFileIds));
|
||||
}
|
||||
return kbIdTmp;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取相关文件列表
|
||||
*/
|
||||
private List<AiCloudFile> getRelatedFiles(Set<Integer> docIds, List<Integer> fileList) {
|
||||
LambdaQueryWrapper<AiCloudFile> queryWrapper = new LambdaQueryWrapper<AiCloudFile>()
|
||||
.in(!docIds.isEmpty(), AiCloudFile::getDocId, docIds)
|
||||
.or(!fileList.isEmpty())
|
||||
.in(!fileList.isEmpty(), AiCloudFile::getId, fileList);
|
||||
return aiCloudFileService.list(queryWrapper);
|
||||
}
|
||||
|
||||
/**
|
||||
* 清理临时知识库
|
||||
*/
|
||||
private void cleanupTempKnowledgeBase(String kbId) {
|
||||
if (StrUtil.isNotBlank(kbId)) {
|
||||
try {
|
||||
knowledgeBaseService.deleteIndex(kbId);
|
||||
} catch (Exception e) {
|
||||
log.warn("删除临时知识库失败: {}", kbId, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出党风廉政建设责任制审计表到Excel
|
||||
*/
|
||||
@@ -219,44 +53,6 @@ public class AuditContent10Controller extends BaseController {
|
||||
this::convertToPartyConductEntityList, PartyConductExportEntity.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* 通用的Excel导出方法
|
||||
*/
|
||||
private <T> void exportToExcel(Map<String, Object> request, HttpServletResponse response,
|
||||
String sheetName, Function<List<Map<String, Object>>, List<T>> converter,
|
||||
Class<T> entityClass) {
|
||||
List<Map<String, Object>> dataList = (List<Map<String, Object>>) request.get("data");
|
||||
String companyName = (String) request.get("companyName");
|
||||
|
||||
List<T> exportData = converter.apply(dataList);
|
||||
|
||||
String fileName = sheetName + "_" + (companyName != null ? companyName : "未知公司");
|
||||
String title = companyName != null ? companyName + " - " + sheetName : sheetName;
|
||||
|
||||
ExcelExportTool.exportExcel(exportData, entityClass, fileName, sheetName, title, response);
|
||||
}
|
||||
|
||||
/**
|
||||
* 参数包装类
|
||||
*/
|
||||
private static class GenerateParams {
|
||||
final String knowledgeBaseId;
|
||||
final String libraryKbIds;
|
||||
final String projectLibrary;
|
||||
final String username;
|
||||
final String history;
|
||||
final String suggestion;
|
||||
|
||||
GenerateParams(String knowledgeBaseId, String libraryKbIds, String projectLibrary, String username, String history, String suggestion) {
|
||||
this.knowledgeBaseId = knowledgeBaseId;
|
||||
this.libraryKbIds = libraryKbIds;
|
||||
this.projectLibrary = projectLibrary;
|
||||
this.username = username;
|
||||
this.history = history;
|
||||
this.suggestion = suggestion;
|
||||
}
|
||||
}
|
||||
|
||||
// ========== 数据转换方法 ==========
|
||||
|
||||
private List<PartyConductExportEntity> convertToPartyConductEntityList(List<Map<String, Object>> originalData) {
|
||||
@@ -273,24 +69,4 @@ public class AuditContent10Controller extends BaseController {
|
||||
entity.setWorkPaperIndex(formatWorkPaperIndex(item.get("workPaperIndex")));
|
||||
return entity;
|
||||
}
|
||||
|
||||
private String getStringValue(Map<String, Object> map, String key) {
|
||||
Object value = map.get(key);
|
||||
return value != null ? value.toString() : "";
|
||||
}
|
||||
|
||||
private String formatWorkPaperIndex(Object workPaperIndex) {
|
||||
if (workPaperIndex == null) {
|
||||
return "";
|
||||
}
|
||||
|
||||
if (workPaperIndex instanceof List) {
|
||||
List<?> list = (List<?>) workPaperIndex;
|
||||
return String.join(", ", list.stream()
|
||||
.map(Object::toString)
|
||||
.collect(Collectors.toList()));
|
||||
}
|
||||
|
||||
return workPaperIndex.toString();
|
||||
}
|
||||
}
|
||||
@@ -1,34 +1,22 @@
|
||||
package com.gxwebsoft.ai.controller;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.gxwebsoft.ai.dto.AuditContentRequest;
|
||||
import com.gxwebsoft.ai.dto.export.HistoryTableExportEntity;
|
||||
import com.gxwebsoft.ai.entity.AiCloudDoc;
|
||||
import com.gxwebsoft.ai.entity.AiCloudFile;
|
||||
import com.gxwebsoft.ai.service.AiHistoryService;
|
||||
import com.gxwebsoft.ai.service.AuditContent11HistoryService;
|
||||
import com.gxwebsoft.ai.utils.ExcelExportTool;
|
||||
import com.gxwebsoft.common.core.web.ApiResult;
|
||||
import com.gxwebsoft.common.core.web.BaseController;
|
||||
import com.gxwebsoft.common.system.entity.User;
|
||||
import com.gxwebsoft.pwl.entity.PwlProjectLibrary;
|
||||
import com.gxwebsoft.pwl.service.PwlProjectLibraryService;
|
||||
import com.gxwebsoft.ai.service.AiCloudDocService;
|
||||
import com.gxwebsoft.ai.service.AiCloudFileService;
|
||||
import com.gxwebsoft.ai.service.AuditContent11HistoryService;
|
||||
import com.gxwebsoft.ai.service.KnowledgeBaseService;
|
||||
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.crypto.digest.DigestUtil;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.util.*;
|
||||
import java.util.function.Function;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
@@ -38,29 +26,11 @@ import java.util.stream.Collectors;
|
||||
@Tag(name = "审计内容11-历史审计问题整改")
|
||||
@RestController
|
||||
@RequestMapping("/api/ai/auditContent11")
|
||||
public class AuditContent11Controller extends BaseController {
|
||||
public class AuditContent11Controller extends BaseAuditContentController {
|
||||
|
||||
@Autowired
|
||||
private AuditContent11HistoryService auditContent11HistoryService;
|
||||
|
||||
@Autowired
|
||||
private AiCloudDocService aiCloudDocService;
|
||||
|
||||
@Autowired
|
||||
private AiCloudFileService aiCloudFileService;
|
||||
|
||||
@Autowired
|
||||
private KnowledgeBaseService knowledgeBaseService;
|
||||
|
||||
@Autowired
|
||||
private PwlProjectLibraryService pwlProjectLibraryService;
|
||||
|
||||
@Autowired
|
||||
private AiHistoryService aiHistoryService;
|
||||
|
||||
// 历史记录有效期(分钟)
|
||||
private static final int HISTORY_EXPIRE_MINUTES = 10;
|
||||
|
||||
/**
|
||||
* 生成历史审计问题整改表数据
|
||||
*/
|
||||
@@ -95,141 +65,6 @@ public class AuditContent11Controller extends BaseController {
|
||||
ExcelExportTool.exportExcel(exportData, HistoryTableExportEntity.class, fileName, sheetName, title, response);
|
||||
}
|
||||
|
||||
/**
|
||||
* 通用的表格数据生成方法
|
||||
*/
|
||||
private ApiResult<?> generateTableData(AuditContentRequest request, String interfaceName, Function<GenerateParams, JSONObject> generateFunction) {
|
||||
final User loginUser = getLoginUser();
|
||||
String requestHistory = request.getHistory();
|
||||
request.setHistory("");
|
||||
|
||||
// 检查历史记录
|
||||
String requestHash = generateRequestHash(request, interfaceName);
|
||||
var history = aiHistoryService.getValidHistory(requestHash, interfaceName, HISTORY_EXPIRE_MINUTES);
|
||||
if (history != null) {
|
||||
log.info("返回历史数据,请求哈希: {}", requestHash);
|
||||
return success(JSONObject.parseObject(history.getResponseData()));
|
||||
}
|
||||
request.setHistory(requestHistory);
|
||||
|
||||
String kbIdTmp = "";
|
||||
String libraryKbIds = "";
|
||||
|
||||
try {
|
||||
// 创建临时知识库(如果需要)
|
||||
if (hasUploadedFiles(request)) {
|
||||
kbIdTmp = createTempKnowledgeBase(request);
|
||||
}
|
||||
|
||||
// 查询项目库信息
|
||||
libraryKbIds = getLibraryKbIds(request.getLibraryIds());
|
||||
|
||||
// 生成数据
|
||||
String knowledgeBaseId = getKnowledgeBaseId(kbIdTmp, request.getKbIds());
|
||||
GenerateParams params = new GenerateParams(knowledgeBaseId, libraryKbIds, request.getProjectLibrary(), loginUser.getUsername(), request.getHistory(), request.getSuggestion());
|
||||
|
||||
JSONObject result = generateFunction.apply(params);
|
||||
|
||||
if(result.getBoolean("success")) {
|
||||
// 保存到历史记录
|
||||
saveToHistory(request, interfaceName, requestHash, result, loginUser);
|
||||
}
|
||||
|
||||
return success(result);
|
||||
} catch (Exception e) {
|
||||
log.error("生成历史审计问题整改表数据失败", e);
|
||||
return fail("生成历史审计问题整改表数据失败: " + e.getMessage());
|
||||
} finally {
|
||||
cleanupTempKnowledgeBase(kbIdTmp);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成请求哈希
|
||||
*/
|
||||
private String generateRequestHash(AuditContentRequest request, String interfaceName) {
|
||||
String requestJson = JSONObject.toJSONString(request);
|
||||
return DigestUtil.md5Hex(interfaceName + ":" + requestJson);
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存到历史记录
|
||||
*/
|
||||
private void saveToHistory(AuditContentRequest request, String interfaceName, String requestHash, JSONObject result, User loginUser) {
|
||||
try {
|
||||
aiHistoryService.saveHistory(requestHash, interfaceName, JSONObject.toJSONString(request), result.toJSONString(), loginUser.getUserId(), loginUser.getUsername(), loginUser.getTenantId());
|
||||
} catch (Exception e) {
|
||||
log.warn("保存历史记录失败", e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查是否有上传的文件
|
||||
*/
|
||||
private boolean hasUploadedFiles(AuditContentRequest request) {
|
||||
return !request.getDocList().isEmpty() || !request.getFileList().isEmpty();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取知识库ID
|
||||
*/
|
||||
private String getKnowledgeBaseId(String tempKbId, String requestKbIds) {
|
||||
return StrUtil.isNotBlank(tempKbId) ? tempKbId : requestKbIds;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取项目库KB IDs
|
||||
*/
|
||||
private String getLibraryKbIds(String libraryIds) {
|
||||
if (StrUtil.isBlank(libraryIds)) {
|
||||
return "";
|
||||
}
|
||||
List<String> idList = StrUtil.split(libraryIds, ',');
|
||||
List<PwlProjectLibrary> ret = pwlProjectLibraryService.list(new LambdaQueryWrapper<PwlProjectLibrary>().in(PwlProjectLibrary::getId, idList));
|
||||
return ret.stream().map(PwlProjectLibrary::getKbId).filter(StrUtil::isNotBlank).collect(Collectors.joining(","));
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建临时知识库并提交文档
|
||||
*/
|
||||
private String createTempKnowledgeBase(AuditContentRequest request) {
|
||||
String kbIdTmp = knowledgeBaseService.createKnowledgeBaseTemp();
|
||||
// 收集文档ID
|
||||
Set<Integer> docIds = request.getDocList().stream().flatMap(docId -> aiCloudDocService.getSelfAndChildren(docId).stream()).map(AiCloudDoc::getId).collect(Collectors.toSet());
|
||||
// 查询相关文件
|
||||
List<AiCloudFile> fileList = getRelatedFiles(docIds, request.getFileList());
|
||||
// 提取文件ID并提交到知识库
|
||||
Set<String> kbFileIds = fileList.stream().map(AiCloudFile::getFileId).collect(Collectors.toSet());
|
||||
if (!kbFileIds.isEmpty()) {
|
||||
knowledgeBaseService.submitDocuments(kbIdTmp, new ArrayList<>(kbFileIds));
|
||||
}
|
||||
return kbIdTmp;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取相关文件列表
|
||||
*/
|
||||
private List<AiCloudFile> getRelatedFiles(Set<Integer> docIds, List<Integer> fileList) {
|
||||
LambdaQueryWrapper<AiCloudFile> queryWrapper = new LambdaQueryWrapper<AiCloudFile>()
|
||||
.in(!docIds.isEmpty(), AiCloudFile::getDocId, docIds)
|
||||
.or(!fileList.isEmpty())
|
||||
.in(!fileList.isEmpty(), AiCloudFile::getId, fileList);
|
||||
return aiCloudFileService.list(queryWrapper);
|
||||
}
|
||||
|
||||
/**
|
||||
* 清理临时知识库
|
||||
*/
|
||||
private void cleanupTempKnowledgeBase(String kbId) {
|
||||
if (StrUtil.isNotBlank(kbId)) {
|
||||
try {
|
||||
knowledgeBaseService.deleteIndex(kbId);
|
||||
} catch (Exception e) {
|
||||
log.warn("删除临时知识库失败: {}", kbId, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ========== 数据转换方法 ==========
|
||||
|
||||
private List<HistoryTableExportEntity> convertToHistoryTableEntityList(List<Map<String, Object>> originalData) {
|
||||
@@ -253,45 +88,4 @@ public class AuditContent11Controller extends BaseController {
|
||||
entity.setWorkPaperIndex(formatWorkPaperIndex(item.get("workPaperIndex")));
|
||||
return entity;
|
||||
}
|
||||
|
||||
private String getStringValue(Map<String, Object> map, String key) {
|
||||
Object value = map.get(key);
|
||||
return value != null ? value.toString() : "";
|
||||
}
|
||||
|
||||
private String formatWorkPaperIndex(Object workPaperIndex) {
|
||||
if (workPaperIndex == null) {
|
||||
return "";
|
||||
}
|
||||
|
||||
if (workPaperIndex instanceof List) {
|
||||
List<?> list = (List<?>) workPaperIndex;
|
||||
return String.join(", ", list.stream()
|
||||
.map(Object::toString)
|
||||
.collect(Collectors.toList()));
|
||||
}
|
||||
|
||||
return workPaperIndex.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* 参数包装类
|
||||
*/
|
||||
private static class GenerateParams {
|
||||
final String knowledgeBaseId;
|
||||
final String libraryKbIds;
|
||||
final String projectLibrary;
|
||||
final String username;
|
||||
final String history;
|
||||
final String suggestion;
|
||||
|
||||
GenerateParams(String knowledgeBaseId, String libraryKbIds, String projectLibrary, String username, String history, String suggestion) {
|
||||
this.knowledgeBaseId = knowledgeBaseId;
|
||||
this.libraryKbIds = libraryKbIds;
|
||||
this.projectLibrary = projectLibrary;
|
||||
this.username = username;
|
||||
this.history = history;
|
||||
this.suggestion = suggestion;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,38 +1,25 @@
|
||||
package com.gxwebsoft.ai.controller;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.gxwebsoft.ai.dto.AuditContentRequest;
|
||||
import com.gxwebsoft.ai.dto.export.EightRegExportEntity;
|
||||
import com.gxwebsoft.ai.dto.export.ExpenseExportEntity;
|
||||
import com.gxwebsoft.ai.dto.export.LeaderListExportEntity;
|
||||
import com.gxwebsoft.ai.entity.AiCloudDoc;
|
||||
import com.gxwebsoft.ai.entity.AiCloudFile;
|
||||
import com.gxwebsoft.ai.service.AiHistoryService;
|
||||
import com.gxwebsoft.ai.utils.ExcelExportTool;
|
||||
import com.gxwebsoft.common.core.web.ApiResult;
|
||||
import com.gxwebsoft.common.core.web.BaseController;
|
||||
import com.gxwebsoft.common.system.entity.User;
|
||||
import com.gxwebsoft.pwl.entity.PwlProjectLibrary;
|
||||
import com.gxwebsoft.pwl.service.PwlProjectLibraryService;
|
||||
import com.gxwebsoft.ai.service.AiCloudDocService;
|
||||
import com.gxwebsoft.ai.service.AiCloudFileService;
|
||||
import com.gxwebsoft.ai.service.AuditContent1EightRegService;
|
||||
import com.gxwebsoft.ai.service.AuditContent1ExpenseService;
|
||||
import com.gxwebsoft.ai.service.AuditContent1LeaderListService;
|
||||
import com.gxwebsoft.ai.service.KnowledgeBaseService;
|
||||
import com.gxwebsoft.common.core.web.ApiResult;
|
||||
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.crypto.digest.DigestUtil;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.util.*;
|
||||
import java.util.function.Function;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
@@ -42,10 +29,10 @@ import java.util.stream.Collectors;
|
||||
@Tag(name = "审计内容1-八项规定")
|
||||
@RestController
|
||||
@RequestMapping("/api/ai/auditContent1")
|
||||
public class AuditContent1Controller extends BaseController {
|
||||
public class AuditContent1Controller extends BaseAuditContentController {
|
||||
|
||||
@Autowired
|
||||
private AuditContent1LeaderListService auditContent1LeaderListService;
|
||||
@Autowired
|
||||
private AuditContent1LeaderListService auditContent1LeaderListService;
|
||||
|
||||
@Autowired
|
||||
private AuditContent1ExpenseService auditContent1ExpenseService;
|
||||
@@ -53,24 +40,6 @@ public class AuditContent1Controller extends BaseController {
|
||||
@Autowired
|
||||
private AuditContent1EightRegService auditContent1EightRegService;
|
||||
|
||||
@Autowired
|
||||
private AiCloudDocService aiCloudDocService;
|
||||
|
||||
@Autowired
|
||||
private AiCloudFileService aiCloudFileService;
|
||||
|
||||
@Autowired
|
||||
private KnowledgeBaseService knowledgeBaseService;
|
||||
|
||||
@Autowired
|
||||
private PwlProjectLibraryService pwlProjectLibraryService;
|
||||
|
||||
@Autowired
|
||||
private AiHistoryService aiHistoryService;
|
||||
|
||||
// 历史记录有效期(分钟)
|
||||
private static final int HISTORY_EXPIRE_MINUTES = 10;
|
||||
|
||||
/**
|
||||
* 生成领导班子名单数据
|
||||
*/
|
||||
@@ -110,141 +79,6 @@ public class AuditContent1Controller extends BaseController {
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* 通用的表格数据生成方法
|
||||
*/
|
||||
private ApiResult<?> generateTableData(AuditContentRequest request, String interfaceName, Function<GenerateParams, JSONObject> generateFunction) {
|
||||
final User loginUser = getLoginUser();
|
||||
String requestHistory = request.getHistory();
|
||||
request.setHistory("");
|
||||
|
||||
// 检查历史记录
|
||||
String requestHash = generateRequestHash(request, interfaceName);
|
||||
var history = aiHistoryService.getValidHistory(requestHash, interfaceName, HISTORY_EXPIRE_MINUTES);
|
||||
if (history != null) {
|
||||
log.info("返回历史数据,请求哈希: {}", requestHash);
|
||||
return success(JSONObject.parseObject(history.getResponseData()));
|
||||
}
|
||||
request.setHistory(requestHistory);
|
||||
|
||||
String kbIdTmp = "";
|
||||
String libraryKbIds = "";
|
||||
|
||||
try {
|
||||
// 创建临时知识库(如果需要)
|
||||
if (hasUploadedFiles(request)) {
|
||||
kbIdTmp = createTempKnowledgeBase(request);
|
||||
}
|
||||
|
||||
// 查询项目库信息
|
||||
libraryKbIds = getLibraryKbIds(request.getLibraryIds());
|
||||
|
||||
// 生成数据
|
||||
String knowledgeBaseId = getKnowledgeBaseId(kbIdTmp, request.getKbIds());
|
||||
GenerateParams params = new GenerateParams(knowledgeBaseId, libraryKbIds, request.getProjectLibrary(), loginUser.getUsername(), request.getHistory(), request.getSuggestion());
|
||||
|
||||
JSONObject result = generateFunction.apply(params);
|
||||
|
||||
if(result.getBoolean("success")) {
|
||||
// 保存到历史记录
|
||||
saveToHistory(request, interfaceName, requestHash, result, loginUser);
|
||||
}
|
||||
|
||||
return success(result);
|
||||
} catch (Exception e) {
|
||||
log.error("生成八项规定表格数据失败,接口: {}", interfaceName, e);
|
||||
return fail("生成八项规定表格数据失败: " + e.getMessage());
|
||||
} finally {
|
||||
cleanupTempKnowledgeBase(kbIdTmp);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成请求哈希
|
||||
*/
|
||||
private String generateRequestHash(AuditContentRequest request, String interfaceName) {
|
||||
String requestJson = JSONObject.toJSONString(request);
|
||||
return DigestUtil.md5Hex(interfaceName + ":" + requestJson);
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存到历史记录
|
||||
*/
|
||||
private void saveToHistory(AuditContentRequest request, String interfaceName, String requestHash, JSONObject result, User loginUser) {
|
||||
try {
|
||||
aiHistoryService.saveHistory(requestHash, interfaceName, JSONObject.toJSONString(request), result.toJSONString(), loginUser.getUserId(), loginUser.getUsername(), loginUser.getTenantId());
|
||||
} catch (Exception e) {
|
||||
log.warn("保存历史记录失败", e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查是否有上传的文件
|
||||
*/
|
||||
private boolean hasUploadedFiles(AuditContentRequest request) {
|
||||
return !request.getDocList().isEmpty() || !request.getFileList().isEmpty();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取知识库ID
|
||||
*/
|
||||
private String getKnowledgeBaseId(String tempKbId, String requestKbIds) {
|
||||
return StrUtil.isNotBlank(tempKbId) ? tempKbId : requestKbIds;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取项目库KB IDs
|
||||
*/
|
||||
private String getLibraryKbIds(String libraryIds) {
|
||||
if (StrUtil.isBlank(libraryIds)) {
|
||||
return "";
|
||||
}
|
||||
List<String> idList = StrUtil.split(libraryIds, ',');
|
||||
List<PwlProjectLibrary> ret = pwlProjectLibraryService.list(new LambdaQueryWrapper<PwlProjectLibrary>().in(PwlProjectLibrary::getId, idList));
|
||||
return ret.stream().map(PwlProjectLibrary::getKbId).filter(StrUtil::isNotBlank).collect(Collectors.joining(","));
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建临时知识库并提交文档
|
||||
*/
|
||||
private String createTempKnowledgeBase(AuditContentRequest request) {
|
||||
String kbIdTmp = knowledgeBaseService.createKnowledgeBaseTemp();
|
||||
// 收集文档ID
|
||||
Set<Integer> docIds = request.getDocList().stream().flatMap(docId -> aiCloudDocService.getSelfAndChildren(docId).stream()).map(AiCloudDoc::getId).collect(Collectors.toSet());
|
||||
// 查询相关文件
|
||||
List<AiCloudFile> fileList = getRelatedFiles(docIds, request.getFileList());
|
||||
// 提取文件ID并提交到知识库
|
||||
Set<String> kbFileIds = fileList.stream().map(AiCloudFile::getFileId).collect(Collectors.toSet());
|
||||
if (!kbFileIds.isEmpty()) {
|
||||
knowledgeBaseService.submitDocuments(kbIdTmp, new ArrayList<>(kbFileIds));
|
||||
}
|
||||
return kbIdTmp;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取相关文件列表
|
||||
*/
|
||||
private List<AiCloudFile> getRelatedFiles(Set<Integer> docIds, List<Integer> fileList) {
|
||||
LambdaQueryWrapper<AiCloudFile> queryWrapper = new LambdaQueryWrapper<AiCloudFile>()
|
||||
.in(!docIds.isEmpty(), AiCloudFile::getDocId, docIds)
|
||||
.or(!fileList.isEmpty())
|
||||
.in(!fileList.isEmpty(), AiCloudFile::getId, fileList);
|
||||
return aiCloudFileService.list(queryWrapper);
|
||||
}
|
||||
|
||||
/**
|
||||
* 清理临时知识库
|
||||
*/
|
||||
private void cleanupTempKnowledgeBase(String kbId) {
|
||||
if (StrUtil.isNotBlank(kbId)) {
|
||||
try {
|
||||
knowledgeBaseService.deleteIndex(kbId);
|
||||
} catch (Exception e) {
|
||||
log.warn("删除临时知识库失败: {}", kbId, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出八项规定对比分析表到Excel
|
||||
*/
|
||||
@@ -256,41 +90,23 @@ public class AuditContent1Controller extends BaseController {
|
||||
}
|
||||
|
||||
/**
|
||||
* 通用的Excel导出方法
|
||||
* 导出领导班子名单到Excel
|
||||
*/
|
||||
private <T> void exportToExcel(Map<String, Object> request, HttpServletResponse response,
|
||||
String sheetName, Function<List<Map<String, Object>>, List<T>> converter,
|
||||
Class<T> entityClass) {
|
||||
List<Map<String, Object>> dataList = (List<Map<String, Object>>) request.get("data");
|
||||
String companyName = (String) request.get("companyName");
|
||||
|
||||
List<T> exportData = converter.apply(dataList);
|
||||
|
||||
String fileName = sheetName + "_" + (companyName != null ? companyName : "未知公司");
|
||||
String title = companyName != null ? companyName + " - " + sheetName : sheetName;
|
||||
|
||||
ExcelExportTool.exportExcel(exportData, entityClass, fileName, sheetName, title, response);
|
||||
@Operation(summary = "导出领导班子名单到Excel")
|
||||
@PostMapping("/exportLeaderListTable")
|
||||
public void exportLeaderListTable(@RequestBody Map<String, Object> request, HttpServletResponse response) {
|
||||
exportToExcel(request, response, "领导班子名单",
|
||||
this::convertToLeaderListEntityList, LeaderListExportEntity.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* 参数包装类
|
||||
* 导出支出情况表到Excel
|
||||
*/
|
||||
private static class GenerateParams {
|
||||
final String knowledgeBaseId;
|
||||
final String libraryKbIds;
|
||||
final String projectLibrary;
|
||||
final String username;
|
||||
final String history;
|
||||
final String suggestion;
|
||||
|
||||
GenerateParams(String knowledgeBaseId, String libraryKbIds, String projectLibrary, String username, String history, String suggestion) {
|
||||
this.knowledgeBaseId = knowledgeBaseId;
|
||||
this.libraryKbIds = libraryKbIds;
|
||||
this.projectLibrary = projectLibrary;
|
||||
this.username = username;
|
||||
this.history = history;
|
||||
this.suggestion = suggestion;
|
||||
}
|
||||
@Operation(summary = "导出支出情况表到Excel")
|
||||
@PostMapping("/exportExpenseTable")
|
||||
public void exportExpenseTable(@RequestBody Map<String, Object> request, HttpServletResponse response) {
|
||||
exportToExcel(request, response, "支出情况表",
|
||||
this::convertToExpenseEntityList, ExpenseExportEntity.class);
|
||||
}
|
||||
|
||||
// ========== 数据转换方法 ==========
|
||||
@@ -309,37 +125,6 @@ public class AuditContent1Controller extends BaseController {
|
||||
return entity;
|
||||
}
|
||||
|
||||
private String getStringValue(Map<String, Object> map, String key) {
|
||||
Object value = map.get(key);
|
||||
return value != null ? value.toString() : "";
|
||||
}
|
||||
|
||||
private String formatWorkPaperIndex(Object workPaperIndex) {
|
||||
if (workPaperIndex == null) {
|
||||
return "";
|
||||
}
|
||||
|
||||
if (workPaperIndex instanceof List) {
|
||||
List<?> list = (List<?>) workPaperIndex;
|
||||
return String.join(", ", list.stream()
|
||||
.map(Object::toString)
|
||||
.collect(Collectors.toList()));
|
||||
}
|
||||
|
||||
return workPaperIndex.toString();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 导出领导班子名单到Excel
|
||||
*/
|
||||
@Operation(summary = "导出领导班子名单到Excel")
|
||||
@PostMapping("/exportLeaderListTable")
|
||||
public void exportLeaderListTable(@RequestBody Map<String, Object> request, HttpServletResponse response) {
|
||||
exportToExcel(request, response, "领导班子名单", this::convertToLeaderListEntityList, LeaderListExportEntity.class);
|
||||
}
|
||||
|
||||
// 添加数据转换方法
|
||||
private List<LeaderListExportEntity> convertToLeaderListEntityList(List<Map<String, Object>> originalData) {
|
||||
return originalData.stream().map(this::convertToLeaderListEntity).collect(Collectors.toList());
|
||||
}
|
||||
@@ -358,19 +143,6 @@ public class AuditContent1Controller extends BaseController {
|
||||
return entity;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 导出支出情况表到Excel
|
||||
*/
|
||||
@Operation(summary = "导出支出情况表到Excel")
|
||||
@PostMapping("/exportExpenseTable")
|
||||
public void exportExpenseTable(@RequestBody Map<String, Object> request, HttpServletResponse response) {
|
||||
exportToExcel(request, response, "支出情况表",
|
||||
this::convertToExpenseEntityList, ExpenseExportEntity.class);
|
||||
}
|
||||
|
||||
// ========== 数据转换方法 ==========
|
||||
|
||||
private List<ExpenseExportEntity> convertToExpenseEntityList(List<Map<String, Object>> originalData) {
|
||||
return originalData.stream().map(this::convertToExpenseEntity).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@@ -1,34 +1,21 @@
|
||||
package com.gxwebsoft.ai.controller;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.gxwebsoft.ai.dto.AuditContentRequest;
|
||||
import com.gxwebsoft.ai.dto.export.StrategyAuditExportEntity;
|
||||
import com.gxwebsoft.ai.entity.AiCloudDoc;
|
||||
import com.gxwebsoft.ai.entity.AiCloudFile;
|
||||
import com.gxwebsoft.ai.service.AiHistoryService;
|
||||
import com.gxwebsoft.ai.utils.ExcelExportTool;
|
||||
import com.gxwebsoft.common.core.web.ApiResult;
|
||||
import com.gxwebsoft.common.core.web.BaseController;
|
||||
import com.gxwebsoft.common.system.entity.User;
|
||||
import com.gxwebsoft.pwl.entity.PwlProjectLibrary;
|
||||
import com.gxwebsoft.pwl.service.PwlProjectLibraryService;
|
||||
import com.gxwebsoft.ai.service.AiCloudDocService;
|
||||
import com.gxwebsoft.ai.service.AiCloudFileService;
|
||||
import com.gxwebsoft.ai.service.AuditContent2StrategyService;
|
||||
import com.gxwebsoft.ai.service.KnowledgeBaseService;
|
||||
import com.gxwebsoft.common.core.web.ApiResult;
|
||||
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.crypto.digest.DigestUtil;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.util.*;
|
||||
import java.util.function.Function;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
@@ -38,29 +25,11 @@ import java.util.stream.Collectors;
|
||||
@Tag(name = "审计内容2-单位发展战略执行")
|
||||
@RestController
|
||||
@RequestMapping("/api/ai/auditContent2")
|
||||
public class AuditContent2Controller extends BaseController {
|
||||
public class AuditContent2Controller extends BaseAuditContentController {
|
||||
|
||||
@Autowired
|
||||
private AuditContent2StrategyService auditContent2StrategyService;
|
||||
|
||||
@Autowired
|
||||
private AiCloudDocService aiCloudDocService;
|
||||
|
||||
@Autowired
|
||||
private AiCloudFileService aiCloudFileService;
|
||||
|
||||
@Autowired
|
||||
private KnowledgeBaseService knowledgeBaseService;
|
||||
|
||||
@Autowired
|
||||
private PwlProjectLibraryService pwlProjectLibraryService;
|
||||
|
||||
@Autowired
|
||||
private AiHistoryService aiHistoryService;
|
||||
|
||||
// 历史记录有效期(分钟)
|
||||
private static final int HISTORY_EXPIRE_MINUTES = 10;
|
||||
|
||||
/**
|
||||
* 生成单位发展战略执行审计表数据
|
||||
*/
|
||||
@@ -74,164 +43,14 @@ public class AuditContent2Controller extends BaseController {
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* 通用的表格数据生成方法
|
||||
*/
|
||||
private ApiResult<?> generateTableData(AuditContentRequest request, String interfaceName, Function<GenerateParams, JSONObject> generateFunction) {
|
||||
final User loginUser = getLoginUser();
|
||||
String requestHistory = request.getHistory();
|
||||
request.setHistory("");
|
||||
|
||||
// 检查历史记录
|
||||
String requestHash = generateRequestHash(request, interfaceName);
|
||||
var history = aiHistoryService.getValidHistory(requestHash, interfaceName, HISTORY_EXPIRE_MINUTES);
|
||||
if (history != null) {
|
||||
log.info("返回历史数据,请求哈希: {}", requestHash);
|
||||
return success(JSONObject.parseObject(history.getResponseData()));
|
||||
}
|
||||
request.setHistory(requestHistory);
|
||||
|
||||
String kbIdTmp = "";
|
||||
String libraryKbIds = "";
|
||||
|
||||
try {
|
||||
// 创建临时知识库(如果需要)
|
||||
if (hasUploadedFiles(request)) {
|
||||
kbIdTmp = createTempKnowledgeBase(request);
|
||||
}
|
||||
|
||||
// 查询项目库信息
|
||||
libraryKbIds = getLibraryKbIds(request.getLibraryIds());
|
||||
|
||||
// 生成数据
|
||||
String knowledgeBaseId = getKnowledgeBaseId(kbIdTmp, request.getKbIds());
|
||||
GenerateParams params = new GenerateParams(knowledgeBaseId, libraryKbIds, request.getProjectLibrary(), loginUser.getUsername(), request.getHistory(), request.getSuggestion());
|
||||
|
||||
JSONObject result = generateFunction.apply(params);
|
||||
|
||||
if(result.getBoolean("success")) {
|
||||
// 保存到历史记录
|
||||
saveToHistory(request, interfaceName, requestHash, result, loginUser);
|
||||
}
|
||||
|
||||
return success(result);
|
||||
} catch (Exception e) {
|
||||
log.error("生成表格数据失败,接口: {}", interfaceName, e);
|
||||
return fail("生成表格数据失败: " + e.getMessage());
|
||||
} finally {
|
||||
cleanupTempKnowledgeBase(kbIdTmp);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成请求哈希
|
||||
*/
|
||||
private String generateRequestHash(AuditContentRequest request, String interfaceName) {
|
||||
String requestJson = JSONObject.toJSONString(request);
|
||||
return DigestUtil.md5Hex(interfaceName + ":" + requestJson);
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存到历史记录
|
||||
*/
|
||||
private void saveToHistory(AuditContentRequest request, String interfaceName, String requestHash, JSONObject result, User loginUser) {
|
||||
try {
|
||||
aiHistoryService.saveHistory(requestHash, interfaceName, JSONObject.toJSONString(request), result.toJSONString(), loginUser.getUserId(), loginUser.getUsername(), loginUser.getTenantId());
|
||||
} catch (Exception e) {
|
||||
log.warn("保存历史记录失败", e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查是否有上传的文件
|
||||
*/
|
||||
private boolean hasUploadedFiles(AuditContentRequest request) {
|
||||
return !request.getDocList().isEmpty() || !request.getFileList().isEmpty();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取知识库ID
|
||||
*/
|
||||
private String getKnowledgeBaseId(String tempKbId, String requestKbIds) {
|
||||
return StrUtil.isNotBlank(tempKbId) ? tempKbId : requestKbIds;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取项目库KB IDs
|
||||
*/
|
||||
private String getLibraryKbIds(String libraryIds) {
|
||||
if (StrUtil.isBlank(libraryIds)) {
|
||||
return "";
|
||||
}
|
||||
List<String> idList = StrUtil.split(libraryIds, ',');
|
||||
List<PwlProjectLibrary> ret = pwlProjectLibraryService.list(new LambdaQueryWrapper<PwlProjectLibrary>().in(PwlProjectLibrary::getId, idList));
|
||||
return ret.stream().map(PwlProjectLibrary::getKbId).filter(StrUtil::isNotBlank).collect(Collectors.joining(","));
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建临时知识库并提交文档
|
||||
*/
|
||||
private String createTempKnowledgeBase(AuditContentRequest request) {
|
||||
String kbIdTmp = knowledgeBaseService.createKnowledgeBaseTemp();
|
||||
// 收集文档ID
|
||||
Set<Integer> docIds = request.getDocList().stream().flatMap(docId -> aiCloudDocService.getSelfAndChildren(docId).stream()).map(AiCloudDoc::getId).collect(Collectors.toSet());
|
||||
// 查询相关文件
|
||||
List<AiCloudFile> fileList = getRelatedFiles(docIds, request.getFileList());
|
||||
// 提取文件ID并提交到知识库
|
||||
Set<String> kbFileIds = fileList.stream().map(AiCloudFile::getFileId).collect(Collectors.toSet());
|
||||
if (!kbFileIds.isEmpty()) {
|
||||
knowledgeBaseService.submitDocuments(kbIdTmp, new ArrayList<>(kbFileIds));
|
||||
}
|
||||
return kbIdTmp;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取相关文件列表
|
||||
*/
|
||||
private List<AiCloudFile> getRelatedFiles(Set<Integer> docIds, List<Integer> fileList) {
|
||||
LambdaQueryWrapper<AiCloudFile> queryWrapper = new LambdaQueryWrapper<AiCloudFile>()
|
||||
.in(!docIds.isEmpty(), AiCloudFile::getDocId, docIds)
|
||||
.or(!fileList.isEmpty())
|
||||
.in(!fileList.isEmpty(), AiCloudFile::getId, fileList);
|
||||
return aiCloudFileService.list(queryWrapper);
|
||||
}
|
||||
|
||||
/**
|
||||
* 清理临时知识库
|
||||
*/
|
||||
private void cleanupTempKnowledgeBase(String kbId) {
|
||||
if (StrUtil.isNotBlank(kbId)) {
|
||||
try {
|
||||
knowledgeBaseService.deleteIndex(kbId);
|
||||
} catch (Exception e) {
|
||||
log.warn("删除临时知识库失败: {}", kbId, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出单位发展战略执行审计表到Excel
|
||||
*/
|
||||
@Operation(summary = "导出单位发展战略执行审计表到Excel")
|
||||
@PostMapping("/exportStrategyAuditTable")
|
||||
public void exportStrategyAuditTable(@RequestBody Map<String, Object> request, HttpServletResponse response) {
|
||||
exportToExcel(request, response);
|
||||
}
|
||||
|
||||
/**
|
||||
* Excel导出方法
|
||||
*/
|
||||
private void exportToExcel(Map<String, Object> request, HttpServletResponse response) {
|
||||
List<Map<String, Object>> dataList = (List<Map<String, Object>>) request.get("data");
|
||||
String companyName = (String) request.get("companyName");
|
||||
|
||||
List<StrategyAuditExportEntity> exportData = convertToExportEntityList(dataList);
|
||||
|
||||
String fileName = "单位发展战略执行审计表_" + (companyName != null ? companyName : "未知公司");
|
||||
String title = companyName != null ? companyName + " - 单位发展战略执行审计表" : "单位发展战略执行审计表";
|
||||
String sheetName = "发展战略执行审计";
|
||||
|
||||
ExcelExportTool.exportExcel(exportData, StrategyAuditExportEntity.class, fileName, sheetName, title, response);
|
||||
exportToExcel(request, response, "单位发展战略执行审计表",
|
||||
this::convertToExportEntityList, StrategyAuditExportEntity.class);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -250,45 +69,4 @@ public class AuditContent2Controller extends BaseController {
|
||||
entity.setWorkPaperIndex(formatWorkPaperIndex(item.get("workPaperIndex")));
|
||||
return entity;
|
||||
}
|
||||
|
||||
private String getStringValue(Map<String, Object> map, String key) {
|
||||
Object value = map.get(key);
|
||||
return value != null ? value.toString() : "";
|
||||
}
|
||||
|
||||
private String formatWorkPaperIndex(Object workPaperIndex) {
|
||||
if (workPaperIndex == null) {
|
||||
return "";
|
||||
}
|
||||
|
||||
if (workPaperIndex instanceof List) {
|
||||
List<?> list = (List<?>) workPaperIndex;
|
||||
return String.join(", ", list.stream()
|
||||
.map(Object::toString)
|
||||
.collect(Collectors.toList()));
|
||||
}
|
||||
|
||||
return workPaperIndex.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* 参数包装类
|
||||
*/
|
||||
private static class GenerateParams {
|
||||
final String knowledgeBaseId;
|
||||
final String libraryKbIds;
|
||||
final String projectLibrary;
|
||||
final String username;
|
||||
final String history;
|
||||
final String suggestion;
|
||||
|
||||
GenerateParams(String knowledgeBaseId, String libraryKbIds, String projectLibrary, String username, String history, String suggestion) {
|
||||
this.knowledgeBaseId = knowledgeBaseId;
|
||||
this.libraryKbIds = libraryKbIds;
|
||||
this.projectLibrary = projectLibrary;
|
||||
this.username = username;
|
||||
this.history = history;
|
||||
this.suggestion = suggestion;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,36 +1,22 @@
|
||||
package com.gxwebsoft.ai.controller;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.gxwebsoft.ai.dto.AuditContentRequest;
|
||||
import com.gxwebsoft.ai.dto.export.TripleOneExportEntity;
|
||||
import com.gxwebsoft.ai.dto.export.DecisionTableExportEntity;
|
||||
import com.gxwebsoft.ai.entity.AiCloudDoc;
|
||||
import com.gxwebsoft.ai.entity.AiCloudFile;
|
||||
import com.gxwebsoft.ai.service.AiHistoryService;
|
||||
import com.gxwebsoft.ai.utils.ExcelExportTool;
|
||||
import com.gxwebsoft.common.core.web.ApiResult;
|
||||
import com.gxwebsoft.common.core.web.BaseController;
|
||||
import com.gxwebsoft.common.system.entity.User;
|
||||
import com.gxwebsoft.pwl.entity.PwlProjectLibrary;
|
||||
import com.gxwebsoft.pwl.service.PwlProjectLibraryService;
|
||||
import com.gxwebsoft.ai.service.AiCloudDocService;
|
||||
import com.gxwebsoft.ai.service.AiCloudFileService;
|
||||
import com.gxwebsoft.ai.service.AuditContent3TripleService;
|
||||
import com.gxwebsoft.common.core.web.ApiResult;
|
||||
import com.gxwebsoft.ai.service.AuditContent3DecisionService;
|
||||
import com.gxwebsoft.ai.service.KnowledgeBaseService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.crypto.digest.DigestUtil;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.util.*;
|
||||
import java.util.function.Function;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
@@ -40,7 +26,7 @@ import java.util.stream.Collectors;
|
||||
@Tag(name = "审计内容3-三重一大制度")
|
||||
@RestController
|
||||
@RequestMapping("/api/ai/auditContent3")
|
||||
public class AuditContent3Controller extends BaseController {
|
||||
public class AuditContent3Controller extends BaseAuditContentController {
|
||||
|
||||
@Autowired
|
||||
private AuditContent3TripleService auditContent3TripleService;
|
||||
@@ -48,24 +34,6 @@ public class AuditContent3Controller extends BaseController {
|
||||
@Autowired
|
||||
private AuditContent3DecisionService auditContent3DecisionService;
|
||||
|
||||
@Autowired
|
||||
private AiCloudDocService aiCloudDocService;
|
||||
|
||||
@Autowired
|
||||
private AiCloudFileService aiCloudFileService;
|
||||
|
||||
@Autowired
|
||||
private KnowledgeBaseService knowledgeBaseService;
|
||||
|
||||
@Autowired
|
||||
private PwlProjectLibraryService pwlProjectLibraryService;
|
||||
|
||||
@Autowired
|
||||
private AiHistoryService aiHistoryService;
|
||||
|
||||
// 历史记录有效期(分钟)
|
||||
private static final int HISTORY_EXPIRE_MINUTES = 10;
|
||||
|
||||
/**
|
||||
* 生成三重一大制度对比分析表数据
|
||||
*/
|
||||
@@ -92,141 +60,6 @@ public class AuditContent3Controller extends BaseController {
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* 通用的表格数据生成方法
|
||||
*/
|
||||
private ApiResult<?> generateTableData(AuditContentRequest request, String interfaceName, Function<GenerateParams, JSONObject> generateFunction) {
|
||||
final User loginUser = getLoginUser();
|
||||
String requestHistory = request.getHistory();
|
||||
request.setHistory("");
|
||||
|
||||
// 检查历史记录
|
||||
String requestHash = generateRequestHash(request, interfaceName);
|
||||
var history = aiHistoryService.getValidHistory(requestHash, interfaceName, HISTORY_EXPIRE_MINUTES);
|
||||
if (history != null) {
|
||||
log.info("返回历史数据,请求哈希: {}", requestHash);
|
||||
return success(JSONObject.parseObject(history.getResponseData()));
|
||||
}
|
||||
request.setHistory(requestHistory);
|
||||
|
||||
String kbIdTmp = "";
|
||||
String libraryKbIds = "";
|
||||
|
||||
try {
|
||||
// 创建临时知识库(如果需要)
|
||||
if (hasUploadedFiles(request)) {
|
||||
kbIdTmp = createTempKnowledgeBase(request);
|
||||
}
|
||||
|
||||
// 查询项目库信息
|
||||
libraryKbIds = getLibraryKbIds(request.getLibraryIds());
|
||||
|
||||
// 生成数据
|
||||
String knowledgeBaseId = getKnowledgeBaseId(kbIdTmp, request.getKbIds());
|
||||
GenerateParams params = new GenerateParams(knowledgeBaseId, libraryKbIds, request.getProjectLibrary(), loginUser.getUsername(), request.getHistory(), request.getSuggestion());
|
||||
|
||||
JSONObject result = generateFunction.apply(params);
|
||||
|
||||
if(result.getBoolean("success")) {
|
||||
// 保存到历史记录
|
||||
saveToHistory(request, interfaceName, requestHash, result, loginUser);
|
||||
}
|
||||
|
||||
return success(result);
|
||||
} catch (Exception e) {
|
||||
log.error("生成表格数据失败,接口: {}", interfaceName, e);
|
||||
return fail("生成表格数据失败: " + e.getMessage());
|
||||
} finally {
|
||||
cleanupTempKnowledgeBase(kbIdTmp);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成请求哈希
|
||||
*/
|
||||
private String generateRequestHash(AuditContentRequest request, String interfaceName) {
|
||||
String requestJson = JSONObject.toJSONString(request);
|
||||
return DigestUtil.md5Hex(interfaceName + ":" + requestJson);
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存到历史记录
|
||||
*/
|
||||
private void saveToHistory(AuditContentRequest request, String interfaceName, String requestHash, JSONObject result, User loginUser) {
|
||||
try {
|
||||
aiHistoryService.saveHistory(requestHash, interfaceName, JSONObject.toJSONString(request), result.toJSONString(), loginUser.getUserId(), loginUser.getUsername(), loginUser.getTenantId());
|
||||
} catch (Exception e) {
|
||||
log.warn("保存历史记录失败", e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查是否有上传的文件
|
||||
*/
|
||||
private boolean hasUploadedFiles(AuditContentRequest request) {
|
||||
return !request.getDocList().isEmpty() || !request.getFileList().isEmpty();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取知识库ID
|
||||
*/
|
||||
private String getKnowledgeBaseId(String tempKbId, String requestKbIds) {
|
||||
return StrUtil.isNotBlank(tempKbId) ? tempKbId : requestKbIds;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取项目库KB IDs
|
||||
*/
|
||||
private String getLibraryKbIds(String libraryIds) {
|
||||
if (StrUtil.isBlank(libraryIds)) {
|
||||
return "";
|
||||
}
|
||||
List<String> idList = StrUtil.split(libraryIds, ',');
|
||||
List<PwlProjectLibrary> ret = pwlProjectLibraryService.list(new LambdaQueryWrapper<PwlProjectLibrary>().in(PwlProjectLibrary::getId, idList));
|
||||
return ret.stream().map(PwlProjectLibrary::getKbId).filter(StrUtil::isNotBlank).collect(Collectors.joining(","));
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建临时知识库并提交文档
|
||||
*/
|
||||
private String createTempKnowledgeBase(AuditContentRequest request) {
|
||||
String kbIdTmp = knowledgeBaseService.createKnowledgeBaseTemp();
|
||||
// 收集文档ID
|
||||
Set<Integer> docIds = request.getDocList().stream().flatMap(docId -> aiCloudDocService.getSelfAndChildren(docId).stream()).map(AiCloudDoc::getId).collect(Collectors.toSet());
|
||||
// 查询相关文件
|
||||
List<AiCloudFile> fileList = getRelatedFiles(docIds, request.getFileList());
|
||||
// 提取文件ID并提交到知识库
|
||||
Set<String> kbFileIds = fileList.stream().map(AiCloudFile::getFileId).collect(Collectors.toSet());
|
||||
if (!kbFileIds.isEmpty()) {
|
||||
knowledgeBaseService.submitDocuments(kbIdTmp, new ArrayList<>(kbFileIds));
|
||||
}
|
||||
return kbIdTmp;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取相关文件列表
|
||||
*/
|
||||
private List<AiCloudFile> getRelatedFiles(Set<Integer> docIds, List<Integer> fileList) {
|
||||
LambdaQueryWrapper<AiCloudFile> queryWrapper = new LambdaQueryWrapper<AiCloudFile>()
|
||||
.in(!docIds.isEmpty(), AiCloudFile::getDocId, docIds)
|
||||
.or(!fileList.isEmpty())
|
||||
.in(!fileList.isEmpty(), AiCloudFile::getId, fileList);
|
||||
return aiCloudFileService.list(queryWrapper);
|
||||
}
|
||||
|
||||
/**
|
||||
* 清理临时知识库
|
||||
*/
|
||||
private void cleanupTempKnowledgeBase(String kbId) {
|
||||
if (StrUtil.isNotBlank(kbId)) {
|
||||
try {
|
||||
knowledgeBaseService.deleteIndex(kbId);
|
||||
} catch (Exception e) {
|
||||
log.warn("删除临时知识库失败: {}", kbId, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出三重一大制度对比分析表到Excel
|
||||
*/
|
||||
@@ -247,44 +80,6 @@ public class AuditContent3Controller extends BaseController {
|
||||
this::convertToDecisionTableEntityList, DecisionTableExportEntity.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* 通用的Excel导出方法
|
||||
*/
|
||||
private <T> void exportToExcel(Map<String, Object> request, HttpServletResponse response,
|
||||
String sheetName, Function<List<Map<String, Object>>, List<T>> converter,
|
||||
Class<T> entityClass) {
|
||||
List<Map<String, Object>> dataList = (List<Map<String, Object>>) request.get("data");
|
||||
String companyName = (String) request.get("companyName");
|
||||
|
||||
List<T> exportData = converter.apply(dataList);
|
||||
|
||||
String fileName = sheetName + "_" + (companyName != null ? companyName : "未知公司");
|
||||
String title = companyName != null ? companyName + " - " + sheetName : sheetName;
|
||||
|
||||
ExcelExportTool.exportExcel(exportData, entityClass, fileName, sheetName, title, response);
|
||||
}
|
||||
|
||||
/**
|
||||
* 参数包装类
|
||||
*/
|
||||
private static class GenerateParams {
|
||||
final String knowledgeBaseId;
|
||||
final String libraryKbIds;
|
||||
final String projectLibrary;
|
||||
final String username;
|
||||
final String history;
|
||||
final String suggestion;
|
||||
|
||||
GenerateParams(String knowledgeBaseId, String libraryKbIds, String projectLibrary, String username, String history, String suggestion) {
|
||||
this.knowledgeBaseId = knowledgeBaseId;
|
||||
this.libraryKbIds = libraryKbIds;
|
||||
this.projectLibrary = projectLibrary;
|
||||
this.username = username;
|
||||
this.history = history;
|
||||
this.suggestion = suggestion;
|
||||
}
|
||||
}
|
||||
|
||||
// ========== 数据转换方法 ==========
|
||||
|
||||
private List<TripleOneExportEntity> convertToTripleOneEntityList(List<Map<String, Object>> originalData) {
|
||||
@@ -320,24 +115,4 @@ public class AuditContent3Controller extends BaseController {
|
||||
entity.setBad(getStringValue(item, "bad"));
|
||||
return entity;
|
||||
}
|
||||
|
||||
private String getStringValue(Map<String, Object> map, String key) {
|
||||
Object value = map.get(key);
|
||||
return value != null ? value.toString() : "";
|
||||
}
|
||||
|
||||
private String formatWorkPaperIndex(Object workPaperIndex) {
|
||||
if (workPaperIndex == null) {
|
||||
return "";
|
||||
}
|
||||
|
||||
if (workPaperIndex instanceof List) {
|
||||
List<?> list = (List<?>) workPaperIndex;
|
||||
return String.join(", ", list.stream()
|
||||
.map(Object::toString)
|
||||
.collect(Collectors.toList()));
|
||||
}
|
||||
|
||||
return workPaperIndex.toString();
|
||||
}
|
||||
}
|
||||
@@ -1,34 +1,22 @@
|
||||
package com.gxwebsoft.ai.controller;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.gxwebsoft.ai.dto.AuditContentRequest;
|
||||
import com.gxwebsoft.ai.dto.export.TargetAuditExportEntity;
|
||||
import com.gxwebsoft.ai.entity.AiCloudDoc;
|
||||
import com.gxwebsoft.ai.entity.AiCloudFile;
|
||||
import com.gxwebsoft.ai.service.AiHistoryService;
|
||||
import com.gxwebsoft.ai.service.AuditContent4TargetService;
|
||||
import com.gxwebsoft.ai.utils.ExcelExportTool;
|
||||
import com.gxwebsoft.common.core.web.ApiResult;
|
||||
import com.gxwebsoft.common.core.web.BaseController;
|
||||
import com.gxwebsoft.common.system.entity.User;
|
||||
import com.gxwebsoft.pwl.entity.PwlProjectLibrary;
|
||||
import com.gxwebsoft.pwl.service.PwlProjectLibraryService;
|
||||
import com.gxwebsoft.ai.service.AiCloudDocService;
|
||||
import com.gxwebsoft.ai.service.AiCloudFileService;
|
||||
import com.gxwebsoft.ai.service.AuditContent4TargetService;
|
||||
import com.gxwebsoft.ai.service.KnowledgeBaseService;
|
||||
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.crypto.digest.DigestUtil;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.util.*;
|
||||
import java.util.function.Function;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
@@ -38,29 +26,11 @@ import java.util.stream.Collectors;
|
||||
@Tag(name = "审计内容4-目标责任制完成情况")
|
||||
@RestController
|
||||
@RequestMapping("/api/ai/auditContent4")
|
||||
public class AuditContent4Controller extends BaseController {
|
||||
public class AuditContent4Controller extends BaseAuditContentController {
|
||||
|
||||
@Autowired
|
||||
private AuditContent4TargetService auditContent4TargetService;
|
||||
|
||||
@Autowired
|
||||
private AiCloudDocService aiCloudDocService;
|
||||
|
||||
@Autowired
|
||||
private AiCloudFileService aiCloudFileService;
|
||||
|
||||
@Autowired
|
||||
private KnowledgeBaseService knowledgeBaseService;
|
||||
|
||||
@Autowired
|
||||
private PwlProjectLibraryService pwlProjectLibraryService;
|
||||
|
||||
@Autowired
|
||||
private AiHistoryService aiHistoryService;
|
||||
|
||||
// 历史记录有效期(分钟)
|
||||
private static final int HISTORY_EXPIRE_MINUTES = 10;
|
||||
|
||||
/**
|
||||
* 生成目标责任制完成情况审计表数据
|
||||
*/
|
||||
@@ -74,154 +44,12 @@ public class AuditContent4Controller extends BaseController {
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* 通用的表格数据生成方法
|
||||
*/
|
||||
private ApiResult<?> generateTableData(AuditContentRequest request, String interfaceName, Function<GenerateParams, JSONObject> generateFunction) {
|
||||
final User loginUser = getLoginUser();
|
||||
String requestHistory = request.getHistory();
|
||||
request.setHistory("");
|
||||
|
||||
// 检查历史记录
|
||||
String requestHash = generateRequestHash(request, interfaceName);
|
||||
var history = aiHistoryService.getValidHistory(requestHash, interfaceName, HISTORY_EXPIRE_MINUTES);
|
||||
if (history != null) {
|
||||
log.info("返回历史数据,请求哈希: {}", requestHash);
|
||||
return success(JSONObject.parseObject(history.getResponseData()));
|
||||
}
|
||||
request.setHistory(requestHistory);
|
||||
|
||||
String kbIdTmp = "";
|
||||
String libraryKbIds = "";
|
||||
|
||||
try {
|
||||
// 创建临时知识库(如果需要)
|
||||
if (hasUploadedFiles(request)) {
|
||||
kbIdTmp = createTempKnowledgeBase(request);
|
||||
}
|
||||
|
||||
// 查询项目库信息
|
||||
libraryKbIds = getLibraryKbIds(request.getLibraryIds());
|
||||
|
||||
// 生成数据
|
||||
String knowledgeBaseId = getKnowledgeBaseId(kbIdTmp, request.getKbIds());
|
||||
GenerateParams params = new GenerateParams(knowledgeBaseId, libraryKbIds, request.getProjectLibrary(), loginUser.getUsername(), request.getHistory(), request.getSuggestion());
|
||||
|
||||
JSONObject result = generateFunction.apply(params);
|
||||
|
||||
if(result.getBoolean("success")) {
|
||||
// 保存到历史记录
|
||||
saveToHistory(request, interfaceName, requestHash, result, loginUser);
|
||||
}
|
||||
|
||||
return success(result);
|
||||
} catch (Exception e) {
|
||||
log.error("生成表格数据失败,接口: {}", interfaceName, e);
|
||||
return fail("生成表格数据失败: " + e.getMessage());
|
||||
} finally {
|
||||
cleanupTempKnowledgeBase(kbIdTmp);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成请求哈希
|
||||
*/
|
||||
private String generateRequestHash(AuditContentRequest request, String interfaceName) {
|
||||
String requestJson = JSONObject.toJSONString(request);
|
||||
return DigestUtil.md5Hex(interfaceName + ":" + requestJson);
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存到历史记录
|
||||
*/
|
||||
private void saveToHistory(AuditContentRequest request, String interfaceName, String requestHash, JSONObject result, User loginUser) {
|
||||
try {
|
||||
aiHistoryService.saveHistory(requestHash, interfaceName, JSONObject.toJSONString(request), result.toJSONString(), loginUser.getUserId(), loginUser.getUsername(), loginUser.getTenantId());
|
||||
} catch (Exception e) {
|
||||
log.warn("保存历史记录失败", e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查是否有上传的文件
|
||||
*/
|
||||
private boolean hasUploadedFiles(AuditContentRequest request) {
|
||||
return !request.getDocList().isEmpty() || !request.getFileList().isEmpty();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取知识库ID
|
||||
*/
|
||||
private String getKnowledgeBaseId(String tempKbId, String requestKbIds) {
|
||||
return StrUtil.isNotBlank(tempKbId) ? tempKbId : requestKbIds;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取项目库KB IDs
|
||||
*/
|
||||
private String getLibraryKbIds(String libraryIds) {
|
||||
if (StrUtil.isBlank(libraryIds)) {
|
||||
return "";
|
||||
}
|
||||
List<String> idList = StrUtil.split(libraryIds, ',');
|
||||
List<PwlProjectLibrary> ret = pwlProjectLibraryService.list(new LambdaQueryWrapper<PwlProjectLibrary>().in(PwlProjectLibrary::getId, idList));
|
||||
return ret.stream().map(PwlProjectLibrary::getKbId).filter(StrUtil::isNotBlank).collect(Collectors.joining(","));
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建临时知识库并提交文档
|
||||
*/
|
||||
private String createTempKnowledgeBase(AuditContentRequest request) {
|
||||
String kbIdTmp = knowledgeBaseService.createKnowledgeBaseTemp();
|
||||
// 收集文档ID
|
||||
Set<Integer> docIds = request.getDocList().stream().flatMap(docId -> aiCloudDocService.getSelfAndChildren(docId).stream()).map(AiCloudDoc::getId).collect(Collectors.toSet());
|
||||
// 查询相关文件
|
||||
List<AiCloudFile> fileList = getRelatedFiles(docIds, request.getFileList());
|
||||
// 提取文件ID并提交到知识库
|
||||
Set<String> kbFileIds = fileList.stream().map(AiCloudFile::getFileId).collect(Collectors.toSet());
|
||||
if (!kbFileIds.isEmpty()) {
|
||||
knowledgeBaseService.submitDocuments(kbIdTmp, new ArrayList<>(kbFileIds));
|
||||
}
|
||||
return kbIdTmp;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取相关文件列表
|
||||
*/
|
||||
private List<AiCloudFile> getRelatedFiles(Set<Integer> docIds, List<Integer> fileList) {
|
||||
LambdaQueryWrapper<AiCloudFile> queryWrapper = new LambdaQueryWrapper<AiCloudFile>()
|
||||
.in(!docIds.isEmpty(), AiCloudFile::getDocId, docIds)
|
||||
.or(!fileList.isEmpty())
|
||||
.in(!fileList.isEmpty(), AiCloudFile::getId, fileList);
|
||||
return aiCloudFileService.list(queryWrapper);
|
||||
}
|
||||
|
||||
/**
|
||||
* 清理临时知识库
|
||||
*/
|
||||
private void cleanupTempKnowledgeBase(String kbId) {
|
||||
if (StrUtil.isNotBlank(kbId)) {
|
||||
try {
|
||||
knowledgeBaseService.deleteIndex(kbId);
|
||||
} catch (Exception e) {
|
||||
log.warn("删除临时知识库失败: {}", kbId, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出目标责任制完成情况审计表到Excel
|
||||
*/
|
||||
@Operation(summary = "导出目标责任制完成情况审计表到Excel")
|
||||
@PostMapping("/exportTargetTable")
|
||||
public void exportTargetTable(@RequestBody Map<String, Object> request, HttpServletResponse response) {
|
||||
exportToExcel(request, response);
|
||||
}
|
||||
|
||||
/**
|
||||
* Excel导出方法
|
||||
*/
|
||||
private void exportToExcel(Map<String, Object> request, HttpServletResponse response) {
|
||||
List<Map<String, Object>> dataList = (List<Map<String, Object>>) request.get("data");
|
||||
String companyName = (String) request.get("companyName");
|
||||
|
||||
@@ -255,45 +83,4 @@ public class AuditContent4Controller extends BaseController {
|
||||
entity.setWorkPaperIndex(formatWorkPaperIndex(item.get("workPaperIndex")));
|
||||
return entity;
|
||||
}
|
||||
|
||||
private String getStringValue(Map<String, Object> map, String key) {
|
||||
Object value = map.get(key);
|
||||
return value != null ? value.toString() : "";
|
||||
}
|
||||
|
||||
private String formatWorkPaperIndex(Object workPaperIndex) {
|
||||
if (workPaperIndex == null) {
|
||||
return "";
|
||||
}
|
||||
|
||||
if (workPaperIndex instanceof List) {
|
||||
List<?> list = (List<?>) workPaperIndex;
|
||||
return String.join(", ", list.stream()
|
||||
.map(Object::toString)
|
||||
.collect(Collectors.toList()));
|
||||
}
|
||||
|
||||
return workPaperIndex.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* 参数包装类
|
||||
*/
|
||||
private static class GenerateParams {
|
||||
final String knowledgeBaseId;
|
||||
final String libraryKbIds;
|
||||
final String projectLibrary;
|
||||
final String username;
|
||||
final String history;
|
||||
final String suggestion;
|
||||
|
||||
GenerateParams(String knowledgeBaseId, String libraryKbIds, String projectLibrary, String username, String history, String suggestion) {
|
||||
this.knowledgeBaseId = knowledgeBaseId;
|
||||
this.libraryKbIds = libraryKbIds;
|
||||
this.projectLibrary = projectLibrary;
|
||||
this.username = username;
|
||||
this.history = history;
|
||||
this.suggestion = suggestion;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,36 +1,22 @@
|
||||
package com.gxwebsoft.ai.controller;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.gxwebsoft.ai.dto.AuditContentRequest;
|
||||
import com.gxwebsoft.ai.dto.export.BudgetManageExportEntity;
|
||||
import com.gxwebsoft.ai.dto.export.BudgetExecutionExportEntity;
|
||||
import com.gxwebsoft.ai.entity.AiCloudDoc;
|
||||
import com.gxwebsoft.ai.entity.AiCloudFile;
|
||||
import com.gxwebsoft.ai.service.AiHistoryService;
|
||||
import com.gxwebsoft.ai.utils.ExcelExportTool;
|
||||
import com.gxwebsoft.common.core.web.ApiResult;
|
||||
import com.gxwebsoft.common.core.web.BaseController;
|
||||
import com.gxwebsoft.common.system.entity.User;
|
||||
import com.gxwebsoft.pwl.entity.PwlProjectLibrary;
|
||||
import com.gxwebsoft.pwl.service.PwlProjectLibraryService;
|
||||
import com.gxwebsoft.ai.service.AiCloudDocService;
|
||||
import com.gxwebsoft.ai.service.AiCloudFileService;
|
||||
import com.gxwebsoft.ai.service.AuditContent5BudgetManageService;
|
||||
import com.gxwebsoft.common.core.web.ApiResult;
|
||||
import com.gxwebsoft.ai.service.AuditContent5BudgetExecutionService;
|
||||
import com.gxwebsoft.ai.service.KnowledgeBaseService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.crypto.digest.DigestUtil;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.util.*;
|
||||
import java.util.function.Function;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
@@ -40,7 +26,7 @@ import java.util.stream.Collectors;
|
||||
@Tag(name = "审计内容5-预算管理审计")
|
||||
@RestController
|
||||
@RequestMapping("/api/ai/auditContent5")
|
||||
public class AuditContent5Controller extends BaseController {
|
||||
public class AuditContent5Controller extends BaseAuditContentController {
|
||||
|
||||
@Autowired
|
||||
private AuditContent5BudgetManageService auditContent5BudgetManageService;
|
||||
@@ -48,24 +34,6 @@ public class AuditContent5Controller extends BaseController {
|
||||
@Autowired
|
||||
private AuditContent5BudgetExecutionService auditContent5BudgetExecutionService;
|
||||
|
||||
@Autowired
|
||||
private AiCloudDocService aiCloudDocService;
|
||||
|
||||
@Autowired
|
||||
private AiCloudFileService aiCloudFileService;
|
||||
|
||||
@Autowired
|
||||
private KnowledgeBaseService knowledgeBaseService;
|
||||
|
||||
@Autowired
|
||||
private PwlProjectLibraryService pwlProjectLibraryService;
|
||||
|
||||
@Autowired
|
||||
private AiHistoryService aiHistoryService;
|
||||
|
||||
// 历史记录有效期(分钟)
|
||||
private static final int HISTORY_EXPIRE_MINUTES = 10;
|
||||
|
||||
/**
|
||||
* 生成预算管理审计表数据
|
||||
*/
|
||||
@@ -92,141 +60,6 @@ public class AuditContent5Controller extends BaseController {
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* 通用的表格数据生成方法
|
||||
*/
|
||||
private ApiResult<?> generateTableData(AuditContentRequest request, String interfaceName, Function<GenerateParams, JSONObject> generateFunction) {
|
||||
final User loginUser = getLoginUser();
|
||||
String requestHistory = request.getHistory();
|
||||
request.setHistory("");
|
||||
|
||||
// 检查历史记录
|
||||
String requestHash = generateRequestHash(request, interfaceName);
|
||||
var history = aiHistoryService.getValidHistory(requestHash, interfaceName, HISTORY_EXPIRE_MINUTES);
|
||||
if (history != null) {
|
||||
log.info("返回历史数据,请求哈希: {}", requestHash);
|
||||
return success(JSONObject.parseObject(history.getResponseData()));
|
||||
}
|
||||
request.setHistory(requestHistory);
|
||||
|
||||
String kbIdTmp = "";
|
||||
String libraryKbIds = "";
|
||||
|
||||
try {
|
||||
// 创建临时知识库(如果需要)
|
||||
if (hasUploadedFiles(request)) {
|
||||
kbIdTmp = createTempKnowledgeBase(request);
|
||||
}
|
||||
|
||||
// 查询项目库信息
|
||||
libraryKbIds = getLibraryKbIds(request.getLibraryIds());
|
||||
|
||||
// 生成数据
|
||||
String knowledgeBaseId = getKnowledgeBaseId(kbIdTmp, request.getKbIds());
|
||||
GenerateParams params = new GenerateParams(knowledgeBaseId, libraryKbIds, request.getProjectLibrary(), loginUser.getUsername(), request.getHistory(), request.getSuggestion());
|
||||
|
||||
JSONObject result = generateFunction.apply(params);
|
||||
|
||||
if(result.getBoolean("success")) {
|
||||
// 保存到历史记录
|
||||
saveToHistory(request, interfaceName, requestHash, result, loginUser);
|
||||
}
|
||||
|
||||
return success(result);
|
||||
} catch (Exception e) {
|
||||
log.error("生成表格数据失败,接口: {}", interfaceName, e);
|
||||
return fail("生成表格数据失败: " + e.getMessage());
|
||||
} finally {
|
||||
cleanupTempKnowledgeBase(kbIdTmp);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成请求哈希
|
||||
*/
|
||||
private String generateRequestHash(AuditContentRequest request, String interfaceName) {
|
||||
String requestJson = JSONObject.toJSONString(request);
|
||||
return DigestUtil.md5Hex(interfaceName + ":" + requestJson);
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存到历史记录
|
||||
*/
|
||||
private void saveToHistory(AuditContentRequest request, String interfaceName, String requestHash, JSONObject result, User loginUser) {
|
||||
try {
|
||||
aiHistoryService.saveHistory(requestHash, interfaceName, JSONObject.toJSONString(request), result.toJSONString(), loginUser.getUserId(), loginUser.getUsername(), loginUser.getTenantId());
|
||||
} catch (Exception e) {
|
||||
log.warn("保存历史记录失败", e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查是否有上传的文件
|
||||
*/
|
||||
private boolean hasUploadedFiles(AuditContentRequest request) {
|
||||
return !request.getDocList().isEmpty() || !request.getFileList().isEmpty();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取知识库ID
|
||||
*/
|
||||
private String getKnowledgeBaseId(String tempKbId, String requestKbIds) {
|
||||
return StrUtil.isNotBlank(tempKbId) ? tempKbId : requestKbIds;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取项目库KB IDs
|
||||
*/
|
||||
private String getLibraryKbIds(String libraryIds) {
|
||||
if (StrUtil.isBlank(libraryIds)) {
|
||||
return "";
|
||||
}
|
||||
List<String> idList = StrUtil.split(libraryIds, ',');
|
||||
List<PwlProjectLibrary> ret = pwlProjectLibraryService.list(new LambdaQueryWrapper<PwlProjectLibrary>().in(PwlProjectLibrary::getId, idList));
|
||||
return ret.stream().map(PwlProjectLibrary::getKbId).filter(StrUtil::isNotBlank).collect(Collectors.joining(","));
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建临时知识库并提交文档
|
||||
*/
|
||||
private String createTempKnowledgeBase(AuditContentRequest request) {
|
||||
String kbIdTmp = knowledgeBaseService.createKnowledgeBaseTemp();
|
||||
// 收集文档ID
|
||||
Set<Integer> docIds = request.getDocList().stream().flatMap(docId -> aiCloudDocService.getSelfAndChildren(docId).stream()).map(AiCloudDoc::getId).collect(Collectors.toSet());
|
||||
// 查询相关文件
|
||||
List<AiCloudFile> fileList = getRelatedFiles(docIds, request.getFileList());
|
||||
// 提取文件ID并提交到知识库
|
||||
Set<String> kbFileIds = fileList.stream().map(AiCloudFile::getFileId).collect(Collectors.toSet());
|
||||
if (!kbFileIds.isEmpty()) {
|
||||
knowledgeBaseService.submitDocuments(kbIdTmp, new ArrayList<>(kbFileIds));
|
||||
}
|
||||
return kbIdTmp;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取相关文件列表
|
||||
*/
|
||||
private List<AiCloudFile> getRelatedFiles(Set<Integer> docIds, List<Integer> fileList) {
|
||||
LambdaQueryWrapper<AiCloudFile> queryWrapper = new LambdaQueryWrapper<AiCloudFile>()
|
||||
.in(!docIds.isEmpty(), AiCloudFile::getDocId, docIds)
|
||||
.or(!fileList.isEmpty())
|
||||
.in(!fileList.isEmpty(), AiCloudFile::getId, fileList);
|
||||
return aiCloudFileService.list(queryWrapper);
|
||||
}
|
||||
|
||||
/**
|
||||
* 清理临时知识库
|
||||
*/
|
||||
private void cleanupTempKnowledgeBase(String kbId) {
|
||||
if (StrUtil.isNotBlank(kbId)) {
|
||||
try {
|
||||
knowledgeBaseService.deleteIndex(kbId);
|
||||
} catch (Exception e) {
|
||||
log.warn("删除临时知识库失败: {}", kbId, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出预算管理审计表到Excel
|
||||
*/
|
||||
@@ -247,44 +80,6 @@ public class AuditContent5Controller extends BaseController {
|
||||
this::convertToBudgetExecutionEntityList, BudgetExecutionExportEntity.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* 通用的Excel导出方法
|
||||
*/
|
||||
private <T> void exportToExcel(Map<String, Object> request, HttpServletResponse response,
|
||||
String sheetName, Function<List<Map<String, Object>>, List<T>> converter,
|
||||
Class<T> entityClass) {
|
||||
List<Map<String, Object>> dataList = (List<Map<String, Object>>) request.get("data");
|
||||
String companyName = (String) request.get("companyName");
|
||||
|
||||
List<T> exportData = converter.apply(dataList);
|
||||
|
||||
String fileName = sheetName + "_" + (companyName != null ? companyName : "未知公司");
|
||||
String title = companyName != null ? companyName + " - " + sheetName : sheetName;
|
||||
|
||||
ExcelExportTool.exportExcel(exportData, entityClass, fileName, sheetName, title, response);
|
||||
}
|
||||
|
||||
/**
|
||||
* 参数包装类
|
||||
*/
|
||||
private static class GenerateParams {
|
||||
final String knowledgeBaseId;
|
||||
final String libraryKbIds;
|
||||
final String projectLibrary;
|
||||
final String username;
|
||||
final String history;
|
||||
final String suggestion;
|
||||
|
||||
GenerateParams(String knowledgeBaseId, String libraryKbIds, String projectLibrary, String username, String history, String suggestion) {
|
||||
this.knowledgeBaseId = knowledgeBaseId;
|
||||
this.libraryKbIds = libraryKbIds;
|
||||
this.projectLibrary = projectLibrary;
|
||||
this.username = username;
|
||||
this.history = history;
|
||||
this.suggestion = suggestion;
|
||||
}
|
||||
}
|
||||
|
||||
// ========== 数据转换方法 ==========
|
||||
|
||||
private List<BudgetManageExportEntity> convertToBudgetManageEntityList(List<Map<String, Object>> originalData) {
|
||||
@@ -329,24 +124,4 @@ public class AuditContent5Controller extends BaseController {
|
||||
entity.setWorkPaperIndex(formatWorkPaperIndex(item.get("workPaperIndex")));
|
||||
return entity;
|
||||
}
|
||||
|
||||
private String getStringValue(Map<String, Object> map, String key) {
|
||||
Object value = map.get(key);
|
||||
return value != null ? value.toString() : "";
|
||||
}
|
||||
|
||||
private String formatWorkPaperIndex(Object workPaperIndex) {
|
||||
if (workPaperIndex == null) {
|
||||
return "";
|
||||
}
|
||||
|
||||
if (workPaperIndex instanceof List) {
|
||||
List<?> list = (List<?>) workPaperIndex;
|
||||
return String.join(", ", list.stream()
|
||||
.map(Object::toString)
|
||||
.collect(Collectors.toList()));
|
||||
}
|
||||
|
||||
return workPaperIndex.toString();
|
||||
}
|
||||
}
|
||||
@@ -1,34 +1,22 @@
|
||||
package com.gxwebsoft.ai.controller;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.gxwebsoft.ai.dto.AuditContentRequest;
|
||||
import com.gxwebsoft.ai.dto.export.StateAssetsAuditExportEntity;
|
||||
import com.gxwebsoft.ai.entity.AiCloudDoc;
|
||||
import com.gxwebsoft.ai.entity.AiCloudFile;
|
||||
import com.gxwebsoft.ai.service.AiHistoryService;
|
||||
import com.gxwebsoft.ai.service.AuditContent6StateAssetsService;
|
||||
import com.gxwebsoft.ai.utils.ExcelExportTool;
|
||||
import com.gxwebsoft.common.core.web.ApiResult;
|
||||
import com.gxwebsoft.common.core.web.BaseController;
|
||||
import com.gxwebsoft.common.system.entity.User;
|
||||
import com.gxwebsoft.pwl.entity.PwlProjectLibrary;
|
||||
import com.gxwebsoft.pwl.service.PwlProjectLibraryService;
|
||||
import com.gxwebsoft.ai.service.AiCloudDocService;
|
||||
import com.gxwebsoft.ai.service.AiCloudFileService;
|
||||
import com.gxwebsoft.ai.service.AuditContent6StateAssetsService;
|
||||
import com.gxwebsoft.ai.service.KnowledgeBaseService;
|
||||
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.crypto.digest.DigestUtil;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.util.*;
|
||||
import java.util.function.Function;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
@@ -38,29 +26,11 @@ import java.util.stream.Collectors;
|
||||
@Tag(name = "审计内容6-国资管理情况")
|
||||
@RestController
|
||||
@RequestMapping("/api/ai/auditContent6")
|
||||
public class AuditContent6Controller extends BaseController {
|
||||
public class AuditContent6Controller extends BaseAuditContentController {
|
||||
|
||||
@Autowired
|
||||
private AuditContent6StateAssetsService auditContent6StateAssetsService;
|
||||
|
||||
@Autowired
|
||||
private AiCloudDocService aiCloudDocService;
|
||||
|
||||
@Autowired
|
||||
private AiCloudFileService aiCloudFileService;
|
||||
|
||||
@Autowired
|
||||
private KnowledgeBaseService knowledgeBaseService;
|
||||
|
||||
@Autowired
|
||||
private PwlProjectLibraryService pwlProjectLibraryService;
|
||||
|
||||
@Autowired
|
||||
private AiHistoryService aiHistoryService;
|
||||
|
||||
// 历史记录有效期(分钟)
|
||||
private static final int HISTORY_EXPIRE_MINUTES = 10;
|
||||
|
||||
/**
|
||||
* 生成国有资产管理审计表数据
|
||||
*/
|
||||
@@ -74,154 +44,12 @@ public class AuditContent6Controller extends BaseController {
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* 通用的表格数据生成方法
|
||||
*/
|
||||
private ApiResult<?> generateTableData(AuditContentRequest request, String interfaceName, Function<GenerateParams, JSONObject> generateFunction) {
|
||||
final User loginUser = getLoginUser();
|
||||
String requestHistory = request.getHistory();
|
||||
request.setHistory("");
|
||||
|
||||
// 检查历史记录
|
||||
String requestHash = generateRequestHash(request, interfaceName);
|
||||
var history = aiHistoryService.getValidHistory(requestHash, interfaceName, HISTORY_EXPIRE_MINUTES);
|
||||
if (history != null) {
|
||||
log.info("返回历史数据,请求哈希: {}", requestHash);
|
||||
return success(JSONObject.parseObject(history.getResponseData()));
|
||||
}
|
||||
request.setHistory(requestHistory);
|
||||
|
||||
String kbIdTmp = "";
|
||||
String libraryKbIds = "";
|
||||
|
||||
try {
|
||||
// 创建临时知识库(如果需要)
|
||||
if (hasUploadedFiles(request)) {
|
||||
kbIdTmp = createTempKnowledgeBase(request);
|
||||
}
|
||||
|
||||
// 查询项目库信息
|
||||
libraryKbIds = getLibraryKbIds(request.getLibraryIds());
|
||||
|
||||
// 生成数据
|
||||
String knowledgeBaseId = getKnowledgeBaseId(kbIdTmp, request.getKbIds());
|
||||
GenerateParams params = new GenerateParams(knowledgeBaseId, libraryKbIds, request.getProjectLibrary(), loginUser.getUsername(), request.getHistory(), request.getSuggestion());
|
||||
|
||||
JSONObject result = generateFunction.apply(params);
|
||||
|
||||
if(result.getBoolean("success")) {
|
||||
// 保存到历史记录
|
||||
saveToHistory(request, interfaceName, requestHash, result, loginUser);
|
||||
}
|
||||
|
||||
return success(result);
|
||||
} catch (Exception e) {
|
||||
log.error("生成表格数据失败,接口: {}", interfaceName, e);
|
||||
return fail("生成表格数据失败: " + e.getMessage());
|
||||
} finally {
|
||||
cleanupTempKnowledgeBase(kbIdTmp);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成请求哈希
|
||||
*/
|
||||
private String generateRequestHash(AuditContentRequest request, String interfaceName) {
|
||||
String requestJson = JSONObject.toJSONString(request);
|
||||
return DigestUtil.md5Hex(interfaceName + ":" + requestJson);
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存到历史记录
|
||||
*/
|
||||
private void saveToHistory(AuditContentRequest request, String interfaceName, String requestHash, JSONObject result, User loginUser) {
|
||||
try {
|
||||
aiHistoryService.saveHistory(requestHash, interfaceName, JSONObject.toJSONString(request), result.toJSONString(), loginUser.getUserId(), loginUser.getUsername(), loginUser.getTenantId());
|
||||
} catch (Exception e) {
|
||||
log.warn("保存历史记录失败", e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查是否有上传的文件
|
||||
*/
|
||||
private boolean hasUploadedFiles(AuditContentRequest request) {
|
||||
return !request.getDocList().isEmpty() || !request.getFileList().isEmpty();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取知识库ID
|
||||
*/
|
||||
private String getKnowledgeBaseId(String tempKbId, String requestKbIds) {
|
||||
return StrUtil.isNotBlank(tempKbId) ? tempKbId : requestKbIds;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取项目库KB IDs
|
||||
*/
|
||||
private String getLibraryKbIds(String libraryIds) {
|
||||
if (StrUtil.isBlank(libraryIds)) {
|
||||
return "";
|
||||
}
|
||||
List<String> idList = StrUtil.split(libraryIds, ',');
|
||||
List<PwlProjectLibrary> ret = pwlProjectLibraryService.list(new LambdaQueryWrapper<PwlProjectLibrary>().in(PwlProjectLibrary::getId, idList));
|
||||
return ret.stream().map(PwlProjectLibrary::getKbId).filter(StrUtil::isNotBlank).collect(Collectors.joining(","));
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建临时知识库并提交文档
|
||||
*/
|
||||
private String createTempKnowledgeBase(AuditContentRequest request) {
|
||||
String kbIdTmp = knowledgeBaseService.createKnowledgeBaseTemp();
|
||||
// 收集文档ID
|
||||
Set<Integer> docIds = request.getDocList().stream().flatMap(docId -> aiCloudDocService.getSelfAndChildren(docId).stream()).map(AiCloudDoc::getId).collect(Collectors.toSet());
|
||||
// 查询相关文件
|
||||
List<AiCloudFile> fileList = getRelatedFiles(docIds, request.getFileList());
|
||||
// 提取文件ID并提交到知识库
|
||||
Set<String> kbFileIds = fileList.stream().map(AiCloudFile::getFileId).collect(Collectors.toSet());
|
||||
if (!kbFileIds.isEmpty()) {
|
||||
knowledgeBaseService.submitDocuments(kbIdTmp, new ArrayList<>(kbFileIds));
|
||||
}
|
||||
return kbIdTmp;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取相关文件列表
|
||||
*/
|
||||
private List<AiCloudFile> getRelatedFiles(Set<Integer> docIds, List<Integer> fileList) {
|
||||
LambdaQueryWrapper<AiCloudFile> queryWrapper = new LambdaQueryWrapper<AiCloudFile>()
|
||||
.in(!docIds.isEmpty(), AiCloudFile::getDocId, docIds)
|
||||
.or(!fileList.isEmpty())
|
||||
.in(!fileList.isEmpty(), AiCloudFile::getId, fileList);
|
||||
return aiCloudFileService.list(queryWrapper);
|
||||
}
|
||||
|
||||
/**
|
||||
* 清理临时知识库
|
||||
*/
|
||||
private void cleanupTempKnowledgeBase(String kbId) {
|
||||
if (StrUtil.isNotBlank(kbId)) {
|
||||
try {
|
||||
knowledgeBaseService.deleteIndex(kbId);
|
||||
} catch (Exception e) {
|
||||
log.warn("删除临时知识库失败: {}", kbId, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出国有资产管理审计表到Excel
|
||||
*/
|
||||
@Operation(summary = "导出国有资产管理审计表到Excel")
|
||||
@PostMapping("/exportAssetsTable")
|
||||
public void exportAssetsTable(@RequestBody Map<String, Object> request, HttpServletResponse response) {
|
||||
exportToExcel(request, response);
|
||||
}
|
||||
|
||||
/**
|
||||
* Excel导出方法
|
||||
*/
|
||||
private void exportToExcel(Map<String, Object> request, HttpServletResponse response) {
|
||||
List<Map<String, Object>> dataList = (List<Map<String, Object>>) request.get("data");
|
||||
String companyName = (String) request.get("companyName");
|
||||
|
||||
@@ -260,45 +88,4 @@ public class AuditContent6Controller extends BaseController {
|
||||
entity.setWorkPaperIndex(formatWorkPaperIndex(item.get("workPaperIndex")));
|
||||
return entity;
|
||||
}
|
||||
|
||||
private String getStringValue(Map<String, Object> map, String key) {
|
||||
Object value = map.get(key);
|
||||
return value != null ? value.toString() : "";
|
||||
}
|
||||
|
||||
private String formatWorkPaperIndex(Object workPaperIndex) {
|
||||
if (workPaperIndex == null) {
|
||||
return "";
|
||||
}
|
||||
|
||||
if (workPaperIndex instanceof List) {
|
||||
List<?> list = (List<?>) workPaperIndex;
|
||||
return String.join(", ", list.stream()
|
||||
.map(Object::toString)
|
||||
.collect(Collectors.toList()));
|
||||
}
|
||||
|
||||
return workPaperIndex.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* 参数包装类
|
||||
*/
|
||||
private static class GenerateParams {
|
||||
final String knowledgeBaseId;
|
||||
final String libraryKbIds;
|
||||
final String projectLibrary;
|
||||
final String username;
|
||||
final String history;
|
||||
final String suggestion;
|
||||
|
||||
GenerateParams(String knowledgeBaseId, String libraryKbIds, String projectLibrary, String username, String history, String suggestion) {
|
||||
this.knowledgeBaseId = knowledgeBaseId;
|
||||
this.libraryKbIds = libraryKbIds;
|
||||
this.projectLibrary = projectLibrary;
|
||||
this.username = username;
|
||||
this.history = history;
|
||||
this.suggestion = suggestion;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,34 +1,21 @@
|
||||
package com.gxwebsoft.ai.controller;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.gxwebsoft.ai.dto.AuditContentRequest;
|
||||
import com.gxwebsoft.ai.dto.export.InvestmentSituationExportEntity;
|
||||
import com.gxwebsoft.ai.entity.AiCloudDoc;
|
||||
import com.gxwebsoft.ai.entity.AiCloudFile;
|
||||
import com.gxwebsoft.ai.service.AiHistoryService;
|
||||
import com.gxwebsoft.ai.utils.ExcelExportTool;
|
||||
import com.gxwebsoft.common.core.web.ApiResult;
|
||||
import com.gxwebsoft.common.core.web.BaseController;
|
||||
import com.gxwebsoft.common.system.entity.User;
|
||||
import com.gxwebsoft.pwl.entity.PwlProjectLibrary;
|
||||
import com.gxwebsoft.pwl.service.PwlProjectLibraryService;
|
||||
import com.gxwebsoft.ai.service.AiCloudDocService;
|
||||
import com.gxwebsoft.ai.service.AiCloudFileService;
|
||||
import com.gxwebsoft.ai.service.AuditContent7InvestmentService;
|
||||
import com.gxwebsoft.ai.service.KnowledgeBaseService;
|
||||
import com.gxwebsoft.common.core.web.ApiResult;
|
||||
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.crypto.digest.DigestUtil;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.util.*;
|
||||
import java.util.function.Function;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
@@ -38,29 +25,11 @@ import java.util.stream.Collectors;
|
||||
@Tag(name = "审计内容7-重大投资情况")
|
||||
@RestController
|
||||
@RequestMapping("/api/ai/auditContent7")
|
||||
public class AuditContent7Controller extends BaseController {
|
||||
public class AuditContent7Controller extends BaseAuditContentController {
|
||||
|
||||
@Autowired
|
||||
private AuditContent7InvestmentService auditContent7InvestmentService;
|
||||
|
||||
@Autowired
|
||||
private AiCloudDocService aiCloudDocService;
|
||||
|
||||
@Autowired
|
||||
private AiCloudFileService aiCloudFileService;
|
||||
|
||||
@Autowired
|
||||
private KnowledgeBaseService knowledgeBaseService;
|
||||
|
||||
@Autowired
|
||||
private PwlProjectLibraryService pwlProjectLibraryService;
|
||||
|
||||
@Autowired
|
||||
private AiHistoryService aiHistoryService;
|
||||
|
||||
// 历史记录有效期(分钟)
|
||||
private static final int HISTORY_EXPIRE_MINUTES = 10;
|
||||
|
||||
/**
|
||||
* 生成重大投资情况审计表数据
|
||||
*/
|
||||
@@ -74,194 +43,16 @@ public class AuditContent7Controller extends BaseController {
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* 通用的表格数据生成方法
|
||||
*/
|
||||
private ApiResult<?> generateTableData(AuditContentRequest request, String interfaceName, Function<GenerateParams, JSONObject> generateFunction) {
|
||||
final User loginUser = getLoginUser();
|
||||
String requestHistory = request.getHistory();
|
||||
request.setHistory("");
|
||||
|
||||
// 检查历史记录
|
||||
String requestHash = generateRequestHash(request, interfaceName);
|
||||
var history = aiHistoryService.getValidHistory(requestHash, interfaceName, HISTORY_EXPIRE_MINUTES);
|
||||
if (history != null) {
|
||||
log.info("返回历史数据,请求哈希: {}", requestHash);
|
||||
return success(JSONObject.parseObject(history.getResponseData()));
|
||||
}
|
||||
request.setHistory(requestHistory);
|
||||
|
||||
String kbIdTmp = "";
|
||||
String libraryKbIds = "";
|
||||
|
||||
try {
|
||||
// 创建临时知识库(如果需要)
|
||||
if (hasUploadedFiles(request)) {
|
||||
kbIdTmp = createTempKnowledgeBase(request);
|
||||
}
|
||||
|
||||
// 查询项目库信息
|
||||
libraryKbIds = getLibraryKbIds(request.getLibraryIds());
|
||||
|
||||
// 生成数据
|
||||
String knowledgeBaseId = getKnowledgeBaseId(kbIdTmp, request.getKbIds());
|
||||
GenerateParams params = new GenerateParams(knowledgeBaseId, libraryKbIds, request.getProjectLibrary(), loginUser.getUsername(), request.getHistory(), request.getSuggestion());
|
||||
|
||||
JSONObject result = generateFunction.apply(params);
|
||||
|
||||
if(result.getBoolean("success")) {
|
||||
// 保存到历史记录
|
||||
saveToHistory(request, interfaceName, requestHash, result, loginUser);
|
||||
}
|
||||
|
||||
return success(result);
|
||||
} catch (Exception e) {
|
||||
log.error("生成表格数据失败,接口: {}", interfaceName, e);
|
||||
return fail("生成表格数据失败: " + e.getMessage());
|
||||
} finally {
|
||||
cleanupTempKnowledgeBase(kbIdTmp);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成请求哈希
|
||||
*/
|
||||
private String generateRequestHash(AuditContentRequest request, String interfaceName) {
|
||||
String requestJson = JSONObject.toJSONString(request);
|
||||
return DigestUtil.md5Hex(interfaceName + ":" + requestJson);
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存到历史记录
|
||||
*/
|
||||
private void saveToHistory(AuditContentRequest request, String interfaceName, String requestHash, JSONObject result, User loginUser) {
|
||||
try {
|
||||
aiHistoryService.saveHistory(requestHash, interfaceName, JSONObject.toJSONString(request), result.toJSONString(), loginUser.getUserId(), loginUser.getUsername(), loginUser.getTenantId());
|
||||
} catch (Exception e) {
|
||||
log.warn("保存历史记录失败", e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查是否有上传的文件
|
||||
*/
|
||||
private boolean hasUploadedFiles(AuditContentRequest request) {
|
||||
return !request.getDocList().isEmpty() || !request.getFileList().isEmpty();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取知识库ID
|
||||
*/
|
||||
private String getKnowledgeBaseId(String tempKbId, String requestKbIds) {
|
||||
return StrUtil.isNotBlank(tempKbId) ? tempKbId : requestKbIds;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取项目库KB IDs
|
||||
*/
|
||||
private String getLibraryKbIds(String libraryIds) {
|
||||
if (StrUtil.isBlank(libraryIds)) {
|
||||
return "";
|
||||
}
|
||||
List<String> idList = StrUtil.split(libraryIds, ',');
|
||||
List<PwlProjectLibrary> ret = pwlProjectLibraryService.list(new LambdaQueryWrapper<PwlProjectLibrary>().in(PwlProjectLibrary::getId, idList));
|
||||
return ret.stream().map(PwlProjectLibrary::getKbId).filter(StrUtil::isNotBlank).collect(Collectors.joining(","));
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建临时知识库并提交文档
|
||||
*/
|
||||
private String createTempKnowledgeBase(AuditContentRequest request) {
|
||||
String kbIdTmp = knowledgeBaseService.createKnowledgeBaseTemp();
|
||||
// 收集文档ID
|
||||
Set<Integer> docIds = request.getDocList().stream().flatMap(docId -> aiCloudDocService.getSelfAndChildren(docId).stream()).map(AiCloudDoc::getId).collect(Collectors.toSet());
|
||||
// 查询相关文件
|
||||
List<AiCloudFile> fileList = getRelatedFiles(docIds, request.getFileList());
|
||||
// 提取文件ID并提交到知识库
|
||||
Set<String> kbFileIds = fileList.stream().map(AiCloudFile::getFileId).collect(Collectors.toSet());
|
||||
if (!kbFileIds.isEmpty()) {
|
||||
knowledgeBaseService.submitDocuments(kbIdTmp, new ArrayList<>(kbFileIds));
|
||||
}
|
||||
return kbIdTmp;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取相关文件列表
|
||||
*/
|
||||
private List<AiCloudFile> getRelatedFiles(Set<Integer> docIds, List<Integer> fileList) {
|
||||
LambdaQueryWrapper<AiCloudFile> queryWrapper = new LambdaQueryWrapper<AiCloudFile>()
|
||||
.in(!docIds.isEmpty(), AiCloudFile::getDocId, docIds)
|
||||
.or(!fileList.isEmpty())
|
||||
.in(!fileList.isEmpty(), AiCloudFile::getId, fileList);
|
||||
return aiCloudFileService.list(queryWrapper);
|
||||
}
|
||||
|
||||
/**
|
||||
* 清理临时知识库
|
||||
*/
|
||||
private void cleanupTempKnowledgeBase(String kbId) {
|
||||
if (StrUtil.isNotBlank(kbId)) {
|
||||
try {
|
||||
knowledgeBaseService.deleteIndex(kbId);
|
||||
} catch (Exception e) {
|
||||
log.warn("删除临时知识库失败: {}", kbId, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出重大投资情况审计表到Excel
|
||||
*/
|
||||
@Operation(summary = "导出重大投资情况审计表到Excel")
|
||||
@PostMapping("/exportInvestmentSituationTable")
|
||||
public void exportInvestmentSituationTable(@RequestBody Map<String, Object> request, HttpServletResponse response) {
|
||||
exportToExcel(request, response, "重大投资情况审计表",
|
||||
exportToExcelWithAuditTime(request, response, "重大投资情况审计表",
|
||||
this::convertToInvestmentSituationEntityList, InvestmentSituationExportEntity.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* 通用的Excel导出方法
|
||||
*/
|
||||
private <T> void exportToExcel(Map<String, Object> request, HttpServletResponse response,
|
||||
String sheetName, Function<List<Map<String, Object>>, List<T>> converter,
|
||||
Class<T> entityClass) {
|
||||
List<Map<String, Object>> dataList = (List<Map<String, Object>>) request.get("data");
|
||||
String companyName = (String) request.get("companyName");
|
||||
String auditTime = (String) request.get("auditTime");
|
||||
|
||||
List<T> exportData = converter.apply(dataList);
|
||||
|
||||
String fileName = sheetName + "_" + (companyName != null ? companyName : "未知公司");
|
||||
String title = companyName != null ? companyName + " - " + sheetName : sheetName;
|
||||
|
||||
if (auditTime != null) {
|
||||
title += "(审计时间:" + auditTime + ")";
|
||||
}
|
||||
|
||||
ExcelExportTool.exportExcel(exportData, entityClass, fileName, sheetName, title, response);
|
||||
}
|
||||
|
||||
/**
|
||||
* 参数包装类
|
||||
*/
|
||||
private static class GenerateParams {
|
||||
final String knowledgeBaseId;
|
||||
final String libraryKbIds;
|
||||
final String projectLibrary;
|
||||
final String username;
|
||||
final String history;
|
||||
final String suggestion;
|
||||
|
||||
GenerateParams(String knowledgeBaseId, String libraryKbIds, String projectLibrary, String username, String history, String suggestion) {
|
||||
this.knowledgeBaseId = knowledgeBaseId;
|
||||
this.libraryKbIds = libraryKbIds;
|
||||
this.projectLibrary = projectLibrary;
|
||||
this.username = username;
|
||||
this.history = history;
|
||||
this.suggestion = suggestion;
|
||||
}
|
||||
}
|
||||
|
||||
// ========== 数据转换方法 ==========
|
||||
|
||||
private List<InvestmentSituationExportEntity> convertToInvestmentSituationEntityList(List<Map<String, Object>> originalData) {
|
||||
@@ -278,24 +69,4 @@ public class AuditContent7Controller extends BaseController {
|
||||
entity.setFileIndex(formatWorkPaperIndex(item.get("fileIndex")));
|
||||
return entity;
|
||||
}
|
||||
|
||||
private String getStringValue(Map<String, Object> map, String key) {
|
||||
Object value = map.get(key);
|
||||
return value != null ? value.toString() : "";
|
||||
}
|
||||
|
||||
private String formatWorkPaperIndex(Object workPaperIndex) {
|
||||
if (workPaperIndex == null) {
|
||||
return "";
|
||||
}
|
||||
|
||||
if (workPaperIndex instanceof List) {
|
||||
List<?> list = (List<?>) workPaperIndex;
|
||||
return String.join(", ", list.stream()
|
||||
.map(Object::toString)
|
||||
.collect(Collectors.toList()));
|
||||
}
|
||||
|
||||
return workPaperIndex.toString();
|
||||
}
|
||||
}
|
||||
@@ -1,34 +1,21 @@
|
||||
package com.gxwebsoft.ai.controller;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.gxwebsoft.ai.dto.AuditContentRequest;
|
||||
import com.gxwebsoft.ai.dto.export.InternalControlExportEntity;
|
||||
import com.gxwebsoft.ai.entity.AiCloudDoc;
|
||||
import com.gxwebsoft.ai.entity.AiCloudFile;
|
||||
import com.gxwebsoft.ai.service.AiHistoryService;
|
||||
import com.gxwebsoft.ai.utils.ExcelExportTool;
|
||||
import com.gxwebsoft.common.core.web.ApiResult;
|
||||
import com.gxwebsoft.common.core.web.BaseController;
|
||||
import com.gxwebsoft.common.system.entity.User;
|
||||
import com.gxwebsoft.pwl.entity.PwlProjectLibrary;
|
||||
import com.gxwebsoft.pwl.service.PwlProjectLibraryService;
|
||||
import com.gxwebsoft.ai.service.AiCloudDocService;
|
||||
import com.gxwebsoft.ai.service.AiCloudFileService;
|
||||
import com.gxwebsoft.ai.service.AuditContent8InternalControlService;
|
||||
import com.gxwebsoft.ai.service.KnowledgeBaseService;
|
||||
import com.gxwebsoft.common.core.web.ApiResult;
|
||||
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.crypto.digest.DigestUtil;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.util.*;
|
||||
import java.util.function.Function;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
@@ -38,29 +25,11 @@ import java.util.stream.Collectors;
|
||||
@Tag(name = "审计内容8-内部控制测试")
|
||||
@RestController
|
||||
@RequestMapping("/api/ai/auditContent8")
|
||||
public class AuditContent8Controller extends BaseController {
|
||||
public class AuditContent8Controller extends BaseAuditContentController {
|
||||
|
||||
@Autowired
|
||||
private AuditContent8InternalControlService auditContent8InternalControlService;
|
||||
|
||||
@Autowired
|
||||
private AiCloudDocService aiCloudDocService;
|
||||
|
||||
@Autowired
|
||||
private AiCloudFileService aiCloudFileService;
|
||||
|
||||
@Autowired
|
||||
private KnowledgeBaseService knowledgeBaseService;
|
||||
|
||||
@Autowired
|
||||
private PwlProjectLibraryService pwlProjectLibraryService;
|
||||
|
||||
@Autowired
|
||||
private AiHistoryService aiHistoryService;
|
||||
|
||||
// 历史记录有效期(分钟)
|
||||
private static final int HISTORY_EXPIRE_MINUTES = 10;
|
||||
|
||||
/**
|
||||
* 生成单位层面财务管理内部控制测试表数据
|
||||
*/
|
||||
@@ -74,141 +43,6 @@ public class AuditContent8Controller extends BaseController {
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* 通用的表格数据生成方法
|
||||
*/
|
||||
private ApiResult<?> generateTableData(AuditContentRequest request, String interfaceName, Function<GenerateParams, JSONObject> generateFunction) {
|
||||
final User loginUser = getLoginUser();
|
||||
String requestHistory = request.getHistory();
|
||||
request.setHistory("");
|
||||
|
||||
// 检查历史记录
|
||||
String requestHash = generateRequestHash(request, interfaceName);
|
||||
var history = aiHistoryService.getValidHistory(requestHash, interfaceName, HISTORY_EXPIRE_MINUTES);
|
||||
if (history != null) {
|
||||
log.info("返回历史数据,请求哈希: {}", requestHash);
|
||||
return success(JSONObject.parseObject(history.getResponseData()));
|
||||
}
|
||||
request.setHistory(requestHistory);
|
||||
|
||||
String kbIdTmp = "";
|
||||
String libraryKbIds = "";
|
||||
|
||||
try {
|
||||
// 创建临时知识库(如果需要)
|
||||
if (hasUploadedFiles(request)) {
|
||||
kbIdTmp = createTempKnowledgeBase(request);
|
||||
}
|
||||
|
||||
// 查询项目库信息
|
||||
libraryKbIds = getLibraryKbIds(request.getLibraryIds());
|
||||
|
||||
// 生成数据
|
||||
String knowledgeBaseId = getKnowledgeBaseId(kbIdTmp, request.getKbIds());
|
||||
GenerateParams params = new GenerateParams(knowledgeBaseId, libraryKbIds, request.getProjectLibrary(), loginUser.getUsername(), request.getHistory(), request.getSuggestion());
|
||||
|
||||
JSONObject result = generateFunction.apply(params);
|
||||
|
||||
if(result.getBoolean("success")) {
|
||||
// 保存到历史记录
|
||||
saveToHistory(request, interfaceName, requestHash, result, loginUser);
|
||||
}
|
||||
|
||||
return success(result);
|
||||
} catch (Exception e) {
|
||||
log.error("生成表格数据失败,接口: {}", interfaceName, e);
|
||||
return fail("生成表格数据失败: " + e.getMessage());
|
||||
} finally {
|
||||
cleanupTempKnowledgeBase(kbIdTmp);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成请求哈希
|
||||
*/
|
||||
private String generateRequestHash(AuditContentRequest request, String interfaceName) {
|
||||
String requestJson = JSONObject.toJSONString(request);
|
||||
return DigestUtil.md5Hex(interfaceName + ":" + requestJson);
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存到历史记录
|
||||
*/
|
||||
private void saveToHistory(AuditContentRequest request, String interfaceName, String requestHash, JSONObject result, User loginUser) {
|
||||
try {
|
||||
aiHistoryService.saveHistory(requestHash, interfaceName, JSONObject.toJSONString(request), result.toJSONString(), loginUser.getUserId(), loginUser.getUsername(), loginUser.getTenantId());
|
||||
} catch (Exception e) {
|
||||
log.warn("保存历史记录失败", e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查是否有上传的文件
|
||||
*/
|
||||
private boolean hasUploadedFiles(AuditContentRequest request) {
|
||||
return !request.getDocList().isEmpty() || !request.getFileList().isEmpty();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取知识库ID
|
||||
*/
|
||||
private String getKnowledgeBaseId(String tempKbId, String requestKbIds) {
|
||||
return StrUtil.isNotBlank(tempKbId) ? tempKbId : requestKbIds;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取项目库KB IDs
|
||||
*/
|
||||
private String getLibraryKbIds(String libraryIds) {
|
||||
if (StrUtil.isBlank(libraryIds)) {
|
||||
return "";
|
||||
}
|
||||
List<String> idList = StrUtil.split(libraryIds, ',');
|
||||
List<PwlProjectLibrary> ret = pwlProjectLibraryService.list(new LambdaQueryWrapper<PwlProjectLibrary>().in(PwlProjectLibrary::getId, idList));
|
||||
return ret.stream().map(PwlProjectLibrary::getKbId).filter(StrUtil::isNotBlank).collect(Collectors.joining(","));
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建临时知识库并提交文档
|
||||
*/
|
||||
private String createTempKnowledgeBase(AuditContentRequest request) {
|
||||
String kbIdTmp = knowledgeBaseService.createKnowledgeBaseTemp();
|
||||
// 收集文档ID
|
||||
Set<Integer> docIds = request.getDocList().stream().flatMap(docId -> aiCloudDocService.getSelfAndChildren(docId).stream()).map(AiCloudDoc::getId).collect(Collectors.toSet());
|
||||
// 查询相关文件
|
||||
List<AiCloudFile> fileList = getRelatedFiles(docIds, request.getFileList());
|
||||
// 提取文件ID并提交到知识库
|
||||
Set<String> kbFileIds = fileList.stream().map(AiCloudFile::getFileId).collect(Collectors.toSet());
|
||||
if (!kbFileIds.isEmpty()) {
|
||||
knowledgeBaseService.submitDocuments(kbIdTmp, new ArrayList<>(kbFileIds));
|
||||
}
|
||||
return kbIdTmp;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取相关文件列表
|
||||
*/
|
||||
private List<AiCloudFile> getRelatedFiles(Set<Integer> docIds, List<Integer> fileList) {
|
||||
LambdaQueryWrapper<AiCloudFile> queryWrapper = new LambdaQueryWrapper<AiCloudFile>()
|
||||
.in(!docIds.isEmpty(), AiCloudFile::getDocId, docIds)
|
||||
.or(!fileList.isEmpty())
|
||||
.in(!fileList.isEmpty(), AiCloudFile::getId, fileList);
|
||||
return aiCloudFileService.list(queryWrapper);
|
||||
}
|
||||
|
||||
/**
|
||||
* 清理临时知识库
|
||||
*/
|
||||
private void cleanupTempKnowledgeBase(String kbId) {
|
||||
if (StrUtil.isNotBlank(kbId)) {
|
||||
try {
|
||||
knowledgeBaseService.deleteIndex(kbId);
|
||||
} catch (Exception e) {
|
||||
log.warn("删除临时知识库失败: {}", kbId, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出单位层面财务管理内部控制测试表到Excel
|
||||
*/
|
||||
@@ -219,44 +53,6 @@ public class AuditContent8Controller extends BaseController {
|
||||
this::convertToInternalControlEntityList, InternalControlExportEntity.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* 通用的Excel导出方法
|
||||
*/
|
||||
private <T> void exportToExcel(Map<String, Object> request, HttpServletResponse response,
|
||||
String sheetName, Function<List<Map<String, Object>>, List<T>> converter,
|
||||
Class<T> entityClass) {
|
||||
List<Map<String, Object>> dataList = (List<Map<String, Object>>) request.get("data");
|
||||
String companyName = (String) request.get("companyName");
|
||||
|
||||
List<T> exportData = converter.apply(dataList);
|
||||
|
||||
String fileName = sheetName + "_" + (companyName != null ? companyName : "未知公司");
|
||||
String title = companyName != null ? companyName + " - " + sheetName : sheetName;
|
||||
|
||||
ExcelExportTool.exportExcel(exportData, entityClass, fileName, sheetName, title, response);
|
||||
}
|
||||
|
||||
/**
|
||||
* 参数包装类
|
||||
*/
|
||||
private static class GenerateParams {
|
||||
final String knowledgeBaseId;
|
||||
final String libraryKbIds;
|
||||
final String projectLibrary;
|
||||
final String username;
|
||||
final String history;
|
||||
final String suggestion;
|
||||
|
||||
GenerateParams(String knowledgeBaseId, String libraryKbIds, String projectLibrary, String username, String history, String suggestion) {
|
||||
this.knowledgeBaseId = knowledgeBaseId;
|
||||
this.libraryKbIds = libraryKbIds;
|
||||
this.projectLibrary = projectLibrary;
|
||||
this.username = username;
|
||||
this.history = history;
|
||||
this.suggestion = suggestion;
|
||||
}
|
||||
}
|
||||
|
||||
// ========== 数据转换方法 ==========
|
||||
|
||||
private List<InternalControlExportEntity> convertToInternalControlEntityList(List<Map<String, Object>> originalData) {
|
||||
@@ -276,24 +72,4 @@ public class AuditContent8Controller extends BaseController {
|
||||
entity.setWorkPaperIndex(formatWorkPaperIndex(item.get("workPaperIndex")));
|
||||
return entity;
|
||||
}
|
||||
|
||||
private String getStringValue(Map<String, Object> map, String key) {
|
||||
Object value = map.get(key);
|
||||
return value != null ? value.toString() : "";
|
||||
}
|
||||
|
||||
private String formatWorkPaperIndex(Object workPaperIndex) {
|
||||
if (workPaperIndex == null) {
|
||||
return "";
|
||||
}
|
||||
|
||||
if (workPaperIndex instanceof List) {
|
||||
List<?> list = (List<?>) workPaperIndex;
|
||||
return String.join(", ", list.stream()
|
||||
.map(Object::toString)
|
||||
.collect(Collectors.toList()));
|
||||
}
|
||||
|
||||
return workPaperIndex.toString();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,277 @@
|
||||
package com.gxwebsoft.ai.controller;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.gxwebsoft.ai.dto.AuditContentRequest;
|
||||
import com.gxwebsoft.ai.entity.AiCloudDoc;
|
||||
import com.gxwebsoft.ai.entity.AiCloudFile;
|
||||
import com.gxwebsoft.ai.service.AiHistoryService;
|
||||
import com.gxwebsoft.ai.utils.ExcelExportTool;
|
||||
import com.gxwebsoft.common.core.web.ApiResult;
|
||||
import com.gxwebsoft.common.core.web.BaseController;
|
||||
import com.gxwebsoft.common.system.entity.User;
|
||||
import com.gxwebsoft.pwl.entity.PwlProjectLibrary;
|
||||
import com.gxwebsoft.pwl.service.PwlProjectLibraryService;
|
||||
import com.gxwebsoft.ai.service.AiCloudDocService;
|
||||
import com.gxwebsoft.ai.service.AiCloudFileService;
|
||||
import com.gxwebsoft.ai.service.KnowledgeBaseService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.crypto.digest.DigestUtil;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.util.*;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 审计内容基础控制器
|
||||
*/
|
||||
@Slf4j
|
||||
public abstract class BaseAuditContentController extends BaseController {
|
||||
|
||||
@Autowired
|
||||
protected AiCloudDocService aiCloudDocService;
|
||||
|
||||
@Autowired
|
||||
protected AiCloudFileService aiCloudFileService;
|
||||
|
||||
@Autowired
|
||||
protected KnowledgeBaseService knowledgeBaseService;
|
||||
|
||||
@Autowired
|
||||
protected PwlProjectLibraryService pwlProjectLibraryService;
|
||||
|
||||
@Autowired
|
||||
protected AiHistoryService aiHistoryService;
|
||||
|
||||
// 历史记录有效期(分钟)
|
||||
protected static final int HISTORY_EXPIRE_MINUTES = 10;
|
||||
|
||||
/**
|
||||
* 通用的表格数据生成方法
|
||||
*/
|
||||
protected ApiResult<?> generateTableData(AuditContentRequest request, String interfaceName, Function<GenerateParams, JSONObject> generateFunction) {
|
||||
final User loginUser = getLoginUser();
|
||||
String requestHistory = request.getHistory();
|
||||
request.setHistory("");
|
||||
|
||||
// 检查历史记录
|
||||
String requestHash = generateRequestHash(request, interfaceName);
|
||||
var history = aiHistoryService.getValidHistory(requestHash, interfaceName, HISTORY_EXPIRE_MINUTES);
|
||||
if (history != null) {
|
||||
log.info("返回历史数据,请求哈希: {}", requestHash);
|
||||
return success(JSONObject.parseObject(history.getResponseData()));
|
||||
}
|
||||
request.setHistory(requestHistory);
|
||||
|
||||
String kbIdTmp = "";
|
||||
String libraryKbIds = "";
|
||||
|
||||
try {
|
||||
// 创建临时知识库(如果需要)
|
||||
if (hasUploadedFiles(request)) {
|
||||
kbIdTmp = createTempKnowledgeBase(request);
|
||||
}
|
||||
|
||||
// 查询项目库信息
|
||||
libraryKbIds = getLibraryKbIds(request.getLibraryIds());
|
||||
|
||||
// 生成数据
|
||||
String knowledgeBaseId = getKnowledgeBaseId(kbIdTmp, request.getKbIds());
|
||||
GenerateParams params = new GenerateParams(knowledgeBaseId, libraryKbIds, request.getProjectLibrary(), loginUser.getUsername(), request.getHistory(), request.getSuggestion());
|
||||
|
||||
JSONObject result = generateFunction.apply(params);
|
||||
|
||||
if(result.getBoolean("success")) {
|
||||
// 保存到历史记录
|
||||
saveToHistory(request, interfaceName, requestHash, result, loginUser);
|
||||
}
|
||||
|
||||
return success(result);
|
||||
} catch (Exception e) {
|
||||
log.error("生成表格数据失败,接口: {}", interfaceName, e);
|
||||
return fail("生成表格数据失败: " + e.getMessage());
|
||||
} finally {
|
||||
cleanupTempKnowledgeBase(kbIdTmp);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成请求哈希
|
||||
*/
|
||||
protected String generateRequestHash(AuditContentRequest request, String interfaceName) {
|
||||
String requestJson = JSONObject.toJSONString(request);
|
||||
return DigestUtil.md5Hex(interfaceName + ":" + requestJson);
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存到历史记录
|
||||
*/
|
||||
protected void saveToHistory(AuditContentRequest request, String interfaceName, String requestHash, JSONObject result, User loginUser) {
|
||||
try {
|
||||
aiHistoryService.saveHistory(request.getProjectId(), requestHash, interfaceName, JSONObject.toJSONString(request), result.toJSONString(), loginUser.getUserId(), loginUser.getUsername(), loginUser.getTenantId());
|
||||
} catch (Exception e) {
|
||||
log.warn("保存历史记录失败", e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查是否有上传的文件
|
||||
*/
|
||||
protected boolean hasUploadedFiles(AuditContentRequest request) {
|
||||
return !request.getDocList().isEmpty() || !request.getFileList().isEmpty();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取知识库ID
|
||||
*/
|
||||
protected String getKnowledgeBaseId(String tempKbId, String requestKbIds) {
|
||||
return StrUtil.isNotBlank(tempKbId) ? tempKbId : requestKbIds;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取项目库KB IDs
|
||||
*/
|
||||
protected String getLibraryKbIds(String libraryIds) {
|
||||
if (StrUtil.isBlank(libraryIds)) {
|
||||
return "";
|
||||
}
|
||||
List<String> idList = StrUtil.split(libraryIds, ',');
|
||||
List<PwlProjectLibrary> ret = pwlProjectLibraryService.list(new LambdaQueryWrapper<PwlProjectLibrary>().in(PwlProjectLibrary::getId, idList));
|
||||
return ret.stream().map(PwlProjectLibrary::getKbId).filter(StrUtil::isNotBlank).collect(Collectors.joining(","));
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建临时知识库并提交文档
|
||||
*/
|
||||
protected String createTempKnowledgeBase(AuditContentRequest request) {
|
||||
String kbIdTmp = knowledgeBaseService.createKnowledgeBaseTemp();
|
||||
// 收集文档ID
|
||||
Set<Integer> docIds = request.getDocList().stream().flatMap(docId -> aiCloudDocService.getSelfAndChildren(docId).stream()).map(AiCloudDoc::getId).collect(Collectors.toSet());
|
||||
// 查询相关文件
|
||||
List<AiCloudFile> fileList = getRelatedFiles(docIds, request.getFileList());
|
||||
// 提取文件ID并提交到知识库
|
||||
Set<String> kbFileIds = fileList.stream().map(AiCloudFile::getFileId).collect(Collectors.toSet());
|
||||
if (!kbFileIds.isEmpty()) {
|
||||
knowledgeBaseService.submitDocuments(kbIdTmp, new ArrayList<>(kbFileIds));
|
||||
}
|
||||
return kbIdTmp;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取相关文件列表
|
||||
*/
|
||||
protected List<AiCloudFile> getRelatedFiles(Set<Integer> docIds, List<Integer> fileList) {
|
||||
LambdaQueryWrapper<AiCloudFile> queryWrapper = new LambdaQueryWrapper<AiCloudFile>()
|
||||
.in(!docIds.isEmpty(), AiCloudFile::getDocId, docIds)
|
||||
.or(!fileList.isEmpty())
|
||||
.in(!fileList.isEmpty(), AiCloudFile::getId, fileList);
|
||||
return aiCloudFileService.list(queryWrapper);
|
||||
}
|
||||
|
||||
/**
|
||||
* 清理临时知识库
|
||||
*/
|
||||
protected void cleanupTempKnowledgeBase(String kbId) {
|
||||
if (StrUtil.isNotBlank(kbId)) {
|
||||
try {
|
||||
knowledgeBaseService.deleteIndex(kbId);
|
||||
} catch (Exception e) {
|
||||
log.warn("删除临时知识库失败: {}", kbId, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 通用的Excel导出方法
|
||||
*/
|
||||
protected <T> void exportToExcel(Map<String, Object> request, HttpServletResponse response,
|
||||
String sheetName, Function<List<Map<String, Object>>, List<T>> converter,
|
||||
Class<T> entityClass) {
|
||||
List<Map<String, Object>> dataList = (List<Map<String, Object>>) request.get("data");
|
||||
String companyName = (String) request.get("companyName");
|
||||
|
||||
List<T> exportData = converter.apply(dataList);
|
||||
|
||||
String fileName = sheetName + "_" + (companyName != null ? companyName : "未知公司");
|
||||
String title = companyName != null ? companyName + " - " + sheetName : sheetName;
|
||||
|
||||
ExcelExportTool.exportExcel(exportData, entityClass, fileName, sheetName, title, response);
|
||||
}
|
||||
|
||||
/**
|
||||
* 带审计时间的Excel导出方法
|
||||
*/
|
||||
protected <T> void exportToExcelWithAuditTime(Map<String, Object> request, HttpServletResponse response,
|
||||
String sheetName, Function<List<Map<String, Object>>, List<T>> converter,
|
||||
Class<T> entityClass) {
|
||||
List<Map<String, Object>> dataList = (List<Map<String, Object>>) request.get("data");
|
||||
String companyName = (String) request.get("companyName");
|
||||
String auditTime = (String) request.get("auditTime");
|
||||
|
||||
List<T> exportData = converter.apply(dataList);
|
||||
|
||||
String fileName = sheetName + "_" + (companyName != null ? companyName : "未知公司");
|
||||
String title = companyName != null ? companyName + " - " + sheetName : sheetName;
|
||||
|
||||
if (auditTime != null) {
|
||||
title += "(审计时间:" + auditTime + ")";
|
||||
}
|
||||
|
||||
ExcelExportTool.exportExcel(exportData, entityClass, fileName, sheetName, title, response);
|
||||
}
|
||||
|
||||
/**
|
||||
* 参数包装类
|
||||
*/
|
||||
protected static class GenerateParams {
|
||||
public final String knowledgeBaseId;
|
||||
public final String libraryKbIds;
|
||||
public final String projectLibrary;
|
||||
public final String username;
|
||||
public final String history;
|
||||
public final String suggestion;
|
||||
|
||||
public GenerateParams(String knowledgeBaseId, String libraryKbIds, String projectLibrary, String username, String history, String suggestion) {
|
||||
this.knowledgeBaseId = knowledgeBaseId;
|
||||
this.libraryKbIds = libraryKbIds;
|
||||
this.projectLibrary = projectLibrary;
|
||||
this.username = username;
|
||||
this.history = history;
|
||||
this.suggestion = suggestion;
|
||||
}
|
||||
}
|
||||
|
||||
// ========== 通用的工具方法 ==========
|
||||
|
||||
/**
|
||||
* 获取字符串值
|
||||
*/
|
||||
protected String getStringValue(Map<String, Object> map, String key) {
|
||||
Object value = map.get(key);
|
||||
return value != null ? value.toString() : "";
|
||||
}
|
||||
|
||||
/**
|
||||
* 格式化底稿索引
|
||||
*/
|
||||
protected String formatWorkPaperIndex(Object workPaperIndex) {
|
||||
if (workPaperIndex == null) {
|
||||
return "";
|
||||
}
|
||||
|
||||
if (workPaperIndex instanceof List) {
|
||||
List<?> list = (List<?>) workPaperIndex;
|
||||
return String.join(", ", list.stream()
|
||||
.map(Object::toString)
|
||||
.collect(Collectors.toList()));
|
||||
}
|
||||
|
||||
return workPaperIndex.toString();
|
||||
}
|
||||
}
|
||||
@@ -10,6 +10,11 @@ import lombok.Data;
|
||||
@Data
|
||||
public class AuditContentRequest {
|
||||
|
||||
/**
|
||||
* 项目ID
|
||||
*/
|
||||
private Long projectId;
|
||||
|
||||
/**
|
||||
* 企业库
|
||||
*/
|
||||
|
||||
@@ -24,6 +24,9 @@ public class AiHistory implements Serializable {
|
||||
@TableId(value = "id", type = IdType.AUTO)
|
||||
private Long id;
|
||||
|
||||
@Schema(description = "项目ID")
|
||||
private Long projectId;
|
||||
|
||||
@Schema(description = "请求哈希值")
|
||||
private String requestHash;
|
||||
|
||||
|
||||
@@ -10,6 +10,9 @@
|
||||
<if test="param.id != null">
|
||||
AND a.id = #{param.id}
|
||||
</if>
|
||||
<if test="param.projectId != null">
|
||||
AND a.project_id = #{param.projectId}
|
||||
</if>
|
||||
<if test="param.requestHash != null">
|
||||
AND a.request_hash = #{param.requestHash}
|
||||
</if>
|
||||
|
||||
@@ -24,6 +24,10 @@ public class AiHistoryParam extends BaseParam {
|
||||
@QueryField(type = QueryType.EQ)
|
||||
private Long id;
|
||||
|
||||
@Schema(description = "项目ID")
|
||||
@QueryField(type = QueryType.EQ)
|
||||
private Long projectId;
|
||||
|
||||
@Schema(description = "请求哈希值")
|
||||
@QueryField(type = QueryType.EQ)
|
||||
private String requestHash;
|
||||
|
||||
@@ -51,6 +51,7 @@ public interface AiHistoryService extends IService<AiHistory> {
|
||||
/**
|
||||
* 保存历史记录
|
||||
*
|
||||
* @param projectId 项目ID
|
||||
* @param requestHash 请求哈希值
|
||||
* @param interfaceName 接口名称
|
||||
* @param requestData 请求数据
|
||||
@@ -58,5 +59,5 @@ public interface AiHistoryService extends IService<AiHistory> {
|
||||
* @param userId 用户ID
|
||||
* @param username 用户名
|
||||
*/
|
||||
void saveHistory(String requestHash, String interfaceName, String requestData, String responseData, Integer userId, String username, Integer tenantId);
|
||||
void saveHistory(Long projectId, String requestHash, String interfaceName, String requestData, String responseData, Integer userId, String username, Integer tenantId);
|
||||
}
|
||||
@@ -57,8 +57,9 @@ public class AiHistoryServiceImpl extends ServiceImpl<AiHistoryMapper, AiHistory
|
||||
}
|
||||
|
||||
@Override
|
||||
public void saveHistory(String requestHash, String interfaceName, String requestData, String responseData, Integer userId, String username, Integer tenantId) {
|
||||
public void saveHistory(Long projectId, String requestHash, String interfaceName, String requestData, String responseData, Integer userId, String username, Integer tenantId) {
|
||||
AiHistory history = new AiHistory();
|
||||
history.setProjectId(projectId);
|
||||
history.setRequestHash(requestHash);
|
||||
history.setInterfaceName(interfaceName);
|
||||
history.setRequestData(requestData);
|
||||
|
||||
Reference in New Issue
Block a user