Commit 91cb74e7 by 毛树良

<fix>:优化推送数据,增加设备卡口关系缓存

1 parent e19283fe
......@@ -2,6 +2,7 @@ package com.viontech.handler;
import com.alibaba.fastjson.JSONObject;
import com.viontech.constant.RedisConstants;
import com.viontech.scheduled.DataCacheScheduled;
import com.viontech.utils.DateUtil;
import com.viontech.utils.Gb1400GenerateIDUtil;
import com.viontech.vo.gb1400.*;
......@@ -309,7 +310,7 @@ public class TrafficDataConvertHandler {
//车辆信息
Map bodyMap = (Map) vehicleMap.get("body");
if (bodyMap != null) {
csys = getCsysByVehicleBody(bodyMap, "");
csys = getCsysByVehicleBody(bodyMap, "Z");
cllx = getCllxByVehicleBody(bodyMap, "");
clpp = getClppByVehicleBody(bodyMap, "");
}
......@@ -325,6 +326,11 @@ public class TrafficDataConvertHandler {
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);
}
vehicle.setTollgateID(tollgateID);
vehicle.setBreakRuleMode(wflxProperties.getProperty(illCode, illCode));
vehicle.setStorageUrl1(picUrl);
......
package com.viontech.scheduled;
import com.viontech.service.TrafficEventService;
import com.viontech.vo.traffic.LaneModel;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.boot.CommandLineRunner;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
@Slf4j
@Component
public class DataCacheScheduled implements CommandLineRunner {
//key:apeid,value:TollgateId
public static Map<String, String> deviceTollgateMap = new ConcurrentHashMap<>();
@Resource
private TrafficEventService trafficEventService;
@Scheduled(cron = "0 0 2 * * ?")
public void flushCache() {
updateDeviceTollgateCache();
}
@Override
public void run(String... args) throws Exception {
updateDeviceTollgateCache();
}
private void updateDeviceTollgateCache() {
log.info("开始更新设备与卡口关系缓存数据");
//查询
int offset = 0;
int limit = 50;
int selectSize = 0;
int num = 0;
do {
LaneModel laneQry = new LaneModel();
laneQry.setOffset(offset);
laneQry.setLimit(limit);
List<LaneModel> laneModels = trafficEventService.selectLaneDatas(laneQry);
selectSize = laneModels.size();
num = num + 1;
offset = limit*num;
if (!CollectionUtils.isEmpty(laneModels)) {
for (LaneModel laneModel : laneModels) {
try {
deviceTollgateMap.put(laneModel.getApeID(), laneModel.getTollgateID());
} catch (Exception e) {
log.error("deviceTollgateMap.put Exception", e);
}
}
}
} while (selectSize >= limit);
log.info("结束更新设备与卡口关系缓存,共更新{}条", deviceTollgateMap.size());
}
}
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!