Parcourir la source

修改首页报警信息

523096025 il y a 4 ans
Parent
commit
166b474557
14 fichiers modifiés avec 330 ajouts et 12 suppressions
  1. 23 1
      huimv-ql-farm/huimv-ql-environment/src/main/java/com/huimv/environment/controller/EnvironmentControlController.java
  2. 5 3
      huimv-ql-farm/huimv-ql-environment/src/main/java/com/huimv/environment/controller/WarningParameterController.java
  3. 3 0
      huimv-ql-farm/huimv-ql-environment/src/main/java/com/huimv/environment/repo/DeviceUpDataEntityRepo.java
  4. 6 0
      huimv-ql-farm/huimv-ql-environment/src/main/java/com/huimv/environment/repo/WarningInfoEntityRepo.java
  5. 8 0
      huimv-ql-farm/huimv-ql-environment/src/main/java/com/huimv/environment/service/IEnvironmentControlService.java
  6. 70 0
      huimv-ql-farm/huimv-ql-environment/src/main/java/com/huimv/environment/service/impl/EnvironmentControlServiceImpl.java
  7. 45 0
      huimv-ql-farm/huimv-ql-production/src/main/java/com/huimv/production/controller/WarningParameterController.java
  8. 2 0
      huimv-ql-farm/huimv-ql-production/src/main/java/com/huimv/production/repo/WarningInfoEntityRepo.java
  9. 10 0
      huimv-ql-farm/huimv-ql-production/src/main/java/com/huimv/production/repo/WarningParameterEntityRepo.java
  10. 27 0
      huimv-ql-farm/huimv-ql-production/src/main/java/com/huimv/production/service/WarningParameterService.java
  11. 1 2
      huimv-ql-farm/huimv-ql-production/src/main/java/com/huimv/production/service/impl/WarningInfoServiceImpl.java
  12. 117 0
      huimv-ql-farm/huimv-ql-production/src/main/java/com/huimv/production/service/impl/WarningParameterServiceImpl.java
  13. 11 4
      huimv-ql-farm/huimv-ql-production/src/main/java/com/huimv/production/task/WarningParameterTask.java
  14. 2 2
      huimv-ql-farm/huimv-ql-production/src/main/resources/application.properties

+ 23 - 1
huimv-ql-farm/huimv-ql-environment/src/main/java/com/huimv/environment/controller/EnvironmentControlController.java

@@ -2,10 +2,15 @@ package com.huimv.environment.controller;
 
 
 import com.huimv.common.result.Result;
+import com.huimv.environment.entity.DeviceUpDataEntity;
+import com.huimv.environment.entity.WarningInfoEntity;
 import com.huimv.environment.service.IEnvironmentControlService;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.scheduling.annotation.Scheduled;
 import org.springframework.web.bind.annotation.*;
+import org.springframework.web.client.RestTemplate;
+
+import java.util.List;
 
 /**
  * @Project : huimv.shiwan
@@ -55,7 +60,7 @@ public class EnvironmentControlController {
 
 
     //定时检测数据库中是否有数据
-    @Scheduled(cron = "0 0 23 1 * ? ")
+    @Scheduled(cron = "0 0 5 * * ? ")
 //    @RequestMapping(value = "/examine")
     public void examine(){
         envControlService.examine();
@@ -67,4 +72,21 @@ public class EnvironmentControlController {
        return envControlService.findExamine();
     }
 
+
+    //查找当天最新的10条数据
+    @RequestMapping(value = "/findAllByTime")
+    public List<DeviceUpDataEntity> findAllByTime(){
+        return envControlService.findAllByTime();
+    }
+
+
+//    @Scheduled(cron = "0 1/15 * * * ? ")
+    @RequestMapping(value = "/test")
+    public void test(){
+        RestTemplate restTemplate = new RestTemplate();
+        DeviceUpDataEntity[] forObject = restTemplate.getForObject("http://127.0.0.1:8085/environmentControl/findAllByTime", DeviceUpDataEntity[].class);
+        envControlService.save(forObject);
+
+    }
+
 }

+ 5 - 3
huimv-ql-farm/huimv-ql-environment/src/main/java/com/huimv/environment/controller/WarningParameterController.java

@@ -1,12 +1,9 @@
 package com.huimv.environment.controller;
 
-import com.huimv.environment.constant.CommonConstant;
 import com.huimv.environment.entity.WarningParameter;
 import com.huimv.environment.result.Result;
 import com.huimv.environment.service.WarningParameterService;
 import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.data.domain.Page;
-import org.springframework.util.StringUtils;
 import org.springframework.web.bind.annotation.*;
 
 @RestController
@@ -42,5 +39,10 @@ public class WarningParameterController {
         return service.findAll(name, pageNum, pageSize);
     }
 
+//    @RequestMapping("/findAllLimit")
+//    public Result findAllLimit(String name, Integer pageNum, Integer pageSize) {
+//        return service.findAll(name, pageNum, pageSize);
+//    }
+
 
 }

+ 3 - 0
huimv-ql-farm/huimv-ql-environment/src/main/java/com/huimv/environment/repo/DeviceUpDataEntityRepo.java

@@ -28,6 +28,9 @@ public interface DeviceUpDataEntityRepo extends JpaRepository<DeviceUpDataEntity
     @Query(nativeQuery = true,value = "SELECT  any_value(`timestamp`),device_id FROM `device_up_data` WHERE DATE_FORMAT(TIMESTAMP,'%Y-%m-%d')=DATE_FORMAT(?1,'%Y-%m-%d') GROUP BY device_id")
     List<Map<String,String>> findAllByIdAfter(String today);
 
+    @Query(nativeQuery = true,value = "SELECT * FROM device_up_data WHERE CONVERT(TIMESTAMP,DATETIME) BETWEEN ?1 AND ?2")
+    List<DeviceUpDataEntity> findAllByTimestampBetween(String startTime,String endTime);
+
 
 
 }

+ 6 - 0
huimv-ql-farm/huimv-ql-environment/src/main/java/com/huimv/environment/repo/WarningInfoEntityRepo.java

@@ -3,6 +3,7 @@ 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.Query;
 
 import java.util.Date;
 import java.util.List;
@@ -10,4 +11,9 @@ import java.util.List;
 public interface WarningInfoEntityRepo extends JpaRepository<WarningInfoEntity, Integer>, JpaSpecificationExecutor<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")
+    void updateShowStatusByWarningType();
+
 }

+ 8 - 0
huimv-ql-farm/huimv-ql-environment/src/main/java/com/huimv/environment/service/IEnvironmentControlService.java

@@ -1,6 +1,10 @@
 package com.huimv.environment.service;
 
 import com.huimv.common.result.Result;
+import com.huimv.environment.entity.DeviceUpDataEntity;
+import com.huimv.environment.entity.WarningInfoEntity;
+
+import java.util.List;
 
 public interface IEnvironmentControlService {
 
@@ -20,4 +24,8 @@ public interface IEnvironmentControlService {
     void examine();
 
     Result findExamine();
+
+    List<DeviceUpDataEntity> findAllByTime();
+
+    void save(DeviceUpDataEntity[] forObject);
 }

+ 70 - 0
huimv-ql-farm/huimv-ql-environment/src/main/java/com/huimv/environment/service/impl/EnvironmentControlServiceImpl.java

@@ -313,6 +313,76 @@ public class EnvironmentControlServiceImpl implements IEnvironmentControlService
         return new Result(ResultCode.SUCCESS,list);
     }
 
+    @Override
+    @DS("slave")
+    public List<DeviceUpDataEntity> findAllByTime() {
+
+
+        Date date = new Date();
+        DateTime dateTime = cn.hutool.core.date.DateUtil.offsetMinute(date, -15);
+        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+        String format = simpleDateFormat.format(date);
+        String format1 = simpleDateFormat.format(dateTime);
+
+        List<DeviceUpDataEntity> allByTimestampBetween = deviceUpDataEntityRepo.findAllByTimestampBetween(format1, format);
+        return allByTimestampBetween;
+
+    }
+
+    @Override
+    @DS("master")
+    public void save(DeviceUpDataEntity[] forObject) {
+        warningInfoEntityRepo.updateShowStatusByWarningType();
+        List<FarmSm> all = farmSmRepository.findAll();
+
+        if (forObject == null){
+            for (FarmSm farmSm : all) {
+                WarningInfoEntity warningInfoEntity = new WarningInfoEntity();
+                warningInfoEntity.setLQID(farmSm.getLqid());
+                warningInfoEntity.setType("设备故障");
+                warningInfoEntity.setUploadTime(new Date());
+                warningInfoEntity.setShowStatus(0);
+                warningInfoEntity.setWarningType(1);
+                warningInfoEntityRepo.save(warningInfoEntity);
+            }
+
+        }else {
+            List list1= new ArrayList();
+            List list2= new ArrayList();
+            for (DeviceUpDataEntity deviceUpDataEntity : forObject) {
+                list1.add(deviceUpDataEntity.getDeviceId());
+            }
+            for (FarmSm farmSm : all) {
+                list2.add(farmSm.getLqid());
+            }
+
+            Collection<String> subtract = CollectionUtils.subtract(list2, list1);
+            if (subtract == null){
+                warningInfoEntityRepo.updateShowStatusByWarningType();
+                return;
+            }else {
+                for (String s : subtract) {
+                    WarningInfoEntity warningInfoEntity = new WarningInfoEntity();
+                    warningInfoEntity.setLQID(s);
+                    warningInfoEntity.setType("设备故障,当天无数据上传");
+                    warningInfoEntity.setUploadTime(new Date());
+                    warningInfoEntity.setWarningType(1);
+                    warningInfoEntity.setShowStatus(0);
+                    warningInfoEntityRepo.save(warningInfoEntity);
+                }
+            }
+        }
+
+        if (forObject != null){
+            for (DeviceUpDataEntity deviceUpDataEntity : forObject) {
+                deviceUpDataEntityRepo.save(deviceUpDataEntity);
+            }
+        }
+
+
+    }
+
+
 
 
   /*  @Override

+ 45 - 0
huimv-ql-farm/huimv-ql-production/src/main/java/com/huimv/production/controller/WarningParameterController.java

@@ -0,0 +1,45 @@
+package com.huimv.production.controller;
+
+
+import com.huimv.production.domain.WarningParameter;
+import com.huimv.production.result.Result;
+import com.huimv.production.service.WarningParameterService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+@RestController
+@RequestMapping("/warningParameter")
+public class WarningParameterController {
+
+    @Autowired
+    private WarningParameterService service;
+
+    @RequestMapping("/add")
+    public Result add(WarningParameter entity) {
+        return service.add(entity);
+    }
+
+    @RequestMapping("/remove")
+    public Result remove(Integer[] ids) {
+        return service.remove(ids);
+    }
+
+    @RequestMapping("/update")
+    public Result update(WarningParameter entity) {
+        return service.update(entity);
+    }
+
+    @RequestMapping("/findAllById")
+    public Result findAllById(Integer id) {
+        return service.findAllById(id);
+    }
+
+
+    @RequestMapping("/findAll")
+    public Result findAll(String name, Integer pageNum, Integer pageSize) {
+        return service.findAll(name, pageNum, pageSize);
+    }
+
+
+}

+ 2 - 0
huimv-ql-farm/huimv-ql-production/src/main/java/com/huimv/production/repo/WarningInfoEntityRepo.java

@@ -15,4 +15,6 @@ public interface WarningInfoEntityRepo extends JpaRepository<WarningInfoEntity,
 
     List<WarningInfoEntity> findAllByShowStatus(int showStatus);
 
+    @Query(nativeQuery = true,value = "UPDATE warning_info SET show_status = 1 WHERE type = ?1 AND show_status = 0")
+    void updatePreviousShowStatusByType(String type);
 }

+ 10 - 0
huimv-ql-farm/huimv-ql-production/src/main/java/com/huimv/production/repo/WarningParameterEntityRepo.java

@@ -3,7 +3,17 @@ package com.huimv.production.repo;
 import com.huimv.production.domain.WarningParameter;
 import org.springframework.data.jpa.repository.JpaRepository;
 import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
+import org.springframework.data.jpa.repository.Query;
 
+import java.util.List;
+
+/**
+ * @author yinhao
+ * @since 2021/5/31 10:42
+ */
 public interface WarningParameterEntityRepo extends JpaRepository<WarningParameter, Integer>, JpaSpecificationExecutor<WarningParameter> {
 
+    @Query(nativeQuery = true ,value = "select * from warning_parameter where parameter_name like %?1% limit ?2 , ?3")
+    List<WarningParameter> findAll(String name, Integer startPage, Integer pageSize);
+
 }

+ 27 - 0
huimv-ql-farm/huimv-ql-production/src/main/java/com/huimv/production/service/WarningParameterService.java

@@ -0,0 +1,27 @@
+package com.huimv.production.service;
+
+
+import com.huimv.production.domain.WarningParameter;
+import com.huimv.production.result.Result;
+
+/**
+ * @author yinhao
+ * @since 2021/5/31 10:44
+ */
+public interface WarningParameterService {
+
+   //添加
+   Result add(WarningParameter entity);
+
+   //添加
+   Result remove(Integer[] ids);
+
+   //添加
+   Result update(WarningParameter entity);
+
+   //查询
+  Result findAll(String name, Integer pageNum, Integer pageSize);
+
+   //根据id查找
+   Result findAllById(Integer id);
+}

+ 1 - 2
huimv-ql-farm/huimv-ql-production/src/main/java/com/huimv/production/service/impl/WarningInfoServiceImpl.java

@@ -50,8 +50,7 @@ public class WarningInfoServiceImpl implements WarningInfoService {
 
                 String name = byLqid.getName();
                 String type = warningInfoEntity.getType();
-                Double temperature = warningInfoEntity.getTemperature();
-                String str = type+"报警,当前温度为:"+temperature+" ℃";
+                String str = type;
 
                 map.put("farmName",name);
                 map.put("time",simpleDateFormat.format(uploadTime));

+ 117 - 0
huimv-ql-farm/huimv-ql-production/src/main/java/com/huimv/production/service/impl/WarningParameterServiceImpl.java

@@ -0,0 +1,117 @@
+package com.huimv.production.service.impl;
+
+
+import com.huimv.production.domain.WarningParameter;
+import com.huimv.production.repo.WarningParameterEntityRepo;
+import com.huimv.production.result.Result;
+import com.huimv.production.result.ResultStatus;
+import com.huimv.production.service.WarningParameterService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+import org.springframework.util.StringUtils;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * @author yinhao
+ * @since 2021/5/28 09:41
+ */
+@Service
+public class WarningParameterServiceImpl implements WarningParameterService {
+
+    @Autowired
+    private WarningParameterEntityRepo rep;
+
+    @Override
+    public Result add(WarningParameter entity) {
+        if (entity == null) {
+            return new Result(10002, ResultStatus.addNull);
+        }
+
+        Double thresholdValue = entity.getThresholdValue();
+        if (StringUtils.isEmpty(entity.getParameterName())) {
+            return new Result(10003, "参数名称不能为空!");
+        }
+        if (thresholdValue == null || thresholdValue < 0) {
+            return new Result(10003, "阈值有误,请检查!");
+        }
+        try {
+            rep.save(entity);
+            return new Result(10000, ResultStatus.addSuccess);
+        } catch (Exception e) {
+            return new Result(10001, ResultStatus.addFailed);
+        }
+    }
+
+    @Override
+    public Result remove(Integer[] ids) {
+        if (ids == null || ids.length == 0) {
+            return new Result(10002, ResultStatus.deleteNull);
+        }
+        try {
+            for (Integer id : ids) {
+                rep.deleteById(id);
+            }
+            return new Result(10000, ResultStatus.deleteSuccess);
+        } catch (Exception e) {
+            return new Result(10001, ResultStatus.deleteFailed);
+        }
+    }
+
+    @Override
+    public Result update(WarningParameter entity) {
+        if (entity == null) {
+            return new Result(10002, ResultStatus.updateNull);
+        }
+        Double thresholdValue = entity.getThresholdValue();
+        if (StringUtils.isEmpty(entity.getParameterName())) {
+            return new Result(10003, "参数名称不能为空!");
+        }
+        if (thresholdValue == null || thresholdValue < 0) {
+            return new Result(10003, "阈值有误,请检查!");
+        }
+        try {
+            rep.save(entity);
+            return new Result(10000, ResultStatus.updateSuccess);
+        } catch (Exception e) {
+            return new Result(10001, ResultStatus.updateFailed);
+        }
+    }
+
+    @Override
+	public Result findAll(String name ,Integer pageNum , Integer pageSize) {
+		try {
+			Map map = new HashMap(16);
+			int size = rep.findAll().size() ;
+			if (pageNum == null) {
+			    pageNum = 1;
+            }
+			if (pageSize == null) {
+			    pageSize = 10;
+            }
+			if (name == null ) {
+			    name = "";
+            }
+			Integer startPage = (pageNum-1) * pageSize;
+			List<WarningParameter> all = rep.findAll(name,startPage,pageSize);
+			map.put("total",size);
+			map.put("totalPageNum",(size  +  pageSize  - 1) / pageSize);
+			map.put("data",all);
+			return new Result(10000,ResultStatus.findSuccess,map);
+		}catch (Exception e){
+			return new Result(10001,ResultStatus.findFailed,null);
+		}
+	}
+
+	@Override
+	public Result findAllById(Integer id) {
+		try {
+			WarningParameter entity = rep.findById(id).get();
+			return new Result(10000,ResultStatus.findSuccess,entity);
+		}catch (Exception e){
+			return new Result(10001,ResultStatus.findFailed,null);
+		}
+	}
+}

+ 11 - 4
huimv-ql-farm/huimv-ql-production/src/main/java/com/huimv/production/task/WarningParameterTask.java

@@ -7,6 +7,7 @@ import org.springframework.context.annotation.Configuration;
 import org.springframework.scheduling.annotation.EnableScheduling;
 import org.springframework.scheduling.annotation.Scheduled;
 
+import javax.transaction.Transactional;
 import java.util.ArrayList;
 import java.util.Date;
 import java.util.List;
@@ -40,6 +41,7 @@ public class WarningParameterTask {
     @Autowired
     private WarningParameterEntityRepo warningParameterEntityRepo;
 
+    @Transactional(rollbackOn = Throwable.class)
     @Scheduled(cron = "0 0 0/12 * * ?")
 //    @Scheduled(cron = "0 41 17 * * ?")
     public void warningTask() {
@@ -63,11 +65,14 @@ public class WarningParameterTask {
                     .anyMatch(warningParameter -> warningParameter.getParameterName().equals(s.getName()) && warningParameter.getThresholdValue() >= Double.parseDouble(s.getData())))
                     .collect(Collectors.toList());
 
+
             for (IndexParameter2Entity indexParameter2Entity : collect1) {
                 WarningInfoEntity warningInfoEntity = new WarningInfoEntity();
                 warningInfoEntity.setUploadTime(new Date());
                 warningInfoEntity.setWarningType(3);
-                warningInfoEntity.setType("本地数据的 " + indexParameter2Entity.getName() + " 参数小于阈值,请核查!");
+                String type = "本地数据的 " + indexParameter2Entity.getName() + " 参数小于阈值";
+                warningInfoEntity.setType(type);
+                warningInfoEntityRepo.updatePreviousShowStatusByType(type);
                 warningInfoEntityRepo.save(warningInfoEntity);
             }
 
@@ -75,7 +80,7 @@ public class WarningParameterTask {
 
             List<WarningInfoEntity> list = new ArrayList<>();
             for (IndexParameter2Entity indexParameter2Entity : collect) {
-                List<WarningInfoEntity> warningInfoEntityList = warningInfoEntityRepo.findDataTypeLikeLeNow("本地数据的 " + indexParameter2Entity.getName(),date);
+                List<WarningInfoEntity> warningInfoEntityList = warningInfoEntityRepo.findDataTypeLikeLeNow("本地数据的 " + indexParameter2Entity.getName(), date);
                 list.addAll(warningInfoEntityList);
             }
             for (WarningInfoEntity warningInfoEntity : list) {
@@ -99,7 +104,9 @@ public class WarningParameterTask {
                 WarningInfoEntity warningInfoEntity = new WarningInfoEntity();
                 warningInfoEntity.setUploadTime(new Date());
                 warningInfoEntity.setWarningType(3);
-                warningInfoEntity.setType("ERP数据的 " + indexParameter2Entity.getName() + " 参数小于阈值,请核查!");
+                String type = "ERP数据的 " + indexParameter2Entity.getName() + " 参数小于阈值!";
+                warningInfoEntity.setType(type);
+                warningInfoEntityRepo.updatePreviousShowStatusByType(type);
                 warningInfoEntityRepo.save(warningInfoEntity);
             }
 
@@ -107,7 +114,7 @@ public class WarningParameterTask {
 
             List<WarningInfoEntity> list = new ArrayList<>();
             for (IndexParameterEntity indexParameterEntity : collect) {
-                List<WarningInfoEntity> warningInfoEntityList = warningInfoEntityRepo.findDataTypeLikeLeNow("ERP数据的 " + indexParameterEntity.getName(),date);
+                List<WarningInfoEntity> warningInfoEntityList = warningInfoEntityRepo.findDataTypeLikeLeNow("ERP数据的 " + indexParameterEntity.getName(), date);
                 list.addAll(warningInfoEntityList);
             }
             for (WarningInfoEntity warningInfoEntity : list) {

+ 2 - 2
huimv-ql-farm/huimv-ql-production/src/main/resources/application.properties

@@ -5,13 +5,13 @@
 #spring.profiles.active=haiyan-demo1
 #spring.profiles.active=haiyan-demo2
 #spring.profiles.active=haiyan-demo3
-spring.profiles.active=haiyan-demo4
+#spring.profiles.active=haiyan-demo4
 #spring.profiles.active=haiyan-demo5
 #spring.profiles.active=haiyan-demo6
 #spring.profiles.active=ycg-demo1
 #spring.profiles.active=ycg-demo2
 #spring.profiles.active=ycg-demo3
-#spring.profiles.active=ycg-demo4
+spring.profiles.active=ycg-demo4
 #spring.profiles.active=ycg-demo5
 #spring.profiles.active=ycg-demo6