Browse Source

Merge remote-tracking branch 'origin/master'

zhongwei
ty 7 months ago
parent
commit
827f9fab27
  1. 1
      hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/constants/FuncRouteEnum.java
  2. 4
      hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/controller/InteractiveController.java
  3. 2
      hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/IInteractiveService.java
  4. 4
      hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/InteractiveServiceImpl.java
  5. 46
      hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/JumpRouteJoinStrategy.java
  6. 2
      hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/schedule/InteractiveSchedule.java
  7. 17
      hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/websocket/handler/InteractiveHandler.java
  8. 12
      hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/websocket/sessionManager/InteractiveSessionManager.java

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

@ -13,6 +13,7 @@ import java.util.Optional;
@AllArgsConstructor @AllArgsConstructor
public enum FuncRouteEnum { public enum FuncRouteEnum {
OPEN_SCADA("open_scada","打开实时画面"), OPEN_SCADA("open_scada","打开实时画面"),
OPEN_VIDEO("open_video","打开视频监控"),
; ;
@Getter @Getter
private String funcCode; private String funcCode;

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

@ -48,8 +48,8 @@ public class InteractiveController {
@RequestMapping(value = "/authentication",method = {RequestMethod.GET,RequestMethod.POST}) @RequestMapping(value = "/authentication",method = {RequestMethod.GET,RequestMethod.POST})
public R authentication(@RequestParam(required = false) @ApiParam("站点编号") String stationId, public R authentication(@RequestParam(required = false) @ApiParam("站点编号") String stationId,
@RequestParam @ApiParam("用户ID") String userId, @RequestParam @ApiParam("用户ID") String userId,
@RequestParam(required = false) @ApiParam("菜单ID") String menuId) { @RequestParam(required = false) @ApiParam("菜单ID") String funcCode) {
return R.status(interactiveService.authentication(stationId,userId,menuId)); return R.status(interactiveService.authentication(stationId,userId,funcCode));
} }
@ApiOperation("获取问答sessionId") @ApiOperation("获取问答sessionId")

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

@ -21,6 +21,6 @@ public interface IInteractiveService {
List<AnswerVO> getAnswerBySessionIds(String sessionIds); List<AnswerVO> getAnswerBySessionIds(String sessionIds);
Boolean authentication(String stationId, String userId, String menuId); Boolean authentication(String stationId, String userId, String funcCode);
} }

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

@ -90,14 +90,14 @@ public class InteractiveServiceImpl implements IInteractiveService {
HttpResponse response = HttpRequest.post(fdpHost + bigModelInvokeUrl.getAssistantStatus()) HttpResponse response = HttpRequest.post(fdpHost + bigModelInvokeUrl.getAssistantStatus())
.body(JSON.toJSONString(params)).execute(); .body(JSON.toJSONString(params)).execute();
Assert.isTrue(response.getStatus() == HttpServletResponse.SC_OK && "1".equals(JSONObject.parseObject(response.body()).getString("success")), () -> { Assert.isTrue(response.getStatus() == HttpServletResponse.SC_OK && "1".equals(JSONObject.parseObject(response.body()).getString("success")), () -> {
throw new ServiceException("远程调用大模型【发起问答】接口失败!"); throw new ServiceException("远程调用大模型【获取问题答案】接口失败!");
}); });
String data = JSONObject.parseObject(response.body()).getString("data"); String data = JSONObject.parseObject(response.body()).getString("data");
return JSONArray.parseArray(data,AnswerVO.class); return JSONArray.parseArray(data,AnswerVO.class);
} }
@Override @Override
public Boolean authentication(String stationId, String userId, String menuId) { public Boolean authentication(String stationId, String userId, String funcCode) {
//TODO 鉴权逻辑完善 //TODO 鉴权逻辑完善
return true; return true;
} }

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

@ -16,6 +16,7 @@ import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.stream.IntStream;
/** /**
* @Author: huangxing * @Author: huangxing
@ -35,6 +36,8 @@ public class JumpRouteJoinStrategy {
switch(routeEnum) { switch(routeEnum) {
case OPEN_SCADA: case OPEN_SCADA:
return this.getScadaExtra(args,function); return this.getScadaExtra(args,function);
case OPEN_VIDEO:
return this.getVideoExtra(args,function);
default: default:
break; break;
} }
@ -77,28 +80,41 @@ public class JumpRouteJoinStrategy {
return extraVO; return extraVO;
} }
private ExtraVO getVideoExtra(Map<String,String> args,FunctionEntity function) {
// 跳转页面逻辑
ExtraVO extraVO = new ExtraVO();
Map<String, String> params = this.videoResolve(args);
String path = this.replacePath(function.getPath(), params);
extraVO.setRoute(path);
return extraVO;
}
/** /**
* 打开实时画面 * 解析实时画面参数
* @param args 大模型解析参数 * @param args 大模型解析参数
* @return 实时画面路径拼接所需参数 * @return 实时画面路径拼接所需参数
*/ */
private Map<String,String> scadaResolve(Map<String,String> args) { private Map<String,String> scadaResolve(Map<String,String> args) {
Map<String,String> result = new HashMap<>(); String params = args.get("params");
Assert.isTrue(args.containsKey("params"), () -> {
throw new ServiceException("大模型传参缺少params参数");
});
// 参数格式为:picResource^context^stationNum^projectId^taskId^name^id // 参数格式为:picResource^context^stationNum^projectId^taskId^name^id
List<String> params = Func.toStrList("\\^", args.get("params")); String[] keys = new String[]{"picResource","context","stationNum","projectId","taskId","name","id"};
Assert.isTrue(params.size() == 7,() -> { return this.resolve(params,keys);
throw new ServiceException("大模型传参params长度错误,传参为:" + args.get("params")); }
private Map<String,String> videoResolve(Map<String,String> args) {
String params = args.get("params");
// 参数格式为:id^name^stationCode^pointCode^host^appKey^appSecret
String[] keys = new String[]{"id","name","stationCode","pointCode","host","appKey","appSecret"};
return this.resolve(params,keys);
}
private 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);
}); });
result.put("picResource",params.get(0)); IntStream.iterate(0,index -> index + 1).limit(params.size()).forEach(index -> result.put(keys[index],params.get(index)));
result.put("context",params.get(1));
result.put("stationNum",params.get(2));
result.put("projectId",params.get(3));
result.put("taskId",params.get(4));
result.put("name",params.get(5));
result.put("id",params.get(6));
return result; return result;
} }

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

@ -72,7 +72,7 @@ public class InteractiveSchedule {
AnswerList.parallelStream().forEach(answerVO -> { AnswerList.parallelStream().forEach(answerVO -> {
CompletableFuture.runAsync(() -> { CompletableFuture.runAsync(() -> {
WebSocketSession session = InteractiveSessionManager.get(answerVO.getSessionId()); WebSocketSession session = InteractiveSessionManager.get(answerVO.getSessionId());
TextMessage message = new TextMessage(JSON.toJSONString(answerVO)); TextMessage message = InteractiveSessionManager.getTextMessage("1",JSON.toJSONString(answerVO));
try { try {
session.sendMessage(message); session.sendMessage(message);
} catch (IOException e) { } catch (IOException e) {

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

@ -1,6 +1,7 @@
package com.hnac.hzims.bigmodel.websocket.handler; package com.hnac.hzims.bigmodel.websocket.handler;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.hnac.hzims.bigmodel.interactive.service.IInteractiveService; import com.hnac.hzims.bigmodel.interactive.service.IInteractiveService;
import com.hnac.hzims.bigmodel.websocket.sessionManager.InteractiveSessionManager; import com.hnac.hzims.bigmodel.websocket.sessionManager.InteractiveSessionManager;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
@ -13,6 +14,7 @@ import org.springframework.web.socket.TextMessage;
import org.springframework.web.socket.WebSocketSession; import org.springframework.web.socket.WebSocketSession;
import org.springframework.web.socket.handler.TextWebSocketHandler; import org.springframework.web.socket.handler.TextWebSocketHandler;
import java.io.IOException;
import java.util.Map; import java.util.Map;
import java.util.Optional; import java.util.Optional;
import java.util.Set; import java.util.Set;
@ -46,8 +48,21 @@ public class InteractiveHandler extends TextWebSocketHandler {
@Override @Override
protected void handleTextMessage(WebSocketSession session, TextMessage message) { protected void handleTextMessage(WebSocketSession session, TextMessage message) {
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 context = messageJSON.getString("context");
IInteractiveService interactiveService = SpringUtil.getBean(IInteractiveService.class); IInteractiveService interactiveService = SpringUtil.getBean(IInteractiveService.class);
R askResult = interactiveService.ask(message.getPayload(), InteractiveSessionManager.getEntryBySession(session).getKey()); R askResult = interactiveService.ask(context, InteractiveSessionManager.getEntryBySession(session).getKey());
log.info("message handle successful!返回结果为:"+ JSON.toJSONString(askResult)); log.info("message handle successful!返回结果为:"+ JSON.toJSONString(askResult));
} }
}
} }

12
hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/websocket/sessionManager/InteractiveSessionManager.java

@ -1,7 +1,10 @@
package com.hnac.hzims.bigmodel.websocket.sessionManager; package com.hnac.hzims.bigmodel.websocket.sessionManager;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springblade.core.log.exception.ServiceException; import org.springblade.core.log.exception.ServiceException;
import org.springframework.web.socket.TextMessage;
import org.springframework.web.socket.WebSocketSession; import org.springframework.web.socket.WebSocketSession;
import java.io.IOException; import java.io.IOException;
@ -23,8 +26,6 @@ public class InteractiveSessionManager {
/** ws会话池 **/ /** ws会话池 **/
public static ConcurrentHashMap<String, WebSocketSession> SESSION_POOL = new ConcurrentHashMap<>(); public static ConcurrentHashMap<String, WebSocketSession> SESSION_POOL = new ConcurrentHashMap<>();
private static final Lock lock = new ReentrantLock();
/** /**
* 获取sessionIds * 获取sessionIds
* @return sessionIds * @return sessionIds
@ -85,4 +86,11 @@ public class InteractiveSessionManager {
} }
SESSION_POOL.remove(sessionId); SESSION_POOL.remove(sessionId);
} }
public static TextMessage getTextMessage(String type,String context) {
JSONObject message = new JSONObject();
message.put("type",type);
message.put("context",context);
return new TextMessage(JSON.toJSONString(message));
}
} }

Loading…
Cancel
Save