Newspaper 2 anni fa
parent
commit
a98166a785

+ 6 - 12
huimv-farm-produce/src/main/java/com/huimv/produce/warning/controller/SysThresholdController.java

@@ -9,6 +9,7 @@ import com.huimv.produce.warning.service.ISysThresholdService;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.*;
 
+import javax.servlet.http.HttpServletRequest;
 import java.util.Map;
 
 /**
@@ -28,20 +29,13 @@ public class SysThresholdController {
     private ISysThresholdService thresholdService;
 
     @PostMapping("/addThreshold")
-    public Result addThreshold(@RequestBody SysThreshold threshold){
-        SysThreshold byId = thresholdService.getById(threshold.getFarmId());
-        if (ObjectUtil.isEmpty(byId)){
-            thresholdService.save(threshold);
-        }else {
-            thresholdService.updateById(threshold);
-        }
-
-        return new Result(10000,"设置成功",true);
+    public Result addThreshold(HttpServletRequest request,@RequestBody Map<String,String> paramsMap){
+        return thresholdService.addThreshold(request,paramsMap);
     }
 
-    @GetMapping("/getThreshold")
-    public Result getThreshold(@RequestParam(name = "farmId") String farmId){
-        return new Result(ResultCode.SUCCESS,thresholdService.getById(farmId));
+    @PostMapping("/getThreshold")
+    public Result getThreshold(HttpServletRequest request){
+        return thresholdService.getThreshold(request);
     }
 
     @PostMapping("/listWarningInfoWeater")

+ 6 - 49
huimv-farm-produce/src/main/java/com/huimv/produce/warning/entity/SysThreshold.java

@@ -45,58 +45,15 @@ public class SysThreshold extends Model {
      */
     private String minHum;
 
-    /**
-     * 累计流量
-     */
-    private String totalFlow;
-
-    /**
-     * 化学需氧量
-     */
-    @TableField("COD")
-    private String COD;
-
-    /**
-     * 氨氮
+    /*
+     *烘干高温报警阈值
      */
-    private String ammonia;
+    private String dryTem;
 
-    /**
-     * 氮
-     */
-    private String nitrogen;
-
-    /**
-     * 磷
+    /*
+     *烘干持续时长报警阈值
      */
-    private String phosphorus;
-
-
-    /**
-     * ph
-     */
-    private String ph;
-
-
-     /**
-     * 瞬时流量
-     */
-    private String flow;
-
-    /**
-     * 天气高温阈值
-     */
-    private String weatherMaxTem;
-
-
-    /**
-     * 天气低温阈值
-     */
-    private String weatherMinTem;
-
-    private String benconValue;
-
-    private String benconTime;
+    private String dryMin;
 
 
 }

+ 5 - 0
huimv-farm-produce/src/main/java/com/huimv/produce/warning/service/ISysThresholdService.java

@@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.extension.service.IService;
 import com.huimv.common.utils.Result;
 import com.huimv.produce.warning.entity.SysThreshold;
 
+import javax.servlet.http.HttpServletRequest;
 import java.util.Map;
 
 /**
@@ -17,4 +18,8 @@ import java.util.Map;
 public interface ISysThresholdService extends IService<SysThreshold> {
 
     Result listWarningInfoWeater(Map<String, String> map);
+
+    Result getThreshold(HttpServletRequest request);
+
+    Result addThreshold(HttpServletRequest request, Map<String, String> paramsMap);
 }

+ 68 - 22
huimv-farm-produce/src/main/java/com/huimv/produce/warning/service/impl/SysThresholdServiceImpl.java

@@ -1,6 +1,7 @@
 package com.huimv.produce.warning.service.impl;
 
 import cn.hutool.core.util.ObjectUtil;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.huimv.common.utils.Result;
 import com.huimv.common.utils.ResultCode;
@@ -9,7 +10,8 @@ import com.huimv.produce.warning.mapper.SysThresholdMapper;
 import com.huimv.produce.warning.service.ISysThresholdService;
 import org.springframework.stereotype.Service;
 
-import java.util.HashMap;
+import javax.annotation.Resource;
+import javax.servlet.http.HttpServletRequest;
 import java.util.Map;
 
 /**
@@ -23,34 +25,78 @@ import java.util.Map;
 @Service
 public class SysThresholdServiceImpl extends ServiceImpl<SysThresholdMapper, SysThreshold> implements ISysThresholdService {
 
+    @Resource
+    private SysThresholdMapper sysThresholdMapper;
+
+
     @Override
     public Result listWarningInfoWeater(Map<String, String> map) {
         String farmId = map.get("farmId");
         String maxTem = map.get("maxTem");
         String minTem = map.get("minTem");
         SysThreshold threshold = this.getById(farmId);
-        if(ObjectUtil.isEmpty(threshold)){
-             return new Result(10001,"该牧场未设置天气阈值",false);
-        }
-        String weatherMaxTem = threshold.getWeatherMaxTem();
-        String weatherMixTem = threshold.getWeatherMinTem();
-        Map endMap =new HashMap();
-        if (Double.parseDouble(maxTem) > Double.parseDouble(weatherMaxTem)){
-            endMap.put("maxTem",true);
-            endMap.put("maxTemStr","今日最高温度为"+maxTem+"℃,高于阈值"+weatherMaxTem+"℃");
-        }else {
-            endMap.put("maxTem",false);
-            endMap.put("maxTemStr",null);
-        }
-        if (Double.parseDouble(minTem) < Double.parseDouble(weatherMixTem)){
-            endMap.put("minTem",true);
-            endMap.put("minTemStr","今日最低温度为"+minTem+"℃,低于阈值"+weatherMixTem+"℃");
-        }else {
-            endMap.put("minTem",false);
-            endMap.put("minTemStr",null);
-        }
+//        if(ObjectUtil.isEmpty(threshold)){
+//             return new Result(10001,"该牧场未设置天气阈值",false);
+//        }
+//        String weatherMaxTem = threshold.getWeatherMaxTem();
+//        String weatherMixTem = threshold.getWeatherMinTem();
+//        Map endMap =new HashMap();
+//        if (Double.parseDouble(maxTem) > Double.parseDouble(weatherMaxTem)){
+//            endMap.put("maxTem",true);
+//            endMap.put("maxTemStr","今日最高温度为"+maxTem+"℃,高于阈值"+weatherMaxTem+"℃");
+//        }else {
+//            endMap.put("maxTem",false);
+//            endMap.put("maxTemStr",null);
+//        }
+//        if (Double.parseDouble(minTem) < Double.parseDouble(weatherMixTem)){
+//            endMap.put("minTem",true);
+//            endMap.put("minTemStr","今日最低温度为"+minTem+"℃,低于阈值"+weatherMixTem+"℃");
+//        }else {
+//            endMap.put("minTem",false);
+//            endMap.put("minTemStr",null);
+//        }
 
 
-        return new Result(ResultCode.SUCCESS,endMap);
+        return new Result(ResultCode.SUCCESS,map);
+    }
+
+    @Override
+    public Result getThreshold(HttpServletRequest request) {
+        String farmId = request.getHeader("farmId");
+        return new Result(ResultCode.SUCCESS,sysThresholdMapper.selectById(farmId));
+    }
+
+    @Override
+    public Result addThreshold(HttpServletRequest request, Map<String, String> paramsMap) {
+        String farmId = request.getHeader("farmId");
+
+        String maxTem = paramsMap.get("maxTem");
+
+        String minTem = paramsMap.get("minTem");
+
+        String maxHum = paramsMap.get("maxHum");
+
+        String minHum = paramsMap.get("minHum");
+
+        String dryTem = paramsMap.get("dryTem");
+
+        String dryMin = paramsMap.get("dryMin");
+
+        SysThreshold newSysThreshold = new SysThreshold();
+        newSysThreshold.setFarmId(Integer.parseInt(farmId));
+        newSysThreshold.setMaxTem(maxTem);
+        newSysThreshold.setMinTem(minTem);
+        newSysThreshold.setMaxHum(maxHum);
+        newSysThreshold.setMinHum(minHum);
+        newSysThreshold.setDryTem(dryTem);
+        newSysThreshold.setDryMin(dryMin);
+        QueryWrapper<SysThreshold> queryWrapper = new QueryWrapper<>();
+        queryWrapper.eq("farm_Id",farmId);
+        if (sysThresholdMapper.exists(queryWrapper)) {
+            sysThresholdMapper.updateById(newSysThreshold);
+        }else{
+            sysThresholdMapper.insert(newSysThreshold);
+        }
+        return Result.SUCCESS();
     }
 }