| | |
| | | |
| | | @Autowired |
| | | private WorkOrderWhiteMapper workOrderWhiteMapper; |
| | | |
| | | /** |
| | | * 查询运维阈值 |
| | | * |
| | |
| | | // 平台离线故障检测 |
| | | if (CollectionUtils.isEmpty(list)) { |
| | | Boolean ping = PingUtil.ping("", 5); |
| | | if (! ping) { |
| | | if (!ping) { |
| | | |
| | | } |
| | | } |
| | |
| | | } |
| | | WorkOrder workOrder = new WorkOrder(); |
| | | //检查时钟准确率 |
| | | Float clockPercent = result.getSnapClock().getClockPercent(); |
| | | check(YwThreadConstants.Face_ClockPercent, clockPercent, result.getExternalIndexCode(), thresholdMap, workOrder, CompareType.LESS_THAN_EQ, ErrorType.CLOCK_RIGHT.getValue()); |
| | | if (result.getSnapClock() != null) { |
| | | Float clockPercent = result.getSnapClock().getClockPercent(); |
| | | check(YwThreadConstants.Face_ClockPercent, clockPercent, result.getExternalIndexCode(), thresholdMap, workOrder, CompareType.LESS_THAN_EQ, ErrorType.CLOCK_RIGHT.getValue()); |
| | | } |
| | | //检查数据及时率 |
| | | Float timelyPercent = result.getSnapTimely().getTimelyPercent(); |
| | | check(YwThreadConstants.Face_TimelyPercent, timelyPercent, result.getExternalIndexCode(), thresholdMap, workOrder, CompareType.LESS_THAN_EQ, ErrorType.DATA_TIMELY_ERROR.getValue()); |
| | | if (result.getSnapTimely() != null) { |
| | | Float timelyPercent = result.getSnapTimely().getTimelyPercent(); |
| | | check(YwThreadConstants.Face_TimelyPercent, timelyPercent, result.getExternalIndexCode(), thresholdMap, workOrder, CompareType.LESS_THAN_EQ, ErrorType.DATA_TIMELY_ERROR.getValue()); |
| | | } |
| | | //检查持续无数据天数 |
| | | Integer continueNoDataCount = result.getContinueNoDataCount(); |
| | | check(YwThreadConstants.Face_ContinueNoDataCount, continueNoDataCount, result.getExternalIndexCode(), thresholdMap, workOrder, CompareType.MORE_THAN_EQ, ErrorType.LONG_DAY_NO_DATA.getValue()); |
| | | if (result.getContinueNoDataCount() != null) { |
| | | Integer continueNoDataCount = result.getContinueNoDataCount(); |
| | | check(YwThreadConstants.Face_ContinueNoDataCount, continueNoDataCount, result.getExternalIndexCode(), thresholdMap, workOrder, CompareType.MORE_THAN_EQ, ErrorType.LONG_DAY_NO_DATA.getValue()); |
| | | } |
| | | //检查不唯一数据量 |
| | | Integer nouniqueCount = result.getSnapUnique().getNouniqueCount(); |
| | | check(YwThreadConstants.Face_NouniqueCount, nouniqueCount, result.getExternalIndexCode(), thresholdMap, workOrder, CompareType.MORE_THAN_EQ, ErrorType.NOT_UNIQUE_DATA_VOLUME.getValue()); |
| | | if (result.getSnapUnique() != null) { |
| | | Integer nouniqueCount = result.getSnapUnique().getNouniqueCount(); |
| | | check(YwThreadConstants.Face_NouniqueCount, nouniqueCount, result.getExternalIndexCode(), thresholdMap, workOrder, CompareType.MORE_THAN_EQ, ErrorType.NOT_UNIQUE_DATA_VOLUME.getValue()); |
| | | } |
| | | //检查人脸低评分率 |
| | | Float lowScorePercent = result.getSnapValidity().getLowScorePercent(); |
| | | check(YwThreadConstants.Face_LowScorePercent, lowScorePercent, result.getExternalIndexCode(), thresholdMap, workOrder, CompareType.MORE_THAN_EQ, ErrorType.FACE_LOW.getValue()); |
| | | if (result.getSnapValidity() != null) { |
| | | Float lowScorePercent = result.getSnapValidity().getLowScorePercent(); |
| | | check(YwThreadConstants.Face_LowScorePercent, lowScorePercent, result.getExternalIndexCode(), thresholdMap, workOrder, CompareType.MORE_THAN_EQ, ErrorType.FACE_LOW.getValue()); |
| | | } |
| | | //检查建模失败率 |
| | | Float failPercent = result.getSnapValidity().getFailPercent(); |
| | | check(YwThreadConstants.Face_FailPercent, failPercent, result.getExternalIndexCode(), thresholdMap, workOrder, CompareType.MORE_THAN_EQ, ErrorType.MODELING_FAIL.getValue()); |
| | | if (result.getSnapValidity() != null) { |
| | | Float failPercent = result.getSnapValidity().getFailPercent(); |
| | | check(YwThreadConstants.Face_FailPercent, failPercent, result.getExternalIndexCode(), thresholdMap, workOrder, CompareType.MORE_THAN_EQ, ErrorType.MODELING_FAIL.getValue()); |
| | | } |
| | | // 点位在线率 |
| | | if (2 == result.getSnapResult()) { |
| | | workOrder.setSerialNumber(result.getExternalIndexCode()); |
| | |
| | | Integer continueNoDataCount = result.getContinueNoDataCount(); |
| | | check(YwThreadConstants.Car_ContinueNoDataCount, continueNoDataCount, result.getExternalIndexCode(), thresholdMap, workOrder, CompareType.MORE_THAN_EQ, ErrorType.LONG_DAY_NO_DATA.getValue()); |
| | | //检查时钟准确率 |
| | | Float clockPercent = result.getSnapClock().getClockPercent(); |
| | | check(YwThreadConstants.Car_ClockPercent, clockPercent, result.getExternalIndexCode(), thresholdMap, workOrder, CompareType.LESS_THAN_EQ, ErrorType.CLOCK_RIGHT.getValue()); |
| | | if (result.getSnapClock() != null) { |
| | | Float clockPercent = result.getSnapClock().getClockPercent(); |
| | | check(YwThreadConstants.Car_ClockPercent, clockPercent, result.getExternalIndexCode(), thresholdMap, workOrder, CompareType.LESS_THAN_EQ, ErrorType.CLOCK_RIGHT.getValue()); |
| | | } |
| | | //检查数据及时率 |
| | | Float timelyPercentResult = result.getSnapTimely().getTimelyPercent(); |
| | | check(YwThreadConstants.Car_TimelyPercent, timelyPercentResult, result.getExternalIndexCode(), thresholdMap, workOrder, CompareType.LESS_THAN_EQ, ErrorType.DATA_TIMELY_ERROR.getValue()); |
| | | if (result.getSnapTimely() != null) { |
| | | Float timelyPercentResult = result.getSnapTimely().getTimelyPercent(); |
| | | check(YwThreadConstants.Car_TimelyPercent, timelyPercentResult, result.getExternalIndexCode(), thresholdMap, workOrder, CompareType.LESS_THAN_EQ, ErrorType.DATA_TIMELY_ERROR.getValue()); |
| | | } |
| | | //检查不唯一数据量 |
| | | Integer nouniqueCountResult = result.getSnapUnique().getNouniqueCount(); |
| | | check(YwThreadConstants.Car_NouniqueCount, nouniqueCountResult, result.getExternalIndexCode(), thresholdMap, workOrder, CompareType.MORE_THAN_EQ, ErrorType.NOT_UNIQUE_DATA_VOLUME.getValue()); |
| | | if (result.getSnapUnique() != null) { |
| | | Integer nouniqueCountResult = result.getSnapUnique().getNouniqueCount(); |
| | | check(YwThreadConstants.Car_NouniqueCount, nouniqueCountResult, result.getExternalIndexCode(), thresholdMap, workOrder, CompareType.MORE_THAN_EQ, ErrorType.NOT_UNIQUE_DATA_VOLUME.getValue()); |
| | | } |
| | | //检查白天未识别量 |
| | | Integer dayNoNumberCountResult = result.getSnapPlate().getDayNoNumberCount(); |
| | | check(YwThreadConstants.Car_DayNoNumberCount, dayNoNumberCountResult, result.getExternalIndexCode(), thresholdMap, workOrder, CompareType.MORE_THAN_EQ, ErrorType.UNRECOGNIZED_DAY_VOLUME.getValue()); |
| | | if (result.getSnapPlate() != null) { |
| | | Integer dayNoNumberCountResult = result.getSnapPlate().getDayNoNumberCount(); |
| | | check(YwThreadConstants.Car_DayNoNumberCount, dayNoNumberCountResult, result.getExternalIndexCode(), thresholdMap, workOrder, CompareType.MORE_THAN_EQ, ErrorType.UNRECOGNIZED_DAY_VOLUME.getValue()); |
| | | } |
| | | //车辆主要属性一致率 |
| | | Integer noIntegrityCountResult = result.getIntegrity().getMainNoIntegrityCount(); |
| | | Integer dataCount = result.getDataCount(); |
| | | Double integrityRate = ((double)dataCount-noIntegrityCountResult)/dataCount; |
| | | check(YwThreadConstants.Car_NoIntegrityCount, integrityRate, result.getExternalIndexCode(), thresholdMap, workOrder, CompareType.LESS_THAN_EQ, ErrorType.CAR_SIX.getValue()); |
| | | if (result.getIntegrity() != null) { |
| | | Integer noIntegrityCountResult = result.getIntegrity().getMainNoIntegrityCount(); |
| | | Integer dataCount = result.getDataCount(); |
| | | Double integrityRate = ((double) dataCount - noIntegrityCountResult) / dataCount; |
| | | check(YwThreadConstants.Car_NoIntegrityCount, integrityRate, result.getExternalIndexCode(), thresholdMap, workOrder, CompareType.LESS_THAN_EQ, ErrorType.CAR_SIX.getValue()); |
| | | } |
| | | // 点位在线率 |
| | | if (2 == result.getSnapResult()) { |
| | | workOrder.setSerialNumber(result.getExternalIndexCode()); |
| | |
| | | |
| | | /** |
| | | * 白名单详情 |
| | | * |
| | | * @param id |
| | | * @return |
| | | */ |
| | |
| | | workOrderWhite.setErrorTypeList(errorTypeList); |
| | | return Result.ok().data(workOrderWhite); |
| | | } |
| | | |
| | | /** |
| | | * 工单白名单列表 |
| | | * |
| | |
| | | IPage<WorkOrderWhite> page = PageUtil.getPage(query, WorkOrderWhite.class); |
| | | workOrderWhiteMapper.page(page, query); |
| | | List<WorkOrderWhite> records = page.getRecords(); |
| | | records.forEach(white-> { |
| | | records.forEach(white -> { |
| | | List<String> errorTextList = new ArrayList<>(); |
| | | List<String> errorTypeList = Arrays.asList(white.getErrorType().split(",")); |
| | | errorTypeList.forEach(error->{ |
| | | errorTypeList.forEach(error -> { |
| | | String errorText = ErrorType.getDescriptionByValue(error); |
| | | errorTextList.add(errorText); |
| | | }); |
| | |
| | | return Result.error("该设备已存在白名单"); |
| | | } else { |
| | | List<String> errorTypeList = workOrderWhite.getErrorTypeList(); |
| | | workOrderWhite.setErrorType(String.join(",",errorTypeList)); |
| | | workOrderWhite.setErrorType(String.join(",", errorTypeList)); |
| | | workOrderWhite.setCreateBy(SecurityUtils.getUsername()); |
| | | workOrderWhiteMapper.insert(workOrderWhite); |
| | | return Result.ok(); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 修改工单白名单 |
| | | * |
| | |
| | | WorkOrderWhite white = workOrderWhiteMapper.selectBySerialNumber(workOrderWhite.getSerialNumber()); |
| | | workOrderWhite.setId(white.getId()); |
| | | List<String> errorTypeList = workOrderWhite.getErrorTypeList(); |
| | | workOrderWhite.setErrorType(String.join(",",errorTypeList)); |
| | | workOrderWhite.setErrorType(String.join(",", errorTypeList)); |
| | | workOrderWhiteMapper.updateById(workOrderWhite); |
| | | return Result.ok(); |
| | | } |
| | |
| | | workOrderWhiteMapper.batchDelete(ids); |
| | | return Result.ok(); |
| | | } |
| | | |
| | | /** |
| | | * 白名单导出 |
| | | * |
| | | * @param response |
| | | * @throws IOException |
| | | */ |
| | |
| | | public void whiteExport(HttpServletResponse response) throws IOException { |
| | | //白名单数据 |
| | | List<WorkOrderWhiteExport> data = workOrderWhiteMapper.whiteExport(); |
| | | data.forEach(white-> { |
| | | data.forEach(white -> { |
| | | List<String> errorTextList = new ArrayList<>(); |
| | | List<String> errorTypeList = Arrays.asList(white.getErrorType().split(",")); |
| | | errorTypeList.forEach(error->{ |
| | | errorTypeList.forEach(error -> { |
| | | String errorText = ErrorType.getDescriptionByValue(error); |
| | | errorTextList.add(errorText); |
| | | }); |
| | |
| | | errorExports.add(errorExport); |
| | | }); |
| | | ExcelWriter excelWriter = null; |
| | | try(OutputStream outputStream = response.getOutputStream()) { |
| | | try (OutputStream outputStream = response.getOutputStream()) { |
| | | excelWriter = EasyExcel.write(outputStream).build(); |
| | | |
| | | WriteSheet whiteSheet = EasyExcel.writerSheet(0, "工单白名单清单").head(WorkOrderWhiteExport.class).build(); |
| | |
| | | excelWriter.write(errorExports, errorSheet); |
| | | excelWriter.finish(); |
| | | outputStream.flush(); |
| | | }catch (Exception e) { |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } finally { |
| | | try { |
| | |
| | | |
| | | /** |
| | | * 导入工单白名单 |
| | | * |
| | | * @param file |
| | | * @return |
| | | */ |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public Result importWhite(MultipartFile file) throws IOException{ |
| | | public Result importWhite(MultipartFile file) throws IOException { |
| | | // Consumer<List<WorkOrderWhiteExport>> consumer = (dataList) -> { |
| | | // try { |
| | | // this.updateWhite(dataList); |
| | |
| | | // 将读取到的每一行存入reportDetails集合中 |
| | | dataList.add(excel); |
| | | } |
| | | |
| | | @Override |
| | | public void doAfterAllAnalysed(AnalysisContext analysisContext) {} |
| | | public void doAfterAllAnalysed(AnalysisContext analysisContext) { |
| | | } |
| | | }).sheet().doRead(); |
| | | |
| | | if (CollectionUtils.isEmpty(dataList)) { |
| | | throw new RuntimeException("导入数据不能为空"); |
| | | } |
| | | boolean duplic = checkDuplic(dataList); |
| | | if(duplic) throw new RuntimeException("存在重复国标设备"); |
| | | //已存在的白名单 |
| | | Map<String, WorkOrderWhite> whiteMap = workOrderWhiteMapper.selectList().stream().collect(Collectors.toMap(WorkOrderWhite::getSerialNumber, Function.identity())); |
| | | if (duplic) throw new RuntimeException("存在重复国标设备"); |
| | | List<WorkOrderWhite> addList = new ArrayList<>(); |
| | | dataList.stream().forEach(item -> { |
| | | WorkOrderWhite white = new WorkOrderWhite(); |
| | |
| | | //备注 |
| | | white.setRemark(item.getRemark()); |
| | | String errorType = item.getErrorType(); |
| | | if(StringUtils.isEmpty(errorType)){ |
| | | throw new RuntimeException("国标码为"+item.getSerialNumber()+"的设备故障不能为空"); |
| | | if (StringUtils.isEmpty(errorType)) { |
| | | throw new RuntimeException("国标码为" + item.getSerialNumber() + "的设备故障不能为空"); |
| | | } |
| | | try { |
| | | List<String> errorDataList = new ArrayList<>(); |
| | | List<String> errorExcelList = Arrays.asList(item.getErrorType().split(",")); |
| | | errorExcelList.forEach(desc->{ |
| | | errorExcelList.forEach(desc -> { |
| | | //把中文转换为数据库存储格式 |
| | | String errorText = ErrorType.getValueByDescription(desc); |
| | | //找不到抛出异常 |
| | | if(errorText == null) throw new RuntimeException("国标码为"+item.getSerialNumber()+"的设备故障类型有误"); |
| | | if (errorText == null) |
| | | throw new RuntimeException("国标码为" + item.getSerialNumber() + "的设备故障类型有误"); |
| | | errorDataList.add(errorText); |
| | | }); |
| | | white.setErrorType(String.join(",", errorDataList)); |
| | | //如果已存在补充id |
| | | WorkOrderWhite whiteExsit = whiteMap.get(white.getSerialNumber()); |
| | | if(whiteExsit!=null) white.setId(whiteExsit.getId()); |
| | | addList.add(white); |
| | | } catch (Exception e) { |
| | | throw new RuntimeException("国标码为"+item.getSerialNumber()+"的设备故障类型有误"); |
| | | throw new RuntimeException("国标码为" + item.getSerialNumber() + "的设备故障类型有误"); |
| | | } |
| | | }); |
| | | if(!CollectionUtils.isEmpty(addList)) { |
| | | if (!CollectionUtils.isEmpty(addList)) { |
| | | workOrderWhiteMapper.deleteAll(); |
| | | workOrderWhiteMapper.insertBatch(addList); |
| | | } |
| | | return Result.ok(); |
| | | } |
| | | |
| | | /** |
| | | * 修改白名单 |
| | | * |
| | |
| | | //备注 |
| | | white.setRemark(item.getRemark()); |
| | | String errorType = item.getErrorType(); |
| | | if(StringUtils.isEmpty(errorType)){ |
| | | throw new RuntimeException("国标码为"+item.getSerialNumber()+"的设备故障不能为空"); |
| | | if (StringUtils.isEmpty(errorType)) { |
| | | throw new RuntimeException("国标码为" + item.getSerialNumber() + "的设备故障不能为空"); |
| | | } |
| | | try { |
| | | List<String> errorDataList = new ArrayList<>(); |
| | | List<String> errorExcelList = Arrays.asList(item.getErrorType().split(",")); |
| | | errorExcelList.forEach(desc->{ |
| | | errorExcelList.forEach(desc -> { |
| | | //把中文转换为数据库存储格式 |
| | | String errorText = ErrorType.getValueByDescription(desc); |
| | | //找不到抛出异常 |
| | | if(errorText == null) throw new RuntimeException("国标码为"+item.getSerialNumber()+"的设备故障类型有误"); |
| | | if (errorText == null) |
| | | throw new RuntimeException("国标码为" + item.getSerialNumber() + "的设备故障类型有误"); |
| | | errorDataList.add(errorText); |
| | | }); |
| | | white.setErrorType(String.join(",", errorDataList)); |
| | | if(!CollectionUtils.isEmpty(serialNumbers) && serialNumbers.contains(white.getSerialNumber())){ |
| | | if (!CollectionUtils.isEmpty(serialNumbers) && serialNumbers.contains(white.getSerialNumber())) { |
| | | updateList.add(white); |
| | | }else { |
| | | } else { |
| | | addList.add(white); |
| | | } |
| | | } catch (Exception e) { |
| | | throw new RuntimeException("国标码为"+item.getSerialNumber()+"的设备故障类型有误"); |
| | | throw new RuntimeException("国标码为" + item.getSerialNumber() + "的设备故障类型有误"); |
| | | } |
| | | }); |
| | | if(!CollectionUtils.isEmpty(addList)) workOrderWhiteMapper.insertBatch(addList); |
| | | if(!CollectionUtils.isEmpty(updateList)) workOrderWhiteMapper.updateBatch(updateList); |
| | | if (!CollectionUtils.isEmpty(addList)) workOrderWhiteMapper.insertBatch(addList); |
| | | if (!CollectionUtils.isEmpty(updateList)) workOrderWhiteMapper.updateBatch(updateList); |
| | | } |
| | | |
| | | /** |
| | | * 检查阈值 |
| | | * |
| | | * @param key 某阈值标识 |
| | | * @param value 接口获取到的值 |
| | | * @param key 某阈值标识 |
| | | * @param value 接口获取到的值 |
| | | * @param serialNumber 国标码 |
| | | * @param thresholds 阈值条件map |
| | | * @param compareType 比较方式:>= <= |
| | | * @param errorType 故障类型 |
| | | * @param thresholds 阈值条件map |
| | | * @param compareType 比较方式:>= <= |
| | | * @param errorType 故障类型 |
| | | * @param <T> |
| | | */ |
| | | @Override |
| | | public <T extends Comparable<T>> void check(String key, T value, String serialNumber, Map<String, YwThreshold> thresholds, WorkOrder workOrder, CompareType compareType,String errorType) { |
| | | public <T extends Comparable<T>> void check(String key, T value, String |
| | | serialNumber, Map<String, YwThreshold> thresholds, WorkOrder workOrder, CompareType compareType, String |
| | | errorType) { |
| | | Optional.ofNullable(value).ifPresentOrElse( |
| | | v -> { |
| | | YwThreshold ywThreshold = thresholds.get(key); |
| | |
| | | T thresholdAutoValue = parseThreshold(ywThreshold.getValueAuto(), value.getClass()); |
| | | //直接下发工单阈值 |
| | | T thresholdValue = parseThreshold(ywThreshold.getValue(), value.getClass()); |
| | | if("percent".equals(ywThreshold.getCountType())){ |
| | | if ("percent".equals(ywThreshold.getCountType())) { |
| | | if (thresholdAutoValue instanceof Float) { |
| | | thresholdAutoValue = (T) Float.valueOf(((Float) thresholdAutoValue) / 100f); |
| | | } |
| | |
| | | ); |
| | | } |
| | | |
| | | /** |
| | | * 所有白名单添加故障类型 |
| | | * |
| | | * @param workOrderWhite |
| | | */ |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public Result addBatch(WorkOrderWhite workOrderWhite) { |
| | | List<String> errorTypeListAdd = workOrderWhite.getErrorTypeList(); |
| | | List<WorkOrderWhite> whites = workOrderWhiteMapper.selectList(); |
| | | for (WorkOrderWhite white : whites) { |
| | | List<String> errorTypeList = Arrays.asList(white.getErrorType().split(",")); |
| | | for (String newError : errorTypeListAdd) { |
| | | if (errorTypeList.contains(newError)) { |
| | | continue; |
| | | } else { |
| | | errorTypeList.add(newError); |
| | | } |
| | | } |
| | | white.setErrorType(String.join(",", errorTypeList)); |
| | | } |
| | | if (!CollectionUtils.isEmpty(whites)) { |
| | | workOrderWhiteMapper.deleteAll(); |
| | | workOrderWhiteMapper.insertBatch(whites); |
| | | } |
| | | return Result.ok(); |
| | | } |
| | | |
| | | private <T extends Comparable<T>> T parseThreshold(String thresholdStr, Class<?> type) { |
| | | if (Integer.class.equals(type)) { |
| | | return (T) Integer.valueOf(thresholdStr); |