Commit 26a2d2e4 by 向延琳

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

1 parent 9f296cac
......@@ -532,15 +532,14 @@ public class VehicleMonitorService {
//2为无源设备查询基站;1为有源设备查询GPS
Device device = deviceService.getDeviceBySn(search.getSn());
Date deviceActivateTime = Optional.ofNullable(device)
.map(Device::getActivateTime)
VehicleDevice vehicleDevice = vehicleDeviceService.getByBindSn(search.getSn());
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());
int lacType;
if (Objects.isNull(device) || Objects.equals(device.getSource(), 1)) {
lacType = 1;
} else {
lacType = 2;
}
//转换前端时间
ImmutablePair<String, String> timeImmutablePair = convertTime(search, deviceActivateTime);
......@@ -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();
String startDate = "";
String endDate = DateUtil.getNowDateTimeFormat();
String deviceActivateTimeStr = DateUtil.formatDate(deviceActivateTime);
switch (search.getTimeRange()) {
//前一个月
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;
//前三个月
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;
//前半年
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;
case ConstantsVehicle.RESIDENT_TYPE_PRESENT:
startDate = DateUtil.formatDate(deviceCreateTime);
startDate = deviceActivateTimeStr;
break;
//自定义
case ConstantsVehicle.RESIDENT_TYPE_CUSTOM:
startDate = search.getStartTime();
startDate = DateUtil.getAfterDateTimeStr(search.getStartTime(), deviceActivateTimeStr);
endDate = search.getEndTime();
break;
default:
......
......@@ -1543,6 +1543,30 @@ public class DateUtil extends org.apache.commons.lang.time.DateUtils {
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) {
// System.out.println(formatDate(getStartDateOfCurrentDay(new Date())));
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!