Bläddra i källkod

参数阈值报警

yinhao 4 år sedan
förälder
incheckning
a57d649ee8

+ 2 - 0
huimv-ql-farm/huimv-ql-environment/src/main/java/com/huimv/environment/HuimvEnvironmentApplication.java

@@ -5,7 +5,9 @@ import org.springframework.boot.SpringApplication;
 import org.springframework.boot.autoconfigure.SpringBootApplication;
 import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
 import org.springframework.data.jpa.repository.config.EnableJpaAuditing;
+import org.springframework.scheduling.annotation.EnableScheduling;
 
+@EnableScheduling
 //自动格式化返回时间
 @EnableJpaAuditing
 // 多数据源

+ 15 - 0
huimv-ql-farm/huimv-ql-environment/src/main/java/com/huimv/environment/constant/CommonConstant.java

@@ -0,0 +1,15 @@
+package com.huimv.environment.constant;
+
+public class CommonConstant {
+    //性别 0-女 1-男
+    public static final Integer GENDER_FEMALE = 0;
+    public static final Integer GENDER_MALE = 1;
+
+    //默认分页
+    //初始页面
+    public static final Integer PAGE_NUM = 1;
+    public static final String PAGE_NUM_STR = "1";
+    //一页数据量
+    public static final Integer PAGE_SIZE = 20;
+    public static final String PAGE_SIZE_STR = "20";
+}

+ 28 - 18
huimv-ql-farm/huimv-ql-environment/src/main/java/com/huimv/environment/controller/WarningParameterController.java

@@ -1,37 +1,47 @@
 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.web.bind.annotation.CrossOrigin;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RestController;
+import org.springframework.data.domain.Page;
+import org.springframework.util.StringUtils;
+import org.springframework.web.bind.annotation.*;
 
 @RestController
 @CrossOrigin
-@RequestMapping("/WarningParameter")
+@RequestMapping("/warningParameter")
 public class WarningParameterController {
 
-	@Autowired
-	private WarningParameterService service;
+    @Autowired
+    private WarningParameterService service;
 
-	@RequestMapping("/add")
-	public Result add(WarningParameter entity){ return service.add(entity); }
+    @RequestMapping("/add")
+    public Result add(WarningParameter entity) {
+        return service.add(entity);
+    }
 
-	@RequestMapping("/remove")
-	public Result remove(Integer[] ids){ return service.remove(ids); }
+    @RequestMapping("/remove")
+    public Result remove(Integer[] ids) {
+        return service.remove(ids);
+    }
 
-	@RequestMapping("/update")
-	public Result update(WarningParameter entity){ return service.update(entity); }
+    @RequestMapping("/update")
+    public Result update(WarningParameter entity) {
+        return service.update(entity);
+    }
 
-	@RequestMapping("/findAllById")
-	public Result findAllById(Integer id){ return service.findAllById(id); }
+    @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);
-	}
+    @RequestMapping("/findAll")
+    public Result findAll(String name, Integer pageNum, Integer pageSize) {
+        return service.findAll(name, pageNum, pageSize);
+    }
+
 
 }

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

@@ -9,6 +9,6 @@ import java.util.List;
 
 public interface WarningParameterRepository extends JpaRepository<WarningParameter, Integer>,JpaSpecificationExecutor<WarningParameter>{
 	
-	@Query(nativeQuery = true ,value = "select * from warning_parameter where parameterName like %?1% limit ?2 , ?3")
+	@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);
 }

+ 1 - 0
huimv-ql-farm/huimv-ql-environment/src/main/java/com/huimv/environment/result/ResultStatus.java

@@ -12,4 +12,5 @@ public  class ResultStatus {
 	public  final static String updateFailed = "修改失败";
 	public  final static String findSuccess = "查询成功";
 	public  final static String findFailed = "查询失败";
+	public  final static String PARAMETER_ERROR = "查询失败";
 }

+ 1 - 0
huimv-ql-farm/huimv-ql-environment/src/main/java/com/huimv/environment/service/WarningParameterService.java

@@ -3,6 +3,7 @@ package com.huimv.environment.service;
 
 import com.huimv.environment.entity.WarningParameter;
 import com.huimv.environment.result.Result;
+import org.springframework.data.domain.Page;
 
 public interface WarningParameterService {
 

+ 76 - 43
huimv-ql-farm/huimv-ql-environment/src/main/java/com/huimv/environment/service/impl/WarningParameterServiceImpl.java

@@ -1,75 +1,108 @@
 package com.huimv.environment.service.impl;
 
+import com.huimv.environment.constant.CommonConstant;
 import com.huimv.environment.entity.WarningParameter;
 import com.huimv.environment.repo.WarningParameterRepository;
 import com.huimv.environment.result.Result;
 import com.huimv.environment.result.ResultStatus;
 import com.huimv.environment.service.WarningParameterService;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.data.domain.Page;
+import org.springframework.data.domain.PageRequest;
 import org.springframework.stereotype.Service;
+import org.springframework.util.StringUtils;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.RequestParam;
 
 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 WarningParameterRepository rep;
+    @Autowired
+    private WarningParameterRepository rep;
 
-	@Override
-	public Result add(WarningParameter entity){
-		if (entity == null){
-			return new Result(10002, ResultStatus.addNull);
-		}
-		try {
-			rep.save(entity);
-			return new Result(10000,ResultStatus.addSuccess);
-		}catch (Exception e){
-			return new Result(10001,ResultStatus.addFailed);
-		}
-	}
+    @Override
+    public Result add(WarningParameter entity) {
+        if (entity == null) {
+            return new Result(10002, ResultStatus.addNull);
+        }
 
-	@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);
-		}
-	}
+        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 update(WarningParameter entity) {
-		if (entity == null){
-			return new Result(10002,ResultStatus.updateNull);
-		}
-		try {
-			rep.save(entity);
-			return new Result(10000,ResultStatus.updateSuccess);
-		}catch (Exception e){
-			return new Result(10001,ResultStatus.updateFailed);
-		}
-	}
+    @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
+    @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();
+			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);

+ 19 - 0
huimv-ql-farm/huimv-ql-environment/src/main/java/com/huimv/environment/task/WarningParameterTask.java

@@ -0,0 +1,19 @@
+package com.huimv.environment.task;
+
+import org.springframework.context.annotation.Configuration;
+import org.springframework.scheduling.annotation.EnableScheduling;
+
+/**
+ * <p>
+ *
+ * </p>
+ *
+ * @author yinhao
+ * @date 2021/5/28 10:34
+ */
+@Configuration
+@EnableScheduling
+public class WarningParameterTask {
+
+    
+}