Browse Source

fix:大模型代码架构修改

add:大模型数据源信息维护
zhongwei
haungxing 5 months ago
parent
commit
4600e74945
  1. 23
      hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/business/dto/ControlDeviceAuthDTO.java
  2. 35
      hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/business/feign/IAuthClient.java
  3. 36
      hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/interactive/dto/ControlDTO.java
  4. 38
      hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/interactive/dto/ControlDeviceDTO.java
  5. 15
      hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/interactive/req/ModelFunctionReq.java
  6. 6
      hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/interactive/vo/ExtraVO.java
  7. 51
      hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/business/feign/AuthClient.java
  8. 12
      hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/business/service/AuthenticationService.java
  9. 1
      hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/datasource/service/DataSourceService.java
  10. 5
      hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/constants/FuncRouteEnum.java
  11. 34
      hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/controller/AnalyseDataController.java
  12. 11
      hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/controller/FontEndInteractiveController.java
  13. 10
      hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/controller/HznlmInteractiveController.java
  14. 116
      hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/controller/InteractiveController.java
  15. 6
      hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/IHznlmInteractiveService.java
  16. 6
      hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/IHznlmInvokeService.java
  17. 15
      hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/IParamsService.java
  18. 13
      hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/AnalyseDataServiceImpl.java
  19. 14
      hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/CanvasResolveServiceImpl.java
  20. 259
      hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/ExtraResolveStrategyService.java
  21. 35
      hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/HznlmInteractiveServiceImpl.java
  22. 21
      hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/HznlmInvokeServiceImpl.java
  23. 430
      hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/InteractiveServiceImpl.java
  24. 46
      hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/JumpPageServiceImpl.java
  25. 3
      hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/JumpRouteJoinStrategy.java
  26. 2
      hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/ParamStrategy.java
  27. 36
      hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/ParamsServiceImpl.java
  28. 10
      hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/VideoResolveServiceImpl.java
  29. 67
      hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/maintenance/controller/DataSourceController.java
  30. 14
      hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/maintenance/controller/TableColumnController.java
  31. 66
      hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/maintenance/controller/TablePropertyController.java
  32. 33
      hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/maintenance/entity/DatasourceEntity.java
  33. 49
      hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/maintenance/entity/TablePropertyEntity.java
  34. 12
      hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/maintenance/mapper/DatasourceMapper.java
  35. 11
      hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/maintenance/mapper/TablePropertyMapper.java
  36. 19
      hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/maintenance/service/DataSourceService.java
  37. 18
      hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/maintenance/service/TableColumnService.java
  38. 20
      hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/maintenance/service/TablePropertyService.java
  39. 201
      hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/schedule/InteractiveSchedule.java
  40. 15
      hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/websocket/handler/InteractiveHandler.java
  41. 31
      hzims-service/hzims-big-model/src/main/resources/db/2.0.0.sql

23
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;
}

35
hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/business/feign/IAuthClient.java

@ -0,0 +1,35 @@
package com.hnac.hzims.bigmodel.business.feign;
import com.hnac.hzims.bigmodel.business.dto.ControlDeviceAuthDTO;
import org.springblade.core.tool.api.R;
/**
* @Author: huangxing
* @Date: 2024/07/09 09:11
* 鉴权接口 - 业务实现
*/
public interface IAuthClient {
/**
* 遥控鉴权
* @param req 遥控信息
* @return 鉴权结果
*/
R remoteAuth(ControlDeviceAuthDTO req);
/**
* 站点鉴权
* @param userId 用户ID
* @param stationId 站点ID
* @return 鉴权结果
*/
R stationAuth(String userId,String stationId);
/**
* 机构鉴权
* @param userId 用户ID
* @param deptId 站点ID
* @return 鉴权结果
*/
R deptAuth(String userId,String deptId);
}

36
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<ControlDeviceDTO> yks;
}

38
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;
}

15
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<String,String> functionArgs;
private Map<String,String> item;
}

6
hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/interactive/vo/ExtraVO.java

@ -1,6 +1,8 @@
package com.hnac.hzims.bigmodel.interactive.vo;
import com.alibaba.fastjson.annotation.JSONField;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonInclude;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
@ -21,9 +23,11 @@ public class ExtraVO implements Serializable {
private String type;
@ApiModelProperty("若为弹窗,则返回路由")
@JsonInclude(JsonInclude.Include.NON_NULL)
private String route;
@ApiModelProperty("链接显示文字")
@JsonInclude(JsonInclude.Include.NON_NULL)
private String label;
@ApiModelProperty("函数编号")
@ -33,12 +37,14 @@ public class ExtraVO implements Serializable {
private boolean isImmediatelyJump = false;
@ApiModelProperty("附带参数")
@JsonInclude(JsonInclude.Include.NON_NULL)
private Map<String,Object> params;
@ApiModelProperty("是否为特殊函数")
private boolean isSpecial;
@ApiModelProperty("选项")
@JsonInclude(JsonInclude.Include.NON_NULL)
private List selection;
@JSONField(name = "agent_name")

51
hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/business/feign/AuthClient.java

@ -0,0 +1,51 @@
package com.hnac.hzims.bigmodel.business.feign;
import com.hnac.hzims.bigmodel.business.dto.ControlDeviceAuthDTO;
import com.hnac.hzims.bigmodel.business.service.AuthenticationService;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springblade.core.tool.api.R;
import org.springblade.core.tool.utils.StringUtil;
import org.springblade.system.dto.DeptStationDTO;
import org.springframework.stereotype.Component;
import java.util.List;
import java.util.Optional;
/**
* @Author: huangxing
* @Date: 2024/07/09 09:31
*/
@Component
@AllArgsConstructor
@Slf4j
public class AuthClient implements IAuthClient {
private final AuthenticationService authenticationService;
@Override
public R remoteAuth(ControlDeviceAuthDTO req) {
// 若站点不为空 则对站点进行鉴权
if(StringUtil.isNotBlank(req.getStationId())) {
if(!authenticationService.stationAuthentication(req.getStationId(), req.getUserId())) {
return R.fail("站点鉴权失败!");
}
}
if("业务".equals(req.getType())) {
}
return R.success("鉴权成功");
}
@Override
public R stationAuth(String userId, String stationId) {
return R.status(authenticationService.stationAuthentication(stationId,userId));
}
@Override
public R deptAuth(String userId, String deptId) {
List<DeptStationDTO> deptStationDTOList = authenticationService.getStationPermissionsById(userId);
boolean result = deptStationDTOList.stream().map(DeptStationDTO::getDeptId).anyMatch(d -> Long.valueOf(deptId).equals(d));
return R.status(result);
}
}

12
hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/AuthenticationService.java → hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/business/service/AuthenticationService.java

@ -1,4 +1,4 @@
package com.hnac.hzims.bigmodel.interactive.service.impl;
package com.hnac.hzims.bigmodel.business.service;
import com.google.common.collect.Lists;
import com.hnac.hzims.bigmodel.entity.FunctionEntity;
@ -48,12 +48,9 @@ public class AuthenticationService {
* @param stationId 站点ID
* @param userId 用户ID
*/
public void stationAuthentication(String stationId, String userId) {
List<String> stations = this.getStationPermissionsById(userId).stream().map(DeptStationDTO::getStationId)
.filter(StringUtil::isNotBlank).filter(Func::isNotEmpty).collect(Collectors.toList());
Assert.isTrue(stations.contains(stationId),() -> {
throw new ServiceException("人员站点鉴权失败!");
});
public Boolean stationAuthentication(String stationId, String userId) {
List<DeptStationDTO> deptStationDTOList = this.getStationPermissionsById(userId);
return deptStationDTOList.stream().map(DeptStationDTO::getStationId).anyMatch(s -> stationId.equals(s));
}
/**
@ -114,7 +111,6 @@ public class AuthenticationService {
});
}
}
}
public List<DeptStationDTO> getStationPermissionsById(String userId) {

1
hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/datasource/service/DataSourceService.java

@ -49,6 +49,7 @@ public class DataSourceService {
String tableSubStr = "(SELECT * FROM " + tableAuthVO.getTableName() + " where" + userAuthDataSQL +") temp";
sql = sql.replace(tableAuthVO.getTableName(),tableSubStr);
}
log.info("执行sql:{}",sql);
return this.queryListOnSpecificDataSource(sql, sqlVO.getTableAuthVOList().get(0).getDatasourceName());
// 过滤更新、删除语句
// Assert.isTrue(!DataSourceService.isUpdateOrDelete(sqlVO.getSql()),() -> {

5
hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/constants/FuncRouteEnum.java

@ -24,16 +24,17 @@ public enum FuncRouteEnum {
SHOW_PARAM("result_record","设备参数查询", FunctionConstants.TypeEnum.PARAMS),
CHOOSE_YC("choose_yc","选择遥测数据",FunctionConstants.TypeEnum.CHOOSE),
HISTORY_DATA("history_data","查询历史数据",FunctionConstants.TypeEnum.CHART),
CONTROL_DEVICE("control_device","设备控制",FunctionConstants.TypeEnum.PARAMS)
;
@Getter
private String funcCode;
private String func;
@Getter
private String funcName;
@Getter
private FunctionConstants.TypeEnum type;
public static FuncRouteEnum getEnumByFuncCode(String funcCode) {
Optional<FuncRouteEnum> FuncRoute = Arrays.stream(FuncRouteEnum.class.getEnumConstants()).filter(e -> funcCode.equals(e.getFuncCode())).findFirst();
Optional<FuncRouteEnum> FuncRoute = Arrays.stream(FuncRouteEnum.class.getEnumConstants()).filter(e -> funcCode.equals(e.getFunc())).findFirst();
return FuncRoute.orElse(null);
}

34
hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/controller/AnalyseDataController.java

@ -1,34 +0,0 @@
package com.hnac.hzims.bigmodel.interactive.controller;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.hnac.hzims.bigmodel.interactive.service.IAnalyseDataService;
import com.hnac.hzims.bigmodel.interactive.vo.HistoryDataSearchVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springblade.core.tool.api.R;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
* @Author: huangxing
* @Date: 2024/05/29 09:22
*/
@RequestMapping("/analyse/data")
@AllArgsConstructor
@Api(value = "数据查询管理",tags = "数据查询管理")
@RestController
@Deprecated
public class AnalyseDataController {
private final IAnalyseDataService analyseDataService;
@GetMapping("/getHistoryData")
@ApiOperation("获取历史数据")
@ApiOperationSupport(order = 1)
public R getHistoryData(@Validated HistoryDataSearchVO searchVO) {
return R.data(analyseDataService.getHistoryData(searchVO));
}
}

11
hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/controller/FontEndInteractiveController.java

@ -10,6 +10,7 @@ import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.AllArgsConstructor;
import org.springblade.core.tool.api.IResultCode;
import org.springblade.core.tool.api.R;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
@ -50,7 +51,7 @@ public class FontEndInteractiveController {
@ApiOperation("获取热点问题")
@ApiOperationSupport(order = 3)
@GetMapping("/hotQuestions")
public R<List<String>> hotQuestions() {
public R<List> hotQuestions() {
return R.data(hznlmInvokeService.hotQuestions());
}
@ -60,4 +61,12 @@ public class FontEndInteractiveController {
public R<String> 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("操作成功!");
}
}

10
hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/controller/HznlmInteractiveController.java

@ -5,6 +5,7 @@ import com.hnac.hzims.bigmodel.BigModelConstants;
import com.hnac.hzims.bigmodel.datasource.service.DataSourceService;
import com.hnac.hzims.bigmodel.datasource.vo.SqlVO;
import com.hnac.hzims.bigmodel.interactive.dto.AuthDataDTO;
import com.hnac.hzims.bigmodel.interactive.dto.ControlDTO;
import com.hnac.hzims.bigmodel.interactive.req.ModelFunctionReq;
import com.hnac.hzims.bigmodel.interactive.service.IHznlmInteractiveService;
import com.hnac.hzims.bigmodel.interactive.vo.AuthDataVO;
@ -51,8 +52,15 @@ public class HznlmInteractiveController {
@PostMapping("/execute_query")
@ApiOperation("执行大模型sql")
@ApiOperationSupport(order = 1)
@ApiOperationSupport(order = 3)
public R<List<Map<String, Object>>> executeQuery(@RequestBody @Valid SqlVO sqlVO) {
return R.data(dataSourceService.queryListOnSpecificDataSource(sqlVO));
}
@PostMapping("/control_device")
@ApiOperation("控制设备")
@ApiOperationSupport(order = 4)
public R<ExtraVO> controlDevice(@RequestBody @Valid ControlDTO req) {
return R.data(interactiveService.controlDevice(req));
}
}

116
hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/controller/InteractiveController.java

@ -1,116 +0,0 @@
package com.hnac.hzims.bigmodel.interactive.controller;
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.google.common.collect.Lists;
import com.hnac.hzims.bigmodel.BigModelConstants;
import com.hnac.hzims.bigmodel.interactive.req.ModelFunctionReq;
import com.hnac.hzims.bigmodel.interactive.service.IInteractiveService;
import com.hnac.hzims.bigmodel.interactive.vo.StationSearchVO;
import com.hnac.hzinfo.log.annotation.Business;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.AllArgsConstructor;
import org.springblade.core.tool.api.R;
import org.springblade.system.dto.ControlDTO;
import org.springframework.web.bind.annotation.*;
import java.text.DecimalFormat;
import java.util.List;
/**
* @Author: huangxing
* @Date: 2024/04/26 14:51
*/
@RestController
@AllArgsConstructor
@Api(value = "FDP大模型交互层",tags = "FDP大模型交互层")
@RequestMapping("/interactive")
@Business(module = BigModelConstants.MODULE_NAME,value = "FDP大模型交互层")
@Deprecated
public class InteractiveController {
private final IInteractiveService interactiveService;
@ApiOperation("解析大模型函数")
@ApiOperationSupport(order = 1)
@PostMapping("/resolve")
public R resolve(@RequestBody ModelFunctionReq req) {
return interactiveService.resolve(req);
}
@ApiOperation("提问")
@ApiOperationSupport(order = 2)
@GetMapping("/ask")
@Deprecated
public R ask(@RequestParam @ApiParam("用户提出问题") String question,@RequestParam @ApiParam("问答sessionId") String sessionId,@RequestParam @ApiParam("用户Id") String userId) {
return interactiveService.ask(question, sessionId, userId);
}
@ApiOperation("站点、菜单鉴权")
@ApiOperationSupport(order = 3)
@Deprecated
@RequestMapping(value = "/authentication",method = {RequestMethod.GET,RequestMethod.POST})
public R authentication(@RequestParam(required = false) @ApiParam("站点编号") String stationId,
@RequestParam @ApiParam("用户ID") String userId,
@RequestParam(required = false) @ApiParam("菜单ID") String func,
@RequestParam(required = false) @ApiParam("会话ID")String askId) {
return R.status(interactiveService.authentication(stationId,userId,func,askId));
}
@ApiOperation("获取问答sessionId")
@ApiOperationSupport(order = 4)
@GetMapping("/getSessionId")
public R<String> getSessionId() {
return R.data(IdWorker.get32UUID());
}
@ApiOperation("删除对话sessionId")
@ApiOperationSupport(order = 5)
@GetMapping("/removeSessionId")
@Deprecated
public R<Boolean> removeSessionId(@RequestParam(value = "id") String sessionId) {
return R.data(interactiveService.removeSessionId(sessionId));
}
@ApiOperation("下发遥控指令")
@ApiOperationSupport(order = 6)
@PostMapping("/sendRemoteControl")
public R sendRemoteControl(@RequestBody ControlDTO operate) {
return interactiveService.sendRemoteControl(operate);
}
@ApiOperation("解析接入站点数量")
@ApiOperationSupport(order = 7)
@PostMapping("/resolveStations")
public R resolveStations(@RequestBody StationSearchVO req) {
return R.data(interactiveService.resolveStations(req.getStartTime(),req.getEndTime(),req.getType(),req.getEnumType()));
}
@ApiOperation("站点发电量")
@ApiOperationSupport(order = 7)
@RequestMapping(value = "/generation",method = {RequestMethod.GET,RequestMethod.POST})
public R generation(@RequestParam @ApiParam("站点编号") String stationId,
@RequestParam @ApiParam("开始时间") String startTime,
@RequestParam @ApiParam("结束时间")String endTime) {
double generate = interactiveService.generation(stationId,startTime,endTime);
DecimalFormat format = new DecimalFormat("0.00");
return R.data(format.format(generate) + "kWh");
}
@ApiOperation("获取热点问题")
@ApiOperationSupport(order = 8)
@GetMapping("/hotQuestions")
@Deprecated
public R hotQuestions() {
try{
List questions = interactiveService.hotQuestions();
return R.data(questions);
}
catch (Exception e) {
e.printStackTrace();
return R.data(Lists.newArrayList());
}
}
}

6
hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/IHznlmInteractiveService.java

@ -1,6 +1,7 @@
package com.hnac.hzims.bigmodel.interactive.service;
import com.hnac.hzims.bigmodel.interactive.dto.AuthDataDTO;
import com.hnac.hzims.bigmodel.interactive.dto.ControlDTO;
import com.hnac.hzims.bigmodel.interactive.req.ModelFunctionReq;
import com.hnac.hzims.bigmodel.interactive.vo.AuthDataVO;
import com.hnac.hzims.bigmodel.interactive.vo.ExtraVO;
@ -16,7 +17,10 @@ import java.util.List;
*/
public interface IHznlmInteractiveService {
List<AuthDataVO> getAuthData(@RequestBody @Valid AuthDataDTO req);
List<AuthDataVO> getAuthData(AuthDataDTO req);
ExtraVO resolve(ModelFunctionReq req);
ExtraVO controlDevice(ControlDTO req);
}

6
hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/IHznlmInvokeService.java

@ -58,6 +58,10 @@ public interface IHznlmInvokeService {
*/
List<AnswerVO> getAnswerBySessionIds(String sessionIds);
/**
* 中断当前的问答
* @param sessionId 会话ID
*/
void askAbort(String sessionId);
}

15
hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/IParamsService.java

@ -1,15 +0,0 @@
package com.hnac.hzims.bigmodel.interactive.service;
import com.hnac.hzims.bigmodel.entity.FunctionEntity;
import java.util.Map;
/**
* @Author: huangxing
* @Date: 2024/05/09 08:50
*/
@Deprecated
public interface IParamsService {
String dealJumpTypeFunction(FunctionEntity function, Map<String,String> args);
}

13
hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/AnalyseDataServiceImpl.java

@ -1,6 +1,5 @@
package com.hnac.hzims.bigmodel.interactive.service.impl;
import com.alibaba.fastjson.JSON;
import com.google.common.collect.Lists;
import com.hnac.hzims.bigmodel.data.service.HistoryDataService;
import com.hnac.hzims.bigmodel.interactive.constants.DataMethodEnum;
@ -10,23 +9,13 @@ import com.hnac.hzims.bigmodel.interactive.service.IAnalyseDataService;
import com.hnac.hzims.bigmodel.interactive.vo.ExtraVO;
import com.hnac.hzims.bigmodel.interactive.vo.HistoryDataSearchVO;
import com.hnac.hzinfo.sdk.core.response.Result;
import com.hnac.hzinfo.sdk.v5.device.DeviceDataClient;
import com.hnac.hzinfo.sdk.v5.device.dto.ReductionAttrDataDTO;
import com.hnac.hzinfo.sdk.v5.device.dto.ReductionDataDTO;
import com.hnac.hzinfo.sdk.v5.device.vo.ReductionDataVO;
import lombok.AllArgsConstructor;
import org.springblade.core.log.exception.ServiceException;
import org.springblade.core.log.logger.BladeLogger;
import org.springblade.core.tool.utils.CollectionUtil;
import org.springblade.core.tool.utils.DateUtil;
import org.springblade.core.tool.utils.Func;
import org.springblade.core.tool.utils.StringUtil;
import org.springframework.stereotype.Service;
import org.springframework.util.Assert;
import java.time.Duration;
import java.time.LocalDateTime;
import java.time.temporal.ChronoUnit;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@ -57,7 +46,7 @@ public class AnalyseDataServiceImpl implements IAnalyseDataService {
searchVO.setDataType(adapterDate.getDateType());
ExtraVO extraVO = new ExtraVO();
extraVO.setType(FuncRouteEnum.HISTORY_DATA.getType().getType());
extraVO.setFunc(FuncRouteEnum.HISTORY_DATA.getFuncCode());
extraVO.setFunc(FuncRouteEnum.HISTORY_DATA.getFunc());
Map<String,Object> params = new HashMap<>(1);
Result<ReductionDataVO> reductionDataVOR = historyDataService.getPolymerizationData(searchVO);
String label;

14
hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/CanvasResolveServiceImpl.java

@ -7,13 +7,10 @@ import com.hnac.hzims.bigmodel.interactive.factory.ResolveFactory;
import com.hnac.hzims.bigmodel.interactive.req.ModelFunctionReq;
import com.hnac.hzims.bigmodel.interactive.service.IResolveService;
import com.hnac.hzims.bigmodel.interactive.vo.ExtraVO;
import com.hnac.hzims.bigmodel.interactive.vo.ResolveResultVO;
import com.hnac.hzims.operational.station.entity.StationEntity;
import com.hnac.hzims.operational.station.feign.IStationClient;
import com.hnac.hzinfo.sdk.v5.scada.ScadaClient;
import groovy.util.logging.Slf4j;
import lombok.AllArgsConstructor;
import lombok.RequiredArgsConstructor;
import org.springblade.core.log.exception.ServiceException;
import org.springblade.core.log.logger.BladeLogger;
import org.springblade.core.tool.api.R;
@ -40,24 +37,21 @@ public class CanvasResolveServiceImpl implements IResolveService {
@Override
public ExtraVO resolve(ModelFunctionReq req) {
Map<String, String> args = req.getFunctionArgs();
String id = args.get("id");
String name = args.get("name");
Map<String, String> args = req.getItem();
String id = args.get("itemId");
String name = args.get("itemName");
Assert.isTrue(StringUtil.isNotBlank(id) && StringUtil.isNotBlank(name),() -> {
logger.error("hzims:video:resolve","解析传参错误,缺少必要参数video_id,传参内容为:" + JSON.toJSONString(req));
throw new ServiceException("解析传参错误,缺少必要参数video_id");
});
return this.resolve(id);
// ExtraVO extra = this.resolve(id);
// String message = "已成功打开" + name + ";";
// return new ResolveResultVO(message,extra);
}
@Override
public ExtraVO resolve(String id) {
ExtraVO extraVO = new ExtraVO();
extraVO.setImmediatelyJump(true);
extraVO.setFunc(FuncRouteEnum.OPEN_CANVAS.getFuncCode());
extraVO.setFunc(FuncRouteEnum.OPEN_CANVAS.getFunc());
final String[] SCADA_PARAMS_SOLVE = new String[]{"picResource","context","stationNum","projectId","taskId","name","id"};
String canvasHost = ParamCache.getValue(ParamKeyConstants.CANVAS_HOST);
// 将ID解析为

259
hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/ExtraResolveStrategyService.java

@ -1,259 +0,0 @@
package com.hnac.hzims.bigmodel.interactive.service.impl;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.hnac.hzims.bigmodel.interactive.constants.FuncRouteEnum;
import com.hnac.hzims.bigmodel.interactive.constants.FunctionConstants;
import com.hnac.hzims.bigmodel.interactive.constants.SearchTypeEnum;
import com.hnac.hzims.bigmodel.interactive.service.IAnalyseDataService;
import com.hnac.hzims.bigmodel.interactive.vo.*;
import com.hnac.hzims.operational.station.entity.StationVideoTypeEntity;
import com.hnac.hzims.operational.station.feign.IStationClient;
import com.hnac.hzims.operational.station.feign.IStationVideoTypeClient;
import com.hnac.hzinfo.sdk.v5.device.client.DeviceClient;
import com.hnac.hzinfo.sdk.v5.device.vo.DeviceInstanceFuncVO;
import com.xxl.job.core.log.XxlJobLogger;
import lombok.AllArgsConstructor;
import org.springblade.core.tool.api.R;
import org.springblade.core.tool.utils.*;
import org.springframework.stereotype.Service;
import java.time.format.DateTimeFormatter;
import java.util.*;
import java.util.stream.Collectors;
/**
* @Author: huangxing
* @Date: 2024/05/08 16:19
*/
@Service
@AllArgsConstructor
@Deprecated
public class ExtraResolveStrategyService {
public static final String PATTERN_DATETIME = "yyyy-MM-dd HH:mm:ss.SSS";
public static final DateTimeFormatter formatter = DateTimeFormatter.ofPattern(PATTERN_DATETIME);
private final IStationClient stationClient;
private final IStationVideoTypeClient videoTypeClient;
private final JumpRouteJoinStrategy jumpRouteJoinStrategy;
private final DeviceClient deviceClient;
private final IAnalyseDataService analyseDataService;
/**
* 解析DFP返回extra
* @param extraStr DFP返回extra
* @return 与前端交互extra
*/
public ExtraVO resolve(String extraStr) {
JSONObject extra = JSONObject.parseObject(extraStr);
String functionCode = Optional.ofNullable(extra.get("func")).map(String::valueOf).orElse("");
if(StringUtil.isNotBlank(functionCode)) {
XxlJobLogger.log("函数编号为:" + functionCode);
FuncRouteEnum funcRouteEnum = FuncRouteEnum.getEnumByFuncCode(functionCode);
if(Func.isNotEmpty(funcRouteEnum)) {
switch (funcRouteEnum) {
case DIAGNOSE:
return this.resolveDiagnose(extra);
case CHOOSE_VIDEO:
case CHOOSE_CANVAS:
case CHOOSE_STATION:
case CHOOSE_FAULT:
case CHOOSE_YC:
case CHOOSE_YK:
return this.resolveChooseSelection(extra,funcRouteEnum);
case CONFIRM_YK:
return this.resolveConfirmRemote(extra);
case SHOW_PARAM:
return this.resolveShowParam(extra);
default:
break;
}
}
}
else if(extra.containsKey("extra")){
return extra.getObject("extra",ExtraVO.class);
}
return JSONObject.parseObject(JSON.toJSONString(extra),ExtraVO.class);
}
private ExtraVO resolveChooseSelection(JSONObject extra,FuncRouteEnum funcRouteEnum) {
ExtraVO result = new ExtraVO();
JSONArray selections = JSONArray.parseArray(JSON.toJSONString(extra.get("data")));
result.setFunc(funcRouteEnum.getFuncCode());
result.setSpecial(true);
result.setSelection(selections);
result.setType(funcRouteEnum.getType().getType());
return result;
}
// private ExtraVO resolveChooseYc(JSONObject extra) {
// ExtraVO result = new ExtraVO();
// JSONObject data = JSONObject.parseObject(JSON.toJSONString(extra.get("data")));
// if(data.containsKey("yks")) {
//
//
// List<AttrSelectionVO> attrs = JSONArray.parseArray(JSON.toJSONString(data.get("yks")), AttrSelectionVO.class);
// result.setSelection(attrs);
// }
// result.setFuncCode(FuncRouteEnum.CHOOSE_YC.getFuncCode());
// result.setSpecial(true);
// result.setType(FuncRouteEnum.CHOOSE_YC.getType().getType());
// return result;
// }
private ExtraVO resolveShowParam(Map<String,Object> extra) {
DataVO data = JSONObject.parseObject(JSON.toJSONString(extra.get("data")),DataVO.class);
if(Func.isNotEmpty(data)) {
if(Func.isNotEmpty(data.getReal())) {
if(Func.isNotEmpty(data.getReal().getTime()) && StringUtil.isNotBlank(data.getReal().getTime())) {
RealDataVO real = data.getReal();
Date date = DateUtil.parse(real.getTime(), PATTERN_DATETIME);
real.setTime(DateUtil.format(date,DateUtil.PATTERN_DATETIME));
}
}
if(Func.isNotEmpty(data.getItem()) && StringUtil.isNotBlank(data.getMethod())) {
if(SearchTypeEnum.HISTORY.getSearchType().equals(data.getType()) && Func.isNotEmpty(data.getItem())) {
DataItemVO item = data.getItem();
HistoryDataSearchVO searchVO = new HistoryDataSearchVO();
searchVO.setDataType(data.getDataType());
searchVO.setAttrName(item.getAttrName());
searchVO.setDeviceCode(item.getDeviceId());
searchVO.setDeviceName(item.getDeviceName());
searchVO.setStationName(item.getProjectName());
searchVO.setMethod(data.getMethod());
searchVO.setSignage(item.getSignage());
searchVO.setStartTime(data.getStartTime());
searchVO.setEndTime(data.getEndTime());
return analyseDataService.getHistoryData(searchVO);
}
}
}
ExtraVO result = new ExtraVO();
result.setFunc(FuncRouteEnum.SHOW_PARAM.getFuncCode());
result.setType(FuncRouteEnum.SHOW_PARAM.getType().getType());
Map<String,Object> param = new HashMap(1);
param.put("data", data);
result.setParams(param);
return result;
}
@Deprecated
private ExtraVO resolveConfirmRemote(Map<String,Object> extra) {
ExtraVO result = new ExtraVO();
RemoteParamVO remoteParam = JSONObject.parseObject(JSON.toJSONString(extra.get("data")), RemoteParamVO.class);
result.setFunc(FuncRouteEnum.CONFIRM_YK.getFuncCode());
result.setType(FuncRouteEnum.CONFIRM_YK.getType().getType());
R<DeviceInstanceFuncVO> funcVOR = deviceClient.getFuncById(remoteParam.getFuncId());
if(funcVOR.isSuccess()) {
Map<String,Object> param = new HashMap();
param.put("control",funcVOR.getData());
param.put("deviceName",remoteParam.getDeviceName());
param.put("projectName",remoteParam.getProjectName());
param.put("deviceCode",remoteParam.getDeviceId());
param.put("value",remoteParam.getValue());
result.setParams(param);
}
return result;
}
// private ExtraVO resolveChooseFault(Map<String,Object> extra) {
// ExtraVO result = new ExtraVO();
// JSONObject data = JSONObject.parseObject(JSON.toJSONString(extra.get("data")));
// if(data.containsKey("faults")) {
// List<FaultSelectionVO> faults = JSONArray.parseArray(JSON.toJSONString(data.get("faults")), FaultSelectionVO.class);
// result.setSelection(faults);
// }
// result.setFuncCode(FuncRouteEnum.CHOOSE_FAULT.getFuncCode());
// result.setSpecial(true);
// result.setType(FunctionConstants.TypeEnum.CHOOSE.getType());
// return result;
// }
private ExtraVO resolveDiagnose(Map<String,Object> extra) {
ExtraVO result = new ExtraVO();
JSONObject data = JSONObject.parseObject(JSON.toJSONString(extra.get("data")));
Map<String,Object> params = new HashMap<>(5);
params.put("faultId",data.getString("fault_id"));
params.put("name",data.getString("fault_name"));
params.put("station",data.getString("station_id"));
params.put("fdpDeviceName",data.getString("device_name"));
params.put("fdpOrd",data.getString("ord"));
result.setParams(params);
result.setFunc(FuncRouteEnum.DIAGNOSE.getFuncCode());
result.setType(FunctionConstants.TypeEnum.PARAMS.getType());
return result;
}
/**
*
* @param extra
* @return
*/
// private ExtraVO resolveChooseStation(Map<String,Object> extra) {
// ExtraVO result = new ExtraVO();
// JSONObject data = JSONObject.parseObject(JSON.toJSONString(extra.get("data")));
// if(data.containsKey("stations")) {
// List<String> stations = JSONArray.parseArray(JSON.toJSONString(data.get("stations")), String.class);
// List<StationSelectionVO> selectionList = stations.stream().map(stationId -> {
// StationSelectionVO selectionVO = new StationSelectionVO();
// R<StationEntity> stationR = stationClient.getStationByCode(stationId);
// if (stationR.isSuccess() && Func.isNotEmpty(stationR.getData())) {
// selectionVO.setId(stationId);
// selectionVO.setName(stationR.getData().getName());
// }
// return selectionVO;
// }).collect(Collectors.toList());
// result.setSelection(selectionList);
// result.setFuncCode(FuncRouteEnum.CHOOSE_STATION.getFuncCode());
// result.setSpecial(true);
// result.setType(FunctionConstants.TypeEnum.CHOOSE.getType());
// }
// result.setType(FunctionConstants.TypeEnum.CHOOSE.getType());
// return result;
// }
private ExtraVO resolveChooseVideo(Map<String,Object> extra) {
ExtraVO result = new ExtraVO();
JSONObject data = JSONObject.parseObject(JSON.toJSONString(extra.get("data")));
if(data.containsKey("videos")) {
List<JSONObject> videoIds = JSONArray.parseArray(JSON.toJSONString(data.get("videos")), JSONObject.class);
List<VideoSelectionVO> selections = videoIds.stream().map(video -> {
R<StationVideoTypeEntity> videoR = videoTypeClient.getById(Long.valueOf(video.getString("id")));
VideoSelectionVO selectionVO = new VideoSelectionVO();
if (videoR.isSuccess() && Func.isNotEmpty(videoR.getData())) {
selectionVO.setId(video.getString("id"));
selectionVO.setName(videoR.getData().getName());
}
return selectionVO;
}).collect(Collectors.toList());
result.setFunc(FuncRouteEnum.CHOOSE_VIDEO.getFuncCode());
result.setSpecial(true);
result.setSelection(selections);
}
result.setType(FunctionConstants.TypeEnum.CHOOSE.getType());
return result;
}
private ExtraVO resolveChooseScada(Map<String,Object> extra) {
ExtraVO result = new ExtraVO();
JSONObject data = JSONObject.parseObject(JSON.toJSONString(extra.get("data")));
if(data.containsKey("canvases")) {
List<JSONObject> canvases = JSONArray.parseArray(JSON.toJSONString(data.get("canvases")), JSONObject.class);
List<ScadaSelectionVO> selections = canvases.stream().map(canvas -> {
ScadaSelectionVO selectionVO = new ScadaSelectionVO();
Map<String, String> resolve = jumpRouteJoinStrategy.resolve(canvas.getString("id"), JumpRouteJoinStrategy.SCADA_PARAMS_SOLVE);
selectionVO.setId(canvas.getString("id"));
selectionVO.setName(resolve.get("name"));
return selectionVO;
}).collect(Collectors.toList());
result.setFunc(FuncRouteEnum.CHOOSE_CANVAS.getFuncCode());
result.setSpecial(true);
result.setSelection(selections);
}
result.setType(FunctionConstants.TypeEnum.CHOOSE.getType());
return result;
}
}

35
hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/HznlmInteractiveServiceImpl.java

@ -1,22 +1,32 @@
package com.hnac.hzims.bigmodel.interactive.service.impl;
import com.hnac.hzims.bigmodel.business.dto.ControlDeviceAuthDTO;
import com.hnac.hzims.bigmodel.business.feign.IAuthClient;
import com.hnac.hzims.bigmodel.business.service.AuthenticationService;
import com.hnac.hzims.bigmodel.interactive.constants.DataAuthTypeEnum;
import com.hnac.hzims.bigmodel.interactive.constants.FuncRouteEnum;
import com.hnac.hzims.bigmodel.interactive.dto.AuthDataDTO;
import com.hnac.hzims.bigmodel.interactive.dto.ControlDTO;
import com.hnac.hzims.bigmodel.interactive.factory.ResolveFactory;
import com.hnac.hzims.bigmodel.interactive.req.ModelFunctionReq;
import com.hnac.hzims.bigmodel.interactive.service.IHznlmInteractiveService;
import com.hnac.hzims.bigmodel.interactive.service.IResolveService;
import com.hnac.hzims.bigmodel.interactive.vo.AuthDataVO;
import com.hnac.hzims.bigmodel.interactive.vo.ExtraVO;
import com.hnac.hzims.bigmodel.interactive.vo.ResolveResultVO;
import groovy.util.logging.Slf4j;
import lombok.AllArgsConstructor;
import org.springblade.core.log.exception.ServiceException;
import org.springblade.core.tool.utils.BeanUtil;
import org.springblade.core.tool.utils.DateUtil;
import org.springblade.core.tool.utils.Func;
import org.springblade.system.dto.DeptStationDTO;
import org.springframework.stereotype.Service;
import org.springframework.util.Assert;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.stream.Collectors;
/**
@ -29,6 +39,7 @@ import java.util.stream.Collectors;
public class HznlmInteractiveServiceImpl implements IHznlmInteractiveService {
private final AuthenticationService authenticationService;
private final IAuthClient authClient;
@Override
public List<AuthDataVO> getAuthData(AuthDataDTO req) {
@ -45,10 +56,30 @@ public class HznlmInteractiveServiceImpl implements IHznlmInteractiveService {
@Override
public ExtraVO resolve(ModelFunctionReq req) {
IResolveService resolveService = ResolveFactory.getResolveService(req.getFunctionName());
IResolveService resolveService = ResolveFactory.getResolveService(req.getFunc());
return resolveService.resolve(req);
}
@Override
public ExtraVO controlDevice(ControlDTO req) {
ExtraVO result = new ExtraVO();
Optional<ControlDeviceAuthDTO> 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<String,Object> params = BeanUtil.toMap(optional.get());
params.put("value", req.getValue());
result.setParams(params);
return result;
}
public List<AuthDataVO> getDeptAuthData(String userId) {
List<DeptStationDTO> deptStationDTOs = authenticationService.getStationPermissionsById(userId);
return deptStationDTOs.stream().map(this::convertDeptAuthData).collect(Collectors.toList());

21
hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/HznlmInvokeServiceImpl.java

@ -1,33 +1,24 @@
package com.hnac.hzims.bigmodel.interactive.service.impl;
import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpResponse;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.TypeReference;
import com.google.common.collect.Lists;
import com.hnac.hzims.bigmodel.business.service.AuthenticationService;
import com.hnac.hzims.bigmodel.configuration.BigModelInvokeUrl;
import com.hnac.hzims.bigmodel.interactive.service.IHznlmInvokeService;
import com.hnac.hzims.bigmodel.interactive.vo.AnswerVO;
import com.hnac.hzims.bigmodel.manager.SessionRedisManager;
import com.hnac.hzims.bigmodel.utils.RequestClientUtil;
import com.hnac.hzims.bigmodel.websocket.sessionManager.InteractiveSessionManager;
import com.xxl.job.core.log.XxlJobLogger;
import lombok.AllArgsConstructor;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springblade.core.log.exception.ServiceException;
import org.springblade.core.log.logger.BladeLogger;
import org.springblade.core.tool.api.R;
import org.springblade.core.tool.utils.CollectionUtil;
import org.springblade.core.tool.utils.Func;
import org.springblade.core.tool.utils.StringUtil;
import org.springblade.system.dto.DeptStationDTO;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.util.Assert;
import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@ -90,14 +81,18 @@ public class HznlmInvokeServiceImpl implements IHznlmInvokeService {
@Override
public void removeSessionId(String sessionId) {
Map<String,Object> params = new HashMap<>();
params.put("id",sessionId);
RequestClientUtil.postCall(fdpHost + bigModelInvokeUrl.getAskAbort(), params);
this.askAbort(sessionId);
// 移除内存sessionId
InteractiveSessionManager.SESSION_POOL.remove(sessionId);
sessionRedisManager.removeSessionId(sessionId);
}
public void askAbort(String sessionId) {
Map<String,Object> params = new HashMap<>();
params.put("id",sessionId);
RequestClientUtil.postCall(fdpHost + bigModelInvokeUrl.getAskAbort(), params);
}
@Override
public List hotQuestions() {
try {

430
hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/InteractiveServiceImpl.java

@ -1,430 +0,0 @@
package com.hnac.hzims.bigmodel.interactive.service.impl;
import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpResponse;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.google.common.util.concurrent.ThreadFactoryBuilder;
import com.hnac.hzims.bigmodel.configuration.BigModelInvokeUrl;
import com.hnac.hzims.bigmodel.entity.FunctionEntity;
import com.hnac.hzims.bigmodel.function.service.IFunctionService;
import com.hnac.hzims.bigmodel.interactive.constants.FuncRouteEnum;
import com.hnac.hzims.bigmodel.interactive.constants.FunctionConstants;
import com.hnac.hzims.bigmodel.interactive.constants.SearchStationTypeEnum;
import com.hnac.hzims.bigmodel.interactive.constants.SearchTypeEnum;
import com.hnac.hzims.bigmodel.interactive.req.ModelFunctionReq;
import com.hnac.hzims.bigmodel.interactive.service.IInteractiveService;
import com.hnac.hzims.bigmodel.interactive.service.IJumpPageService;
import com.hnac.hzims.bigmodel.interactive.service.IParamsService;
import com.hnac.hzims.bigmodel.interactive.vo.AnswerVO;
import com.hnac.hzims.bigmodel.interactive.vo.ExtraVO;
import com.hnac.hzims.operational.station.entity.StationEntity;
import com.hnac.hzims.operational.station.feign.IStationClient;
import com.hnac.hzims.equipment.feign.IEmInfoClient;
import com.hnac.hzims.equipment.vo.EminfoAndEmParamVo;
import com.hnac.hzims.equipment.vo.RideDeviceVo;
import com.hnac.hzims.operational.fill.feign.IGenerateClient;
import com.hnac.hzims.operational.main.constant.HomePageConstant;
import com.hnac.hzims.operational.station.entity.StationEntity;
import com.hnac.hzims.operational.station.feign.IStationClient;
import com.hnac.hzinfo.datasearch.analyse.IAnalyseDataSearchClient;
import com.hnac.hzinfo.datasearch.analyse.po.AnalyseCodeByAnalyseDataPO;
import com.hnac.hzinfo.datasearch.analyse.po.AnalyzeDataConditionPO;
import com.hnac.hzinfo.datasearch.analyse.vo.AnalyseDataTaosVO;
import com.hnac.hzinfo.datasearch.analyse.vo.AnalyzeDataConditionVO;
import com.xxl.job.core.log.XxlJobLogger;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.MapUtils;
import org.apache.poi.ss.formula.functions.T;
import org.springblade.core.log.exception.ServiceException;
import org.springblade.core.log.logger.BladeLogger;
import org.springblade.core.tool.api.R;
import org.springblade.core.tool.utils.*;
import org.springblade.system.dto.ControlDTO;
import org.springblade.system.dto.DeptStationDTO;
import org.springblade.system.feign.IDeptClient;
import org.springblade.system.feign.IRemoteClient;
import org.springblade.system.user.feign.IUserClient;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;
import org.springframework.util.Assert;
import org.springframework.util.StringUtils;
import javax.servlet.http.HttpServletResponse;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.*;
import java.util.concurrent.*;
import java.util.stream.Collectors;
import static com.hnac.hzims.bigmodel.interactive.constants.FunctionConstants.TypeEnum;
import static com.hnac.hzims.bigmodel.schedule.XxlJobHandlerConstant.HZIMS_BIGMODEL_ASK_KEY;
/**
* @Author: huangxing
* @Date: 2024/04/26 14:51
*/
@Service
@Slf4j
@RequiredArgsConstructor
@Deprecated
public class InteractiveServiceImpl implements IInteractiveService {
private final BladeLogger logger;
private final IEmInfoClient deviceClient;
private final IRemoteClient remoteClient;
private final IStationClient stationClient;
private final IGenerateClient generateClient;
private final IJumpPageService jumpPageService;
private final IParamsService paramsService;
private final IFunctionService functionService;
private final BigModelInvokeUrl bigModelInvokeUrl;
private final AuthenticationService authenticationService;
private final RedisTemplate redisTemplate;
private final IAnalyseDataSearchClient analyseDataSearchClient;
private final ExtraResolveStrategyService extraResolveStrategyService;
private static final ExecutorService pool = new ThreadPoolExecutor(10, 10, 0L, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<>(1024), new ThreadFactoryBuilder().setNameFormat("station-device-generate-%d").build(), new ThreadPoolExecutor.CallerRunsPolicy());
@Value("${fdp.host}")
private String fdpHost;
@Override
public ExtraVO resolveStations(String startTime, String endTime, String type, String enumType) {
ExtraVO extraVO = new ExtraVO();
extraVO.setType(TypeEnum.PARAMS.getType());
extraVO.setFunc("stations_num");
String label;
SearchStationTypeEnum stationTypeEnum = SearchStationTypeEnum.getTypeEnum(enumType);
if(!startTime.equals(endTime) && SearchTypeEnum.HISTORY.getSearchType().equals(type)) {
label = String.format("自%s到%s时间为止,",startTime,endTime);
}
else {
startTime = null;
endTime = null;
label = "目前";
}
R<List<StationEntity>> stationListR = stationClient.getStationByTypeAndDuration(startTime, endTime, stationTypeEnum.getStationType());
Assert.isTrue(stationListR.isSuccess(),() -> {
throw new ServiceException("获取接入站点数量失败!");
});
Map<String, Object> params = new HashMap<>();
params.put("searchStationType",stationTypeEnum.getSearchStationType());
params.put("label",label + String.format(stationTypeEnum.getLabel(),stationListR.getData().size()));
params.put("startTime",startTime);
params.put("endTime",endTime);
extraVO.setParams(params);
return extraVO;
}
@Override
public R resolve(ModelFunctionReq req) {
logger.info("interactive:resolve","开始解析大模型函数,函数内容为:" + JSON.toJSONString(req));
FunctionEntity function = functionService.getFunctionByCode(req.getFunctionName());
TypeEnum typeEnum = TypeEnum.getTypeEnumByType(function.getType());
if(Func.isEmpty(typeEnum)) {
throw new ServiceException("函数解析失败!");
}
switch (typeEnum) {
// 页面跳转
case JUMP:
String jumpExtra = jumpPageService.dealJumpTypeFunction(function, req.getFunctionArgs());
Assert.isTrue(StringUtil.isNotBlank(jumpExtra) && Func.isNotEmpty(jumpExtra), () -> {
throw new ServiceException("解析" + function.getName() + "函数失败!");
});
return R.data(jumpExtra);
case PARAMS:
String paramExtra = paramsService.dealJumpTypeFunction(function, req.getFunctionArgs());
return R.data(paramExtra);
default:
throw new ServiceException("函数解析失败!");
}
}
@Override
public R ask(String question,String sessionId,String userId) {
Map<String,Object> params = new HashMap<>();
params.put("id",sessionId);
params.put("userid", userId);
params.put("query",question);
params.put("stationids",authenticationService.getStationPermissionsById(userId).stream().map(DeptStationDTO::getStationId).filter(StringUtil::isNotBlank).filter(Func::isNotEmpty).toArray());
params.put("projectids",authenticationService.getStationPermissionsById(userId).stream().map(DeptStationDTO::getDeptId).filter(Func::isNotEmpty).map(String::valueOf).toArray());
HttpResponse response = HttpRequest.post(fdpHost + bigModelInvokeUrl.getAssistantAsk())
.body(JSON.toJSONString(params)).execute();
logger.info("interactive:ask","问答传参为:" + JSON.toJSONString(params) + "结果为:" + response.body());
if(response.getStatus() != HttpServletResponse.SC_OK) {
log.error("远程调用大模型【发起问答】接口失败!");
return R.fail("远程调用大模型【发起问答】接口失败!");
}
this.addQuestionSessionId(sessionId);
return R.success("消息发送成功");
}
private void addQuestionSessionId(String sessionId) {
redisTemplate.opsForList().leftPush(HZIMS_BIGMODEL_ASK_KEY,sessionId);
}
@Override
public R specialAsk(String sessionId, String userId, Map<String, Object> extra) {
Map<String,Object> params = new HashMap<>();
params.put("id",sessionId);
params.put("userid", userId);
params.put("extra",extra);
params.put("stationids",authenticationService.getStationPermissionsById(userId).stream().map(DeptStationDTO::getStationId).filter(StringUtil::isNotBlank).filter(Func::isNotEmpty).toArray());
params.put("projectids",authenticationService.getStationPermissionsById(userId).stream().map(DeptStationDTO::getDeptId).filter(Func::isNotEmpty).map(String::valueOf).toArray());
HttpResponse response = HttpRequest.post(fdpHost + bigModelInvokeUrl.getAssistantSpecialAsk())
.body(JSON.toJSONString(params)).execute();
if(response.getStatus() != HttpServletResponse.SC_OK) {
log.error("远程调用大模型【发起特殊问答】接口失败!");
return R.fail("远程调用大模型【发起特殊问答】接口失败!");
}
this.addQuestionSessionId(sessionId);
return R.success("消息发送成功");
}
@Override
public List hotQuestions() {
String url = fdpHost + bigModelInvokeUrl.getHotQuestion();
return this.postCall(url,null,List.class);
}
/**
* 远程调用http接口
* @param url 接口url
* @param body 传参
* @param resultT 结果解析对象
* @return 结果
* @param <T> 结果解析对象类型
*/
public <T> T postCall(String url,Map body,Class<T> resultT) {
HttpResponse response = HttpRequest.post(url).body(JSON.toJSONString(body)).execute();
Assert.isTrue(response.getStatus() == HttpServletResponse.SC_OK, () -> {
log.error("远程调用大模型接口" + url + "失败!");
throw new ServiceException("远程调用大模型接口" + url + "失败!");
});
return JSONObject.parseObject(response.body(), resultT);
}
@Override
public void updateVideo(Map<String, Object> request) {
HttpResponse response = HttpRequest.post(fdpHost + bigModelInvokeUrl.getUpdateVideo())
.body(JSON.toJSONString(request)).execute();
Assert.isTrue(response.getStatus() == HttpServletResponse.SC_OK, () -> {
throw new ServiceException("远程调用大模型【更新实时监控】接口失败!");
});
}
@Override
public Boolean updateCanvas(Map<String, Object> request) {
HttpResponse response = HttpRequest.post(fdpHost + bigModelInvokeUrl.getUpdateCanvas())
.body(JSON.toJSONString(request)).execute();
if (response.getStatus() == HttpServletResponse.SC_OK) {
return true;
}
log.error("远程调用大模型【更新实时画面】接口失败!");
return false;
}
@Override
public void updateFault(Map<String, Object> request) {
HttpResponse response = HttpRequest.post(fdpHost + bigModelInvokeUrl.getUpdateFault())
.body(JSON.toJSONString(request)).execute();
Assert.isTrue(response.getStatus() == HttpServletResponse.SC_OK, () -> {
throw new ServiceException("远程调用大模型【更新故障列表】接口失败!");
});
}
@Override
public List<AnswerVO> getAnswerBySessionIds(String sessionIds) {
Map<String,Object> params = new HashMap<>();
params.put("ids",Func.toStrList(",",sessionIds).toArray());
HttpResponse response = HttpRequest.post(fdpHost + bigModelInvokeUrl.getAssistantStatus())
.body(JSON.toJSONString(params)).execute();
Assert.isTrue(response.getStatus() == HttpServletResponse.SC_OK, () -> {
throw new ServiceException("远程调用大模型【获取问题答案】接口失败!");
});
XxlJobLogger.log("接收到答案:"+JSON.toJSONString(response.body()));
List<AnswerVO> result = JSONArray.parseArray(response.body(), AnswerVO.class);
if(CollectionUtil.isNotEmpty(result)) {
logger.info("interactive:getAnswerBySessionIds","获取答案:" + response.body());
}
return result;
}
@Override
public Boolean authentication(String stationId, String userId, String func,String sessionId) {
// 站点鉴权
if(StringUtil.isNotBlank(stationId)) {
authenticationService.stationAuthentication(stationId,userId);
}
// 菜单鉴权
if(StringUtil.isNotBlank(func) && StringUtil.isNotBlank(userId)) {
authenticationService.menuAuthentication(userId,func);
}
// 遥控鉴权
if(FuncRouteEnum.CONFIRM_YK.getFuncCode().equals(func)) {
authenticationService.remoteAuthentication(stationId,userId,sessionId);
}
return true;
}
@Override
public Boolean removeSessionId(String sessionId) {
// 调用大模型删除对话
Map<String,Object> params = new HashMap<>();
params.put("id",sessionId);
HttpResponse response = HttpRequest.post(fdpHost + bigModelInvokeUrl.getAskAbort())
.body(JSON.toJSONString(params)).execute();
if(response.getStatus() != HttpServletResponse.SC_OK) {
log.error("远程调用大模型【删除对话】接口失败!");
throw new ServiceException("远程调用大模型【删除对话】接口失败!");
}
// 移除对应reids中问题标记
redisTemplate.opsForList().remove(HZIMS_BIGMODEL_ASK_KEY,1,sessionId);
return true;
}
/**
* 发起知识库问答
*/
@Override
public R knowledgeAsk(String question, String sessionId, String userId, String knowledge) {
Map<String,Object> params = new HashMap<>();
params.put("id", sessionId);
params.put("userid", userId);
params.put("query", question);
params.put("knowledge", knowledge);
params.put("stationids", authenticationService.getStationPermissionsById(userId).stream().map(DeptStationDTO::getStationId)
.filter(StringUtil::isNotBlank).filter(Func::isNotEmpty).toArray());
params.put("projectids", authenticationService.getStationPermissionsById(userId).stream().map(DeptStationDTO::getDeptId)
.filter(Func::isNotEmpty).map(String::valueOf).toArray());
HttpResponse response = HttpRequest.post(fdpHost + bigModelInvokeUrl.getAssistantKnowledgeAsk())
.body(JSON.toJSONString(params)).execute();
logger.info("interactive:knowledgeAsk", "知识库问答传参为:" + JSON.toJSONString(params) + " 结果为:" + response.body());
if (response.getStatus() != HttpServletResponse.SC_OK) {
log.error("远程调用大模型【发起知识库问答】接口失败!");
return R.fail("远程调用大模型【发起知识库问答】接口失败!");
}
this.addQuestionSessionId(sessionId);
return R.success("消息发送成功");
}
/**
* 下发遥控指令
* @param operate
* @return
*/
@Override
public R<Object> sendRemoteControl(ControlDTO operate) {
return remoteClient.sendCtrl(operate);
}
/**
* 站点发电量
* @param stationId
* @param startTime
* @param endTime
* @return
*/
@Override
public Double generation(String stationId, String startTime, String endTime) {
// 步骤1.查询站点
R<StationEntity> station = stationClient.getStationByCode(stationId);
if(!station.isSuccess() || ObjectUtil.isEmpty(station.getData())){
return 0.0;
}
// 步骤2.查询填报发电量
double fill = generateClient.stationGenerateByTime(stationId,startTime,endTime);
// 步骤3.查询设备
List<RideDeviceVo> devices = deviceClient.rideDevices(Collections.singletonList(station.getData().getRefDept()));
if(CollectionUtil.isEmpty(devices)){
return fill;
}
// 步骤4.遍历设备查询发电量
// 监控线程执行完后返回结果
CountDownLatch countDownLatch = new CountDownLatch(devices.size());
List<Double> deviceGenerate = new CopyOnWriteArrayList();
for(RideDeviceVo device : devices){
pool.submit(()->{
deviceGenerate.add(this.periodTargetFloat(startTime,endTime,5,6,device.getNumber(),device.getRide(), HomePageConstant.HYDROPOWER_GENERATE_POWER));
});
countDownLatch.countDown();
}
//所有模板数据获取完成后释放锁
try {
countDownLatch.await();
} catch (InterruptedException e) {
e.printStackTrace();
Thread.currentThread().interrupt();
}
return fill + deviceGenerate.stream().mapToDouble(Double::doubleValue).sum();
}
/***
* 指标数据列表查询
* @param startTime 开始时间
* @param endTime 结束时间
* @param accessRules 取数规则 : 0=最早值 1=最大值 2=最小值 3=平均值 4=和值 5=差值 6=最新值
* @param cycleType 间隔周期 : 0-> 1-> 2-> 小时 3-> 4-> 5-> 6->
* @param deviceCode 设备编号
* @param ride 配电比
* @param signages 指标
* @return
*/
private Double periodTargetFloat(String startTime, String endTime, Integer accessRules, Integer cycleType, String deviceCode,Double ride,String signages) {
AnalyseCodeByAnalyseDataPO po = new AnalyseCodeByAnalyseDataPO();
List<AnalyzeDataConditionPO> signboardConditions = new ArrayList<>();
AnalyzeDataConditionPO analyzeDataConditionPO = new AnalyzeDataConditionPO();
analyzeDataConditionPO.setFull(1);
po.setDeviceCode(deviceCode);
analyzeDataConditionPO.setSignages(signages);
analyzeDataConditionPO.setKeepFigures(2);
analyzeDataConditionPO.setAccessRules(accessRules);
analyzeDataConditionPO.setSaveTimeType(cycleType);
// 间隔
analyzeDataConditionPO.setTimeInterval(1);
analyzeDataConditionPO.setBeginTime(LocalDateTime.parse(DateUtil.format(new Date(), startTime), DateTimeFormatter.ofPattern(DateUtil.PATTERN_DATETIME)));
analyzeDataConditionPO.setEndTime(LocalDateTime.parse(DateUtil.format(new Date(), endTime), DateTimeFormatter.ofPattern(DateUtil.PATTERN_DATETIME)));
signboardConditions.add(analyzeDataConditionPO);
po.setSignboardConditions(signboardConditions);
R<List<AnalyzeDataConditionVO>> result = analyseDataSearchClient.getAnalyzeDataByAnalyzeCodeAndSignages(po);
if (!result.isSuccess() || CollectionUtil.isEmpty(result.getData())) {
return 0.0;
}
List<AnalyzeDataConditionVO> records = result.getData();
if(CollectionUtil.isEmpty(records)){
return 0.0;
}
AnalyzeDataConditionVO analyzeDataConditionVO = records.get(0);
if (ObjectUtil.isEmpty(analyzeDataConditionVO)) {
return 0.0;
}
List<AnalyseDataTaosVO> analyseDataTaosVOList = analyzeDataConditionVO.getList();
if (CollectionUtil.isEmpty(analyseDataTaosVOList)) {
return 0.0;
}
AnalyseDataTaosVO analyseDataTaosVO = analyzeDataConditionVO.getList().get(0);
if (ObjectUtil.isEmpty(analyseDataTaosVO) || StringUtil.isBlank(analyseDataTaosVO.getVal())) {
return 0.0;
}
return Double.parseDouble(analyseDataTaosVO.getVal()) * ride;
}
}

46
hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/JumpPageServiceImpl.java

@ -1,46 +0,0 @@
package com.hnac.hzims.bigmodel.interactive.service.impl;
import com.alibaba.fastjson.JSON;
import com.hnac.hzims.bigmodel.entity.FuncParamEntity;
import com.hnac.hzims.bigmodel.entity.FunctionEntity;
import com.hnac.hzims.bigmodel.function.service.IFuncParamService;
import com.hnac.hzims.bigmodel.interactive.constants.FunctionConstants;
import com.hnac.hzims.bigmodel.interactive.service.IJumpPageService;
import com.hnac.hzims.bigmodel.interactive.vo.ExtraVO;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springblade.core.log.exception.ServiceException;
import org.springblade.core.tool.utils.StringUtil;
import org.springframework.stereotype.Service;
import org.springframework.util.Assert;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
/**
* @Author: huangxing
* @Date: 2024/04/26 11:46
*/
@Service
@AllArgsConstructor
@Slf4j
@Deprecated
public class JumpPageServiceImpl implements IJumpPageService {
private final IFuncParamService paramService;
private final JumpRouteJoinStrategy strategy;
@Override
public String dealJumpTypeFunction(FunctionEntity function,Map<String,String> args) {
List<FuncParamEntity> params = paramService.getParamsByFuncId(function.getId());
Optional<FuncParamEntity> 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);
}
}

3
hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/JumpRouteJoinStrategy.java

@ -1,6 +1,5 @@
package com.hnac.hzims.bigmodel.interactive.service.impl;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.hnac.hzims.bigmodel.entity.FunctionEntity;
import com.hnac.hzims.bigmodel.interactive.constants.FuncRouteEnum;
@ -54,7 +53,7 @@ public class JumpRouteJoinStrategy {
// 跳转页面逻辑
ExtraVO extraVO = new ExtraVO();
extraVO.setImmediatelyJump(true);
extraVO.setFunc(FuncRouteEnum.OPEN_CANVAS.getFuncCode());
extraVO.setFunc(FuncRouteEnum.OPEN_CANVAS.getFunc());
Map<String, String> params = this.scadaResolve(args);
// 根据hz3000画面版本获取path
Integer picResource = Integer.valueOf(params.get("picResource"));

2
hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/ParamStrategy.java

@ -57,7 +57,7 @@ public class ParamStrategy {
StationVideoTypeEntity video = videoR.getData();
extraVO.setType(FunctionConstants.TypeEnum.PARAMS.getType());
extraVO.setImmediatelyJump(true);
extraVO.setFunc(FuncRouteEnum.OPEN_VIDEO.getFuncCode());
extraVO.setFunc(FuncRouteEnum.OPEN_VIDEO.getFunc());
Map<String,Object> params = new HashMap<>();
params.put("name", video.getName());
params.put("videoHost", video.getVideoHost());

36
hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/ParamsServiceImpl.java

@ -1,36 +0,0 @@
package com.hnac.hzims.bigmodel.interactive.service.impl;
import com.alibaba.fastjson.JSON;
import com.hnac.hzims.bigmodel.entity.FuncParamEntity;
import com.hnac.hzims.bigmodel.entity.FunctionEntity;
import com.hnac.hzims.bigmodel.interactive.service.IParamsService;
import com.hnac.hzims.bigmodel.interactive.vo.ExtraVO;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springblade.core.log.exception.ServiceException;
import org.springframework.stereotype.Service;
import org.springframework.util.Assert;
import java.util.List;
import java.util.Map;
import java.util.Optional;
/**
* @Author: huangxing
* @Date: 2024/05/09 08:51
*/
@Service
@Slf4j
@AllArgsConstructor
@Deprecated
public class ParamsServiceImpl implements IParamsService {
private final ParamStrategy strategy;
@Override
public String dealJumpTypeFunction(FunctionEntity function, Map<String, String> args) {
// 跳转页面逻辑
ExtraVO extraVO = strategy.resolve(function,args);
return JSON.toJSONString(extraVO);
}
}

10
hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/VideoResolveServiceImpl.java

@ -7,7 +7,6 @@ import com.hnac.hzims.bigmodel.interactive.factory.ResolveFactory;
import com.hnac.hzims.bigmodel.interactive.req.ModelFunctionReq;
import com.hnac.hzims.bigmodel.interactive.service.IResolveService;
import com.hnac.hzims.bigmodel.interactive.vo.ExtraVO;
import com.hnac.hzims.bigmodel.interactive.vo.ResolveResultVO;
import com.hnac.hzims.operational.station.entity.StationVideoTypeEntity;
import com.hnac.hzims.operational.station.feign.IStationVideoTypeClient;
import groovy.util.logging.Slf4j;
@ -15,7 +14,6 @@ import lombok.AllArgsConstructor;
import org.springblade.core.log.exception.ServiceException;
import org.springblade.core.log.logger.BladeLogger;
import org.springblade.core.tool.api.R;
import org.springblade.core.tool.utils.Func;
import org.springblade.core.tool.utils.StringUtil;
import org.springframework.stereotype.Service;
import org.springframework.util.Assert;
@ -37,9 +35,9 @@ public class VideoResolveServiceImpl implements IResolveService {
@Override
public ExtraVO resolve(ModelFunctionReq req) {
Map<String, String> args = req.getFunctionArgs();
String id = args.get("id");
String name = args.get("name");
Map<String, String> args = req.getItem();
String id = args.get("itemId");
String name = args.get("itemName");
Assert.isTrue(StringUtil.isNotBlank(id) && StringUtil.isNotBlank(name),() -> {
logger.error("hzims:video:resolve","解析传参错误,缺少必要参数video_id,传参内容为:" + JSON.toJSONString(req));
throw new ServiceException("解析传参错误,缺少必要参数video_id");
@ -60,7 +58,7 @@ public class VideoResolveServiceImpl implements IResolveService {
StationVideoTypeEntity video = videoR.getData();
extraVO.setType(FunctionConstants.TypeEnum.PARAMS.getType());
extraVO.setImmediatelyJump(true);
extraVO.setFunc(FuncRouteEnum.OPEN_VIDEO.getFuncCode());
extraVO.setFunc(FuncRouteEnum.OPEN_VIDEO.getFunc());
Map<String,Object> params = new HashMap<>();
params.put("name", video.getName());
params.put("videoHost", video.getVideoHost());

67
hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/maintenance/controller/DataSourceController.java

@ -0,0 +1,67 @@
package com.hnac.hzims.bigmodel.maintenance.controller;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.hnac.hzims.bigmodel.maintenance.entity.DatasourceEntity;
import com.hnac.hzims.bigmodel.maintenance.service.DataSourceService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.AllArgsConstructor;
import org.springblade.core.mp.support.Condition;
import org.springblade.core.mp.support.Query;
import org.springblade.core.tool.api.R;
import org.springblade.core.tool.utils.Func;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.*;
/**
* @Author: huangxing
* @Date: 2024/07/05 16:55
*/
@RestController
@RequestMapping("/datasource")
@Api(value = "数据源管理",tags = "数据源管理")
public class DataSourceController {
@Autowired
@Qualifier("dataSourceMaintenanceService")
private DataSourceService dataSourceService;
@GetMapping("/listPage")
@ApiOperation(value = "分页查询")
@ApiOperationSupport(order = 1)
public R<IPage<DatasourceEntity>> 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<DatasourceEntity> 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));
}
}

14
hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/maintenance/controller/TableColumnController.java

@ -33,22 +33,24 @@ public class TableColumnController {
@ApiOperation("获取数据库")
@ApiOperationSupport(order = 1)
@GetMapping("/getDatabase")
public R<List<Map<String,Object>>> getDatabase() {
return R.data(tableColumnService.getDatabase());
public R<List<Map<String,Object>>> getDatabase(@RequestParam @ApiParam(value = "数据源名") String datasource) {
return R.data(tableColumnService.getDatabase(datasource));
}
@ApiOperation("获取数据库表列表")
@ApiOperationSupport(order = 2)
@GetMapping("/getTables")
public R<List<Map<String,Object>>> getTables(@RequestParam @ApiParam(value = "数据库名") String database) {
return R.data(tableColumnService.getTables(database));
public R<List<Map<String,Object>>> 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<List<Map<String,Object>>> getColumns(@RequestParam @ApiParam(value = "数据库名") String database,
public R<List<Map<String,Object>>> getColumns(String datasource,
@RequestParam @ApiParam(value = "数据源名") String database,
@RequestParam @ApiParam(value = "数据库表名") String tableName) {
return R.data(tableColumnService.getColumns(database,tableName));
return R.data(tableColumnService.getColumns(datasource,database,tableName));
}
}

66
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<IPage<TablePropertyEntity>> 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<TablePropertyEntity> 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));
}
}

33
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;
}

49
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;
}

12
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<DatasourceEntity> {
}

11
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<TablePropertyEntity> {
}

19
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<DatasourceMapper, DatasourceEntity> {
}

18
hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/maintenance/service/TableColumnService.java

@ -20,19 +20,19 @@ public class TableColumnService {
private final DataSourceService dataSourceService;
public List<Map<String,Object>> getDatabase() {
String sql = "select distinct `table_schema` from `tables` where `table_schema` <> 'information_schema';";
return dataSourceService.queryListOnSpecificDataSource(sql,"information");
public List<Map<String,Object>> getDatabase(String datasource) {
String sql = "select distinct `table_schema` from `information_schema`.`tables` where `table_schema` <> 'information_schema';";
return dataSourceService.queryListOnSpecificDataSource(sql,datasource);
}
public List<Map<String, Object>> getTables(String database) {
String sql = "select distinct `table_name` from `tables` where `table_schema` = '" + database + "';";
return dataSourceService.queryListOnSpecificDataSource(sql,"information");
public List<Map<String, Object>> getTables(String datasource,String database) {
String sql = "select distinct `table_name` from `information_schema`.`tables` where `table_schema` = '" + database + "';";
return dataSourceService.queryListOnSpecificDataSource(sql,datasource);
}
public List<Map<String, Object>> getColumns(String database,String tableName) {
String sql = "select `COLUMN_NAME` from `COLUMNS` where `TABLE_SCHEMA` = '" + database + "' and `TABLE_NAME` = '" + tableName + "';";
return dataSourceService.queryListOnSpecificDataSource(sql,"information");
public List<Map<String, Object>> getColumns(String datasource,String database,String tableName) {
String sql = "select distinct `column_name`,`column_comment` from `information_schema`.`COLUMNS` where `TABLE_SCHEMA` = '" + database + "' and `TABLE_NAME` = '" + tableName + "';";
return dataSourceService.queryListOnSpecificDataSource(sql,datasource);
}
}

20
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<TablePropertyMapper, TablePropertyEntity> {
}

201
hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/schedule/InteractiveSchedule.java

@ -1,201 +0,0 @@
package com.hnac.hzims.bigmodel.schedule;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.hnac.hzims.bigmodel.interactive.service.IInteractiveService;
import com.hnac.hzims.bigmodel.interactive.service.impl.ExtraResolveStrategyService;
import com.hnac.hzims.bigmodel.interactive.vo.AnswerVO;
import com.hnac.hzims.bigmodel.interactive.vo.UpdateStationVO;
import com.hnac.hzims.bigmodel.interactive.vo.UpdateUsualVO;
import com.hnac.hzims.bigmodel.websocket.service.InteractiveWsService;
import com.hnac.hzims.bigmodel.websocket.sessionManager.InteractiveSessionManager;
import com.hnac.hzims.operational.station.entity.StationEntity;
import com.hnac.hzims.operational.station.entity.StationVideoTypeEntity;
import com.hnac.hzims.operational.station.feign.IStationClient;
import com.hnac.hzims.operational.station.feign.IStationVideoTypeClient;
import com.hnac.hzinfo.sdk.core.response.Result;
import com.hnac.hzinfo.sdk.v5.project.ProjectClient;
import com.hnac.hzinfo.sdk.v5.project.vo.ProjectVO;
import com.hnac.hzinfo.sdk.v5.scada.ScadaClient;
import com.hnac.hzinfo.sdk.v5.scada.vo.CanvasVO;
import com.xxl.job.core.biz.model.ReturnT;
import com.xxl.job.core.handler.annotation.XxlJob;
import com.xxl.job.core.log.XxlJobLogger;
import lombok.AllArgsConstructor;
import org.springblade.core.tool.api.R;
import org.springblade.core.tool.utils.CollectionUtil;
import org.springblade.core.tool.utils.Func;
import org.springblade.core.tool.utils.ObjectUtil;
import org.springblade.core.tool.utils.StringUtil;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import org.springframework.web.socket.TextMessage;
import org.springframework.web.socket.WebSocketSession;
import java.util.*;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.stream.Collectors;
import static com.hnac.hzims.bigmodel.schedule.XxlJobHandlerConstant.*;
/**
* @Author: huangxing
* @Date: 2024/04/28 16:18
*/
@Component
@AllArgsConstructor
@Deprecated
public class InteractiveSchedule {
private final InteractiveWsService wsService;
private final IInteractiveService interactiveService;
private final ThreadPoolExecutor getAnswerPoolExecutor;
private final RedisTemplate redisTemplate;
private final IStationVideoTypeClient videoClient;
private final ProjectClient projectClient;
private final ScadaClient scadaClient;
private final IStationClient stationClient;
private final ExtraResolveStrategyService extraResolveStrategyService;
// @XxlJob(GET_INTERACTIVE_RESULT)
public ReturnT getInteractiveResult(String params) {
List<String> sessionIds = redisTemplate.opsForList().range(HZIMS_BIGMODEL_ASK_KEY, 0, -1);
if(CollectionUtil.isEmpty(sessionIds)){
XxlJobLogger.log("问题都已经回答完毕!");
return ReturnT.SUCCESS;
}
List<AnswerVO> answerList = interactiveService.getAnswerBySessionIds(String.join(",", sessionIds));
answerList.stream().parallel().forEach(answerVO -> CompletableFuture.runAsync(() -> {
// 如果已经获取到答案 则删除缓存
if(answerVO.getRunning() == 0) {
redisTemplate.opsForList().remove(HZIMS_BIGMODEL_ASK_KEY,1,answerVO.getSessionId());
}
Object[] extras = answerVO.getExtras();
if(ObjectUtil.isNotEmpty(answerVO.getExtras()) && extras.length > 0){
try {
List<String> extraList = Arrays.stream(extras).map(Object::toString).map(extraResolveStrategyService::resolve).map(JSON::toJSONString).collect(Collectors.toList());
answerVO.setExtras(extraList.toArray(new String[extraList.size()]));
}
catch(Exception e) {
e.printStackTrace();
AnswerVO.error(answerVO);
answerVO.setAnswer("非常抱歉,系统在处理您的请求时遇到了问题。请稍后再试或联系我们的客服团队。");
}
}
if(sessionIds.contains(answerVO.getSessionId())){
WebSocketSession session = InteractiveSessionManager.get(answerVO.getSessionId());
TextMessage message = InteractiveSessionManager.getTextMessage("1",JSON.toJSONString(answerVO));
if(Func.isNotEmpty(session)) {
wsService.sendMessage(session,message);
}
}
}, getAnswerPoolExecutor));
return ReturnT.SUCCESS;
}
@XxlJob(SYNCHRONOUS_VIDEO_INSTRUCT)
public ReturnT synchronousVideoInstruct(String params) {
Map<String,Object> request = new HashMap<>(2);
// 获取站点列表
R<List<StationEntity>> stationsR = stationClient.list(new StationEntity());
if(!stationsR.isSuccess() || CollectionUtil.isEmpty(stationsR.getData())) {
XxlJobLogger.log("获取站点列表失败!");
return ReturnT.FAIL;
}
List<UpdateStationVO> updateStationList = stationsR.getData().stream().map(station -> {
UpdateStationVO stationVO = new UpdateStationVO();
stationVO.setId(station.getCode());
stationVO.setName(station.getName());
return stationVO;
}).collect(Collectors.toList());
request.put("stations", updateStationList);
// 获取视频列表
R<List<StationVideoTypeEntity>> videoListR = videoClient.list(new StationVideoTypeEntity());
if(!videoListR.isSuccess() || CollectionUtil.isEmpty(videoListR.getData())) {
XxlJobLogger.log("获取视频列表失败!");
return ReturnT.FAIL;
}
List<UpdateUsualVO> updateUsualList = videoListR.getData().stream().map(video -> {
UpdateUsualVO usualVO = new UpdateUsualVO();
usualVO.setStationId(video.getStationId());
usualVO.setId(String.valueOf(video.getId()));
usualVO.setName(video.getName());
return usualVO;
}).collect(Collectors.toList());
request.put("videos", updateUsualList);
// 同步指令
interactiveService.updateVideo(request);
return ReturnT.SUCCESS;
}
@XxlJob(SYNCHRONOUS_SCADA_INSTRUCT)
public ReturnT synchronousScadaInstruct(String params) {
// 查询项目数据
Result<List<ProjectVO>> projects = projectClient.getProjectByAppId();
if(!projects.isSuccess() || CollectionUtil.isEmpty(projects.getData())){
return ReturnT.SUCCESS;
}
// 请求fdp同步实时画面方法参数定义
Map<String,Object> param = new HashMap<>(2);
List<UpdateStationVO> stations = projects.getData().stream().map(station -> {
UpdateStationVO updateStation = new UpdateStationVO();
updateStation.setId(station.getId());
updateStation.setName(station.getName());
return updateStation;
}).collect(Collectors.toList());
param.put("stations", stations);
// 查询画面信息
Result<List<CanvasVO>> canvas = scadaClient.getCanvasList(projects.getData().stream().map(ProjectVO::getId).collect(Collectors.toList()));
if(!canvas.isSuccess() || CollectionUtil.isEmpty(canvas.getData())) {
return ReturnT.SUCCESS;
}
List<UpdateUsualVO> updateUsuals = canvas.getData().stream().map(canva -> {
UpdateUsualVO usualVO = new UpdateUsualVO();
usualVO.setStationId(canva.getProjectId());
usualVO.setName(canva.getName());
// 画面id =
String id = Optional.of(canva.getPicSource()).map(String::valueOf).orElse("") + "^" +
Optional.ofNullable(canva.getContext()).orElse("") + "^" +
Optional.ofNullable(canva.getStationNum()).orElse("") + "^" +
Optional.ofNullable(canva.getProjectId()).orElse("") + "^" +
Optional.ofNullable(canva.getTaskId()).map(String::valueOf).orElse("") + "^" +
Optional.ofNullable(canva.getName()).orElse("") + "^" +
Optional.ofNullable(canva.getId()).map(String::valueOf).orElse("") + "^";
usualVO.setId(id);
return usualVO;
}).collect(Collectors.toList());
param.put("canvases", updateUsuals);
Boolean status = interactiveService.updateCanvas(param);
return ReturnT.SUCCESS;
}
@XxlJob(SYNCHRONOUS_FAULT_INSTRUCT)
public ReturnT synchronousFaultInstruct(String params) {
Map<String,Object> request = new HashMap<>(2);
// 获取站点列表
R<List<StationEntity>> stationsR = stationClient.list(new StationEntity());
if(!stationsR.isSuccess() || CollectionUtil.isEmpty(stationsR.getData())) {
XxlJobLogger.log("获取站点列表失败!");
return ReturnT.FAIL;
}
List<UpdateStationVO> updateStationList = stationsR.getData().stream().map(station -> {
UpdateStationVO stationVO = new UpdateStationVO();
stationVO.setId(station.getCode());
stationVO.setName(station.getName());
return stationVO;
}).collect(Collectors.toList());
request.put("stations", updateStationList);
interactiveService.updateFault(request);
return ReturnT.SUCCESS;
}
}

15
hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/websocket/handler/InteractiveHandler.java

@ -13,15 +13,11 @@ import com.hnac.hzims.bigmodel.interactive.service.IInteractiveService;
import com.hnac.hzims.bigmodel.websocket.constants.RedisKeyConstants;
import com.hnac.hzims.bigmodel.websocket.service.InteractiveWsService;
import com.hnac.hzims.bigmodel.websocket.sessionManager.InteractiveSessionManager;
import lombok.AllArgsConstructor;
import lombok.NoArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springblade.core.tool.api.R;
import org.springblade.core.tool.utils.BeanUtil;
import org.springblade.core.tool.utils.Func;
import org.springblade.core.tool.utils.SpringUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;
import org.springframework.web.socket.CloseStatus;
@ -33,7 +29,6 @@ import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import java.util.function.Function;
/**
* @Author: huangxing
@ -94,13 +89,11 @@ public class InteractiveHandler extends TextWebSocketHandler {
String context = messageContext.getString("context");
String userId = messageContext.getString("userId");
String knowledge = messageContext.getString("knowledge");
IInteractiveService interactiveService = SpringUtil.getBean(IInteractiveService.class);
IHznlmInvokeService hznlmInvokeService = SpringUtil.getBean(IHznlmInvokeService.class);
if (knowledge != null) {
R askResult = interactiveService.knowledgeAsk(context, sessionId, userId, knowledge);
log.info("知识库问答返回结果:" + JSON.toJSONString(askResult));
hznlmInvokeService.knowledgeAsk(context, sessionId, userId, knowledge);
} else {
R askResult = interactiveService.ask(context, sessionId, userId);
log.info("返回结果为:"+ JSON.toJSONString(askResult));
hznlmInvokeService.ask(context, sessionId, userId);
}
}
else {
@ -170,7 +163,7 @@ public class InteractiveHandler extends TextWebSocketHandler {
Map<String,String> param = new HashMap<>(1);
param.put("canvas_id",selection.getId());
IFunctionService functionService = SpringUtil.getBean(IFunctionService.class);
FunctionEntity function = functionService.getFunctionByCode(FuncRouteEnum.OPEN_CANVAS.getFuncCode());
FunctionEntity function = functionService.getFunctionByCode(FuncRouteEnum.OPEN_CANVAS.getFunc());
ExtraVO scadaExtra = strategy.getScadaExtra(param, function);
AnswerVO answerVO = new AnswerVO();
answerVO.setSessionId(sessionId);

31
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='数据库表配置';
Loading…
Cancel
Save