diff --git a/hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/api/dto/CanvasSyncDTO.java b/hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/api/dto/CanvasSyncDTO.java new file mode 100644 index 0000000..45a4bd0 --- /dev/null +++ b/hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/api/dto/CanvasSyncDTO.java @@ -0,0 +1,20 @@ +package com.hnac.hzims.bigmodel.api.dto; + +import io.swagger.annotations.ApiModel; +import lombok.Data; +import lombok.EqualsAndHashCode; + +import java.io.Serializable; + +/** + * @Author: huangxing + * @Date: 2024/07/09 19:48 + */ +@Data +@EqualsAndHashCode +@ApiModel(value = "实时画面同步DTO对象",description = "实时画面同步DTO对象") +public class CanvasSyncDTO extends SyncDTO implements Serializable { + + + +} diff --git a/hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/api/dto/ControlSyncDTO.java b/hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/api/dto/ControlSyncDTO.java new file mode 100644 index 0000000..a1121fd --- /dev/null +++ b/hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/api/dto/ControlSyncDTO.java @@ -0,0 +1,20 @@ +package com.hnac.hzims.bigmodel.api.dto; + +import io.swagger.annotations.ApiModel; +import lombok.Data; +import lombok.EqualsAndHashCode; + +import java.io.Serializable; + +/** + * @Author: huangxing + * @Date: 2024/07/09 19:51 + */ +@Data +@EqualsAndHashCode +@ApiModel(value = "遥控同步DTO对象",description = "遥控同步DTO对象") +public class ControlSyncDTO extends SyncDTO implements Serializable { + + + +} diff --git a/hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/api/dto/SyncDTO.java b/hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/api/dto/SyncDTO.java new file mode 100644 index 0000000..19507de --- /dev/null +++ b/hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/api/dto/SyncDTO.java @@ -0,0 +1,50 @@ +package com.hnac.hzims.bigmodel.api.dto; + +import com.alibaba.fastjson.annotation.JSONField; +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 19:33 + */ +@Data +@EqualsAndHashCode +@ApiModel(value = "视频同步DTO",description = "视频同步DTO") +public class SyncDTO implements Serializable { + + @ApiModelProperty("数据ID") + private String id; + + @ApiModelProperty("在问答流程中使用的数据ID") + @JSONField(name = "item_id") + private String itemId; + + @ApiModelProperty("用于匹配的名字。应包含所有匹配相关信息") + @JSONField(name = "item_name") + private String itemName; + + @ApiModelProperty("类型,可为'平台'或'业务'") + private String type; + + @ApiModelProperty("站点I,平台yk必须有,否则可为null") + @JSONField(name = "station_id") + private String stationId; + + @ApiModelProperty("站点名称,平台yk必须有,否则可为null") + @JSONField(name = "station_name") + private String stationName; + + @ApiModelProperty("设备ID,平台yk必须有,否则可为null") + @JSONField(name = "device_id") + private String deviceId; + + @ApiModelProperty("设备名称,平台yk必须有,否则可为null") + @JSONField(name = "device_name") + private String deviceName; + +} diff --git a/hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/api/dto/VideoSyncDTO.java b/hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/api/dto/VideoSyncDTO.java new file mode 100644 index 0000000..3969228 --- /dev/null +++ b/hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/api/dto/VideoSyncDTO.java @@ -0,0 +1,20 @@ +package com.hnac.hzims.bigmodel.api.dto; + +import io.swagger.annotations.ApiModel; +import lombok.Data; +import lombok.EqualsAndHashCode; + +import java.io.Serializable; + +/** + * @Author: huangxing + * @Date: 2024/07/09 19:42 + */ +@ApiModel(value = "视频同步DTO对象",description = "视频同步DTO对象") +@Data +@EqualsAndHashCode +public class VideoSyncDTO extends SyncDTO implements Serializable { + + + +} diff --git a/hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/api/feign/ICanvasSyncClient.java b/hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/api/feign/ICanvasSyncClient.java new file mode 100644 index 0000000..e92cfec --- /dev/null +++ b/hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/api/feign/ICanvasSyncClient.java @@ -0,0 +1,12 @@ +package com.hnac.hzims.bigmodel.api.feign; + +import com.hnac.hzims.bigmodel.api.dto.CanvasSyncDTO; + +/** + * @Author: huangxing + * @Date: 2024/07/09 19:53 + */ +public interface ICanvasSyncClient extends ISyncClient { + + +} diff --git a/hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/api/feign/IControlSyncClient.java b/hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/api/feign/IControlSyncClient.java new file mode 100644 index 0000000..f35a680 --- /dev/null +++ b/hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/api/feign/IControlSyncClient.java @@ -0,0 +1,11 @@ +package com.hnac.hzims.bigmodel.api.feign; + +import com.hnac.hzims.bigmodel.api.dto.ControlSyncDTO; + +/** + * @Author: huangxing + * @Date: 2024/07/09 19:55 + */ +public interface IControlSyncClient extends ISyncClient { + +} diff --git a/hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/api/feign/ISyncClient.java b/hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/api/feign/ISyncClient.java new file mode 100644 index 0000000..8744be5 --- /dev/null +++ b/hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/api/feign/ISyncClient.java @@ -0,0 +1,40 @@ +package com.hnac.hzims.bigmodel.api.feign; + +import com.hnac.hzims.bigmodel.api.dto.SyncDTO; +import org.springblade.core.tool.api.R; +import org.springframework.web.bind.annotation.RequestBody; + +import java.util.List; + +/** + * @Author: huangxing + * @Date: 2024/07/09 19:32 + */ +public interface ISyncClient { + + String SAVE_BATCH = "/saveBatch"; + String UPDATE_BY_ID = "/updateById"; + String DELETE_BY_IDS = "/deleteByIds"; + + /** + * 同步 - 新增对象 + * @param syncDTO 同步对象列表 + * @return 同步结果 + */ + R saveBatch(List syncDTO); + + /** + * 同步 - 更新对象 + * @param syncDTO 同步对象 + * @return 同步结果 + */ + R updateById(T syncDTO); + + /** + * 同步 - 删除对象 + * @param ids 主键id按逗号分隔 + * @return 删除结果 + */ + R deleteByIds(String ids); + +} diff --git a/hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/api/feign/IVideoSyncClient.java b/hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/api/feign/IVideoSyncClient.java new file mode 100644 index 0000000..5af759e --- /dev/null +++ b/hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/api/feign/IVideoSyncClient.java @@ -0,0 +1,33 @@ +package com.hnac.hzims.bigmodel.api.feign; + +import com.hnac.hzims.bigmodel.BigModelConstants; +import com.hnac.hzims.bigmodel.api.dto.SyncDTO; +import com.hnac.hzims.bigmodel.api.dto.VideoSyncDTO; +import org.springblade.core.tool.api.R; +import org.springframework.cloud.openfeign.FeignClient; +import org.springframework.web.bind.annotation.*; + +import java.util.List; + +/** + * @Author: huangxing + * @Date: 2024/07/09 19:31 + */ +@FeignClient(name = BigModelConstants.APP_NAME) +public interface IVideoSyncClient extends ISyncClient { + + String PREFIX_API = "/feign/sync/video"; + + @Override + @PostMapping(PREFIX_API + SAVE_BATCH) + R saveBatch(@RequestBody List syncDTO); + + @Override + @PutMapping(PREFIX_API + UPDATE_BY_ID) + R updateById(@RequestBody VideoSyncDTO syncDTO); + + @Override + @DeleteMapping(PREFIX_API + DELETE_BY_IDS) + R deleteByIds(@RequestParam String ids); + +} 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..5301c0d --- /dev/null +++ b/hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/business/feign/IAuthClient.java @@ -0,0 +1,45 @@ +package com.hnac.hzims.bigmodel.business.feign; + +import com.hnac.hzims.bigmodel.business.dto.ControlDeviceAuthDTO; +import org.springblade.core.tool.api.R; + +import java.util.List; +import java.util.Map; + +/** + * @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); + + /** + * 获取用户权限数据 + * @param userId 用户ID + * @return 权限数据 + */ + R> getAuthData(String userId); +} diff --git a/hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/entity/WhitelistEntity.java b/hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/entity/WhitelistEntity.java new file mode 100644 index 0000000..cc563f0 --- /dev/null +++ b/hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/entity/WhitelistEntity.java @@ -0,0 +1,24 @@ +package com.hnac.hzims.bigmodel.entity; + +import com.baomidou.mybatisplus.annotation.TableName; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; +import lombok.EqualsAndHashCode; +import org.springblade.core.tenant.mp.TenantEntity; + +/** + * @author ysj + */ +@EqualsAndHashCode(callSuper = true) +@TableName("hzims_whitelist") +@ApiModel(value = "白名单实体类",description = "大模型白名单") +@Data +public class WhitelistEntity extends TenantEntity { + + @ApiModelProperty(value = "用户Id") + private Long userId; + + @ApiModelProperty(value = "用户登录账号") + private String account; +} 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/AttrSelectionVO.java b/hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/interactive/vo/AttrSelectionVO.java new file mode 100644 index 0000000..67f0011 --- /dev/null +++ b/hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/interactive/vo/AttrSelectionVO.java @@ -0,0 +1,14 @@ +package com.hnac.hzims.bigmodel.interactive.vo; + +import lombok.Data; + +import java.io.Serializable; + +/** + * @Author: huangxing + * @Date: 2024/05/24 15:55 + */ +@Data +public class AttrSelectionVO extends SelectionVO implements Serializable { + private DataItemVO item; +} diff --git a/hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/interactive/vo/DataItemVO.java b/hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/interactive/vo/DataItemVO.java new file mode 100644 index 0000000..d4e8d76 --- /dev/null +++ b/hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/interactive/vo/DataItemVO.java @@ -0,0 +1,40 @@ +package com.hnac.hzims.bigmodel.interactive.vo; + +import com.alibaba.fastjson.annotation.JSONField; +import lombok.Data; + +import java.io.Serializable; + +/** + * @Author: huangxing + * @Date: 2024/05/22 10:20 + */ +@Data +public class DataItemVO implements Serializable { + + private String name; + + @JSONField(name = "itemId") + private String attrId; + + @JSONField(name = "record_name") + private String attrName; + + @JSONField(name = "device_name") + private String deviceName; + + @JSONField(name = "device_id") + private String deviceId; + + @JSONField(name = "station_id") + private String projectId; + + @JSONField(name = "station_name") + private String projectName; + + @JSONField(name = "record_id") + private String signage; + + private String units; + +} diff --git a/hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/interactive/vo/DataVO.java b/hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/interactive/vo/DataVO.java new file mode 100644 index 0000000..b23874f --- /dev/null +++ b/hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/interactive/vo/DataVO.java @@ -0,0 +1,35 @@ +package com.hnac.hzims.bigmodel.interactive.vo; + +import com.alibaba.fastjson.annotation.JSONField; +import lombok.Data; + +import java.io.Serializable; + +/** + * @Author: huangxing + * @Date: 2024/05/22 10:28 + */ +@Data +public class DataVO implements Serializable { + + /**数据查询类型:实时、历史**/ + private String type; + + @JSONField(name = "time_begin") + private String startTime; + + @JSONField(name = "time_end") + private String endTime; + + /**实时数据结果集**/ + private RealDataVO real; + + private DataItemVO item; + + /**包括:"其它"、"最大值"、"最小值"、"总和值"、"平均值"**/ + private String method; + + @JSONField(name = "data_type") + private String dataType; + +} diff --git a/hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/interactive/vo/ExtraVO.java b/hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/interactive/vo/ExtraVO.java index 303a21e..d9be4d7 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,10 +1,15 @@ 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; import java.io.Serializable; +import java.util.List; +import java.util.Map; /** * @Author: huangxing @@ -14,16 +19,38 @@ import java.io.Serializable; @ApiModel("响应内容") public class ExtraVO implements Serializable { - @ApiModelProperty("交互类型") + @ApiModelProperty("交互类型 1:打开页面,2:打开链接,3:参数传递,4:完善选项") private String type; @ApiModelProperty("若为弹窗,则返回路由") + @JsonInclude(JsonInclude.Include.NON_NULL) private String route; @ApiModelProperty("链接显示文字") + @JsonInclude(JsonInclude.Include.NON_NULL) private String label; + @ApiModelProperty("函数编号") + private String func; + @ApiModelProperty("是否立即跳转") - private boolean isImmediatelyJump = true; + 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 data; + + @JSONField(name = "agent_name") + private String agentName; + + @JSONField(name = "agent_data") + private Map agentData; } diff --git a/hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/interactive/vo/FaultSelectionVO.java b/hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/interactive/vo/FaultSelectionVO.java new file mode 100644 index 0000000..a504076 --- /dev/null +++ b/hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/interactive/vo/FaultSelectionVO.java @@ -0,0 +1,18 @@ +package com.hnac.hzims.bigmodel.interactive.vo; + +import lombok.Data; +import lombok.EqualsAndHashCode; + +import java.io.Serializable; + +/** + * @Author: huangxing + * @Date: 2024/05/16 15:10 + */ +@Data +@EqualsAndHashCode +public class FaultSelectionVO extends SelectionVO implements Serializable { + + private Object item; + +} diff --git a/hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/interactive/vo/RealDataVO.java b/hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/interactive/vo/RealDataVO.java new file mode 100644 index 0000000..16a5a46 --- /dev/null +++ b/hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/interactive/vo/RealDataVO.java @@ -0,0 +1,20 @@ +package com.hnac.hzims.bigmodel.interactive.vo; + +import com.fasterxml.jackson.annotation.JsonFormat; +import lombok.Data; +import org.springblade.core.tool.utils.DateUtil; + +import java.io.Serializable; + +/** + * @Author: huangxing + * @Date: 2024/05/24 10:26 + */ +@Data +public class RealDataVO implements Serializable { + + private String time; + + private String value; + +} diff --git a/hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/interactive/vo/RemoteSelectionVO.java b/hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/interactive/vo/RemoteSelectionVO.java new file mode 100644 index 0000000..07d95d8 --- /dev/null +++ b/hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/interactive/vo/RemoteSelectionVO.java @@ -0,0 +1,13 @@ +package com.hnac.hzims.bigmodel.interactive.vo; + +import java.io.Serializable; + +/** + * @Author: huangxing + * @Date: 2024/05/31 09:15 + */ +public class RemoteSelectionVO extends SelectionVO implements Serializable { + + private Object item; + +} diff --git a/hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/interactive/vo/ScadaSelectionVO.java b/hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/interactive/vo/ScadaSelectionVO.java new file mode 100644 index 0000000..9b0f7e0 --- /dev/null +++ b/hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/interactive/vo/ScadaSelectionVO.java @@ -0,0 +1,18 @@ +package com.hnac.hzims.bigmodel.interactive.vo; + +import lombok.Data; +import lombok.EqualsAndHashCode; + +import java.io.Serializable; + +/** + * @Author: huangxing + * @Date: 2024/05/11 16:21 + */ +@Data +@EqualsAndHashCode +public class ScadaSelectionVO extends SelectionVO implements Serializable { + + private Object item; + +} diff --git a/hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/interactive/vo/SelectionVO.java b/hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/interactive/vo/SelectionVO.java new file mode 100644 index 0000000..e953435 --- /dev/null +++ b/hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/interactive/vo/SelectionVO.java @@ -0,0 +1,23 @@ +package com.hnac.hzims.bigmodel.interactive.vo; + +import com.alibaba.fastjson.annotation.JSONField; +import lombok.Data; + +import java.io.Serializable; + +/** + * @Author: huangxing + * @Date: 2024/05/09 16:30 + */ +@Data +public class SelectionVO implements Serializable { + + /**选项ID**/ + @JSONField(name = "item_id") + private String itemId; + + /**选项名称**/ + @JSONField(name = "item_name") + private String itemName; + +} diff --git a/hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/interactive/vo/StationSelectionVO.java b/hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/interactive/vo/StationSelectionVO.java new file mode 100644 index 0000000..84209d9 --- /dev/null +++ b/hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/interactive/vo/StationSelectionVO.java @@ -0,0 +1,15 @@ +package com.hnac.hzims.bigmodel.interactive.vo; + +import com.hnac.hzims.bigmodel.interactive.vo.SelectionVO; +import lombok.Data; + +import java.io.Serializable; + +/** + * @Author: huangxing + * @Date: 2024/05/09 16:32 + */ +@Data +public class StationSelectionVO extends SelectionVO implements Serializable { + +} diff --git a/hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/interactive/vo/VideoSelectionVO.java b/hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/interactive/vo/VideoSelectionVO.java new file mode 100644 index 0000000..0bcc529 --- /dev/null +++ b/hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/interactive/vo/VideoSelectionVO.java @@ -0,0 +1,16 @@ +package com.hnac.hzims.bigmodel.interactive.vo; + +import lombok.Data; +import lombok.EqualsAndHashCode; + +import java.io.Serializable; + +/** + * @Author: huangxing + * @Date: 2024/05/11 16:20 + */ +@Data +@EqualsAndHashCode +public class VideoSelectionVO extends SelectionVO implements Serializable { + +} diff --git a/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/fill/feign/IGenerateClient.java b/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/fill/feign/IGenerateClient.java new file mode 100644 index 0000000..d73fa37 --- /dev/null +++ b/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/fill/feign/IGenerateClient.java @@ -0,0 +1,26 @@ +package com.hnac.hzims.operational.fill.feign; + +import com.hnac.hzims.operational.OperationalConstants; +import org.springframework.cloud.openfeign.FeignClient; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestParam; + +/** + * @author ysj + */ +@FeignClient( + value = OperationalConstants.APP_NAME, + fallback = IGenerateClientFallback.class +) +public interface IGenerateClient { + + String API_PREFIX = "/feign/generate/"; + + String STATION_GENERATE_BY_TIME = API_PREFIX + "/stationGenerateByTime"; + + + @GetMapping(STATION_GENERATE_BY_TIME) + Double stationGenerateByTime(@RequestParam("stationId") String stationId, + @RequestParam("startTime") String startTime, + @RequestParam("endTime") String endTime); +} diff --git a/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/fill/feign/IGenerateClientFallback.java b/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/fill/feign/IGenerateClientFallback.java new file mode 100644 index 0000000..da7c067 --- /dev/null +++ b/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/fill/feign/IGenerateClientFallback.java @@ -0,0 +1,15 @@ +package com.hnac.hzims.operational.fill.feign; + +import org.springframework.stereotype.Component; + +/** + * @author hx + */ +@Component +public class IGenerateClientFallback implements IGenerateClient { + + @Override + public Double stationGenerateByTime(String stationId, String startTime, String endTime) { + return 0.0; + } +} diff --git a/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/station/feign/IStationClient.java b/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/station/feign/IStationClient.java index cc8856a..28019bd 100644 --- a/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/station/feign/IStationClient.java +++ b/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/station/feign/IStationClient.java @@ -30,7 +30,7 @@ public interface IStationClient { String LIST = API_PREFIX + "/list"; String QUERY_EXIST_LGTD_LTTD = API_PREFIX + "/queryExistLgtdAndLttd"; String GET_ONE = API_PREFIX + "/getOne"; - + String GET_STATIONS_BY_TYPE_AND_DURATION = API_PREFIX + "/getStationByTypeAndDuration"; String QUERY_STATION_BY_CODES = API_PREFIX + "/querySatationByCodes"; @GetMapping(GET_LIST_ALL) @@ -81,4 +81,7 @@ public interface IStationClient { */ @PostMapping(QUERY_STATION_BY_CODES) R> querySatationByCodes(@RequestParam("codes") List codes); + + @GetMapping(GET_STATIONS_BY_TYPE_AND_DURATION) + R> getStationByTypeAndDuration(@RequestParam(required = false) String startTime,@RequestParam(required = false) String endTime,@RequestParam(required = false) String type); } diff --git a/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/station/feign/IStationClientFallBack.java b/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/station/feign/IStationClientFallBack.java index 32dfb51..0607d79 100644 --- a/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/station/feign/IStationClientFallBack.java +++ b/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/station/feign/IStationClientFallBack.java @@ -77,4 +77,9 @@ public class IStationClientFallBack implements IStationClient { public R> querySatationByCodes(List codes) { return R.data(new ArrayList<>()); } + + @Override + public R> getStationByTypeAndDuration(String startTime, String endTime, String type) { + return R.fail("远程调用失败!"); + } } diff --git a/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/station/feign/IStationVideoTypeClient.java b/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/station/feign/IStationVideoTypeClient.java index 46e26c4..b29e3e2 100644 --- a/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/station/feign/IStationVideoTypeClient.java +++ b/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/station/feign/IStationVideoTypeClient.java @@ -4,6 +4,7 @@ import com.hnac.hzims.operational.OperationalConstants; import com.hnac.hzims.operational.station.entity.StationVideoTypeEntity; import org.springblade.core.tool.api.R; import org.springframework.cloud.openfeign.FeignClient; +import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestParam; @@ -16,7 +17,16 @@ import java.util.List; public interface IStationVideoTypeClient { String API_PREFIX = "/feign/station/videoType"; String LIST_BY_STATION_ID = API_PREFIX + "/listByStationId"; + String LIST = API_PREFIX + "/list"; + String GET_BY_ID = API_PREFIX + "/getById"; + String GET_RTSP_ADDRESS_BY_ID = API_PREFIX + "/getRtspAddressById"; @PostMapping(LIST_BY_STATION_ID) List listByStationId(@RequestParam("stationId") String stationId); + + @GetMapping(LIST) + R> list(StationVideoTypeEntity req); + + @GetMapping(GET_BY_ID) + R getById(@RequestParam Long id); } diff --git a/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/station/feign/IStationVideoTypeClientFallback.java b/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/station/feign/IStationVideoTypeClientFallback.java index 24fb9db..5ee3541 100644 --- a/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/station/feign/IStationVideoTypeClientFallback.java +++ b/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/station/feign/IStationVideoTypeClientFallback.java @@ -16,4 +16,15 @@ public class IStationVideoTypeClientFallback implements IStationVideoTypeClient log.info("调用{}接口失败",LIST_BY_STATION_ID); return new ArrayList(); } + + @Override + public R> list(StationVideoTypeEntity req) { + return R.fail("远程调用失败!"); + } + + @Override + public R getById(Long id) { + return R.fail("远程调用失败!"); + } + } diff --git a/hzims-service/hzims-big-model/pom.xml b/hzims-service/hzims-big-model/pom.xml index fa26e50..35ad20c 100644 --- a/hzims-service/hzims-big-model/pom.xml +++ b/hzims-service/hzims-big-model/pom.xml @@ -13,24 +13,12 @@ - org.springblade - blade-common - - - org.springblade - blade-system-api - - - com.hnac.hzims big-model-api 4.0.0-SNAPSHOT compile - - org.eclipse.paho - org.eclipse.paho.client.mqttv3 - + org.springframework.boot @@ -47,6 +35,29 @@ com.xuxueli xxl-job-core + + org.springblade + blade-system-api + + + + com.hnac.hzims + hzims-operational-api + 4.0.0-SNAPSHOT + + + com.hnac.hzinfo.data + hzinfo-data-sdk + + + com.hnac.hzims + equipment-api + + + com.baomidou + dynamic-datasource-spring-boot-starter + 2.5.6 + diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/HzimsBigModelApplication.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/HzimsBigModelApplication.java index e6e8393..3d58539 100644 --- a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/HzimsBigModelApplication.java +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/HzimsBigModelApplication.java @@ -1,31 +1,39 @@ package com.hnac.hzims.bigmodel; +import lombok.extern.slf4j.Slf4j; import org.mybatis.spring.annotation.MapperScan; import org.springblade.core.cloud.feign.EnableBladeFeign; +import org.springblade.core.jwt.JwtUtil; import org.springblade.core.launch.BladeApplication; -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.builder.SpringApplicationBuilder; import org.springframework.boot.web.servlet.support.SpringBootServletInitializer; import org.springframework.cloud.client.SpringCloudApplication; -import org.springframework.cloud.openfeign.EnableFeignClients; import org.springframework.context.annotation.ComponentScan; -import org.springframework.scheduling.annotation.EnableScheduling; +import org.springframework.data.redis.core.RedisTemplate; import javax.annotation.Resource; -@SpringBootApplication(scanBasePackages = {"org.springblade", "com.hnac.*"}) -@MapperScan(basePackages = {"com.hnac.hzinfo.**.mapper","com.hnac.hzims.**.mapper"}) -@EnableFeignClients(basePackages = {"org.springblade", "com.hnac"}) -public class HzimsBigModelApplication { +import static com.hnac.hzims.bigmodel.schedule.XxlJobHandlerConstant.HZIMS_BIGMODEL_ASK_KEY; + +@EnableBladeFeign(basePackages = {"org.springblade","com.hnac"}) +@SpringCloudApplication +@MapperScan("com.hnac.hzims.**.mapper.**") +@Resource +@ComponentScan(basePackages = {"com.hnac.hzims.**"}) +@Slf4j +public class HzimsBigModelApplication extends SpringBootServletInitializer { + public static void main(String[] args) { BladeApplication.run(BigModelConstants.APP_NAME, HzimsBigModelApplication.class, args); + RedisTemplate redisTemplate = JwtUtil.getRedisTemplate(); + redisTemplate.delete(HZIMS_BIGMODEL_ASK_KEY); + log.info("服务重启删除问题reids缓存:{}",HZIMS_BIGMODEL_ASK_KEY); } -// @Override -// protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) { -// return BladeApplication.createSpringApplicationBuilder(builder, BigModelConstants.APP_NAME, HzimsBigModelApplication.class); -// } + @Override + protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) { + return BladeApplication.createSpringApplicationBuilder(builder, BigModelConstants.APP_NAME, HzimsBigModelApplication.class); + } } diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/api/feign/VideoSyncClient.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/api/feign/VideoSyncClient.java new file mode 100644 index 0000000..58cf420 --- /dev/null +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/api/feign/VideoSyncClient.java @@ -0,0 +1,35 @@ +package com.hnac.hzims.bigmodel.api.feign; + +import com.hnac.hzims.bigmodel.api.dto.VideoSyncDTO; +import lombok.AllArgsConstructor; +import org.springblade.core.tool.api.R; +import org.springframework.web.bind.annotation.*; + +import java.util.List; + +/** + * @Author: huangxing + * @Date: 2024/07/09 20:17 + */ +@RestController +@AllArgsConstructor +public class VideoSyncClient implements IVideoSyncClient{ + + @Override + @PostMapping(PREFIX_API + SAVE_BATCH) + public R saveBatch(@RequestBody List syncDTO) { + return null; + } + + @Override + @PutMapping(PREFIX_API + UPDATE_BY_ID) + public R updateById(@RequestBody VideoSyncDTO syncDTO) { + return null; + } + + @Override + @DeleteMapping(PREFIX_API + DELETE_BY_IDS) + public R deleteByIds(@RequestParam String ids) { + return null; + } +} diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/api/service/SyncService.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/api/service/SyncService.java new file mode 100644 index 0000000..422989f --- /dev/null +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/api/service/SyncService.java @@ -0,0 +1,16 @@ +package com.hnac.hzims.bigmodel.api.service; + +import lombok.AllArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Service; + +/** + * @Author: huangxing + * @Date: 2024/07/10 09:03 + */ +@Service +@Slf4j +@AllArgsConstructor +public class SyncService { + +} diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/business/control/DataSourceExecuteController.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/business/control/DataSourceExecuteController.java new file mode 100644 index 0000000..4efcf3b --- /dev/null +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/business/control/DataSourceExecuteController.java @@ -0,0 +1,33 @@ +package com.hnac.hzims.bigmodel.business.control; + +import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport; +import com.hnac.hzims.bigmodel.business.service.DataSourceService; +import com.hnac.hzims.bigmodel.business.vo.SqlVO; +import io.swagger.annotations.ApiOperation; +import lombok.AllArgsConstructor; +import org.springblade.core.tool.api.R; +import org.springframework.web.bind.annotation.*; + +import javax.validation.Valid; +import java.util.List; +import java.util.Map; + +/** + * @Author: huangxing + * @Date: 2024/06/28 14:07 + */ +@RestController +@RequestMapping("/dataSource/execute") +@AllArgsConstructor +public class DataSourceExecuteController { + + private final DataSourceService dataSourceService; + + @PostMapping("/executeQuery") + @ApiOperation("执行大模型sql") + @ApiOperationSupport(order = 1) + public R>> executeQuery(@RequestBody @Valid SqlVO sqlVO) { + return R.data(dataSourceService.queryListOnSpecificDataSource(sqlVO)); + } + +} diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/business/control/RemoteController.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/business/control/RemoteController.java new file mode 100644 index 0000000..9f2a798 --- /dev/null +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/business/control/RemoteController.java @@ -0,0 +1,36 @@ +package com.hnac.hzims.bigmodel.business.control; + +import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport; +import com.hnac.hzims.bigmodel.BigModelConstants; +import com.hnac.hzims.bigmodel.business.service.RemoteService; +import com.hnac.hzinfo.log.annotation.Business; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import lombok.AllArgsConstructor; +import org.springblade.core.tool.api.R; +import org.springblade.system.dto.ControlDTO; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +/** + * @Author: huangxing + * @Date: 2024/06/24 14:42 + */ +@AllArgsConstructor +@RequestMapping("/remote") +@RestController +@Api(value = "数据平台遥控指令管理",tags = "数据平台遥控指令管理") +@Business(module = BigModelConstants.APP_NAME,value = "数据平台遥控指令管理") +public class RemoteController { + + private final RemoteService remoteService; + + @ApiOperation("下发遥控指令") + @ApiOperationSupport(order = 1) + @PostMapping("/sendRemoteControl") + public R sendRemoteControl(ControlDTO controlDTO) { + return remoteService.sendRemoteControl(controlDTO); + } + +} 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..08a3d85 --- /dev/null +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/business/feign/AuthClient.java @@ -0,0 +1,87 @@ +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.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Optional; +import java.util.stream.Collectors; + +/** + * @Author: huangxing + * @Date: 2024/07/09 09:31 + */ +@Component +@AllArgsConstructor +@Slf4j +public class AuthClient implements IAuthClient { + + private final AuthenticationService authenticationService; + + /** + * 设备控制鉴权 + * @param req 遥控信息 + * @return 鉴权结果 + */ + @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("鉴权成功"); + } + + /** + * 站点鉴权 + * @param userId 用户ID + * @param stationId 站点ID + * @return 鉴权结果 + */ + @Override + public R stationAuth(String userId, String stationId) { + return R.status(authenticationService.stationAuthentication(stationId,userId)); + } + + /** + * 机构鉴权 + * @param userId 用户ID + * @param deptId 站点ID + * @return 鉴权结果 + */ + @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); + } + + /** + * 获取用户权限数据 + * @param userId 用户ID + * @return 权限数据 - 站点、机构 + */ + @Override + public R> getAuthData(String userId) { + Map result = new HashMap<>(2); + List deptStationDTOList = authenticationService.getStationPermissionsById(userId); + String[] stationIds = deptStationDTOList.stream().map(DeptStationDTO::getStationId).filter(StringUtil::isNotBlank).toArray(String[]::new); + String[] deptIds = deptStationDTOList.stream().map(DeptStationDTO::getDeptId).map(String::valueOf).toArray(String[]::new); + result.put("stationids",stationIds); + result.put("projectids",deptIds); + return R.data(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..13db6f2 --- /dev/null +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/business/service/AuthenticationService.java @@ -0,0 +1,119 @@ +package com.hnac.hzims.bigmodel.business.service; + +import com.google.common.collect.Lists; +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; + +/** + * @Author: huangxing + * @Date: 2024/05/21 16:10 + */ +@Service +@AllArgsConstructor +public class AuthenticationService { + + private final IDeptClient deptClient; + 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(stationId::equals); + } + + /** + * 菜单鉴权 + * @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() == 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/business/service/DataSourceService.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/business/service/DataSourceService.java new file mode 100644 index 0000000..5e305aa --- /dev/null +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/business/service/DataSourceService.java @@ -0,0 +1,121 @@ +package com.hnac.hzims.bigmodel.business.service; + +import com.baomidou.dynamic.datasource.toolkit.DynamicDataSourceContextHolder; +import com.hnac.hzims.bigmodel.business.vo.SqlVO; +import com.hnac.hzims.bigmodel.business.vo.TableAuthVO; +import com.hnac.hzims.common.service.UserAuthDataService; +import lombok.AllArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springblade.core.log.exception.ServiceException; +import org.springframework.jdbc.core.JdbcTemplate; +import org.springframework.stereotype.Service; +import org.springframework.util.Assert; + +import java.util.List; +import java.util.Map; +import java.util.regex.Pattern; + +/** + * @Author: huangxing + * @Date: 2024/06/28 15:24 + */ +@Service +@AllArgsConstructor +@Slf4j +public class DataSourceService { + + private final JdbcTemplate jdbcTemplate; + private final UserAuthDataService userAuthDataService; + + private static final Pattern UPDATE_PATTERN = Pattern.compile("^UPDATE\\s", Pattern.CASE_INSENSITIVE); + private static final Pattern DELETE_PATTERN = Pattern.compile("^DELETE\\s", Pattern.CASE_INSENSITIVE); + + + public List> queryListOnSpecificDataSource(SqlVO sqlVO) { + // 过滤更新、删除语句 + Assert.isTrue(!DataSourceService.isUpdateOrDelete(sqlVO.getSql()),() -> { + throw new ServiceException("执行sql语句包含更新/删除操作,执行失败!"); + }); + String sql = sqlVO.getSql(); + String userAuthDataSQL = userAuthDataService.getUserAuthDataSQL(Long.parseLong(sqlVO.getUserId())); + for (TableAuthVO tableAuthVO : sqlVO.getTableAuthVOList()) { + 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()),() -> { +// throw new ServiceException("执行sql语句包含更新/删除操作,执行失败!"); +// }); +// String sql = sqlVO.getSql(); +// String userAuthDataSQL = userAuthDataService.getUserAuthDataSQL(Long.parseLong(sqlVO.getUserId())); +// List> tempViewList = Lists.newArrayList(); +// try { +// for (TableAuthVO tableAuthVO : sqlVO.getTableAuthVOList()) { +// // 创建视图语句 +// String viewName = "V_TEMP_" + UUID.randomUUID().toString().replace("-", ""); +// String createView = "CREATE VIEW " + viewName + " AS SELECT * FROM " + tableAuthVO.getTableName() + " where " + userAuthDataSQL; +// this.updateOnSpecificDataSource(createView,tableAuthVO.getDatasourceName()); +// Map viewMap = new HashMap(2); +// viewMap.put("datasource",tableAuthVO.getDatasourceName()); +// viewMap.put("viewName",viewName); +// tempViewList.add(viewMap); +// sql = sql.replace(tableAuthVO.getTableName(),viewName); +// } +// log.info("执行sql:{}",sql); +// return this.queryListOnSpecificDataSource(sql, sqlVO.getTableAuthVOList().get(0).getDatasourceName()); +// } +// catch(Exception e) { +// log.error("An Error occurred!",e); +// throw new ServiceException("sql执行失败!"); +// } +// finally { +// if(CollectionUtil.isNotEmpty(tempViewList)) { +// tempViewList.forEach(viewMap -> { +// this.updateOnSpecificDataSource("DROP VIEW IF EXISTS `" + viewMap.get("viewName")+"`;",viewMap.get("datasource")); +// }); +// } +// } + } + + /** + * sql + * @param sql + * @param dataSourceName + * @return + */ + public List> queryListOnSpecificDataSource(String sql,String dataSourceName) { + // 切换到指定的数据源 + DynamicDataSourceContextHolder.push(dataSourceName); + try { + return jdbcTemplate.queryForList(sql); + } finally { + // 清除,恢复默认数据源 + DynamicDataSourceContextHolder.clear(); + } + } + + public Integer updateOnSpecificDataSource(String sql,String dataSourceName) { + // 切换到指定的数据源 + DynamicDataSourceContextHolder.push(dataSourceName); + try { + return jdbcTemplate.update(sql); + } finally { + // 清除,恢复默认数据源 + DynamicDataSourceContextHolder.clear(); + } + } + + /** + * 过滤更新、删除语法的sql脚本 + * @param sql 待执行sql脚本 + * @return 执行结果 + */ + public static boolean isUpdateOrDelete(String sql) { + if (sql == null) { + return false; + } + return UPDATE_PATTERN.matcher(sql).find() || DELETE_PATTERN.matcher(sql).find(); + } +} diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/business/service/HistoryDataService.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/business/service/HistoryDataService.java new file mode 100644 index 0000000..edd905c --- /dev/null +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/business/service/HistoryDataService.java @@ -0,0 +1,97 @@ +package com.hnac.hzims.bigmodel.business.service; + +import com.alibaba.fastjson.JSON; +import com.google.common.collect.Lists; +import com.hnac.hzims.bigmodel.interactive.constants.DataMethodEnum; +import com.hnac.hzims.bigmodel.interactive.constants.DateEnum; +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 lombok.extern.slf4j.Slf4j; +import org.springblade.core.log.exception.ServiceException; +import org.springblade.core.log.logger.BladeLogger; +import org.springblade.core.tool.utils.DateUtil; +import org.springblade.core.tool.utils.Func; +import org.springframework.stereotype.Service; +import org.springframework.util.Assert; + +import java.time.Duration; +import java.time.LocalDateTime; +import java.time.temporal.ChronoUnit; + +/** + * @Author: huangxing + * @Date: 2024/06/24 14:57 + */ +@Service +@Slf4j +@AllArgsConstructor +public class HistoryDataService { + + private final DeviceDataClient deviceDataClient; + private final BladeLogger logger; + public static final int DATA_COUNT_MAX = 1000; + + public Result getPolymerizationData(HistoryDataSearchVO searchVO) { + DataMethodEnum enumByMethod = DataMethodEnum.getEnumByMethod(searchVO.getMethod()); + Assert.isTrue(Func.isNotEmpty(enumByMethod),() -> { + throw new ServiceException("数据查询聚合方式传参有误,查询失败!"); + }); + // 聚合数据方式处理 + DateEnum dateEnum = DateEnum.getDateEnumByType(searchVO.getDataType()); + ReductionDataDTO dataDTO = new ReductionDataDTO(); + ReductionAttrDataDTO reductionAttrData = new ReductionAttrDataDTO(); + reductionAttrData.setSignage(searchVO.getSignage()); + reductionAttrData.setAccessRules(enumByMethod.getAccessRule()); + reductionAttrData.setKeepFigures(2); + dataDTO.setBeginTime(LocalDateTime.parse(searchVO.getStartTime(), DateUtil.DATETIME_FORMATTER)); + dataDTO.setEndTime(LocalDateTime.parse(searchVO.getEndTime(),DateUtil.DATETIME_FORMATTER)); + dataDTO.setDeviceCode(searchVO.getDeviceCode()); + dataDTO.setNeedPage(false); + dataDTO.setSaveTimeType(dateEnum.getSaveTimeType()); + dataDTO.setTimeInterval(1); + dataDTO.setDtos(Lists.newArrayList(reductionAttrData)); + logger.info("interactive:getPolymerizationData","config传参为:" + JSON.toJSONString(dataDTO)); + return deviceDataClient.pageDeviceCodeAndSignages(dataDTO); + } + + public DateEnum getDateEnumByDuration(String startTime,String endTime,DateEnum dateEnum) { + LocalDateTime start = LocalDateTime.parse(startTime, DateUtil.DATETIME_FORMATTER); + LocalDateTime end = LocalDateTime.parse(endTime, DateUtil.DATETIME_FORMATTER); + Duration duration = Duration.between(start, end); + int count; + switch(dateEnum) { + case YEAR: + count = Long.valueOf(ChronoUnit.YEARS.between(start.toLocalDate(), end.toLocalDate())).intValue(); + break; + case MONTH: + count = Long.valueOf(ChronoUnit.MONTHS.between(start.toLocalDate(), end.toLocalDate())).intValue(); + break; + case DAY: + count = Long.valueOf(ChronoUnit.DAYS.between(start.toLocalDate(), end.toLocalDate())).intValue(); + break; + case HOUR: + count = Long.valueOf(duration.toHours()).intValue(); + break; + case MINUTE: + count = Long.valueOf(duration.toMinutes()).intValue(); + break; + case SECOND: + count = Long.valueOf(duration.getSeconds()).intValue(); + break; + default: + throw new ServiceException("未找到相关时间类型,查询失败!"); + } + if(count <= DATA_COUNT_MAX) { + return dateEnum; + } + else { + return getDateEnumByDuration(startTime, endTime, DateEnum.getDateEnumByOrder(dateEnum.getOrder() + 1)); + } + } + +} diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/business/service/RemoteService.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/business/service/RemoteService.java new file mode 100644 index 0000000..96e8259 --- /dev/null +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/business/service/RemoteService.java @@ -0,0 +1,31 @@ +package com.hnac.hzims.bigmodel.business.service; + +import lombok.AllArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springblade.core.tool.api.R; +import org.springblade.system.dto.ControlDTO; +import org.springblade.system.feign.IRemoteClient; +import org.springframework.stereotype.Service; + +/** + * @Author: huangxing + * @Date: 2024/06/24 14:36 + * @Descirbe: 数据平台 - 遥控服务类 + */ +@Service +@Slf4j +@AllArgsConstructor +public class RemoteService { + + private final IRemoteClient remoteClient; + + /** + * 发送遥控指令 + * @param controlDTO 遥控指令 + * @return 结果 + */ + public R sendRemoteControl(ControlDTO controlDTO) { + return remoteClient.sendCtrl(controlDTO); + } + +} diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/business/vo/SqlVO.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/business/vo/SqlVO.java new file mode 100644 index 0000000..5a5bff8 --- /dev/null +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/business/vo/SqlVO.java @@ -0,0 +1,32 @@ +package com.hnac.hzims.bigmodel.business.vo; + +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/05 08:19 + */ +@ApiModel(value = "",description = "") +@Data +@EqualsAndHashCode +public class SqlVO implements Serializable { + + @ApiModelProperty("执行sql") + @NotBlank + private String sql; + + @ApiModelProperty("执行人") + @NotBlank + private String userId; + + @ApiModelProperty("执行sql设计表信息") + private List tableAuthVOList; + +} diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/business/vo/TableAuthVO.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/business/vo/TableAuthVO.java new file mode 100644 index 0000000..b1524fa --- /dev/null +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/business/vo/TableAuthVO.java @@ -0,0 +1,28 @@ +package com.hnac.hzims.bigmodel.business.vo; + +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/04 17:29 + */ +@ApiModel(value = "表鉴权对象",description = "表鉴权对象") +@Data +@EqualsAndHashCode +public class TableAuthVO implements Serializable { + + @ApiModelProperty("鉴权类型,目前不为空即为平台数据权限") + private String auth; + + @ApiModelProperty("数据源名称") + private String datasourceName; + + @ApiModelProperty("数据表名称") + private String tableName; + +} diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/configuration/BigModelInvokeUrl.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/configuration/BigModelInvokeUrl.java index 70a539d..996a155 100644 --- a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/configuration/BigModelInvokeUrl.java +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/configuration/BigModelInvokeUrl.java @@ -15,6 +15,19 @@ public class BigModelInvokeUrl { private String assistantAsk; + private String assistantSpecialAsk; + private String assistantStatus; + private String askAbort; + + private String updateVideo; + + private String updateFault; + + private String updateCanvas; + + private String assistantKnowledgeAsk; + + private String hotQuestion; } diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/function/controller/FunctionController.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/function/controller/FunctionController.java deleted file mode 100644 index bffa1db..0000000 --- a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/function/controller/FunctionController.java +++ /dev/null @@ -1,73 +0,0 @@ -package com.hnac.hzims.bigmodel.function.controller; - -import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; -import com.baomidou.mybatisplus.core.metadata.IPage; -import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport; -import com.hnac.hzims.bigmodel.BigModelConstants; -import com.hnac.hzims.bigmodel.entity.FunctionEntity; -import com.hnac.hzims.bigmodel.function.service.IFunctionService; -import com.hnac.hzims.common.utils.Condition; -import com.hnac.hzinfo.log.annotation.Business; -import io.swagger.annotations.Api; -import io.swagger.annotations.ApiModel; -import io.swagger.annotations.ApiOperation; -import lombok.AllArgsConstructor; -import org.springblade.core.mp.support.Query; -import org.springblade.core.tool.api.R; -import org.springblade.core.tool.utils.BeanUtil; -import org.springblade.core.tool.utils.Func; -import org.springframework.validation.annotation.Validated; -import org.springframework.web.bind.annotation.*; - -import java.util.List; - -/** - * @Author: huangxing - * @Date: 2024/04/29 14:39 - */ -@RestController -@RequestMapping("/function") -@Api(value = "大模型函数管理",tags = "大模型函数管理") -@Business(module = BigModelConstants.MODULE_NAME,value = "大模型函数管理") -@AllArgsConstructor -public class FunctionController { - - private final IFunctionService functionService; - - @PostMapping("/save") - @ApiOperation("保存函数") - @ApiOperationSupport(order = 1) - public R save(@RequestBody @Validated FunctionEntity req) { - return R.status(functionService.save(req)); - } - - @PutMapping("/save") - @ApiOperation("编辑函数") - @ApiOperationSupport(order = 2) - public R updateById(@RequestBody FunctionEntity req) { - return R.status(functionService.save(req)); - } - - @GetMapping("/list") - @ApiOperation("列表查询") - @ApiOperationSupport(order = 3) - public R> list(FunctionEntity req) { - return R.data(functionService.list(Condition.getQueryWrapper(BeanUtil.toMap(req),FunctionEntity.class))); - } - - @GetMapping("/page") - @ApiOperation("分页查询") - @ApiOperationSupport(order = 4) - public R> page(FunctionEntity req, Query query) { - QueryWrapper queryWrapper = Condition.getQueryWrapper(BeanUtil.toMap(req), FunctionEntity.class); - return R.data(functionService.page(Condition.getPage(query),queryWrapper)); - } - - @DeleteMapping("/remove") - @ApiOperation("删除函数") - @ApiOperationSupport(order = 4) - public R remove(String ids) { - return R.data(functionService.removeByIds(Func.toLongList(",",ids))); - } - -} diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/function/controller/FunctionParamController.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/function/controller/FunctionParamController.java deleted file mode 100644 index 0f58067..0000000 --- a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/function/controller/FunctionParamController.java +++ /dev/null @@ -1,74 +0,0 @@ -package com.hnac.hzims.bigmodel.function.controller; - -import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; -import com.baomidou.mybatisplus.core.metadata.IPage; -import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport; -import com.hnac.hzims.bigmodel.BigModelConstants; -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.function.service.IFunctionService; -import com.hnac.hzims.common.utils.Condition; -import com.hnac.hzinfo.log.annotation.Business; -import io.swagger.annotations.Api; -import io.swagger.annotations.ApiOperation; -import lombok.AllArgsConstructor; -import org.springblade.core.mp.support.Query; -import org.springblade.core.tool.api.R; -import org.springblade.core.tool.utils.BeanUtil; -import org.springblade.core.tool.utils.Func; -import org.springframework.validation.annotation.Validated; -import org.springframework.web.bind.annotation.*; - -import java.util.List; - -/** - * @Author: huangxing - * @Date: 2024/04/29 15:46 - */ -@RestController -@RequestMapping("/function/param") -@Api(value = "大模型函数参数管理",tags = "大模型函数参数管理") -@Business(module = BigModelConstants.MODULE_NAME,value = "大模型函数参数管理") -@AllArgsConstructor -public class FunctionParamController { - - private final IFuncParamService funcParamService; - - @PostMapping("/save") - @ApiOperation("保存函数参数") - @ApiOperationSupport(order = 1) - public R save(@RequestBody @Validated FuncParamEntity req) { - return R.status(funcParamService.save(req)); - } - - @PutMapping("/save") - @ApiOperation("编辑函数参数") - @ApiOperationSupport(order = 2) - public R updateById(@RequestBody FuncParamEntity req) { - return R.status(funcParamService.save(req)); - } - - @GetMapping("/list") - @ApiOperation("列表查询") - @ApiOperationSupport(order = 3) - public R> list(FuncParamEntity req) { - return R.data(funcParamService.list(Condition.getQueryWrapper(BeanUtil.toMap(req),FuncParamEntity.class))); - } - - @GetMapping("/page") - @ApiOperation("分页查询") - @ApiOperationSupport(order = 4) - public R> page(FuncParamEntity req, Query query) { - QueryWrapper queryWrapper = Condition.getQueryWrapper(BeanUtil.toMap(req), FuncParamEntity.class); - return R.data(funcParamService.page(Condition.getPage(query),queryWrapper)); - } - - @DeleteMapping("/remove") - @ApiOperation("删除函数参数") - @ApiOperationSupport(order = 4) - public R remove(String ids) { - return R.data(funcParamService.removeByIds(Func.toLongList(",",ids))); - } - -} diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/function/mapper/FuncParamMapper.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/function/mapper/FuncParamMapper.java deleted file mode 100644 index 7a9723e..0000000 --- a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/function/mapper/FuncParamMapper.java +++ /dev/null @@ -1,11 +0,0 @@ -package com.hnac.hzims.bigmodel.function.mapper; - -import com.baomidou.mybatisplus.core.mapper.BaseMapper; -import com.hnac.hzims.bigmodel.entity.FuncParamEntity; - -/** - * @Author: huangxing - * @Date: 2024/04/26 11:11 - */ -public interface FuncParamMapper extends BaseMapper { -} diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/function/mapper/FunctionMapper.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/function/mapper/FunctionMapper.java deleted file mode 100644 index 6d0e1c2..0000000 --- a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/function/mapper/FunctionMapper.java +++ /dev/null @@ -1,12 +0,0 @@ -package com.hnac.hzims.bigmodel.function.mapper; - -import com.baomidou.mybatisplus.core.mapper.BaseMapper; -import com.hnac.hzims.bigmodel.entity.FunctionEntity; - -/** - * @Author: huangxing - * @Date: 2024/04/26 11:10 - */ -public interface FunctionMapper extends BaseMapper { - -} diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/function/service/IFuncParamService.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/function/service/IFuncParamService.java deleted file mode 100644 index 813dcd1..0000000 --- a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/function/service/IFuncParamService.java +++ /dev/null @@ -1,22 +0,0 @@ -package com.hnac.hzims.bigmodel.function.service; - -import com.baomidou.mybatisplus.extension.service.IService; -import com.hnac.hzims.bigmodel.entity.FuncParamEntity; - - -import java.util.List; - -/** - * @Author: huangxing - * @Date: 2024/04/26 11:12 - */ -public interface IFuncParamService extends IService { - - /** - * 根据函数ID获取参数列表 - * @param funcId 函数ID - * @return 参数列表 - */ - List getParamsByFuncId(Long funcId); - -} diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/function/service/IFunctionService.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/function/service/IFunctionService.java deleted file mode 100644 index d2c40fc..0000000 --- a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/function/service/IFunctionService.java +++ /dev/null @@ -1,15 +0,0 @@ -package com.hnac.hzims.bigmodel.function.service; - -import com.baomidou.mybatisplus.extension.service.IService; -import com.hnac.hzims.bigmodel.entity.FunctionEntity; - - -/** - * @Author: huangxing - * @Date: 2024/04/26 11:08 - */ -public interface IFunctionService extends IService { - - FunctionEntity getFunctionByCode(String code); - -} diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/function/service/impl/FuncParamServiceImpl.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/function/service/impl/FuncParamServiceImpl.java deleted file mode 100644 index 18910c9..0000000 --- a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/function/service/impl/FuncParamServiceImpl.java +++ /dev/null @@ -1,28 +0,0 @@ -package com.hnac.hzims.bigmodel.function.service.impl; - -import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; -import com.baomidou.mybatisplus.core.toolkit.Wrappers; -import com.hnac.hzims.bigmodel.entity.FuncParamEntity; -import com.hnac.hzims.bigmodel.function.mapper.FuncParamMapper; -import com.hnac.hzims.bigmodel.function.service.IFuncParamService; -import lombok.extern.slf4j.Slf4j; -import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; -import org.springframework.stereotype.Service; - -import java.util.List; - -/** - * @Author: huangxing - * @Date: 2024/04/26 11:13 - */ -@Service -@Slf4j -public class FuncParamServiceImpl extends ServiceImpl implements IFuncParamService { - - @Override - public List getParamsByFuncId(Long funcId) { - LambdaQueryWrapper queryWrapper = Wrappers.lambdaQuery().eq(FuncParamEntity::getFuncId, funcId); - return this.list(queryWrapper); - } - -} diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/function/service/impl/FunctionServiceImpl.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/function/service/impl/FunctionServiceImpl.java deleted file mode 100644 index 9c03b3a..0000000 --- a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/function/service/impl/FunctionServiceImpl.java +++ /dev/null @@ -1,27 +0,0 @@ -package com.hnac.hzims.bigmodel.function.service.impl; - -import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; -import com.baomidou.mybatisplus.core.toolkit.Wrappers; -import com.hnac.hzims.bigmodel.entity.FunctionEntity; -import com.hnac.hzims.bigmodel.function.mapper.FunctionMapper; -import com.hnac.hzims.bigmodel.function.service.IFunctionService; -import lombok.AllArgsConstructor; -import lombok.extern.slf4j.Slf4j; -import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; -import org.springframework.stereotype.Service; - -/** - * @Author: huangxing - * @Date: 2024/04/26 11:09 - */ -@Service -@Slf4j -@AllArgsConstructor -public class FunctionServiceImpl extends ServiceImpl implements IFunctionService { - - @Override - public FunctionEntity getFunctionByCode(String code) { - LambdaQueryWrapper queryWrapper = Wrappers.lambdaQuery().eq(FunctionEntity::getCode, code); - return this.getOne(queryWrapper); - } -} diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/constants/DataAuthTypeEnum.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/constants/DataAuthTypeEnum.java new file mode 100644 index 0000000..ad3bb77 --- /dev/null +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/constants/DataAuthTypeEnum.java @@ -0,0 +1,27 @@ +package com.hnac.hzims.bigmodel.interactive.constants; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.Getter; + +import java.util.Arrays; +import java.util.Optional; + +/** + * @Author: huangxing + * @Date: 2024/06/21 10:49 + */ +@AllArgsConstructor +@Getter +public enum DataAuthTypeEnum { + /**站点鉴权**/ + STATION("station"), + DEPT("dept"), + ; + private final String type; + + public static DataAuthTypeEnum getEnumByType(String type) { + Optional typeEnumOptional = Arrays.stream(DataAuthTypeEnum.class.getEnumConstants()).filter(e -> e.getType().equals(type)).findFirst(); + return typeEnumOptional.orElse(null); + } +} diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/constants/DataMethodEnum.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/constants/DataMethodEnum.java new file mode 100644 index 0000000..49a117b --- /dev/null +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/constants/DataMethodEnum.java @@ -0,0 +1,36 @@ +package com.hnac.hzims.bigmodel.interactive.constants; + +import lombok.AllArgsConstructor; +import lombok.Getter; + +import java.util.Arrays; + +/** + * @Author: huangxing + * @Date: 2024/05/29 08:31 + */ +@AllArgsConstructor +public enum DataMethodEnum { + USUAL("详情",6,"详情"), + EARLIEST("最早值",0,"最早值"), + MAX("最大值",1,"最大值"), + MIN("最小值",2,"最小值"), + AVERAGE("平均值",3,"平均值"), + SUM("累计值/和值",4,"总和值"), + DIFFERENCE("变化值/差值",5,"变化值"), + LATEST("最新值",6,"最新值"), + ; + @Getter + private String name; + @Getter + private Integer accessRule; + @Getter + private String method; + + public static DataMethodEnum getEnumByMethod(String method) { + return Arrays.stream(DataMethodEnum.class.getEnumConstants()) + .filter(e -> e.getMethod().equals(method)) + .findFirst().orElse(null); + } + +} diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/constants/DateEnum.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/constants/DateEnum.java new file mode 100644 index 0000000..a615988 --- /dev/null +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/constants/DateEnum.java @@ -0,0 +1,41 @@ +package com.hnac.hzims.bigmodel.interactive.constants; + +import lombok.AllArgsConstructor; +import lombok.Getter; + +import java.util.Arrays; + +/** + * @Author: huangxing + * @Date: 2024/05/28 11:37 + */ +@AllArgsConstructor +public enum DateEnum { + YEAR("year","每年","按年",5,6), + MONTH("month","每月","按月",4,5), + DAY("day","每天","按天",3,3), + HOUR("hour","每小时","按小时",2,2), + MINUTE("minute","每分钟","按分钟",1,1), + SECOND("second","每秒","按秒",0,0), + USUAL("usual","详情","按秒",0,0) + ; + @Getter + private String code; + @Getter + private String name; + @Getter + private String dateType; + @Getter + private int order; + @Getter + private Integer saveTimeType; + + public static DateEnum getDateEnumByType(String dateType) { + return Arrays.stream(DateEnum.class.getEnumConstants()).filter(d -> d.getDateType().equals(dateType)).findFirst().orElse(null); + } + + public static DateEnum getDateEnumByOrder(int order) { + return Arrays.stream(DateEnum.class.getEnumConstants()).filter(d -> d.getOrder() == order).findFirst().orElse(null); + } + +} 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 11ef13c..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 @@ -12,16 +12,30 @@ import java.util.Optional; */ @AllArgsConstructor public enum FuncRouteEnum { - OPEN_SCADA("open_scada","打开实时画面"), + OPEN_CANVAS("open_canvas","打开实时画面",FunctionConstants.TypeEnum.JUMP), + OPEN_VIDEO("open_video","打开视频监控",FunctionConstants.TypeEnum.PARAMS), + DIAGNOSE("result_diagnose","智能诊断",FunctionConstants.TypeEnum.PARAMS), + CHOOSE_STATION("choose_station","选择站点",FunctionConstants.TypeEnum.CHOOSE), + CHOOSE_VIDEO("choose_video","选择视频",FunctionConstants.TypeEnum.CHOOSE), + CHOOSE_CANVAS("choose_canvas","选择画面",FunctionConstants.TypeEnum.CHOOSE), + CHOOSE_FAULT("choose_fault","选择故障",FunctionConstants.TypeEnum.CHOOSE), + CHOOSE_YK("choose_yk","选择遥控",FunctionConstants.TypeEnum.CHOOSE), + CONFIRM_YK("confirm_yk","遥控确认", FunctionConstants.TypeEnum.PARAMS), + 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(); - return FuncRoute.get(); + Optional FuncRoute = Arrays.stream(FuncRouteEnum.class.getEnumConstants()).filter(e -> funcCode.equals(e.getFunc())).findFirst(); + return FuncRoute.orElse(null); } } diff --git a/hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/interactive/constants/FunctionConstants.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/constants/FunctionConstants.java similarity index 76% rename from hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/interactive/constants/FunctionConstants.java rename to hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/constants/FunctionConstants.java index 7d34a5d..4005c37 100644 --- a/hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/interactive/constants/FunctionConstants.java +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/constants/FunctionConstants.java @@ -15,7 +15,16 @@ public interface FunctionConstants { @AllArgsConstructor enum TypeEnum { /**跳转页面**/ - JUMP("1") + JUMP("1"), + /**链接**/ + LINK("2"), + /**参数**/ + PARAMS("3"), + /**选项**/ + CHOOSE("4"), + /**确认**/ + CONFIRM("5"), + CHART("6"); ; @Getter private String type; diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/constants/InfoMessageConstant.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/constants/InfoMessageConstant.java new file mode 100644 index 0000000..6663556 --- /dev/null +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/constants/InfoMessageConstant.java @@ -0,0 +1,11 @@ +package com.hnac.hzims.bigmodel.interactive.constants; + +/** + * @Author: huangxing + * @Date: 2024/06/21 16:35 + */ +public interface InfoMessageConstant { + + String ERROR_MESSAGE = "非常抱歉,系统在处理您的请求时遇到了问题。请稍后再试或联系我们的客服团队。"; + +} diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/constants/ParamKeyConstants.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/constants/ParamKeyConstants.java new file mode 100644 index 0000000..cb7b02a --- /dev/null +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/constants/ParamKeyConstants.java @@ -0,0 +1,19 @@ +package com.hnac.hzims.bigmodel.interactive.constants; + +/** + * @Author: huangxing + * @Date: 2024/07/01 14:26 + * @Describe: 参数key管理 + */ +public interface ParamKeyConstants { + + /**实时画面host**/ + String CANVAS_HOST = "hzims:bigModel:canvas:host"; + /**实时画面v3路径 {context}&stationNum={stationNum}&projectId={projectId}**/ + String CANVAS_V3_PATH = "hzims:bigModel:canvas:v3:path"; + /**实时画面v4路径 other/v4/canvas/index.html?hzinfowebkit=true&taskId={taskId}&stationNum={stationNum}&projectId={projectId}&source=app&picName={context}&name={name}**/ + String CANVAS_V4_PATH = "hzims:bigModel:canvas:v4:path"; + /**实时画面云组态路径 hzinfo-data-scada/view/{projectId}/{id}?source=app**/ + String CANVAS_YZT_PATH = "hzims:bigModel:canvas:yzt:path"; + +} diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/constants/ProjectRemoteTypeEnum.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/constants/ProjectRemoteTypeEnum.java new file mode 100644 index 0000000..069572a --- /dev/null +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/constants/ProjectRemoteTypeEnum.java @@ -0,0 +1,22 @@ +package com.hnac.hzims.bigmodel.interactive.constants; + +import lombok.AllArgsConstructor; +import lombok.Getter; + +/** + * @Author: huangxing + * @Date: 2024/05/21 16:34 + */ +@AllArgsConstructor +public enum ProjectRemoteTypeEnum { + /**不允许发送遥控**/ + NOT_ALLOW(0), + /**运行发送遥控并且需要校验权限**/ + VALID(1), + /**运行发送遥控并免校验权限**/ + ALLOW(2), + ; + @Getter + private Integer ctrlType; + +} diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/constants/SearchStationTypeEnum.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/constants/SearchStationTypeEnum.java new file mode 100644 index 0000000..ea935c1 --- /dev/null +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/constants/SearchStationTypeEnum.java @@ -0,0 +1,44 @@ +package com.hnac.hzims.bigmodel.interactive.constants; + +import lombok.AllArgsConstructor; +import lombok.Getter; + +import java.util.Arrays; + +/** + * @Author: huangxing + * @Date: 2024/05/24 17:14 + */ +@AllArgsConstructor +public enum SearchStationTypeEnum { + STATION_TOTAL("电站总数量",null,"智能运维平台接入电站总数为:%s"), + SET_TOTAL("站点总数量",null,"智能运维平台接入站点总数为:%s"), + HYDROPOWER_TOTAL("水电站总数量","0","智能运维平台接入水电站总数为:%s"), + WIND_POWER_TOTAL("风电场总数量","1","智能运维平台接入风电场总数为:%s"), + ENERGY_STORAGE_TOTAL("储能站总数量","3","智能运维平台接入储能站总数为:%s"), + PHOTOVOLTAIC_TOTAL("光伏站总数量","5","智能运维平台接入光伏站总数为:%s"), + CHARGE_TOTAL("充电站总数量","7","智能运维平台接入充电站总数为:%s"), + STATION_NUM("电站接入量",null,"智能运维平台接入电站总数为:%s"), + SET_NUM("站点接入量",null,"智能运维平台接入站点总数为:%s"), + HYDROPOWER_NUM("水电站接入量","0","智能运维平台接入水电站接入量为:%s"), + WIND_POWER_NUM("风电场接入量","1","智能运维平台接入风电场接入量为:%s"), + ENERGY_STORAGE_NUM("储能站接入量","3","智能运维平台接入储能站接入量为:%s"), + PHOTOVOLTAIC_NUM("光伏站接入量","5","智能运维平台接入光伏站接入量为:%s"), + CHARGE_NUM("充电站接入量","7","智能运维平台接入充电站接入量为:%s"), + ; + + @Getter + private String searchStationType; + @Getter + private String stationType; + @Getter + private String label; + + public static SearchStationTypeEnum getTypeEnum(String searchStationType) { + return Arrays.stream(SearchStationTypeEnum.class.getEnumConstants()) + .filter(e -> e.getSearchStationType().equals(searchStationType)) + .findFirst() + .orElse(null); + } + +} diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/constants/SearchTypeEnum.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/constants/SearchTypeEnum.java new file mode 100644 index 0000000..0692d62 --- /dev/null +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/constants/SearchTypeEnum.java @@ -0,0 +1,28 @@ +package com.hnac.hzims.bigmodel.interactive.constants; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.Getter; + +import java.util.Arrays; + +/** + * @Author: huangxing + * @Date: 2024/05/24 17:13 + */ +@AllArgsConstructor +public enum SearchTypeEnum { + REAL("实时"), + HISTORY("历史") + ; + @Getter + private String searchType; + + public static SearchTypeEnum getSearchType(String searchType) { + return Arrays.stream(SearchTypeEnum.class.getEnumConstants()) + .filter(e -> e.getSearchType().equals(searchType)) + .findFirst() + .orElse(null); + } + +} 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 new file mode 100644 index 0000000..ac3789b --- /dev/null +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/controller/FontEndInteractiveController.java @@ -0,0 +1,72 @@ +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.service.IHznlmInvokeService; +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.IResultCode; +import org.springblade.core.tool.api.R; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +import java.util.List; + +/** + * @Author: huangxing + * @Date: 2024/06/24 14:19 + */ +@RestController +@RequestMapping("/fontEnd/interactive") +@Api(value = "前端交互控制层",tags = "前端交互控制层") +@AllArgsConstructor +@Business(module = BigModelConstants.APP_NAME,value = "前端交互层管理",ignore = false) +public class FontEndInteractiveController { + + private final IHznlmInvokeService hznlmInvokeService; + + @ApiOperation("提问") + @ApiOperationSupport(order = 1) + @GetMapping("/ask") + public R ask(@RequestParam @ApiParam("用户提出问题") String question, @RequestParam @ApiParam("问答sessionId") String sessionId, @RequestParam @ApiParam("用户Id") String userId) { + hznlmInvokeService.ask(question, sessionId, userId); + return R.success("操作成功!"); + } + + @ApiOperation("删除对话sessionId") + @ApiOperationSupport(order = 2) + @GetMapping("/removeSessionId") + public R removeSessionId(@RequestParam(value = "id") String sessionId) { + hznlmInvokeService.removeSessionId(sessionId); + return R.success("操作成功!"); + } + + @ApiOperation("获取热点问题") + @ApiOperationSupport(order = 3) + @GetMapping("/hotQuestions") + public R hotQuestions() { + return R.data(hznlmInvokeService.hotQuestions()); + } + + @ApiOperation("获取问答sessionId") + @ApiOperationSupport(order = 4) + @GetMapping("/getSessionId") + 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 new file mode 100644 index 0000000..eafdc47 --- /dev/null +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/controller/HznlmInteractiveController.java @@ -0,0 +1,65 @@ +package com.hnac.hzims.bigmodel.interactive.controller; + +import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport; +import com.hnac.hzims.bigmodel.BigModelConstants; +import com.hnac.hzims.bigmodel.business.service.DataSourceService; +import com.hnac.hzims.bigmodel.business.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; +import com.hnac.hzims.bigmodel.interactive.vo.ExtraVO; +import com.hnac.hzinfo.log.annotation.Business; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import lombok.AllArgsConstructor; +import org.springblade.core.tool.api.R; +import org.springframework.web.bind.annotation.*; + +import javax.validation.Valid; +import java.util.List; +import java.util.Map; + +/** + * @Author: huangxing + * @Date: 2024/06/21 10:21 + */ +@RestController +@AllArgsConstructor +@Api(value = "HZLLM大模型交互层",tags = "HZLLM大模型交互层") +@RequestMapping("/hzn_lm/interactive") +@Business(module = BigModelConstants.MODULE_NAME,value = "HZLLM大模型交互层") +public class HznlmInteractiveController { + + private final IHznlmInteractiveService interactiveService; + private final DataSourceService dataSourceService; + + @PostMapping(value = "/get_auth_data") + @ApiOperation("获取鉴权数据") + @ApiOperationSupport(order = 1) + public R> getAuthData(@RequestBody AuthDataDTO req) { + return R.data(interactiveService.getAuthData(req)); + } + + @ApiOperation("解析大模型函数") + @ApiOperationSupport(order = 2) + @PostMapping("/resolve") + public R resolve(@RequestBody ModelFunctionReq req) { + return R.data(interactiveService.resolve(req)); + } + + @PostMapping("/execute_query") + @ApiOperation("执行大模型sql") + @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 eebb4bf..0000000 --- a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/controller/InteractiveController.java +++ /dev/null @@ -1,62 +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.hnac.hzims.bigmodel.BigModelConstants; -import com.hnac.hzims.bigmodel.interactive.req.ModelFunctionReq; -import com.hnac.hzims.bigmodel.interactive.service.IInteractiveService; -import com.hnac.hzinfo.log.annotation.Business; -import io.swagger.annotations.Api; -import io.swagger.annotations.ApiModelProperty; -import io.swagger.annotations.ApiOperation; -import io.swagger.annotations.ApiParam; -import lombok.AllArgsConstructor; -import org.springblade.core.tool.api.R; -import org.springframework.web.bind.annotation.*; - -import javax.servlet.http.HttpServletRequest; - -/** - * @Author: huangxing - * @Date: 2024/04/26 14:51 - */ -@RestController -@AllArgsConstructor -@Api(value = "FDP大模型交互层",tags = "FDP大模型交互层") -@RequestMapping("/interactive") -@Business(module = BigModelConstants.MODULE_NAME,value = "FDP大模型交互层") -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") - public R ask(@RequestParam @ApiParam("用户提出问题") String question,@RequestParam @ApiParam("问答sessionId") String sessionId) { - return interactiveService.ask(question, sessionId); - } - - @ApiOperation("站点、菜单鉴权") - @ApiOperationSupport(order = 3) - @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 menuId) { - return R.status(interactiveService.authentication(stationId,userId,menuId)); - } - - @ApiOperation("获取问答sessionId") - @ApiOperationSupport(order = 4) - @GetMapping("/getSessionId") - public R getSessionId() { - return R.data(IdWorker.get32UUID()); - } - -} diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/dto/AuthDataDTO.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/dto/AuthDataDTO.java new file mode 100644 index 0000000..b891ec0 --- /dev/null +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/dto/AuthDataDTO.java @@ -0,0 +1,35 @@ +package com.hnac.hzims.bigmodel.interactive.dto; + +import com.alibaba.fastjson.annotation.JSONField; +import com.fasterxml.jackson.annotation.JsonProperty; +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/06/21 10:39 + */ +@Data +@ApiModel(value = "获取权限接口传参格式",description = "获取权限接口传参格式") +@EqualsAndHashCode +public class AuthDataDTO implements Serializable { + + @JsonProperty("chatId") + @ApiModelProperty("问答ID,用于获取前端发起问答传入缓存中数据") + @NotBlank + private String sessionId; + + @ApiModelProperty("提问用户ID") + @NotBlank + private String userId; + + @ApiModelProperty("鉴权类型") + @NotBlank + private String type; + +} diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/factory/AnswerResolveFactory.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/factory/AnswerResolveFactory.java new file mode 100644 index 0000000..b9daa43 --- /dev/null +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/factory/AnswerResolveFactory.java @@ -0,0 +1,55 @@ +package com.hnac.hzims.bigmodel.interactive.factory; + +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONObject; +import com.hnac.hzims.bigmodel.interactive.constants.FuncRouteEnum; +import com.hnac.hzims.bigmodel.interactive.service.IAnswerResolveService; +import com.hnac.hzims.bigmodel.interactive.service.IResolveService; +import com.hnac.hzims.bigmodel.interactive.vo.AnswerVO; +import org.springblade.core.log.exception.ServiceException; +import org.springblade.core.log.logger.BladeLogger; +import org.springblade.core.tool.utils.Func; +import org.springblade.core.tool.utils.SpringUtil; + +/** + * @Author: huangxing + * @Date: 2024/06/21 18:44 + */ +public class AnswerResolveFactory { + + public static final String DIAGNOSE_ANSWER_SERVICE = "diagnoseAnswerResolveService"; + public static final String CHOICE_ANSWER_SERVICE = "choiceAnswerResolveService"; + public static final String REMOTE_ANSWER_SERVICE = "remoteAnswerResolveService"; + public static final String PARAM_ANSWER_SERVICE = "paramAnswerResolveService"; + public static final String PRE_ANSWER_SERVICE = "preAnswerResolveService"; + + public static IAnswerResolveService getResolveService(Object extra) { + String funcCode = JSONObject.parseObject(JSON.toJSONString(extra)).getString("func"); + return AnswerResolveFactory.getResolveService(funcCode); + } + + public static IAnswerResolveService getResolveService(String funcCode) { + FuncRouteEnum funcRouteEnum = FuncRouteEnum.getEnumByFuncCode(funcCode); + if(Func.isNotEmpty(funcRouteEnum)) { + switch (funcRouteEnum) { + case DIAGNOSE: + return SpringUtil.getBean(DIAGNOSE_ANSWER_SERVICE); + case CHOOSE_VIDEO: + case CHOOSE_CANVAS: + case CHOOSE_STATION: + case CHOOSE_FAULT: + case CHOOSE_YC: + case CHOOSE_YK: + return SpringUtil.getBean(CHOICE_ANSWER_SERVICE); + case CONFIRM_YK: + return SpringUtil.getBean(REMOTE_ANSWER_SERVICE); + case SHOW_PARAM: + return SpringUtil.getBean(PARAM_ANSWER_SERVICE); + default: + return null; + } + } + throw new ServiceException("service解析失败!"); + } + +} diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/factory/ResolveFactory.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/factory/ResolveFactory.java new file mode 100644 index 0000000..6f7a632 --- /dev/null +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/factory/ResolveFactory.java @@ -0,0 +1,41 @@ +package com.hnac.hzims.bigmodel.interactive.factory; + +import com.hnac.hzims.bigmodel.interactive.constants.FuncRouteEnum; +import com.hnac.hzims.bigmodel.interactive.service.IResolveService; +import org.springblade.core.log.exception.ServiceException; +import org.springblade.core.log.logger.BladeLogger; +import org.springblade.core.tool.utils.Func; +import org.springblade.core.tool.utils.SpringUtil; + +/** + * @Author: huangxing + * @Date: 2024/06/21 15:53 + */ +public class ResolveFactory { + + public static final String CANVAS_RESOLVE_SERVICE = "canvasResolveService"; + public static final String VIDEO_RESOLVE_SERVICE = "videoResolveService"; + + /** + * 获取解析函数需要的service + * @param funcCode 函数编号 + * @return 解析函数所需service + */ + public static IResolveService getResolveService(String funcCode) { + BladeLogger logger = SpringUtil.getBean(BladeLogger.class); + FuncRouteEnum funcRouteEnum = FuncRouteEnum.getEnumByFuncCode(funcCode); + if(Func.isNotEmpty(funcRouteEnum)) { + switch(funcRouteEnum) { + case OPEN_CANVAS: + return SpringUtil.getBean("canvasResolveService"); + case OPEN_VIDEO: + return SpringUtil.getBean("videoResolveService"); + default: + logger.error("hzims:bigModel:getResolveService","函数解析失败,函数编号为:" + funcCode); + throw new ServiceException("service解析失败"); + } + } + throw new ServiceException("service解析失败"); + } + +} diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/IAnalyseDataService.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/IAnalyseDataService.java new file mode 100644 index 0000000..d290dab --- /dev/null +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/IAnalyseDataService.java @@ -0,0 +1,16 @@ +package com.hnac.hzims.bigmodel.interactive.service; + +import com.alibaba.fastjson.JSONObject; +import com.hnac.hzims.bigmodel.interactive.vo.AnswerVO; +import com.hnac.hzims.bigmodel.interactive.vo.ExtraVO; +import com.hnac.hzims.bigmodel.interactive.vo.HistoryDataSearchVO; + +/** + * @Author: huangxing + * @Date: 2024/05/28 11:29 + */ +public interface IAnalyseDataService { + + ExtraVO getHistoryData(HistoryDataSearchVO searchVO); + +} diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/IAnswerResolveService.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/IAnswerResolveService.java new file mode 100644 index 0000000..4800164 --- /dev/null +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/IAnswerResolveService.java @@ -0,0 +1,34 @@ +package com.hnac.hzims.bigmodel.interactive.service; + +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONObject; +import com.hnac.hzims.bigmodel.interactive.vo.AnswerVO; +import com.hnac.hzims.bigmodel.interactive.vo.ExtraVO; + +import java.util.Arrays; +import java.util.stream.Stream; + +/** + * @Author: huangxing + * @Date: 2024/06/21 18:39 + */ +public interface IAnswerResolveService { + + AnswerVO resolve(AnswerVO answer); + + /** + * 解析 extra + * @param originExtra 大模型传入 extra + * @return 解析后的 extra + */ + ExtraVO getExtra(JSONObject originExtra); + + /*** + * + * @param answer + * @return + */ + default Stream extraStream(AnswerVO answer) { + return Arrays.stream(answer.getExtras()).map(JSON::toJSONString).map(JSONObject::parseObject); + } +} diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/IHznlmInteractiveService.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/IHznlmInteractiveService.java new file mode 100644 index 0000000..c9aed6b --- /dev/null +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/IHznlmInteractiveService.java @@ -0,0 +1,26 @@ +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; +import com.hnac.hzims.bigmodel.interactive.vo.ResolveResultVO; +import org.springframework.web.bind.annotation.RequestBody; + +import javax.validation.Valid; +import java.util.List; + +/** + * @Author: huangxing + * @Date: 2024/06/21 10:23 + */ +public interface IHznlmInteractiveService { + + 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 new file mode 100644 index 0000000..69f319c --- /dev/null +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/IHznlmInvokeService.java @@ -0,0 +1,77 @@ +package com.hnac.hzims.bigmodel.interactive.service; + +import com.hnac.hzims.bigmodel.interactive.vo.AnswerVO; +import com.hnac.hzims.bigmodel.question.dto.QuestionDTO; +import org.springblade.core.tool.api.R; + +import java.util.List; +import java.util.Map; + +/** + * @Author: huangxing + * @Date: 2024/06/21 17:20 + */ +public interface IHznlmInvokeService { + + /** + * 基础问题 + * @param question 提问问题 + * @param sessionId 会话ID + * @param userId 提问人ID + * @return 提问结果 + */ + @Deprecated + void ask(String question, String sessionId, String userId); + + void ask(QuestionDTO question); + + /** + * 特殊问题 + * @param sessionId 会话ID + * @param userId 提问人ID + * @param extra 特殊问题内容 + * @return 提问结果 + */ + @Deprecated + void specialAsk(String sessionId, String userId, Map extra); + + void specialAsk(QuestionDTO questionDTO); + + /** + * 知识库问题 + * @param question 问题名称 + * @param sessionId 会话ID + * @param userId 提问人ID + * @param knowledge 知识库名称 + */ + @Deprecated + void knowledgeAsk(String question, String sessionId, String userId, String knowledge); + + void knowledgeAsk(QuestionDTO questionDTO); + + /** + * 删除对话记录 + * @param sessionId 会话ID + */ + void removeSessionId(String sessionId); + + /** + * 获取热点问题 + * @return 热点问题 + */ + List hotQuestions(); + + /** + * 查询问答状态 + * @param sessionIds 会话ID,按逗号分隔 + * @return 答案列表 + */ + 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/IInteractiveService.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/IInteractiveService.java deleted file mode 100644 index 1c718ac..0000000 --- a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/IInteractiveService.java +++ /dev/null @@ -1,26 +0,0 @@ -package com.hnac.hzims.bigmodel.interactive.service; - -import com.hnac.hzims.bigmodel.interactive.req.ModelFunctionReq; -import com.hnac.hzims.bigmodel.interactive.vo.AnswerVO; -import io.swagger.annotations.ApiParam; -import org.springblade.core.tool.api.R; -import org.springframework.web.bind.annotation.RequestParam; - -import javax.servlet.http.HttpServletRequest; -import java.util.List; - -/** - * @Author: huangxing - * @Date: 2024/04/26 14:51 - */ -public interface IInteractiveService { - - R resolve(ModelFunctionReq req); - - R ask(String question,String sessionId); - - List getAnswerBySessionIds(String sessionIds); - - Boolean authentication(String stationId, String userId, String menuId); - -} diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/IJumpPageService.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/IJumpPageService.java deleted file mode 100644 index fa4f9d5..0000000 --- a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/IJumpPageService.java +++ /dev/null @@ -1,16 +0,0 @@ -package com.hnac.hzims.bigmodel.interactive.service; - -import com.hnac.hzims.bigmodel.entity.FunctionEntity; -import com.hnac.hzims.bigmodel.interactive.vo.ExtraVO; - -import java.util.Map; - -/** - * @Author: huangxing - * @Date: 2024/04/26 11:46 - */ -public interface IJumpPageService { - - String dealJumpTypeFunction(FunctionEntity function, Map args); - -} diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/IResolveService.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/IResolveService.java new file mode 100644 index 0000000..19a5869 --- /dev/null +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/IResolveService.java @@ -0,0 +1,17 @@ +package com.hnac.hzims.bigmodel.interactive.service; + +import com.hnac.hzims.bigmodel.interactive.req.ModelFunctionReq; +import com.hnac.hzims.bigmodel.interactive.vo.ExtraVO; +import com.hnac.hzims.bigmodel.interactive.vo.ResolveResultVO; + +/** + * @Author: huangxing + * @Date: 2024/06/21 15:39 + */ +public interface IResolveService { + + ExtraVO resolve(String id); + + ExtraVO resolve(ModelFunctionReq req); + +} 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 new file mode 100644 index 0000000..9b59e99 --- /dev/null +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/AnalyseDataServiceImpl.java @@ -0,0 +1,89 @@ +package com.hnac.hzims.bigmodel.interactive.service.impl; + +import com.google.common.collect.Lists; +import com.hnac.hzims.bigmodel.business.service.HistoryDataService; +import com.hnac.hzims.bigmodel.interactive.constants.DataMethodEnum; +import com.hnac.hzims.bigmodel.interactive.constants.DateEnum; +import com.hnac.hzims.bigmodel.interactive.constants.FuncRouteEnum; +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.vo.ReductionDataVO; +import lombok.AllArgsConstructor; +import org.springblade.core.tool.utils.CollectionUtil; +import org.springblade.core.tool.utils.Func; +import org.springblade.core.tool.utils.StringUtil; +import org.springframework.stereotype.Service; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; + +/** + * @Author: huangxing + * @Date: 2024/05/28 11:29 + */ +@Service +@AllArgsConstructor +public class AnalyseDataServiceImpl implements IAnalyseDataService { + + private final HistoryDataService historyDataService; + + @Override + public ExtraVO getHistoryData(HistoryDataSearchVO searchVO) { + if(Func.isEmpty(searchVO.getDataType()) || StringUtil.isBlank(searchVO.getDataType()) + || DataMethodEnum.USUAL.getMethod().equals(searchVO.getMethod())) { + searchVO.setDataType(DateEnum.SECOND.getDateType()); + } + // 聚合数据方式处理 + DateEnum dateEnum = DateEnum.getDateEnumByType(searchVO.getDataType()); + searchVO.setDataType(dateEnum.getDateType()); + // 获取最适配时间段 + DateEnum adapterDate = historyDataService.getDateEnumByDuration(searchVO.getStartTime(), searchVO.getEndTime(), dateEnum); + String note = adapterDate.getDateType().equals(searchVO.getDataType()) ? "" : "(由于数据量过大,只能帮您" + adapterDate.getDateType() + "查询)"; + searchVO.setDataType(adapterDate.getDateType()); + ExtraVO extraVO = new ExtraVO(); + extraVO.setType(FuncRouteEnum.HISTORY_DATA.getType().getType()); + extraVO.setFunc(FuncRouteEnum.HISTORY_DATA.getFunc()); + Map params = new HashMap<>(1); + Result reductionDataVOR = historyDataService.getPolymerizationData(searchVO); + String label; + if(!reductionDataVOR.isSuccess()) { + params.put("errorInfo",reductionDataVOR.getMsg()); + label = "查询数据失败!"; + } + else { + ReductionDataVO dataVO = reductionDataVOR.getData(); + label = "暂未查到数据"; + params.put("data",Lists.newArrayList()); + if(Func.isNotEmpty(dataVO) && CollectionUtil.isNotEmpty(dataVO.getDataList())) { + List datalist = dataVO.getDataList().stream().map(m -> { + m.put("val", m.get(searchVO.getSignage())); + m.remove(searchVO.getSignage()); + return m; + }).collect(Collectors.toList()); + DataMethodEnum enumByMethod = DataMethodEnum.getEnumByMethod(searchVO.getMethod()); + if(CollectionUtil.isNotEmpty(datalist)) { + label = searchVO.getStationName() + "_" + + searchVO.getDeviceName() + "_" + + dataVO.getFieldMap().get(searchVO.getSignage()) + "_" + + (DataMethodEnum.USUAL.getMethod().equals(enumByMethod.getMethod()) ? "" : adapterDate.getName()) + + enumByMethod.getMethod() + + (DataMethodEnum.USUAL.getMethod().equals(enumByMethod.getMethod()) ? "" : note) + + ":"; + } + params.put("data",datalist); + } + } + extraVO.setLabel(label); + params.put("deviceName",searchVO.getDeviceName()); + params.put("attrName",searchVO.getAttrName()); + params.put("stationName",searchVO.getStationName()); + params.put("beginTime",searchVO.getStartTime()); + params.put("endTime",searchVO.getEndTime()); + extraVO.setParams(params); + return extraVO; + } +} diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/CanvasResolveServiceImpl.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/CanvasResolveServiceImpl.java new file mode 100644 index 0000000..6b7f247 --- /dev/null +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/CanvasResolveServiceImpl.java @@ -0,0 +1,129 @@ +package com.hnac.hzims.bigmodel.interactive.service.impl; + +import com.alibaba.fastjson.JSON; +import com.hnac.hzims.bigmodel.interactive.constants.FuncRouteEnum; +import com.hnac.hzims.bigmodel.interactive.constants.ParamKeyConstants; +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.operational.station.entity.StationEntity; +import com.hnac.hzims.operational.station.feign.IStationClient; +import groovy.util.logging.Slf4j; +import lombok.AllArgsConstructor; +import org.springblade.core.log.exception.ServiceException; +import org.springblade.core.log.logger.BladeLogger; +import org.springblade.core.tool.api.R; +import org.springblade.core.tool.utils.Func; +import org.springblade.core.tool.utils.StringUtil; +import org.springblade.system.cache.ParamCache; +import org.springframework.stereotype.Service; +import org.springframework.util.Assert; + +import java.util.*; +import java.util.stream.IntStream; + +/** + * @Author: huangxing + * @Date: 2024/06/21 15:39 + */ +@Service(ResolveFactory.CANVAS_RESOLVE_SERVICE) +@AllArgsConstructor +@Slf4j +public class CanvasResolveServiceImpl implements IResolveService { + + private final IStationClient stationClient; + private final BladeLogger logger; + + @Override + public ExtraVO resolve(ModelFunctionReq req) { + 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); + } + + @Override + public ExtraVO resolve(String id) { + ExtraVO extraVO = new ExtraVO(); + extraVO.setImmediatelyJump(true); + 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解析为 + Map resolveMap = this.resolve(id, SCADA_PARAMS_SOLVE); + R stationR = stationClient.getStationByCode(resolveMap.get("projectId")); + extraVO.setLabel(Optional.ofNullable(stationR).filter(r -> r.isSuccess()).map(R::getData).map(StationEntity::getName).orElse("") + "_" + resolveMap.get("name")); + int picResource = Integer.parseInt(resolveMap.get("picResource")); + Map extraParams = new HashMap<>(1); + extraParams.put("picResource",picResource); + extraVO.setParams(extraParams); + // 云组态 + if(picResource == 0) { + String path = this.replacePath(ParamCache.getValue(ParamKeyConstants.CANVAS_YZT_PATH), resolveMap); + extraVO.setRoute(canvasHost + path); + } + // v3.0 + else if(picResource == 1) { + String path = this.replacePath(ParamCache.getValue(ParamKeyConstants.CANVAS_V3_PATH), resolveMap); + extraVO.setRoute(canvasHost + path); + } + // v4.0 + else if (picResource == 2) { + // pic_name 去掉头部的/ 以及尾部的.js + String context = resolveMap.get("context"); + context = this.removeHeadChars(context,"/"); + context = this.removeTailChars(context,".js"); + resolveMap.put("context",context); + extraVO.setRoute(this.replacePath("other/v4/canvas/index.html?hzinfowebkit=true&taskId={taskId}&stationNum={stationNum}&projectId={projectId}&source=app&picName={context}&itemName={itemName}", resolveMap)); + } + else { + throw new ServiceException("解析出来的画面类型在云组态、v3、v4类型之外,无法解析路由"); + } + return extraVO; + } + + public Map resolve(String paramsStr, String... keys) { + Map result = new HashMap<>(); + List params = Func.toStrList("\\^", paramsStr); + Assert.isTrue(params.size() == keys.length, () -> { + throw new ServiceException("大模型传参params长度错误,传参为:" + paramsStr); + }); + IntStream.iterate(0, index -> index + 1).limit(params.size()).forEach(index -> result.put(keys[index],params.get(index))); + return result; + } + + private String replacePath(String path,Map params) { + Set> entries = params.entrySet(); + // 替换path中变量 + for (Map.Entry entry : entries) { + String replaceVariables = "{" + entry.getKey() + "}"; + path = StringUtil.replace(path,replaceVariables,entry.getValue()); + } + return path; + } + + public String removeHeadChars(String str, String charsToRemove) { + if (str == null || charsToRemove == null || charsToRemove.isEmpty()) { + return str; + } + while (str.startsWith(charsToRemove)) { + str = str.substring(charsToRemove.length()); + } + return str; + } + + public String removeTailChars(String str, String charsToRemove) { + if (str == null || charsToRemove == null || charsToRemove.isEmpty()) { + return str; + } + while (str.endsWith(charsToRemove)) { + str = str.substring(0, str.length() - charsToRemove.length()); + } + return str; + } +} diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/ChoiceAnswerResolveServiceImpl.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/ChoiceAnswerResolveServiceImpl.java new file mode 100644 index 0000000..f6495f1 --- /dev/null +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/ChoiceAnswerResolveServiceImpl.java @@ -0,0 +1,43 @@ +package com.hnac.hzims.bigmodel.interactive.service.impl; + +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONArray; +import com.alibaba.fastjson.JSONObject; +import com.hnac.hzims.bigmodel.interactive.constants.FuncRouteEnum; +import com.hnac.hzims.bigmodel.interactive.factory.AnswerResolveFactory; +import com.hnac.hzims.bigmodel.interactive.service.IAnswerResolveService; +import com.hnac.hzims.bigmodel.interactive.vo.AnswerVO; +import com.hnac.hzims.bigmodel.interactive.vo.ExtraVO; +import groovy.util.logging.Slf4j; +import lombok.AllArgsConstructor; +import org.springframework.stereotype.Service; + +import java.util.Arrays; +import java.util.List; +import java.util.stream.Collectors; + +/** + * @Author: huangxing + * @Date: 2024/06/21 19:02 + * @Describe 选项答案解析服务层 + */ +@AllArgsConstructor +@Service(AnswerResolveFactory.CHOICE_ANSWER_SERVICE) +@Slf4j +public class ChoiceAnswerResolveServiceImpl implements IAnswerResolveService { + + @Override + public AnswerVO resolve(AnswerVO answer) { + Object[] extraArray = this.extraStream(answer).map(this::getExtra).toArray(); + answer.setExtras(extraArray); + return answer; + } + + @Override + public ExtraVO getExtra(JSONObject originExtra) { + ExtraVO result = JSONObject.parseObject(JSON.toJSONString(originExtra),ExtraVO.class); + result.setSpecial(true); + result.setType(FuncRouteEnum.getEnumByFuncCode(result.getFunc()).getType().getType()); + return result; + } +} diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/DiagnoseAnswerResolveServiceImpl.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/DiagnoseAnswerResolveServiceImpl.java new file mode 100644 index 0000000..fa94148 --- /dev/null +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/DiagnoseAnswerResolveServiceImpl.java @@ -0,0 +1,50 @@ +package com.hnac.hzims.bigmodel.interactive.service.impl; + +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONObject; +import com.hnac.hzims.bigmodel.interactive.constants.FuncRouteEnum; +import com.hnac.hzims.bigmodel.interactive.constants.FunctionConstants; +import com.hnac.hzims.bigmodel.interactive.factory.AnswerResolveFactory; +import com.hnac.hzims.bigmodel.interactive.service.IAnswerResolveService; +import com.hnac.hzims.bigmodel.interactive.vo.AnswerVO; +import com.hnac.hzims.bigmodel.interactive.vo.ExtraVO; +import groovy.util.logging.Slf4j; +import lombok.AllArgsConstructor; +import org.springframework.stereotype.Service; + +import java.util.HashMap; +import java.util.Map; + +/** + * @Author: huangxing + * @Date: 2024/06/21 18:59 + */ +@Service(AnswerResolveFactory.DIAGNOSE_ANSWER_SERVICE) +@Slf4j +@AllArgsConstructor +public class DiagnoseAnswerResolveServiceImpl implements IAnswerResolveService { + + @Override + public AnswerVO resolve(AnswerVO answer) { + Object[] extraArray = this.extraStream(answer).map(this::getExtra).toArray(); + answer.setExtras(extraArray); + return answer; + } + + @Override + public ExtraVO getExtra(JSONObject originExtra) { + ExtraVO result = new ExtraVO(); + JSONObject data = JSONObject.parseObject(JSON.toJSONString(originExtra.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); + String funcCode = originExtra.getString("func"); + result.setFunc(funcCode); + result.setType(FuncRouteEnum.getEnumByFuncCode(funcCode).getType().getType()); + return result; + } +} diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/HznlmInteractiveServiceImpl.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/HznlmInteractiveServiceImpl.java new file mode 100644 index 0000000..b22a790 --- /dev/null +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/HznlmInteractiveServiceImpl.java @@ -0,0 +1,100 @@ +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 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; + +/** + * @Author: huangxing + * @Date: 2024/06/21 10:24 + */ +@Service +@AllArgsConstructor +@Slf4j +public class HznlmInteractiveServiceImpl implements IHznlmInteractiveService { + + private final AuthenticationService authenticationService; + private final IAuthClient authClient; + + @Override + public List getAuthData(AuthDataDTO req) { + DataAuthTypeEnum authTypeEnum = DataAuthTypeEnum.getEnumByType(req.getType()); + switch(authTypeEnum) { + case STATION: + return this.getStationAuthData(req.getUserId()); + case DEPT: + return this.getDeptAuthData(req.getUserId()); + default: + throw new ServiceException(req.getType() + "改类型获取权限数据暂不支持"); + } + } + + @Override + public ExtraVO resolve(ModelFunctionReq req) { + 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()); + } + + public List getStationAuthData(String userId) { + List deptStationDTOs = authenticationService.getStationPermissionsById(userId); + return deptStationDTOs.stream().map(this::convertStationAuthData).filter(d -> Func.isNotBlank(d.getItemId())).collect(Collectors.toList()); + } + + private AuthDataVO convertStationAuthData(DeptStationDTO req) { + return new AuthDataVO(req.getStationId(),req.getDeptName()); + } + + private AuthDataVO convertDeptAuthData(DeptStationDTO req) { + return new AuthDataVO(String.valueOf(req.getDeptId()),req.getDeptName()); + } +} diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/HznlmInvokeServiceImpl.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/HznlmInvokeServiceImpl.java new file mode 100644 index 0000000..8d1cee2 --- /dev/null +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/HznlmInvokeServiceImpl.java @@ -0,0 +1,143 @@ +package com.hnac.hzims.bigmodel.interactive.service.impl; + +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.TypeReference; +import com.google.common.collect.Lists; +import com.hnac.hzims.bigmodel.business.feign.IAuthClient; +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.question.dto.QuestionDTO; +import com.hnac.hzims.bigmodel.utils.RequestClientUtil; +import com.hnac.hzims.bigmodel.websocket.sessionManager.InteractiveSessionManager; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springblade.core.log.logger.BladeLogger; +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.StringUtil; +import org.springblade.system.dto.DeptStationDTO; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Service; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** + * @Author: huangxing + * @Date: 2024/06/21 17:20 + * @Describe HZN_LM大模型接口调用服务层 + */ +@Service +@RequiredArgsConstructor +@Slf4j +public class HznlmInvokeServiceImpl implements IHznlmInvokeService { + + private final BigModelInvokeUrl bigModelInvokeUrl; + private final BladeLogger logger; + private final SessionRedisManager sessionRedisManager; + private final IAuthClient authClient; + + @Value("${fdp.host}") + private String fdpHost; + + @Override + public void ask(String question, String sessionId, String userId) { + Map params = new HashMap<>(); + params.put("chat_id",sessionId); + params.put("user_id", userId); + params.put("query",question); + Map authDataIds = this.getAuthDataIds(userId); + params.putAll(authDataIds); + RequestClientUtil.postCall(fdpHost + bigModelInvokeUrl.getAssistantAsk(), params); + sessionRedisManager.addSessionId(sessionId); + } + + @Override + public void ask(QuestionDTO question) { + RequestClientUtil.postCall(fdpHost + bigModelInvokeUrl.getAssistantAsk(), JSON.toJSONString(question)); + sessionRedisManager.addSessionId(question.getChatId()); + } + + @Override + public void specialAsk(String sessionId, String userId, Map extra) { + Map params = new HashMap<>(); + params.put("chat_id",sessionId); + params.put("user_id", userId); + params.put("extra",extra); + Map authDataIds = this.getAuthDataIds(userId); + params.putAll(authDataIds); + log.info("调用大模型接口:{},传参为:{}",fdpHost + bigModelInvokeUrl.getAssistantSpecialAsk(),JSON.toJSONString(params)); + RequestClientUtil.postCall(fdpHost + bigModelInvokeUrl.getAssistantSpecialAsk(), params); + sessionRedisManager.addSessionId(sessionId); + } + + @Override + public void specialAsk(QuestionDTO question) { + RequestClientUtil.postCall(fdpHost + bigModelInvokeUrl.getAssistantSpecialAsk(), JSON.toJSONString(question)); + sessionRedisManager.addSessionId(question.getChatId()); + } + + @Override + public void knowledgeAsk(String question, String sessionId, String userId, String knowledge) { + Map params = new HashMap<>(); + params.put("chat_id", sessionId); + params.put("user_id", userId); + params.put("query", question); + params.put("knowledge", knowledge); + Map authDataIds = this.getAuthDataIds(userId); + params.putAll(authDataIds); + RequestClientUtil.postCall(fdpHost + bigModelInvokeUrl.getAssistantKnowledgeAsk(), params); + sessionRedisManager.addSessionId(sessionId); + } + + @Override + public void knowledgeAsk(QuestionDTO question) { + RequestClientUtil.postCall(fdpHost + bigModelInvokeUrl.getAssistantKnowledgeAsk(), JSON.toJSONString(question)); + sessionRedisManager.addSessionId(question.getChatId()); + } + + @Override + public void removeSessionId(String sessionId) { + this.askAbort(sessionId); + // 移除内存sessionId + InteractiveSessionManager.SESSION_POOL.remove(sessionId); + sessionRedisManager.removeSessionId(sessionId); + } + + @Override + public void askAbort(String sessionId) { + Map params = new HashMap<>(); + params.put("id",sessionId); + RequestClientUtil.postCall(fdpHost + bigModelInvokeUrl.getAskAbort(), params); + } + + @Override + public List hotQuestions() { + try { + return RequestClientUtil.postCall(fdpHost + bigModelInvokeUrl.getHotQuestion(), null, new TypeReference>(){}); + } + catch (Exception e) { + log.error("An error occurred",e); + return Lists.newArrayList(); + } + } + + @Override + public List getAnswerBySessionIds(String sessionIds) { + Map params = new HashMap<>(); + params.put("chat_ids",Func.toStrList(",",sessionIds).toArray()); + return RequestClientUtil.postCall(fdpHost + bigModelInvokeUrl.getAssistantStatus(), params, new TypeReference>(){}); + } + + private Map getAuthDataIds(String userId) { + Map result = new HashMap<>(2); + R> authDataR = authClient.getAuthData(userId); + result.putAll(authDataR.getData()); + return result; + } +} diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/InteractiveServiceImpl.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/InteractiveServiceImpl.java deleted file mode 100644 index 91c6820..0000000 --- a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/InteractiveServiceImpl.java +++ /dev/null @@ -1,105 +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.hnac.hzims.bigmodel.configuration.BigModelInvokeUrl; -import com.hnac.hzims.bigmodel.entity.FunctionEntity; -import com.hnac.hzims.bigmodel.interactive.req.ModelFunctionReq; -import com.hnac.hzims.bigmodel.interactive.service.IInteractiveService; -import com.hnac.hzims.bigmodel.interactive.service.IJumpPageService; -import com.hnac.hzims.bigmodel.function.service.IFunctionService; -import com.hnac.hzims.bigmodel.interactive.vo.AnswerVO; -import lombok.AllArgsConstructor; -import lombok.RequiredArgsConstructor; -import lombok.extern.slf4j.Slf4j; -import org.springblade.core.log.exception.ServiceException; -import org.springblade.core.secure.utils.AuthUtil; -import org.springblade.core.tool.api.R; -import org.springblade.core.tool.utils.Func; -import org.springblade.core.tool.utils.StringUtil; -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 javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import javax.servlet.http.HttpSession; - -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import static com.hnac.hzims.bigmodel.interactive.constants.FunctionConstants.*; -/** - * @Author: huangxing - * @Date: 2024/04/26 14:51 - */ -@Service -@Slf4j -@RequiredArgsConstructor -public class InteractiveServiceImpl implements IInteractiveService { - - private final IJumpPageService jumpPageService; - private final IFunctionService functionService; - private final BigModelInvokeUrl bigModelInvokeUrl; - @Value("${fdp.host}") - private String fdpHost; - - @Override - public R resolve(ModelFunctionReq req) { - //TODO 数据鉴权 - FunctionEntity function = functionService.getFunctionByCode(req.getFunctionName()); - TypeEnum typeEnum = TypeEnum.getTypeEnumByType(function.getType()); - switch (typeEnum) { - // 页面跳转 - case JUMP: - String extra = jumpPageService.dealJumpTypeFunction(function, req.getFunctionArgs()); - Assert.isTrue(StringUtil.isNotBlank(extra) && Func.isNotEmpty(extra), () -> { - throw new ServiceException("解析" + function.getName() + "函数失败!"); - }); - return R.data(extra); - default: - throw new ServiceException("函数解析失败!"); - } - } - - @Override - public R ask(String question,String sessionId) { - Long userId = AuthUtil.getUserId(); - //TODO 保存问题 - Map params = new HashMap<>(); - params.put("id",sessionId); - params.put("userid",userId.toString()); - params.put("query",question); - HttpResponse response = HttpRequest.post(fdpHost + bigModelInvokeUrl.getAssistantAsk()) - .body(JSON.toJSONString(params)).execute(); - Assert.isTrue(response.getStatus() == HttpServletResponse.SC_OK && "1".equals(JSONObject.parseObject(response.body()).getString("success")), () -> { - throw new ServiceException("远程调用大模型【发起问答】接口失败!"); - }); - return R.data(JSONObject.parseObject(response.body()).getString("data")); - } - - @Override - public List getAnswerBySessionIds(String sessionIds) { - Map params = new HashMap<>(); - params.put("ids",sessionIds); - HttpResponse response = HttpRequest.post(fdpHost + bigModelInvokeUrl.getAssistantStatus()) - .body(JSON.toJSONString(params)).execute(); - Assert.isTrue(response.getStatus() == HttpServletResponse.SC_OK && "1".equals(JSONObject.parseObject(response.body()).getString("success")), () -> { - throw new ServiceException("远程调用大模型【发起问答】接口失败!"); - }); - String data = JSONObject.parseObject(response.body()).getString("data"); - return JSONArray.parseArray(data,AnswerVO.class); - } - - @Override - public Boolean authentication(String stationId, String userId, String menuId) { - //TODO 鉴权逻辑完善 - return true; - } - -} diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/JumpPageServiceImpl.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/JumpPageServiceImpl.java deleted file mode 100644 index b5012db..0000000 --- a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/JumpPageServiceImpl.java +++ /dev/null @@ -1,45 +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 -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 deleted file mode 100644 index 11e0cd4..0000000 --- a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/JumpRouteJoinStrategy.java +++ /dev/null @@ -1,134 +0,0 @@ -package com.hnac.hzims.bigmodel.interactive.service.impl; - -import com.alibaba.fastjson.JSON; -import com.alibaba.fastjson.JSONObject; -import com.hnac.hzims.bigmodel.entity.FunctionEntity; -import com.hnac.hzims.bigmodel.interactive.constants.FuncRouteEnum; -import com.hnac.hzims.bigmodel.interactive.constants.FunctionConstants; -import com.hnac.hzims.bigmodel.interactive.vo.ExtraVO; -import org.springblade.core.log.exception.ServiceException; -import org.springblade.core.tool.utils.Func; -import org.springblade.core.tool.utils.StringUtil; -import org.springframework.stereotype.Component; -import org.springframework.util.Assert; - -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Set; - -/** - * @Author: huangxing - * @Date: 2024/04/30 11:38 - */ -@Component -public class JumpRouteJoinStrategy { - - /** - * 解析大模型传参 - * @param args 大模型传参 - * @return 跳转path所需要的参数 - */ - public ExtraVO resolve(FunctionEntity function,Map args) { - FuncRouteEnum routeEnum = FuncRouteEnum.getEnumByFuncCode(function.getCode()); - if(Func.isNotEmpty(routeEnum)) { - switch(routeEnum) { - case OPEN_SCADA: - return this.getScadaExtra(args,function); - default: - break; - } - } - return null; - } - - private ExtraVO getScadaExtra(Map args,FunctionEntity function) { - // 跳转页面逻辑 - ExtraVO extraVO = new ExtraVO(); - Map params = this.scadaResolve(args); - // 根据hz3000画面版本获取path - Integer picResource = Integer.valueOf(params.get("picResource")); - JSONObject pathObject = JSONObject.parseObject(function.getPath()); - // 云组态 - if(picResource == 0) { - String scada = pathObject.getString("scada"); - extraVO.setRoute(this.replacePath(scada, params)); - extraVO.setRoute(scada); - } - // v3.0 - else if (picResource == 1) { - String v3 = pathObject.getString("v3"); - extraVO.setRoute(this.replacePath(v3, params)); - } - // v4.0 - else if (picResource == 2) { - String v4 = pathObject.getString("v4"); - // pic_name 去掉头部的/ 以及尾部的.js - String context = params.get("context"); - context = this.removeHeadChars(context,"/"); - context = this.removeTailChars(context,".js"); - params.put("context",context); - extraVO.setRoute(this.replacePath(v4, params)); - } - else { - throw new ServiceException("解析出来的画面类型在云组态、v3、v4类型之外,无法解析路由"); - } - extraVO.setType(FunctionConstants.TypeEnum.JUMP.getType()); - return extraVO; - } - - /** - * 打开实时画面 - * @param args 大模型解析参数 - * @return 实时画面路径拼接所需参数 - */ - private Map scadaResolve(Map args) { - Map result = new HashMap<>(); - Assert.isTrue(args.containsKey("params"), () -> { - throw new ServiceException("大模型传参缺少params参数"); - }); - // 参数格式为:picResource^context^stationNum^projectId^taskId^name^id - List params = Func.toStrList("\\^", args.get("params")); - Assert.isTrue(params.size() == 7,() -> { - throw new ServiceException("大模型传参params长度错误,传参为:" + args.get("params")); - }); - result.put("picResource",params.get(0)); - result.put("context",params.get(1)); - result.put("stationNum",params.get(2)); - result.put("projectId",params.get(3)); - result.put("taskId",params.get(4)); - result.put("name",params.get(5)); - result.put("id",params.get(6)); - return result; - } - - private String replacePath(String path,Map params) { - Set> entries = params.entrySet(); - // 替换path中变量 - for (Map.Entry entry : entries) { - String replaceVariables = "{" + entry.getKey() + "}"; - path = StringUtil.replace(path,replaceVariables,entry.getValue()); - } - return path; - } - - public String removeHeadChars(String str, String charsToRemove) { - if (str == null || charsToRemove == null || charsToRemove.isEmpty()) { - return str; - } - while (str.startsWith(charsToRemove)) { - str = str.substring(charsToRemove.length()); - } - return str; - } - - public String removeTailChars(String str, String charsToRemove) { - if (str == null || charsToRemove == null || charsToRemove.isEmpty()) { - return str; - } - while (str.endsWith(charsToRemove)) { - str = str.substring(0, str.length() - charsToRemove.length()); - } - return str; - } -} diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/ParamAnswerResolveServiceImpl.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/ParamAnswerResolveServiceImpl.java new file mode 100644 index 0000000..8a52994 --- /dev/null +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/ParamAnswerResolveServiceImpl.java @@ -0,0 +1,106 @@ +package com.hnac.hzims.bigmodel.interactive.service.impl; + +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONObject; +import com.hnac.hzims.bigmodel.interactive.constants.FuncRouteEnum; +import com.hnac.hzims.bigmodel.interactive.constants.SearchTypeEnum; +import com.hnac.hzims.bigmodel.interactive.factory.AnswerResolveFactory; +import com.hnac.hzims.bigmodel.interactive.service.IAnalyseDataService; +import com.hnac.hzims.bigmodel.interactive.service.IAnswerResolveService; +import com.hnac.hzims.bigmodel.interactive.vo.*; +import com.xxl.job.core.log.XxlJobLogger; +import groovy.util.logging.Slf4j; +import lombok.AllArgsConstructor; +import org.springblade.core.log.exception.ServiceException; +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.util.Date; +import java.util.HashMap; +import java.util.Map; + +/** + * @Author: huangxing + * @Date: 2024/06/21 19:02 + */ +@Service(AnswerResolveFactory.PARAM_ANSWER_SERVICE) +@Slf4j +@AllArgsConstructor +public class ParamAnswerResolveServiceImpl implements IAnswerResolveService { + + private final IAnalyseDataService analyseDataService; + + public static final String PATTERN_DATETIME = "yyyy-MM-dd HH:mm:ss.SSS"; + + @Override + public AnswerVO resolve(AnswerVO answer) { + Object[] extraArray = this.extraStream(answer).map(this::getExtra).toArray(); + answer.setExtras(extraArray); + return answer; + } + + @Override + public ExtraVO getExtra(JSONObject originExtra) { + DataVO data = JSONObject.parseObject(JSON.toJSONString(originExtra.get("data")),DataVO.class); + Assert.isTrue(Func.isNotEmpty(data),() -> { + XxlJobLogger.log("解析参数答案失败,extra不能为空!"); + throw new ServiceException("解析参数答案失败,extra不能为空!"); + }); + if(Func.isNotEmpty(data.getReal())) { + // 处理查询实时数据 + RealDataVO real = data.getReal(); + Date date = DateUtil.parse(real.getTime(), PATTERN_DATETIME); + real.setTime(DateUtil.format(date,DateUtil.PATTERN_DATETIME)); + } + else if(StringUtil.isNotBlank(data.getType()) && SearchTypeEnum.HISTORY.getSearchType().equals(data.getType())) { + // 处理查询历史数据 + return this.getHistoryData(data); + } + String funcCode = originExtra.getString("func"); + ExtraVO result = new ExtraVO(); + result.setFunc(funcCode); + result.setType(FuncRouteEnum.getEnumByFuncCode(funcCode).getType().getType()); + Map param = new HashMap(1); + param.put("data", data); + result.setParams(param); + return result; + } + + /** + * 查询历史数据 + * @param data 大模型识别数据信息 + * @return 历史数据 + */ + private ExtraVO getHistoryData(DataVO data) { + // 确认查询聚合方式传入 + Assert.isTrue(Func.isNotEmpty(data.getItem()) && StringUtil.isNotBlank(data.getMethod()),() -> { + XxlJobLogger.log("历史数据查询方式为空,查询失败!"); + throw new ServiceException("历史数据查询方式为空,查询失败!"); + }); + return analyseDataService.getHistoryData(this.convertHistoryDataSearch(data)); + } + + /** + * 获取历史数据查询对象 + * @param data 大模型解析点位信息 + * @return 历史数据查询对象 + */ + private HistoryDataSearchVO convertHistoryDataSearch(DataVO data) { + HistoryDataSearchVO searchVO = new HistoryDataSearchVO(); + DataItemVO item = data.getItem(); + 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 searchVO; + } + +} diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/RemoteAnswerResolveServiceImpl.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/RemoteAnswerResolveServiceImpl.java new file mode 100644 index 0000000..09cc711 --- /dev/null +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/RemoteAnswerResolveServiceImpl.java @@ -0,0 +1,59 @@ +package com.hnac.hzims.bigmodel.interactive.service.impl; + +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONArray; +import com.alibaba.fastjson.JSONObject; +import com.hnac.hzims.bigmodel.interactive.constants.FuncRouteEnum; +import com.hnac.hzims.bigmodel.interactive.factory.AnswerResolveFactory; +import com.hnac.hzims.bigmodel.interactive.service.IAnswerResolveService; +import com.hnac.hzims.bigmodel.interactive.vo.AnswerVO; +import com.hnac.hzims.bigmodel.interactive.vo.ExtraVO; +import com.hnac.hzims.bigmodel.interactive.vo.RemoteParamVO; +import com.hnac.hzinfo.sdk.v5.device.client.DeviceClient; +import com.hnac.hzinfo.sdk.v5.device.vo.DeviceInstanceFuncVO; +import groovy.util.logging.Slf4j; +import lombok.AllArgsConstructor; +import org.springblade.core.tool.api.R; +import org.springframework.stereotype.Service; + +import java.util.HashMap; +import java.util.Map; + +/** + * @Author: huangxing + * @Date: 2024/06/21 19:02 + */ +@Service(AnswerResolveFactory.REMOTE_ANSWER_SERVICE) +@Slf4j +@AllArgsConstructor +public class RemoteAnswerResolveServiceImpl implements IAnswerResolveService { + + private final DeviceClient deviceClient; + + @Override + public AnswerVO resolve(AnswerVO answer) { + Object[] extraArray = this.extraStream(answer).map(this::getExtra).toArray(); + answer.setExtras(extraArray); + return answer; + } + + @Override + public ExtraVO getExtra(JSONObject originExtra) { + ExtraVO result = new ExtraVO(); + RemoteParamVO remoteParam = JSONObject.parseObject(JSON.toJSONString(originExtra.get("data")), RemoteParamVO.class); + String funcCode = originExtra.getString("func"); + result.setFunc(funcCode); + result.setType(FuncRouteEnum.getEnumByFuncCode(funcCode).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; + } +} diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/VideoResolveServiceImpl.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/VideoResolveServiceImpl.java new file mode 100644 index 0000000..10fbf2e --- /dev/null +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/VideoResolveServiceImpl.java @@ -0,0 +1,73 @@ +package com.hnac.hzims.bigmodel.interactive.service.impl; + +import com.alibaba.fastjson.JSON; +import com.hnac.hzims.bigmodel.interactive.constants.FuncRouteEnum; +import com.hnac.hzims.bigmodel.interactive.constants.FunctionConstants; +import com.hnac.hzims.bigmodel.interactive.factory.ResolveFactory; +import com.hnac.hzims.bigmodel.interactive.req.ModelFunctionReq; +import com.hnac.hzims.bigmodel.interactive.service.IResolveService; +import com.hnac.hzims.bigmodel.interactive.vo.ExtraVO; +import com.hnac.hzims.operational.station.entity.StationVideoTypeEntity; +import com.hnac.hzims.operational.station.feign.IStationVideoTypeClient; +import groovy.util.logging.Slf4j; +import lombok.AllArgsConstructor; +import org.springblade.core.log.exception.ServiceException; +import org.springblade.core.log.logger.BladeLogger; +import org.springblade.core.tool.api.R; +import org.springblade.core.tool.utils.StringUtil; +import org.springframework.stereotype.Service; +import org.springframework.util.Assert; + +import java.util.HashMap; +import java.util.Map; + +/** + * @Author: huangxing + * @Date: 2024/06/21 16:17 + */ +@Service(ResolveFactory.VIDEO_RESOLVE_SERVICE) +@AllArgsConstructor +@Slf4j +public class VideoResolveServiceImpl implements IResolveService { + + private final IStationVideoTypeClient videoClient; + private final BladeLogger logger; + + @Override + public ExtraVO resolve(ModelFunctionReq req) { + 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 idStr) { + Long id = Long.valueOf(idStr); + // 跳转页面逻辑 + ExtraVO extraVO = new ExtraVO(); + R videoR = videoClient.getById(Long.valueOf(id)); + if(videoR.isSuccess()) { + StationVideoTypeEntity video = videoR.getData(); + extraVO.setType(FunctionConstants.TypeEnum.PARAMS.getType()); + extraVO.setImmediatelyJump(true); + extraVO.setFunc(FuncRouteEnum.OPEN_VIDEO.getFunc()); + Map params = new HashMap<>(); + params.put("name", video.getName()); + params.put("videoHost", video.getVideoHost()); + params.put("pointCode", video.getPointCode()); + params.put("appKey", video.getAppKey()); + params.put("appSecret", video.getAppSecret()); + params.put("liveSourceAddress",video.getLiveSourceAddress()); + extraVO.setParams(params); + } + return extraVO; + } +} diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/vo/AnswerVO.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/vo/AnswerVO.java index ae34551..9fd4774 100644 --- a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/vo/AnswerVO.java +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/vo/AnswerVO.java @@ -1,10 +1,14 @@ package com.hnac.hzims.bigmodel.interactive.vo; import com.alibaba.fastjson.annotation.JSONField; +import com.hnac.hzims.bigmodel.interactive.constants.InfoMessageConstant; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; +import lombok.AllArgsConstructor; import lombok.Data; import lombok.EqualsAndHashCode; +import lombok.NoArgsConstructor; +import org.springblade.core.tool.utils.BeanUtil; import java.io.Serializable; @@ -15,14 +19,16 @@ import java.io.Serializable; @Data @ApiModel("HZLLM答案VO对象") @EqualsAndHashCode +@AllArgsConstructor +@NoArgsConstructor public class AnswerVO implements Serializable { @ApiModelProperty("发起问答时的随机ID") - @JSONField(name = "id") + @JSONField(name = "chat_id") private String sessionId; @ApiModelProperty("发起问答时的用户ID") - @JSONField(name = "userid") + @JSONField(name = "user_id") private String userId; @ApiModelProperty("1代表代表正在进行问答,0代表已完成") @@ -44,4 +50,23 @@ public class AnswerVO implements Serializable { @ApiModelProperty("query对应的答案") private String answer; + @ApiModelProperty("其它调用的参数") + private Object[] extras; + + @ApiModelProperty("用于语音回复的状态文本") + @JSONField(name = "voice_text") + private String[] voiceText; + + @ApiModelProperty("用于语音回复的答案") + @JSONField(name = "voice_answer") + private String[] voiceAnswer; + + public static AnswerVO error(String sessionId,String userId,String query) { + return new AnswerVO(sessionId,userId,0,-2,null,query, InfoMessageConstant.ERROR_MESSAGE, null,null,new String[]{InfoMessageConstant.ERROR_MESSAGE}); + } + + public static void error(AnswerVO usualVO) { + usualVO.setRunning(0); + usualVO.setStatus(-2); + } } diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/vo/AuthDataVO.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/vo/AuthDataVO.java new file mode 100644 index 0000000..dafd6e7 --- /dev/null +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/vo/AuthDataVO.java @@ -0,0 +1,27 @@ +package com.hnac.hzims.bigmodel.interactive.vo; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.EqualsAndHashCode; + +import java.io.Serializable; + +/** + * @Author: huangxing + * @Date: 2024/06/21 10:26 + */ +@Data +@AllArgsConstructor +@ApiModel(value = "鉴权数据VO",description = "鉴权数据VO,包含站点、机构、遥控权限") +@EqualsAndHashCode +public class AuthDataVO implements Serializable { + + @ApiModelProperty("数据ID") + private String itemId; + + @ApiModelProperty("数据名称") + private String itemName; + +} diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/vo/HistoryDataSearchVO.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/vo/HistoryDataSearchVO.java new file mode 100644 index 0000000..0728206 --- /dev/null +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/vo/HistoryDataSearchVO.java @@ -0,0 +1,37 @@ +package com.hnac.hzims.bigmodel.interactive.vo; + +import lombok.Data; + +import javax.validation.constraints.NotBlank; + +/** + * @Author: huangxing + * @Date: 2024/05/28 11:48 + */ +@Data +public class HistoryDataSearchVO { + + @NotBlank + private String startTime; + + @NotBlank + private String endTime; + + @NotBlank + private String deviceCode; + + @NotBlank + private String signage; + + private String attrName; + + @NotBlank + private String method; + + private String dataType; + + private String stationName; + + private String deviceName; + +} diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/vo/RemoteParamVO.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/vo/RemoteParamVO.java new file mode 100644 index 0000000..6448893 --- /dev/null +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/vo/RemoteParamVO.java @@ -0,0 +1,39 @@ +package com.hnac.hzims.bigmodel.interactive.vo; + +import com.alibaba.fastjson.annotation.JSONField; +import lombok.Data; +import lombok.EqualsAndHashCode; + +import java.io.Serializable; + +/** + * @Author: huangxing + * @Date: 2024/05/20 14:46 + */ +@Data +@EqualsAndHashCode +public class RemoteParamVO implements Serializable { + + @JSONField(name = "itemId") + private String funcId; + + @JSONField(name = "yk_name") + private String remoteName; + + @JSONField(name = "device_id") + private String deviceId; + + @JSONField(name = "device_name") + private String deviceName; + + @JSONField(name = "station_id") + private String projectId; + + @JSONField(name = "station_name") + private String projectName; + + private String signage; + + private String value; + +} diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/vo/ResolveResultVO.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/vo/ResolveResultVO.java new file mode 100644 index 0000000..f24b67e --- /dev/null +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/vo/ResolveResultVO.java @@ -0,0 +1,29 @@ +package com.hnac.hzims.bigmodel.interactive.vo; + +import com.hnac.hzims.bigmodel.interactive.constants.InfoMessageConstant; +import io.swagger.annotations.ApiModel; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.EqualsAndHashCode; + +import java.io.Serializable; + +/** + * @Author: huangxing + * @Date: 2024/06/21 16:31 + */ +@EqualsAndHashCode +@Data +@AllArgsConstructor +@ApiModel(value = "解析结果",description = "解析结果") +public class ResolveResultVO implements Serializable { + + private String content; + + private ExtraVO extraVO; + + public static ResolveResultVO error() { + return new ResolveResultVO(InfoMessageConstant.ERROR_MESSAGE,null); + } + +} diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/vo/SessionContentVO.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/vo/SessionContentVO.java new file mode 100644 index 0000000..1de0532 --- /dev/null +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/vo/SessionContentVO.java @@ -0,0 +1,19 @@ +package com.hnac.hzims.bigmodel.interactive.vo; + +import lombok.Data; +import lombok.EqualsAndHashCode; + +import java.io.Serializable; + +/** + * @Author: huangxing + * @Date: 2024/05/20 19:31 + */ +@Data +@EqualsAndHashCode +public class SessionContentVO implements Serializable { + + /**机器码**/ + private String machineCode; + +} diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/vo/StationSearchVO.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/vo/StationSearchVO.java new file mode 100644 index 0000000..d111b70 --- /dev/null +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/vo/StationSearchVO.java @@ -0,0 +1,24 @@ +package com.hnac.hzims.bigmodel.interactive.vo; + +import lombok.Data; + +import javax.validation.constraints.NotBlank; +import java.io.Serializable; + +/** + * @Author: huangxing + * @Date: 2024/05/25 14:03 + */ +@Data +public class StationSearchVO implements Serializable { + + private String startTime; + + private String endTime; + + @NotBlank(message = "查询类型不能为空") + private String type; + + private String enumType; + +} diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/vo/UpdateStationVO.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/vo/UpdateStationVO.java new file mode 100644 index 0000000..3ed167a --- /dev/null +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/vo/UpdateStationVO.java @@ -0,0 +1,20 @@ +package com.hnac.hzims.bigmodel.interactive.vo; + +import lombok.Data; + +import java.io.Serializable; + +/** + * @Author: huangxing + * @Date: 2024/05/09 09:50 + */ +@Data +public class UpdateStationVO implements Serializable { + + /**站点ID**/ + private String id; + + /**站点名称**/ + private String name; + +} diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/vo/UpdateUsualVO.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/vo/UpdateUsualVO.java new file mode 100644 index 0000000..88a9c73 --- /dev/null +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/vo/UpdateUsualVO.java @@ -0,0 +1,25 @@ +package com.hnac.hzims.bigmodel.interactive.vo; + +import com.alibaba.fastjson.annotation.JSONField; +import lombok.Data; + +import java.io.Serializable; + +/** + * @Author: huangxing + * @Date: 2024/05/09 09:53 + */ +@Data +public class UpdateUsualVO implements Serializable { + + /**站点ID**/ + @JSONField(name = "station_id") + private String stationId; + + /**业务ID**/ + private String id; + + /**业务名称**/ + private String name; + +} 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..91989c1 --- /dev/null +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/maintenance/controller/DataSourceController.java @@ -0,0 +1,76 @@ +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.*; + +import java.util.List; + +/** + * @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)); + } + + @GetMapping("/list") + @ApiOperation(value = "列表查询") + @ApiOperationSupport(order = 1) + public R> list(DatasourceEntity req) { + return R.data(dataSourceService.list(Condition.getQueryWrapper(req).lambda())); + } + +} 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 new file mode 100644 index 0000000..840f784 --- /dev/null +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/maintenance/controller/TableColumnController.java @@ -0,0 +1,56 @@ +package com.hnac.hzims.bigmodel.maintenance.controller; + +import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport; +import com.hnac.hzims.bigmodel.BigModelConstants; +import com.hnac.hzims.bigmodel.maintenance.service.TableColumnService; +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.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +import java.util.List; +import java.util.Map; + +/** + * @Author: huangxing + * @Date: 2024/07/04 09:28 + */ +@RestController +@RequestMapping("/table/info") +@Api(value = "数据库表、列信息查询管理",tags = "数据库表、列信息查询管理") +@Business(module = BigModelConstants.APP_NAME,value = "数据库表、列信息查询管理",ignore = false) +@AllArgsConstructor +public class TableColumnController { + + private final TableColumnService tableColumnService; + + @ApiOperation("获取数据库") + @ApiOperationSupport(order = 1) + @GetMapping("/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 datasource, + @RequestParam @ApiParam(value = "数据库名") String database) { + return R.data(tableColumnService.getTables(datasource,database)); + } + + @ApiOperation("获取数据库表列列表") + @ApiOperationSupport(order = 3) + @GetMapping("/getColumns") + public R>> getColumns(String datasource, + @RequestParam @ApiParam(value = "数据源名") String database, + @RequestParam @ApiParam(value = "数据库表名") String 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/TableInfoController.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/maintenance/controller/TableInfoController.java new file mode 100644 index 0000000..4bc0f1d --- /dev/null +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/maintenance/controller/TableInfoController.java @@ -0,0 +1,61 @@ +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.BigModelConstants; +import com.hnac.hzims.bigmodel.maintenance.entity.TableInfoEntity; +import com.hnac.hzims.bigmodel.maintenance.service.TableInfoService; +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.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 javax.validation.Valid; + +/** + * @Author: huangxing + * @Date: 2024/07/04 15:26 + */ +@RestController +@RequestMapping("/tableInfo") +@Api(value = "数据库信息管理",tags = "数据库信息管理") +@AllArgsConstructor +@Business(module = BigModelConstants.APP_NAME,value = "数据库信息管理",ignore = false) +public class TableInfoController { + + private final TableInfoService tableInfoService; + + @PostMapping("/save") + @ApiOperation("保存数据库信息") + @ApiOperationSupport(order = 1) + public R save(@RequestBody @Valid TableInfoEntity req) { + return R.data(tableInfoService.save(req)); + } + + @PostMapping("/update") + @ApiOperation("编辑数据库信息") + @ApiOperationSupport(order = 2) + public R update(@RequestBody TableInfoEntity req) { + return R.data(tableInfoService.updateById(req)); + } + + @GetMapping("/listPage") + @ApiOperation("数据库信息列表查询") + @ApiOperationSupport(order = 3) + public R> listPage(Query query, TableInfoEntity req) { + return R.data(tableInfoService.page(Condition.getPage(query),Condition.getQueryWrapper(req).lambda())); + } + + @DeleteMapping("/removeByIds") + @ApiOperation("删除数据库信息") + @ApiOperationSupport(order = 4) + public R removeByIds(@RequestParam @ApiParam("id,按逗号分隔") String ids) { + return R.status(tableInfoService.removeByIds(Func.toLongList(",",ids))); + } +} 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..1961bef --- /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/DataRecordEntity.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/maintenance/entity/DataRecordEntity.java new file mode 100644 index 0000000..af8248c --- /dev/null +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/maintenance/entity/DataRecordEntity.java @@ -0,0 +1,17 @@ +package com.hnac.hzims.bigmodel.maintenance.entity; + +import lombok.Data; +import org.springblade.core.tenant.mp.TenantEntity; + +/** + * @Author: huangxing + * @Date: 2024/07/04 15:45 + */ +@Data +public class DataRecordEntity extends TenantEntity { + + private String tableId; + + + +} 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/TableInfoEntity.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/maintenance/entity/TableInfoEntity.java new file mode 100644 index 0000000..9a37d57 --- /dev/null +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/maintenance/entity/TableInfoEntity.java @@ -0,0 +1,56 @@ +package com.hnac.hzims.bigmodel.maintenance.entity; + +import com.baomidou.mybatisplus.annotation.TableField; +import com.baomidou.mybatisplus.annotation.TableName; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +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 javax.validation.constraints.NotBlank; +import java.io.Serializable; + +/** + * @Author: huangxing + * @Date: 2024/07/04 14:59 + */ +@Data +@TableName("mysql_table_info") +@EqualsAndHashCode +@ApiModel(value = "数据库信息",description = "数据库信息") +public class TableInfoEntity extends TenantEntity implements Serializable { + + @TableField("db_source") + @ApiModelProperty("数据源") + @NotBlank + @QueryField(condition = SqlCondition.LIKE) + private String datasource; + + @TableField("db_name") + @ApiModelProperty("数据库") + @NotBlank + @QueryField(condition = SqlCondition.EQUAL) + private String database; + + @ApiModelProperty("数据库表名") + @NotBlank + @QueryField(condition = SqlCondition.EQUAL) + private String tableName; + + @ApiModelProperty("数据库表描述信息") + @NotBlank + @QueryField(condition = SqlCondition.LIKE) + private String tableDesc; + + @ApiModelProperty("数据库表列信息") + @NotBlank + private String propDesc; + + @ApiModelProperty("举例") + @NotBlank + private String example; + +} 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/TableInfoMapper.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/maintenance/mapper/TableInfoMapper.java new file mode 100644 index 0000000..f451a78 --- /dev/null +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/maintenance/mapper/TableInfoMapper.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.TableInfoEntity; + +/** + * @Author: huangxing + * @Date: 2024/07/04 15:25 + */ +public interface TableInfoMapper 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 new file mode 100644 index 0000000..91f04fb --- /dev/null +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/maintenance/service/TableColumnService.java @@ -0,0 +1,37 @@ +package com.hnac.hzims.bigmodel.maintenance.service; + +import com.hnac.hzims.bigmodel.business.service.DataSourceService; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Service; + +import java.util.List; +import java.util.Map; + +/** + * @Author: huangxing + * @Date: 2024/07/04 09:29 + */ +@Service +@RequiredArgsConstructor +@Slf4j +public class TableColumnService { + + private final DataSourceService dataSourceService; + + public List> getDatabase(String datasource) { + String sql = "select distinct `table_schema` as tableName from `information_schema`.`tables` where `table_schema` <> 'information_schema';"; + return dataSourceService.queryListOnSpecificDataSource(sql,datasource); + } + + public List> getTables(String datasource,String database) { + String sql = "select distinct `table_name` as tableName from `information_schema`.`tables` where `table_schema` = '" + database + "';"; + return dataSourceService.queryListOnSpecificDataSource(sql,datasource); + } + + public List> getColumns(String datasource,String database,String tableName) { + String sql = "select distinct `column_name` as columnName,`column_comment` as columnComment 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/TableInfoService.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/maintenance/service/TableInfoService.java new file mode 100644 index 0000000..e5643d5 --- /dev/null +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/maintenance/service/TableInfoService.java @@ -0,0 +1,21 @@ +package com.hnac.hzims.bigmodel.maintenance.service; + +import com.baomidou.dynamic.datasource.annotation.DS; +import com.hnac.hzims.bigmodel.maintenance.entity.TableInfoEntity; +import com.hnac.hzims.bigmodel.maintenance.mapper.TableInfoMapper; +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/04 15:23 + */ +@Service +@AllArgsConstructor +@Slf4j +@DS("hznlm") +public class TableInfoService extends BaseServiceImpl { + +} 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/manager/SessionRedisManager.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/manager/SessionRedisManager.java new file mode 100644 index 0000000..43c7af3 --- /dev/null +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/manager/SessionRedisManager.java @@ -0,0 +1,34 @@ +package com.hnac.hzims.bigmodel.manager; + +import com.hnac.hzims.bigmodel.interactive.vo.AnswerVO; +import lombok.AllArgsConstructor; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.redis.core.RedisTemplate; +import org.springframework.stereotype.Component; + +import java.util.List; + +import static com.hnac.hzims.bigmodel.schedule.XxlJobHandlerConstant.HZIMS_BIGMODEL_ASK_KEY; + +/** + * @Author: huangxing + * @Date: 2024/06/21 18:23 + */ +@Component +public class SessionRedisManager { + + @Autowired + private RedisTemplate redisTemplate; + + public void addSessionId(String sessionId) { + redisTemplate.opsForList().leftPush(HZIMS_BIGMODEL_ASK_KEY,sessionId); + } + + public void removeSessionId(String sessionId) { + redisTemplate.opsForList().remove(HZIMS_BIGMODEL_ASK_KEY,1,sessionId); + } + + public List getSessionIds() { + return redisTemplate.opsForList().range(HZIMS_BIGMODEL_ASK_KEY, 0, -1); + } +} diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/question/dto/MessageDTO.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/question/dto/MessageDTO.java new file mode 100644 index 0000000..6f2c729 --- /dev/null +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/question/dto/MessageDTO.java @@ -0,0 +1,101 @@ +package com.hnac.hzims.bigmodel.question.dto; + +import com.alibaba.fastjson.annotation.JSONField; +import com.hnac.hzims.bigmodel.interactive.vo.SessionContentVO; +import lombok.Data; +import lombok.EqualsAndHashCode; + +import java.io.Serializable; +import java.util.Map; + +/** + * @Author: huangxing + * @Date: 2024/07/10 10:22 + * @Describe: 接收前端发送消息 + */ +@Data +@EqualsAndHashCode +public class MessageDTO implements Serializable { + + /** + * 消息类型 0-心跳消息 1-问题 + */ + private String type; + + /** + * 前端提出问题 + */ + private String context; + + /** + * 前端传参附带参数 + */ + private SessionContentVO content; + + /** + * 是否发起特殊问答 + */ + private Boolean isSpecial; + + /** + * 发起问题用户ID + */ + private String userId; + + /** + * 知识库 + */ + private String knowledge; + + /** + * 会话ID + */ + private String chatId; + + /** + * 大模型函数 + */ + private String func; + + /** + * 特殊问题参数 + */ + private Map extra; + + /** + * 是否允许大模型查询数据,默认为1 + */ + @JSONField(name = "enable_record") + private int enableRecord = 1; + + /** + * 是否允许大模型发送指令,默认为1 + */ + @JSONField(name = "enable_yk") + private int enableControl = 1; + + /** + * 是否允许大模型打开视频,默认为1 + */ + @JSONField(name = "enable_video") + private int enableVideo = 1; + + /** + * 是否允许大模型打开画面,默认为1 + */ + @JSONField(name = "enable_canvas") + private int enableCanvas = 1; + + /** + * 是否允许大模型诊断故障,默认为1 + */ + @JSONField(name = "enable_fault") + private int enableFault = 1; + + /** + * 大模型默认的意图理解方式,可以为"default","yk"... + */ + @JSONField(name = "default") + private String defaultMode; + +} diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/question/dto/QuestionDTO.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/question/dto/QuestionDTO.java new file mode 100644 index 0000000..d01369e --- /dev/null +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/question/dto/QuestionDTO.java @@ -0,0 +1,76 @@ +package com.hnac.hzims.bigmodel.question.dto; + +import com.alibaba.fastjson.annotation.JSONField; +import lombok.Data; +import lombok.EqualsAndHashCode; + +import java.io.Serializable; +import java.util.Map; + +/** + * @Author: huangxing + * @Date: 2024/07/10 10:27 + */ +@Data +@EqualsAndHashCode +public class QuestionDTO implements Serializable { + + /** + * 随机ID,同一个用户的对话使用统一的ID + */ + @JSONField(name = "chat_id") + private String chatId; + + /** + * 用户ID,同一个随机ID只能对应一个用户ID + */ + @JSONField(name = "user_id") + private String userId; + + /** + * 用户的问题 + */ + private String query; + + /** + * 特殊提问内容 + */ + private Map extra; + + /** + * 是否允许大模型查询数据,默认为 1 + */ + @JSONField(name = "enable_record") + private int enableRecord = 1; + + /** + * 是否允许大模型发送指令,默认为 1 + */ + @JSONField(name = "enable_yk") + private int enableControl = 1; + + /** + * 是否允许大模型打开视频,默认为 1 + */ + @JSONField(name = "enable_video") + private int enableVideo = 1; + + /** + * 是否允许大模型打开画面,默认为 1 + */ + @JSONField(name = "enable_canvas") + private int enableCanvas = 1; + + /** + * 是否允许大模型诊断故障,默认为 1 + */ + @JSONField(name = "enable_fault") + private int enableFault = 1; + + /** + * 大模型默认的意图理解方式,可以为"default","yk"... + */ + @JSONField(name = "default") + private String defaultMode; + +} diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/question/service/QuestionHandlerService.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/question/service/QuestionHandlerService.java new file mode 100644 index 0000000..a9c168e --- /dev/null +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/question/service/QuestionHandlerService.java @@ -0,0 +1,122 @@ +package com.hnac.hzims.bigmodel.question.service; + +import com.alibaba.fastjson.JSON; +import com.hnac.hzims.bigmodel.interactive.constants.FuncRouteEnum; +import com.hnac.hzims.bigmodel.interactive.factory.ResolveFactory; +import com.hnac.hzims.bigmodel.interactive.service.IHznlmInvokeService; +import com.hnac.hzims.bigmodel.interactive.service.IResolveService; +import com.hnac.hzims.bigmodel.interactive.vo.AnswerVO; +import com.hnac.hzims.bigmodel.interactive.vo.ExtraVO; +import com.hnac.hzims.bigmodel.interactive.vo.ScadaSelectionVO; +import com.hnac.hzims.bigmodel.interactive.vo.VideoSelectionVO; +import com.hnac.hzims.bigmodel.question.dto.MessageDTO; +import com.hnac.hzims.bigmodel.question.dto.QuestionDTO; +import com.hnac.hzims.bigmodel.websocket.service.InteractiveWsService; +import com.hnac.hzims.bigmodel.websocket.sessionManager.InteractiveSessionManager; +import lombok.AllArgsConstructor; +import org.springblade.core.tool.utils.BeanUtil; +import org.springblade.core.tool.utils.Func; +import org.springblade.core.tool.utils.SpringUtil; +import org.springblade.core.tool.utils.StringUtil; +import org.springframework.stereotype.Service; +import org.springframework.web.socket.TextMessage; + +/** + * @Author: huangxing + * @Date: 2024/07/10 11:03 + */ +@Service +@AllArgsConstructor +public class QuestionHandlerService { + + private final IHznlmInvokeService hznlmInvokeService; + + /** + * 处理用户发起问题 + * @param messageDTO 接收前端消息内容体 + */ + public void handleMessage(MessageDTO messageDTO) { + // 将message转换为question + QuestionDTO question = BeanUtil.copy(messageDTO,QuestionDTO.class); + question.setQuery(messageDTO.getContext()); + // 普通问答 + if(Func.isEmpty(messageDTO.getIsSpecial()) || !messageDTO.getIsSpecial()) { + if (StringUtil.isNotBlank(messageDTO.getKnowledge())) { + hznlmInvokeService.knowledgeAsk(question); + } else { + hznlmInvokeService.ask(question); + } + } else { + FuncRouteEnum funcEnum = FuncRouteEnum.getEnumByFuncCode((String) messageDTO.getExtra().get("func")); + switch (funcEnum) { + case CHOOSE_STATION: + case CHOOSE_YC: + case CHOOSE_FAULT: + case CHOOSE_YK: + hznlmInvokeService.specialAsk(question); + break; + case CHOOSE_VIDEO: + this.handleVideoChoose(messageDTO); + break; + case CHOOSE_CANVAS: + this.handleScadaChoose(messageDTO); + break; + default: + break; + } + } + } + + private void handleVideoChoose(MessageDTO messageDTO) { + InteractiveWsService wsService = SpringUtil.getBean(InteractiveWsService.class); + try { + VideoSelectionVO selection = (VideoSelectionVO) messageDTO.getExtra().get("data"); + IResolveService resolveService = ResolveFactory.getResolveService(FuncRouteEnum.OPEN_VIDEO.getFunc()); + String videoId = selection.getItemId(); + ExtraVO videoExtras = resolveService.resolve(videoId); + AnswerVO answerVO = new AnswerVO(); + answerVO.setSessionId(messageDTO.getChatId()); + answerVO.setQuery(selection.getItemName()); + answerVO.setRunning(0); + answerVO.setStatus(0); + answerVO.setAnswer("已成功打开"+selection.getItemName()+"视频"); + answerVO.setExtras(new Object[]{JSON.toJSONString(videoExtras)}); + TextMessage textMessage = InteractiveSessionManager.getTextMessage("1", JSON.toJSONString(answerVO)); + wsService.sendMessage(messageDTO.getChatId(),textMessage); + } + catch (Exception e) { + AnswerVO answerVO = new AnswerVO(); + answerVO.setRunning(0); + answerVO.setStatus(-2); + answerVO.setAnswer("视频解析失败!"); + TextMessage textMessage = InteractiveSessionManager.getTextMessage("1", JSON.toJSONString(answerVO)); + wsService.sendMessage(messageDTO.getChatId(),textMessage); + } + } + + private void handleScadaChoose(MessageDTO messageDTO) { + InteractiveWsService wsService = SpringUtil.getBean(InteractiveWsService.class); + try { + ScadaSelectionVO selection = (ScadaSelectionVO) messageDTO.getExtra().get("data"); + IResolveService resolveService = ResolveFactory.getResolveService(FuncRouteEnum.OPEN_CANVAS.getFunc()); + ExtraVO scadaExtra = resolveService.resolve(selection.getItemId()); + AnswerVO answerVO = new AnswerVO(); + answerVO.setSessionId(messageDTO.getChatId()); + answerVO.setRunning(0); + answerVO.setStatus(0); + answerVO.setQuery(selection.getItemName()); + answerVO.setAnswer("已成功打开"+selection.getItemName()+"实时画面"); + answerVO.setExtras(new Object[]{JSON.toJSONString(scadaExtra)}); + TextMessage textMessage = InteractiveSessionManager.getTextMessage("1", JSON.toJSONString(answerVO)); + wsService.sendMessage(messageDTO.getChatId(),textMessage); + } + catch (Exception e) { + AnswerVO answerVO = new AnswerVO(); + answerVO.setRunning(0); + answerVO.setStatus(-2); + answerVO.setAnswer("实时画面解析失败!"); + TextMessage textMessage = InteractiveSessionManager.getTextMessage("1", JSON.toJSONString(answerVO)); + wsService.sendMessage(messageDTO.getChatId(),textMessage); + } + } +} diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/schedule/FrontEndInteractiveSchedule.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/schedule/FrontEndInteractiveSchedule.java new file mode 100644 index 0000000..e861d7a --- /dev/null +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/schedule/FrontEndInteractiveSchedule.java @@ -0,0 +1,88 @@ +package com.hnac.hzims.bigmodel.schedule; + +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONObject; +import com.hnac.hzims.bigmodel.interactive.factory.AnswerResolveFactory; +import com.hnac.hzims.bigmodel.interactive.service.IAnswerResolveService; +import com.hnac.hzims.bigmodel.interactive.service.IHznlmInteractiveService; +import com.hnac.hzims.bigmodel.interactive.service.IHznlmInvokeService; +import com.hnac.hzims.bigmodel.interactive.service.IResolveService; +import com.hnac.hzims.bigmodel.interactive.vo.AnswerVO; +import com.hnac.hzims.bigmodel.manager.SessionRedisManager; +import com.hnac.hzims.bigmodel.websocket.service.InteractiveWsService; +import com.hnac.hzims.bigmodel.websocket.sessionManager.InteractiveSessionManager; +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 lombok.extern.slf4j.Slf4j; +import org.springblade.core.log.logger.BladeLogger; +import org.springblade.core.tool.utils.CollectionUtil; +import org.springblade.core.tool.utils.Func; +import org.springblade.core.tool.utils.ObjectUtil; +import org.springframework.stereotype.Component; +import org.springframework.web.socket.TextMessage; +import org.springframework.web.socket.WebSocketSession; + +import java.util.Arrays; +import java.util.List; +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/06/24 09:53 + */ +@Component +@AllArgsConstructor +@Slf4j +public class FrontEndInteractiveSchedule { + + private final SessionRedisManager sessionRedisManager; + private final InteractiveWsService wsService; + private final ThreadPoolExecutor getAnswerPoolExecutor; + private final IHznlmInvokeService hznlmInvokeService; + private final BladeLogger logger; + + @XxlJob(GET_INTERACTIVE_RESULT) + public ReturnT getInteractiveResult(String params) { + List sessionIds = sessionRedisManager.getSessionIds(); + if(CollectionUtil.isEmpty(sessionIds)){ + XxlJobLogger.log("问题都已经回答完毕!"); + return ReturnT.SUCCESS; + } + List answerList = hznlmInvokeService.getAnswerBySessionIds(String.join(",", sessionIds)); + answerList.stream().parallel().forEach(answerVO -> CompletableFuture.runAsync(() -> { + // 如果已经获取到答案 则删除缓存 + if(answerVO.getRunning() == 0) { + logger.info("hzims:bigmodel:getInteractiveResult:answer","获取大模型解析答案:" + JSON.toJSONString(answerVO)); + sessionRedisManager.removeSessionId(answerVO.getSessionId()); + } + Object[] extras = answerVO.getExtras(); + if(ObjectUtil.isNotEmpty(answerVO.getExtras()) && extras.length > 0){ + try { + // 解析答案 + Object[] resolveExtras = Arrays.stream(extras).map(extra -> { + IAnswerResolveService answerResolveService = AnswerResolveFactory.getResolveService(extra); + if(Func.isNotEmpty(answerResolveService)) { + JSONObject extraObject = JSONObject.parseObject(JSON.toJSONString(extra)); + return answerResolveService.getExtra(extraObject); + } + return extra; + }).map(JSON::toJSONString).toArray(); + answerVO.setExtras(resolveExtras); + } + catch(Exception e) { + log.error("An error occurred",e); + AnswerVO.error(answerVO.getSessionId(), answerVO.getUserId(), answerVO.getQuery()); + } + } + TextMessage message = InteractiveSessionManager.getTextMessage("1",JSON.toJSONString(answerVO)); + wsService.sendMessage(answerVO.getSessionId(),message); + }, getAnswerPoolExecutor)); + return ReturnT.SUCCESS; + } +} 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 a9c3ba1..0000000 --- a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/schedule/InteractiveSchedule.java +++ /dev/null @@ -1,85 +0,0 @@ -package com.hnac.hzims.bigmodel.schedule; - -import com.alibaba.fastjson.JSON; -import com.hnac.hzims.bigmodel.interactive.service.IInteractiveService; -import com.hnac.hzims.bigmodel.interactive.vo.AnswerVO; -import com.hnac.hzims.bigmodel.websocket.server.InteractiveWsServer; -import com.hnac.hzims.bigmodel.websocket.service.InteractiveWsService; -import com.hnac.hzims.bigmodel.websocket.sessionManager.InteractiveSessionManager; -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.log.exception.ServiceException; -import org.springblade.core.tool.utils.Func; -import org.springblade.system.cache.ParamCache; -import org.springframework.data.redis.core.RedisTemplate; -import org.springframework.stereotype.Component; -import org.springframework.util.Assert; -import org.springframework.web.socket.TextMessage; -import org.springframework.web.socket.WebSocketSession; - -import java.io.IOException; -import java.util.Enumeration; -import java.util.List; -import java.util.Set; -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 -public class InteractiveSchedule { - - private final RedisTemplate redisTemplate; - private final InteractiveWsService wsService; - private final IInteractiveService interactiveService; - private final ThreadPoolExecutor getAnswerPoolExecutor; - -// @XxlJob(GET_INTERACTIVE_RESULT) -// public ReturnT execute(String params) { -// String resultKey = ParamCache.getValue(GET_INTERACTIVE_RESULT); -// Set keySet = redisTemplate.keys(resultKey + "*"); -// keySet.parallelStream().forEach(key -> { -// // 根据Key获取sessionId -// List keySplits = Func.toStrList(":", key); -// String sessionId = keySplits.get(2); -// // 查询websocket是否存在连接session -// WebSocketSession session = InteractiveSessionManager.get(sessionId); -// if(session == null) { -// return; -// } -// TextMessage message = new TextMessage(JSON.toJSONString(redisTemplate.opsForValue().get(key))); -// Boolean sendResult = wsService.sendMessage(sessionId, message); -// Assert.isTrue(sendResult, () -> { -// throw new ServiceException(key + "推送消息失败,推送消息体为:" + JSON.toJSONString(redisTemplate.opsForValue().get(key))); -// }); -// redisTemplate.delete(key); -// }); -// return ReturnT.SUCCESS; -// } - - @XxlJob(GET_INTERACTIVE_RESULT) - public ReturnT execute(String params) { - List sessionIds = InteractiveSessionManager.getSessionIds(); - List AnswerList = interactiveService.getAnswerBySessionIds(sessionIds.stream().collect(Collectors.joining(","))); - AnswerList.parallelStream().forEach(answerVO -> { - CompletableFuture.runAsync(() -> { - WebSocketSession session = InteractiveSessionManager.get(answerVO.getSessionId()); - TextMessage message = new TextMessage(JSON.toJSONString(answerVO)); - try { - session.sendMessage(message); - } catch (IOException e) { - XxlJobLogger.log("消息中心推送失败,推送内容为:" + JSON.toJSONString(answerVO)); - } - }, getAnswerPoolExecutor); - }); - return ReturnT.SUCCESS; - } -} diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/schedule/XxlJobHandlerConstant.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/schedule/XxlJobHandlerConstant.java index 708d3e8..0f210b7 100644 --- a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/schedule/XxlJobHandlerConstant.java +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/schedule/XxlJobHandlerConstant.java @@ -1,13 +1,25 @@ package com.hnac.hzims.bigmodel.schedule; +import com.hnac.hzims.common.constant.CommonConstant; + /** * @Author: huangxing * @Date: 2024/04/28 16:19 */ public interface XxlJobHandlerConstant { + /**获取问答结果**/ String GET_INTERACTIVE_RESULT = "getInteractiveResult"; + String SYNCHRONOUS_FAULT_INSTRUCT = "synchronousFaultInstruct"; + + /**同步视频指令**/ + String SYNCHRONOUS_VIDEO_INSTRUCT = "synchronousVideoInstruct"; + + String SYNCHRONOUS_SCADA_INSTRUCT = "synchronousScadaInstruct"; + String INTERACTIVE_RESULT_KEY = "hzllm:interactive:result"; + String HZIMS_BIGMODEL_ASK_KEY = CommonConstant.TENANT_ID + ":hzims:bigmodel:ask:key"; + } diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/utils/RequestClientUtil.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/utils/RequestClientUtil.java new file mode 100644 index 0000000..f456c65 --- /dev/null +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/utils/RequestClientUtil.java @@ -0,0 +1,67 @@ +package com.hnac.hzims.bigmodel.utils; + +import cn.hutool.http.HttpRequest; +import cn.hutool.http.HttpResponse; +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONObject; +import com.alibaba.fastjson.TypeReference; +import lombok.extern.slf4j.Slf4j; +import org.springblade.core.log.exception.ServiceException; +import org.springframework.util.Assert; + +import javax.servlet.http.HttpServletResponse; +import java.util.Map; + +/** + * @Author: huangxing + * @Date: 2024/06/21 17:12 + */ +@Slf4j +public class RequestClientUtil { + + + /** + * 无返回结果远程调用http接口 + * @param url 接口url + * @param body 传参body + */ + public static void postCall(String url, String body) { + log.info("开始远程调用{}接口",url); + HttpResponse response = HttpRequest.post(url).body(body).execute(); + log.info("远程调用{}接口结束",url); + Assert.isTrue(response.getStatus() == HttpServletResponse.SC_OK, () -> { + throw new ServiceException("远程调用接口" + url + "失败!"); + }); + } + + /** + * 无返回结果远程调用http接口 + * @param url 接口url + * @param body 传参body + */ + public static void postCall(String url, Map body) { + log.info("开始远程调用{}接口",url); + HttpResponse response = HttpRequest.post(url).body(JSON.toJSONString(body)).execute(); + log.info("远程调用{}接口结束",url); + Assert.isTrue(response.getStatus() == HttpServletResponse.SC_OK, () -> { + throw new ServiceException("远程调用接口" + url + "失败!"); + }); + } + + /** + * 远程调用http接口 + * @param url 接口url + * @param body 传参 + * @param typeRef 结果解析对象 + * @return 结果 + * @param 结果解析对象类型 + */ + public static T postCall(String url, Map body, TypeReference typeRef) { + HttpResponse response = HttpRequest.post(url).body(JSON.toJSONString(body)).execute(); + Assert.isTrue(response.getStatus() == HttpServletResponse.SC_OK, () -> { + throw new ServiceException("远程调用大模型接口" + url + "失败!"); + }); + return JSONObject.parseObject(response.body(), typeRef); + } + +} diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/websocket/config/WebSocketConfig.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/websocket/config/WebSocketConfig.java index 04a4405..ed9a2a5 100644 --- a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/websocket/config/WebSocketConfig.java +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/websocket/config/WebSocketConfig.java @@ -18,7 +18,7 @@ public class WebSocketConfig implements WebSocketConfigurer { @Override public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) { - registry.addHandler(interactiveHandler(), "/interactive/{sessionId}").setAllowedOrigins("*"); + registry.addHandler(interactiveHandler(), "/websocket/interactive/{sessionId}").setAllowedOrigins("*"); } @Bean public WebSocketHandler interactiveHandler() { diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/websocket/constants/RedisKeyConstants.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/websocket/constants/RedisKeyConstants.java new file mode 100644 index 0000000..3cd0e30 --- /dev/null +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/websocket/constants/RedisKeyConstants.java @@ -0,0 +1,13 @@ +package com.hnac.hzims.bigmodel.websocket.constants; + +import com.hnac.hzims.common.constant.CommonConstant; + +/** + * @Author: huangxing + * @Date: 2024/05/20 19:11 + */ +public interface RedisKeyConstants { + + String SESSION_CONTENT_KEY = CommonConstant.TENANT_ID + ":hzims:bigModel:session:content"; + +} 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 cf4a92f..ba93fb4 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 @@ -1,28 +1,43 @@ package com.hnac.hzims.bigmodel.websocket.handler; import com.alibaba.fastjson.JSON; -import com.hnac.hzims.bigmodel.interactive.service.IInteractiveService; +import com.alibaba.fastjson.JSONObject; +import com.hnac.hzims.bigmodel.interactive.constants.FuncRouteEnum; +import com.hnac.hzims.bigmodel.interactive.factory.ResolveFactory; +import com.hnac.hzims.bigmodel.interactive.service.IHznlmInvokeService; +import com.hnac.hzims.bigmodel.interactive.service.IResolveService; +import com.hnac.hzims.bigmodel.interactive.vo.*; +import com.hnac.hzims.bigmodel.question.dto.MessageDTO; +import com.hnac.hzims.bigmodel.question.service.QuestionHandlerService; +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.extern.slf4j.Slf4j; -import org.springblade.core.log.exception.ServiceException; -import org.springblade.core.tool.api.R; +import org.springblade.core.tool.utils.Func; import org.springblade.core.tool.utils.SpringUtil; -import org.springframework.util.Assert; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.redis.core.RedisTemplate; +import org.springframework.stereotype.Component; import org.springframework.web.socket.CloseStatus; import org.springframework.web.socket.TextMessage; import org.springframework.web.socket.WebSocketSession; import org.springframework.web.socket.handler.TextWebSocketHandler; +import java.io.IOException; import java.util.Map; -import java.util.Optional; -import java.util.Set; +import java.util.concurrent.TimeUnit; /** * @Author: huangxing * @Date: 2024/04/28 13:45 */ @Slf4j +@Component public class InteractiveHandler extends TextWebSocketHandler { + + @Autowired + private RedisTemplate redisTemplate; + @Override public void afterConnectionEstablished(WebSocketSession session) { String[] split = session.getUri().toString().split("/"); @@ -46,8 +61,138 @@ public class InteractiveHandler extends TextWebSocketHandler { @Override protected void handleTextMessage(WebSocketSession session, TextMessage message) { - IInteractiveService interactiveService = SpringUtil.getBean(IInteractiveService.class); - R askResult = interactiveService.ask(message.getPayload(), InteractiveSessionManager.getEntryBySession(session).getKey()); - log.info("message handle successful!返回结果为:"+ JSON.toJSONString(askResult)); + MessageDTO messageDTO = JSONObject.parseObject(message.getPayload(), MessageDTO.class); + if("0".equals(messageDTO.getType())) { + // 接收心跳消息,返回一条心跳消息 + try { + session.sendMessage(InteractiveSessionManager.getTextMessage("0","收到心跳消息")); + } catch (IOException e) { + throw new RuntimeException(e); + } + } else { + String chatId = InteractiveSessionManager.getEntryBySession(session).getKey(); + messageDTO.setChatId(chatId); + // 将发送参数存入redis + if(Func.isNotEmpty(messageDTO.getContent())) { + redisTemplate.expire(RedisKeyConstants.SESSION_CONTENT_KEY,30, TimeUnit.MINUTES); + redisTemplate.opsForHash().put(RedisKeyConstants.SESSION_CONTENT_KEY,chatId,messageDTO.getContent()); + } + QuestionHandlerService service = SpringUtil.getBean(QuestionHandlerService.class); + service.handleMessage(messageDTO); + } +// JSONObject messageJSON = JSONObject.parseObject(message.getPayload()); +// if("0".equals(messageJSON.getString("type"))) { +// // 接收心跳消息,返回一条心跳消息 +// try { +// session.sendMessage(InteractiveSessionManager.getTextMessage("0","收到心跳消息")); +// } catch (IOException e) { +// throw new RuntimeException(e); +// } +// } else { +// String sessionId = InteractiveSessionManager.getEntryBySession(session).getKey(); +// if(messageJSON.containsKey("content")) { +// // 将发送参数存入redis +// redisTemplate.expire(RedisKeyConstants.SESSION_CONTENT_KEY,30, TimeUnit.MINUTES); +// redisTemplate.opsForHash().put(RedisKeyConstants.SESSION_CONTENT_KEY,sessionId,messageJSON.getObject("content", SessionContentVO.class)); +// } +// this.handleMessage(messageJSON, sessionId); +// } + } + + private void handleMessage(JSONObject messageContext, String sessionId) { + Boolean isSpecial = messageContext.getBoolean("isSpecial"); + if (Func.isEmpty(isSpecial) || !isSpecial) { + String context = messageContext.getString("context"); + String userId = messageContext.getString("userId"); + String knowledge = messageContext.getString("knowledge"); + IHznlmInvokeService hznlmInvokeService = SpringUtil.getBean(IHznlmInvokeService.class); + if (knowledge != null) { + hznlmInvokeService.knowledgeAsk(context, sessionId, userId, knowledge); + } else { + hznlmInvokeService.ask(context, sessionId, userId); + } + } + else { + String funcCode = messageContext.getString("func"); + FuncRouteEnum funcEnum = FuncRouteEnum.getEnumByFuncCode(funcCode); + switch (funcEnum) { + case CHOOSE_STATION: + case CHOOSE_YC: + case CHOOSE_FAULT: + case CHOOSE_YK: + this.handleDefaultChoose(messageContext,sessionId); + break; + case CHOOSE_VIDEO: + this.handleVideoChoose(messageContext,sessionId); + break; + case CHOOSE_CANVAS: + this.handleScadaChoose(messageContext,sessionId); + break; + default: + break; + } + } + } + + private void handleDefaultChoose(JSONObject messageContext,String sessionId) { + IHznlmInvokeService invokeService = SpringUtil.getBean(IHznlmInvokeService.class); + Map extra = messageContext.toJavaObject(Map.class); + extra.put("func",extra.get("func")); + extra.put("data",JSONObject.parseObject(JSON.toJSONString(extra.get("selection")))); + invokeService.specialAsk(sessionId, (String) extra.get("userId"),extra); + } + + private void handleVideoChoose(JSONObject messageContext,String sessionId) { + InteractiveWsService wsService = SpringUtil.getBean(InteractiveWsService.class); + try { + VideoSelectionVO selection = messageContext.getObject("selection", VideoSelectionVO.class); + IResolveService resolveService = ResolveFactory.getResolveService(FuncRouteEnum.OPEN_VIDEO.getFunc()); + String videoId = selection.getItemId(); + ExtraVO videoExtras = resolveService.resolve(videoId); + AnswerVO answerVO = new AnswerVO(); + answerVO.setSessionId(sessionId); + answerVO.setQuery(selection.getItemName()); + answerVO.setRunning(0); + answerVO.setStatus(0); + answerVO.setAnswer("已成功打开"+selection.getItemName()+"视频"); + answerVO.setExtras(new Object[]{JSON.toJSONString(videoExtras)}); + TextMessage textMessage = InteractiveSessionManager.getTextMessage("1", JSON.toJSONString(answerVO)); + wsService.sendMessage(sessionId,textMessage); + } + catch (Exception e) { + AnswerVO answerVO = new AnswerVO(); + answerVO.setRunning(0); + answerVO.setStatus(-2); + answerVO.setAnswer("视频解析失败!"); + TextMessage textMessage = InteractiveSessionManager.getTextMessage("1", JSON.toJSONString(answerVO)); + wsService.sendMessage(sessionId,textMessage); + } } + + private void handleScadaChoose(JSONObject messageContext,String sessionId) { + InteractiveWsService wsService = SpringUtil.getBean(InteractiveWsService.class); + try { + ScadaSelectionVO selection = messageContext.getObject("selection", ScadaSelectionVO.class); + IResolveService resolveService = ResolveFactory.getResolveService(FuncRouteEnum.OPEN_CANVAS.getFunc()); + ExtraVO scadaExtra = resolveService.resolve(selection.getItemId()); + AnswerVO answerVO = new AnswerVO(); + answerVO.setSessionId(sessionId); + answerVO.setRunning(0); + answerVO.setStatus(0); + answerVO.setQuery(selection.getItemName()); + answerVO.setAnswer("已成功打开"+selection.getItemName()+"实时画面"); + answerVO.setExtras(new Object[]{JSON.toJSONString(scadaExtra)}); + TextMessage textMessage = InteractiveSessionManager.getTextMessage("1", JSON.toJSONString(answerVO)); + wsService.sendMessage(sessionId,textMessage); + } + catch (Exception e) { + AnswerVO answerVO = new AnswerVO(); + answerVO.setRunning(0); + answerVO.setStatus(-2); + answerVO.setAnswer("实时画面解析失败!"); + TextMessage textMessage = InteractiveSessionManager.getTextMessage("1", JSON.toJSONString(answerVO)); + wsService.sendMessage(sessionId,textMessage); + } + } + } diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/websocket/service/InteractiveWsService.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/websocket/service/InteractiveWsService.java index c7cce27..c02fbab 100644 --- a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/websocket/service/InteractiveWsService.java +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/websocket/service/InteractiveWsService.java @@ -19,13 +19,24 @@ import java.io.IOException; public class InteractiveWsService implements WebSocketService { @Override - public Boolean sendMessage(String signage, TextMessage message) { - WebSocketSession session = InteractiveSessionManager.get(signage); + public Boolean sendMessage(String sessionId, TextMessage message) { + if(InteractiveSessionManager.SESSION_POOL.containsKey(sessionId)) { + WebSocketSession session = InteractiveSessionManager.get(sessionId); + return this.sendMessage(session,message); + } + else { + log.error("未查询到sessionId,消息推送失败;"); + return false; + } + } + + @Override + public Boolean sendMessage(WebSocketSession session, TextMessage message) { try { session.sendMessage(message); return true; } catch (IOException e) { - log.error("消息推送失败,推送sessionId为:" + signage + ";消息体为:" + JSON.toJSONString(message)); + log.error("消息推送失败;消息体为:" + JSON.toJSONString(message)); return false; } } diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/websocket/service/WebSocketService.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/websocket/service/WebSocketService.java index f4937ad..8729472 100644 --- a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/websocket/service/WebSocketService.java +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/websocket/service/WebSocketService.java @@ -1,6 +1,7 @@ package com.hnac.hzims.bigmodel.websocket.service; import org.springframework.web.socket.TextMessage; +import org.springframework.web.socket.WebSocketSession; /** * @Author: huangxing @@ -10,4 +11,6 @@ public interface WebSocketService { Boolean sendMessage(String signage, TextMessage message); + Boolean sendMessage(WebSocketSession session, TextMessage message); + } diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/websocket/sessionManager/InteractiveSessionManager.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/websocket/sessionManager/InteractiveSessionManager.java index 5e3d1a6..ea022cc 100644 --- a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/websocket/sessionManager/InteractiveSessionManager.java +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/websocket/sessionManager/InteractiveSessionManager.java @@ -1,7 +1,10 @@ package com.hnac.hzims.bigmodel.websocket.sessionManager; +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONObject; import lombok.extern.slf4j.Slf4j; import org.springblade.core.log.exception.ServiceException; +import org.springframework.web.socket.TextMessage; import org.springframework.web.socket.WebSocketSession; import java.io.IOException; @@ -23,8 +26,6 @@ public class InteractiveSessionManager { /** ws会话池 **/ public static ConcurrentHashMap SESSION_POOL = new ConcurrentHashMap<>(); - private static final Lock lock = new ReentrantLock(); - /** * 获取sessionIds * @return sessionIds @@ -42,7 +43,7 @@ public class InteractiveSessionManager { public static Map.Entry getEntryBySession(WebSocketSession session) { Set> sessionEntrySet = InteractiveSessionManager.SESSION_POOL.entrySet(); Optional> sessionIdOptional = sessionEntrySet.stream().filter(sessionEntry -> session.equals(sessionEntry.getValue())).findFirst(); - if(sessionIdOptional.isPresent()) { + if(!sessionIdOptional.isPresent()) { log.error("当前Session Pool未查询到相关session,消息推送失败"); throw new ServiceException("当前Session Pool未查询到相关session,消息推送失败"); } @@ -85,4 +86,11 @@ public class InteractiveSessionManager { } SESSION_POOL.remove(sessionId); } + + public static TextMessage getTextMessage(String type,String context) { + JSONObject message = new JSONObject(); + message.put("type",type); + message.put("context",context); + return new TextMessage(JSON.toJSONString(message)); + } } diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/whitelist/controller/WhitelistController.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/whitelist/controller/WhitelistController.java new file mode 100644 index 0000000..7c1d6d6 --- /dev/null +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/whitelist/controller/WhitelistController.java @@ -0,0 +1,38 @@ +package com.hnac.hzims.bigmodel.whitelist.controller; + +import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport; +import com.hnac.hzims.bigmodel.BigModelConstants; +import com.hnac.hzims.bigmodel.entity.WhitelistEntity; +import com.hnac.hzims.bigmodel.whitelist.service.WhitelistService; +import com.hnac.hzinfo.log.annotation.Business; +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import lombok.AllArgsConstructor; +import org.springblade.core.mp.support.Condition; +import org.springblade.core.tool.api.R; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import java.util.List; + +/** + * @author ysj + */ +@RestController +@RequestMapping("/whitelist") +@Api(value = "白名单用户",tags = "白名单用户") +@Business(module = BigModelConstants.MODULE_NAME,value = "大模型函数管理") +@AllArgsConstructor +public class WhitelistController { + + private final WhitelistService whitelistService; + + @PostMapping("/list") + @ApiOperation("查询列表") + @ApiOperationSupport(order = 1) + public R> list(@RequestBody WhitelistEntity entity) { + return R.data(whitelistService.list(Condition.getQueryWrapper(entity))); + } +} diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/whitelist/mapper/WhitelistMapper.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/whitelist/mapper/WhitelistMapper.java new file mode 100644 index 0000000..c1f87d2 --- /dev/null +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/whitelist/mapper/WhitelistMapper.java @@ -0,0 +1,11 @@ +package com.hnac.hzims.bigmodel.whitelist.mapper; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import com.hnac.hzims.bigmodel.entity.WhitelistEntity; + +/** + * @author ysj + */ +public interface WhitelistMapper extends BaseMapper { + +} \ No newline at end of file diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/whitelist/service/WhitelistService.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/whitelist/service/WhitelistService.java new file mode 100644 index 0000000..ceaf79e --- /dev/null +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/whitelist/service/WhitelistService.java @@ -0,0 +1,12 @@ +package com.hnac.hzims.bigmodel.whitelist.service; + +import com.hnac.hzims.bigmodel.entity.WhitelistEntity; +import org.springblade.core.mp.base.BaseService; + + +/** + * @author ysj + */ +public interface WhitelistService extends BaseService { + +} \ No newline at end of file diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/whitelist/service/impl/WhitelistServiceImpl.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/whitelist/service/impl/WhitelistServiceImpl.java new file mode 100644 index 0000000..b4b0cb3 --- /dev/null +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/whitelist/service/impl/WhitelistServiceImpl.java @@ -0,0 +1,18 @@ +package com.hnac.hzims.bigmodel.whitelist.service.impl; + +import com.hnac.hzims.bigmodel.entity.WhitelistEntity; +import com.hnac.hzims.bigmodel.whitelist.mapper.WhitelistMapper; +import com.hnac.hzims.bigmodel.whitelist.service.WhitelistService; +import lombok.extern.slf4j.Slf4j; +import org.springblade.core.mp.base.BaseServiceImpl; +import org.springframework.stereotype.Service; + +/** + * @Author: huangxing + * @Date: 2024/04/26 11:13 + */ +@Service +@Slf4j +public class WhitelistServiceImpl extends BaseServiceImpl implements WhitelistService { + +} \ No newline at end of file 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 diff --git a/hzims-service/hzims-big-model/src/main/resources/template/template.yml b/hzims-service/hzims-big-model/src/main/resources/template/template.yml deleted file mode 100644 index 447d972..0000000 --- a/hzims-service/hzims-big-model/src/main/resources/template/template.yml +++ /dev/null @@ -1,75 +0,0 @@ -#服务器端口 -server: - port: 8135 - -#oss配置 -oss: - endpoint: "${hzinfo.oss.endpoint}" - access-key: "${hzinfo.oss.access-key}" - secret-key: "${hzinfo.oss.secret-key}" - -#数据源配置 -spring: - #排除DruidDataSourceAutoConfigure - autoconfigure: - exclude: com.baomidou.dynamic.datasource.spring.boot.autoconfigure.DruidDataSourceAutoConfigure - datasource: - url: jdbc:mysql://${hzinfo.db.busines.ip}:${hzinfo.db.busines.port}/prod_hzims_big_model?useSSL=false&useUnicode=true&characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull&transformedBitIsBoolean=true&tinyInt1isBit=false&allowMultiQueries=true&serverTimezone=GMT%2B8&nullCatalogMeansCurrent=true&allowPublicKeyRetrieval=true - username: ${hzinfo.db.busines.username} - password: ${hzinfo.db.busines.password} - redis: - # redis数据库索引(默认为0),我们使用索引为0的数据库,避免和其他数据库冲突 - database: 2 - # redis服务器地址(默认为localhost) - host: 192.168.60.29 - # redis端口(默认为6379) - port: 3577 - # redis访问密码(默认为空) - password: 1qaz2WSX@redis - - -fdp: - host: http://192.168.60.16:9997 - url: - assistantAsk: /qa/assistant_ask - assistantStatus: /qa/assistant_status - askAbort: /qa/ask_abort - updateVideo: /kn/update_video - updateCanvas: /kn/update_canvas - updateFault: /kn/update_fault - assistantSpecialAsk: /qa/assistant_special_ask - assistantKnowledgeAsk: /qa/assistant_knowledge_ask - hotQuestion: /qa/question_recommand -xxl: - job: - accessToken: '' - admin: - addresses: http://192.168.60.29:7009/xxl-job-admin - executor: - appname: hzims-big-model - ip: 172.31.0.12 - logpath: /data/applogs/xxl-job/jobhandler - logretentiondays: 7 - port: 28135 - -blade: - data: - sdk: - enabled: true - url: http://192.168.60.29/api/hzinfo-data-config - ctrlUrl: http://192.168.60.29/api/hzinfo-data-handler - scadaUrl: http://192.168.60.29/api/hzinfo-data-scada - appId: '1635888805125099521' - appSecret: f4b6a4dc696b36445d2e5d38bbab2417 - redisIp: 192.168.60.34 - redisPort: 3577 - password: L_MM&h=+Nm&p)U9sk.uH - maxKeys: 1000 - data-scope: - enabled: false - lock: - enabled: true - address: redis://192.168.60.29:3577 - password: 1qaz2WSX@redis - database: 0 - ssl: false \ No newline at end of file diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/feign/StationClient.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/feign/StationClient.java index e9cf868..b2ca924 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/feign/StationClient.java +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/feign/StationClient.java @@ -14,6 +14,7 @@ import org.springblade.core.mp.support.Condition; import org.springblade.core.tool.api.R; import org.springblade.core.tool.utils.Func; import org.springblade.core.tool.utils.ObjectUtil; +import org.springblade.core.tool.utils.StringUtil; import org.springblade.system.user.entity.User; import org.springframework.beans.factory.annotation.Value; import org.springframework.web.bind.annotation.*; @@ -137,6 +138,18 @@ public class StationClient implements IStationClient { .in(StationEntity::getCode,codes))); } + @Override + @GetMapping("/getStationByTypeAndDuration") + public R> getStationByTypeAndDuration(@RequestParam(required = false) String startTime, + @RequestParam(required = false) String endTime, + @RequestParam(required = false) String type) { + LambdaQueryWrapper wrapper = Wrappers.lambdaQuery() + .eq(StringUtil.isNotBlank(type) && Func.isNotEmpty(type),StationEntity::getType, type) + .le(StringUtil.isNotBlank(endTime) && Func.isNotEmpty(endTime),StationEntity::getCreateTime, endTime) + .ge(StringUtil.isNotBlank(startTime) && Func.isNotEmpty(startTime),StationEntity::getCreateTime, startTime); + return R.data(stationService.list(wrapper)); + } + @Override @PostMapping("/getStationByCodeOrRedDept") diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/feign/StationVideoTypeClient.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/feign/StationVideoTypeClient.java index 68fbe08..cefe689 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/feign/StationVideoTypeClient.java +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/feign/StationVideoTypeClient.java @@ -1,18 +1,18 @@ package com.hnac.hzims.operational.station.feign; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.core.toolkit.Wrappers; +import com.hnac.hzims.common.support.utils.Condition; import com.hnac.hzims.operational.station.entity.StationVideoTypeEntity; import com.hnac.hzims.operational.station.service.IStationVideoTypeService; import lombok.AllArgsConstructor; - -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; +import org.springblade.core.tool.api.R; +import org.springframework.web.bind.annotation.*; import java.util.List; @RestController -@RequestMapping("/feign/station/videoType") @AllArgsConstructor public class StationVideoTypeClient implements IStationVideoTypeClient { @@ -20,11 +20,24 @@ public class StationVideoTypeClient implements IStationVideoTypeClient { @Override - @PostMapping("/listByStationId") + @PostMapping(LIST_BY_STATION_ID) public List listByStationId(String stationId) { List result = stationVideoTypeService.list(new LambdaQueryWrapper(){{ eq(StationVideoTypeEntity::getStationId,stationId); }}); return result; } + + @Override + @GetMapping(LIST) + public R> list(StationVideoTypeEntity req) { + QueryWrapper queryWrapper = Condition.getQueryWrapper(req); + return R.data(stationVideoTypeService.list(queryWrapper)); + } + + @Override + @GetMapping(GET_BY_ID) + public R getById(@RequestParam Long id) { + return R.data(stationVideoTypeService.getById(id,0)); + } }