|
|
@@ -8,6 +8,8 @@ import com.takai.ai.domain.dto.*;
|
|
|
import com.takai.ai.domain.entity.*;
|
|
|
import com.takai.ai.mapper.*;
|
|
|
import com.takai.ai.service.ITakaiAiService;
|
|
|
+import com.takai.ai.utils.ApprovalFlowManager;
|
|
|
+import com.takai.ai.utils.ApprovalNode;
|
|
|
import com.takai.ai.utils.MinioUtil;
|
|
|
import com.takai.ai.utils.SnowflakeDigitGenerator;
|
|
|
import com.takai.common.annotation.DataSource;
|
|
|
@@ -17,6 +19,14 @@ import com.takai.common.core.redis.RedisCache;
|
|
|
import com.takai.common.enums.DataSourceType;
|
|
|
import com.takai.common.utils.StringUtils;
|
|
|
import com.takai.common.utils.uuid.IdUtils;
|
|
|
+import com.takai.framework.web.service.SysPermissionService;
|
|
|
+import com.takai.system.domain.DocumentAuditConfig;
|
|
|
+import com.takai.system.domain.DocumentAuditInfo;
|
|
|
+import com.takai.system.domain.TypeApp;
|
|
|
+import com.takai.system.mapper.SysDictDataMapper;
|
|
|
+import com.takai.system.mapper.TypeAppMapper;
|
|
|
+import com.takai.system.mapper.DocumentAuditConfigMapper;
|
|
|
+import com.takai.system.mapper.DocumentAuditInfoMapper;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import okhttp3.*;
|
|
|
import okhttp3.sse.EventSource;
|
|
|
@@ -24,13 +34,11 @@ import okhttp3.sse.EventSourceListener;
|
|
|
import okhttp3.sse.EventSources;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
-import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.data.redis.core.RedisTemplate;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
import org.springframework.web.servlet.mvc.method.annotation.SseEmitter;
|
|
|
-
|
|
|
import javax.validation.constraints.NotNull;
|
|
|
import java.io.IOException;
|
|
|
import java.time.LocalDate;
|
|
|
@@ -38,6 +46,7 @@ import java.time.LocalDateTime;
|
|
|
import java.time.temporal.ChronoUnit;
|
|
|
import java.util.*;
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
+import java.util.function.Function;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
@@ -95,6 +104,24 @@ public class TakaiAiServiceImpl implements ITakaiAiService {
|
|
|
@Autowired
|
|
|
private TakaiSliceInfoMapper takaiSliceInfoMapper;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private DocumentAuditConfigMapper documentAuditConfigMapper;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private DocumentAuditInfoMapper documentAuditInfoMapper;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private SysPermissionService permissionService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private TypeAppMapper appTypeMapper;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private TakaiAppCollectMapper appCollectMapper;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private SysDictDataMapper sysDictDataMapper;
|
|
|
+
|
|
|
public static final String START_SIGN = "【";
|
|
|
public static final String END_SIGN = "】";
|
|
|
public static final String SYMBOL = "【示意图序号";
|
|
|
@@ -621,7 +648,6 @@ public class TakaiAiServiceImpl implements ITakaiAiService {
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
|
-
|
|
|
@Override
|
|
|
public int updateDocument(TakaiDocumentParams documentParams, String documentId) {
|
|
|
int i = takaiDocumentMapper.updateDocument(TakaiDocument.builder()
|
|
|
@@ -710,7 +736,6 @@ public class TakaiAiServiceImpl implements ITakaiAiService {
|
|
|
public int createApplication(TakaiApplicationParams params) {
|
|
|
SnowflakeDigitGenerator snowflakeDigitGenerator = new SnowflakeDigitGenerator(1, 1);
|
|
|
long appId = snowflakeDigitGenerator.nextId();
|
|
|
-
|
|
|
TakaiApplication info = TakaiApplication.builder().appId(String.valueOf(appId))
|
|
|
.name(params.getName())
|
|
|
.desc(params.getDesc())
|
|
|
@@ -723,9 +748,17 @@ public class TakaiAiServiceImpl implements ITakaiAiService {
|
|
|
.knowledgeInfo(params.getKnowledge_info())
|
|
|
.sliceCount(params.getSlice_count())
|
|
|
.typeId(params.getTypeId())
|
|
|
+ .status("5") // 未开始审核状态
|
|
|
+ .approver(params.getApprover())
|
|
|
.build();
|
|
|
+ info.setCreateBy(params.getUserId());
|
|
|
int i = takaiApplicationMapper.insertApplication(info);
|
|
|
if (i > 0) {
|
|
|
+ TypeApp appType = new TypeApp();
|
|
|
+ appType.setTypeId(params.getTypeId());
|
|
|
+ appType.setAppId(String.valueOf(appId));
|
|
|
+ appTypeMapper.insertAppType(appType);
|
|
|
+
|
|
|
logger.info("create application success, id:{}, name:{}", appId, params.getName());
|
|
|
TakaiAppInfo appInfo = new TakaiAppInfo();
|
|
|
appInfo.setAppId(String.valueOf(appId));
|
|
|
@@ -760,6 +793,10 @@ public class TakaiAiServiceImpl implements ITakaiAiService {
|
|
|
.knowledgeInfo(params.getKnowledge_info())
|
|
|
.sliceCount(params.getSlice_count())
|
|
|
.typeId(params.getTypeId())
|
|
|
+ .status("5") // 未开始审核状态
|
|
|
+ .approver(params.getApprover())
|
|
|
+ .comment(null)
|
|
|
+ .nodeOrder(null)
|
|
|
.build();
|
|
|
int i = takaiApplicationMapper.updateApplication(info);
|
|
|
if (1 > 0) {
|
|
|
@@ -785,8 +822,8 @@ public class TakaiAiServiceImpl implements ITakaiAiService {
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public List<TakaiApplication> getApplicationList() {
|
|
|
- return takaiApplicationMapper.selectApplicationList(null);
|
|
|
+ public List<TakaiApplicationResult> getApplicationList(TakaiApplication params) {
|
|
|
+ return takaiApplicationMapper.selectApplicationList(params);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
@@ -1046,24 +1083,50 @@ public class TakaiAiServiceImpl implements ITakaiAiService {
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public List<Object> searchAppTypeGroupList(List<SysDictData> dictDataList) {
|
|
|
+ public List<Object> searchAppTypeGroupList(List<SysDictData> dictDataList, String userId) {
|
|
|
List<Object> result = new ArrayList();
|
|
|
if (dictDataList!= null && dictDataList.size() > 0) {
|
|
|
for (SysDictData dictData : dictDataList){
|
|
|
Map<String, Object> map = new HashMap();
|
|
|
- List<TakaiApplication> list = takaiApplicationMapper.selectApplicationList(TakaiApplication.builder().typeId(dictData.getDictCode()).build());
|
|
|
+ List<TakaiApplicationResult> list = takaiApplicationMapper.selectApplicationList(TakaiApplication.builder().approver(userId).flag("0").typeId(dictData.getDictCode()).build());
|
|
|
if(list!= null && list.size() > 0){
|
|
|
- map.put("title", dictData.getDictLabel());
|
|
|
- List<Object> appInfoList = new ArrayList();
|
|
|
- for (TakaiApplication application : list){
|
|
|
- Map<String, Object> infoMap = new HashMap();
|
|
|
- infoMap.put("title", application.getName());
|
|
|
- infoMap.put("appId", application.getAppId());
|
|
|
- infoMap.put("showMenu", "false");
|
|
|
- infoMap.put("chatMode", "LOCAL");
|
|
|
- appInfoList.add(infoMap);
|
|
|
+ if(dictData.getDictCode() == 41){ // 项目级应用
|
|
|
+ List<Object> l = new ArrayList<>();
|
|
|
+ map.put("title", dictData.getDictLabel());
|
|
|
+ for (TakaiApplicationResult application : list){
|
|
|
+ Map<String, Object> infoProjectMap = new HashMap();
|
|
|
+ List<TakaiApplicationResult> projectList = takaiApplicationMapper.selectApplicationListByProjectType(application.getAppId());
|
|
|
+ if(projectList != null && projectList.size() > 0){
|
|
|
+ List<TakaiApplicationResult> uniqueAppList = projectList.stream().collect(Collectors.collectingAndThen(Collectors.toCollection(() -> new TreeSet<>(Comparator.comparing(TakaiApplicationResult :: getAppId))), ArrayList::new)); // 去重
|
|
|
+ List<Object> projectInfoList = new ArrayList();
|
|
|
+ for (TakaiApplicationResult project : uniqueAppList){
|
|
|
+ SysDictData vo = sysDictDataMapper.selectDictDataById(Long.valueOf(project.getTypeId()));
|
|
|
+ infoProjectMap.put("title", vo.getDictLabel());
|
|
|
+ Map<String, Object> projectMap = new HashMap();
|
|
|
+ projectMap.put("appId", project.getAppId());
|
|
|
+ projectMap.put("showMenu", "false");
|
|
|
+ projectMap.put("chatMode", "LOCAL");
|
|
|
+ projectMap.put("title", vo.getDictLabel());
|
|
|
+ projectInfoList.add(projectMap);
|
|
|
+ }
|
|
|
+ infoProjectMap.put("children", projectInfoList);
|
|
|
+ l.add(infoProjectMap);
|
|
|
+ }
|
|
|
+ map.put("children", l);
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ List<Object> appInfoList = new ArrayList();
|
|
|
+ map.put("title", dictData.getDictLabel());
|
|
|
+ for (TakaiApplicationResult application : list){
|
|
|
+ Map<String, Object> infoMap = new HashMap();
|
|
|
+ infoMap.put("title", application.getName());
|
|
|
+ infoMap.put("appId", application.getAppId());
|
|
|
+ infoMap.put("showMenu", "false");
|
|
|
+ infoMap.put("chatMode", "LOCAL");
|
|
|
+ appInfoList.add(infoMap);
|
|
|
+ }
|
|
|
+ map.put("children", appInfoList);
|
|
|
}
|
|
|
- map.put("children", appInfoList);
|
|
|
result.add(map);
|
|
|
}
|
|
|
}
|
|
|
@@ -1071,6 +1134,146 @@ public class TakaiAiServiceImpl implements ITakaiAiService {
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public List<TakaiApplication> applicationListByApprover(TakaiApplicationParams takaiApplicationParams) {
|
|
|
+ TakaiApplication vo = TakaiApplication.builder().approver(takaiApplicationParams.getApprover())
|
|
|
+ .build();
|
|
|
+ return takaiApplicationMapper.selectAppListByApprover(vo);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public int startAudit(String appId, String userId) {
|
|
|
+ List<DocumentAuditConfig> list = documentAuditConfigMapper.selectDocumentAuditConfigListByBo(null);
|
|
|
+ if(list != null && list.size() > 0) {
|
|
|
+ ApprovalFlowManager flowManager = new ApprovalFlowManager();
|
|
|
+ logger.info("开启审核");
|
|
|
+ for (DocumentAuditConfig config : list) {
|
|
|
+ // 添加审核节点
|
|
|
+ flowManager.addNode(new ApprovalNode(config.getId(), config.getNodeOrder(), Long.valueOf(config.getApprover()), config.getChain()));
|
|
|
+ }
|
|
|
+
|
|
|
+ ApprovalNode vo = flowManager.getFirstApprover();
|
|
|
+ int i = takaiApplicationMapper.updateApplication(TakaiApplication.builder()
|
|
|
+ .appId(appId)
|
|
|
+ .approver(String.valueOf(vo.getApprover()))
|
|
|
+ .nodeOrder(String.valueOf(vo.getNodeOrder()))
|
|
|
+ .status("1") // 待审核
|
|
|
+ .build());
|
|
|
+ if(i > 0){
|
|
|
+ DocumentAuditInfo info = new DocumentAuditInfo();
|
|
|
+ info.setAppId(appId);
|
|
|
+ info.setApprover(userId);
|
|
|
+ info.setStatus("5");
|
|
|
+ info.setNodeOrder(Integer.valueOf("0"));
|
|
|
+ info.setCreateBy(userId);
|
|
|
+ info.setCreateTime(new Date());
|
|
|
+ documentAuditInfoMapper.insertDocumentAuditInfo(info); // 审核记录
|
|
|
+ }
|
|
|
+ return i;
|
|
|
+ }else{
|
|
|
+ return 9;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public int updateAuditApplication(TakaiApplicationParams appParams, String appId) {
|
|
|
+// 获取审核配置信息 (人员,节点)
|
|
|
+ List<DocumentAuditConfig> list = documentAuditConfigMapper.selectDocumentAuditConfigListByBo(null);
|
|
|
+ if(list != null && list.size() > 0){
|
|
|
+ if(("Y").equals(appParams.getStatus())){
|
|
|
+ ApprovalFlowManager flowManager = new ApprovalFlowManager();
|
|
|
+ logger.info("审核通过,开始审批流程");
|
|
|
+ for (DocumentAuditConfig config: list){
|
|
|
+ // 添加审核节点
|
|
|
+ flowManager.addNode(new ApprovalNode(config.getId(), config.getNodeOrder(), Long.valueOf(config.getApprover()), config.getChain()));
|
|
|
+ }
|
|
|
+ // 根据审核节点获取下一个审核节点
|
|
|
+ ApprovalNode nextNode = flowManager.getNextApproverByOrder(Integer.valueOf(appParams.getNodeOrder()));
|
|
|
+ if (nextNode == null) {
|
|
|
+ // 审核通过,更新文档状态
|
|
|
+ logger.info("审核通过,到最后节点");
|
|
|
+ return saveAuditInfo(appParams, "3", appId);
|
|
|
+ }else{
|
|
|
+ // 审核通过,下一个节点
|
|
|
+ int successI = takaiApplicationMapper.updateApplication(TakaiApplication.builder()
|
|
|
+ .appId(appId)
|
|
|
+ .status("2")
|
|
|
+ .approver(String.valueOf(nextNode.getApprover()))
|
|
|
+ .nodeOrder(String.valueOf(nextNode.getNodeOrder()))
|
|
|
+ .comment(appParams.getComment())
|
|
|
+ .build());
|
|
|
+ if(successI > 0){
|
|
|
+ DocumentAuditInfo info = new DocumentAuditInfo();
|
|
|
+ info.setAppId(appId);
|
|
|
+ info.setApprover(appParams.getApprover());
|
|
|
+ info.setComment(appParams.getComment());
|
|
|
+ info.setStatus("2");
|
|
|
+ info.setNodeOrder(Integer.valueOf(appParams.getNodeOrder()));
|
|
|
+ info.setCreateBy(appParams.getApprover());
|
|
|
+ info.setCreateTime(new Date());
|
|
|
+ documentAuditInfoMapper.insertDocumentAuditInfo(info); // 审核记录
|
|
|
+ }
|
|
|
+ return successI;
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ // 审核拒绝,更新文档状态
|
|
|
+ logger.info("审核拒绝,更新状态");
|
|
|
+ return saveAuditInfo(appParams, "5", appId);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ private int saveAuditInfo(TakaiApplicationParams appParams, String status, String appId){
|
|
|
+ int successI = takaiApplicationMapper.updateApplication(TakaiApplication.builder()
|
|
|
+ .appId(appId)
|
|
|
+ .status(status)
|
|
|
+ .approver(appParams.getApprover())
|
|
|
+ .nodeOrder(appParams.getNodeOrder())
|
|
|
+ .comment(appParams.getComment())
|
|
|
+ .build());
|
|
|
+ if(successI > 0){
|
|
|
+ DocumentAuditInfo info = new DocumentAuditInfo();
|
|
|
+ info.setAppId(appId);
|
|
|
+ info.setApprover(appParams.getApprover());
|
|
|
+ info.setComment(appParams.getComment());
|
|
|
+ if("5".equals(status)){
|
|
|
+ info.setStatus("4");
|
|
|
+ }else{
|
|
|
+ info.setStatus(status);
|
|
|
+ }
|
|
|
+ info.setNodeOrder(Integer.valueOf(appParams.getNodeOrder()));
|
|
|
+ info.setCreateBy(appParams.getApprover());
|
|
|
+ info.setCreateTime(new Date());
|
|
|
+ documentAuditInfoMapper.insertDocumentAuditInfo(info); // 审核记录
|
|
|
+ }
|
|
|
+ return successI;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<TakaiApplicationResult> selectAppByUserId(String userId) {
|
|
|
+ return takaiApplicationMapper.selectAppByUserId(userId);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<String> selectAppCollectList(String userId) {
|
|
|
+ return appCollectMapper.selectAppCollectList(userId);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public int insertAppCollect(AppCollect appCollect) {
|
|
|
+ AppCollect collect = appCollectMapper.selectAppCollectDetail(appCollect.getAppId(), appCollect.getUserId());
|
|
|
+ if (collect == null) {
|
|
|
+ return appCollectMapper.insertAppCollect(appCollect);
|
|
|
+ }
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public int deleteAppCollect(String userId, String appId) {
|
|
|
+ return appCollectMapper.delAppCollect(userId, appId);
|
|
|
+ }
|
|
|
+
|
|
|
private JSONObject analysisFile(List<UploadDocumentParams> result, TakaiDocumentSettings settings, String flag) {
|
|
|
String url = deepseekConfig.getBaseurl() + deepseekConfig.getUploadKnowledge();
|
|
|
JSONObject json = new JSONObject();
|