Commit 51ac3ca7 by 毛树良

<fix>:优化查询

1 parent b78d683d
package com.viontech.handler; package com.viontech.handler;
import java.sql.CallableStatement; import java.sql.*;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.text.ParseException; import java.text.ParseException;
import java.util.Date; import java.util.Date;
...@@ -21,14 +18,15 @@ public class MilliDateTypeHandler extends BaseTypeHandler<String> { ...@@ -21,14 +18,15 @@ public class MilliDateTypeHandler extends BaseTypeHandler<String> {
@Override @Override
public void setNonNullParameter(PreparedStatement arg0, int arg1, public void setNonNullParameter(PreparedStatement arg0, int arg1,
String arg2, JdbcType arg3) throws SQLException { String arg2, JdbcType arg3) throws SQLException {
Date time = new Date(); // Date time = new Date();
try { // try {
time = DateUtil.dateFormat(arg2); // time = DateUtil.dateFormat(arg2);
} catch (ParseException e) { // } catch (ParseException e) {
// TODO Auto-generated catch block // // TODO Auto-generated catch block
e.printStackTrace(); // e.printStackTrace();
} // }
java.sql.Timestamp sqlTimestamp = new java.sql.Timestamp(time.getTime()); // java.sql.Timestamp sqlTimestamp = new java.sql.Timestamp(time.getTime());
java.sql.Timestamp sqlTimestamp = Timestamp.valueOf(arg2);
arg0.setTimestamp(arg1, sqlTimestamp); arg0.setTimestamp(arg1, sqlTimestamp);
} }
......
...@@ -83,9 +83,11 @@ public class TrafficIllegalScheduled { ...@@ -83,9 +83,11 @@ public class TrafficIllegalScheduled {
trafficMongoModels.add(trafficModel); trafficMongoModels.add(trafficModel);
} else { } else {
log.info("ill.update.record:{}-{}", trafficModel.getId(), trafficModel.getEvent_dt()); log.info("ill.update.record:{}-{}", trafficModel.getId(), trafficModel.getEvent_dt());
if (CheckUtil.checkTime(trafficModel, lastTimeUtc)) {
redisTemplate.opsForValue().set(RedisConstants.FANXING_TO_GB1400_LASTTIME, trafficModel.getEvent_dt()); redisTemplate.opsForValue().set(RedisConstants.FANXING_TO_GB1400_LASTTIME, trafficModel.getEvent_dt());
} }
} }
}
//List<TrafficMongoModel> 转 SubscribeNotificationsObj //List<TrafficMongoModel> 转 SubscribeNotificationsObj
SubscribeNotificationsObj subscribeNotificationsObj = trafficDataConvertHandler.trafficIllegalToSubscribeNotifications(trafficMongoModels); SubscribeNotificationsObj subscribeNotificationsObj = trafficDataConvertHandler.trafficIllegalToSubscribeNotifications(trafficMongoModels);
//将违法数据同步gb1400 //将违法数据同步gb1400
...@@ -93,8 +95,16 @@ public class TrafficIllegalScheduled { ...@@ -93,8 +95,16 @@ public class TrafficIllegalScheduled {
JsonMessage resultVo = gb1400Service.subscribeNotifications(subscribeNotificationsObj); JsonMessage resultVo = gb1400Service.subscribeNotifications(subscribeNotificationsObj);
if (SystemConstants.APP_CODE_SUCCESS == resultVo.getCode()) { if (SystemConstants.APP_CODE_SUCCESS == resultVo.getCode()) {
TrafficMongoModel last = trafficMongoModels.get(trafficMongoModels.size() - 1); TrafficMongoModel last = trafficMongoModels.get(trafficMongoModels.size() - 1);
log.info("ill.update.record:{}-{}", last.getId(), last.getEvent_dt()); log.info("ill.update.record2:{}-{}", last.getId(), last.getEvent_dt());
if (CheckUtil.checkTime(last, lastTimeUtc)) {
redisTemplate.opsForValue().set(RedisConstants.FANXING_TO_GB1400_LASTTIME, last.getEvent_dt()); redisTemplate.opsForValue().set(RedisConstants.FANXING_TO_GB1400_LASTTIME, last.getEvent_dt());
} else {
log.info("ill.update.record-false:{}-{}", last.getId(), last.getEvent_dt());
Date lastRecord = DateUtil.parse(lastTimeUtc, DateUtil.TIMESTAMP_FORMAT);
Date lastRecord1 = DateUtil.addSeconds(lastRecord, 1);
String lastRecord1Str = DateUtil.format(lastRecord1, DateUtil.TIMESTAMP_FORMAT);
redisTemplate.opsForValue().set(RedisConstants.FANXING_TO_GB1400_LASTTIME, lastRecord1Str);
}
} }
} else { } else {
log.error("trafficDataConvertHandler.trafficIllegalToSubscribeNotifications is null"); log.error("trafficDataConvertHandler.trafficIllegalToSubscribeNotifications is null");
......
...@@ -72,7 +72,7 @@ public class TrafficVehicleScheduled { ...@@ -72,7 +72,7 @@ public class TrafficVehicleScheduled {
trafficQry.setEvent_dt__lt(event_dt__lt); trafficQry.setEvent_dt__lt(event_dt__lt);
trafficQry.setLimit(limit); trafficQry.setLimit(limit);
trafficQry.setOffset(offset); trafficQry.setOffset(offset);
log.info("过车查询范围(lastTimeUtc,currentTimeUtc]=({},{}]", lastTimeUtc, currentTimeUtc); log.info("过车查询范围(lastTimeUtc,currentTimeUtc]=({},{}]!", lastTimeUtc, currentTimeUtc);
List<Object> trafficModels = trafficEventService.selectJsonDatas(trafficQry); List<Object> trafficModels = trafficEventService.selectJsonDatas(trafficQry);
log.info("过车查询范围(lastTimeUtc,currentTimeUtc]=({},{}],本批次待同步过车数据总{}条。", lastTimeUtc, currentTimeUtc, trafficModels.size()); log.info("过车查询范围(lastTimeUtc,currentTimeUtc]=({},{}],本批次待同步过车数据总{}条。", lastTimeUtc, currentTimeUtc, trafficModels.size());
if (!CollectionUtils.isEmpty(trafficModels)) { if (!CollectionUtils.isEmpty(trafficModels)) {
...@@ -83,9 +83,11 @@ public class TrafficVehicleScheduled { ...@@ -83,9 +83,11 @@ public class TrafficVehicleScheduled {
trafficMongoModels.add(trafficModel); trafficMongoModels.add(trafficModel);
} else { } else {
log.info("gc.update.record:{}-{}", trafficModel.getId(), trafficModel.getEvent_dt()); log.info("gc.update.record:{}-{}", trafficModel.getId(), trafficModel.getEvent_dt());
if (CheckUtil.checkTime(trafficModel, lastTimeUtc)) {
redisTemplate.opsForValue().set(RedisConstants.FANXING_TO_GB1400_VEHICLE_LASTTIME, trafficModel.getEvent_dt()); redisTemplate.opsForValue().set(RedisConstants.FANXING_TO_GB1400_VEHICLE_LASTTIME, trafficModel.getEvent_dt());
} }
} }
}
//List<TrafficMongoModel> 转 SubscribeNotificationsObj //List<TrafficMongoModel> 转 SubscribeNotificationsObj
SubscribeNotificationsObj subscribeNotificationsObj = trafficDataConvertHandler.trafficVehicleToSubscribeNotifications(trafficMongoModels); SubscribeNotificationsObj subscribeNotificationsObj = trafficDataConvertHandler.trafficVehicleToSubscribeNotifications(trafficMongoModels);
//将违法数据同步gb1400 //将违法数据同步gb1400
...@@ -93,8 +95,16 @@ public class TrafficVehicleScheduled { ...@@ -93,8 +95,16 @@ public class TrafficVehicleScheduled {
JsonMessage resultVo = gb1400Service.subscribeNotifications(subscribeNotificationsObj); JsonMessage resultVo = gb1400Service.subscribeNotifications(subscribeNotificationsObj);
if (SystemConstants.APP_CODE_SUCCESS == resultVo.getCode()) { if (SystemConstants.APP_CODE_SUCCESS == resultVo.getCode()) {
TrafficMongoModel last = trafficMongoModels.get(trafficMongoModels.size() - 1); TrafficMongoModel last = trafficMongoModels.get(trafficMongoModels.size() - 1);
log.info("gc.update.record:{}-{}", last.getId(), last.getEvent_dt()); log.info("gc.update.record2:{}-{}", last.getId(), last.getEvent_dt());
if (CheckUtil.checkTime(last, lastTimeUtc)) {
redisTemplate.opsForValue().set(RedisConstants.FANXING_TO_GB1400_VEHICLE_LASTTIME, last.getEvent_dt()); redisTemplate.opsForValue().set(RedisConstants.FANXING_TO_GB1400_VEHICLE_LASTTIME, last.getEvent_dt());
} else {
log.info("gc.update.record-false:{}-{}", last.getId(), last.getEvent_dt());
Date lastRecord = DateUtil.parse(lastTimeUtc, DateUtil.TIMESTAMP_FORMAT);
Date lastRecord1 = DateUtil.addSeconds(lastRecord, 1);
String lastRecord1Str = DateUtil.format(lastRecord1, DateUtil.TIMESTAMP_FORMAT);
redisTemplate.opsForValue().set(RedisConstants.FANXING_TO_GB1400_VEHICLE_LASTTIME, lastRecord1Str);
}
} }
} else { } else {
log.error("trafficDataConvertHandler.trafficVehicleToSubscribeNotifications is null"); log.error("trafficDataConvertHandler.trafficVehicleToSubscribeNotifications is null");
......
...@@ -2,6 +2,7 @@ package com.viontech.utils; ...@@ -2,6 +2,7 @@ package com.viontech.utils;
import com.viontech.vo.traffic.TrafficMongoModel; import com.viontech.vo.traffic.TrafficMongoModel;
import java.util.Date;
import java.util.Map; import java.util.Map;
import java.util.Optional; import java.util.Optional;
...@@ -16,4 +17,14 @@ public class CheckUtil { ...@@ -16,4 +17,14 @@ public class CheckUtil {
} }
return false; return false;
} }
public static boolean checkTime(TrafficMongoModel last, String lastTimeUtc) {
Date lastDate = DateUtil.parse(lastTimeUtc, DateUtil.TIMESTAMP_FORMAT);
Date lastRecord = DateUtil.parse(last.getEvent_dt(), DateUtil.TIMESTAMP_FORMAT);
if (lastRecord.getTime() >= lastDate.getTime()) {
return true;
} else {
return false;
}
}
} }
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!