From 4600e749452dd1ba9462eb10a557bdf0dc740c41 Mon Sep 17 00:00:00 2001 From: haungxing <1203316822@qq.com> Date: Tue, 9 Jul 2024 18:59:45 +0800 Subject: [PATCH] =?UTF-8?q?fix=EF=BC=9A=E5=A4=A7=E6=A8=A1=E5=9E=8B?= =?UTF-8?q?=E4=BB=A3=E7=A0=81=E6=9E=B6=E6=9E=84=E4=BF=AE=E6=94=B9=20add:?= =?UTF-8?q?=E5=A4=A7=E6=A8=A1=E5=9E=8B=E6=95=B0=E6=8D=AE=E6=BA=90=E4=BF=A1?= =?UTF-8?q?=E6=81=AF=E7=BB=B4=E6=8A=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../business/dto/ControlDeviceAuthDTO.java | 23 ++ .../hzims/bigmodel/business/feign/IAuthClient.java | 35 ++ .../hzims/bigmodel/interactive/dto/ControlDTO.java | 36 ++ .../bigmodel/interactive/dto/ControlDeviceDTO.java | 38 ++ .../bigmodel/interactive/req/ModelFunctionReq.java | 15 +- .../hzims/bigmodel/interactive/vo/ExtraVO.java | 6 + .../hzims/bigmodel/business/feign/AuthClient.java | 51 +++ .../business/service/AuthenticationService.java | 124 ++++++ .../datasource/service/DataSourceService.java | 1 + .../interactive/constants/FuncRouteEnum.java | 5 +- .../controller/AnalyseDataController.java | 34 -- .../controller/FontEndInteractiveController.java | 11 +- .../controller/HznlmInteractiveController.java | 10 +- .../controller/InteractiveController.java | 116 ------ .../service/IHznlmInteractiveService.java | 6 +- .../interactive/service/IHznlmInvokeService.java | 6 +- .../interactive/service/IParamsService.java | 15 - .../service/impl/AnalyseDataServiceImpl.java | 13 +- .../service/impl/AuthenticationService.java | 128 ------ .../service/impl/CanvasResolveServiceImpl.java | 14 +- .../service/impl/ExtraResolveStrategyService.java | 259 ------------- .../service/impl/HznlmInteractiveServiceImpl.java | 35 +- .../service/impl/HznlmInvokeServiceImpl.java | 21 +- .../service/impl/InteractiveServiceImpl.java | 430 --------------------- .../service/impl/JumpPageServiceImpl.java | 46 --- .../service/impl/JumpRouteJoinStrategy.java | 3 +- .../interactive/service/impl/ParamStrategy.java | 2 +- .../service/impl/ParamsServiceImpl.java | 36 -- .../service/impl/VideoResolveServiceImpl.java | 10 +- .../controller/DataSourceController.java | 67 ++++ .../controller/TableColumnController.java | 14 +- .../controller/TablePropertyController.java | 66 ++++ .../maintenance/entity/DatasourceEntity.java | 33 ++ .../maintenance/entity/TablePropertyEntity.java | 49 +++ .../maintenance/mapper/DatasourceMapper.java | 12 + .../maintenance/mapper/TablePropertyMapper.java | 11 + .../maintenance/service/DataSourceService.java | 19 + .../maintenance/service/TableColumnService.java | 18 +- .../maintenance/service/TablePropertyService.java | 20 + .../bigmodel/schedule/InteractiveSchedule.java | 201 ---------- .../websocket/handler/InteractiveHandler.java | 15 +- .../src/main/resources/db/2.0.0.sql | 31 ++ 42 files changed, 735 insertions(+), 1350 deletions(-) create mode 100644 hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/business/dto/ControlDeviceAuthDTO.java create mode 100644 hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/business/feign/IAuthClient.java create mode 100644 hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/interactive/dto/ControlDTO.java create mode 100644 hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/interactive/dto/ControlDeviceDTO.java create mode 100644 hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/business/feign/AuthClient.java create mode 100644 hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/business/service/AuthenticationService.java delete mode 100644 hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/controller/AnalyseDataController.java delete mode 100644 hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/controller/InteractiveController.java delete mode 100644 hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/IParamsService.java delete mode 100644 hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/AuthenticationService.java delete mode 100644 hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/ExtraResolveStrategyService.java delete mode 100644 hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/InteractiveServiceImpl.java delete mode 100644 hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/JumpPageServiceImpl.java delete mode 100644 hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/ParamsServiceImpl.java create mode 100644 hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/maintenance/controller/DataSourceController.java create mode 100644 hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/maintenance/controller/TablePropertyController.java create mode 100644 hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/maintenance/entity/DatasourceEntity.java create mode 100644 hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/maintenance/entity/TablePropertyEntity.java create mode 100644 hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/maintenance/mapper/DatasourceMapper.java create mode 100644 hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/maintenance/mapper/TablePropertyMapper.java create mode 100644 hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/maintenance/service/DataSourceService.java create mode 100644 hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/maintenance/service/TablePropertyService.java delete mode 100644 hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/schedule/InteractiveSchedule.java create mode 100644 hzims-service/hzims-big-model/src/main/resources/db/2.0.0.sql diff --git a/hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/business/dto/ControlDeviceAuthDTO.java b/hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/business/dto/ControlDeviceAuthDTO.java new file mode 100644 index 0000000..b64fc69 --- /dev/null +++ b/hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/business/dto/ControlDeviceAuthDTO.java @@ -0,0 +1,23 @@ +package com.hnac.hzims.bigmodel.business.dto; + +import com.hnac.hzims.bigmodel.interactive.dto.ControlDeviceDTO; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.EqualsAndHashCode; + +import java.io.Serializable; + +/** + * @Author: huangxing + * @Date: 2024/07/09 09:43 + */ +@Data +@EqualsAndHashCode +@ApiModel(value = "遥控设备鉴权DTO",description = "遥控设备鉴权DTO") +public class ControlDeviceAuthDTO extends ControlDeviceDTO implements Serializable { + + @ApiModelProperty("用户ID") + private String userId; + +} diff --git a/hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/business/feign/IAuthClient.java b/hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/business/feign/IAuthClient.java new file mode 100644 index 0000000..e4764e7 --- /dev/null +++ b/hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/business/feign/IAuthClient.java @@ -0,0 +1,35 @@ +package com.hnac.hzims.bigmodel.business.feign; + +import com.hnac.hzims.bigmodel.business.dto.ControlDeviceAuthDTO; +import org.springblade.core.tool.api.R; + +/** + * @Author: huangxing + * @Date: 2024/07/09 09:11 + * 鉴权接口 - 业务实现 + */ +public interface IAuthClient { + + /** + * 遥控鉴权 + * @param req 遥控信息 + * @return 鉴权结果 + */ + R remoteAuth(ControlDeviceAuthDTO req); + + /** + * 站点鉴权 + * @param userId 用户ID + * @param stationId 站点ID + * @return 鉴权结果 + */ + R stationAuth(String userId,String stationId); + + /** + * 机构鉴权 + * @param userId 用户ID + * @param deptId 站点ID + * @return 鉴权结果 + */ + R deptAuth(String userId,String deptId); +} diff --git a/hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/interactive/dto/ControlDTO.java b/hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/interactive/dto/ControlDTO.java new file mode 100644 index 0000000..bc28e67 --- /dev/null +++ b/hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/interactive/dto/ControlDTO.java @@ -0,0 +1,36 @@ +package com.hnac.hzims.bigmodel.interactive.dto; + +import com.alibaba.fastjson.annotation.JSONField; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.EqualsAndHashCode; + +import javax.validation.constraints.NotBlank; +import java.io.Serializable; +import java.util.List; + +/** + * @Author: huangxing + * @Date: 2024/07/08 09:20 + */ +@ApiModel("设备控制DTO") +@Data +@EqualsAndHashCode +public class ControlDTO implements Serializable { + + @ApiModelProperty("用户ID") + @NotBlank + private String userId; + + @ApiModelProperty("会话ID") + @NotBlank + private String chatId; + + @ApiModelProperty("value目前有值、'大' '小' '最大' '最小' ‘开’ '关'") + private String value; + + @ApiModelProperty("遥控点位") + private List yks; + +} diff --git a/hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/interactive/dto/ControlDeviceDTO.java b/hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/interactive/dto/ControlDeviceDTO.java new file mode 100644 index 0000000..40e3516 --- /dev/null +++ b/hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/interactive/dto/ControlDeviceDTO.java @@ -0,0 +1,38 @@ +package com.hnac.hzims.bigmodel.interactive.dto; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.EqualsAndHashCode; + +import javax.validation.constraints.NotBlank; +import java.io.Serializable; + +/** + * @Author: huangxing + * @Date: 2024/07/08 16:22 + */ +@Data +@ApiModel(value = "",description = "") +@EqualsAndHashCode +public class ControlDeviceDTO implements Serializable { + + @ApiModelProperty(value = "站点ID") + private String stationId; + + @ApiModelProperty(value = "设备ID") + @NotBlank + private String deviceId; + + @ApiModelProperty(value = "控制ID") + @NotBlank + private String itemId; + + @ApiModelProperty(value = "控制名称") + private String itemName; + + @ApiModelProperty(value = "遥控类型,平台、业务") + @NotBlank + private String type; + +} diff --git a/hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/interactive/req/ModelFunctionReq.java b/hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/interactive/req/ModelFunctionReq.java index a1fe20c..3977291 100644 --- a/hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/interactive/req/ModelFunctionReq.java +++ b/hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/interactive/req/ModelFunctionReq.java @@ -16,15 +16,16 @@ import java.util.Map; @ApiModel("大模型响应内容") public class ModelFunctionReq implements Serializable { - @ApiModelProperty("类型") - private String type; - - @JSONField(name = "function_name") @ApiModelProperty("函数标识") - private String functionName; + private String func; + + @ApiModelProperty("会话ID") + private String chatId; + + @ApiModelProperty("用户ID") + private String userId; - @JSONField(name = "function_args") @ApiModelProperty("函数参数") - private Map functionArgs; + private Map item; } 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 d01b6e6..c864829 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 @@ -1,6 +1,8 @@ package com.hnac.hzims.bigmodel.interactive.vo; import com.alibaba.fastjson.annotation.JSONField; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonInclude; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; import lombok.Data; @@ -21,9 +23,11 @@ public class ExtraVO implements Serializable { private String type; @ApiModelProperty("若为弹窗,则返回路由") + @JsonInclude(JsonInclude.Include.NON_NULL) private String route; @ApiModelProperty("链接显示文字") + @JsonInclude(JsonInclude.Include.NON_NULL) private String label; @ApiModelProperty("函数编号") @@ -33,12 +37,14 @@ public class ExtraVO implements Serializable { private boolean isImmediatelyJump = false; @ApiModelProperty("附带参数") + @JsonInclude(JsonInclude.Include.NON_NULL) private Map params; @ApiModelProperty("是否为特殊函数") private boolean isSpecial; @ApiModelProperty("选项") + @JsonInclude(JsonInclude.Include.NON_NULL) private List selection; @JSONField(name = "agent_name") diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/business/feign/AuthClient.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/business/feign/AuthClient.java new file mode 100644 index 0000000..91ec809 --- /dev/null +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/business/feign/AuthClient.java @@ -0,0 +1,51 @@ +package com.hnac.hzims.bigmodel.business.feign; + +import com.hnac.hzims.bigmodel.business.dto.ControlDeviceAuthDTO; +import com.hnac.hzims.bigmodel.business.service.AuthenticationService; +import lombok.AllArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springblade.core.tool.api.R; +import org.springblade.core.tool.utils.StringUtil; +import org.springblade.system.dto.DeptStationDTO; +import org.springframework.stereotype.Component; + +import java.util.List; +import java.util.Optional; + +/** + * @Author: huangxing + * @Date: 2024/07/09 09:31 + */ +@Component +@AllArgsConstructor +@Slf4j +public class AuthClient implements IAuthClient { + + private final AuthenticationService authenticationService; + + @Override + public R remoteAuth(ControlDeviceAuthDTO req) { + // 若站点不为空 则对站点进行鉴权 + if(StringUtil.isNotBlank(req.getStationId())) { + if(!authenticationService.stationAuthentication(req.getStationId(), req.getUserId())) { + return R.fail("站点鉴权失败!"); + } + } + if("业务".equals(req.getType())) { + + } + return R.success("鉴权成功"); + } + + @Override + public R stationAuth(String userId, String stationId) { + return R.status(authenticationService.stationAuthentication(stationId,userId)); + } + + @Override + public R deptAuth(String userId, String deptId) { + List deptStationDTOList = authenticationService.getStationPermissionsById(userId); + boolean result = deptStationDTOList.stream().map(DeptStationDTO::getDeptId).anyMatch(d -> Long.valueOf(deptId).equals(d)); + return R.status(result); + } +} diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/business/service/AuthenticationService.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/business/service/AuthenticationService.java new file mode 100644 index 0000000..f8e23a0 --- /dev/null +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/business/service/AuthenticationService.java @@ -0,0 +1,124 @@ +package com.hnac.hzims.bigmodel.business.service; + +import com.google.common.collect.Lists; +import com.hnac.hzims.bigmodel.entity.FunctionEntity; +import com.hnac.hzims.bigmodel.function.service.IFunctionService; +import com.hnac.hzims.bigmodel.interactive.constants.ProjectRemoteTypeEnum; +import com.hnac.hzims.bigmodel.interactive.vo.SessionContentVO; +import com.hnac.hzims.bigmodel.websocket.constants.RedisKeyConstants; +import com.hnac.hzinfo.sdk.core.response.Result; +import com.hnac.hzinfo.sdk.v5.project.ProjectClient; +import com.hnac.hzinfo.sdk.v5.project.vo.ProjectVO; +import lombok.AllArgsConstructor; +import org.springblade.core.log.exception.ServiceException; +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.springblade.system.entity.CtrlAuth; +import org.springblade.system.feign.IDeptClient; +import org.springblade.system.feign.IRemoteClient; +import org.springblade.system.user.feign.IUserClient; +import org.springframework.data.redis.core.RedisTemplate; +import org.springframework.stereotype.Service; +import org.springframework.util.Assert; + +import java.util.List; +import java.util.Optional; +import java.util.stream.Collectors; + +/** + * @Author: huangxing + * @Date: 2024/05/21 16:10 + */ +@Service +@AllArgsConstructor +public class AuthenticationService { + + private final IDeptClient deptClient; + private final IFunctionService functionService; + private final IUserClient userClient; + private final ProjectClient projectClient; + private final IRemoteClient remoteClient; + private final RedisTemplate redisTemplate; + + /** + * 站点鉴权 + * @param stationId 站点ID + * @param userId 用户ID + */ + public Boolean stationAuthentication(String stationId, String userId) { + List deptStationDTOList = this.getStationPermissionsById(userId); + return deptStationDTOList.stream().map(DeptStationDTO::getStationId).anyMatch(s -> stationId.equals(s)); + } + + /** + * 菜单鉴权 + * @param userId 用户ID + * @param func 函数编号 + */ + public void menuAuthentication(String userId, String func) { + FunctionEntity function = functionService.getFunctionByCode(func); + if(Func.isNotEmpty(function) && Func.isNotEmpty(function.getRoute()) && StringUtil.isNotBlank(function.getRoute())) { + R authenticationR = userClient.permissionMenuById(Long.valueOf(userId), function.getRoute()); + Assert.isTrue(authenticationR.isSuccess() && authenticationR.getData(), () -> { + throw new ServiceException("人员菜单鉴权失败!"); + }); + } + } + + /** + * 遥控鉴权 + * @param stationId 站点ID + * @param userId 用户ID + */ + public void remoteAuthentication(String stationId, String userId,String sessionId) { + // 查询数据平台站点是否可被遥控 + Result> projectR = projectClient.getProjectIds(Lists.newArrayList(stationId)); + Assert.isTrue(projectR.isSuccess() && CollectionUtil.isNotEmpty(projectR.getData()) && projectR.getData().size() == 1,() -> { + throw new ServiceException("未查询到站点,鉴权失败!"); + }); + ProjectVO project = projectR.getData().get(0); + if(ProjectRemoteTypeEnum.NOT_ALLOW.getCtrlType().equals(project.getCtrlType())) { + // 不允许发送遥控 + throw new ServiceException("该站点不允许发送遥控指令,校验失败!"); + } + else if(ProjectRemoteTypeEnum.VALID.getCtrlType().equals(project.getCtrlType())) { + // 运行发送遥控并且需要校验权限 + R> ctrlAuthR = remoteClient.getCtrlAuth(Optional.ofNullable(userId).filter(StringUtil::isNotBlank).map(Long::parseLong).orElse(null)); + Assert.isTrue(ctrlAuthR.isSuccess(),() -> { + throw new ServiceException("该站点未设置鉴权用户,校验失败!"); + }); + List ctrlAuthList = ctrlAuthR.getData(); + Optional authOptional = ctrlAuthList.stream().filter(c -> c.getProjectId().equals(stationId)).findFirst(); + Assert.isTrue(authOptional.isPresent() && Func.isNotEmpty(authOptional.get().getIsLimitMachine()), () -> { + throw new ServiceException("该用户不存在相应站点权限,校验不通过!"); + }); + CtrlAuth ctrlAuth = authOptional.get(); + // 如限制机器发送遥控指令 + if(ctrlAuth.getIsLimitMachine().intValue() == 1) { + SessionContentVO sessionContent = (SessionContentVO) redisTemplate.opsForHash().get(RedisKeyConstants.SESSION_CONTENT_KEY, sessionId); + Assert.isTrue(Func.isNotEmpty(sessionContent),() -> { + throw new ServiceException("获取问题机器码失败,校验不通过!"); + }); + String machineCode = sessionContent.getMachineCode(); + Assert.isTrue(StringUtil.isNotBlank(machineCode) && Func.isNotEmpty(machineCode) ,() -> { + throw new ServiceException("获取问题机器码失败,校验不通过!"); + }); + Assert.isTrue(machineCode.equals(ctrlAuth.getMachineCode()),() -> { + throw new ServiceException("站点校验码校验失败,校验不通过!"); + }); + } + } + } + + public List getStationPermissionsById(String userId) { + R> deptSattionR = deptClient.getStationPermissionsById(Long.valueOf(userId)); + Assert.isTrue(deptSattionR.isSuccess() && CollectionUtil.isNotEmpty(deptSattionR.getData()),() -> { + throw new ServiceException("获取人员站点权限失败!"); + }); + return deptSattionR.getData(); + } + +} diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/datasource/service/DataSourceService.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/datasource/service/DataSourceService.java index 68dd57f..5cb211f 100644 --- a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/datasource/service/DataSourceService.java +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/datasource/service/DataSourceService.java @@ -49,6 +49,7 @@ public class DataSourceService { String tableSubStr = "(SELECT * FROM " + tableAuthVO.getTableName() + " where" + userAuthDataSQL +") temp"; sql = sql.replace(tableAuthVO.getTableName(),tableSubStr); } + log.info("执行sql:{}",sql); return this.queryListOnSpecificDataSource(sql, sqlVO.getTableAuthVOList().get(0).getDatasourceName()); // 过滤更新、删除语句 // Assert.isTrue(!DataSourceService.isUpdateOrDelete(sqlVO.getSql()),() -> { 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 c3baac3..cdd2857 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 @@ -24,16 +24,17 @@ public enum FuncRouteEnum { SHOW_PARAM("result_record","设备参数查询", FunctionConstants.TypeEnum.PARAMS), CHOOSE_YC("choose_yc","选择遥测数据",FunctionConstants.TypeEnum.CHOOSE), HISTORY_DATA("history_data","查询历史数据",FunctionConstants.TypeEnum.CHART), + CONTROL_DEVICE("control_device","设备控制",FunctionConstants.TypeEnum.PARAMS) ; @Getter - private String funcCode; + private String func; @Getter private String funcName; @Getter private FunctionConstants.TypeEnum type; public static FuncRouteEnum getEnumByFuncCode(String funcCode) { - Optional FuncRoute = Arrays.stream(FuncRouteEnum.class.getEnumConstants()).filter(e -> funcCode.equals(e.getFuncCode())).findFirst(); + Optional FuncRoute = Arrays.stream(FuncRouteEnum.class.getEnumConstants()).filter(e -> funcCode.equals(e.getFunc())).findFirst(); return FuncRoute.orElse(null); } diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/controller/AnalyseDataController.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/controller/AnalyseDataController.java deleted file mode 100644 index d09637f..0000000 --- a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/controller/AnalyseDataController.java +++ /dev/null @@ -1,34 +0,0 @@ -package com.hnac.hzims.bigmodel.interactive.controller; - -import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport; -import com.hnac.hzims.bigmodel.interactive.service.IAnalyseDataService; -import com.hnac.hzims.bigmodel.interactive.vo.HistoryDataSearchVO; -import io.swagger.annotations.Api; -import io.swagger.annotations.ApiOperation; -import lombok.AllArgsConstructor; -import org.springblade.core.tool.api.R; -import org.springframework.validation.annotation.Validated; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; - -/** - * @Author: huangxing - * @Date: 2024/05/29 09:22 - */ -@RequestMapping("/analyse/data") -@AllArgsConstructor -@Api(value = "数据查询管理",tags = "数据查询管理") -@RestController -@Deprecated -public class AnalyseDataController { - - private final IAnalyseDataService analyseDataService; - - @GetMapping("/getHistoryData") - @ApiOperation("获取历史数据") - @ApiOperationSupport(order = 1) - public R getHistoryData(@Validated HistoryDataSearchVO searchVO) { - return R.data(analyseDataService.getHistoryData(searchVO)); - } -} diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/controller/FontEndInteractiveController.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/controller/FontEndInteractiveController.java index 9d0afe8..ac3789b 100644 --- a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/controller/FontEndInteractiveController.java +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/controller/FontEndInteractiveController.java @@ -10,6 +10,7 @@ import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiParam; import lombok.AllArgsConstructor; +import org.springblade.core.tool.api.IResultCode; import org.springblade.core.tool.api.R; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; @@ -50,7 +51,7 @@ public class FontEndInteractiveController { @ApiOperation("获取热点问题") @ApiOperationSupport(order = 3) @GetMapping("/hotQuestions") - public R> hotQuestions() { + public R hotQuestions() { return R.data(hznlmInvokeService.hotQuestions()); } @@ -60,4 +61,12 @@ public class FontEndInteractiveController { public R getSessionId() { return R.data(IdWorker.get32UUID()); } + + @ApiOperation("中断当前的问答") + @ApiOperationSupport(order = 5) + @GetMapping("/interruptSession") + public R interruptSession(@RequestParam(value = "id") String sessionId) { + hznlmInvokeService.askAbort(sessionId); + return R.success("操作成功!"); + } } diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/controller/HznlmInteractiveController.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/controller/HznlmInteractiveController.java index 1ebbacf..2e8843e 100644 --- a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/controller/HznlmInteractiveController.java +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/controller/HznlmInteractiveController.java @@ -5,6 +5,7 @@ import com.hnac.hzims.bigmodel.BigModelConstants; import com.hnac.hzims.bigmodel.datasource.service.DataSourceService; import com.hnac.hzims.bigmodel.datasource.vo.SqlVO; import com.hnac.hzims.bigmodel.interactive.dto.AuthDataDTO; +import com.hnac.hzims.bigmodel.interactive.dto.ControlDTO; import com.hnac.hzims.bigmodel.interactive.req.ModelFunctionReq; import com.hnac.hzims.bigmodel.interactive.service.IHznlmInteractiveService; import com.hnac.hzims.bigmodel.interactive.vo.AuthDataVO; @@ -51,8 +52,15 @@ public class HznlmInteractiveController { @PostMapping("/execute_query") @ApiOperation("执行大模型sql") - @ApiOperationSupport(order = 1) + @ApiOperationSupport(order = 3) public R>> executeQuery(@RequestBody @Valid SqlVO sqlVO) { return R.data(dataSourceService.queryListOnSpecificDataSource(sqlVO)); } + + @PostMapping("/control_device") + @ApiOperation("控制设备") + @ApiOperationSupport(order = 4) + public R controlDevice(@RequestBody @Valid ControlDTO req) { + return R.data(interactiveService.controlDevice(req)); + } } 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 deleted file mode 100644 index 35537ee..0000000 --- a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/controller/InteractiveController.java +++ /dev/null @@ -1,116 +0,0 @@ -package com.hnac.hzims.bigmodel.interactive.controller; - -import com.baomidou.mybatisplus.core.toolkit.IdWorker; -import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport; -import com.google.common.collect.Lists; -import com.hnac.hzims.bigmodel.BigModelConstants; -import com.hnac.hzims.bigmodel.interactive.req.ModelFunctionReq; -import com.hnac.hzims.bigmodel.interactive.service.IInteractiveService; -import com.hnac.hzims.bigmodel.interactive.vo.StationSearchVO; -import com.hnac.hzinfo.log.annotation.Business; -import io.swagger.annotations.Api; -import io.swagger.annotations.ApiOperation; -import io.swagger.annotations.ApiParam; -import lombok.AllArgsConstructor; -import org.springblade.core.tool.api.R; -import org.springblade.system.dto.ControlDTO; -import org.springframework.web.bind.annotation.*; - -import java.text.DecimalFormat; -import java.util.List; - -/** - * @Author: huangxing - * @Date: 2024/04/26 14:51 - */ -@RestController -@AllArgsConstructor -@Api(value = "FDP大模型交互层",tags = "FDP大模型交互层") -@RequestMapping("/interactive") -@Business(module = BigModelConstants.MODULE_NAME,value = "FDP大模型交互层") -@Deprecated -public class InteractiveController { - - private final IInteractiveService interactiveService; - - @ApiOperation("解析大模型函数") - @ApiOperationSupport(order = 1) - @PostMapping("/resolve") - public R resolve(@RequestBody ModelFunctionReq req) { - return interactiveService.resolve(req); - } - - @ApiOperation("提问") - @ApiOperationSupport(order = 2) - @GetMapping("/ask") - @Deprecated - public R ask(@RequestParam @ApiParam("用户提出问题") String question,@RequestParam @ApiParam("问答sessionId") String sessionId,@RequestParam @ApiParam("用户Id") String userId) { - return interactiveService.ask(question, sessionId, userId); - } - - @ApiOperation("站点、菜单鉴权") - @ApiOperationSupport(order = 3) - @Deprecated - @RequestMapping(value = "/authentication",method = {RequestMethod.GET,RequestMethod.POST}) - public R authentication(@RequestParam(required = false) @ApiParam("站点编号") String stationId, - @RequestParam @ApiParam("用户ID") String userId, - @RequestParam(required = false) @ApiParam("菜单ID") String func, - @RequestParam(required = false) @ApiParam("会话ID")String askId) { - return R.status(interactiveService.authentication(stationId,userId,func,askId)); - } - - @ApiOperation("获取问答sessionId") - @ApiOperationSupport(order = 4) - @GetMapping("/getSessionId") - public R getSessionId() { - return R.data(IdWorker.get32UUID()); - } - - @ApiOperation("删除对话sessionId") - @ApiOperationSupport(order = 5) - @GetMapping("/removeSessionId") - @Deprecated - public R removeSessionId(@RequestParam(value = "id") String sessionId) { - return R.data(interactiveService.removeSessionId(sessionId)); - } - - @ApiOperation("下发遥控指令") - @ApiOperationSupport(order = 6) - @PostMapping("/sendRemoteControl") - public R sendRemoteControl(@RequestBody ControlDTO operate) { - return interactiveService.sendRemoteControl(operate); - } - - @ApiOperation("解析接入站点数量") - @ApiOperationSupport(order = 7) - @PostMapping("/resolveStations") - public R resolveStations(@RequestBody StationSearchVO req) { - return R.data(interactiveService.resolveStations(req.getStartTime(),req.getEndTime(),req.getType(),req.getEnumType())); - } - - @ApiOperation("站点发电量") - @ApiOperationSupport(order = 7) - @RequestMapping(value = "/generation",method = {RequestMethod.GET,RequestMethod.POST}) - public R generation(@RequestParam @ApiParam("站点编号") String stationId, - @RequestParam @ApiParam("开始时间") String startTime, - @RequestParam @ApiParam("结束时间")String endTime) { - double generate = interactiveService.generation(stationId,startTime,endTime); - DecimalFormat format = new DecimalFormat("0.00"); - return R.data(format.format(generate) + "kWh"); - } - - @ApiOperation("获取热点问题") - @ApiOperationSupport(order = 8) - @GetMapping("/hotQuestions") - @Deprecated - public R hotQuestions() { - try{ - List questions = interactiveService.hotQuestions(); - return R.data(questions); - } - catch (Exception e) { - e.printStackTrace(); - return R.data(Lists.newArrayList()); - } - } -} 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 ec26387..c9aed6b 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,6 +1,7 @@ package com.hnac.hzims.bigmodel.interactive.service; import com.hnac.hzims.bigmodel.interactive.dto.AuthDataDTO; +import com.hnac.hzims.bigmodel.interactive.dto.ControlDTO; import com.hnac.hzims.bigmodel.interactive.req.ModelFunctionReq; import com.hnac.hzims.bigmodel.interactive.vo.AuthDataVO; import com.hnac.hzims.bigmodel.interactive.vo.ExtraVO; @@ -16,7 +17,10 @@ import java.util.List; */ public interface IHznlmInteractiveService { - List getAuthData(@RequestBody @Valid AuthDataDTO req); + List getAuthData(AuthDataDTO req); ExtraVO resolve(ModelFunctionReq req); + + ExtraVO controlDevice(ControlDTO 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 index 6cfa306..59c2089 100644 --- 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 @@ -58,6 +58,10 @@ public interface IHznlmInvokeService { */ List getAnswerBySessionIds(String sessionIds); - + /** + * 中断当前的问答 + * @param sessionId 会话ID + */ + void askAbort(String sessionId); } 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 deleted file mode 100644 index f39a0fb..0000000 --- a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/IParamsService.java +++ /dev/null @@ -1,15 +0,0 @@ -package com.hnac.hzims.bigmodel.interactive.service; - -import com.hnac.hzims.bigmodel.entity.FunctionEntity; - -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/impl/AnalyseDataServiceImpl.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/AnalyseDataServiceImpl.java index 418f66c..ae74c7f 100644 --- a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/AnalyseDataServiceImpl.java +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/AnalyseDataServiceImpl.java @@ -1,6 +1,5 @@ package com.hnac.hzims.bigmodel.interactive.service.impl; -import com.alibaba.fastjson.JSON; import com.google.common.collect.Lists; import com.hnac.hzims.bigmodel.data.service.HistoryDataService; import com.hnac.hzims.bigmodel.interactive.constants.DataMethodEnum; @@ -10,23 +9,13 @@ import com.hnac.hzims.bigmodel.interactive.service.IAnalyseDataService; import com.hnac.hzims.bigmodel.interactive.vo.ExtraVO; import com.hnac.hzims.bigmodel.interactive.vo.HistoryDataSearchVO; import com.hnac.hzinfo.sdk.core.response.Result; -import com.hnac.hzinfo.sdk.v5.device.DeviceDataClient; -import com.hnac.hzinfo.sdk.v5.device.dto.ReductionAttrDataDTO; -import com.hnac.hzinfo.sdk.v5.device.dto.ReductionDataDTO; import com.hnac.hzinfo.sdk.v5.device.vo.ReductionDataVO; import lombok.AllArgsConstructor; -import org.springblade.core.log.exception.ServiceException; -import org.springblade.core.log.logger.BladeLogger; import org.springblade.core.tool.utils.CollectionUtil; -import org.springblade.core.tool.utils.DateUtil; 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.time.Duration; -import java.time.LocalDateTime; -import java.time.temporal.ChronoUnit; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -57,7 +46,7 @@ public class AnalyseDataServiceImpl implements IAnalyseDataService { searchVO.setDataType(adapterDate.getDateType()); ExtraVO extraVO = new ExtraVO(); extraVO.setType(FuncRouteEnum.HISTORY_DATA.getType().getType()); - extraVO.setFunc(FuncRouteEnum.HISTORY_DATA.getFuncCode()); + extraVO.setFunc(FuncRouteEnum.HISTORY_DATA.getFunc()); Map params = new HashMap<>(1); Result reductionDataVOR = historyDataService.getPolymerizationData(searchVO); String label; diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/AuthenticationService.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/AuthenticationService.java deleted file mode 100644 index f34088b..0000000 --- a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/AuthenticationService.java +++ /dev/null @@ -1,128 +0,0 @@ -package com.hnac.hzims.bigmodel.interactive.service.impl; - -import com.google.common.collect.Lists; -import com.hnac.hzims.bigmodel.entity.FunctionEntity; -import com.hnac.hzims.bigmodel.function.service.IFunctionService; -import com.hnac.hzims.bigmodel.interactive.constants.ProjectRemoteTypeEnum; -import com.hnac.hzims.bigmodel.interactive.vo.SessionContentVO; -import com.hnac.hzims.bigmodel.websocket.constants.RedisKeyConstants; -import com.hnac.hzinfo.sdk.core.response.Result; -import com.hnac.hzinfo.sdk.v5.project.ProjectClient; -import com.hnac.hzinfo.sdk.v5.project.vo.ProjectVO; -import lombok.AllArgsConstructor; -import org.springblade.core.log.exception.ServiceException; -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.springblade.system.entity.CtrlAuth; -import org.springblade.system.feign.IDeptClient; -import org.springblade.system.feign.IRemoteClient; -import org.springblade.system.user.feign.IUserClient; -import org.springframework.data.redis.core.RedisTemplate; -import org.springframework.stereotype.Service; -import org.springframework.util.Assert; - -import java.util.List; -import java.util.Optional; -import java.util.stream.Collectors; - -/** - * @Author: huangxing - * @Date: 2024/05/21 16:10 - */ -@Service -@AllArgsConstructor -public class AuthenticationService { - - private final IDeptClient deptClient; - private final IFunctionService functionService; - private final IUserClient userClient; - private final ProjectClient projectClient; - private final IRemoteClient remoteClient; - private final RedisTemplate redisTemplate; - - /** - * 站点鉴权 - * @param stationId 站点ID - * @param userId 用户ID - */ - public void stationAuthentication(String stationId, String userId) { - List stations = this.getStationPermissionsById(userId).stream().map(DeptStationDTO::getStationId) - .filter(StringUtil::isNotBlank).filter(Func::isNotEmpty).collect(Collectors.toList()); - Assert.isTrue(stations.contains(stationId),() -> { - throw new ServiceException("人员站点鉴权失败!"); - }); - } - - /** - * 菜单鉴权 - * @param userId 用户ID - * @param func 函数编号 - */ - public void menuAuthentication(String userId, String func) { - FunctionEntity function = functionService.getFunctionByCode(func); - if(Func.isNotEmpty(function) && Func.isNotEmpty(function.getRoute()) && StringUtil.isNotBlank(function.getRoute())) { - R authenticationR = userClient.permissionMenuById(Long.valueOf(userId), function.getRoute()); - Assert.isTrue(authenticationR.isSuccess() && authenticationR.getData(), () -> { - throw new ServiceException("人员菜单鉴权失败!"); - }); - } - } - - /** - * 遥控鉴权 - * @param stationId 站点ID - * @param userId 用户ID - */ - public void remoteAuthentication(String stationId, String userId,String sessionId) { - // 查询数据平台站点是否可被遥控 - Result> projectR = projectClient.getProjectIds(Lists.newArrayList(stationId)); - Assert.isTrue(projectR.isSuccess() && CollectionUtil.isNotEmpty(projectR.getData()) && projectR.getData().size() == 1,() -> { - throw new ServiceException("未查询到站点,鉴权失败!"); - }); - ProjectVO project = projectR.getData().get(0); - if(ProjectRemoteTypeEnum.NOT_ALLOW.getCtrlType().equals(project.getCtrlType())) { - // 不允许发送遥控 - throw new ServiceException("该站点不允许发送遥控指令,校验失败!"); - } - else if(ProjectRemoteTypeEnum.VALID.getCtrlType().equals(project.getCtrlType())) { - // 运行发送遥控并且需要校验权限 - R> ctrlAuthR = remoteClient.getCtrlAuth(Optional.ofNullable(userId).filter(StringUtil::isNotBlank).map(Long::parseLong).orElse(null)); - Assert.isTrue(ctrlAuthR.isSuccess(),() -> { - throw new ServiceException("该站点未设置鉴权用户,校验失败!"); - }); - List ctrlAuthList = ctrlAuthR.getData(); - Optional authOptional = ctrlAuthList.stream().filter(c -> c.getProjectId().equals(stationId)).findFirst(); - Assert.isTrue(authOptional.isPresent() && Func.isNotEmpty(authOptional.get().getIsLimitMachine()), () -> { - throw new ServiceException("该用户不存在相应站点权限,校验不通过!"); - }); - CtrlAuth ctrlAuth = authOptional.get(); - // 如限制机器发送遥控指令 - if(ctrlAuth.getIsLimitMachine().intValue() == 1) { - SessionContentVO sessionContent = (SessionContentVO) redisTemplate.opsForHash().get(RedisKeyConstants.SESSION_CONTENT_KEY, sessionId); - Assert.isTrue(Func.isNotEmpty(sessionContent),() -> { - throw new ServiceException("获取问题机器码失败,校验不通过!"); - }); - String machineCode = sessionContent.getMachineCode(); - Assert.isTrue(StringUtil.isNotBlank(machineCode) && Func.isNotEmpty(machineCode) ,() -> { - throw new ServiceException("获取问题机器码失败,校验不通过!"); - }); - Assert.isTrue(machineCode.equals(ctrlAuth.getMachineCode()),() -> { - throw new ServiceException("站点校验码校验失败,校验不通过!"); - }); - } - } - - } - - public List getStationPermissionsById(String userId) { - R> deptSattionR = deptClient.getStationPermissionsById(Long.valueOf(userId)); - Assert.isTrue(deptSattionR.isSuccess() && CollectionUtil.isNotEmpty(deptSattionR.getData()),() -> { - throw new ServiceException("获取人员站点权限失败!"); - }); - return deptSattionR.getData(); - } - -} 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 index 3016a6b..b54712b 100644 --- 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 @@ -7,13 +7,10 @@ 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.StationEntity; import com.hnac.hzims.operational.station.feign.IStationClient; -import com.hnac.hzinfo.sdk.v5.scada.ScadaClient; 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; @@ -40,24 +37,21 @@ public class CanvasResolveServiceImpl implements IResolveService { @Override public ExtraVO resolve(ModelFunctionReq req) { - Map args = req.getFunctionArgs(); - String id = args.get("id"); - String name = args.get("name"); + Map args = req.getItem(); + String id = args.get("itemId"); + String name = args.get("itemName"); Assert.isTrue(StringUtil.isNotBlank(id) && StringUtil.isNotBlank(name),() -> { logger.error("hzims:video:resolve","解析传参错误,缺少必要参数video_id,传参内容为:" + JSON.toJSONString(req)); throw new ServiceException("解析传参错误,缺少必要参数video_id"); }); return this.resolve(id); -// ExtraVO extra = this.resolve(id); -// String message = "已成功打开" + name + ";"; -// return new ResolveResultVO(message,extra); } @Override public ExtraVO resolve(String id) { ExtraVO extraVO = new ExtraVO(); extraVO.setImmediatelyJump(true); - extraVO.setFunc(FuncRouteEnum.OPEN_CANVAS.getFuncCode()); + extraVO.setFunc(FuncRouteEnum.OPEN_CANVAS.getFunc()); final String[] SCADA_PARAMS_SOLVE = new String[]{"picResource","context","stationNum","projectId","taskId","name","id"}; String canvasHost = ParamCache.getValue(ParamKeyConstants.CANVAS_HOST); // 将ID解析为 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 deleted file mode 100644 index 05f54db..0000000 --- a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/ExtraResolveStrategyService.java +++ /dev/null @@ -1,259 +0,0 @@ -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.constants.FunctionConstants; -import com.hnac.hzims.bigmodel.interactive.constants.SearchTypeEnum; -import com.hnac.hzims.bigmodel.interactive.service.IAnalyseDataService; -import com.hnac.hzims.bigmodel.interactive.vo.*; -import com.hnac.hzims.operational.station.entity.StationVideoTypeEntity; -import com.hnac.hzims.operational.station.feign.IStationClient; -import com.hnac.hzims.operational.station.feign.IStationVideoTypeClient; -import com.hnac.hzinfo.sdk.v5.device.client.DeviceClient; -import com.hnac.hzinfo.sdk.v5.device.vo.DeviceInstanceFuncVO; -import com.xxl.job.core.log.XxlJobLogger; -import lombok.AllArgsConstructor; -import org.springblade.core.tool.api.R; -import org.springblade.core.tool.utils.*; -import org.springframework.stereotype.Service; - -import java.time.format.DateTimeFormatter; -import java.util.*; -import java.util.stream.Collectors; - -/** - * @Author: huangxing - * @Date: 2024/05/08 16:19 - */ -@Service -@AllArgsConstructor -@Deprecated -public class ExtraResolveStrategyService { - - public static final String PATTERN_DATETIME = "yyyy-MM-dd HH:mm:ss.SSS"; - - public static final DateTimeFormatter formatter = DateTimeFormatter.ofPattern(PATTERN_DATETIME); - - private final IStationClient stationClient; - private final IStationVideoTypeClient videoTypeClient; - private final JumpRouteJoinStrategy jumpRouteJoinStrategy; - private final DeviceClient deviceClient; - private final IAnalyseDataService analyseDataService; - - /** - * 解析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)) { - XxlJobLogger.log("函数编号为:" + functionCode); - FuncRouteEnum funcRouteEnum = FuncRouteEnum.getEnumByFuncCode(functionCode); - if(Func.isNotEmpty(funcRouteEnum)) { - switch (funcRouteEnum) { - case DIAGNOSE: - return this.resolveDiagnose(extra); - case CHOOSE_VIDEO: - case CHOOSE_CANVAS: - case CHOOSE_STATION: - case CHOOSE_FAULT: - case CHOOSE_YC: - case CHOOSE_YK: - return this.resolveChooseSelection(extra,funcRouteEnum); - case CONFIRM_YK: - return this.resolveConfirmRemote(extra); - case SHOW_PARAM: - return this.resolveShowParam(extra); - default: - break; - } - } - } - else if(extra.containsKey("extra")){ - return extra.getObject("extra",ExtraVO.class); - } - return JSONObject.parseObject(JSON.toJSONString(extra),ExtraVO.class); - } - - private ExtraVO resolveChooseSelection(JSONObject extra,FuncRouteEnum funcRouteEnum) { - ExtraVO result = new ExtraVO(); - JSONArray selections = JSONArray.parseArray(JSON.toJSONString(extra.get("data"))); - result.setFunc(funcRouteEnum.getFuncCode()); - result.setSpecial(true); - result.setSelection(selections); - result.setType(funcRouteEnum.getType().getType()); - return result; - } - -// private ExtraVO resolveChooseYc(JSONObject extra) { -// ExtraVO result = new ExtraVO(); -// JSONObject data = JSONObject.parseObject(JSON.toJSONString(extra.get("data"))); -// if(data.containsKey("yks")) { -// -// -// List attrs = JSONArray.parseArray(JSON.toJSONString(data.get("yks")), AttrSelectionVO.class); -// result.setSelection(attrs); -// } -// result.setFuncCode(FuncRouteEnum.CHOOSE_YC.getFuncCode()); -// result.setSpecial(true); -// result.setType(FuncRouteEnum.CHOOSE_YC.getType().getType()); -// return result; -// } - - private ExtraVO resolveShowParam(Map extra) { - DataVO data = JSONObject.parseObject(JSON.toJSONString(extra.get("data")),DataVO.class); - if(Func.isNotEmpty(data)) { - if(Func.isNotEmpty(data.getReal())) { - if(Func.isNotEmpty(data.getReal().getTime()) && StringUtil.isNotBlank(data.getReal().getTime())) { - RealDataVO real = data.getReal(); - Date date = DateUtil.parse(real.getTime(), PATTERN_DATETIME); - real.setTime(DateUtil.format(date,DateUtil.PATTERN_DATETIME)); - } - } - if(Func.isNotEmpty(data.getItem()) && StringUtil.isNotBlank(data.getMethod())) { - if(SearchTypeEnum.HISTORY.getSearchType().equals(data.getType()) && Func.isNotEmpty(data.getItem())) { - DataItemVO item = data.getItem(); - HistoryDataSearchVO searchVO = new HistoryDataSearchVO(); - searchVO.setDataType(data.getDataType()); - searchVO.setAttrName(item.getAttrName()); - searchVO.setDeviceCode(item.getDeviceId()); - searchVO.setDeviceName(item.getDeviceName()); - searchVO.setStationName(item.getProjectName()); - searchVO.setMethod(data.getMethod()); - searchVO.setSignage(item.getSignage()); - searchVO.setStartTime(data.getStartTime()); - searchVO.setEndTime(data.getEndTime()); - return analyseDataService.getHistoryData(searchVO); - } - } - } - ExtraVO result = new ExtraVO(); - result.setFunc(FuncRouteEnum.SHOW_PARAM.getFuncCode()); - result.setType(FuncRouteEnum.SHOW_PARAM.getType().getType()); - Map param = new HashMap(1); - param.put("data", data); - result.setParams(param); - return result; - } - - @Deprecated - private ExtraVO resolveConfirmRemote(Map extra) { - ExtraVO result = new ExtraVO(); - RemoteParamVO remoteParam = JSONObject.parseObject(JSON.toJSONString(extra.get("data")), RemoteParamVO.class); - result.setFunc(FuncRouteEnum.CONFIRM_YK.getFuncCode()); - result.setType(FuncRouteEnum.CONFIRM_YK.getType().getType()); - R funcVOR = deviceClient.getFuncById(remoteParam.getFuncId()); - if(funcVOR.isSuccess()) { - Map param = new HashMap(); - param.put("control",funcVOR.getData()); - param.put("deviceName",remoteParam.getDeviceName()); - param.put("projectName",remoteParam.getProjectName()); - param.put("deviceCode",remoteParam.getDeviceId()); - param.put("value",remoteParam.getValue()); - result.setParams(param); - } - return result; - } - -// private ExtraVO resolveChooseFault(Map extra) { -// ExtraVO result = new ExtraVO(); -// JSONObject data = JSONObject.parseObject(JSON.toJSONString(extra.get("data"))); -// if(data.containsKey("faults")) { -// List faults = JSONArray.parseArray(JSON.toJSONString(data.get("faults")), FaultSelectionVO.class); -// result.setSelection(faults); -// } -// result.setFuncCode(FuncRouteEnum.CHOOSE_FAULT.getFuncCode()); -// result.setSpecial(true); -// result.setType(FunctionConstants.TypeEnum.CHOOSE.getType()); -// return result; -// } - - private ExtraVO resolveDiagnose(Map extra) { - ExtraVO result = new ExtraVO(); - JSONObject data = JSONObject.parseObject(JSON.toJSONString(extra.get("data"))); - Map params = new HashMap<>(5); - params.put("faultId",data.getString("fault_id")); - params.put("name",data.getString("fault_name")); - params.put("station",data.getString("station_id")); - params.put("fdpDeviceName",data.getString("device_name")); - params.put("fdpOrd",data.getString("ord")); - result.setParams(params); - result.setFunc(FuncRouteEnum.DIAGNOSE.getFuncCode()); - result.setType(FunctionConstants.TypeEnum.PARAMS.getType()); - return result; - } - - /** - * - * @param extra - * @return - */ -// private ExtraVO resolveChooseStation(Map extra) { -// ExtraVO result = new ExtraVO(); -// JSONObject data = JSONObject.parseObject(JSON.toJSONString(extra.get("data"))); -// if(data.containsKey("stations")) { -// List stations = JSONArray.parseArray(JSON.toJSONString(data.get("stations")), String.class); -// List selectionList = stations.stream().map(stationId -> { -// StationSelectionVO selectionVO = new StationSelectionVO(); -// R stationR = stationClient.getStationByCode(stationId); -// if (stationR.isSuccess() && Func.isNotEmpty(stationR.getData())) { -// selectionVO.setId(stationId); -// selectionVO.setName(stationR.getData().getName()); -// } -// return selectionVO; -// }).collect(Collectors.toList()); -// result.setSelection(selectionList); -// result.setFuncCode(FuncRouteEnum.CHOOSE_STATION.getFuncCode()); -// result.setSpecial(true); -// result.setType(FunctionConstants.TypeEnum.CHOOSE.getType()); -// } -// result.setType(FunctionConstants.TypeEnum.CHOOSE.getType()); -// return result; -// } - - private ExtraVO resolveChooseVideo(Map extra) { - ExtraVO result = new ExtraVO(); - JSONObject data = JSONObject.parseObject(JSON.toJSONString(extra.get("data"))); - if(data.containsKey("videos")) { - List videoIds = JSONArray.parseArray(JSON.toJSONString(data.get("videos")), JSONObject.class); - List selections = videoIds.stream().map(video -> { - R videoR = videoTypeClient.getById(Long.valueOf(video.getString("id"))); - VideoSelectionVO selectionVO = new VideoSelectionVO(); - if (videoR.isSuccess() && Func.isNotEmpty(videoR.getData())) { - selectionVO.setId(video.getString("id")); - selectionVO.setName(videoR.getData().getName()); - } - return selectionVO; - }).collect(Collectors.toList()); - result.setFunc(FuncRouteEnum.CHOOSE_VIDEO.getFuncCode()); - result.setSpecial(true); - result.setSelection(selections); - } - result.setType(FunctionConstants.TypeEnum.CHOOSE.getType()); - return result; - } - - private ExtraVO resolveChooseScada(Map extra) { - ExtraVO result = new ExtraVO(); - JSONObject data = JSONObject.parseObject(JSON.toJSONString(extra.get("data"))); - if(data.containsKey("canvases")) { - List canvases = JSONArray.parseArray(JSON.toJSONString(data.get("canvases")), JSONObject.class); - List selections = canvases.stream().map(canvas -> { - ScadaSelectionVO selectionVO = new ScadaSelectionVO(); - Map resolve = jumpRouteJoinStrategy.resolve(canvas.getString("id"), JumpRouteJoinStrategy.SCADA_PARAMS_SOLVE); - selectionVO.setId(canvas.getString("id")); - selectionVO.setName(resolve.get("name")); - return selectionVO; - }).collect(Collectors.toList()); - result.setFunc(FuncRouteEnum.CHOOSE_CANVAS.getFuncCode()); - result.setSpecial(true); - result.setSelection(selections); - } - result.setType(FunctionConstants.TypeEnum.CHOOSE.getType()); - return result; - } -} diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/HznlmInteractiveServiceImpl.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/HznlmInteractiveServiceImpl.java index 44182a3..b22a790 100644 --- a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/HznlmInteractiveServiceImpl.java +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/HznlmInteractiveServiceImpl.java @@ -1,22 +1,32 @@ package com.hnac.hzims.bigmodel.interactive.service.impl; +import com.hnac.hzims.bigmodel.business.dto.ControlDeviceAuthDTO; +import com.hnac.hzims.bigmodel.business.feign.IAuthClient; +import com.hnac.hzims.bigmodel.business.service.AuthenticationService; import com.hnac.hzims.bigmodel.interactive.constants.DataAuthTypeEnum; +import com.hnac.hzims.bigmodel.interactive.constants.FuncRouteEnum; import com.hnac.hzims.bigmodel.interactive.dto.AuthDataDTO; +import com.hnac.hzims.bigmodel.interactive.dto.ControlDTO; 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.ExtraVO; -import com.hnac.hzims.bigmodel.interactive.vo.ResolveResultVO; import groovy.util.logging.Slf4j; import lombok.AllArgsConstructor; import org.springblade.core.log.exception.ServiceException; +import org.springblade.core.tool.utils.BeanUtil; +import org.springblade.core.tool.utils.DateUtil; import org.springblade.core.tool.utils.Func; import org.springblade.system.dto.DeptStationDTO; import org.springframework.stereotype.Service; +import org.springframework.util.Assert; +import java.util.HashMap; import java.util.List; +import java.util.Map; +import java.util.Optional; import java.util.stream.Collectors; /** @@ -29,6 +39,7 @@ import java.util.stream.Collectors; public class HznlmInteractiveServiceImpl implements IHznlmInteractiveService { private final AuthenticationService authenticationService; + private final IAuthClient authClient; @Override public List getAuthData(AuthDataDTO req) { @@ -45,10 +56,30 @@ public class HznlmInteractiveServiceImpl implements IHznlmInteractiveService { @Override public ExtraVO resolve(ModelFunctionReq req) { - IResolveService resolveService = ResolveFactory.getResolveService(req.getFunctionName()); + IResolveService resolveService = ResolveFactory.getResolveService(req.getFunc()); return resolveService.resolve(req); } + @Override + public ExtraVO controlDevice(ControlDTO req) { + ExtraVO result = new ExtraVO(); + Optional optional = req.getYks().stream().map(controlDeviceDTO -> { + ControlDeviceAuthDTO deviceAuthDTO = BeanUtil.copy(controlDeviceDTO, ControlDeviceAuthDTO.class); + deviceAuthDTO.setUserId(req.getUserId()); + return deviceAuthDTO; + }).filter(d -> authClient.remoteAuth(d).isSuccess()).findFirst(); + Assert.isTrue(optional.isPresent(),() -> { + throw new ServiceException("鉴权失败!!"); + }); + // 封装返回的extra + result.setFunc(FuncRouteEnum.CONTROL_DEVICE.getFunc()); + result.setType(FuncRouteEnum.CONTROL_DEVICE.getType().getType()); + Map params = BeanUtil.toMap(optional.get()); + params.put("value", req.getValue()); + result.setParams(params); + return result; + } + 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 index db48d34..a910692 100644 --- 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 @@ -1,33 +1,24 @@ 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.alibaba.fastjson.TypeReference; import com.google.common.collect.Lists; +import com.hnac.hzims.bigmodel.business.service.AuthenticationService; 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.hnac.hzims.bigmodel.websocket.sessionManager.InteractiveSessionManager; -import com.xxl.job.core.log.XxlJobLogger; -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.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; @@ -90,14 +81,18 @@ public class HznlmInvokeServiceImpl implements IHznlmInvokeService { @Override public void removeSessionId(String sessionId) { - Map params = new HashMap<>(); - params.put("id",sessionId); - RequestClientUtil.postCall(fdpHost + bigModelInvokeUrl.getAskAbort(), params); + this.askAbort(sessionId); // 移除内存sessionId InteractiveSessionManager.SESSION_POOL.remove(sessionId); sessionRedisManager.removeSessionId(sessionId); } + public void askAbort(String sessionId) { + Map params = new HashMap<>(); + params.put("id",sessionId); + RequestClientUtil.postCall(fdpHost + bigModelInvokeUrl.getAskAbort(), params); + } + @Override public List hotQuestions() { try { 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 deleted file mode 100644 index a5eff60..0000000 --- a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/InteractiveServiceImpl.java +++ /dev/null @@ -1,430 +0,0 @@ -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.alibaba.fastjson.JSONObject; -import com.google.common.util.concurrent.ThreadFactoryBuilder; -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.constants.FuncRouteEnum; -import com.hnac.hzims.bigmodel.interactive.constants.FunctionConstants; -import com.hnac.hzims.bigmodel.interactive.constants.SearchStationTypeEnum; -import com.hnac.hzims.bigmodel.interactive.constants.SearchTypeEnum; -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.interactive.service.IParamsService; -import com.hnac.hzims.bigmodel.interactive.vo.AnswerVO; -import com.hnac.hzims.bigmodel.interactive.vo.ExtraVO; -import com.hnac.hzims.operational.station.entity.StationEntity; -import com.hnac.hzims.operational.station.feign.IStationClient; -import com.hnac.hzims.equipment.feign.IEmInfoClient; - import com.hnac.hzims.equipment.vo.EminfoAndEmParamVo; -import com.hnac.hzims.equipment.vo.RideDeviceVo; -import com.hnac.hzims.operational.fill.feign.IGenerateClient; -import com.hnac.hzims.operational.main.constant.HomePageConstant; -import com.hnac.hzims.operational.station.entity.StationEntity; -import com.hnac.hzims.operational.station.feign.IStationClient; -import com.hnac.hzinfo.datasearch.analyse.IAnalyseDataSearchClient; -import com.hnac.hzinfo.datasearch.analyse.po.AnalyseCodeByAnalyseDataPO; -import com.hnac.hzinfo.datasearch.analyse.po.AnalyzeDataConditionPO; -import com.hnac.hzinfo.datasearch.analyse.vo.AnalyseDataTaosVO; -import com.hnac.hzinfo.datasearch.analyse.vo.AnalyzeDataConditionVO; -import com.xxl.job.core.log.XxlJobLogger; -import lombok.RequiredArgsConstructor; -import lombok.extern.slf4j.Slf4j; -import org.apache.commons.collections4.MapUtils; -import org.apache.poi.ss.formula.functions.T; -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.*; -import org.springblade.system.dto.ControlDTO; -import org.springblade.system.dto.DeptStationDTO; -import org.springblade.system.feign.IDeptClient; -import org.springblade.system.feign.IRemoteClient; -import org.springblade.system.user.feign.IUserClient; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.data.redis.core.RedisTemplate; -import org.springframework.stereotype.Service; -import org.springframework.util.Assert; -import org.springframework.util.StringUtils; - -import javax.servlet.http.HttpServletResponse; -import java.time.LocalDateTime; -import java.time.format.DateTimeFormatter; -import java.util.*; -import java.util.concurrent.*; -import java.util.stream.Collectors; - -import static com.hnac.hzims.bigmodel.interactive.constants.FunctionConstants.TypeEnum; -import static com.hnac.hzims.bigmodel.schedule.XxlJobHandlerConstant.HZIMS_BIGMODEL_ASK_KEY; - -/** - * @Author: huangxing - * @Date: 2024/04/26 14:51 - */ -@Service -@Slf4j -@RequiredArgsConstructor -@Deprecated -public class InteractiveServiceImpl implements IInteractiveService { - - private final BladeLogger logger; - - private final IEmInfoClient deviceClient; - - private final IRemoteClient remoteClient; - - private final IStationClient stationClient; - - private final IGenerateClient generateClient; - - private final IJumpPageService jumpPageService; - - private final IParamsService paramsService; - - private final IFunctionService functionService; - - private final BigModelInvokeUrl bigModelInvokeUrl; - - private final AuthenticationService authenticationService; - - private final RedisTemplate redisTemplate; - - private final IAnalyseDataSearchClient analyseDataSearchClient; - - private final ExtraResolveStrategyService extraResolveStrategyService; - - private static final ExecutorService pool = new ThreadPoolExecutor(10, 10, 0L, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<>(1024), new ThreadFactoryBuilder().setNameFormat("station-device-generate-%d").build(), new ThreadPoolExecutor.CallerRunsPolicy()); - - @Value("${fdp.host}") - private String fdpHost; - - @Override - public ExtraVO resolveStations(String startTime, String endTime, String type, String enumType) { - ExtraVO extraVO = new ExtraVO(); - extraVO.setType(TypeEnum.PARAMS.getType()); - extraVO.setFunc("stations_num"); - String label; - SearchStationTypeEnum stationTypeEnum = SearchStationTypeEnum.getTypeEnum(enumType); - if(!startTime.equals(endTime) && SearchTypeEnum.HISTORY.getSearchType().equals(type)) { - label = String.format("自%s到%s时间为止,",startTime,endTime); - } - else { - startTime = null; - endTime = null; - label = "目前"; - } - R> stationListR = stationClient.getStationByTypeAndDuration(startTime, endTime, stationTypeEnum.getStationType()); - Assert.isTrue(stationListR.isSuccess(),() -> { - throw new ServiceException("获取接入站点数量失败!"); - }); - Map params = new HashMap<>(); - params.put("searchStationType",stationTypeEnum.getSearchStationType()); - params.put("label",label + String.format(stationTypeEnum.getLabel(),stationListR.getData().size())); - params.put("startTime",startTime); - params.put("endTime",endTime); - extraVO.setParams(params); - return extraVO; - } - - @Override - public R resolve(ModelFunctionReq req) { - logger.info("interactive:resolve","开始解析大模型函数,函数内容为:" + JSON.toJSONString(req)); - FunctionEntity function = functionService.getFunctionByCode(req.getFunctionName()); - TypeEnum typeEnum = TypeEnum.getTypeEnumByType(function.getType()); - if(Func.isEmpty(typeEnum)) { - throw new ServiceException("函数解析失败!"); - } - switch (typeEnum) { - // 页面跳转 - case JUMP: - String jumpExtra = jumpPageService.dealJumpTypeFunction(function, req.getFunctionArgs()); - Assert.isTrue(StringUtil.isNotBlank(jumpExtra) && Func.isNotEmpty(jumpExtra), () -> { - throw new ServiceException("解析" + function.getName() + "函数失败!"); - }); - return R.data(jumpExtra); - case PARAMS: - String paramExtra = paramsService.dealJumpTypeFunction(function, req.getFunctionArgs()); - return R.data(paramExtra); - default: - throw new ServiceException("函数解析失败!"); - } - } - - @Override - public R ask(String question,String sessionId,String userId) { - Map params = new HashMap<>(); - params.put("id",sessionId); - params.put("userid", userId); - params.put("query",question); - params.put("stationids",authenticationService.getStationPermissionsById(userId).stream().map(DeptStationDTO::getStationId).filter(StringUtil::isNotBlank).filter(Func::isNotEmpty).toArray()); - params.put("projectids",authenticationService.getStationPermissionsById(userId).stream().map(DeptStationDTO::getDeptId).filter(Func::isNotEmpty).map(String::valueOf).toArray()); - HttpResponse response = HttpRequest.post(fdpHost + bigModelInvokeUrl.getAssistantAsk()) - .body(JSON.toJSONString(params)).execute(); - logger.info("interactive:ask","问答传参为:" + JSON.toJSONString(params) + "结果为:" + response.body()); - if(response.getStatus() != HttpServletResponse.SC_OK) { - log.error("远程调用大模型【发起问答】接口失败!"); - return R.fail("远程调用大模型【发起问答】接口失败!"); - } - this.addQuestionSessionId(sessionId); - return R.success("消息发送成功"); - } - - private void addQuestionSessionId(String sessionId) { - redisTemplate.opsForList().leftPush(HZIMS_BIGMODEL_ASK_KEY,sessionId); - } - - @Override - public R specialAsk(String sessionId, String userId, Map extra) { - Map params = new HashMap<>(); - params.put("id",sessionId); - params.put("userid", userId); - params.put("extra",extra); - params.put("stationids",authenticationService.getStationPermissionsById(userId).stream().map(DeptStationDTO::getStationId).filter(StringUtil::isNotBlank).filter(Func::isNotEmpty).toArray()); - params.put("projectids",authenticationService.getStationPermissionsById(userId).stream().map(DeptStationDTO::getDeptId).filter(Func::isNotEmpty).map(String::valueOf).toArray()); - HttpResponse response = HttpRequest.post(fdpHost + bigModelInvokeUrl.getAssistantSpecialAsk()) - .body(JSON.toJSONString(params)).execute(); - if(response.getStatus() != HttpServletResponse.SC_OK) { - log.error("远程调用大模型【发起特殊问答】接口失败!"); - return R.fail("远程调用大模型【发起特殊问答】接口失败!"); - } - this.addQuestionSessionId(sessionId); - return R.success("消息发送成功"); - } - - @Override - public List hotQuestions() { - String url = fdpHost + bigModelInvokeUrl.getHotQuestion(); - return this.postCall(url,null,List.class); - } - - /** - * 远程调用http接口 - * @param url 接口url - * @param body 传参 - * @param resultT 结果解析对象 - * @return 结果 - * @param 结果解析对象类型 - */ - public 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, () -> { - log.error("远程调用大模型接口" + url + "失败!"); - throw new ServiceException("远程调用大模型接口" + url + "失败!"); - }); - return JSONObject.parseObject(response.body(), resultT); - } - - @Override - public void updateVideo(Map request) { - HttpResponse response = HttpRequest.post(fdpHost + bigModelInvokeUrl.getUpdateVideo()) - .body(JSON.toJSONString(request)).execute(); - Assert.isTrue(response.getStatus() == HttpServletResponse.SC_OK, () -> { - throw new ServiceException("远程调用大模型【更新实时监控】接口失败!"); - }); - } - - @Override - public Boolean updateCanvas(Map request) { - HttpResponse response = HttpRequest.post(fdpHost + bigModelInvokeUrl.getUpdateCanvas()) - .body(JSON.toJSONString(request)).execute(); - if (response.getStatus() == HttpServletResponse.SC_OK) { - return true; - } - log.error("远程调用大模型【更新实时画面】接口失败!"); - return false; - } - - @Override - public void updateFault(Map request) { - HttpResponse response = HttpRequest.post(fdpHost + bigModelInvokeUrl.getUpdateFault()) - .body(JSON.toJSONString(request)).execute(); - Assert.isTrue(response.getStatus() == HttpServletResponse.SC_OK, () -> { - throw new ServiceException("远程调用大模型【更新故障列表】接口失败!"); - }); - } - - @Override - public List getAnswerBySessionIds(String sessionIds) { - Map params = new HashMap<>(); - params.put("ids",Func.toStrList(",",sessionIds).toArray()); - HttpResponse response = HttpRequest.post(fdpHost + bigModelInvokeUrl.getAssistantStatus()) - .body(JSON.toJSONString(params)).execute(); - Assert.isTrue(response.getStatus() == HttpServletResponse.SC_OK, () -> { - throw new ServiceException("远程调用大模型【获取问题答案】接口失败!"); - }); - XxlJobLogger.log("接收到答案:"+JSON.toJSONString(response.body())); - List result = JSONArray.parseArray(response.body(), AnswerVO.class); - if(CollectionUtil.isNotEmpty(result)) { - logger.info("interactive:getAnswerBySessionIds","获取答案:" + response.body()); - } - return result; - } - - - - @Override - public Boolean authentication(String stationId, String userId, String func,String sessionId) { - // 站点鉴权 - if(StringUtil.isNotBlank(stationId)) { - authenticationService.stationAuthentication(stationId,userId); - } - // 菜单鉴权 - if(StringUtil.isNotBlank(func) && StringUtil.isNotBlank(userId)) { - authenticationService.menuAuthentication(userId,func); - } - // 遥控鉴权 - if(FuncRouteEnum.CONFIRM_YK.getFuncCode().equals(func)) { - authenticationService.remoteAuthentication(stationId,userId,sessionId); - } - return true; - } - - @Override - public Boolean removeSessionId(String sessionId) { - // 调用大模型删除对话 - Map params = new HashMap<>(); - params.put("id",sessionId); - HttpResponse response = HttpRequest.post(fdpHost + bigModelInvokeUrl.getAskAbort()) - .body(JSON.toJSONString(params)).execute(); - if(response.getStatus() != HttpServletResponse.SC_OK) { - log.error("远程调用大模型【删除对话】接口失败!"); - throw new ServiceException("远程调用大模型【删除对话】接口失败!"); - } - // 移除对应reids中问题标记 - redisTemplate.opsForList().remove(HZIMS_BIGMODEL_ASK_KEY,1,sessionId); - return true; - } - - /** - * 发起知识库问答 - */ - @Override - public R 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); - params.put("stationids", authenticationService.getStationPermissionsById(userId).stream().map(DeptStationDTO::getStationId) - .filter(StringUtil::isNotBlank).filter(Func::isNotEmpty).toArray()); - params.put("projectids", authenticationService.getStationPermissionsById(userId).stream().map(DeptStationDTO::getDeptId) - .filter(Func::isNotEmpty).map(String::valueOf).toArray()); - HttpResponse response = HttpRequest.post(fdpHost + bigModelInvokeUrl.getAssistantKnowledgeAsk()) - .body(JSON.toJSONString(params)).execute(); - logger.info("interactive:knowledgeAsk", "知识库问答传参为:" + JSON.toJSONString(params) + " 结果为:" + response.body()); - if (response.getStatus() != HttpServletResponse.SC_OK) { - log.error("远程调用大模型【发起知识库问答】接口失败!"); - return R.fail("远程调用大模型【发起知识库问答】接口失败!"); - } - this.addQuestionSessionId(sessionId); - return R.success("消息发送成功"); - } - - /** - * 下发遥控指令 - * @param operate - * @return - */ - @Override - public R sendRemoteControl(ControlDTO operate) { - return remoteClient.sendCtrl(operate); - } - - /** - * 站点发电量 - * @param stationId - * @param startTime - * @param endTime - * @return - */ - @Override - public Double generation(String stationId, String startTime, String endTime) { - // 步骤1.查询站点 - R station = stationClient.getStationByCode(stationId); - if(!station.isSuccess() || ObjectUtil.isEmpty(station.getData())){ - return 0.0; - } - // 步骤2.查询填报发电量 - double fill = generateClient.stationGenerateByTime(stationId,startTime,endTime); - - // 步骤3.查询设备 - List devices = deviceClient.rideDevices(Collections.singletonList(station.getData().getRefDept())); - if(CollectionUtil.isEmpty(devices)){ - return fill; - } - // 步骤4.遍历设备查询发电量 - // 监控线程执行完后返回结果 - CountDownLatch countDownLatch = new CountDownLatch(devices.size()); - List deviceGenerate = new CopyOnWriteArrayList(); - for(RideDeviceVo device : devices){ - pool.submit(()->{ - deviceGenerate.add(this.periodTargetFloat(startTime,endTime,5,6,device.getNumber(),device.getRide(), HomePageConstant.HYDROPOWER_GENERATE_POWER)); - }); - countDownLatch.countDown(); - } - //所有模板数据获取完成后释放锁 - try { - countDownLatch.await(); - } catch (InterruptedException e) { - e.printStackTrace(); - Thread.currentThread().interrupt(); - } - return fill + deviceGenerate.stream().mapToDouble(Double::doubleValue).sum(); - } - - /*** - * 指标数据列表查询 - * @param startTime 开始时间 - * @param endTime 结束时间 - * @param accessRules 取数规则 : 0=最早值 1=最大值 2=最小值 3=平均值 4=和值 5=差值 6=最新值 - * @param cycleType 间隔周期 : 0-> 秒 1-> 分 2-> 小时 3->天 4-> 周 5-> 月 6-> 年 - * @param deviceCode 设备编号 - * @param ride 配电比 - * @param signages 指标 - * @return - */ - private Double periodTargetFloat(String startTime, String endTime, Integer accessRules, Integer cycleType, String deviceCode,Double ride,String signages) { - AnalyseCodeByAnalyseDataPO po = new AnalyseCodeByAnalyseDataPO(); - List signboardConditions = new ArrayList<>(); - AnalyzeDataConditionPO analyzeDataConditionPO = new AnalyzeDataConditionPO(); - analyzeDataConditionPO.setFull(1); - po.setDeviceCode(deviceCode); - analyzeDataConditionPO.setSignages(signages); - analyzeDataConditionPO.setKeepFigures(2); - analyzeDataConditionPO.setAccessRules(accessRules); - analyzeDataConditionPO.setSaveTimeType(cycleType); - // 间隔 - analyzeDataConditionPO.setTimeInterval(1); - analyzeDataConditionPO.setBeginTime(LocalDateTime.parse(DateUtil.format(new Date(), startTime), DateTimeFormatter.ofPattern(DateUtil.PATTERN_DATETIME))); - analyzeDataConditionPO.setEndTime(LocalDateTime.parse(DateUtil.format(new Date(), endTime), DateTimeFormatter.ofPattern(DateUtil.PATTERN_DATETIME))); - signboardConditions.add(analyzeDataConditionPO); - po.setSignboardConditions(signboardConditions); - R> result = analyseDataSearchClient.getAnalyzeDataByAnalyzeCodeAndSignages(po); - if (!result.isSuccess() || CollectionUtil.isEmpty(result.getData())) { - return 0.0; - } - List records = result.getData(); - if(CollectionUtil.isEmpty(records)){ - return 0.0; - } - AnalyzeDataConditionVO analyzeDataConditionVO = records.get(0); - if (ObjectUtil.isEmpty(analyzeDataConditionVO)) { - return 0.0; - } - List analyseDataTaosVOList = analyzeDataConditionVO.getList(); - if (CollectionUtil.isEmpty(analyseDataTaosVOList)) { - return 0.0; - } - AnalyseDataTaosVO analyseDataTaosVO = analyzeDataConditionVO.getList().get(0); - if (ObjectUtil.isEmpty(analyseDataTaosVO) || StringUtil.isBlank(analyseDataTaosVO.getVal())) { - return 0.0; - } - return Double.parseDouble(analyseDataTaosVO.getVal()) * ride; - } -} 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 deleted file mode 100644 index 71bcc88..0000000 --- a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/JumpPageServiceImpl.java +++ /dev/null @@ -1,46 +0,0 @@ -package com.hnac.hzims.bigmodel.interactive.service.impl; - -import com.alibaba.fastjson.JSON; -import com.hnac.hzims.bigmodel.entity.FuncParamEntity; -import com.hnac.hzims.bigmodel.entity.FunctionEntity; -import com.hnac.hzims.bigmodel.function.service.IFuncParamService; -import com.hnac.hzims.bigmodel.interactive.constants.FunctionConstants; -import com.hnac.hzims.bigmodel.interactive.service.IJumpPageService; -import com.hnac.hzims.bigmodel.interactive.vo.ExtraVO; -import lombok.AllArgsConstructor; -import lombok.extern.slf4j.Slf4j; -import org.springblade.core.log.exception.ServiceException; -import org.springblade.core.tool.utils.StringUtil; -import org.springframework.stereotype.Service; -import org.springframework.util.Assert; - -import java.util.List; -import java.util.Map; -import java.util.Optional; -import java.util.Set; - -/** - * @Author: huangxing - * @Date: 2024/04/26 11:46 - */ -@Service -@AllArgsConstructor -@Slf4j -@Deprecated -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 -> p.getIsRequire()).filter(p -> !args.containsKey(p.getAlias())).findAny(); - Assert.isTrue(!paramOptional.isPresent(), () -> { - throw new ServiceException("解析参数失败,缺少参数:" + paramOptional.get().getName()); - }); - // 跳转页面逻辑 - ExtraVO extraVO = strategy.resolve(function,args); - 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 index e2e1cbd..838d3d7 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 @@ -1,6 +1,5 @@ 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; @@ -54,7 +53,7 @@ public class JumpRouteJoinStrategy { // 跳转页面逻辑 ExtraVO extraVO = new ExtraVO(); extraVO.setImmediatelyJump(true); - extraVO.setFunc(FuncRouteEnum.OPEN_CANVAS.getFuncCode()); + extraVO.setFunc(FuncRouteEnum.OPEN_CANVAS.getFunc()); Map params = this.scadaResolve(args); // 根据hz3000画面版本获取path Integer picResource = Integer.valueOf(params.get("picResource")); 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 e2a37b2..5a8d80c 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 @@ -57,7 +57,7 @@ public class ParamStrategy { StationVideoTypeEntity video = videoR.getData(); extraVO.setType(FunctionConstants.TypeEnum.PARAMS.getType()); extraVO.setImmediatelyJump(true); - extraVO.setFunc(FuncRouteEnum.OPEN_VIDEO.getFuncCode()); + extraVO.setFunc(FuncRouteEnum.OPEN_VIDEO.getFunc()); Map params = new HashMap<>(); params.put("name", video.getName()); params.put("videoHost", video.getVideoHost()); 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 deleted file mode 100644 index 7d134e1..0000000 --- a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/ParamsServiceImpl.java +++ /dev/null @@ -1,36 +0,0 @@ -package com.hnac.hzims.bigmodel.interactive.service.impl; - -import com.alibaba.fastjson.JSON; -import com.hnac.hzims.bigmodel.entity.FuncParamEntity; -import com.hnac.hzims.bigmodel.entity.FunctionEntity; -import com.hnac.hzims.bigmodel.interactive.service.IParamsService; -import com.hnac.hzims.bigmodel.interactive.vo.ExtraVO; -import lombok.AllArgsConstructor; -import lombok.extern.slf4j.Slf4j; -import org.springblade.core.log.exception.ServiceException; -import org.springframework.stereotype.Service; -import org.springframework.util.Assert; - -import java.util.List; -import java.util.Map; -import java.util.Optional; - -/** - * @Author: huangxing - * @Date: 2024/05/09 08:51 - */ -@Service -@Slf4j -@AllArgsConstructor -@Deprecated -public class ParamsServiceImpl implements IParamsService { - - private final ParamStrategy strategy; - - @Override - public String dealJumpTypeFunction(FunctionEntity function, Map args) { - // 跳转页面逻辑 - ExtraVO extraVO = strategy.resolve(function,args); - return JSON.toJSONString(extraVO); - } -} 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 index ee17050..10fbf2e 100644 --- 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 @@ -7,7 +7,6 @@ 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; @@ -15,7 +14,6 @@ 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; @@ -37,9 +35,9 @@ public class VideoResolveServiceImpl implements IResolveService { @Override public ExtraVO resolve(ModelFunctionReq req) { - Map args = req.getFunctionArgs(); - String id = args.get("id"); - String name = args.get("name"); + Map args = req.getItem(); + String id = args.get("itemId"); + String name = args.get("itemName"); Assert.isTrue(StringUtil.isNotBlank(id) && StringUtil.isNotBlank(name),() -> { logger.error("hzims:video:resolve","解析传参错误,缺少必要参数video_id,传参内容为:" + JSON.toJSONString(req)); throw new ServiceException("解析传参错误,缺少必要参数video_id"); @@ -60,7 +58,7 @@ public class VideoResolveServiceImpl implements IResolveService { StationVideoTypeEntity video = videoR.getData(); extraVO.setType(FunctionConstants.TypeEnum.PARAMS.getType()); extraVO.setImmediatelyJump(true); - extraVO.setFunc(FuncRouteEnum.OPEN_VIDEO.getFuncCode()); + extraVO.setFunc(FuncRouteEnum.OPEN_VIDEO.getFunc()); Map params = new HashMap<>(); params.put("name", video.getName()); params.put("videoHost", video.getVideoHost()); diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/maintenance/controller/DataSourceController.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/maintenance/controller/DataSourceController.java new file mode 100644 index 0000000..656910e --- /dev/null +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/maintenance/controller/DataSourceController.java @@ -0,0 +1,67 @@ +package com.hnac.hzims.bigmodel.maintenance.controller; + +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport; +import com.hnac.hzims.bigmodel.maintenance.entity.DatasourceEntity; +import com.hnac.hzims.bigmodel.maintenance.service.DataSourceService; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import io.swagger.annotations.ApiParam; +import lombok.AllArgsConstructor; +import org.springblade.core.mp.support.Condition; +import org.springblade.core.mp.support.Query; +import org.springblade.core.tool.api.R; +import org.springblade.core.tool.utils.Func; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.web.bind.annotation.*; + +/** + * @Author: huangxing + * @Date: 2024/07/05 16:55 + */ +@RestController +@RequestMapping("/datasource") +@Api(value = "数据源管理",tags = "数据源管理") +public class DataSourceController { + + @Autowired + @Qualifier("dataSourceMaintenanceService") + private DataSourceService dataSourceService; + + @GetMapping("/listPage") + @ApiOperation(value = "分页查询") + @ApiOperationSupport(order = 1) + public R> listPage(Query query, DatasourceEntity req) { + return R.data(dataSourceService.page(Condition.getPage(query),Condition.getQueryWrapper(req).lambda())); + } + + @GetMapping("/detail") + @ApiOperation(value = "分页查询") + @ApiOperationSupport(order = 2) + public R detail(@RequestParam @ApiParam("主键ID") Long id) { + return R.data(dataSourceService.getById(id)); + } + + @PostMapping("/save") + @ApiOperation(value = "保存数据源配置") + @ApiOperationSupport(order = 3) + public R save(@RequestBody DatasourceEntity req) { + return R.status(dataSourceService.save(req)); + } + + @DeleteMapping("/remove") + @ApiOperation(value = "删除数据源配置") + @ApiOperationSupport(order = 4) + public R remove(@RequestParam @ApiParam("主键ID,按逗号分隔") String ids) { + return R.status(dataSourceService.removeByIds(Func.toLongList(",",ids))); + } + + @PutMapping("/update") + @ApiOperation(value = "编辑数据源配置") + @ApiOperationSupport(order = 5) + public R update(@RequestBody DatasourceEntity req) { + return R.status(dataSourceService.updateById(req)); + } + +} diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/maintenance/controller/TableColumnController.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/maintenance/controller/TableColumnController.java index 79376ff..840f784 100644 --- a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/maintenance/controller/TableColumnController.java +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/maintenance/controller/TableColumnController.java @@ -33,22 +33,24 @@ public class TableColumnController { @ApiOperation("获取数据库") @ApiOperationSupport(order = 1) @GetMapping("/getDatabase") - public R>> getDatabase() { - return R.data(tableColumnService.getDatabase()); + public R>> getDatabase(@RequestParam @ApiParam(value = "数据源名") String datasource) { + return R.data(tableColumnService.getDatabase(datasource)); } @ApiOperation("获取数据库表列表") @ApiOperationSupport(order = 2) @GetMapping("/getTables") - public R>> getTables(@RequestParam @ApiParam(value = "数据库名") String database) { - return R.data(tableColumnService.getTables(database)); + public R>> getTables(@RequestParam @ApiParam(value = "数据源名") String datasource, + @RequestParam @ApiParam(value = "数据库名") String database) { + return R.data(tableColumnService.getTables(datasource,database)); } @ApiOperation("获取数据库表列列表") @ApiOperationSupport(order = 3) @GetMapping("/getColumns") - public R>> getColumns(@RequestParam @ApiParam(value = "数据库名") String database, + public R>> getColumns(String datasource, + @RequestParam @ApiParam(value = "数据源名") String database, @RequestParam @ApiParam(value = "数据库表名") String tableName) { - return R.data(tableColumnService.getColumns(database,tableName)); + return R.data(tableColumnService.getColumns(datasource,database,tableName)); } } diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/maintenance/controller/TablePropertyController.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/maintenance/controller/TablePropertyController.java new file mode 100644 index 0000000..88412f0 --- /dev/null +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/maintenance/controller/TablePropertyController.java @@ -0,0 +1,66 @@ +package com.hnac.hzims.bigmodel.maintenance.controller; + +import com.baomidou.mybatisplus.core.metadata.IPage; +import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport; +import com.hnac.hzims.bigmodel.maintenance.entity.TablePropertyEntity; +import com.hnac.hzims.bigmodel.maintenance.service.TablePropertyService; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import io.swagger.annotations.ApiParam; +import lombok.AllArgsConstructor; +import org.springblade.core.mp.support.Condition; +import org.springblade.core.mp.support.Query; +import org.springblade.core.tool.api.R; +import org.springblade.core.tool.utils.Func; +import org.springframework.web.bind.annotation.*; + +import java.util.List; + +/** + * @Author: huangxing + * @Date: 2024/07/05 15:19 + */ +@RestController +@RequestMapping("/table/property") +@Api(value = "表配置",tags = "表配置") +@AllArgsConstructor +public class TablePropertyController { + + private final TablePropertyService tablePropertyService; + + @GetMapping("/listPage") + @ApiOperation(value = "分页查询") + @ApiOperationSupport(order = 1) + public R> listPage(Query query, TablePropertyEntity req) { + return R.data(tablePropertyService.page(Condition.getPage(query),Condition.getQueryWrapper(req).lambda())); + } + + @GetMapping("/detail") + @ApiOperation(value = "分页查询") + @ApiOperationSupport(order = 2) + public R detail(@RequestParam @ApiParam("主键ID") Long id) { + return R.data(tablePropertyService.getById(id)); + } + + @PostMapping("/save") + @ApiOperation(value = "保存表配置") + @ApiOperationSupport(order = 3) + public R save(@RequestBody TablePropertyEntity req) { + return R.status(tablePropertyService.save(req)); + } + + @DeleteMapping("/remove") + @ApiOperation(value = "删除表配置") + @ApiOperationSupport(order = 4) + public R remove(@RequestParam @ApiParam("主键ID,按逗号分隔") String ids) { + return R.status(tablePropertyService.removeByIds(Func.toLongList(",",ids))); + } + + @PutMapping("/update") + @ApiOperation(value = "编辑表配置") + @ApiOperationSupport(order = 5) + public R update(@RequestBody TablePropertyEntity req) { + return R.status(tablePropertyService.updateById(req)); + } + +} diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/maintenance/entity/DatasourceEntity.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/maintenance/entity/DatasourceEntity.java new file mode 100644 index 0000000..0ed6f68 --- /dev/null +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/maintenance/entity/DatasourceEntity.java @@ -0,0 +1,33 @@ +package com.hnac.hzims.bigmodel.maintenance.entity; + +import com.baomidou.mybatisplus.annotation.TableName; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.EqualsAndHashCode; +import org.springblade.core.mp.support.QueryField; +import org.springblade.core.mp.support.SqlCondition; +import org.springblade.core.tenant.mp.TenantEntity; + +import java.io.Serializable; + +/** + * @Author: huangxing + * @Date: 2024/07/05 14:45 + */ +@Data +@EqualsAndHashCode +@TableName("HZIMS_DATASOURCE") +@ApiModel(value = "数据源配置",description = "数据源配置") +public class DatasourceEntity extends TenantEntity implements Serializable { + + @ApiModelProperty("数据源名称") + @QueryField(condition = SqlCondition.LIKE) + private String datasourceName; + + @ApiModelProperty("数据库名称") + @QueryField(condition = SqlCondition.LIKE) + private String databaseName; + +} diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/maintenance/entity/TablePropertyEntity.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/maintenance/entity/TablePropertyEntity.java new file mode 100644 index 0000000..003d46b --- /dev/null +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/maintenance/entity/TablePropertyEntity.java @@ -0,0 +1,49 @@ +package com.hnac.hzims.bigmodel.maintenance.entity; + +import com.baomidou.mybatisplus.annotation.TableName; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import org.springblade.core.mp.support.QueryField; +import org.springblade.core.mp.support.SqlCondition; +import org.springblade.core.tenant.mp.TenantEntity; + +import javax.validation.constraints.NotBlank; +import javax.validation.constraints.NotNull; +import java.io.Serializable; + +/** + * @Author: huangxing + * @Date: 2024/07/05 14:49 + */ +@ApiModel("数据库表配置") +@TableName("HZIMS_TABLE_PROPERTY") +@Data +public class TablePropertyEntity extends TenantEntity implements Serializable { + + @ApiModelProperty("数据源Id") + @QueryField(condition = SqlCondition.EQUAL) + @NotNull + private Long datasourceId; + + @ApiModelProperty("数据源名称") + @QueryField(condition = SqlCondition.LIKE) + @NotNull + private String datasourceName; + + @ApiModelProperty("数据库名") + @QueryField(condition = SqlCondition.LIKE) + @NotBlank + private String databaseName; + + @ApiModelProperty("数据表名") + @QueryField(condition = SqlCondition.LIKE) + @NotBlank + private String tableName; + + @ApiModelProperty("鉴权类型") + @QueryField(condition = SqlCondition.EQUAL) + @NotBlank + private String authType; + +} diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/maintenance/mapper/DatasourceMapper.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/maintenance/mapper/DatasourceMapper.java new file mode 100644 index 0000000..b62ce18 --- /dev/null +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/maintenance/mapper/DatasourceMapper.java @@ -0,0 +1,12 @@ +package com.hnac.hzims.bigmodel.maintenance.mapper; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.hnac.hzims.bigmodel.maintenance.entity.DatasourceEntity; + +/** + * @Author: huangxing + * @Date: 2024/07/05 15:05 + */ +public interface DatasourceMapper extends BaseMapper { + +} diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/maintenance/mapper/TablePropertyMapper.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/maintenance/mapper/TablePropertyMapper.java new file mode 100644 index 0000000..e4d1333 --- /dev/null +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/maintenance/mapper/TablePropertyMapper.java @@ -0,0 +1,11 @@ +package com.hnac.hzims.bigmodel.maintenance.mapper; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.hnac.hzims.bigmodel.maintenance.entity.TablePropertyEntity; + +/** + * @Author: huangxing + * @Date: 2024/07/05 15:12 + */ +public interface TablePropertyMapper extends BaseMapper { +} diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/maintenance/service/DataSourceService.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/maintenance/service/DataSourceService.java new file mode 100644 index 0000000..a58f598 --- /dev/null +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/maintenance/service/DataSourceService.java @@ -0,0 +1,19 @@ +package com.hnac.hzims.bigmodel.maintenance.service; + +import com.hnac.hzims.bigmodel.maintenance.entity.DatasourceEntity; +import com.hnac.hzims.bigmodel.maintenance.mapper.DatasourceMapper; +import lombok.AllArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springblade.core.mp.base.BaseServiceImpl; +import org.springframework.stereotype.Service; + +/** + * @Author: huangxing + * @Date: 2024/07/05 15:06 + */ +@Service("dataSourceMaintenanceService") +@Slf4j +@AllArgsConstructor +public class DataSourceService extends BaseServiceImpl { + +} diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/maintenance/service/TableColumnService.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/maintenance/service/TableColumnService.java index 8c31998..888d575 100644 --- a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/maintenance/service/TableColumnService.java +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/maintenance/service/TableColumnService.java @@ -20,19 +20,19 @@ public class TableColumnService { private final DataSourceService dataSourceService; - public List> getDatabase() { - String sql = "select distinct `table_schema` from `tables` where `table_schema` <> 'information_schema';"; - return dataSourceService.queryListOnSpecificDataSource(sql,"information"); + public List> getDatabase(String datasource) { + String sql = "select distinct `table_schema` from `information_schema`.`tables` where `table_schema` <> 'information_schema';"; + return dataSourceService.queryListOnSpecificDataSource(sql,datasource); } - public List> getTables(String database) { - String sql = "select distinct `table_name` from `tables` where `table_schema` = '" + database + "';"; - return dataSourceService.queryListOnSpecificDataSource(sql,"information"); + public List> getTables(String datasource,String database) { + String sql = "select distinct `table_name` from `information_schema`.`tables` where `table_schema` = '" + database + "';"; + return dataSourceService.queryListOnSpecificDataSource(sql,datasource); } - public List> getColumns(String database,String tableName) { - String sql = "select `COLUMN_NAME` from `COLUMNS` where `TABLE_SCHEMA` = '" + database + "' and `TABLE_NAME` = '" + tableName + "';"; - return dataSourceService.queryListOnSpecificDataSource(sql,"information"); + public List> getColumns(String datasource,String database,String tableName) { + String sql = "select distinct `column_name`,`column_comment` from `information_schema`.`COLUMNS` where `TABLE_SCHEMA` = '" + database + "' and `TABLE_NAME` = '" + tableName + "';"; + return dataSourceService.queryListOnSpecificDataSource(sql,datasource); } } diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/maintenance/service/TablePropertyService.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/maintenance/service/TablePropertyService.java new file mode 100644 index 0000000..f78294b --- /dev/null +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/maintenance/service/TablePropertyService.java @@ -0,0 +1,20 @@ +package com.hnac.hzims.bigmodel.maintenance.service; + +import com.hnac.hzims.bigmodel.maintenance.entity.TablePropertyEntity; +import com.hnac.hzims.bigmodel.maintenance.mapper.TablePropertyMapper; +import lombok.AllArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springblade.core.mp.base.BaseService; +import org.springblade.core.mp.base.BaseServiceImpl; +import org.springframework.stereotype.Service; + +/** + * @Author: huangxing + * @Date: 2024/07/05 15:11 + */ +@Service +@AllArgsConstructor +@Slf4j +public class TablePropertyService extends BaseServiceImpl { + +} 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 deleted file mode 100644 index 6ca3031..0000000 --- a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/schedule/InteractiveSchedule.java +++ /dev/null @@ -1,201 +0,0 @@ -package com.hnac.hzims.bigmodel.schedule; - -import com.alibaba.fastjson.JSON; -import com.alibaba.fastjson.JSONObject; -import com.hnac.hzims.bigmodel.interactive.service.IInteractiveService; -import com.hnac.hzims.bigmodel.interactive.service.impl.ExtraResolveStrategyService; -import com.hnac.hzims.bigmodel.interactive.vo.AnswerVO; -import com.hnac.hzims.bigmodel.interactive.vo.UpdateStationVO; -import com.hnac.hzims.bigmodel.interactive.vo.UpdateUsualVO; -import com.hnac.hzims.bigmodel.websocket.service.InteractiveWsService; -import com.hnac.hzims.bigmodel.websocket.sessionManager.InteractiveSessionManager; -import com.hnac.hzims.operational.station.entity.StationEntity; -import com.hnac.hzims.operational.station.entity.StationVideoTypeEntity; -import com.hnac.hzims.operational.station.feign.IStationClient; -import com.hnac.hzims.operational.station.feign.IStationVideoTypeClient; -import com.hnac.hzinfo.sdk.core.response.Result; -import com.hnac.hzinfo.sdk.v5.project.ProjectClient; -import com.hnac.hzinfo.sdk.v5.project.vo.ProjectVO; -import com.hnac.hzinfo.sdk.v5.scada.ScadaClient; -import com.hnac.hzinfo.sdk.v5.scada.vo.CanvasVO; -import com.xxl.job.core.biz.model.ReturnT; -import com.xxl.job.core.handler.annotation.XxlJob; -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.scheduling.annotation.Scheduled; -import org.springframework.stereotype.Component; -import org.springframework.web.socket.TextMessage; -import org.springframework.web.socket.WebSocketSession; - -import java.util.*; -import java.util.concurrent.CompletableFuture; -import java.util.concurrent.ThreadPoolExecutor; -import java.util.stream.Collectors; - -import static com.hnac.hzims.bigmodel.schedule.XxlJobHandlerConstant.*; - -/** - * @Author: huangxing - * @Date: 2024/04/28 16:18 - */ -@Component -@AllArgsConstructor -@Deprecated -public class InteractiveSchedule { - - private final InteractiveWsService wsService; - - private final IInteractiveService interactiveService; - - private final ThreadPoolExecutor getAnswerPoolExecutor; - - private final RedisTemplate redisTemplate; - - private final IStationVideoTypeClient videoClient; - - private final ProjectClient projectClient; - - private final ScadaClient scadaClient; - - private final IStationClient stationClient; - - private final ExtraResolveStrategyService extraResolveStrategyService; - - // @XxlJob(GET_INTERACTIVE_RESULT) - public ReturnT getInteractiveResult(String params) { - List sessionIds = redisTemplate.opsForList().range(HZIMS_BIGMODEL_ASK_KEY, 0, -1); - if(CollectionUtil.isEmpty(sessionIds)){ - XxlJobLogger.log("问题都已经回答完毕!"); - return ReturnT.SUCCESS; - } - List answerList = interactiveService.getAnswerBySessionIds(String.join(",", sessionIds)); - answerList.stream().parallel().forEach(answerVO -> CompletableFuture.runAsync(() -> { - // 如果已经获取到答案 则删除缓存 - if(answerVO.getRunning() == 0) { - redisTemplate.opsForList().remove(HZIMS_BIGMODEL_ASK_KEY,1,answerVO.getSessionId()); - } - Object[] extras = answerVO.getExtras(); - if(ObjectUtil.isNotEmpty(answerVO.getExtras()) && extras.length > 0){ - try { - List extraList = Arrays.stream(extras).map(Object::toString).map(extraResolveStrategyService::resolve).map(JSON::toJSONString).collect(Collectors.toList()); - answerVO.setExtras(extraList.toArray(new String[extraList.size()])); - } - catch(Exception e) { - e.printStackTrace(); - AnswerVO.error(answerVO); - answerVO.setAnswer("非常抱歉,系统在处理您的请求时遇到了问题。请稍后再试或联系我们的客服团队。"); - } - } - if(sessionIds.contains(answerVO.getSessionId())){ - WebSocketSession session = InteractiveSessionManager.get(answerVO.getSessionId()); - TextMessage message = InteractiveSessionManager.getTextMessage("1",JSON.toJSONString(answerVO)); - if(Func.isNotEmpty(session)) { - wsService.sendMessage(session,message); - } - } - }, getAnswerPoolExecutor)); - return ReturnT.SUCCESS; - } - - @XxlJob(SYNCHRONOUS_VIDEO_INSTRUCT) - public ReturnT synchronousVideoInstruct(String params) { - Map request = new HashMap<>(2); - // 获取站点列表 - R> stationsR = stationClient.list(new StationEntity()); - if(!stationsR.isSuccess() || CollectionUtil.isEmpty(stationsR.getData())) { - XxlJobLogger.log("获取站点列表失败!"); - return ReturnT.FAIL; - } - List updateStationList = stationsR.getData().stream().map(station -> { - UpdateStationVO stationVO = new UpdateStationVO(); - stationVO.setId(station.getCode()); - stationVO.setName(station.getName()); - return stationVO; - }).collect(Collectors.toList()); - request.put("stations", updateStationList); - // 获取视频列表 - R> videoListR = videoClient.list(new StationVideoTypeEntity()); - if(!videoListR.isSuccess() || CollectionUtil.isEmpty(videoListR.getData())) { - XxlJobLogger.log("获取视频列表失败!"); - return ReturnT.FAIL; - } - List updateUsualList = videoListR.getData().stream().map(video -> { - UpdateUsualVO usualVO = new UpdateUsualVO(); - usualVO.setStationId(video.getStationId()); - usualVO.setId(String.valueOf(video.getId())); - usualVO.setName(video.getName()); - return usualVO; - }).collect(Collectors.toList()); - request.put("videos", updateUsualList); - // 同步指令 - interactiveService.updateVideo(request); - return ReturnT.SUCCESS; - } - - @XxlJob(SYNCHRONOUS_SCADA_INSTRUCT) - public ReturnT synchronousScadaInstruct(String params) { - // 查询项目数据 - Result> projects = projectClient.getProjectByAppId(); - if(!projects.isSuccess() || CollectionUtil.isEmpty(projects.getData())){ - return ReturnT.SUCCESS; - } - // 请求fdp同步实时画面方法参数定义 - Map param = new HashMap<>(2); - List stations = projects.getData().stream().map(station -> { - UpdateStationVO updateStation = new UpdateStationVO(); - updateStation.setId(station.getId()); - updateStation.setName(station.getName()); - return updateStation; - }).collect(Collectors.toList()); - param.put("stations", stations); - // 查询画面信息 - Result> canvas = scadaClient.getCanvasList(projects.getData().stream().map(ProjectVO::getId).collect(Collectors.toList())); - if(!canvas.isSuccess() || CollectionUtil.isEmpty(canvas.getData())) { - return ReturnT.SUCCESS; - } - List updateUsuals = canvas.getData().stream().map(canva -> { - UpdateUsualVO usualVO = new UpdateUsualVO(); - usualVO.setStationId(canva.getProjectId()); - usualVO.setName(canva.getName()); - // 画面id = - String id = Optional.of(canva.getPicSource()).map(String::valueOf).orElse("") + "^" + - Optional.ofNullable(canva.getContext()).orElse("") + "^" + - Optional.ofNullable(canva.getStationNum()).orElse("") + "^" + - Optional.ofNullable(canva.getProjectId()).orElse("") + "^" + - Optional.ofNullable(canva.getTaskId()).map(String::valueOf).orElse("") + "^" + - Optional.ofNullable(canva.getName()).orElse("") + "^" + - Optional.ofNullable(canva.getId()).map(String::valueOf).orElse("") + "^"; - usualVO.setId(id); - return usualVO; - }).collect(Collectors.toList()); - param.put("canvases", updateUsuals); - Boolean status = interactiveService.updateCanvas(param); - return ReturnT.SUCCESS; - } - - @XxlJob(SYNCHRONOUS_FAULT_INSTRUCT) - public ReturnT synchronousFaultInstruct(String params) { - Map request = new HashMap<>(2); - // 获取站点列表 - R> stationsR = stationClient.list(new StationEntity()); - if(!stationsR.isSuccess() || CollectionUtil.isEmpty(stationsR.getData())) { - XxlJobLogger.log("获取站点列表失败!"); - return ReturnT.FAIL; - } - List updateStationList = stationsR.getData().stream().map(station -> { - UpdateStationVO stationVO = new UpdateStationVO(); - stationVO.setId(station.getCode()); - stationVO.setName(station.getName()); - return stationVO; - }).collect(Collectors.toList()); - request.put("stations", updateStationList); - interactiveService.updateFault(request); - return ReturnT.SUCCESS; - } -} diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/websocket/handler/InteractiveHandler.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/websocket/handler/InteractiveHandler.java index 594981b..2c76eb5 100644 --- a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/websocket/handler/InteractiveHandler.java +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/websocket/handler/InteractiveHandler.java @@ -13,15 +13,11 @@ import com.hnac.hzims.bigmodel.interactive.service.IInteractiveService; import com.hnac.hzims.bigmodel.websocket.constants.RedisKeyConstants; import com.hnac.hzims.bigmodel.websocket.service.InteractiveWsService; import com.hnac.hzims.bigmodel.websocket.sessionManager.InteractiveSessionManager; -import lombok.AllArgsConstructor; -import lombok.NoArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springblade.core.tool.api.R; -import org.springblade.core.tool.utils.BeanUtil; import org.springblade.core.tool.utils.Func; import org.springblade.core.tool.utils.SpringUtil; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.data.redis.core.RedisTemplate; import org.springframework.stereotype.Component; import org.springframework.web.socket.CloseStatus; @@ -33,7 +29,6 @@ import java.io.IOException; import java.util.HashMap; import java.util.Map; import java.util.concurrent.TimeUnit; -import java.util.function.Function; /** * @Author: huangxing @@ -94,13 +89,11 @@ public class InteractiveHandler extends TextWebSocketHandler { String context = messageContext.getString("context"); String userId = messageContext.getString("userId"); String knowledge = messageContext.getString("knowledge"); - IInteractiveService interactiveService = SpringUtil.getBean(IInteractiveService.class); + IHznlmInvokeService hznlmInvokeService = SpringUtil.getBean(IHznlmInvokeService.class); if (knowledge != null) { - R askResult = interactiveService.knowledgeAsk(context, sessionId, userId, knowledge); - log.info("知识库问答返回结果:" + JSON.toJSONString(askResult)); + hznlmInvokeService.knowledgeAsk(context, sessionId, userId, knowledge); } else { - R askResult = interactiveService.ask(context, sessionId, userId); - log.info("返回结果为:"+ JSON.toJSONString(askResult)); + hznlmInvokeService.ask(context, sessionId, userId); } } else { @@ -170,7 +163,7 @@ public class InteractiveHandler extends TextWebSocketHandler { Map param = new HashMap<>(1); param.put("canvas_id",selection.getId()); IFunctionService functionService = SpringUtil.getBean(IFunctionService.class); - FunctionEntity function = functionService.getFunctionByCode(FuncRouteEnum.OPEN_CANVAS.getFuncCode()); + FunctionEntity function = functionService.getFunctionByCode(FuncRouteEnum.OPEN_CANVAS.getFunc()); ExtraVO scadaExtra = strategy.getScadaExtra(param, function); AnswerVO answerVO = new AnswerVO(); answerVO.setSessionId(sessionId); diff --git a/hzims-service/hzims-big-model/src/main/resources/db/2.0.0.sql b/hzims-service/hzims-big-model/src/main/resources/db/2.0.0.sql new file mode 100644 index 0000000..8c3c5cc --- /dev/null +++ b/hzims-service/hzims-big-model/src/main/resources/db/2.0.0.sql @@ -0,0 +1,31 @@ +CREATE TABLE IF NOT EXISTS `HZIMS_TABLE_PROPERTY` ( + `ID` bigint(20) NOT NULL COMMENT '主键ID', + `DATASOURCE_ID` BIGINT(50) NOT NULL COMMENT '数据源Id', + `DATASOURCE_NAME` varchar(50) NOT NULL COLLATE utf8mb4_bin NOT NULL COMMENT '数据源名', + `DATABASE_NAME` varchar(50) NOT NULL COLLATE utf8mb4_bin NOT NULL COMMENT '数据库名', + `TABLE_NAME` varchar(100) NOT NULL COLLATE utf8mb4_bin NOT NULL COMMENT '数据表名', + `AUTH_TYPE` varchar(20) NOT NULL COLLATE utf8mb4_bin NOT NULL COMMENT '鉴权类型', + `TENANT_ID` varchar(12) CHARACTER SET utf8 DEFAULT NULL COMMENT '租户ID', + `STATUS` bigint(1) DEFAULT NULL COMMENT '状态', + `CREATE_DEPT` bigint(20) DEFAULT NULL COMMENT '创建单位', + `CREATE_USER` bigint(20) DEFAULT NULL COMMENT '创建人', + `CREATE_TIME` datetime DEFAULT NULL COMMENT '创建时间', + `UPDATE_USER` bigint(20) DEFAULT NULL COMMENT '修改人', + `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='数据库表配置'; + +CREATE TABLE IF NOT EXISTS `HZIMS_TABLE_PROPERTY` ( + `ID` bigint(20) NOT NULL COMMENT '主键ID', + `DATASOURCE_NAME` varchar(50) COLLATE utf8mb4_bin NOT NULL COMMENT '数据源名', + `DATABASE_NAME` varchar(50) NOT NULL COLLATE utf8mb4_bin NOT NULL COMMENT '数据库名', + `STATUS` bigint(1) DEFAULT NULL COMMENT '状态', + `CREATE_DEPT` bigint(20) DEFAULT NULL COMMENT '创建单位', + `CREATE_USER` bigint(20) DEFAULT NULL COMMENT '创建人', + `CREATE_TIME` datetime DEFAULT NULL COMMENT '创建时间', + `UPDATE_USER` bigint(20) DEFAULT NULL COMMENT '修改人', + `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