diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/HzimsBigModelApplication.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/HzimsBigModelApplication.java index 2709c09..0f09cc7 100644 --- a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/HzimsBigModelApplication.java +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/HzimsBigModelApplication.java @@ -1,28 +1,35 @@ package com.hnac.hzims.bigmodel; +import lombok.extern.slf4j.Slf4j; import org.mybatis.spring.annotation.MapperScan; import org.springblade.core.cloud.feign.EnableBladeFeign; +import org.springblade.core.jwt.JwtUtil; import org.springblade.core.launch.BladeApplication; -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.builder.SpringApplicationBuilder; import org.springframework.boot.web.servlet.support.SpringBootServletInitializer; import org.springframework.cloud.client.SpringCloudApplication; import org.springframework.context.annotation.ComponentScan; -import org.springframework.scheduling.annotation.EnableScheduling; +import org.springframework.data.redis.core.RedisTemplate; import javax.annotation.Resource; +import static com.hnac.hzims.bigmodel.schedule.XxlJobHandlerConstant.HZIMS_BIGMODEL_ASK_KEY; + @EnableBladeFeign(basePackages = {"org.springblade","com.hnac"}) @SpringCloudApplication @MapperScan("com.hnac.hzims.**.mapper.**") @ComponentScan(basePackages = {"com.hnac.hzims.bigmodel.*"}) @Resource @ComponentScan(basePackages = {"com.hnac.hzims.*"}) +@Slf4j public class HzimsBigModelApplication extends SpringBootServletInitializer { + public static void main(String[] args) { BladeApplication.run(BigModelConstants.APP_NAME, HzimsBigModelApplication.class, args); + RedisTemplate redisTemplate = JwtUtil.getRedisTemplate(); + redisTemplate.delete(HZIMS_BIGMODEL_ASK_KEY); + log.info("服务重启删除问题reids缓存:{}",HZIMS_BIGMODEL_ASK_KEY); } @Override diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/configuration/BigModelInvokeUrl.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/configuration/BigModelInvokeUrl.java index c8248dd..2a50a77 100644 --- a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/configuration/BigModelInvokeUrl.java +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/configuration/BigModelInvokeUrl.java @@ -17,7 +17,7 @@ public class BigModelInvokeUrl { private String assistantStatus; - private String deleteAssistant; + private String askAbort; private String updateVideo; diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/controller/InteractiveController.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/controller/InteractiveController.java index 0ad5398..7739800 100644 --- a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/controller/InteractiveController.java +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/controller/InteractiveController.java @@ -62,7 +62,7 @@ public class InteractiveController { @ApiOperation("删除对话sessionId") @ApiOperationSupport(order = 5) @GetMapping("/removeSessionId") - public R removeSessionId(@RequestParam(value = "sessionId") String sessionId) { + public R removeSessionId(@RequestParam(value = "id") String sessionId) { return R.data(interactiveService.removeSessionId(sessionId)); } diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/InteractiveServiceImpl.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/InteractiveServiceImpl.java index 2bb4ffc..1222533 100644 --- a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/InteractiveServiceImpl.java +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/InteractiveServiceImpl.java @@ -110,7 +110,9 @@ public class InteractiveServiceImpl implements IInteractiveService { redisTemplate.opsForValue().set(HZIMS_BIGMODEL_ASK_KEY,JSONObject.toJSONString(asks)); }else{ List asks = JSONObject.parseArray(json.toString(),String.class); - asks.add(sessionId); + if(!asks.contains(sessionId)){ + asks.add(sessionId); + } redisTemplate.opsForValue().set(HZIMS_BIGMODEL_ASK_KEY,JSONObject.toJSONString(asks)); } return R.success("消息发送成功"); @@ -137,6 +139,9 @@ public class InteractiveServiceImpl implements IInteractiveService { }); JSONArray.parseArray(response.body(),AnswerVO.class).forEach(answerVO -> { String[] extras = answerVO.getExtra(); + if(ObjectUtil.isEmpty(answerVO.getExtra()) || extras.length == 0){ + return; + } List extraList = Arrays.stream(extras).map(extraResolveStrategyService::resolve).map(JSON::toJSONString).collect(Collectors.toList()); answerVO.setExtra(extraList.toArray(new String[extraList.size()])); }); @@ -172,7 +177,7 @@ public class InteractiveServiceImpl implements IInteractiveService { // 调用大模型删除对话 Map params = new HashMap<>(); params.put("id",sessionId); - HttpResponse response = HttpRequest.post(fdpHost + bigModelInvokeUrl.getAssistantStatus()) + HttpResponse response = HttpRequest.post(fdpHost + bigModelInvokeUrl.getAskAbort()) .body(JSON.toJSONString(params)).execute(); if(response.getStatus() != HttpServletResponse.SC_OK) { log.error("远程调用大模型【删除对话】接口失败!"); diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/schedule/InteractiveSchedule.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/schedule/InteractiveSchedule.java index a8cc9a7..d1ed666 100644 --- a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/schedule/InteractiveSchedule.java +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/schedule/InteractiveSchedule.java @@ -102,15 +102,17 @@ public class InteractiveSchedule { List answerList = interactiveService.getAnswerBySessionIds(String.join(",", sessionIds)); answerList.parallelStream().forEach(answerVO -> CompletableFuture.runAsync(() -> { XxlJobLogger.log("开始获取" + answerVO.getSessionId() + "答案!"); - WebSocketSession session = InteractiveSessionManager.get(answerVO.getSessionId()); - TextMessage message = InteractiveSessionManager.getTextMessage("1",JSON.toJSONString(answerVO)); - wsService.sendMessage(session,message); + if(sessionIds.contains(answerVO.getSessionId())){ + WebSocketSession session = InteractiveSessionManager.get(answerVO.getSessionId()); + TextMessage message = InteractiveSessionManager.getTextMessage("1",JSON.toJSONString(answerVO)); + wsService.sendMessage(session,message); + } // 问题回答完成,去除redis问题标记 if(answerVO.getStatus() == 0){ sessionIds.remove(answerVO.getSessionId()); } + redisTemplate.opsForValue().set(HZIMS_BIGMODEL_ASK_KEY, JSONObject.toJSONString(sessionIds)); }, getAnswerPoolExecutor)); - redisTemplate.opsForValue().set(HZIMS_BIGMODEL_ASK_KEY, JSONObject.toJSONString(sessionIds)); return ReturnT.SUCCESS; }