Browse Source

星逻算法- 1.record记录保存扩展 2.预警提示-联动工作流+前台提示

dev
时子升 2 weeks ago
parent
commit
dc7adedf99
  1. 4
      dk-modules/business/src/main/java/org/dromara/business/controller/BusinessAlertController.java
  2. 2
      dk-modules/business/src/main/java/org/dromara/business/dubbo/RemoteBusinessAlertServiceImpl.java
  3. 3
      dk-modules/business/src/main/java/org/dromara/business/service/IBusinessAlertService.java
  4. 68
      dk-modules/business/src/main/java/org/dromara/business/service/impl/BusinessAlertServiceImpl.java
  5. 2
      dk-modules/sample/src/main/java/org/dromara/sample/feign/RemoteBusinessAlertFeign.java
  6. 3
      dk-modules/sample/src/main/java/org/dromara/sample/manage/model/entity/EngineRecordEntity.java
  7. 6
      dk-modules/sample/src/main/java/org/dromara/sample/manage/model/entity/TaskJobEntity.java
  8. 3
      dk-modules/sample/src/main/java/org/dromara/sample/manage/model/entity/WarningRecordEntity.java
  9. 36
      dk-modules/sample/src/main/java/org/dromara/sample/manage/service/impl/SampleEngineRecordServiceImpl.java

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

@ -170,7 +170,9 @@ public class BusinessAlertController extends BaseController {
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());
Long pushDeptId = requestJSON.getLong("pushDeptId");
return businessAlertService.batchAddBusinessAlert(requestObj.getAlertVoList(), requestObj.getActiveProfile(), pushDeptId);
}

2
dk-modules/business/src/main/java/org/dromara/business/dubbo/RemoteBusinessAlertServiceImpl.java

@ -34,7 +34,7 @@ public class RemoteBusinessAlertServiceImpl implements RemoteBusinessAlertServic
@Override
public Boolean saveBusinessAlert(List<RemoteBusinessAlertVo> alertVoList, String activeProfile) {
return businessAlertService.batchAddBusinessAlert(alertVoList, activeProfile);
return businessAlertService.batchAddBusinessAlert(alertVoList, activeProfile,null);
}
/**

3
dk-modules/business/src/main/java/org/dromara/business/service/IBusinessAlertService.java

@ -49,7 +49,7 @@ public interface IBusinessAlertService {
* @param alertVoList 预警任务
* @return 是否新增成功
*/
Boolean batchAddBusinessAlert(List<RemoteBusinessAlertVo> alertVoList, String activeProfile);
Boolean batchAddBusinessAlert(List<RemoteBusinessAlertVo> alertVoList, String activeProfile,Long pushDeptId);
/**
* 修改预警任务
@ -108,5 +108,6 @@ public interface IBusinessAlertService {
void exportAlert(BusinessAlertBo bo, HttpServletResponse response) throws IOException;
void pushAlert(Long alertId, String deptId, String deptName);
void pushAlertSimple(Long alertId, String deptId, String deptName);
}

68
dk-modules/business/src/main/java/org/dromara/business/service/impl/BusinessAlertServiceImpl.java

@ -49,6 +49,7 @@ import org.dromara.resource.api.RemoteMessageService;
import org.dromara.system.api.*;
import org.dromara.system.api.domain.bo.RemoteNoticeBo;
import org.dromara.system.api.domain.vo.RemoteAiLabelPostVo;
import org.dromara.system.api.domain.vo.RemoteDeptVo;
import org.dromara.system.api.domain.vo.RemoteUserVo;
import org.dromara.business.domain.BusinessAlertConstructInfoOss;
import org.dromara.business.mapper.BusinessAlertConstructInfoOssMapper;
@ -127,6 +128,9 @@ public class BusinessAlertServiceImpl implements IBusinessAlertService {
@DubboReference(timeout = 30000)
private RemoteNoticeService remoteNoticeService;
@DubboReference
private RemoteDeptService remoteDeptService;
/**
* 新增预警任务
@ -264,10 +268,11 @@ public class BusinessAlertServiceImpl implements IBusinessAlertService {
/**
* 批量添加
* @param alertVoList 预警任务
* @param pushDeptId 星逻算法+pushDeptId 可以自动推送预警记录
* @return
*/
@Override
public Boolean batchAddBusinessAlert(List<RemoteBusinessAlertVo> alertVoList, String activeProfile) {
public Boolean batchAddBusinessAlert(List<RemoteBusinessAlertVo> alertVoList, String activeProfile, Long pushDeptId) {
List<BusinessAlert> businessAlerts = alertVoList.stream().map(alert -> {
BusinessAlert businessAlert = new BusinessAlert();
alert.setCreateTime(new Date());
@ -292,20 +297,6 @@ public class BusinessAlertServiceImpl implements IBusinessAlertService {
boolean b = this.baseMapper.insertBatch(businessAlerts);
//推送消息-基于部门-找用户 发送json格式 --此时没有deptId,无效预警
for (BusinessAlert alert : businessAlerts) {
if(ObjectUtil.isEmpty(alert.getDeptId())){
continue;
}
ArrayList<Long> deptIds = new ArrayList<>();
deptIds.add(Long.parseLong(alert.getDeptId()));
List<RemoteUserVo> remoteUserVos = remoteUserService.selectUsersByDeptIds(deptIds);
List<Long> userIds = remoteUserVos.stream().map(RemoteUserVo::getUserId).collect(Collectors.toList());
String imagePreviewUrl = MinioUntil.getObjectUrlOne(MinIOConstants.BUCKET_DKCY, alert.getImages(), 3600).toString();
JSONObject jsonObject = setupBusinessAlertSSEObj(alert, imagePreviewUrl);
remoteMessageService.publishMessage(userIds, jsonObject.toString() );
}
/*List<BusinessAlertConstructInfo> alertConstructInfoList = businessAlerts.stream().map(alert -> {
BusinessAlertConstructInfoVo alertConstructInfoVo = alert.getAlertConstructInfoVo();
@ -318,17 +309,32 @@ public class BusinessAlertServiceImpl implements IBusinessAlertService {
//基于系统参数判断是否要自动提交
boolean submitFlag = remoteConfigService.selectXingluoAutoSubmit();
if(submitFlag){
System.out.println("记录内容提交");
String collect = alertVoList.stream().map(RemoteBusinessAlertVo::getLabelCn).collect(Collectors.joining(","));
System.out.println(collect);
for (BusinessAlert businessAlert : businessAlerts) {
// this.pushAlert(businessAlert.getAlertId(),);
if(!submitFlag){ return b; }
if(ObjectUtil.isEmpty(pushDeptId)){ return b;}
RemoteDeptVo remoteDeptVo = remoteDeptService.selectDeptById(pushDeptId);
/** 更新记录 **/
System.out.println("记录内容提交");
String collect = alertVoList.stream().map(RemoteBusinessAlertVo::getLabelCn).collect(Collectors.joining(","));
System.out.println(collect);
for (BusinessAlert businessAlert : businessAlerts) {
// this.pushAlert(businessAlert.getAlertId(), businessAlert.getDeptId());
this.pushAlertSimple(businessAlert.getId(), pushDeptId.toString(),remoteDeptVo.getDeptName());
}
}
/** 推送消息-基于部门-找用户 发送json格式 --没有deptId就是无效预警 **/
for (BusinessAlert alert : businessAlerts) {
if(ObjectUtil.isEmpty(pushDeptId)){ continue;} //ObjectUtil.isEmpty(alert.getDeptId()) ||
}
ArrayList<Long> deptIds = new ArrayList<>();
deptIds.add(pushDeptId);
List<RemoteUserVo> remoteUserVos = remoteUserService.selectUsersByDeptIds(deptIds);
List<Long> userIds = remoteUserVos.stream().map(RemoteUserVo::getUserId).collect(Collectors.toList());
String imagePreviewUrl = MinioUntil.getObjectUrlOne(MinIOConstants.BUCKET_DKCY, alert.getImages(), 3600).toString();
JSONObject jsonObject = setupBusinessAlertSSEObj(alert, imagePreviewUrl);
remoteMessageService.publishMessage(userIds, jsonObject.toString() );
}
return b;
}
@ -1071,6 +1077,22 @@ public class BusinessAlertServiceImpl implements IBusinessAlertService {
remoteSubmailConfigService.remoteCmdSend("smsMultixsend", JSON.toJSONString(businessAlert));
}
//更新工作流-简版
@Override
public void pushAlertSimple(Long alertId, String deptId, String deptName) {
BusinessAlert businessAlert= this.getBusinessAlert(alertId);
if(!ObjectUtil.hasEmpty(deptId,deptName)){
businessAlert.setDeptName(deptName);
businessAlert.setDeptId(deptId);
}
businessAlert.setCreateTime(new Date());
//businessAlert.setJobName(deptName + businessAlert.getLabelCn() + DateUtils.parseDateToStr("yyyy-MM-dd HH:mm:ss",businessAlert.getCreateTime()));
this.updateBusinessAlert(businessAlert);
RemoteStartProcess startProcess = new RemoteStartProcess();
startProcess.setBusinessId(String.valueOf(businessAlert.getId()));
startProcess.setFlowCode("alertChz");
remoteWorkflowService.startWorkFlowBatch(List.of(startProcess));
}
// 压缩图片方法
private static BufferedImage compressImage(BufferedImage originalImage, int targetWidth, int targetHeight) {

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

@ -12,5 +12,5 @@ public interface RemoteBusinessAlertFeign {
@PostMapping("/saveBusinessAlert")
// public R<Boolean> saveBusinessAlert(@RequestBody RemoteBusinessAlertRequest requestObj);
public R<Boolean> saveBusinessAlert(@RequestBody JSONObject requestObj);
public Boolean saveBusinessAlert(@RequestBody JSONObject requestObj);
}

3
dk-modules/sample/src/main/java/org/dromara/sample/manage/model/entity/EngineRecordEntity.java

@ -62,4 +62,7 @@ public class EngineRecordEntity implements Serializable {
@TableField(value = "stop_res_data_str")
private String stopResDataStr;
@TableField(value = "push_dept_id")
private Long pushDeptId;
}

6
dk-modules/sample/src/main/java/org/dromara/sample/manage/model/entity/TaskJobEntity.java

@ -32,6 +32,12 @@ public class TaskJobEntity implements Serializable {
private String deviceSn;
@TableField(value = "extra_type") //算法类型
private String extraType;
@TableField(value = "push_dept_id")
private Long pushDeptId;
@TableField(fill = FieldFill.INSERT)
private Date createTime;

3
dk-modules/sample/src/main/java/org/dromara/sample/manage/model/entity/WarningRecordEntity.java

@ -26,6 +26,9 @@ public class WarningRecordEntity implements Serializable {
@TableField(value = "task_id")
private String taskId;
@TableField(value = "device_sn")
private String deviceSn;
@TableField(value = "algo_id")
private Integer algoId; //算法 id")

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

@ -24,6 +24,7 @@ import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;
import org.dromara.business.api.domain.RemoteBusinessAlertRequest;
import org.dromara.business.api.domain.vo.RemoteBusinessAlertVo;
import org.dromara.common.core.domain.R;
import org.dromara.common.core.utils.file.MimeTypeUtils;
import org.dromara.common.oss.core.OssClient;
import org.dromara.common.oss.entity.UploadResult;
@ -164,9 +165,22 @@ public class SampleEngineRecordServiceImpl implements ISampleEngineRecordService
@Override
public Map<String, Object> startEngine(Map<String, Object> objectMap){
System.out.println("objectMap" + objectMap);
String deviceSn = MapUtil.getStr(objectMap, "deviceSn", "");
String type = MapUtil.getStr(objectMap, "type", ""); // objectMap.get("type").toString();
DeviceDTO deviceDTO = deviceService.getDeviceBySn(deviceSn).orElse(null);
//获取rtmpUrl + 默认记录上传 pushDeptId
String rtmpUrl = "";
Long pushDeptId = null;
if (deviceDTO != null) {
String childDeviceRtmpUrl = deviceService.getChildDeviceStreamUrlByDeviceSn(deviceDTO.getChildDeviceSn());
rtmpUrl = childDeviceRtmpUrl;
pushDeptId = deviceDTO.getPushDeptId();
}
// String configKey = remoteSystemFeign.getConfigKey("xingluo.auto.submit");//通
// System.out.println("configKey"+configKey);
EngineRecordEntity record = new EngineRecordEntity();
record.setPushDeptId(pushDeptId);
// String ip = remoteConfigService.selectStreamIp();
String ip = remoteConfigFeign.getConfigKey("stream");
System.out.println(ip);
@ -185,21 +199,12 @@ public class SampleEngineRecordServiceImpl implements ISampleEngineRecordService
String algorithmResponseBody = null;
String taskId = "";
String missionBatch = "";
String deviceSn = MapUtil.getStr(objectMap, "deviceSn", "");
//获取rtmpUrl
String rtmpUrl = "";
DeviceDTO deviceDTO = deviceService.getDeviceBySn(deviceSn).orElse(null);
if (deviceDTO != null) {
String childDeviceRtmpUrl = deviceService.getChildDeviceStreamUrlByDeviceSn(deviceDTO.getChildDeviceSn());
rtmpUrl = childDeviceRtmpUrl;
}
//查询用户开通的场景
Object rtmpUrlParam = objectMap.get("rtmpUrl");
String pushUrl = "rtmp://" + ip + "/live/livesteam/" + rtmpUrl + "ai1";
if (StringUtils.isNotEmpty(token)){
JSONObject jsonObj2 = new JSONObject();
String type = objectMap.get("type").toString();
if (StringUtils.isNotEmpty(type)){ //2004_ext 算法名称
List<String> list = Arrays.asList(type.split(","));
jsonObj2.put("scene", "可见光"); // sanitize函数见下文
@ -266,6 +271,8 @@ public class SampleEngineRecordServiceImpl implements ISampleEngineRecordService
taskJobEntity.setJobId(jobIdStr);
taskJobEntity.setTaskId(objectMap.get("task_id").toString());
taskJobEntity.setDeviceSn(deviceSn);
taskJobEntity.setExtraType(type);
taskJobEntity.setPushDeptId(pushDeptId);
taskJobMapper.insert(taskJobEntity);
return map;
}
@ -363,7 +370,8 @@ public class SampleEngineRecordServiceImpl implements ISampleEngineRecordService
// .eq(WarningRecordEntity::getTrackIds, trackIds)
// .count();
LambdaQueryWrapper<WarningRecordEntity> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(WarningRecordEntity::getTaskId, taskIdStr)
queryWrapper
.eq(WarningRecordEntity::getTaskId, taskIdStr)
.eq(WarningRecordEntity::getExtraType, extraTypeStr)
.eq(WarningRecordEntity::getTrackIds, trackIds);
Long count = sampleWarningRecordMapper.selectCount(queryWrapper);
@ -391,6 +399,8 @@ public class SampleEngineRecordServiceImpl implements ISampleEngineRecordService
String activeProfile = "w_nantong";
ArrayList<RemoteBusinessAlertVo> alertVoList = new ArrayList<>();
Long pushDeptId = null;
String pushDeptName = "";
for (WarningRecordEntity warningRecordEntity : warningRecordList) {
RemoteBusinessAlertVo remoteBusinessAlertVo = new RemoteBusinessAlertVo();
if(ObjectUtil.isEmpty(warningRecordEntity.getTaskId())){ continue;} //空数据跳过
@ -405,9 +415,11 @@ public class SampleEngineRecordServiceImpl implements ISampleEngineRecordService
TaskJobEntity taskJobEntity = taskJobMapper.selectOne(taskJobquery);
String deviceSn = "";
if(BeanUtil.isNotEmpty(taskJobEntity)){
String jobId = taskJobEntity.getJobId();
deviceSn = taskJobEntity.getDeviceSn();
pushDeptId = taskJobEntity.getPushDeptId();
if(StrUtil.equals("-1",jobId)){ //没有jobId,给个默认名称
remoteBusinessAlertVo.setJobId("-1");
remoteBusinessAlertVo.setJobName("手动飞行" + "-" +remoteBusinessAlertVo.getLabelCn()+ DateUtil.format(new Date(), "yyyy-MM-dd HH:mm:ss"));
@ -445,13 +457,15 @@ public class SampleEngineRecordServiceImpl implements ISampleEngineRecordService
//businessAlertConstructInfo数据
alertVoList.add(remoteBusinessAlertVo);
}
// 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);
requestObj.set("pushDeptId", pushDeptId);
Boolean booleanR = remoteBusinessAlertFeign.saveBusinessAlert(requestObj);
return callBackVo.getEvents().size();
}

Loading…
Cancel
Save