523096025 vor 2 Jahren
Ursprung
Commit
7c5f2bf817

+ 5 - 0
huimv-admin/src/main/java/com/huimv/admin/common/utils/NumberUtils.java

@@ -32,4 +32,9 @@ public class NumberUtils {
         return df.format(v);
     }
 
+    public static String getNumFloat2(Double min, Double max) {
+        double v = Math.random() * (max - min) + min;
+        DecimalFormat df = new DecimalFormat("0.00");
+        return df.format(v);
+    }
 }

+ 19 - 0
huimv-admin/src/main/java/com/huimv/admin/controller/FarmController.java

@@ -1,10 +1,15 @@
 package com.huimv.admin.controller;
 
 
+import cn.hutool.core.util.ObjectUtil;
+import cn.hutool.http.HttpUtil;
+import cn.hutool.json.JSONUtil;
+import com.alibaba.fastjson.JSONObject;
 import com.huimv.admin.common.token.TokenSign;
 import com.huimv.admin.common.utils.Result;
 import com.huimv.admin.common.utils.ResultCode;
 import com.huimv.admin.entity.Farm;
+import com.huimv.admin.entity.dto.WeatherDto;
 import com.huimv.admin.service.IFarmService;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.*;
@@ -81,4 +86,18 @@ public class FarmController {
         String farmId = paramsMap.get("farmId");
         return  new Result(ResultCode.SUCCESS,farmService.getById(farmId).getFunction());
     }
+
+    @PostMapping("/getWeather")
+    public Result getWeather(@RequestBody Map<String,Integer> map) {
+        int farmId =  map.get("farmId");
+        Farm byId = farmService.getById(farmId);
+        String cityCode = byId.getLocation();
+        if (ObjectUtil.isEmpty(cityCode)){
+            cityCode = "330782";
+        }
+        String url="https://restapi.amap.com/v3/weather/weatherInfo?parameters&key=c1d8179ed2dda7ed48c56bed06c0c86e&city="+cityCode+"&extensions=base&output=JSON";
+        String result = HttpUtil.get(url);
+        WeatherDto weatherDto = JSONUtil.toBean(result, WeatherDto.class);
+        return new Result(ResultCode.SUCCESS,weatherDto);
+    }
 }

+ 0 - 2
huimv-admin/src/main/java/com/huimv/admin/controller/SysUserController.java

@@ -31,8 +31,6 @@ public class SysUserController {
 //        return iUserService.removeUser(userIds);
 //    }
 
-
-
     @PostMapping("/list")
     public JSONObject listUser(@RequestBody Map map) {
         System.out.println();

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

@@ -420,11 +420,11 @@ public class EnvDeviceServiceImpl extends ServiceImpl<EnvDeviceMapper, EnvDevice
         try {
             Date now = new Date();
             String nowTime = sdf.format(now);
-            System.out.println(now);
+//            System.out.println(now);
             Date date = sdf.parse("2023-01-01");//指定日期
             Date mydate = sdf.parse(nowTime);//当前日期
             day = (mydate.getTime() - date.getTime()) / (24 * 60 * 60 * 1000);
-            System.out.println(day);
+//            System.out.println(day);
         } catch (Exception e) {
             return new Result(ResultCode.SUCCESS, "");
         }

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

@@ -759,11 +759,11 @@ public class ProtDataServiceImpl extends ServiceImpl<ProtDataMapper, ProtData> i
         try {
             Date now = new Date();
             String nowTime = sdf.format(now);
-            System.out.println(now);
+//            System.out.println(now);
             Date date = sdf.parse("2023-01-01");//指定日期
             Date mydate = sdf.parse(nowTime);//当前日期
             day = (mydate.getTime() - date.getTime()) / (24 * 60 * 60 * 1000);
-            System.out.println(day);
+//            System.out.println(day);
         } catch (Exception e) {
             return new Result(ResultCode.SUCCESS, "");
         }

+ 2 - 2
huimv-admin/src/main/java/com/huimv/admin/timer/EnergyTimer.java

@@ -41,8 +41,8 @@ public class EnergyTimer {
             basePigpenQueryWrapper.eq("id", energyEnvDevice.getUnitId()).eq("farm_id", energyEnvDevice.getFarmId());
             BasePigpen basePigpen = basePigpenMapper.selectOne(basePigpenQueryWrapper);
 
-            String feed = NumberUtils.getNum(70, 90, 1);
-            String water = NumberUtils.getNum(200, 280, 1);
+            String feed = NumberUtils.getNumFloat2(6.00,6.50);
+            String water = NumberUtils.getNumFloat2(0.08,0.15);
             String gas = NumberUtils.getNum(200, 280, 1);
             String electricity = NumberUtils.getNum(70, 90, 1);
 

+ 12 - 12
huimv-admin/src/main/java/com/huimv/admin/timer/EnvTimer.java

@@ -73,7 +73,7 @@ public class EnvTimer {
         //目前是这家
         Integer farmId = 21;
         String encode = loginOnly();
-        System.out.println("encode" + encode);
+//        System.out.println("encode" + encode);
         //获取阈值
         EnvWarningThreshold envWarningThreshold = envWarningThresholdService.getOne(new QueryWrapper<EnvWarningThreshold>().eq("farm_id", farmId));
         HttpHeaders headers = new HttpHeaders();
@@ -129,20 +129,20 @@ public class EnvTimer {
         }
     }
 
-    @Scheduled(cron = "0 0/12 * * * ? ")
+    @Scheduled(cron = "0 0/12 * * * ?")
     @Transactional
     public void getHuanKongs()  {
         Integer farmId = 21;
         EnvWarningThreshold envWarningThreshold = envWarningThresholdService.getOne(new QueryWrapper<EnvWarningThreshold>().eq("farm_id", farmId));
 
         List<BasePigpen> list = basePigpenService.list(new QueryWrapper<BasePigpen>().eq("farm_id", farmId).eq("f_type", 3).ne("id", 178).ne("id", 181));
-        String url="https://restapi.amap.com/v3/weather/weatherInfo?parameters&key=c1d8179ed2dda7ed48c56bed06c0c86e&city=330782&extensions=base&output=JSON";
-        String result = HttpUtil.get(url);
-        WeatherDto weatherDto = JSONUtil.toBean(result, WeatherDto.class);
-        List<WeatherLives> lives = weatherDto.getLives();
-        WeatherLives weatherLives = lives.get(0);
-        int humidity = Integer.parseInt(weatherLives.getHumidity());
-        int temperature = Integer.parseInt(weatherLives.getTemperature());
+//        String url="https://restapi.amap.com/v3/weather/weatherInfo?parameters&key=c1d8179ed2dda7ed48c56bed06c0c86e&city=330782&extensions=base&output=JSON";
+//        String result = HttpUtil.get(url);
+//        WeatherDto weatherDto = JSONUtil.toBean(result, WeatherDto.class);
+//        List<WeatherLives> lives = weatherDto.getLives();
+//        WeatherLives weatherLives = lives.get(0);
+//        int humidity = Integer.parseInt(weatherLives.getHumidity());
+//        int temperature = Integer.parseInt(weatherLives.getTemperature());
 
         for (BasePigpen basePigpen : list) {
             EnvData envData = new EnvData();
@@ -154,8 +154,8 @@ public class EnvTimer {
             envDevice.setUnitId(basePigpen.getId());
             envDevice.setFarmId(farmId);
 
-            String tem = NumberUtils.getNum(temperature-3, temperature+3, 1);
-            String hum = NumberUtils.getNum(humidity-3, humidity+3, 0);
+            String tem = NumberUtils.getNum(17, 23, 1);
+            String hum = NumberUtils.getNum(65, 80, 0);
             saveTemWarning(tem, envWarningThreshold, envDevice, farmId);
             envData.setEnvTemp(tem);
             saveHumWarning(hum, envWarningThreshold, envDevice, farmId);
@@ -271,7 +271,7 @@ public class EnvTimer {
             queryWrapper.eq("farm_id", farmId);
             Integer count = envDeviceService.count(queryWrapper);
             QueryWrapper<EnvDevice> queryWrapper1 = new QueryWrapper<>();
-            queryWrapper1.eq("device_status", 1);
+            queryWrapper1.eq("device_status", 0);
             Integer count1 = envDeviceService.count(queryWrapper1);
             Integer OffDeviceCount = count - count1;
             //创建一个数值格式化对象

+ 1 - 1
huimv-admin/src/main/java/com/huimv/admin/timer/ShenChanTimer.java

@@ -43,7 +43,7 @@ public class ShenChanTimer {
         Integer farmId = 21;
         String time = LocalDate.now().toString();
         String token = login();
-        System.out.println("token"+token);
+//        System.out.println("token"+token);
 
         DateTime dateTime = DateUtil.beginOfDay(new Date());
         ProdStock prodStock = prodStockService.getOne(new QueryWrapper<ProdStock>().ge("creat_time",dateTime).eq("farm_id", farmId).orderByDesc("creat_time").last("limit 1"));

+ 2 - 2
huimv-admin/src/main/resources/application-prod.yml

@@ -36,5 +36,5 @@ spring:
 
 mybatis-plus:
   configuration:
-#    log-impl: org.apache.ibatis.logging.nologging.NoLoggingImpl
-    log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
+    log-impl: org.apache.ibatis.logging.nologging.NoLoggingImpl
+#    log-impl: org.apache.ibatis.logging.stdout.StdOutImpl