| | |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.ycl.platform.domain.entity.WorkOrder; |
| | | import com.ycl.platform.domain.entity.YwThreshold; |
| | | import com.ycl.platform.domain.result.HK.FaceDeviceInspectionResult; |
| | | import com.ycl.platform.domain.result.HK.VehicleDeviceInspectionResult; |
| | | import com.ycl.platform.mapper.WorkOrderMapper; |
| | | import com.ycl.platform.mapper.YwThresholdMapper; |
| | | import com.ycl.platform.service.IYwThresholdService; |
| | | import constant.CompareConstant; |
| | | import constant.YwThreadConstants; |
| | | import enumeration.CompareType; |
| | | import enumeration.general.BusinessTypeEnum; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import utils.DateUtils; |
| | | |
| | | import java.util.Date; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.*; |
| | | import java.util.function.Function; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | |
| | | * @date 2024-07-19 |
| | | */ |
| | | @Service |
| | | @Slf4j |
| | | public class YwThresholdServiceImpl extends ServiceImpl<YwThresholdMapper, YwThreshold> implements IYwThresholdService { |
| | | @Autowired |
| | | private YwThresholdMapper ywThresholdMapper; |
| | |
| | | |
| | | |
| | | @Override |
| | | public void faceCheck(List list) { |
| | | public void videoCheck(List list) { |
| | | |
| | | } |
| | | |
| | | /** |
| | | * 判断人脸阈值是否满足下发条件 |
| | | * |
| | | * @param list |
| | | */ |
| | | @Override |
| | | public void videoCheck(List list) { |
| | | |
| | | public void faceCheck(List<FaceDeviceInspectionResult> list) { |
| | | Map<String, YwThreshold> thresholdMap = getYwThresholdMap(BusinessTypeEnum.FACE.name()); |
| | | //准备下发工单集合 |
| | | List<FaceDeviceInspectionResult> distributeList = new ArrayList<>(); |
| | | //准备自动生成工单集合 |
| | | List<FaceDeviceInspectionResult> workOrderList = new ArrayList<>(); |
| | | //处理接口数据 |
| | | for (FaceDeviceInspectionResult result : list) { |
| | | if (result == null) { |
| | | log.error("人脸对象数据为空"); |
| | | continue; |
| | | } |
| | | //检查时钟准确率 |
| | | Float clockPercent = result.getSnapClock().getClockPercent(); |
| | | check(YwThreadConstants.Face_ClockPercent, clockPercent, result, thresholdMap, distributeList, workOrderList, CompareType.LESS_THAN_EQ); |
| | | //检查数据及时率 |
| | | Float timelyPercent = result.getSnapTimely().getTimelyPercent(); |
| | | check(YwThreadConstants.Face_TimelyPercent, timelyPercent, result, thresholdMap, distributeList, workOrderList, CompareType.LESS_THAN_EQ); |
| | | //检查持续无数据天数 |
| | | Integer continueNoDataCount = result.getContinueNoDataCount(); |
| | | check(YwThreadConstants.Face_ContinueNoDataCount, continueNoDataCount, result, thresholdMap, distributeList, workOrderList, CompareType.MORE_THAN_EQ); |
| | | //检查不唯一数据量 |
| | | Integer nouniqueCount = result.getSnapUnique().getNouniqueCount(); |
| | | check(YwThreadConstants.Face_NouniqueCount, nouniqueCount, result, thresholdMap, distributeList, workOrderList, CompareType.MORE_THAN_EQ); |
| | | //检查人脸低评分率 |
| | | Float lowScorePercent = result.getSnapValidity().getLowScorePercent(); |
| | | check(YwThreadConstants.Face_LowScorePercent, lowScorePercent, result, thresholdMap, distributeList, workOrderList, CompareType.LESS_THAN_EQ); |
| | | //检查建模失败率 |
| | | Float failPercent = result.getSnapValidity().getFailPercent(); |
| | | check(YwThreadConstants.Face_FailPercent, failPercent, result, thresholdMap, distributeList, workOrderList, CompareType.LESS_THAN_EQ); |
| | | } |
| | | //TODO:待处理集合添加工单 |
| | | } |
| | | |
| | | /** |
| | |
| | | */ |
| | | @Override |
| | | public void carCheck(List<VehicleDeviceInspectionResult> list) { |
| | | QueryWrapper<YwThreshold> wrapper = new QueryWrapper<>(); |
| | | wrapper.eq("monitor_type", BusinessTypeEnum.CAR.name()); |
| | | List<YwThreshold> ywThresholds = ywThresholdMapper.selectList(wrapper); |
| | | Map<String, YwThreshold> map = new HashMap<>(); |
| | | for (YwThreshold ywThreshold : ywThresholds) { |
| | | String key = ywThreshold.getKey(); |
| | | map.put(key, ywThreshold); |
| | | } |
| | | //时钟准确率阈值 |
| | | Float clockPercent = Float.valueOf(map.get(YwThreadConstants.Car_ClockPercent).getValue()); |
| | | Float clockPercentAuto = Float.valueOf(map.get(YwThreadConstants.Car_ClockPercent).getValueAuto()); |
| | | //数据及时率阈值 |
| | | Float timelyPercent = Float.valueOf(map.get(YwThreadConstants.Car_TimelyPercent).getValue()); |
| | | Float timelyPercentAuto = Float.valueOf(map.get(YwThreadConstants.Car_TimelyPercent).getValueAuto()); |
| | | //持续无数据天数阈值 |
| | | Integer continueNoDataCount = Integer.valueOf(map.get(YwThreadConstants.Car_ContinueNoDataCount).getValue()); |
| | | Integer continueNoDataCountAuto = Integer.valueOf(map.get(YwThreadConstants.Car_ContinueNoDataCount).getValueAuto()); |
| | | //不唯一数据量阈值 |
| | | Integer nouniqueCount = Integer.valueOf(map.get(YwThreadConstants.Car_NouniqueCount).getValue()); |
| | | Integer nouniqueCountAuto = Integer.valueOf(map.get(YwThreadConstants.Car_NouniqueCount).getValueAuto()); |
| | | //白天未识别量阈值 |
| | | Integer dayNoNumberCount = Integer.valueOf(map.get(YwThreadConstants.Car_DayNoNumberCount).getValue()); |
| | | Integer dayNoNumberCountAuto = Integer.valueOf(map.get(YwThreadConstants.Car_DayNoNumberCount).getValueAuto()); |
| | | //车辆六项属性不完整量阈值 |
| | | Integer noIntegrityCount = Integer.valueOf(map.get(YwThreadConstants.Car_NoIntegrityCount).getValue()); |
| | | Integer noIntegrityCountAuto = Integer.valueOf(map.get(YwThreadConstants.Car_NoIntegrityCount).getValueAuto()); |
| | | |
| | | Map<String, YwThreshold> thresholdMap = getYwThresholdMap(BusinessTypeEnum.CAR.name()); |
| | | //准备下发工单集合 |
| | | List<VehicleDeviceInspectionResult> distributeList = new ArrayList<>(); |
| | | //准备自动生成工单集合 |
| | | List<VehicleDeviceInspectionResult> workOrderList = new ArrayList<>(); |
| | | //处理接口数据 |
| | | for (VehicleDeviceInspectionResult result : list) { |
| | | if (result == null) { |
| | |
| | | continue; |
| | | } |
| | | //检查持续无数据天数 |
| | | Integer continueNoDataCountResult = result.getContinueNoDataCount(); |
| | | check(continueNoDataCount, continueNoDataCountAuto, result, continueNoDataCountResult, "车辆持续无数据天数为空", CompareConstant.MoreThanEq); |
| | | Integer continueNoDataCount = result.getContinueNoDataCount(); |
| | | check(YwThreadConstants.Car_ContinueNoDataCount, continueNoDataCount, result, thresholdMap, distributeList, workOrderList, CompareType.MORE_THAN_EQ); |
| | | //检查时钟准确率 |
| | | Float clockPercentResult = result.getSnapClock().getClockPercent(); |
| | | check(clockPercent, clockPercentAuto, result, clockPercentResult, "车辆时钟准确率为空", CompareConstant.LessThanEq); |
| | | Float clockPercent = result.getSnapClock().getClockPercent(); |
| | | check(YwThreadConstants.Car_ClockPercent, clockPercent, result, thresholdMap, distributeList, workOrderList, CompareType.LESS_THAN_EQ); |
| | | //检查数据及时率 |
| | | Float timelyPercentResult = result.getSnapTimely().getTimelyPercent(); |
| | | check(timelyPercent, timelyPercentAuto, result, timelyPercentResult, "车辆数据及时率为空", CompareConstant.LessThanEq); |
| | | check(YwThreadConstants.Car_TimelyPercent, timelyPercentResult, result, thresholdMap, distributeList, workOrderList, CompareType.LESS_THAN_EQ); |
| | | //检查不唯一数据量 |
| | | Integer nouniqueCountResult = result.getSnapUnique().getNouniqueCount(); |
| | | check(nouniqueCount, nouniqueCountAuto, result, nouniqueCountResult, "车辆不唯一数据量为空", CompareConstant.MoreThanEq); |
| | | check(YwThreadConstants.Car_NouniqueCount, nouniqueCountResult, result, thresholdMap, distributeList, workOrderList, CompareType.MORE_THAN_EQ); |
| | | //检查白天未识别量 |
| | | Integer dayNoNumberCountResult = result.getSnapPlate().getDayNoNumberCount(); |
| | | check(dayNoNumberCount, dayNoNumberCountAuto, result, dayNoNumberCountResult, "车辆白天未识别量为空", CompareConstant.MoreThanEq); |
| | | check(YwThreadConstants.Car_DayNoNumberCount, dayNoNumberCountResult, result, thresholdMap, distributeList, workOrderList, CompareType.MORE_THAN_EQ); |
| | | //车辆六项属性不完整量 |
| | | Integer noIntegrityCountResult = result.getIntegrity().getNoIntegrityCount(); |
| | | check(noIntegrityCount, noIntegrityCountAuto, result, noIntegrityCountResult, "车辆六项属性不完整量为空", CompareConstant.MoreThanEq); |
| | | check(YwThreadConstants.Car_NoIntegrityCount, noIntegrityCountResult, result, thresholdMap, distributeList, workOrderList, CompareType.MORE_THAN_EQ); |
| | | } |
| | | //TODO:待处理集合添加工单 |
| | | } |
| | | |
| | | //封装阈值为map |
| | | private Map<String, YwThreshold> getYwThresholdMap(String name) { |
| | | return ywThresholdMapper.selectList( |
| | | new QueryWrapper<YwThreshold>().eq("monitor_type", name) |
| | | ).stream().collect(Collectors.toMap( |
| | | YwThreshold::getKey, |
| | | Function.identity() |
| | | )); |
| | | } |
| | | |
| | | //检查阈值 |
| | | private <T extends Comparable<T>> void check(String key, T value, Object result, Map<String, YwThreshold> thresholds, List distributeList, List workOrderList, CompareType compareType) { |
| | | Optional.ofNullable(value).ifPresentOrElse( |
| | | v -> { |
| | | YwThreshold ywThreshold = thresholds.get(key); |
| | | //转换类型 |
| | | T thresholdValue = parseThreshold(ywThreshold.getValueAuto(), value.getClass()); |
| | | T thresholdAutoValue = parseThreshold(ywThreshold.getValue(), value.getClass()); |
| | | //比较大小,加入到对应待处理集合 |
| | | if (compareType.compare(v, thresholdAutoValue)) { |
| | | workOrderList.add(result); |
| | | } else if (compareType.compare(v, thresholdValue)) { |
| | | distributeList.add(result); |
| | | } |
| | | }, |
| | | () -> log.error("{} 为空: {}", thresholds.get(key).getName(), result) |
| | | ); |
| | | |
| | | |
| | | } |
| | | |
| | | private void check(Integer threshold, Integer thresholdAuto, VehicleDeviceInspectionResult result, Integer thresholdResult, String message, String command) { |
| | | if (thresholdResult != null) { |
| | | //大于类型 |
| | | if (CompareConstant.MoreThanEq.equals(command)) { |
| | | if (thresholdResult >= thresholdAuto) { |
| | | //TODO:自动下发工单 |
| | | } else if (thresholdResult >= threshold) { |
| | | //TODO:进入下发工单页面 |
| | | } |
| | | } else if (CompareConstant.LessThanEq.equals(command)) { |
| | | //小于类型 |
| | | if (thresholdResult <= thresholdAuto) { |
| | | //TODO:自动下发工单 |
| | | } else if (thresholdResult <= threshold) { |
| | | //TODO:进入下发工单页面 |
| | | } |
| | | } |
| | | private <T extends Comparable<T>> T parseThreshold(String thresholdStr, Class<?> type) { |
| | | if (Integer.class.equals(type)) { |
| | | return (T) Integer.valueOf(thresholdStr); |
| | | } else if (Float.class.equals(type)) { |
| | | return (T) Float.valueOf(thresholdStr); |
| | | } else if (Double.class.equals(type)) { |
| | | return (T) Double.valueOf(thresholdStr); |
| | | } else if (Long.class.equals(type)) { |
| | | return (T) Long.valueOf(thresholdStr); |
| | | } else { |
| | | log.error(message + result); |
| | | throw new IllegalArgumentException("不支持转换类型" + type); |
| | | } |
| | | } |
| | | |
| | | private void check(Float threshold, Float thresholdAuto, VehicleDeviceInspectionResult result, Float thresholdResult, String message, String command) { |
| | | if (thresholdResult != null) { |
| | | //大于类型 |
| | | if (CompareConstant.MoreThanEq.equals(command)) { |
| | | if (thresholdResult >= thresholdAuto) { |
| | | //TODO:自动下发工单 |
| | | } else if (thresholdResult >= threshold) { |
| | | //TODO:进入下发工单页面 |
| | | } |
| | | } else if (CompareConstant.LessThanEq.equals(command)) { |
| | | //小于类型 |
| | | if (thresholdResult <= thresholdAuto) { |
| | | //TODO:自动下发工单 |
| | | } else if (thresholdResult <= threshold) { |
| | | //TODO:进入下发工单页面 |
| | | } |
| | | } |
| | | } else { |
| | | log.error(message + result); |
| | | } |
| | | } |
| | | } |