diff --git a/hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/interactive/constants/FunctionConstants.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/constants/FunctionConstants.java similarity index 100% rename from hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/interactive/constants/FunctionConstants.java rename to hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/constants/FunctionConstants.java diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/constants/InfoMessageConstant.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/constants/InfoMessageConstant.java new file mode 100644 index 0000000..6663556 --- /dev/null +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/constants/InfoMessageConstant.java @@ -0,0 +1,11 @@ +package com.hnac.hzims.bigmodel.interactive.constants; + +/** + * @Author: huangxing + * @Date: 2024/06/21 16:35 + */ +public interface InfoMessageConstant { + + String ERROR_MESSAGE = "非常抱歉,系统在处理您的请求时遇到了问题。请稍后再试或联系我们的客服团队。"; + +} diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/factory/AnswerResolveFactory.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/factory/AnswerResolveFactory.java new file mode 100644 index 0000000..27a8978 --- /dev/null +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/factory/AnswerResolveFactory.java @@ -0,0 +1,46 @@ +package com.hnac.hzims.bigmodel.interactive.factory; + +import com.hnac.hzims.bigmodel.interactive.constants.FuncRouteEnum; +import com.hnac.hzims.bigmodel.interactive.service.IResolveService; +import com.hnac.hzims.bigmodel.interactive.vo.AnswerVO; +import org.springblade.core.log.exception.ServiceException; +import org.springblade.core.log.logger.BladeLogger; +import org.springblade.core.tool.utils.Func; +import org.springblade.core.tool.utils.SpringUtil; + +/** + * @Author: huangxing + * @Date: 2024/06/21 18:44 + */ +public class AnswerResolveFactory { + + public static final String DIAGNOSE_ANSWER_SERVICE = "diagnoseAnswerResolveService"; + public static final String CHOICE_ANSWER_SERVICE = "choiceAnswerResolveService"; + public static final String REMOTE_ANSWER_SERVICE = "remoteAnswerResolveService"; + public static final String PARAM_ANSWER_SERVICE = "paramAnswerResolveService"; + + public static IResolveService getResolveService(String funcCode) { + FuncRouteEnum funcRouteEnum = FuncRouteEnum.getEnumByFuncCode(funcCode); + if(Func.isNotEmpty(funcRouteEnum)) { + switch (funcRouteEnum) { + case DIAGNOSE: + return SpringUtil.getBean(DIAGNOSE_ANSWER_SERVICE); + case CHOOSE_VIDEO: + case CHOOSE_CANVAS: + case CHOOSE_STATION: + case CHOOSE_FAULT: + case CHOOSE_YC: + case CHOOSE_YK: + return SpringUtil.getBean(CHOICE_ANSWER_SERVICE); + case CONFIRM_YK: + return SpringUtil.getBean(REMOTE_ANSWER_SERVICE); + case SHOW_PARAM: + return SpringUtil.getBean(PARAM_ANSWER_SERVICE); + default: + throw new ServiceException("service解析失败!"); + } + } + throw new ServiceException("service解析失败!"); + } + +} diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/factory/ResolveFactory.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/factory/ResolveFactory.java new file mode 100644 index 0000000..b3fafc6 --- /dev/null +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/factory/ResolveFactory.java @@ -0,0 +1,44 @@ +package com.hnac.hzims.bigmodel.interactive.factory; + +import com.hnac.hzims.bigmodel.entity.FunctionEntity; +import com.hnac.hzims.bigmodel.function.service.IFunctionService; +import com.hnac.hzims.bigmodel.interactive.constants.FuncRouteEnum; +import com.hnac.hzims.bigmodel.interactive.constants.FunctionConstants; +import com.hnac.hzims.bigmodel.interactive.service.IResolveService; +import org.springblade.core.log.exception.ServiceException; +import org.springblade.core.log.logger.BladeLogger; +import org.springblade.core.tool.utils.Func; +import org.springblade.core.tool.utils.SpringUtil; + +/** + * @Author: huangxing + * @Date: 2024/06/21 15:53 + */ +public class ResolveFactory { + + public static final String CANVAS_RESOLVE_SERVICE = "canvasResolveService"; + public static final String VIDEO_RESOLVE_SERVICE = "videoResolveService"; + + /** + * 获取解析函数需要的service + * @param funcCode 函数编号 + * @return 解析函数所需service + */ + public static IResolveService getResolveService(String funcCode) { + BladeLogger logger = SpringUtil.getBean(BladeLogger.class); + FuncRouteEnum funcRouteEnum = FuncRouteEnum.getEnumByFuncCode(funcCode); + if(Func.isNotEmpty(funcRouteEnum)) { + switch(funcRouteEnum) { + case OPEN_CANVAS: + return SpringUtil.getBean("canvasResolveService"); + case OPEN_VIDEO: + return SpringUtil.getBean("videoResolveService"); + default: + logger.error("hzims:bigModel:getResolveService","函数解析失败,函数编号为:" + funcCode); + throw new ServiceException("service解析失败"); + } + } + throw new ServiceException("service解析失败"); + } + +} diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/IAnswerResolveService.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/IAnswerResolveService.java new file mode 100644 index 0000000..49608bb --- /dev/null +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/IAnswerResolveService.java @@ -0,0 +1,22 @@ +package com.hnac.hzims.bigmodel.interactive.service; + +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONObject; +import com.hnac.hzims.bigmodel.interactive.vo.AnswerVO; + +import java.util.Arrays; +import java.util.stream.Stream; + +/** + * @Author: huangxing + * @Date: 2024/06/21 18:39 + */ +public interface IAnswerResolveService { + + AnswerVO resolve(AnswerVO answer); + + default Stream extraStream(AnswerVO answer) { + return Arrays.stream(answer.getExtras()).map(JSON::toJSONString).map(JSONObject::parseObject); + } + +} diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/IHznlmInteractiveService.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/IHznlmInteractiveService.java index f134480..6239980 100644 --- a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/IHznlmInteractiveService.java +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/IHznlmInteractiveService.java @@ -1,7 +1,9 @@ package com.hnac.hzims.bigmodel.interactive.service; import com.hnac.hzims.bigmodel.interactive.dto.AuthDataDTO; +import com.hnac.hzims.bigmodel.interactive.req.ModelFunctionReq; import com.hnac.hzims.bigmodel.interactive.vo.AuthDataVO; +import com.hnac.hzims.bigmodel.interactive.vo.ResolveResultVO; import org.springframework.web.bind.annotation.RequestBody; import javax.validation.Valid; @@ -15,4 +17,5 @@ public interface IHznlmInteractiveService { List getAuthData(@RequestBody @Valid AuthDataDTO req); + ResolveResultVO resolve(ModelFunctionReq req); } diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/IHznlmInvokeService.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/IHznlmInvokeService.java new file mode 100644 index 0000000..6cfa306 --- /dev/null +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/IHznlmInvokeService.java @@ -0,0 +1,63 @@ +package com.hnac.hzims.bigmodel.interactive.service; + +import com.hnac.hzims.bigmodel.interactive.vo.AnswerVO; +import org.springblade.core.tool.api.R; + +import java.util.List; +import java.util.Map; + +/** + * @Author: huangxing + * @Date: 2024/06/21 17:20 + */ +public interface IHznlmInvokeService { + + /** + * 基础问题 + * @param question 提问问题 + * @param sessionId 会话ID + * @param userId 提问人ID + * @return 提问结果 + */ + void ask(String question, String sessionId, String userId); + + /** + * 特殊问题 + * @param sessionId 会话ID + * @param userId 提问人ID + * @param extra 特殊问题内容 + * @return 提问结果 + */ + void specialAsk(String sessionId, String userId, Map extra); + + /** + * 知识库问题 + * @param question 问题名称 + * @param sessionId 会话ID + * @param userId 提问人ID + * @param knowledge 知识库名称 + */ + void knowledgeAsk(String question, String sessionId, String userId, String knowledge); + + /** + * 删除对话记录 + * @param sessionId 会话ID + */ + void removeSessionId(String sessionId); + + /** + * 获取热点问题 + * @return 热点问题 + */ + List hotQuestions(); + + /** + * 查询问答状态 + * @param sessionIds 会话ID,按逗号分隔 + * @return 答案列表 + */ + List getAnswerBySessionIds(String sessionIds); + + + +} 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 9474795..e35541b 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 @@ -13,6 +13,7 @@ import java.util.Map; * @Author: huangxing * @Date: 2024/04/26 14:51 */ +@Deprecated public interface IInteractiveService { ExtraVO resolveStations(String startTime, String endTime, String type, String enumType); diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/IJumpPageService.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/IJumpPageService.java index fa4f9d5..5a24baa 100644 --- a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/IJumpPageService.java +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/IJumpPageService.java @@ -9,6 +9,7 @@ import java.util.Map; * @Author: huangxing * @Date: 2024/04/26 11:46 */ +@Deprecated public interface IJumpPageService { String dealJumpTypeFunction(FunctionEntity function, Map args); diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/IParamsService.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/IParamsService.java index aee914a..f39a0fb 100644 --- a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/IParamsService.java +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/IParamsService.java @@ -8,6 +8,7 @@ import java.util.Map; * @Author: huangxing * @Date: 2024/05/09 08:50 */ +@Deprecated public interface IParamsService { String dealJumpTypeFunction(FunctionEntity function, Map args); diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/IResolveService.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/IResolveService.java new file mode 100644 index 0000000..97c6aa4 --- /dev/null +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/IResolveService.java @@ -0,0 +1,17 @@ +package com.hnac.hzims.bigmodel.interactive.service; + +import com.hnac.hzims.bigmodel.interactive.req.ModelFunctionReq; +import com.hnac.hzims.bigmodel.interactive.vo.ExtraVO; +import com.hnac.hzims.bigmodel.interactive.vo.ResolveResultVO; + +/** + * @Author: huangxing + * @Date: 2024/06/21 15:39 + */ +public interface IResolveService { + + ExtraVO resolve(Long id); + + ResolveResultVO resolve(ModelFunctionReq req); + +} diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/CanvasResolveServiceImpl.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/CanvasResolveServiceImpl.java new file mode 100644 index 0000000..4ae5cd5 --- /dev/null +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/CanvasResolveServiceImpl.java @@ -0,0 +1,33 @@ +package com.hnac.hzims.bigmodel.interactive.service.impl; + +import com.hnac.hzims.bigmodel.interactive.factory.ResolveFactory; +import com.hnac.hzims.bigmodel.interactive.req.ModelFunctionReq; +import com.hnac.hzims.bigmodel.interactive.service.IResolveService; +import com.hnac.hzims.bigmodel.interactive.vo.ExtraVO; +import com.hnac.hzims.bigmodel.interactive.vo.ResolveResultVO; +import com.hnac.hzinfo.sdk.v5.scada.ScadaClient; +import groovy.util.logging.Slf4j; +import lombok.AllArgsConstructor; +import org.springframework.stereotype.Service; + +/** + * @Author: huangxing + * @Date: 2024/06/21 15:39 + */ +@Service(ResolveFactory.CANVAS_RESOLVE_SERVICE) +@AllArgsConstructor +@Slf4j +public class CanvasResolveServiceImpl implements IResolveService { + + private final ScadaClient scadaClient; + + @Override + public ResolveResultVO resolve(ModelFunctionReq req) { + return null; + } + + @Override + public ExtraVO resolve(Long id) { + return null; + } +} diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/ChoiceAnswerResolveServiceImpl.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/ChoiceAnswerResolveServiceImpl.java new file mode 100644 index 0000000..7b27572 --- /dev/null +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/ChoiceAnswerResolveServiceImpl.java @@ -0,0 +1,47 @@ +package com.hnac.hzims.bigmodel.interactive.service.impl; + +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONArray; +import com.alibaba.fastjson.JSONObject; +import com.hnac.hzims.bigmodel.interactive.constants.FuncRouteEnum; +import com.hnac.hzims.bigmodel.interactive.factory.AnswerResolveFactory; +import com.hnac.hzims.bigmodel.interactive.service.IAnswerResolveService; +import com.hnac.hzims.bigmodel.interactive.vo.AnswerVO; +import com.hnac.hzims.bigmodel.interactive.vo.ExtraVO; +import groovy.util.logging.Slf4j; +import lombok.AllArgsConstructor; +import org.springframework.stereotype.Service; + +import java.util.Arrays; +import java.util.List; +import java.util.stream.Collectors; + +/** + * @Author: huangxing + * @Date: 2024/06/21 19:02 + * @Describe 选项答案解析服务层 + */ +@AllArgsConstructor +@Service(AnswerResolveFactory.CHOICE_ANSWER_SERVICE) +@Slf4j +public class ChoiceAnswerResolveServiceImpl implements IAnswerResolveService { + + @Override + public AnswerVO resolve(AnswerVO answer) { + List extraList = this.extraStream(answer).map(this::getExtra).collect(Collectors.toList()); + answer.setExtras(extraList.toArray()); + + return answer; + } + + private ExtraVO getExtra(JSONObject originExtra) { + ExtraVO result = new ExtraVO(); + JSONArray selections = JSONArray.parseArray(JSON.toJSONString(originExtra.get("data"))); + result.setSelection(selections); + result.setSpecial(true); + String funcCode = originExtra.getString("func"); + result.setFuncCode(funcCode); + result.setType(FuncRouteEnum.getEnumByFuncCode(funcCode).getType().getType()); + return result; + } +} diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/DiagnoseAnswerResolveServiceImpl.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/DiagnoseAnswerResolveServiceImpl.java new file mode 100644 index 0000000..984247a --- /dev/null +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/DiagnoseAnswerResolveServiceImpl.java @@ -0,0 +1,23 @@ +package com.hnac.hzims.bigmodel.interactive.service.impl; + +import com.hnac.hzims.bigmodel.interactive.factory.AnswerResolveFactory; +import com.hnac.hzims.bigmodel.interactive.service.IAnswerResolveService; +import com.hnac.hzims.bigmodel.interactive.vo.AnswerVO; +import groovy.util.logging.Slf4j; +import lombok.AllArgsConstructor; +import org.springframework.stereotype.Service; + +/** + * @Author: huangxing + * @Date: 2024/06/21 18:59 + */ +@Service(AnswerResolveFactory.DIAGNOSE_ANSWER_SERVICE) +@Slf4j +@AllArgsConstructor +public class DiagnoseAnswerResolveServiceImpl implements IAnswerResolveService { + + @Override + public AnswerVO resolve(AnswerVO answer) { + return null; + } +} diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/ExtraResolveStrategyService.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/ExtraResolveStrategyService.java index 2a59476..1dc967a 100644 --- a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/ExtraResolveStrategyService.java +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/ExtraResolveStrategyService.java @@ -36,6 +36,7 @@ import java.util.stream.Collectors; */ @Service @AllArgsConstructor +@Deprecated public class ExtraResolveStrategyService { public static final String PATTERN_DATETIME = "yyyy-MM-dd HH:mm:ss.SSS"; diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/HzllmInteractiveServiceImpl.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/HznlmInteractiveServiceImpl.java similarity index 77% rename from hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/HzllmInteractiveServiceImpl.java rename to hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/HznlmInteractiveServiceImpl.java index 668bd66..2ccc41f 100644 --- a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/HzllmInteractiveServiceImpl.java +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/HznlmInteractiveServiceImpl.java @@ -2,8 +2,12 @@ package com.hnac.hzims.bigmodel.interactive.service.impl; import com.hnac.hzims.bigmodel.interactive.constants.DataAuthTypeEnum; import com.hnac.hzims.bigmodel.interactive.dto.AuthDataDTO; +import com.hnac.hzims.bigmodel.interactive.factory.ResolveFactory; +import com.hnac.hzims.bigmodel.interactive.req.ModelFunctionReq; import com.hnac.hzims.bigmodel.interactive.service.IHznlmInteractiveService; +import com.hnac.hzims.bigmodel.interactive.service.IResolveService; import com.hnac.hzims.bigmodel.interactive.vo.AuthDataVO; +import com.hnac.hzims.bigmodel.interactive.vo.ResolveResultVO; import groovy.util.logging.Slf4j; import lombok.AllArgsConstructor; import org.springblade.core.log.exception.ServiceException; @@ -21,7 +25,7 @@ import java.util.stream.Collectors; @Service @AllArgsConstructor @Slf4j -public class HzllmInteractiveServiceImpl implements IHznlmInteractiveService { +public class HznlmInteractiveServiceImpl implements IHznlmInteractiveService { private final AuthenticationService authenticationService; @@ -38,6 +42,16 @@ public class HzllmInteractiveServiceImpl implements IHznlmInteractiveService { } } + @Override + public ResolveResultVO resolve(ModelFunctionReq req) { + IResolveService resolveService = ResolveFactory.getResolveService(req.getFunctionName()); + try { + return resolveService.resolve(req); + } catch (Exception e) { + return ResolveResultVO.error(); + } + } + public List getDeptAuthData(String userId) { List deptStationDTOs = authenticationService.getStationPermissionsById(userId); return deptStationDTOs.stream().map(this::convertDeptAuthData).collect(Collectors.toList()); diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/HznlmInvokeServiceImpl.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/HznlmInvokeServiceImpl.java new file mode 100644 index 0000000..34445c7 --- /dev/null +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/HznlmInvokeServiceImpl.java @@ -0,0 +1,120 @@ +package com.hnac.hzims.bigmodel.interactive.service.impl; + +import cn.hutool.http.HttpRequest; +import cn.hutool.http.HttpResponse; +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONArray; +import com.hnac.hzims.bigmodel.configuration.BigModelInvokeUrl; +import com.hnac.hzims.bigmodel.interactive.service.IHznlmInvokeService; +import com.hnac.hzims.bigmodel.interactive.vo.AnswerVO; +import com.hnac.hzims.bigmodel.manager.SessionRedisManager; +import com.hnac.hzims.bigmodel.utils.RequestClientUtil; +import com.xxl.job.core.log.XxlJobLogger; +import groovy.util.logging.Slf4j; +import lombok.AllArgsConstructor; +import lombok.RequiredArgsConstructor; +import org.springblade.core.log.exception.ServiceException; +import org.springblade.core.log.logger.BladeLogger; +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.StringUtil; +import org.springblade.system.dto.DeptStationDTO; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Service; +import org.springframework.util.Assert; + +import javax.servlet.http.HttpServletResponse; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** + * @Author: huangxing + * @Date: 2024/06/21 17:20 + * @Describe HZN_LM大模型接口调用服务层 + */ +@Service +@RequiredArgsConstructor +@Slf4j +public class HznlmInvokeServiceImpl implements IHznlmInvokeService { + + private final AuthenticationService authenticationService; + private final BigModelInvokeUrl bigModelInvokeUrl; + private final BladeLogger logger; + private final SessionRedisManager sessionRedisManager; + + @Value("${fdp.host}") + private String fdpHost; + + @Override + public void ask(String question, String sessionId, String userId) { + Map params = new HashMap<>(); + params.put("id",sessionId); + params.put("userid", userId); + params.put("query",question); + Map authDataIds = this.getAuthDataIds(userId); + params.putAll(authDataIds); + RequestClientUtil.postCall(fdpHost + bigModelInvokeUrl.getAssistantAsk(), params); + sessionRedisManager.addSessionId(sessionId); + } + + @Override + public void specialAsk(String sessionId, String userId, Map extra) { + Map params = new HashMap<>(); + params.put("id",sessionId); + params.put("userid", userId); + params.put("extra",extra); + Map authDataIds = this.getAuthDataIds(userId); + params.putAll(authDataIds); + RequestClientUtil.postCall(fdpHost + bigModelInvokeUrl.getAssistantSpecialAsk(), params); + sessionRedisManager.addSessionId(sessionId); + } + + @Override + public void knowledgeAsk(String question, String sessionId, String userId, String knowledge) { + Map params = new HashMap<>(); + params.put("id", sessionId); + params.put("userid", userId); + params.put("query", question); + params.put("knowledge", knowledge); + Map authDataIds = this.getAuthDataIds(userId); + params.putAll(authDataIds); + RequestClientUtil.postCall(fdpHost + bigModelInvokeUrl.getAssistantKnowledgeAsk(), params); + sessionRedisManager.addSessionId(sessionId); + } + + @Override + public void removeSessionId(String sessionId) { + Map params = new HashMap<>(); + params.put("id",sessionId); + RequestClientUtil.postCall(fdpHost + bigModelInvokeUrl.getAskAbort(), params); + sessionRedisManager.removeSessionId(sessionId); + } + + @Override + public List hotQuestions() { + return RequestClientUtil.postCall(fdpHost + bigModelInvokeUrl.getHotQuestion(), null, List.class); + } + + @Override + public List getAnswerBySessionIds(String sessionIds) { + Map params = new HashMap<>(); + params.put("ids",Func.toStrList(",",sessionIds).toArray()); + List answerVOList = RequestClientUtil.postCall(fdpHost + bigModelInvokeUrl.getAssistantStatus(), params, List.class); + //TODO 解析答案 + return answerVOList; + } + + private Map getAuthDataIds(String userId) { + List authDatas = authenticationService.getStationPermissionsById(userId); + Map result = new HashMap<>(2); + String[] stationIds = authDatas.stream().map(DeptStationDTO::getStationId) + .filter(StringUtil::isNotBlank).toArray(String[]::new); + String[] projectIds = authDatas.stream().map(DeptStationDTO::getDeptId) + .filter(Func::isNotEmpty).toArray(String[]::new); + result.put("stationids", stationIds); + result.put("projectids", projectIds); + return result; + } +} 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 d670ef6..d5e1e6e 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 @@ -70,6 +70,7 @@ import static com.hnac.hzims.bigmodel.schedule.XxlJobHandlerConstant.HZIMS_BIGMO @Service @Slf4j @RequiredArgsConstructor +@Deprecated public class InteractiveServiceImpl implements IInteractiveService { private final BladeLogger logger; @@ -216,7 +217,7 @@ public class InteractiveServiceImpl implements IInteractiveService { log.error("远程调用大模型接口" + url + "失败!"); throw new ServiceException("远程调用大模型接口" + url + "失败!"); }); - return JSONObject.parseObject(response.body(),resultT); + return JSONObject.parseObject(response.body(), resultT); } @Override diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/JumpPageServiceImpl.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/JumpPageServiceImpl.java index b5012db..71bcc88 100644 --- a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/JumpPageServiceImpl.java +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/JumpPageServiceImpl.java @@ -26,6 +26,7 @@ import java.util.Set; @Service @AllArgsConstructor @Slf4j +@Deprecated public class JumpPageServiceImpl implements IJumpPageService { private final IFuncParamService paramService; diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/JumpRouteJoinStrategy.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/JumpRouteJoinStrategy.java index ddb6f69..b5b6b5f 100644 --- a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/JumpRouteJoinStrategy.java +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/JumpRouteJoinStrategy.java @@ -25,6 +25,7 @@ import java.util.stream.IntStream; */ @Component @RequiredArgsConstructor +@Deprecated public class JumpRouteJoinStrategy { private final IStationClient stationClient; diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/ParamAnswerResolveServiceImpl.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/ParamAnswerResolveServiceImpl.java new file mode 100644 index 0000000..e982d7f --- /dev/null +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/ParamAnswerResolveServiceImpl.java @@ -0,0 +1,23 @@ +package com.hnac.hzims.bigmodel.interactive.service.impl; + +import com.hnac.hzims.bigmodel.interactive.factory.AnswerResolveFactory; +import com.hnac.hzims.bigmodel.interactive.service.IAnswerResolveService; +import com.hnac.hzims.bigmodel.interactive.vo.AnswerVO; +import groovy.util.logging.Slf4j; +import lombok.AllArgsConstructor; +import org.springframework.stereotype.Service; + +/** + * @Author: huangxing + * @Date: 2024/06/21 19:02 + */ +@Service(AnswerResolveFactory.PARAM_ANSWER_SERVICE) +@Slf4j +@AllArgsConstructor +public class ParamAnswerResolveServiceImpl implements IAnswerResolveService { + + @Override + public AnswerVO resolve(AnswerVO answer) { + return null; + } +} diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/ParamStrategy.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/ParamStrategy.java index e84f616..67e49a0 100644 --- a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/ParamStrategy.java +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/ParamStrategy.java @@ -23,6 +23,7 @@ import java.util.Map; @Component @Slf4j @AllArgsConstructor +@Deprecated public class ParamStrategy { private final IStationVideoTypeClient videoClient; diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/ParamsServiceImpl.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/ParamsServiceImpl.java index dd462c6..7d134e1 100644 --- a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/ParamsServiceImpl.java +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/ParamsServiceImpl.java @@ -22,6 +22,7 @@ import java.util.Optional; @Service @Slf4j @AllArgsConstructor +@Deprecated public class ParamsServiceImpl implements IParamsService { private final ParamStrategy strategy; diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/RemoteAnswerResolveServiceImpl.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/RemoteAnswerResolveServiceImpl.java new file mode 100644 index 0000000..9ba5e42 --- /dev/null +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/RemoteAnswerResolveServiceImpl.java @@ -0,0 +1,23 @@ +package com.hnac.hzims.bigmodel.interactive.service.impl; + +import com.hnac.hzims.bigmodel.interactive.factory.AnswerResolveFactory; +import com.hnac.hzims.bigmodel.interactive.service.IAnswerResolveService; +import com.hnac.hzims.bigmodel.interactive.vo.AnswerVO; +import groovy.util.logging.Slf4j; +import lombok.AllArgsConstructor; +import org.springframework.stereotype.Service; + +/** + * @Author: huangxing + * @Date: 2024/06/21 19:02 + */ +@Service(AnswerResolveFactory.REMOTE_ANSWER_SERVICE) +@Slf4j +@AllArgsConstructor +public class RemoteAnswerResolveServiceImpl implements IAnswerResolveService { + + @Override + public AnswerVO resolve(AnswerVO answer) { + return null; + } +} diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/VideoResolveServiceImpl.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/VideoResolveServiceImpl.java new file mode 100644 index 0000000..3cdc225 --- /dev/null +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/VideoResolveServiceImpl.java @@ -0,0 +1,73 @@ +package com.hnac.hzims.bigmodel.interactive.service.impl; + +import com.alibaba.fastjson.JSON; +import com.hnac.hzims.bigmodel.interactive.constants.FuncRouteEnum; +import com.hnac.hzims.bigmodel.interactive.constants.FunctionConstants; +import com.hnac.hzims.bigmodel.interactive.factory.ResolveFactory; +import com.hnac.hzims.bigmodel.interactive.req.ModelFunctionReq; +import com.hnac.hzims.bigmodel.interactive.service.IResolveService; +import com.hnac.hzims.bigmodel.interactive.vo.ExtraVO; +import com.hnac.hzims.bigmodel.interactive.vo.ResolveResultVO; +import com.hnac.hzims.operational.station.entity.StationVideoTypeEntity; +import com.hnac.hzims.operational.station.feign.IStationVideoTypeClient; +import groovy.util.logging.Slf4j; +import lombok.AllArgsConstructor; +import org.springblade.core.log.exception.ServiceException; +import org.springblade.core.log.logger.BladeLogger; +import org.springblade.core.tool.api.R; +import org.springblade.core.tool.utils.Func; +import org.springblade.core.tool.utils.StringUtil; +import org.springframework.stereotype.Service; +import org.springframework.util.Assert; + +import java.util.HashMap; +import java.util.Map; + +/** + * @Author: huangxing + * @Date: 2024/06/21 16:17 + */ +@Service(ResolveFactory.VIDEO_RESOLVE_SERVICE) +@AllArgsConstructor +@Slf4j +public class VideoResolveServiceImpl implements IResolveService { + + private final IStationVideoTypeClient videoClient; + private final BladeLogger logger; + + @Override + public ResolveResultVO resolve(ModelFunctionReq req) { + Map args = req.getFunctionArgs(); + String id = args.get("id"); + String name = args.get("name"); + Assert.isTrue(StringUtil.isNotBlank(id) && StringUtil.isNotBlank(name),() -> { + logger.error("hzims:video:resolve","解析传参错误,缺少必要参数video_id,传参内容为:" + JSON.toJSONString(req)); + throw new ServiceException("解析传参错误,缺少必要参数video_id"); + }); + ExtraVO extra = this.resolve(Long.valueOf(id)); + String message = "已成功打开" + name + ";"; + return new ResolveResultVO(message,extra); + } + + @Override + public ExtraVO resolve(Long id) { + // 跳转页面逻辑 + ExtraVO extraVO = new ExtraVO(); + R videoR = videoClient.getById(Long.valueOf(id)); + if(videoR.isSuccess()) { + StationVideoTypeEntity video = videoR.getData(); + extraVO.setType(FunctionConstants.TypeEnum.PARAMS.getType()); + extraVO.setImmediatelyJump(true); + extraVO.setFuncCode(FuncRouteEnum.OPEN_VIDEO.getFuncCode()); + Map params = new HashMap<>(); + params.put("name", video.getName()); + params.put("videoHost", video.getVideoHost()); + params.put("pointCode", video.getPointCode()); + params.put("appKey", video.getAppKey()); + params.put("appSecret", video.getAppSecret()); + params.put("liveSourceAddress",video.getLiveSourceAddress()); + extraVO.setParams(params); + } + return extraVO; + } +} diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/vo/AnswerVO.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/vo/AnswerVO.java index 29baf54..e4b9e1c 100644 --- a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/vo/AnswerVO.java +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/vo/AnswerVO.java @@ -1,8 +1,10 @@ package com.hnac.hzims.bigmodel.interactive.vo; import com.alibaba.fastjson.annotation.JSONField; +import com.hnac.hzims.bigmodel.interactive.constants.InfoMessageConstant; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; +import lombok.AllArgsConstructor; import lombok.Data; import lombok.EqualsAndHashCode; import org.springblade.core.tool.utils.BeanUtil; @@ -16,6 +18,7 @@ import java.io.Serializable; @Data @ApiModel("HZLLM答案VO对象") @EqualsAndHashCode +@AllArgsConstructor public class AnswerVO implements Serializable { @ApiModelProperty("发起问答时的随机ID") @@ -56,6 +59,10 @@ public class AnswerVO implements Serializable { @JSONField(name = "voice_answer") private String[] voiceAnswer; + public static AnswerVO error(String sessionId,String userId,String query) { + return new AnswerVO(sessionId,userId,0,-2,null,query, InfoMessageConstant.ERROR_MESSAGE, null,null,new String[]{InfoMessageConstant.ERROR_MESSAGE}); + } + public static void error(AnswerVO usualVO) { usualVO.setRunning(0); usualVO.setStatus(-2); diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/vo/ResolveResultVO.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/vo/ResolveResultVO.java new file mode 100644 index 0000000..f24b67e --- /dev/null +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/vo/ResolveResultVO.java @@ -0,0 +1,29 @@ +package com.hnac.hzims.bigmodel.interactive.vo; + +import com.hnac.hzims.bigmodel.interactive.constants.InfoMessageConstant; +import io.swagger.annotations.ApiModel; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.EqualsAndHashCode; + +import java.io.Serializable; + +/** + * @Author: huangxing + * @Date: 2024/06/21 16:31 + */ +@EqualsAndHashCode +@Data +@AllArgsConstructor +@ApiModel(value = "解析结果",description = "解析结果") +public class ResolveResultVO implements Serializable { + + private String content; + + private ExtraVO extraVO; + + public static ResolveResultVO error() { + return new ResolveResultVO(InfoMessageConstant.ERROR_MESSAGE,null); + } + +} diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/manager/SessionRedisManager.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/manager/SessionRedisManager.java new file mode 100644 index 0000000..decbf60 --- /dev/null +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/manager/SessionRedisManager.java @@ -0,0 +1,28 @@ +package com.hnac.hzims.bigmodel.manager; + +import lombok.AllArgsConstructor; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.redis.core.RedisTemplate; +import org.springframework.stereotype.Component; + +import static com.hnac.hzims.bigmodel.schedule.XxlJobHandlerConstant.HZIMS_BIGMODEL_ASK_KEY; + +/** + * @Author: huangxing + * @Date: 2024/06/21 18:23 + */ +@Component +public class SessionRedisManager { + + @Autowired + private RedisTemplate redisTemplate; + + public void addSessionId(String sessionId) { + redisTemplate.opsForList().leftPush(HZIMS_BIGMODEL_ASK_KEY,sessionId); + } + + public void removeSessionId(String sessionId) { + redisTemplate.opsForList().remove(HZIMS_BIGMODEL_ASK_KEY,1,sessionId); + } + +} diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/utils/RequestClientUtil.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/utils/RequestClientUtil.java new file mode 100644 index 0000000..d49dc3c --- /dev/null +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/utils/RequestClientUtil.java @@ -0,0 +1,48 @@ +package com.hnac.hzims.bigmodel.utils; + +import cn.hutool.http.HttpRequest; +import cn.hutool.http.HttpResponse; +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONObject; +import groovy.util.logging.Slf4j; +import org.springblade.core.log.exception.ServiceException; +import org.springframework.util.Assert; + +import javax.servlet.http.HttpServletResponse; +import java.util.Map; + +/** + * @Author: huangxing + * @Date: 2024/06/21 17:12 + */ +public class RequestClientUtil { + + /** + * 无返回结果远程调用http接口 + * @param url 接口url + * @param body 传参body + */ + public static void postCall(String url, Map body) { + HttpResponse response = HttpRequest.post(url).body(JSON.toJSONString(body)).execute(); + Assert.isTrue(response.getStatus() == HttpServletResponse.SC_OK, () -> { + throw new ServiceException("远程调用大模型接口" + url + "失败!"); + }); + } + + /** + * 远程调用http接口 + * @param url 接口url + * @param body 传参 + * @param resultT 结果解析对象 + * @return 结果 + * @param 结果解析对象类型 + */ + public static T postCall(String url, Map body, Class resultT) { + HttpResponse response = HttpRequest.post(url).body(JSON.toJSONString(body)).execute(); + Assert.isTrue(response.getStatus() == HttpServletResponse.SC_OK, () -> { + throw new ServiceException("远程调用大模型接口" + url + "失败!"); + }); + return JSONObject.parseObject(response.body(), resultT); + } + +}