2024-05-27 18:25:07 +08:00
|
|
|
|
package com.zhgd.xmgl.task;
|
|
|
|
|
|
|
2025-11-26 18:37:16 +08:00
|
|
|
|
import java.util.Date;
|
|
|
|
|
|
|
2024-05-27 18:25:07 +08:00
|
|
|
|
import cn.hutool.core.collection.CollUtil;
|
|
|
|
|
|
import cn.hutool.core.date.DateUtil;
|
2025-02-21 19:18:53 +08:00
|
|
|
|
import cn.hutool.core.util.NumberUtil;
|
|
|
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
2024-05-27 18:25:07 +08:00
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
2025-02-21 19:18:53 +08:00
|
|
|
|
import com.zhgd.redis.lock.RedisRepository;
|
|
|
|
|
|
import com.zhgd.xmgl.base.HikvisionEventsPictureRq;
|
|
|
|
|
|
import com.zhgd.xmgl.call.HikvisionCall;
|
2025-11-26 18:37:16 +08:00
|
|
|
|
import com.zhgd.xmgl.modules.baotou.entity.CarDangerDetect;
|
|
|
|
|
|
import com.zhgd.xmgl.modules.baotou.entity.CarDangerDetectRecord;
|
|
|
|
|
|
import com.zhgd.xmgl.modules.baotou.service.ICarDangerDetectRecordService;
|
|
|
|
|
|
import com.zhgd.xmgl.modules.baotou.service.ICarDangerDetectService;
|
2024-05-27 18:25:07 +08:00
|
|
|
|
import com.zhgd.xmgl.modules.car.entity.CarInfo;
|
2024-05-28 15:14:02 +08:00
|
|
|
|
import com.zhgd.xmgl.modules.car.entity.CarInfoApprovalFlow;
|
2025-02-21 19:18:53 +08:00
|
|
|
|
import com.zhgd.xmgl.modules.car.entity.CarMeasureSpeedData;
|
|
|
|
|
|
import com.zhgd.xmgl.modules.car.entity.CarMeasureSpeedDev;
|
2024-07-05 19:07:36 +08:00
|
|
|
|
import com.zhgd.xmgl.modules.car.enums.CarInfoCarModuleTypeEnum;
|
2024-05-27 22:58:57 +08:00
|
|
|
|
import com.zhgd.xmgl.modules.car.mapper.CarInfoApprovalFlowMapper;
|
2024-05-27 18:25:07 +08:00
|
|
|
|
import com.zhgd.xmgl.modules.car.mapper.CarInfoMapper;
|
2025-02-21 19:18:53 +08:00
|
|
|
|
import com.zhgd.xmgl.modules.car.service.ICarMeasureSpeedDataService;
|
|
|
|
|
|
import com.zhgd.xmgl.modules.car.service.ICarMeasureSpeedDevService;
|
2024-05-27 18:25:07 +08:00
|
|
|
|
import com.zhgd.xmgl.modules.car.service.impl.CarInfoServiceImpl;
|
|
|
|
|
|
import com.zhgd.xmgl.modules.project.entity.Project;
|
|
|
|
|
|
import com.zhgd.xmgl.modules.project.mapper.ProjectMapper;
|
2025-02-21 19:18:53 +08:00
|
|
|
|
import com.zhgd.xmgl.util.HikvisionUtil;
|
2024-05-27 18:25:07 +08:00
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
2025-02-21 19:18:53 +08:00
|
|
|
|
import net.javacrumbs.shedlock.core.SchedulerLock;
|
|
|
|
|
|
import org.apache.commons.lang3.StringUtils;
|
2024-05-27 18:25:07 +08:00
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
|
import org.springframework.context.annotation.Lazy;
|
|
|
|
|
|
import org.springframework.scheduling.annotation.Scheduled;
|
2025-02-21 19:18:53 +08:00
|
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
|
|
|
import org.springframework.web.bind.annotation.RestController;
|
2024-05-27 18:25:07 +08:00
|
|
|
|
|
2025-02-21 19:18:53 +08:00
|
|
|
|
import java.math.BigDecimal;
|
|
|
|
|
|
import java.util.*;
|
|
|
|
|
|
import java.util.function.Function;
|
|
|
|
|
|
import java.util.stream.Collectors;
|
2024-05-27 18:25:07 +08:00
|
|
|
|
|
|
|
|
|
|
@Slf4j
|
2025-02-21 19:18:53 +08:00
|
|
|
|
@RequestMapping("/xmgl/task")
|
|
|
|
|
|
@RestController
|
2024-05-27 18:25:07 +08:00
|
|
|
|
public class CarInfoTask {
|
2025-02-21 19:18:53 +08:00
|
|
|
|
@Lazy
|
|
|
|
|
|
@Autowired
|
|
|
|
|
|
HikvisionCall hikvisionCall;
|
2024-05-27 18:25:07 +08:00
|
|
|
|
@Lazy
|
|
|
|
|
|
@Autowired
|
|
|
|
|
|
private CarInfoServiceImpl carInfoService;
|
|
|
|
|
|
@Lazy
|
|
|
|
|
|
@Autowired
|
|
|
|
|
|
private CarInfoMapper carInfoMapper;
|
|
|
|
|
|
@Lazy
|
|
|
|
|
|
@Autowired
|
|
|
|
|
|
private ProjectMapper projectMapper;
|
|
|
|
|
|
@Lazy
|
|
|
|
|
|
@Autowired
|
|
|
|
|
|
private CarInfoApprovalFlowMapper carInfoApprovalFlowMapper;
|
2025-02-21 19:18:53 +08:00
|
|
|
|
@Lazy
|
|
|
|
|
|
@Autowired
|
|
|
|
|
|
private RedisRepository redisRepository;
|
|
|
|
|
|
@Lazy
|
|
|
|
|
|
@Autowired
|
|
|
|
|
|
private ICarMeasureSpeedDevService carMeasureSpeedDevService;
|
|
|
|
|
|
@Autowired
|
|
|
|
|
|
private ICarMeasureSpeedDataService carMeasureSpeedDataService;
|
2025-11-26 18:37:16 +08:00
|
|
|
|
@Lazy
|
|
|
|
|
|
@Autowired
|
|
|
|
|
|
private ICarDangerDetectRecordService carDangerDetectRecordService;
|
|
|
|
|
|
@Lazy
|
|
|
|
|
|
@Autowired
|
|
|
|
|
|
private ICarDangerDetectService carDangerDetectService;
|
2024-05-27 18:25:07 +08:00
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 定时删除/更新过期的车辆,并下发新的预约时间的车辆到海康
|
|
|
|
|
|
*/
|
|
|
|
|
|
@Scheduled(cron = "*/30 * * * * ?")
|
|
|
|
|
|
public void deleteOrUpdateExpiredCar() {
|
2024-05-28 15:14:02 +08:00
|
|
|
|
//删除过期
|
|
|
|
|
|
carInfoApprovalFlowMapper.delete(new LambdaQueryWrapper<CarInfoApprovalFlow>()
|
2024-05-29 14:16:17 +08:00
|
|
|
|
.lt(CarInfoApprovalFlow::getReserveEndTime, DateUtil.now())
|
|
|
|
|
|
.eq(CarInfoApprovalFlow::getIsBlack, 0)
|
|
|
|
|
|
);
|
2024-05-27 18:25:07 +08:00
|
|
|
|
List<Project> projects = projectMapper.selectList(new LambdaQueryWrapper<Project>().eq(Project::getSyncHikvision, 1));
|
|
|
|
|
|
for (Project project : projects) {
|
2024-05-27 22:58:57 +08:00
|
|
|
|
//过期或者未来车
|
|
|
|
|
|
List<CarInfo> cars = carInfoMapper.selectList(new LambdaQueryWrapper<CarInfo>()
|
2024-07-05 19:07:36 +08:00
|
|
|
|
.ne(CarInfo::getCarModuleType, CarInfoCarModuleTypeEnum.GD.getValue())
|
2024-05-29 14:16:17 +08:00
|
|
|
|
.eq(CarInfo::getIsBlack, 0)
|
2024-05-27 18:25:07 +08:00
|
|
|
|
.eq(CarInfo::getProjectSn, project.getProjectSn())
|
2024-05-27 22:58:57 +08:00
|
|
|
|
.and(w -> w.lt(CarInfo::getReserveEndTime, DateUtil.now()).or().gt(CarInfo::getReserveStartTime, DateUtil.now()))
|
2024-05-27 18:25:07 +08:00
|
|
|
|
);
|
2024-05-27 22:58:57 +08:00
|
|
|
|
if (CollUtil.isEmpty(cars)) {
|
2024-05-27 18:25:07 +08:00
|
|
|
|
return;
|
|
|
|
|
|
}
|
2024-05-27 22:58:57 +08:00
|
|
|
|
for (CarInfo carInfo : cars) {
|
2024-05-29 14:16:17 +08:00
|
|
|
|
carInfoService.deleteOrUpdateCar(project, carInfo, false);
|
2024-05-27 18:25:07 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-02-21 19:18:53 +08:00
|
|
|
|
/**
|
|
|
|
|
|
* 定时到海康拉取车辆超速,园区卡口违章事件查询v2
|
|
|
|
|
|
*/
|
|
|
|
|
|
@Scheduled(cron = "* */2 * * * ?")
|
|
|
|
|
|
@SchedulerLock(name = "getCarMeasureSpeedData", lockAtMostFor = 1000 * 60, lockAtLeastFor = 1000 * 60)
|
|
|
|
|
|
@RequestMapping("getCarMeasureSpeedData")
|
|
|
|
|
|
public void getCarMeasureSpeedData() {
|
|
|
|
|
|
String start;
|
|
|
|
|
|
String queryTimeKey = "GET_ISC_CAR_MEASURE_SPEED_DATA_TIME";
|
|
|
|
|
|
Object o = redisRepository.get(queryTimeKey);
|
|
|
|
|
|
if (o != null) {
|
|
|
|
|
|
start = o.toString();
|
|
|
|
|
|
} else {
|
|
|
|
|
|
start = DateUtil.format(DateUtil.offsetDay(new Date(), -1), "yyyy-MM-dd'T'HH:mm:ss.SSSXXX");
|
|
|
|
|
|
}
|
2025-11-26 18:37:16 +08:00
|
|
|
|
String end = DateUtil.format(DateUtil.offsetMinute(new Date(), -2), "yyyy-MM-dd'T'HH:mm:ss.SSSXXX");
|
2025-02-21 19:18:53 +08:00
|
|
|
|
redisRepository.set(queryTimeKey, end);
|
|
|
|
|
|
List<Project> projects = projectMapper.selectList(new LambdaQueryWrapper<Project>()
|
|
|
|
|
|
.eq(Project::getSyncHikvision, 1));
|
2025-11-26 18:37:16 +08:00
|
|
|
|
Map<String, List<CarMeasureSpeedDev>> projectMap = carMeasureSpeedDevService.list().stream().collect(Collectors.groupingBy(CarMeasureSpeedDev::getProjectSn));
|
|
|
|
|
|
Map<String, List<CarDangerDetect>> dangerDetectProjectMap = carDangerDetectService.list().stream().collect(Collectors.groupingBy(CarDangerDetect::getProjectSn));
|
|
|
|
|
|
for (Project project : projects) {
|
|
|
|
|
|
try {
|
|
|
|
|
|
JSONArray listJa = getSpeedDataList(start, project);
|
|
|
|
|
|
if (CollUtil.isEmpty(listJa)) {
|
|
|
|
|
|
continue;
|
2025-02-21 19:18:53 +08:00
|
|
|
|
}
|
2025-11-26 18:37:16 +08:00
|
|
|
|
Map<String, CarMeasureSpeedDev> devMap = Optional.ofNullable(projectMap.get(project.getProjectSn())).map(m -> m.stream().collect(Collectors.toMap(CarMeasureSpeedDev::getDevSn, Function.identity()))).orElse(null);
|
|
|
|
|
|
List<CarMeasureSpeedData> speedDatas = buildSpeedData(listJa, devMap, project);
|
|
|
|
|
|
if (CollUtil.isNotEmpty(speedDatas)) {
|
|
|
|
|
|
carMeasureSpeedDataService.saveBatch(speedDatas);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Map<String, CarDangerDetect> carDangerDevMap = Optional.ofNullable(dangerDetectProjectMap.get(project.getProjectSn())).map(m -> m.stream().collect(Collectors.toMap(CarDangerDetect::getHardwareId, Function.identity()))).orElse(null);
|
|
|
|
|
|
List<CarDangerDetectRecord> carDangers = buildCarDangerData(listJa, carDangerDevMap, project);
|
|
|
|
|
|
if (CollUtil.isNotEmpty(carDangers)) {
|
|
|
|
|
|
carDangerDetectRecordService.saveBatch(carDangers);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
|
log.error("定时到海康拉取车辆超速错误:", e);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private List<CarDangerDetectRecord> buildCarDangerData(JSONArray listJa, Map<String, CarDangerDetect> carDangerDevMap, Project project) throws Exception {
|
|
|
|
|
|
List<CarDangerDetectRecord> datas = new ArrayList<>();
|
|
|
|
|
|
if (CollUtil.isNotEmpty(listJa)) {
|
|
|
|
|
|
for (int i = 0; i < listJa.size(); i++) {
|
|
|
|
|
|
JSONObject jo = listJa.getJSONObject(i);
|
|
|
|
|
|
Integer illegalType = jo.getInteger("illegalType");
|
|
|
|
|
|
if (!Objects.equals(illegalType, 1) && !Objects.equals(illegalType, 7)) {
|
|
|
|
|
|
continue;
|
|
|
|
|
|
}
|
|
|
|
|
|
String monitoringId = jo.getString("monitoringId");
|
|
|
|
|
|
CarDangerDetect dev = carDangerDevMap.get(monitoringId);
|
|
|
|
|
|
if (dev == null) {
|
|
|
|
|
|
continue;
|
|
|
|
|
|
}
|
|
|
|
|
|
String plateNo = jo.getString("plateNo");
|
|
|
|
|
|
BigDecimal speed = jo.getBigDecimal("speed");
|
|
|
|
|
|
Date time = DateUtil.parse(jo.getString("crossTime"));
|
|
|
|
|
|
CarDangerDetectRecord data = new CarDangerDetectRecord();
|
|
|
|
|
|
data.setProjectSn(dev.getProjectSn());
|
|
|
|
|
|
data.setHardwareName(dev.getHardwareName());
|
|
|
|
|
|
data.setHardwareId(dev.getHardwareId());
|
|
|
|
|
|
String platePicUrl = jo.getString("carPicUri");
|
|
|
|
|
|
String svrIndex = jo.getString("aswSyscode");
|
|
|
|
|
|
if (StringUtils.isNotBlank(platePicUrl)) {
|
|
|
|
|
|
data.setImageUrl(hikvisionCall.saveToLocal(HikvisionCall.getHikvisionEventsPicture(new HikvisionEventsPictureRq(svrIndex, platePicUrl), project.getArtemisConfigHost(), project.getArtemisConfigAppKey(), project.getArtemisConfigAppSecret())));
|
|
|
|
|
|
}
|
|
|
|
|
|
data.setAlarmDesc(dev.getHardwareName());
|
|
|
|
|
|
data.setAlarmType(1);
|
|
|
|
|
|
data.setLocation(dev.getHardwareName());
|
|
|
|
|
|
data.setCreateTime(DateUtil.formatDateTime(time));
|
|
|
|
|
|
data.setIsPushed(false);
|
|
|
|
|
|
data.setCarNumber(plateNo);
|
|
|
|
|
|
data.setCurrentSpeed(speed);
|
|
|
|
|
|
datas.add(data);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
return datas;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private List<CarMeasureSpeedData> buildSpeedData(JSONArray listJa, Map<String, CarMeasureSpeedDev> devMap, Project project) throws Exception {
|
|
|
|
|
|
List<CarMeasureSpeedData> datas = new ArrayList<>();
|
|
|
|
|
|
if (CollUtil.isNotEmpty(listJa)) {
|
|
|
|
|
|
for (int i = 0; i < listJa.size(); i++) {
|
|
|
|
|
|
JSONObject jo = listJa.getJSONObject(i);
|
|
|
|
|
|
Integer illegalType = jo.getInteger("illegalType");
|
|
|
|
|
|
if (!Objects.equals(illegalType, 1) && !Objects.equals(illegalType, 7)) {
|
|
|
|
|
|
continue;
|
|
|
|
|
|
}
|
|
|
|
|
|
String monitoringId = jo.getString("monitoringId");
|
|
|
|
|
|
CarMeasureSpeedDev dev = devMap.get(monitoringId);
|
|
|
|
|
|
if (dev == null) {
|
|
|
|
|
|
continue;
|
|
|
|
|
|
}
|
|
|
|
|
|
String plateNo = jo.getString("plateNo");
|
|
|
|
|
|
BigDecimal speed = jo.getBigDecimal("speed");
|
|
|
|
|
|
Date time = DateUtil.parse(jo.getString("crossTime"));
|
|
|
|
|
|
CarMeasureSpeedData data = new CarMeasureSpeedData();
|
|
|
|
|
|
data.setDevSn(monitoringId);
|
|
|
|
|
|
data.setCarNumber(plateNo);
|
|
|
|
|
|
data.setIsExceed(NumberUtil.isGreater(speed, dev.getThreshold()) ? 1 : 0);
|
|
|
|
|
|
data.setCurrentSpeed(speed);
|
|
|
|
|
|
data.setExceedingThreshold(Objects.equals(data.getIsExceed(), 1) ? NumberUtil.sub(speed, dev.getThreshold()) : new BigDecimal("0"));
|
|
|
|
|
|
String platePicUrl = jo.getString("carPicUri");
|
|
|
|
|
|
String svrIndex = jo.getString("aswSyscode");
|
|
|
|
|
|
if (StringUtils.isNotBlank(platePicUrl)) {
|
|
|
|
|
|
data.setSnapshotImage(hikvisionCall.saveToLocal(HikvisionCall.getHikvisionEventsPicture(new HikvisionEventsPictureRq(svrIndex, platePicUrl), project.getArtemisConfigHost(), project.getArtemisConfigAppKey(), project.getArtemisConfigAppSecret())));
|
|
|
|
|
|
}
|
|
|
|
|
|
data.setUploadTime(time);
|
|
|
|
|
|
data.setProjectSn(dev.getProjectSn());
|
|
|
|
|
|
datas.add(data);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
return datas;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private JSONArray getSpeedDataList(String start, Project project) {
|
|
|
|
|
|
try {
|
|
|
|
|
|
JSONObject param = new JSONObject();
|
|
|
|
|
|
HikvisionUtil.addPageParamIfAbsent(param);
|
|
|
|
|
|
param.put("beginTime", start);
|
|
|
|
|
|
param.put("endTime", DateUtil.format(new Date(), "yyyy-MM-dd'T'HH:mm:ss.SSSXXX"));
|
|
|
|
|
|
JSONObject rsJo = HikvisionUtil.getSpeedDataList(project, param);
|
|
|
|
|
|
if (HikvisionUtil.isSuccess(rsJo)) {
|
|
|
|
|
|
JSONObject dataJo = HikvisionUtil.getJsonObjectData(rsJo);
|
|
|
|
|
|
return dataJo.getJSONArray("list");
|
2025-02-21 19:18:53 +08:00
|
|
|
|
}
|
2025-11-26 18:37:16 +08:00
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
|
log.error("定时http到海康拉取车辆超速错误:{}", e.getMessage());
|
|
|
|
|
|
log.error("", e);
|
2025-02-21 19:18:53 +08:00
|
|
|
|
}
|
2025-11-26 18:37:16 +08:00
|
|
|
|
return null;
|
2025-02-21 19:18:53 +08:00
|
|
|
|
}
|
2024-05-27 18:25:07 +08:00
|
|
|
|
}
|