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 70a539d..122dbce 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,4 +17,6 @@ public class BigModelInvokeUrl { private String assistantStatus; + private String deleteAssistant; + } 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 5ca95c7..0ad5398 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 @@ -59,4 +59,12 @@ public class InteractiveController { return R.data(IdWorker.get32UUID()); } + @ApiOperation("删除对话sessionId") + @ApiOperationSupport(order = 5) + @GetMapping("/removeSessionId") + public R removeSessionId(@RequestParam(value = "sessionId") 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/IInteractiveService.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/IInteractiveService.java index f497498..1eb206f 100644 --- a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/IInteractiveService.java +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/IInteractiveService.java @@ -23,4 +23,5 @@ public interface IInteractiveService { Boolean authentication(String stationId, String userId, String funcCode); + Boolean removeSessionId(String 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 7a44495..3dc22fb 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 @@ -7,20 +7,16 @@ import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import com.hnac.hzims.bigmodel.configuration.BigModelInvokeUrl; import com.hnac.hzims.bigmodel.entity.FunctionEntity; +import com.hnac.hzims.bigmodel.function.service.IFunctionService; import com.hnac.hzims.bigmodel.interactive.req.ModelFunctionReq; import com.hnac.hzims.bigmodel.interactive.service.IInteractiveService; import com.hnac.hzims.bigmodel.interactive.service.IJumpPageService; -import com.hnac.hzims.bigmodel.function.service.IFunctionService; import com.hnac.hzims.bigmodel.interactive.vo.AnswerVO; -import com.hnac.hzims.bigmodel.interactive.vo.ExtraVO; -import lombok.AllArgsConstructor; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springblade.core.log.exception.ServiceException; import org.springblade.core.log.logger.BladeLogger; -import org.springblade.core.secure.utils.AuthUtil; import org.springblade.core.tool.api.R; -import org.springblade.core.tool.utils.BeanUtil; import org.springblade.core.tool.utils.CollectionUtil; import org.springblade.core.tool.utils.Func; import org.springblade.core.tool.utils.ObjectUtil; @@ -35,14 +31,11 @@ import org.springframework.util.Assert; import javax.servlet.http.HttpServletResponse; import java.util.*; +import java.util.stream.Collectors; import static com.hnac.hzims.bigmodel.interactive.constants.FunctionConstants.TypeEnum; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.stream.Collectors; +import static com.hnac.hzims.bigmodel.schedule.XxlJobHandlerConstant.HZIMS_BIGMODEL_ASK_KEY; -import static com.hnac.hzims.bigmodel.interactive.constants.FunctionConstants.*; /** * @Author: huangxing * @Date: 2024/04/26 14:51 @@ -71,8 +64,6 @@ public class InteractiveServiceImpl implements IInteractiveService { @Value("${fdp.host}") private String fdpHost; - private final static String HZIMS_BIGMODEL_ASK_KEY = "hzims:bigmodel:ask:key"; - @Override public R resolve(ModelFunctionReq req) { logger.info("interactive:resolve","开始解析大模型函数,函数内容为:" + JSON.toJSONString(req)); @@ -131,7 +122,7 @@ public class InteractiveServiceImpl implements IInteractiveService { }); JSONArray.parseArray(response.body(),AnswerVO.class).forEach(answerVO -> { String[] extras = answerVO.getExtra(); - List extraList = Arrays.stream(extras).map(extra -> extraResolveStrategyService.resolve(extra)).map(JSON::toJSONString).collect(Collectors.toList()); + List extraList = Arrays.stream(extras).map(extraResolveStrategyService::resolve).map(JSON::toJSONString).collect(Collectors.toList()); answerVO.setExtra(extraList.toArray(new String[extraList.size()])); }); return JSONArray.parseArray(response.body(),AnswerVO.class); @@ -161,6 +152,33 @@ public class InteractiveServiceImpl implements IInteractiveService { return true; } + @Override + public Boolean removeSessionId(String sessionId) { + // 调用大模型删除对话 + Map params = new HashMap<>(); + params.put("id",sessionId); + HttpResponse response = HttpRequest.post(fdpHost + bigModelInvokeUrl.getAssistantStatus()) + .body(JSON.toJSONString(params)).execute(); + if(response.getStatus() != HttpServletResponse.SC_OK) { + log.error("远程调用大模型【删除对话】接口失败!"); + throw new ServiceException("远程调用大模型【删除对话】接口失败!"); + } + // 移除对应reids中问题标记 + Object json = redisTemplate.opsForValue().get(HZIMS_BIGMODEL_ASK_KEY); + if(ObjectUtil.isEmpty(json)) { + return true; + } + List sessionIds = JSONObject.parseArray(json.toString(),String.class); + if(CollectionUtil.isEmpty(sessionIds)){ + return true; + } + if(sessionIds.contains(sessionId)){ + sessionIds.remove(sessionId); + redisTemplate.opsForValue().set(HZIMS_BIGMODEL_ASK_KEY,JSONObject.toJSONString(sessionIds)); + } + return true; + } + private List getStationPermissionsById(String userId) { R> deptSattionR = deptClient.getStationPermissionsById(Long.valueOf(userId)); Assert.isTrue(deptSattionR.isSuccess() && CollectionUtil.isNotEmpty(deptSattionR.getData()),() -> { 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 6d7298f..5f3752f 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 @@ -19,9 +19,7 @@ import com.xxl.job.core.log.XxlJobLogger; import lombok.AllArgsConstructor; import org.springblade.core.tool.api.R; import org.springblade.core.tool.utils.CollectionUtil; -import org.springblade.core.tool.utils.Func; import org.springblade.core.tool.utils.ObjectUtil; -import org.springblade.core.tool.utils.StringUtil; import org.springframework.data.redis.core.RedisTemplate; import org.springframework.stereotype.Component; import org.springframework.web.socket.TextMessage; @@ -30,7 +28,6 @@ import org.springframework.web.socket.WebSocketSession; import java.util.List; import java.util.concurrent.CompletableFuture; import java.util.concurrent.ThreadPoolExecutor; -import java.util.function.Function; import java.util.stream.Collectors; import static com.hnac.hzims.bigmodel.schedule.XxlJobHandlerConstant.*; @@ -74,19 +71,15 @@ 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); // 问题回答完成,去除redis问题标记 if(answerVO.getStatus() == 0){ - WebSocketSession session = InteractiveSessionManager.get(answerVO.getSessionId()); - TextMessage message = InteractiveSessionManager.getTextMessage("1",JSON.toJSONString(answerVO)); - wsService.sendMessage(session,message); sessionIds.remove(answerVO.getSessionId()); - redisTemplate.opsForValue().set(HZIMS_BIGMODEL_ASK_KEY, JSONObject.toJSONString(sessionIds)); - }else{ - WebSocketSession session = InteractiveSessionManager.get(answerVO.getSessionId()); - TextMessage message = InteractiveSessionManager.getTextMessage("1",JSON.toJSONString(answerVO)); - wsService.sendMessage(session,message); } }, getAnswerPoolExecutor)); + redisTemplate.opsForValue().set(HZIMS_BIGMODEL_ASK_KEY, JSONObject.toJSONString(sessionIds)); return ReturnT.SUCCESS; } @@ -106,7 +99,7 @@ public class InteractiveSchedule { if(projectListR.isSuccess()) { List projectIds = projectListR.getData().stream().map(ProjectVO::getId).collect(Collectors.toList()); Result> canvasListR = scadaClient.getCanvasList(projectIds); - if(canvasListR.isSuccess()) { + if(canvasListR.isSuccess() && CollectionUtil.isNotEmpty(canvasListR.getData())) { List canvasList = canvasListR.getData(); //TODO 同步站点画面指令 } diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/schedule/XxlJobHandlerConstant.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/schedule/XxlJobHandlerConstant.java index de73434..9d3cefd 100644 --- a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/schedule/XxlJobHandlerConstant.java +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/schedule/XxlJobHandlerConstant.java @@ -16,4 +16,6 @@ public interface XxlJobHandlerConstant { String INTERACTIVE_RESULT_KEY = "hzllm:interactive:result"; + String HZIMS_BIGMODEL_ASK_KEY = "hzims:bigmodel:ask:key"; + }