Commit e720ee8c by 毛树良

<fix>:增加过车数据同步

1 parent 602e808b
...@@ -11,6 +11,10 @@ public class RedisConstants { ...@@ -11,6 +11,10 @@ public class RedisConstants {
*/ */
public static final String FANXING_TO_GB1400_LASTTIME = "fanxing:to:gb1400:lasttime"; public static final String FANXING_TO_GB1400_LASTTIME = "fanxing:to:gb1400:lasttime";
/** /**
* 上次同步过车数据到的时间点
*/
public static final String FANXING_TO_GB1400_VEHICLE_LASTTIME = "fanxing:to:gb1400:gc:lasttime";
/**
* 设备数据上次同步到的时间点 * 设备数据上次同步到的时间点
*/ */
public static final String FANXING_TO_GB1400_DEVICE_LASTTIME = "fanxing:to:gb1400:device:lasttime"; public static final String FANXING_TO_GB1400_DEVICE_LASTTIME = "fanxing:to:gb1400:device:lasttime";
......
...@@ -98,6 +98,57 @@ public class TrafficDataConvertHandler { ...@@ -98,6 +98,57 @@ public class TrafficDataConvertHandler {
return result; return result;
} }
public SubscribeNotificationsObj trafficVehicleToSubscribeNotifications(List<TrafficMongoModel> trafficMongoModels) {
if (CollectionUtils.isEmpty(trafficMongoModels)) {
log.warn("trafficMongoModels isEmpty");
return null;
}
SubscribeNotificationsObj result = new SubscribeNotificationsObj();
SubscribeNotificationsObj.SubscribeNotificationListObject resultListObject = new SubscribeNotificationsObj.SubscribeNotificationListObject();
List<SubscribeNotificationsObj.SubscribeNotificationObject> subNotifList = new ArrayList<>();
SubscribeNotificationsObj.SubscribeNotificationObject subNotifObj = new SubscribeNotificationsObj.SubscribeNotificationObject();
JSONObject subscribeInfo = getSubscribeInfo("13");
if (StringUtils.isBlank(subscribeInfo.getString("SubscribeID"))) {
log.warn("未查询到过车订阅信息!");
return null;
}
subNotifObj.setNotificationID(gb1400GenerateIDUtil.generateNotificationID());
subNotifObj.setSubscribeID(subscribeInfo.getString("SubscribeID"));
subNotifObj.setTitle(subscribeInfo.getString("Title"));
subNotifObj.setTriggerTime(DateUtil.format(new Date(), DateUtil.DATE_TIME_FORMAT_NO_DELIMITER));
MotorVehicleObj vehicleObj = new MotorVehicleObj();
List<MotorVehicleObj.MotorVehicleObject> vehicleList = new ArrayList<>();
StringBuilder infoIds = new StringBuilder();
//设置过车数据
for (TrafficMongoModel trafficMongoModel : trafficMongoModels) {
MotorVehicleObj.MotorVehicleObject vehicle = tranferVehicleToMotorVehicleObject(trafficMongoModel);
if (vehicle == null) {
continue;
}
vehicleList.add(vehicle);
if ("".equals(infoIds.toString())) {
infoIds.append(vehicle.getMotorVehicleID());
} else {
infoIds.append("," + vehicle.getMotorVehicleID());
}
}
if (CollectionUtils.isEmpty(vehicleList)) {
return null;
}
vehicleObj.setMotorVehicleObject(vehicleList);
subNotifObj.setInfoIDs(infoIds.toString());
subNotifObj.setMotorVehicleObjectList(vehicleObj);
subNotifList.add(subNotifObj);
resultListObject.setSubscribeNotificationObjects(subNotifList);
result.setSubscribeNotificationListObject(resultListObject);
return result;
}
public SubscribeNotificationsObj deviceToSubscribeNotifications(List<DeviceModel> deviceModels) { public SubscribeNotificationsObj deviceToSubscribeNotifications(List<DeviceModel> deviceModels) {
if (CollectionUtils.isEmpty(deviceModels)) { if (CollectionUtils.isEmpty(deviceModels)) {
log.warn("deviceModels isEmpty"); log.warn("deviceModels isEmpty");
...@@ -354,6 +405,116 @@ public class TrafficDataConvertHandler { ...@@ -354,6 +405,116 @@ public class TrafficDataConvertHandler {
} }
/** /**
* 过车转成MotorVehicleObject对象
* @param trafficMongoModel
* @return
*/
private MotorVehicleObj.MotorVehicleObject tranferVehicleToMotorVehicleObject(TrafficMongoModel trafficMongoModel) {
String passTime = "";
String picUrl = "";
String deviceID = "";
Map eventData = trafficMongoModel.getEvent_data();
List pics = trafficMongoModel.getPics();
if (eventData == null || eventData.get("device") == null || CollectionUtils.isEmpty(pics)) {
log.warn("缺少必填数据!");
return null;
}
try {
String eventDateStr = trafficMongoModel.getEvent_dt();
Date eventDateUtc = DateUtil.parse(eventDateStr, DateUtil.TIMESTAMP_FORMAT);
passTime = DateUtil.format(DateUtil.addHours(eventDateUtc, 8), DateUtil.DATE_TIME_FORMAT_NO_DELIMITER);
//图片
Map picMap = (Map) pics.get(0);
String pic_unid = (String) picMap.get("pic_unid");
picUrl = getPicUrlByPicUnid(pic_unid);
// Map object_rect = (Map) picMap.get("object_rect");
//设备信息
Map deviceMap = (Map) eventData.get("device");
deviceID = (String) deviceMap.get("code");
} catch (Exception e) {
log.error("获取必须字段异常Exception", e);
}
if (StringUtils.isBlank(picUrl) || StringUtils.isBlank(deviceID) || StringUtils.isBlank(passTime)) {
log.warn("获取必填数据失败!");
return null;
}
Integer laneNo = 1;
String hasPlate = "1";
String plateNo = "-";
String plateClass = "99";
String plateColor = "99";
String csys = "";
String cllx = "";
String clpp = "";
try {
//车道
Map laneMap = (Map) eventData.get("lane");
if (laneMap != null) {
laneNo = (Integer) laneMap.get("number");
}
//车牌
Map vehicleMap = (Map) eventData.get("vehicle");
if (vehicleMap != null) {
Map plateMap = (Map) vehicleMap.get("plate");
if (plateMap != null) {
String text = (String) plateMap.get("text");
if (StringUtils.isBlank(text) || "无牌".equals(text)) {
hasPlate = "0";
} else {
plateNo = text;
}
plateColor = hpysProperties.getProperty((String) plateMap.getOrDefault("color_code", "9"), "99");
plateClass = hpzlProperties.getProperty((String) plateMap.getOrDefault("type_code", "99"), "99");
}
//车辆信息
Map bodyMap = (Map) vehicleMap.get("body");
if (bodyMap != null) {
csys = getCsysByVehicleBody(bodyMap, "Z");
cllx = getCllxByVehicleBody(bodyMap, "");
clpp = getClppByVehicleBody(bodyMap, "");
}
}
} catch (Exception e) {
log.error("获取车辆信息异常", e);
}
MotorVehicleObj.MotorVehicleObject vehicle = new MotorVehicleObj.MotorVehicleObject();
//基本信息
vehicle.setInfoKind(1);
vehicle.setDeviceID(deviceID);
vehicle.setPassTime(passTime);
vehicle.setSourceID(gb1400GenerateIDUtil.generateSourceID(vehicle.getDeviceID(), "02", vehicle.getPassTime()));
vehicle.setMotorVehicleID(gb1400GenerateIDUtil.generateMotorVehicleID(vehicle.getSourceID(), "02"));
String tollgateID = "";
if (DataCacheScheduled.deviceTollgateMap.containsKey(deviceID)) {
tollgateID = DataCacheScheduled.deviceTollgateMap.get(deviceID);
}
if (StringUtils.isNotBlank(tollgateID)) {
vehicle.setTollgateID(tollgateID);
}
vehicle.setStorageUrl1(picUrl);
vehicle.setLeftTopX(0);
vehicle.setLeftTopY(0);
vehicle.setRightBtmX(0);
vehicle.setRightBtmY(0);
vehicle.setLaneNo(laneNo);
vehicle.setHasPlate(hasPlate);
vehicle.setPlateClass(plateClass);
vehicle.setPlateColor(plateColor);
vehicle.setPlateNo(plateNo);
// vehicle.setDirection("");
vehicle.setVehicleClass(cllx);
vehicle.setVehicleBrand(clpp);
// vehicle.setVehicleStyles("");
vehicle.setVehicleColor(csys);
return vehicle;
}
/**
* 获取图片url * 获取图片url
* @param pic_unid * @param pic_unid
* @return * @return
...@@ -402,7 +563,7 @@ public class TrafficDataConvertHandler { ...@@ -402,7 +563,7 @@ public class TrafficDataConvertHandler {
/** /**
* 获取指定的订阅信息 * 获取指定的订阅信息
* 订阅类别 : 3:设备,7:卡口,9:车道,50:违法数据 * 订阅类别 : 3:设备,7:卡口,9:车道,50:违法数据,13:自动采集的车辆信息
* @return * @return
*/ */
private JSONObject getSubscribeInfo(String target) { private JSONObject getSubscribeInfo(String target) {
......
package com.viontech.scheduled;
import com.viontech.constant.Gb1400Constants;
import com.viontech.constant.RedisConstants;
import com.viontech.constant.SystemConstants;
import com.viontech.handler.TrafficDataConvertHandler;
import com.viontech.service.Gb1400Service;
import com.viontech.service.TrafficEventService;
import com.viontech.utils.DateUtil;
import com.viontech.utils.JavaBean2Json;
import com.viontech.utils.JsonMessage;
import com.viontech.vo.gb1400.SubscribeNotificationsObj;
import com.viontech.vo.traffic.TrafficModel;
import com.viontech.vo.traffic.TrafficMongoModel;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
@Slf4j
@Component
public class TrafficVehicleScheduled {
@Resource
private TrafficEventService trafficEventService;
@Resource
private Gb1400Service gb1400Service;
@Autowired
private RedisTemplate redisTemplate;
@Autowired
private TrafficDataConvertHandler trafficDataConvertHandler;
// @Scheduled(cron = "0/5 * * * * ?")
public void handleVehicle() {
log.info("开始处理过车数据");
if (!Gb1400Constants.LinkStatus) {
return;
}
Object o = redisTemplate.opsForValue().get(RedisConstants.FANXING_TO_GB1400_VEHICLE_LASTTIME);
//上次对接到的过车记录时间
String lastTimeUtc = "";
if (o == null) {
//查询一小时前的数据,-1,-8:转UTC时间,总-9
lastTimeUtc = DateUtil.formatDate(DateUtil.addHours(new Date(), -9), DateUtil.TIMESTAMP_FORMAT);
} else {
lastTimeUtc = (String) o;
}
String currentTimeUtc = DateUtil.formatDate(DateUtil.addHours(new Date(), -8), DateUtil.TIMESTAMP_FORMAT);
if (StringUtils.isBlank(lastTimeUtc) || StringUtils.isBlank(currentTimeUtc)) {
log.warn("lastTimeUtc or currentTimeUtc isBlank");
return;
}
int offset = 0;
int limit = 20;
//utc时间,当前时间减8小时
String event_dt__gte = lastTimeUtc;
String event_dt__lt = currentTimeUtc;
TrafficModel trafficQry = new TrafficModel();
trafficQry.setEvent_cate("traffic");
trafficQry.setEvent_type("vehicle");
trafficQry.setIllegal_state("false");
trafficQry.setEvent_dt__gte(event_dt__gte);
trafficQry.setEvent_dt__lt(event_dt__lt);
trafficQry.setLimit(limit);
trafficQry.setOffset(offset);
List<Object> trafficModels = trafficEventService.selectJsonDatas(trafficQry);
log.info("查询范围(lastTimeUtc,currentTimeUtc]=({},{}],本批次待同步过车数据总{}条。", lastTimeUtc, currentTimeUtc, trafficModels.size());
if (!CollectionUtils.isEmpty(trafficModels)) {
List<TrafficMongoModel> trafficMongoModels = new ArrayList<>();
for (Object model : trafficModels) {
trafficMongoModels.add(JavaBean2Json.Json2JavaBean(JavaBean2Json.javaBean2Json(model), TrafficMongoModel.class));
}
//List<TrafficMongoModel> 转 SubscribeNotificationsObj
SubscribeNotificationsObj subscribeNotificationsObj = trafficDataConvertHandler.trafficVehicleToSubscribeNotifications(trafficMongoModels);
//将违法数据同步gb1400
if (subscribeNotificationsObj != null) {
JsonMessage resultVo = gb1400Service.subscribeNotifications(subscribeNotificationsObj);
if (SystemConstants.APP_CODE_SUCCESS == resultVo.getCode()) {
redisTemplate.opsForValue().set(RedisConstants.FANXING_TO_GB1400_VEHICLE_LASTTIME, trafficMongoModels.get(trafficMongoModels.size() - 1).getEvent_dt());
}
} else {
log.error("trafficDataConvertHandler.trafficVehicleToSubscribeNotifications is null");
}
}
log.info("结束处理过车数据");
}
}
...@@ -13,6 +13,7 @@ public class MotorVehicleObj { ...@@ -13,6 +13,7 @@ public class MotorVehicleObj {
public static class MotorVehicleObject { public static class MotorVehicleObject {
@JSONField(name = "MotorVehicleID") @JSONField(name = "MotorVehicleID")
private String MotorVehicleID; private String MotorVehicleID;
//0:其他,1:自动采集,2:人工采集
@JSONField(name = "InfoKind") @JSONField(name = "InfoKind")
private Integer InfoKind; private Integer InfoKind;
@JSONField(name = "SourceID") @JSONField(name = "SourceID")
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!