Commit 51ac3ca7 by 毛树良

<fix>:优化查询

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