|
@@ -1,155 +1,155 @@
|
|
|
-/*
|
|
|
- * Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
|
|
|
- *
|
|
|
- * Redistribution and use in source and binary forms, with or without
|
|
|
- * modification, are permitted provided that the following conditions are met:
|
|
|
- *
|
|
|
- * Redistributions of source code must retain the above copyright notice,
|
|
|
- * this list of conditions and the following disclaimer.
|
|
|
- * Redistributions in binary form must reproduce the above copyright
|
|
|
- * notice, this list of conditions and the following disclaimer in the
|
|
|
- * documentation and/or other materials provided with the distribution.
|
|
|
- * Neither the name of the dreamlu.net developer nor the names of its
|
|
|
- * contributors may be used to endorse or promote products derived from
|
|
|
- * this software without specific prior written permission.
|
|
|
- * Author: Chill 庄骞 (smallchill@163.com)
|
|
|
- */
|
|
|
-package org.springblade.archive.service.impl;
|
|
|
-
|
|
|
-
|
|
|
-import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
-import org.apache.commons.lang.StringUtils;
|
|
|
-import org.springblade.archive.entity.ArchiveAiName;
|
|
|
-import org.springblade.archive.mapper.ArchiveAiNameMapper;
|
|
|
-import org.springblade.archive.service.IArchiveAiNameService;
|
|
|
-import org.springblade.archive.vo.ArchiveAiNameVO;
|
|
|
-import org.springblade.archive.vo.ArchiveAiNameVO1;
|
|
|
-import org.springblade.common.utils.DeepSeekClient;
|
|
|
-import org.springblade.core.mp.base.BaseServiceImpl;
|
|
|
-import org.springframework.beans.factory.annotation.Autowired;
|
|
|
-import org.springframework.jdbc.core.BeanPropertyRowMapper;
|
|
|
-import org.springframework.jdbc.core.JdbcTemplate;
|
|
|
-import org.springframework.scheduling.annotation.Async;
|
|
|
-import org.springframework.stereotype.Service;
|
|
|
-import org.springframework.transaction.annotation.Transactional;
|
|
|
-
|
|
|
-import javax.annotation.Resource;
|
|
|
-import java.text.SimpleDateFormat;
|
|
|
-import java.util.*;
|
|
|
-import java.util.concurrent.Semaphore;
|
|
|
-import java.util.concurrent.ThreadPoolExecutor;
|
|
|
-import java.util.stream.Collectors;
|
|
|
-
|
|
|
-import static java.util.stream.Collectors.groupingBy;
|
|
|
-
|
|
|
-/**
|
|
|
- * 服务实现类
|
|
|
- *
|
|
|
- * @author BladeX
|
|
|
- * @since 2025-07-03
|
|
|
- */
|
|
|
-@Service
|
|
|
-public class ArchiveAiNameServiceImpl extends BaseServiceImpl<ArchiveAiNameMapper, ArchiveAiName> implements IArchiveAiNameService {
|
|
|
-
|
|
|
- private static String DEEPSEEK_ARCHIVE_NAME = ".这是一段案卷题名,精简案卷题名重复啰嗦的内容,不要加以上内容没有的词语 返回值不要有任何多余得废话,只要结果";
|
|
|
- private static final int MAX_CONCURRENT_REQUESTS = 5;
|
|
|
-
|
|
|
- @Autowired
|
|
|
- private JdbcTemplate jdbcTemplate;
|
|
|
-
|
|
|
- @Autowired
|
|
|
- private DeepSeekClient deepSeekClient;
|
|
|
-
|
|
|
- @Resource(name = "taskExecutor1")
|
|
|
- private ThreadPoolExecutor executor;
|
|
|
-
|
|
|
- private final Semaphore apiSemaphore = new Semaphore(MAX_CONCURRENT_REQUESTS);
|
|
|
-
|
|
|
- @Override
|
|
|
- @Async("taskExecutor1")
|
|
|
- @Transactional
|
|
|
- public void syncCreatAiName(List<ArchiveAiName> aiNames) {
|
|
|
- aiNames.parallelStream().forEach(name -> {
|
|
|
- try {
|
|
|
- apiSemaphore.acquire();
|
|
|
- try {
|
|
|
- String content = deepSeekClient.getSimplifiedContent(name.getArchiveName() + DEEPSEEK_ARCHIVE_NAME);
|
|
|
- if (content.startsWith("API_ERROR:") ||
|
|
|
- content.startsWith("PARSE_ERROR:") ||
|
|
|
- content.startsWith("IO_ERROR:")||content.startsWith("Error:")) {
|
|
|
- name.setStatus(4);
|
|
|
- name.setArchiveNameAi("获取失败");
|
|
|
- } else {
|
|
|
- name.setArchiveNameAi(content);
|
|
|
- name.setStatus(2); // 标记为成功
|
|
|
- }
|
|
|
- } finally {
|
|
|
- apiSemaphore.release();
|
|
|
- }
|
|
|
- } catch (InterruptedException e) {
|
|
|
- Thread.currentThread().interrupt();
|
|
|
- name.setStatus(4); // 设置失败状态
|
|
|
- name.setArchiveNameAi("获取失败");
|
|
|
- } catch (Exception e) {
|
|
|
- name.setStatus(4); // 设置失败状态
|
|
|
- name.setArchiveNameAi("获取失败");
|
|
|
- }
|
|
|
- });
|
|
|
-
|
|
|
- // 分批更新数据库
|
|
|
- int batchSize = 100;
|
|
|
- for (int i = 0; i < aiNames.size(); i += batchSize) {
|
|
|
- int end = Math.min(i + batchSize, aiNames.size());
|
|
|
- List<ArchiveAiName> batch = aiNames.subList(i, end);
|
|
|
- this.updateBatchById(batch);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public List<ArchiveAiNameVO> getArchiveAiTask(Long projectId, Long contractId) {
|
|
|
- List<ArchiveAiNameVO>list=new ArrayList<>();
|
|
|
- List<ArchiveAiName> archiveAiNameList = this.baseMapper.selectList(new LambdaQueryWrapper<>(ArchiveAiName.class).eq(ArchiveAiName::getProjectId, projectId).eq(ArchiveAiName::getContractId, contractId));
|
|
|
- if(!archiveAiNameList.isEmpty()){
|
|
|
- Map<Long, List<ArchiveAiName>> map = archiveAiNameList.stream().collect(groupingBy(ArchiveAiName::getTaskId));
|
|
|
- for (Map.Entry<Long, List<ArchiveAiName>> entry : map.entrySet()) {
|
|
|
- ArchiveAiNameVO archiveAiNameVO = new ArchiveAiNameVO();
|
|
|
- List<ArchiveAiName> archiveAiNames = entry.getValue();
|
|
|
- archiveAiNameVO.setTaskId(entry.getKey());
|
|
|
- Date createTime = archiveAiNames.get(0).getCreateTime();
|
|
|
- SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
- String formattedDate = sdf.format(createTime);
|
|
|
- archiveAiNameVO.setTaskTime(formattedDate);
|
|
|
- archiveAiNameVO.setNum(archiveAiNames.size());
|
|
|
- archiveAiNameVO.setStatus(archiveAiNames.stream().allMatch(ai -> ai.getStatus() >1) ? 2:1);
|
|
|
- list.add(archiveAiNameVO);
|
|
|
- }
|
|
|
- }
|
|
|
- return list;
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- @Transactional
|
|
|
- public boolean confirmAiName(List<ArchiveAiNameVO1>vos) {
|
|
|
- for (ArchiveAiNameVO1 archiveAiName : vos) {
|
|
|
- if(archiveAiName.getStatus()==2&& StringUtils.isNotEmpty(archiveAiName.getArchiveNameAi())){
|
|
|
- archiveAiName.setStatus(3);
|
|
|
- String sql=" update u_archives_auto set name='"+archiveAiName.getArchiveNameAi()+"', colour_status=2 where id="+archiveAiName.getArchiveAutoId();
|
|
|
- jdbcTemplate.update(sql);
|
|
|
- String sql2="update u_archive_ai_name set status=3 where id="+archiveAiName.getId();
|
|
|
- jdbcTemplate.update(sql2);
|
|
|
- }
|
|
|
- }
|
|
|
- Long taskId = vos.get(0).getTaskId();
|
|
|
- String sql3="select * from u_archive_ai_name where task_id="+taskId+" and is_deleted=0";
|
|
|
- List<ArchiveAiName> list = jdbcTemplate.query(sql3, new BeanPropertyRowMapper<>(ArchiveAiName.class));
|
|
|
- if(list.stream().allMatch(item -> item.getStatus() >= 3)){
|
|
|
- deletedArchiveAiTask(taskId);
|
|
|
- };
|
|
|
- return true;
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public Boolean deletedArchiveAiTask(Long taskId) {
|
|
|
- return baseMapper.deletedArchiveAiTask(taskId);
|
|
|
- }
|
|
|
-}
|
|
|
+///*
|
|
|
+// * Copyright (c) 2018-2028, Chill Zhuang All rights reserved.
|
|
|
+// *
|
|
|
+// * Redistribution and use in source and binary forms, with or without
|
|
|
+// * modification, are permitted provided that the following conditions are met:
|
|
|
+// *
|
|
|
+// * Redistributions of source code must retain the above copyright notice,
|
|
|
+// * this list of conditions and the following disclaimer.
|
|
|
+// * Redistributions in binary form must reproduce the above copyright
|
|
|
+// * notice, this list of conditions and the following disclaimer in the
|
|
|
+// * documentation and/or other materials provided with the distribution.
|
|
|
+// * Neither the name of the dreamlu.net developer nor the names of its
|
|
|
+// * contributors may be used to endorse or promote products derived from
|
|
|
+// * this software without specific prior written permission.
|
|
|
+// * Author: Chill 庄骞 (smallchill@163.com)
|
|
|
+// */
|
|
|
+//package org.springblade.archive.service.impl;
|
|
|
+//
|
|
|
+//
|
|
|
+//import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+//import org.apache.commons.lang.StringUtils;
|
|
|
+//import org.springblade.archive.entity.ArchiveAiName;
|
|
|
+//import org.springblade.archive.mapper.ArchiveAiNameMapper;
|
|
|
+//import org.springblade.archive.service.IArchiveAiNameService;
|
|
|
+//import org.springblade.archive.vo.ArchiveAiNameVO;
|
|
|
+//import org.springblade.archive.vo.ArchiveAiNameVO1;
|
|
|
+//import org.springblade.common.utils.DeepSeekClient;
|
|
|
+//import org.springblade.core.mp.base.BaseServiceImpl;
|
|
|
+//import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+//import org.springframework.jdbc.core.BeanPropertyRowMapper;
|
|
|
+//import org.springframework.jdbc.core.JdbcTemplate;
|
|
|
+//import org.springframework.scheduling.annotation.Async;
|
|
|
+//import org.springframework.stereotype.Service;
|
|
|
+//import org.springframework.transaction.annotation.Transactional;
|
|
|
+//
|
|
|
+//import javax.annotation.Resource;
|
|
|
+//import java.text.SimpleDateFormat;
|
|
|
+//import java.util.*;
|
|
|
+//import java.util.concurrent.Semaphore;
|
|
|
+//import java.util.concurrent.ThreadPoolExecutor;
|
|
|
+//import java.util.stream.Collectors;
|
|
|
+//
|
|
|
+//import static java.util.stream.Collectors.groupingBy;
|
|
|
+//
|
|
|
+///**
|
|
|
+// * 服务实现类
|
|
|
+// *
|
|
|
+// * @author BladeX
|
|
|
+// * @since 2025-07-03
|
|
|
+// */
|
|
|
+//@Service
|
|
|
+//public class ArchiveAiNameServiceImpl extends BaseServiceImpl<ArchiveAiNameMapper, ArchiveAiName> implements IArchiveAiNameService {
|
|
|
+//
|
|
|
+// private static String DEEPSEEK_ARCHIVE_NAME = ".这是一段案卷题名,精简案卷题名重复啰嗦的内容,不要加以上内容没有的词语 返回值不要有任何多余得废话,只要结果";
|
|
|
+// private static final int MAX_CONCURRENT_REQUESTS = 5;
|
|
|
+//
|
|
|
+// @Autowired
|
|
|
+// private JdbcTemplate jdbcTemplate;
|
|
|
+//
|
|
|
+// @Autowired
|
|
|
+// private DeepSeekClient deepSeekClient;
|
|
|
+//
|
|
|
+// @Resource(name = "taskExecutor1")
|
|
|
+// private ThreadPoolExecutor executor;
|
|
|
+//
|
|
|
+// private final Semaphore apiSemaphore = new Semaphore(MAX_CONCURRENT_REQUESTS);
|
|
|
+//
|
|
|
+// @Override
|
|
|
+// @Async("taskExecutor1")
|
|
|
+// @Transactional
|
|
|
+// public void syncCreatAiName(List<ArchiveAiName> aiNames) {
|
|
|
+// aiNames.parallelStream().forEach(name -> {
|
|
|
+// try {
|
|
|
+// apiSemaphore.acquire();
|
|
|
+// try {
|
|
|
+// String content = deepSeekClient.getSimplifiedContent(name.getArchiveName() + DEEPSEEK_ARCHIVE_NAME);
|
|
|
+// if (content.startsWith("API_ERROR:") ||
|
|
|
+// content.startsWith("PARSE_ERROR:") ||
|
|
|
+// content.startsWith("IO_ERROR:")||content.startsWith("Error:")) {
|
|
|
+// name.setStatus(4);
|
|
|
+// name.setArchiveNameAi("获取失败");
|
|
|
+// } else {
|
|
|
+// name.setArchiveNameAi(content);
|
|
|
+// name.setStatus(2); // 标记为成功
|
|
|
+// }
|
|
|
+// } finally {
|
|
|
+// apiSemaphore.release();
|
|
|
+// }
|
|
|
+// } catch (InterruptedException e) {
|
|
|
+// Thread.currentThread().interrupt();
|
|
|
+// name.setStatus(4); // 设置失败状态
|
|
|
+// name.setArchiveNameAi("获取失败");
|
|
|
+// } catch (Exception e) {
|
|
|
+// name.setStatus(4); // 设置失败状态
|
|
|
+// name.setArchiveNameAi("获取失败");
|
|
|
+// }
|
|
|
+// });
|
|
|
+//
|
|
|
+// // 分批更新数据库
|
|
|
+// int batchSize = 100;
|
|
|
+// for (int i = 0; i < aiNames.size(); i += batchSize) {
|
|
|
+// int end = Math.min(i + batchSize, aiNames.size());
|
|
|
+// List<ArchiveAiName> batch = aiNames.subList(i, end);
|
|
|
+// this.updateBatchById(batch);
|
|
|
+// }
|
|
|
+// }
|
|
|
+//
|
|
|
+// @Override
|
|
|
+// public List<ArchiveAiNameVO> getArchiveAiTask(Long projectId, Long contractId) {
|
|
|
+// List<ArchiveAiNameVO>list=new ArrayList<>();
|
|
|
+// List<ArchiveAiName> archiveAiNameList = this.baseMapper.selectList(new LambdaQueryWrapper<>(ArchiveAiName.class).eq(ArchiveAiName::getProjectId, projectId).eq(ArchiveAiName::getContractId, contractId));
|
|
|
+// if(!archiveAiNameList.isEmpty()){
|
|
|
+// Map<Long, List<ArchiveAiName>> map = archiveAiNameList.stream().collect(groupingBy(ArchiveAiName::getTaskId));
|
|
|
+// for (Map.Entry<Long, List<ArchiveAiName>> entry : map.entrySet()) {
|
|
|
+// ArchiveAiNameVO archiveAiNameVO = new ArchiveAiNameVO();
|
|
|
+// List<ArchiveAiName> archiveAiNames = entry.getValue();
|
|
|
+// archiveAiNameVO.setTaskId(entry.getKey());
|
|
|
+// Date createTime = archiveAiNames.get(0).getCreateTime();
|
|
|
+// SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
+// String formattedDate = sdf.format(createTime);
|
|
|
+// archiveAiNameVO.setTaskTime(formattedDate);
|
|
|
+// archiveAiNameVO.setNum(archiveAiNames.size());
|
|
|
+// archiveAiNameVO.setStatus(archiveAiNames.stream().allMatch(ai -> ai.getStatus() >1) ? 2:1);
|
|
|
+// list.add(archiveAiNameVO);
|
|
|
+// }
|
|
|
+// }
|
|
|
+// return list;
|
|
|
+// }
|
|
|
+//
|
|
|
+//
|
|
|
+// @Transactional
|
|
|
+// public boolean confirmAiName(List<ArchiveAiNameVO1>vos) {
|
|
|
+// for (ArchiveAiNameVO1 archiveAiName : vos) {
|
|
|
+// if(archiveAiName.getStatus()==2&& StringUtils.isNotEmpty(archiveAiName.getArchiveNameAi())){
|
|
|
+// archiveAiName.setStatus(3);
|
|
|
+// String sql=" update u_archives_auto set name='"+archiveAiName.getArchiveNameAi()+"', colour_status=2 where id="+archiveAiName.getArchiveAutoId();
|
|
|
+// jdbcTemplate.update(sql);
|
|
|
+// String sql2="update u_archive_ai_name set status=3 where id="+archiveAiName.getId();
|
|
|
+// jdbcTemplate.update(sql2);
|
|
|
+// }
|
|
|
+// }
|
|
|
+// Long taskId = vos.get(0).getTaskId();
|
|
|
+// String sql3="select * from u_archive_ai_name where task_id="+taskId+" and is_deleted=0";
|
|
|
+// List<ArchiveAiName> list = jdbcTemplate.query(sql3, new BeanPropertyRowMapper<>(ArchiveAiName.class));
|
|
|
+// if(list.stream().allMatch(item -> item.getStatus() >= 3)){
|
|
|
+// deletedArchiveAiTask(taskId);
|
|
|
+// };
|
|
|
+// return true;
|
|
|
+// }
|
|
|
+//
|
|
|
+// @Override
|
|
|
+// public Boolean deletedArchiveAiTask(Long taskId) {
|
|
|
+// return baseMapper.deletedArchiveAiTask(taskId);
|
|
|
+// }
|
|
|
+//}
|