From a0a525d59f1cb3167a54af9309c8dab162e89005 Mon Sep 17 00:00:00 2001 From: whycxzp <glperry@163.com> Date: 星期四, 12 六月 2025 19:23:32 +0800 Subject: [PATCH] 优化巡检和维修器件的图片路径 --- src/main/java/com/whyc/schedule/AlarmInspectionSchedule.java | 135 +++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 135 insertions(+), 0 deletions(-) diff --git a/src/main/java/com/whyc/schedule/AlarmInspectionSchedule.java b/src/main/java/com/whyc/schedule/AlarmInspectionSchedule.java new file mode 100644 index 0000000..a2e1373 --- /dev/null +++ b/src/main/java/com/whyc/schedule/AlarmInspectionSchedule.java @@ -0,0 +1,135 @@ +package com.whyc.schedule; + +import com.whyc.pojo.db_pwrdev_alarm.PwrdevAlarm; +import com.whyc.pojo.web_site.AlarmInspection; +import com.whyc.pojo.web_site.AlarmInspectionId; +import com.whyc.service.*; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.scheduling.annotation.EnableScheduling; +import org.springframework.scheduling.annotation.Scheduled; +import org.springframework.stereotype.Component; +import org.springframework.transaction.annotation.Transactional; + +import java.util.ArrayList; +import java.util.List; +import java.util.stream.Collectors; + +/** + * 鏈変袱涓畾鏃朵换鍔�:1.鍛婅浜х敓,鍔犲叆鍒板贰妫�瀹炴椂琛�,2.鍛婅鏄惁娑堝け,鍚屾鍒板贰妫�瀹炴椂琛� + */ +@EnableScheduling +@Component +public class AlarmInspectionSchedule { + + @Autowired + private AlarmInspectionService inspectionService; + + @Autowired + private AlarmInspectionIdService alarmIdService; + + @Autowired + private PwrdevAlarmService powerAlarmService; + + @Autowired + private DevalarmDataService devAlarmService; + + @Autowired + private BattalarmDataService battAlarmService; + + + /** + * 鏁版嵁4绉掗挓鑾峰彇涓�娆� + * 鍛婅浜х敓,鍔犲叆鍒板贰妫�瀹炴椂琛� + * */ + @Scheduled(cron = "0/4 * * * * ? ") + @Transactional + public void getAndRecord(){ + AlarmInspectionId alarmInspectionId = alarmIdService.get(); + List<AlarmInspection> inspectionList = new ArrayList<>(); + //鏌ヨ鏂扮殑鐢垫簮鍛婅 + List<AlarmInspection> powerAlarmList = powerAlarmService.getListGreatThan(alarmInspectionId.getPowerAlarmId()); + //鏌ヨ鏂扮殑璁惧鍛婅 + List<AlarmInspection> devAlarmList = devAlarmService.getListGreatThan(alarmInspectionId.getDevAlarmId()); + //鏌ヨ鏂扮殑鐢垫睜鍛婅 + List<AlarmInspection> battAlarmList = battAlarmService.getListGreatThan(alarmInspectionId.getBattAlarmId()); + + inspectionList.addAll(powerAlarmList); + inspectionList.addAll(devAlarmList); + inspectionList.addAll(battAlarmList); + if(inspectionList.size() != 0) { + //鎻掑叆鍒板贰妫�瀹炴椂琛� + inspectionService.addBatch(inspectionList); + + //鑾峰彇鏈鎴鐨勫憡璀d,骞舵洿鏂板贰妫�鍛婅鐨勫憡璀d + Long powerAlmId = powerAlarmList.get(powerAlarmList.size() - 1).getAlmNum(); + Long devAlmId = devAlarmList.get(devAlarmList.size() - 1).getAlmNum(); + Long battAlmId = battAlarmList.get(battAlarmList.size() - 1).getAlmNum(); + + alarmInspectionId.setPowerAlarmId(powerAlmId); + alarmInspectionId.setDevAlarmId(devAlmId); + alarmInspectionId.setBattAlarmId(battAlmId); + alarmIdService.update(alarmInspectionId); + } + } + + /** + * 鏁版嵁4绉掗挓鑾峰彇涓�娆� + * 鍛婅鏄惁娑堝け,鍚屾鍒板贰妫�瀹炴椂琛� + * */ + @Scheduled(cron = "0/4 * * * * ? ") + public void checkAlarm(){ + List<AlarmInspection> alarmExistList =inspectionService.getAlarmExistList(); + //鎸夌數婧�,璁惧,鐢垫睜鍛婅杩涜鍒嗙被,鍐嶅垎鍒繘琛屾煡璇� + List<AlarmInspection> powerAlarmInspectionList = alarmExistList.stream().filter(alarmInspection -> alarmInspection.getType() == 1).collect(Collectors.toList()); + List<Long> powerAlarmNumList = powerAlarmInspectionList.stream().map(AlarmInspection::getAlmNum).collect(Collectors.toList()); + + List<AlarmInspection> devAlarmInspectionList = alarmExistList.stream().filter(alarmInspection -> alarmInspection.getType() == 2).collect(Collectors.toList()); + List<Long> devAlarmNumList = devAlarmInspectionList.stream().map(AlarmInspection::getAlmNum).collect(Collectors.toList()); + + List<AlarmInspection> battAlarmInspectionList = alarmExistList.stream().filter(alarmInspection -> alarmInspection.getType() == 3).collect(Collectors.toList()); + List<Long> battAlarmNumList = battAlarmInspectionList.stream().map(AlarmInspection::getAlmNum).collect(Collectors.toList()); + + //鍛婅娑堝け浜嗙殑宸℃瀹炴椂琛╥d + List<Long> notExistIdList = new ArrayList<>(); + if(powerAlarmNumList.size() != 0){ + //鏌ヨid鏄惁杩樺瓨鍦� + List<Long> powerNumListInDB = powerAlarmService.getNumListInDB(powerAlarmNumList); + for (AlarmInspection alarm : powerAlarmInspectionList) { + Long almNum = alarm.getAlmNum(); + if(!powerNumListInDB.contains(almNum)){ + notExistIdList.add(alarm.getId()); + } + } + } + + if(devAlarmNumList.size() != 0){ + //鏌ヨid鏄惁杩樺瓨鍦� + List<Long> devNumListInDB = devAlarmService.getNumListInDB(devAlarmNumList); + for (AlarmInspection alarm : devAlarmInspectionList) { + Long almNum = alarm.getAlmNum(); + if(!devNumListInDB.contains(almNum)){ + notExistIdList.add(alarm.getId()); + } + } + } + + if(battAlarmNumList.size() != 0){ + //鏌ヨid鏄惁杩樺瓨鍦� + List<Long> battNumListInDB = battAlarmService.getNumListInDB(battAlarmNumList); + for (AlarmInspection alarm : battAlarmInspectionList) { + Long almNum = alarm.getAlmNum(); + if(!battNumListInDB.contains(almNum)){ + notExistIdList.add(alarm.getId()); + } + } + } + + if(notExistIdList.size() != 0){ + //鏇存柊宸℃瀹炴椂琛� + inspectionService.updateIsExist(notExistIdList); + } + + } + + +} -- Gitblit v1.9.1