|
@@ -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, "修改成功");
|
|
|
+ }
|
|
|
}
|