Browse Source

雷达关联监控点查询接口

develop
王兴琳 4 months ago
parent
commit
89ce6d2d23
  1. 7
      zc-business/pom.xml
  2. 11
      zc-business/src/main/java/com/zc/business/controller/DcWarningController.java
  3. 37
      zc-business/src/main/java/com/zc/business/controller/VideoController.java
  4. 4
      zc-business/src/main/java/com/zc/business/enums/UniversalEnum.java
  5. 4
      zc-business/src/main/java/com/zc/business/message/device/handler/DeviceMessageHandler.java
  6. 4
      zc-business/src/main/java/com/zc/business/service/IDcWarningService.java
  7. 456
      zc-business/src/main/java/com/zc/business/service/impl/DcWarningServiceImpl.java

7
zc-business/pom.xml

@ -21,6 +21,13 @@
<artifactId>org.eclipse.paho.client.mqttv3</artifactId> <artifactId>org.eclipse.paho.client.mqttv3</artifactId>
<version>1.2.2</version> <version>1.2.2</version>
</dependency> </dependency>
<!-- 雷达关联监控点-->
<dependency>
<groupId>com.hikvision.ga</groupId>
<artifactId>artemis-http-client</artifactId>
<version>1.1.12.RELEASE</version>
</dependency>
<!-- FTTP--> <!-- FTTP-->
<dependency> <dependency>
<groupId>commons-net</groupId> <groupId>commons-net</groupId>

11
zc-business/src/main/java/com/zc/business/controller/DcWarningController.java

@ -238,5 +238,16 @@ public class DcWarningController extends BaseController
return toAjax(dcWarningService.falseAlarmResolution(dcWarning)); return toAjax(dcWarningService.falseAlarmResolution(dcWarning));
} }
/**
* 获取雷达事件视频
*
*
*/
@GetMapping("/video/{id}")
public AjaxResult getRadarIncidentVideo(@PathVariable("id") String id)throws Exception{
return AjaxResult.success(dcWarningService.getRadarIncidentVideo(id));
}
} }

37
zc-business/src/main/java/com/zc/business/controller/VideoController.java

@ -699,6 +699,43 @@ public class VideoController extends BaseController {
return getJsonResult(response,okHttp); return getJsonResult(response,okHttp);
} }
/**
* 获取视频流信息
* camId string 相机编号
* startTime Date 相机开始时间 yyyy-MM-dd HH:mm:ss
* duration 是Int 下载时长/分钟 不能超过五分钟
*/
@ApiOperation("下载相机录像")
@GetMapping(value = "/downloadCameraVideo")
public JSONObject downloadCameraVideo( String camId,String startTime,int duration) throws HttpException, IOException {
JSONObject cameraInfo = JSONObject.parseObject(configService.selectConfigByKey("dc.cameraInfo"));
OkHttp okHttp = new OkHttp();
RequestParams requestParams = new RequestParams();
requestParams.put("camId", camId);
requestParams.put("startTime", startTime);
requestParams.put("duration", duration);
Map<String, String> header = new HashMap<>();
if (VideoController.TOKEN == null) {
getToken();
}
header.put("Authorization", TOKEN);
Response response // 请求响应
= okHttp
.headers(header)
.url(cameraInfo.getString("URL") + UniversalEnum.DOWNLOAD_CAMERA_VIDEO.getValue()) // 请求地址
.data(requestParams) // 请求参数
.get(); // 请求方法
return getJsonResult(response,okHttp);
}
public void getToken() throws HttpException, IOException { public void getToken() throws HttpException, IOException {

4
zc-business/src/main/java/com/zc/business/enums/UniversalEnum.java

@ -1732,6 +1732,10 @@ public enum UniversalEnum {
// 获取视频流信息 /videoInfo/api/externalVideoStreaming // 获取视频流信息 /videoInfo/api/externalVideoStreaming
GET_VIDEO_STREAM_INFORMATION(0, "/videoInfo/api/externalVideoStreaming"), GET_VIDEO_STREAM_INFORMATION(0, "/videoInfo/api/externalVideoStreaming"),
//下载相机录像
DOWNLOAD_CAMERA_VIDEO(0,"/videoInfo/api/downloadVideotape"),
//雷达关联监控点查询接口
RADAR_ASSOCIATED_MONITORING_POINT_QUERY_INTERFACE(0,"/api/radar/v1/selectRelateByPage"),
// 云平台控制 /videoInfo/api/PTZControl // 云平台控制 /videoInfo/api/PTZControl
CLOUD_PLATFORM_CONTROL(0, "/videoInfo/api/PTZControl"), CLOUD_PLATFORM_CONTROL(0, "/videoInfo/api/PTZControl"),

4
zc-business/src/main/java/com/zc/business/message/device/handler/DeviceMessageHandler.java

@ -317,12 +317,12 @@ public class DeviceMessageHandler {
} }
dcWarning.setLane(String.valueOf(relatedLaneNo)); dcWarning.setLane(String.valueOf(relatedLaneNo));
String title = direction + WarningSubclassEnum.getDecorateInfo(warningSubclass); String title = direction+UniversalEnum.BLANK_SPACE.getValue() + WarningSubclassEnum.getDecorateInfo(warningSubclass);
// 标题 // 标题
dcWarning.setWarningTitle(title); dcWarning.setWarningTitle(title);
SimpleDateFormat sdf = new SimpleDateFormat(UniversalEnum.CHINESE_CHARACTER_TIME_FORMAT.getValue()); SimpleDateFormat sdf = new SimpleDateFormat(UniversalEnum.CHINESE_CHARACTER_TIME_FORMAT.getValue());
String formattedDate = sdf.format(new Date()); String formattedDate = sdf.format(new Date());
dcWarning.setRemark(formattedDate + UniversalEnum.BLANK_SPACE.getValue() + title); dcWarning.setRemark(formattedDate + UniversalEnum.BLANK_SPACE.getValue() +data.getString("stakeMark")+UniversalEnum.BLANK_SPACE.getValue()+ title);
// 影响车道 // 影响车道
// 物联设备id // 物联设备id

4
zc-business/src/main/java/com/zc/business/service/IDcWarningService.java

@ -108,4 +108,8 @@ public interface IDcWarningService
public Integer insertDispatch(DcDispatch dcDispatch); public Integer insertDispatch(DcDispatch dcDispatch);
//误报解除 //误报解除
public Integer falseAlarmResolution(DcWarning dcWarning); public Integer falseAlarmResolution(DcWarning dcWarning);
/**
* 获取雷达事件视频
*/
String getRadarIncidentVideo(String id)throws Exception;
} }

456
zc-business/src/main/java/com/zc/business/service/impl/DcWarningServiceImpl.java

@ -2,13 +2,17 @@ package com.zc.business.service.impl;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.google.gson.JsonObject; import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.hikvision.artemis.sdk.ArtemisHttpUtil;
import com.hikvision.artemis.sdk.config.ArtemisConfig;
import com.ruoyi.common.core.domain.AjaxResult; import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.redis.RedisCache; import com.ruoyi.common.core.redis.RedisCache;
import com.ruoyi.common.utils.DateUtils; import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.SecurityUtils; import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.uuid.IdUtils; import com.ruoyi.common.utils.uuid.IdUtils;
import com.ruoyi.system.service.ISysConfigService; import com.ruoyi.system.service.ISysConfigService;
import com.zc.business.controller.VideoController;
import com.zc.business.domain.*; import com.zc.business.domain.*;
import com.zc.business.enums.UniversalEnum; import com.zc.business.enums.UniversalEnum;
import com.zc.business.enums.ValueConverter; import com.zc.business.enums.ValueConverter;
@ -22,7 +26,6 @@ import com.zc.business.service.IDcWarningService;
import com.zc.business.utils.StakeMarkUtils; import com.zc.business.utils.StakeMarkUtils;
import com.zc.common.core.httpclient.OkHttp; import com.zc.common.core.httpclient.OkHttp;
import com.zc.common.core.httpclient.exception.HttpException; import com.zc.common.core.httpclient.exception.HttpException;
import com.zc.common.core.httpclient.request.RequestParams;
import com.zc.common.core.websocket.WebSocketService; import com.zc.common.core.websocket.WebSocketService;
import com.zc.common.core.websocket.constant.WebSocketEvent; import com.zc.common.core.websocket.constant.WebSocketEvent;
import okhttp3.Response; import okhttp3.Response;
@ -35,10 +38,15 @@ import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.io.IOException; import java.io.IOException;
import java.time.Duration;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.time.temporal.ChronoUnit;
import java.util.*; import java.util.*;
import java.util.concurrent.ThreadLocalRandom; import java.util.concurrent.ThreadLocalRandom;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors; import java.util.stream.Collectors;
/** /**
* 预警信息Service业务层处理 * 预警信息Service业务层处理
* *
@ -46,8 +54,7 @@ import java.util.stream.Collectors;
* @date 2024-01-26 * @date 2024-01-26
*/ */
@Service @Service
public class DcWarningServiceImpl implements IDcWarningService public class DcWarningServiceImpl implements IDcWarningService {
{
@Autowired @Autowired
private DcWarningMapper dcWarningMapper; private DcWarningMapper dcWarningMapper;
//事件 //事件
@ -63,6 +70,8 @@ public class DcWarningServiceImpl implements IDcWarningService
private DcProcessConfigMapper dcProcessConfigMapper; private DcProcessConfigMapper dcProcessConfigMapper;
@Autowired @Autowired
private ISysConfigService configService; private ISysConfigService configService;
@Autowired
private VideoController videoController;
@Resource @Resource
private RedisCache redisCache; private RedisCache redisCache;
private final String HAPPEN = UniversalEnum.TAKE_PLACE.getValue(); private final String HAPPEN = UniversalEnum.TAKE_PLACE.getValue();
@ -71,9 +80,11 @@ public class DcWarningServiceImpl implements IDcWarningService
private static final String WARNINGSTRATEGY = UniversalEnum.WARNING_STRATEGY.getValue();//redis策略缓存的key private static final String WARNINGSTRATEGY = UniversalEnum.WARNING_STRATEGY.getValue();//redis策略缓存的key
private static final String WARNINGDATA = UniversalEnum.WARNING_DATA.getValue();//redis事件缓存的key private static final String WARNINGDATA = UniversalEnum.WARNING_DATA.getValue();//redis事件缓存的key
//private static String JUDGE = "1"; //自定义判断参数,1为满足0为不满足 //private static String JUDGE = "1"; //自定义判断参数,1为满足0为不满足
private static final String ARTEMIS_PATH = "/artemis";
/** /**
* 感知事件数据统计 * 感知事件数据统计
*
* @return * @return
*/ */
@Override @Override
@ -88,8 +99,7 @@ public class DcWarningServiceImpl implements IDcWarningService
* @return 预警信息 * @return 预警信息
*/ */
@Override @Override
public HashMap<String, Object> selectDcWarningById(String id) public HashMap<String, Object> selectDcWarningById(String id) {
{
return dcWarningMapper.selectDcWarningById(id); return dcWarningMapper.selectDcWarningById(id);
} }
@ -100,8 +110,7 @@ public class DcWarningServiceImpl implements IDcWarningService
* @return 预警信息 * @return 预警信息
*/ */
@Override @Override
public HashMap<String, Object> selectAlarmById(String id) public HashMap<String, Object> selectAlarmById(String id) {
{
return dcWarningMapper.selectAlarmById(id); return dcWarningMapper.selectAlarmById(id);
} }
@ -112,10 +121,10 @@ public class DcWarningServiceImpl implements IDcWarningService
* @return 预警信息 * @return 预警信息
*/ */
@Override @Override
public List<HashMap<String,Object>> selectDcWarningList(DcWarning dcWarning) public List<HashMap<String, Object>> selectDcWarningList(DcWarning dcWarning) {
{
return dcWarningMapper.selectDcWarningList(dcWarning); return dcWarningMapper.selectDcWarningList(dcWarning);
} }
//导出 //导出
@Override @Override
public List<DcWarning> export(DcWarning dcWarning) { public List<DcWarning> export(DcWarning dcWarning) {
@ -129,24 +138,23 @@ public class DcWarningServiceImpl implements IDcWarningService
* @return 结果 * @return 结果
*/ */
@Override @Override
public int insertDcWarning(DcWarning dcWarning) public int insertDcWarning(DcWarning dcWarning) {
{
dcWarning.setCreateTime(DateUtils.getNowDate()); dcWarning.setCreateTime(DateUtils.getNowDate());
//设置事件Id UUID无下划线格式32 //设置事件Id UUID无下划线格式32
String uuid = IdUtils.fastSimpleUUID(); String uuid = IdUtils.fastSimpleUUID();
dcWarning.setId(uuid); dcWarning.setId(uuid);
if (StringUtils.isBlank(dcWarning.getStakeMark())||dcWarning.getWarningSource()==null||dcWarning.getWarningType()==null|| if (StringUtils.isBlank(dcWarning.getStakeMark()) || dcWarning.getWarningSource() == null || dcWarning.getWarningType() == null ||
StringUtils.isBlank(dcWarning.getWarningSubclass())||StringUtils.isBlank(dcWarning.getDirection())){ StringUtils.isBlank(dcWarning.getWarningSubclass()) || StringUtils.isBlank(dcWarning.getDirection())) {
return UniversalEnum.ZERO.getNumber(); return UniversalEnum.ZERO.getNumber();
} }
String redisKye=dcWarning.getWarningSource().toString()+dcWarning.getWarningType().toString()+dcWarning.getWarningSubclass();//配置数据的key 事件源+事件类型+策略 String redisKye = dcWarning.getWarningSource().toString() + dcWarning.getWarningType().toString() + dcWarning.getWarningSubclass();//配置数据的key 事件源+事件类型+策略
Map<String, HashMap> redisWarningStrategy = redisCache.getCacheMap(WARNINGSTRATEGY);//获取缓存全部的配置数据 Map<String, HashMap> redisWarningStrategy = redisCache.getCacheMap(WARNINGSTRATEGY);//获取缓存全部的配置数据
if (redisWarningStrategy==null||redisWarningStrategy.size()==UniversalEnum.ZERO.getNumber()){//如果缓存为空,查询数据重新加入缓存 if (redisWarningStrategy == null || redisWarningStrategy.size() == UniversalEnum.ZERO.getNumber()) {//如果缓存为空,查询数据重新加入缓存
Map<String, JSONObject> redisMap = new HashMap<>(); Map<String, JSONObject> redisMap = new HashMap<>();
List<DcWaringStrategy> dcWaringStrategies = dcWarningMapper.selectDcWaringStrategyList();//数据库全部配置数据 List<DcWaringStrategy> dcWaringStrategies = dcWarningMapper.selectDcWaringStrategyList();//数据库全部配置数据
for (DcWaringStrategy waringStrategy : dcWaringStrategies) { for (DcWaringStrategy waringStrategy : dcWaringStrategies) {
String key = waringStrategy.getWarningSource().toString() + waringStrategy.getWarningType().toString() String key = waringStrategy.getWarningSource().toString() + waringStrategy.getWarningType().toString()
+ waringStrategy.getWarningSubclass()+waringStrategy.getStrategy().toString();//redis配置数据key + waringStrategy.getWarningSubclass() + waringStrategy.getStrategy().toString();//redis配置数据key
JSONObject jsonObject = new JSONObject(); JSONObject jsonObject = new JSONObject();
jsonObject.put("strategy", waringStrategy.getStrategy());//策略模式 jsonObject.put("strategy", waringStrategy.getStrategy());//策略模式
jsonObject.put("strategyTime", waringStrategy.getStrategyTime());//模式时长,单位为分钟 jsonObject.put("strategyTime", waringStrategy.getStrategyTime());//模式时长,单位为分钟
@ -156,32 +164,32 @@ public class DcWarningServiceImpl implements IDcWarningService
redisCache.setCacheMap(WARNINGSTRATEGY, redisMap);//数据库配置数据加入缓存中 redisCache.setCacheMap(WARNINGSTRATEGY, redisMap);//数据库配置数据加入缓存中
redisWarningStrategy = redisCache.getCacheMap(WARNINGSTRATEGY);//缓存数据为空重新加入到缓存在取出缓存的配置 redisWarningStrategy = redisCache.getCacheMap(WARNINGSTRATEGY);//缓存数据为空重新加入到缓存在取出缓存的配置
} }
String key=dcWarning.getStakeMark()+dcWarning.getDirection()+dcWarning.getWarningSource(). String key = dcWarning.getStakeMark() + dcWarning.getDirection() + dcWarning.getWarningSource().
toString()+dcWarning.getWarningType().toString()+dcWarning.getWarningSubclass();//key,redis存储事件的key(桩号+方向+事件源+类型) toString() + dcWarning.getWarningType().toString() + dcWarning.getWarningSubclass();//key,redis存储事件的key(桩号+方向+事件源+类型)
String dataId = redisCache.getCacheObject(WARNINGDATA + key);//查看redis是否存在数据(id的值) String dataId = redisCache.getCacheObject(WARNINGDATA + key);//查看redis是否存在数据(id的值)
HashMap redisValueTwo = redisWarningStrategy.get(redisKye+UniversalEnum.TWO.getValue());//查看传入的事件类型是否配置策略2(延迟策略) HashMap redisValueTwo = redisWarningStrategy.get(redisKye + UniversalEnum.TWO.getValue());//查看传入的事件类型是否配置策略2(延迟策略)
if (redisValueTwo!=null){ //执行策略2, if (redisValueTwo != null) { //执行策略2,
String strategyTime = redisValueTwo.get("strategyTime").toString();//策略时长 String strategyTime = redisValueTwo.get("strategyTime").toString();//策略时长
dcWarning.setEndTime(DateUtils.getObtainDateAfter(Integer.parseInt(strategyTime)));//注入过期时间 dcWarning.setEndTime(DateUtils.getObtainDateAfter(Integer.parseInt(strategyTime)));//注入过期时间
if (dataId==null){//如果不存在直接加入数据库,加入缓存,配置对应的缓存过期时间以及数据库过期时间 if (dataId == null) {//如果不存在直接加入数据库,加入缓存,配置对应的缓存过期时间以及数据库过期时间
int insertDcWarning = dcWarningMapper.insertDcWarning(dcWarning);//加入数据库 int insertDcWarning = dcWarningMapper.insertDcWarning(dcWarning);//加入数据库
//事件推送至 Websocket //事件推送至 Websocket
extracted(dcWarning); extracted(dcWarning);
if (insertDcWarning==UniversalEnum.ZERO.getNumber()){ if (insertDcWarning == UniversalEnum.ZERO.getNumber()) {
return UniversalEnum.ZERO.getNumber(); return UniversalEnum.ZERO.getNumber();
} }
String id = dcWarning.getId();//取出加入后的id作为value String id = dcWarning.getId();//取出加入后的id作为value
redisCache.setCacheObject(WARNINGDATA+key,id,Integer.parseInt(strategyTime),TimeUnit.MINUTES);//加入缓存并设置延迟时间(单位分钟) redisCache.setCacheObject(WARNINGDATA + key, id, Integer.parseInt(strategyTime), TimeUnit.MINUTES);//加入缓存并设置延迟时间(单位分钟)
return UniversalEnum.ONE.getNumber();//结束 return UniversalEnum.ONE.getNumber();//结束
} }
//redis存在数据,取出redis的id找对对应事件的配置,合成事件配置,重新定义延迟时间 //redis存在数据,取出redis的id找对对应事件的配置,合成事件配置,重新定义延迟时间
HashMap<String, Object> map = dcWarningMapper.selectDcWarningById(dataId); HashMap<String, Object> map = dcWarningMapper.selectDcWarningById(dataId);
if (map==null||(map.get("warningState")!=null&&map.get("warningState").toString().equals(UniversalEnum.FOUR.getValue()))){//redis中有id但是数据库中没有这条数据,或则数据库中有数据但是状态不为结束,那就删除这条redis数据,新数据加入到数据库,并加入到redis if (map == null || (map.get("warningState") != null && map.get("warningState").toString().equals(UniversalEnum.FOUR.getValue()))) {//redis中有id但是数据库中没有这条数据,或则数据库中有数据但是状态不为结束,那就删除这条redis数据,新数据加入到数据库,并加入到redis
redisCache.deleteObject(WARNINGDATA+key); redisCache.deleteObject(WARNINGDATA + key);
String id = dcWarning.getId(); String id = dcWarning.getId();
redisCache.setCacheObject(WARNINGDATA+key,id,Integer.parseInt(strategyTime),TimeUnit.MINUTES); redisCache.setCacheObject(WARNINGDATA + key, id, Integer.parseInt(strategyTime), TimeUnit.MINUTES);
int i = dcWarningMapper.insertDcWarning(dcWarning); int i = dcWarningMapper.insertDcWarning(dcWarning);
//事件推送至 Websocket //事件推送至 Websocket
@ -189,13 +197,13 @@ public class DcWarningServiceImpl implements IDcWarningService
return i; return i;
} }
String otherConfig=UniversalEnum.EMPTY_STRING.getValue(); String otherConfig = UniversalEnum.EMPTY_STRING.getValue();
if (map.get("otherConfig")!=null){ if (map.get("otherConfig") != null) {
otherConfig = map.get("otherConfig").toString(); //取出原id的配置信息 otherConfig = map.get("otherConfig").toString(); //取出原id的配置信息
} }
String otherConfigString = dcWarning.getOtherConfig();//新增的配置信息 String otherConfigString = dcWarning.getOtherConfig();//新增的配置信息
if (StringUtils.isBlank(otherConfig)&&StringUtils.isBlank(otherConfigString)){//数据为空不新增,直接走规则 if (StringUtils.isBlank(otherConfig) && StringUtils.isBlank(otherConfigString)) {//数据为空不新增,直接走规则
redisCache.setCacheObject(WARNINGDATA+key,dataId,Integer.parseInt(strategyTime),TimeUnit.MINUTES);//重新设置延迟时间 redisCache.setCacheObject(WARNINGDATA + key, dataId, Integer.parseInt(strategyTime), TimeUnit.MINUTES);//重新设置延迟时间
return 1;//修改数据库配置 return 1;//修改数据库配置
} }
JSONObject jsonObjectOne = new JSONObject(otherConfig);//原始数据库数据 JSONObject jsonObjectOne = new JSONObject(otherConfig);//原始数据库数据
@ -208,15 +216,15 @@ public class DcWarningServiceImpl implements IDcWarningService
if (jsonObjectOne != null && jsonObjectOne.has("videoList")) {//验证视频是否存在 if (jsonObjectOne != null && jsonObjectOne.has("videoList")) {//验证视频是否存在
picturesArrayVideo = jsonObjectOne.getJSONArray("videoList"); picturesArrayVideo = jsonObjectOne.getJSONArray("videoList");
} }
if (picturesArrayVideo!=null||picturesArrayPic!=null) { if (picturesArrayVideo != null || picturesArrayPic != null) {
boolean a =false; boolean a = false;
if (picturesArrayVideo != null) { if (picturesArrayVideo != null) {
int videoListLength = jsonObjectOne.getJSONArray("pictures").length();//已经存在数据库的视频的长度 int videoListLength = jsonObjectOne.getJSONArray("pictures").length();//已经存在数据库的视频的长度
if (videoListLength >= UniversalEnum.TEN.getNumber() && jsonObjectTwo.get("videoList") != null) { if (videoListLength >= UniversalEnum.TEN.getNumber() && jsonObjectTwo.get("videoList") != null) {
JSONArray videoList = jsonObjectOne.getJSONArray("videoList"); JSONArray videoList = jsonObjectOne.getJSONArray("videoList");
videoList.put(videoListLength - UniversalEnum.ONE.getNumber(), jsonObjectTwo.getJSONArray("videoList").getString(UniversalEnum.ZERO.getNumber())); videoList.put(videoListLength - UniversalEnum.ONE.getNumber(), jsonObjectTwo.getJSONArray("videoList").getString(UniversalEnum.ZERO.getNumber()));
jsonObjectOne.put("videoList", videoList); jsonObjectOne.put("videoList", videoList);
a=true; a = true;
} }
} }
if (picturesArrayPic != null) { if (picturesArrayPic != null) {
@ -225,30 +233,30 @@ public class DcWarningServiceImpl implements IDcWarningService
JSONArray pictures = jsonObjectOne.getJSONArray("pictures");//获取图片数组 JSONArray pictures = jsonObjectOne.getJSONArray("pictures");//获取图片数组
pictures.put(picturesLength - UniversalEnum.ONE.getNumber(), jsonObjectTwo.getJSONArray("pictures").getString(UniversalEnum.ZERO.getNumber())); //替换第十个元素 pictures.put(picturesLength - UniversalEnum.ONE.getNumber(), jsonObjectTwo.getJSONArray("pictures").getString(UniversalEnum.ZERO.getNumber())); //替换第十个元素
jsonObjectOne.put("pictures", pictures);//更新 jsonObjectOne中的pictures 数组 jsonObjectOne.put("pictures", pictures);//更新 jsonObjectOne中的pictures 数组
a=true; a = true;
} }
} }
if (a==true){ if (a == true) {
redisCache.setCacheObject(WARNINGDATA + key, dataId, Integer.parseInt(strategyTime), TimeUnit.MINUTES);//重新设置延迟时间 redisCache.setCacheObject(WARNINGDATA + key, dataId, Integer.parseInt(strategyTime), TimeUnit.MINUTES);//重新设置延迟时间
return dcWarningMapper.updateOtherConfig(dataId, jsonObjectOne.toString(), dcWarning.getEndTime());//修改数据库配置 return dcWarningMapper.updateOtherConfig(dataId, jsonObjectOne.toString(), dcWarning.getEndTime());//修改数据库配置
} }
} }
DcWarningServiceImpl dcWarningService = new DcWarningServiceImpl();//合成工具类 DcWarningServiceImpl dcWarningService = new DcWarningServiceImpl();//合成工具类
JSONObject jsonObject = dcWarningService.mergeJsonObjects(jsonObjectOne, jsonObjectTwo); JSONObject jsonObject = dcWarningService.mergeJsonObjects(jsonObjectOne, jsonObjectTwo);
if (jsonObject==null){ //没有进行合成或则合成后的数据为null if (jsonObject == null) { //没有进行合成或则合成后的数据为null
redisCache.setCacheObject(WARNINGDATA+key,dataId,Integer.parseInt(strategyTime),TimeUnit.MINUTES);//重新设置延迟时间 redisCache.setCacheObject(WARNINGDATA + key, dataId, Integer.parseInt(strategyTime), TimeUnit.MINUTES);//重新设置延迟时间
if (jsonObjectOne!=null) { if (jsonObjectOne != null) {
return dcWarningMapper.updateOtherConfig(dataId, jsonObjectOne.toString(), dcWarning.getEndTime());//修改数据库配置 return dcWarningMapper.updateOtherConfig(dataId, jsonObjectOne.toString(), dcWarning.getEndTime());//修改数据库配置
}else if (jsonObjectTwo!=null){ } else if (jsonObjectTwo != null) {
return dcWarningMapper.updateOtherConfig(dataId, jsonObjectTwo.toString(), dcWarning.getEndTime());//修改数据库配置 return dcWarningMapper.updateOtherConfig(dataId, jsonObjectTwo.toString(), dcWarning.getEndTime());//修改数据库配置
}else { } else {
return dcWarningMapper.updateOtherConfig(dataId, "", dcWarning.getEndTime());//修改数据库配置 return dcWarningMapper.updateOtherConfig(dataId, "", dcWarning.getEndTime());//修改数据库配置
} }
} }
redisCache.setCacheObject(WARNINGDATA+key,dataId,Integer.parseInt(strategyTime),TimeUnit.MINUTES);//重新设置延迟时间 redisCache.setCacheObject(WARNINGDATA + key, dataId, Integer.parseInt(strategyTime), TimeUnit.MINUTES);//重新设置延迟时间
return dcWarningMapper.updateOtherConfig(dataId, jsonObject.toString(),dcWarning.getEndTime());//修改数据库配置 return dcWarningMapper.updateOtherConfig(dataId, jsonObject.toString(), dcWarning.getEndTime());//修改数据库配置
} }
if (redisValueTwo==null){ //如果传进来的事件未配置策略,在这里出入默认的过去时间值 if (redisValueTwo == null) { //如果传进来的事件未配置策略,在这里出入默认的过去时间值
dcWarning.setEndTime(DateUtils.getObtainDateAfter(UniversalEnum.SIXTY.getNumber()));//注入过期时间(默认值为60分钟) dcWarning.setEndTime(DateUtils.getObtainDateAfter(UniversalEnum.SIXTY.getNumber()));//注入过期时间(默认值为60分钟)
} }
//事件推送至 Websocket //事件推送至 Websocket
@ -259,34 +267,35 @@ public class DcWarningServiceImpl implements IDcWarningService
/** /**
* 事件推送至 Websocket * 事件推送至 Websocket
*
* @param dcWarning * @param dcWarning
*/ */
private void extracted(DcWarning dcWarning) { private void extracted(DcWarning dcWarning) {
String direction = UniversalEnum.EMPTY_STRING.getValue();// 方向 String direction = UniversalEnum.EMPTY_STRING.getValue();// 方向
String EventSubclass = UniversalEnum.EMPTY_STRING.getValue();// 事件类型 String EventSubclass = UniversalEnum.EMPTY_STRING.getValue();// 事件类型
if (dcWarning.getDirection().equals(UniversalEnum.ONE.getValue())) { if (dcWarning.getDirection().equals(UniversalEnum.ONE.getValue())) {
direction=UniversalEnum.DIRECTION_OF_HEZE.getValue(); direction = UniversalEnum.DIRECTION_OF_HEZE.getValue();
}else { } else {
direction=UniversalEnum.DIRECTION_OF_JINAN.getValue(); direction = UniversalEnum.DIRECTION_OF_JINAN.getValue();
} }
for (WarningSubclassEnum eventSubclass : WarningSubclassEnum.values()) { for (WarningSubclassEnum eventSubclass : WarningSubclassEnum.values()) {
if (eventSubclass.getCode().equals(dcWarning.getWarningSubclass())) { if (eventSubclass.getCode().equals(dcWarning.getWarningSubclass())) {
EventSubclass=eventSubclass.getInfo(); EventSubclass = eventSubclass.getInfo();
break; break;
} }
} }
Map<String,Object> contentMap = new HashMap<>(); Map<String, Object> contentMap = new HashMap<>();
if (dcWarning.getWarningSource() == 7) { if (dcWarning.getWarningSource() == 7) {
String remark = dcWarning.getRemark(); String remark = dcWarning.getRemark();
String[] split = remark.split(" "); String[] split = remark.split(" ");
String s = split[split.length - 1]; String s = split[split.length - 1];
contentMap.put("content",s); contentMap.put("content", s);
}else { } else {
String content= direction+UniversalEnum.BLANK_SPACE.getValue() + dcWarning.getStakeMark()+UniversalEnum.BLANK_SPACE.getValue()+HAPPEN+EventSubclass+EVENT ; String content = direction + UniversalEnum.BLANK_SPACE.getValue() + dcWarning.getStakeMark() + UniversalEnum.BLANK_SPACE.getValue() + HAPPEN + EventSubclass + EVENT;
contentMap.put("content",content); contentMap.put("content", content);
} }
contentMap.put("event",dcWarning); contentMap.put("event", dcWarning);
WebSocketService.broadcast(WebSocketEvent.WARNING, contentMap); //推送事件消息 0不是感知事件 WebSocketService.broadcast(WebSocketEvent.WARNING, contentMap); //推送事件消息 0不是感知事件
dcEventService.getCountNum(); dcEventService.getCountNum();
} }
@ -460,14 +469,14 @@ public class DcWarningServiceImpl implements IDcWarningService
// } // }
// return dcWarningMapper.insertDcWarning(dcWarning);//如果没有配置策略直接加入数据库; // return dcWarningMapper.insertDcWarning(dcWarning);//如果没有配置策略直接加入数据库;
// } // }
private JSONObject mergeJsonObjects(JSONObject jsonObjectOne, JSONObject jsonObjectTwo){ private JSONObject mergeJsonObjects(JSONObject jsonObjectOne, JSONObject jsonObjectTwo) {
if(jsonObjectOne!=null&&jsonObjectTwo==null){ if (jsonObjectOne != null && jsonObjectTwo == null) {
return jsonObjectOne; //两个存在一个为空返回不为空的 return jsonObjectOne; //两个存在一个为空返回不为空的
} }
if (jsonObjectOne==null&&jsonObjectTwo!=null){ if (jsonObjectOne == null && jsonObjectTwo != null) {
return jsonObjectTwo;//两个存在一个为空返回不为空的 return jsonObjectTwo;//两个存在一个为空返回不为空的
} }
if(jsonObjectOne==null&&jsonObjectTwo==null){ if (jsonObjectOne == null && jsonObjectTwo == null) {
return new JSONObject();//两个都为空返回空json return new JSONObject();//两个都为空返回空json
} }
// 合并videoList // 合并videoList
@ -496,6 +505,7 @@ public class DcWarningServiceImpl implements IDcWarningService
} }
return jsonObjectOne; return jsonObjectOne;
} }
/** /**
* 修改预警信息 * 修改预警信息
* *
@ -503,8 +513,7 @@ public class DcWarningServiceImpl implements IDcWarningService
* @return 结果 * @return 结果
*/ */
@Override @Override
public int updateDcWarning(DcWarning dcWarning) public int updateDcWarning(DcWarning dcWarning) {
{
dcWarning.setUpdateTime(DateUtils.getNowDate()); dcWarning.setUpdateTime(DateUtils.getNowDate());
return dcWarningMapper.updateDcWarning(dcWarning); return dcWarningMapper.updateDcWarning(dcWarning);
} }
@ -516,8 +525,7 @@ public class DcWarningServiceImpl implements IDcWarningService
* @return 结果 * @return 结果
*/ */
@Override @Override
public int deleteDcWarningByIds(String id) public int deleteDcWarningByIds(String id) {
{
return dcWarningMapper.deleteDcWarningByIds(id); return dcWarningMapper.deleteDcWarningByIds(id);
} }
@ -528,27 +536,27 @@ public class DcWarningServiceImpl implements IDcWarningService
* @return 结果 * @return 结果
*/ */
@Override @Override
public int deleteDcWarningById(Integer id) public int deleteDcWarningById(Integer id) {
{
return dcWarningMapper.deleteDcWarningById(id); return dcWarningMapper.deleteDcWarningById(id);
} }
//感知事件转交通事件(感知事件状态改为处置中,把感知事件的数据整理新增到交通事件) //感知事件转交通事件(感知事件状态改为处置中,把感知事件的数据整理新增到交通事件)
@Override @Override
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public AjaxResult updateWarningConvert(DcWarning dcWarning) { public AjaxResult updateWarningConvert(DcWarning dcWarning) {
if (dcWarning==null||dcWarning.getId()==null|| dcWarning.getStakeMark()==null|| if (dcWarning == null || dcWarning.getId() == null || dcWarning.getStakeMark() == null ||
StringUtils.isBlank(dcWarning.getStakeMark())||dcWarning.getDirection()==null|| StringUtils.isBlank(dcWarning.getStakeMark()) || dcWarning.getDirection() == null ||
StringUtils.isBlank(dcWarning.getDirection()) || StringUtils.isBlank(dcWarning.getDirection()) ||
dcWarning.getWarningType()==null|| dcWarning.getWarningSource()==null){ dcWarning.getWarningType() == null || dcWarning.getWarningSource() == null) {
return AjaxResult.error(UniversalEnum.PARAMETER_ERROR.getValue()); return AjaxResult.error(UniversalEnum.PARAMETER_ERROR.getValue());
} }
if (UniversalEnum.SIX.getValue().equals(dcWarning.getWarningSource().toString())){ if (UniversalEnum.SIX.getValue().equals(dcWarning.getWarningSource().toString())) {
return AjaxResult.error("非机预警无需转换"); return AjaxResult.error("非机预警无需转换");
} }
ArrayList<HashMap<String,Object>> hashMaps = new ArrayList<>(); ArrayList<HashMap<String, Object>> hashMaps = new ArrayList<>();
dcWarning.setUserId(SecurityUtils.getUserId()); dcWarning.setUserId(SecurityUtils.getUserId());
int updateState = dcWarningMapper.updateState(dcWarning);//感知事件状态改变为已完成 int updateState = dcWarningMapper.updateState(dcWarning);//感知事件状态改变为已完成
if (updateState==UniversalEnum.ZERO.getNumber()){ if (updateState == UniversalEnum.ZERO.getNumber()) {
return AjaxResult.error(UniversalEnum.OPERATION_FAILURE.getValue()); return AjaxResult.error(UniversalEnum.OPERATION_FAILURE.getValue());
} }
String stakeMark = dcWarning.getStakeMark(); String stakeMark = dcWarning.getStakeMark();
@ -559,16 +567,16 @@ public class DcWarningServiceImpl implements IDcWarningService
dcEvent.setDeptId(dcWarning.getDeptId());//部门 dcEvent.setDeptId(dcWarning.getDeptId());//部门
dcEvent.setOccurrenceTime(dcWarning.getWarningTime());//预警时间 dcEvent.setOccurrenceTime(dcWarning.getWarningTime());//预警时间
Integer warningType = dcWarning.getWarningType();//事件主类 Integer warningType = dcWarning.getWarningType();//事件主类
if (dcWarning.getWarningLevel()!=null) { if (dcWarning.getWarningLevel() != null) {
dcEvent.setEventLevel(dcWarning.getWarningLevel().longValue());//事件等级 dcEvent.setEventLevel(dcWarning.getWarningLevel().longValue());//事件等级
} }
if (dcWarning.getWarningSource()!=null) { if (dcWarning.getWarningSource() != null) {
dcEvent.setEventSource((long) ValueConverter.convertValueSource(dcWarning.getWarningSource()));//事件来源 dcEvent.setEventSource((long) ValueConverter.convertValueSource(dcWarning.getWarningSource()));//事件来源
} }
if (warningType!=null) { if (warningType != null) {
dcEvent.setEventType((long) ValueConverter.convertValueHost(dcWarning.getWarningType()));//事件主类 dcEvent.setEventType((long) ValueConverter.convertValueHost(dcWarning.getWarningType()));//事件主类
} }
if (dcWarning.getWarningSubclass()!=null) { if (dcWarning.getWarningSubclass() != null) {
dcEvent.setEventSubclass(ValueConverter.convertValueSon(dcWarning.getWarningSubclass()));//事件子类 dcEvent.setEventSubclass(ValueConverter.convertValueSon(dcWarning.getWarningSubclass()));//事件子类
} }
// if (dcWarning.getWarningSubclass()!=null&&(warningType==UniversalEnum.SEVEN.getNumber())){ // if (dcWarning.getWarningSubclass()!=null&&(warningType==UniversalEnum.SEVEN.getNumber())){
@ -586,14 +594,14 @@ public class DcWarningServiceImpl implements IDcWarningService
dcEvent.setUserId(SecurityUtils.getUserId());//处置人员 dcEvent.setUserId(SecurityUtils.getUserId());//处置人员
dcEvent.setRoadId(Long.valueOf(UniversalEnum.ONE.getNumber()));//高速公路(济菏高速) dcEvent.setRoadId(Long.valueOf(UniversalEnum.ONE.getNumber()));//高速公路(济菏高速)
int insertDcEvent = dcEventService.insertDcEventWarning(dcEvent); int insertDcEvent = dcEventService.insertDcEventWarning(dcEvent);
if (insertDcEvent==UniversalEnum.ZERO.getNumber()){ if (insertDcEvent == UniversalEnum.ZERO.getNumber()) {
return AjaxResult.error(UniversalEnum.OPERATION_FAILURE.getValue()); return AjaxResult.error(UniversalEnum.OPERATION_FAILURE.getValue());
} }
//推送待处理数量 //推送待处理数量
dcEventService.getCountNum(); dcEventService.getCountNum();
//扫码报警小程序 //扫码报警小程序
if(dcWarning.getWarningSource() == 5){ if (dcWarning.getWarningSource() == 5) {
HashMap<String, Object> warningInfo = dcWarningMapper.selectDcWarningById(dcWarning.getId()); HashMap<String, Object> warningInfo = dcWarningMapper.selectDcWarningById(dcWarning.getId());
com.alibaba.fastjson.JSONObject otherConfig = com.alibaba.fastjson.JSONObject.parseObject(warningInfo.get("otherConfig").toString()); com.alibaba.fastjson.JSONObject otherConfig = com.alibaba.fastjson.JSONObject.parseObject(warningInfo.get("otherConfig").toString());
String alarmId = otherConfig.getString("id"); String alarmId = otherConfig.getString("id");
@ -626,33 +634,32 @@ public class DcWarningServiceImpl implements IDcWarningService
public int deleteDcWarningByStringId(DcWarning dcWarning) { public int deleteDcWarningByStringId(DcWarning dcWarning) {
return dcWarningMapper.deleteDcWarningByStringId(dcWarning); return dcWarningMapper.deleteDcWarningByStringId(dcWarning);
} }
@Override @Override
public List<HashMap<String,Object>> selectDcWarningoTherConfig(DcWarning dcWarning) public List<HashMap<String, Object>> selectDcWarningoTherConfig(DcWarning dcWarning) {
{
return dcWarningMapper.selectDcWarningoTherConfig(dcWarning); return dcWarningMapper.selectDcWarningoTherConfig(dcWarning);
} }
/** /**
* @param dcWarningBatchConvert
* @return com.ruoyi.common.core.domain.AjaxResult
* @Description 感知事件批量转换 * @Description 感知事件批量转换
*
* @author liuwenge * @author liuwenge
* @date 2024/3/16 16:36 * @date 2024/3/16 16:36
* @param dcWarningBatchConvert
* @return com.ruoyi.common.core.domain.AjaxResult
*/ */
@Override @Override
@Transactional @Transactional
public AjaxResult batchConvert(DcWarningBatchConvert dcWarningBatchConvert){ public AjaxResult batchConvert(DcWarningBatchConvert dcWarningBatchConvert) {
if (StringUtils.isBlank(dcWarningBatchConvert.getType())){ if (StringUtils.isBlank(dcWarningBatchConvert.getType())) {
return AjaxResult.error(UniversalEnum.THE_OPERATION_TYPE_CANNOT_BE_EMPTY.getValue()); return AjaxResult.error(UniversalEnum.THE_OPERATION_TYPE_CANNOT_BE_EMPTY.getValue());
} }
List<DcWarning> dcWarningList = dcWarningBatchConvert.getWarningList(); List<DcWarning> dcWarningList = dcWarningBatchConvert.getWarningList();
if (dcWarningList != null && dcWarningList.size() > UniversalEnum.ZERO.getNumber()){ if (dcWarningList != null && dcWarningList.size() > UniversalEnum.ZERO.getNumber()) {
//误报,批量删除 //误报,批量删除
if (UniversalEnum.ZERO.getValue().equals(dcWarningBatchConvert.getType())){ if (UniversalEnum.ZERO.getValue().equals(dcWarningBatchConvert.getType())) {
dcWarningMapper.batchDelete(dcWarningList); dcWarningMapper.batchDelete(dcWarningList);
} else { } else {
//确认,批量转换为事件 //确认,批量转换为事件
@ -694,7 +701,7 @@ public class DcWarningServiceImpl implements IDcWarningService
} }
//批量更改感知事件状态 //批量更改感知事件状态
dcWarningMapper.batchUpdateState(SecurityUtils.getUserId(),dcWarningList); dcWarningMapper.batchUpdateState(SecurityUtils.getUserId(), dcWarningList);
//批量插入事件表 //批量插入事件表
dcEventService.batchInsertDcEventWarning(dcEventList); dcEventService.batchInsertDcEventWarning(dcEventList);
} }
@ -710,7 +717,7 @@ public class DcWarningServiceImpl implements IDcWarningService
@Override @Override
public Integer updateEndSection() { public Integer updateEndSection() {
List<DcWarning> dcWarnings = dcWarningMapper.selectEndSection();//全部应该结束事件的id List<DcWarning> dcWarnings = dcWarningMapper.selectEndSection();//全部应该结束事件的id
if (dcWarnings.size()==UniversalEnum.ZERO.getNumber()){ if (dcWarnings.size() == UniversalEnum.ZERO.getNumber()) {
return UniversalEnum.ONE.getNumber(); return UniversalEnum.ONE.getNumber();
} }
Integer i = dcWarningMapper.updateEndSection(dcWarnings); Integer i = dcWarningMapper.updateEndSection(dcWarnings);
@ -726,131 +733,135 @@ public class DcWarningServiceImpl implements IDcWarningService
public AjaxResult commandAndDispatch(DcWarning dcWarning) { public AjaxResult commandAndDispatch(DcWarning dcWarning) {
Map<String, Object> mapAll = new HashMap<>(); Map<String, Object> mapAll = new HashMap<>();
HashMap<String, Object> dcDispatch = dcWarningMapper.selectDcDispatch(dcWarning.getId());//查询是否存在调度记录 HashMap<String, Object> dcDispatch = dcWarningMapper.selectDcDispatch(dcWarning.getId());//查询是否存在调度记录
if (dcDispatch==null){ if (dcDispatch == null) {
mapAll.put("existence",UniversalEnum.ZERO.getNumber()); mapAll.put("existence", UniversalEnum.ZERO.getNumber());
return AjaxResult.success(mapAll); return AjaxResult.success(mapAll);
} }
//逻辑,调用全部的机构信息,计算传入的桩号与机构桩号的距离作为排序使用,使用机构的id调出车辆,人员,值班等信息 //逻辑,调用全部的机构信息,计算传入的桩号与机构桩号的距离作为排序使用,使用机构的id调出车辆,人员,值班等信息
List<HashMap<String, Object>> mapList = dcWarningMapper.selectRecentlySection();//全部机构的桩号和名称 List<HashMap<String, Object>> mapList = dcWarningMapper.selectRecentlySection();//全部机构的桩号和名称
ArrayList<HashMap<String,Object>> hashMaps = new ArrayList<>(); ArrayList<HashMap<String, Object>> hashMaps = new ArrayList<>();
for (HashMap<String,Object> map:mapList){ for (HashMap<String, Object> map : mapList) {
if (StringUtils.isBlank(map.get("stakeMark").toString())){ if (StringUtils.isBlank(map.get("stakeMark").toString())) {
continue; continue;
} }
String stakeMark = map.get("stakeMark").toString(); String stakeMark = map.get("stakeMark").toString();
StakeMarkUtils stakeMarkUtils = new StakeMarkUtils(); StakeMarkUtils stakeMarkUtils = new StakeMarkUtils();
Integer itselfStakeMark = stakeMarkUtils.stakeMarkToInt(stakeMark);//桩号本身的米数 Integer itselfStakeMark = stakeMarkUtils.stakeMarkToInt(stakeMark);//桩号本身的米数
Integer afferentStakeMark = stakeMarkUtils.stakeMarkToInt(dcWarning.getStakeMark());//传入的桩号米数 Integer afferentStakeMark = stakeMarkUtils.stakeMarkToInt(dcWarning.getStakeMark());//传入的桩号米数
Integer difference =Math.abs(afferentStakeMark-itselfStakeMark); //计算距离绝对值 Integer difference = Math.abs(afferentStakeMark - itselfStakeMark); //计算距离绝对值
map.put("difference",difference/1000.0);//米转公里加入到map map.put("difference", difference / 1000.0);//米转公里加入到map
Long id =Long.parseLong(map.get("id").toString());//机构的id,用户获取人员、值班、车辆等信息 Long id = Long.parseLong(map.get("id").toString());//机构的id,用户获取人员、值班、车辆等信息
List<HashMap<String, Object>> employeesMap = dcWarningMapper.selectEmployeesDispatch(id,dcWarning.getId());//人员map List<HashMap<String, Object>> employeesMap = dcWarningMapper.selectEmployeesDispatch(id, dcWarning.getId());//人员map
List<HashMap<String, Object>> vehiclesMap = dcWarningMapper.selectVehiclesDispatch(id,dcWarning.getId());//车辆map List<HashMap<String, Object>> vehiclesMap = dcWarningMapper.selectVehiclesDispatch(id, dcWarning.getId());//车辆map
map.put("employeesMap",employeesMap); map.put("employeesMap", employeesMap);
map.put("vehiclesMap",vehiclesMap); map.put("vehiclesMap", vehiclesMap);
hashMaps.add(map); hashMaps.add(map);
} }
List<HashMap<String, Object>> sortedHashMaps = hashMaps.stream().sorted(Comparator.comparing(map -> { List<HashMap<String, Object>> sortedHashMaps = hashMaps.stream().sorted(Comparator.comparing(map -> {
return (Double) map.get("difference"); })).collect(Collectors.toList()); return (Double) map.get("difference");
mapAll.put("listData",sortedHashMaps); })).collect(Collectors.toList());
mapAll.put("listData", sortedHashMaps);
if (!sortedHashMaps.isEmpty()) { if (!sortedHashMaps.isEmpty()) {
HashMap<String, Object> map = sortedHashMaps.get(UniversalEnum.ZERO.getNumber()); HashMap<String, Object> map = sortedHashMaps.get(UniversalEnum.ZERO.getNumber());
Long id = Long.parseLong(map.get("id").toString());//取出最近的机构id Long id = Long.parseLong(map.get("id").toString());//取出最近的机构id
//todo 交警 //todo 交警
DcTrafficPolice dcTrafficPolice = dcTrafficPoliceService.selectEvent(dcWarning.getStakeMark()); DcTrafficPolice dcTrafficPolice = dcTrafficPoliceService.selectEvent(dcWarning.getStakeMark());
mapAll.put("trafficPolice",dcTrafficPolice); mapAll.put("trafficPolice", dcTrafficPolice);
} }
mapAll.put("dispatchId",dcDispatch.get("id")); mapAll.put("dispatchId", dcDispatch.get("id"));
mapAll.put("existence",UniversalEnum.ONE.getNumber()); mapAll.put("existence", UniversalEnum.ONE.getNumber());
HashMap<String, Object> map = dcWarningMapper.selectDcDispatch(dcWarning.getId());//获取机构id与资源id HashMap<String, Object> map = dcWarningMapper.selectDcDispatch(dcWarning.getId());//获取机构id与资源id
if (map!=null){ if (map != null) {
HashMap<Object, Object> hashMap = new HashMap<>(); HashMap<Object, Object> hashMap = new HashMap<>();
Long id =Long.parseLong(map.get("id").toString());//调度记录id Long id = Long.parseLong(map.get("id").toString());//调度记录id
Object deptName =map.get("deptName");//部门名称 Object deptName = map.get("deptName");//部门名称
//List<HashMap<String, Object>> shifts = dcWarningMapper.selectShiftsEmployees();//值班为空把全部的人员信息作为值班人员信息 //List<HashMap<String, Object>> shifts = dcWarningMapper.selectShiftsEmployees();//值班为空把全部的人员信息作为值班人员信息
List<HashMap<String, Object>> resource = dcWarningMapper.selectDispatchResource(id);//全部资源信息 List<HashMap<String, Object>> resource = dcWarningMapper.selectDispatchResource(id);//全部资源信息
List<HashMap<String, Object>> employeesChoice = dcWarningMapper.selectEmployeesChoice(id);//选中人员信息 List<HashMap<String, Object>> employeesChoice = dcWarningMapper.selectEmployeesChoice(id);//选中人员信息
List<HashMap<String, Object>> vehiclesChoice = dcWarningMapper.selectVehiclesChoice(id);//选中车辆信息 List<HashMap<String, Object>> vehiclesChoice = dcWarningMapper.selectVehiclesChoice(id);//选中车辆信息
hashMap.put("id",id);//调度记录id hashMap.put("id", id);//调度记录id
hashMap.put("deptName",deptName); hashMap.put("deptName", deptName);
//hashMap.put("shifts",shifts); //hashMap.put("shifts",shifts);
hashMap.put("resource",resource); hashMap.put("resource", resource);
mapAll.put("resource",hashMap); mapAll.put("resource", hashMap);
mapAll.put("employeesChoice",employeesChoice); mapAll.put("employeesChoice", employeesChoice);
mapAll.put("vehiclesChoice",vehiclesChoice); mapAll.put("vehiclesChoice", vehiclesChoice);
} }
return AjaxResult.success(mapAll); return AjaxResult.success(mapAll);
} }
//指挥调度,当调度信息为空的时候调用智能分配资源 //指挥调度,当调度信息为空的时候调用智能分配资源
@Override @Override
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public AjaxResult intelligentSource(DcWarning dcWarning) { public AjaxResult intelligentSource(DcWarning dcWarning) {
String stakeMark = dcWarning.getStakeMark(); String stakeMark = dcWarning.getStakeMark();
ArrayList<HashMap<String,Object>> hashMaps = new ArrayList<>(); ArrayList<HashMap<String, Object>> hashMaps = new ArrayList<>();
Map<String, Object> mapAll = new HashMap<>(); Map<String, Object> mapAll = new HashMap<>();
List<HashMap<String, Object>> mapList = dcWarningMapper.selectRecentlySection();//全部机构的桩号和名称 List<HashMap<String, Object>> mapList = dcWarningMapper.selectRecentlySection();//全部机构的桩号和名称
for (HashMap<String,Object> map:mapList){ for (HashMap<String, Object> map : mapList) {
HashMap<String, Object> mapValue = new HashMap<>(); HashMap<String, Object> mapValue = new HashMap<>();
if (StringUtils.isBlank(map.get("stakeMark").toString())){ if (StringUtils.isBlank(map.get("stakeMark").toString())) {
continue; continue;
} }
StakeMarkUtils stakeMarkUtils = new StakeMarkUtils(); StakeMarkUtils stakeMarkUtils = new StakeMarkUtils();
String stakeMarkValue = map.get("stakeMark").toString(); String stakeMarkValue = map.get("stakeMark").toString();
Integer itselfStakeMark = stakeMarkUtils.stakeMarkToInt(stakeMarkValue);//桩号本身的米数 Integer itselfStakeMark = stakeMarkUtils.stakeMarkToInt(stakeMarkValue);//桩号本身的米数
Integer afferentStakeMark = stakeMarkUtils.stakeMarkToInt(dcWarning.getStakeMark());//传入的桩号米数 Integer afferentStakeMark = stakeMarkUtils.stakeMarkToInt(dcWarning.getStakeMark());//传入的桩号米数
Integer difference =Math.abs(afferentStakeMark-itselfStakeMark); //计算距离绝对值 Integer difference = Math.abs(afferentStakeMark - itselfStakeMark); //计算距离绝对值
mapValue.put("difference",difference/1000.0);//米转公里加入到map mapValue.put("difference", difference / 1000.0);//米转公里加入到map
Long id =Long.parseLong(map.get("id").toString());//机构的id,用户获取人员、车辆等信息 Long id = Long.parseLong(map.get("id").toString());//机构的id,用户获取人员、车辆等信息
List<HashMap<String, Object>> employeesMap = dcWarningMapper.selectEmployeesDispatch(id,dcWarning.getId());//人员map List<HashMap<String, Object>> employeesMap = dcWarningMapper.selectEmployeesDispatch(id, dcWarning.getId());//人员map
List<HashMap<String, Object>> vehiclesMap = dcWarningMapper.selectVehiclesDispatch(id,dcWarning.getId());//车辆map List<HashMap<String, Object>> vehiclesMap = dcWarningMapper.selectVehiclesDispatch(id, dcWarning.getId());//车辆map
String organizationName = dcWarningMapper.organizationName(id); String organizationName = dcWarningMapper.organizationName(id);
mapValue.put("employeesMap",employeesMap); mapValue.put("employeesMap", employeesMap);
mapValue.put("vehiclesMap",vehiclesMap); mapValue.put("vehiclesMap", vehiclesMap);
mapValue.put("organizationId",id); mapValue.put("organizationId", id);
mapValue.put("organizationName",organizationName); mapValue.put("organizationName", organizationName);
hashMaps.add(mapValue); hashMaps.add(mapValue);
} }
mapAll.put("selectData",hashMaps); mapAll.put("selectData", hashMaps);
List<HashMap<String, Object>> sortedHashMaps = hashMaps.stream().sorted(Comparator.comparing(map -> { List<HashMap<String, Object>> sortedHashMaps = hashMaps.stream().sorted(Comparator.comparing(map -> {
return (Double) map.get("difference"); })).collect(Collectors.toList()); return (Double) map.get("difference");
})).collect(Collectors.toList());
if (!sortedHashMaps.isEmpty()) { if (!sortedHashMaps.isEmpty()) {
HashMap<String, Object> map = sortedHashMaps.get(UniversalEnum.ZERO.getNumber()); HashMap<String, Object> map = sortedHashMaps.get(UniversalEnum.ZERO.getNumber());
Long id = Long.parseLong(map.get("organizationId").toString());//取出最近的机构id Long id = Long.parseLong(map.get("organizationId").toString());//取出最近的机构id
if (id != null) { if (id != null) {
List<HashMap<String, Object>> employeesMap = dcWarningMapper.selectOrganizationEmployees(id);//人员map List<HashMap<String, Object>> employeesMap = dcWarningMapper.selectOrganizationEmployees(id);//人员map
if (employeesMap != null&&employeesMap.size()>UniversalEnum.ZERO.getNumber()) { if (employeesMap != null && employeesMap.size() > UniversalEnum.ZERO.getNumber()) {
HashMap<String, Object> employeesHashMap = new HashMap<>(); HashMap<String, Object> employeesHashMap = new HashMap<>();
// 生成一个随机索引,范围在0到列表长度减1之间 // 生成一个随机索引,范围在0到列表长度减1之间
int randomIndex = ThreadLocalRandom.current().nextInt(employeesMap.size()); int randomIndex = ThreadLocalRandom.current().nextInt(employeesMap.size());
HashMap<String, Object> randomEmployee = employeesMap.get(randomIndex); HashMap<String, Object> randomEmployee = employeesMap.get(randomIndex);
Long employeesId = Long.parseLong(randomEmployee.get("id").toString());//随机人员id Long employeesId = Long.parseLong(randomEmployee.get("id").toString());//随机人员id
String employeesName = dcWarningMapper.employeesName(employeesId);//随机人员姓名 String employeesName = dcWarningMapper.employeesName(employeesId);//随机人员姓名
employeesHashMap.put("employeesId",employeesId); employeesHashMap.put("employeesId", employeesId);
employeesHashMap.put("employeesName",employeesName); employeesHashMap.put("employeesName", employeesName);
mapAll.put("employees",employeesHashMap); mapAll.put("employees", employeesHashMap);
} }
List<HashMap<String, Object>> vehiclesMap = dcWarningMapper.selectVehicles(id);//车辆map List<HashMap<String, Object>> vehiclesMap = dcWarningMapper.selectVehicles(id);//车辆map
if (vehiclesMap != null&&vehiclesMap.size()>UniversalEnum.ZERO.getNumber()) { if (vehiclesMap != null && vehiclesMap.size() > UniversalEnum.ZERO.getNumber()) {
HashMap<String, Object> vehiclesHashMap = new HashMap<>(); HashMap<String, Object> vehiclesHashMap = new HashMap<>();
// 生成一个随机索引,范围在0到列表长度减1之间 // 生成一个随机索引,范围在0到列表长度减1之间
int randomIndex = ThreadLocalRandom.current().nextInt(vehiclesMap.size()); int randomIndex = ThreadLocalRandom.current().nextInt(vehiclesMap.size());
HashMap<String, Object> randomEmployee = vehiclesMap.get(randomIndex); HashMap<String, Object> randomEmployee = vehiclesMap.get(randomIndex);
Long vehiclesId =Long.parseLong(randomEmployee.get("id").toString());//随机车辆id Long vehiclesId = Long.parseLong(randomEmployee.get("id").toString());//随机车辆id
String vehiclesName = dcWarningMapper.vehiclesName(vehiclesId);//随机车辆 String vehiclesName = dcWarningMapper.vehiclesName(vehiclesId);//随机车辆
String vehiclesType = dcWarningMapper.vehiclesType(vehiclesId);//随机车辆 String vehiclesType = dcWarningMapper.vehiclesType(vehiclesId);//随机车辆
vehiclesHashMap.put("vehiclesId",vehiclesId); vehiclesHashMap.put("vehiclesId", vehiclesId);
vehiclesHashMap.put("vehiclesName",vehiclesName); vehiclesHashMap.put("vehiclesName", vehiclesName);
vehiclesHashMap.put("vehiclesType",vehiclesType); vehiclesHashMap.put("vehiclesType", vehiclesType);
mapAll.put("vehicles",vehiclesHashMap); mapAll.put("vehicles", vehiclesHashMap);
} }
} }
} }
return AjaxResult.success(mapAll); return AjaxResult.success(mapAll);
} }
//3.指挥调度新增资源 //3.指挥调度新增资源
@Override @Override
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
@ -858,12 +869,12 @@ public class DcWarningServiceImpl implements IDcWarningService
//事件id、事件备注、机构id、资源id //事件id、事件备注、机构id、资源id
String eventId = map.get("eventId").toString();//事件id String eventId = map.get("eventId").toString();//事件id
String remark = Objects.toString(map.get("remark"), UniversalEnum.EMPTY_STRING.getValue()); String remark = Objects.toString(map.get("remark"), UniversalEnum.EMPTY_STRING.getValue());
Long employees=null; Long employees = null;
if (map.get("employeesId")!=null){ if (map.get("employeesId") != null) {
employees = Long.parseLong(map.get("employeesId").toString());//人员 employees = Long.parseLong(map.get("employeesId").toString());//人员
} }
Long vehicles=null; Long vehicles = null;
if (map.get("vehiclesId")!=null){ if (map.get("vehiclesId") != null) {
vehicles = Long.parseLong(map.get("vehiclesId").toString());//车辆 vehicles = Long.parseLong(map.get("vehiclesId").toString());//车辆
} }
DcDispatch dcDispatch = new DcDispatch(); DcDispatch dcDispatch = new DcDispatch();
@ -874,41 +885,41 @@ public class DcWarningServiceImpl implements IDcWarningService
dcDispatch.setDispatchStatus(Long.valueOf(UniversalEnum.TWO.getNumber()));//进行中状态 dcDispatch.setDispatchStatus(Long.valueOf(UniversalEnum.TWO.getNumber()));//进行中状态
dcDispatch.setRemark(remark); dcDispatch.setRemark(remark);
HashMap<String, Object> dispatch = dcWarningMapper.selectDcDispatch(eventId);//查询是否存在调度记录 HashMap<String, Object> dispatch = dcWarningMapper.selectDcDispatch(eventId);//查询是否存在调度记录
if (dispatch!=null){ //不为空说明已经存在处置记录,不在新增 if (dispatch != null) { //不为空说明已经存在处置记录,不在新增
return AjaxResult.success(UniversalEnum.EXISTING_RECORD.getNumber()); return AjaxResult.success(UniversalEnum.EXISTING_RECORD.getNumber());
} }
Integer integer = dcWarningMapper.insertDcDispatch(dcDispatch);//事件绑定信息记录 Integer integer = dcWarningMapper.insertDcDispatch(dcDispatch);//事件绑定信息记录
if (integer==UniversalEnum.ZERO.getNumber()){ if (integer == UniversalEnum.ZERO.getNumber()) {
return AjaxResult.error(); return AjaxResult.error();
} }
Long dispatchId = dcDispatch.getId();//信息记录id Long dispatchId = dcDispatch.getId();//信息记录id
String context = ""; String context = "";
if (employees!=null) { if (employees != null) {
dcDispatchResource.setResourceId(employees);//资源id dcDispatchResource.setResourceId(employees);//资源id
dcDispatchResource.setDispatchType(UniversalEnum.ONE.getNumber());//资源类型 dcDispatchResource.setDispatchType(UniversalEnum.ONE.getNumber());//资源类型
dcDispatchResource.setDispatchId(dispatchId);//信息记录id dcDispatchResource.setDispatchId(dispatchId);//信息记录id
Integer employeesSource = dcWarningMapper.insertDispatchResource(dcDispatchResource); Integer employeesSource = dcWarningMapper.insertDispatchResource(dcDispatchResource);
if (employeesSource==UniversalEnum.ZERO.getNumber()){ if (employeesSource == UniversalEnum.ZERO.getNumber()) {
return AjaxResult.error(UniversalEnum.PERSONNEL_SCHEDULING_EXCEPTION.getValue()); return AjaxResult.error(UniversalEnum.PERSONNEL_SCHEDULING_EXCEPTION.getValue());
} }
String employeesName = dcWarningMapper.employeesName(employees); String employeesName = dcWarningMapper.employeesName(employees);
context = "路管人员" + employeesName + "参与事件救援,"; context = "路管人员" + employeesName + "参与事件救援,";
} }
if (vehicles!=null) { if (vehicles != null) {
// 生成一个随机索引,范围在0到列表长度减1之间 // 生成一个随机索引,范围在0到列表长度减1之间
dcDispatchResource.setResourceId(vehicles);//资源id dcDispatchResource.setResourceId(vehicles);//资源id
dcDispatchResource.setDispatchType(UniversalEnum.TWO.getNumber());//资源类型 dcDispatchResource.setDispatchType(UniversalEnum.TWO.getNumber());//资源类型
dcDispatchResource.setDispatchId(dispatchId);//信息记录id dcDispatchResource.setDispatchId(dispatchId);//信息记录id
Integer dispatchResource = dcWarningMapper.insertDispatchResource(dcDispatchResource);//绑定车辆信息 Integer dispatchResource = dcWarningMapper.insertDispatchResource(dcDispatchResource);//绑定车辆信息
if (dispatchResource==UniversalEnum.ZERO.getNumber()){ if (dispatchResource == UniversalEnum.ZERO.getNumber()) {
return AjaxResult.error(UniversalEnum.VEHICLE_SCHEDULING_EXCEPTION.getValue()); return AjaxResult.error(UniversalEnum.VEHICLE_SCHEDULING_EXCEPTION.getValue());
} }
String vehiclePlate = dcWarningMapper.vehiclesName(vehicles); String vehiclePlate = dcWarningMapper.vehiclesName(vehicles);
context += "救援车辆" + vehiclePlate + "参与事件救援,"; context += "救援车辆" + vehiclePlate + "参与事件救援,";
} }
if (StringUtils.isNotBlank(context)){ if (StringUtils.isNotBlank(context)) {
context = context.substring(0,context.length() -1); context = context.substring(0, context.length() - 1);
DcEventProcess dcEventProcess = new DcEventProcess(); DcEventProcess dcEventProcess = new DcEventProcess();
dcEventProcess.setEventId(eventId); dcEventProcess.setEventId(eventId);
dcEventProcess.setSource(UniversalEnum.ONE.getNumber()); dcEventProcess.setSource(UniversalEnum.ONE.getNumber());
@ -921,11 +932,12 @@ public class DcWarningServiceImpl implements IDcWarningService
@Override @Override
public Integer insertDispatch(DcDispatch dcDispatch) { public Integer insertDispatch(DcDispatch dcDispatch) {
if (dcDispatch.getId()==null){ //id为空说明新增 if (dcDispatch.getId() == null) { //id为空说明新增
return null; return null;
} }
return dcWarningMapper.updateDcDispatch(dcDispatch); return dcWarningMapper.updateDcDispatch(dcDispatch);
} }
//4.新增指挥调度资源记录 //4.新增指挥调度资源记录
@Override @Override
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
@ -940,17 +952,17 @@ public class DcWarningServiceImpl implements IDcWarningService
dcDispatch.setDispatchStatus(Long.valueOf(UniversalEnum.TWO.getNumber()));//进行中状态 dcDispatch.setDispatchStatus(Long.valueOf(UniversalEnum.TWO.getNumber()));//进行中状态
dcDispatch.setRemark(remark); dcDispatch.setRemark(remark);
HashMap<String, Object> dispatch = dcWarningMapper.selectDcDispatch(eventId);//查询是否存在调度记录 HashMap<String, Object> dispatch = dcWarningMapper.selectDcDispatch(eventId);//查询是否存在调度记录
if (dispatch!=null){ //不为空说明已经存在处置记录,不在新增 if (dispatch != null) { //不为空说明已经存在处置记录,不在新增
return 1; return 1;
} }
dcWarningMapper.insertDcDispatch(dcDispatch);//事件绑定信息记录 dcWarningMapper.insertDcDispatch(dcDispatch);//事件绑定信息记录
Long dispatchId = dcDispatch.getId(); Long dispatchId = dcDispatch.getId();
dcWarningMapper.deleteDispatchResource(dispatchId);//删除全部属于该调度记录下的全部资源 dcWarningMapper.deleteDispatchResource(dispatchId);//删除全部属于该调度记录下的全部资源
ArrayList<Map<String,Object>> employeesArray = (ArrayList<Map<String,Object>>) map.get("employees");//取出人员 ArrayList<Map<String, Object>> employeesArray = (ArrayList<Map<String, Object>>) map.get("employees");//取出人员
String context = UniversalEnum.EMPTY_STRING.getValue(); String context = UniversalEnum.EMPTY_STRING.getValue();
if (employeesArray!=null&&employeesArray.size()>UniversalEnum.ZERO.getNumber()) { if (employeesArray != null && employeesArray.size() > UniversalEnum.ZERO.getNumber()) {
context += UniversalEnum.ROAD_CONTROL_PERSONNEL.getValue(); context += UniversalEnum.ROAD_CONTROL_PERSONNEL.getValue();
for (Map<String,Object> array : employeesArray) { for (Map<String, Object> array : employeesArray) {
dcDispatchResource.setDispatchType(UniversalEnum.ONE.getNumber());//类型 dcDispatchResource.setDispatchType(UniversalEnum.ONE.getNumber());//类型
dcDispatchResource.setResourceId(Long.valueOf(array.get("id").toString()));//资源id dcDispatchResource.setResourceId(Long.valueOf(array.get("id").toString()));//资源id
dcDispatchResource.setDispatchId(dispatchId);//关联调度记录 dcDispatchResource.setDispatchId(dispatchId);//关联调度记录
@ -960,16 +972,16 @@ public class DcWarningServiceImpl implements IDcWarningService
throw new RuntimeException(UniversalEnum.FAILED_TO_INSERT_RESOURCE.getValue()); throw new RuntimeException(UniversalEnum.FAILED_TO_INSERT_RESOURCE.getValue());
} }
} }
context = context.substring(UniversalEnum.ZERO.getNumber(),context.length() -UniversalEnum.ONE.getNumber()); context = context.substring(UniversalEnum.ZERO.getNumber(), context.length() - UniversalEnum.ONE.getNumber());
context += UniversalEnum.PARTICIPATE_IN_INCIDENT_RESCUE.getValue(); context += UniversalEnum.PARTICIPATE_IN_INCIDENT_RESCUE.getValue();
} }
ArrayList<Map<String,Object>> vehicleArray = (ArrayList<Map<String,Object>>) map.get("vehicle");////取出车辆 ArrayList<Map<String, Object>> vehicleArray = (ArrayList<Map<String, Object>>) map.get("vehicle");////取出车辆
if (vehicleArray!=null&&vehicleArray.size()>UniversalEnum.ZERO.getNumber()) { if (vehicleArray != null && vehicleArray.size() > UniversalEnum.ZERO.getNumber()) {
if (context.length() > UniversalEnum.ZERO.getNumber()){ if (context.length() > UniversalEnum.ZERO.getNumber()) {
context += UniversalEnum.CHINESE_COMMA.getValue(); context += UniversalEnum.CHINESE_COMMA.getValue();
} }
context += UniversalEnum.RESCUE_VEHICLE.getValue(); context += UniversalEnum.RESCUE_VEHICLE.getValue();
for (Map<String,Object> array : vehicleArray) { for (Map<String, Object> array : vehicleArray) {
dcDispatchResource.setDispatchType(UniversalEnum.TWO.getNumber()); dcDispatchResource.setDispatchType(UniversalEnum.TWO.getNumber());
dcDispatchResource.setResourceId(Long.valueOf(array.get("id").toString())); dcDispatchResource.setResourceId(Long.valueOf(array.get("id").toString()));
dcDispatchResource.setDispatchId(dispatchId); dcDispatchResource.setDispatchId(dispatchId);
@ -980,7 +992,7 @@ public class DcWarningServiceImpl implements IDcWarningService
throw new RuntimeException(UniversalEnum.FAILED_TO_INSERT_RESOURCE.getValue()); throw new RuntimeException(UniversalEnum.FAILED_TO_INSERT_RESOURCE.getValue());
} }
} }
context = context.substring(UniversalEnum.ZERO.getNumber(),context.length() -UniversalEnum.ONE.getNumber()); context = context.substring(UniversalEnum.ZERO.getNumber(), context.length() - UniversalEnum.ONE.getNumber());
context += UniversalEnum.PARTICIPATE_IN_INCIDENT_RESCUE.getValue(); context += UniversalEnum.PARTICIPATE_IN_INCIDENT_RESCUE.getValue();
} }
@ -1003,11 +1015,11 @@ public class DcWarningServiceImpl implements IDcWarningService
DcDispatchResource dcDispatchResource = new DcDispatchResource(); DcDispatchResource dcDispatchResource = new DcDispatchResource();
Long dispatchId = Long.parseLong(map.get("dispatchId").toString()); Long dispatchId = Long.parseLong(map.get("dispatchId").toString());
dcWarningMapper.deleteDispatchResource(dispatchId);//删除全部属于该调度记录下的全部资源 dcWarningMapper.deleteDispatchResource(dispatchId);//删除全部属于该调度记录下的全部资源
ArrayList<Map<String,Object>> employeesArray = (ArrayList<Map<String,Object>>) map.get("employees");//取出人员 ArrayList<Map<String, Object>> employeesArray = (ArrayList<Map<String, Object>>) map.get("employees");//取出人员
String context = UniversalEnum.EMPTY_STRING.getValue(); String context = UniversalEnum.EMPTY_STRING.getValue();
if (employeesArray!=null&&employeesArray.size()>UniversalEnum.ZERO.getNumber()) { if (employeesArray != null && employeesArray.size() > UniversalEnum.ZERO.getNumber()) {
context += UniversalEnum.ROAD_CONTROL_PERSONNEL.getValue(); context += UniversalEnum.ROAD_CONTROL_PERSONNEL.getValue();
for (Map<String,Object> array : employeesArray) { for (Map<String, Object> array : employeesArray) {
dcDispatchResource.setDispatchType(UniversalEnum.ONE.getNumber());//类型 dcDispatchResource.setDispatchType(UniversalEnum.ONE.getNumber());//类型
dcDispatchResource.setResourceId(Long.valueOf(array.get("id").toString()));//资源id dcDispatchResource.setResourceId(Long.valueOf(array.get("id").toString()));//资源id
dcDispatchResource.setDispatchId(dispatchId);//关联调度记录 dcDispatchResource.setDispatchId(dispatchId);//关联调度记录
@ -1017,16 +1029,16 @@ public class DcWarningServiceImpl implements IDcWarningService
throw new RuntimeException(UniversalEnum.FAILED_TO_INSERT_RESOURCE.getValue()); throw new RuntimeException(UniversalEnum.FAILED_TO_INSERT_RESOURCE.getValue());
} }
} }
context = context.substring(UniversalEnum.ZERO.getNumber(),context.length() -UniversalEnum.ONE.getNumber()); context = context.substring(UniversalEnum.ZERO.getNumber(), context.length() - UniversalEnum.ONE.getNumber());
context += UniversalEnum.PARTICIPATE_IN_INCIDENT_RESCUE.getValue(); context += UniversalEnum.PARTICIPATE_IN_INCIDENT_RESCUE.getValue();
} }
ArrayList<Map<String,Object>> vehicleArray = (ArrayList<Map<String,Object>>) map.get("vehicle");////取出车辆 ArrayList<Map<String, Object>> vehicleArray = (ArrayList<Map<String, Object>>) map.get("vehicle");////取出车辆
if (vehicleArray!=null&&vehicleArray.size()>UniversalEnum.ZERO.getNumber()) { if (vehicleArray != null && vehicleArray.size() > UniversalEnum.ZERO.getNumber()) {
if (context.length() > UniversalEnum.ZERO.getNumber()){ if (context.length() > UniversalEnum.ZERO.getNumber()) {
context += UniversalEnum.CHINESE_COMMA.getValue(); context += UniversalEnum.CHINESE_COMMA.getValue();
} }
context += UniversalEnum.RESCUE_VEHICLE.getValue(); context += UniversalEnum.RESCUE_VEHICLE.getValue();
for (Map<String,Object> array : vehicleArray) { for (Map<String, Object> array : vehicleArray) {
dcDispatchResource.setDispatchType(UniversalEnum.TWO.getNumber()); dcDispatchResource.setDispatchType(UniversalEnum.TWO.getNumber());
dcDispatchResource.setResourceId(Long.valueOf(array.get("id").toString())); dcDispatchResource.setResourceId(Long.valueOf(array.get("id").toString()));
dcDispatchResource.setDispatchId(dispatchId); dcDispatchResource.setDispatchId(dispatchId);
@ -1037,7 +1049,7 @@ public class DcWarningServiceImpl implements IDcWarningService
throw new RuntimeException(UniversalEnum.FAILED_TO_INSERT_RESOURCE.getValue()); throw new RuntimeException(UniversalEnum.FAILED_TO_INSERT_RESOURCE.getValue());
} }
} }
context = context.substring(UniversalEnum.ZERO.getNumber(),context.length() -UniversalEnum.ONE.getNumber()); context = context.substring(UniversalEnum.ZERO.getNumber(), context.length() - UniversalEnum.ONE.getNumber());
context += UniversalEnum.PARTICIPATE_IN_INCIDENT_RESCUE.getValue(); context += UniversalEnum.PARTICIPATE_IN_INCIDENT_RESCUE.getValue();
} }
@ -1061,4 +1073,110 @@ public class DcWarningServiceImpl implements IDcWarningService
return i; return i;
} }
/**
* 获取雷达事件视频
*/
@Override
public String getRadarIncidentVideo(String id) throws Exception {
String msg = "";
HashMap<String, Object> stringObjectHashMap = dcWarningMapper.selectDcWarningById(id);
// 给定的时间
String givenTime = (String) stringObjectHashMap.get("warningTime");
// 定义日期时间格式
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
// 解析给定的时间
LocalDateTime currentTime = LocalDateTime.parse(givenTime, formatter);
// 计算 30 秒后的时间
LocalDateTime timeAfter30Seconds = currentTime.plus(Duration.ofSeconds(30));
// 获取当前时间
LocalDateTime now = LocalDateTime.now();
// 判断时间与当前时间不能超过两个月
boolean isWithinTwoMonths = ChronoUnit.MONTHS.between(now, currentTime) <= 2;
if (isWithinTwoMonths) {
// 格式化时间
String formattedTime = timeAfter30Seconds.format(formatter);
Object otherConfig = stringObjectHashMap.get("otherConfig");
ObjectMapper objectMapper = new ObjectMapper();
JsonNode rootNode = objectMapper.readTree(otherConfig.toString());
// 提取 cameraIndexCode 的值
String cameraIndexCode = extractCameraIndexCode(rootNode);
//雷达关联监控点查询接口
String callPostApiGetRegions = callPostApiGetRegions(cameraIndexCode);
JsonNode roocallPostApiGetRegionstNode = objectMapper.readTree(callPostApiGetRegions);
JsonNode jsonNode = roocallPostApiGetRegionstNode.get("data");
JsonNode jsonNodelist = jsonNode.get("list");
JsonNode code = jsonNodelist.get(0).get("cameraIndexCode");
// 使用 textValue() 方法获取纯字符串
String codestring = code.textValue();
com.alibaba.fastjson.JSONObject jsonObject = videoController.downloadCameraVideo(codestring, formattedTime, 1);
JsonNode data = objectMapper.readTree(jsonObject.get("data").toString());
// 使用 textValue() 方法获取纯字符串
String fileUrl = data.get("fileUrl").textValue();
return fileUrl;
} else {
return null;
}
}
/**
* 雷达关联监控点查询接口
*
* @throws HttpException
* @throws IOException
*/
private String extractCameraIndexCode(JsonNode rootNode) {
JsonNode dataNode = rootNode.get("data");
JsonNode otherConfigurationNode = dataNode.get("otherConfiguration");
JsonNode paramsNode = otherConfigurationNode.get("params");
JsonNode eventsNode = paramsNode.get("events");
// 假设只有一个事件,我们只处理第一个事件
JsonNode eventDataNode = eventsNode.get(0);
JsonNode dataNode2 = eventDataNode.get("data");
JsonNode vehicleRcogResultNode = dataNode2.get("vehicleRcogResult");
// 假设只有一个 vehicleRcogResult 对象
JsonNode targetAttrsNode = vehicleRcogResultNode.get(0).get("targetAttrs");
return targetAttrsNode.get("cameraIndexCode").asText();
}
/**
* 调用POST请求类型接口这里以分页获取区域列表为例
* 接口实际urlhttps://ip:port/artemis/api/api/resource/v1/regions
*
* @return
*/
public String callPostApiGetRegions(String cameraIndexCode) throws Exception {
/**
* https://ip:port/artemis/api/resource/v1/regions
* 过查阅AI Cloud开放平台文档或网关门户的文档可以看到分页获取区域列表的定义,这是一个POST请求的Rest接口, 入参为JSON字符串接口协议为https
* ArtemisHttpUtil工具类提供了doPostStringArtemis调用POST请求的方法入参可传JSON字符串, 请阅读开发指南了解方法入参没有的参数可传null
*/
com.alibaba.fastjson.JSONObject radarCorrelation = com.alibaba.fastjson.JSONObject.parseObject(configService.selectConfigByKey("radarCorrelation"));
ArtemisConfig config = new ArtemisConfig();
config.setHost(radarCorrelation.getString("url")); // 雷达关联监控点查询接口
config.setAppKey(radarCorrelation.getString("appkey")); // 秘钥appkey
config.setAppSecret(radarCorrelation.getString("appSecret"));// 秘钥appSecret
final String getCamsApi = ARTEMIS_PATH + UniversalEnum.RADAR_ASSOCIATED_MONITORING_POINT_QUERY_INTERFACE.getValue();
Map<String, String> paramMap = new HashMap<String, String>();// post请求Form表单参数
paramMap.put("pageNo", "1");
paramMap.put("pageSize", "20");
paramMap.put("radarIndexCode", cameraIndexCode);
String body = JSON.toJSON(paramMap).toString();
Map<String, String> path = new HashMap<String, String>(2) {
{
put("https://", getCamsApi);
}
};
return ArtemisHttpUtil.doPostStringArtemis(config, path, body, null, null, "application/json");
}
} }
Loading…
Cancel
Save