Commit d0041183 by 毛树良

增加车道信息

1 parent f217772f
...@@ -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_LANE_LASTTIME = "fanxing:to:gb1400:lane:lasttime";
/**
* 国标1400注册auth * 国标1400注册auth
*/ */
public static final String GB1400_REGISTER_AUTH = "fanxing:to:gb1400:register:auth"; public static final String GB1400_REGISTER_AUTH = "fanxing:to:gb1400:register:auth";
......
...@@ -4,8 +4,7 @@ import com.alibaba.fastjson.JSONObject; ...@@ -4,8 +4,7 @@ import com.alibaba.fastjson.JSONObject;
import com.viontech.constant.RedisConstants; import com.viontech.constant.RedisConstants;
import com.viontech.utils.DateUtil; import com.viontech.utils.DateUtil;
import com.viontech.utils.Gb1400GenerateIDUtil; import com.viontech.utils.Gb1400GenerateIDUtil;
import com.viontech.vo.gb1400.MotorVehicleObj; import com.viontech.vo.gb1400.*;
import com.viontech.vo.gb1400.SubscribeNotificationsObj;
import com.viontech.vo.traffic.TrafficMongoModel; import com.viontech.vo.traffic.TrafficMongoModel;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
...@@ -88,6 +87,143 @@ public class TrafficDataConvertHandler { ...@@ -88,6 +87,143 @@ public class TrafficDataConvertHandler {
return result; return result;
} }
public SubscribeNotificationsObj deviceToSubscribeNotifications(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("3");
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));
APEList apeListObj = new APEList();
List<APEList.APE> apeList = new ArrayList<>();
StringBuilder infoIds = new StringBuilder();
//设置设备数据
for (TrafficMongoModel trafficMongoModel : trafficMongoModels) {
APEList.APE ape = null;
apeList.add(ape);
if ("".equals(infoIds.toString())) {
infoIds.append(ape.getApeID());
} else {
infoIds.append("," + ape.getApeID());
}
}
apeListObj.setAPEObject(apeList);
subNotifObj.setInfoIDs(infoIds.toString());
subNotifObj.setDeviceList(apeListObj);
subNotifList.add(subNotifObj);
resultListObject.setSubscribeNotificationObjects(subNotifList);
result.setSubscribeNotificationListObject(resultListObject);
return result;
}
public SubscribeNotificationsObj tollgateToSubscribeNotifications(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("7");
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));
TollgateList tollgateListObj = new TollgateList();
List<TollgateList.Tollgate> tollgateList = new ArrayList<>();
StringBuilder infoIds = new StringBuilder();
//设置卡口数据
for (TrafficMongoModel trafficMongoModel : trafficMongoModels) {
TollgateList.Tollgate tollgate = null;
tollgateList.add(tollgate);
if ("".equals(infoIds.toString())) {
infoIds.append(tollgate.getTollgateID());
} else {
infoIds.append("," + tollgate.getTollgateID());
}
}
tollgateListObj.setTollgateObject(tollgateList);
subNotifObj.setInfoIDs(infoIds.toString());
subNotifObj.setTollgateObjectList(tollgateListObj);
subNotifList.add(subNotifObj);
resultListObject.setSubscribeNotificationObjects(subNotifList);
result.setSubscribeNotificationListObject(resultListObject);
return result;
}
public SubscribeNotificationsObj laneToSubscribeNotifications(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("9");
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));
LaneList laneListObj = new LaneList();
List<LaneList.Lane> laneList = new ArrayList<>();
StringBuilder infoIds = new StringBuilder();
//设置车道数据
for (TrafficMongoModel trafficMongoModel : trafficMongoModels) {
LaneList.Lane lane = null;
laneList.add(lane);
StringBuilder laneSb = new StringBuilder();
laneSb.append(lane.getTollgateID()).append("_").append(lane.getLaneId());
if ("".equals(infoIds.toString())) {
infoIds.append(laneSb.toString());
} else {
infoIds.append("," + laneSb.toString());
}
}
laneListObj.setLaneObject(laneList);
subNotifObj.setInfoIDs(infoIds.toString());
subNotifObj.setLaneObjectList(laneListObj);
subNotifList.add(subNotifObj);
resultListObject.setSubscribeNotificationObjects(subNotifList);
result.setSubscribeNotificationListObject(resultListObject);
return result;
}
/** /**
* 转成MotorVehicleObject对象 * 转成MotorVehicleObject对象
* @param trafficMongoModel * @param trafficMongoModel
...@@ -243,6 +379,31 @@ public class TrafficDataConvertHandler { ...@@ -243,6 +379,31 @@ public class TrafficDataConvertHandler {
return new JSONObject(); return new JSONObject();
} }
/**
* 获取指定的订阅信息
* 订阅类别 : 3:设备,7:卡口,9:车道,50:违法数据
* @return
*/
private JSONObject getSubscribeInfo(String target) {
List<Object> values = redisTemplate.opsForHash().values(RedisConstants.GB1400_SUBSCRIBES_HASH);
if (!CollectionUtils.isEmpty(values)) {
for (Object value : values) {
String data = (String) value;
JSONObject dataObj = JSONObject.parseObject(data);
String subscribeDetail = dataObj.getString("SubscribeDetail");
if (StringUtils.isBlank(subscribeDetail)) {
continue;
}
String[] subArr = subscribeDetail.split(",");
List<String> subList = Arrays.asList(subArr);
if (subList.contains(target)) {
return dataObj;
}
}
}
return new JSONObject();
}
private String getCsysByVehicleBody(Map bodyMap, String defaultValue) { private String getCsysByVehicleBody(Map bodyMap, String defaultValue) {
try { try {
Map colorMap = (Map) bodyMap.get("color"); Map colorMap = (Map) bodyMap.get("color");
......
package com.viontech.mapper; package com.viontech.mapper;
import com.viontech.vo.traffic.LaneModel;
import com.viontech.vo.traffic.TrafficModel; import com.viontech.vo.traffic.TrafficModel;
import java.util.List; import java.util.List;
public interface TrafficEventMapper { public interface TrafficEventMapper {
List<Object> selectJsonDatas(TrafficModel trafficModel); List<Object> selectJsonDatas(TrafficModel trafficModel);
List<LaneModel> selectLaneDatas(LaneModel laneModel);
} }
<?xml version="1.0" encoding="UTF-8" ?> <?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" > <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="com.viontech.mapper.TrafficEventMapper"> <mapper namespace="com.viontech.mapper.TrafficEventMapper">
<resultMap id="LaneResultMap" type="com.viontech.vo.traffic.LaneModel">
<result column="tollgate_id" jdbcType="VARCHAR" property="tollgateID"/>
<result column="lane_id" jdbcType="INTEGER" property="laneId"/>
<result column="lane_no" jdbcType="INTEGER" property="laneNo"/>
<result column="name" jdbcType="VARCHAR" property="name"/>
<result column="direction" jdbcType="VARCHAR" property="direction"/>
<result column="ape_id" jdbcType="VARCHAR" property="apeID"/>
<result column="create_time" jdbcType="TIMESTAMP" property="createTime"/>
<result column="modify_time" jdbcType="TIMESTAMP" property="modifyTime"/>
</resultMap>
<!-- fetchSize="5000" --> <!-- fetchSize="5000" -->
<select id="selectJsonDatas" parameterType="com.viontech.vo.traffic.TrafficModel" <select id="selectJsonDatas" parameterType="com.viontech.vo.traffic.TrafficModel"
resultType="java.lang.String" fetchSize="5000"> resultType="java.lang.String" fetchSize="5000">
...@@ -162,4 +172,24 @@ ...@@ -162,4 +172,24 @@
LIMIT #{limit} OFFSET #{offset} LIMIT #{limit} OFFSET #{offset}
</if> </if>
</select> </select>
<select id="selectLaneDatas" parameterType="com.viontech.vo.traffic.LaneModel"
resultMap="LaneResultMap" fetchSize="5000">
select tollgate_id,lane_id,lane_no,`name`,direction,ape_id,create_time,modify_time
from tb_lane
<where>
<if test="modifyTime_gte != null and modifyTime_gte != ''">
and modify_time > #{modifyTime_gte,typeHandler=com.viontech.handler.MilliDateTypeHandler}
<!-- and shoot_dtime >= #{modifyTime_gte}-->
</if>
<if test="modifyTime_lte != null and modifyTime_lte != ''">
and modify_time <![CDATA[<=]]> #{modifyTime_lte,typeHandler=com.viontech.handler.MilliDateTypeHandler}
<!-- and shoot_dtime <![CDATA[<]]> #{modifyTime_lte}-->
</if>
</where>
order by modify_time asc
<if test="limit != null and offset != null">
LIMIT #{limit} OFFSET #{offset}
</if>
</select>
</mapper> </mapper>
\ No newline at end of file \ No newline at end of file
package com.viontech.scheduled;
import com.viontech.constant.Gb1400Constants;
import com.viontech.constant.RedisConstants;
import com.viontech.handler.TrafficDataConvertHandler;
import com.viontech.service.Gb1400Service;
import com.viontech.service.TrafficEventService;
import com.viontech.utils.DateUtil;
import com.viontech.vo.traffic.LaneModel;
import lombok.extern.slf4j.Slf4j;
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 javax.annotation.Resource;
import java.util.Date;
import java.util.List;
/**
* @author msl
* @date 2022/5/7
*/
@Slf4j
@Component
public class LaneSyncScheduled {
@Resource
private TrafficEventService trafficEventService;
@Resource
private Gb1400Service gb1400Service;
@Autowired
private RedisTemplate redisTemplate;
@Autowired
private TrafficDataConvertHandler trafficDataConvertHandler;
@Scheduled(cron = "0 */2 * * * ?")
public void handleIllegal() {
log.info("开始处理车道数据");
if (!Gb1400Constants.LinkStatus) {
return;
}
Object o = redisTemplate.opsForValue().get(RedisConstants.FANXING_TO_GB1400_LANE_LASTTIME);
//上次对接到的车道记录时间
String lastTimeUtc = "";
if (o == null) {
//初次查询12小时前的数据
lastTimeUtc = DateUtil.formatDate(DateUtil.addHours(new Date(), -12), DateUtil.TIMESTAMP_FORMAT);
} else {
lastTimeUtc = (String) o;
}
//查询
LaneModel laneQry = new LaneModel();
laneQry.setOffset(0);
laneQry.setLimit(10);
List<LaneModel> laneModels = trafficEventService.selectLaneDatas(laneQry);
log.info("结束处理车道数据");
}
}
package com.viontech.service; package com.viontech.service;
import com.viontech.vo.traffic.LaneModel;
import com.viontech.vo.traffic.TrafficModel; import com.viontech.vo.traffic.TrafficModel;
import java.util.List; import java.util.List;
public interface TrafficEventService { public interface TrafficEventService {
List<Object> selectJsonDatas(TrafficModel trafficModel); List<Object> selectJsonDatas(TrafficModel trafficModel);
List<LaneModel> selectLaneDatas(LaneModel laneModel);
} }
...@@ -2,6 +2,7 @@ package com.viontech.service.impl; ...@@ -2,6 +2,7 @@ package com.viontech.service.impl;
import com.viontech.mapper.TrafficEventMapper; import com.viontech.mapper.TrafficEventMapper;
import com.viontech.service.TrafficEventService; import com.viontech.service.TrafficEventService;
import com.viontech.vo.traffic.LaneModel;
import com.viontech.vo.traffic.TrafficModel; import com.viontech.vo.traffic.TrafficModel;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
...@@ -18,4 +19,9 @@ public class TrafficEventServiceImpl implements TrafficEventService { ...@@ -18,4 +19,9 @@ public class TrafficEventServiceImpl implements TrafficEventService {
public List<Object> selectJsonDatas(TrafficModel trafficModel) { public List<Object> selectJsonDatas(TrafficModel trafficModel) {
return trafficEventMapper.selectJsonDatas(trafficModel); return trafficEventMapper.selectJsonDatas(trafficModel);
} }
@Override
public List<LaneModel> selectLaneDatas(LaneModel laneModel) {
return trafficEventMapper.selectLaneDatas(laneModel);
}
} }
package com.viontech.vo.gb1400;
import com.alibaba.fastjson.annotation.JSONField;
import lombok.Data;
import java.util.List;
/**
* @author msl
* @date 2022/5/7
*/
@Data
public class APEList {
@JSONField(name = "APEObject")
private List<APE> APEObject;
@Data
public static class APE {
@JSONField(name = "ApeID")
private String ApeID;
@JSONField(name = "Name")
private String Name;
@JSONField(name = "Model")
private String Model;
@JSONField(name = "IPAddr")
private String IPAddr;
@JSONField(name = "Port")
private Integer Port;
@JSONField(name = "Longtitude")
private Double Longtitude;
@JSONField(name = "Latitude")
private Double Latitude;
@JSONField(name = "PlaceCode")
private String PlaceCode;
@JSONField(name = "IsOnline")
private String IsOnline;
}
}
package com.viontech.vo.gb1400;
import com.alibaba.fastjson.annotation.JSONField;
import lombok.Data;
import java.util.List;
/**
* @author msl
* @date 2022/5/7
*/
@Data
public class LaneList {
@JSONField(name = "LaneObject")
private List<Lane> LaneObject;
@Data
public static class Lane {
@JSONField(name = "TollgateID")
private String TollgateID;
@JSONField(name = "LaneId")
private Integer LaneId;
@JSONField(name = "LaneNo")
private Integer LaneNo;
@JSONField(name = "Name")
private String Name;
@JSONField(name = "Direction")
private String Direction;
@JSONField(name = "ApeID")
private String ApeID;
}
}
...@@ -30,5 +30,11 @@ public class SubscribeNotificationsObj { ...@@ -30,5 +30,11 @@ public class SubscribeNotificationsObj {
private String InfoIDs; private String InfoIDs;
@JSONField(name = "MotorVehicleObjectList") @JSONField(name = "MotorVehicleObjectList")
private MotorVehicleObj MotorVehicleObjectList; private MotorVehicleObj MotorVehicleObjectList;
@JSONField(name = "DeviceList")
private APEList DeviceList;
@JSONField(name = "TollgateObjectList")
private TollgateList TollgateObjectList;
@JSONField(name = "LaneObjectList")
private LaneList LaneObjectList;
} }
} }
package com.viontech.vo.gb1400;
import com.alibaba.fastjson.annotation.JSONField;
import lombok.Data;
import java.util.List;
/**
* @author msl
* @date 2022/5/7
*/
@Data
public class TollgateList {
@JSONField(name = "TollgateObject")
private List<Tollgate> TollgateObject;
@Data
public static class Tollgate {
@JSONField(name = "TollgateID")
private String TollgateID;
@JSONField(name = "Name")
private String Name;
@JSONField(name = "Longtitude")
private Double Longtitude;
@JSONField(name = "Latitue")
private Double Latitue;
@JSONField(name = "PlaceCode")
private String PlaceCode;
@JSONField(name = "Status")
private String Status;
@JSONField(name = "TollgateCat")
private String TollgateCat;
@JSONField(name = "TollgateUsage")
private Integer TollgateUsage;
}
}
package com.viontech.vo.traffic;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.Data;
import java.util.Date;
/**
* @author msl
* @date 2022/5/7
*/
@Data
@JsonInclude(value = JsonInclude.Include.NON_NULL)
public class LaneModel {
private String tollgateID;
private Integer laneId;
private Integer laneNo;
private String name;
private String direction;
private String apeID;
/**
* 创建时间
*/
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss.SSS", timezone = "GMT+8")
private Date createTime;
/**
* 修改时间
*/
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss.SSS", timezone = "GMT+8")
private Date modifyTime;
//
private String modifyTime_gte;
private String modifyTime_lte;
private Integer offset;
private Integer limit;
}
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!