Browse Source

fix:大模型结构调整

zhongwei
haungxing 5 months ago
parent
commit
55d24f867d
  1. 20
      hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/api/dto/CanvasSyncDTO.java
  2. 20
      hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/api/dto/ControlSyncDTO.java
  3. 50
      hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/api/dto/SyncDTO.java
  4. 20
      hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/api/dto/VideoSyncDTO.java
  5. 12
      hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/api/feign/ICanvasSyncClient.java
  6. 11
      hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/api/feign/IControlSyncClient.java
  7. 40
      hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/api/feign/ISyncClient.java
  8. 33
      hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/api/feign/IVideoSyncClient.java
  9. 10
      hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/business/feign/IAuthClient.java
  10. 2
      hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/interactive/vo/DataItemVO.java
  11. 7
      hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/interactive/vo/SelectionVO.java
  12. 35
      hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/api/feign/VideoSyncClient.java
  13. 16
      hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/api/service/SyncService.java
  14. 6
      hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/business/control/DataSourceExecuteController.java
  15. 5
      hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/business/control/RemoteController.java
  16. 36
      hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/business/feign/AuthClient.java
  17. 27
      hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/business/service/AuthenticationService.java
  18. 13
      hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/business/service/DataSourceService.java
  19. 2
      hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/business/service/HistoryDataService.java
  20. 2
      hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/business/service/RemoteService.java
  21. 2
      hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/business/vo/SqlVO.java
  22. 2
      hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/business/vo/TableAuthVO.java
  23. 73
      hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/function/controller/FunctionController.java
  24. 74
      hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/function/controller/FunctionParamController.java
  25. 11
      hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/function/mapper/FuncParamMapper.java
  26. 12
      hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/function/mapper/FunctionMapper.java
  27. 21
      hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/function/service/IFuncParamService.java
  28. 14
      hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/function/service/IFunctionService.java
  29. 28
      hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/function/service/impl/FuncParamServiceImpl.java
  30. 27
      hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/function/service/impl/FunctionServiceImpl.java
  31. 5
      hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/controller/HznlmInteractiveController.java
  32. 10
      hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/IHznlmInvokeService.java
  33. 58
      hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/IInteractiveService.java
  34. 17
      hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/IJumpPageService.java
  35. 2
      hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/AnalyseDataServiceImpl.java
  36. 6
      hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/CanvasResolveServiceImpl.java
  37. 51
      hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/HznlmInvokeServiceImpl.java
  38. 144
      hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/JumpRouteJoinStrategy.java
  39. 73
      hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/ParamStrategy.java
  40. 4
      hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/vo/AnswerVO.java
  41. 2
      hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/vo/RemoteParamVO.java
  42. 3
      hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/maintenance/service/TableColumnService.java
  43. 106
      hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/question/dto/MessageDTO.java
  44. 78
      hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/question/dto/QuestionDTO.java
  45. 123
      hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/question/service/QuestionHandlerService.java
  46. 2
      hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/schedule/FrontEndInteractiveSchedule.java
  47. 18
      hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/utils/RequestClientUtil.java
  48. 68
      hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/websocket/handler/InteractiveHandler.java

20
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 {
}

20
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 {
}

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

20
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 {
}

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

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

40
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<T extends SyncDTO> {
String SAVE_BATCH = "/saveBatch";
String UPDATE_BY_ID = "/updateById";
String DELETE_BY_IDS = "/deleteByIds";
/**
* 同步 - 新增对象
* @param syncDTO 同步对象列表
* @return 同步结果
*/
R saveBatch(List<T> syncDTO);
/**
* 同步 - 更新对象
* @param syncDTO 同步对象
* @return 同步结果
*/
R updateById(T syncDTO);
/**
* 同步 - 删除对象
* @param ids 主键id按逗号分隔
* @return 删除结果
*/
R deleteByIds(String ids);
}

33
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<VideoSyncDTO> {
String PREFIX_API = "/feign/sync/video";
@Override
@PostMapping(PREFIX_API + SAVE_BATCH)
R saveBatch(@RequestBody List<VideoSyncDTO> 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);
}

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

@ -3,6 +3,9 @@ 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
@ -32,4 +35,11 @@ public interface IAuthClient {
* @return 鉴权结果
*/
R deptAuth(String userId,String deptId);
/**
* 获取用户权限数据
* @param userId 用户ID
* @return 权限数据
*/
R<Map<String, String[]>> getAuthData(String userId);
}

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

@ -14,7 +14,7 @@ public class DataItemVO implements Serializable {
private String name;
@JSONField(name = "id")
@JSONField(name = "itemId")
private String attrId;
@JSONField(name = "record_name")

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

@ -1,5 +1,6 @@
package com.hnac.hzims.bigmodel.interactive.vo;
import com.alibaba.fastjson.annotation.JSONField;
import lombok.Data;
import java.io.Serializable;
@ -12,9 +13,11 @@ import java.io.Serializable;
public class SelectionVO implements Serializable {
/**选项ID**/
private String id;
@JSONField(name = "item_id")
private String itemId;
/**选项名称**/
private String name;
@JSONField(name = "item_name")
private String itemName;
}

35
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<VideoSyncDTO> 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;
}
}

16
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 {
}

6
hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/datasource/controller/DataSourceExecuteController.java → hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/business/control/DataSourceExecuteController.java

@ -1,8 +1,8 @@
package com.hnac.hzims.bigmodel.datasource.controller;
package com.hnac.hzims.bigmodel.business.control;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.hnac.hzims.bigmodel.datasource.service.DataSourceService;
import com.hnac.hzims.bigmodel.datasource.vo.SqlVO;
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;

5
hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/data/controller/RemoteController.java → hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/business/control/RemoteController.java

@ -1,13 +1,12 @@
package com.hnac.hzims.bigmodel.data.controller;
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.data.service.RemoteService;
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 lombok.extern.slf4j.Slf4j;
import org.springblade.core.tool.api.R;
import org.springblade.system.dto.ControlDTO;
import org.springframework.web.bind.annotation.PostMapping;

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

@ -9,8 +9,11 @@ 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
@ -23,6 +26,11 @@ public class AuthClient implements IAuthClient {
private final AuthenticationService authenticationService;
/**
* 设备控制鉴权
* @param req 遥控信息
* @return 鉴权结果
*/
@Override
public R remoteAuth(ControlDeviceAuthDTO req) {
// 若站点不为空 则对站点进行鉴权
@ -37,15 +45,43 @@ public class AuthClient implements IAuthClient {
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<DeptStationDTO> 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<Map<String,String[]>> getAuthData(String userId) {
Map<String,String[]> result = new HashMap<>(2);
List<DeptStationDTO> 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);
}
}

27
hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/business/service/AuthenticationService.java

@ -1,8 +1,6 @@
package com.hnac.hzims.bigmodel.business.service;
import com.google.common.collect.Lists;
import com.hnac.hzims.bigmodel.entity.FunctionEntity;
import com.hnac.hzims.bigmodel.function.service.IFunctionService;
import com.hnac.hzims.bigmodel.interactive.constants.ProjectRemoteTypeEnum;
import com.hnac.hzims.bigmodel.interactive.vo.SessionContentVO;
import com.hnac.hzims.bigmodel.websocket.constants.RedisKeyConstants;
@ -26,7 +24,6 @@ import org.springframework.util.Assert;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;
/**
* @Author: huangxing
@ -37,8 +34,6 @@ import java.util.stream.Collectors;
public class AuthenticationService {
private final IDeptClient deptClient;
private final IFunctionService functionService;
private final IUserClient userClient;
private final ProjectClient projectClient;
private final IRemoteClient remoteClient;
private final RedisTemplate redisTemplate;
@ -50,7 +45,7 @@ public class AuthenticationService {
*/
public Boolean stationAuthentication(String stationId, String userId) {
List<DeptStationDTO> deptStationDTOList = this.getStationPermissionsById(userId);
return deptStationDTOList.stream().map(DeptStationDTO::getStationId).anyMatch(s -> stationId.equals(s));
return deptStationDTOList.stream().map(DeptStationDTO::getStationId).anyMatch(stationId::equals);
}
/**
@ -58,15 +53,15 @@ public class AuthenticationService {
* @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<Boolean> authenticationR = userClient.permissionMenuById(Long.valueOf(userId), function.getRoute());
Assert.isTrue(authenticationR.isSuccess() && authenticationR.getData(), () -> {
throw new ServiceException("人员菜单鉴权失败!");
});
}
}
// 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<Boolean> authenticationR = userClient.permissionMenuById(Long.valueOf(userId), function.getRoute());
// Assert.isTrue(authenticationR.isSuccess() && authenticationR.getData(), () -> {
// throw new ServiceException("人员菜单鉴权失败!");
// });
// }
// }
/**
* 遥控鉴权
@ -97,7 +92,7 @@ public class AuthenticationService {
});
CtrlAuth ctrlAuth = authOptional.get();
// 如限制机器发送遥控指令
if(ctrlAuth.getIsLimitMachine().intValue() == 1) {
if(ctrlAuth.getIsLimitMachine() == 1) {
SessionContentVO sessionContent = (SessionContentVO) redisTemplate.opsForHash().get(RedisKeyConstants.SESSION_CONTENT_KEY, sessionId);
Assert.isTrue(Func.isNotEmpty(sessionContent),() -> {
throw new ServiceException("获取问题机器码失败,校验不通过!");

13
hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/datasource/service/DataSourceService.java → hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/business/service/DataSourceService.java

@ -1,26 +1,19 @@
package com.hnac.hzims.bigmodel.datasource.service;
package com.hnac.hzims.bigmodel.business.service;
import com.baomidou.dynamic.datasource.toolkit.DynamicDataSourceContextHolder;
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
import com.google.common.collect.Lists;
import com.hnac.hzims.bigmodel.datasource.vo.SqlVO;
import com.hnac.hzims.bigmodel.datasource.vo.TableAuthVO;
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.springblade.core.tool.utils.CollectionUtil;
import org.springblade.core.tool.utils.StringUtil;
import org.springframework.jdbc.core.JdbcTemplate;
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.UUID;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
/**
* @Author: huangxing

2
hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/data/service/HistoryDataService.java → hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/business/service/HistoryDataService.java

@ -1,4 +1,4 @@
package com.hnac.hzims.bigmodel.data.service;
package com.hnac.hzims.bigmodel.business.service;
import com.alibaba.fastjson.JSON;
import com.google.common.collect.Lists;

2
hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/data/service/RemoteService.java → hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/business/service/RemoteService.java

@ -1,4 +1,4 @@
package com.hnac.hzims.bigmodel.data.service;
package com.hnac.hzims.bigmodel.business.service;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;

2
hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/datasource/vo/SqlVO.java → hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/business/vo/SqlVO.java

@ -1,4 +1,4 @@
package com.hnac.hzims.bigmodel.datasource.vo;
package com.hnac.hzims.bigmodel.business.vo;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;

2
hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/datasource/vo/TableAuthVO.java → hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/business/vo/TableAuthVO.java

@ -1,4 +1,4 @@
package com.hnac.hzims.bigmodel.datasource.vo;
package com.hnac.hzims.bigmodel.business.vo;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;

73
hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/function/controller/FunctionController.java

@ -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("/updateById")
@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>> list(FunctionEntity req) {
return R.data(functionService.list(Condition.getQueryWrapper(BeanUtil.toMap(req),FunctionEntity.class)));
}
@GetMapping("/page")
@ApiOperation("分页查询")
@ApiOperationSupport(order = 4)
public R<IPage<FunctionEntity>> page(FunctionEntity req, Query query) {
QueryWrapper<FunctionEntity> 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)));
}
}

74
hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/function/controller/FunctionParamController.java

@ -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>> list(FuncParamEntity req) {
return R.data(funcParamService.list(Condition.getQueryWrapper(BeanUtil.toMap(req),FuncParamEntity.class)));
}
@GetMapping("/page")
@ApiOperation("分页查询")
@ApiOperationSupport(order = 4)
public R<IPage<FuncParamEntity>> page(FuncParamEntity req, Query query) {
QueryWrapper<FuncParamEntity> 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)));
}
}

11
hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/function/mapper/FuncParamMapper.java

@ -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<FuncParamEntity> {
}

12
hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/function/mapper/FunctionMapper.java

@ -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<FunctionEntity> {
}

21
hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/function/service/IFuncParamService.java

@ -1,21 +0,0 @@
package com.hnac.hzims.bigmodel.function.service;
import com.hnac.hzims.bigmodel.entity.FuncParamEntity;
import org.springblade.core.mp.base.BaseService;
import java.util.List;
/**
* @Author: huangxing
* @Date: 2024/04/26 11:12
*/
public interface IFuncParamService extends BaseService<FuncParamEntity> {
/**
* 根据函数ID获取参数列表
* @param funcId 函数ID
* @return 参数列表
*/
List<FuncParamEntity> getParamsByFuncId(Long funcId);
}

14
hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/function/service/IFunctionService.java

@ -1,14 +0,0 @@
package com.hnac.hzims.bigmodel.function.service;
import com.hnac.hzims.bigmodel.entity.FunctionEntity;
import org.springblade.core.mp.base.BaseService;
/**
* @Author: huangxing
* @Date: 2024/04/26 11:08
*/
public interface IFunctionService extends BaseService<FunctionEntity> {
FunctionEntity getFunctionByCode(String code);
}

28
hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/function/service/impl/FuncParamServiceImpl.java

@ -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 org.springblade.core.mp.base.BaseServiceImpl;
import org.springframework.stereotype.Service;
import java.util.List;
/**
* @Author: huangxing
* @Date: 2024/04/26 11:13
*/
@Service
@Slf4j
public class FuncParamServiceImpl extends BaseServiceImpl<FuncParamMapper, FuncParamEntity> implements IFuncParamService {
@Override
public List<FuncParamEntity> getParamsByFuncId(Long funcId) {
LambdaQueryWrapper<FuncParamEntity> queryWrapper = Wrappers.<FuncParamEntity>lambdaQuery().eq(FuncParamEntity::getFuncId, funcId);
return this.list(queryWrapper);
}
}

27
hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/function/service/impl/FunctionServiceImpl.java

@ -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 org.springblade.core.mp.base.BaseServiceImpl;
import org.springframework.stereotype.Service;
/**
* @Author: huangxing
* @Date: 2024/04/26 11:09
*/
@Service
@Slf4j
@AllArgsConstructor
public class FunctionServiceImpl extends BaseServiceImpl<FunctionMapper, FunctionEntity> implements IFunctionService {
@Override
public FunctionEntity getFunctionByCode(String code) {
LambdaQueryWrapper<FunctionEntity> queryWrapper = Wrappers.<FunctionEntity>lambdaQuery().eq(FunctionEntity::getCode, code);
return this.getOne(queryWrapper);
}
}

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

@ -2,15 +2,14 @@ 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.datasource.service.DataSourceService;
import com.hnac.hzims.bigmodel.datasource.vo.SqlVO;
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.hzims.bigmodel.interactive.vo.ResolveResultVO;
import com.hnac.hzinfo.log.annotation.Business;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

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

@ -1,6 +1,7 @@
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;
@ -19,8 +20,11 @@ public interface IHznlmInvokeService {
* @param userId 提问人ID
* @return 提问结果
*/
@Deprecated
void ask(String question, String sessionId, String userId);
void ask(QuestionDTO question);
/**
* 特殊问题
* @param sessionId 会话ID
@ -28,8 +32,11 @@ public interface IHznlmInvokeService {
* @param extra 特殊问题内容
* @return 提问结果
*/
@Deprecated
void specialAsk(String sessionId, String userId, Map<String,Object> extra);
void specialAsk(QuestionDTO questionDTO);
/**
* 知识库问题
* @param question 问题名称
@ -37,8 +44,11 @@ public interface IHznlmInvokeService {
* @param userId 提问人ID
* @param knowledge 知识库名称
*/
@Deprecated
void knowledgeAsk(String question, String sessionId, String userId, String knowledge);
void knowledgeAsk(QuestionDTO questionDTO);
/**
* 删除对话记录
* @param sessionId 会话ID

58
hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/IInteractiveService.java

@ -1,58 +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 com.hnac.hzims.bigmodel.interactive.vo.ExtraVO;
import org.springblade.core.tool.api.R;
import org.springblade.system.dto.ControlDTO;
import java.util.List;
import java.util.Map;
/**
* @Author: huangxing
* @Date: 2024/04/26 14:51
*/
@Deprecated
public interface IInteractiveService {
ExtraVO resolveStations(String startTime, String endTime, String type, String enumType);
R resolve(ModelFunctionReq req);
R ask(String question,String sessionId,String userId);
R specialAsk(String sessionId,String userId,Map<String,Object> extra);
void updateVideo(Map<String,Object> request);
Boolean updateCanvas(Map<String,Object> request);
void updateFault(Map<String,Object> request);
List<AnswerVO> getAnswerBySessionIds(String sessionIds);
Boolean authentication(String stationId, String userId, String func,String sessionId);
Boolean removeSessionId(String sessionId);
/**
* 发起知识库问答
* @param question 问题
* @param sessionId 会话id
* @param userId 用户id
* @param knowledge 知识库名称
* @return 发起结果
*/
R knowledgeAsk(String question, String sessionId, String userId, String knowledge);
R<Object> sendRemoteControl(ControlDTO operate);
Double generation(String stationId, String startTime, String endTime);
/**
* 获取热点问题
* @return 热点问题
*/
List hotQuestions();
}

17
hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/IJumpPageService.java

@ -1,17 +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
*/
@Deprecated
public interface IJumpPageService {
String dealJumpTypeFunction(FunctionEntity function, Map<String,String> args);
}

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

@ -1,7 +1,7 @@
package com.hnac.hzims.bigmodel.interactive.service.impl;
import com.google.common.collect.Lists;
import com.hnac.hzims.bigmodel.data.service.HistoryDataService;
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;

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

@ -52,13 +52,13 @@ public class CanvasResolveServiceImpl implements IResolveService {
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"};
final String[] SCADA_PARAMS_SOLVE = new String[]{"picResource","context","stationNum","projectId","taskId","name","itemId"};
String canvasHost = ParamCache.getValue(ParamKeyConstants.CANVAS_HOST);
// 将ID解析为
Map<String, String> resolveMap = this.resolve(id, SCADA_PARAMS_SOLVE);
R<StationEntity> 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"));
Integer picResource = Integer.valueOf(resolveMap.get("picResource"));
int picResource = Integer.parseInt(resolveMap.get("picResource"));
Map<String,Object> extraParams = new HashMap<>(1);
extraParams.put("picResource",picResource);
extraVO.setParams(extraParams);
@ -79,7 +79,7 @@ public class CanvasResolveServiceImpl implements IResolveService {
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}&name={name}", resolveMap));
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类型之外,无法解析路由");

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

@ -3,16 +3,20 @@ 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;
@ -33,10 +37,10 @@ import java.util.Map;
@Slf4j
public class HznlmInvokeServiceImpl implements IHznlmInvokeService {
private final AuthenticationService authenticationService;
private final BigModelInvokeUrl bigModelInvokeUrl;
private final BladeLogger logger;
private final SessionRedisManager sessionRedisManager;
private final IAuthClient authClient;
@Value("${fdp.host}")
private String fdpHost;
@ -44,8 +48,8 @@ public class HznlmInvokeServiceImpl implements IHznlmInvokeService {
@Override
public void ask(String question, String sessionId, String userId) {
Map<String,Object> params = new HashMap<>();
params.put("id",sessionId);
params.put("userid", userId);
params.put("chat_id",sessionId);
params.put("user_id", userId);
params.put("query",question);
Map<String, String[]> authDataIds = this.getAuthDataIds(userId);
params.putAll(authDataIds);
@ -54,10 +58,16 @@ public class HznlmInvokeServiceImpl implements IHznlmInvokeService {
}
@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<String, Object> extra) {
Map<String,Object> params = new HashMap<>();
params.put("id",sessionId);
params.put("userid", userId);
params.put("chat_id",sessionId);
params.put("user_id", userId);
params.put("extra",extra);
Map<String, String[]> authDataIds = this.getAuthDataIds(userId);
params.putAll(authDataIds);
@ -67,10 +77,16 @@ public class HznlmInvokeServiceImpl implements IHznlmInvokeService {
}
@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<String,Object> params = new HashMap<>();
params.put("id", sessionId);
params.put("userid", userId);
params.put("chat_id", sessionId);
params.put("user_id", userId);
params.put("query", question);
params.put("knowledge", knowledge);
Map<String, String[]> authDataIds = this.getAuthDataIds(userId);
@ -80,6 +96,12 @@ public class HznlmInvokeServiceImpl implements IHznlmInvokeService {
}
@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
@ -87,6 +109,7 @@ public class HznlmInvokeServiceImpl implements IHznlmInvokeService {
sessionRedisManager.removeSessionId(sessionId);
}
@Override
public void askAbort(String sessionId) {
Map<String,Object> params = new HashMap<>();
params.put("id",sessionId);
@ -107,20 +130,14 @@ public class HznlmInvokeServiceImpl implements IHznlmInvokeService {
@Override
public List<AnswerVO> getAnswerBySessionIds(String sessionIds) {
Map<String,Object> params = new HashMap<>();
params.put("ids",Func.toStrList(",",sessionIds).toArray());
List<AnswerVO> answerVOList = RequestClientUtil.postCall(fdpHost + bigModelInvokeUrl.getAssistantStatus(), params, new TypeReference<List<AnswerVO>>(){});
return answerVOList;
params.put("chat_ids",Func.toStrList(",",sessionIds).toArray());
return RequestClientUtil.postCall(fdpHost + bigModelInvokeUrl.getAssistantStatus(), params, new TypeReference<List<AnswerVO>>(){});
}
private Map<String,String[]> getAuthDataIds(String userId) {
List<DeptStationDTO> authDatas = authenticationService.getStationPermissionsById(userId);
Map<String, String[]> result = new HashMap<>(2);
String[] stationIds = authDatas.stream().map(DeptStationDTO::getStationId)
.filter(StringUtil::isNotBlank).toArray(String[]::new);
String[] projectIds = authDatas.stream().map(DeptStationDTO::getDeptId)
.filter(Func::isNotEmpty).map(String::valueOf).toArray(String[]::new);
result.put("stationids", stationIds);
result.put("projectids", projectIds);
R<Map<String, String[]>> authDataR = authClient.getAuthData(userId);
result.putAll(authDataR.getData());
return result;
}
}

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

@ -1,144 +0,0 @@
package com.hnac.hzims.bigmodel.interactive.service.impl;
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 com.hnac.hzims.operational.station.entity.StationEntity;
import com.hnac.hzims.operational.station.feign.IStationClient;
import lombok.RequiredArgsConstructor;
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.StringUtil;
import org.springframework.stereotype.Component;
import org.springframework.util.Assert;
import java.util.*;
import java.util.stream.IntStream;
/**
* @Author: huangxing
* @Date: 2024/04/30 11:38
*/
@Component
@RequiredArgsConstructor
@Deprecated
public class JumpRouteJoinStrategy {
private final IStationClient stationClient;
public static String[] SCADA_PARAMS_SOLVE = new String[]{"picResource","context","stationNum","projectId","taskId","name","id"};
/**
* 解析大模型传参
* @param args 大模型传参
* @return 跳转path所需要的参数
*/
public ExtraVO resolve(FunctionEntity function,Map<String,String> args) {
FuncRouteEnum routeEnum = FuncRouteEnum.getEnumByFuncCode(function.getCode());
if(Func.isNotEmpty(routeEnum)) {
switch(routeEnum) {
case OPEN_CANVAS:
return this.getScadaExtra(args,function);
default:
break;
}
}
return null;
}
public ExtraVO getScadaExtra(Map<String,String> args,FunctionEntity function) {
// 跳转页面逻辑
ExtraVO extraVO = new ExtraVO();
extraVO.setImmediatelyJump(true);
extraVO.setFunc(FuncRouteEnum.OPEN_CANVAS.getFunc());
Map<String, String> params = this.scadaResolve(args);
// 根据hz3000画面版本获取path
Integer picResource = Integer.valueOf(params.get("picResource"));
JSONObject pathObject = JSONObject.parseObject(function.getPath());
R<StationEntity> stationR = stationClient.getStationByCode(params.get("projectId"));
extraVO.setLabel(Optional.ofNullable(stationR).filter(r -> r.isSuccess()).map(R::getData).map(StationEntity::getName).orElse("") + "_" + params.get("name"));
Map<String,Object> extraParams = new HashMap<>(1);
extraParams.put("picResource",picResource);
extraVO.setParams(extraParams);
// 云组态
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 实时画面路径拼接所需参数
*/
public Map<String,String> scadaResolve(Map<String,String> args) {
String params = args.get("canvas_id");
// 参数格式为:picResource^context^stationNum^projectId^taskId^name^id
return this.resolve(params,SCADA_PARAMS_SOLVE);
}
public Map<String,String> resolve(String paramsStr,String... keys) {
Map<String,String> result = new HashMap<>();
List<String> 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<String,String> params) {
Set<Map.Entry<String, String>> entries = params.entrySet();
// 替换path中变量
for (Map.Entry<String, String> 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;
}
}

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

@ -1,73 +0,0 @@
package com.hnac.hzims.bigmodel.interactive.service.impl;
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 com.hnac.hzims.operational.station.entity.StationVideoTypeEntity;
import com.hnac.hzims.operational.station.feign.IStationVideoTypeClient;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
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.Component;
import java.util.HashMap;
import java.util.Map;
/**
* @Author: huangxing
* @Date: 2024/05/09 08:56
*/
@Component
@Slf4j
@AllArgsConstructor
@Deprecated
public class ParamStrategy {
private final IStationVideoTypeClient videoClient;
/**
* 解析发送参数方式函数
* @param function 函数
* @param args 大模型识别参数
* @return 前端传参EXTRA
*/
public ExtraVO resolve(FunctionEntity function, Map<String,String> args) {
FuncRouteEnum routeEnum = FuncRouteEnum.getEnumByFuncCode(function.getCode());
if(Func.isNotEmpty(routeEnum)) {
switch(routeEnum) {
case OPEN_VIDEO:
return this.getVideoExtra(args);
default:
break;
}
}
return null;
}
public ExtraVO getVideoExtra(Map<String,String> args) {
// 跳转页面逻辑
ExtraVO extraVO = new ExtraVO();
String id = args.get("canvas_id");
if(StringUtil.isNotBlank(id) && Func.isNotEmpty(id)) {
R<StationVideoTypeEntity> 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<String,Object> 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;
}
}

4
hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/vo/AnswerVO.java

@ -24,11 +24,11 @@ import java.io.Serializable;
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代表已完成")

2
hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/vo/RemoteParamVO.java

@ -14,7 +14,7 @@ import java.io.Serializable;
@EqualsAndHashCode
public class RemoteParamVO implements Serializable {
@JSONField(name = "id")
@JSONField(name = "itemId")
private String funcId;
@JSONField(name = "yk_name")

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

@ -1,7 +1,6 @@
package com.hnac.hzims.bigmodel.maintenance.service;
import com.hnac.hzims.bigmodel.datasource.service.DataSourceService;
import lombok.AllArgsConstructor;
import com.hnac.hzims.bigmodel.business.service.DataSourceService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

106
hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/question/dto/MessageDTO.java

@ -0,0 +1,106 @@
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 Object selection;
/**
* 大模型函数
*/
private String func;
/**
* 特殊问题参数
*/
private Map<String,Object> 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;
}

78
hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/question/dto/QuestionDTO.java

@ -0,0 +1,78 @@
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<String, Object> extra;
private Object data;
/**
* 是否允许大模型查询数据,默认为 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;
}

123
hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/question/service/QuestionHandlerService.java

@ -0,0 +1,123 @@
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(messageDTO.getFunc());
switch (funcEnum) {
case CHOOSE_STATION:
case CHOOSE_YC:
case CHOOSE_FAULT:
case CHOOSE_YK:
question.setData(messageDTO.getSelection());
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.getSelection();
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.getSelection();
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);
}
}
}

2
hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/schedule/FrontEndInteractiveSchedule.java

@ -48,7 +48,7 @@ public class FrontEndInteractiveSchedule {
private final BladeLogger logger;
@XxlJob(GET_INTERACTIVE_RESULT)
public ReturnT getInteractiveResult(String params) {
public ReturnT<String> getInteractiveResult(String params) {
List<String> sessionIds = sessionRedisManager.getSessionIds();
if(CollectionUtil.isEmpty(sessionIds)){
XxlJobLogger.log("问题都已经回答完毕!");

18
hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/utils/RequestClientUtil.java

@ -19,14 +19,15 @@ import java.util.Map;
@Slf4j
public class RequestClientUtil {
/**
* 无返回结果远程调用http接口
* @param url 接口url
* @param body 传参body
*/
public static void postCall(String url, Map body) {
public static void postCall(String url, String body) {
log.info("开始远程调用{}接口",url);
HttpResponse response = HttpRequest.post(url).body(JSON.toJSONString(body)).execute();
HttpResponse response = HttpRequest.post(url).body(body).execute();
log.info("远程调用{}接口结束",url);
Assert.isTrue(response.getStatus() == HttpServletResponse.SC_OK, () -> {
throw new ServiceException("远程调用接口" + url + "失败!");
@ -34,6 +35,19 @@ public class RequestClientUtil {
}
/**
* 无返回结果远程调用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 传参

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

@ -2,19 +2,17 @@ package com.hnac.hzims.bigmodel.websocket.handler;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
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.factory.ResolveFactory;
import com.hnac.hzims.bigmodel.interactive.service.IHznlmInvokeService;
import com.hnac.hzims.bigmodel.interactive.service.impl.JumpRouteJoinStrategy;
import com.hnac.hzims.bigmodel.interactive.service.impl.ParamStrategy;
import com.hnac.hzims.bigmodel.interactive.service.IResolveService;
import com.hnac.hzims.bigmodel.interactive.vo.*;
import com.hnac.hzims.bigmodel.interactive.service.IInteractiveService;
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.tool.api.R;
import org.springblade.core.tool.utils.Func;
import org.springblade.core.tool.utils.SpringUtil;
import org.springframework.beans.factory.annotation.Autowired;
@ -26,7 +24,6 @@ import org.springframework.web.socket.WebSocketSession;
import org.springframework.web.socket.handler.TextWebSocketHandler;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.TimeUnit;
@ -64,8 +61,8 @@ public class InteractiveHandler extends TextWebSocketHandler {
@Override
protected void handleTextMessage(WebSocketSession session, TextMessage message) {
JSONObject messageJSON = JSONObject.parseObject(message.getPayload());
if("0".equals(messageJSON.getString("type"))) {
MessageDTO messageDTO = JSONObject.parseObject(message.getPayload(), MessageDTO.class);
if("0".equals(messageDTO.getType())) {
// 接收心跳消息,返回一条心跳消息
try {
session.sendMessage(InteractiveSessionManager.getTextMessage("0","收到心跳消息"));
@ -73,14 +70,33 @@ public class InteractiveHandler extends TextWebSocketHandler {
throw new RuntimeException(e);
}
} else {
String sessionId = InteractiveSessionManager.getEntryBySession(session).getKey();
if(messageJSON.containsKey("content")) {
// 将发送参数存入redis
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,sessionId,messageJSON.getObject("content", SessionContentVO.class));
redisTemplate.opsForHash().put(RedisKeyConstants.SESSION_CONTENT_KEY,chatId,messageDTO.getContent());
}
this.handleMessage(messageJSON, sessionId);
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) {
@ -129,18 +145,16 @@ public class InteractiveHandler extends TextWebSocketHandler {
private void handleVideoChoose(JSONObject messageContext,String sessionId) {
InteractiveWsService wsService = SpringUtil.getBean(InteractiveWsService.class);
try {
ParamStrategy strategy = SpringUtil.getBean(ParamStrategy.class);
VideoSelectionVO selection = messageContext.getObject("selection", VideoSelectionVO.class);
String videoId = selection.getId();
Map<String,String> param = new HashMap<>(1);
param.put("canvas_id",videoId);
ExtraVO videoExtras = strategy.getVideoExtra(param);
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.getName());
answerVO.setQuery(selection.getItemName());
answerVO.setRunning(0);
answerVO.setStatus(0);
answerVO.setAnswer("已成功打开"+selection.getName()+"视频");
answerVO.setAnswer("已成功打开"+selection.getItemName()+"视频");
answerVO.setExtras(new Object[]{JSON.toJSONString(videoExtras)});
TextMessage textMessage = InteractiveSessionManager.getTextMessage("1", JSON.toJSONString(answerVO));
wsService.sendMessage(sessionId,textMessage);
@ -158,19 +172,15 @@ public class InteractiveHandler extends TextWebSocketHandler {
private void handleScadaChoose(JSONObject messageContext,String sessionId) {
InteractiveWsService wsService = SpringUtil.getBean(InteractiveWsService.class);
try {
JumpRouteJoinStrategy strategy = SpringUtil.getBean(JumpRouteJoinStrategy.class);
ScadaSelectionVO selection = messageContext.getObject("selection", ScadaSelectionVO.class);
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.getFunc());
ExtraVO scadaExtra = strategy.getScadaExtra(param, function);
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.getName());
answerVO.setAnswer("已成功打开"+selection.getName()+"实时画面");
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);

Loading…
Cancel
Save