From 9873e843d5a13cf7d36635aa8fad5ddc49edd09a Mon Sep 17 00:00:00 2001 From: haungxing <1203316822@qq.com> Date: Wed, 8 May 2024 17:28:46 +0800 Subject: [PATCH] =?UTF-8?q?add:=E6=99=BA=E8=83=BD=E8=AF=8A=E6=96=AD?= =?UTF-8?q?=E9=A1=B5=E9=9D=A2=E8=B7=B3=E8=BD=AC=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../hzims/bigmodel/interactive/vo/ExtraVO.java | 2 +- .../interactive/constants/ExtraTypeEnum.java | 20 +++++++++ .../interactive/constants/FuncRouteEnum.java | 1 + .../service/impl/ExtraResolveStrategyService.java | 51 ++++++++++++++++++++++ .../service/impl/InteractiveServiceImpl.java | 9 ++++ .../service/impl/JumpRouteJoinStrategy.java | 1 + 6 files changed, 83 insertions(+), 1 deletion(-) create mode 100644 hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/constants/ExtraTypeEnum.java create mode 100644 hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/ExtraResolveStrategyService.java diff --git a/hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/interactive/vo/ExtraVO.java b/hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/interactive/vo/ExtraVO.java index 303a21e..c736e30 100644 --- a/hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/interactive/vo/ExtraVO.java +++ b/hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/interactive/vo/ExtraVO.java @@ -14,7 +14,7 @@ import java.io.Serializable; @ApiModel("响应内容") public class ExtraVO implements Serializable { - @ApiModelProperty("交互类型") + @ApiModelProperty("交互类型 1:打开页面,2:打开链接") private String type; @ApiModelProperty("若为弹窗,则返回路由") diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/constants/ExtraTypeEnum.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/constants/ExtraTypeEnum.java new file mode 100644 index 0000000..96a4661 --- /dev/null +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/constants/ExtraTypeEnum.java @@ -0,0 +1,20 @@ +package com.hnac.hzims.bigmodel.interactive.constants; + +import lombok.AllArgsConstructor; +import lombok.Getter; + +/** + * @Author: huangxing + * @Date: 2024/05/08 16:49 + */ +@AllArgsConstructor +public enum ExtraTypeEnum { + /**打开页面**/ + OPEN_PAGE("1"), + /**链接**/ + LINK("2") + ; + @Getter + private final String type; + +} diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/constants/FuncRouteEnum.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/constants/FuncRouteEnum.java index 4d51364..7419128 100644 --- a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/constants/FuncRouteEnum.java +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/constants/FuncRouteEnum.java @@ -14,6 +14,7 @@ import java.util.Optional; public enum FuncRouteEnum { OPEN_SCADA("open_scada","打开实时画面"), OPEN_VIDEO("open_video","打开视频监控"), + DIAGNOSE("diagnose","智能诊断") ; @Getter private String funcCode; 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 new file mode 100644 index 0000000..ddd33ea --- /dev/null +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/ExtraResolveStrategyService.java @@ -0,0 +1,51 @@ +package com.hnac.hzims.bigmodel.interactive.service.impl; + +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONObject; +import com.hnac.hzims.bigmodel.interactive.constants.ExtraTypeEnum; +import com.hnac.hzims.bigmodel.interactive.constants.FuncRouteEnum; +import com.hnac.hzims.bigmodel.interactive.vo.ExtraVO; +import org.springblade.core.tool.utils.StringUtil; +import org.springframework.stereotype.Service; + +import java.util.Map; +import java.util.Optional; + +/** + * @Author: huangxing + * @Date: 2024/05/08 16:19 + */ +@Service +public class ExtraResolveStrategyService { + + /** + * 解析DFP返回extra + * @param extraStr DFP返回extra + * @return 与前端交互extra + */ + public ExtraVO resolve(String extraStr) { + JSONObject extra = JSONObject.parseObject(extraStr); + String functionCode = Optional.ofNullable(extra.get("func")).map(String::valueOf).orElse(""); + if(StringUtil.isNotBlank(functionCode)) { + FuncRouteEnum funcRouteEnum = FuncRouteEnum.getEnumByFuncCode(functionCode); + switch (funcRouteEnum) { + case DIAGNOSE: + return this.resolveDiagnose(extra); + default: + break; + } + } + return JSONObject.parseObject(JSON.toJSONString(extra),ExtraVO.class); + } + + private ExtraVO resolveDiagnose(Map extra) { + ExtraVO result = new ExtraVO(); + JSONObject data = JSONObject.parseObject(JSON.toJSONString(extra.get("data"))); + String faultId = data.getString("fault_id"); + String faultName = data.getString("fault_name"); + result.setLabel(faultName); + // TODO 拼接诊断链接 + result.setType(ExtraTypeEnum.LINK.getType()); + 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 de8c3ac..7a44495 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 @@ -12,6 +12,7 @@ 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; @@ -19,6 +20,7 @@ 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; @@ -64,6 +66,8 @@ public class InteractiveServiceImpl implements IInteractiveService { private final RedisTemplate redisTemplate; + private final ExtraResolveStrategyService extraResolveStrategyService; + @Value("${fdp.host}") private String fdpHost; @@ -125,6 +129,11 @@ public class InteractiveServiceImpl implements IInteractiveService { Assert.isTrue(response.getStatus() == HttpServletResponse.SC_OK, () -> { throw new ServiceException("远程调用大模型【获取问题答案】接口失败!"); }); + 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()); + answerVO.setExtra(extraList.toArray(new String[extraList.size()])); + }); return JSONArray.parseArray(response.body(),AnswerVO.class); } 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 31ad197..b3e2fdf 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 @@ -48,6 +48,7 @@ public class JumpRouteJoinStrategy { private ExtraVO getScadaExtra(Map args,FunctionEntity function) { // 跳转页面逻辑 ExtraVO extraVO = new ExtraVO(); + Map params = this.scadaResolve(args); // 根据hz3000画面版本获取path Integer picResource = Integer.valueOf(params.get("picResource"));