diff --git a/hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/entity/FuncParamEntity.java b/hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/entity/FuncParamEntity.java index 99e55ed..a456ee3 100644 --- a/hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/entity/FuncParamEntity.java +++ b/hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/entity/FuncParamEntity.java @@ -9,6 +9,8 @@ import org.springblade.core.mp.support.SqlCondition; import org.springblade.core.tenant.mp.TenantEntity; import javax.validation.constraints.Max; +import javax.validation.constraints.NotBlank; +import javax.validation.constraints.NotNull; import javax.validation.constraints.Size; /** @@ -22,17 +24,20 @@ public class FuncParamEntity extends TenantEntity { @ApiModelProperty(value = "函数表主键ID") @QueryField(condition = SqlCondition.EQUAL) - @Max(20) + @NotNull private Long funcId; @ApiModelProperty("参数名称") @QueryField(condition = SqlCondition.LIKE) - @Size(min = 1,max = 50) + @NotBlank private String name; @ApiModelProperty(value = "参数别名,传参参数") @QueryField(condition = SqlCondition.EQUAL) - @Size(min = 1,max = 25) private String alias; + @ApiModelProperty(value = "是否必须") + @QueryField(condition = SqlCondition.EQUAL) + private Boolean isRequire; + } diff --git a/hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/entity/FunctionEntity.java b/hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/entity/FunctionEntity.java index af01299..dd6ba36 100644 --- a/hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/entity/FunctionEntity.java +++ b/hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/entity/FunctionEntity.java @@ -42,4 +42,7 @@ public class FunctionEntity extends TenantEntity { @ApiModelProperty("描述") private String remake; + @ApiModelProperty("路由") + private String route; + } 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 new file mode 100644 index 0000000..11ef13c --- /dev/null +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/constants/FuncRouteEnum.java @@ -0,0 +1,27 @@ +package com.hnac.hzims.bigmodel.interactive.constants; + +import lombok.AllArgsConstructor; +import lombok.Getter; + +import java.util.Arrays; +import java.util.Optional; + +/** + * @Author: huangxing + * @Date: 2024/04/30 11:41 + */ +@AllArgsConstructor +public enum FuncRouteEnum { + OPEN_SCADA("open_scada","打开实时画面"), + ; + @Getter + private String funcCode; + @Getter + private String funcName; + + public static FuncRouteEnum getEnumByFuncCode(String funcCode) { + Optional FuncRoute = Arrays.stream(FuncRouteEnum.class.getEnumConstants()).filter(e -> funcCode.equals(e.getFuncCode())).findFirst(); + return FuncRoute.get(); + } + +} 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 41f3885..9c6e453 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 @@ -42,4 +42,13 @@ public class InteractiveController { return interactiveService.ask(request, question); } + @ApiOperation("站点、菜单鉴权") + @ApiOperationSupport(order = 3) + @GetMapping("/authentication") + public R authentication(@RequestParam(required = false) @ApiParam("站点编号") String stationId, + @RequestParam @ApiParam("用户ID") String userId, + @RequestParam(required = false) @ApiParam("菜单ID") String menuId) { + return R.status(interactiveService.authentication(stationId,userId,menuId)); + } + } 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 3fe695e..7916509 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 @@ -17,4 +17,6 @@ public interface IInteractiveService { R ask(HttpServletRequest request, String question); + Boolean authentication(String stationId, String userId, String menuId); + } 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 1a2b719..8ad00e6 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 @@ -58,7 +58,7 @@ public class InteractiveServiceImpl implements IInteractiveService { Assert.isTrue(StringUtil.isNotBlank(extra) && Func.isNotEmpty(extra), () -> { throw new ServiceException("解析" + function.getName() + "函数失败!"); }); - R.data(extra); + return R.data(extra); default: throw new ServiceException("函数解析失败!"); } @@ -82,4 +82,10 @@ public class InteractiveServiceImpl implements IInteractiveService { return R.data(JSONObject.parseObject(response.body()).getString("data")); } + @Override + public Boolean authentication(String stationId, String userId, String menuId) { + //TODO 鉴权逻辑完善 + return true; + } + } 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 2c95d1c..dafcf7f 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 @@ -29,25 +29,17 @@ import java.util.Set; public class JumpPageServiceImpl implements IJumpPageService { private final IFuncParamService paramService; + private final JumpRouteJoinStrategy strategy; @Override public String dealJumpTypeFunction(FunctionEntity function,Map args) { List params = paramService.getParamsByFuncId(function.getId()); - Optional paramOptional = params.stream().filter(p -> !args.containsKey(p)).findAny(); + Optional paramOptional = params.stream().filter(p -> p.getIsRequire()).filter(p -> !args.containsKey(p.getAlias())).findAny(); Assert.isTrue(!paramOptional.isPresent(), () -> { throw new ServiceException("解析参数失败,缺少参数:" + paramOptional.get().getName()); }); // 跳转页面逻辑 - ExtraVO extraVO = new ExtraVO(); - String path = function.getPath(); - Set> entries = args.entrySet(); - // 替换path中变量 - for (Map.Entry entry : entries) { - String replaceVariables = "{" + entry.getKey() + "}"; - path = StringUtil.replace(path,replaceVariables,entry.getValue()); - } - extraVO.setType(FunctionConstants.TypeEnum.JUMP.getType()); - extraVO.setRoute(path); + ExtraVO extraVO = strategy.resolve(function,args); // TODO 将结果存入redis中供前端获取 return JSON.toJSONString(extraVO); } 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 new file mode 100644 index 0000000..11e0cd4 --- /dev/null +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/JumpRouteJoinStrategy.java @@ -0,0 +1,134 @@ +package com.hnac.hzims.bigmodel.interactive.service.impl; + +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONObject; +import com.hnac.hzims.bigmodel.entity.FunctionEntity; +import com.hnac.hzims.bigmodel.interactive.constants.FuncRouteEnum; +import com.hnac.hzims.bigmodel.interactive.constants.FunctionConstants; +import com.hnac.hzims.bigmodel.interactive.vo.ExtraVO; +import org.springblade.core.log.exception.ServiceException; +import org.springblade.core.tool.utils.Func; +import org.springblade.core.tool.utils.StringUtil; +import org.springframework.stereotype.Component; +import org.springframework.util.Assert; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Set; + +/** + * @Author: huangxing + * @Date: 2024/04/30 11:38 + */ +@Component +public class JumpRouteJoinStrategy { + + /** + * 解析大模型传参 + * @param args 大模型传参 + * @return 跳转path所需要的参数 + */ + public ExtraVO resolve(FunctionEntity function,Map args) { + FuncRouteEnum routeEnum = FuncRouteEnum.getEnumByFuncCode(function.getCode()); + if(Func.isNotEmpty(routeEnum)) { + switch(routeEnum) { + case OPEN_SCADA: + return this.getScadaExtra(args,function); + default: + break; + } + } + return null; + } + + 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")); + JSONObject pathObject = JSONObject.parseObject(function.getPath()); + // 云组态 + if(picResource == 0) { + String scada = pathObject.getString("scada"); + extraVO.setRoute(this.replacePath(scada, params)); + extraVO.setRoute(scada); + } + // v3.0 + else if (picResource == 1) { + String v3 = pathObject.getString("v3"); + extraVO.setRoute(this.replacePath(v3, params)); + } + // v4.0 + else if (picResource == 2) { + String v4 = pathObject.getString("v4"); + // pic_name 去掉头部的/ 以及尾部的.js + String context = params.get("context"); + context = this.removeHeadChars(context,"/"); + context = this.removeTailChars(context,".js"); + params.put("context",context); + extraVO.setRoute(this.replacePath(v4, params)); + } + else { + throw new ServiceException("解析出来的画面类型在云组态、v3、v4类型之外,无法解析路由"); + } + extraVO.setType(FunctionConstants.TypeEnum.JUMP.getType()); + return extraVO; + } + + /** + * 打开实时画面 + * @param args 大模型解析参数 + * @return 实时画面路径拼接所需参数 + */ + private Map scadaResolve(Map args) { + Map result = new HashMap<>(); + Assert.isTrue(args.containsKey("params"), () -> { + throw new ServiceException("大模型传参缺少params参数"); + }); + // 参数格式为:picResource^context^stationNum^projectId^taskId^name^id + List params = Func.toStrList("\\^", args.get("params")); + Assert.isTrue(params.size() == 7,() -> { + throw new ServiceException("大模型传参params长度错误,传参为:" + args.get("params")); + }); + result.put("picResource",params.get(0)); + result.put("context",params.get(1)); + result.put("stationNum",params.get(2)); + result.put("projectId",params.get(3)); + result.put("taskId",params.get(4)); + result.put("name",params.get(5)); + result.put("id",params.get(6)); + return result; + } + + private String replacePath(String path,Map params) { + Set> entries = params.entrySet(); + // 替换path中变量 + for (Map.Entry entry : entries) { + String replaceVariables = "{" + entry.getKey() + "}"; + path = StringUtil.replace(path,replaceVariables,entry.getValue()); + } + return path; + } + + public String removeHeadChars(String str, String charsToRemove) { + if (str == null || charsToRemove == null || charsToRemove.isEmpty()) { + return str; + } + while (str.startsWith(charsToRemove)) { + str = str.substring(charsToRemove.length()); + } + return str; + } + + public String removeTailChars(String str, String charsToRemove) { + if (str == null || charsToRemove == null || charsToRemove.isEmpty()) { + return str; + } + while (str.endsWith(charsToRemove)) { + str = str.substring(0, str.length() - charsToRemove.length()); + } + return str; + } +} 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 b50c578..771cfd5 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 @@ -37,6 +37,8 @@ public class InteractiveSchedule { String resultKey = ParamCache.getValue(GET_INTERACTIVE_RESULT); Set keySet = redisTemplate.keys(resultKey + "*"); keySet.parallelStream().forEach(key -> { + //TODO 保存问题结果 + // 根据Key获取sessionId List keySplits = Func.toStrList(":", key); String sessionId = keySplits.get(2); diff --git a/hzims-service/hzims-big-model/src/main/resources/db/1.0.0.sql b/hzims-service/hzims-big-model/src/main/resources/db/1.0.0.sql index 2a0cf7e..200900c 100644 --- a/hzims-service/hzims-big-model/src/main/resources/db/1.0.0.sql +++ b/hzims-service/hzims-big-model/src/main/resources/db/1.0.0.sql @@ -31,4 +31,7 @@ CREATE TABLE IF NOT EXISTS `hzims_func_param` ( `UPDATE_TIME` datetime DEFAULT NULL COMMENT '更新时间', `IS_DELETED` tinyint(4) NOT NULL COMMENT '是否删除', PRIMARY KEY (`ID`) USING BTREE - ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin COMMENT='模型函数参数'; \ No newline at end of file +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin COMMENT='模型函数参数'; + +alter table `HZIMS_FUNCTION` add column `ROUTE` varchar(100) default null comment '菜单路由'; +alter table `HZIMS_FUNC_PARAM` add column `IS_REQUIRE` TINYINT(2) default 0 comment '是否必须'; \ No newline at end of file