293 lines
12 KiB
Java
293 lines
12 KiB
Java
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.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.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 javax.servlet.http.HttpServletResponse;
|
|
import java.util.*;
|
|
import java.util.stream.Collectors;
|
|
|
|
/**
|
|
* 审计内容3控制器 - 三重一大制度对比分析 & 重大经济决策调查表
|
|
*/
|
|
@Slf4j
|
|
@Tag(name = "审计内容3-三重一大制度")
|
|
@RestController
|
|
@RequestMapping("/api/ai/auditContent3")
|
|
public class AuditContent3Controller extends BaseController {
|
|
|
|
@Autowired
|
|
private AuditContent3TripleService auditContent3TripleService;
|
|
|
|
@Autowired
|
|
private AuditContent3DecisionService auditContent3DecisionService;
|
|
|
|
@Autowired
|
|
private AiCloudDocService aiCloudDocService;
|
|
|
|
@Autowired
|
|
private AiCloudFileService aiCloudFileService;
|
|
|
|
@Autowired
|
|
private KnowledgeBaseService knowledgeBaseService;
|
|
|
|
@Autowired
|
|
private PwlProjectLibraryService pwlProjectLibraryService;
|
|
|
|
/**
|
|
* 生成三重一大制度对比分析表数据
|
|
*/
|
|
@Operation(summary = "生成三重一大制度对比分析表")
|
|
@PostMapping("/generateTripleOneTable")
|
|
public ApiResult<?> generateTripleOneTable(@RequestBody AuditContentRequest request) {
|
|
final User loginUser = getLoginUser();
|
|
String kbIdTmp = "";
|
|
String libraryKbIds = "";
|
|
|
|
try {
|
|
// 创建临时知识库(如果需要)
|
|
if (!request.getDocList().isEmpty() || !request.getFileList().isEmpty()) {
|
|
kbIdTmp = createTempKnowledgeBase(request);
|
|
}
|
|
|
|
// 提前查询项目库信息
|
|
if (StrUtil.isNotBlank(request.getLibraryIds())) {
|
|
List<String> idList = StrUtil.split(request.getLibraryIds(), ',');
|
|
List<PwlProjectLibrary> ret = pwlProjectLibraryService.list(
|
|
new LambdaQueryWrapper<PwlProjectLibrary>().in(PwlProjectLibrary::getId, idList));
|
|
libraryKbIds = ret.stream().map(PwlProjectLibrary::getKbId).collect(Collectors.joining(","));
|
|
}
|
|
|
|
// 生成三重一大制度对比分析表数据
|
|
String knowledgeBaseId = StrUtil.isNotBlank(kbIdTmp) ? kbIdTmp : request.getKbIds();
|
|
JSONObject result = auditContent3TripleService.generateTripleOneTableData(
|
|
knowledgeBaseId,
|
|
libraryKbIds,
|
|
request.getProjectLibrary(),
|
|
loginUser.getUsername(),
|
|
request.getHistory(),
|
|
request.getSuggestion()
|
|
);
|
|
|
|
return success(result);
|
|
} catch (Exception e) {
|
|
log.error("生成三重一大制度对比分析表失败", e);
|
|
return fail("生成三重一大制度对比分析表失败: " + e.getMessage());
|
|
} finally {
|
|
cleanupTempKnowledgeBase(kbIdTmp);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 生成重大经济决策调查表数据
|
|
*/
|
|
@Operation(summary = "生成重大经济决策调查表")
|
|
@PostMapping("/generateDecisionTable")
|
|
public ApiResult<?> generateDecisionTable(@RequestBody AuditContentRequest request) {
|
|
final User loginUser = getLoginUser();
|
|
String kbIdTmp = "";
|
|
|
|
try {
|
|
// 创建临时知识库(如果需要)
|
|
if (!request.getDocList().isEmpty() || !request.getFileList().isEmpty()) {
|
|
kbIdTmp = createTempKnowledgeBase(request);
|
|
}
|
|
|
|
// 生成重大经济决策调查表数据
|
|
String knowledgeBaseId = StrUtil.isNotBlank(kbIdTmp) ? kbIdTmp : request.getKbIds();
|
|
JSONObject result = auditContent3DecisionService.generateDecisionTableData(
|
|
knowledgeBaseId,
|
|
request.getLibraryIds(),
|
|
request.getProjectLibrary(),
|
|
loginUser.getUsername(),
|
|
request.getHistory(),
|
|
request.getSuggestion(),
|
|
request.getData()
|
|
);
|
|
|
|
return success(result);
|
|
} catch (Exception e) {
|
|
log.error("生成重大经济决策调查表失败", e);
|
|
return fail("生成重大经济决策调查表失败: " + e.getMessage());
|
|
} finally {
|
|
cleanupTempKnowledgeBase(kbIdTmp);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 创建临时知识库并提交文档
|
|
*/
|
|
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());
|
|
|
|
// 查询相关文件
|
|
LambdaQueryWrapper<AiCloudFile> queryWrapper = new LambdaQueryWrapper<AiCloudFile>()
|
|
.in(!docIds.isEmpty(), AiCloudFile::getDocId, docIds)
|
|
.or(!request.getFileList().isEmpty())
|
|
.in(!request.getFileList().isEmpty(), AiCloudFile::getId, request.getFileList());
|
|
|
|
List<AiCloudFile> fileList = aiCloudFileService.list(queryWrapper);
|
|
|
|
// 提取文件ID并提交到知识库
|
|
Set<String> kbFileIds = fileList.stream()
|
|
.map(AiCloudFile::getFileId)
|
|
.collect(Collectors.toSet());
|
|
|
|
if (!kbFileIds.isEmpty()) {
|
|
knowledgeBaseService.submitDocuments(kbIdTmp, new ArrayList<>(kbFileIds));
|
|
}
|
|
|
|
return kbIdTmp;
|
|
}
|
|
|
|
/**
|
|
* 清理临时知识库
|
|
*/
|
|
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("/exportTripleOneTable")
|
|
public void exportTripleOneTable(@RequestBody 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<TripleOneExportEntity> exportData = convertToTripleOneEntityList(dataList);
|
|
|
|
// 使用工具类导出
|
|
String fileName = "三重一大制度对比分析表_" + (companyName != null ? companyName : "未知公司");
|
|
String title = companyName != null ? companyName + " - 三重一大制度对比分析表" : "三重一大制度对比分析表";
|
|
|
|
ExcelExportTool.exportExcel(exportData, TripleOneExportEntity.class, fileName, "三重一大制度对比分析表", title, response);
|
|
}
|
|
|
|
/**
|
|
* 导出重大经济决策调查表到Excel
|
|
*/
|
|
@Operation(summary = "导出重大经济决策调查表到Excel")
|
|
@PostMapping("/exportDecisionTable")
|
|
public void exportDecisionTable(@RequestBody 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<DecisionTableExportEntity> exportData = convertToDecisionTableEntityList(dataList);
|
|
|
|
// 使用工具类导出
|
|
String fileName = "重大经济决策调查表_" + (companyName != null ? companyName : "未知公司");
|
|
String title = companyName != null ? companyName + " - 重大经济决策调查表" : "重大经济决策调查表";
|
|
|
|
ExcelExportTool.exportExcel(exportData, DecisionTableExportEntity.class, fileName, "重大经济决策调查表", title, response);
|
|
}
|
|
|
|
/**
|
|
* 转换为三重一大实体列表
|
|
*/
|
|
private List<TripleOneExportEntity> convertToTripleOneEntityList(List<Map<String, Object>> originalData) {
|
|
return originalData.stream().map(this::convertToTripleOneEntity).collect(Collectors.toList());
|
|
}
|
|
|
|
/**
|
|
* 转换为重大经济决策调查表实体列表
|
|
*/
|
|
private List<DecisionTableExportEntity> convertToDecisionTableEntityList(List<Map<String, Object>> originalData) {
|
|
return originalData.stream().map(this::convertToDecisionTableEntity).collect(Collectors.toList());
|
|
}
|
|
|
|
/**
|
|
* 单个Map转换为三重一大实体
|
|
*/
|
|
private TripleOneExportEntity convertToTripleOneEntity(Map<String, Object> item) {
|
|
TripleOneExportEntity entity = new TripleOneExportEntity();
|
|
entity.setCategory(getStringValue(item, "category"));
|
|
entity.setPolicyContent(getStringValue(item, "policyContent"));
|
|
entity.setGroupSystem(getStringValue(item, "groupSystem"));
|
|
entity.setCompanyFormulation(getStringValue(item, "companyFormulation"));
|
|
entity.setCheckEvidence(getStringValue(item, "checkEvidence"));
|
|
entity.setTestResult(getStringValue(item, "testResult"));
|
|
entity.setWorkPaperIndex(formatWorkPaperIndex(item.get("workPaperIndex")));
|
|
return entity;
|
|
}
|
|
|
|
/**
|
|
* 单个Map转换为重大经济决策调查表实体
|
|
*/
|
|
private DecisionTableExportEntity convertToDecisionTableEntity(Map<String, Object> item) {
|
|
DecisionTableExportEntity entity = new DecisionTableExportEntity();
|
|
entity.setIndex(getStringValue(item, "index"));
|
|
entity.setDecisionItem(getStringValue(item, "name"));
|
|
entity.setMeetingTime(getStringValue(item, "meetingTime"));
|
|
entity.setDecisionAmount(getStringValue(item, "decisionAmount"));
|
|
entity.setProcedure(getStringValue(item, "procedure"));
|
|
entity.setExecutionStatus(getStringValue(item, "executionStatus"));
|
|
entity.setGood(getStringValue(item, "goods"));
|
|
entity.setNormal(getStringValue(item, "normal"));
|
|
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();
|
|
}
|
|
} |