增强代码的健壮性

This commit is contained in:
ZLI263
2025-09-22 11:47:51 +08:00
parent 154711851f
commit 2a127b5814
4 changed files with 12 additions and 13 deletions

View File

@@ -5,7 +5,7 @@ public enum CategoryEnum {
ENTERPRISE_WECHAT("enterprise_wechat", "企微记录"), ENTERPRISE_WECHAT("enterprise_wechat", "企微记录"),
ENTERPRISE_WECHAT_PORTRAIT("enterprise_wechat_portrait", "企微语料客户画像"), ENTERPRISE_WECHAT_PORTRAIT("enterprise_wechat_portrait", "企微语料客户画像"),
PHONE_VOICE("phone_voice", "语音电话"), PHONE_VOICE("phone_voice", "语音电话"),
PORTRAIT_ALLIN("portrait_allin", "语音电话,用户画像"), PORTRAIT_ALLIN("portrait_allin", "综合allin,用户画像"),
NAMEPLATE_VOICE("nameplate_voice", "铭牌"), NAMEPLATE_VOICE("nameplate_voice", "铭牌"),
NAMEPLATE_VOICE_PORTRAIT("nameplate_voice_portrait", "铭牌客户画像"), NAMEPLATE_VOICE_PORTRAIT("nameplate_voice_portrait", "铭牌客户画像"),

View File

@@ -24,7 +24,7 @@ public class ExecutorConfig {
private int maxPoolSize; private int maxPoolSize;
@Value("${task.pool.keepAliveSeconds}") @Value("${task.pool.keepAliveSeconds}")
private int keepAliveSeconds=6000000; private int keepAliveSeconds=120;
@Value("${task.pool.queueCapacity}") @Value("${task.pool.queueCapacity}")
private int queueCapacity; private int queueCapacity;
@@ -97,7 +97,7 @@ public class ExecutorConfig {
try { try {
// 等待所有任务完成最多等待30秒 // 等待所有任务完成最多等待30秒
if (!threadPoolExecutor.awaitTermination(30, TimeUnit.SECONDS)) { if (!threadPoolExecutor.awaitTermination(120, TimeUnit.SECONDS)) {
log.warn("线程池未能在30秒内正常关闭强制关闭"); log.warn("线程池未能在30秒内正常关闭强制关闭");
threadPoolExecutor.shutdownNow(); threadPoolExecutor.shutdownNow();
} }

View File

@@ -28,10 +28,7 @@ import org.springframework.stereotype.Service;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.time.LocalDate; import java.time.LocalDate;
import java.util.*; import java.util.*;
import java.util.concurrent.CompletableFuture; import java.util.concurrent.*;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Semaphore;
/** /**
@@ -183,7 +180,12 @@ public class TmNameplateCorpusServiceImpl extends ServiceImpl<TmNameplateCorpusM
try { try {
log.info("铭牌语料可用许可授权数,总结和分类场景={}", semaphore.availablePermits()); log.info("铭牌语料可用许可授权数,总结和分类场景={}", semaphore.availablePermits());
// 获取许可 - 如果没有可用许可会阻塞等待 // 获取许可 - 如果没有可用许可会阻塞等待
semaphore.acquire(); // 获取许可 - 如果没有可用许可会阻塞等待
// 修改为带超时的获取许可方式超时时间为1分钟
if (!semaphore.tryAcquire(1, TimeUnit.MINUTES)) {
log.warn("获取许可超时,跳过执行任务");
return;
}
//第一个业务场景 开始: 总结和分类业务场景 //第一个业务场景 开始: 总结和分类业务场景
JSONObject execDifyFlow = diFyService.executeDifyFlow(diFyImageReq, BusinessTypeEnum.SMART_ASSISTANT_NAMEPLATE.getCode(), JSONObject execDifyFlow = diFyService.executeDifyFlow(diFyImageReq, BusinessTypeEnum.SMART_ASSISTANT_NAMEPLATE.getCode(),
JSONObject.toJSONString(corpusReportDTO), null); JSONObject.toJSONString(corpusReportDTO), null);
@@ -259,9 +261,9 @@ public class TmNameplateCorpusServiceImpl extends ServiceImpl<TmNameplateCorpusM
try { try {
log.info("铭牌sendNameplateLto toJSONString :{}", execDifyFlow); log.info("铭牌sendNameplateLto toJSONString :{}", execDifyFlow);
log.info("tmNameplateCorpus.tostrign:{}", tmNameplateCorpus.toString()); log.info("tmNameplateCorpus.tostrign:{}", tmNameplateCorpus);
if (execDifyFlow.get("status").equals("succeeded")) { if (execDifyFlow != null && "succeeded".equals(execDifyFlow.get("status"))) {
String text = execDifyFlow.getString(outputsFinal); String text = execDifyFlow.getString(outputsFinal);
// 发送MQ // 发送MQ
log.info("铭牌send mq 业务类型是:{}, Json 是:{}", businessType, text); log.info("铭牌send mq 业务类型是:{}, Json 是:{}", businessType, text);

View File

@@ -95,9 +95,6 @@ public class TmOdsVdqwMessagearchivingServiceImpl extends ServiceImpl<TmOdsVdqwM
@Value("${batch.threadNum}") @Value("${batch.threadNum}")
int threadNum =2; int threadNum =2;
private Semaphore semaphore = new Semaphore(threadNum); // 限制并发数
String consultantIdStr ="consultantId"; String consultantIdStr ="consultantId";
@Override @Override