diff --git a/hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/interactive/constants/FunctionConstants.java b/hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/interactive/constants/FunctionConstants.java index 7d34a5d..7114de1 100644 --- a/hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/interactive/constants/FunctionConstants.java +++ b/hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/interactive/constants/FunctionConstants.java @@ -15,7 +15,12 @@ public interface FunctionConstants { @AllArgsConstructor enum TypeEnum { /**跳转页面**/ - JUMP("1") + JUMP("1"), + /**链接**/ + LINK("2"), + /**参数**/ + PARAMS("3"), + CHOOSE("4") ; @Getter private String type; diff --git a/hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/interactive/constants/SelectionVO.java b/hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/interactive/constants/SelectionVO.java new file mode 100644 index 0000000..a7a271f --- /dev/null +++ b/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; + +} diff --git a/hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/interactive/constants/StationSelectionVO.java b/hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/interactive/constants/StationSelectionVO.java new file mode 100644 index 0000000..d67a829 --- /dev/null +++ b/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 { + +} diff --git a/hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/interactive/vo/ExtraVO.java b/hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/interactive/vo/ExtraVO.java index 303a21e..cda702f 100644 --- a/hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/interactive/vo/ExtraVO.java +++ b/hzims-service-api/big-model-api/src/main/java/com/hnac/hzims/bigmodel/interactive/vo/ExtraVO.java @@ -1,10 +1,14 @@ 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; +import java.util.Map; /** * @Author: huangxing @@ -14,7 +18,7 @@ import java.io.Serializable; @ApiModel("响应内容") public class ExtraVO implements Serializable { - @ApiModelProperty("交互类型") + @ApiModelProperty("交互类型 1:打开页面,2:打开链接,3:参数传递,4:完善选项") private String type; @ApiModelProperty("若为弹窗,则返回路由") @@ -23,7 +27,18 @@ public class ExtraVO implements Serializable { @ApiModelProperty("链接显示文字") private String label; + @ApiModelProperty("函数编号") + private String funcCode; + @ApiModelProperty("是否立即跳转") - private boolean isImmediatelyJump = true; + private boolean isImmediatelyJump = false; + + @ApiModelProperty("附带参数") + private Map params; + + @ApiModelProperty("是否为特殊函数") + private boolean isSpecial; + @ApiModelProperty("选项") + private List selection; } diff --git a/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/station/feign/IStationVideoTypeClient.java b/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/station/feign/IStationVideoTypeClient.java index 46e26c4..b29e3e2 100644 --- a/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/station/feign/IStationVideoTypeClient.java +++ b/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/station/feign/IStationVideoTypeClient.java @@ -4,6 +4,7 @@ import com.hnac.hzims.operational.OperationalConstants; import com.hnac.hzims.operational.station.entity.StationVideoTypeEntity; import org.springblade.core.tool.api.R; import org.springframework.cloud.openfeign.FeignClient; +import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestParam; @@ -16,7 +17,16 @@ import java.util.List; 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 listByStationId(@RequestParam("stationId") String stationId); + + @GetMapping(LIST) + R> list(StationVideoTypeEntity req); + + @GetMapping(GET_BY_ID) + R getById(@RequestParam Long id); } diff --git a/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/station/feign/IStationVideoTypeClientFallback.java b/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/station/feign/IStationVideoTypeClientFallback.java index 24fb9db..5ee3541 100644 --- a/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/station/feign/IStationVideoTypeClientFallback.java +++ b/hzims-service-api/hzims-operational-api/src/main/java/com/hnac/hzims/operational/station/feign/IStationVideoTypeClientFallback.java @@ -16,4 +16,15 @@ public class IStationVideoTypeClientFallback implements IStationVideoTypeClient log.info("调用{}接口失败",LIST_BY_STATION_ID); return new ArrayList(); } + + @Override + public R> list(StationVideoTypeEntity req) { + return R.fail("远程调用失败!"); + } + + @Override + public R getById(Long id) { + return R.fail("远程调用失败!"); + } + } diff --git a/hzims-service/hzims-big-model/pom.xml b/hzims-service/hzims-big-model/pom.xml index ece5cf6..cedb16a 100644 --- a/hzims-service/hzims-big-model/pom.xml +++ b/hzims-service/hzims-big-model/pom.xml @@ -65,6 +65,16 @@ org.springblade blade-system-api + + + com.hnac.hzims + hzims-operational-api + 4.0.0-SNAPSHOT + + + com.hnac.hzinfo.data + hzinfo-data-sdk + diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/HzimsBigModelApplication.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/HzimsBigModelApplication.java index 2709c09..0f09cc7 100644 --- a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/HzimsBigModelApplication.java +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/HzimsBigModelApplication.java @@ -1,28 +1,35 @@ package com.hnac.hzims.bigmodel; +import lombok.extern.slf4j.Slf4j; import org.mybatis.spring.annotation.MapperScan; import org.springblade.core.cloud.feign.EnableBladeFeign; +import org.springblade.core.jwt.JwtUtil; import org.springblade.core.launch.BladeApplication; -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.builder.SpringApplicationBuilder; import org.springframework.boot.web.servlet.support.SpringBootServletInitializer; import org.springframework.cloud.client.SpringCloudApplication; import org.springframework.context.annotation.ComponentScan; -import org.springframework.scheduling.annotation.EnableScheduling; +import org.springframework.data.redis.core.RedisTemplate; import javax.annotation.Resource; +import static com.hnac.hzims.bigmodel.schedule.XxlJobHandlerConstant.HZIMS_BIGMODEL_ASK_KEY; + @EnableBladeFeign(basePackages = {"org.springblade","com.hnac"}) @SpringCloudApplication @MapperScan("com.hnac.hzims.**.mapper.**") @ComponentScan(basePackages = {"com.hnac.hzims.bigmodel.*"}) @Resource @ComponentScan(basePackages = {"com.hnac.hzims.*"}) +@Slf4j public class HzimsBigModelApplication extends SpringBootServletInitializer { + public static void main(String[] args) { BladeApplication.run(BigModelConstants.APP_NAME, HzimsBigModelApplication.class, args); + RedisTemplate redisTemplate = JwtUtil.getRedisTemplate(); + redisTemplate.delete(HZIMS_BIGMODEL_ASK_KEY); + log.info("服务重启删除问题reids缓存:{}",HZIMS_BIGMODEL_ASK_KEY); } @Override diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/configuration/BigModelInvokeUrl.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/configuration/BigModelInvokeUrl.java index 70a539d..0456fa2 100644 --- a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/configuration/BigModelInvokeUrl.java +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/configuration/BigModelInvokeUrl.java @@ -15,6 +15,14 @@ public class BigModelInvokeUrl { private String assistantAsk; + private String assistantSpecialAsk; + private String assistantStatus; + private String askAbort; + + private String updateVideo; + + private String updateCanvas; + } diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/constants/FuncRouteEnum.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/constants/FuncRouteEnum.java index 4d51364..724f97e 100644 --- a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/constants/FuncRouteEnum.java +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/constants/FuncRouteEnum.java @@ -14,6 +14,8 @@ import java.util.Optional; public enum FuncRouteEnum { OPEN_SCADA("open_scada","打开实时画面"), OPEN_VIDEO("open_video","打开视频监控"), + DIAGNOSE("diagnose","智能诊断"), + CHOOSE_STATION("choose_station","选择站点"), ; @Getter private String funcCode; diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/controller/InteractiveController.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/controller/InteractiveController.java index 5ca95c7..7739800 100644 --- a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/controller/InteractiveController.java +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/controller/InteractiveController.java @@ -59,4 +59,12 @@ public class InteractiveController { return R.data(IdWorker.get32UUID()); } + @ApiOperation("删除对话sessionId") + @ApiOperationSupport(order = 5) + @GetMapping("/removeSessionId") + public R removeSessionId(@RequestParam(value = "id") String sessionId) { + return R.data(interactiveService.removeSessionId(sessionId)); + } + + } diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/IInteractiveService.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/IInteractiveService.java index f497498..f740a40 100644 --- a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/IInteractiveService.java +++ b/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,8 +20,15 @@ public interface IInteractiveService { R ask(String question,String sessionId,String userId); + R specialAsk(String sessionId,String userId,Map extra); + + void updateVideo(Map request); + + Boolean updateCanvas(Map request); + List getAnswerBySessionIds(String sessionIds); Boolean authentication(String stationId, String userId, String funcCode); + Boolean removeSessionId(String sessionId); } diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/IParamsService.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/IParamsService.java new file mode 100644 index 0000000..aee914a --- /dev/null +++ b/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 args); + +} diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/ExtraResolveStrategyService.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/ExtraResolveStrategyService.java new file mode 100644 index 0000000..6c19dc0 --- /dev/null +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/ExtraResolveStrategyService.java @@ -0,0 +1,94 @@ +package com.hnac.hzims.bigmodel.interactive.service.impl; + +import com.alibaba.fastjson.JSON; +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.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.springframework.stereotype.Service; + +import java.util.List; +import java.util.Map; +import java.util.Optional; +import java.util.stream.Collectors; + +/** + * @Author: huangxing + * @Date: 2024/05/08 16:19 + */ +@Service +@AllArgsConstructor +public class ExtraResolveStrategyService { + + private final IStationClient stationClient; + + /** + * 解析DFP返回extra + * @param extraStr DFP返回extra + * @return 与前端交互extra + */ + public ExtraVO resolve(String extraStr) { + JSONObject extra = JSONObject.parseObject(extraStr); + String functionCode = Optional.ofNullable(extra.get("func")).map(String::valueOf).orElse(""); + if(StringUtil.isNotBlank(functionCode)) { + FuncRouteEnum funcRouteEnum = FuncRouteEnum.getEnumByFuncCode(functionCode); + switch (funcRouteEnum) { + case DIAGNOSE: + return this.resolveDiagnose(extra); + case CHOOSE_STATION: + return this.resolveChooseStation(extra); + default: + break; + } + } + return JSONObject.parseObject(JSON.toJSONString(extra),ExtraVO.class); + } + + private ExtraVO resolveDiagnose(Map extra) { + ExtraVO result = new ExtraVO(); + JSONObject data = JSONObject.parseObject(JSON.toJSONString(extra.get("data"))); + String faultId = data.getString("fault_id"); + String faultName = data.getString("fault_name"); + result.setLabel(faultName); + // TODO 拼接诊断链接 + result.setType(FunctionConstants.TypeEnum.LINK.getType()); + return result; + } + + /** + * + * @param extra + * @return + */ + private ExtraVO resolveChooseStation(Map extra) { + ExtraVO result = new ExtraVO(); + JSONObject data = JSONObject.parseObject(JSON.toJSONString(extra.get("data"))); + if(data.containsKey("stations")) { + List stations = JSONArray.parseArray(JSON.toJSONString(data.get("stations")), String.class); + List selectionList = stations.stream().map(stationId -> { + StationSelectionVO selectionVO = new StationSelectionVO(); + R 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.setFuncCode(FuncRouteEnum.CHOOSE_STATION.getFuncCode()); + result.setSpecial(true); + result.setType(FunctionConstants.TypeEnum.CHOOSE.getType()); + } + result.setType(FunctionConstants.TypeEnum.CHOOSE.getType()); + return result; + } +} diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/InteractiveServiceImpl.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/InteractiveServiceImpl.java index d9e2efb..aee1bda 100644 --- a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/InteractiveServiceImpl.java +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/InteractiveServiceImpl.java @@ -7,21 +7,22 @@ import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import com.hnac.hzims.bigmodel.configuration.BigModelInvokeUrl; import com.hnac.hzims.bigmodel.entity.FunctionEntity; +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.function.service.IFunctionService; +import com.hnac.hzims.bigmodel.interactive.service.IParamsService; import com.hnac.hzims.bigmodel.interactive.vo.AnswerVO; -import lombok.AllArgsConstructor; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springblade.core.log.exception.ServiceException; import org.springblade.core.log.logger.BladeLogger; -import org.springblade.core.secure.utils.AuthUtil; import org.springblade.core.tool.api.R; import org.springblade.core.tool.utils.CollectionUtil; import org.springblade.core.tool.utils.Func; +import org.springblade.core.tool.utils.ObjectUtil; import org.springblade.core.tool.utils.StringUtil; +import org.springblade.system.dto.DeptStationDTO; import org.springblade.system.feign.IDeptClient; import org.springblade.system.user.feign.IUserClient; import org.springframework.beans.factory.annotation.Value; @@ -29,15 +30,13 @@ import org.springframework.data.redis.core.RedisTemplate; import org.springframework.stereotype.Service; import org.springframework.util.Assert; -import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; -import javax.servlet.http.HttpSession; +import java.util.*; +import java.util.stream.Collectors; -import java.util.HashMap; -import java.util.List; -import java.util.Map; +import static com.hnac.hzims.bigmodel.interactive.constants.FunctionConstants.TypeEnum; +import static com.hnac.hzims.bigmodel.schedule.XxlJobHandlerConstant.HZIMS_BIGMODEL_ASK_KEY; -import static com.hnac.hzims.bigmodel.interactive.constants.FunctionConstants.*; /** * @Author: huangxing * @Date: 2024/04/26 14:51 @@ -47,12 +46,24 @@ import static com.hnac.hzims.bigmodel.interactive.constants.FunctionConstants.*; @RequiredArgsConstructor public class InteractiveServiceImpl implements IInteractiveService { + private final BladeLogger logger; + private final IJumpPageService jumpPageService; + + private final IParamsService paramsService; + private final IFunctionService functionService; + private final BigModelInvokeUrl bigModelInvokeUrl; - private final BladeLogger logger; + private final IDeptClient deptClient; + private final IUserClient userClient; + + private final RedisTemplate redisTemplate; + + private final ExtraResolveStrategyService extraResolveStrategyService; + @Value("${fdp.host}") private String fdpHost; @@ -64,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("函数解析失败!"); } @@ -76,21 +90,77 @@ public class InteractiveServiceImpl implements IInteractiveService { @Override public R ask(String question,String sessionId,String userId) { - //TODO 保存问题 - Map params = new HashMap<>(); + Map params = new HashMap<>(); params.put("id",sessionId); - params.put("userid",userId.toString()); + params.put("userid", userId); params.put("query",question); + 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.getAssistantAsk()) .body(JSON.toJSONString(params)).execute(); + logger.info("interactive:ask","问答传参为:" + JSON.toJSONString(params) + "结果为:" + response.body()); if(response.getStatus() != HttpServletResponse.SC_OK) { log.error("远程调用大模型【发起问答】接口失败!"); return R.fail("远程调用大模型【发起问答】接口失败!"); } + this.addQuestionSessionId(sessionId); + return R.success("消息发送成功"); + } + + private void addQuestionSessionId(String sessionId) { + // 添加redis问题会话 + Object json = redisTemplate.opsForValue().get(HZIMS_BIGMODEL_ASK_KEY); + if(ObjectUtil.isEmpty(json)){ + List asks = Collections.singletonList(sessionId); + redisTemplate.opsForValue().set(HZIMS_BIGMODEL_ASK_KEY,JSONObject.toJSONString(asks)); + }else{ + List asks = JSONObject.parseArray(json.toString(),String.class); + if(!asks.contains(sessionId)){ + asks.add(sessionId); + } + redisTemplate.opsForValue().set(HZIMS_BIGMODEL_ASK_KEY,JSONObject.toJSONString(asks)); + } + } + + @Override + public R specialAsk(String sessionId, String userId, Map extra) { + Map 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("消息发送成功"); } @Override + public void updateVideo(Map 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 Boolean updateCanvas(Map request) { + HttpResponse response = HttpRequest.post(fdpHost + bigModelInvokeUrl.getUpdateCanvas()) + .body(JSON.toJSONString(request)).execute(); + if (response.getStatus() == HttpServletResponse.SC_OK) { + return true; + } + log.error("远程调用大模型【更新实时画面】接口失败!"); + return false; + } + + @Override public List getAnswerBySessionIds(String sessionIds) { Map params = new HashMap<>(); params.put("ids",Func.toStrList(",",sessionIds).toArray()); @@ -100,18 +170,25 @@ public class InteractiveServiceImpl implements IInteractiveService { Assert.isTrue(response.getStatus() == HttpServletResponse.SC_OK, () -> { throw new ServiceException("远程调用大模型【获取问题答案】接口失败!"); }); - return JSONArray.parseArray(response.body(),AnswerVO.class); + + List result = JSONArray.parseArray(response.body(), AnswerVO.class); + result.stream().filter(answerVO -> answerVO.getRunning() == 0).forEach(answerVO -> { + Object[] extras = answerVO.getExtra(); + if(ObjectUtil.isEmpty(answerVO.getExtra()) || extras.length == 0){ + return; + } + List extraList = Arrays.stream(extras).map(Object::toString).map(extraResolveStrategyService::resolve).map(JSON::toJSONString).collect(Collectors.toList()); + answerVO.setExtra(extraList.toArray(new String[extraList.size()])); + }); + return result; } @Override public Boolean authentication(String stationId, String userId, String funcCode) { // 站点鉴权 if(StringUtil.isNotBlank(stationId)) { - R> stationsR = deptClient.getStationPermissionsById(Long.valueOf(userId)); - Assert.isTrue(stationsR.isSuccess() && CollectionUtil.isNotEmpty(stationsR.getData()),() -> { - throw new ServiceException("获取人员站点权限失败!"); - }); - List stations = stationsR.getData(); + List stations = this.getStationPermissionsById(userId).stream().map(DeptStationDTO::getStationId) + .filter(StringUtil::isNotBlank).filter(Func::isNotEmpty).collect(Collectors.toList()); Assert.isTrue(stations.contains(stationId),() -> { throw new ServiceException("人员站点鉴权失败!"); }); @@ -130,4 +207,38 @@ public class InteractiveServiceImpl implements IInteractiveService { return true; } + @Override + public Boolean removeSessionId(String sessionId) { + // 调用大模型删除对话 + Map params = new HashMap<>(); + params.put("id",sessionId); + HttpResponse response = HttpRequest.post(fdpHost + bigModelInvokeUrl.getAskAbort()) + .body(JSON.toJSONString(params)).execute(); + if(response.getStatus() != HttpServletResponse.SC_OK) { + log.error("远程调用大模型【删除对话】接口失败!"); + throw new ServiceException("远程调用大模型【删除对话】接口失败!"); + } + // 移除对应reids中问题标记 + Object json = redisTemplate.opsForValue().get(HZIMS_BIGMODEL_ASK_KEY); + if(ObjectUtil.isEmpty(json)) { + return true; + } + List sessionIds = JSONObject.parseArray(json.toString(),String.class); + if(CollectionUtil.isEmpty(sessionIds)){ + return true; + } + if(sessionIds.contains(sessionId)){ + sessionIds.remove(sessionId); + redisTemplate.opsForValue().set(HZIMS_BIGMODEL_ASK_KEY,JSONObject.toJSONString(sessionIds)); + } + return true; + } + + private List getStationPermissionsById(String userId) { + R> deptSattionR = deptClient.getStationPermissionsById(Long.valueOf(userId)); + Assert.isTrue(deptSattionR.isSuccess() && CollectionUtil.isNotEmpty(deptSattionR.getData()),() -> { + throw new ServiceException("获取人员站点权限失败!"); + }); + return deptSattionR.getData(); + } } diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/JumpRouteJoinStrategy.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/JumpRouteJoinStrategy.java index 31ad197..907266e 100644 --- a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/JumpRouteJoinStrategy.java +++ b/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; } @@ -48,6 +46,7 @@ public class JumpRouteJoinStrategy { private ExtraVO getScadaExtra(Map args,FunctionEntity function) { // 跳转页面逻辑 ExtraVO extraVO = new ExtraVO(); + extraVO.setImmediatelyJump(true); Map params = this.scadaResolve(args); // 根据hz3000画面版本获取path Integer picResource = Integer.valueOf(params.get("picResource")); @@ -80,15 +79,6 @@ public class JumpRouteJoinStrategy { return extraVO; } - private ExtraVO getVideoExtra(Map args,FunctionEntity function) { - // 跳转页面逻辑 - ExtraVO extraVO = new ExtraVO(); - Map params = this.videoResolve(args); - String path = this.replacePath(function.getPath(), params); - extraVO.setRoute(path); - return extraVO; - } - /** * 解析实时画面参数 * @param args 大模型解析参数 @@ -101,13 +91,6 @@ public class JumpRouteJoinStrategy { return this.resolve(params,keys); } - private Map videoResolve(Map 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 resolve(String paramsStr,String... keys) { Map result = new HashMap<>(); List params = Func.toStrList("\\^", paramsStr); diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/ParamStrategy.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/ParamStrategy.java new file mode 100644 index 0000000..d1928c3 --- /dev/null +++ b/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 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 args) { + // 跳转页面逻辑 + ExtraVO extraVO = new ExtraVO(); + String id = args.get("canvas_id"); + if(StringUtil.isNotBlank(id) && Func.isNotEmpty(id)) { + R videoR = videoClient.getById(Long.valueOf(id)); + if(videoR.isSuccess()) { + StationVideoTypeEntity video = videoR.getData(); + extraVO.setType(FunctionConstants.TypeEnum.PARAMS.getType()); + Map 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; + } +} diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/ParamsServiceImpl.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/service/impl/ParamsServiceImpl.java new file mode 100644 index 0000000..dd462c6 --- /dev/null +++ b/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 args) { + // 跳转页面逻辑 + ExtraVO extraVO = strategy.resolve(function,args); + return JSON.toJSONString(extraVO); + } +} diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/vo/AnswerVO.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/vo/AnswerVO.java index 3b1ac38..ec2760d 100644 --- a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/vo/AnswerVO.java +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/vo/AnswerVO.java @@ -45,6 +45,6 @@ public class AnswerVO implements Serializable { private String answer; @ApiModelProperty("其它调用的参数") - private String[] extra; + private Object[] extra; } diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/vo/UpdateStationVO.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/vo/UpdateStationVO.java new file mode 100644 index 0000000..3ed167a --- /dev/null +++ b/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; + +} diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/vo/UpdateUsualVO.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/interactive/vo/UpdateUsualVO.java new file mode 100644 index 0000000..88a9c73 --- /dev/null +++ b/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; + +} diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/schedule/InteractiveSchedule.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/schedule/InteractiveSchedule.java index 56af36e..7af5118 100644 --- a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/schedule/InteractiveSchedule.java +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/schedule/InteractiveSchedule.java @@ -1,28 +1,40 @@ package com.hnac.hzims.bigmodel.schedule; 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.websocket.server.InteractiveWsServer; +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; +import com.hnac.hzinfo.sdk.v5.project.vo.ProjectVO; +import com.hnac.hzinfo.sdk.v5.scada.ScadaClient; +import com.hnac.hzinfo.sdk.v5.scada.vo.CanvasVO; import com.xxl.job.core.biz.model.ReturnT; import com.xxl.job.core.handler.annotation.XxlJob; import com.xxl.job.core.log.XxlJobLogger; import lombok.AllArgsConstructor; -import org.springblade.core.log.exception.ServiceException; -import org.springblade.core.tool.utils.Func; -import org.springblade.system.cache.ParamCache; +import org.springblade.core.tool.api.R; +import org.springblade.core.tool.utils.CollectionUtil; +import org.springblade.core.tool.utils.ObjectUtil; +import org.springblade.core.tool.utils.StringUtil; import org.springframework.data.redis.core.RedisTemplate; +import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Component; -import org.springframework.util.Assert; import org.springframework.web.socket.TextMessage; import org.springframework.web.socket.WebSocketSession; -import java.io.IOException; -import java.util.Enumeration; +import java.util.HashMap; import java.util.List; -import java.util.Set; +import java.util.Map; +import java.util.Optional; import java.util.concurrent.CompletableFuture; import java.util.concurrent.ThreadPoolExecutor; import java.util.stream.Collectors; @@ -37,11 +49,22 @@ import static com.hnac.hzims.bigmodel.schedule.XxlJobHandlerConstant.*; @AllArgsConstructor public class InteractiveSchedule { - private final RedisTemplate redisTemplate; private final InteractiveWsService wsService; + private final IInteractiveService interactiveService; + private final ThreadPoolExecutor getAnswerPoolExecutor; + private final RedisTemplate redisTemplate; + + private final IStationVideoTypeClient videoClient; + + private final ProjectClient projectClient; + + private final ScadaClient scadaClient; + + private final IStationClient stationClient; + // @XxlJob(GET_INTERACTIVE_RESULT) // public ReturnT execute(String params) { // String resultKey = ParamCache.getValue(GET_INTERACTIVE_RESULT); @@ -66,19 +89,107 @@ public class InteractiveSchedule { // } @XxlJob(GET_INTERACTIVE_RESULT) - public ReturnT execute(String params) { - List sessionIds = InteractiveSessionManager.getSessionIds(); - XxlJobLogger.log("开始获取到sessionId:"+sessionIds.stream().collect(Collectors.joining(","))); - List AnswerList = interactiveService.getAnswerBySessionIds(sessionIds.stream().collect(Collectors.joining(","))); - XxlJobLogger.log("获取到答案:"+JSON.toJSONString(AnswerList)); - AnswerList.parallelStream().forEach(answerVO -> { - CompletableFuture.runAsync(() -> { - XxlJobLogger.log("开始获取"+answerVO.getSessionId()+"答案!"); + public ReturnT getInteractiveResult(String params) { + Object json = redisTemplate.opsForValue().get(HZIMS_BIGMODEL_ASK_KEY); + if(ObjectUtil.isEmpty(json)){ + XxlJobLogger.log("未获取到问题标识,或者用户未进行提问!"); + return ReturnT.SUCCESS; + } + List sessionIds = JSONObject.parseArray(json.toString(),String.class); + if(CollectionUtil.isEmpty(sessionIds)){ + XxlJobLogger.log("问题都已经回答完毕!"); + return ReturnT.SUCCESS; + } + List answerList = interactiveService.getAnswerBySessionIds(String.join(",", sessionIds)); + answerList.parallelStream().forEach(answerVO -> CompletableFuture.runAsync(() -> { + XxlJobLogger.log("开始获取" + answerVO.getSessionId() + "答案!"); + if(sessionIds.contains(answerVO.getSessionId())){ WebSocketSession session = InteractiveSessionManager.get(answerVO.getSessionId()); TextMessage message = InteractiveSessionManager.getTextMessage("1",JSON.toJSONString(answerVO)); wsService.sendMessage(session,message); - }, getAnswerPoolExecutor); - }); + } + // 问题回答完成,去除redis问题标记 + if(answerVO.getRunning() == 0){ + sessionIds.remove(answerVO.getSessionId()); + } + redisTemplate.opsForValue().set(HZIMS_BIGMODEL_ASK_KEY, JSONObject.toJSONString(sessionIds)); + }, getAnswerPoolExecutor)); + return ReturnT.SUCCESS; + } + + @XxlJob(SYNCHRONOUS_VIDEO_INSTRUCT) + public ReturnT synchronousVideoInstruct(String params) { + Map request = new HashMap<>(2); + // 获取站点列表 + R> stationsR = stationClient.list(new StationEntity()); + if(!stationsR.isSuccess() || CollectionUtil.isEmpty(stationsR.getData())) { + XxlJobLogger.log("获取站点列表失败!"); + return ReturnT.FAIL; + } + List 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> videoListR = videoClient.list(new StationVideoTypeEntity()); + if(!videoListR.isSuccess() || CollectionUtil.isEmpty(videoListR.getData())) { + XxlJobLogger.log("获取视频列表失败!"); + return ReturnT.FAIL; + } + List 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; + } + + @XxlJob(SYNCHRONOUS_SCADA_INSTRUCT) + public ReturnT synchronousScadaInstruct(String params) { + // 查询项目数据 + Result> projects = projectClient.getProjectByAppId(); + if(!projects.isSuccess() || CollectionUtil.isEmpty(projects.getData())){ + return ReturnT.SUCCESS; + } + // 请求fdp同步实时画面方法参数定义 + Map param = new HashMap<>(2); + List stations = projects.getData().stream().map(station -> { + UpdateStationVO updateStation = new UpdateStationVO(); + updateStation.setId(station.getId()); + updateStation.setName(station.getName()); + return updateStation; + }).collect(Collectors.toList()); + param.put("stations", stations); + // 查询画面信息 + Result> canvas = scadaClient.getCanvasList(projects.getData().stream().map(ProjectVO::getId).collect(Collectors.toList())); + if(!canvas.isSuccess() || CollectionUtil.isEmpty(canvas.getData())) { + return ReturnT.SUCCESS; + } + List updateUsuals = canvas.getData().stream().map(canva -> { + UpdateUsualVO usualVO = new UpdateUsualVO(); + usualVO.setStationId(canva.getProjectId()); + usualVO.setName(canva.getName()); + // 画面id = + String id = Optional.of(canva.getPicSource()).map(String::valueOf).orElse("") + "^" + + Optional.ofNullable(canva.getContext()).orElse("") + "^" + + Optional.ofNullable(canva.getStationNum()).orElse("") + "^" + + Optional.ofNullable(canva.getProjectId()).orElse("") + "^" + + Optional.ofNullable(canva.getTaskId()).map(String::valueOf).orElse("") + "^" + + Optional.ofNullable(canva.getName()).orElse("") + "^" + + Optional.ofNullable(canva.getId()).map(String::valueOf).orElse("") + "^"; + usualVO.setId(id); + return usualVO; + }).collect(Collectors.toList()); + param.put("canvases", updateUsuals); + Boolean status = interactiveService.updateCanvas(param); return ReturnT.SUCCESS; } } diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/schedule/XxlJobHandlerConstant.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/schedule/XxlJobHandlerConstant.java index 708d3e8..9d3cefd 100644 --- a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/schedule/XxlJobHandlerConstant.java +++ b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/schedule/XxlJobHandlerConstant.java @@ -6,8 +6,16 @@ package com.hnac.hzims.bigmodel.schedule; */ public interface XxlJobHandlerConstant { + /**获取问答结果**/ String GET_INTERACTIVE_RESULT = "getInteractiveResult"; + /**同步视频指令**/ + String SYNCHRONOUS_VIDEO_INSTRUCT = "synchronousVideoInstruct"; + + String SYNCHRONOUS_SCADA_INSTRUCT = "synchronousScadaInstruct"; + String INTERACTIVE_RESULT_KEY = "hzllm:interactive:result"; + String HZIMS_BIGMODEL_ASK_KEY = "hzims:bigmodel:ask:key"; + } diff --git a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/websocket/handler/InteractiveHandler.java b/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/websocket/handler/InteractiveHandler.java index a2dc3c6..3a25314 100644 --- a/hzims-service/hzims-big-model/src/main/java/com/hnac/hzims/bigmodel/websocket/handler/InteractiveHandler.java +++ b/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.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.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; @@ -15,6 +18,7 @@ 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.Optional; import java.util.Set; @@ -56,14 +60,45 @@ public class InteractiveHandler extends TextWebSocketHandler { } catch (IOException e) { throw new RuntimeException(e); } + }else { + String sessionId = InteractiveSessionManager.getEntryBySession(session).getKey(); + this.handleMessage(messageJSON,sessionId); } - else { - // 发送问题 - String context = messageJSON.getString("context"); - String userId = messageJSON.getString("userId"); + } + + private void handleMessage(JSONObject messageContext,String sessionId) { + Boolean isSpecial = messageContext.getBoolean("isSpecial"); + if(Func.isEmpty(isSpecial) || !isSpecial) { + String context = messageContext.getString("context"); + String userId = messageContext.getString("userId"); 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)); } + else { + String funcCode = messageContext.getString("funcCode"); + FuncRouteEnum funcEnum = FuncRouteEnum.getEnumByFuncCode(funcCode); + switch (funcEnum) { + case CHOOSE_STATION: + this.handleChooseStation(messageContext,sessionId); + break; + default: + break; + } + } + } + + private void handleChooseStation(JSONObject messageContext,String sessionId) { + IInteractiveService interactiveService = SpringUtil.getBean(IInteractiveService.class); + String userId = messageContext.getString("userId"); + String funcCode = messageContext.getString("funcCode"); + StationSelectionVO selectionVO = messageContext.getObject("selection",StationSelectionVO.class); + JSONObject data = new JSONObject(); + data.put("station_id",selectionVO.getId()); + data.put("station_name",selectionVO.getName()); + Map extra = new HashMap<>(2); + extra.put("func",funcCode); + extra.put("data",data); + interactiveService.specialAsk(sessionId,userId,extra); } } diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/fill/service/impl/GenerateServiceImpl.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/fill/service/impl/GenerateServiceImpl.java index 2e170cd..bc33c70 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/fill/service/impl/GenerateServiceImpl.java +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/fill/service/impl/GenerateServiceImpl.java @@ -60,7 +60,7 @@ public class GenerateServiceImpl extends BaseServiceImpl listByStationId(String stationId) { List result = stationVideoTypeService.list(new LambdaQueryWrapper(){{ eq(StationVideoTypeEntity::getStationId,stationId); }}); return result; } + + @Override + @GetMapping(LIST) + public R> list(StationVideoTypeEntity req) { + QueryWrapper queryWrapper = Condition.getQueryWrapper(req); + return R.data(stationVideoTypeService.list(queryWrapper)); + } + + @Override + @GetMapping(GET_BY_ID) + public R getById(@RequestParam Long id) { + return R.data(stationVideoTypeService.getById(id,0)); + } } diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/service/IStationVideoTypeService.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/service/IStationVideoTypeService.java index 3862dff..24da4a6 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/service/IStationVideoTypeService.java +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/service/IStationVideoTypeService.java @@ -81,4 +81,6 @@ public interface IStationVideoTypeService extends BaseService 0.9){ + }else if((station.getWaterLevel() / station.getWaterLevelMax()) > 0.8){ station.setWaterColor(1); } } diff --git a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/service/impl/StationVideoTypeServiceImpl.java b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/service/impl/StationVideoTypeServiceImpl.java index ca4272b..1b96b23 100644 --- a/hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/service/impl/StationVideoTypeServiceImpl.java +++ b/hzims-service/operational/src/main/java/com/hnac/hzims/operational/station/service/impl/StationVideoTypeServiceImpl.java @@ -274,6 +274,11 @@ public class StationVideoTypeServiceImpl extends BaseServiceImpl deviceMap.get(c.getString("encodeDevIndexCode")))); } + @Override + public String getRtspAddressByVideo(StationVideoTypeEntity req) { + return null; + } + private HikVideoAreaTreeVO generateAreaTree(Map> videoAreaMapByParent,HikVideoAreaVO area) { HikVideoAreaTreeVO parentTree = BeanUtil.copy(area,HikVideoAreaTreeVO.class); if(CollectionUtil.isNotEmpty(videoAreaMapByParent.get(area.getIndexCode()))) { diff --git a/pom.xml b/pom.xml index 182b612..47b1aaa 100644 --- a/pom.xml +++ b/pom.xml @@ -49,12 +49,14 @@ org.springblade blade-system-api - ${bladex.project.version} + + 5.1.1.RELEASE.fix.4 org.springblade blade-user-api - ${bladex.project.version} + + 5.1.1.RELEASE.fix.4 org.springblade @@ -74,7 +76,8 @@ com.hnac.hzinfo.data hzinfo-data-sdk - ${bladex.project.version} + + 5.1.1.RELEASE.fix.4 com.xuxueli