浏览代码

更新斯高德对接数据

523096025 3 年之前
父节点
当前提交
3a533b58c0
共有 89 个文件被更改,包括 4097 次插入1 次删除
  1. 142 0
      huimv-farm-v2/huimv-common/src/main/java/com/huimv/common/utils/DataUill.java
  2. 25 0
      huimv-farm-v2/huimv-produce-warning/pom.xml
  3. 3 1
      huimv-farm-v2/huimv-produce-warning/src/main/java/com/huimv/produce/HuimvProduceWarningApplication.java
  4. 42 0
      huimv-farm-v2/huimv-produce-warning/src/main/java/com/huimv/produce/controller/BaseBoxController.java
  5. 33 0
      huimv-farm-v2/huimv-produce-warning/src/main/java/com/huimv/produce/controller/BaseFloorController.java
  6. 51 0
      huimv-farm-v2/huimv-produce-warning/src/main/java/com/huimv/produce/controller/BaseRoomController.java
  7. 28 0
      huimv-farm-v2/huimv-produce-warning/src/main/java/com/huimv/produce/controller/SysDayWaterController.java
  8. 41 0
      huimv-farm-v2/huimv-produce-warning/src/main/java/com/huimv/produce/controller/SysFodderController.java
  9. 19 0
      huimv-farm-v2/huimv-produce-warning/src/main/java/com/huimv/produce/controller/SysHumidityController.java
  10. 35 0
      huimv-farm-v2/huimv-produce-warning/src/main/java/com/huimv/produce/controller/SysMonthWaterController.java
  11. 19 0
      huimv-farm-v2/huimv-produce-warning/src/main/java/com/huimv/produce/controller/SysTemperatureController.java
  12. 40 0
      huimv-farm-v2/huimv-produce-warning/src/main/java/com/huimv/produce/entity/BaseBox.java
  13. 39 0
      huimv-farm-v2/huimv-produce-warning/src/main/java/com/huimv/produce/entity/BaseFloor.java
  14. 34 0
      huimv-farm-v2/huimv-produce-warning/src/main/java/com/huimv/produce/entity/BaseRoom.java
  15. 42 0
      huimv-farm-v2/huimv-produce-warning/src/main/java/com/huimv/produce/entity/SysDayWater.java
  16. 42 0
      huimv-farm-v2/huimv-produce-warning/src/main/java/com/huimv/produce/entity/SysFodder.java
  17. 41 0
      huimv-farm-v2/huimv-produce-warning/src/main/java/com/huimv/produce/entity/SysHumidity.java
  18. 44 0
      huimv-farm-v2/huimv-produce-warning/src/main/java/com/huimv/produce/entity/SysMonthWater.java
  19. 43 0
      huimv-farm-v2/huimv-produce-warning/src/main/java/com/huimv/produce/entity/SysTemperature.java
  20. 23 0
      huimv-farm-v2/huimv-produce-warning/src/main/java/com/huimv/produce/entity/dto/FodderDto.java
  21. 18 0
      huimv-farm-v2/huimv-produce-warning/src/main/java/com/huimv/produce/mapper/BaseBoxMapper.java
  22. 18 0
      huimv-farm-v2/huimv-produce-warning/src/main/java/com/huimv/produce/mapper/BaseFloorMapper.java
  23. 18 0
      huimv-farm-v2/huimv-produce-warning/src/main/java/com/huimv/produce/mapper/BaseRoomMapper.java
  24. 26 0
      huimv-farm-v2/huimv-produce-warning/src/main/java/com/huimv/produce/mapper/SysDayWaterMapper.java
  25. 29 0
      huimv-farm-v2/huimv-produce-warning/src/main/java/com/huimv/produce/mapper/SysFodderMapper.java
  26. 18 0
      huimv-farm-v2/huimv-produce-warning/src/main/java/com/huimv/produce/mapper/SysHumidityMapper.java
  27. 24 0
      huimv-farm-v2/huimv-produce-warning/src/main/java/com/huimv/produce/mapper/SysMonthWaterMapper.java
  28. 18 0
      huimv-farm-v2/huimv-produce-warning/src/main/java/com/huimv/produce/mapper/SysTemperatureMapper.java
  29. 17 0
      huimv-farm-v2/huimv-produce-warning/src/main/java/com/huimv/produce/service/IBaseBoxService.java
  30. 16 0
      huimv-farm-v2/huimv-produce-warning/src/main/java/com/huimv/produce/service/IBaseFloorService.java
  31. 22 0
      huimv-farm-v2/huimv-produce-warning/src/main/java/com/huimv/produce/service/IBaseRoomService.java
  32. 22 0
      huimv-farm-v2/huimv-produce-warning/src/main/java/com/huimv/produce/service/ISysDayWaterService.java
  33. 22 0
      huimv-farm-v2/huimv-produce-warning/src/main/java/com/huimv/produce/service/ISysFodderService.java
  34. 16 0
      huimv-farm-v2/huimv-produce-warning/src/main/java/com/huimv/produce/service/ISysHumidityService.java
  35. 18 0
      huimv-farm-v2/huimv-produce-warning/src/main/java/com/huimv/produce/service/ISysMonthWaterService.java
  36. 16 0
      huimv-farm-v2/huimv-produce-warning/src/main/java/com/huimv/produce/service/ISysTemperatureService.java
  37. 20 0
      huimv-farm-v2/huimv-produce-warning/src/main/java/com/huimv/produce/service/impl/BaseBoxServiceImpl.java
  38. 20 0
      huimv-farm-v2/huimv-produce-warning/src/main/java/com/huimv/produce/service/impl/BaseFloorServiceImpl.java
  39. 139 0
      huimv-farm-v2/huimv-produce-warning/src/main/java/com/huimv/produce/service/impl/BaseRoomServiceImpl.java
  40. 203 0
      huimv-farm-v2/huimv-produce-warning/src/main/java/com/huimv/produce/service/impl/SysDayWaterServiceImpl.java
  41. 116 0
      huimv-farm-v2/huimv-produce-warning/src/main/java/com/huimv/produce/service/impl/SysFodderServiceImpl.java
  42. 20 0
      huimv-farm-v2/huimv-produce-warning/src/main/java/com/huimv/produce/service/impl/SysHumidityServiceImpl.java
  43. 59 0
      huimv-farm-v2/huimv-produce-warning/src/main/java/com/huimv/produce/service/impl/SysMonthWaterServiceImpl.java
  44. 20 0
      huimv-farm-v2/huimv-produce-warning/src/main/java/com/huimv/produce/service/impl/SysTemperatureServiceImpl.java
  45. 161 0
      huimv-farm-v2/huimv-produce-warning/src/main/java/com/huimv/produce/sgd/FBoxSignalRConnection.java
  46. 45 0
      huimv-farm-v2/huimv-produce-warning/src/main/java/com/huimv/produce/sgd/Global.java
  47. 215 0
      huimv-farm-v2/huimv-produce-warning/src/main/java/com/huimv/produce/sgd/Main.java
  48. 24 0
      huimv-farm-v2/huimv-produce-warning/src/main/java/com/huimv/produce/sgd/entity/Item.java
  49. 20 0
      huimv-farm-v2/huimv-produce-warning/src/main/java/com/huimv/produce/sgd/entity/Monitory.java
  50. 27 0
      huimv-farm-v2/huimv-produce-warning/src/main/java/com/huimv/produce/sgd/entity/MonitoryGetArgs.java
  51. 122 0
      huimv-farm-v2/huimv-produce-warning/src/main/java/com/huimv/produce/sgd/entity/MonitoryValue.java
  52. 18 0
      huimv-farm-v2/huimv-produce-warning/src/main/java/com/huimv/produce/sgd/fbox/BoxServerResponseException.java
  53. 18 0
      huimv-farm-v2/huimv-produce-warning/src/main/java/com/huimv/produce/sgd/fbox/ClientCredential.java
  54. 34 0
      huimv-farm-v2/huimv-produce-warning/src/main/java/com/huimv/produce/sgd/fbox/ConsoleLogger.java
  55. 12 0
      huimv-farm-v2/huimv-produce-warning/src/main/java/com/huimv/produce/sgd/fbox/ConsoleLoggerFactory.java
  56. 17 0
      huimv-farm-v2/huimv-produce-warning/src/main/java/com/huimv/produce/sgd/fbox/CredentialProvider.java
  57. 10 0
      huimv-farm-v2/huimv-produce-warning/src/main/java/com/huimv/produce/sgd/fbox/Logger.java
  58. 5 0
      huimv-farm-v2/huimv-produce-warning/src/main/java/com/huimv/produce/sgd/fbox/LoggerFactory.java
  59. 9 0
      huimv-farm-v2/huimv-produce-warning/src/main/java/com/huimv/produce/sgd/fbox/LoginFailedException.java
  60. 23 0
      huimv-farm-v2/huimv-produce-warning/src/main/java/com/huimv/produce/sgd/fbox/NullLogger.java
  61. 301 0
      huimv-farm-v2/huimv-produce-warning/src/main/java/com/huimv/produce/sgd/fbox/ServerCaller.java
  62. 21 0
      huimv-farm-v2/huimv-produce-warning/src/main/java/com/huimv/produce/sgd/fbox/StaticCredentialProvider.java
  63. 132 0
      huimv-farm-v2/huimv-produce-warning/src/main/java/com/huimv/produce/sgd/fbox/TokenManager.java
  64. 5 0
      huimv-farm-v2/huimv-produce-warning/src/main/java/com/huimv/produce/sgd/fbox/TokenResponse.java
  65. 18 0
      huimv-farm-v2/huimv-produce-warning/src/main/java/com/huimv/produce/sgd/fbox/UserCredential.java
  66. 24 0
      huimv-farm-v2/huimv-produce-warning/src/main/java/com/huimv/produce/sgd/fbox/models/Box.java
  67. 8 0
      huimv-farm-v2/huimv-produce-warning/src/main/java/com/huimv/produce/sgd/fbox/models/BoxGroup.java
  68. 18 0
      huimv-farm-v2/huimv-produce-warning/src/main/java/com/huimv/produce/sgd/fbox/models/BoxReg.java
  69. 7 0
      huimv-farm-v2/huimv-produce-warning/src/main/java/com/huimv/produce/sgd/fbox/models/BoxStateChanged.java
  70. 5 0
      huimv-farm-v2/huimv-produce-warning/src/main/java/com/huimv/produce/sgd/fbox/models/ByRowHdata.java
  71. 19 0
      huimv-farm-v2/huimv-produce-warning/src/main/java/com/huimv/produce/sgd/fbox/models/ByRowHdataRow.java
  72. 13 0
      huimv-farm-v2/huimv-produce-warning/src/main/java/com/huimv/produce/sgd/fbox/models/Cs.java
  73. 53 0
      huimv-farm-v2/huimv-produce-warning/src/main/java/com/huimv/produce/sgd/fbox/models/DataSource.java
  74. 76 0
      huimv-farm-v2/huimv-produce-warning/src/main/java/com/huimv/produce/sgd/fbox/models/DataType.java
  75. 14 0
      huimv-farm-v2/huimv-produce-warning/src/main/java/com/huimv/produce/sgd/fbox/models/DmonWriteValueArgs.java
  76. 11 0
      huimv-farm-v2/huimv-produce-warning/src/main/java/com/huimv/produce/sgd/fbox/models/GetByChannelHdataArgs.java
  77. 9 0
      huimv-farm-v2/huimv-produce-warning/src/main/java/com/huimv/produce/sgd/fbox/models/GetByRowHdataArgs.java
  78. 9 0
      huimv-farm-v2/huimv-produce-warning/src/main/java/com/huimv/produce/sgd/fbox/models/GetDmonValuesById.java
  79. 9 0
      huimv-farm-v2/huimv-produce-warning/src/main/java/com/huimv/produce/sgd/fbox/models/GetDmonValuesByName.java
  80. 39 0
      huimv-farm-v2/huimv-produce-warning/src/main/java/com/huimv/produce/sgd/fbox/models/GetHdataArgs.java
  81. 33 0
      huimv-farm-v2/huimv-produce-warning/src/main/java/com/huimv/produce/sgd/fbox/models/HdataChannelDef.java
  82. 5 0
      huimv-farm-v2/huimv-produce-warning/src/main/java/com/huimv/produce/sgd/fbox/models/HdataControlOptions.java
  83. 33 0
      huimv-farm-v2/huimv-produce-warning/src/main/java/com/huimv/produce/sgd/fbox/models/HdataDef.java
  84. 189 0
      huimv-farm-v2/huimv-produce-warning/src/main/java/com/huimv/produce/sgd/fbox/signalr/SignalRConnectionBase.java
  85. 28 0
      huimv-farm-v2/huimv-produce-warning/src/main/java/com/huimv/produce/sgd/fbox/signalr/SignalRLoggerWrapper.java
  86. 481 0
      huimv-farm-v2/huimv-produce-warning/src/main/java/com/huimv/produce/timer/SgdTimer.java
  87. 23 0
      huimv-farm-v2/huimv-produce-warning/src/main/resources/com/huimv/produce/mapper/SysDayWaterMapper.xml
  88. 36 0
      huimv-farm-v2/huimv-produce-warning/src/main/resources/com/huimv/produce/mapper/SysFodderMapper.xml
  89. 17 0
      huimv-farm-v2/huimv-produce-warning/src/main/resources/com/huimv/produce/mapper/SysMonthWaterMapper.xml

+ 142 - 0
huimv-farm-v2/huimv-common/src/main/java/com/huimv/common/utils/DataUill.java

@@ -0,0 +1,142 @@
+package com.huimv.common.utils;
+  
+import java.text.SimpleDateFormat;
+import java.util.Calendar;
+import java.util.Date;
+  
+public class DataUill {
+  
+
+  
+    // 获得当天0点时间
+    public static Date getTimesmorning() {
+        Calendar cal = Calendar.getInstance();
+        cal.set(Calendar.HOUR_OF_DAY, 0);
+        cal.set(Calendar.SECOND, 0);
+        cal.set(Calendar.MINUTE, 0);
+        cal.set(Calendar.MILLISECOND, 0);
+        return cal.getTime();
+  
+  
+    }
+    // 获得昨天0点时间
+    public static Date getYesterdaymorning() {
+        Calendar cal = Calendar.getInstance();
+        cal.setTimeInMillis(getTimesmorning().getTime()-3600*24*1000);
+        return cal.getTime();
+    }
+    // 获得当天近7天时间
+    public static Date getWeekFromNow() {
+        Calendar cal = Calendar.getInstance();
+        cal.setTimeInMillis( getTimesmorning().getTime()-3600*24*1000*7);
+        return cal.getTime();
+    }
+  
+    // 获得当天24点时间
+    public static Date getTimesnight() {
+        Calendar cal = Calendar.getInstance();
+        cal.set(Calendar.HOUR_OF_DAY, 24);
+        cal.set(Calendar.SECOND, 0);
+        cal.set(Calendar.MINUTE, 0);
+        cal.set(Calendar.MILLISECOND, 0);
+        return cal.getTime();
+    }
+  
+    // 获得本周一0点时间
+    public static Date getTimesWeekmorning() {
+        Calendar cal = Calendar.getInstance();
+        cal.set(cal.get(Calendar.YEAR), cal.get(Calendar.MONDAY), cal.get(Calendar.DAY_OF_MONTH), 0, 0, 0);
+        cal.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY);
+        return cal.getTime();
+    }
+  
+    // 获得本周日24点时间
+    public static Date getTimesWeeknight() {
+        Calendar cal = Calendar.getInstance();
+        cal.setTime(getTimesWeekmorning());
+        cal.add(Calendar.DAY_OF_WEEK, 7);
+        return cal.getTime();
+    }
+  
+    // 获得本月第一天0点时间
+    public static Date getTimesMonthmorning() {
+        Calendar cal = Calendar.getInstance();
+        cal.set(cal.get(Calendar.YEAR), cal.get(Calendar.MONDAY), cal.get(Calendar.DAY_OF_MONTH), 0, 0, 0);
+        cal.set(Calendar.DAY_OF_MONTH, cal.getActualMinimum(Calendar.DAY_OF_MONTH));
+        return cal.getTime();
+    }
+  
+    // 获得本月最后一天24点时间
+    public static Date getTimesMonthnight() {
+        Calendar cal = Calendar.getInstance();
+        cal.set(cal.get(Calendar.YEAR), cal.get(Calendar.MONDAY), cal.get(Calendar.DAY_OF_MONTH), 0, 0, 0);
+        cal.set(Calendar.DAY_OF_MONTH, cal.getActualMaximum(Calendar.DAY_OF_MONTH));
+        cal.set(Calendar.HOUR_OF_DAY, 24);
+        return cal.getTime();
+    }
+  
+    public static Date getLastMonthStartMorning() {
+        Calendar cal = Calendar.getInstance();
+        cal.setTime(getTimesMonthmorning());
+        cal.add(Calendar.MONTH, -1);
+        return cal.getTime();
+    }
+  
+    public static Date getCurrentQuarterStartTime() {
+        Calendar c = Calendar.getInstance();
+        int currentMonth = c.get(Calendar.MONTH) + 1;
+        SimpleDateFormat longSdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+        SimpleDateFormat shortSdf = new SimpleDateFormat("yyyy-MM-dd");
+        Date now = null;
+        try {
+            if (currentMonth >= 1 && currentMonth <= 3)
+                c.set(Calendar.MONTH, 0);
+            else if (currentMonth >= 4 && currentMonth <= 6)
+                c.set(Calendar.MONTH, 3);
+            else if (currentMonth >= 7 && currentMonth <= 9)
+                c.set(Calendar.MONTH, 4);
+            else if (currentMonth >= 10 && currentMonth <= 12)
+                c.set(Calendar.MONTH, 9);
+            c.set(Calendar.DATE, 1);
+            now = longSdf.parse(shortSdf.format(c.getTime()) + " 00:00:00");
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+        return now;
+    }
+  
+    /**
+     * 当前季度的结束时间,即2012-03-31 23:59:59
+     *
+     * @return
+     */
+    public static Date getCurrentQuarterEndTime() {
+        Calendar cal = Calendar.getInstance();
+        cal.setTime(getCurrentQuarterStartTime());
+        cal.add(Calendar.MONTH, 3);
+        return cal.getTime();
+    }
+  
+  
+    public static Date getCurrentYearStartTime() {
+        Calendar cal = Calendar.getInstance();
+        cal.set(cal.get(Calendar.YEAR), cal.get(Calendar.MONDAY), cal.get(Calendar.DAY_OF_MONTH), 0, 0, 0);
+        cal.set(Calendar.DAY_OF_MONTH, cal.getActualMinimum(Calendar.YEAR));
+        return cal.getTime();
+    }
+  
+    public static Date getCurrentYearEndTime() {
+        Calendar cal = Calendar.getInstance();
+        cal.setTime(getCurrentYearStartTime());
+        cal.add(Calendar.YEAR, 1);
+        return cal.getTime();
+    }
+  
+    public static Date getLastYearStartTime() {
+        Calendar cal = Calendar.getInstance();
+        cal.setTime(getCurrentYearStartTime());
+        cal.add(Calendar.YEAR, -1);
+        return cal.getTime();
+    }
+  
+}

+ 25 - 0
huimv-farm-v2/huimv-produce-warning/pom.xml

@@ -17,6 +17,31 @@
             <artifactId>huimv-common</artifactId>
             <artifactId>huimv-common</artifactId>
             <version>0.0.1-SNAPSHOT</version>
             <version>0.0.1-SNAPSHOT</version>
         </dependency>
         </dependency>
+        <dependency>
+            <groupId>com.google.code.gson</groupId>
+            <artifactId>gson</artifactId>
+            <version>2.8.6</version>
+        </dependency>
+        <dependency>
+            <groupId>com.github.fryderykhuang</groupId>
+            <artifactId>signalr4j</artifactId>
+            <version>3.0.1</version>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.httpcomponents</groupId>
+            <artifactId>httpclient-cache</artifactId>
+            <version>4.5.3</version>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.httpcomponents</groupId>
+            <artifactId>httpcore</artifactId>
+            <version>4.4.4</version>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.poi</groupId>
+            <artifactId>poi-ooxml</artifactId>
+            <version>4.1.2</version>
+        </dependency>
     </dependencies>
     </dependencies>
 
 
 </project>
 </project>

+ 3 - 1
huimv-farm-v2/huimv-produce-warning/src/main/java/com/huimv/produce/HuimvProduceWarningApplication.java

@@ -5,13 +5,15 @@ import org.springframework.boot.SpringApplication;
 import org.springframework.boot.autoconfigure.SpringBootApplication;
 import org.springframework.boot.autoconfigure.SpringBootApplication;
 import org.springframework.context.ApplicationContext;
 import org.springframework.context.ApplicationContext;
 import org.springframework.scheduling.annotation.EnableScheduling;
 import org.springframework.scheduling.annotation.EnableScheduling;
+import org.springframework.scheduling.annotation.Scheduled;
 
 
 @SpringBootApplication
 @SpringBootApplication
 @MapperScan("com.huimv.produce.mapper")
 @MapperScan("com.huimv.produce.mapper")
+@EnableScheduling
 public class HuimvProduceWarningApplication {
 public class HuimvProduceWarningApplication {
 
 
     public static void main(String[] args) {
     public static void main(String[] args) {
-        ApplicationContext applicationContext = SpringApplication.run(HuimvProduceWarningApplication.class, args);
+      SpringApplication.run(HuimvProduceWarningApplication.class, args);
 //        applicationContext.getBean(SocketServer.class).startSocketServer();
 //        applicationContext.getBean(SocketServer.class).startSocketServer();
     }
     }
 
 

+ 42 - 0
huimv-farm-v2/huimv-produce-warning/src/main/java/com/huimv/produce/controller/BaseBoxController.java

@@ -0,0 +1,42 @@
+package com.huimv.produce.controller;
+
+
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.baomidou.mybatisplus.extension.api.R;
+import com.huimv.common.utils.Result;
+import com.huimv.common.utils.ResultCode;
+import com.huimv.produce.entity.BaseBox;
+import com.huimv.produce.service.IBaseBoxService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestParam;
+import org.springframework.web.bind.annotation.RestController;
+
+/**
+ * <p>
+ *  前端控制器
+ * </p>
+ *
+ * @author astupidcoder
+ * @since 2021-11-11
+ */
+@RestController
+@RequestMapping("/box")
+public class BaseBoxController {
+
+    @Autowired
+    private IBaseBoxService baseBoxService;
+
+    @GetMapping("list")
+    public Result list(){
+        return new Result(ResultCode.SUCCESS,baseBoxService.list());
+    }
+
+    @GetMapping("listByFloor")
+    public Result listByFloor(@RequestParam(name = "floorId") Integer floorId){
+
+        return new Result(ResultCode.SUCCESS, baseBoxService.list(new QueryWrapper<BaseBox>().eq("floor_id",floorId)));
+    }
+
+}

+ 33 - 0
huimv-farm-v2/huimv-produce-warning/src/main/java/com/huimv/produce/controller/BaseFloorController.java

@@ -0,0 +1,33 @@
+package com.huimv.produce.controller;
+
+
+import com.huimv.common.utils.Result;
+import com.huimv.common.utils.ResultCode;
+import com.huimv.produce.service.IBaseBoxService;
+import com.huimv.produce.service.IBaseFloorService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+/**
+ * <p>
+ *  前端控制器
+ * </p>
+ *
+ * @author astupidcoder
+ * @since 2021-11-11
+ */
+@RestController
+@RequestMapping("/floor")
+public class BaseFloorController {
+
+    @Autowired
+    private IBaseFloorService baseFloorService;
+
+    @GetMapping("list")
+    public Result list(){
+        return new Result(ResultCode.SUCCESS,baseFloorService.list());
+    }
+
+}

+ 51 - 0
huimv-farm-v2/huimv-produce-warning/src/main/java/com/huimv/produce/controller/BaseRoomController.java

@@ -0,0 +1,51 @@
+package com.huimv.produce.controller;
+
+
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.huimv.common.utils.Result;
+import com.huimv.common.utils.ResultCode;
+import com.huimv.produce.entity.BaseRoom;
+import com.huimv.produce.service.IBaseFloorService;
+import com.huimv.produce.service.IBaseRoomService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.*;
+
+import java.util.Map;
+
+/**
+ * <p>
+ *  前端控制器
+ * </p>
+ *
+ * @author astupidcoder
+ * @since 2021-11-11
+ */
+@RestController
+@RequestMapping("/room")
+public class BaseRoomController {
+
+    @Autowired
+    private IBaseRoomService baseRoomService;
+
+    @GetMapping("/getAllRoomEnvironment")
+    private Result getAllRoomEnvironment(){
+        return  baseRoomService.getAllRoomEnvironment();
+
+    }
+
+    @GetMapping("list")
+    public Result list(){
+        return new Result(ResultCode.SUCCESS,baseRoomService.list());
+    }
+
+    @PostMapping("/listByRoom")
+    public Result listByRoom(@RequestBody Map<String,String> map){
+        return  baseRoomService.listByRoom(map);
+    }
+
+    @GetMapping("/listBy")
+    public Result listByRoom(@RequestParam(name = "uid") String uid){
+        return new Result(ResultCode.SUCCESS,baseRoomService.list(new QueryWrapper<BaseRoom>().eq("box_id",uid)));
+    }
+
+}

+ 28 - 0
huimv-farm-v2/huimv-produce-warning/src/main/java/com/huimv/produce/controller/SysDayWaterController.java

@@ -0,0 +1,28 @@
+package com.huimv.produce.controller;
+
+
+import com.huimv.common.utils.Result;
+import com.huimv.produce.service.ISysDayWaterService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.*;
+
+import java.util.Map;
+
+@RestController
+@RequestMapping("/dayWater")
+public class SysDayWaterController {
+
+    @Autowired
+    private ISysDayWaterService dayWaterService;
+
+    @PostMapping("/listWater")
+    public Result listWater(@RequestBody Map<String,String>  map){
+        return dayWaterService.listWater(map);
+    }
+
+    @PostMapping("/listAllWater")
+    public Result listAllWater(@RequestBody Map<String,String>  map){
+        return dayWaterService.listAllWater(map);
+    }
+
+}

+ 41 - 0
huimv-farm-v2/huimv-produce-warning/src/main/java/com/huimv/produce/controller/SysFodderController.java

@@ -0,0 +1,41 @@
+package com.huimv.produce.controller;
+
+
+import com.huimv.common.utils.Result;
+import com.huimv.produce.service.ISysFodderService;
+import org.apache.ibatis.annotations.Param;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.*;
+
+import javax.swing.plaf.PanelUI;
+import java.security.PublicKey;
+import java.util.Map;
+
+/**
+ * <p>
+ *  前端控制器
+ * </p>
+ *
+ * @author astupidcoder
+ * @since 2021-11-15
+ */
+@RestController
+@RequestMapping("/sysFodder")
+public class SysFodderController {
+    @Autowired
+    private ISysFodderService fodderService;
+
+    @PostMapping("/getAllFodder")
+    public Result getAllFodder(@RequestBody Map map){
+        return fodderService.getAllFodder(map);
+    }
+
+    @PostMapping("/getFodder")
+    public Result getFodder(@RequestBody Map map){
+        return fodderService.getFodder(map);
+    }
+
+
+
+
+}

+ 19 - 0
huimv-farm-v2/huimv-produce-warning/src/main/java/com/huimv/produce/controller/SysHumidityController.java

@@ -0,0 +1,19 @@
+package com.huimv.produce.controller;
+
+
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+/**
+ * <p>
+ *  前端控制器
+ * </p>
+ *
+ * @author astupidcoder
+ * @since 2021-11-11
+ */
+@RestController
+@RequestMapping("/humidity")
+public class SysHumidityController {
+
+}

+ 35 - 0
huimv-farm-v2/huimv-produce-warning/src/main/java/com/huimv/produce/controller/SysMonthWaterController.java

@@ -0,0 +1,35 @@
+package com.huimv.produce.controller;
+
+
+import com.huimv.common.utils.Result;
+import com.huimv.produce.service.ISysMonthWaterService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+
+import org.springframework.web.bind.annotation.RestController;
+
+/**
+ * <p>
+ *  前端控制器
+ * </p>
+ *
+ * @author astupidcoder
+ * @since 2021-11-12
+ */
+@RestController
+@RequestMapping("/monthWater")
+public class SysMonthWaterController {
+
+    @Autowired
+    private ISysMonthWaterService monthWaterService;
+
+
+
+
+    @GetMapping("/getAllDayWater")
+    public Result getAllDayWater(){
+        return  monthWaterService.getAllDayWater();
+    }
+
+}

+ 19 - 0
huimv-farm-v2/huimv-produce-warning/src/main/java/com/huimv/produce/controller/SysTemperatureController.java

@@ -0,0 +1,19 @@
+package com.huimv.produce.controller;
+
+
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+/**
+ * <p>
+ *  前端控制器
+ * </p>
+ *
+ * @author astupidcoder
+ * @since 2021-11-11
+ */
+@RestController
+@RequestMapping("/temperature")
+public class SysTemperatureController {
+
+}

+ 40 - 0
huimv-farm-v2/huimv-produce-warning/src/main/java/com/huimv/produce/entity/BaseBox.java

@@ -0,0 +1,40 @@
+package com.huimv.produce.entity;
+
+import com.baomidou.mybatisplus.extension.activerecord.Model;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+import lombok.experimental.Accessors;
+
+/**
+ * <p>
+ * 
+ * </p>
+ *
+ * @author astupidcoder
+ * @since 2021-11-11
+ */
+@Data
+@EqualsAndHashCode(callSuper = true)
+@Accessors(chain = true)
+public class BaseBox extends Model {
+
+    private static final long serialVersionUID = 1L;
+
+    private String uid;
+
+    /**
+     * 别名
+     */
+    private String alias;
+
+    private Integer floorId;
+
+    public BaseBox() {
+    }
+
+    public BaseBox(String uid, String alias, Integer floorId) {
+        this.uid = uid;
+        this.alias = alias;
+        this.floorId = floorId;
+    }
+}

+ 39 - 0
huimv-farm-v2/huimv-produce-warning/src/main/java/com/huimv/produce/entity/BaseFloor.java

@@ -0,0 +1,39 @@
+package com.huimv.produce.entity;
+
+import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.annotation.TableId;
+import com.baomidou.mybatisplus.extension.activerecord.Model;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+import lombok.experimental.Accessors;
+
+/**
+ * <p>
+ * 
+ * </p>
+ *
+ * @author astupidcoder
+ * @since 2021-11-11
+ */
+@Data
+@EqualsAndHashCode(callSuper = true)
+@Accessors(chain = true)
+public class BaseFloor extends Model {
+
+    private static final long serialVersionUID = 1L;
+
+    @TableId(value = "id", type = IdType.AUTO)
+    private Integer id;
+
+    /**
+     * 别名
+     */
+    private String floorName;
+
+    /**
+     * 几栋
+     */
+    private Integer block;
+
+
+}

+ 34 - 0
huimv-farm-v2/huimv-produce-warning/src/main/java/com/huimv/produce/entity/BaseRoom.java

@@ -0,0 +1,34 @@
+package com.huimv.produce.entity;
+
+import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.annotation.TableId;
+import com.baomidou.mybatisplus.extension.activerecord.Model;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+import lombok.experimental.Accessors;
+
+/**
+ * <p>
+ * 
+ * </p>
+ *
+ * @author astupidcoder
+ * @since 2021-11-11
+ */
+@Data
+@EqualsAndHashCode(callSuper = true)
+@Accessors(chain = true)
+public class BaseRoom extends Model {
+
+    private static final long serialVersionUID = 1L;
+
+    @TableId(value = "id", type = IdType.AUTO)
+    private Integer id;
+
+    private String boxId;
+
+    private String roomName;
+
+    private String  alias;
+
+}

+ 42 - 0
huimv-farm-v2/huimv-produce-warning/src/main/java/com/huimv/produce/entity/SysDayWater.java

@@ -0,0 +1,42 @@
+package com.huimv.produce.entity;
+
+import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.extension.activerecord.Model;
+import java.time.LocalDateTime;
+import java.util.Date;
+
+import com.baomidou.mybatisplus.annotation.TableId;
+import com.fasterxml.jackson.annotation.JsonFormat;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+import lombok.experimental.Accessors;
+
+/**
+ * <p>
+ * 
+ * </p>
+ *
+ * @author astupidcoder
+ * @since 2021-11-12
+ */
+@Data
+@EqualsAndHashCode(callSuper = true)
+@Accessors(chain = true)
+public class SysDayWater extends Model {
+
+    private static final long serialVersionUID = 1L;
+
+    private String id;
+
+    private String value;
+
+    @JsonFormat(pattern = "MM-dd HH:mm",timezone = "GMT+8")
+    private Date createTime;
+
+    private Integer roomId;
+
+    @TableId(value = "day_water_id", type = IdType.AUTO)
+    private Integer dayWaterId;
+
+
+}

+ 42 - 0
huimv-farm-v2/huimv-produce-warning/src/main/java/com/huimv/produce/entity/SysFodder.java

@@ -0,0 +1,42 @@
+package com.huimv.produce.entity;
+
+import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.extension.activerecord.Model;
+import java.time.LocalDateTime;
+import java.util.Date;
+
+import com.baomidou.mybatisplus.annotation.TableId;
+import com.fasterxml.jackson.annotation.JsonFormat;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+import lombok.experimental.Accessors;
+
+/**
+ * <p>
+ * 
+ * </p>
+ *
+ * @author astupidcoder
+ * @since 2021-11-15
+ */
+@Data
+@EqualsAndHashCode(callSuper = true)
+@Accessors(chain = true)
+public class SysFodder extends Model {
+
+    private static final long serialVersionUID = 1L;
+
+    private String id;
+
+    private Double value;
+
+    @JsonFormat(pattern = "MM-dd" ,timezone = "GMT+8")
+    private Date createTime;
+
+    private Integer floorId;
+
+    @TableId(value = "fodder_id", type = IdType.AUTO)
+    private Integer fodderId;
+
+
+}

+ 41 - 0
huimv-farm-v2/huimv-produce-warning/src/main/java/com/huimv/produce/entity/SysHumidity.java

@@ -0,0 +1,41 @@
+package com.huimv.produce.entity;
+
+import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.annotation.TableId;
+import com.baomidou.mybatisplus.extension.activerecord.Model;
+import com.fasterxml.jackson.annotation.JsonFormat;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+import lombok.experimental.Accessors;
+
+import java.util.Date;
+
+/**
+ * <p>
+ * 
+ * </p>
+ *
+ * @author astupidcoder
+ * @since 2021-11-11
+ */
+@Data
+@EqualsAndHashCode(callSuper = true)
+@Accessors(chain = true)
+public class SysHumidity extends Model {
+
+    private static final long serialVersionUID = 1L;
+
+    @TableId(value = "hum_id", type = IdType.AUTO)
+    private Integer humId;
+
+    private String id;
+
+    private String value;
+
+    @JsonFormat(pattern = "MM-dd HH:mm",timezone = "GMT+8")
+    private Date createTime;
+
+    private Integer roomId;
+
+
+}

+ 44 - 0
huimv-farm-v2/huimv-produce-warning/src/main/java/com/huimv/produce/entity/SysMonthWater.java

@@ -0,0 +1,44 @@
+package com.huimv.produce.entity;
+
+import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.extension.activerecord.Model;
+import java.time.LocalDateTime;
+import java.util.Date;
+
+import com.baomidou.mybatisplus.annotation.TableId;
+import com.fasterxml.jackson.annotation.JsonFormat;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+import lombok.experimental.Accessors;
+
+/**
+ * <p>
+ * 
+ * </p>
+ *
+ * @author astupidcoder
+ * @since 2021-11-12
+ */
+@Data
+@EqualsAndHashCode(callSuper = true)
+@Accessors(chain = true)
+public class SysMonthWater extends Model {
+
+    private static final long serialVersionUID = 1L;
+
+    private String id;
+
+    private String value;
+
+    @JsonFormat(pattern = "MM-dd HH:mm",timezone = "GMT+8")
+    private Date createTime;
+
+    private Integer roomId;
+
+    @TableId(value = "month_water_id", type = IdType.AUTO)
+    private Integer monthWaterId;
+
+    private String increaseValue;
+
+
+}

+ 43 - 0
huimv-farm-v2/huimv-produce-warning/src/main/java/com/huimv/produce/entity/SysTemperature.java

@@ -0,0 +1,43 @@
+package com.huimv.produce.entity;
+
+import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.annotation.TableId;
+import com.baomidou.mybatisplus.extension.activerecord.Model;
+import com.fasterxml.jackson.annotation.JsonFormat;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+import lombok.experimental.Accessors;
+
+import java.util.Date;
+
+/**
+ * <p>
+ * 
+ * </p>
+ *
+ * @author astupidcoder
+ * @since 2021-11-11
+ */
+@Data
+@EqualsAndHashCode(callSuper = true)
+@Accessors(chain = true)
+public class SysTemperature extends Model {
+
+    private static final long serialVersionUID = 1L;
+
+    @TableId(value = "tem_id", type = IdType.AUTO)
+    private Integer temId;
+
+    private String id;
+
+    private String value;
+
+    @JsonFormat(pattern = "MM-dd HH:mm",timezone = "GMT+8")
+    private Date createTime;
+
+    private Integer roomId;
+
+
+
+
+}

+ 23 - 0
huimv-farm-v2/huimv-produce-warning/src/main/java/com/huimv/produce/entity/dto/FodderDto.java

@@ -0,0 +1,23 @@
+package com.huimv.produce.entity.dto;
+
+
+import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.annotation.TableId;
+import com.fasterxml.jackson.annotation.JsonFormat;
+import lombok.Data;
+
+
+@Data
+public class FodderDto {
+
+    private static final long serialVersionUID = 1L;
+
+    private String screateTime;
+    private Integer floorId;
+    private Integer onevalue;
+    private Integer twovalue;
+    private Integer threevalue;
+
+
+
+}

+ 18 - 0
huimv-farm-v2/huimv-produce-warning/src/main/java/com/huimv/produce/mapper/BaseBoxMapper.java

@@ -0,0 +1,18 @@
+package com.huimv.produce.mapper;
+
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.huimv.produce.entity.BaseBox;
+import org.springframework.stereotype.Repository;
+
+/**
+ * <p>
+ *  Mapper 接口
+ * </p>
+ *
+ * @author astupidcoder
+ * @since 2021-11-11
+ */
+@Repository
+public interface BaseBoxMapper extends BaseMapper<BaseBox> {
+
+}

+ 18 - 0
huimv-farm-v2/huimv-produce-warning/src/main/java/com/huimv/produce/mapper/BaseFloorMapper.java

@@ -0,0 +1,18 @@
+package com.huimv.produce.mapper;
+
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.huimv.produce.entity.BaseFloor;
+import org.springframework.stereotype.Repository;
+
+/**
+ * <p>
+ *  Mapper 接口
+ * </p>
+ *
+ * @author astupidcoder
+ * @since 2021-11-11
+ */
+@Repository
+public interface BaseFloorMapper extends BaseMapper<BaseFloor> {
+
+}

+ 18 - 0
huimv-farm-v2/huimv-produce-warning/src/main/java/com/huimv/produce/mapper/BaseRoomMapper.java

@@ -0,0 +1,18 @@
+package com.huimv.produce.mapper;
+
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.huimv.produce.entity.BaseRoom;
+import org.springframework.stereotype.Repository;
+
+/**
+ * <p>
+ *  Mapper 接口
+ * </p>
+ *
+ * @author astupidcoder
+ * @since 2021-11-11
+ */
+@Repository
+public interface BaseRoomMapper extends BaseMapper<BaseRoom> {
+
+}

+ 26 - 0
huimv-farm-v2/huimv-produce-warning/src/main/java/com/huimv/produce/mapper/SysDayWaterMapper.java

@@ -0,0 +1,26 @@
+package com.huimv.produce.mapper;
+
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.baomidou.mybatisplus.core.toolkit.Constants;
+import com.huimv.produce.entity.SysDayWater;
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import org.apache.ibatis.annotations.Param;
+import org.springframework.stereotype.Repository;
+
+import java.util.List;
+
+/**
+ * <p>
+ *  Mapper 接口
+ * </p>
+ *
+ * @author astupidcoder
+ * @since 2021-11-12
+ */
+@Repository
+public interface SysDayWaterMapper extends BaseMapper<SysDayWater> {
+
+    Double countWater(@Param(Constants.WRAPPER) QueryWrapper<SysDayWater> wrapper);
+
+    List<SysDayWater> listAllWater(@Param(Constants.WRAPPER) QueryWrapper<SysDayWater> wrapper);
+}

+ 29 - 0
huimv-farm-v2/huimv-produce-warning/src/main/java/com/huimv/produce/mapper/SysFodderMapper.java

@@ -0,0 +1,29 @@
+package com.huimv.produce.mapper;
+
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.baomidou.mybatisplus.core.toolkit.Constants;
+import com.huimv.produce.entity.SysFodder;
+import com.huimv.produce.entity.dto.FodderDto;
+import org.apache.ibatis.annotations.Param;
+import org.springframework.stereotype.Repository;
+
+import java.util.List;
+
+/**
+ * <p>
+ *  Mapper 接口
+ * </p>
+ *
+ * @author astupidcoder
+ * @since 2021-11-15
+ */
+@Repository
+public interface SysFodderMapper extends BaseMapper<SysFodder> {
+
+    List<SysFodder> countDayValue(@Param(Constants.WRAPPER)QueryWrapper<SysFodder> wrapper);
+
+    List<FodderDto> countAllDayValue(@Param(Constants.WRAPPER)QueryWrapper<SysFodder> wrapper);
+
+    Integer countAllValue(@Param(Constants.WRAPPER)QueryWrapper<SysFodder> wrapper);
+}

+ 18 - 0
huimv-farm-v2/huimv-produce-warning/src/main/java/com/huimv/produce/mapper/SysHumidityMapper.java

@@ -0,0 +1,18 @@
+package com.huimv.produce.mapper;
+
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.huimv.produce.entity.SysHumidity;
+import org.springframework.stereotype.Repository;
+
+/**
+ * <p>
+ *  Mapper 接口
+ * </p>
+ *
+ * @author astupidcoder
+ * @since 2021-11-11
+ */
+@Repository
+public interface SysHumidityMapper extends BaseMapper<SysHumidity> {
+
+}

+ 24 - 0
huimv-farm-v2/huimv-produce-warning/src/main/java/com/huimv/produce/mapper/SysMonthWaterMapper.java

@@ -0,0 +1,24 @@
+package com.huimv.produce.mapper;
+
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.baomidou.mybatisplus.core.toolkit.Constants;
+import com.huimv.produce.entity.SysMonthWater;
+import org.apache.ibatis.annotations.Param;
+import org.springframework.stereotype.Repository;
+
+import java.util.List;
+
+/**
+ * <p>
+ *  Mapper 接口
+ * </p>
+ *
+ * @author astupidcoder
+ * @since 2021-11-12
+ */
+@Repository
+public interface SysMonthWaterMapper extends BaseMapper<SysMonthWater> {
+
+    List<SysMonthWater> selecAllMonthWater(@Param(Constants.WRAPPER)QueryWrapper<SysMonthWater> monthWaterWrapper);
+}

+ 18 - 0
huimv-farm-v2/huimv-produce-warning/src/main/java/com/huimv/produce/mapper/SysTemperatureMapper.java

@@ -0,0 +1,18 @@
+package com.huimv.produce.mapper;
+
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.huimv.produce.entity.SysTemperature;
+import org.springframework.stereotype.Repository;
+
+/**
+ * <p>
+ *  Mapper 接口
+ * </p>
+ *
+ * @author astupidcoder
+ * @since 2021-11-11
+ */
+@Repository
+public interface SysTemperatureMapper extends BaseMapper<SysTemperature> {
+
+}

+ 17 - 0
huimv-farm-v2/huimv-produce-warning/src/main/java/com/huimv/produce/service/IBaseBoxService.java

@@ -0,0 +1,17 @@
+package com.huimv.produce.service;
+
+import com.baomidou.mybatisplus.extension.service.IService;
+import com.huimv.produce.entity.BaseBox;
+
+import java.util.List;
+
+/**
+ * <p>
+ *  服务类
+ * </p>
+ *
+ * @author astupidcoder
+ * @since 2021-11-11
+ */
+public interface IBaseBoxService extends IService<BaseBox> {
+}

+ 16 - 0
huimv-farm-v2/huimv-produce-warning/src/main/java/com/huimv/produce/service/IBaseFloorService.java

@@ -0,0 +1,16 @@
+package com.huimv.produce.service;
+
+import com.baomidou.mybatisplus.extension.service.IService;
+import com.huimv.produce.entity.BaseFloor;
+
+/**
+ * <p>
+ *  服务类
+ * </p>
+ *
+ * @author astupidcoder
+ * @since 2021-11-11
+ */
+public interface IBaseFloorService extends IService<BaseFloor> {
+
+}

+ 22 - 0
huimv-farm-v2/huimv-produce-warning/src/main/java/com/huimv/produce/service/IBaseRoomService.java

@@ -0,0 +1,22 @@
+package com.huimv.produce.service;
+
+import com.baomidou.mybatisplus.extension.service.IService;
+import com.huimv.common.utils.Result;
+import com.huimv.produce.entity.BaseRoom;
+
+import java.util.Map;
+
+/**
+ * <p>
+ *  服务类
+ * </p>
+ *
+ * @author astupidcoder
+ * @since 2021-11-11
+ */
+public interface IBaseRoomService extends IService<BaseRoom> {
+
+    Result getAllRoomEnvironment();
+
+    Result listByRoom(Map<String,String> map);
+}

+ 22 - 0
huimv-farm-v2/huimv-produce-warning/src/main/java/com/huimv/produce/service/ISysDayWaterService.java

@@ -0,0 +1,22 @@
+package com.huimv.produce.service;
+
+import com.huimv.common.utils.Result;
+import com.huimv.produce.entity.SysDayWater;
+import com.baomidou.mybatisplus.extension.service.IService;
+
+import java.util.Map;
+
+/**
+ * <p>
+ *  服务类
+ * </p>
+ *
+ * @author astupidcoder
+ * @since 2021-11-12
+ */
+public interface ISysDayWaterService extends IService<SysDayWater> {
+
+    Result listWater(Map<String,String>  map);
+
+    Result listAllWater(Map<String, String> map);
+}

+ 22 - 0
huimv-farm-v2/huimv-produce-warning/src/main/java/com/huimv/produce/service/ISysFodderService.java

@@ -0,0 +1,22 @@
+package com.huimv.produce.service;
+
+import com.baomidou.mybatisplus.extension.service.IService;
+import com.huimv.common.utils.Result;
+import com.huimv.produce.entity.SysFodder;
+
+import java.util.Map;
+
+/**
+ * <p>
+ *  服务类
+ * </p>
+ *
+ * @author astupidcoder
+ * @since 2021-11-15
+ */
+public interface ISysFodderService extends IService<SysFodder> {
+
+    Result getFodder(Map map);
+
+    Result getAllFodder(Map map);
+}

+ 16 - 0
huimv-farm-v2/huimv-produce-warning/src/main/java/com/huimv/produce/service/ISysHumidityService.java

@@ -0,0 +1,16 @@
+package com.huimv.produce.service;
+
+import com.baomidou.mybatisplus.extension.service.IService;
+import com.huimv.produce.entity.SysHumidity;
+
+/**
+ * <p>
+ *  服务类
+ * </p>
+ *
+ * @author astupidcoder
+ * @since 2021-11-11
+ */
+public interface ISysHumidityService extends IService<SysHumidity> {
+
+}

+ 18 - 0
huimv-farm-v2/huimv-produce-warning/src/main/java/com/huimv/produce/service/ISysMonthWaterService.java

@@ -0,0 +1,18 @@
+package com.huimv.produce.service;
+
+import com.huimv.common.utils.Result;
+import com.huimv.produce.entity.SysMonthWater;
+import com.baomidou.mybatisplus.extension.service.IService;
+
+/**
+ * <p>
+ *  服务类
+ * </p>
+ *
+ * @author astupidcoder
+ * @since 2021-11-12
+ */
+public interface ISysMonthWaterService extends IService<SysMonthWater> {
+
+    Result getAllDayWater();
+}

+ 16 - 0
huimv-farm-v2/huimv-produce-warning/src/main/java/com/huimv/produce/service/ISysTemperatureService.java

@@ -0,0 +1,16 @@
+package com.huimv.produce.service;
+
+import com.baomidou.mybatisplus.extension.service.IService;
+import com.huimv.produce.entity.SysTemperature;
+
+/**
+ * <p>
+ *  服务类
+ * </p>
+ *
+ * @author astupidcoder
+ * @since 2021-11-11
+ */
+public interface ISysTemperatureService extends IService<SysTemperature> {
+
+}

+ 20 - 0
huimv-farm-v2/huimv-produce-warning/src/main/java/com/huimv/produce/service/impl/BaseBoxServiceImpl.java

@@ -0,0 +1,20 @@
+package com.huimv.produce.service.impl;
+
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.huimv.produce.entity.BaseBox;
+import com.huimv.produce.mapper.BaseBoxMapper;
+import com.huimv.produce.service.IBaseBoxService;
+import org.springframework.stereotype.Service;
+
+/**
+ * <p>
+ *  服务实现类
+ * </p>
+ *
+ * @author astupidcoder
+ * @since 2021-11-11
+ */
+@Service
+public class BaseBoxServiceImpl extends ServiceImpl<BaseBoxMapper, BaseBox> implements IBaseBoxService {
+
+}

+ 20 - 0
huimv-farm-v2/huimv-produce-warning/src/main/java/com/huimv/produce/service/impl/BaseFloorServiceImpl.java

@@ -0,0 +1,20 @@
+package com.huimv.produce.service.impl;
+
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.huimv.produce.entity.BaseFloor;
+import com.huimv.produce.mapper.BaseFloorMapper;
+import com.huimv.produce.service.IBaseFloorService;
+import org.springframework.stereotype.Service;
+
+/**
+ * <p>
+ *  服务实现类
+ * </p>
+ *
+ * @author astupidcoder
+ * @since 2021-11-11
+ */
+@Service
+public class BaseFloorServiceImpl extends ServiceImpl<BaseFloorMapper, BaseFloor> implements IBaseFloorService {
+
+}

+ 139 - 0
huimv-farm-v2/huimv-produce-warning/src/main/java/com/huimv/produce/service/impl/BaseRoomServiceImpl.java

@@ -0,0 +1,139 @@
+package com.huimv.produce.service.impl;
+
+import cn.hutool.core.util.StrUtil;
+import cn.hutool.poi.excel.ExcelUtil;
+import cn.hutool.poi.excel.ExcelWriter;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.baomidou.mybatisplus.core.toolkit.StringUtils;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.huimv.common.utils.DataUill;
+import com.huimv.common.utils.Result;
+import com.huimv.common.utils.ResultCode;
+import com.huimv.produce.entity.BaseRoom;
+import com.huimv.produce.entity.SysHumidity;
+import com.huimv.produce.entity.SysTemperature;
+import com.huimv.produce.mapper.BaseRoomMapper;
+import com.huimv.produce.mapper.SysHumidityMapper;
+import com.huimv.produce.mapper.SysTemperatureMapper;
+import com.huimv.produce.service.IBaseRoomService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.util.*;
+
+/**
+ * <p>
+ *  服务实现类
+ * </p>
+ *
+ * @author astupidcoder
+ * @since 2021-11-11
+ */
+@Service
+public class BaseRoomServiceImpl extends ServiceImpl<BaseRoomMapper, BaseRoom> implements IBaseRoomService {
+
+    @Autowired
+    private SysHumidityMapper humidityMapper;
+
+    @Autowired
+    private SysTemperatureMapper temperatureMapper;
+
+    @Override
+    public Result getAllRoomEnvironment() {
+        List<BaseRoom> roomList = this.list();
+        List resultList = new ArrayList();
+        for (BaseRoom baseRoom : roomList) {
+            Map map =new HashMap();
+            SysHumidity humidity = humidityMapper.selectOne(new QueryWrapper<SysHumidity>().eq("room_id", baseRoom.getId()).last("ORDER BY hum_id  DESC limit 1"));
+            SysTemperature temperature = temperatureMapper.selectOne(new QueryWrapper<SysTemperature>().eq("room_id", baseRoom.getId()).last("ORDER BY tem_id  DESC limit 1"));
+            if (humidity != null){
+                map.put("humidity",humidity.getValue());
+            }else {
+                map.put("humidity",null);
+            }
+            if (temperature != null){
+                map.put("temperature",temperature.getValue());
+            }else {
+                map.put("temperature",null);
+            }
+
+
+            map.put("room",baseRoom.getAlias()+baseRoom.getRoomName());
+            resultList.add(map);
+        }
+        return new Result(ResultCode.SUCCESS,resultList);
+    }
+
+    @Override
+    public Result listByRoom(Map<String,String> map) {
+        String roomId = map.get("roomId");
+        String startDate = map.get("startDate");
+        String endDate = map.get("endDate");
+        String type = map.get("type");
+        String isExcel =(String) map.get("isExcel");
+
+        BaseRoom baseRoom = new BaseRoom();
+        if (StrUtil.isBlank(roomId)){
+            baseRoom =  this.getOne(new QueryWrapper<BaseRoom>().last("limit 1"));
+            roomId = baseRoom.getId()+"";
+        }else {
+            baseRoom =this.getById(roomId);
+        }
+
+        QueryWrapper<SysHumidity> humidityWrapper = new QueryWrapper<>();
+        QueryWrapper<SysTemperature> temperatureWrapper = new QueryWrapper<>();
+        humidityWrapper.eq("room_id",roomId);
+        temperatureWrapper.eq("room_id",roomId);
+
+        List<SysHumidity> humidities;
+        List<SysTemperature> semperatures;
+        //根据自定义
+        Map resultMap = new HashMap<>();
+        if ("4".equals(type) ){
+             humidities = humidityMapper.selectList(humidityWrapper.between("create_time", startDate, endDate));
+             semperatures = temperatureMapper.selectList(temperatureWrapper.between("create_time", startDate, endDate));
+            resultMap.put("humidities",humidities);
+            resultMap.put("semperatures",semperatures);
+        }
+
+        //本月
+        else if ("3".equals(type)){
+            Date timesMonthmorning = DataUill.getTimesMonthmorning();
+            humidities = humidityMapper.selectList(humidityWrapper.ge("create_time",timesMonthmorning ));
+             semperatures = temperatureMapper.selectList(temperatureWrapper.ge("create_time", timesMonthmorning));
+            resultMap.put("humidities",humidities);
+            resultMap.put("semperatures",semperatures);
+        }
+        //本周
+        else if ("2".equals(type)){
+            Date timesWeekmorning = DataUill.getTimesWeekmorning();
+             humidities = humidityMapper.selectList(humidityWrapper.ge("create_time",timesWeekmorning ));
+             semperatures = temperatureMapper.selectList(temperatureWrapper.ge("create_time", timesWeekmorning));
+            resultMap.put("humidities",humidities);
+            resultMap.put("semperatures",semperatures);
+        }
+        //今日
+        else {
+            Date timesmorning = DataUill.getTimesmorning();
+            humidities = humidityMapper.selectList(humidityWrapper.ge("create_time",timesmorning ));
+            semperatures = temperatureMapper.selectList(temperatureWrapper.ge("create_time", timesmorning));
+            resultMap.put("humidities",humidities);
+            resultMap.put("semperatures",semperatures);
+        }
+
+        resultMap.put("roomName",baseRoom.getAlias()+baseRoom.getRoomName());
+//        if ("1".equals(isExcel)){
+//            writerExcel(humidities,"温度曲线");
+//        }
+
+        return new Result(ResultCode.SUCCESS,resultMap);
+    }
+
+//    private void writerExcel(List list,String title) {
+//        ExcelWriter writer = ExcelUtil.getWriter("C:\\Users\\Administrator\\Desktop\\writeBeanTest.xlsx");
+//        writer.merge(4, title);
+//
+//        writer.write(list, true);
+//        writer.close();
+//    }
+}

+ 203 - 0
huimv-farm-v2/huimv-produce-warning/src/main/java/com/huimv/produce/service/impl/SysDayWaterServiceImpl.java

@@ -0,0 +1,203 @@
+package com.huimv.produce.service.impl;
+
+import cn.hutool.core.util.ObjectUtil;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.baomidou.mybatisplus.core.toolkit.StringUtils;
+import com.huimv.common.utils.DataUill;
+import com.huimv.common.utils.Result;
+import com.huimv.common.utils.ResultCode;
+import com.huimv.produce.entity.BaseRoom;
+import com.huimv.produce.entity.SysMonthWater;
+import com.huimv.produce.mapper.BaseRoomMapper;
+import com.huimv.produce.mapper.SysDayWaterMapper;
+import com.huimv.produce.mapper.SysMonthWaterMapper;
+import com.huimv.produce.service.ISysDayWaterService;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.huimv.produce.entity.SysDayWater;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.text.DecimalFormat;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * <p>
+ *  服务实现类
+ * </p>
+ *
+ * @author astupidcoder
+ * @since 2021-11-12
+ */
+@Service
+public class SysDayWaterServiceImpl extends ServiceImpl<SysDayWaterMapper, SysDayWater> implements ISysDayWaterService {
+
+    @Autowired
+    private SysDayWaterMapper dayWaterMapper;
+
+    @Autowired
+    private SysMonthWaterMapper monthWaterMapper;
+
+    @Autowired
+    private BaseRoomMapper baseRoomMapper;
+
+
+
+    @Override
+    public Result listWater(Map<String,String> map) {
+        String type = map.get("type");
+        String startDate = map.get("startDate");
+        String endDate = map.get("endDate");
+        String roomId = map.get("roomId");
+        DecimalFormat df = new DecimalFormat("#.00");
+        BaseRoom baseRoom ;
+        if (roomId == null){
+            baseRoom = baseRoomMapper.selectList(null).get(0);
+            roomId = baseRoom.getId()+"";
+        }else {
+            baseRoom = baseRoomMapper.selectById(roomId);
+        }
+
+
+
+        QueryWrapper<SysDayWater> wrapper = new QueryWrapper<>();
+        wrapper.eq(StringUtils.isNotEmpty(roomId),"room_id",roomId);
+
+
+        Map endMap = new HashMap();
+        //自定义
+        if ("4".equals(type)){
+            endDate= endDate+" 23:59:59";
+            wrapper.between("create_time", startDate, endDate);
+            List<SysDayWater> dayWater = this.list(wrapper);
+            endMap.put("data",dayWater);
+            Double countWater = dayWaterMapper.countWater(wrapper);
+            endMap.put("countWater",countWater);
+        }
+        //本月
+        else if ("3".equals(type)) {
+            wrapper.ge("create_time", DataUill.getTimesMonthmorning());
+            List<SysDayWater> dayWater = this.list(wrapper);
+            endMap.put("data",dayWater);
+
+
+            Double countWater = dayWaterMapper.countWater(wrapper);
+            endMap.put("countWater",countWater);
+        }
+
+        //本周
+        else if ("2".equals(type)) {
+            wrapper.ge("create_time", DataUill.getTimesWeekmorning());
+            List<SysDayWater> dayWater = this.list(wrapper);
+            endMap.put("data",dayWater);
+            Double countWater = dayWaterMapper.countWater(wrapper);
+            endMap.put("countWater",countWater);
+        }
+        //今日
+        else  {
+
+            QueryWrapper<SysMonthWater> monthWaterWrapper = new QueryWrapper<>();
+            monthWaterWrapper.ge("create_time", DataUill.getTimesmorning());
+            monthWaterWrapper.eq("room_id",roomId);
+            List<SysMonthWater> monthWaters = monthWaterMapper.selecAllMonthWater(monthWaterWrapper);
+            List<SysMonthWater> list= new ArrayList<>();
+            endMap.put("countWater",null);
+            if (ObjectUtil.isNotEmpty(monthWaters)){
+                Double num  =0.0;
+                for (SysMonthWater monthWater : monthWaters) {
+
+                    num =  Double.valueOf( monthWater.getValue()) + num;
+                }
+                String format = df.format(num);
+                if (format.length() == 3){
+                    endMap.put("countWater","0.00");
+                }else {
+                    endMap.put("countWater",format);
+                }
+
+            }
+            endMap.put("data",monthWaters);
+
+        }
+        endMap.put("room",baseRoom.getAlias()+baseRoom.getRoomName());
+
+
+        return new Result(ResultCode.SUCCESS,endMap);
+    }
+
+    @Override
+    public Result listAllWater(Map<String, String> map) {
+        String type = map.get("type");
+        String startDate = map.get("startDate");
+        String endDate = map.get("endDate");
+        DecimalFormat df = new DecimalFormat("#.00");
+
+
+        QueryWrapper<SysDayWater> wrapper = new QueryWrapper<>();
+
+
+        Map endMap = new HashMap();
+        //自定义
+        if ("4".equals(type)){
+            wrapper.between("create_time", startDate, endDate);
+            List<SysDayWater> dayWater = dayWaterMapper.listAllWater(wrapper);
+            endMap.put("data",dayWater);
+            Double countWater = dayWaterMapper.countWater(wrapper);
+            if (ObjectUtil.isNotEmpty(countWater)){
+                endMap.put("countWater",countWater);
+            }else {
+                endMap.put("countWater",null);
+            }
+
+        }
+        //本月
+        else if ("3".equals(type)) {
+            wrapper.ge("create_time", DataUill.getTimesMonthmorning());
+            List<SysDayWater> dayWater = dayWaterMapper.listAllWater(wrapper);
+            endMap.put("data",dayWater);
+
+
+            Double countWater = dayWaterMapper.countWater(wrapper);
+            endMap.put("countWater",countWater);
+        }
+
+        //本周
+        else if ("2".equals(type)) {
+            wrapper.ge("create_time", DataUill.getTimesWeekmorning());
+            List<SysDayWater> dayWater = dayWaterMapper.listAllWater(wrapper);
+            endMap.put("data",dayWater);
+            Double countWater = dayWaterMapper.countWater(wrapper);
+            endMap.put("countWater",countWater);
+        }
+        //今日
+        else  {
+
+            QueryWrapper<SysMonthWater> monthWaterWrapper = new QueryWrapper<>();
+            monthWaterWrapper.ge("create_time", DataUill.getTimesmorning());
+            List<SysMonthWater> monthWaters = monthWaterMapper.selecAllMonthWater(monthWaterWrapper);
+//            List<SysMonthWater> list= new ArrayList<>();
+            endMap.put("countWater",null);
+            if (ObjectUtil.isNotEmpty(monthWaters)){
+                Double num  =0.0;
+                for (SysMonthWater monthWater : monthWaters) {
+
+                   num =  Double.valueOf( monthWater.getValue()) + num;
+                }
+                String format = df.format(num);
+                if (format.length() == 3){
+                    endMap.put("countWater","0.00");
+                }else {
+                    endMap.put("countWater",format);
+                }
+            }
+            endMap.put("data",monthWaters);
+
+        }
+
+
+
+        return new Result(ResultCode.SUCCESS,endMap);
+    }
+}

+ 116 - 0
huimv-farm-v2/huimv-produce-warning/src/main/java/com/huimv/produce/service/impl/SysFodderServiceImpl.java

@@ -0,0 +1,116 @@
+package com.huimv.produce.service.impl;
+
+import cn.hutool.core.util.ObjectUtil;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.baomidou.mybatisplus.core.toolkit.StringUtils;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.huimv.common.utils.DataUill;
+import com.huimv.common.utils.Result;
+import com.huimv.common.utils.ResultCode;
+import com.huimv.produce.entity.SysFodder;
+import com.huimv.produce.entity.dto.FodderDto;
+import com.huimv.produce.mapper.SysFodderMapper;
+import com.huimv.produce.service.ISysFodderService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * <p>
+ *  服务实现类
+ * </p>
+ *
+ * @author astupidcoder
+ * @since 2021-11-15
+ */
+@Service
+public class SysFodderServiceImpl extends ServiceImpl<SysFodderMapper, SysFodder> implements ISysFodderService {
+
+    @Autowired
+    private SysFodderMapper fodderMapper;
+
+
+
+    @Override
+    public Result getAllFodder(Map map) {
+        String startDate = (String) map.get("satrtDate");
+        String endDate = (String) map.get("endDate");
+        Integer type = (Integer) map.get("type");
+        QueryWrapper<SysFodder> wrapper = new QueryWrapper<>();
+        Map endMap = new HashMap();
+        //自定义
+        if ("3".equals(type)){
+            endDate = endDate +" 23:59:59";
+            wrapper.between("create_time",startDate,endDate);
+
+            List<FodderDto> sysFodders = fodderMapper.countAllDayValue(wrapper);
+            Integer countAllValue = fodderMapper.countAllValue(wrapper);
+            endMap.put("fodderList",sysFodders);
+            endMap.put("value",countAllValue);
+        }
+        //本周
+        else if ("1".equals(type)){
+            wrapper.ge("create_time", DataUill.getTimesWeekmorning());
+            List<FodderDto> sysFodders = fodderMapper.countAllDayValue(wrapper);
+            Integer countAllValue = fodderMapper.countAllValue(wrapper);
+            endMap.put("fodderList",sysFodders);
+            endMap.put("value",countAllValue);
+        }
+        //本月
+        else {
+            wrapper.ge("create_time", DataUill.getTimesMonthmorning());
+            List<FodderDto> sysFodders = fodderMapper.countAllDayValue(wrapper);
+            Integer countAllValue = fodderMapper.countAllValue(wrapper);
+            endMap.put("fodderList",sysFodders);
+            endMap.put("value",countAllValue);
+        }
+        return new Result(ResultCode.SUCCESS,endMap);
+    }
+
+    @Override
+    public Result getFodder(Map map) {
+        String startDate = (String) map.get("satrtDate");
+        String endDate = (String) map.get("endDate");
+        Integer type = (Integer) map.get("type");
+        Integer floorId = (Integer)map.get("floorId");
+       if (ObjectUtil.isEmpty(floorId)){
+           floorId =1;
+       }
+
+        QueryWrapper<SysFodder> wrapper = new QueryWrapper<>();
+        wrapper.eq("floor_id",floorId);
+        Map endMap = new HashMap();
+        //自定义
+        if ("3".equals(type)){
+            endDate = endDate +" 23:59:59";
+            wrapper.between("create_time",startDate,endDate);
+
+            List<SysFodder> sysFodders = fodderMapper.countDayValue(wrapper);
+            Integer countAllValue = fodderMapper.countAllValue(wrapper);
+            endMap.put("fodderList",sysFodders);
+            endMap.put("value",countAllValue);
+        }
+        //本周
+        else if ("1".equals(type)){
+            wrapper.ge("create_time", DataUill.getTimesWeekmorning());
+            List<SysFodder> sysFodders = fodderMapper.countDayValue(wrapper);
+            Integer countAllValue = fodderMapper.countAllValue(wrapper);
+            endMap.put("fodderList",sysFodders);
+            endMap.put("value",countAllValue);
+        }
+        //本月
+        else {
+            wrapper.ge("create_time", DataUill.getTimesMonthmorning());
+            List<SysFodder> sysFodders = fodderMapper.countDayValue(wrapper);
+            Integer countAllValue = fodderMapper.countAllValue(wrapper);
+            endMap.put("fodderList",sysFodders);
+            endMap.put("value",countAllValue);
+        }
+        return new Result(ResultCode.SUCCESS,endMap);
+    }
+
+
+}

+ 20 - 0
huimv-farm-v2/huimv-produce-warning/src/main/java/com/huimv/produce/service/impl/SysHumidityServiceImpl.java

@@ -0,0 +1,20 @@
+package com.huimv.produce.service.impl;
+
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.huimv.produce.entity.SysHumidity;
+import com.huimv.produce.mapper.SysHumidityMapper;
+import com.huimv.produce.service.ISysHumidityService;
+import org.springframework.stereotype.Service;
+
+/**
+ * <p>
+ *  服务实现类
+ * </p>
+ *
+ * @author astupidcoder
+ * @since 2021-11-11
+ */
+@Service
+public class SysHumidityServiceImpl extends ServiceImpl<SysHumidityMapper, SysHumidity> implements ISysHumidityService {
+
+}

+ 59 - 0
huimv-farm-v2/huimv-produce-warning/src/main/java/com/huimv/produce/service/impl/SysMonthWaterServiceImpl.java

@@ -0,0 +1,59 @@
+package com.huimv.produce.service.impl;
+
+import cn.hutool.core.util.ObjectUtil;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.huimv.common.utils.Result;
+import com.huimv.common.utils.ResultCode;
+import com.huimv.produce.entity.BaseRoom;
+import com.huimv.produce.entity.SysMonthWater;
+import com.huimv.produce.mapper.BaseRoomMapper;
+import com.huimv.produce.mapper.SysMonthWaterMapper;
+import com.huimv.produce.service.ISysMonthWaterService;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * <p>
+ *  服务实现类
+ * </p>
+ *
+ * @author astupidcoder
+ * @since 2021-11-12
+ */
+@Service
+public class SysMonthWaterServiceImpl extends ServiceImpl<SysMonthWaterMapper, SysMonthWater> implements ISysMonthWaterService {
+
+    @Autowired
+    private BaseRoomMapper baseRoomMapper;
+
+    @Override
+    public Result getAllDayWater() {
+        List<BaseRoom> baseRooms = baseRoomMapper.selectList(null);
+        List endList = new ArrayList();
+        for (BaseRoom baseRoom : baseRooms) {
+            Integer id = baseRoom.getId();
+
+            SysMonthWater monthWater = this.getOne(new QueryWrapper<SysMonthWater>().eq("room_id", id).orderByDesc("id").last("limit 1"));
+
+            Map map = new HashMap();
+            map.put("room",baseRoom.getAlias()+baseRoom.getRoomName());
+            if (ObjectUtil.isNotEmpty(monthWater)){
+                map.put("water",monthWater.getValue());
+            }else {
+                map.put("water",null);
+            }
+
+            endList.add(map);
+        }
+
+
+
+        return new Result(ResultCode.SUCCESS,endList);
+    }
+}

+ 20 - 0
huimv-farm-v2/huimv-produce-warning/src/main/java/com/huimv/produce/service/impl/SysTemperatureServiceImpl.java

@@ -0,0 +1,20 @@
+package com.huimv.produce.service.impl;
+
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.huimv.produce.entity.SysTemperature;
+import com.huimv.produce.mapper.SysTemperatureMapper;
+import com.huimv.produce.service.ISysTemperatureService;
+import org.springframework.stereotype.Service;
+
+/**
+ * <p>
+ *  服务实现类
+ * </p>
+ *
+ * @author astupidcoder
+ * @since 2021-11-11
+ */
+@Service
+public class SysTemperatureServiceImpl extends ServiceImpl<SysTemperatureMapper, SysTemperature> implements ISysTemperatureService {
+
+}

+ 161 - 0
huimv-farm-v2/huimv-produce-warning/src/main/java/com/huimv/produce/sgd/FBoxSignalRConnection.java

@@ -0,0 +1,161 @@
+package com.huimv.produce.sgd;
+
+import com.github.signalr4j.client.hubs.HubProxy;
+import com.google.gson.Gson;
+import com.google.gson.GsonBuilder;
+import com.google.gson.JsonArray;
+import com.google.gson.JsonObject;
+import com.huimv.produce.sgd.fbox.Logger;
+import com.huimv.produce.sgd.fbox.LoggerFactory;
+import com.huimv.produce.sgd.fbox.TokenManager;
+import com.huimv.produce.sgd.fbox.signalr.SignalRConnectionBase;
+
+import java.net.Proxy;
+import java.text.SimpleDateFormat;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.atomic.LongAdder;
+
+public class FBoxSignalRConnection extends SignalRConnectionBase {
+    private final Gson gson;
+    private final Logger logger;
+    ConcurrentHashMap<Long, LongAdder> dmonIds = new ConcurrentHashMap<>();
+    private LongAdder dmonMsgCounter = new LongAdder();
+    private long lastDmonItemCount;
+    private long lastDmonMsgCount;
+    private long lastReportTime;
+    private Proxy proxy;
+    private LongAdder dmonItemCounter = new LongAdder();
+
+    public FBoxSignalRConnection(String hubUrl, String signalrClientId, TokenManager tokenManager, Proxy proxy, LoggerFactory loggerFactory) {
+        super(hubUrl, signalrClientId, tokenManager, proxy, loggerFactory);
+        this.logger = loggerFactory.createLogger("FBoxSignalRConnection");
+        this.proxy = proxy;
+        gson = new GsonBuilder().create();
+//        new Thread(() -> {
+//            //统计条目数线程,可以去掉此线程代码
+//            for (; ; ) {
+//                try {
+//                    Thread.sleep(5000);
+//                } catch (InterruptedException e) {
+//                    e.printStackTrace();
+//                }
+//                long currentTime = System.nanoTime();
+//                long currentMsgCount = this.dmonMsgCounter.longValue();
+//                long currentItemCount = this.dmonItemCounter.longValue();
+//                long msgRate = (currentMsgCount - this.lastDmonMsgCount) * 1000000000 / (currentTime - this.lastReportTime);
+//                long itemRate = (currentItemCount - this.lastDmonItemCount) * 1000000000 / (currentTime - this.lastReportTime);
+//                this.logger.logInformation(String.format("Dmon id count: %d, item rate: %d, message rate: %d", this.dmonIds.size(), itemRate, msgRate));
+//                this.lastReportTime = currentTime;
+//                this.lastDmonMsgCount = currentMsgCount;
+//                this.lastDmonItemCount = currentItemCount;
+//            }
+//        }).start();
+    }
+
+    @Override
+    public void connected() {
+        super.connected();
+        dmonIds.clear();
+    }
+
+
+    @Override
+    protected void onHubProxyDestroyed(HubProxy hubProxy){
+        hubProxy.removeSubscription("dMonUpdateValue");
+        hubProxy.removeSubscription("alarmTriggered");
+        hubProxy.removeSubscription("alarmRecovered");
+        hubProxy.removeSubscription("boxConnStateChanged");
+    }
+
+    SimpleDateFormat sdf  = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
+    @Override
+    protected void onHubProxyCreated(HubProxy hubProxy) {
+        //signalr实时数据推送事件,接收此事件数据前提条件,开启监控点数据推送控制接口(订阅)
+        hubProxy.subscribe("dMonUpdateValue").addReceivedHandler(jsonElements -> {
+            Global.threadPool.submit(() -> {
+                //try{
+                    this.dmonMsgCounter.increment();
+                    //System.out.println("Dmon data received: ");
+                    //收到的推送数据
+                    JsonArray items = jsonElements[1].getAsJsonArray();
+                    for (com.google.gson.JsonElement jsonElement : items) {
+                        JsonObject item = jsonElement.getAsJsonObject();
+                        this.dmonIds.computeIfAbsent(item.get("id").getAsLong(), aLong -> new LongAdder()).increment();
+                        this.dmonItemCounter.increment();
+                        //收到的推送数据
+                        String name = item.get("name").getAsString();
+                        String value = item.get("value").getAsString();
+                        long time = item.get("t").getAsLong();
+                        this.logger.logInformation(String.format(" %s, %s, %d\n",name,value,time));
+                        //监控点正常无status属性
+                        //long statu = item.get("status").getAsLong();
+                    };
+                    //打印监控点的值集合,集合详细信息请看接口文档http://docs.flexem.net/fbox/zh-cn/tutorials/RealtimeDataPush.html
+                    System.out.printf("%s",jsonElements[1].getAsJsonArray());
+                    //打印boxUid
+                    System.out.printf("%s",jsonElements[2].getAsLong());
+//                }
+//                catch (Exception e) {
+//                    System.out.printf("%s", e);
+//                }
+            });
+        });
+
+        // signalr报警触发事件
+//        hubProxy.subscribe("alarmTriggered").addReceivedHandler(jsonElements -> {
+//            Global.threadPool.submit(() -> {
+//                System.out.println("Alarm triggered: ");
+//                for (com.google.gson.JsonElement jsonElement : jsonElements) {
+//                    //报警推送消息全部打印。具体参数解释请看接口文档http://docs.flexem.net/fbox/zh-cn/tutorials/AlarmTiggerPush.html
+//                    System.out.println("\t" + jsonElement);
+//                };
+//                //打印报警条目的值集合
+//                System.out.printf("%s",jsonElements[1].getAsJsonArray());
+//                //打印boxUid
+//                System.out.printf("%s",jsonElements[2].getAsLong());
+//            });
+//        });
+
+        // signalr报警还原事件
+//        hubProxy.subscribe("alarmRecovered").addReceivedHandler(jsonElements -> {
+//            Global.threadPool.submit(() -> {
+//                System.out.println("Alarm recovered: ");
+//                for (com.google.gson.JsonElement jsonElement : jsonElements) {
+//                    //报警推送消息全部打印。具体参数解释请看接口文档http://docs.flexem.net/fbox/zh-cn/tutorials/AlarmReductionPush.html
+//                    System.out.println("\t" + jsonElement);
+//                };
+//                //打印报警条目的值集合
+//                System.out.printf("%s",jsonElements[1].getAsJsonArray());
+//                //打印boxUid
+//                System.out.printf("%s",jsonElements[2].getAsLong());
+//            });
+//        });
+
+        // signalr盒子状态变更事件
+//        hubProxy.subscribe("boxConnStateChanged").addReceivedHandler(jsonElements -> {
+//            Global.threadPool.submit(() -> {
+//                System.out.println("Box state changed.");
+//                if (jsonElements.length <= 0)
+//                    return;
+//                BoxStateChanged[] stateChanges = gson.fromJson(jsonElements[0], BoxStateChanged[].class);
+//                this.logger.logInformation(String.format("receive count: %d", stateChanges.length));
+//                for (BoxStateChanged stateChange : stateChanges) {
+//                    // stateChange.id 是盒子列表中BoxReg对象下的box.id,可以根据这个过滤要开的盒子。
+//                    // stateChange.state 为1、2是盒子上线事件。实时数据推送需要开点
+//                    if (stateChange.state == 1 || stateChange.state == 2) {
+//                            try {
+//                                // 盒子每次上线后,均需要开启FBox数据推送控制接口(订阅)
+//                                Global.commServer.executePost("box/" + stateChange.id + "/dmon/start", String.class);
+//                                // token有效期为两小时。若token过期,demo会自动刷新token。所以返回401后均需要重试接口
+//                                this.logger.logInformation(String.format("Start dmon points on box ok %s\n",stateChange.id));
+//                            } catch (IOException e) {
+//                                System.out.println(e);
+//                                e.printStackTrace();
+//                            }
+//                    }
+//                }
+//
+//            });
+//        });
+    }
+}

+ 45 - 0
huimv-farm-v2/huimv-produce-warning/src/main/java/com/huimv/produce/sgd/Global.java

@@ -0,0 +1,45 @@
+package com.huimv.produce.sgd;
+
+
+import com.huimv.produce.sgd.fbox.ServerCaller;
+
+import java.net.Proxy;
+import java.util.UUID;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+
+public class Global {
+    public static Proxy proxy = null;
+//    配置流量过Fiddler代理
+//    public static Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress("127.0.0.1", 8888));
+    public static ExecutorService threadPool = Executors.newCachedThreadPool();
+    public static ServerCaller commServer;
+    public static ServerCaller appServer;
+    public static ServerCaller hdataServer;
+    public static ServerCaller apiBaseServer;
+
+    // 以下服务器地址是繁易公有云,私有云请根据实际情况修改
+//    public static final String idServerUrl = "https://account.flexem.com/core/";
+//    public static String appServerApiUrl = "http://fbox360.com/api/client/";
+//    public static final String commServerApiUrl = "http://fbcs101.fbox360.com/api/";
+//    public static final String commServerSignalRUrl = "http://fbcs101.fbox360.com/push";
+//    public static String hdataServerApiUrl = "http://fbhs1.fbox360.com/api/";
+
+    public static final String idServerUrl = "http://account.highgerman.cn/core/";
+    public static String appServerApiUrl = "http://cloud.highgerman.cn/";
+    public static final String commServerApiUrl = "http://cs.highgerman.cn/api/";
+    public static final String commServerSignalRUrl = "http://cs.highgerman.cn/push";
+    public static String hdataServerApiUrl = "http://hs.highgerman.cn/api/";
+    public static String apiBaserUrl = "http://cs.highgerman.cn/api";
+    public static String signalrClientId = UUID.randomUUID().toString();
+
+
+    //FlexManager注册的账号
+    public static String username = "sgdsgd103";
+    public static String password = "sgdsgd123";
+    // 获取API账号请咨询对接的销售。
+    public static String clientId = "fboxsdkcc";
+    public static String clientSecret = "6f556f31d524498baa0fc8c8bcb99285";
+
+
+}

+ 215 - 0
huimv-farm-v2/huimv-produce-warning/src/main/java/com/huimv/produce/sgd/Main.java

@@ -0,0 +1,215 @@
+package com.huimv.produce.sgd;
+
+import cn.hutool.core.util.ObjectUtil;
+import cn.hutool.json.JSONUtil;
+import com.huimv.produce.sgd.entity.Item;
+import com.huimv.produce.sgd.entity.Monitory;
+import com.huimv.produce.sgd.entity.MonitoryGetArgs;
+import com.huimv.produce.sgd.entity.MonitoryValue;
+import com.huimv.produce.sgd.fbox.ConsoleLoggerFactory;
+import com.huimv.produce.sgd.fbox.ServerCaller;
+import com.huimv.produce.sgd.fbox.StaticCredentialProvider;
+import com.huimv.produce.sgd.fbox.TokenManager;
+import com.huimv.produce.sgd.fbox.models.BoxGroup;
+import com.huimv.produce.sgd.fbox.models.BoxReg;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+public class Main {
+    private static final long SLEEP_TIME = 1000;
+
+    public static void main(String[] args) throws IOException, InterruptedException {
+        ConsoleLoggerFactory loggerFactory = new ConsoleLoggerFactory();
+        // 指定连接服务器的凭据参数
+        TokenManager tokenManager = new TokenManager(new StaticCredentialProvider(Global.clientId, Global.clientSecret, Global.username, Global.password), Global.idServerUrl, loggerFactory);
+        ServerCaller appServer = new ServerCaller(tokenManager, Global.appServerApiUrl, Global.signalrClientId, loggerFactory);
+        ServerCaller apiBaseServer = new ServerCaller(tokenManager, Global.apiBaserUrl, Global.signalrClientId, loggerFactory);
+        Global.appServer = appServer;
+        Global.apiBaseServer = apiBaseServer;
+
+        BoxGroup[] boxGroups = appServer.executeGet("api/client/box/grouped", BoxGroup[].class);
+        // 返回的是 盒子分组-盒子注册项(BoxReg) 的二层结构
+        List<Map> list = new ArrayList();
+        for (BoxGroup group : boxGroups) {
+            //盒子
+            for (BoxReg boxReg : group.boxRegs) {
+                if (boxReg.alias.contains("环控")){
+                    Monitory[] monitories = apiBaseServer.executeGet("/v2/box/" + boxReg.boxUid + "/dmon/grouped", Monitory[].class);
+                    //每个监控点
+                    List<Map> groupnames = new ArrayList();
+                    for (Monitory monitory : monitories) {
+//                        System.out.println("监控点------------->" + monitory.toString());
+                       List names = new ArrayList();
+                        for (Item item : monitory.items) {
+                            String name = item.name;
+                            if ( monitory.name.contains("每个房间") && name != null ) {
+                                if (name.contains("平均温度") || name.contains("湿度") ||name.contains("日用水量") ||name.contains("月用水量")  ) {
+                                    names.add(name);
+                                }
+                            }
+
+                        }
+                                              Map map = new HashMap();
+
+                        if (ObjectUtil.isNotEmpty(names)) {
+                            MonitoryValue[] monitoryValues = apiBaseServer.executePost("/v2/box/" + boxReg.boxUid + "/dmon/value/get", new MonitoryGetArgs(names, null, new ArrayList()), MonitoryValue[].class);
+                            StringBuilder str = new StringBuilder();
+                            for (MonitoryValue monitoryValue : monitoryValues) {
+                                if (ObjectUtil.isNotEmpty(monitory)) {
+                                    str.append(JSONUtil.toJsonStr(monitoryValue));
+                                }
+
+                            }
+                            map.put("monitoryValues", str);
+                            map.put("grpName", monitory.name);
+//                        map.put("names",names);
+                            groupnames.add(map);
+                        }
+                    }
+
+                    if (ObjectUtil.isNotEmpty(groupnames)){
+                        Map map = new HashMap();
+                        map.put("name",boxReg.alias);
+                        map.put("groupnames",groupnames);
+
+                        list.add(map);
+                    }
+                }
+            }
+        }
+
+        for (Map map : list) {
+            System.out.println(map.get("name")+"----->"+map.get("groupnames"));
+        }
+
+
+    }
+
+
+
+
+   /* private static final long SLEEP_TIME = 3000;
+    public static void main(String[] args) {
+
+        ConsoleLoggerFactory loggerFactory = new ConsoleLoggerFactory();
+
+        // 指定连接服务器的凭据参数
+        TokenManager tokenManager = new TokenManager(new StaticCredentialProvider(Global.clientId, Global.clientSecret, Global.username, Global.password), Global.idServerUrl, loggerFactory);
+
+        ServerCaller commServer = new ServerCaller(tokenManager, Global.commServerApiUrl, Global.signalrClientId, loggerFactory);
+        ServerCaller appServer = new ServerCaller(tokenManager, Global.appServerApiUrl, Global.signalrClientId, loggerFactory);
+        ServerCaller hdataServer = new ServerCaller(tokenManager, Global.hdataServerApiUrl, Global.signalrClientId, loggerFactory);
+
+        Global.commServer = commServer;
+        Global.appServer = appServer;
+        Global.hdataServer = hdataServer;
+
+        //建立signalr实例,signalr为单例模式
+        FBoxSignalRConnection fboxSignalR = new FBoxSignalRConnection(Global.commServerSignalRUrl, Global.signalrClientId, tokenManager, Global.proxy, loggerFactory);
+
+        // 连接SignalR推送通道
+        fboxSignalR.start();
+//        fboxSignalR.onHubProxyCreated();
+        // signalr连上后,请看src/main/java/FBoxSignalRConnection.java 接受推送数据的回调类。
+
+        System.out.println("Box list:");
+//        try {
+//以下为调接口示例,可忽略,若使用,参数请根据文档填写自己的账号下的参数
+
+        // 获取盒子列表接口示例,可忽略
+        try {
+            BoxGroup[] boxGroups = Global.appServer.executeGet("api/client/box/grouped", BoxGroup[].class);
+            // 返回的是 盒子分组-盒子注册项(BoxReg) 的二层结构
+//            for (BoxGroup group : boxGroups) {
+//                for (BoxReg boxReg : group.boxRegs) {
+//                    System.out.printf("\t%s\t%s\t%s\n", boxReg.alias, boxReg.box.boxNo, boxReg.box.boxType);
+//                }
+//            }
+//            commServer.executePost("box/300220120152/dmon/start", Object.class);
+            for (BoxGroup boxGroup : boxGroups) {
+                for (BoxReg boxReg : boxGroup.boxRegs) {
+                    commServer.executePost("box/" + boxReg.boxUid +"/dmon/start", Object.class);
+                    Thread.sleep(1000);
+                }
+            }
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+//        try {
+//            JsonObject jsonObject = commServer.executePost("dmon/222171502968050130/start", JsonObject.class);
+//        } catch (IOException e) {
+//            System.out.println("调用失败!");
+//            e.printStackTrace();
+//        }
+
+//        try {
+//            commServer.executePost("box/-6025651360718913057/dmon/start", Object.class);
+//        } catch (Exception e) {
+//            System.out.println("500");
+//            e.printStackTrace();
+//        }
+        System.out.println("测试");
+
+
+
+//
+//            // 获取按通道的数据接口示例 (数组第1维是固定两个元素时间和值,第2维是单个通道的所有数据,第3维是请求的每个通道)
+//            Object[][][] result =
+////                    String  result =
+//                    Global.hdataServer.executePost(String.format("v2/hdata/get"),
+//                            new GetByChannelHdataArgs(channelIds, new Date().getTime() - 7 * 86400000, new Date().getTime(), -100, 3),
+////                    String.class);
+//                            Object[][][].class);
+//
+//            System.out.println(result);
+//
+//            SimpleDateFormat dateFormatter = new SimpleDateFormat("yyyyMMdd");
+//
+//            for (int i = 0; i < result.length; i++) {
+//                Object[][] channel = result[i];
+//                System.out.print("Channel " + channelNames.get(i));
+//                for (Object[] datum : channel) {
+//                    System.out.printf("(%s: %s)", dateFormatter.format(new Date(Math.round((double) datum[0]))), datum[1]);
+//                }
+//                System.out.println();
+//            }
+//
+//            //获取按行的数据接口示例(每行固定有通道个数个数据,如果这行的时间某些通道没有值,则为null)
+//            ByRowHdata result2 =
+////            String result2 =
+//                    Global.hdataServer.executePost(String.format("v2/hdata/get"),
+//                            new GetByRowHdataArgs(channelIds, new Date().getTime() - 7 * 86400000, new Date().getTime(), -100, 3),
+////                            String.class);
+//                            ByRowHdata.class);
+////            System.out.println(result2);
+//
+//            for (ByRowHdataRow row : result2.rows) {
+//                System.out.print(dateFormatter.format(row.getTime()) + ": ");
+//                Object[] c = row.c;
+//                for (int i = 0; i < c.length; i++) {
+//                    Object value = c[i];
+//                    if (i == 0) {
+//                        System.out.printf("%s", value);
+//                    } else {
+//                        System.out.printf(",%s", value);
+//                    }
+//                }
+//                System.out.println();
+//            }
+
+
+//        } catch (IOException e) {
+//            e.printStackTrace();
+//        }
+//
+//
+//        Scanner s = new Scanner(System.in);
+//        s.nextLine();
+    }*/
+
+
+}

+ 24 - 0
huimv-farm-v2/huimv-produce-warning/src/main/java/com/huimv/produce/sgd/entity/Item.java

@@ -0,0 +1,24 @@
+package com.huimv.produce.sgd.entity;
+
+
+public class Item {
+
+    public String id;
+
+    public String name;
+
+    public String devAlias;
+
+    public String dataType;
+    public String grpName;
+
+    @Override
+    public String toString() {
+        return "Items{" +
+                "id='" + id + '\'' +
+                ", name='" + name + '\'' +
+                ", devAlias='" + devAlias + '\'' +
+                ", dataType='" + dataType + '\'' +
+                '}';
+    }
+}

+ 20 - 0
huimv-farm-v2/huimv-produce-warning/src/main/java/com/huimv/produce/sgd/entity/Monitory.java

@@ -0,0 +1,20 @@
+package com.huimv.produce.sgd.entity;
+
+
+import java.util.Arrays;
+
+public class Monitory {
+    public String id;
+    public String name;
+    public Item[] items;
+
+
+    @Override
+    public String toString() {
+        return "Monitory{" +
+                "id='" + id + '\'' +
+                ", name='" + name + '\'' +
+                ", items=" + Arrays.toString(items) +
+                '}';
+    }
+}

+ 27 - 0
huimv-farm-v2/huimv-produce-warning/src/main/java/com/huimv/produce/sgd/entity/MonitoryGetArgs.java

@@ -0,0 +1,27 @@
+package com.huimv.produce.sgd.entity;
+
+
+import java.util.List;
+
+public class MonitoryGetArgs {
+    public List names;
+    public Long timeOut;
+    public List groupnames;
+    public MonitoryGetArgs() {
+    }
+    public MonitoryGetArgs(List names, Long timeOut, List groupnames) {
+        this.names = names;
+        this.timeOut = timeOut;
+        this.groupnames = groupnames;
+    }
+
+
+    @Override
+    public String toString() {
+        return "Test{" +
+                "names=" + names +
+                ", timeOut=" + timeOut +
+                ", groupnames=" + groupnames +
+                '}';
+    }
+}

+ 122 - 0
huimv-farm-v2/huimv-produce-warning/src/main/java/com/huimv/produce/sgd/entity/MonitoryValue.java

@@ -0,0 +1,122 @@
+package com.huimv.produce.sgd.entity;
+
+
+import java.util.Date;
+
+public class MonitoryValue {
+
+    //监控点id
+    private  String id;
+
+    //时间戳,由于从缓存里拉的数据,所以需要时间戳来判断是否已经过期,UTC 时间
+    private Date timestamp;
+
+    //数据类型,见附录二
+    private int dataType;
+
+    //值
+    private Object value;
+
+    //监控点名称
+    private String name;
+
+    //盒子id
+    private long boxId;
+
+    //监控点状态,0:正常,1:无数据,2:超时,3:错误,4:Socket 异常,5:FDS 错误,16:未完成
+    private int status;
+
+    //盒子连接状态, 0:未知 , 1:已连接 ,2:超时, 3:断开
+    private int connState;
+
+    //盒子的上线时间
+    private  Date connStateTimestamp ;
+
+
+    public String getId() {
+        return id;
+    }
+
+    public void setId(String id) {
+        this.id = id;
+    }
+
+    public Date getTimestamp() {
+        return timestamp;
+    }
+
+    public void setTimestamp(Date timestamp) {
+        this.timestamp = timestamp;
+    }
+
+    public int getDataType() {
+        return dataType;
+    }
+
+    public void setDataType(int dataType) {
+        this.dataType = dataType;
+    }
+
+    public Object getValue() {
+        return value;
+    }
+
+    public void setValue(Object value) {
+        this.value = value;
+    }
+
+    public String getName() {
+        return name;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    public long getBoxId() {
+        return boxId;
+    }
+
+    public void setBoxId(long boxId) {
+        this.boxId = boxId;
+    }
+
+    public int getStatus() {
+        return status;
+    }
+
+    public void setStatus(int status) {
+        this.status = status;
+    }
+
+    public int getConnState() {
+        return connState;
+    }
+
+    public void setConnState(int connState) {
+        this.connState = connState;
+    }
+
+    public Date getConnStateTimestamp() {
+        return connStateTimestamp;
+    }
+
+    public void setConnStateTimestamp(Date connStateTimestamp) {
+        this.connStateTimestamp = connStateTimestamp;
+    }
+
+    @Override
+    public String toString() {
+        return "MonitoryValue{" +
+                "id='" + id + '\'' +
+                ", timestamp=" + timestamp +
+                ", dataType=" + dataType +
+                ", value=" + value +
+                ", name='" + name + '\'' +
+                ", boxId=" + boxId +
+                ", status=" + status +
+                ", connState=" + connState +
+                ", connStateTimestamp=" + connStateTimestamp +
+                '}';
+    }
+}

+ 18 - 0
huimv-farm-v2/huimv-produce-warning/src/main/java/com/huimv/produce/sgd/fbox/BoxServerResponseException.java

@@ -0,0 +1,18 @@
+package com.huimv.produce.sgd.fbox;
+
+import org.apache.http.client.HttpResponseException;
+
+public class BoxServerResponseException extends HttpResponseException {
+    public BoxServerResponseException(int statusCode, String s) {
+        super(statusCode, s);
+    }
+
+    public BoxServerResponseException(int statusCode, String s, int errCode) {
+        super(statusCode, s);
+        this.errCode = errCode;
+    }
+
+    public int errCode;
+
+
+}

+ 18 - 0
huimv-farm-v2/huimv-produce-warning/src/main/java/com/huimv/produce/sgd/fbox/ClientCredential.java

@@ -0,0 +1,18 @@
+package com.huimv.produce.sgd.fbox;
+
+public class ClientCredential {
+    public ClientCredential(String clientId, String clientSecret) {
+        this.clientId = clientId;
+        this.clientSecret = clientSecret;
+    }
+
+    /// <summary>
+    /// API账号
+    /// </summary>
+    public String clientId;
+
+    /// <summary>
+    /// API secret
+    /// </summary>
+    public String clientSecret;
+}

+ 34 - 0
huimv-farm-v2/huimv-produce-warning/src/main/java/com/huimv/produce/sgd/fbox/ConsoleLogger.java

@@ -0,0 +1,34 @@
+package com.huimv.produce.sgd.fbox;
+
+import java.text.SimpleDateFormat;
+import java.util.Date;
+
+public class ConsoleLogger implements Logger {
+    private final String name;
+    private final SimpleDateFormat formatter;
+
+    ConsoleLogger(String name) {
+        this.formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+        this.name = name;
+    }
+
+    @Override
+    public void logInformation(String msg) {
+        System.out.println(formatter.format(new Date()) + " [Info ][" + name + "] " + msg);
+    }
+
+    @Override
+    public void logWarning(String msg) {
+        System.out.println(formatter.format(new Date()) + " [Warn ][" + name + "] " + msg);
+    }
+
+    @Override
+    public void logError(String msg) {
+        System.out.println(formatter.format(new Date()) + " [Error][" + name + "] " + msg);
+    }
+
+    @Override
+    public void logTrace(String msg) {
+        System.out.println(formatter.format(new Date()) + " [Trace][" + name + "] " + msg);
+    }
+}

+ 12 - 0
huimv-farm-v2/huimv-produce-warning/src/main/java/com/huimv/produce/sgd/fbox/ConsoleLoggerFactory.java

@@ -0,0 +1,12 @@
+package com.huimv.produce.sgd.fbox;
+
+public class ConsoleLoggerFactory implements LoggerFactory {
+    @Override
+    public Logger createLogger(String name) {
+        if (name == "FBoxSignalRConnection" || name == "SignalRConnectionBase" || name == "ServerCaller") {
+            return new ConsoleLogger(name);
+        }
+
+        return new NullLogger();
+    }
+}

+ 17 - 0
huimv-farm-v2/huimv-produce-warning/src/main/java/com/huimv/produce/sgd/fbox/CredentialProvider.java

@@ -0,0 +1,17 @@
+package com.huimv.produce.sgd.fbox;
+
+public interface CredentialProvider {
+
+    /// <summary>
+    /// 获取用户密钥信息
+    /// </summary>
+    /// <returns></returns>
+    ClientCredential getClientCredential();
+
+    /// <summary>
+    /// 获取用户信息
+    /// </summary>
+    /// <returns></returns>
+    UserCredential getUserCredential();
+
+}

+ 10 - 0
huimv-farm-v2/huimv-produce-warning/src/main/java/com/huimv/produce/sgd/fbox/Logger.java

@@ -0,0 +1,10 @@
+package com.huimv.produce.sgd.fbox;
+
+public interface Logger{
+    void logInformation(String msg);
+    void logWarning(String msg);
+    void logError(String msg);
+    void logTrace(String msg);
+}
+
+

+ 5 - 0
huimv-farm-v2/huimv-produce-warning/src/main/java/com/huimv/produce/sgd/fbox/LoggerFactory.java

@@ -0,0 +1,5 @@
+package com.huimv.produce.sgd.fbox;
+
+public interface LoggerFactory {
+    Logger createLogger(String name);
+}

+ 9 - 0
huimv-farm-v2/huimv-produce-warning/src/main/java/com/huimv/produce/sgd/fbox/LoginFailedException.java

@@ -0,0 +1,9 @@
+package com.huimv.produce.sgd.fbox;
+
+import org.apache.http.client.HttpResponseException;
+
+public class LoginFailedException extends HttpResponseException {
+    public LoginFailedException(int statusCode, String s) {
+        super(statusCode, s);
+    }
+}

+ 23 - 0
huimv-farm-v2/huimv-produce-warning/src/main/java/com/huimv/produce/sgd/fbox/NullLogger.java

@@ -0,0 +1,23 @@
+package com.huimv.produce.sgd.fbox;
+
+public class NullLogger implements Logger {
+    @Override
+    public void logInformation(String msg) {
+        
+    }
+
+    @Override
+    public void logWarning(String msg) {
+
+    }
+
+    @Override
+    public void logError(String msg) {
+
+    }
+
+    @Override
+    public void logTrace(String msg) {
+
+    }
+}

+ 301 - 0
huimv-farm-v2/huimv-produce-warning/src/main/java/com/huimv/produce/sgd/fbox/ServerCaller.java

@@ -0,0 +1,301 @@
+package com.huimv.produce.sgd.fbox;
+
+import com.google.gson.Gson;
+import com.google.gson.GsonBuilder;
+import com.google.gson.JsonSyntaxException;
+import org.apache.http.*;
+import org.apache.http.client.HttpResponseException;
+import org.apache.http.client.ServiceUnavailableRetryStrategy;
+import org.apache.http.client.methods.*;
+import org.apache.http.client.protocol.HttpClientContext;
+import org.apache.http.entity.ContentType;
+import org.apache.http.entity.StringEntity;
+import org.apache.http.impl.client.CloseableHttpClient;
+import org.apache.http.impl.client.HttpClientBuilder;
+import org.apache.http.impl.client.HttpClients;
+import org.apache.http.impl.client.cache.CacheConfig;
+import org.apache.http.impl.client.cache.ExponentialBackOffSchedulingStrategy;
+import org.apache.http.message.BasicHeader;
+import org.apache.http.protocol.BasicHttpContext;
+import org.apache.http.protocol.HttpContext;
+import org.apache.http.util.EntityUtils;
+
+import javax.net.ssl.SSLException;
+import java.io.IOException;
+import java.io.InterruptedIOException;
+import java.net.MalformedURLException;
+import java.net.SocketException;
+import java.net.URI;
+import java.net.UnknownHostException;
+import java.util.ArrayList;
+import java.util.Iterator;
+
+public class ServerCaller {
+    private static final long RETRY_SLEEP_TIME_MILLIS = 2000;
+    private static ArrayList<Class<?>> exceptionWhitelist = new ArrayList<>();
+    private static ArrayList<Class<?>> exceptionBlacklist = new ArrayList<>();
+
+    static {
+        // Retry if the server dropped connection on us
+        exceptionWhitelist.add(NoHttpResponseException.class);
+        // retry-this, since it may happens as part of a Wi-Fi to 3G failover
+        exceptionWhitelist.add(UnknownHostException.class);
+        // retry-this, since it may happens as part of a Wi-Fi to 3G failover
+        exceptionWhitelist.add(SocketException.class);
+
+        // never retry timeouts
+        exceptionBlacklist.add(InterruptedIOException.class);
+        // never retry SSL handshake failures
+        exceptionBlacklist.add(SSLException.class);
+    }
+
+    private final String baseUrl;
+    private final String signalrClientId;
+    private final Gson gson;
+    private final Logger logger;
+    private CloseableHttpClient http;
+    private TokenManager tokenManager;
+    private String accessToken;
+    private int maxRetries = 30;
+
+    public ServerCaller(TokenManager tokenManager, LoggerFactory loggerFactory) throws MalformedURLException {
+        this(tokenManager, null, null, loggerFactory);
+    }
+
+    public ServerCaller(TokenManager tokenManager, String signalrClientId, LoggerFactory loggerFactory) {
+        this(tokenManager, null, signalrClientId, null, null, loggerFactory);
+    }
+
+    public ServerCaller(TokenManager tokenManager, String baseUrl, String signalrClientId, LoggerFactory loggerFactory) {
+        this(tokenManager, baseUrl, signalrClientId, null, null, loggerFactory);
+    }
+
+    public ServerCaller(TokenManager tokenManager, String baseUrl, String signalrClientId, CloseableHttpClient http, HttpHost proxy, LoggerFactory loggerFactory) {
+        logger = loggerFactory.createLogger("ServerCaller");
+        this.baseUrl = baseUrl;
+        this.tokenManager = tokenManager;
+        this.signalrClientId = signalrClientId;
+        this.http = http;
+
+        this.gson = new GsonBuilder().create();
+
+        ArrayList<Header> headers = new ArrayList<>();
+        if (signalrClientId != null) {
+            headers.add(new BasicHeader("X-FBox-ClientId", signalrClientId));
+        }
+
+        if (http == null) {
+            CacheConfig cc = CacheConfig.DEFAULT;
+            ExponentialBackOffSchedulingStrategy ebo = new ExponentialBackOffSchedulingStrategy(cc);
+
+            HttpClientBuilder httpBuilder = HttpClients.custom()
+                    .setDefaultHeaders(headers).setServiceUnavailableRetryStrategy(new ServiceUnavailableRetryStrategy() {
+                        @Override
+                        public boolean retryRequest(HttpResponse response, int executionCount, HttpContext context) {
+                            if (executionCount > maxRetries)
+                                return false;
+                            if (response == null) {
+                                return false;
+                            }
+                            if (response.getStatusLine()== null) {
+                                return false;
+                            }
+                            switch (response.getStatusLine().getStatusCode()) {
+//                                case 401:
+//                                    Object otm = context.getAttribute("ServerCaller");
+//                                    if (otm == null)
+//                                        return false;
+//
+//                                    ServerCaller tm = (ServerCaller) otm;
+//                                    try {
+//                                        tm.accessToken = tm.tokenManager.getOrUpdateToken(tm.accessToken);
+//                                    } catch (IOException e) {
+//                                        System.err.printf("Error fetching token in service unavailable retry logic %s.\n", e.toString());
+//                                        return true;
+//                                    }
+//
+//                                    HttpClientContext clientContext = HttpClientContext.adapt(context);
+//                                    clientContext.getRequest().setHeader("Authorization", "Bearer " + tm.accessToken);
+//                                    return true;
+
+                                case HttpStatus.SC_BAD_GATEWAY:
+                                case HttpStatus.SC_SERVICE_UNAVAILABLE:
+                                    return true;
+                                default:
+                                    return false;
+                            }
+                        }
+
+                        @Override
+                        public long getRetryInterval() {
+                            return 1000;
+                        }
+                    })
+                    .setRetryHandler((exception, executionCount, context) -> {
+                        if (exception != null) {
+                            System.err.printf("Retrying due to %s.\n", exception.toString());
+                        }
+                        if (executionCount > maxRetries) {
+                            // Do not retry if over max retry count
+                            System.err.printf("Maxmimum retry count reached.\n");
+                            return false;
+                        } else if (isInList(exceptionBlacklist, exception)) {
+                            // immediately cancel retry if the error is blacklisted
+                            return false;
+                        } else if (isInList(exceptionWhitelist, exception)) {
+                            // immediately retry if error is whitelisted
+                        }
+
+                        HttpClientContext clientContext = HttpClientContext.adapt(context);
+                        if (clientContext == null) {
+                            return true;
+                        }
+
+                        HttpRequest request = clientContext.getRequest();
+                        if (request == null) {
+                            return true;
+                        }
+
+                        HttpResponse response = clientContext.getResponse();
+                        if (response == null) {
+                            return true;
+                        }
+                        StatusLine statusLine = response.getStatusLine();
+
+                        if (statusLine != null && statusLine.getStatusCode() == 401) {
+                            try {
+                                System.err.println("ServerCaller: try get another token for " + request.toString());
+                                this.accessToken = this.tokenManager.getOrUpdateToken(this.accessToken);
+                                request.setHeader("Authorization", "Bearer " + this.accessToken);
+                                return true;
+                            } catch (IOException e) {
+                                System.err.printf("Error fetching token in retry logic %s.\n", e.toString());
+                            }
+                        } else {
+
+                        }
+
+                        try {
+                            Thread.sleep(RETRY_SLEEP_TIME_MILLIS);
+                        } catch (InterruptedException e) {
+                        }
+                        return true;
+                    });
+            if (proxy != null)
+                httpBuilder = httpBuilder.setProxy(proxy);
+            this.http = httpBuilder.build();
+        }
+    }
+
+    protected boolean isInList(ArrayList<Class<?>> list, Throwable error) {
+        Iterator<Class<?>> itr = list.iterator();
+        while (itr.hasNext()) {
+            if (itr.next().isInstance(error)) {
+                return true;
+            }
+        }
+        return false;
+    }
+
+    public <T> T executeGet(String url, Class<T> responseType) throws IOException {
+        HttpGet request;
+        request = new HttpGet(baseUrl + url);
+        return executeCore(request, responseType);
+    }
+
+    public <T> T executePost(String url, Class<T> responseType) throws IOException {
+        return executePost(url, null, responseType);
+    }
+
+    public <T> T executePost(String url, Object entity, Class<T> responseType) throws IOException {
+        HttpPost request;
+        request = new HttpPost(baseUrl + url);
+        if (entity != null) {
+            String str = gson.toJson(entity);
+            request.setEntity(new StringEntity(str, ContentType.APPLICATION_JSON));
+        }
+        return executeCore(request, responseType);
+    }
+
+    public <T> T executePost(String url, HttpEntity body, Class<T> responseType) throws IOException {
+        HttpPost request;
+        request = new HttpPost(baseUrl + url);
+        if (body != null)
+            request.setEntity(body);
+        return executeCore(request, responseType);
+    }
+
+    public <T> T executePut(String url, HttpEntity body, Class<T> responseType) throws IOException {
+        HttpPut request;
+        request = new HttpPut(baseUrl + url);
+        request.setEntity(body);
+        return executeCore(request, responseType);
+    }
+
+    public <T> T executeDelete(String url, Class<T> responseType) throws IOException {
+        HttpDelete request;
+        request = new HttpDelete(baseUrl + url);
+        return executeCore(request, responseType);
+    }
+
+    private <T> T executeCore(HttpUriRequest request, Class<T> responseType) throws IOException {
+        if (this.accessToken == null) {
+            this.accessToken = this.tokenManager.getOrUpdateToken(this.accessToken);
+        }
+        request.setHeader("Authorization", "Bearer " + this.accessToken);
+        request.addHeader("Accept", "application/json; */*");
+        for (; ; ) {
+            String method = request.getMethod();
+            URI uri = request.getURI();
+         //   this.logger.logTrace(String.format("Executing request %s %s", method, uri));
+            CloseableHttpResponse response = null;
+            BasicHttpContext ctx = new BasicHttpContext();
+            ctx.setAttribute("ServerCaller", this);
+            try {
+                response = this.http.execute(request, ctx);
+            } catch (IOException e) {
+                System.err.printf("Request failed with error: %s.\n", e.toString());
+                throw e;
+            }
+            try {
+                StatusLine statusLine = response.getStatusLine();
+                if (statusLine == null)
+                    throw new HttpResponseException(0, "Null status line.");
+                int statusCode = statusLine.getStatusCode();
+              //  this.logger.logTrace(String.format("Executed request %s %s with code %d", method, uri, statusCode));
+                if (statusCode == 401) {
+//                    throw new HttpResponseException(401, "Unauthorized request");
+                    this.logger.logTrace("ServerCaller: 401 from " + request.getURI().toString());
+                    this.accessToken = this.tokenManager.getOrUpdateToken(this.accessToken);
+                    request.setHeader("Authorization", "Bearer " + this.accessToken);
+                    continue;
+                } else if (statusCode >= 300) {
+                    String exmsg = statusLine.getReasonPhrase();
+                    Header errCodeHeader = response.getFirstHeader("X-FBox-Code");
+                    int errCode = 0;
+                    if (errCodeHeader != null) {
+                        errCode = Integer.parseInt(errCodeHeader.getValue());
+                        exmsg += " code=" + errCode;
+                    }
+                    throw new BoxServerResponseException(statusCode, exmsg, errCode);
+                }
+                HttpEntity body = response.getEntity();
+                if (body != null && responseType != null) {
+                    String str = EntityUtils.toString(body);
+                    try {
+                        return gson.fromJson(str, responseType);
+                    } catch (JsonSyntaxException ex) {
+                        if (responseType.isAssignableFrom(String.class))
+                            return (T) str;
+                        else
+                            throw new IllegalArgumentException("Response cannot be parsed to " + responseType.toString() + " contentType is " + body.getContentType());
+                    }
+                }
+//                this.logger.logTrace(String.format("Request %s %s returned with empty body.", method, uri));
+                return null;
+            } finally {
+                response.close();
+            }
+        }
+    }
+}

+ 21 - 0
huimv-farm-v2/huimv-produce-warning/src/main/java/com/huimv/produce/sgd/fbox/StaticCredentialProvider.java

@@ -0,0 +1,21 @@
+package com.huimv.produce.sgd.fbox;
+
+public class StaticCredentialProvider implements CredentialProvider {
+    private final ClientCredential clientCred;
+    private final UserCredential userCred;
+
+    public StaticCredentialProvider(String clientId, String clientSecret, String userName, String password) {
+        this.clientCred = new ClientCredential(clientId, clientSecret);
+        this.userCred = new UserCredential(userName, password);
+    }
+
+    @Override
+    public ClientCredential getClientCredential() {
+        return clientCred;
+    }
+
+    @Override
+    public UserCredential getUserCredential() {
+        return userCred;
+    }
+}

+ 132 - 0
huimv-farm-v2/huimv-produce-warning/src/main/java/com/huimv/produce/sgd/fbox/TokenManager.java

@@ -0,0 +1,132 @@
+package com.huimv.produce.sgd.fbox;
+
+import com.google.gson.Gson;
+import com.google.gson.GsonBuilder;
+import org.apache.http.HttpEntity;
+import org.apache.http.NameValuePair;
+import org.apache.http.StatusLine;
+import org.apache.http.client.ClientProtocolException;
+import org.apache.http.client.HttpResponseException;
+import org.apache.http.client.config.RequestConfig;
+import org.apache.http.client.entity.UrlEncodedFormEntity;
+import org.apache.http.client.methods.CloseableHttpResponse;
+import org.apache.http.client.methods.HttpPost;
+import org.apache.http.entity.ContentType;
+import org.apache.http.impl.client.CloseableHttpClient;
+import org.apache.http.impl.client.HttpClients;
+import org.apache.http.message.BasicNameValuePair;
+
+import java.io.Closeable;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.io.Reader;
+import java.nio.charset.Charset;
+import java.util.ArrayList;
+import java.util.List;
+
+public class TokenManager implements Closeable {
+    private final CredentialProvider credentialProvider;
+    private final Object tokenLock;
+    private final Gson gson;
+    private final Logger logger;
+    private CloseableHttpClient http;
+    private final String idSvrUrl;
+
+    public TokenManager(CredentialProvider credentialProvider, LoggerFactory loggerFactory) {
+        this(credentialProvider, "https://account.flexem.com/core/", loggerFactory);
+    }
+
+    public TokenManager(CredentialProvider credentialProvider, String idSvrUrl, LoggerFactory loggerFactory) {
+        this(credentialProvider, idSvrUrl, null, loggerFactory);
+    }
+
+    public TokenManager(CredentialProvider credentialProvider, String idSvrUrl, CloseableHttpClient http, LoggerFactory loggerFactory) {
+        this.logger = loggerFactory.createLogger("TokenManager");
+        this.idSvrUrl = idSvrUrl;
+        this.credentialProvider = credentialProvider;
+        this.tokenLock = new Object();
+        this.http = http;
+        if (http == null) {
+            this.http = HttpClients.createDefault();
+        }
+        this.gson = new GsonBuilder().create();
+    }
+
+    private String accessToken;
+
+    public String getOrUpdateToken(String currentToken) throws IOException {
+        if (currentToken == null) {
+            String at = accessToken;
+            if (at != null)
+                return at;
+        }
+
+        synchronized (tokenLock) {
+            String at = accessToken;
+            if (at != null && at != currentToken)
+                return at;
+
+            at = fetchToken();
+            accessToken = at;
+            return at;
+        }
+    }
+
+    private String fetchToken() throws IOException {
+        ClientCredential clientCredential = credentialProvider.getClientCredential();
+        UserCredential userCredential = credentialProvider.getUserCredential();
+        // 登录接口,用于获取access_Token,access_Token有效期2小时
+        HttpPost request = new HttpPost(idSvrUrl + "connect/token");
+        List<NameValuePair> formparams = new ArrayList<NameValuePair>();
+        formparams.add(new BasicNameValuePair("username", userCredential.userName));
+        formparams.add(new BasicNameValuePair("password", userCredential.password));
+        formparams.add(new BasicNameValuePair("scope", "openid offline_access fbox email profile"));
+        formparams.add(new BasicNameValuePair("client_id", clientCredential.clientId));
+        formparams.add(new BasicNameValuePair("client_secret", clientCredential.clientSecret));
+        formparams.add(new BasicNameValuePair("grant_type", "password"));
+        request.setEntity(new UrlEncodedFormEntity(formparams));
+        CloseableHttpResponse response = http.execute(request);
+        //401
+        final RequestConfig params = RequestConfig.custom().setConnectTimeout(8000).setSocketTimeout(8000).build();
+        request.setConfig(params);
+
+
+        try {
+            StatusLine statusLine = response.getStatusLine();
+            HttpEntity entity = response.getEntity();
+            int statusCode = statusLine.getStatusCode();
+            // the following status code range mostly caused by incorrect credential.
+            if (statusCode >= 400 && statusCode < 500 && statusCode != 429) {
+                throw new LoginFailedException(
+                        statusLine.getStatusCode(),
+                        statusLine.getReasonPhrase());
+            }
+            if (statusCode >= 300) {
+                throw new HttpResponseException(statusCode, statusLine.getReasonPhrase());
+            }
+            if (entity == null) {
+                throw new ClientProtocolException("Response contains no content");
+            }
+            ContentType contentType = ContentType.getOrDefault(entity);
+            Charset charset = contentType.getCharset();
+            Reader reader = new InputStreamReader(entity.getContent(), charset);
+            String at;
+            try {
+                at = (gson.fromJson(reader, TokenResponse.class)).access_token;
+            } finally {
+                reader.close();
+            }
+            this.logger.logTrace("Fetched new token.");
+            return at;
+        } finally {
+            response.close();
+        }
+    }
+
+    @Override
+    public void close() throws IOException {
+        if (this.http instanceof Closeable) {
+            ((Closeable) this.http).close();
+        }
+    }
+}

+ 5 - 0
huimv-farm-v2/huimv-produce-warning/src/main/java/com/huimv/produce/sgd/fbox/TokenResponse.java

@@ -0,0 +1,5 @@
+package com.huimv.produce.sgd.fbox;
+
+public class TokenResponse {
+    public String access_token;
+}

+ 18 - 0
huimv-farm-v2/huimv-produce-warning/src/main/java/com/huimv/produce/sgd/fbox/UserCredential.java

@@ -0,0 +1,18 @@
+package com.huimv.produce.sgd.fbox;
+
+public class UserCredential {
+    public UserCredential(String userName, String password) {
+        this.userName = userName;
+        this.password = password;
+    }
+
+    /// <summary>
+    /// 用户名
+    /// </summary>
+    public String userName;
+
+    /// <summary>
+    /// 密码
+    /// </summary>
+    public String password;
+}

+ 24 - 0
huimv-farm-v2/huimv-produce-warning/src/main/java/com/huimv/produce/sgd/fbox/models/Box.java

@@ -0,0 +1,24 @@
+package com.huimv.produce.sgd.fbox.models;
+
+public class Box {
+    public long id;
+    public String boxNo;
+    public int boxType;
+    public int connState;
+    public int net;
+    public int feat;
+    public Cs cs;
+
+    @Override
+    public String toString() {
+        return "Box{" +
+                "id=" + id +
+                ", boxNo='" + boxNo + '\'' +
+                ", boxType=" + boxType +
+                ", connState=" + connState +
+                ", net=" + net +
+                ", feat=" + feat +
+                ", cs=" + cs +
+                '}';
+    }
+}

+ 8 - 0
huimv-farm-v2/huimv-produce-warning/src/main/java/com/huimv/produce/sgd/fbox/models/BoxGroup.java

@@ -0,0 +1,8 @@
+package com.huimv.produce.sgd.fbox.models;
+
+public class BoxGroup {
+    public long id;
+    public String name;
+    public BoxReg[] boxRegs;
+}
+

+ 18 - 0
huimv-farm-v2/huimv-produce-warning/src/main/java/com/huimv/produce/sgd/fbox/models/BoxReg.java

@@ -0,0 +1,18 @@
+package com.huimv.produce.sgd.fbox.models;
+
+public class BoxReg {
+    public long id;
+    public String alias;
+    public String boxUid;
+    public Box box;
+
+    @Override
+    public String toString() {
+        return "BoxReg{" +
+                "id=" + id +
+                ", alias='" + alias + '\'' +
+                ", boxUid='" + boxUid + '\'' +
+                ", box=" + box +
+                '}';
+    }
+}

+ 7 - 0
huimv-farm-v2/huimv-produce-warning/src/main/java/com/huimv/produce/sgd/fbox/models/BoxStateChanged.java

@@ -0,0 +1,7 @@
+package com.huimv.produce.sgd.fbox.models;
+
+public class BoxStateChanged {
+    public long id;
+    public int state;
+    public int net;
+}

+ 5 - 0
huimv-farm-v2/huimv-produce-warning/src/main/java/com/huimv/produce/sgd/fbox/models/ByRowHdata.java

@@ -0,0 +1,5 @@
+package com.huimv.produce.sgd.fbox.models;
+
+public class ByRowHdata {
+    public ByRowHdataRow[] rows;
+}

+ 19 - 0
huimv-farm-v2/huimv-produce-warning/src/main/java/com/huimv/produce/sgd/fbox/models/ByRowHdataRow.java

@@ -0,0 +1,19 @@
+package com.huimv.produce.sgd.fbox.models;
+
+import java.util.Date;
+
+public class ByRowHdataRow {
+    /**
+     * 时间戳(1970-1-1以来的毫秒数)
+     */
+    public long t;
+
+    public Date getTime (){
+        return new Date(t);
+    }
+
+    /**
+     * 一行中每个单元格的值
+     */
+    public Object[] c;
+}

+ 13 - 0
huimv-farm-v2/huimv-produce-warning/src/main/java/com/huimv/produce/sgd/fbox/models/Cs.java

@@ -0,0 +1,13 @@
+package com.huimv.produce.sgd.fbox.models;
+
+
+public class Cs {
+    public String signalRUrl;
+
+    @Override
+    public String toString() {
+        return "Cs{" +
+                "signalRUrl='" + signalRUrl + '\'' +
+                '}';
+    }
+}

+ 53 - 0
huimv-farm-v2/huimv-produce-warning/src/main/java/com/huimv/produce/sgd/fbox/models/DataSource.java

@@ -0,0 +1,53 @@
+package com.huimv.produce.sgd.fbox.models;
+
+public class DataSource {
+    /**
+     * PLC别名
+     */
+    public String devAlias;
+
+    /**
+     * 站号
+     */
+    public int stationNo;
+
+    /**
+     * 数据类型
+     */
+    public int dataType;
+
+    /**
+     * 寄存器ID(与寄存器位宽联合使用)
+     */
+    public int regId;
+
+    /**
+     * 寄存器位宽 (与寄存器ID联合使用)
+     */
+    public int ioWidth;
+    /// <summary>
+    ///     寄存器名称
+    /// </summary>
+    public String regName;
+    /// <summary>
+    ///     主地址
+    /// </summary>
+    public int addr;
+    /// <summary>
+    ///     子地址
+    /// </summary>
+    public int subAddr;
+    /// <summary>
+    ///     数据块(DB块)
+    /// </summary>
+    public int addrBlk;
+    /// <summary>
+    /// 是否启用按位索引
+    /// </summary>
+    public boolean bitIndexEnabled;
+    /// <summary>
+    /// 按位索引号
+    /// </summary>
+    public int bitIndex;
+
+}

+ 76 - 0
huimv-farm-v2/huimv-produce-warning/src/main/java/com/huimv/produce/sgd/fbox/models/DataType.java

@@ -0,0 +1,76 @@
+package com.huimv.produce.sgd.fbox.models;//package fbox.models;
+//
+//public enum DataType {
+//        /// <summary>
+//        /// 位
+//        /// </summary>
+//        Bit(0),
+//
+//            /// <summary>
+//            /// 16位无符号
+//            /// </summary>
+//        UInt16 = 1,
+//
+//            /// <summary>
+//            /// 16位有符号
+//            /// </summary>
+//        Int16 = 2,
+//
+//            /// <summary>
+//            /// 16位BCD
+//            /// </summary>
+//        Bcd16 = 3,
+//
+//            /// <summary>
+//            /// 16位16进制
+//            /// </summary>
+//        Hex16 = 4,
+//
+//            /// <summary>
+//            /// 16位二进制
+//            /// </summary>
+//        Binary16 = 5,
+//
+//            /// <summary>
+//            /// 32位无符号
+//            /// </summary>
+//            [Description("32位无符号")]
+//        UInt32 = 11,
+//
+//            /// <summary>
+//            /// 32位有符号
+//            /// </summary>
+//            [Description("32位有符号")]
+//        Int32 = 12,
+//
+//            /// <summary>
+//            /// 32位BCD
+//            /// </summary>
+//            [Description("32位BCD")]
+//        Bcd32 = 13,
+//
+//            /// <summary>
+//            /// 32位16进制
+//            /// </summary>
+//            [Description("32位16进制")]
+//        Hex32 = 14,
+//
+//            /// <summary>
+//            /// 32位二进制
+//            /// </summary>
+//            [Description("32位二进制")]
+//        Binary32 = 15,
+//
+//            /// <summary>
+//            /// 单精度浮点
+//            /// </summary>
+//            [Description("单精度浮点")]
+//        Single = 16,
+//
+//            /// <summary>
+//            /// 字符串
+//            /// </summary>
+//            [Description("字符串")]
+//        String = 30,
+//    }
+//}

+ 14 - 0
huimv-farm-v2/huimv-produce-warning/src/main/java/com/huimv/produce/sgd/fbox/models/DmonWriteValueArgs.java

@@ -0,0 +1,14 @@
+package com.huimv.produce.sgd.fbox.models;
+
+public class DmonWriteValueArgs {
+    public DmonWriteValueArgs(String groupName, String name, String value) {
+        this.name = name;
+        this.value = value;
+        this.groupName = groupName;
+    }
+
+    public String name;
+    public int type = 0;
+    public String value;
+    public String groupName;
+}

+ 11 - 0
huimv-farm-v2/huimv-produce-warning/src/main/java/com/huimv/produce/sgd/fbox/models/GetByChannelHdataArgs.java

@@ -0,0 +1,11 @@
+package com.huimv.produce.sgd.fbox.models;
+
+import java.util.List;
+
+
+public class GetByChannelHdataArgs extends GetHdataArgs{
+    public GetByChannelHdataArgs(List<Long> ids, long begin, long end, int limit, int tr) {
+        super(1, ids, begin, end, limit, tr);
+    }
+}
+

+ 9 - 0
huimv-farm-v2/huimv-produce-warning/src/main/java/com/huimv/produce/sgd/fbox/models/GetByRowHdataArgs.java

@@ -0,0 +1,9 @@
+package com.huimv.produce.sgd.fbox.models;
+
+import java.util.List;
+
+public class GetByRowHdataArgs extends GetHdataArgs{
+    public GetByRowHdataArgs(List<Long> ids, long begin, long end, int limit, int tr) {
+        super(0, ids, begin, end, limit, tr);
+    }
+}

+ 9 - 0
huimv-farm-v2/huimv-produce-warning/src/main/java/com/huimv/produce/sgd/fbox/models/GetDmonValuesById.java

@@ -0,0 +1,9 @@
+package com.huimv.produce.sgd.fbox.models;
+
+public class GetDmonValuesById {
+    public GetDmonValuesById(long[] ids) {
+        this.ids = ids;
+    }
+
+    public long[] ids;
+}

+ 9 - 0
huimv-farm-v2/huimv-produce-warning/src/main/java/com/huimv/produce/sgd/fbox/models/GetDmonValuesByName.java

@@ -0,0 +1,9 @@
+package com.huimv.produce.sgd.fbox.models;
+
+public class GetDmonValuesByName {
+    public GetDmonValuesByName(String[] names) {
+        this.names = names;
+    }
+
+    public String[] names;
+}

+ 39 - 0
huimv-farm-v2/huimv-produce-warning/src/main/java/com/huimv/produce/sgd/fbox/models/GetHdataArgs.java

@@ -0,0 +1,39 @@
+package com.huimv.produce.sgd.fbox.models;
+
+import java.util.List;
+
+public class GetHdataArgs {
+    /**
+     * 通道ID列表
+     */
+    public List<Long> ids;
+    /**
+     * 开始时间(1970-1-1以来的毫秒数)
+     */
+    public long begin;
+    /**
+     * 结束时间(1970-1-1以来的毫秒数)
+     */
+    public long end;
+    /**
+     * 取值最大个数
+     * 正数表示从开始时间向结束时间取最多limit个,负值表示从结束时间向开始时间最多取limit个
+     */
+    public int limit;
+    /**
+     * 时间范围边界类型
+     * 0:全开区间, 1:左开右闭, 2: 左闭右开, 3:全闭区间
+     */
+    public int tr;
+
+    public int type;
+
+    public GetHdataArgs(int type, List<Long> ids, long begin, long end, int limit, int tr) {
+        this.ids = ids;
+        this.begin = begin;
+        this.end = end;
+        this.limit = limit;
+        this.tr = tr;
+        this.type = type;
+    }
+}

+ 33 - 0
huimv-farm-v2/huimv-produce-warning/src/main/java/com/huimv/produce/sgd/fbox/models/HdataChannelDef.java

@@ -0,0 +1,33 @@
+package com.huimv.produce.sgd.fbox.models;
+
+public class HdataChannelDef extends DataSource {
+    /**
+     * 通道ID
+     */
+    public long uid;
+
+    /**
+     * 通道名称
+     */
+    public String name;
+
+    /**
+     * 单位
+     */
+    public String unit;
+
+    /**
+     * 描述
+     */
+    public String desc;
+
+    /**
+     * 整数位
+     */
+    public int intDigits;
+
+    /**
+     * 小数位
+     */
+    public int fracDigits;
+}

+ 5 - 0
huimv-farm-v2/huimv-produce-warning/src/main/java/com/huimv/produce/sgd/fbox/models/HdataControlOptions.java

@@ -0,0 +1,5 @@
+package com.huimv.produce.sgd.fbox.models;
+
+public class HdataControlOptions extends DataSource {
+        public int ctrlType;
+}

+ 33 - 0
huimv-farm-v2/huimv-produce-warning/src/main/java/com/huimv/produce/sgd/fbox/models/HdataDef.java

@@ -0,0 +1,33 @@
+package com.huimv.produce.sgd.fbox.models;
+
+public class HdataDef {
+
+    public long uid;
+
+    /**
+     * 名称
+     */
+    public String name;
+
+    /**
+     * 采样时间
+     */
+    public int period;
+
+    /**
+     * 关联的盒子ID
+     */
+    public long boxId;
+
+    /**
+     * 是否使用使能设置
+     */
+    public boolean hasCtrl;
+
+    /**
+     * 使能控制详细配置
+     */
+    public HdataControlOptions ctrl;
+
+    public HdataChannelDef[] channels;
+}

+ 189 - 0
huimv-farm-v2/huimv-produce-warning/src/main/java/com/huimv/produce/sgd/fbox/signalr/SignalRConnectionBase.java

@@ -0,0 +1,189 @@
+package com.huimv.produce.sgd.fbox.signalr;
+
+import com.github.signalr4j.client.ConnectionState;
+import com.github.signalr4j.client.http.java.JavaHttpConnection;
+import com.github.signalr4j.client.hubs.HubConnection;
+import com.github.signalr4j.client.hubs.HubProxy;
+import com.github.signalr4j.client.transport.ServerSentEventsTransport;
+import com.huimv.produce.sgd.fbox.Logger;
+import com.huimv.produce.sgd.fbox.LoggerFactory;
+import com.huimv.produce.sgd.fbox.LoginFailedException;
+import com.huimv.produce.sgd.fbox.TokenManager;
+
+import java.io.IOException;
+import java.net.Proxy;
+import java.util.Date;
+import java.util.concurrent.Semaphore;
+import java.util.concurrent.TimeUnit;
+
+public abstract class SignalRConnectionBase {
+    private final Semaphore connectEvent;
+    private HubConnection hubConnection;
+    private HubProxy hubProxy;
+    private final Logger logger;
+    private final LoggerFactory loggerFactory;
+    private final SignalRLoggerWrapper javaconnLogger;
+    private final SignalRLoggerWrapper sseLogger;
+    private String hubUrl;
+    private String signalrClientId;
+    private Proxy proxy;
+    private TokenManager tokenManager;
+    private String accessToken;
+    private boolean shouldGetNewToken;
+    private int retryCount;
+    private long lastConnectedTime = 0;
+    private boolean reconnecting;
+    private boolean monitorStarted;
+
+    public SignalRConnectionBase(String hubUrl, String signalrClientId, TokenManager tokenManager, Proxy proxy, LoggerFactory loggerFactory) {
+        this.hubUrl = hubUrl;
+        this.signalrClientId = signalrClientId;
+        this.proxy = proxy;
+        this.loggerFactory = loggerFactory;
+        this.logger = loggerFactory.createLogger("SignalRConnectionBase");
+        this.sseLogger = new SignalRLoggerWrapper(this.loggerFactory.createLogger("ServerSentEventsTransport"));
+        this.javaconnLogger = new SignalRLoggerWrapper(this.loggerFactory.createLogger("SignalRTransportConnection"));
+        this.tokenManager = tokenManager;
+        this.connectEvent = new Semaphore(1);
+        new Thread(() -> {
+            try {
+                SignalRConnectWorker();
+            } catch (InterruptedException e) {
+                logger.logError("SignalR connect worker exited with " + e.toString());
+            }
+        }).start();
+    }
+
+    private void HookEvents() {
+        this.hubConnection.error(throwable -> onConnectionError(throwable));
+        this.hubConnection.reconnecting(() -> onReconnecting());
+        this.hubConnection.reconnected(() -> onReconnected());
+        this.hubConnection.closed(() -> onConnectionClosed());
+        this.hubConnection.connected(() -> connected());
+    }
+
+    private void UnhookEvents() {
+        this.hubConnection.error(null);
+        this.hubConnection.reconnecting(null);
+        this.hubConnection.reconnected(null);
+        this.hubConnection.closed(null);
+        this.hubConnection.connected(null);
+    }
+
+    private void onReconnecting() {
+        this.logger.logInformation("Reconnecting. hubconn=" + this.hubConnection.getUrl());
+    }
+
+    private void onReconnected() {
+        this.logger.logInformation("Reconnected. hubconn=" + this.hubConnection.getUrl());
+    }
+
+    private void onConnectionClosed() {
+        this.logger.logInformation("Closed. hubconn=" + this.hubConnection.getUrl());
+        this.connectEvent.release();
+    }
+
+    private void onConnectionError(Throwable e) {
+        this.logger.logInformation(String.format("Connection error. exception=%s. hubConnection=%s", e, this.hubConnection.getUrl()));
+        if (e != null) {
+            Throwable cause = e.getCause();
+            if (cause != null && cause.getMessage() != null && cause.getMessage().contains("401")) {
+                this.shouldGetNewToken = true;
+            }
+        }
+    }
+
+    protected abstract void onHubProxyCreated(HubProxy hubProxy);
+
+    protected abstract void onHubProxyDestroyed(HubProxy hubProxy);
+
+    public void connected() {
+        this.reconnecting = false;
+        this.logger.logInformation("Connected. hubconn=" + this.hubConnection.getUrl());
+    }
+
+    private void UpdateToken() throws LoginFailedException, InterruptedException {
+        int retryCount2 = 0;
+        for (; ; ) {
+            try {
+                this.accessToken = this.tokenManager.getOrUpdateToken(this.accessToken);
+                break;
+            } catch (LoginFailedException e) {
+                throw e;
+            } catch (IOException e) {
+                logger.logError("Get token failed. " + e.toString());
+                int waitTime2 = retryCount2++ * 1000;
+                if (waitTime2 > 300000) {
+                    waitTime2 = 5000;
+                }
+                Thread.sleep(waitTime2);
+            }
+        }
+    }
+
+    private void SignalRConnectWorker() throws InterruptedException {
+        //signalr重连代码
+        for (; ; ) {
+            do {
+//                this.logger.logTrace("Current connection state is " + this.hubConnection.getState());
+                this.connectEvent.acquire();
+            }
+            while (this.hubConnection != null && this.hubConnection.getState() == ConnectionState.Connected);
+
+            try {
+                //刷新token
+                UpdateToken();
+                if (this.hubConnection != null)
+                    this.UnhookEvents();
+                if (this.hubProxy != null) {
+                    onHubProxyDestroyed(this.hubProxy);
+                }
+                if (this.hubConnection != null)
+                    this.hubConnection.disconnect();
+                this.hubConnection = new HubConnection(hubUrl, "cid=" + signalrClientId, true, new SignalRLoggerWrapper(loggerFactory.createLogger("SignalR")));
+                this.hubConnection.setReconnectOnError(false);
+                this.HookEvents();
+                this.hubProxy = this.hubConnection.createHubProxy("clienthub");
+                this.onHubProxyCreated(this.hubProxy);
+                this.hubConnection.setCredentials(request -> request.addHeader("Authorization", "Bearer " + this.accessToken));
+                this.connectEvent.drainPermits();
+                this.hubConnection.start(new ServerSentEventsTransport(this.sseLogger, new JavaHttpConnection(this.javaconnLogger))).get(40, TimeUnit.SECONDS);
+                this.retryCount = 0;
+                this.shouldGetNewToken = false;
+                this.lastConnectedTime = new Date().getTime();
+            } catch (Exception e) {
+                assert hubConnection.getState() != ConnectionState.Connected;
+                if (e instanceof LoginFailedException) {
+                    this.logger.logError("Login error.");
+                } else {
+                    this.logger.logError("Hub connection start error. " + e.toString());
+                    e.printStackTrace();
+                }
+                Throwable cause = e.getCause();
+                if (cause != null) {
+                    String msg = cause.getMessage();
+                    if (msg != null && msg.contains("401"))
+                        this.shouldGetNewToken = true;
+                }
+
+                int waitTime = this.retryCount++ * 1000;
+                if (waitTime > 60000) {
+                    waitTime = 5000;
+                }
+
+                if (waitTime > 0)
+                    Thread.sleep(waitTime);
+                this.connectEvent.release();
+                this.reconnecting = true;
+            }
+        }
+    }
+
+    public void start() {
+        this.connectEvent.release();
+    }
+
+    public void stop() {
+        this.hubConnection.stop();
+    }
+}

+ 28 - 0
huimv-farm-v2/huimv-produce-warning/src/main/java/com/huimv/produce/sgd/fbox/signalr/SignalRLoggerWrapper.java

@@ -0,0 +1,28 @@
+package com.huimv.produce.sgd.fbox.signalr;
+
+import com.github.signalr4j.client.LogLevel;
+import com.github.signalr4j.client.Logger;
+
+public class SignalRLoggerWrapper implements Logger {
+
+    private final  com.huimv.produce.sgd.fbox.Logger logger;
+
+    public SignalRLoggerWrapper( com.huimv.produce.sgd.fbox.Logger logger){
+        this.logger = logger;
+    }
+    @Override
+    public void log(String message, LogLevel level) {
+        switch (level) {
+            case Critical:
+                this.logger.logError(message);
+                break;
+            case Information:
+                this.logger.logInformation(message);
+                break;
+            case Verbose:
+                this.logger.logTrace(message);
+                break;
+        }
+    }
+
+}

+ 481 - 0
huimv-farm-v2/huimv-produce-warning/src/main/java/com/huimv/produce/timer/SgdTimer.java

@@ -0,0 +1,481 @@
+package com.huimv.produce.timer;
+
+
+import cn.hutool.core.util.ObjectUtil;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.huimv.common.utils.DataUill;
+import com.huimv.produce.entity.*;
+import com.huimv.produce.service.*;
+import com.huimv.produce.sgd.Global;
+import com.huimv.produce.sgd.entity.Item;
+import com.huimv.produce.sgd.entity.Monitory;
+import com.huimv.produce.sgd.entity.MonitoryGetArgs;
+import com.huimv.produce.sgd.entity.MonitoryValue;
+import com.huimv.produce.sgd.fbox.ConsoleLoggerFactory;
+import com.huimv.produce.sgd.fbox.ServerCaller;
+import com.huimv.produce.sgd.fbox.StaticCredentialProvider;
+import com.huimv.produce.sgd.fbox.TokenManager;
+import com.huimv.produce.sgd.fbox.models.BoxGroup;
+import com.huimv.produce.sgd.fbox.models.BoxReg;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.scheduling.annotation.Scheduled;
+import org.springframework.stereotype.Component;
+
+import java.io.IOException;
+import java.text.DecimalFormat;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+
+@Component
+public class SgdTimer {
+    private static final long SLEEP_TIME = 1000;
+
+    @Autowired
+    private  IBaseBoxService baseBoxService;
+
+    @Autowired
+    private  IBaseRoomService baseRoomService;
+
+    @Autowired
+    private ISysHumidityService humidityService;
+
+    @Autowired
+    private ISysTemperatureService temperatureService;
+
+    @Autowired
+    private ISysDayWaterService dayWaterService;
+
+    @Autowired
+    private ISysMonthWaterService monthWaterService;
+
+    @Autowired
+    private ISysFodderService fodderService;
+
+
+
+  /*  //更新盒子,房间信息
+    @Scheduled(cron = "0 0 0 1/7 * ?")
+//    @Scheduled(cron = "0 0/6 * * * ?")
+    private void updateBox(){
+
+        ConsoleLoggerFactory loggerFactory = new ConsoleLoggerFactory();
+        // 指定连接服务器的凭据参数
+        TokenManager tokenManager = new TokenManager(new StaticCredentialProvider(Global.clientId, Global.clientSecret, Global.username, Global.password), Global.idServerUrl, loggerFactory);
+        ServerCaller appServer = new ServerCaller(tokenManager, Global.appServerApiUrl, Global.signalrClientId, loggerFactory);
+        ServerCaller apiBaseServer = new ServerCaller(tokenManager, Global.apiBaserUrl, Global.signalrClientId, loggerFactory);
+        Global.appServer = appServer;
+        Global.apiBaseServer = apiBaseServer;
+        try {
+            BoxGroup[] boxGroups = appServer.executeGet("api/client/box/grouped", BoxGroup[].class);
+            List<BaseBox> boxs = new ArrayList<>();
+            List<BaseRoom> rooms = new ArrayList<>();
+            for (BoxGroup group : boxGroups) {
+                //盒子
+                for (BoxReg boxReg : group.boxRegs) {
+                    String alias = boxReg.alias;
+                    if (alias.endsWith("层环控系统")) {
+                        if (alias.startsWith("海盐青莲1号楼")){
+                            boxs.add( new BaseBox(boxReg.boxUid,alias,1));
+                        }
+                        if (alias.startsWith("海盐青莲2号楼")){
+                            boxs.add( new BaseBox(boxReg.boxUid,alias,2));
+                        }
+                        if (alias.startsWith("海盐青莲3号楼")){
+                            boxs.add( new BaseBox(boxReg.boxUid,alias,3));
+                        }
+                        for (int i= 1 ;i <= 6 ;i++){
+                            BaseRoom baseRoom = new BaseRoom();
+                            baseRoom.setBoxId(boxReg.boxUid);
+                            baseRoom.setRoomName("房舍"+i);
+                            baseRoom.setAlias(alias.substring(4,9));
+                            rooms.add(baseRoom);
+                        }
+
+                    }
+
+                }
+            }
+            baseBoxService.remove(null);
+            baseBoxService.saveBatch(boxs);
+
+            baseRoomService.remove(null);
+            baseRoomService.saveBatch(rooms);
+            System.out.println("更新房舍信息,更新时间------------->"+ new Date());
+        } catch (IOException e) {
+            e.printStackTrace();
+        }
+
+    }*/
+
+    //更新环境数据
+    @Scheduled(cron = "0 0/30 * * * ?")
+    private void updateEnv(){
+        ConsoleLoggerFactory loggerFactory = new ConsoleLoggerFactory();
+        // 指定连接服务器的凭据参数
+        TokenManager tokenManager = new TokenManager(new StaticCredentialProvider(Global.clientId, Global.clientSecret, Global.username, Global.password), Global.idServerUrl, loggerFactory);
+        ServerCaller apiBaseServer = new ServerCaller(tokenManager, Global.apiBaserUrl, Global.signalrClientId, loggerFactory);
+        Global.apiBaseServer = apiBaseServer;
+        DecimalFormat df = new DecimalFormat("#.00");
+
+
+        try {
+
+        List<BaseBox> boxes = baseBoxService.list();
+        for (BaseBox box : boxes) {
+            String uid = box.getUid();
+            Monitory[] monitories = apiBaseServer.executeGet("/v2/box/" + uid + "/dmon/grouped", Monitory[].class);
+            List names = new ArrayList();
+            for (Monitory monitory : monitories) {
+                for (Item item : monitory.items) {
+                    String name = item.name;
+                    if (monitory.name.contains("每个房间") && name != null&& name.startsWith("房舍")) {
+                        if (name.contains("平均温度") || name.contains("湿度")) {
+                            names.add(name);
+                        }
+                    }
+                }
+            }
+
+
+            if (ObjectUtil.isNotEmpty(names)) {
+                MonitoryValue[] monitoryValues = apiBaseServer.executePost("/v2/box/" +uid + "/dmon/value/get", new MonitoryGetArgs(names, null, new ArrayList()), MonitoryValue[].class);
+                List<SysTemperature> temList = new ArrayList();
+                List<SysHumidity> humList = new ArrayList<>();
+                for (MonitoryValue monitoryValue : monitoryValues) {
+                    if (ObjectUtil.isEmpty(monitoryValue)){
+                        continue;
+                    }
+                    String name = monitoryValue.getName();
+                    String[] split = name.split("-");
+                    BaseRoom room = baseRoomService.getOne(new QueryWrapper<BaseRoom>().eq("room_name", split[0]).eq("box_id", uid));
+                    Integer roomId = room.getId();
+                    if (split[1].contains("温度")){
+                        SysTemperature sysTemperature = new SysTemperature();
+                        if (ObjectUtil.isNotEmpty(monitoryValue.getValue())){
+                            Double value = (Double)monitoryValue.getValue() * 0.1;
+                            sysTemperature.setId(monitoryValue.getId());
+                            sysTemperature.setRoomId(roomId);
+                            if (value != 0.0){
+                                sysTemperature.setValue(df.format(value));
+                            }else {
+                                sysTemperature.setValue(value+"");
+                            }
+                            sysTemperature.setCreateTime(monitoryValue.getTimestamp());
+                            temList.add(sysTemperature);
+                        }
+
+                    }
+                    if (split[1].contains("湿度")){
+                        SysHumidity humidity = new SysHumidity();
+                        Double value = (Double)monitoryValue.getValue() ;
+                        humidity.setId(monitoryValue.getId());
+                        humidity.setRoomId(roomId);
+                        if (ObjectUtil.isNotEmpty(value)){
+                            if (value != 0.0){
+                                humidity.setValue(df.format(value));
+                            }else{
+                                humidity.setValue(value+"");
+                            }
+
+                            humidity.setCreateTime(monitoryValue.getTimestamp());
+                            humList.add(humidity);
+                        }
+
+                    }
+
+                }
+                humidityService.saveBatch(humList);
+                temperatureService.saveBatch(temList);
+
+            }
+
+
+        }
+
+
+
+        } catch (IOException e) {
+            e.printStackTrace();
+        }
+        System.out.println("更新温湿度信息,更新时间------------->"+ new Date());
+    }
+
+
+
+    //更新日用水  9
+    @Scheduled(cron = "0 55 8 * * ? ")
+//    @Scheduled(cron = "0 * * * * ?")
+    private void updateDayWater(){
+        ConsoleLoggerFactory loggerFactory = new ConsoleLoggerFactory();
+        // 指定连接服务器的凭据参数
+        TokenManager tokenManager = new TokenManager(new StaticCredentialProvider(Global.clientId, Global.clientSecret, Global.username, Global.password), Global.idServerUrl, loggerFactory);
+        ServerCaller apiBaseServer = new ServerCaller(tokenManager, Global.apiBaserUrl, Global.signalrClientId, loggerFactory);
+        Global.apiBaseServer = apiBaseServer;
+        DecimalFormat df = new DecimalFormat("#.00");
+
+
+        try {
+
+            List<BaseBox> boxes = baseBoxService.list();
+            for (BaseBox box : boxes) {
+                String uid = box.getUid();
+                Monitory[] monitories = apiBaseServer.executeGet("/v2/box/" + uid + "/dmon/grouped", Monitory[].class);
+                List names = new ArrayList();
+                if (ObjectUtil.isEmpty(monitories)){
+                    continue;
+                }
+                for (Monitory monitory : monitories) {
+                    for (Item item : monitory.items) {
+                        String name = item.name;
+                        if (monitory.name.contains("每个房间") && name != null&& name.startsWith("房舍")) {
+                            if (name.contains("日用水量") ) {
+                                names.add(name);
+                            }
+                        }
+                    }
+                }
+
+
+                if (ObjectUtil.isNotEmpty(names)) {
+                    MonitoryValue[] monitoryValues = apiBaseServer.executePost("/v2/box/" +uid + "/dmon/value/get", new MonitoryGetArgs(names, null, new ArrayList()), MonitoryValue[].class);
+
+                    List<SysDayWater> dayWatersList = new ArrayList();
+                    for (MonitoryValue monitoryValue : monitoryValues) {
+                        if (ObjectUtil.isEmpty(monitoryValue)){
+                            continue;
+                        }
+                        String name = monitoryValue.getName();
+                        String[] split = name.split("-");
+                        BaseRoom room = baseRoomService.getOne(new QueryWrapper<BaseRoom>().eq("room_name", split[0]).eq("box_id", uid));
+                        Integer roomId = room.getId();
+
+                        SysDayWater dayWater = new SysDayWater();
+                        Double value = (Double)monitoryValue.getValue();
+
+                        dayWater.setId(monitoryValue.getId());
+                        dayWater.setRoomId(roomId);
+                        if (value == null){
+                            continue;
+                        }
+                        if (0.0 != value){
+                            String format = df.format(value);
+                            if (format.length()==3){
+                                dayWater.setValue(0+format);
+                            }else {
+                                dayWater.setValue(format);
+                            }
+
+                        }else {
+                            dayWater.setValue(value+"");
+                        }
+                        dayWater.setCreateTime(monitoryValue.getTimestamp());
+                        dayWatersList.add(dayWater);
+                    }
+                    dayWaterService.saveBatch(dayWatersList);
+                }
+            }
+
+        } catch (IOException e) {
+            e.printStackTrace();
+        }
+        System.out.println("更新日用水信息,更新时间------------->"+ new Date());
+    }
+
+    //更新两个小时用水
+    @Scheduled(cron = "0 59 0,2,4,6,8,10,12,14,16,18,20,22 * * ? ")
+//    @Scheduled(cron = "0 0/5 * * * ?")
+    private void updateMonthWater(){
+        ConsoleLoggerFactory loggerFactory = new ConsoleLoggerFactory();
+        // 指定连接服务器的凭据参数
+        TokenManager tokenManager = new TokenManager(new StaticCredentialProvider(Global.clientId, Global.clientSecret, Global.username, Global.password), Global.idServerUrl, loggerFactory);
+        ServerCaller apiBaseServer = new ServerCaller(tokenManager, Global.apiBaserUrl, Global.signalrClientId, loggerFactory);
+        Global.apiBaseServer = apiBaseServer;
+        DecimalFormat df = new DecimalFormat("#.00");
+
+
+        try {
+
+            List<BaseBox> boxes = baseBoxService.list();
+            for (BaseBox box : boxes) {
+                String uid = box.getUid();
+                Monitory[] monitories = apiBaseServer.executeGet("/v2/box/" + uid + "/dmon/grouped", Monitory[].class);
+                List names = new ArrayList();
+                for (Monitory monitory : monitories) {
+                    for (Item item : monitory.items) {
+                        String name = item.name;
+                        if (monitory.name.contains("每个房间") && name != null&& name.startsWith("房舍")) {
+                            if (name.contains("日用水量") ) {
+                                names.add(name);
+                            }
+                        }
+                    }
+                }
+
+
+                if (ObjectUtil.isNotEmpty(names)) {
+                    MonitoryValue[] monitoryValues = apiBaseServer.executePost("/v2/box/" +uid + "/dmon/value/get", new MonitoryGetArgs(names, null, new ArrayList()), MonitoryValue[].class);
+                    List<SysMonthWater> dayWatersList = new ArrayList();
+                    for (MonitoryValue monitoryValue : monitoryValues) {
+
+
+
+                        if (ObjectUtil.isEmpty(monitoryValue)){
+                            continue;
+                        }
+                        String name = monitoryValue.getName();
+                        String[] split = name.split("-");
+                        BaseRoom room = baseRoomService.getOne(new QueryWrapper<BaseRoom>().eq("room_name", split[0]).eq("box_id", uid));
+                        Integer roomId = room.getId();
+                        SysMonthWater oldWater = monthWaterService.getOne(
+                                new QueryWrapper<SysMonthWater>()
+                                        .ge("create_time", DataUill.getTimesmorning())
+                                        .eq("room_id", roomId)
+                                        .last("ORDER BY create_time LIMIT 1"));
+
+                        SysMonthWater monthWater = new SysMonthWater();
+                        Double newValue = (Double)monitoryValue.getValue();
+                        Double add =0.0 ;
+                        if (ObjectUtil.isEmpty(oldWater)){
+                            add = newValue;
+                        }else {
+                            Double oldValue = Double.parseDouble(oldWater.getValue());
+                            if (newValue >= oldValue){
+                                add = newValue  -oldValue;
+                            }else {
+                                add = oldValue - newValue + newValue;
+                            }
+
+                        }
+
+
+                        if (add != 0.0){
+                            String format = df.format(add);
+                            if (format.length()==3){
+                                monthWater.setIncreaseValue(0+format);
+                            }else {
+                                monthWater.setIncreaseValue(format);
+                            }
+                        }else {
+                            monthWater.setIncreaseValue(add+"");
+                        }
+
+                        monthWater.setId(monitoryValue.getId());
+                        monthWater.setRoomId(roomId);
+                        if (newValue != 0.0){
+                            String format = df.format(newValue);
+                            if (format.length()==3){
+                                monthWater.setValue(0+format);
+                            }else {
+                                monthWater.setValue(format);
+                            }
+                        }else {
+                            monthWater.setValue(newValue+"");
+                        }
+                        monthWater.setCreateTime(monitoryValue.getTimestamp());
+                        dayWatersList.add(monthWater);
+
+                    }
+                    monthWaterService.saveBatch(dayWatersList);
+                }
+            }
+
+        } catch (IOException e) {
+            e.printStackTrace();
+        }
+        System.out.println("更新月用水信息,更新时间------------->"+ new Date());
+    }
+
+
+    //更新料控
+    @Scheduled(cron = "0 0/3 * * * ? ")
+//    @Scheduled(cron = "0 0/5 * * * ?")
+    private void updateFodder() throws IOException {
+        ConsoleLoggerFactory loggerFactory = new ConsoleLoggerFactory();
+        // 指定连接服务器的凭据参数
+        TokenManager tokenManager = new TokenManager(new StaticCredentialProvider(Global.clientId, Global.clientSecret, Global.username, Global.password), Global.idServerUrl, loggerFactory);
+        ServerCaller apiBaseServer = new ServerCaller(tokenManager, Global.apiBaserUrl, Global.signalrClientId, loggerFactory);
+        Global.apiBaseServer = apiBaseServer;
+
+        List names = new ArrayList();
+        String oneUid = "-1277226674647203111";
+        String twoUid = "-1277176930335980834";
+        String threeUid = "-1277075358654397725";
+        names.add("累计重量");
+
+        MonitoryValue[] monitoryValues = apiBaseServer.executePost("/v2/box/" + oneUid + "/dmon/value/get", new MonitoryGetArgs(names, null, new ArrayList()), MonitoryValue[].class);
+
+        MonitoryValue monitoryValue = monitoryValues[0];
+        Double value = (Double)monitoryValue.getValue();
+        SysFodder oneFodder = fodderService.getOne(new QueryWrapper<SysFodder>().eq("floor_id", 1).last("ORDER BY fodder_id DESC limit 1"));
+        Double oldVale = oneFodder.getValue();
+        if (oldVale < value){
+            oneFodder.setValue(value);
+            fodderService.updateById(oneFodder);
+            System.out.println("一号楼更新------------>"+monitoryValue);
+        }else if (value < oldVale){
+            SysFodder fodder = new SysFodder();
+            fodder.setValue(value);
+            fodder.setCreateTime(monitoryValue.getTimestamp());
+            fodder.setFloorId(1);
+            fodder.setId(monitoryValue.getId());
+            fodderService.save(fodder);
+            System.out.println("一号楼新增------------>"+monitoryValue);
+        }else {
+            System.out.println("一号楼舍弃------------>"+monitoryValue);
+        }
+
+
+
+        MonitoryValue[] twoMonitoryValues = apiBaseServer.executePost("/v2/box/" + twoUid + "/dmon/value/get", new MonitoryGetArgs(names, null, new ArrayList()), MonitoryValue[].class);
+        MonitoryValue twoMonitoryValue = twoMonitoryValues[0];
+        Double twoValue = (Double)twoMonitoryValue.getValue();
+        SysFodder twoFodder = fodderService.getOne(new QueryWrapper<SysFodder>().eq("floor_id", 2).last("ORDER BY fodder_id DESC limit 1"));
+        Double twoOldVale = twoFodder.getValue();
+        if (twoOldVale < twoValue){
+            twoFodder.setValue(twoValue);
+            fodderService.updateById(twoFodder);
+            System.out.println("二号楼更新------------>"+twoFodder);
+        }else if (twoValue < twoOldVale){
+            SysFodder fodder = new SysFodder();
+            fodder.setValue(twoValue);
+            fodder.setCreateTime(twoMonitoryValue.getTimestamp());
+            fodder.setFloorId(2);
+            fodder.setId(twoMonitoryValue.getId());
+            fodderService.save(fodder);
+            System.out.println("二号楼新增------------>"+twoMonitoryValue);
+        }else {
+            System.out.println("二号楼舍弃------------>"+twoMonitoryValue);
+        }
+
+
+        MonitoryValue[] threeMonitoryValues = apiBaseServer.executePost("/v2/box/" + threeUid + "/dmon/value/get", new MonitoryGetArgs(names, null, new ArrayList()), MonitoryValue[].class);
+        MonitoryValue threeMonitoryValue = threeMonitoryValues[0];
+        Double threeValue = (Double)threeMonitoryValue.getValue();
+        SysFodder threeFodder = fodderService.getOne(new QueryWrapper<SysFodder>().eq("floor_id", 3).last("ORDER BY fodder_id DESC limit 1"));
+        Double threeOldVale = threeFodder.getValue();
+        if (threeOldVale < threeValue){
+            threeFodder.setValue(threeValue);
+            fodderService.updateById(threeFodder);
+            System.out.println("三号楼更新------------>"+threeFodder);
+        }else if (threeValue < threeOldVale){
+            SysFodder fodder = new SysFodder();
+            fodder.setValue(threeValue);
+            fodder.setCreateTime(threeMonitoryValue.getTimestamp());
+            fodder.setFloorId(3);
+            fodder.setId(threeMonitoryValue.getId());
+            fodderService.save(fodder);
+            System.out.println("三号楼新增------------>"+threeMonitoryValue);
+        }else {
+            System.out.println("三号楼舍弃------------>"+threeMonitoryValue);
+        }
+
+
+
+        System.out.println("更新料塔信息,更新时间------------->" + new Date());
+
+    }
+}
+
+

+ 23 - 0
huimv-farm-v2/huimv-produce-warning/src/main/resources/com/huimv/produce/mapper/SysDayWaterMapper.xml

@@ -0,0 +1,23 @@
+<?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.produce.mapper.SysDayWaterMapper">
+
+    <select id="countWater" resultType="java.lang.Double">
+        SELECT  ROUND(SUM(`value`),2)
+        FROM   `sys_day_water`
+        ${ew.customSqlSegment}
+
+    </select>
+    <select id="listAllWater" resultType="com.huimv.produce.entity.SysDayWater">
+
+        SELECT
+        id,ROUND(SUM(`value`),2)'value' , create_time, room_id,day_water_id FROM `sys_day_water`
+
+            ${ew.customSqlSegment}
+
+              GROUP BY DATE_FORMAT(create_time,"%y-%m-%d")
+
+    </select>
+
+
+</mapper>

+ 36 - 0
huimv-farm-v2/huimv-produce-warning/src/main/resources/com/huimv/produce/mapper/SysFodderMapper.xml

@@ -0,0 +1,36 @@
+<?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.produce.mapper.SysFodderMapper">
+
+
+
+    <select id="countDayValue" resultType="com.huimv.produce.entity.SysFodder">
+
+        SELECT
+            id,SUM(`value`)'value' ,create_time,floor_id,fodder_id
+        FROM `sys_fodder`
+        ${ew.customSqlSegment}
+        GROUP BY DATE_FORMAT(create_time,"%y-%m-%d")
+    </select>
+
+    <select id="countAllDayValue" resultType="com.huimv.produce.entity.dto.FodderDto">
+
+        SELECT
+             DATE_FORMAT(create_time,"%m-%d") screate_time,floor_id,
+            IFNULL( (SELECT SUM(`value`)  FROM `sys_fodder` WHERE floor_id =1 AND  DATE_FORMAT( f.`create_time`,"%m-%d") = DATE_FORMAT(create_time,"%m-%d")  ),0)'onevalue' ,
+            IFNULL(  (SELECT SUM(`value`)  FROM `sys_fodder` WHERE floor_id =2  AND  DATE_FORMAT( f.`create_time`,"%m-%d") = DATE_FORMAT(create_time,"%m-%d") ),0) 'twovalue',
+            IFNULL( (SELECT SUM(`value`)  FROM `sys_fodder` WHERE floor_id =3  AND  DATE_FORMAT( f.`create_time`,"%m-%d") = DATE_FORMAT(create_time,"%m-%d")),0) 'threevalue'
+        FROM `sys_fodder` f
+            ${ew.customSqlSegment}
+        GROUP BY  screate_time
+    </select>
+    <select id="countAllValue" resultType="java.lang.Integer">
+        SELECT
+            SUM(`value`)
+        FROM `sys_fodder`
+        ${ew.customSqlSegment}
+
+    </select>
+
+
+</mapper>

+ 17 - 0
huimv-farm-v2/huimv-produce-warning/src/main/resources/com/huimv/produce/mapper/SysMonthWaterMapper.xml

@@ -0,0 +1,17 @@
+<?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.produce.mapper.SysMonthWaterMapper">
+
+    <select id="selecAllMonthWater" resultType="com.huimv.produce.entity.SysMonthWater">
+
+        SELECT
+        id,ROUND(SUM(`increase_value`),2)'value' , create_time, room_id,month_water_id FROM `sys_month_water`
+            ${ew.customSqlSegment}
+              GROUP BY DATE_FORMAT(create_time,"%y-%m-%d %H")
+                ORDER BY create_time ASC
+
+    </select>
+
+
+
+</mapper>