Commit aab895eb by 谢海旭

用量分析接口优化+bug修复

1 parent a23936fc
......@@ -560,7 +560,7 @@ public class RiskAssessmentService {
});
// 查询防拆警情:断电、光感、翻转
// TODO 接口测试,生效中的警情没有,只有开始时间没有结束时间
// TODO 接口测试,生效中的警情,只有开始时间没有结束时间
log.info("查询防拆警情 请求参数:{}", JSONUtil.toJsonStr(snList));
List<CommonAlarmDto> tearDownAlarmList = remoteAlarmService.selectLatestAlarmOfEachType(snList);
log.info("查询防拆警情 请求结果:{}", JSONUtil.toJsonStr(tearDownAlarmList));
......@@ -798,25 +798,34 @@ public class RiskAssessmentService {
DeviceJourneyOverview overview = deviceJourneyOverviewMapper.selectOneByExample(overviewExample);
//激活日期
Date activeDate =vehicleMapper.getActiveDate(vehicleId);
int activeDays = (int) cn.hutool.core.date.DateUtil.between(activeDate, DateUtils.addDays(new Date(), -1), DateUnit.DAY);
Integer distance = overview.getDistance();
analysisVO.setAverage((((distance*1.00))/activeDays)/1000);
if (!Objects.isNull(overview)) {
int activeDays = (int) cn.hutool.core.date.DateUtil.between(activeDate, DateUtils.addDays(new Date(), -1), DateUnit.DAY);
Integer distance = overview.getDistance();
analysisVO.setAverage((((distance*1.00))/activeDays)/1000);
} else {
analysisVO.setAverage(0.00);
}
//超过全平台百分比车主
List<Long> vehicleDeviceIds = vehicleDeviceMapper.getVehicleEarliestWireDeviceIdsByPermit();
Example vdExample = new Example.Builder(VehicleDevice.class).where(WeekendSqls.<VehicleDevice>custom()
.andIn(VehicleDevice::getId, vehicleDeviceIds)).build();
List<VehicleDevice> devices = vehicleDeviceMapper.selectByExample(vdExample);
List<String> snList = devices.stream().map(VehicleDevice::getSn).collect(Collectors.toList());
Example allOverviewExample = new Example.Builder(DeviceJourneyOverview.class)
.where(WeekendSqls.<DeviceJourneyOverview>custom()
.andIn(DeviceJourneyOverview::getSn, snList).andEqualTo(DeviceJourneyOverview::getDelFlag, 0))
.orderByDesc("distance").build();
List<DeviceJourneyOverview> overviews = deviceJourneyOverviewMapper.selectByExample(allOverviewExample);
List<Integer> allDistance = overviews.stream().map(DeviceJourneyOverview::getDistance).collect(Collectors.toList());
// TODO 取小数点
int percentage = ((allDistance.indexOf(distance) + 1) * 100) / snList.size();
analysisVO.setPercentage(100 - percentage);
int percentage = 100;
if (!Objects.isNull(overview)) {
List<Long> vehicleDeviceIds = vehicleDeviceMapper.getVehicleEarliestWireDeviceIdsByPermit();
Example vdExample = new Example.Builder(VehicleDevice.class).where(WeekendSqls.<VehicleDevice>custom()
.andIn(VehicleDevice::getId, vehicleDeviceIds)).build();
List<VehicleDevice> devices = vehicleDeviceMapper.selectByExample(vdExample);
List<String> snList = devices.stream().map(VehicleDevice::getSn).collect(Collectors.toList());
Example allOverviewExample = new Example.Builder(DeviceJourneyOverview.class)
.where(WeekendSqls.<DeviceJourneyOverview>custom()
.andIn(DeviceJourneyOverview::getSn, snList).andEqualTo(DeviceJourneyOverview::getDelFlag, 0))
.orderByDesc("distance").build();
List<DeviceJourneyOverview> overviews = deviceJourneyOverviewMapper.selectByExample(allOverviewExample);
List<Integer> allDistance = overviews.stream().map(DeviceJourneyOverview::getDistance).collect(Collectors.toList());
// TODO 取小数点
percentage = ((allDistance.indexOf(overview.getDistance()) + 1) * 100) / snList.size();
analysisVO.setPercentage(100 - percentage);
} else {
analysisVO.setPercentage(0);
}
//用车活跃度
if (percentage <= 33) {
......@@ -834,29 +843,39 @@ public class RiskAssessmentService {
Example locationExample = new Example.Builder(DeviceLocation.class).where(WeekendSqls.<DeviceLocation>custom()
.andEqualTo(DeviceLocation::getSn, sn)).build();
DeviceLocation deviceLocation = deviceLocationMapper.selectOneByExample(locationExample);
Date locationDate = DateUtil.getMaxDate(deviceLocation.getLastGpsTime(), deviceLocation.getLastBsTime());
int daysOfUsage = (int) cn.hutool.core.date.DateUtil.between(activeDate, locationDate, DateUnit.DAY);
analysisVO.setDays(daysOfUsage);
if (Objects.nonNull(deviceLocation)) {
Date locationDate = DateUtil.getMaxDate(deviceLocation.getLastGpsTime(), deviceLocation.getLastBsTime());
int daysOfUsage = (int) cn.hutool.core.date.DateUtil.between(activeDate, locationDate, DateUnit.DAY);
analysisVO.setDays(daysOfUsage);
} else {
analysisVO.setDays(0);
}
//日里程
List<VehicleUsageAnalysisPointVO> mileage = deviceJourneyMapper.statisMileageBySnGroupByDate(sn);
String firstDateStr = mileage.get(0).getX();
String lastDateStr = mileage.get(mileage.size() - 1).getX();
if (DateUtil.isSameWeek(DateUtil.parseDateYmd(firstDateStr), DateUtil.parseDateYmd(lastDateStr))) {
mileage = fillBlankDate(mileage, DateUtil.getFirstDateOfWeek(DateUtil.parseDateYmd(firstDateStr)), DateUtil.getLastDateOfWeek(DateUtil.parseDateYmd(firstDateStr)), 1);
analysisVO.setMileage(mileage);
return analysisVO;
if (CollectionUtils.isNotEmpty(mileage)) {
String firstDateStr = mileage.get(0).getX();
String lastDateStr = mileage.get(mileage.size() - 1).getX();
if (DateUtil.isSameWeek(DateUtil.parseDateYmd(firstDateStr), DateUtil.parseDateYmd(lastDateStr))) {
mileage = fillBlankDate(mileage, DateUtil.getFirstDateOfWeek(DateUtil.parseDateYmd(firstDateStr)), DateUtil.getLastDateOfWeek(DateUtil.parseDateYmd(firstDateStr)), 1);
analysisVO.setMileage(mileage);
return analysisVO;
} else {
mileage = fillBlankDate(mileage, DateUtil.getFirstDateOfWeek(DateUtil.parseDateYmd(firstDateStr)), DateUtil.getLastDateOfWeek(DateUtil.parseDateYmd(lastDateStr)), 1);
analysisVO.setMileage(mileage);
}
// 周用车天数
List<VehicleUsageAnalysisPointVO> usage = deviceJourneyMapper.statisUsageBySnGroupByWeek(sn);
String firstWeek = usage.get(0).getX();
String lastWeek = usage.get(usage.size() - 1).getX();
usage = fillBlankDate(mileage, DateUtil.parseDateYmd(firstWeek), DateUtil.parseDateYmd(lastWeek), 7);
analysisVO.setDaysOfVehicle(usage);
} else {
mileage = fillBlankDate(mileage, DateUtil.getFirstDateOfWeek(DateUtil.parseDateYmd(firstDateStr)), DateUtil.getLastDateOfWeek(DateUtil.parseDateYmd(lastDateStr)), 1);
analysisVO.setMileage(mileage);
analysisVO.setMileage(Lists.newArrayList());
analysisVO.setDaysOfVehicle(Lists.newArrayList());
}
// 周用车天数
List<VehicleUsageAnalysisPointVO> usage = deviceJourneyMapper.statisUsageBySnGroupByWeek(sn);
String firstWeek = usage.get(0).getX();
String lastWeek = usage.get(usage.size() - 1).getX();
usage = fillBlankDate(mileage, DateUtil.parseDateYmd(firstWeek), DateUtil.parseDateYmd(lastWeek), 7);
analysisVO.setDaysOfVehicle(usage);
return analysisVO;
}
......
......@@ -372,7 +372,7 @@
) t2 on t2.id = t1.id
</select>
<select id="getVehicleEarliestWireDeviceIdsByPermit" resultType="java.lang.Long">
select min(tv.id)
select min(tvd.id)
from t_vehicle tv
left join t_vehicle_device tvd on tvd.vehicle_id = tv.id
where tv.del_flag = 0 and tvd.del_flag = 0 and tvd.bind_status = 1 and tvd.wire_type = 1
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!