package com.ycl.calculate;
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
import com.ycl.platform.domain.entity.CheckIndexCar;
|
import com.ycl.platform.domain.entity.YwPoint;
|
import com.ycl.platform.domain.result.UY.MonitorQualifyResult;
|
import com.ycl.platform.mapper.CheckIndexCarMapper;
|
import com.ycl.platform.mapper.YwPointMapper;
|
import com.ycl.platform.service.ICheckIndexCarService;
|
import lombok.extern.slf4j.Slf4j;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.stereotype.Component;
|
import utils.DateUtils;
|
|
import java.math.BigDecimal;
|
import java.util.ArrayList;
|
import java.util.HashMap;
|
import java.util.List;
|
import java.util.Map;
|
|
/**
|
* 计算车辆目录一致率
|
* 获取分省厅、区域的map<k,v> k为deptId或者Province_deptId
|
* 更新或新增
|
*/
|
@Component
|
@Slf4j
|
public class CarConsistentCalculation extends IndexCalculationServe<MonitorQualifyResult, CarConsistentCalculation.AreaStats> implements CalculationStrategy<MonitorQualifyResult> {
|
@Autowired
|
private CheckIndexCarMapper checkIndexCarMapper;
|
@Autowired
|
private ICheckIndexCarService checkIndexCarService;
|
//区域车辆目录一致率的内部类
|
protected static class AreaStats {
|
int totalSites = 0;
|
int newSites = 0;
|
}
|
|
@Override
|
public void calculate(List<MonitorQualifyResult> list) {
|
//获取分区域的指标数量
|
Map<String, AreaStats> areaStatsMap = getAreaStatsMap(list,Boolean.FALSE);
|
if (areaStatsMap == null) return;
|
|
// 查询是否index表已经存在今日数据
|
List<CheckIndexCar> checkIndexCarList = checkIndexCarMapper.selectToday(DateUtils.getDate());
|
|
List<CheckIndexCar> checkIndexCars = new ArrayList<>();
|
areaStatsMap.forEach((deptId, stats) -> {
|
if (stats.totalSites > 0) {
|
CheckIndexCar checkIndexCar = createOrUpdateCheckIndexCar(deptId, stats, checkIndexCarList);
|
if (checkIndexCar != null) {
|
checkIndexCars.add(checkIndexCar);
|
}
|
}
|
});
|
checkIndexCarService.saveOrUpdateBatch(checkIndexCars);
|
}
|
|
|
/**
|
* 累计车辆目录一致率
|
*/
|
@Override
|
public void updateAreaStats(Map<String, AreaStats> areaStatsMap, String key, MonitorQualifyResult result) {
|
//返回对象的引用,如果不存在会放入新的key,value
|
AreaStats stats = areaStatsMap.computeIfAbsent(key, k -> new AreaStats());
|
stats.totalSites++;
|
if(result.getNewDevice()!=null && result.getNewDevice()){
|
stats.newSites++;
|
}
|
}
|
|
/**
|
* 车辆信息采集正确率
|
*/
|
private CheckIndexCar createOrUpdateCheckIndexCar(String key, AreaStats stats, List<CheckIndexCar> checkIndexCarList) {
|
CheckIndexCar checkIndexCar = getCheckIndex(key, checkIndexCarList, CheckIndexCar.class);
|
if (checkIndexCar == null) {
|
return null;
|
}
|
//调用目录一致率计算方法
|
Map<String, Object> param = new HashMap<>();
|
param.put("totalSites", stats.totalSites);
|
param.put("newSites", stats.newSites);
|
BigDecimal directoryConstant = directoryConstant(param);
|
checkIndexCar.setDeviceDirectoryConsistent(directoryConstant);
|
return checkIndexCar;
|
}
|
|
|
}
|