Browse Source

add:打开视频、大模型打开视频指令同步

zhongwei
haungxing 7 months ago
parent
commit
1087377b2e
  1. 3
      hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/interactive/constants/FunctionConstants.java
  2. 6
      hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/interactive/vo/ExtraVO.java
  3. 5
      hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/station/feign/IStationVideoTypeClient.java
  4. 6
      hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/station/feign/IStationVideoTypeClientFallback.java
  5. 2
      hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/configuration/BigModelInvokeUrl.java
  6. 3
      hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/IInteractiveService.java
  7. 14
      hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/IParamsService.java
  8. 21
      hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/InteractiveServiceImpl.java
  9. 2
      hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/JumpRouteJoinStrategy.java
  10. 69
      hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/ParamStrategy.java
  11. 35
      hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/ParamsServiceImpl.java
  12. 20
      hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/vo/UpdateStationVO.java
  13. 25
      hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/vo/UpdateUsualVO.java
  14. 62
      hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/schedule/InteractiveSchedule.java
  15. 11
      hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/feign/StationVideoTypeClient.java
  16. 2
      hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/service/IStationVideoTypeService.java
  17. 5
      hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/service/impl/StationVideoTypeServiceImpl.java

3
hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/interactive/constants/FunctionConstants.java

@ -15,7 +15,8 @@ public interface FunctionConstants {
@AllArgsConstructor
enum TypeEnum {
/**跳转页面**/
JUMP("1")
JUMP("1"),
PARAMS("2")
;
@Getter
private String type;

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

@ -5,6 +5,7 @@ import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.io.Serializable;
import java.util.Map;
/**
* @Author: huangxing
@ -14,7 +15,7 @@ import java.io.Serializable;
@ApiModel("响应内容")
public class ExtraVO implements Serializable {
@ApiModelProperty("交互类型 1:打开页面,2:打开链接")
@ApiModelProperty("交互类型 1:打开页面,2:打开链接,3:参数传递")
private String type;
@ApiModelProperty("若为弹窗,则返回路由")
@ -26,4 +27,7 @@ public class ExtraVO implements Serializable {
@ApiModelProperty("是否立即跳转")
private boolean isImmediatelyJump = true;
@ApiModelProperty("附带参数")
private Map<String,Object> params;
}

5
hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/station/feign/IStationVideoTypeClient.java

@ -18,10 +18,15 @@ public interface IStationVideoTypeClient {
String API_PREFIX = "/feign/station/videoType";
String LIST_BY_STATION_ID = API_PREFIX + "/listByStationId";
String LIST = API_PREFIX + "/list";
String GET_BY_ID = API_PREFIX + "/getById";
String GET_RTSP_ADDRESS_BY_ID = API_PREFIX + "/getRtspAddressById";
@PostMapping(LIST_BY_STATION_ID)
List<StationVideoTypeEntity> listByStationId(@RequestParam("stationId") String stationId);
@GetMapping(LIST)
R<List<StationVideoTypeEntity>> list(StationVideoTypeEntity req);
@GetMapping(GET_BY_ID)
R<StationVideoTypeEntity> getById(@RequestParam Long id);
}

6
hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/station/feign/IStationVideoTypeClientFallback.java

@ -21,4 +21,10 @@ public class IStationVideoTypeClientFallback implements IStationVideoTypeClient
public R<List<StationVideoTypeEntity>> list(StationVideoTypeEntity req) {
return R.fail("远程调用失败!");
}
@Override
public R<StationVideoTypeEntity> getById(Long id) {
return R.fail("远程调用失败!");
}
}

2
hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/configuration/BigModelInvokeUrl.java

@ -19,4 +19,6 @@ public class BigModelInvokeUrl {
private String deleteAssistant;
private String updateVideo;
}

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

@ -8,6 +8,7 @@ import org.springframework.web.bind.annotation.RequestParam;
import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;
/**
* @Author: huangxing
@ -19,6 +20,8 @@ public interface IInteractiveService {
R ask(String question,String sessionId,String userId);
void updateVideo(Map<String,Object> request);
List<AnswerVO> getAnswerBySessionIds(String sessionIds);
Boolean authentication(String stationId, String userId, String funcCode);

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

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

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

@ -11,6 +11,7 @@ import com.hnac.hzims.bigmodel.function.service.IFunctionService;
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 lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
@ -49,6 +50,8 @@ public class InteractiveServiceImpl implements IInteractiveService {
private final IJumpPageService jumpPageService;
private final IParamsService paramsService;
private final IFunctionService functionService;
private final BigModelInvokeUrl bigModelInvokeUrl;
@ -72,11 +75,14 @@ public class InteractiveServiceImpl implements IInteractiveService {
switch (typeEnum) {
// 页面跳转
case JUMP:
String extra = jumpPageService.dealJumpTypeFunction(function, req.getFunctionArgs());
Assert.isTrue(StringUtil.isNotBlank(extra) && Func.isNotEmpty(extra), () -> {
String jumpExtra = jumpPageService.dealJumpTypeFunction(function, req.getFunctionArgs());
Assert.isTrue(StringUtil.isNotBlank(jumpExtra) && Func.isNotEmpty(jumpExtra), () -> {
throw new ServiceException("解析" + function.getName() + "函数失败!");
});
return R.data(extra);
return R.data(jumpExtra);
case PARAMS:
String paramExtra = paramsService.dealJumpTypeFunction(function, req.getFunctionArgs());
return R.data(paramExtra);
default:
throw new ServiceException("函数解析失败!");
}
@ -111,6 +117,15 @@ public class InteractiveServiceImpl implements IInteractiveService {
}
@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 List<AnswerVO> getAnswerBySessionIds(String sessionIds) {
Map<String,Object> params = new HashMap<>();
params.put("ids",Func.toStrList(",",sessionIds).toArray());

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

@ -36,8 +36,6 @@ public class JumpRouteJoinStrategy {
switch(routeEnum) {
case OPEN_SCADA:
return this.getScadaExtra(args,function);
case OPEN_VIDEO:
return this.getVideoExtra(args,function);
default:
break;
}

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

@ -0,0 +1,69 @@
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
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;
}
private 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());
Map<String,Object> params = new HashMap<>();
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;
}
}

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

@ -0,0 +1,35 @@
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
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);
}
}

20
hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/vo/UpdateStationVO.java

@ -0,0 +1,20 @@
package com.hnac.hzims.bigmodel.interactive.vo;
import lombok.Data;
import java.io.Serializable;
/**
* @Author: huangxing
* @Date: 2024/05/09 09:50
*/
@Data
public class UpdateStationVO implements Serializable {
/**站点ID**/
private String id;
/**站点名称**/
private String name;
}

25
hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/vo/UpdateUsualVO.java

@ -0,0 +1,25 @@
package com.hnac.hzims.bigmodel.interactive.vo;
import com.alibaba.fastjson.annotation.JSONField;
import lombok.Data;
import java.io.Serializable;
/**
* @Author: huangxing
* @Date: 2024/05/09 09:53
*/
@Data
public class UpdateUsualVO implements Serializable {
/**站点ID**/
@JSONField(name = "station_id")
private String stationId;
/**业务ID**/
private String id;
/**业务名称**/
private String name;
}

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

@ -4,9 +4,13 @@ import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.hnac.hzims.bigmodel.interactive.service.IInteractiveService;
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;
@ -25,7 +29,9 @@ import org.springframework.stereotype.Component;
import org.springframework.web.socket.TextMessage;
import org.springframework.web.socket.WebSocketSession;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.stream.Collectors;
@ -54,8 +60,33 @@ public class InteractiveSchedule {
private final ScadaClient scadaClient;
private final IStationClient stationClient;
private final static String HZIMS_BIGMODEL_ASK_KEY = "hzims:bigmodel:ask:key";
// @XxlJob(GET_INTERACTIVE_RESULT)
// public ReturnT execute(String params) {
// String resultKey = ParamCache.getValue(GET_INTERACTIVE_RESULT);
// Set<String> keySet = redisTemplate.keys(resultKey + "*");
// keySet.parallelStream().forEach(key -> {
// // 根据Key获取sessionId
// List<String> keySplits = Func.toStrList(":", key);
// String sessionId = keySplits.get(2);
// // 查询websocket是否存在连接session
// WebSocketSession session = InteractiveSessionManager.get(sessionId);
// if(session == null) {
// return;
// }
// TextMessage message = new TextMessage(JSON.toJSONString(redisTemplate.opsForValue().get(key)));
// Boolean sendResult = wsService.sendMessage(sessionId, message);
// Assert.isTrue(sendResult, () -> {
// throw new ServiceException(key + "推送消息失败,推送消息体为:" + JSON.toJSONString(redisTemplate.opsForValue().get(key)));
// });
// redisTemplate.delete(key);
// });
// return ReturnT.SUCCESS;
// }
@XxlJob(GET_INTERACTIVE_RESULT)
public ReturnT getInteractiveResult(String params) {
Object json = redisTemplate.opsForValue().get(HZIMS_BIGMODEL_ASK_KEY);
@ -85,11 +116,36 @@ public class InteractiveSchedule {
@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()) {
List<StationVideoTypeEntity> stationVideoList = videoListR.getData();
//TODO 同步站点视频指令
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;
}

11
hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/feign/StationVideoTypeClient.java

@ -9,10 +9,7 @@ import com.hnac.hzims.operational.station.service.IStationVideoTypeService;
import lombok.AllArgsConstructor;
import org.springblade.core.log.annotation.ApiLog;
import org.springblade.core.tool.api.R;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
import java.util.List;
@ -38,4 +35,10 @@ public class StationVideoTypeClient implements IStationVideoTypeClient {
QueryWrapper<StationVideoTypeEntity> queryWrapper = Condition.getQueryWrapper(req);
return R.data(stationVideoTypeService.list(queryWrapper));
}
@Override
@GetMapping(GET_BY_ID)
public R<StationVideoTypeEntity> getById(@RequestParam Long id) {
return R.data(stationVideoTypeService.getById(id,0));
}
}

2
hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/service/IStationVideoTypeService.java

@ -81,4 +81,6 @@ public interface IStationVideoTypeService extends BaseService<StationVideoTypeEn
Map getVideoPointByRegion(Long refDept,String regionCode);
String getRtspAddressByVideo(StationVideoTypeEntity req);
}

5
hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/service/impl/StationVideoTypeServiceImpl.java

@ -274,6 +274,11 @@ public class StationVideoTypeServiceImpl extends BaseServiceImpl<StationVideoTyp
return cameras.stream().collect(Collectors.groupingBy(c -> deviceMap.get(c.getString("encodeDevIndexCode"))));
}
@Override
public String getRtspAddressByVideo(StationVideoTypeEntity req) {
return null;
}
private HikVideoAreaTreeVO generateAreaTree(Map<String, List<HikVideoAreaVO>> videoAreaMapByParent,HikVideoAreaVO area) {
HikVideoAreaTreeVO parentTree = BeanUtil.copy(area,HikVideoAreaTreeVO.class);
if(CollectionUtil.isNotEmpty(videoAreaMapByParent.get(area.getIndexCode()))) {

Loading…
Cancel
Save