Browse Source

星逻算法-预警记录-dubbo改feign请求

pull/7/head
时子升 2 weeks ago
parent
commit
02388eacc2
  1. 20
      dk-api/api-business/src/main/java/org/dromara/business/api/domain/RemoteBusinessAlertRequest.java
  2. 24
      dk-modules/business/src/main/java/org/dromara/business/controller/BusinessAlertController.java
  3. 16
      dk-modules/sample/src/main/java/org/dromara/sample/feign/RemoteBusinessAlertFeign.java
  4. 18
      dk-modules/sample/src/main/java/org/dromara/sample/feign/RemoteConfigFeign.java
  5. 47
      dk-modules/sample/src/main/java/org/dromara/sample/manage/service/impl/SampleEngineRecordServiceImpl.java
  6. 5
      dk-modules/system/src/main/java/org/dromara/system/controller/system/SysConfigController.java

20
dk-api/api-business/src/main/java/org/dromara/business/api/domain/RemoteBusinessAlertRequest.java

@ -0,0 +1,20 @@
package org.dromara.business.api.domain;
import lombok.Data;
import org.dromara.business.api.domain.vo.RemoteBusinessAlertVo;
import java.util.List;
/**
* 预警任务对象 business_alert
*
* @author LionLi
* @date 2025-02-27
*/
@Data
public class RemoteBusinessAlertRequest {
private List<RemoteBusinessAlertVo> alertVoList;
private String activeProfile;
}

24
dk-modules/business/src/main/java/org/dromara/business/controller/BusinessAlertController.java

@ -1,40 +1,31 @@
package org.dromara.business.controller;
import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.hutool.core.convert.Convert;
import cn.hutool.core.util.ObjectUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.nacos.client.utils.TenantUtil;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.http.HttpServletResponse;
import lombok.RequiredArgsConstructor;
import org.apache.dubbo.config.annotation.DubboReference;
import org.dromara.business.api.domain.RemoteBusinessAlertRequest;
import org.dromara.business.domain.BusinessAlert;
import org.dromara.business.domain.bo.BusinessAlertBo;
import org.dromara.business.domain.vo.BusinessAlertVo;
import org.dromara.business.service.IBusinessAlertService;
import org.dromara.business.utils.MinioUntil;
import org.dromara.business.utils.constants.MinIOConstants;
import org.dromara.common.core.domain.R;
import org.dromara.common.core.utils.DateUtils;
import org.dromara.common.log.annotation.Log;
import org.dromara.common.log.enums.BusinessType;
import org.dromara.common.mybatis.core.page.PageQuery;
import org.dromara.common.mybatis.core.page.TableDataInfo;
import org.dromara.common.satoken.utils.LoginHelper;
import org.dromara.common.tenant.helper.TenantHelper;
import org.dromara.common.web.core.BaseController;
import org.dromara.system.api.RemoteNoticeService;
import org.dromara.system.api.RemoteSubmailConfigService;
import org.dromara.system.api.domain.bo.RemoteNoticeBo;
import org.dromara.workflow.api.RemoteWorkflowService;
import org.dromara.workflow.api.domain.RemoteStartProcess;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import java.io.IOException;
import java.util.Date;
import java.util.List;
/**
@ -173,6 +164,15 @@ public class BusinessAlertController extends BaseController {
businessAlertService.exportAlert(bo,response);
}
@PostMapping("/saveBusinessAlert")
// public Boolean saveBusinessAlert(List<RemoteBusinessAlertVo> alertVoList, String activeProfile) {
// public Boolean saveBusinessAlert(@RequestBody RemoteBusinessAlertRequest requestObj) {
public Boolean saveBusinessAlert(@RequestBody JSONObject requestJSON) {
// return businessAlertService.batchAddBusinessAlert(alertVoList, activeProfile);
RemoteBusinessAlertRequest requestObj = JSONUtil.toBean(requestJSON, RemoteBusinessAlertRequest.class);
return businessAlertService.batchAddBusinessAlert(requestObj.getAlertVoList(), requestObj.getActiveProfile());
}
// @Operation(summary ="ai实时流预警保存-用于演示",description = "ai实时流预警保存-用于演示")

16
dk-modules/sample/src/main/java/org/dromara/sample/feign/RemoteBusinessAlertFeign.java

@ -0,0 +1,16 @@
package org.dromara.sample.feign;
import cn.hutool.json.JSONObject;
import org.dromara.business.api.domain.RemoteBusinessAlertRequest;
import org.dromara.common.core.domain.R;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
@FeignClient(name = "gateway",path = "business")
public interface RemoteBusinessAlertFeign {
@PostMapping("/saveBusinessAlert")
// public R<Boolean> saveBusinessAlert(@RequestBody RemoteBusinessAlertRequest requestObj);
public R<Boolean> saveBusinessAlert(@RequestBody JSONObject requestObj);
}

18
dk-modules/sample/src/main/java/org/dromara/sample/feign/RemoteConfigFeign.java

@ -0,0 +1,18 @@
package org.dromara.sample.feign;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestParam;
import java.util.List;
@FeignClient(name = "gateway",path = "system")
public interface RemoteConfigFeign {
@GetMapping("/config/configKeyFeign/{configKey}")
String getConfigKey(@PathVariable String configKey);
}

47
dk-modules/sample/src/main/java/org/dromara/sample/manage/service/impl/SampleEngineRecordServiceImpl.java

@ -14,7 +14,6 @@ import com.fasterxml.jackson.databind.ObjectMapper;
import io.seata.common.util.StringUtils;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboReference;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
@ -23,17 +22,18 @@ import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;
import org.dromara.business.api.RemoteBusinessAlertService;
import org.dromara.business.api.domain.RemoteBusinessAlertRequest;
import org.dromara.business.api.domain.vo.RemoteBusinessAlertVo;
import org.dromara.common.core.utils.file.MimeTypeUtils;
import org.dromara.common.oss.core.OssClient;
import org.dromara.common.oss.entity.UploadResult;
import org.dromara.common.oss.factory.OssFactory;
import org.dromara.common.sdk.mqtt.CommonTopicRequest;
import org.dromara.sample.common.util.Md5Utils;
import org.dromara.sample.feign.RemoteBusinessAlertFeign;
import org.dromara.sample.feign.RemoteConfigFeign;
import org.dromara.sample.feign.RemoteSystemFeign;
import org.dromara.sample.manage.config.XingluoApiConfig;
import org.dromara.sample.manage.config.XingluoApiEnum;
import org.dromara.sample.manage.mapper.IDeviceMapper;
import org.dromara.sample.manage.mapper.ISampleEngineRecordMapper;
import org.dromara.sample.manage.mapper.ITaskJobMapper;
import org.dromara.sample.manage.mapper.SampleWarningRecordMapper;
@ -43,19 +43,16 @@ import org.dromara.sample.manage.model.entity.TaskJobEntity;
import org.dromara.sample.manage.model.entity.WarningRecordEntity;
import org.dromara.sample.manage.service.IDeviceService;
import org.dromara.sample.manage.service.ISampleEngineRecordService;
import org.dromara.sample.manage.service.ISampleWarningRecordService;
import org.dromara.sample.media.constant.MinIOConstants;
import org.dromara.sample.wayline.mapper.IWaylineJobMapper;
import org.dromara.sample.wayline.model.entity.WaylineJobEntity;
import org.dromara.system.api.RemoteConfigService;
import org.dromara.system.api.RemoteDictService;
import org.json.JSONArray;
import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import jakarta.annotation.Resource;
import java.io.IOException;
import java.io.InputStream;
import java.net.URI;
@ -93,12 +90,15 @@ public class SampleEngineRecordServiceImpl implements ISampleEngineRecordService
// @Autowired
private final IWaylineJobMapper waylineJobMapper;
@DubboReference
private RemoteConfigService remoteConfigService;
@Resource
private RemoteConfigFeign remoteConfigFeign;
@Resource
private RemoteSystemFeign remoteSystemFeign;
@DubboReference
private final RemoteBusinessAlertService businessAlertService;
@Resource
private RemoteBusinessAlertFeign remoteBusinessAlertFeign;
@ -163,8 +163,14 @@ public class SampleEngineRecordServiceImpl implements ISampleEngineRecordService
@Override
public Map<String, Object> startEngine(Map<String, Object> objectMap){
System.out.println("objectMap" + objectMap);
// String configKey = remoteSystemFeign.getConfigKey("xingluo.auto.submit");//通
// System.out.println("configKey"+configKey);
EngineRecordEntity record = new EngineRecordEntity();
String ip = remoteConfigService.selectStreamIp();
// String ip = remoteConfigService.selectStreamIp();
String ip = remoteConfigFeign.getConfigKey("stream");
System.out.println(ip);
ip = "121.237.182.235";//服务器使用ip
String md5 = Md5Utils.hash("xuzhou_ai"); //获取token + 设置请求Header和Body(如JSON)
JSONObject jsonObj = new JSONObject();
jsonObj.put("username", sanitize("xuzhou_ai")); // sanitize函数见下文
@ -213,10 +219,12 @@ public class SampleEngineRecordServiceImpl implements ISampleEngineRecordService
//测试环境,直接接收url,跳过无人机
// Object rtmpUrlParam = objectMap.get("inputUrl");
jsonObj2.put("input_url", "rtmp://114.235.183.163/live/livesteam/1581F6Q8X24CE00G02S4-81-0-0");//预览接口必须要传rtmp,不能是flv
jsonObj2.put("push_url", "rtmp://114.235.183.163/live/livesteam/1581F6Q8X24CE00G02S4-81-0-0ai1");//预览接口必须要传rtmp,不能是flv
// jsonObj2.put("input_url", "rtmp://114.235.183.163/live/livesteam/1581F6Q8X24CE00G02S4-81-0-0");//预览接口必须要传rtmp,不能是flv
// jsonObj2.put("push_url", "rtmp://114.235.183.163/live/livesteam/1581F6Q8X24CE00G02S4-81-0-0ai1");//预览接口必须要传rtmp,不能是flv
System.out.println(jsonObj2.toString());
String responseBody2 = PostRequest(jsonObj2, xingluoApiConfig.getEngineStart(),token); //"http://60.204.247.65:8100/Third/Engine/Start"
System.out.println(responseBody2);
ObjectMapper mapper1 = new ObjectMapper();
EngineResponse response = null;
try {
@ -336,6 +344,7 @@ public class SampleEngineRecordServiceImpl implements ISampleEngineRecordService
CallBackDTO callBackVo = JSONUtil.toBean(resObject, CallBackDTO.class);
String taskIdStr = entries.getStr("taskId");
if(StrUtil.isBlank(taskIdStr)){return 0;} //无任务ID拦截
if(callBackVo.getEvents().isEmpty()){ return 0;}
//基于历史记录,找相同设备- trackId是否相同,不同才保存, (每次记录中eventId都不同,所以不做参考)
//同一图片上传可能包含多个物体,传值可能是 h1v93,或者fdi32,或者h1v93,fdi32, 只要trackIds不同,就保存记录
@ -436,7 +445,13 @@ public class SampleEngineRecordServiceImpl implements ISampleEngineRecordService
//businessAlertConstructInfo数据
alertVoList.add(remoteBusinessAlertVo);
}
businessAlertService.saveBusinessAlert(alertVoList,activeProfile); //触发预警消息
// businessAlertService.saveBusinessAlert(alertVoList,activeProfile); //远程触发预警消息
RemoteBusinessAlertRequest remoteBusinessAlertRequest = new RemoteBusinessAlertRequest();
remoteBusinessAlertRequest.setAlertVoList(alertVoList);
remoteBusinessAlertRequest.setActiveProfile(activeProfile);
cn.hutool.json.JSONObject requestObj = new cn.hutool.json.JSONObject(remoteBusinessAlertRequest);
remoteBusinessAlertFeign.saveBusinessAlert(requestObj);
return callBackVo.getEvents().size();
}

5
dk-modules/system/src/main/java/org/dromara/system/controller/system/SysConfigController.java

@ -73,6 +73,11 @@ public class SysConfigController extends BaseController {
return R.ok("操作成功", configService.selectConfigByKey(configKey));
}
@GetMapping(value = "/configKeyFeign/{configKey}")
public String getConfigKeyFeign(@PathVariable String configKey) {
return configService.selectConfigByKey(configKey);
}
/**
* 新增参数配置
*/

Loading…
Cancel
Save