Browse Source

预警信息 设备状态

Newspaper 2 năm trước cách đây
mục cha
commit
ef1e1557a6

+ 32 - 0
src/main/java/com/huimv/admin/controller/EnvWarningController.java

@@ -1,11 +1,21 @@
 package com.huimv.admin.controller;
 
 
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.huimv.admin.common.utils.DataUill;
 import com.huimv.admin.common.utils.Result;
+import com.huimv.admin.common.utils.ResultCode;
+import com.huimv.admin.entity.EnvWarning;
+import com.huimv.admin.entity.vo.WarningTopVo;
+import com.huimv.admin.mapper.EnvWarningMapper;
 import com.huimv.admin.service.IEnvWarningService;
+import io.swagger.models.auth.In;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.*;
 
+import java.util.Date;
+import java.util.HashMap;
+import java.util.List;
 import java.util.Map;
 
 /**
@@ -22,6 +32,8 @@ import java.util.Map;
 public class EnvWarningController {
     @Autowired
     private IEnvWarningService envWarningService;
+    @Autowired
+    private EnvWarningMapper envWarningMapper;
 
     @PostMapping("/listCount")
     public Result listWarningCount(@RequestBody Map<String,String> paramsMap){
@@ -37,4 +49,24 @@ public class EnvWarningController {
     public Result listTop(@RequestBody Map<String ,String> paramsMap){
         return envWarningService.listTop(paramsMap);
     }
+
+    @PostMapping("/appList")
+    public Result listAppWarning(@RequestBody Map<String ,String> paramsMap ){
+        String farmId = paramsMap.get("farmId");
+        Date timesMonthmorning = DataUill.getTimesMonthmorning();
+        Date timesmorning = DataUill.getTimesmorning();
+        List<WarningTopVo> warningTopVos = envWarningMapper.listTop(farmId);
+        WarningTopVo warningTopVo = warningTopVos.get(0);
+        Integer monthWarning = envWarningService.count(new QueryWrapper<EnvWarning>()
+                .ge("update_time", timesMonthmorning)
+                .eq("farm_id", farmId));
+        Integer dayWarning = envWarningService.count(new QueryWrapper<EnvWarning>()
+                .ge("update_time", timesmorning)
+                .eq("farm_id", farmId));
+        Map resultMap = new HashMap();
+        resultMap.put("mostWarning",warningTopVo.getLocation());
+        resultMap.put("monthWarning",monthWarning);
+        resultMap.put("dayWarning",dayWarning);
+        return new Result(ResultCode.SUCCESS,resultMap);
+    }
 }

+ 2 - 0
src/main/java/com/huimv/admin/mapper/EnvWarningMapper.java

@@ -9,6 +9,7 @@ import com.huimv.admin.entity.vo.WarningTopVo;
 import com.huimv.admin.entity.vo.WarningVo;
 import org.apache.ibatis.annotations.Param;
 
+import javax.annotation.Resource;
 import java.util.Date;
 import java.util.List;
 
@@ -20,6 +21,7 @@ import java.util.List;
  * @author author
  * @since 2023-03-23
  */
+@Resource
 public interface EnvWarningMapper extends BaseMapper<EnvWarning> {
 
     Integer getCount(@Param(Constants.WRAPPER) QueryWrapper<EnvWarning> update_time);

+ 1 - 0
src/main/java/com/huimv/admin/service/IEnvWarningService.java

@@ -20,4 +20,5 @@ public interface IEnvWarningService extends IService<EnvWarning> {
     Result listWarning(Map<String, String> paramsMap);
 
     Result listTop(Map<String, String> paramsMap);
+
 }

+ 2 - 2
src/main/java/com/huimv/admin/service/impl/EnvDeviceOnlineServiceImpl.java

@@ -68,11 +68,11 @@ public class EnvDeviceOnlineServiceImpl extends ServiceImpl<EnvDeviceOnlineMappe
         BigDecimal lastStatus = envDeviceOnlineMapper.getStatus(wrapper);
         if (ObjectUtil.isNull(lastStatus)){
             resultMap.put("lastValue",0);
-            resultMap.put("gap",100);
+            resultMap.put("gap",currentStatus);
             return new Result(ResultCode.SUCCESS,resultMap);
         }
         resultMap.put("lastValue",lastStatus);
-        double gap = ((currentStatus.doubleValue() - lastStatus.doubleValue()) / lastStatus.doubleValue()) * 100;
+        double gap = currentStatus.doubleValue() - lastStatus.doubleValue();
         if (ObjectUtil.isNull(gap)){
             gap = 0.0;
         }

+ 3 - 5
src/main/java/com/huimv/admin/service/impl/EnvWarningServiceImpl.java

@@ -18,7 +18,6 @@ import org.springframework.stereotype.Service;
 import javax.annotation.Resource;
 import java.math.BigDecimal;
 import java.math.RoundingMode;
-import java.text.DecimalFormat;
 import java.text.SimpleDateFormat;
 import java.util.*;
 
@@ -68,7 +67,7 @@ public class EnvWarningServiceImpl extends ServiceImpl<EnvWarningMapper, EnvWarn
         QueryWrapper<EnvWarning> wrapper = new QueryWrapper<>();
         wrapper.eq("farm_id",farmId);
         Integer lastCount = envWarningMapper.getCount(wrapper.between("update_time",firstDay,lastDay));
-        if (ObjectUtil.isNull(lastCount)){
+        if (ObjectUtil.isNull(lastCount) || lastCount == 0){
             resultMap.put("lastValue",0);
             resultMap.put("gap",100);
             return new Result(ResultCode.SUCCESS,resultMap);
@@ -78,9 +77,7 @@ public class EnvWarningServiceImpl extends ServiceImpl<EnvWarningMapper, EnvWarn
         if (ObjectUtil.isNull(gap)){
             gap = 0.0;
         }
-//        BigDecimal bg = new BigDecimal(gap).setScale(2, RoundingMode.UP);
-        DecimalFormat def = new DecimalFormat("#.00");
-        String bg = def.format(gap);
+        BigDecimal bg = new BigDecimal(gap).setScale(2, RoundingMode.UP);
         resultMap.put("gap",bg);
         return new Result(ResultCode.SUCCESS,resultMap);
     }
@@ -99,4 +96,5 @@ public class EnvWarningServiceImpl extends ServiceImpl<EnvWarningMapper, EnvWarn
         List<WarningTopVo> warningCountVos = envWarningMapper.listTop(farmId);
         return new Result(ResultCode.SUCCESS,warningCountVos);
     }
+
 }