Commit 26a2d2e4 by 向延琳

fix:常驻地查询取到激活之前的数据

1 parent 9f296cac
...@@ -532,15 +532,14 @@ public class VehicleMonitorService { ...@@ -532,15 +532,14 @@ public class VehicleMonitorService {
//2为无源设备查询基站;1为有源设备查询GPS //2为无源设备查询基站;1为有源设备查询GPS
Device device = deviceService.getDeviceBySn(search.getSn()); Device device = deviceService.getDeviceBySn(search.getSn());
Date deviceActivateTime = Optional.ofNullable(device) VehicleDevice vehicleDevice = vehicleDeviceService.getByBindSn(search.getSn());
.map(Device::getActivateTime)
boolean isGps = Objects.isNull(device) || Objects.equals(device.getSource(), 1);
int lacType = isGps ? 1 : 2;
Date deviceActivateTime = Optional.ofNullable(vehicleDevice)
.map(VehicleDevice::getCreatedDate)
.orElse(new Date()); .orElse(new Date());
int lacType;
if (Objects.isNull(device) || Objects.equals(device.getSource(), 1)) {
lacType = 1;
} else {
lacType = 2;
}
//转换前端时间 //转换前端时间
ImmutablePair<String, String> timeImmutablePair = convertTime(search, deviceActivateTime); ImmutablePair<String, String> timeImmutablePair = convertTime(search, deviceActivateTime);
...@@ -550,30 +549,37 @@ public class VehicleMonitorService { ...@@ -550,30 +549,37 @@ public class VehicleMonitorService {
/** /**
* 转换开始结束时间 * 转换开始结束时间
* @return 开始时间只取设备激活时间之后
*/ */
public ImmutablePair<String, String> convertTime(ResidentSearch search, Date deviceCreateTime) { public ImmutablePair<String, String> convertTime(ResidentSearch search, Date deviceActivateTime) {
Date now = new Date(); Date now = new Date();
String startDate = ""; String startDate = "";
String endDate = DateUtil.getNowDateTimeFormat(); String endDate = DateUtil.getNowDateTimeFormat();
String deviceActivateTimeStr = DateUtil.formatDate(deviceActivateTime);
switch (search.getTimeRange()) { switch (search.getTimeRange()) {
//前一个月 //前一个月
case ConstantsVehicle.RESIDENT_TYPE_ONE: case ConstantsVehicle.RESIDENT_TYPE_ONE:
startDate = DateUtil.formatDate(DateUtil.getDayBefore(30, now)); String afterOneMonth = DateUtil.formatDate(DateUtil.getDayBefore(30, now));
startDate = DateUtil.getAfterDateTimeStr(afterOneMonth, deviceActivateTimeStr);
break; break;
//前三个月 //前三个月
case ConstantsVehicle.RESIDENT_TYPE_THREE: case ConstantsVehicle.RESIDENT_TYPE_THREE:
startDate = DateUtil.formatDate(DateUtil.getDayBefore(90, now)); String afterThreeMonth = DateUtil.formatDate(DateUtil.getDayBefore(90, now));
startDate = DateUtil.getAfterDateTimeStr(afterThreeMonth, deviceActivateTimeStr);
break; break;
//前半年 //前半年
case ConstantsVehicle.RESIDENT_TYPE_SIX: case ConstantsVehicle.RESIDENT_TYPE_SIX:
startDate = DateUtil.formatDate(DateUtil.getDayBefore(180, now));
String afterSixMonth = DateUtil.formatDate(DateUtil.getDayBefore(180, now));
startDate = DateUtil.getAfterDateTimeStr(afterSixMonth, deviceActivateTimeStr);
break; break;
case ConstantsVehicle.RESIDENT_TYPE_PRESENT: case ConstantsVehicle.RESIDENT_TYPE_PRESENT:
startDate = DateUtil.formatDate(deviceCreateTime); startDate = deviceActivateTimeStr;
break; break;
//自定义 //自定义
case ConstantsVehicle.RESIDENT_TYPE_CUSTOM: case ConstantsVehicle.RESIDENT_TYPE_CUSTOM:
startDate = search.getStartTime(); startDate = DateUtil.getAfterDateTimeStr(search.getStartTime(), deviceActivateTimeStr);
endDate = search.getEndTime(); endDate = search.getEndTime();
break; break;
default: default:
......
...@@ -1543,6 +1543,30 @@ public class DateUtil extends org.apache.commons.lang.time.DateUtils { ...@@ -1543,6 +1543,30 @@ public class DateUtil extends org.apache.commons.lang.time.DateUtils {
return datetime.toInstant(ZoneOffset.ofHours(8)).toEpochMilli(); return datetime.toInstant(ZoneOffset.ofHours(8)).toEpochMilli();
} }
/**
* 获取之后的时间
* @param dateTime1 yyyy-MM-dd HH:mm:ss
* @param dateTime2 yyyy-MM-dd HH:mm:ss
* @return yyyy-MM-dd HH:mm:ss
*/
public static String getAfterDateTimeStr(String dateTime1, String dateTime2) {
if(StringUtils.isEmpty(dateTime1) && StringUtils.isEmpty(dateTime1)) {
return "";
}
if(StringUtils.isEmpty(dateTime1) ) {
return dateTime2;
}
if(StringUtils.isEmpty(dateTime2) ) {
return dateTime1;
}
LocalDateTime localDateTime1 = LocalDateTime.parse(dateTime1, DateTimeFormatter.ofPattern(YMDHMS));
LocalDateTime localDateTime2 = LocalDateTime.parse(dateTime2, DateTimeFormatter.ofPattern(YMDHMS));
if(localDateTime1.isAfter(localDateTime2)) {
return dateTime1;
}
return dateTime2;
}
public static void main(String[] args) { public static void main(String[] args) {
// System.out.println(formatDate(getStartDateOfCurrentDay(new Date()))); // System.out.println(formatDate(getStartDateOfCurrentDay(new Date())));
System.out.println(getMaxDayOfCurrentMonth()); System.out.println(getMaxDayOfCurrentMonth());
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!