Bladeren bron

修改bug,添加预警功能

523096025 2 jaren geleden
bovenliggende
commit
829beb8fbe

+ 54 - 0
huimv-env-platform/huimv-env-common/src/main/java/com/huimv/env/common/entity/BaseThreshold.java

@@ -0,0 +1,54 @@
+package com.huimv.env.common.entity;
+
+import java.math.BigDecimal;
+import com.baomidou.mybatisplus.annotation.TableName;
+import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.annotation.TableId;
+import java.io.Serializable;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+import lombok.experimental.Accessors;
+
+/**
+ * <p>
+ * 
+ * </p>
+ *
+ * @author author
+ * @since 2022-11-01
+ */
+@Data
+@EqualsAndHashCode(callSuper = false)
+@Accessors(chain = true)
+@TableName("base_threshold")
+public class BaseThreshold implements Serializable {
+
+    private static final long serialVersionUID = 1L;
+
+    @TableId(value = "id", type = IdType.AUTO)
+    private Integer id;
+
+    private BigDecimal maxTemp;
+
+    private BigDecimal minTemp;
+
+    private BigDecimal minHumi;
+
+    private BigDecimal maxHumi;
+
+    private Integer farmCode;
+
+    private String other1;
+
+    private String other2;
+
+    private String other3;
+
+    private String other4;
+
+    private String other5;
+
+    private String other6;
+
+
+}

+ 16 - 0
huimv-env-platform/huimv-env-common/src/main/java/com/huimv/env/common/mapper/BaseThresholdMapper.java

@@ -0,0 +1,16 @@
+package com.huimv.env.common.mapper;
+
+import com.huimv.env.common.entity.BaseThreshold;
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+
+/**
+ * <p>
+ *  Mapper 接口
+ * </p>
+ *
+ * @author author
+ * @since 2022-11-01
+ */
+public interface BaseThresholdMapper extends BaseMapper<BaseThreshold> {
+
+}

+ 21 - 0
huimv-env-platform/huimv-env-common/src/main/java/com/huimv/env/common/mapper/xml/BaseThresholdMapper.xml

@@ -0,0 +1,21 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="com.huimv.env.common.mapper.BaseThresholdMapper">
+
+    <!-- 通用查询映射结果 -->
+    <resultMap id="BaseResultMap" type="com.huimv.env.common.entity.BaseThreshold">
+        <id column="id" property="id" />
+        <result column="max_temp" property="maxTemp" />
+        <result column="min_temp" property="minTemp" />
+        <result column="min_humi" property="minHumi" />
+        <result column="max_humi" property="maxHumi" />
+        <result column="farm_code" property="farmCode" />
+        <result column="other1" property="other1" />
+        <result column="other2" property="other2" />
+        <result column="other3" property="other3" />
+        <result column="other4" property="other4" />
+        <result column="other5" property="other5" />
+        <result column="other6" property="other6" />
+    </resultMap>
+
+</mapper>

+ 20 - 0
huimv-env-platform/huimv-env-common/src/main/java/com/huimv/env/common/service/IBaseThresholdService.java

@@ -0,0 +1,20 @@
+package com.huimv.env.common.service;
+
+import com.huimv.common.utils.Result;
+import com.huimv.env.common.entity.BaseThreshold;
+import com.baomidou.mybatisplus.extension.service.IService;
+
+import java.util.Map;
+
+/**
+ * <p>
+ *  服务类
+ * </p>
+ *
+ * @author author
+ * @since 2022-11-01
+ */
+public interface IBaseThresholdService extends IService<BaseThreshold> {
+
+    Result listThreshold(Map<String,String> map);
+}

+ 55 - 0
huimv-env-platform/huimv-env-common/src/main/java/com/huimv/env/common/service/impl/BaseThresholdServiceImpl.java

@@ -0,0 +1,55 @@
+package com.huimv.env.common.service.impl;
+
+import cn.hutool.core.util.ObjectUtil;
+import cn.hutool.core.util.RandomUtil;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.huimv.common.utils.Result;
+import com.huimv.common.utils.ResultCode;
+import com.huimv.env.common.entity.BaseThreshold;
+import com.huimv.env.common.mapper.BaseThresholdMapper;
+import com.huimv.env.common.service.IBaseThresholdService;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.math.BigDecimal;
+import java.util.Map;
+
+/**
+ * <p>
+ *  服务实现类
+ * </p>
+ *
+ * @author author
+ * @since 2022-11-01
+ */
+@Service
+public class BaseThresholdServiceImpl extends ServiceImpl<BaseThresholdMapper, BaseThreshold> implements IBaseThresholdService {
+
+    @Autowired
+    private BaseThresholdMapper baseThresholdMapper;
+
+    @Override
+    public Result listThreshold(Map<String,String> map) {
+        String farmCode = map.get("farmCode");
+        BaseThreshold baseThreshold = baseThresholdMapper.selectOne(new QueryWrapper<BaseThreshold>().eq("farm_code", farmCode));
+        if (ObjectUtil.isEmpty(baseThreshold)){
+            baseThreshold = new BaseThreshold();
+            baseThreshold.setFarmCode(Integer.parseInt(farmCode));
+            baseThreshold.setMaxHumi(new BigDecimal("40.0"));
+            baseThreshold.setMaxTemp(new BigDecimal("90.0"));
+            baseThreshold.setMinHumi(new BigDecimal("0.0"));
+            baseThreshold.setMinTemp(new BigDecimal("0.0"));
+            baseThreshold.setOther1("0");
+            baseThreshold.setOther2("0");
+            baseThreshold.setOther3("0");
+            baseThreshold.setOther4("0");
+            baseThreshold.setOther5("0");
+            baseThreshold.setOther6("0");
+            baseThresholdMapper.insert(baseThreshold);
+
+        }
+
+        return new Result(ResultCode.SUCCESS,baseThreshold);
+    }
+}

+ 5 - 1
huimv-env-platform/huimv-env-common/src/main/java/com/huimv/env/common/service/impl/EnvElectricityDayServiceImpl.java

@@ -168,7 +168,11 @@ public class EnvElectricityDayServiceImpl extends ServiceImpl<EnvElectricityDayM
         if(lastEnvElectricityDay == null){
             return new BigDecimal(0);
         }else{
-            return (newElectricityBd.subtract(lastEnvElectricityDay.getDayElectricity())).divide(lastEnvElectricityDay.getDayElectricity(),2,BigDecimal.ROUND_HALF_UP).multiply(new BigDecimal(100));
+            try {
+                return (newElectricityBd.subtract(lastEnvElectricityDay.getDayElectricity())).divide(lastEnvElectricityDay.getDayElectricity()).multiply(new BigDecimal(100));
+            }catch (Exception e) {
+                return new BigDecimal(0);
+            }
         }
     }
 }

+ 8 - 3
huimv-env-platform/huimv-env-common/src/main/java/com/huimv/env/common/service/impl/EnvElectricityMonthServiceImpl.java

@@ -78,8 +78,13 @@ public class EnvElectricityMonthServiceImpl extends ServiceImpl<EnvElectricityMo
     public void updateMonthElectricity(EnvElectricityMonth envElectricityMonth, JSONObject dataJo, Timestamp nowTimestamp) {
         BigDecimal endElectricityBd = new BigDecimal(dataJo.getString("value"));
         BigDecimal newMonthElectricityBd = (endElectricityBd.subtract(envElectricityMonth.getStartElectricity())).divide(new BigDecimal("100"), 2, BigDecimal.ROUND_HALF_UP);
-        BigDecimal linkRelativeRatioBd = newMonthElectricityBd.divide(envElectricityMonth.getStartElectricity(),2,BigDecimal.ROUND_HALF_UP).multiply(new BigDecimal(100));
-        envElectricityMonth.setEndTime(nowTimestamp);
+        BigDecimal linkRelativeRatioBd = new BigDecimal(0);
+        try {
+            linkRelativeRatioBd= newMonthElectricityBd.divide(envElectricityMonth.getStartElectricity(), 2, BigDecimal.ROUND_HALF_UP).multiply(new BigDecimal(100));
+        }catch (ArithmeticException e){
+            System.out.println(linkRelativeRatioBd +"-->" + e);
+        }
+         envElectricityMonth.setEndTime(nowTimestamp);
         envElectricityMonth.setEndElectricity(endElectricityBd);
         envElectricityMonth.setMonthElectricity(newMonthElectricityBd);
         envElectricityMonth.setLinkRelativeRatio(linkRelativeRatioBd);
@@ -160,7 +165,7 @@ public class EnvElectricityMonthServiceImpl extends ServiceImpl<EnvElectricityMo
         if(lastEnvElectricityMonth == null){
             return new BigDecimal(0);
         }else{
-            return (newWaterBd.subtract(lastEnvElectricityMonth.getMonthElectricity())).divide(lastEnvElectricityMonth.getMonthElectricity(),2,BigDecimal.ROUND_HALF_UP).multiply(new BigDecimal(100));
+            return (newWaterBd.subtract(lastEnvElectricityMonth.getMonthElectricity())).divide(lastEnvElectricityMonth.getMonthElectricity()).multiply(new BigDecimal(100));
         }
     }
 }

+ 1 - 1
huimv-env-platform/huimv-env-common/src/main/java/com/huimv/env/common/service/impl/EnvWaterMonthServiceImpl.java

@@ -149,7 +149,7 @@ public class EnvWaterMonthServiceImpl extends ServiceImpl<EnvWaterMonthMapper, E
         if(lastEnvWaterMonth == null){
             return new BigDecimal(0);
         }else{
-            return (newWaterBd.subtract(lastEnvWaterMonth.getMonthWater())).divide(lastEnvWaterMonth.getMonthWater(),2,BigDecimal.ROUND_HALF_UP).multiply(new BigDecimal(100));
+            return (newWaterBd.subtract(lastEnvWaterMonth.getMonthWater())).divide(lastEnvWaterMonth.getMonthWater(), 2, BigDecimal.ROUND_HALF_UP).multiply(new BigDecimal(100));
         }
     }
 

+ 1 - 1
huimv-env-platform/huimv-env-common/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/inputFiles.lst

@@ -1 +1 @@
-D:\idea6\huimv.env.platform\huimv-env-platform\huimv-env-common\src\test\java\com\huimv\env\common\CodeGenerator.java
+G:\idea\huimv.env.platform\huimv-env-platform\huimv-env-common\src\test\java\com\huimv\env\common\CodeGenerator.java

+ 35 - 0
huimv-env-platform/huimv-env-manage/src/main/java/com/huimv/env/manage/controller/BaseThresholdController.java

@@ -0,0 +1,35 @@
+package com.huimv.env.manage.controller;
+
+
+import com.huimv.common.utils.Result;
+import com.huimv.env.common.entity.BaseThreshold;
+import com.huimv.env.common.service.IBaseThresholdService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.*;
+
+import java.util.Map;
+
+@RestController
+@CrossOrigin
+@RequestMapping("/baseThreshold")
+public class BaseThresholdController {
+    @Autowired
+    private IBaseThresholdService baseThresholdService;
+
+    @PostMapping("/listThreshold")
+    private Result listThreshold(@RequestBody Map<String,String> map){
+       return baseThresholdService.listThreshold(map);
+    }
+    @PostMapping("/updateThreshold")
+    private Result updateThreshold(@RequestBody BaseThreshold baseThreshold){
+        try {
+            baseThresholdService.updateById(baseThreshold);
+            return new Result(10000,"设置成功",true);
+        }catch (Exception e){
+            return new Result(10001,"设置失败",false);
+        }
+    }
+
+
+
+}

+ 1 - 1
huimv-env-platform/huimv-env-manage/src/main/java/com/huimv/env/manage/service/impl/EnvPhServiceImpl.java

@@ -39,7 +39,7 @@ public class EnvPhServiceImpl extends ServiceImpl<EnvPhMapper, EnvPh> implements
         QueryWrapper<EnvPh> queryWrapper = new QueryWrapper<>();
         queryWrapper.eq(StringUtils.isNotBlank(unitId),"unit_id",unitId);
         queryWrapper.eq("farm_code",farmCode);
-        queryWrapper.orderByDesc("add_time");
+        queryWrapper.orderByAsc("add_time");
         queryWrapper.last("LIMIT 1");
         EnvPh envPh = envPhMapper.selectOne(queryWrapper);
         if (envPh == null) {