Bläddra i källkod

气体阈值设置

wwh 2 år sedan
förälder
incheckning
b4cd65defa

+ 34 - 0
huimv-admin/src/main/java/com/huimv/admin/controller/GasThresholdController.java

@@ -1,10 +1,23 @@
 package com.huimv.admin.controller;
 
 
+import com.huimv.admin.common.utils.Result;
+import com.huimv.admin.entity.GasThreshold;
+import com.huimv.admin.entity.ProtThreshold;
+import com.huimv.admin.entity.vo.GasThresholdVo;
+import com.huimv.admin.service.IGasThresholdService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.CrossOrigin;
+import org.springframework.web.bind.annotation.RequestBody;
 import org.springframework.web.bind.annotation.RequestMapping;
 
 import org.springframework.web.bind.annotation.RestController;
 
+import javax.servlet.http.HttpServletRequest;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+
 /**
  * <p>
  * 气体阈值 前端控制器
@@ -15,6 +28,27 @@ import org.springframework.web.bind.annotation.RestController;
  */
 @RestController
 @RequestMapping("/gas-threshold")
+@CrossOrigin
 public class GasThresholdController {
 
+    @Autowired
+    private IGasThresholdService gasThresholdService;
+
+    @RequestMapping("/list")
+    public Result list(HttpServletRequest httpServletRequest, @RequestBody Map<String,String> paramsMap) {
+        return gasThresholdService.list(httpServletRequest,paramsMap);
+    }
+
+    @RequestMapping("/edit")
+    public Result list(HttpServletRequest httpServletRequest, @RequestBody GasThresholdVo gasThresholdVo) {
+        String farmId = gasThresholdVo.getFarmId();
+        GasThreshold gasThreshold = gasThresholdVo.getPigpen().setFarmId(Integer.parseInt(farmId));
+        GasThreshold gasThreshold1 = gasThresholdVo.getPigpen().setFarmId(Integer.parseInt(farmId));
+        GasThreshold gasThreshold2 = gasThresholdVo.getPigpen().setFarmId(Integer.parseInt(farmId));
+        List<GasThreshold> gasThresholds = new LinkedList<>();
+        gasThresholds.add(gasThreshold);
+        gasThresholds.add(gasThreshold1);
+        gasThresholds.add(gasThreshold2);
+        return gasThresholdService.edit(httpServletRequest, gasThresholds);
+    }
 }

+ 13 - 0
huimv-admin/src/main/java/com/huimv/admin/entity/vo/GasThresholdVo.java

@@ -0,0 +1,13 @@
+package com.huimv.admin.entity.vo;
+
+import com.huimv.admin.entity.GasThreshold;
+import lombok.Data;
+
+@Data
+public class GasThresholdVo {
+    private String farmId;
+    private GasThreshold pigpen;
+    private GasThreshold above;
+    private GasThreshold under;
+    private GasThreshold people;
+}

+ 7 - 0
huimv-admin/src/main/java/com/huimv/admin/service/IGasThresholdService.java

@@ -1,8 +1,13 @@
 package com.huimv.admin.service;
 
+import com.huimv.admin.common.utils.Result;
 import com.huimv.admin.entity.GasThreshold;
 import com.baomidou.mybatisplus.extension.service.IService;
 
+import javax.servlet.http.HttpServletRequest;
+import java.util.List;
+import java.util.Map;
+
 /**
  * <p>
  * 气体阈值 服务类
@@ -12,5 +17,7 @@ import com.baomidou.mybatisplus.extension.service.IService;
  * @since 2023-02-21
  */
 public interface IGasThresholdService extends IService<GasThreshold> {
+    Result list(HttpServletRequest httpServletRequest, Map<String,String> paramsMap);
 
+    Result edit(HttpServletRequest httpServletRequest, List<GasThreshold> gasThresholds);
 }

+ 79 - 0
huimv-admin/src/main/java/com/huimv/admin/service/impl/GasThresholdServiceImpl.java

@@ -1,11 +1,21 @@
 package com.huimv.admin.service.impl;
 
+import cn.hutool.core.util.ObjectUtil;
+import com.alibaba.fastjson.JSONObject;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.huimv.admin.common.utils.ResultCode;
 import com.huimv.admin.entity.GasThreshold;
 import com.huimv.admin.mapper.GasThresholdMapper;
 import com.huimv.admin.service.IGasThresholdService;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
+import javax.servlet.http.HttpServletRequest;
+import com.huimv.admin.common.utils.Result;
+import java.util.List;
+import java.util.Map;
+
 /**
  * <p>
  * 气体阈值 服务实现类
@@ -17,4 +27,73 @@ import org.springframework.stereotype.Service;
 @Service
 public class GasThresholdServiceImpl extends ServiceImpl<GasThresholdMapper, GasThreshold> implements IGasThresholdService {
 
+    @Autowired
+    private GasThresholdMapper gasThresholdMapper;
+    @Override
+    public Result list(HttpServletRequest httpServletRequest, Map<String, String> paramsMap) {
+        String farmId = paramsMap.get("farmId");
+        QueryWrapper<GasThreshold> queryWrapper = new QueryWrapper<>();
+        queryWrapper.eq("farm_id", farmId);
+        List<GasThreshold> gasThresholds = gasThresholdMapper.selectList(queryWrapper);
+        JSONObject jsonObject = new JSONObject();
+        if (gasThresholds.size() == 0) {
+            jsonObject.put("NH3-N", 0);
+            jsonObject.put("JLM", 0);
+            jsonObject.put("ELHT", 0);
+            jsonObject.put("EJEL", 0);
+            jsonObject.put("H2S", 0);
+            jsonObject.put("BYX", 0);
+            jsonObject.put("CH3SH", 0);
+            jsonObject.put("SJA", 0);
+            jsonObject.put("CQ", 0);
+        } else {
+            for (GasThreshold gasThreshold : gasThresholds) {
+                if (gasThreshold.getGasType() == 1) {
+                    jsonObject.put("pigpen", gasThreshold);
+                }
+                else if (gasThreshold.getGasType() == 2) {
+                    jsonObject.put("above", gasThreshold);
+                }
+                else if (gasThreshold.getGasType() == 3) {
+                    jsonObject.put("under", gasThreshold);
+                }
+                else if (gasThreshold.getGasType() == 4) {
+                    jsonObject.put("people", gasThreshold);
+                }
+            }
+            jsonObject.put("userIds", gasThresholds.get(1).getUserIds());
+        }
+        return new Result(ResultCode.SUCCESS,jsonObject);
+    }
+
+    @Override
+    public Result edit(HttpServletRequest httpServletRequest, List<GasThreshold> gasThresholds) {
+        for (GasThreshold gasThreshold : gasThresholds) {
+            if (ObjectUtil.isNotEmpty(gasThreshold)) {
+                GasThreshold gasThreshold1 = new GasThreshold();
+                gasThreshold1.setGasType(gasThreshold.getGasType());
+                gasThreshold1.setNh3N(gasThreshold.getNh3N());
+                gasThreshold1.setJlm(gasThreshold.getJlm());
+                gasThreshold1.setElht(gasThreshold.getElht());
+                gasThreshold1.setH2s(gasThreshold.getH2s());
+                gasThreshold1.setByx(gasThreshold.getByx());
+                gasThreshold1.setCh3sh(gasThreshold.getCh3sh());
+                gasThreshold1.setSja(gasThreshold.getSja());
+                gasThreshold1.setCq(gasThreshold.getCq());
+                gasThreshold1.setUserIds(gasThreshold.getUserIds());
+
+                QueryWrapper<GasThreshold> queryWrapper = new QueryWrapper<>();
+                queryWrapper.eq("farm_id", gasThreshold.getFarmId()).eq("gas_type", gasThreshold.getGasType());
+                GasThreshold gasThreshold2 = gasThresholdMapper.selectOne(queryWrapper);
+                if (ObjectUtil.isEmpty(gasThreshold2)) {
+                    gasThresholdMapper.insert(gasThreshold1);
+                } else {
+                    gasThreshold1.setId(gasThreshold.getId());
+                    gasThresholdMapper.updateById(gasThreshold1);
+                }
+            }
+
+        }
+        return new Result(ResultCode.SUCCESS, "修改成功");
+    }
 }