Kaynağa Gözat

生物防控人员2

523096025 1 ay önce
ebeveyn
işleme
089b3c581f
25 değiştirilmiş dosya ile 4487 ekleme ve 4376 silme
  1. 10 13
      get-data/pom.xml
  2. 2 1
      get-data/src/main/java/com/huimv/getdata/GetdataApplication.java
  3. 25 0
      get-data/src/main/java/com/huimv/getdata/config/AppConfig.java
  4. 11 2
      get-data/src/main/java/com/huimv/getdata/controller/CenterController.java
  5. 67 0
      get-data/src/main/java/com/huimv/getdata/test/TestConnection.java
  6. 11 0
      get-data/src/main/java/com/huimv/getdata/test/TestWeight.java
  7. 4 3
      get-data/src/main/resources/application-prod.yml
  8. 131 131
      huimv-admin/src/main/java/com/huimv/admin/jinghongtimer/EnergyFeedTimer.java
  9. 86 86
      huimv-admin/src/main/java/com/huimv/admin/jinghongtimer/EnvTimer.java
  10. 101 101
      huimv-admin/src/main/java/com/huimv/admin/jinghongtimer/ProtTimer.java
  11. 103 103
      huimv-admin/src/main/java/com/huimv/admin/timer/CarmeraTimer.java
  12. 56 56
      huimv-admin/src/main/java/com/huimv/admin/timer/EnergyFeedTimer.java
  13. 159 159
      huimv-admin/src/main/java/com/huimv/admin/timer/EnergyTimer.java
  14. 524 524
      huimv-admin/src/main/java/com/huimv/admin/timer/EnvTimer.java
  15. 296 296
      huimv-admin/src/main/java/com/huimv/admin/timer/FeedTimer.java
  16. 50 50
      huimv-admin/src/main/java/com/huimv/admin/timer/FermentTimer.java
  17. 499 499
      huimv-admin/src/main/java/com/huimv/admin/timer/GasTimer.java
  18. 215 215
      huimv-admin/src/main/java/com/huimv/admin/timer/NewEnvTimer.java
  19. 184 184
      huimv-admin/src/main/java/com/huimv/admin/timer/ProdWarningTimer.java
  20. 569 569
      huimv-admin/src/main/java/com/huimv/admin/timer/ProtTimer.java
  21. 54 54
      huimv-admin/src/main/java/com/huimv/admin/timer/SafeTimer.java
  22. 528 528
      huimv-admin/src/main/java/com/huimv/admin/timer/ShenChanTimer.java
  23. 793 793
      huimv-admin/src/main/java/com/huimv/admin/timer/WaterAndElcTimer.java
  24. 2 2
      huimv-admin/src/main/resources/application.properties
  25. 7 7
      huimv-receive/src/main/java/com/huimv/receive/service/impl/BillCleanServiceImpl.java

+ 10 - 13
get-data/pom.xml

@@ -1,4 +1,5 @@
 <?xml version="1.0" encoding="UTF-8"?>
+
 <project xmlns="http://maven.apache.org/POM/4.0.0"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
@@ -15,11 +16,7 @@
 
     <version>0.0.1-SNAPSHOT</version>
     <dependencies>
-<!--        <dependency>-->
-<!--            <groupId>org.springframework.boot</groupId>-->
-<!--            <artifactId>spring-boot-starter-data-jpa</artifactId>-->
-<!--            <version>2.3.1.RELEASE</version>-->
-<!--        </dependency>-->
+
 
         <dependency>
             <groupId>org.projectlombok</groupId>
@@ -28,20 +25,20 @@
 
 <!--        <dependency>-->
 <!--            <groupId>com.microsoft.sqlserver</groupId>-->
-<!--            <artifactId>mssql-jdbc</artifactId>-->
-<!--            <version>9.4.0.jre8</version>-->
-<!--        </dependency>-->
-<!--        <dependency>-->
-<!--            <groupId>com.microsoft.sqlserver</groupId>-->
 <!--            <artifactId>sqljdbc4</artifactId>-->
 <!--            <version>4.0</version>-->
 <!--        </dependency>-->
         <dependency>
-            <groupId>com.microsoft.sqlserver</groupId>
-            <artifactId>sqljdbc4</artifactId>
-            <version>4.0</version>
+            <groupId>net.sourceforge.jtds</groupId>
+            <artifactId>jtds</artifactId>
+            <version>1.2.4</version>
         </dependency>
 
+        <dependency>
+            <groupId>org.apache.commons</groupId>
+            <artifactId>commons-dbcp2</artifactId>
+            <version>2.12.0</version>
+        </dependency>
         <!-- 排除Tomcat容器 -->
         <dependency>
             <groupId>org.springframework.boot</groupId>

+ 2 - 1
get-data/src/main/java/com/huimv/getdata/GetdataApplication.java

@@ -3,6 +3,8 @@ package com.huimv.getdata;
 import org.mybatis.spring.annotation.MapperScan;
 import org.springframework.boot.SpringApplication;
 import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.context.annotation.Bean;
+import org.springframework.jdbc.core.JdbcTemplate;
 
 @SpringBootApplication
 @MapperScan("com.huimv.getdata.mapper")
@@ -11,5 +13,4 @@ public class GetdataApplication {
     public static void main(String[] args) {
         SpringApplication.run(GetdataApplication.class, args);
     }
-
 }

+ 25 - 0
get-data/src/main/java/com/huimv/getdata/config/AppConfig.java

@@ -0,0 +1,25 @@
+package com.huimv.getdata.config;
+
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.jdbc.core.JdbcTemplate;
+import javax.sql.DataSource;
+import org.apache.commons.dbcp2.BasicDataSource;
+
+@Configuration
+public class AppConfig {
+    @Bean
+    public DataSource dataSource() {
+        BasicDataSource dataSource = new BasicDataSource();
+        dataSource.setDriverClassName("net.sourceforge.jtds.jdbc.Driver");
+        dataSource.setUrl("jdbc:jtds:sqlserver://218.76.168.4:1433/CMTWeight");
+        dataSource.setUsername("sa");
+        dataSource.setPassword("jh@123");
+        return dataSource;
+    }
+
+    @Bean
+    public JdbcTemplate jdbcTemplate(DataSource dataSource) {
+        return new JdbcTemplate(dataSource);
+    }
+}

+ 11 - 2
get-data/src/main/java/com/huimv/getdata/controller/CenterController.java

@@ -9,6 +9,7 @@ import com.huimv.getdata.entity.center.YangMaoZhiCaiGouJinE;
 import com.huimv.getdata.entity.voucher.LinJinHuanKuanQi;
 import com.huimv.getdata.service.IErpCenterService;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.jdbc.core.JdbcTemplate;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RequestMethod;
 import org.springframework.web.bind.annotation.RequestParam;
@@ -21,11 +22,19 @@ import java.util.Map;
 @RestController
 @RequestMapping("/weight")
 public class CenterController {
+    private final JdbcTemplate jdbcTemplate;
     @Autowired
     private IErpCenterService centerService;
+
+    @Autowired
+    public CenterController(JdbcTemplate jdbcTemplate) {
+        this.jdbcTemplate = jdbcTemplate;
+    }
     @RequestMapping(value = "/getWeightTest",method = RequestMethod.GET)
-    public Map getWeightTest(@RequestParam(value = "date" ,required = false) String date){
-        return centerService.getWeightTest(date);
+    public List<Map<String, Object>> getWeightTest(@RequestParam(value = "date" ,required = false) String date){
+        String sql = "SELECT * FROM Employees ";
+        return jdbcTemplate.queryForList(sql);
+//        return centerService.getWeightTest(date);
     }
 
     @RequestMapping(value = "/getXiaoShouE",method = RequestMethod.GET)

+ 67 - 0
get-data/src/main/java/com/huimv/getdata/test/TestConnection.java

@@ -0,0 +1,67 @@
+package com.huimv.getdata.test;
+
+import cn.hutool.db.handler.BeanListHandler;
+import org.springframework.jdbc.core.JdbcTemplate;
+import org.springframework.jdbc.support.JdbcUtils;
+import org.springframework.util.LinkedCaseInsensitiveMap;
+
+import javax.sql.DataSource;
+import java.sql.*;
+import java.util.List;
+import java.util.Map;
+
+public class TestConnection {
+    public static void main(String[] args) throws ClassNotFoundException {
+//        try {
+//            Class.forName("net.sourceforge.jtds.jdbc.Driver");
+//            Connection conn = DriverManager.getConnection(
+//                    "jdbc:jtds:sqlserver://218.76.168.4:1433/CMTWeight", "sa", "jh@123");
+//            System.out.println("连接成功!");
+//            conn.close();
+//        } catch (Exception e) {
+//            e.printStackTrace();
+//        }
+
+
+        String url = "jdbc:jtds:sqlserver://218.76.168.4:1433/CMTWeight"; // 使用 jTDS 连接字符串
+        String user = "sa";
+        String password = "jh@123";
+        Class.forName("net.sourceforge.jtds.jdbc.Driver");
+        try (Connection conn = DriverManager.getConnection(url, user, password)) {
+            // 创建 Statement
+            Statement stmt = conn.createStatement();
+            // 创建 PreparedStatement(推荐)
+            String sql = "select * from T_Standard order by F_StdNo desc";
+            PreparedStatement pstmt = conn.prepareStatement(sql);
+            // 执行查询...
+            ResultSet resultSet = pstmt.executeQuery();
+
+//            ResultSetMetaData rsmd = resultSet.getMetaData();
+//            int columnCount = rsmd.getColumnCount();
+//            Map<String, Object> mapOfColumnValues = new LinkedCaseInsensitiveMap(rsmd.getColumnCount());
+//            for(int i = 1; i <= columnCount; ++i) {
+//                String column = JdbcUtils.lookupColumnName(rsmd, i);
+//                mapOfColumnValues.putIfAbsent(column, JdbcUtils.getResultSetValue(resultSet, i));
+//                System.out.println(i);
+//            }
+//            for (String s : mapOfColumnValues.keySet()) {
+//                System.out.println(s + ":"+ mapOfColumnValues.get(s));
+//            }
+            while (resultSet.next()) {
+                String F_CarNo = resultSet.getString("F_CarNo");
+                String F_ProName = resultSet.getString("F_ProName");
+                String F_Model = resultSet.getString("F_Model");
+                System.out.printf("ID: %s, Name: %s, Salary: %s", F_CarNo, F_ProName, F_Model);
+            }
+
+        } catch (Exception  e) {
+            e.printStackTrace();
+        }
+    }
+
+    //  url: jdbc:jtds:sqlserver://218.76.168.4:1433/CMTWeight
+    //    username: sa
+    //    password: jh@123
+    //#    driver-class-name: com.microsoft.sqlserver.jdbc.SQLServerDriver
+    //    driver-class-name: net.sourceforge.jtds.jdbc.Driver
+}

+ 11 - 0
get-data/src/main/java/com/huimv/getdata/test/TestWeight.java

@@ -0,0 +1,11 @@
+package com.huimv.getdata.test;
+
+/**
+ * @Project : huimv.shiwan
+ * @Package : com.huimv.getdata.test
+ * @Description : TODO
+ * @Author : yuxuexuan
+ * @Create : 2025-04-01 16:22
+ **/
+public class TestWeight {
+}

+ 4 - 3
get-data/src/main/resources/application-prod.yml

@@ -4,11 +4,12 @@ spring:
   application:
     name: huimv-getdata
   datasource:
-    url: jdbc:sqlserver://218.76.168.4:1433;DatabaseName=CMTWeight
+#    url: jdbc:sqlserver://218.76.168.4:1433;DatabaseName=CMTWeight
+    url: jdbc:jtds:sqlserver://218.76.168.4:1433/CMTWeight
     username: sa
     password: jh@123
-    driver-class-name: com.microsoft.sqlserver.jdbc.SQLServerDriver
-#    driver-class-name: com.microsoft.jdbc.sqlserver.SQLServerDriver
+#    driver-class-name: com.microsoft.sqlserver.jdbc.SQLServerDriver
+    driver-class-name: net.sourceforge.jtds.jdbc.Driver
     maxActive: 20
     initialSize: 1
     maxWait: 60000

+ 131 - 131
huimv-admin/src/main/java/com/huimv/admin/jinghongtimer/EnergyFeedTimer.java

@@ -1,136 +1,136 @@
-package com.huimv.admin.jinghongtimer;
-
-import cn.hutool.core.date.DateTime;
-import cn.hutool.core.date.DateUtil;
-import cn.hutool.core.util.ObjectUtil;
-import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
-import com.huimv.admin.entity.EnergyData;
-import com.huimv.admin.entity.EnergyEnvDevice;
-import com.huimv.admin.jinghongtimer.Vo.EneryDataVo;
-import com.huimv.admin.jinghongtimer.Vo.EneryDataVo3;
-import com.huimv.admin.jinghongtimer.Vo.TokenVo;
-import com.huimv.admin.mapper.EnergyDataMapper;
-import com.huimv.admin.mapper.EnergyEnvDeviceMapper;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.context.annotation.Configuration;
-import org.springframework.http.HttpEntity;
-import org.springframework.http.HttpHeaders;
-import org.springframework.http.MediaType;
-import org.springframework.http.ResponseEntity;
-import org.springframework.scheduling.annotation.EnableScheduling;
-import org.springframework.scheduling.annotation.Scheduled;
-import org.springframework.util.LinkedMultiValueMap;
-import org.springframework.util.MultiValueMap;
-import org.springframework.util.StringUtils;
-import org.springframework.web.bind.annotation.GetMapping;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RestController;
-import org.springframework.web.client.RestTemplate;
-
-import java.util.Date;
-import java.util.List;
-
-
-//@RestController
-//@RequestMapping("/test")
-@Configuration
-@EnableScheduling
-public class EnergyFeedTimer {
-    @Autowired
-    private EnergyEnvDeviceMapper energyEnvDeviceMapper;
-    @Autowired
-    private EnergyDataMapper energyDataMapper;
-    @Autowired
-    private RestTemplate restTemplate;
-
-
-//    @GetMapping("/test3")
-    @Scheduled(cron = "0 0 * * * ? ")
-    public void action(){
-        DateTime dateTime = DateUtil.offsetHour(new Date(),-1);
-        DateTime endOfMonth = new DateTime();
-        List<EnergyEnvDevice> remark = energyEnvDeviceMapper.selectList(new QueryWrapper<EnergyEnvDevice>().eq("remark", 3));
-        String url = "http://api.infoexdata.cn/foreignApps/foreignerDevice/getDeviceInventoryList";
-        String token = getToke();
-        for (EnergyEnvDevice energyEnvDevice : remark) {
-
-            MultiValueMap<String, String> formData = new LinkedMultiValueMap<>();
-            formData.add("pageNum", "1");
-            formData.add("pageSize", "20");
-            formData.add("uniqueNo", energyEnvDevice.getDeviceCode());
-            formData.add("type", "2");
-            formData.add("compensate", "0");
-            formData.add("startTime", dateTime.toString("yyyy-MM-dd HH:mm:ss"));
-            formData.add("endTime", endOfMonth.toString("yyyy-MM-dd HH:mm:ss"));
-
-            // 设置请求头,指定内容类型为 form-data
-            HttpHeaders headers = new HttpHeaders();
-            headers.set("token",token);
-            headers.setContentType(MediaType.MULTIPART_FORM_DATA);
-            // 创建 HttpEntity
-            HttpEntity<MultiValueMap<String, String>> requestEntity = new HttpEntity<>(formData, headers);
-            // 发送 POST 请求
-            ResponseEntity<EneryDataVo> response = restTemplate.postForEntity(url, requestEntity, EneryDataVo.class);
-            EneryDataVo body = response.getBody();
-            System.out.println(body);
-            if (ObjectUtil.isEmpty(body) || ObjectUtil.isEmpty(body.getData())){
-                continue;
-            }
-            if (body.getData().getRecords() !=null){
-                List<EneryDataVo3> records = body.getData().getRecords();
-                for (EneryDataVo3 record : records) {
-                    EnergyData energyData = new EnergyData();
-//                    energyData.setCreateDate(DateUtil.parse(record.getEndTime(),"yyyy-MM-dd HH:mm:ss"));
-                    energyData.setCreateDate(record.getEndTime());
-                    energyData.setDisplayType(0);
-                    energyData.setFeedValue(record.getNum()+"");
-                    energyData.setUnitId(energyEnvDevice.getUnitId());
-                    energyData.setUnitName(energyEnvDevice.getUnitName());
-                    energyData.setFarmId(energyEnvDevice.getFarmId());
-                    energyDataMapper.insert(energyData);
-                }
-            }
-        }
-
-    }
-
-
-    private  String getToke(){
-        String url = "http://api.infoexdata.cn/foreignApps/foreignApplications/getToken?appId=farnek23dxr5yk8ymvwuhbmup&appKey=x6re4jt63kcpyt3jhyjzb4ckj";
-        TokenVo forObject = restTemplate.getForObject(url, TokenVo.class);
-        if (ObjectUtil.isNotEmpty(forObject) &&forObject.getCode() ==200 ){
-            return forObject.getData();
-        }else {
-            return null;
-        }
-    }
-
-
-    //华统料塔
+//package com.huimv.admin.jinghongtimer;
+//
+//import cn.hutool.core.date.DateTime;
+//import cn.hutool.core.date.DateUtil;
+//import cn.hutool.core.util.ObjectUtil;
+//import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+//import com.huimv.admin.entity.EnergyData;
+//import com.huimv.admin.entity.EnergyEnvDevice;
+//import com.huimv.admin.jinghongtimer.Vo.EneryDataVo;
+//import com.huimv.admin.jinghongtimer.Vo.EneryDataVo3;
+//import com.huimv.admin.jinghongtimer.Vo.TokenVo;
+//import com.huimv.admin.mapper.EnergyDataMapper;
+//import com.huimv.admin.mapper.EnergyEnvDeviceMapper;
+//import org.springframework.beans.factory.annotation.Autowired;
+//import org.springframework.context.annotation.Configuration;
+//import org.springframework.http.HttpEntity;
+//import org.springframework.http.HttpHeaders;
+//import org.springframework.http.MediaType;
+//import org.springframework.http.ResponseEntity;
+//import org.springframework.scheduling.annotation.EnableScheduling;
+//import org.springframework.scheduling.annotation.Scheduled;
+//import org.springframework.util.LinkedMultiValueMap;
+//import org.springframework.util.MultiValueMap;
+//import org.springframework.util.StringUtils;
+//import org.springframework.web.bind.annotation.GetMapping;
+//import org.springframework.web.bind.annotation.RequestMapping;
+//import org.springframework.web.bind.annotation.RestController;
+//import org.springframework.web.client.RestTemplate;
+//
+//import java.util.Date;
+//import java.util.List;
+//
+//
+////@RestController
+////@RequestMapping("/test")
+//@Configuration
+//@EnableScheduling
+//public class EnergyFeedTimer {
+//    @Autowired
+//    private EnergyEnvDeviceMapper energyEnvDeviceMapper;
+//    @Autowired
+//    private EnergyDataMapper energyDataMapper;
+//    @Autowired
+//    private RestTemplate restTemplate;
+//
+//
+////    @GetMapping("/test3")
 //    @Scheduled(cron = "0 0 * * * ? ")
-//    private void action(){
-//        BigDecimal feedConsume;
-//        BasePigpen basePigpen = basePigpenMapper.selectOne(new QueryWrapper<BasePigpen>().lambda()
-//                .eq(BasePigpen::getFType, 3)
-//                .eq(BasePigpen::getFarmId, 26).last("Limit 1"));
-//        if (ObjectUtil.isNotEmpty(basePigpen)){
-//            EnergyData energyData = new EnergyData();
-//            ProdStock prodStock = prodStockMapper.selectOne(new QueryWrapper<ProdStock>().lambda()
-//                    .eq(ProdStock::getFarmId, 26)
-//                    .eq(ProdStock::getDisplayType, 0).orderByDesc(ProdStock::getCreatTime).last("LIMIT 1"));
-//            if (ObjectUtil.isNotEmpty(prodStock)){
-//                feedConsume = BigDecimal.valueOf((800*2.5)*prodStock.getZcl()/1000/12);
-//                feedConsume = feedConsume.setScale(2, RoundingMode.UP);
-//                energyData.setFeedValue(feedConsume.toString());
-//                energyData.setFarmId(26);
-//                energyData.setCreateDate(new Date());
-//                energyData.setDisplayType(1);
-//                energyData.setUnitId(basePigpen.getId());
-//                energyData.setUnitName(basePigpen.getBuildName());
-//                energyDataMapper.insert(energyData);
+//    public void action(){
+//        DateTime dateTime = DateUtil.offsetHour(new Date(),-1);
+//        DateTime endOfMonth = new DateTime();
+//        List<EnergyEnvDevice> remark = energyEnvDeviceMapper.selectList(new QueryWrapper<EnergyEnvDevice>().eq("remark", 3));
+//        String url = "http://api.infoexdata.cn/foreignApps/foreignerDevice/getDeviceInventoryList";
+//        String token = getToke();
+//        for (EnergyEnvDevice energyEnvDevice : remark) {
+//
+//            MultiValueMap<String, String> formData = new LinkedMultiValueMap<>();
+//            formData.add("pageNum", "1");
+//            formData.add("pageSize", "20");
+//            formData.add("uniqueNo", energyEnvDevice.getDeviceCode());
+//            formData.add("type", "2");
+//            formData.add("compensate", "0");
+//            formData.add("startTime", dateTime.toString("yyyy-MM-dd HH:mm:ss"));
+//            formData.add("endTime", endOfMonth.toString("yyyy-MM-dd HH:mm:ss"));
+//
+//            // 设置请求头,指定内容类型为 form-data
+//            HttpHeaders headers = new HttpHeaders();
+//            headers.set("token",token);
+//            headers.setContentType(MediaType.MULTIPART_FORM_DATA);
+//            // 创建 HttpEntity
+//            HttpEntity<MultiValueMap<String, String>> requestEntity = new HttpEntity<>(formData, headers);
+//            // 发送 POST 请求
+//            ResponseEntity<EneryDataVo> response = restTemplate.postForEntity(url, requestEntity, EneryDataVo.class);
+//            EneryDataVo body = response.getBody();
+//            System.out.println(body);
+//            if (ObjectUtil.isEmpty(body) || ObjectUtil.isEmpty(body.getData())){
+//                continue;
 //            }
+//            if (body.getData().getRecords() !=null){
+//                List<EneryDataVo3> records = body.getData().getRecords();
+//                for (EneryDataVo3 record : records) {
+//                    EnergyData energyData = new EnergyData();
+////                    energyData.setCreateDate(DateUtil.parse(record.getEndTime(),"yyyy-MM-dd HH:mm:ss"));
+//                    energyData.setCreateDate(record.getEndTime());
+//                    energyData.setDisplayType(0);
+//                    energyData.setFeedValue(record.getNum()+"");
+//                    energyData.setUnitId(energyEnvDevice.getUnitId());
+//                    energyData.setUnitName(energyEnvDevice.getUnitName());
+//                    energyData.setFarmId(energyEnvDevice.getFarmId());
+//                    energyDataMapper.insert(energyData);
+//                }
+//            }
+//        }
+//
+//    }
 //
+//
+//    private  String getToke(){
+//        String url = "http://api.infoexdata.cn/foreignApps/foreignApplications/getToken?appId=farnek23dxr5yk8ymvwuhbmup&appKey=x6re4jt63kcpyt3jhyjzb4ckj";
+//        TokenVo forObject = restTemplate.getForObject(url, TokenVo.class);
+//        if (ObjectUtil.isNotEmpty(forObject) &&forObject.getCode() ==200 ){
+//            return forObject.getData();
+//        }else {
+//            return null;
 //        }
 //    }
-    //景宏料塔
-}
+//
+//
+//    //华统料塔
+////    @Scheduled(cron = "0 0 * * * ? ")
+////    private void action(){
+////        BigDecimal feedConsume;
+////        BasePigpen basePigpen = basePigpenMapper.selectOne(new QueryWrapper<BasePigpen>().lambda()
+////                .eq(BasePigpen::getFType, 3)
+////                .eq(BasePigpen::getFarmId, 26).last("Limit 1"));
+////        if (ObjectUtil.isNotEmpty(basePigpen)){
+////            EnergyData energyData = new EnergyData();
+////            ProdStock prodStock = prodStockMapper.selectOne(new QueryWrapper<ProdStock>().lambda()
+////                    .eq(ProdStock::getFarmId, 26)
+////                    .eq(ProdStock::getDisplayType, 0).orderByDesc(ProdStock::getCreatTime).last("LIMIT 1"));
+////            if (ObjectUtil.isNotEmpty(prodStock)){
+////                feedConsume = BigDecimal.valueOf((800*2.5)*prodStock.getZcl()/1000/12);
+////                feedConsume = feedConsume.setScale(2, RoundingMode.UP);
+////                energyData.setFeedValue(feedConsume.toString());
+////                energyData.setFarmId(26);
+////                energyData.setCreateDate(new Date());
+////                energyData.setDisplayType(1);
+////                energyData.setUnitId(basePigpen.getId());
+////                energyData.setUnitName(basePigpen.getBuildName());
+////                energyDataMapper.insert(energyData);
+////            }
+////
+////        }
+////    }
+//    //景宏料塔
+//}

+ 86 - 86
huimv-admin/src/main/java/com/huimv/admin/jinghongtimer/EnvTimer.java

@@ -1,86 +1,86 @@
-package com.huimv.admin.jinghongtimer;
-
-import cn.hutool.core.date.DateTime;
-import cn.hutool.core.date.DateUtil;
-import cn.hutool.core.util.ObjectUtil;
-import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
-import com.huimv.admin.entity.EnergyData;
-import com.huimv.admin.entity.EnergyEnvDevice;
-import com.huimv.admin.entity.EnvData;
-import com.huimv.admin.entity.EnvDevice;
-import com.huimv.admin.jinghongtimer.Vo.*;
-import com.huimv.admin.mapper.EnergyDataMapper;
-import com.huimv.admin.mapper.EnergyEnvDeviceMapper;
-import com.huimv.admin.mapper.EnvDataMapper;
-import com.huimv.admin.mapper.EnvDeviceMapper;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.context.annotation.Configuration;
-import org.springframework.http.HttpEntity;
-import org.springframework.http.HttpHeaders;
-import org.springframework.http.MediaType;
-import org.springframework.http.ResponseEntity;
-import org.springframework.scheduling.annotation.EnableScheduling;
-import org.springframework.scheduling.annotation.Scheduled;
-import org.springframework.util.LinkedMultiValueMap;
-import org.springframework.util.MultiValueMap;
-import org.springframework.web.bind.annotation.*;
-import org.springframework.web.client.RestTemplate;
-
-import java.io.IOException;
-import java.util.Date;
-import java.util.List;
-
-
-@RestController
-@RequestMapping("/test")
-public class EnvTimer {
-    @Autowired
-    private EnvDataMapper envDataMapper;
-    @Autowired
-    private EnvDeviceMapper envDeviceMapper;
-    @GetMapping("/test3")
-    public Object test3(@RequestParam String verify) throws IOException {
-        System.out.println(verify);
-        return verify;
-    }
-    @PostMapping("/test3")
-    public Object test3( @RequestBody JingHongWenShi data) throws IOException {
-        System.out.println("test3");
-        System.out.println(data.toString());
-        JingHongWenShi2 data1 = data.getData();
-        String deviceId = data1.getDeviceId();
-        EnvDevice envDevice = envDeviceMapper.selectOne(new QueryWrapper<EnvDevice>().eq("device_code", deviceId));
-
-        EnvData envData = new EnvData();
-        envData.setDeviceId(envDevice.getDeviceCode());
-        envData.setCreateTime(new Date());
-        envData.setFarmId(envDevice.getFarmId());
-        envData.setEnvHum(getHum(data1));
-        envData.setEnvTemp(getTem(data1));
-        envData.setUnitId(envDevice.getUnitId());
-//        envData.setReceiveDate();
-        envDataMapper.insert(envData);
-        return data;
-    }
-
-    private String getHum(JingHongWenShi2 data1) {
-        List<JingHongWenShi3> dataPoints = data1.getDataPoints();
-        for (JingHongWenShi3 dataPoint : dataPoints) {
-            if ("湿度".equals(dataPoint.getVariableName())){
-                return dataPoint.getValue();
-            }
-        }
-        return "0";
-    }
-    private String getTem(JingHongWenShi2 data1) {
-        List<JingHongWenShi3> dataPoints = data1.getDataPoints();
-        for (JingHongWenShi3 dataPoint : dataPoints) {
-            if ("温度".equals(dataPoint.getVariableName())){
-                return dataPoint.getValue();
-            }
-        }
-        return "0";
-    }
-
-
-}
+//package com.huimv.admin.jinghongtimer;
+//
+//import cn.hutool.core.date.DateTime;
+//import cn.hutool.core.date.DateUtil;
+//import cn.hutool.core.util.ObjectUtil;
+//import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+//import com.huimv.admin.entity.EnergyData;
+//import com.huimv.admin.entity.EnergyEnvDevice;
+//import com.huimv.admin.entity.EnvData;
+//import com.huimv.admin.entity.EnvDevice;
+//import com.huimv.admin.jinghongtimer.Vo.*;
+//import com.huimv.admin.mapper.EnergyDataMapper;
+//import com.huimv.admin.mapper.EnergyEnvDeviceMapper;
+//import com.huimv.admin.mapper.EnvDataMapper;
+//import com.huimv.admin.mapper.EnvDeviceMapper;
+//import org.springframework.beans.factory.annotation.Autowired;
+//import org.springframework.context.annotation.Configuration;
+//import org.springframework.http.HttpEntity;
+//import org.springframework.http.HttpHeaders;
+//import org.springframework.http.MediaType;
+//import org.springframework.http.ResponseEntity;
+//import org.springframework.scheduling.annotation.EnableScheduling;
+//import org.springframework.scheduling.annotation.Scheduled;
+//import org.springframework.util.LinkedMultiValueMap;
+//import org.springframework.util.MultiValueMap;
+//import org.springframework.web.bind.annotation.*;
+//import org.springframework.web.client.RestTemplate;
+//
+//import java.io.IOException;
+//import java.util.Date;
+//import java.util.List;
+//
+//
+//@RestController
+//@RequestMapping("/test")
+//public class EnvTimer {
+//    @Autowired
+//    private EnvDataMapper envDataMapper;
+//    @Autowired
+//    private EnvDeviceMapper envDeviceMapper;
+//    @GetMapping("/test3")
+//    public Object test3(@RequestParam String verify) throws IOException {
+//        System.out.println(verify);
+//        return verify;
+//    }
+//    @PostMapping("/test3")
+//    public Object test3( @RequestBody JingHongWenShi data) throws IOException {
+//        System.out.println("test3");
+//        System.out.println(data.toString());
+//        JingHongWenShi2 data1 = data.getData();
+//        String deviceId = data1.getDeviceId();
+//        EnvDevice envDevice = envDeviceMapper.selectOne(new QueryWrapper<EnvDevice>().eq("device_code", deviceId));
+//
+//        EnvData envData = new EnvData();
+//        envData.setDeviceId(envDevice.getDeviceCode());
+//        envData.setCreateTime(new Date());
+//        envData.setFarmId(envDevice.getFarmId());
+//        envData.setEnvHum(getHum(data1));
+//        envData.setEnvTemp(getTem(data1));
+//        envData.setUnitId(envDevice.getUnitId());
+////        envData.setReceiveDate();
+//        envDataMapper.insert(envData);
+//        return data;
+//    }
+//
+//    private String getHum(JingHongWenShi2 data1) {
+//        List<JingHongWenShi3> dataPoints = data1.getDataPoints();
+//        for (JingHongWenShi3 dataPoint : dataPoints) {
+//            if ("湿度".equals(dataPoint.getVariableName())){
+//                return dataPoint.getValue();
+//            }
+//        }
+//        return "0";
+//    }
+//    private String getTem(JingHongWenShi2 data1) {
+//        List<JingHongWenShi3> dataPoints = data1.getDataPoints();
+//        for (JingHongWenShi3 dataPoint : dataPoints) {
+//            if ("温度".equals(dataPoint.getVariableName())){
+//                return dataPoint.getValue();
+//            }
+//        }
+//        return "0";
+//    }
+//
+//
+//}

+ 101 - 101
huimv-admin/src/main/java/com/huimv/admin/jinghongtimer/ProtTimer.java

@@ -1,101 +1,101 @@
-package com.huimv.admin.jinghongtimer;
-
-import com.huimv.admin.entity.ProtData;
-import com.huimv.admin.jinghongtimer.Vo.JinghongWater;
-import com.huimv.admin.mapper.*;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.context.annotation.Configuration;
-import org.springframework.http.ResponseEntity;
-import org.springframework.scheduling.annotation.EnableScheduling;
-import org.springframework.scheduling.annotation.Scheduled;
-import org.springframework.web.bind.annotation.GetMapping;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RestController;
-import org.springframework.web.client.RestClientException;
-import org.springframework.web.client.RestTemplate;
-
-import java.util.List;
-import java.util.Objects;
-
-//@RestController
-//@RequestMapping("/test")
-@Configuration
-@EnableScheduling
-public class ProtTimer {
-
-    @Autowired
-    private ProtDataMapper protDataMapper;
-    @Autowired
-    private RestTemplate restTemplate;
-
-    @Scheduled(cron = "0 0/10 * * * ? ")
-//    @GetMapping("/test3")
-    public void action(){
-        String url = "http://139.9.172.209:8085/getFlow"; // 更好的做法是从配置中读取这个URL
-        try {
-            // 使用泛型来指定返回类型
-            ResponseEntity<List<JinghongWater>> response = restTemplate.exchange(
-                    url,
-                    org.springframework.http.HttpMethod.GET,
-                    null,
-                    new org.springframework.core.ParameterizedTypeReference<List<JinghongWater>>() {}
-            );
-
-            for (JinghongWater jinghongWater : Objects.requireNonNull(response.getBody())) {
-                ProtData protData = new ProtData();
-                protData.setCreateDate(jinghongWater.getCreateTime());
-                protData.setFarmId(getFarmId(jinghongWater.getDeviceId()));
-                protData.setFlow(jinghongWater.getValueA());
-
-                if ("861213058872158".equals(jinghongWater.getDeviceId())){
-                    protData.setLoctionType(2);
-                }else {
-                    protData.setLoctionType(1);
-                }
-
-                protData.setCod("0");
-                protData.setNh3n("0");
-                protData.setPh("0");
-                protData.setTn("0");
-                protData.setTp("0");
-                protDataMapper.insert(protData);
-            }
-
-        } catch (RestClientException e) {
-            // 处理异常,比如记录日志或抛出更具体的业务异常
-            e.printStackTrace();
-            throw new RuntimeException("Failed to fetch flows", e);
-        }
-    }
-    private Integer getFarmId(String deivceId){
-        switch (deivceId){
-            case "861213058861409":
-                return 28;
-            case "861213058829596":
-                return 31;
-            case "861213058846764":
-                return 29;
-            case "861213058846640":
-                return 30;
-            default: //"861213058872158":
-                return 28;
-        }
-
-    }
-    private String getDevice(String deivceId){
-        switch (deivceId){
-            case "861213058861409":
-                return "芙江";
-            case "861213058829596":
-                return "凤行";
-            case "861213058846764":
-                return "庙贝";
-            case "861213058846640":
-                return "潞水";
-            default: //"861213058872158"
-                return "芙江2";
-        }
-
-
-    }
-}
+//package com.huimv.admin.jinghongtimer;
+//
+//import com.huimv.admin.entity.ProtData;
+//import com.huimv.admin.jinghongtimer.Vo.JinghongWater;
+//import com.huimv.admin.mapper.*;
+//import org.springframework.beans.factory.annotation.Autowired;
+//import org.springframework.context.annotation.Configuration;
+//import org.springframework.http.ResponseEntity;
+//import org.springframework.scheduling.annotation.EnableScheduling;
+//import org.springframework.scheduling.annotation.Scheduled;
+//import org.springframework.web.bind.annotation.GetMapping;
+//import org.springframework.web.bind.annotation.RequestMapping;
+//import org.springframework.web.bind.annotation.RestController;
+//import org.springframework.web.client.RestClientException;
+//import org.springframework.web.client.RestTemplate;
+//
+//import java.util.List;
+//import java.util.Objects;
+//
+////@RestController
+////@RequestMapping("/test")
+//@Configuration
+//@EnableScheduling
+//public class ProtTimer {
+//
+//    @Autowired
+//    private ProtDataMapper protDataMapper;
+//    @Autowired
+//    private RestTemplate restTemplate;
+//
+//    @Scheduled(cron = "0 0/10 * * * ? ")
+////    @GetMapping("/test3")
+//    public void action(){
+//        String url = "http://139.9.172.209:8085/getFlow"; // 更好的做法是从配置中读取这个URL
+//        try {
+//            // 使用泛型来指定返回类型
+//            ResponseEntity<List<JinghongWater>> response = restTemplate.exchange(
+//                    url,
+//                    org.springframework.http.HttpMethod.GET,
+//                    null,
+//                    new org.springframework.core.ParameterizedTypeReference<List<JinghongWater>>() {}
+//            );
+//
+//            for (JinghongWater jinghongWater : Objects.requireNonNull(response.getBody())) {
+//                ProtData protData = new ProtData();
+//                protData.setCreateDate(jinghongWater.getCreateTime());
+//                protData.setFarmId(getFarmId(jinghongWater.getDeviceId()));
+//                protData.setFlow(jinghongWater.getValueA());
+//
+//                if ("861213058872158".equals(jinghongWater.getDeviceId())){
+//                    protData.setLoctionType(2);
+//                }else {
+//                    protData.setLoctionType(1);
+//                }
+//
+//                protData.setCod("0");
+//                protData.setNh3n("0");
+//                protData.setPh("0");
+//                protData.setTn("0");
+//                protData.setTp("0");
+//                protDataMapper.insert(protData);
+//            }
+//
+//        } catch (RestClientException e) {
+//            // 处理异常,比如记录日志或抛出更具体的业务异常
+//            e.printStackTrace();
+//            throw new RuntimeException("Failed to fetch flows", e);
+//        }
+//    }
+//    private Integer getFarmId(String deivceId){
+//        switch (deivceId){
+//            case "861213058861409":
+//                return 28;
+//            case "861213058829596":
+//                return 31;
+//            case "861213058846764":
+//                return 29;
+//            case "861213058846640":
+//                return 30;
+//            default: //"861213058872158":
+//                return 28;
+//        }
+//
+//    }
+//    private String getDevice(String deivceId){
+//        switch (deivceId){
+//            case "861213058861409":
+//                return "芙江";
+//            case "861213058829596":
+//                return "凤行";
+//            case "861213058846764":
+//                return "庙贝";
+//            case "861213058846640":
+//                return "潞水";
+//            default: //"861213058872158"
+//                return "芙江2";
+//        }
+//
+//
+//    }
+//}

+ 103 - 103
huimv-admin/src/main/java/com/huimv/admin/timer/CarmeraTimer.java

@@ -1,103 +1,103 @@
-//package com.huimv.admin.timer;
-//
-//import cn.hutool.core.codec.Base64;
-//import cn.hutool.core.util.ObjectUtil;
-//import cn.hutool.json.JSONUtil;
-//import com.alibaba.fastjson.JSON;
-//import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
-//import com.baomidou.mybatisplus.core.toolkit.StringUtils;
-//import com.huimv.admin.common.utils.Digests;
-//import com.huimv.admin.common.utils.HttpClientSSLUtils;
-//import com.huimv.admin.entity.EnvData;
-//import com.huimv.admin.entity.EnvDevice;
-//import com.huimv.admin.entity.EnvWarningInfo;
-//import com.huimv.admin.entity.EnvWarningThreshold;
-//import com.huimv.admin.entity.hkwsdto.CameraDto1;
-//import com.huimv.admin.entity.hkwsdto.HkvsCameraDto;
-//import com.huimv.admin.entity.zengxindto.*;
-//import com.huimv.admin.service.*;
-//import org.springframework.beans.factory.annotation.Autowired;
-//import org.springframework.context.annotation.Configuration;
-//import org.springframework.http.*;
-//import org.springframework.scheduling.annotation.EnableScheduling;
-//import org.springframework.scheduling.annotation.Scheduled;
-//import org.springframework.transaction.annotation.Transactional;
-//import org.springframework.web.client.RestTemplate;
-//
-//import java.lang.invoke.MethodHandleProxies;
-//import java.time.LocalDate;
-//import java.time.LocalDateTime;
-//import java.time.LocalTime;
-//import java.util.Date;
-//import java.util.HashMap;
-//import java.util.List;
-//import java.util.Map;
-//
-//@Configuration
-//@EnableScheduling
-//public class CarmeraTimer {
-//    private static final String APPKEY = "1c9ee657";
-//    private static final String SECRET = "a5d723941c804a429447e71db2707ce8";
-//    private static final String OPENAPI_IP_PORT_HTTP = "http://61.153.248.106:100";
-//    private static final String OPENAPI_IP_PORT_HTTPS = "https://61.153.248.106:4430";
-//    private static final String ITF_ADDRESS_GET_CAMERAS = "/openapi/service/vss/res/getCameras";
-//    private static final String OP_USER_UUID = "5b2eb534696b11e89c2e438f92627767";
-//
-//    @Autowired
-//    private ICameraBaseService cameraBaseService;
-//        //数据库账号密码加密
-//    //更新摄像头状态
-//    @Scheduled(cron = "0 0/10 * * * ? ")
-//    private void updateCameraOnlin() throws Exception {
-//        String cameras = testGetCameras();
-//        HkvsCameraDto hkvsCameraDto = JSONUtil.toBean(cameras, HkvsCameraDto.class);
-//        if (ObjectUtil.isNotEmpty(hkvsCameraDto) && hkvsCameraDto.getErrorCode() ==0 ){
-//            List<CameraDto1> list = hkvsCameraDto.getData().getList();
-//            if (ObjectUtil.isNotEmpty(list)){
-//                cameraBaseService.updateCameraOnlin(list);
-//            }
-//            System.out.println("更新成功");
-//        }else {
-//            System.out.println("摄像头信息为空");
-//        }
-//    }
-//    /**
-//     * HTTP方式
-//     * 分页获取监控点信息 测试
-//     * @return
-//     * @throws Exception
-//     */
-//    private static String testGetCameras() throws Exception{
-//        String url = OPENAPI_IP_PORT_HTTP + ITF_ADDRESS_GET_CAMERAS;
-//        Map<String, Object> map = new HashMap<String, Object>();
-//        map.put("appkey", APPKEY);//设置APPKEY
-//        map.put("time", System.currentTimeMillis());//设置时间参数
-//        map.put("pageNo", 1);//设置分页参数
-//        map.put("pageSize", 1000);//设置分页参数
-//        map.put("opUserUuid", OP_USER_UUID);//设置操作用户UUID
-//        String params = JSON.toJSONString(map);
-//        System.out.println(" ====== getCameras请求参数:【" + params + "】");
-//        String data = HttpClientSSLUtils.doPost(url + "?token=" + Digests.buildToken(url + "?" + params, null, SECRET), params);
-//        System.out.println(" ====== getCameras请求返回结果:【{" + data + "}】");
-//        return data;
-//    }
-//
-//
-//    public static void main(String[] args) {
-//        RestTemplate restTemplate = new RestTemplate();
-//        String envUrl = "https://dnqyt.envchina.com/api/public/station-data";
-//        LocalDate previousDay = LocalDate.now().minusDays(1);
-//        LocalDateTime previousDayStart = LocalDateTime.of(previousDay, LocalTime.MIN);
-//
-//        String sgToken = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhdWQiOiJkYW9ub25nIiwidWlkIjozLCJ1biI6IlpYUUxZWktKMjMwN0EyIiwiZXhwIjoxNjg5MDcwNTYxLCJqdGkiOiIzIn0.BEFESZrKOwBej4rxOfoj7qPcHGomh6KN7xbXdjOB__w";
-//        HttpHeaders headers = new HttpHeaders();
-//        headers.add("token",sgToken);
-//        headers.setContentType(MediaType.APPLICATION_JSON);
-//        HttpEntity<Map<String, Object>> formEntity = new HttpEntity<Map<String, Object>>(headers);
-//
-//        String urlWithParams = envUrl + "?type=D&mn=33330424001391" + "&startTime=" + "2023-07-10 00:00:00" + "&endTime=" + "2023-07-10 00:00:00";
-//        ResponseEntity<String> result = restTemplate.exchange(urlWithParams, HttpMethod.GET,formEntity,String.class);
-//        System.out.println(result);
-//    }
-//
-//}
+package com.huimv.admin.timer;
+
+import cn.hutool.core.codec.Base64;
+import cn.hutool.core.util.ObjectUtil;
+import cn.hutool.json.JSONUtil;
+import com.alibaba.fastjson.JSON;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.baomidou.mybatisplus.core.toolkit.StringUtils;
+import com.huimv.admin.common.utils.Digests;
+import com.huimv.admin.common.utils.HttpClientSSLUtils;
+import com.huimv.admin.entity.EnvData;
+import com.huimv.admin.entity.EnvDevice;
+import com.huimv.admin.entity.EnvWarningInfo;
+import com.huimv.admin.entity.EnvWarningThreshold;
+import com.huimv.admin.entity.hkwsdto.CameraDto1;
+import com.huimv.admin.entity.hkwsdto.HkvsCameraDto;
+import com.huimv.admin.entity.zengxindto.*;
+import com.huimv.admin.service.*;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.http.*;
+import org.springframework.scheduling.annotation.EnableScheduling;
+import org.springframework.scheduling.annotation.Scheduled;
+import org.springframework.transaction.annotation.Transactional;
+import org.springframework.web.client.RestTemplate;
+
+import java.lang.invoke.MethodHandleProxies;
+import java.time.LocalDate;
+import java.time.LocalDateTime;
+import java.time.LocalTime;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+@Configuration
+@EnableScheduling
+public class CarmeraTimer {
+    private static final String APPKEY = "1c9ee657";
+    private static final String SECRET = "a5d723941c804a429447e71db2707ce8";
+    private static final String OPENAPI_IP_PORT_HTTP = "http://61.153.248.106:100";
+    private static final String OPENAPI_IP_PORT_HTTPS = "https://61.153.248.106:4430";
+    private static final String ITF_ADDRESS_GET_CAMERAS = "/openapi/service/vss/res/getCameras";
+    private static final String OP_USER_UUID = "5b2eb534696b11e89c2e438f92627767";
+
+    @Autowired
+    private ICameraBaseService cameraBaseService;
+        //数据库账号密码加密
+    //更新摄像头状态
+    @Scheduled(cron = "0 0/10 * * * ? ")
+    private void updateCameraOnlin() throws Exception {
+        String cameras = testGetCameras();
+        HkvsCameraDto hkvsCameraDto = JSONUtil.toBean(cameras, HkvsCameraDto.class);
+        if (ObjectUtil.isNotEmpty(hkvsCameraDto) && hkvsCameraDto.getErrorCode() ==0 ){
+            List<CameraDto1> list = hkvsCameraDto.getData().getList();
+            if (ObjectUtil.isNotEmpty(list)){
+                cameraBaseService.updateCameraOnlin(list);
+            }
+            System.out.println("更新成功");
+        }else {
+            System.out.println("摄像头信息为空");
+        }
+    }
+    /**
+     * HTTP方式
+     * 分页获取监控点信息 测试
+     * @return
+     * @throws Exception
+     */
+    private static String testGetCameras() throws Exception{
+        String url = OPENAPI_IP_PORT_HTTP + ITF_ADDRESS_GET_CAMERAS;
+        Map<String, Object> map = new HashMap<String, Object>();
+        map.put("appkey", APPKEY);//设置APPKEY
+        map.put("time", System.currentTimeMillis());//设置时间参数
+        map.put("pageNo", 1);//设置分页参数
+        map.put("pageSize", 1000);//设置分页参数
+        map.put("opUserUuid", OP_USER_UUID);//设置操作用户UUID
+        String params = JSON.toJSONString(map);
+        System.out.println(" ====== getCameras请求参数:【" + params + "】");
+        String data = HttpClientSSLUtils.doPost(url + "?token=" + Digests.buildToken(url + "?" + params, null, SECRET), params);
+        System.out.println(" ====== getCameras请求返回结果:【{" + data + "}】");
+        return data;
+    }
+
+
+    public static void main(String[] args) {
+        RestTemplate restTemplate = new RestTemplate();
+        String envUrl = "https://dnqyt.envchina.com/api/public/station-data";
+        LocalDate previousDay = LocalDate.now().minusDays(1);
+        LocalDateTime previousDayStart = LocalDateTime.of(previousDay, LocalTime.MIN);
+
+        String sgToken = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhdWQiOiJkYW9ub25nIiwidWlkIjozLCJ1biI6IlpYUUxZWktKMjMwN0EyIiwiZXhwIjoxNjg5MDcwNTYxLCJqdGkiOiIzIn0.BEFESZrKOwBej4rxOfoj7qPcHGomh6KN7xbXdjOB__w";
+        HttpHeaders headers = new HttpHeaders();
+        headers.add("token",sgToken);
+        headers.setContentType(MediaType.APPLICATION_JSON);
+        HttpEntity<Map<String, Object>> formEntity = new HttpEntity<Map<String, Object>>(headers);
+
+        String urlWithParams = envUrl + "?type=D&mn=33330424001391" + "&startTime=" + "2023-07-10 00:00:00" + "&endTime=" + "2023-07-10 00:00:00";
+        ResponseEntity<String> result = restTemplate.exchange(urlWithParams, HttpMethod.GET,formEntity,String.class);
+        System.out.println(result);
+    }
+
+}

+ 56 - 56
huimv-admin/src/main/java/com/huimv/admin/timer/EnergyFeedTimer.java

@@ -1,57 +1,57 @@
-//package com.huimv.admin.timer;
+package com.huimv.admin.timer;
+
+import cn.hutool.core.util.ObjectUtil;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.huimv.admin.entity.BasePigpen;
+import com.huimv.admin.entity.EnergyData;
+import com.huimv.admin.entity.ProdStock;
+import com.huimv.admin.mapper.BaseFarmMapper;
+import com.huimv.admin.mapper.BasePigpenMapper;
+import com.huimv.admin.mapper.EnergyDataMapper;
+import com.huimv.admin.mapper.ProdStockMapper;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.scheduling.annotation.EnableScheduling;
+import org.springframework.scheduling.annotation.Scheduled;
+
+import java.math.BigDecimal;
+import java.math.RoundingMode;
+import java.util.Date;
+
+@Configuration
+@EnableScheduling
+public class EnergyFeedTimer {
+    @Autowired
+    private BasePigpenMapper basePigpenMapper;
+    @Autowired
+    private EnergyDataMapper energyDataMapper;
+    @Autowired
+    private ProdStockMapper prodStockMapper;
+    //华统料塔
+//    @Scheduled(cron = "0 0 * * * ? ")
+//    private void action(){
+//        BigDecimal feedConsume;
+//        BasePigpen basePigpen = basePigpenMapper.selectOne(new QueryWrapper<BasePigpen>().lambda()
+//                .eq(BasePigpen::getFType, 3)
+//                .eq(BasePigpen::getFarmId, 26).last("Limit 1"));
+//        if (ObjectUtil.isNotEmpty(basePigpen)){
+//            EnergyData energyData = new EnergyData();
+//            ProdStock prodStock = prodStockMapper.selectOne(new QueryWrapper<ProdStock>().lambda()
+//                    .eq(ProdStock::getFarmId, 26)
+//                    .eq(ProdStock::getDisplayType, 0).orderByDesc(ProdStock::getCreatTime).last("LIMIT 1"));
+//            if (ObjectUtil.isNotEmpty(prodStock)){
+//                feedConsume = BigDecimal.valueOf((800*2.5)*prodStock.getZcl()/1000/12);
+//                feedConsume = feedConsume.setScale(2, RoundingMode.UP);
+//                energyData.setFeedValue(feedConsume.toString());
+//                energyData.setFarmId(26);
+//                energyData.setCreateDate(new Date());
+//                energyData.setDisplayType(1);
+//                energyData.setUnitId(basePigpen.getId());
+//                energyData.setUnitName(basePigpen.getBuildName());
+//                energyDataMapper.insert(energyData);
+//            }
 //
-//import cn.hutool.core.util.ObjectUtil;
-//import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
-//import com.huimv.admin.entity.BasePigpen;
-//import com.huimv.admin.entity.EnergyData;
-//import com.huimv.admin.entity.ProdStock;
-//import com.huimv.admin.mapper.BaseFarmMapper;
-//import com.huimv.admin.mapper.BasePigpenMapper;
-//import com.huimv.admin.mapper.EnergyDataMapper;
-//import com.huimv.admin.mapper.ProdStockMapper;
-//import org.springframework.beans.factory.annotation.Autowired;
-//import org.springframework.context.annotation.Configuration;
-//import org.springframework.scheduling.annotation.EnableScheduling;
-//import org.springframework.scheduling.annotation.Scheduled;
-//
-//import java.math.BigDecimal;
-//import java.math.RoundingMode;
-//import java.util.Date;
-//
-//@Configuration
-//@EnableScheduling
-//public class EnergyFeedTimer {
-//    @Autowired
-//    private BasePigpenMapper basePigpenMapper;
-//    @Autowired
-//    private EnergyDataMapper energyDataMapper;
-//    @Autowired
-//    private ProdStockMapper prodStockMapper;
-//    //华统料塔
-////    @Scheduled(cron = "0 0 * * * ? ")
-////    private void action(){
-////        BigDecimal feedConsume;
-////        BasePigpen basePigpen = basePigpenMapper.selectOne(new QueryWrapper<BasePigpen>().lambda()
-////                .eq(BasePigpen::getFType, 3)
-////                .eq(BasePigpen::getFarmId, 26).last("Limit 1"));
-////        if (ObjectUtil.isNotEmpty(basePigpen)){
-////            EnergyData energyData = new EnergyData();
-////            ProdStock prodStock = prodStockMapper.selectOne(new QueryWrapper<ProdStock>().lambda()
-////                    .eq(ProdStock::getFarmId, 26)
-////                    .eq(ProdStock::getDisplayType, 0).orderByDesc(ProdStock::getCreatTime).last("LIMIT 1"));
-////            if (ObjectUtil.isNotEmpty(prodStock)){
-////                feedConsume = BigDecimal.valueOf((800*2.5)*prodStock.getZcl()/1000/12);
-////                feedConsume = feedConsume.setScale(2, RoundingMode.UP);
-////                energyData.setFeedValue(feedConsume.toString());
-////                energyData.setFarmId(26);
-////                energyData.setCreateDate(new Date());
-////                energyData.setDisplayType(1);
-////                energyData.setUnitId(basePigpen.getId());
-////                energyData.setUnitName(basePigpen.getBuildName());
-////                energyDataMapper.insert(energyData);
-////            }
-////
-////        }
-////    }
-//    //景宏料塔
-//}
+//        }
+//    }
+    //景宏料塔
+}

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

@@ -1,159 +1,159 @@
-//package com.huimv.admin.timer;
-//
-//import cn.hutool.core.date.DateTime;
-//import cn.hutool.core.date.DateUtil;
-//import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
-//import com.huimv.admin.common.utils.NumberUtils;
-//import com.huimv.admin.entity.*;
-//import com.huimv.admin.mapper.*;
-//import org.apache.commons.lang.time.DateUtils;
-//import org.springframework.beans.factory.annotation.Autowired;
-//import org.springframework.context.annotation.Configuration;
-//import org.springframework.scheduling.annotation.EnableScheduling;
-//import org.springframework.scheduling.annotation.Scheduled;
-//
-//import java.text.DecimalFormat;
-//import java.util.Date;
-//import java.util.List;
-//
-//@Configuration
-//@EnableScheduling
-//public class EnergyTimer {
-//
-//    @Autowired
-//    private EnergyEnvDeviceMapper deviceMapper;
-//    @Autowired
-//    private EnergyDataMapper dataMapper;
-//    @Autowired
-//    private BasePigpenMapper basePigpenMapper;
-//    @Autowired
-//    private EnergyWarningThresholdMapper warningThresholdMapper;
-//    @Autowired
-//    private EnergyWarningInfoMapper infoMapper;
-//    @Autowired
-//    private BaseFarmMapper baseFarmMapper;
-//
-//    //    能耗数据
-//    @Scheduled(cron = "0 0 */1 * * ? ")
-////    @Scheduled(cron = "0 */1 * * * ? ")
-//    private void getShenChan() throws Exception {
-//        List<EnergyEnvDevice> energyEnvDevices = deviceMapper.selectList(new QueryWrapper<EnergyEnvDevice>().ne("farm_id",26)
-//                .ne("farm_id",29).ne("farm_id",21).ne("farm_id",28).ne("farm_id",27).
-//                        ne("farm_id",35).ne("farm_id",33).ne("farm_id",22).ne("farm_id",23)
-//                .ne("farm_id",34) .ne("farm_id",36) .ne("farm_id",37).ne("farm_id",38)
-//                .ne("farm_id",40).ne("farm_id",41).ne("farm_id",39).ne("farm_id",42)
-//                .ne("farm_id",24));
-//
-//        for (EnergyEnvDevice energyEnvDevice : energyEnvDevices) {
-//            QueryWrapper<BasePigpen> basePigpenQueryWrapper = new QueryWrapper<>();
-//            basePigpenQueryWrapper.eq("id", energyEnvDevice.getUnitId()).eq("farm_id", energyEnvDevice.getFarmId());
-//            BasePigpen basePigpen1 = basePigpenMapper.selectOne(basePigpenQueryWrapper);
-//            QueryWrapper<BasePigpen> queryWrapper = new QueryWrapper<>();
-//            queryWrapper.eq("id", basePigpen1.getParentId());
-//            BasePigpen basePigpen = basePigpenMapper.selectOne(queryWrapper);
-//
-//            String feed = NumberUtils.getNumFloat2(6.00, 6.50);
-//            String water = NumberUtils.getNumFloat2(0.08, 0.15);
-////            String gas = NumberUtils.getNum(200, 280, 1);
-//            String gas = "0";
-//            String electricity = NumberUtils.getNumFloat2(1.0, 1.45);
-//
-//            EnergyData energyData = new EnergyData();
-//            energyData.setCreateDate(new Date());
-//            energyData.setFarmId(energyEnvDevice.getFarmId());
-//            energyData.setUnitId(energyEnvDevice.getUnitId());
-//            if (energyEnvDevice.getFarmId() == 23) {
-//                energyData.setFeedValue("0");
-//            } else {
-//                energyData.setFeedValue(feed);
-//            }
-//
-//            energyData.setWaterValue(water);
-//            energyData.setGasValue(gas);
-//            energyData.setElectricityValue(electricity);
-//            if (energyEnvDevice.getFarmId() == 24) {
-//                String feed1 = NumberUtils.getNumFloat2(1.40, 1.50);
-//                String water1 = NumberUtils.getNumFloat2(20.80, 20.84);
-//                String electricity1 = NumberUtils.getNumFloat2(333.30, 333.34);
-//                energyData.setElectricityValue(electricity1);
-//                energyData.setWaterValue(water1);
-//                energyData.setFeedValue(feed1);
-//            }
-//            dataMapper.insert(energyData);
-//
-//            QueryWrapper<EnergyWarningThreshold> wrapper = new QueryWrapper<>();
-//            wrapper.eq("other1", basePigpen.getStageCode()).eq("farm_id", energyEnvDevice.getFarmId());
-//            EnergyWarningThreshold threshold = warningThresholdMapper.selectOne(wrapper);
-//
-//            QueryWrapper<EnergyData> dataQueryWrapper = new QueryWrapper<>();
-//            dataQueryWrapper.eq("farm_id", energyEnvDevice.getFarmId()).eq("unit_id", energyEnvDevice.getUnitId());
-//            DateTime dateTime = DateUtil.beginOfDay(new Date());
-//            dataQueryWrapper.ge("create_date", dateTime);
-//            EnergyData energyData1 = dataMapper.listDataCount(dataQueryWrapper);
-//
-//            if (Float.parseFloat(energyData1.getWaterValue()) + Float.parseFloat(water) > Float.parseFloat(threshold.getMaxWater())) {
-//                float waterCount = Float.parseFloat(energyData1.getWaterValue()) + Float.parseFloat(water);
-//                DecimalFormat df = new DecimalFormat("#.00");
-//                String format = df.format(waterCount);
-//                EnergyWarningInfo warningInfo = new EnergyWarningInfo();
-//                warningInfo.setWarningType(1);
-//                warningInfo.setWarningContent("今日累计用水量" + format + "t,超过阈值");
-//                warningInfo.setUnitName(basePigpen1.getBuildName());
-//                warningInfo.setUnitId(energyEnvDevice.getUnitId());
-//                warningInfo.setDeviceId(energyEnvDevice.getId());
-//                warningInfo.setDate(new Date());
-//                warningInfo.setFarmId(energyEnvDevice.getFarmId());
-//                warningInfo.setUserIds(threshold.getUserIds());
-//                infoMapper.insert(warningInfo);
-//            }
-//            if (Float.parseFloat(energyData1.getElectricityValue()) + Float.parseFloat(electricity) > Float.parseFloat(threshold.getMaxElectricity())) {
-//                float electricityCount = Float.parseFloat(energyData1.getElectricityValue()) + Float.parseFloat(electricity);
-//                DecimalFormat df = new DecimalFormat("#.00");
-//                String format = df.format(electricityCount);
-//                EnergyWarningInfo warningInfo = new EnergyWarningInfo();
-//                warningInfo.setWarningType(2);
-//                warningInfo.setWarningContent("今日累计用电量" + format + "kw/h,超过阈值");
-//                warningInfo.setUnitName(basePigpen1.getBuildName());
-//                warningInfo.setUnitId(energyEnvDevice.getUnitId());
-//                warningInfo.setDeviceId(energyEnvDevice.getId());
-//                warningInfo.setDate(new Date());
-//                warningInfo.setFarmId(energyEnvDevice.getFarmId());
-//                warningInfo.setUserIds(threshold.getUserIds());
-//                infoMapper.insert(warningInfo);
-//            }
-//            if (Float.parseFloat(energyData1.getFeedValue()) + Float.parseFloat(feed) > Float.parseFloat(threshold.getMaxFeed())) {
-//                float feedCount = Float.parseFloat(energyData1.getFeedValue()) + Float.parseFloat(feed);
-//                DecimalFormat df = new DecimalFormat("#.00");
-//                String format = df.format(feedCount);
-//                EnergyWarningInfo warningInfo = new EnergyWarningInfo();
-//                warningInfo.setWarningType(3);
-//                warningInfo.setWarningContent("今日累计用料量" + format + "kg,超过阈值");
-//                warningInfo.setUnitName(basePigpen.getBuildName());
-//                warningInfo.setUnitId(energyEnvDevice.getUnitId());
-//                warningInfo.setDeviceId(energyEnvDevice.getId());
-//                warningInfo.setDate(new Date());
-//                warningInfo.setFarmId(energyEnvDevice.getFarmId());
-//                warningInfo.setUserIds(threshold.getUserIds());
-//                infoMapper.insert(warningInfo);
-//            }
-//            if (Float.parseFloat(energyData1.getGasValue()) + Float.parseFloat(gas) > Float.parseFloat(threshold.getMaxGas())) {
-//                float gasCount = Float.parseFloat(energyData1.getGasValue()) + Float.parseFloat(gas);
-//                DecimalFormat df = new DecimalFormat("#.00");
-//                String format = df.format(gasCount);
-//                EnergyWarningInfo warningInfo = new EnergyWarningInfo();
-//                warningInfo.setWarningType(4);
-//                warningInfo.setWarningContent("今日累计用气量" + format + "m³,超过阈值");
-//                warningInfo.setUnitName(basePigpen.getBuildName());
-//                warningInfo.setUnitId(energyEnvDevice.getUnitId());
-//                warningInfo.setDeviceId(energyEnvDevice.getId());
-//                warningInfo.setDate(new Date());
-//                warningInfo.setFarmId(energyEnvDevice.getFarmId());
-//                warningInfo.setUserIds(threshold.getUserIds());
-//                infoMapper.insert(warningInfo);
-//            }
-//
-//        }
-//
-//
-//    }
-//}
+package com.huimv.admin.timer;
+
+import cn.hutool.core.date.DateTime;
+import cn.hutool.core.date.DateUtil;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.huimv.admin.common.utils.NumberUtils;
+import com.huimv.admin.entity.*;
+import com.huimv.admin.mapper.*;
+import org.apache.commons.lang.time.DateUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.scheduling.annotation.EnableScheduling;
+import org.springframework.scheduling.annotation.Scheduled;
+
+import java.text.DecimalFormat;
+import java.util.Date;
+import java.util.List;
+
+@Configuration
+@EnableScheduling
+public class EnergyTimer {
+
+    @Autowired
+    private EnergyEnvDeviceMapper deviceMapper;
+    @Autowired
+    private EnergyDataMapper dataMapper;
+    @Autowired
+    private BasePigpenMapper basePigpenMapper;
+    @Autowired
+    private EnergyWarningThresholdMapper warningThresholdMapper;
+    @Autowired
+    private EnergyWarningInfoMapper infoMapper;
+    @Autowired
+    private BaseFarmMapper baseFarmMapper;
+
+    //    能耗数据
+    @Scheduled(cron = "0 0 */1 * * ? ")
+//    @Scheduled(cron = "0 */1 * * * ? ")
+    private void getShenChan() throws Exception {
+        List<EnergyEnvDevice> energyEnvDevices = deviceMapper.selectList(new QueryWrapper<EnergyEnvDevice>().ne("farm_id",26)
+                .ne("farm_id",29).ne("farm_id",21).ne("farm_id",28).ne("farm_id",27).
+                        ne("farm_id",35).ne("farm_id",33).ne("farm_id",22).ne("farm_id",23)
+                .ne("farm_id",34) .ne("farm_id",36) .ne("farm_id",37).ne("farm_id",38)
+                .ne("farm_id",40).ne("farm_id",41).ne("farm_id",39).ne("farm_id",42)
+                .ne("farm_id",24));
+
+        for (EnergyEnvDevice energyEnvDevice : energyEnvDevices) {
+            QueryWrapper<BasePigpen> basePigpenQueryWrapper = new QueryWrapper<>();
+            basePigpenQueryWrapper.eq("id", energyEnvDevice.getUnitId()).eq("farm_id", energyEnvDevice.getFarmId());
+            BasePigpen basePigpen1 = basePigpenMapper.selectOne(basePigpenQueryWrapper);
+            QueryWrapper<BasePigpen> queryWrapper = new QueryWrapper<>();
+            queryWrapper.eq("id", basePigpen1.getParentId());
+            BasePigpen basePigpen = basePigpenMapper.selectOne(queryWrapper);
+
+            String feed = NumberUtils.getNumFloat2(6.00, 6.50);
+            String water = NumberUtils.getNumFloat2(0.08, 0.15);
+//            String gas = NumberUtils.getNum(200, 280, 1);
+            String gas = "0";
+            String electricity = NumberUtils.getNumFloat2(1.0, 1.45);
+
+            EnergyData energyData = new EnergyData();
+            energyData.setCreateDate(new Date());
+            energyData.setFarmId(energyEnvDevice.getFarmId());
+            energyData.setUnitId(energyEnvDevice.getUnitId());
+            if (energyEnvDevice.getFarmId() == 23) {
+                energyData.setFeedValue("0");
+            } else {
+                energyData.setFeedValue(feed);
+            }
+
+            energyData.setWaterValue(water);
+            energyData.setGasValue(gas);
+            energyData.setElectricityValue(electricity);
+            if (energyEnvDevice.getFarmId() == 24) {
+                String feed1 = NumberUtils.getNumFloat2(1.40, 1.50);
+                String water1 = NumberUtils.getNumFloat2(20.80, 20.84);
+                String electricity1 = NumberUtils.getNumFloat2(333.30, 333.34);
+                energyData.setElectricityValue(electricity1);
+                energyData.setWaterValue(water1);
+                energyData.setFeedValue(feed1);
+            }
+            dataMapper.insert(energyData);
+
+            QueryWrapper<EnergyWarningThreshold> wrapper = new QueryWrapper<>();
+            wrapper.eq("other1", basePigpen.getStageCode()).eq("farm_id", energyEnvDevice.getFarmId());
+            EnergyWarningThreshold threshold = warningThresholdMapper.selectOne(wrapper);
+
+            QueryWrapper<EnergyData> dataQueryWrapper = new QueryWrapper<>();
+            dataQueryWrapper.eq("farm_id", energyEnvDevice.getFarmId()).eq("unit_id", energyEnvDevice.getUnitId());
+            DateTime dateTime = DateUtil.beginOfDay(new Date());
+            dataQueryWrapper.ge("create_date", dateTime);
+            EnergyData energyData1 = dataMapper.listDataCount(dataQueryWrapper);
+
+            if (Float.parseFloat(energyData1.getWaterValue()) + Float.parseFloat(water) > Float.parseFloat(threshold.getMaxWater())) {
+                float waterCount = Float.parseFloat(energyData1.getWaterValue()) + Float.parseFloat(water);
+                DecimalFormat df = new DecimalFormat("#.00");
+                String format = df.format(waterCount);
+                EnergyWarningInfo warningInfo = new EnergyWarningInfo();
+                warningInfo.setWarningType(1);
+                warningInfo.setWarningContent("今日累计用水量" + format + "t,超过阈值");
+                warningInfo.setUnitName(basePigpen1.getBuildName());
+                warningInfo.setUnitId(energyEnvDevice.getUnitId());
+                warningInfo.setDeviceId(energyEnvDevice.getId());
+                warningInfo.setDate(new Date());
+                warningInfo.setFarmId(energyEnvDevice.getFarmId());
+                warningInfo.setUserIds(threshold.getUserIds());
+                infoMapper.insert(warningInfo);
+            }
+            if (Float.parseFloat(energyData1.getElectricityValue()) + Float.parseFloat(electricity) > Float.parseFloat(threshold.getMaxElectricity())) {
+                float electricityCount = Float.parseFloat(energyData1.getElectricityValue()) + Float.parseFloat(electricity);
+                DecimalFormat df = new DecimalFormat("#.00");
+                String format = df.format(electricityCount);
+                EnergyWarningInfo warningInfo = new EnergyWarningInfo();
+                warningInfo.setWarningType(2);
+                warningInfo.setWarningContent("今日累计用电量" + format + "kw/h,超过阈值");
+                warningInfo.setUnitName(basePigpen1.getBuildName());
+                warningInfo.setUnitId(energyEnvDevice.getUnitId());
+                warningInfo.setDeviceId(energyEnvDevice.getId());
+                warningInfo.setDate(new Date());
+                warningInfo.setFarmId(energyEnvDevice.getFarmId());
+                warningInfo.setUserIds(threshold.getUserIds());
+                infoMapper.insert(warningInfo);
+            }
+            if (Float.parseFloat(energyData1.getFeedValue()) + Float.parseFloat(feed) > Float.parseFloat(threshold.getMaxFeed())) {
+                float feedCount = Float.parseFloat(energyData1.getFeedValue()) + Float.parseFloat(feed);
+                DecimalFormat df = new DecimalFormat("#.00");
+                String format = df.format(feedCount);
+                EnergyWarningInfo warningInfo = new EnergyWarningInfo();
+                warningInfo.setWarningType(3);
+                warningInfo.setWarningContent("今日累计用料量" + format + "kg,超过阈值");
+                warningInfo.setUnitName(basePigpen.getBuildName());
+                warningInfo.setUnitId(energyEnvDevice.getUnitId());
+                warningInfo.setDeviceId(energyEnvDevice.getId());
+                warningInfo.setDate(new Date());
+                warningInfo.setFarmId(energyEnvDevice.getFarmId());
+                warningInfo.setUserIds(threshold.getUserIds());
+                infoMapper.insert(warningInfo);
+            }
+            if (Float.parseFloat(energyData1.getGasValue()) + Float.parseFloat(gas) > Float.parseFloat(threshold.getMaxGas())) {
+                float gasCount = Float.parseFloat(energyData1.getGasValue()) + Float.parseFloat(gas);
+                DecimalFormat df = new DecimalFormat("#.00");
+                String format = df.format(gasCount);
+                EnergyWarningInfo warningInfo = new EnergyWarningInfo();
+                warningInfo.setWarningType(4);
+                warningInfo.setWarningContent("今日累计用气量" + format + "m³,超过阈值");
+                warningInfo.setUnitName(basePigpen.getBuildName());
+                warningInfo.setUnitId(energyEnvDevice.getUnitId());
+                warningInfo.setDeviceId(energyEnvDevice.getId());
+                warningInfo.setDate(new Date());
+                warningInfo.setFarmId(energyEnvDevice.getFarmId());
+                warningInfo.setUserIds(threshold.getUserIds());
+                infoMapper.insert(warningInfo);
+            }
+
+        }
+
+
+    }
+}

Dosya farkı çok büyük olduğundan ihmal edildi
+ 524 - 524
huimv-admin/src/main/java/com/huimv/admin/timer/EnvTimer.java


+ 296 - 296
huimv-admin/src/main/java/com/huimv/admin/timer/FeedTimer.java

@@ -1,302 +1,302 @@
-//package com.huimv.admin.timer;
-//
-//
-//import cn.hutool.core.codec.Base64;
-//import cn.hutool.core.date.DateTime;
-//import cn.hutool.core.date.DateUtil;
-//import cn.hutool.core.io.FileUtil;
-//import cn.hutool.core.util.ObjectUtil;
-//import cn.hutool.http.HttpRequest;
-//import cn.hutool.http.HttpUtil;
-//import cn.hutool.json.JSONUtil;
-//import com.alibaba.fastjson.JSON;
-//import com.alibaba.fastjson.JSONArray;
-//import com.alibaba.fastjson.JSONObject;
-//import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
-//import com.baomidou.mybatisplus.core.toolkit.StringUtils;
-//import com.huimv.admin.common.utils.HttpClientSSLUtils;
-//import com.huimv.admin.common.utils.NumberUtils;
-//import com.huimv.admin.common.utils.Result;
-//import com.huimv.admin.entity.*;
-//import com.huimv.admin.entity.zengxindto.*;
-//import com.huimv.admin.mapper.FeedAreaMapper;
-//import com.huimv.admin.mapper.FeedPigMapper;
-//import com.huimv.admin.mapper.FeedingDataMapper;
-//import com.huimv.admin.mapper.FeedingEnvMapper;
-//import com.huimv.admin.service.*;
-//import org.springframework.beans.factory.annotation.Autowired;
-//import org.springframework.context.annotation.Configuration;
-//import org.springframework.http.HttpEntity;
-//import org.springframework.http.HttpHeaders;
-//import org.springframework.http.HttpMethod;
-//import org.springframework.http.ResponseEntity;
-//import org.springframework.scheduling.annotation.EnableScheduling;
-//import org.springframework.scheduling.annotation.Scheduled;
-//import org.springframework.transaction.annotation.Transactional;
-//import org.springframework.web.client.RestTemplate;
-//
-//import java.text.DecimalFormat;
-//import java.text.NumberFormat;
-//import java.text.SimpleDateFormat;
-//import java.time.Duration;
-//import java.time.LocalDateTime;
-//import java.util.*;
-//import java.util.concurrent.ThreadLocalRandom;
-//
-//@Configuration
-//@EnableScheduling
-//public class FeedTimer {
-//
-//    @Autowired
-//    private FeedAreaMapper feedAreaMapper;
-//    @Autowired
-//    private FeedingEnvMapper envMapper;
-//    @Autowired
-//    private FeedingDataMapper dataMapper;
-//    @Autowired
-//    private FeedPigMapper pigMapper;
-//
-//
-//    //    @Scheduled(cron = "0 0 */1 * * ? ")
-//    @Scheduled(cron = "0 0/59 * * * ? ")
-//    @Transactional
-//    public void getFeed() throws Exception {
-//        QueryWrapper<FeedArea> queryWrapper = new QueryWrapper<>();
-//        queryWrapper.eq("farm_id", 26);
-//        List<FeedArea> feedAreas = feedAreaMapper.selectList(queryWrapper);
-////        Date now = new Date(); // 获取当前时间
-////        long oneHour = 1 * 60 * 60 * 1000; // 1小时的毫秒数
-////        Date oneHourAgo = new Date(now.getTime() - oneHour); // 获取1小时前的时间
-////        List<String> time = new ArrayList<>();
-////        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
-////        time.add(sdf.format(oneHourAgo));
-////        time.add(sdf.format(new Date()));
-////        System.out.println("这个是传入的时间数组:" + time);
-//        for (FeedArea feedArea : feedAreas) {
-//            HashMap<String, String> paramMap = new HashMap<>();
-//            JSONObject jsonObject = new JSONObject();
-////            jsonObject.put("pageNum", "1");
-////            jsonObject.put("pageSize", "50");
-////            jsonObject.put("createTime", time);
-//            jsonObject.put("fdQrcode", "");
-//            jsonObject.put("fenceNum", "");
-//            jsonObject.put("gatewayNo", feedArea.getGatewayNo());
-//            jsonObject.put("areaId", feedArea.getAreaId());
-//            paramMap.put("Content-Type", "application/json;charset=utf-8");
-//            paramMap.put("AuthorizationF", getToken());
-//            String post = HttpRequest.post("http://znsw.zxkj2006.com/feed/api/mqtt/pageQryRealtime?pageNum=1&pageSize=50").headerMap(paramMap, false).body(jsonObject.toJSONString()).timeout(30 * 1000).execute().body();
-//            JSONObject jsonObject1 = JSONObject.parseObject(post);
-//            Map map = (Map) jsonObject1.get("data");
-//            List<Map<String, Object>> list = (List) map.get("records");
-//            System.out.println("取到了记录:" + list);
-//            if (null != list) {
-//                for (Map<String, Object> stringMap : list) {
-//                    FeedingData data = new FeedingData();
-//                    data.setFarmId(26);
-//                    data.setUnitName(feedArea.getName());
-//                    data.setDeviceCode(stringMap.get("fdQrcode").toString());
-//
-//                    SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm");
-//                    data.setUploadTime(dateFormat.parse(stringMap.get("createTime").toString()));
-//                    data.setBlanking(stringMap.get("zkAlram").toString());
-//                    data.setDeviceType(feedArea.getType());
-//
-//                    QueryWrapper<FeedingEnv> queryWrapper1 = new QueryWrapper<>();
-//                    queryWrapper1.eq("device_code", stringMap.get("fdQrcode"));
-//                    FeedingEnv env = envMapper.selectOne(queryWrapper1);
-//                    if (ObjectUtil.isNotEmpty(env)) {
-//                        data.setEartag(env.getEartag());
-//                    }
-//                    data.setMeals(Integer.parseInt(stringMap.get("dayDeliver").toString()));
-//                    Integer intFdWeight = Integer.parseInt(stringMap.get("intFdWeight").toString());
-//                    Double feed = Double.valueOf(intFdWeight) / 100;
-//                    DecimalFormat def = new DecimalFormat("0.00");
-//                    data.setFoodIntake(def.format(feed));
-//                    data.setWater(stringMap.get("intDwWeight").toString());
-//                    data.setDayNum(stringMap.get("dayOld").toString());
-//                    data.setBodySize(stringMap.get("backfat").toString());
-//                    dataMapper.insert(data);
-//                }
-//            }
-//
-//        }
-//    }
-//
-//    public String getToken() {
+package com.huimv.admin.timer;
+
+
+import cn.hutool.core.codec.Base64;
+import cn.hutool.core.date.DateTime;
+import cn.hutool.core.date.DateUtil;
+import cn.hutool.core.io.FileUtil;
+import cn.hutool.core.util.ObjectUtil;
+import cn.hutool.http.HttpRequest;
+import cn.hutool.http.HttpUtil;
+import cn.hutool.json.JSONUtil;
+import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.baomidou.mybatisplus.core.toolkit.StringUtils;
+import com.huimv.admin.common.utils.HttpClientSSLUtils;
+import com.huimv.admin.common.utils.NumberUtils;
+import com.huimv.admin.common.utils.Result;
+import com.huimv.admin.entity.*;
+import com.huimv.admin.entity.zengxindto.*;
+import com.huimv.admin.mapper.FeedAreaMapper;
+import com.huimv.admin.mapper.FeedPigMapper;
+import com.huimv.admin.mapper.FeedingDataMapper;
+import com.huimv.admin.mapper.FeedingEnvMapper;
+import com.huimv.admin.service.*;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.http.HttpEntity;
+import org.springframework.http.HttpHeaders;
+import org.springframework.http.HttpMethod;
+import org.springframework.http.ResponseEntity;
+import org.springframework.scheduling.annotation.EnableScheduling;
+import org.springframework.scheduling.annotation.Scheduled;
+import org.springframework.transaction.annotation.Transactional;
+import org.springframework.web.client.RestTemplate;
+
+import java.text.DecimalFormat;
+import java.text.NumberFormat;
+import java.text.SimpleDateFormat;
+import java.time.Duration;
+import java.time.LocalDateTime;
+import java.util.*;
+import java.util.concurrent.ThreadLocalRandom;
+
+@Configuration
+@EnableScheduling
+public class FeedTimer {
+
+    @Autowired
+    private FeedAreaMapper feedAreaMapper;
+    @Autowired
+    private FeedingEnvMapper envMapper;
+    @Autowired
+    private FeedingDataMapper dataMapper;
+    @Autowired
+    private FeedPigMapper pigMapper;
+
+
+    //    @Scheduled(cron = "0 0 */1 * * ? ")
+    @Scheduled(cron = "0 0/59 * * * ? ")
+    @Transactional
+    public void getFeed() throws Exception {
+        QueryWrapper<FeedArea> queryWrapper = new QueryWrapper<>();
+        queryWrapper.eq("farm_id", 26);
+        List<FeedArea> feedAreas = feedAreaMapper.selectList(queryWrapper);
+//        Date now = new Date(); // 获取当前时间
+//        long oneHour = 1 * 60 * 60 * 1000; // 1小时的毫秒数
+//        Date oneHourAgo = new Date(now.getTime() - oneHour); // 获取1小时前的时间
+//        List<String> time = new ArrayList<>();
+//        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+//        time.add(sdf.format(oneHourAgo));
+//        time.add(sdf.format(new Date()));
+//        System.out.println("这个是传入的时间数组:" + time);
+        for (FeedArea feedArea : feedAreas) {
+            HashMap<String, String> paramMap = new HashMap<>();
+            JSONObject jsonObject = new JSONObject();
+//            jsonObject.put("pageNum", "1");
+//            jsonObject.put("pageSize", "50");
+//            jsonObject.put("createTime", time);
+            jsonObject.put("fdQrcode", "");
+            jsonObject.put("fenceNum", "");
+            jsonObject.put("gatewayNo", feedArea.getGatewayNo());
+            jsonObject.put("areaId", feedArea.getAreaId());
+            paramMap.put("Content-Type", "application/json;charset=utf-8");
+            paramMap.put("AuthorizationF", getToken());
+            String post = HttpRequest.post("http://znsw.zxkj2006.com/feed/api/mqtt/pageQryRealtime?pageNum=1&pageSize=50").headerMap(paramMap, false).body(jsonObject.toJSONString()).timeout(30 * 1000).execute().body();
+            JSONObject jsonObject1 = JSONObject.parseObject(post);
+            Map map = (Map) jsonObject1.get("data");
+            List<Map<String, Object>> list = (List) map.get("records");
+            System.out.println("取到了记录:" + list);
+            if (null != list) {
+                for (Map<String, Object> stringMap : list) {
+                    FeedingData data = new FeedingData();
+                    data.setFarmId(26);
+                    data.setUnitName(feedArea.getName());
+                    data.setDeviceCode(stringMap.get("fdQrcode").toString());
+
+                    SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm");
+                    data.setUploadTime(dateFormat.parse(stringMap.get("createTime").toString()));
+                    data.setBlanking(stringMap.get("zkAlram").toString());
+                    data.setDeviceType(feedArea.getType());
+
+                    QueryWrapper<FeedingEnv> queryWrapper1 = new QueryWrapper<>();
+                    queryWrapper1.eq("device_code", stringMap.get("fdQrcode"));
+                    FeedingEnv env = envMapper.selectOne(queryWrapper1);
+                    if (ObjectUtil.isNotEmpty(env)) {
+                        data.setEartag(env.getEartag());
+                    }
+                    data.setMeals(Integer.parseInt(stringMap.get("dayDeliver").toString()));
+                    Integer intFdWeight = Integer.parseInt(stringMap.get("intFdWeight").toString());
+                    Double feed = Double.valueOf(intFdWeight) / 100;
+                    DecimalFormat def = new DecimalFormat("0.00");
+                    data.setFoodIntake(def.format(feed));
+                    data.setWater(stringMap.get("intDwWeight").toString());
+                    data.setDayNum(stringMap.get("dayOld").toString());
+                    data.setBodySize(stringMap.get("backfat").toString());
+                    dataMapper.insert(data);
+                }
+            }
+
+        }
+    }
+
+    public String getToken() {
+        HashMap<String, String> paramMap = new HashMap<>();
+        JSONObject jsonObject = new JSONObject();
+        jsonObject.put("username", "ruanzong");
+        jsonObject.put("password", "123456");
+        paramMap.put("Content-Type", "application/json;charset=utf-8");
+        String post = HttpRequest.post("http://znsw.zxkj2006.com/feed/api/admin/appLogin").headerMap(paramMap, false).body(jsonObject.toJSONString()).timeout(30 * 1000).execute().body();
+        JSONObject jsonObject1 = JSONObject.parseObject(post);
+        Map map = (Map) jsonObject1.get("data");
+        String s = map.get("tokenHead") + " " + map.get("token");
+        return s;
+    }
+
+    public static void main(String[] args) {
+//        Date now = new Date(); // 获取当前时间
+//        long oneHour = 1 * 30 * 1000; // 1小时的毫秒数
+//        Date oneHourAgo = new Date(now.getTime() - oneHour); // 获取1小时前的时间
+//        List<String> time = new ArrayList<>();
+//        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+//        time.add(sdf.format(oneHourAgo));
+//        time.add(sdf.format(new Date()));
 //        HashMap<String, String> paramMap = new HashMap<>();
 //        JSONObject jsonObject = new JSONObject();
-//        jsonObject.put("username", "ruanzong");
-//        jsonObject.put("password", "123456");
+//        jsonObject.put("pageNum", 1);
+//        jsonObject.put("pageSize", 20);
+//        jsonObject.put("createTime", time);
+//        jsonObject.put("areaId","1017517");
 //        paramMap.put("Content-Type", "application/json;charset=utf-8");
-//        String post = HttpRequest.post("http://znsw.zxkj2006.com/feed/api/admin/appLogin").headerMap(paramMap, false).body(jsonObject.toJSONString()).timeout(30 * 1000).execute().body();
+//        paramMap.put("AuthorizationF","Bearer eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiJoZW5sdSIsImNyZWF0ZWQiOjE2OTUzNjg1OTE4MjEsImV4cCI6MTY5NTQ1NDk5MX0.63A5FNJD714MVLp2cdH9HLyN25lYtAzsXHysXLEp1eR-FfkQZel6FnuoLfkIoFbgaht1OsEN-2ERabw0Lby7Pg");
+//        String post = HttpRequest.post("http://znsw.zxkj2006.com/feed/api/mqtt/pageQryRealtime").headerMap(paramMap, false).body(jsonObject.toJSONString()).timeout(30 * 1000).execute().body();
 //        JSONObject jsonObject1 = JSONObject.parseObject(post);
 //        Map map = (Map) jsonObject1.get("data");
-//        String s = map.get("tokenHead") + " " + map.get("token");
-//        return s;
-//    }
-//
-//    public static void main(String[] args) {
-////        Date now = new Date(); // 获取当前时间
-////        long oneHour = 1 * 30 * 1000; // 1小时的毫秒数
-////        Date oneHourAgo = new Date(now.getTime() - oneHour); // 获取1小时前的时间
-////        List<String> time = new ArrayList<>();
-////        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
-////        time.add(sdf.format(oneHourAgo));
-////        time.add(sdf.format(new Date()));
-////        HashMap<String, String> paramMap = new HashMap<>();
-////        JSONObject jsonObject = new JSONObject();
-////        jsonObject.put("pageNum", 1);
-////        jsonObject.put("pageSize", 20);
-////        jsonObject.put("createTime", time);
-////        jsonObject.put("areaId","1017517");
-////        paramMap.put("Content-Type", "application/json;charset=utf-8");
-////        paramMap.put("AuthorizationF","Bearer eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiJoZW5sdSIsImNyZWF0ZWQiOjE2OTUzNjg1OTE4MjEsImV4cCI6MTY5NTQ1NDk5MX0.63A5FNJD714MVLp2cdH9HLyN25lYtAzsXHysXLEp1eR-FfkQZel6FnuoLfkIoFbgaht1OsEN-2ERabw0Lby7Pg");
-////        String post = HttpRequest.post("http://znsw.zxkj2006.com/feed/api/mqtt/pageQryRealtime").headerMap(paramMap, false).body(jsonObject.toJSONString()).timeout(30 * 1000).execute().body();
-////        JSONObject jsonObject1 = JSONObject.parseObject(post);
-////        Map map = (Map) jsonObject1.get("data");
-////        System.out.println(map);
-////        List<Map<String, String>> list = (List) map.get("records");
-////        System.out.println(list);
-////        List<String> jsonArray = (ArrayList) map.get("records");
-////        System.out.println(jsonArray);
-//    }
-//
-//
-//    //饲养器添加
-//    @Scheduled(cron = "0 0/57 * * * ? ")
-//    @Transactional
-//    public void getFeedEnv() throws Exception {
-//        QueryWrapper<FeedArea> queryWrapper = new QueryWrapper<>();
-//        queryWrapper.eq("farm_id", 26);
-//        List<FeedArea> feedAreas = feedAreaMapper.selectList(queryWrapper);
-//        for (FeedArea feedArea : feedAreas) {
-//            HashMap<String, String> paramMap = new HashMap<>();
-//            JSONObject jsonObject = new JSONObject();
-//            jsonObject.put("pageNum", "1");
-//            jsonObject.put("pageSize", "200");
-//            jsonObject.put("areaId", feedArea.getAreaId());
-//            paramMap.put("Content-Type", "application/json;charset=utf-8");
-//            paramMap.put("AuthorizationF", getToken());
-//            String post = HttpRequest.post("http://znsw.zxkj2006.com/feed/api/api/v1/feeder/pageQry?pageNum=1&pageSize=50").headerMap(paramMap, false).body(jsonObject.toJSONString()).timeout(30 * 1000).execute().body();
-//            JSONObject jsonObject1 = JSONObject.parseObject(post);
-//            Map map = (Map) jsonObject1.get("data");
-//            List<Map<String, Object>> list = (List) map.get("records");
-//            for (Map<String, Object> stringMap : list) {
-//                QueryWrapper<FeedingEnv> queryWrapper1 = new QueryWrapper<>();
-//                queryWrapper1.eq("farm_id", 26).eq("device_code", stringMap.get("qrcode"));
-//                if (ObjectUtil.isEmpty(envMapper.selectOne(queryWrapper1))) {
-//                    FeedingEnv feedingEnv = new FeedingEnv();
-//                    feedingEnv.setFarmId(26);
-//                    feedingEnv.setUnitName(feedArea.getName());
-//                    feedingEnv.setUnitId(Integer.parseInt(feedArea.getUnitId()));
-//                    feedingEnv.setDeviceType(feedArea.getType());
-//                    feedingEnv.setDeviceCode(stringMap.get("qrcode").toString());
-//                    SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm");
-//                    feedingEnv.setLastTime(dateFormat.parse((String) stringMap.get("createTime")));
-//                    feedingEnv.setOnlineStatus((Integer) stringMap.get("feedStatus"));
-//                    envMapper.insert(feedingEnv);
-//                } else {
-//                    if (StringUtils.isNotBlank(stringMap.get("earTag").toString())) {
-//                        FeedingEnv feedingEnv = envMapper.selectOne(queryWrapper1);
-//                        feedingEnv.setEartag(stringMap.get("earTag").toString());
-//                        envMapper.updateById(feedingEnv);
-//                    }
-//                }
-//
-//            }
-//        }
-//    }
-//
-//
-//    //猪群数量变动
-//    @Scheduled(cron = "0 0 1 * * ? ")
-//    @Transactional
-//    public void getPigCount() throws Exception {
-//        List<FeedingEnv> envs = envMapper.selectList(null);
-//        Integer number = 0;
-//        String type = "";
-//        for (FeedingEnv env : envs) {
-//            String url = "http://znsw.zxkj2006.com/feed/api/api/v1/pig/list/" + env.getEartag();
-//            Map<String, String> heads = new HashMap<>();
-//            heads.put("Authorizationf", getToken());
-//            String body = HttpRequest.get(url).addHeaders(heads).execute().body();
-//            JSONObject jsonObject1 = JSONObject.parseObject(body);
-//            System.out.println("这个是转换为json的" + jsonObject1);
-//            List<JSONObject> data = (List<JSONObject>) jsonObject1.get("data");
-//            System.out.println(data);
-//            if (data.size() > 0) {
-//                JSONObject jsonObject = data.get(0);
-//                String num = jsonObject.get("litterNum").toString();
-//                number = number + Integer.parseInt(num);
-//                type = jsonObject.get("pigType").toString();//类型
-//            }
-//        }
-//        List<FeedPig> feedPigs = pigMapper.selectList(null);
-//        for (FeedPig feedPig : feedPigs) {
-//            if (type.equals(feedPig.getType())) {
-//                feedPig.setNumber(number.toString());
-//                pigMapper.updateById(feedPig);
-//            }
-////            else {
-////                FeedPig pig = new FeedPig();
-////                pig.setType(type);
-////                pig.setNumber(number.toString());
-////                pigMapper.insert(pig);
-////            }
-//        }
-//
-//    }
-//
-//
-//    //饲养器状态修改
-//    @Scheduled(cron = "0 0/5 * * * ? ")
-//    @Transactional
-//    public void getFeedEnvStatus() throws Exception {
-//        QueryWrapper<FeedArea> queryWrapper = new QueryWrapper<>();
-//        queryWrapper.eq("farm_id", 26);
-//        List<FeedArea> feedAreas = feedAreaMapper.selectList(queryWrapper);
-//        for (FeedArea feedArea : feedAreas) {
-//            HashMap<String, String> paramMap = new HashMap<>();
-//            JSONObject jsonObject = new JSONObject();
-//            jsonObject.put("pageNum", "1");
-//            jsonObject.put("pageSize", "20");
-//            jsonObject.put("areaId", feedArea.getAreaId());
-//            paramMap.put("Content-Type", "application/json;charset=utf-8");
-//            paramMap.put("AuthorizationF", getToken());
-//            String post = HttpRequest.post("http://znsw.zxkj2006.com/feed/api/api/v1/feeder/pageQry?pageNum=1&pageSize=50").headerMap(paramMap, false).body(jsonObject.toJSONString()).timeout(30 * 1000).execute().body();
-//            JSONObject jsonObject1 = JSONObject.parseObject(post);
-//            Map map = (Map) jsonObject1.get("data");
-//            List<Map<String, Object>> list = (List) map.get("records");
-//            for (Map<String, Object> stringMap : list) {
-//                QueryWrapper<FeedingEnv> queryWrapper1 = new QueryWrapper<>();
-//                queryWrapper1.eq("farm_id", 26).eq("device_code", stringMap.get("qrcode"));
-//                if (ObjectUtil.isEmpty(envMapper.selectOne(queryWrapper1))) {
-//                    FeedingEnv feedingEnv = new FeedingEnv();
-//                    feedingEnv.setFarmId(26);
-//                    feedingEnv.setUnitName(feedArea.getName());
-//                    feedingEnv.setUnitId(Integer.parseInt(feedArea.getUnitId()));
-//                    feedingEnv.setDeviceType(feedArea.getType());
-//                    feedingEnv.setDeviceCode(stringMap.get("qrcode").toString());
-//                    SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm");
-//                    feedingEnv.setLastTime(dateFormat.parse((String) stringMap.get("createTime")));
-//                    feedingEnv.setOnlineStatus((Integer) stringMap.get("feedStatus"));
-//                    envMapper.insert(feedingEnv);
-//                } else {
-//                    if (StringUtils.isNotBlank(stringMap.get("earTag").toString())) {
-//                        FeedingEnv feedingEnv = envMapper.selectOne(queryWrapper1);
-//                        feedingEnv.setEartag(stringMap.get("earTag").toString());
-//                        String status = stringMap.get("swAlram").toString();
-//                        if ("0".equals(status)) {
-//                            feedingEnv.setOnlineStatus(0);
-//                        } else {
-//                            feedingEnv.setOnlineStatus(1);
-//                        }
-//                        envMapper.updateById(feedingEnv);
-//                    }
-//
-//                }
-//
+//        System.out.println(map);
+//        List<Map<String, String>> list = (List) map.get("records");
+//        System.out.println(list);
+//        List<String> jsonArray = (ArrayList) map.get("records");
+//        System.out.println(jsonArray);
+    }
+
+
+    //饲养器添加
+    @Scheduled(cron = "0 0/57 * * * ? ")
+    @Transactional
+    public void getFeedEnv() throws Exception {
+        QueryWrapper<FeedArea> queryWrapper = new QueryWrapper<>();
+        queryWrapper.eq("farm_id", 26);
+        List<FeedArea> feedAreas = feedAreaMapper.selectList(queryWrapper);
+        for (FeedArea feedArea : feedAreas) {
+            HashMap<String, String> paramMap = new HashMap<>();
+            JSONObject jsonObject = new JSONObject();
+            jsonObject.put("pageNum", "1");
+            jsonObject.put("pageSize", "200");
+            jsonObject.put("areaId", feedArea.getAreaId());
+            paramMap.put("Content-Type", "application/json;charset=utf-8");
+            paramMap.put("AuthorizationF", getToken());
+            String post = HttpRequest.post("http://znsw.zxkj2006.com/feed/api/api/v1/feeder/pageQry?pageNum=1&pageSize=50").headerMap(paramMap, false).body(jsonObject.toJSONString()).timeout(30 * 1000).execute().body();
+            JSONObject jsonObject1 = JSONObject.parseObject(post);
+            Map map = (Map) jsonObject1.get("data");
+            List<Map<String, Object>> list = (List) map.get("records");
+            for (Map<String, Object> stringMap : list) {
+                QueryWrapper<FeedingEnv> queryWrapper1 = new QueryWrapper<>();
+                queryWrapper1.eq("farm_id", 26).eq("device_code", stringMap.get("qrcode"));
+                if (ObjectUtil.isEmpty(envMapper.selectOne(queryWrapper1))) {
+                    FeedingEnv feedingEnv = new FeedingEnv();
+                    feedingEnv.setFarmId(26);
+                    feedingEnv.setUnitName(feedArea.getName());
+                    feedingEnv.setUnitId(Integer.parseInt(feedArea.getUnitId()));
+                    feedingEnv.setDeviceType(feedArea.getType());
+                    feedingEnv.setDeviceCode(stringMap.get("qrcode").toString());
+                    SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm");
+                    feedingEnv.setLastTime(dateFormat.parse((String) stringMap.get("createTime")));
+                    feedingEnv.setOnlineStatus((Integer) stringMap.get("feedStatus"));
+                    envMapper.insert(feedingEnv);
+                } else {
+                    if (StringUtils.isNotBlank(stringMap.get("earTag").toString())) {
+                        FeedingEnv feedingEnv = envMapper.selectOne(queryWrapper1);
+                        feedingEnv.setEartag(stringMap.get("earTag").toString());
+                        envMapper.updateById(feedingEnv);
+                    }
+                }
+
+            }
+        }
+    }
+
+
+    //猪群数量变动
+    @Scheduled(cron = "0 0 1 * * ? ")
+    @Transactional
+    public void getPigCount() throws Exception {
+        List<FeedingEnv> envs = envMapper.selectList(null);
+        Integer number = 0;
+        String type = "";
+        for (FeedingEnv env : envs) {
+            String url = "http://znsw.zxkj2006.com/feed/api/api/v1/pig/list/" + env.getEartag();
+            Map<String, String> heads = new HashMap<>();
+            heads.put("Authorizationf", getToken());
+            String body = HttpRequest.get(url).addHeaders(heads).execute().body();
+            JSONObject jsonObject1 = JSONObject.parseObject(body);
+            System.out.println("这个是转换为json的" + jsonObject1);
+            List<JSONObject> data = (List<JSONObject>) jsonObject1.get("data");
+            System.out.println(data);
+            if (data.size() > 0) {
+                JSONObject jsonObject = data.get(0);
+                String num = jsonObject.get("litterNum").toString();
+                number = number + Integer.parseInt(num);
+                type = jsonObject.get("pigType").toString();//类型
+            }
+        }
+        List<FeedPig> feedPigs = pigMapper.selectList(null);
+        for (FeedPig feedPig : feedPigs) {
+            if (type.equals(feedPig.getType())) {
+                feedPig.setNumber(number.toString());
+                pigMapper.updateById(feedPig);
+            }
+//            else {
+//                FeedPig pig = new FeedPig();
+//                pig.setType(type);
+//                pig.setNumber(number.toString());
+//                pigMapper.insert(pig);
 //            }
-//        }
-//    }
-//}
+        }
+
+    }
+
+
+    //饲养器状态修改
+    @Scheduled(cron = "0 0/5 * * * ? ")
+    @Transactional
+    public void getFeedEnvStatus() throws Exception {
+        QueryWrapper<FeedArea> queryWrapper = new QueryWrapper<>();
+        queryWrapper.eq("farm_id", 26);
+        List<FeedArea> feedAreas = feedAreaMapper.selectList(queryWrapper);
+        for (FeedArea feedArea : feedAreas) {
+            HashMap<String, String> paramMap = new HashMap<>();
+            JSONObject jsonObject = new JSONObject();
+            jsonObject.put("pageNum", "1");
+            jsonObject.put("pageSize", "20");
+            jsonObject.put("areaId", feedArea.getAreaId());
+            paramMap.put("Content-Type", "application/json;charset=utf-8");
+            paramMap.put("AuthorizationF", getToken());
+            String post = HttpRequest.post("http://znsw.zxkj2006.com/feed/api/api/v1/feeder/pageQry?pageNum=1&pageSize=50").headerMap(paramMap, false).body(jsonObject.toJSONString()).timeout(30 * 1000).execute().body();
+            JSONObject jsonObject1 = JSONObject.parseObject(post);
+            Map map = (Map) jsonObject1.get("data");
+            List<Map<String, Object>> list = (List) map.get("records");
+            for (Map<String, Object> stringMap : list) {
+                QueryWrapper<FeedingEnv> queryWrapper1 = new QueryWrapper<>();
+                queryWrapper1.eq("farm_id", 26).eq("device_code", stringMap.get("qrcode"));
+                if (ObjectUtil.isEmpty(envMapper.selectOne(queryWrapper1))) {
+                    FeedingEnv feedingEnv = new FeedingEnv();
+                    feedingEnv.setFarmId(26);
+                    feedingEnv.setUnitName(feedArea.getName());
+                    feedingEnv.setUnitId(Integer.parseInt(feedArea.getUnitId()));
+                    feedingEnv.setDeviceType(feedArea.getType());
+                    feedingEnv.setDeviceCode(stringMap.get("qrcode").toString());
+                    SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm");
+                    feedingEnv.setLastTime(dateFormat.parse((String) stringMap.get("createTime")));
+                    feedingEnv.setOnlineStatus((Integer) stringMap.get("feedStatus"));
+                    envMapper.insert(feedingEnv);
+                } else {
+                    if (StringUtils.isNotBlank(stringMap.get("earTag").toString())) {
+                        FeedingEnv feedingEnv = envMapper.selectOne(queryWrapper1);
+                        feedingEnv.setEartag(stringMap.get("earTag").toString());
+                        String status = stringMap.get("swAlram").toString();
+                        if ("0".equals(status)) {
+                            feedingEnv.setOnlineStatus(0);
+                        } else {
+                            feedingEnv.setOnlineStatus(1);
+                        }
+                        envMapper.updateById(feedingEnv);
+                    }
+
+                }
+
+            }
+        }
+    }
+}

+ 50 - 50
huimv-admin/src/main/java/com/huimv/admin/timer/FermentTimer.java

@@ -1,50 +1,50 @@
-//package com.huimv.admin.timer;
-//
-//import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
-//import com.huimv.admin.common.utils.NumberUtils;
-//import com.huimv.admin.entity.ProdFermentData;
-//import com.huimv.admin.entity.ProdFermentDevice;
-//import com.huimv.admin.mapper.ProdFermentDataMapper;
-//import com.huimv.admin.mapper.ProdFermentDeviceMapper;
-//import org.springframework.beans.factory.annotation.Autowired;
-//import org.springframework.context.annotation.Configuration;
-//import org.springframework.scheduling.annotation.EnableScheduling;
-//import org.springframework.scheduling.annotation.Scheduled;
-//
-//import java.util.Date;
-//import java.util.List;
-//
-//@Configuration
-//@EnableScheduling
-//public class FermentTimer {
-//    @Autowired
-//    private ProdFermentDeviceMapper deviceMapper;
-//    @Autowired
-//    private ProdFermentDataMapper dataMapper;
-//
-//    @Scheduled(cron = "0 0/30 * * * ? ")
-//    private void getFerment() {
-//        QueryWrapper<ProdFermentDevice> queryWrapper = new QueryWrapper<>();
-//        queryWrapper.eq("farm_id", 26);
-//        List<ProdFermentDevice> devices = deviceMapper.selectList(queryWrapper);
-//        for (ProdFermentDevice device : devices) {
-//            String temp = NumberUtils.getNumFloat(20.0, 50.0);//温度20-50
-//            String hum = NumberUtils.getNumFloat(50.0, 90.0);//湿度50-90
-//            String ph = NumberUtils.getNumFloat(6.5, 7.5);//PH6.5-7.5
-//            String o2 = NumberUtils.getNumFloat(50.0, 500.0);//氧气
-//            String co2 = NumberUtils.getNumFloat(50.0, 500.0);//二氧化碳
-//            ProdFermentData data = new ProdFermentData();
-//            data.setDeviceCode(device.getDeviceCode());
-//            data.setBuildName(device.getBuildName());
-//            data.setFarmId(device.getFarmId());
-//            data.setCreateTime(new Date());
-//            data.setCo2(co2);
-//            data.setHum(hum);
-//            data.setPh(ph);
-//            data.setO2(o2);
-//            data.setTemp(temp);
-//            dataMapper.insert(data);
-//        }
-//
-//    }
-//}
+package com.huimv.admin.timer;
+
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.huimv.admin.common.utils.NumberUtils;
+import com.huimv.admin.entity.ProdFermentData;
+import com.huimv.admin.entity.ProdFermentDevice;
+import com.huimv.admin.mapper.ProdFermentDataMapper;
+import com.huimv.admin.mapper.ProdFermentDeviceMapper;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.scheduling.annotation.EnableScheduling;
+import org.springframework.scheduling.annotation.Scheduled;
+
+import java.util.Date;
+import java.util.List;
+
+@Configuration
+@EnableScheduling
+public class FermentTimer {
+    @Autowired
+    private ProdFermentDeviceMapper deviceMapper;
+    @Autowired
+    private ProdFermentDataMapper dataMapper;
+
+    @Scheduled(cron = "0 0/30 * * * ? ")
+    private void getFerment() {
+        QueryWrapper<ProdFermentDevice> queryWrapper = new QueryWrapper<>();
+        queryWrapper.eq("farm_id", 26);
+        List<ProdFermentDevice> devices = deviceMapper.selectList(queryWrapper);
+        for (ProdFermentDevice device : devices) {
+            String temp = NumberUtils.getNumFloat(20.0, 50.0);//温度20-50
+            String hum = NumberUtils.getNumFloat(50.0, 90.0);//湿度50-90
+            String ph = NumberUtils.getNumFloat(6.5, 7.5);//PH6.5-7.5
+            String o2 = NumberUtils.getNumFloat(50.0, 500.0);//氧气
+            String co2 = NumberUtils.getNumFloat(50.0, 500.0);//二氧化碳
+            ProdFermentData data = new ProdFermentData();
+            data.setDeviceCode(device.getDeviceCode());
+            data.setBuildName(device.getBuildName());
+            data.setFarmId(device.getFarmId());
+            data.setCreateTime(new Date());
+            data.setCo2(co2);
+            data.setHum(hum);
+            data.setPh(ph);
+            data.setO2(o2);
+            data.setTemp(temp);
+            dataMapper.insert(data);
+        }
+
+    }
+}

Dosya farkı çok büyük olduğundan ihmal edildi
+ 499 - 499
huimv-admin/src/main/java/com/huimv/admin/timer/GasTimer.java


+ 215 - 215
huimv-admin/src/main/java/com/huimv/admin/timer/NewEnvTimer.java

@@ -1,215 +1,215 @@
-//package com.huimv.admin.timer;
-//
-//import cn.hutool.core.util.ObjectUtil;
-//import com.alibaba.fastjson.JSONArray;
-//import com.alibaba.fastjson.JSONObject;
-//import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
-//import com.huimv.admin.entity.*;
-//import com.huimv.admin.service.*;
-//import org.apache.commons.lang.StringUtils;
-//import org.springframework.beans.factory.annotation.Autowired;
-//import org.springframework.context.annotation.Configuration;
-//import org.springframework.http.HttpEntity;
-//import org.springframework.http.HttpHeaders;
-//import org.springframework.http.HttpMethod;
-//import org.springframework.http.ResponseEntity;
-//import org.springframework.scheduling.annotation.EnableScheduling;
-//import org.springframework.scheduling.annotation.Scheduled;
-//import org.springframework.util.LinkedMultiValueMap;
-//import org.springframework.util.MultiValueMap;
-//import org.springframework.web.client.RestTemplate;
-//
-//import java.math.BigDecimal;
-//import java.text.ParseException;
-//import java.util.Calendar;
-//import java.util.Date;
-//import java.util.List;
-//
-//@Configuration
-//@EnableScheduling
-//public class NewEnvTimer {
-//    @Autowired
-//    private RestTemplate restTemplate;
-//
-//    @Autowired
-//    private IEnvDeviceService envDeviceService;
-//
-//    @Autowired
-//    private IEnvDataService envDataService;
-//
-//    @Autowired
-//    private IEnvWarningThresholdService envWarningThresholdService;
-//
-//    @Autowired
-//    private IEnvWarningInfoService envWarningInfoService;
-//
-//    @Autowired
-//    private IEnvNh3nService nh3nService;
-//
-//
-//    @Scheduled(cron = "0 0/59 * * * ?")  //每10分钟执行一次
-////    @Scheduled(cron = "0 * * * * ?")  //每10分钟执行一次
-////    @Scheduled(cron = "*/5 * * * * ?")  //每10秒钟执行一次
-//    public void getDeviceFlowData() throws ParseException {
-//        String userId = "-1618620464";
-//        String farmCode = "26";
-//
-//        List<EnvDevice> farm_id = envDeviceService.list(new QueryWrapper<EnvDevice>().eq("farm_id", farmCode));
-//        EnvWarningThreshold envWarningThreshold = envWarningThresholdService.getOne(new QueryWrapper<EnvWarningThreshold>().eq("farm_id", farmCode));
-//        System.out.println("开始");
-//        Date date = new Date();
-//        for (EnvDevice envDevice : farm_id) {
-//            String deviceCode = envDevice.getDeviceCode();
-//            if (StringUtils.isNotBlank(deviceCode)) {
-//                JSONObject resultJo = JSONObject.parseObject(getDeviceFlowFromRemoteURL(userId, deviceCode));
-//                System.out.println("resultJo >>>>>>>>>>>> =" + resultJo);
-//                if (resultJo.getInteger("code") != 1000) {
-//                    System.out.println("牧场[" + farmCode + "]设备组编号(" + deviceCode + ")调用远程接口返回结果出错.");
-//                } else {
-//                    JSONArray dataJa = resultJo.getJSONArray("data");
-//                    JSONObject dataJo = dataJa.getJSONObject(0);
-//                    JSONArray realTimeDataJa = dataJo.getJSONArray("realTimeData");
-//                    JSONObject tempJo = realTimeDataJa.getJSONObject(0);
-//                    String temp = tempJo.getString("dataValue");
-//                    JSONObject humiJo = realTimeDataJa.getJSONObject(1);
-//                    String humi = humiJo.getString("dataValue");
-//                    if (StringUtils.isBlank(humi)) {
-//                        humi = "0";
-//                    }
-//                    if (StringUtils.isBlank(temp)) {
-//                        temp = "0";
-//                    }
-//                    EnvData envData = new EnvData();
-//                    envData.setUnitId(envDevice.getUnitId());
-//                    envData.setEnvTemp(temp);
-//                    envData.setEnvHum(humi);
-//                    envData.setFarmId(envDevice.getFarmId());
-//                    envData.setCreateTime(date);
-//                    envData.setDeviceId(envDevice.getDeviceCode());
-//                    saveTemWarning(temp, envWarningThreshold, envDevice);
-//                    saveHumWarning(humi, envWarningThreshold, envDevice);
-//                    envDataService.save(envData);
-//                    String remark = envDevice.getRemark();
-//                    if (StringUtils.isNotBlank(remark)) {
-//                        QueryWrapper<EnvNh3n> queryWrapper = new QueryWrapper<>();
-//                        queryWrapper.eq("farm_id", farmCode).eq("device_code", remark);
-//                        Calendar calendar = Calendar.getInstance();
-//                        calendar.setTime(new Date());
-//                        calendar.add(Calendar.MINUTE, -40);//
-//                        queryWrapper.between("create_date", calendar.getTime(), new Date());
-//                        List<EnvNh3n> list = nh3nService.list(queryWrapper);
-//                        if (list.size() == 0 && humi.equals("0") && temp.equals("0")) {
-//                            envDevice.setDeviceStatus(0);
-//                        } else {
-//                            envDevice.setDeviceStatus(1);
-//                        }
-//                        envDeviceService.updateById(envDevice);
-//                    }
-//                }
-//            }
-//        }
-//
-//    }
-//
-//
-//    //获取远程数据
-//    private String getDeviceFlowFromRemoteURL(String userId, String groupId) {
-//        //请求头
-//        HttpHeaders headers = new HttpHeaders();
-//        headers.add("userId", userId);
-//        //Body参数
-//        MultiValueMap<String, Object> paramsMap = new LinkedMultiValueMap<String, Object>();
-//        HttpEntity<MultiValueMap> objectHttpEntity = new HttpEntity<MultiValueMap>(paramsMap, headers);
-//        System.out.println("URL_ENVIRON_DEVICE_SERVICE=" + "http://www.0531yun.com/app/GetDeviceData");
-//        ResponseEntity<String> result = restTemplate.exchange("http://www.0531yun.com/app/GetDeviceData?groupId=" + groupId, HttpMethod.GET, objectHttpEntity, String.class);
-//        System.out.println("result.getBody()=" + result.getBody());
-//        return result.getBody();
-//    }
-//
-//    private void saveTemWarning(String val, EnvWarningThreshold envWarningThreshold, EnvDevice envDevice) {
-//        if (com.baomidou.mybatisplus.core.toolkit.StringUtils.isNotBlank(val)) {
-//            String maxTem;
-//            String minTem;
-//            if (ObjectUtil.isEmpty(envWarningThreshold) || com.baomidou.mybatisplus.core.toolkit.StringUtils.isBlank(envWarningThreshold.getMaxTem())) {
-//                maxTem = "40";
-//            } else {
-//                maxTem = envWarningThreshold.getMaxTem();
-//            }
-//            if (ObjectUtil.isEmpty(envWarningThreshold) || com.baomidou.mybatisplus.core.toolkit.StringUtils.isBlank(envWarningThreshold.getMinTem())) {
-//                minTem = "0";
-//            } else {
-//                minTem = envWarningThreshold.getMinTem();
-//            }
-//            System.out.println("maxTem:" + Double.parseDouble(maxTem) + "  minTem:" + Double.parseDouble(minTem) + "   val:" + Double.parseDouble(val));
-//            if (Double.parseDouble(maxTem) < Double.parseDouble(val)) {
-//                EnvWarningInfo envWarningInfo = new EnvWarningInfo();
-//                envWarningInfo.setBuildLocation(envDevice.getUnitName());
-//                envWarningInfo.setDate(new Date());
-//                envWarningInfo.setDeviceId(envDevice.getDeviceCode());
-//                envWarningInfo.setFarmId(envDevice.getFarmId());
-//                envWarningInfo.setUnitId(envDevice.getUnitId());
-//                envWarningInfo.setUnitName(envDevice.getUnitName());
-//                envWarningInfo.setUserIds(envWarningThreshold.getUserIds());
-//                envWarningInfo.setWarningContent("当前温度为" + val + "°超过阈值,请及时检查");
-//                envWarningInfo.setWarningType(1);
-//                envWarningInfoService.save(envWarningInfo);
-//            }
-//            if (Double.parseDouble(minTem) > Double.parseDouble(val)) {
-//                EnvWarningInfo envWarningInfo = new EnvWarningInfo();
-//                envWarningInfo.setBuildLocation(envDevice.getUnitName());
-//                envWarningInfo.setDate(new Date());
-//                envWarningInfo.setDeviceId(envDevice.getDeviceCode());
-//                envWarningInfo.setFarmId(envDevice.getFarmId());
-//                envWarningInfo.setUnitId(envDevice.getUnitId());
-//                envWarningInfo.setUnitName(envDevice.getUnitName());
-//                envWarningInfo.setUserIds(envWarningThreshold.getUserIds());
-//                envWarningInfo.setWarningContent("当前温度为" + val + "°低于阈值,请及时检查");
-//                envWarningInfo.setWarningType(1);
-//                envWarningInfoService.save(envWarningInfo);
-//            }
-//        }
-//    }
-//
-//    public void saveHumWarning(String val, EnvWarningThreshold envWarningThreshold, EnvDevice envDevice) {
-//        if (com.baomidou.mybatisplus.core.toolkit.StringUtils.isNotBlank(val)) {
-//            String maxHum;
-//            String minHum;
-//            if (ObjectUtil.isEmpty(envWarningThreshold) || com.baomidou.mybatisplus.core.toolkit.StringUtils.isBlank(envWarningThreshold.getMaxHum())) {
-//                maxHum = "90";
-//            } else {
-//                maxHum = envWarningThreshold.getMaxHum();
-//            }
-//            if (ObjectUtil.isEmpty(envWarningThreshold) || com.baomidou.mybatisplus.core.toolkit.StringUtils.isBlank(envWarningThreshold.getMinHum())) {
-//                minHum = "0";
-//            } else {
-//                minHum = envWarningThreshold.getMinHum();
-//            }
-//            if (Double.parseDouble(maxHum) < Double.parseDouble(val)) {
-//                EnvWarningInfo envWarningInfo = new EnvWarningInfo();
-//                envWarningInfo.setBuildLocation(envDevice.getUnitName());
-//                envWarningInfo.setDate(new Date());
-//                envWarningInfo.setDeviceId(envDevice.getDeviceCode());
-//                envWarningInfo.setFarmId(envDevice.getFarmId());
-//                envWarningInfo.setUnitId(envDevice.getUnitId());
-//                envWarningInfo.setUnitName(envDevice.getUnitName());
-//                envWarningInfo.setUserIds(envWarningThreshold.getUserIds());
-//                envWarningInfo.setWarningContent("当前湿度为" + val + "%超过阈值,请及时检查");
-//                envWarningInfo.setWarningType(2);
-//                envWarningInfoService.save(envWarningInfo);
-//            }
-//            if (Double.parseDouble(minHum) > Double.parseDouble(val)) {
-//                EnvWarningInfo envWarningInfo = new EnvWarningInfo();
-//                envWarningInfo.setBuildLocation(envDevice.getUnitName());
-//                envWarningInfo.setDate(new Date());
-//                envWarningInfo.setDeviceId(envDevice.getDeviceCode());
-//                envWarningInfo.setFarmId(envDevice.getFarmId());
-//                envWarningInfo.setUnitId(envDevice.getUnitId());
-//                envWarningInfo.setUnitName(envDevice.getUnitName());
-//                envWarningInfo.setUserIds(envWarningThreshold.getUserIds());
-//                envWarningInfo.setWarningContent("当前湿度为" + val + "%低于阈值,请及时检查");
-//                envWarningInfo.setWarningType(2);
-//                envWarningInfoService.save(envWarningInfo);
-//            }
-//        }
-//    }
-//}
+package com.huimv.admin.timer;
+
+import cn.hutool.core.util.ObjectUtil;
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.huimv.admin.entity.*;
+import com.huimv.admin.service.*;
+import org.apache.commons.lang.StringUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.http.HttpEntity;
+import org.springframework.http.HttpHeaders;
+import org.springframework.http.HttpMethod;
+import org.springframework.http.ResponseEntity;
+import org.springframework.scheduling.annotation.EnableScheduling;
+import org.springframework.scheduling.annotation.Scheduled;
+import org.springframework.util.LinkedMultiValueMap;
+import org.springframework.util.MultiValueMap;
+import org.springframework.web.client.RestTemplate;
+
+import java.math.BigDecimal;
+import java.text.ParseException;
+import java.util.Calendar;
+import java.util.Date;
+import java.util.List;
+
+@Configuration
+@EnableScheduling
+public class NewEnvTimer {
+    @Autowired
+    private RestTemplate restTemplate;
+
+    @Autowired
+    private IEnvDeviceService envDeviceService;
+
+    @Autowired
+    private IEnvDataService envDataService;
+
+    @Autowired
+    private IEnvWarningThresholdService envWarningThresholdService;
+
+    @Autowired
+    private IEnvWarningInfoService envWarningInfoService;
+
+    @Autowired
+    private IEnvNh3nService nh3nService;
+
+
+    @Scheduled(cron = "0 0/59 * * * ?")  //每10分钟执行一次
+//    @Scheduled(cron = "0 * * * * ?")  //每10分钟执行一次
+//    @Scheduled(cron = "*/5 * * * * ?")  //每10秒钟执行一次
+    public void getDeviceFlowData() throws ParseException {
+        String userId = "-1618620464";
+        String farmCode = "26";
+
+        List<EnvDevice> farm_id = envDeviceService.list(new QueryWrapper<EnvDevice>().eq("farm_id", farmCode));
+        EnvWarningThreshold envWarningThreshold = envWarningThresholdService.getOne(new QueryWrapper<EnvWarningThreshold>().eq("farm_id", farmCode));
+        System.out.println("开始");
+        Date date = new Date();
+        for (EnvDevice envDevice : farm_id) {
+            String deviceCode = envDevice.getDeviceCode();
+            if (StringUtils.isNotBlank(deviceCode)) {
+                JSONObject resultJo = JSONObject.parseObject(getDeviceFlowFromRemoteURL(userId, deviceCode));
+                System.out.println("resultJo >>>>>>>>>>>> =" + resultJo);
+                if (resultJo.getInteger("code") != 1000) {
+                    System.out.println("牧场[" + farmCode + "]设备组编号(" + deviceCode + ")调用远程接口返回结果出错.");
+                } else {
+                    JSONArray dataJa = resultJo.getJSONArray("data");
+                    JSONObject dataJo = dataJa.getJSONObject(0);
+                    JSONArray realTimeDataJa = dataJo.getJSONArray("realTimeData");
+                    JSONObject tempJo = realTimeDataJa.getJSONObject(0);
+                    String temp = tempJo.getString("dataValue");
+                    JSONObject humiJo = realTimeDataJa.getJSONObject(1);
+                    String humi = humiJo.getString("dataValue");
+                    if (StringUtils.isBlank(humi)) {
+                        humi = "0";
+                    }
+                    if (StringUtils.isBlank(temp)) {
+                        temp = "0";
+                    }
+                    EnvData envData = new EnvData();
+                    envData.setUnitId(envDevice.getUnitId());
+                    envData.setEnvTemp(temp);
+                    envData.setEnvHum(humi);
+                    envData.setFarmId(envDevice.getFarmId());
+                    envData.setCreateTime(date);
+                    envData.setDeviceId(envDevice.getDeviceCode());
+                    saveTemWarning(temp, envWarningThreshold, envDevice);
+                    saveHumWarning(humi, envWarningThreshold, envDevice);
+                    envDataService.save(envData);
+                    String remark = envDevice.getRemark();
+                    if (StringUtils.isNotBlank(remark)) {
+                        QueryWrapper<EnvNh3n> queryWrapper = new QueryWrapper<>();
+                        queryWrapper.eq("farm_id", farmCode).eq("device_code", remark);
+                        Calendar calendar = Calendar.getInstance();
+                        calendar.setTime(new Date());
+                        calendar.add(Calendar.MINUTE, -40);//
+                        queryWrapper.between("create_date", calendar.getTime(), new Date());
+                        List<EnvNh3n> list = nh3nService.list(queryWrapper);
+                        if (list.size() == 0 && humi.equals("0") && temp.equals("0")) {
+                            envDevice.setDeviceStatus(0);
+                        } else {
+                            envDevice.setDeviceStatus(1);
+                        }
+                        envDeviceService.updateById(envDevice);
+                    }
+                }
+            }
+        }
+
+    }
+
+
+    //获取远程数据
+    private String getDeviceFlowFromRemoteURL(String userId, String groupId) {
+        //请求头
+        HttpHeaders headers = new HttpHeaders();
+        headers.add("userId", userId);
+        //Body参数
+        MultiValueMap<String, Object> paramsMap = new LinkedMultiValueMap<String, Object>();
+        HttpEntity<MultiValueMap> objectHttpEntity = new HttpEntity<MultiValueMap>(paramsMap, headers);
+        System.out.println("URL_ENVIRON_DEVICE_SERVICE=" + "http://www.0531yun.com/app/GetDeviceData");
+        ResponseEntity<String> result = restTemplate.exchange("http://www.0531yun.com/app/GetDeviceData?groupId=" + groupId, HttpMethod.GET, objectHttpEntity, String.class);
+        System.out.println("result.getBody()=" + result.getBody());
+        return result.getBody();
+    }
+
+    private void saveTemWarning(String val, EnvWarningThreshold envWarningThreshold, EnvDevice envDevice) {
+        if (com.baomidou.mybatisplus.core.toolkit.StringUtils.isNotBlank(val)) {
+            String maxTem;
+            String minTem;
+            if (ObjectUtil.isEmpty(envWarningThreshold) || com.baomidou.mybatisplus.core.toolkit.StringUtils.isBlank(envWarningThreshold.getMaxTem())) {
+                maxTem = "40";
+            } else {
+                maxTem = envWarningThreshold.getMaxTem();
+            }
+            if (ObjectUtil.isEmpty(envWarningThreshold) || com.baomidou.mybatisplus.core.toolkit.StringUtils.isBlank(envWarningThreshold.getMinTem())) {
+                minTem = "0";
+            } else {
+                minTem = envWarningThreshold.getMinTem();
+            }
+            System.out.println("maxTem:" + Double.parseDouble(maxTem) + "  minTem:" + Double.parseDouble(minTem) + "   val:" + Double.parseDouble(val));
+            if (Double.parseDouble(maxTem) < Double.parseDouble(val)) {
+                EnvWarningInfo envWarningInfo = new EnvWarningInfo();
+                envWarningInfo.setBuildLocation(envDevice.getUnitName());
+                envWarningInfo.setDate(new Date());
+                envWarningInfo.setDeviceId(envDevice.getDeviceCode());
+                envWarningInfo.setFarmId(envDevice.getFarmId());
+                envWarningInfo.setUnitId(envDevice.getUnitId());
+                envWarningInfo.setUnitName(envDevice.getUnitName());
+                envWarningInfo.setUserIds(envWarningThreshold.getUserIds());
+                envWarningInfo.setWarningContent("当前温度为" + val + "°超过阈值,请及时检查");
+                envWarningInfo.setWarningType(1);
+                envWarningInfoService.save(envWarningInfo);
+            }
+            if (Double.parseDouble(minTem) > Double.parseDouble(val)) {
+                EnvWarningInfo envWarningInfo = new EnvWarningInfo();
+                envWarningInfo.setBuildLocation(envDevice.getUnitName());
+                envWarningInfo.setDate(new Date());
+                envWarningInfo.setDeviceId(envDevice.getDeviceCode());
+                envWarningInfo.setFarmId(envDevice.getFarmId());
+                envWarningInfo.setUnitId(envDevice.getUnitId());
+                envWarningInfo.setUnitName(envDevice.getUnitName());
+                envWarningInfo.setUserIds(envWarningThreshold.getUserIds());
+                envWarningInfo.setWarningContent("当前温度为" + val + "°低于阈值,请及时检查");
+                envWarningInfo.setWarningType(1);
+                envWarningInfoService.save(envWarningInfo);
+            }
+        }
+    }
+
+    public void saveHumWarning(String val, EnvWarningThreshold envWarningThreshold, EnvDevice envDevice) {
+        if (com.baomidou.mybatisplus.core.toolkit.StringUtils.isNotBlank(val)) {
+            String maxHum;
+            String minHum;
+            if (ObjectUtil.isEmpty(envWarningThreshold) || com.baomidou.mybatisplus.core.toolkit.StringUtils.isBlank(envWarningThreshold.getMaxHum())) {
+                maxHum = "90";
+            } else {
+                maxHum = envWarningThreshold.getMaxHum();
+            }
+            if (ObjectUtil.isEmpty(envWarningThreshold) || com.baomidou.mybatisplus.core.toolkit.StringUtils.isBlank(envWarningThreshold.getMinHum())) {
+                minHum = "0";
+            } else {
+                minHum = envWarningThreshold.getMinHum();
+            }
+            if (Double.parseDouble(maxHum) < Double.parseDouble(val)) {
+                EnvWarningInfo envWarningInfo = new EnvWarningInfo();
+                envWarningInfo.setBuildLocation(envDevice.getUnitName());
+                envWarningInfo.setDate(new Date());
+                envWarningInfo.setDeviceId(envDevice.getDeviceCode());
+                envWarningInfo.setFarmId(envDevice.getFarmId());
+                envWarningInfo.setUnitId(envDevice.getUnitId());
+                envWarningInfo.setUnitName(envDevice.getUnitName());
+                envWarningInfo.setUserIds(envWarningThreshold.getUserIds());
+                envWarningInfo.setWarningContent("当前湿度为" + val + "%超过阈值,请及时检查");
+                envWarningInfo.setWarningType(2);
+                envWarningInfoService.save(envWarningInfo);
+            }
+            if (Double.parseDouble(minHum) > Double.parseDouble(val)) {
+                EnvWarningInfo envWarningInfo = new EnvWarningInfo();
+                envWarningInfo.setBuildLocation(envDevice.getUnitName());
+                envWarningInfo.setDate(new Date());
+                envWarningInfo.setDeviceId(envDevice.getDeviceCode());
+                envWarningInfo.setFarmId(envDevice.getFarmId());
+                envWarningInfo.setUnitId(envDevice.getUnitId());
+                envWarningInfo.setUnitName(envDevice.getUnitName());
+                envWarningInfo.setUserIds(envWarningThreshold.getUserIds());
+                envWarningInfo.setWarningContent("当前湿度为" + val + "%低于阈值,请及时检查");
+                envWarningInfo.setWarningType(2);
+                envWarningInfoService.save(envWarningInfo);
+            }
+        }
+    }
+}

+ 184 - 184
huimv-admin/src/main/java/com/huimv/admin/timer/ProdWarningTimer.java

@@ -1,184 +1,184 @@
-//package com.huimv.admin.timer;
-//
-//import cn.hutool.core.util.ObjectUtil;
-//import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
-//import com.huimv.admin.entity.*;
-//import com.huimv.admin.mapper.*;
-//import com.huimv.admin.service.IDisplayTypeService;
-//import org.springframework.beans.factory.annotation.Autowired;
-//import org.springframework.context.annotation.Configuration;
-//import org.springframework.scheduling.annotation.EnableScheduling;
-//import org.springframework.scheduling.annotation.Scheduled;
-//
-//import java.time.LocalDateTime;
-//import java.util.List;
-//
-//@Configuration
-//@EnableScheduling
-//public class ProdWarningTimer {
-//    @Autowired
-//    private BaseFarmMapper baseFarmMapper;
-//    @Autowired
-//    private ProdWarningInfoMapper prodWarningInfoMapper;
-//    @Autowired
-//    private ProdProductionMapper prodProductionMapper;
-//    @Autowired
-//    private ProdProductionThresholdMapper prodProductionThresholdMapper;
-//    @Autowired
-//    private ProdStockMapper prodStockMapper;
-//    @Autowired
-//    private ProdStockThresholdMapper prodStockThresholdMapper;
-//    @Autowired
-//    private IDisplayTypeService displayTypeService;
-//
-////    @Scheduled(cron = "*/5 * * * * ?")
-//    @Scheduled(cron = "0 0 0 * * ?")
-//    private void action(){
-//        Integer type1 = 0;
-//        List<BaseFarm> baseFarms = baseFarmMapper.selectList(new QueryWrapper<BaseFarm>().lambda().ne(BaseFarm::getId, 25));
-//        for (BaseFarm baseFarm : baseFarms) {
-//            Integer farmId = baseFarm.getId();
-//            DisplayType displayType1 = displayTypeService.getOne(new QueryWrapper<DisplayType>().lambda().eq(DisplayType::getFarmId, farmId).eq(DisplayType::getEventType, 3));
-//            if (ObjectUtil.isNotEmpty(displayType1)){
-//                type1 = displayType1.getDisplayType();
-//            }
-//            ProdStock prodStock = prodStockMapper.selectOne(new QueryWrapper<ProdStock>().lambda()
-//                    .eq(ProdStock::getDisplayType, type1)
-//                    .eq(ProdStock::getFarmId, farmId)
-//                    .orderByDesc(ProdStock::getCreatTime).last("LIMIT 1"));
-//            if (ObjectUtil.isNotEmpty(prodStock)){
-//                ProdStockThreshold threshold = prodStockThresholdMapper.selectOne(new QueryWrapper<ProdStockThreshold>().lambda().eq(ProdStockThreshold::getFarmId, farmId));
-//                if (ObjectUtil.isNotEmpty(threshold)){
-//                    Integer minBrzcl = threshold.getMinBrzcl();
-//                    Integer minByzcl = threshold.getMinByzcl();
-//                    Integer minGzcl = threshold.getMinGzcl();
-//                    Integer minHbzcl = threshold.getMinHbzcl();
-//                    Integer minMzcl = threshold.getMinMzcl();
-//                    Integer minYfzcl = threshold.getMinYfzcl();
-//                    if (ObjectUtil.isNotEmpty(minBrzcl)){
-//                        if (ObjectUtil.isNotEmpty(prodStock.getBrzcl())){
-//                            if (prodStock.getBrzcl().compareTo(minBrzcl) < 0){
-//                                ProdWarningInfo prodWarningInfo = new ProdWarningInfo();
-//                                prodWarningInfo.setDate(LocalDateTime.now());
-//                                prodWarningInfo.setFarmId(farmId);
-//                                prodWarningInfo.setWarningContent("哺乳猪存栏小于阈值!");
-//                                prodWarningInfo.setWarningType(0);
-//                                prodWarningInfoMapper.insert(prodWarningInfo);
-//                            }
-//                        }
-//                    }
-//                    if (ObjectUtil.isNotEmpty(minByzcl)){
-//                        if (ObjectUtil.isNotEmpty(prodStock.getByzcl())){
-//                            if (prodStock.getByzcl().compareTo(minByzcl) < 0){
-//                                ProdWarningInfo prodWarningInfo = new ProdWarningInfo();
-//                                prodWarningInfo.setDate(LocalDateTime.now());
-//                                prodWarningInfo.setFarmId(farmId);
-//                                prodWarningInfo.setWarningContent("保育猪存栏小于阈值!");
-//                                prodWarningInfo.setWarningType(0);
-//                                prodWarningInfoMapper.insert(prodWarningInfo);
-//                            }
-//                        }
-//                    }
-//                    if (ObjectUtil.isNotEmpty(minGzcl)){
-//                        if (ObjectUtil.isNotEmpty(prodStock.getGzcl())){
-//                            if (prodStock.getGzcl().compareTo(minGzcl) < 0){
-//                                ProdWarningInfo prodWarningInfo = new ProdWarningInfo();
-//                                prodWarningInfo.setDate(LocalDateTime.now());
-//                                prodWarningInfo.setFarmId(farmId);
-//                                prodWarningInfo.setWarningContent("公猪存栏小于阈值!");
-//                                prodWarningInfo.setWarningType(0);
-//                                prodWarningInfoMapper.insert(prodWarningInfo);
-//                            }
-//                        }
-//                    }
-//                    if (ObjectUtil.isNotEmpty(minHbzcl)){
-//                        if (ObjectUtil.isNotEmpty(prodStock.getHbzcl())){
-//                            if (prodStock.getHbzcl().compareTo(minHbzcl) < 0){
-//                                ProdWarningInfo prodWarningInfo = new ProdWarningInfo();
-//                                prodWarningInfo.setDate(LocalDateTime.now());
-//                                prodWarningInfo.setFarmId(farmId);
-//                                prodWarningInfo.setWarningContent("后备猪存栏小于阈值!");
-//                                prodWarningInfo.setWarningType(0);
-//                                prodWarningInfoMapper.insert(prodWarningInfo);
-//                            }
-//                        }
-//                    }
-//                    if (ObjectUtil.isNotEmpty(minMzcl)){
-//                        if (ObjectUtil.isNotEmpty(prodStock.getMzcl())){
-//                            if (prodStock.getMzcl().compareTo(minMzcl) < 0){
-//                                ProdWarningInfo prodWarningInfo = new ProdWarningInfo();
-//                                prodWarningInfo.setDate(LocalDateTime.now());
-//                                prodWarningInfo.setFarmId(farmId);
-//                                prodWarningInfo.setWarningContent("母猪存栏小于阈值!");
-//                                prodWarningInfo.setWarningType(0);
-//                                prodWarningInfoMapper.insert(prodWarningInfo);
-//                            }
-//                        }
-//                    }
-//                    if (ObjectUtil.isNotEmpty(minYfzcl)){
-//                        if (ObjectUtil.isNotEmpty(prodStock.getYfzcl())){
-//                            if (prodStock.getYfzcl().compareTo(minYfzcl) < 0){
-//                                ProdWarningInfo prodWarningInfo = new ProdWarningInfo();
-//                                prodWarningInfo.setDate(LocalDateTime.now());
-//                                prodWarningInfo.setFarmId(farmId);
-//                                prodWarningInfo.setWarningContent("育肥猪存栏小于阈值!");
-//                                prodWarningInfo.setWarningType(0);
-//                                prodWarningInfoMapper.insert(prodWarningInfo);
-//                            }
-//                        }
-//                    }
-//                }
-//            }
-//            ProdProduction prodProduction = prodProductionMapper.selectOne(new QueryWrapper<ProdProduction>().lambda()
-//                    .eq(ProdProduction::getFarmId, farmId).orderByDesc(ProdProduction::getCreatTime).last("LIMIT 1"));
-//            if (ObjectUtil.isNotEmpty(prodProduction)){
-//                ProdProductionThreshold prodProductionThreshold = prodProductionThresholdMapper.selectOne(new QueryWrapper<ProdProductionThreshold>().lambda().eq(ProdProductionThreshold::getFarmId,farmId));
-//                if (ObjectUtil.isNotEmpty(prodProductionThreshold)){
-//                    checkAndWarn(prodProductionThreshold.getMinBychl(), prodProduction.getBychl(),farmId, 1, "保育成活率小于阈值!");
-//                    checkAndWarn(prodProductionThreshold.getMinCfchl(), prodProduction.getCfchl(),farmId, 1, "产房成活率小于阈值!");
-//                    checkAndWarn2(prodProductionThreshold.getMinFccts(), prodProduction.getFccts(),farmId, 1, "非生产天数大于阈值!");
-//                    checkAndWarn(prodProductionThreshold.getMinFzchl(), prodProduction.getFzchl(),farmId, 1, "肥猪成活率小于阈值!");
-//                    checkAndWarn(prodProductionThreshold.getMinMrwll(), prodProduction.getMrwll(),farmId, 1, "每日喂料量小于阈值!");
-//                    checkAndWarn(prodProductionThreshold.getMinPjwchzs(), prodProduction.getPjwchzs(),farmId, 1, "平均窝产活仔数小于阈值!");
-//                    checkAndWarn(prodProductionThreshold.getMinPjwczczs(), prodProduction.getPjwczczs(),farmId, 1, "平均窝产正常仔数小于阈值!");
-//                    checkAndWarn(prodProductionThreshold.getMinPjwdnz(), prodProduction.getPjwdnz(),farmId, 1, "平均窝断奶窝重小于阈值!");
-//                    checkAndWarn(prodProductionThreshold.getMinPsy(), prodProduction.getPsy(),farmId, 1, "PSY小于阈值!");
-//                    checkAndWarn(prodProductionThreshold.getMinPzfml(), prodProduction.getPzfml(),farmId, 1, "配种分娩率小于阈值!");
-//                    checkAndWarn(prodProductionThreshold.getMinQrdpl(), prodProduction.getQrdpl(),farmId, 1, "7日断配率小于阈值!");
-//                    checkAndWarn(prodProductionThreshold.getMinRzz(), prodProduction.getRzz(),farmId, 1, "日增重小于阈值!");
-//                    checkAndWarn(prodProductionThreshold.getMinScws(), prodProduction.getScws(),farmId, 1, "年产窝数小于阈值!");
-//                    checkAndWarn(prodProductionThreshold.getMinWdnzzs(), prodProduction.getWdnzzs(),farmId, 1, "窝断奶仔猪数小于阈值!");
-//                    checkAndWarn(prodProductionThreshold.getMinYfchl(), prodProduction.getYfchl(),farmId, 1, "育肥成活率小于阈值!");
-//                    checkAndWarn(prodProductionThreshold.getMinPjwczs(), prodProduction.getPjwczs(),farmId, 1, "平均窝产仔数小于阈值!");
-//                }
-//            }
-//        }
-//    }
-//
-//    private void checkAndWarn(String threshold, String actualValue,Integer farmId, int warningType, String warningContent) {
-//        if (ObjectUtil.isNotEmpty(threshold) && ObjectUtil.isNotEmpty(actualValue)) {
-//            if (Double.valueOf(actualValue).compareTo(Double.valueOf(threshold)) < 0) {
-//                ProdWarningInfo prodWarningInfo = new ProdWarningInfo();
-//                prodWarningInfo.setDate(LocalDateTime.now());
-//                prodWarningInfo.setFarmId(farmId);
-//                prodWarningInfo.setWarningContent(warningContent);
-//                prodWarningInfo.setWarningType(warningType);
-//                prodWarningInfoMapper.insert(prodWarningInfo);
-//            }
-//        }
-//    }
-//
-//    private void checkAndWarn2(String threshold, String actualValue,Integer farmId, int warningType, String warningContent) {
-//        if (ObjectUtil.isNotEmpty(threshold) && ObjectUtil.isNotEmpty(actualValue)) {
-//            if (Double.valueOf(actualValue).compareTo(Double.valueOf(threshold)) > 0) {
-//                ProdWarningInfo prodWarningInfo = new ProdWarningInfo();
-//                prodWarningInfo.setDate(LocalDateTime.now());
-//                prodWarningInfo.setFarmId(farmId);
-//                prodWarningInfo.setWarningContent(warningContent);
-//                prodWarningInfo.setWarningType(warningType);
-//                prodWarningInfoMapper.insert(prodWarningInfo);
-//            }
-//        }
-//    }
-//
-//}
+package com.huimv.admin.timer;
+
+import cn.hutool.core.util.ObjectUtil;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.huimv.admin.entity.*;
+import com.huimv.admin.mapper.*;
+import com.huimv.admin.service.IDisplayTypeService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.scheduling.annotation.EnableScheduling;
+import org.springframework.scheduling.annotation.Scheduled;
+
+import java.time.LocalDateTime;
+import java.util.List;
+
+@Configuration
+@EnableScheduling
+public class ProdWarningTimer {
+    @Autowired
+    private BaseFarmMapper baseFarmMapper;
+    @Autowired
+    private ProdWarningInfoMapper prodWarningInfoMapper;
+    @Autowired
+    private ProdProductionMapper prodProductionMapper;
+    @Autowired
+    private ProdProductionThresholdMapper prodProductionThresholdMapper;
+    @Autowired
+    private ProdStockMapper prodStockMapper;
+    @Autowired
+    private ProdStockThresholdMapper prodStockThresholdMapper;
+    @Autowired
+    private IDisplayTypeService displayTypeService;
+
+//    @Scheduled(cron = "*/5 * * * * ?")
+    @Scheduled(cron = "0 0 0 * * ?")
+    private void action(){
+        Integer type1 = 0;
+        List<BaseFarm> baseFarms = baseFarmMapper.selectList(new QueryWrapper<BaseFarm>().lambda().ne(BaseFarm::getId, 25));
+        for (BaseFarm baseFarm : baseFarms) {
+            Integer farmId = baseFarm.getId();
+            DisplayType displayType1 = displayTypeService.getOne(new QueryWrapper<DisplayType>().lambda().eq(DisplayType::getFarmId, farmId).eq(DisplayType::getEventType, 3));
+            if (ObjectUtil.isNotEmpty(displayType1)){
+                type1 = displayType1.getDisplayType();
+            }
+            ProdStock prodStock = prodStockMapper.selectOne(new QueryWrapper<ProdStock>().lambda()
+                    .eq(ProdStock::getDisplayType, type1)
+                    .eq(ProdStock::getFarmId, farmId)
+                    .orderByDesc(ProdStock::getCreatTime).last("LIMIT 1"));
+            if (ObjectUtil.isNotEmpty(prodStock)){
+                ProdStockThreshold threshold = prodStockThresholdMapper.selectOne(new QueryWrapper<ProdStockThreshold>().lambda().eq(ProdStockThreshold::getFarmId, farmId));
+                if (ObjectUtil.isNotEmpty(threshold)){
+                    Integer minBrzcl = threshold.getMinBrzcl();
+                    Integer minByzcl = threshold.getMinByzcl();
+                    Integer minGzcl = threshold.getMinGzcl();
+                    Integer minHbzcl = threshold.getMinHbzcl();
+                    Integer minMzcl = threshold.getMinMzcl();
+                    Integer minYfzcl = threshold.getMinYfzcl();
+                    if (ObjectUtil.isNotEmpty(minBrzcl)){
+                        if (ObjectUtil.isNotEmpty(prodStock.getBrzcl())){
+                            if (prodStock.getBrzcl().compareTo(minBrzcl) < 0){
+                                ProdWarningInfo prodWarningInfo = new ProdWarningInfo();
+                                prodWarningInfo.setDate(LocalDateTime.now());
+                                prodWarningInfo.setFarmId(farmId);
+                                prodWarningInfo.setWarningContent("哺乳猪存栏小于阈值!");
+                                prodWarningInfo.setWarningType(0);
+                                prodWarningInfoMapper.insert(prodWarningInfo);
+                            }
+                        }
+                    }
+                    if (ObjectUtil.isNotEmpty(minByzcl)){
+                        if (ObjectUtil.isNotEmpty(prodStock.getByzcl())){
+                            if (prodStock.getByzcl().compareTo(minByzcl) < 0){
+                                ProdWarningInfo prodWarningInfo = new ProdWarningInfo();
+                                prodWarningInfo.setDate(LocalDateTime.now());
+                                prodWarningInfo.setFarmId(farmId);
+                                prodWarningInfo.setWarningContent("保育猪存栏小于阈值!");
+                                prodWarningInfo.setWarningType(0);
+                                prodWarningInfoMapper.insert(prodWarningInfo);
+                            }
+                        }
+                    }
+                    if (ObjectUtil.isNotEmpty(minGzcl)){
+                        if (ObjectUtil.isNotEmpty(prodStock.getGzcl())){
+                            if (prodStock.getGzcl().compareTo(minGzcl) < 0){
+                                ProdWarningInfo prodWarningInfo = new ProdWarningInfo();
+                                prodWarningInfo.setDate(LocalDateTime.now());
+                                prodWarningInfo.setFarmId(farmId);
+                                prodWarningInfo.setWarningContent("公猪存栏小于阈值!");
+                                prodWarningInfo.setWarningType(0);
+                                prodWarningInfoMapper.insert(prodWarningInfo);
+                            }
+                        }
+                    }
+                    if (ObjectUtil.isNotEmpty(minHbzcl)){
+                        if (ObjectUtil.isNotEmpty(prodStock.getHbzcl())){
+                            if (prodStock.getHbzcl().compareTo(minHbzcl) < 0){
+                                ProdWarningInfo prodWarningInfo = new ProdWarningInfo();
+                                prodWarningInfo.setDate(LocalDateTime.now());
+                                prodWarningInfo.setFarmId(farmId);
+                                prodWarningInfo.setWarningContent("后备猪存栏小于阈值!");
+                                prodWarningInfo.setWarningType(0);
+                                prodWarningInfoMapper.insert(prodWarningInfo);
+                            }
+                        }
+                    }
+                    if (ObjectUtil.isNotEmpty(minMzcl)){
+                        if (ObjectUtil.isNotEmpty(prodStock.getMzcl())){
+                            if (prodStock.getMzcl().compareTo(minMzcl) < 0){
+                                ProdWarningInfo prodWarningInfo = new ProdWarningInfo();
+                                prodWarningInfo.setDate(LocalDateTime.now());
+                                prodWarningInfo.setFarmId(farmId);
+                                prodWarningInfo.setWarningContent("母猪存栏小于阈值!");
+                                prodWarningInfo.setWarningType(0);
+                                prodWarningInfoMapper.insert(prodWarningInfo);
+                            }
+                        }
+                    }
+                    if (ObjectUtil.isNotEmpty(minYfzcl)){
+                        if (ObjectUtil.isNotEmpty(prodStock.getYfzcl())){
+                            if (prodStock.getYfzcl().compareTo(minYfzcl) < 0){
+                                ProdWarningInfo prodWarningInfo = new ProdWarningInfo();
+                                prodWarningInfo.setDate(LocalDateTime.now());
+                                prodWarningInfo.setFarmId(farmId);
+                                prodWarningInfo.setWarningContent("育肥猪存栏小于阈值!");
+                                prodWarningInfo.setWarningType(0);
+                                prodWarningInfoMapper.insert(prodWarningInfo);
+                            }
+                        }
+                    }
+                }
+            }
+            ProdProduction prodProduction = prodProductionMapper.selectOne(new QueryWrapper<ProdProduction>().lambda()
+                    .eq(ProdProduction::getFarmId, farmId).orderByDesc(ProdProduction::getCreatTime).last("LIMIT 1"));
+            if (ObjectUtil.isNotEmpty(prodProduction)){
+                ProdProductionThreshold prodProductionThreshold = prodProductionThresholdMapper.selectOne(new QueryWrapper<ProdProductionThreshold>().lambda().eq(ProdProductionThreshold::getFarmId,farmId));
+                if (ObjectUtil.isNotEmpty(prodProductionThreshold)){
+                    checkAndWarn(prodProductionThreshold.getMinBychl(), prodProduction.getBychl(),farmId, 1, "保育成活率小于阈值!");
+                    checkAndWarn(prodProductionThreshold.getMinCfchl(), prodProduction.getCfchl(),farmId, 1, "产房成活率小于阈值!");
+                    checkAndWarn2(prodProductionThreshold.getMinFccts(), prodProduction.getFccts(),farmId, 1, "非生产天数大于阈值!");
+                    checkAndWarn(prodProductionThreshold.getMinFzchl(), prodProduction.getFzchl(),farmId, 1, "肥猪成活率小于阈值!");
+                    checkAndWarn(prodProductionThreshold.getMinMrwll(), prodProduction.getMrwll(),farmId, 1, "每日喂料量小于阈值!");
+                    checkAndWarn(prodProductionThreshold.getMinPjwchzs(), prodProduction.getPjwchzs(),farmId, 1, "平均窝产活仔数小于阈值!");
+                    checkAndWarn(prodProductionThreshold.getMinPjwczczs(), prodProduction.getPjwczczs(),farmId, 1, "平均窝产正常仔数小于阈值!");
+                    checkAndWarn(prodProductionThreshold.getMinPjwdnz(), prodProduction.getPjwdnz(),farmId, 1, "平均窝断奶窝重小于阈值!");
+                    checkAndWarn(prodProductionThreshold.getMinPsy(), prodProduction.getPsy(),farmId, 1, "PSY小于阈值!");
+                    checkAndWarn(prodProductionThreshold.getMinPzfml(), prodProduction.getPzfml(),farmId, 1, "配种分娩率小于阈值!");
+                    checkAndWarn(prodProductionThreshold.getMinQrdpl(), prodProduction.getQrdpl(),farmId, 1, "7日断配率小于阈值!");
+                    checkAndWarn(prodProductionThreshold.getMinRzz(), prodProduction.getRzz(),farmId, 1, "日增重小于阈值!");
+                    checkAndWarn(prodProductionThreshold.getMinScws(), prodProduction.getScws(),farmId, 1, "年产窝数小于阈值!");
+                    checkAndWarn(prodProductionThreshold.getMinWdnzzs(), prodProduction.getWdnzzs(),farmId, 1, "窝断奶仔猪数小于阈值!");
+                    checkAndWarn(prodProductionThreshold.getMinYfchl(), prodProduction.getYfchl(),farmId, 1, "育肥成活率小于阈值!");
+                    checkAndWarn(prodProductionThreshold.getMinPjwczs(), prodProduction.getPjwczs(),farmId, 1, "平均窝产仔数小于阈值!");
+                }
+            }
+        }
+    }
+
+    private void checkAndWarn(String threshold, String actualValue,Integer farmId, int warningType, String warningContent) {
+        if (ObjectUtil.isNotEmpty(threshold) && ObjectUtil.isNotEmpty(actualValue)) {
+            if (Double.valueOf(actualValue).compareTo(Double.valueOf(threshold)) < 0) {
+                ProdWarningInfo prodWarningInfo = new ProdWarningInfo();
+                prodWarningInfo.setDate(LocalDateTime.now());
+                prodWarningInfo.setFarmId(farmId);
+                prodWarningInfo.setWarningContent(warningContent);
+                prodWarningInfo.setWarningType(warningType);
+                prodWarningInfoMapper.insert(prodWarningInfo);
+            }
+        }
+    }
+
+    private void checkAndWarn2(String threshold, String actualValue,Integer farmId, int warningType, String warningContent) {
+        if (ObjectUtil.isNotEmpty(threshold) && ObjectUtil.isNotEmpty(actualValue)) {
+            if (Double.valueOf(actualValue).compareTo(Double.valueOf(threshold)) > 0) {
+                ProdWarningInfo prodWarningInfo = new ProdWarningInfo();
+                prodWarningInfo.setDate(LocalDateTime.now());
+                prodWarningInfo.setFarmId(farmId);
+                prodWarningInfo.setWarningContent(warningContent);
+                prodWarningInfo.setWarningType(warningType);
+                prodWarningInfoMapper.insert(prodWarningInfo);
+            }
+        }
+    }
+
+}

Dosya farkı çok büyük olduğundan ihmal edildi
+ 569 - 569
huimv-admin/src/main/java/com/huimv/admin/timer/ProtTimer.java


+ 54 - 54
huimv-admin/src/main/java/com/huimv/admin/timer/SafeTimer.java

@@ -1,54 +1,54 @@
-//package com.huimv.admin.timer;
-//
-//
-//import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
-//import com.huimv.admin.common.utils.NumberUtils;
-//import com.huimv.admin.entity.BillIsolate;
-//import com.huimv.admin.entity.GasData;
-//import com.huimv.admin.entity.GasThreshold;
-//import com.huimv.admin.entity.GasWarningInfo;
-//import com.huimv.admin.mapper.GasDataMapper;
-//import com.huimv.admin.mapper.GasThresholdMapper;
-//import com.huimv.admin.mapper.GasWarningInfoMapper;
-//import com.huimv.admin.service.IBillIsolateService;
-//import com.huimv.admin.service.IBillPcrService;
-//import org.springframework.beans.factory.annotation.Autowired;
-//import org.springframework.context.annotation.Configuration;
-//import org.springframework.scheduling.annotation.EnableScheduling;
-//import org.springframework.scheduling.annotation.Scheduled;
-//
-//import java.text.ParseException;
-//import java.text.SimpleDateFormat;
-//import java.util.Date;
-//import java.util.List;
-//
-//@Configuration
-//@EnableScheduling
-//public class SafeTimer {
-//
-//
-//    @Autowired
-//    private IBillPcrService pcrService;
-//    @Autowired
-//    private IBillIsolateService isolateService;
-//
-//
-//    @Scheduled(cron = "0 0/1 * * * ? ")
-//    private void getShenChan() throws Exception {
-//        QueryWrapper<BillIsolate> queryWrapper = new QueryWrapper<>();
-//        queryWrapper.eq("bill_status", 1);
-//        List<BillIsolate> isolates = isolateService.list(queryWrapper);
-//        Date date = new Date();
-//        for (BillIsolate isolate : isolates) {
-//            if (isolate.getIsolateEndDate().getTime() <= date.getTime()) {
-//                isolate.setIsolateRealEndDate(date);
-//                isolate.setIsolateRealDayNum(isolate.getIsolateDayNum());
-//                isolate.setBillStatus(2);
-//                isolate.setPassUserName("自然解除隔离");
-//                isolate.setPassDate(date);
-//                isolateService.updateById(isolate);
-//            }
-//        }
-//    }
-//
-//}
+package com.huimv.admin.timer;
+
+
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.huimv.admin.common.utils.NumberUtils;
+import com.huimv.admin.entity.BillIsolate;
+import com.huimv.admin.entity.GasData;
+import com.huimv.admin.entity.GasThreshold;
+import com.huimv.admin.entity.GasWarningInfo;
+import com.huimv.admin.mapper.GasDataMapper;
+import com.huimv.admin.mapper.GasThresholdMapper;
+import com.huimv.admin.mapper.GasWarningInfoMapper;
+import com.huimv.admin.service.IBillIsolateService;
+import com.huimv.admin.service.IBillPcrService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.scheduling.annotation.EnableScheduling;
+import org.springframework.scheduling.annotation.Scheduled;
+
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import java.util.List;
+
+@Configuration
+@EnableScheduling
+public class SafeTimer {
+
+
+    @Autowired
+    private IBillPcrService pcrService;
+    @Autowired
+    private IBillIsolateService isolateService;
+
+
+    @Scheduled(cron = "0 0/1 * * * ? ")
+    private void getShenChan() throws Exception {
+        QueryWrapper<BillIsolate> queryWrapper = new QueryWrapper<>();
+        queryWrapper.eq("bill_status", 1);
+        List<BillIsolate> isolates = isolateService.list(queryWrapper);
+        Date date = new Date();
+        for (BillIsolate isolate : isolates) {
+            if (isolate.getIsolateEndDate().getTime() <= date.getTime()) {
+                isolate.setIsolateRealEndDate(date);
+                isolate.setIsolateRealDayNum(isolate.getIsolateDayNum());
+                isolate.setBillStatus(2);
+                isolate.setPassUserName("自然解除隔离");
+                isolate.setPassDate(date);
+                isolateService.updateById(isolate);
+            }
+        }
+    }
+
+}

Dosya farkı çok büyük olduğundan ihmal edildi
+ 528 - 528
huimv-admin/src/main/java/com/huimv/admin/timer/ShenChanTimer.java


Dosya farkı çok büyük olduğundan ihmal edildi
+ 793 - 793
huimv-admin/src/main/java/com/huimv/admin/timer/WaterAndElcTimer.java


+ 2 - 2
huimv-admin/src/main/resources/application.properties

@@ -1,5 +1,5 @@
-spring.profiles.active=dev
-#spring.profiles.active=prod
+#spring.profiles.active=dev
+spring.profiles.active=prod
 
 #¿ªÆô½¡¿µ¼à¿Ø
 management.endpoints.web.exposure.include=*

+ 7 - 7
huimv-receive/src/main/java/com/huimv/receive/service/impl/BillCleanServiceImpl.java

@@ -658,7 +658,7 @@ public class BillCleanServiceImpl extends ServiceImpl<BillCleanMapper, BillClean
 
             QueryWrapper<BaseProcess> queryWrapper = new QueryWrapper<>();
             queryWrapper.eq("farm_id", farmId).eq("id", billClean.getProcessId());
-            BaseProcess baseProcess = processMapper.selectOne(queryWrapper);//某条进程
+//            BaseProcess baseProcess = processMapper.selectOne(queryWrapper);//某条进程
 
             billClean.setBillStatus(0);
             billClean.setImgStatus(1);
@@ -668,7 +668,7 @@ public class BillCleanServiceImpl extends ServiceImpl<BillCleanMapper, BillClean
             billClean.setTestLocationId(baseLocation.getId());
             billClean.setCheckDate(sdf.parse(data));
             billClean.setPassDate(sdf.parse(sdf.format(new Date())));
-            billClean.setCleanTime("10");
+            billClean.setCleanTime("20");
             String s1 = "";
             String s2 = "";
             String s3 = "";
@@ -727,7 +727,7 @@ public class BillCleanServiceImpl extends ServiceImpl<BillCleanMapper, BillClean
 
             QueryWrapper<BaseProcess> queryWrapper = new QueryWrapper<>();
             queryWrapper.eq("farm_id", farmId).eq("id", billClean.getProcessId());
-            BaseProcess baseProcess = processMapper.selectOne(queryWrapper);//某条进程
+//            BaseProcess baseProcess = processMapper.selectOne(queryWrapper);//某条进程
 
             billClean.setBillStatus(0);
             billClean.setImgStatus(1);
@@ -738,7 +738,7 @@ public class BillCleanServiceImpl extends ServiceImpl<BillCleanMapper, BillClean
             billClean.setCheckDate(sdf.parse(data));
             billClean.setPassDate(sdf.parse(sdf.format(new Date())));
             billClean.setDryTem("70");
-            billClean.setDryTime("10");
+            billClean.setDryTime("40");
             String s1 = "";
             String s2 = "";
             String s3 = "";
@@ -1161,7 +1161,7 @@ public class BillCleanServiceImpl extends ServiceImpl<BillCleanMapper, BillClean
                 billClean.setTestLocationId(baseLocation.getId());
                 billClean.setCheckDate(sdf.parse(date));
                 billClean.setPassDate(sdf.parse(sdf.format(new Date())));
-                billClean.setCleanTime("10");
+                billClean.setCleanTime("20");
 
                 baseProcess.setProcessType(2);
                 baseProcess.setUpdateDate(baseProcess.getUpdateDate() + "," + sdf.format(new Date()));
@@ -1219,7 +1219,7 @@ public class BillCleanServiceImpl extends ServiceImpl<BillCleanMapper, BillClean
                     billClean.setPassUserId(TokenSign.getMemberIdByJwtToken(httpServletRequest));
                     billClean.setTestLocation(baseLocation.getLocationName());
                     billClean.setTestLocationId(baseLocation.getId());
-                    billClean.setDryTime("10");
+                    billClean.setDryTime("40");
                     billClean.setDryTem("70");
                     dryMapper.updateById(billClean);
 
@@ -1480,7 +1480,7 @@ public class BillCleanServiceImpl extends ServiceImpl<BillCleanMapper, BillClean
                     billClean.setTestLocationId(baseLocation.getId());
                     billClean.setCheckDate(sdf.parse(date));
                     billClean.setPassDate(sdf.parse(sdf.format(new Date())));
-                    billClean.setDryTime("10");
+                    billClean.setDryTime("40");
                     billClean.setDryTem("70");
                     dryMapper.updateById(billClean);