|
@@ -1,75 +1,108 @@
|
|
package com.huimv.environment.service.impl;
|
|
package com.huimv.environment.service.impl;
|
|
|
|
|
|
|
|
+import com.huimv.environment.constant.CommonConstant;
|
|
import com.huimv.environment.entity.WarningParameter;
|
|
import com.huimv.environment.entity.WarningParameter;
|
|
import com.huimv.environment.repo.WarningParameterRepository;
|
|
import com.huimv.environment.repo.WarningParameterRepository;
|
|
import com.huimv.environment.result.Result;
|
|
import com.huimv.environment.result.Result;
|
|
import com.huimv.environment.result.ResultStatus;
|
|
import com.huimv.environment.result.ResultStatus;
|
|
import com.huimv.environment.service.WarningParameterService;
|
|
import com.huimv.environment.service.WarningParameterService;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
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.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.HashMap;
|
|
import java.util.List;
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
import java.util.Map;
|
|
|
|
|
|
|
|
+/**
|
|
|
|
+ * @author yinhao
|
|
|
|
+ * @since 2021/5/28 09:41
|
|
|
|
+ */
|
|
@Service
|
|
@Service
|
|
public class WarningParameterServiceImpl implements WarningParameterService {
|
|
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) {
|
|
public Result findAll(String name ,Integer pageNum , Integer pageSize) {
|
|
try {
|
|
try {
|
|
- Map map = new HashMap();
|
|
|
|
|
|
+ Map map = new HashMap(16);
|
|
int size = rep.findAll().size() ;
|
|
int size = rep.findAll().size() ;
|
|
|
|
+ if (pageNum == null) {
|
|
|
|
+ pageNum = 1;
|
|
|
|
+ }
|
|
|
|
+ if (pageSize == null) {
|
|
|
|
+ pageSize = 10;
|
|
|
|
+ }
|
|
|
|
+ if (name == null ) {
|
|
|
|
+ name = "";
|
|
|
|
+ }
|
|
Integer startPage = (pageNum-1) * pageSize;
|
|
Integer startPage = (pageNum-1) * pageSize;
|
|
List<WarningParameter> all = rep.findAll(name,startPage,pageSize);
|
|
List<WarningParameter> all = rep.findAll(name,startPage,pageSize);
|
|
map.put("total",size);
|
|
map.put("total",size);
|
|
map.put("totalPageNum",(size + pageSize - 1) / pageSize);
|
|
map.put("totalPageNum",(size + pageSize - 1) / pageSize);
|
|
map.put("data",all);
|
|
map.put("data",all);
|
|
-
|
|
|
|
return new Result(10000,ResultStatus.findSuccess,map);
|
|
return new Result(10000,ResultStatus.findSuccess,map);
|
|
}catch (Exception e){
|
|
}catch (Exception e){
|
|
return new Result(10001,ResultStatus.findFailed,null);
|
|
return new Result(10001,ResultStatus.findFailed,null);
|