| | |
| | | log.info("【出库超时预警】:没有暂存的医废记录,跳过定时任务执行"); |
| | | return; |
| | | } |
| | | |
| | | //查询所有出库超时预警 |
| | | List<MwWarningRecord> warningRecordList = mwWarningRecordService.lambdaQuery() |
| | | .eq(MwWarningRecord::getType, WarningTypeEnum.CHECKOUT_TIMEOUT_WARNING.getCode()) |
| | | .list(); |
| | | // 遍历配置项并处理预警 |
| | | for (MwWarningConfigItem configItem : configItems) { |
| | | // 过滤出需要预警的记录 |
| | | List<MwCollectRecord> recordList = collectRecordList.stream() |
| | | .filter(item -> item.getWasteType().equals(configItem.getWasteType()) && |
| | | DateUtils.timeDistanceHour(new Date(), item.getCollectTime()) > configItem.getValue()) |
| | | DateUtils.timeDistanceHour(new Date(), item.getCollectTime()) |
| | | >= configItem.getValue()) |
| | | .collect(Collectors.toList()); |
| | | |
| | | if (CollUtils.isEmpty(recordList)) { |
| | |
| | | } |
| | | |
| | | // 创建预警记录并保存 |
| | | List<MwWarningRecord> warningRecordList = recordList.stream().map(item -> { |
| | | Long id = item.getId(); |
| | | String medicalWasteNumber = item.getMedicalWasteNumber(); |
| | | String hospitalName = item.getHospitalName(); |
| | | String msg = String.format("%s医废超过%d小时未出库", item.getWasteTypeStr(), configItem.getValue()); |
| | | String currentValue = String.valueOf(DateUtils.timeDistanceHour(new Date(), item.getCollectTime())); |
| | | Long departmentId = item.getDepartmentId(); |
| | | String configValue = configItem.getValue().toString(); |
| | | return getMwWarningRecord(WarningTypeEnum.CHECKOUT_TIMEOUT_WARNING.getCode(), id, medicalWasteNumber, hospitalName, msg, departmentId, currentValue, configValue); |
| | | }).collect(Collectors.toList()); |
| | | List<MwWarningRecord> warningRecordSaveList = recordList.stream().map(item -> { |
| | | long count = warningRecordList.stream().filter(record -> record.getWarningTargetId().equals(item.getId())).count(); |
| | | if (count == 0L) { |
| | | Long id = item.getId(); |
| | | String medicalWasteNumber = item.getMedicalWasteNumber(); |
| | | String hospitalName = item.getHospitalName(); |
| | | String msg = String.format("%s医废超过%d小时未出库", item.getWasteTypeStr(), configItem.getValue()); |
| | | String currentValue = String.valueOf(DateUtils.timeDistanceHour(new Date(), item.getCollectTime())); |
| | | Long departmentId = item.getDepartmentId(); |
| | | String configValue = configItem.getValue().toString(); |
| | | return getMwWarningRecord(WarningTypeEnum.CHECKOUT_TIMEOUT_WARNING.getCode(), id, medicalWasteNumber, hospitalName, msg, departmentId, currentValue, configValue); |
| | | } |
| | | return null; |
| | | }).filter(Objects::nonNull).collect(Collectors.toList()); |
| | | |
| | | // 批量保存预警记录 |
| | | if (!warningRecordList.isEmpty()) { |
| | | mwWarningRecordService.saveBatch(warningRecordList); |
| | | if (!warningRecordSaveList.isEmpty()) { |
| | | mwWarningRecordService.saveBatch(warningRecordSaveList); |
| | | } |
| | | } |
| | | } |
| | |
| | | warningRecord.setNormalRange(normalRange); |
| | | warningRecord.setStatus(WarningStatusEnum.UNRESOLVED.getCode()); |
| | | warningRecord.setWarnTime(new Date()); |
| | | warningRecord.setCreateTime(new Date()); |
| | | return warningRecord; |
| | | } |
| | | |