Commit a23936fc by 谢海旭

预警分析时间轴接口优化

1 parent 592c092e
......@@ -93,6 +93,7 @@ public class RiskAssessmentController extends AbstractController {
@ApiResponses({@ApiResponse(code = 200, message = "OK", response = AlarmTimeLinePointVo.class)})
@GetMapping(value = "/getAlarmTimeLine")
public R<List<AlarmTimeLinePointVo>> getAlarmTimeLine(@RequestParam("vehicleId") Long vehicleId) {
log.info("查询车辆警情时间轴信息 vehicleId:{}", vehicleId);
List<AlarmTimeLinePointVo> alarmTimeLinePointVos = riskAssessmentService.getAlarmTimeLine(vehicleId);
return R.ok().data(alarmTimeLinePointVos);
}
......
......@@ -529,50 +529,54 @@ public class RiskAssessmentService {
List<VehicleDevice> devices = vehicleDeviceMapper.selectBindDeviceByVehicleId(vehicleId);
List<String> snList = devices.stream().map(device -> device.getSn()).collect(Collectors.toList());
devices.sort(Comparator.comparing(VehicleDevice::getId));
Map<String, String> snDeviceNameMap = new HashMap<>();
int wireTypeNum = 1;
int wireLessTypeNum = 1;
for (VehicleDevice device : devices) {
Integer type = device.getWireType();
String typeName = TypeConverseEnum.SourceEnum.getStrBySourceType(type);
if (type.equals(TypeConverseEnum.SourceEnum.HAS_SOURCE.getSourceType())) {
snDeviceNameMap.put(device.getSn(), typeName + wireTypeNum);
wireTypeNum++;
} else {
snDeviceNameMap.put(device.getSn(), typeName + wireLessTypeNum);
wireLessTypeNum++;
}
}
// 查询大数据研判警情:黑区、聚集
List<AlarmTimeLinePointVo> alarmInfoList = Lists.newArrayList();
log.info("查询大数据研判警情 请求参数:{}", JSONUtil.toJsonStr(snList));
List<StuJudgeAlarmDto> stuJudgeAlarmList = remoteStuJudgeAlarmService.selectLatestAlarmOfEachType(snList);
log.info("查询大数据研判警情 请求结果:{}", JSONUtil.toJsonStr(stuJudgeAlarmList));
stuJudgeAlarmList.forEach(alarm -> {
AlarmTimeLinePointVo pointVo = new AlarmTimeLinePointVo();
// 2聚集 3黑区 TODO 优化
pointVo.setAlarmType(alarm.getAlarmType().equals(3)?"黑区":"聚集");
pointVo.setAlarmType(TypeConverseEnum.AlarmTypeEnum.getStrByAlarmType(alarm.getAlarmType()));
pointVo.setAlarmTime(alarm.getAlarmEndTime());
// TODO 处理 设备类型名称+排序序号,如“有线设备1”
pointVo.setDevice("有线设备1");
pointVo.setDevice(snDeviceNameMap.get(alarm.getSn()));
pointVo.setAlarmLevel(1);
alarmInfoList.add(pointVo);
});
// 查询防拆警情:断电、光感、翻转
// TODO 接口测试,生效中的警情没有,只有开始时间没有结束时间
log.info("查询防拆警情 请求参数:{}", JSONUtil.toJsonStr(snList));
List<CommonAlarmDto> tearDownAlarmList = remoteAlarmService.selectLatestAlarmOfEachType(snList);
log.info("查询防拆警情 请求结果:{}", JSONUtil.toJsonStr(tearDownAlarmList));
if (CollectionUtils.isNotEmpty(tearDownAlarmList)) {
tearDownAlarmList.forEach(alarm -> {
AlarmTimeLinePointVo pointVo = new AlarmTimeLinePointVo();
pointVo.setAlarmLevel(1);
pointVo.setAlarmTime(alarm.getBeginTime());
// TODO 处理 设备类型名称+排序序号,如“有线设备1”
pointVo.setDevice("有线设备1");
// TODO 优化
switch (alarm.getAlarmType()) {
case 1:
pointVo.setAlarmType("断电");
break;
case 99:
pointVo.setAlarmType("光感");
break;
case 15:
pointVo.setAlarmType("翻转");
break;
default:
break;
}
pointVo.setDevice(snDeviceNameMap.get(alarm.getSn()));
pointVo.setAlarmType(TypeConverseEnum.AlarmRecTypeEnum.getStrByAlarmType(alarm.getAlarmType()));
alarmInfoList.add(pointVo);
});
}
// 查询离线警情
getOffLinePoint(snList, alarmInfoList);
getOffLinePoint(snList, alarmInfoList, snDeviceNameMap);
// 查询警情研判:多种警情
List<AlarmWarnAnalyse> alarmWarnAnalyseList = alarmWarnAnalyseMapper.selectLatestAlarmOfEachType(vehicleId);
......@@ -582,8 +586,14 @@ public class RiskAssessmentService {
pointVo.setAlarmLevel(alarm.getAlarmLevel());
pointVo.setAlarmTime(DateUtil.formatDate(alarm.getAlarmTime()));
pointVo.setAlarmType(alarm.getAlarmExplain());
// TODO 处理 设备类型名称+排序序号,如“有线设备1”
pointVo.setDevice("有线设备1");
String[] snArr = alarm.getDeviceNoes().split(";");
for (String sn : snArr) {
if (snDeviceNameMap.containsKey(sn)) {
pointVo.setDevice(snDeviceNameMap.get(sn));
break;
}
}
alarmInfoList.add(pointVo);
});
}
......@@ -592,7 +602,6 @@ public class RiskAssessmentService {
Comparator<AlarmTimeLinePointVo> comparator = (e1, e2) -> {
Date date1 = DateUtil.parseDate(e1.getAlarmTime());
Date date2 = DateUtil.parseDate(e2.getAlarmTime());
// TODO 考虑判空
if (date1.equals(date2)) {
return Integer.compare(e1.getAlarmLevel(), e2.getAlarmLevel());
} else {
......@@ -609,8 +618,7 @@ public class RiskAssessmentService {
alarmInfoList.add(0, firstPoint);
// 获取最后检测时间节点
getLatestCheckPoint(alarmInfoList, vehicle);
getLatestCheckPoint(alarmInfoList, vehicle, snDeviceNameMap);
return alarmInfoList;
}
......@@ -620,7 +628,7 @@ public class RiskAssessmentService {
* @param alarmInfoList
* @param vehicle
*/
private void getLatestCheckPoint(List<AlarmTimeLinePointVo> alarmInfoList, Vehicle vehicle) {
private void getLatestCheckPoint(List<AlarmTimeLinePointVo> alarmInfoList, Vehicle vehicle, Map<String, String> snDeviceNameMap) {
FinalPositioningSearch search = new FinalPositioningSearch();
search.setKeywords(vehicle.getVin());
search.setPageNumber(1);
......@@ -634,7 +642,7 @@ public class RiskAssessmentService {
TreeMap<String, String> sortedMap = new TreeMap<>(new Comparator<String>() {
@Override
public int compare(String o1, String o2) {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
SimpleDateFormat sdf = new SimpleDateFormat(DateUtil.YMDHMS);
try {
Date time1 = sdf.parse(o1);
Date time2 = sdf.parse(o2);
......@@ -662,16 +670,14 @@ public class RiskAssessmentService {
AlarmTimeLinePointVo lastPoint = new AlarmTimeLinePointVo();
lastPoint.setAlarmType("最后检测");
if (sortedMap.size() == 0) {
// TODO 处理 设备类型名称+排序序号,如“有线设备1”
String sn = finalPositioningList.get(0).getSn();
lastPoint.setDevice("有线设备1");
lastPoint.setDevice(snDeviceNameMap.get(sn));
} else {
Map.Entry<String, String> firstEntry = sortedMap.firstEntry();
String time = firstEntry.getKey();
String sn = firstEntry.getValue();
lastPoint.setAlarmTime(time);
// TODO 处理 设备类型名称+排序序号,如“有线设备1”
lastPoint.setDevice("有线设备1");
lastPoint.setDevice(snDeviceNameMap.get(sn));
}
alarmInfoList.add(lastPoint);
......@@ -683,13 +689,13 @@ public class RiskAssessmentService {
* @param snList
* @param alarmInfoList
*/
private void getOffLinePoint(List<String> snList, List<AlarmTimeLinePointVo> alarmInfoList) {
private void getOffLinePoint(List<String> snList, List<AlarmTimeLinePointVo> alarmInfoList, Map<String, String> snDeviceNameMap) {
List<DeviceLocation> deviceLocationList = deviceLocationMapper.findLocationListBySnList(snList);
if (CollectionUtils.isEmpty(deviceLocationList)) {
return;
}
// 是否离线判断
// 是否离线判断 前三天时间范围内存在上报记录则不算离线
for (DeviceLocation location : deviceLocationList) {
Date date = DateUtils.addDays(new Date(), -3);
Date lastGpsTime = location.getLastGpsTime();
......@@ -703,6 +709,7 @@ public class RiskAssessmentService {
}
}
// 取基准时间
Date latestTime = null;
String alarmSn = null;
for (DeviceLocation location : deviceLocationList) {
......@@ -721,17 +728,18 @@ public class RiskAssessmentService {
}
}
// 不存在基准时间则以第一个设备为准
if (Objects.isNull(latestTime)) {
AlarmTimeLinePointVo pointVo = new AlarmTimeLinePointVo();
pointVo.setAlarmLevel(3);
pointVo.setAlarmType("离线报警");
// TODO 处理 设备类型名称+排序序号,如“有线设备1”
String sn = deviceLocationList.get(0).getSn();
pointVo.setDevice("有线设备1");
pointVo.setDevice(snDeviceNameMap.get(sn));
alarmInfoList.add(pointVo);
return;
}
// 取最近上报时间点
for (DeviceLocation location : deviceLocationList) {
Date lastGpsTime = location.getLastGpsTime();
if (Objects.nonNull(lastGpsTime) && lastGpsTime.compareTo(latestTime) > 0) {
......@@ -750,8 +758,7 @@ public class RiskAssessmentService {
pointVo.setAlarmLevel(3);
pointVo.setAlarmTime(DateUtil.formatDate(latestTime));
pointVo.setAlarmType("离线报警");
// TODO 处理 设备类型名称+排序序号,如“有线设备1”
pointVo.setDevice("有线设备1");
pointVo.setDevice(snDeviceNameMap.get(alarmSn));
alarmInfoList.add(pointVo);
}
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!