Procházet zdrojové kódy

自动检测机器是否故障,并添加报警信息

523096025 před 4 roky
rodič
revize
a3d245b124

+ 2 - 3
huimv-ql-farm/huimv-ql-environment/src/main/java/com/huimv/environment/controller/EnvironmentControlController.java

@@ -80,12 +80,11 @@ public class EnvironmentControlController {
     }
 
 
-//    @Scheduled(cron = "0 1/15 * * * ? ")
-    @RequestMapping(value = "/test")
+    @Scheduled(cron = "0 1/15 * * * ? ")
     public void test(){
         RestTemplate restTemplate = new RestTemplate();
         DeviceUpDataEntity[] forObject = restTemplate.getForObject("http://127.0.0.1:8085/environmentControl/findAllByTime", DeviceUpDataEntity[].class);
-        System.out.println(forObject);
+
         envControlService.save(forObject);
 
     }

+ 5 - 1
huimv-ql-farm/huimv-ql-environment/src/main/java/com/huimv/environment/repo/WarningInfoEntityRepo.java

@@ -3,8 +3,10 @@ package com.huimv.environment.repo;
 import com.huimv.environment.entity.WarningInfoEntity;
 import org.springframework.data.jpa.repository.JpaRepository;
 import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
+import org.springframework.data.jpa.repository.Modifying;
 import org.springframework.data.jpa.repository.Query;
 
+import javax.transaction.Transactional;
 import java.util.Date;
 import java.util.List;
 
@@ -13,7 +15,9 @@ public interface WarningInfoEntityRepo extends JpaRepository<WarningInfoEntity,
     List<WarningInfoEntity> findAllByShowStatusAndUploadTimeBetween(Integer showStatus,Date starTime, Date endTime);
 
 
-    @Query(nativeQuery = true,value = "update warning_info set show_status 1 where warning_type = 2 and show_status = 0")
+    @Transactional
+    @Modifying
+    @Query(nativeQuery = true,value = "update warning_info set show_status = 1 where warning_type = 1  and show_status = 0")
     void updateShowStatusByWarningType();
 
 }

+ 12 - 6
huimv-ql-farm/huimv-ql-environment/src/main/java/com/huimv/environment/service/impl/EnvironmentControlServiceImpl.java

@@ -333,9 +333,12 @@ public class EnvironmentControlServiceImpl implements IEnvironmentControlService
     @DS("master")
     public void save(DeviceUpDataEntity[] forObject) {
 
+        //把之前的报警信息清除
+        warningInfoEntityRepo.updateShowStatusByWarningType();
 
+        //查找全部栋舍
         List<FarmSm> all = farmSmRepository.findAll();
-        warningInfoEntityRepo.updateShowStatusByWarningType();
+        //没有信息,全部栋舍无数据,都加入到报警表中
         if (forObject == null){
             for (FarmSm farmSm : all) {
                 WarningInfoEntity warningInfoEntity = new WarningInfoEntity();
@@ -347,6 +350,11 @@ public class EnvironmentControlServiceImpl implements IEnvironmentControlService
                 warningInfoEntityRepo.save(warningInfoEntity);
             }
         }else {
+            //同步数据
+            for (DeviceUpDataEntity deviceUpDataEntity : forObject) {
+                deviceUpDataEntityRepo.save(deviceUpDataEntity);
+            }
+            //拿出没有数据的栋舍集合
             List list1= new ArrayList();
             List list2= new ArrayList();
             for (DeviceUpDataEntity deviceUpDataEntity : forObject) {
@@ -356,6 +364,8 @@ public class EnvironmentControlServiceImpl implements IEnvironmentControlService
                 list2.add(farmSm.getLqid());
             }
             Collection<String> subtract = CollectionUtils.subtract(list2, list1);
+
+            //又没数据的栋舍就加入到报警表中,没有直接返回
             if (subtract == null){
                 return;
             }else {
@@ -371,11 +381,7 @@ public class EnvironmentControlServiceImpl implements IEnvironmentControlService
             }
         }
 
-        if (forObject != null){
-            for (DeviceUpDataEntity deviceUpDataEntity : forObject) {
-                deviceUpDataEntityRepo.save(deviceUpDataEntity);
-            }
-        }
+
 
 
     }