Browse Source

add:choose_video/choose_canvas函数添加

zhongwei
haungxing 9 months ago
parent
commit
8ea15ba11f
  1. 12
      hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/interactive/constants/StationSelectionVO.java
  2. 2
      hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/interactive/vo/ExtraVO.java
  3. 16
      hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/interactive/vo/ScadaSelectionVO.java
  4. 2
      hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/interactive/vo/SelectionVO.java
  5. 15
      hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/interactive/vo/StationSelectionVO.java
  6. 16
      hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/interactive/vo/VideoSelectionVO.java
  7. 2
      hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/constants/FuncRouteEnum.java
  8. 57
      hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/ExtraResolveStrategyService.java
  9. 11
      hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/JumpRouteJoinStrategy.java
  10. 2
      hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/ParamStrategy.java
  11. 81
      hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/websocket/handler/InteractiveHandler.java

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

@ -1,12 +0,0 @@
package com.hnac.hzims.bigmodel.interactive.constants;
import lombok.Data;
/**
* @Author: huangxing
* @Date: 2024/05/09 16:32
*/
@Data
public class StationSelectionVO extends SelectionVO {
}

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

@ -1,10 +1,8 @@
package com.hnac.hzims.bigmodel.interactive.vo;
import com.hnac.hzims.bigmodel.interactive.constants.SelectionVO;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import net.sf.jsqlparser.statement.select.Select;
import java.io.Serializable;
import java.util.List;

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

@ -0,0 +1,16 @@
package com.hnac.hzims.bigmodel.interactive.vo;
import lombok.Data;
import lombok.EqualsAndHashCode;
import java.io.Serializable;
/**
* @Author: huangxing
* @Date: 2024/05/11 16:21
*/
@Data
@EqualsAndHashCode
public class ScadaSelectionVO extends SelectionVO implements Serializable {
}

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

@ -1,4 +1,4 @@
package com.hnac.hzims.bigmodel.interactive.constants;
package com.hnac.hzims.bigmodel.interactive.vo;
import lombok.Data;

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

@ -0,0 +1,15 @@
package com.hnac.hzims.bigmodel.interactive.vo;
import com.hnac.hzims.bigmodel.interactive.vo.SelectionVO;
import lombok.Data;
import java.io.Serializable;
/**
* @Author: huangxing
* @Date: 2024/05/09 16:32
*/
@Data
public class StationSelectionVO extends SelectionVO implements Serializable {
}

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

@ -0,0 +1,16 @@
package com.hnac.hzims.bigmodel.interactive.vo;
import lombok.Data;
import lombok.EqualsAndHashCode;
import java.io.Serializable;
/**
* @Author: huangxing
* @Date: 2024/05/11 16:20
*/
@Data
@EqualsAndHashCode
public class VideoSelectionVO extends SelectionVO implements Serializable {
}

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

@ -16,6 +16,8 @@ public enum FuncRouteEnum {
OPEN_VIDEO("open_video","打开视频监控"),
DIAGNOSE("diagnose","智能诊断"),
CHOOSE_STATION("choose_station","选择站点"),
CHOOSE_VIDEO("choose_video","选择视频"),
CHOOSE_CANVAS("choose_canvas","选择画面"),
;
@Getter
private String funcCode;

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

@ -5,12 +5,15 @@ 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.StationSelectionVO;
import com.hnac.hzims.bigmodel.interactive.vo.ScadaSelectionVO;
import com.hnac.hzims.bigmodel.interactive.vo.StationSelectionVO;
import com.hnac.hzims.bigmodel.interactive.vo.ExtraVO;
import com.hnac.hzims.bigmodel.interactive.vo.VideoSelectionVO;
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 lombok.AllArgsConstructor;
import lombok.Data;
import org.springblade.core.tool.api.R;
import org.springblade.core.tool.utils.Func;
import org.springblade.core.tool.utils.StringUtil;
@ -31,6 +34,8 @@ import java.util.stream.Collectors;
public class ExtraResolveStrategyService {
private final IStationClient stationClient;
private final IStationVideoTypeClient videoTypeClient;
private final JumpRouteJoinStrategy jumpRouteJoinStrategy;
/**
* 解析DFP返回extra
@ -39,7 +44,7 @@ public class ExtraResolveStrategyService {
*/
public ExtraVO resolve(String extraStr) {
JSONObject extra = JSONObject.parseObject(extraStr);
String functionCode = Optional.ofNullable(extra.get("func")).map(String::valueOf).orElse("");
String functionCode = Optional.ofNullable(extra.get("func")).map(String::valueOf).orElse("ttps");
if(StringUtil.isNotBlank(functionCode)) {
FuncRouteEnum funcRouteEnum = FuncRouteEnum.getEnumByFuncCode(functionCode);
switch (funcRouteEnum) {
@ -47,6 +52,10 @@ public class ExtraResolveStrategyService {
return this.resolveDiagnose(extra);
case CHOOSE_STATION:
return this.resolveChooseStation(extra);
case CHOOSE_VIDEO:
return this.resolveChooseVideo(extra);
case CHOOSE_CANVAS:
return this.resolveChooseScada(extra);
default:
break;
}
@ -96,4 +105,46 @@ public class ExtraResolveStrategyService {
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.setFuncCode(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.setFuncCode(FuncRouteEnum.CHOOSE_CANVAS.getFuncCode());
result.setSpecial(true);
result.setSelection(selections);
}
result.setType(FunctionConstants.TypeEnum.CHOOSE.getType());
return result;
}
}

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

@ -25,6 +25,8 @@ import java.util.stream.IntStream;
@Component
public class JumpRouteJoinStrategy {
public static String[] SCADA_PARAMS_SOLVE = new String[]{"picResource","context","stationNum","projectId","taskId","name","id"};
/**
* 解析大模型传参
* @param args 大模型传参
@ -43,7 +45,7 @@ public class JumpRouteJoinStrategy {
return null;
}
private ExtraVO getScadaExtra(Map<String,String> args,FunctionEntity function) {
public ExtraVO getScadaExtra(Map<String,String> args,FunctionEntity function) {
// 跳转页面逻辑
ExtraVO extraVO = new ExtraVO();
extraVO.setImmediatelyJump(true);
@ -86,14 +88,13 @@ public class JumpRouteJoinStrategy {
* @param args 大模型解析参数
* @return 实时画面路径拼接所需参数
*/
private Map<String,String> scadaResolve(Map<String,String> args) {
public Map<String,String> scadaResolve(Map<String,String> args) {
String params = args.get("canvas_id");
// 参数格式为:picResource^context^stationNum^projectId^taskId^name^id
String[] keys = new String[]{"picResource","context","stationNum","projectId","taskId","name","id"};
return this.resolve(params,keys);
return this.resolve(params,SCADA_PARAMS_SOLVE);
}
private Map<String,String> resolve(String paramsStr,String... keys) {
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, () -> {

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

@ -46,7 +46,7 @@ public class ParamStrategy {
return null;
}
private ExtraVO getVideoExtra(Map<String,String> args) {
public ExtraVO getVideoExtra(Map<String,String> args) {
// 跳转页面逻辑
ExtraVO extraVO = new ExtraVO();
String id = args.get("canvas_id");

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

@ -2,16 +2,19 @@ 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.constants.StationSelectionVO;
import com.hnac.hzims.bigmodel.interactive.service.impl.JumpRouteJoinStrategy;
import com.hnac.hzims.bigmodel.interactive.service.impl.ParamStrategy;
import com.hnac.hzims.bigmodel.interactive.vo.*;
import com.hnac.hzims.bigmodel.interactive.service.IInteractiveService;
import com.hnac.hzims.bigmodel.websocket.service.InteractiveWsService;
import com.hnac.hzims.bigmodel.websocket.sessionManager.InteractiveSessionManager;
import lombok.extern.slf4j.Slf4j;
import org.springblade.core.log.exception.ServiceException;
import org.springblade.core.tool.api.R;
import org.springblade.core.tool.utils.Func;
import org.springblade.core.tool.utils.SpringUtil;
import org.springframework.util.Assert;
import org.springframework.web.socket.CloseStatus;
import org.springframework.web.socket.TextMessage;
import org.springframework.web.socket.WebSocketSession;
@ -20,8 +23,7 @@ import org.springframework.web.socket.handler.TextWebSocketHandler;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.function.Function;
/**
* @Author: huangxing
@ -80,7 +82,13 @@ public class InteractiveHandler extends TextWebSocketHandler {
FuncRouteEnum funcEnum = FuncRouteEnum.getEnumByFuncCode(funcCode);
switch (funcEnum) {
case CHOOSE_STATION:
this.handleChooseStation(messageContext,sessionId);
this.handleDefaultChoose(messageContext,sessionId);
break;
case CHOOSE_VIDEO:
this.handleVideoChoose(messageContext,sessionId);
break;
case CHOOSE_CANVAS:
this.handleScadaChoose(messageContext,sessionId);
break;
default:
break;
@ -88,7 +96,7 @@ public class InteractiveHandler extends TextWebSocketHandler {
}
}
private void handleChooseStation(JSONObject messageContext,String sessionId) {
private void handleDefaultChoose(JSONObject messageContext,String sessionId) {
IInteractiveService interactiveService = SpringUtil.getBean(IInteractiveService.class);
String userId = messageContext.getString("userId");
String funcCode = messageContext.getString("funcCode");
@ -101,4 +109,63 @@ public class InteractiveHandler extends TextWebSocketHandler {
extra.put("data",data);
interactiveService.specialAsk(sessionId,userId,extra);
}
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);
AnswerVO answerVO = new AnswerVO();
answerVO.setSessionId(sessionId);
answerVO.setQuery(selection.getName());
answerVO.setRunning(0);
answerVO.setStatus(0);
answerVO.setAnswer("已成功打开"+selection.getName()+"视频");
answerVO.setExtras(new Object[]{JSON.toJSONString(videoExtras)});
TextMessage textMessage = InteractiveSessionManager.getTextMessage("1", JSON.toJSONString(answerVO));
wsService.sendMessage(sessionId,textMessage);
}
catch (Exception e) {
AnswerVO answerVO = new AnswerVO();
answerVO.setRunning(0);
answerVO.setStatus(-2);
answerVO.setAnswer("视频解析失败!");
TextMessage textMessage = InteractiveSessionManager.getTextMessage("1", JSON.toJSONString(answerVO));
wsService.sendMessage(sessionId,textMessage);
}
}
private void handleScadaChoose(JSONObject messageContext,String sessionId) {
InteractiveWsService wsService = SpringUtil.getBean(InteractiveWsService.class);
try {
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("open_scada");
ExtraVO scadaExtra = strategy.getScadaExtra(param, function);
AnswerVO answerVO = new AnswerVO();
answerVO.setSessionId(sessionId);
answerVO.setRunning(0);
answerVO.setStatus(0);
answerVO.setQuery(selection.getName());
answerVO.setAnswer("已成功打开"+selection.getName()+"实时画面");
answerVO.setExtras(new Object[]{JSON.toJSONString(scadaExtra)});
TextMessage textMessage = InteractiveSessionManager.getTextMessage("1", JSON.toJSONString(answerVO));
wsService.sendMessage(sessionId,textMessage);
}
catch (Exception e) {
AnswerVO answerVO = new AnswerVO();
answerVO.setRunning(0);
answerVO.setStatus(-2);
answerVO.setAnswer("实时画面解析失败!");
TextMessage textMessage = InteractiveSessionManager.getTextMessage("1", JSON.toJSONString(answerVO));
wsService.sendMessage(sessionId,textMessage);
}
}
}

Loading…
Cancel
Save