Browse Source

Merge remote-tracking branch 'origin/master'

zhongwei
yang_shj 7 months ago
parent
commit
3efddeab20
  1. 3
      hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/interactive/constants/FunctionConstants.java
  2. 20
      hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/interactive/constants/SelectionVO.java
  3. 12
      hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/interactive/constants/StationSelectionVO.java
  4. 12
      hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/interactive/vo/ExtraVO.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/constants/FuncRouteEnum.java
  7. 2
      hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/IInteractiveService.java
  8. 42
      hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/ExtraResolveStrategyService.java
  9. 22
      hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/InteractiveServiceImpl.java
  10. 18
      hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/JumpRouteJoinStrategy.java
  11. 34
      hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/websocket/handler/InteractiveHandler.java

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

@ -19,7 +19,8 @@ public interface FunctionConstants {
/**链接**/ /**链接**/
LINK("2"), LINK("2"),
/**参数**/ /**参数**/
PARAMS("3") PARAMS("3"),
CHOOSE("4")
; ;
@Getter @Getter
private String type; private String type;

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

@ -0,0 +1,20 @@
package com.hnac.hzims.bigmodel.interactive.constants;
import lombok.Data;
import java.io.Serializable;
/**
* @Author: huangxing
* @Date: 2024/05/09 16:30
*/
@Data
public class SelectionVO implements Serializable {
/**选项ID**/
private String id;
/**选项名称**/
private String name;
}

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

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

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

@ -1,10 +1,13 @@
package com.hnac.hzims.bigmodel.interactive.vo; package com.hnac.hzims.bigmodel.interactive.vo;
import com.hnac.hzims.bigmodel.interactive.constants.SelectionVO;
import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty; import io.swagger.annotations.ApiModelProperty;
import lombok.Data; import lombok.Data;
import net.sf.jsqlparser.statement.select.Select;
import java.io.Serializable; import java.io.Serializable;
import java.util.List;
import java.util.Map; import java.util.Map;
/** /**
@ -15,7 +18,7 @@ import java.util.Map;
@ApiModel("响应内容") @ApiModel("响应内容")
public class ExtraVO implements Serializable { public class ExtraVO implements Serializable {
@ApiModelProperty("交互类型 1:打开页面,2:打开链接,3:参数传递") @ApiModelProperty("交互类型 1:打开页面,2:打开链接,3:参数传递,4:完善选项")
private String type; private String type;
@ApiModelProperty("若为弹窗,则返回路由") @ApiModelProperty("若为弹窗,则返回路由")
@ -25,9 +28,14 @@ public class ExtraVO implements Serializable {
private String label; private String label;
@ApiModelProperty("是否立即跳转") @ApiModelProperty("是否立即跳转")
private boolean isImmediatelyJump = true; private boolean isImmediatelyJump = false;
@ApiModelProperty("附带参数") @ApiModelProperty("附带参数")
private Map<String,Object> params; private Map<String,Object> params;
@ApiModelProperty("是否为特殊函数")
private boolean isSpecial;
@ApiModelProperty("选项")
private List<? extends SelectionVO> selection;
} }

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

@ -15,6 +15,8 @@ public class BigModelInvokeUrl {
private String assistantAsk; private String assistantAsk;
private String assistantSpecialAsk;
private String assistantStatus; private String assistantStatus;
private String askAbort; private String askAbort;

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

@ -14,7 +14,8 @@ import java.util.Optional;
public enum FuncRouteEnum { public enum FuncRouteEnum {
OPEN_SCADA("open_scada","打开实时画面"), OPEN_SCADA("open_scada","打开实时画面"),
OPEN_VIDEO("open_video","打开视频监控"), OPEN_VIDEO("open_video","打开视频监控"),
DIAGNOSE("diagnose","智能诊断") DIAGNOSE("diagnose","智能诊断"),
CHOOSE_STATION("choose_station","选择站点"),
; ;
@Getter @Getter
private String funcCode; private String funcCode;

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

@ -20,6 +20,8 @@ public interface IInteractiveService {
R ask(String question,String sessionId,String userId); R ask(String question,String sessionId,String userId);
R specialAsk(String sessionId,String userId,Map<String,Object> extra);
void updateVideo(Map<String,Object> request); void updateVideo(Map<String,Object> request);
Boolean updateCanvas(Map<String,Object> request); Boolean updateCanvas(Map<String,Object> request);

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

@ -1,23 +1,36 @@
package com.hnac.hzims.bigmodel.interactive.service.impl; package com.hnac.hzims.bigmodel.interactive.service.impl;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.hnac.hzims.bigmodel.interactive.constants.FuncRouteEnum; import com.hnac.hzims.bigmodel.interactive.constants.FuncRouteEnum;
import com.hnac.hzims.bigmodel.interactive.constants.FunctionConstants; import com.hnac.hzims.bigmodel.interactive.constants.FunctionConstants;
import com.hnac.hzims.bigmodel.interactive.constants.StationSelectionVO;
import com.hnac.hzims.bigmodel.interactive.vo.ExtraVO; 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.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; import org.springblade.core.tool.utils.StringUtil;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Optional; import java.util.Optional;
import java.util.stream.Collectors;
/** /**
* @Author: huangxing * @Author: huangxing
* @Date: 2024/05/08 16:19 * @Date: 2024/05/08 16:19
*/ */
@Service @Service
@AllArgsConstructor
public class ExtraResolveStrategyService { public class ExtraResolveStrategyService {
private final IStationClient stationClient;
/** /**
* 解析DFP返回extra * 解析DFP返回extra
* @param extraStr DFP返回extra * @param extraStr DFP返回extra
@ -31,6 +44,8 @@ public class ExtraResolveStrategyService {
switch (funcRouteEnum) { switch (funcRouteEnum) {
case DIAGNOSE: case DIAGNOSE:
return this.resolveDiagnose(extra); return this.resolveDiagnose(extra);
case CHOOSE_STATION:
return this.resolveChooseStation(extra);
default: default:
break; break;
} }
@ -48,4 +63,31 @@ public class ExtraResolveStrategyService {
result.setType(FunctionConstants.TypeEnum.LINK.getType()); result.setType(FunctionConstants.TypeEnum.LINK.getType());
return result; return result;
} }
/**
*
* @param extra
* @return
*/
private ExtraVO resolveChooseStation(Map<String,Object> extra) {
ExtraVO result = new ExtraVO();
JSONObject data = JSONObject.parseObject(JSON.toJSONString(extra.get("data")));
if(data.containsKey("stations")) {
List<String> stations = JSONArray.parseArray(JSON.toJSONString(data.get("stations")), String.class);
List<StationSelectionVO> selectionList = stations.stream().map(stationId -> {
StationSelectionVO selectionVO = new StationSelectionVO();
R<StationEntity> stationR = stationClient.getStationByCode(stationId);
if (stationR.isSuccess() && Func.isNotEmpty(stationR.getData())) {
selectionVO.setId(stationId);
selectionVO.setName(stationR.getData().getName());
}
return selectionVO;
}).collect(Collectors.toList());
result.setSelection(selectionList);
result.setSpecial(true);
result.setType(FunctionConstants.TypeEnum.CHOOSE.getType());
}
result.setType(FunctionConstants.TypeEnum.CHOOSE.getType());
return result;
}
} }

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

@ -103,6 +103,11 @@ public class InteractiveServiceImpl implements IInteractiveService {
log.error("远程调用大模型【发起问答】接口失败!"); log.error("远程调用大模型【发起问答】接口失败!");
return R.fail("远程调用大模型【发起问答】接口失败!"); return R.fail("远程调用大模型【发起问答】接口失败!");
} }
this.addQuestionSessionId(sessionId);
return R.success("消息发送成功");
}
private void addQuestionSessionId(String sessionId) {
// 添加redis问题会话 // 添加redis问题会话
Object json = redisTemplate.opsForValue().get(HZIMS_BIGMODEL_ASK_KEY); Object json = redisTemplate.opsForValue().get(HZIMS_BIGMODEL_ASK_KEY);
if(ObjectUtil.isEmpty(json)){ if(ObjectUtil.isEmpty(json)){
@ -115,6 +120,23 @@ public class InteractiveServiceImpl implements IInteractiveService {
} }
redisTemplate.opsForValue().set(HZIMS_BIGMODEL_ASK_KEY,JSONObject.toJSONString(asks)); redisTemplate.opsForValue().set(HZIMS_BIGMODEL_ASK_KEY,JSONObject.toJSONString(asks));
} }
}
@Override
public R specialAsk(String sessionId, String userId, Map<String, Object> extra) {
Map<String,Object> params = new HashMap<>();
params.put("id",sessionId);
params.put("userid", userId);
params.put("extra",extra);
params.put("stationids",this.getStationPermissionsById(userId).stream().map(DeptStationDTO::getStationId).filter(StringUtil::isNotBlank).filter(Func::isNotEmpty).toArray());
params.put("projectids",this.getStationPermissionsById(userId).stream().map(DeptStationDTO::getDeptId).filter(Func::isNotEmpty).map(String::valueOf).toArray());
HttpResponse response = HttpRequest.post(fdpHost + bigModelInvokeUrl.getAssistantSpecialAsk())
.body(JSON.toJSONString(params)).execute();
if(response.getStatus() != HttpServletResponse.SC_OK) {
log.error("远程调用大模型【发起特殊问答】接口失败!");
return R.fail("远程调用大模型【发起特殊问答】接口失败!");
}
this.addQuestionSessionId(sessionId);
return R.success("消息发送成功"); return R.success("消息发送成功");
} }

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

@ -46,7 +46,7 @@ public class JumpRouteJoinStrategy {
private ExtraVO getScadaExtra(Map<String,String> args,FunctionEntity function) { private ExtraVO getScadaExtra(Map<String,String> args,FunctionEntity function) {
// 跳转页面逻辑 // 跳转页面逻辑
ExtraVO extraVO = new ExtraVO(); ExtraVO extraVO = new ExtraVO();
extraVO.setImmediatelyJump(true);
Map<String, String> params = this.scadaResolve(args); Map<String, String> params = this.scadaResolve(args);
// 根据hz3000画面版本获取path // 根据hz3000画面版本获取path
Integer picResource = Integer.valueOf(params.get("picResource")); Integer picResource = Integer.valueOf(params.get("picResource"));
@ -79,15 +79,6 @@ 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 大模型解析参数
@ -100,13 +91,6 @@ public class JumpRouteJoinStrategy {
return this.resolve(params,keys); return this.resolve(params,keys);
} }
private Map<String,String> videoResolve(Map<String,String> args) {
String params = args.get("canvas_id");
// 参数格式为: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) { private Map<String,String> resolve(String paramsStr,String... keys) {
Map<String,String> result = new HashMap<>(); Map<String,String> result = new HashMap<>();
List<String> params = Func.toStrList("\\^", paramsStr); List<String> params = Func.toStrList("\\^", paramsStr);

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

@ -2,11 +2,14 @@ package com.hnac.hzims.bigmodel.websocket.handler;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.hnac.hzims.bigmodel.interactive.constants.FuncRouteEnum;
import com.hnac.hzims.bigmodel.interactive.constants.StationSelectionVO;
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;
import org.springblade.core.log.exception.ServiceException; import org.springblade.core.log.exception.ServiceException;
import org.springblade.core.tool.api.R; import org.springblade.core.tool.api.R;
import org.springblade.core.tool.utils.Func;
import org.springblade.core.tool.utils.SpringUtil; import org.springblade.core.tool.utils.SpringUtil;
import org.springframework.util.Assert; import org.springframework.util.Assert;
import org.springframework.web.socket.CloseStatus; import org.springframework.web.socket.CloseStatus;
@ -57,12 +60,35 @@ public class InteractiveHandler extends TextWebSocketHandler {
throw new RuntimeException(e); throw new RuntimeException(e);
} }
}else { }else {
// 发送问题 String sessionId = InteractiveSessionManager.getEntryBySession(session).getKey();
String context = messageJSON.getString("context"); this.handleMessage(messageJSON,sessionId);
String userId = messageJSON.getString("userId"); }
}
private void handleMessage(JSONObject messageContext,String sessionId) {
Boolean isSpecial = messageContext.getBoolean("isSpecial");
String context = messageContext.getString("context");
String userId = messageContext.getString("userId");
if(Func.isEmpty(isSpecial) || !isSpecial) {
IInteractiveService interactiveService = SpringUtil.getBean(IInteractiveService.class); IInteractiveService interactiveService = SpringUtil.getBean(IInteractiveService.class);
R askResult = interactiveService.ask(context, InteractiveSessionManager.getEntryBySession(session).getKey(), userId); R askResult = interactiveService.ask(context, sessionId, userId);
log.info("返回结果为:"+ JSON.toJSONString(askResult)); log.info("返回结果为:"+ JSON.toJSONString(askResult));
} }
else {
String funcCode = messageContext.getString("func");
FuncRouteEnum funcEnum = FuncRouteEnum.getEnumByFuncCode(funcCode);
switch (funcEnum) {
case CHOOSE_STATION:
this.handleChooseStation(messageContext);
break;
default:
break;
}
}
}
private void handleChooseStation(JSONObject messageContext) {
StationSelectionVO selectionVO = messageContext.getObject("selection",StationSelectionVO.class);
} }
} }

Loading…
Cancel
Save