Commit aab895eb by 谢海旭

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

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