소스 검색

更新耳标注册

zhuoning 2 년 전
부모
커밋
115c6ffbe9
33개의 변경된 파일0개의 추가작업 그리고 3576개의 파일을 삭제
  1. 0 65
      huimv-eartag2-platform/huimv-eartag2-process/pom.xml
  2. 0 27
      huimv-eartag2-platform/huimv-eartag2-process/src/main/java/com/huimv/eartag2/process/HuimvProcessApplication.java
  3. 0 68
      huimv-eartag2-platform/huimv-eartag2-process/src/main/java/com/huimv/eartag2/process/config/TopicRabbitMQConfig.java
  4. 0 191
      huimv-eartag2-platform/huimv-eartag2-process/src/main/java/com/huimv/eartag2/process/listener/FlowListener.java
  5. 0 51
      huimv-eartag2-platform/huimv-eartag2-process/src/main/java/com/huimv/eartag2/process/producer/ProcessProducer.java
  6. 0 14
      huimv-eartag2-platform/huimv-eartag2-process/src/main/java/com/huimv/eartag2/process/service/IDeviceService.java
  7. 0 10
      huimv-eartag2-platform/huimv-eartag2-process/src/main/java/com/huimv/eartag2/process/service/IEartagService.java
  8. 0 136
      huimv-eartag2-platform/huimv-eartag2-process/src/main/java/com/huimv/eartag2/process/service/impl/DeviceServiceImpl.java
  9. 0 139
      huimv-eartag2-platform/huimv-eartag2-process/src/main/java/com/huimv/eartag2/process/service/impl/EartagServiceImpl.java
  10. 0 21
      huimv-eartag2-platform/huimv-eartag2-process/src/main/java/com/huimv/eartag2/process/task/TestTask.java
  11. 0 12
      huimv-eartag2-platform/huimv-eartag2-process/src/main/java/com/huimv/eartag2/process/utils/BaseTemplete.java
  12. 0 187
      huimv-eartag2-platform/huimv-eartag2-process/src/main/java/com/huimv/eartag2/process/utils/DateUtil.java
  13. 0 90
      huimv-eartag2-platform/huimv-eartag2-process/src/main/java/com/huimv/eartag2/process/utils/MathUtil.java
  14. 0 107
      huimv-eartag2-platform/huimv-eartag2-process/src/main/resources/application-dev.yml
  15. 0 1
      huimv-eartag2-platform/huimv-eartag2-process/src/main/resources/application.properties
  16. 0 88
      huimv-eartag2-platform/huimv-eartag2-process2/pom.xml
  17. 0 25
      huimv-eartag2-platform/huimv-eartag2-process2/src/main/java/com/huimv/eartag2/process2/HuimvProcess2Application.java
  18. 0 63
      huimv-eartag2-platform/huimv-eartag2-process2/src/main/java/com/huimv/eartag2/process2/config/TopicRabbitMQConfig.java
  19. 0 103
      huimv-eartag2-platform/huimv-eartag2-process2/src/main/java/com/huimv/eartag2/process2/controller/RedisContrller.java
  20. 0 214
      huimv-eartag2-platform/huimv-eartag2-process2/src/main/java/com/huimv/eartag2/process2/listener/DeviceListener.java
  21. 0 124
      huimv-eartag2-platform/huimv-eartag2-process2/src/main/java/com/huimv/eartag2/process2/listener/EartagListener.java
  22. 0 33
      huimv-eartag2-platform/huimv-eartag2-process2/src/main/java/com/huimv/eartag2/process2/producer/ProcessProducer.java
  23. 0 62
      huimv-eartag2-platform/huimv-eartag2-process2/src/main/java/com/huimv/eartag2/process2/service/ICacheService.java
  24. 0 41
      huimv-eartag2-platform/huimv-eartag2-process2/src/main/java/com/huimv/eartag2/process2/service/IDeviceService.java
  25. 0 22
      huimv-eartag2-platform/huimv-eartag2-process2/src/main/java/com/huimv/eartag2/process2/service/IEartagService.java
  26. 0 377
      huimv-eartag2-platform/huimv-eartag2-process2/src/main/java/com/huimv/eartag2/process2/service/impl/CacheServiceImpl.java
  27. 0 768
      huimv-eartag2-platform/huimv-eartag2-process2/src/main/java/com/huimv/eartag2/process2/service/impl/DeviceServiceImpl.java
  28. 0 146
      huimv-eartag2-platform/huimv-eartag2-process2/src/main/java/com/huimv/eartag2/process2/service/impl/EartagServiceImpl.java
  29. 0 187
      huimv-eartag2-platform/huimv-eartag2-process2/src/main/java/com/huimv/eartag2/process2/utils/DateUtil.java
  30. 0 107
      huimv-eartag2-platform/huimv-eartag2-process2/src/main/resources/application-dev.yml
  31. 0 3
      huimv-eartag2-platform/huimv-eartag2-process2/src/main/resources/application.properties
  32. 0 68
      huimv-eartag2-platform/huimv-eartag2-process2/src/test/java/com/huimv/eartag2/process2/utils/RedisUtil.java
  33. 0 26
      huimv-eartag2-platform/huimv-eartag2-process2/src/test/java/com/huimv/eartag2/process2/utils/TypeTest.java

+ 0 - 65
huimv-eartag2-platform/huimv-eartag2-process/pom.xml

@@ -1,65 +0,0 @@
-<?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">
-    <parent>
-        <artifactId>huimv-eartag2-platform</artifactId>
-        <groupId>com.huimv</groupId>
-        <version>0.0.1-SNAPSHOT</version>
-    </parent>
-    <modelVersion>4.0.0</modelVersion>
-
-    <artifactId>huimv-eartag2-process</artifactId>
-
-    <dependencies>
-        <!-- eartag2-common -->
-        <dependency>
-            <groupId>com.huimv</groupId>
-            <artifactId>huimv-eartag2-common</artifactId>
-            <version>0.0.1-SNAPSHOT</version>
-        </dependency>
-        <!--rabbitmq-->
-        <dependency>
-            <groupId>org.springframework.boot</groupId>
-            <artifactId>spring-boot-starter-amqp</artifactId>
-        </dependency>
-        <!-- eartag2-common -->
-<!--        <dependency>-->
-<!--            <groupId>com.huimv</groupId>-->
-<!--            <artifactId>huimv-eartag2-common</artifactId>-->
-<!--            <version>0.0.1-SNAPSHOT</version>-->
-<!--        </dependency>-->
-        <dependency>
-            <groupId>org.springframework.boot</groupId>
-            <artifactId>spring-boot-starter-web</artifactId>
-        </dependency>
-    </dependencies>
-
-    <build>
-        <plugins>
-            <!--  -->
-            <plugin>
-                <groupId>org.springframework.boot</groupId>
-                <artifactId>spring-boot-maven-plugin</artifactId>
-            </plugin>
-            <!--  -->
-            <plugin>
-                <groupId>org.apache.maven.plugins</groupId>
-                <artifactId>maven-resources-plugin</artifactId>
-                <version>2.6</version>
-            </plugin>
-        </plugins>
-    </build>
-
-<!--    <build>-->
-<!--        <plugins>-->
-<!--            <plugin>-->
-<!--                <groupId>org.springframework.boot</groupId>-->
-<!--                <artifactId>spring-boot-maven-plugin</artifactId>-->
-<!--                <configuration>-->
-<!--                    <executable>true</executable>-->
-<!--                </configuration>-->
-<!--            </plugin>-->
-<!--        </plugins>-->
-<!--    </build>-->
-</project>

+ 0 - 27
huimv-eartag2-platform/huimv-eartag2-process/src/main/java/com/huimv/eartag2/process/HuimvProcessApplication.java

@@ -1,27 +0,0 @@
-package com.huimv.eartag2.process;
-
-import org.springframework.boot.SpringApplication;
-import org.springframework.boot.autoconfigure.SpringBootApplication;
-import org.springframework.boot.autoconfigure.domain.EntityScan;
-import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
-import org.springframework.scheduling.annotation.EnableScheduling;
-
-/**
- * @Project : huimv.shiwan
- * @Package : com.huimv.biosafety.uface.controller
- * @Description : TODO
- * @Version : 1.0
- * @Author : ZhuoNing
- * @Create : 2020-12-25
- **/
-
-//@ComponentScan(basePackages = {"com.huimv.eartag2.common.utils"})
-@EntityScan(value = "com.huimv.eartag2.common.dao.entity")
-@EnableJpaRepositories(basePackages = "com.huimv.eartag2.common.dao.repo")
-@SpringBootApplication
-@EnableScheduling
-public class HuimvProcessApplication {
-    public static void main(String[] args) {
-        SpringApplication.run(HuimvProcessApplication.class, args);
-    }
-}

+ 0 - 68
huimv-eartag2-platform/huimv-eartag2-process/src/main/java/com/huimv/eartag2/process/config/TopicRabbitMQConfig.java

@@ -1,68 +0,0 @@
-package com.huimv.eartag2.process.config;
-
-import com.huimv.eartag2.common.mq.Const;
-import org.springframework.amqp.core.Binding;
-import org.springframework.amqp.core.BindingBuilder;
-import org.springframework.amqp.core.Queue;
-import org.springframework.amqp.core.TopicExchange;
-import org.springframework.boot.autoconfigure.amqp.RabbitProperties;
-import org.springframework.context.annotation.Bean;
-import org.springframework.context.annotation.Configuration;
-import org.springframework.context.annotation.Import;
-import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
-
-/**
- * @Project : huimv.shiwan
- * @Package : com.huimv.biosafety.uface.controller
- * @Description : TODO
- * @Version : 1.0
- * @Author : ZhuoNing
- * @Create : 2020-12-25
- **/
-@Configuration
-public class TopicRabbitMQConfig {
-    //心跳
-    @Bean
-    public Queue heartbeatQueue() {
-        return new Queue(Const.QUEUE_DEVICE_HEARTBEAT);
-    }
-    //采集器温度
-    @Bean
-    public Queue deviceTempQueue() {
-        return new Queue(Const.QUEUE_DEVICE_TEMP);
-    }
-    //耳标数据
-    @Bean
-    public Queue eartagQueue() {
-        return new Queue(Const.QUEUE_EARTAG);
-    }
-
-    //采集器设备交换机
-//    @Bean
-    TopicExchange deviceExchange() {
-        return new TopicExchange(Const.EXCHANGE_DEVICE);
-    }
-
-    //耳标交换机
-//    @Bean
-    TopicExchange eartagExchange() {
-        return new TopicExchange(Const.EXCHANGE_EARTAG);
-    }
-
-    //设备交换机、心跳队列、心跳路由键绑定
-    @Bean
-    Binding bindingHeartbeatExchangeMessage() {
-        return BindingBuilder.bind(heartbeatQueue()).to(deviceExchange()).with(Const.ROUTING_KEY_DEVICE_HEARTBEAT);
-    }
-    //设备交换机、设备环境温度队列、设备环境路由键绑定
-    @Bean
-    Binding bindingDeviceTempExchangeMessage() {
-        return BindingBuilder.bind(deviceTempQueue()).to(deviceExchange()).with(Const.ROUTING_KEY_DEVICE_TEMP);
-    }
-    //耳标交换机、耳标队列、耳标路由键绑定
-    @Bean
-    Binding bindingEartagExchangeMessage() {
-        return BindingBuilder.bind(eartagQueue()).to(eartagExchange()).with(Const.ROUTING_KEY_EARTAG);
-    }
-
-}

+ 0 - 191
huimv-eartag2-platform/huimv-eartag2-process/src/main/java/com/huimv/eartag2/process/listener/FlowListener.java

@@ -1,191 +0,0 @@
-package com.huimv.eartag2.process.listener;
-
-import com.alibaba.fastjson.JSONObject;
-import com.huimv.eartag2.common.mq.Const;
-//import com.huimv.eartag2.common.utils.MathUtil;
-import com.huimv.eartag2.process.producer.ProcessProducer;
-import com.huimv.eartag2.process.service.IDeviceService;
-import com.huimv.eartag2.process.service.IEartagService;
-import com.huimv.eartag2.process.utils.DateUtil;
-import com.huimv.eartag2.process.utils.MathUtil;
-import lombok.extern.slf4j.Slf4j;
-import org.springframework.amqp.rabbit.annotation.RabbitHandler;
-import org.springframework.amqp.rabbit.annotation.RabbitListener;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.stereotype.Component;
-
-import javax.annotation.Resource;
-import java.math.BigDecimal;
-import java.text.ParseException;
-import java.util.HashMap;
-import java.util.Map;
-
-/**
- * @Project : huimv.shiwan
- * @Package : com.huimv.biosafety.uface.controller
- * @Description : TODO
- * @Version : 1.0
- * @Author : ZhuoNing
- * @Create : 2020-12-25
- **/
-@Component
-@Slf4j
-//@RabbitListener(queues = "topic.device")
-public class FlowListener {
-    @Autowired
-    private MathUtil mathUtil;
-    @Autowired
-    private DateUtil dateUtil;
-    @Autowired
-    private IDeviceService deviceService;
-    @Autowired
-    private IEartagService eartagService;
-    @Autowired
-    private ProcessProducer processProducer;
-
-//    @RabbitHandler
-//    public void process(Map deviceMap) {
-//        System.out.println("TopicDevice消费者收到消息  : " + deviceMap.toString());
-//    }
-
-//    @RabbitListener(queues = "topic.device.register")
-    @RabbitHandler
-    public void processDeviceStatus(Map registerMap) {
-        System.out.println("TopicDevice消费者收到消息  : " + registerMap);
-    }
-
-//    @RabbitListener(queues = Const.QUEUE_ASK)
-    @RabbitHandler
-    public void processRawdata(Map RawMap) throws ParseException {
-        System.out.println("<<<<<<<<<<<<<<< RawMap>>"+RawMap.toString());
-        String askText = RawMap.get("askText").toString();
-        System.out.println("askText>>"+askText);
-        //本模块主要执行保存以下4类数据:(其他注册数据,在线数据,状态数据等都是由其他模块工程执行处理-process2模块工程)
-        //--保存原始流水数据(原始流水表)
-        //--保存设备心跳流水数据(设备心跳流水表)
-        //--保存设备环境流水数据(设备温度流水表)
-        //--保存耳标流水数据(耳标流水表)
-
-        //处理请求报文//
-        Map askMap = handleAskText(askText);
-        String type = askMap.get("type").toString();
-        JSONObject dataJo = (JSONObject) askMap.get("data");
-        switch (type){
-            case "device-heartbeat":
-                //--(1)处理心跳数据
-                //--保存设备心跳流水数据(MySQL)
-
-                //保存心跳流水数据
-                deviceService.saveDeviceHeartbeat(dataJo);
-                //发送心跳数据到MQ
-                processProducer.sendHeartbeat(dataJo);
-                break;
-            case "device-temp":
-                //--(2)处理环境数据
-                //--保存设备环境流水数据(MySQL)
-
-                //保存设备环境温度流水数据
-                deviceService.saveDeviceTemp(dataJo);
-                //发送设备环境温度数据到MQ
-                processProducer.sendDeviceTemp(dataJo);
-                break;
-            case "eartag":
-                //--(3)处理耳标数据
-                //--保存耳标流水数据(MySQL)
-
-                //保存耳标流水数据
-                eartagService.saveEartag(dataJo);
-                //发送耳标数据到MQ
-                processProducer.sendEartag(dataJo);
-                break;
-            default:
-        }
-        //保存原始数据//
-        deviceService.saveRawdata(askText);
-    }
-
-    /**
-     * @Method      : handleAskText
-     * @Description : 处理请求
-     * @Params      : [askText]
-     * @Return      : java.util.Map
-     *
-     * @Author      : ZhuoNing
-     * @Date        : 2022/2/9
-     * @Time        : 13:38
-     */
-    private Map handleAskText(String askText) {
-        Map outMap = new HashMap();
-        JSONObject dataJo = new JSONObject();
-        String type = "";
-        String[] dataArray = askText.split("\\+");
-        String cmdHeader = dataArray[0];
-        if (cmdHeader.trim().equalsIgnoreCase("hm")) {
-            //采集器原始数据
-            String device = dataArray[1];
-            String cmd = dataArray[2];
-            if (cmd.trim().equalsIgnoreCase("0")) {
-                //不需要处理
-            } else if (cmd.trim().equalsIgnoreCase("1")) {
-                //获取设备编码
-            } else if (cmd.trim().equalsIgnoreCase("2")) {
-                //获取服务器时间命令
-            } else if (cmd.trim().equalsIgnoreCase("3")) {
-                //心跳包命令
-                dataJo.put("device", device);
-                type = "device-heartbeat";
-            } else if (cmd.trim().equalsIgnoreCase("4")) {
-                //环境温度-设备、数值、上传时间
-                dataJo.put("device", dataArray[1]);
-                dataJo.put("temp", dataArray[4]);
-                dataJo.put("askTime", dataArray[5]);
-                type = "device-temp";
-            } else {
-                log.error("##当前数据为非法数据>>" + askText);
-            }
-        } else if (cmdHeader.trim().equalsIgnoreCase("zj")) {
-//            String device = dataArray[1];
-            //-- 耳标数据 --//
-            //计算耳标温度
-            Double earTemp = 0D;
-            String other = dataArray[9];
-            if (other != null && other.trim().length() > 0) {
-                String[] otherArray = other.split("#");
-                String resi = otherArray[2];
-                int resiInt = Integer.parseInt(resi);
-                if(resiInt != 0){
-                    Double temp = MathUtil.ln(resiInt);
-                    earTemp = new BigDecimal(temp).setScale(1, BigDecimal.ROUND_HALF_UP).doubleValue();
-                }
-            }
-            //计算运动量//
-            Integer act1Int = eartagService.countAct(dataArray[1], dataArray[6]);
-            //命令头
-            dataJo.put("cmdHeader", dataArray[0]);
-            //采集器id
-            dataJo.put("device", dataArray[1]);
-            //耳标号
-            dataJo.put("earmark", dataArray[2]);
-            //电池电量
-            dataJo.put("bat", dataArray[3]);
-            //耳标温度
-            dataJo.put("earTemp", dataArray[4]);
-            dataJo.put("earTemp1", earTemp);
-            //环境温度
-            dataJo.put("envTemp", dataArray[5]);
-            //运动量
-            dataJo.put("act", dataArray[6]);
-            dataJo.put("act1", act1Int);
-            //信号强度
-            dataJo.put("signal", dataArray[7]);
-            //采集时间
-            dataJo.put("askTime", dataArray[8]);
-            //预留字段
-            dataJo.put("other", dataArray[9]);
-            type = "eartag";
-        }
-        outMap.put("type",type);
-        outMap.put("data",dataJo);
-        return outMap;
-    }
-}

+ 0 - 51
huimv-eartag2-platform/huimv-eartag2-process/src/main/java/com/huimv/eartag2/process/producer/ProcessProducer.java

@@ -1,51 +0,0 @@
-package com.huimv.eartag2.process.producer;
-
-import com.alibaba.fastjson.JSONObject;
-import com.huimv.eartag2.common.mq.Const;
-import org.springframework.amqp.rabbit.core.RabbitTemplate;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.stereotype.Component;
-
-import java.util.HashMap;
-import java.util.Map;
-
-/**
- * @Project : huimv.shiwan
- * @Package : com.huimv.biosafety.uface.controller
- * @Description : TODO
- * @Version : 1.0
- * @Author : ZhuoNing
- * @Create : 2020-12-25
- **/
-@Component
-public class ProcessProducer {
-    @Autowired
-    RabbitTemplate rabbitTemplate;  //使用RabbitTemplate,这提供了接收/发送等等方法
-
-    //处理心跳数据
-    public String sendHeartbeat(JSONObject dataJo) {
-        Map map = new HashMap();
-        map.put("heartbeat",dataJo.toString());
-        rabbitTemplate.convertAndSend(Const.EXCHANGE_DEVICE, Const.ROUTING_KEY_DEVICE_HEARTBEAT, map);
-        System.out.println("处理心跳 >>"+dataJo);
-        return "ok";
-    }
-
-    //处理环境温度数据
-    public String sendDeviceTemp(JSONObject dataJo) {
-        Map map = new HashMap();
-        map.put("deviceTemp",dataJo);
-        rabbitTemplate.convertAndSend(Const.EXCHANGE_DEVICE, Const.ROUTING_KEY_DEVICE_TEMP, map);
-        System.out.println("处理环境温度 >>"+dataJo);
-        return "ok";
-    }
-
-    //处理耳标数据
-    public String sendEartag(JSONObject dataJo) {
-        Map map = new HashMap();
-        map.put("eartag",dataJo);
-        rabbitTemplate.convertAndSend(Const.EXCHANGE_EARTAG, Const.ROUTING_KEY_EARTAG, map);
-        System.out.println("处理耳标数据 >>"+dataJo);
-        return "ok";
-    }
-}

+ 0 - 14
huimv-eartag2-platform/huimv-eartag2-process/src/main/java/com/huimv/eartag2/process/service/IDeviceService.java

@@ -1,14 +0,0 @@
-package com.huimv.eartag2.process.service;
-
-import com.alibaba.fastjson.JSONObject;
-
-import java.text.ParseException;
-
-public interface IDeviceService {
-    //保存心跳数据
-    void saveDeviceHeartbeat(JSONObject dataJo);
-    //保存设备温度数据
-    void saveDeviceTemp(JSONObject dataJo);
-    //保存采集器上传的原始数据
-    void saveRawdata(String askText) throws ParseException;
-}

+ 0 - 10
huimv-eartag2-platform/huimv-eartag2-process/src/main/java/com/huimv/eartag2/process/service/IEartagService.java

@@ -1,10 +0,0 @@
-package com.huimv.eartag2.process.service;
-
-import com.alibaba.fastjson.JSONObject;
-
-public interface IEartagService {
-    //计算运动量
-    Integer countAct(String deviceCode, String nowAct);
-    //保存耳标数据
-    void saveEartag(JSONObject dataJo);
-}

+ 0 - 136
huimv-eartag2-platform/huimv-eartag2-process/src/main/java/com/huimv/eartag2/process/service/impl/DeviceServiceImpl.java

@@ -1,136 +0,0 @@
-package com.huimv.eartag2.process.service.impl;
-
-import com.alibaba.fastjson.JSONObject;
-import com.huimv.eartag2.common.dao.entity.EartagEnvEntity;
-import com.huimv.eartag2.common.dao.entity.EartagHeartbeatEntity;
-import com.huimv.eartag2.common.dao.entity.EartagRawEntity;
-import com.huimv.eartag2.common.dao.repo.EartagEnvRepo;
-import com.huimv.eartag2.common.dao.repo.EartagHeartbeatRepo;
-import com.huimv.eartag2.common.dao.repo.EartagRawRepo;
-import com.huimv.eartag2.process.service.IDeviceService;
-import com.huimv.eartag2.process.utils.DateUtil;
-import com.huimv.eartag2.process.utils.MathUtil;
-import lombok.extern.slf4j.Slf4j;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.stereotype.Service;
-
-import java.sql.Timestamp;
-import java.text.ParseException;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.Map;
-
-/**
- * @Project : huimv.shiwan
- * @Package : com.huimv.biosafety.uface.controller
- * @Description : TODO
- * @Version : 1.0
- * @Author : ZhuoNing
- * @Create : 2020-12-25
- **/
-@Service
-@Slf4j
-public class DeviceServiceImpl implements IDeviceService {
-    @Autowired
-    private MathUtil mathUtil;
-    @Autowired
-    private DateUtil dateUtil;
-    @Autowired
-    private EartagRawRepo rawRepo;
-    @Autowired
-    private EartagHeartbeatRepo heartbeatRepo;
-    @Autowired
-    private EartagEnvRepo envRepo;
-
-    /**
-     * @Method      : saveDeviceHeartbeat
-     * @Description : 保存设备心跳数据
-     * @Params      : [dataJo]
-     * @Return      : void
-     * 
-     * @Author      : ZhuoNing
-     * @Date        : 2022/2/15       
-     * @Time        : 14:39
-     */
-    @Override
-    public void saveDeviceHeartbeat(JSONObject dataJo) {
-        String deviceCode = dataJo.getString("device");
-        EartagHeartbeatEntity addHeartbeatEntity = new EartagHeartbeatEntity();
-        addHeartbeatEntity.setDeviceCode(deviceCode);
-        addHeartbeatEntity.setAddTime(new Timestamp(new Date().getTime()));
-        heartbeatRepo.saveAndFlush(addHeartbeatEntity);
-    }
-
-    /**
-     * @Method      : saveDeviceTemp
-     * @Description : 保存设备温度数据
-     * @Params      : [dataJo]
-     * @Return      : void
-     * 
-     * @Author      : ZhuoNing
-     * @Date        : 2022/2/15       
-     * @Time        : 14:39
-     */
-    @Override
-    public void saveDeviceTemp(JSONObject dataJo) {
-        String device = dataJo.getString("device");
-        String temp = dataJo.getString("temp");
-        EartagEnvEntity envEntity = new EartagEnvEntity();
-        envEntity.setDeviceCode(device);
-        envEntity.setTemp1(Integer.parseInt(temp));
-        envEntity.setTemp2(0F);
-        envEntity.setAddTime(new Timestamp(new Date().getTime()));
-        envRepo.saveAndFlush(envEntity);
-    }
-
-    /**
-     * @Method      : saveRawdata
-     * @Description : 保存原始数据
-     * @Params      : [askText]
-     * @Return      : void
-     *
-     * @Author      : ZhuoNing
-     * @Date        : 2022/2/9
-     * @Time        : 13:38
-     */
-    @Override
-    public void saveRawdata(String askText) throws ParseException {
-//        log.info("#开始解析Ask请求数据>>" + askText.trim().replace("\n", ""));
-        String[] dataArray = askText.split("\\+");
-        String cmdHeader = dataArray[0];
-        Map rawMap = new HashMap();
-        if (cmdHeader.trim().equalsIgnoreCase("hm")) {
-            //采集器原始数据
-            String device = dataArray[1];
-            String cmd = dataArray[2];
-            rawMap.put("cmdHeader", cmdHeader);
-            rawMap.put("device", device);
-            rawMap.put("cmd", cmd);
-            rawMap.put("ask", askText);
-        } else if (cmdHeader.trim().equalsIgnoreCase("zj")) {
-            //采集器原始数据
-            String device = dataArray[1];
-            rawMap.put("cmdHeader", cmdHeader);
-            rawMap.put("device", device);
-            rawMap.put("cmd", "");
-            rawMap.put("ask", askText);
-            rawMap.put("addTime", dateUtil.getTodayMissionText());
-        } else {
-            //采集器原始数据
-            String device = dataArray[1];
-            rawMap.put("cmdHeader", cmdHeader);
-            rawMap.put("device", device);
-            rawMap.put("cmd", "");
-            rawMap.put("ask", askText);
-        }
-        //保存原始数据
-        //类型、设备、命令、数据内容、日期
-        EartagRawEntity addRawEntity = new EartagRawEntity();
-        addRawEntity.setCmdHeader(rawMap.get("cmdHeader").toString());
-        addRawEntity.setDevice(rawMap.get("device").toString());
-        addRawEntity.setCmd(rawMap.get("cmd").toString());
-        addRawEntity.setAsk(rawMap.get("ask").toString());
-        addRawEntity.setAddTime(new Timestamp(new Date().getTime()));
-        rawRepo.saveAndFlush(addRawEntity);
-    }
-}

+ 0 - 139
huimv-eartag2-platform/huimv-eartag2-process/src/main/java/com/huimv/eartag2/process/service/impl/EartagServiceImpl.java

@@ -1,139 +0,0 @@
-package com.huimv.eartag2.process.service.impl;
-
-import com.alibaba.fastjson.JSONObject;
-import com.huimv.eartag2.common.dao.entity.EartagDataEntity;
-import com.huimv.eartag2.common.dao.repo.EartagDataRepo;
-import com.huimv.eartag2.process.service.IEartagService;
-import lombok.extern.slf4j.Slf4j;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.data.redis.core.RedisTemplate;
-import org.springframework.stereotype.Service;
-
-import javax.annotation.Resource;
-import java.sql.Timestamp;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.Map;
-
-/**
- * @Project : huimv.shiwan
- * @Package : com.huimv.biosafety.uface.controller
- * @Description : TODO
- * @Version : 1.0
- * @Author : ZhuoNing
- * @Create : 2020-12-25
- **/
-@Service
-@Slf4j
-public class EartagServiceImpl implements IEartagService {
-    @Autowired
-    private RedisTemplate redisTemplate;
-    @Autowired
-    private EartagDataRepo eartagDataRepo;
-
-    /**
-     * @Method : countAct
-     * @Description : 计算act数值
-     * @Params : [deviceCode, nowAct0]
-     * @Return : java.lang.Integer
-     * @Author : ZhuoNing
-     * @Date : 2022/1/18
-     * @Time : 15:25
-     */
-    @Override
-    public Integer countAct(String deviceCode, String nowAct) {
-        //读取hash
-        Object actObj = redisTemplate.opsForHash().get(deviceCode, "act");
-        if (actObj == null) {
-            //--初始化最新的redis记录
-            initRedisObj(deviceCode);
-            Object lastAct = redisTemplate.opsForHash().get(deviceCode, "act");
-            if (lastAct == null) {
-                log.error("#--- redis数据库有问题,请检查redis是否能正常连接 ---# ");
-                return 0;
-            }
-        }
-        Object lastAct = redisTemplate.opsForHash().get(deviceCode, "act");
-        Integer act1 = Integer.parseInt(nowAct) - Integer.parseInt(lastAct.toString());
-//        redisTemplate.opsForHash().put(deviceCode, "act1", act1);
-        return act1;
-    }
-
-    /**
-     * @Author      : ZhuoNing
-     * @Date        : 2022/2/9
-     * @Time        : 14:33
-     */
-    @Override
-    public void saveEartag(JSONObject eartagJo) {
-        EartagDataEntity dataEntity = new EartagDataEntity();
-        dataEntity.setCmdHeader(eartagJo.getString("cmdHeader"));
-        dataEntity.setDevice(eartagJo.getString("device"));
-        dataEntity.setEarmark(eartagJo.getString("earmark"));
-        dataEntity.setBat(Integer.parseInt(eartagJo.getString("bat")));
-        dataEntity.setEarTemp(Integer.parseInt(eartagJo.getString("earTemp")));
-        dataEntity.setEarTemp1(eartagJo.getFloat("earTemp1"));
-        dataEntity.setEnvTemp(Integer.parseInt(eartagJo.getString("envTemp")));
-        dataEntity.setEnvTemp1(eartagJo.getFloat("envTemp1"));
-        dataEntity.setAct(Integer.parseInt(eartagJo.getString("act")));
-        dataEntity.setAct1(Integer.parseInt(eartagJo.getString("act1")));
-        dataEntity.setSignal1(Integer.parseInt(eartagJo.getString("signal")));
-        dataEntity.setAskTime(getAskTime(eartagJo.getString("askTime")));
-        dataEntity.setOther(eartagJo.getString("other"));
-        dataEntity.setAddTime(new Timestamp(new Date().getTime()));
-        eartagDataRepo.saveAndFlush(dataEntity);
-
-        //最新的耳标数据覆盖老数据
-        Map<String, String> map = new HashMap<>();
-        map.put("cmdHeader", dataEntity.getCmdHeader());
-        map.put("device", dataEntity.getDevice());
-        map.put("earmark", dataEntity.getEarmark());
-        map.put("bat", dataEntity.getBat().toString());
-        map.put("earTemp", dataEntity.getEarTemp().toString());
-        map.put("earTemp1", dataEntity.getEarTemp1().toString());
-        map.put("envTemp", dataEntity.getEnvTemp().toString());
-        map.put("envTemp1", dataEntity.getEnvTemp1().toString());
-        map.put("act", dataEntity.getAct().toString());
-        map.put("act1", dataEntity.getAct1().toString());
-        map.put("signal1", dataEntity.getSignal1().toString());
-        map.put("askTime", dataEntity.getAskTime());
-        map.put("other", dataEntity.getOther());
-        map.put("addTime", dataEntity.getAddTime().toString());
-        //为hash结构设置多个键值对(hmset)
-        redisTemplate.opsForHash().putAll(dataEntity.getDevice(), map);
-    }
-
-    //
-    public String getAskTime(String askTime) {
-        String newAskTime = askTime.substring(0, 4) + "-" + askTime.substring(4, 6) + "-" + askTime.substring(6, 8) + " " + askTime.substring(8, 10) + ":" + askTime.substring(10, 12) + ":" + askTime.substring(12, 14);
-        return newAskTime;
-    }
-
-    /**
-     * 初始化redis最新记录
-     */
-    private void initRedisObj(String deviceCode) {
-        EartagDataEntity lastEartagDataEntity = eartagDataRepo.getLastEartagData(deviceCode);
-        if (lastEartagDataEntity != null) {
-            System.out.println("## lastEartagDataEntity.toString>>" + lastEartagDataEntity.toString());
-            //--从数据库读取最新记录并覆盖redis
-            Map<String, String> map = new HashMap<>();
-            map.put("cmdHeader", lastEartagDataEntity.getCmdHeader());
-            map.put("device", lastEartagDataEntity.getDevice());
-            map.put("earmark", lastEartagDataEntity.getEarmark());
-            map.put("bat", lastEartagDataEntity.getBat().toString());
-            map.put("earTemp", lastEartagDataEntity.getEarTemp().toString());
-            map.put("earTemp1", lastEartagDataEntity.getEarTemp1().toString());
-            map.put("envTemp", lastEartagDataEntity.getEnvTemp().toString());
-            map.put("envTemp1", lastEartagDataEntity.getEnvTemp1().toString());
-            map.put("act", lastEartagDataEntity.getAct().toString());
-            map.put("act1", lastEartagDataEntity.getAct1().toString());
-            map.put("signal1", lastEartagDataEntity.getSignal1().toString());
-            map.put("askTime", lastEartagDataEntity.getAskTime());
-            map.put("other", lastEartagDataEntity.getOther());
-            map.put("addTime", lastEartagDataEntity.getAddTime().toString());
-            //为hash结构设置多个键值对(hmset)
-            redisTemplate.opsForHash().putAll(deviceCode, map);
-        }
-    }
-}

+ 0 - 21
huimv-eartag2-platform/huimv-eartag2-process/src/main/java/com/huimv/eartag2/process/task/TestTask.java

@@ -1,21 +0,0 @@
-package com.huimv.eartag2.process.task;
-
-import org.springframework.scheduling.annotation.Scheduled;
-import org.springframework.stereotype.Component;
-
-/**
- * @Project : huimv.shiwan
- * @Package : com.huimv.biosafety.uface.controller
- * @Description : TODO
- * @Version : 1.0
- * @Author : ZhuoNing
- * @Create : 2020-12-25
- **/
-@Component
-public class TestTask {
-
-//    @Scheduled(cron="0/5 * * * * ?")
-    public void test1(){
-        System.out.println("定时任务开启.");
-    }
-}

+ 0 - 12
huimv-eartag2-platform/huimv-eartag2-process/src/main/java/com/huimv/eartag2/process/utils/BaseTemplete.java

@@ -1,12 +0,0 @@
-package com.huimv.eartag2.process.utils;
-
-/**
- * @Project : huimv.shiwan
- * @Package : com.huimv.biosafety.uface.controller
- * @Description : TODO
- * @Version : 1.0
- * @Author : ZhuoNing
- * @Create : 2020-12-25
- **/
-public class BaseTemplete {
-}

+ 0 - 187
huimv-eartag2-platform/huimv-eartag2-process/src/main/java/com/huimv/eartag2/process/utils/DateUtil.java

@@ -1,187 +0,0 @@
-package com.huimv.eartag2.process.utils;
-
-import cn.hutool.core.date.DateTime;
-import lombok.extern.slf4j.Slf4j;
-import org.springframework.stereotype.Component;
-
-import java.text.ParseException;
-import java.text.SimpleDateFormat;
-import java.util.ArrayList;
-import java.util.Calendar;
-import java.util.Date;
-
-/**
- * @Project : huimv.shiwan
- * @Package : com.huimv.biosafety.uface.controller
- * @Description : TODO
- * @Version : 1.0
- * @Author : ZhuoNing
- * @Create : 2020-12-25
- **/
-@Component
-@Slf4j
-public class DateUtil {
-
-    //格式化日期(Long --> Date)
-    public String formatLongToDate(Long longDate){
-        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
-        Date date= new Date(longDate);
-        return df.format(date);
-    }
-
-    //格式化本年
-    public String getThisYear(){
-        Calendar cal = Calendar.getInstance();
-        int year = cal.get(Calendar.YEAR);
-        return String.valueOf(year);
-    }
-
-    //格式化本月
-    public String getThisMonth(){
-        Calendar cal = Calendar.getInstance();
-        int month = cal.get(Calendar.MONTH) + 1;
-        if(String.valueOf(month).length()==1)
-        {
-            return "0"+String.valueOf(month);
-        }else{
-            return String.valueOf(month);
-        }
-    }
-
-    //格式化日期时间
-    public String formatDateTime(String dateText) throws ParseException {
-        if(dateText.indexOf("T") != -1){
-            dateText = dateText.replace("T"," ");
-        }
-        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
-        Date date = sdf.parse(dateText);
-        return sdf.format(date);
-    }
-
-    public Date parseDateTime(String dateText) throws ParseException {
-        if(dateText.indexOf("T") != -1){
-            dateText = dateText.replace("T"," ");
-        }
-        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
-        return sdf.parse(dateText);
-    }
-
-    public Long parseDateTimeLong(String dateText) throws ParseException {
-        if(dateText.indexOf("T") != -1){
-            dateText = dateText.replace("T"," ");
-        }
-        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
-        Date date = sdf.parse(dateText);
-        return date.getTime();
-    }
-
-    //
-    public Date getTodayDate() throws ParseException {
-        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
-        return sdf.parse(sdf.format(new Date()));
-    }
-
-    public Date getTodayDatetime() throws ParseException {
-        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
-        return sdf.parse(sdf.format(new Date()));
-    }
-
-    public String getTodayDateText() throws ParseException {
-        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
-        return sdf.format(new Date());
-    }
-
-    public String getTodayText() throws ParseException {
-        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
-        return sdf.format(new Date());
-    }
-
-    public String getNowText() throws ParseException {
-        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
-        return sdf.format(new Date());
-    }
-
-    public String getTodayMissionText() throws ParseException {
-        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
-        return sdf.format(new Date());
-    }
-
-    public String getStartDateInThisMonth(){
-        DateTime date = cn.hutool.core.date.DateUtil.date();
-        return (cn.hutool.core.date.DateUtil.beginOfMonth(date) + "").substring(0, 10);
-    }
-
-    public String getEndDateInThisMonth(){
-        DateTime date = cn.hutool.core.date.DateUtil.date();
-        return (date + "").substring(0, 10);
-    }
-
-    /**
-     * 获取过去或者未来 任意天内的日期数组
-     * @param intervals      intervals天内
-     * @return              日期数组
-     */
-    public ArrayList<String> test(int intervals ) {
-        ArrayList<String> pastDaysList = new ArrayList<>();
-        ArrayList<String> fetureDaysList = new ArrayList<>();
-        for (int i = 0; i <intervals; i++) {
-            pastDaysList.add(getPastDate(i));
-            fetureDaysList.add(getFetureDate(i));
-        }
-        return pastDaysList;
-    }
-
-    /**
-     * 获取过去第几天的日期
-     *
-     * @param past
-     * @return
-     */
-    public String getPastDate(int past) {
-        Calendar calendar = Calendar.getInstance();
-        calendar.set(Calendar.DAY_OF_YEAR, calendar.get(Calendar.DAY_OF_YEAR) - past);
-        Date today = calendar.getTime();
-        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
-        String result = format.format(today);
-        return result;
-    }
-
-    /**
-     * 获取未来 第 past 天的日期
-     * @param past
-     * @return
-     */
-    public String getFetureDate(int past) {
-        Calendar calendar = Calendar.getInstance();
-        calendar.set(Calendar.DAY_OF_YEAR, calendar.get(Calendar.DAY_OF_YEAR) + past);
-        Date today = calendar.getTime();
-        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
-        String result = format.format(today);
-        return result;
-    }
-
-    //重新构建日期
-    public String rebuildDateTime(String text){
-        return text.substring(0,4)+"-"+text.substring(4,6)+"-"+text.substring(6,8)+" "+text.substring(8,10)+":"+text.substring(10,12)+":"+text.substring(12,14);
-    }
-
-    public static void main(String[] args){
-        DateUtil du = new DateUtil();
-        //
-        du.test1();
-    }
-
-    private void test1() {
-        String text = "20211201104300";
-//        String text = "1234567890abcd";
-        String date = text.substring(0,4)+"-"+text.substring(4,6)+"-"+text.substring(6,8)+" "+text.substring(8,10)+":"+text.substring(10,12)+":"+text.substring(12,14);
-        System.out.println("date="+date);
-    }
-
-    //获取long时间
-    public Long getNowLong(){
-        Calendar calendar = Calendar.getInstance();
-        calendar.set(calendar.get(Calendar.YEAR),calendar.get(Calendar.MONTH),calendar.get(Calendar.DAY_OF_MONTH)-1,0,0,0);
-        return calendar.getTime().getTime();
-    }
-}

+ 0 - 90
huimv-eartag2-platform/huimv-eartag2-process/src/main/java/com/huimv/eartag2/process/utils/MathUtil.java

@@ -1,90 +0,0 @@
-package com.huimv.eartag2.process.utils;
-
-import org.springframework.stereotype.Component;
-
-import java.text.DecimalFormat;
-import java.text.NumberFormat;
-
-/**
- * @Project : huimv.shiwan
- * @Package : com.huimv.biosafety.uface.controller
- * @Description : TODO
- * @Version : 1.0
- * @Author : ZhuoNing
- * @Create : 2020-12-25
- **/
-@Component
-public class MathUtil {
-
-    public static double A = 0.00335396319311466;
-    public static double B = 0.000256376549039663;
-    public static double C = 0.00000248933580817244;
-    public static double D = 0.0000000753805242068686;
-    public static double E = -0.0000000204758173596178;
-
-    //保留一位小数
-    public static  double changeDouble(Double dou) {
-        NumberFormat nf = new DecimalFormat("0.0 ");
-        dou = Double.parseDouble(nf.format(dou));
-        return dou;
-    }
-
-    public static double ln(int rv) {
-        int R_REF = 10000;
-        double ln = Math.log((double) rv / R_REF);
-//        System.out.println("$$$$$$$$$ ln>>"+ln);
-        //保留一位小数
-        return changeDouble(1 / (A + B * ln + C * Math.pow(ln, 2) + D * Math.pow(ln, 3) + E * Math.pow(ln, 4)) - 273.15) + 0.001;
-    }
-
-    public String formatBit(float num, int bit) {
-        // 创建一个数值格式化对象
-        NumberFormat numberFormat = NumberFormat.getInstance();
-        // 设置精确到小数点后2位
-        numberFormat.setMaximumFractionDigits(bit);
-        return numberFormat.format(num);
-    }
-
-    public String formatBit(float num) {
-        return String.valueOf(num);
-    }
-
-    //计算比率
-    public String countRate(float num, int bit) {
-        // 创建一个数值格式化对象
-        NumberFormat numberFormat = NumberFormat.getInstance();
-        // 设置精确到小数点后2位
-        numberFormat.setMaximumFractionDigits(bit);
-        return numberFormat.format(num * 100);//所占百分比
-    }
-
-    //计算占比
-    public String countRate(float num, float total,int bit) {
-        // 创建一个数值格式化对象
-        NumberFormat numberFormat = NumberFormat.getInstance();
-        // 设置精确到小数点后2位
-        numberFormat.setMaximumFractionDigits(bit);
-        //所占百分比
-        return numberFormat.format((float)  num/ (float)total* 100);
-    }
-
-    //格式化
-    public String format(float num, int bit) {
-        // 创建一个数值格式化对象
-        NumberFormat numberFormat = NumberFormat.getInstance();
-        // 设置精确到小数点后2位
-        numberFormat.setMaximumFractionDigits(bit);
-        return numberFormat.format(num * 100);//所占百分比
-    }
-
-    //格式化
-    public String format(float num, float total,int bit) {
-        // 创建一个数值格式化对象
-        NumberFormat numberFormat = NumberFormat.getInstance();
-        // 设置精确到小数点后2位
-        numberFormat.setMaximumFractionDigits(bit);
-        //所占百分比
-        return numberFormat.format((float)  num/ (float)total* 100);
-    }
-
-}

+ 0 - 107
huimv-eartag2-platform/huimv-eartag2-process/src/main/resources/application-dev.yml

@@ -1,107 +0,0 @@
-server:
-  port: 8092
-spring:
-  application:
-    name: huimv-eartag2-process
-
-  datasource:
-    url: jdbc:mysql://192.168.1.7:3306/huimv-demo-eartag20?useUnicode=true&characterEncoding=UTF-8&useSSL=false&autoReconnect=true&serverTimezone=Asia/Shanghai
-    username: root
-    password: hm123456
-    driver-class-name: com.mysql.cj.jdbc.Driver
-  jpa:
-    show-sql: true
-    database: mysql
-    hibernate:
-      ddl-auto: update
-    database-platform: org.hibernate.dialect.MySQL5InnoDBDialect
-    open-in-view: true
-
-  #配置rabbitMq 服务器
-#  rabbitmq:
-#    host: 10.0.0.4
-#    port: 5672
-#    username: huimv
-#    password: hm123456
-#    #虚拟host 可以不设置,使用server默认host
-#    virtual-host: /
-  rabbitmq:
-    host: 192.168.1.170
-    port: 5672
-    username: admin
-    password: admin
-    #虚拟host 可以不设置,使用server默认host
-    virtual-host: /
-    listener:
-      simple:
-        acknowledge-mode: none  #消费端不需要确认
-
-  #redis
-  redis:
-    database: 0
-    host: 192.168.1.68
-    port: 6379
-    password: hm123456
-    timeout: 5000ms
-    jedis:
-      pool:
-        max-active: 20
-        max-wait: -1
-        max-idle: 10
-        min-idle: 0
-
-  #redis
-#  redis:
-#    database: 0
-#    host: 192.168.1.68
-#    port: 6379
-#    password: hm123456
-#    timeout: 5000ms
-#    jedis:
-#      pool:
-#        max-active: 20
-#        max-wait: -1
-#        max-idle: 10
-#        min-idle: 0
-#    lettuce:
-#      pool:
-#        max-active: 3
-#        min-idle: 2
-#        max-idle: 3
-#        max-wait: 1
-#      shutdown-timeout: 100
-
-#  data:
-#    redis:
-#      repositories:
-#        enabled: false
-
-  #是否缓存空值
-#  cache:
-#    redis:
-#      cache-null-values: false
-    #server:
-#  port: 9110
-#spring:
-#  application:
-#    name: huimv-hy-autoGetData
-#
-#  datasource:
-##    url: jdbc:mysql://47.98.175.112:3306/huimv_ql_farm_haiyan?useUnicode=true&characterEncoding=UTF-8&useSSL=false&autoReconnect=true&serverTimezone=Asia/Shanghai
-#    #    url: jdbc:mysql://36.22.189.214:3306/huimv_ql_farm?useUnicode=true&characterEncoding=UTF-8&useSSL=false&autoReconnect=true&serverTimezone=Asia/Shanghai
-#        url: jdbc:mysql://192.168.1.7:3306/huimv_ql_farm?useUnicode=true&characterEncoding=UTF-8&useSSL=false&autoReconnect=true&serverTimezone=Asia/Shanghai
-#    username: root
-#    password: hm123456
-#    driver-class-name: com.mysql.cj.jdbc.Driver
-#  jpa:
-#    properties:
-#      hibernate:
-#        enable_lazy_load_no_trans: true
-#    show-sql: true
-#    database: mysql
-#    hibernate:
-#      ddl-auto: update
-#    database-platform: org.hibernate.dialect.MySQL5InnoDBDialect
-#    open-in-view: true
-
-

+ 0 - 1
huimv-eartag2-platform/huimv-eartag2-process/src/main/resources/application.properties

@@ -1 +0,0 @@
-spring.profiles.active=dev

+ 0 - 88
huimv-eartag2-platform/huimv-eartag2-process2/pom.xml

@@ -1,88 +0,0 @@
-<?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">
-    <parent>
-        <artifactId>huimv-eartag2-platform</artifactId>
-        <groupId>com.huimv</groupId>
-        <version>0.0.1-SNAPSHOT</version>
-    </parent>
-    <modelVersion>4.0.0</modelVersion>
-
-    <artifactId>huimv-eartag2-process2</artifactId>
-
-    <dependencies>
-        <!-- eartag2-common -->
-        <dependency>
-            <groupId>com.huimv</groupId>
-            <artifactId>huimv-eartag2-common</artifactId>
-            <version>0.0.1-SNAPSHOT</version>
-        </dependency>
-        <!--rabbitmq-->
-        <dependency>
-            <groupId>org.springframework.boot</groupId>
-            <artifactId>spring-boot-starter-amqp</artifactId>
-        </dependency>
-        <!-- eartag2-common -->
-        <!--        <dependency>-->
-        <!--            <groupId>com.huimv</groupId>-->
-        <!--            <artifactId>huimv-eartag2-common</artifactId>-->
-        <!--            <version>0.0.1-SNAPSHOT</version>-->
-        <!--        </dependency>-->
-        <dependency>
-            <groupId>org.springframework.boot</groupId>
-            <artifactId>spring-boot-starter-web</artifactId>
-        </dependency>
-        <!-- lombok -->
-        <dependency>
-            <groupId>org.projectlombok</groupId>
-            <artifactId>lombok</artifactId>
-            <version>1.16.18</version>
-            <scope>provided</scope>
-        </dependency>
-        <!--hutool-->
-        <dependency>
-            <groupId>cn.hutool</groupId>
-            <artifactId>hutool-all</artifactId>
-            <version>LATEST</version>
-        </dependency>
-        <dependency>
-            <groupId>org.apache.httpcomponents</groupId>
-            <artifactId>httpclient</artifactId>
-            <version>4.5.5</version>
-        </dependency>
-        <dependency>
-            <groupId>junit</groupId>
-            <artifactId>junit</artifactId>
-            <scope>test</scope>
-        </dependency>
-    </dependencies>
-
-    <build>
-        <plugins>
-            <!--  -->
-            <plugin>
-                <groupId>org.springframework.boot</groupId>
-                <artifactId>spring-boot-maven-plugin</artifactId>
-            </plugin>
-            <!--  -->
-            <plugin>
-                <groupId>org.apache.maven.plugins</groupId>
-                <artifactId>maven-resources-plugin</artifactId>
-                <version>2.6</version>
-            </plugin>
-        </plugins>
-    </build>
-
-    <!--    <build>-->
-    <!--        <plugins>-->
-    <!--            <plugin>-->
-    <!--                <groupId>org.springframework.boot</groupId>-->
-    <!--                <artifactId>spring-boot-maven-plugin</artifactId>-->
-    <!--                <configuration>-->
-    <!--                    <executable>true</executable>-->
-    <!--                </configuration>-->
-    <!--            </plugin>-->
-    <!--        </plugins>-->
-    <!--    </build>-->
-</project>

+ 0 - 25
huimv-eartag2-platform/huimv-eartag2-process2/src/main/java/com/huimv/eartag2/process2/HuimvProcess2Application.java

@@ -1,25 +0,0 @@
-package com.huimv.eartag2.process2;
-
-import org.springframework.boot.SpringApplication;
-import org.springframework.boot.autoconfigure.SpringBootApplication;
-import org.springframework.boot.autoconfigure.domain.EntityScan;
-import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
-
-/**
- * @Project : huimv.shiwan
- * @Package : com.huimv.biosafety.uface.controller
- * @Description : TODO
- * @Version : 1.0
- * @Author : ZhuoNing
- * @Create : 2020-12-25
- **/
-@SpringBootApplication
-//@ComponentScan(basePackages = {"com.huimv.eartag2.common.utils"})
-@EntityScan(value = "com.huimv.eartag2.common.dao.entity")
-@EnableJpaRepositories(basePackages = "com.huimv.eartag2.common.dao.repo")
-public class HuimvProcess2Application {
-    public static void main(String[] args) {
-        SpringApplication.run(HuimvProcess2Application.class, args);
-    }
-
-}

+ 0 - 63
huimv-eartag2-platform/huimv-eartag2-process2/src/main/java/com/huimv/eartag2/process2/config/TopicRabbitMQConfig.java

@@ -1,63 +0,0 @@
-package com.huimv.eartag2.process2.config;
-
-import com.huimv.eartag2.common.mq.Const;
-import org.springframework.amqp.core.Binding;
-import org.springframework.amqp.core.BindingBuilder;
-import org.springframework.amqp.core.Queue;
-import org.springframework.amqp.core.TopicExchange;
-import org.springframework.context.annotation.Bean;
-import org.springframework.context.annotation.Configuration;
-
-/**
- * @Project : huimv.shiwan
- * @Package : com.huimv.biosafety.uface.controller
- * @Description : TODO
- * @Version : 1.0
- * @Author : ZhuoNing
- * @Create : 2020-12-25
- **/
-@Configuration
-public class TopicRabbitMQConfig {
-    //心跳
-    @Bean
-    public Queue heartbeatQueue() {
-        return new Queue(Const.QUEUE_DEVICE_HEARTBEAT);
-    }
-    //采集器温度
-//    @Bean
-//    public Queue deviceTempQueue() {
-//        return new Queue(Const.QUEUE_DEVICE_TEMP);
-//    }
-    //耳标数据
-//    @Bean
-//    public Queue eartagQueue() {
-//        return new Queue(Const.QUEUE_EARTAG);
-//    }
-
-    //采集器设备交换机
-    TopicExchange deviceExchange() {
-        return new TopicExchange(Const.EXCHANGE_DEVICE);
-    }
-
-    //耳标交换机
-//    TopicExchange eartagExchange() {
-//        return new TopicExchange(Const.EXCHANGE_EARTAG);
-//    }
-
-    //设备交换机、心跳队列、心跳路由键绑定
-    @Bean
-    Binding bindingHeartbeatExchangeMessage() {
-        return BindingBuilder.bind(heartbeatQueue()).to(deviceExchange()).with(Const.ROUTING_KEY_DEVICE_HEARTBEAT);
-    }
-    //设备交换机、设备环境温度队列、设备环境路由键绑定
-//    @Bean
-//    Binding bindingDeviceTempExchangeMessage() {
-//        return BindingBuilder.bind(deviceTempQueue()).to(deviceExchange()).with(Const.ROUTING_KEY_DEVICE_TEMP);
-//    }
-    //耳标交换机、耳标队列、耳标路由键绑定
-//    @Bean
-//    Binding bindingEartagExchangeMessage() {
-//        return BindingBuilder.bind(eartagQueue()).to(eartagExchange()).with(Const.ROUTING_KEY_EARTAG);
-//    }
-
-}

+ 0 - 103
huimv-eartag2-platform/huimv-eartag2-process2/src/main/java/com/huimv/eartag2/process2/controller/RedisContrller.java

@@ -1,103 +0,0 @@
-package com.huimv.eartag2.process2.controller;
-
-import com.huimv.eartag2.common.utils.BizConst;
-import com.huimv.eartag2.common.utils.MathUtil;
-import com.huimv.eartag2.process2.service.ICacheService;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.data.redis.core.RedisTemplate;
-import org.springframework.web.bind.annotation.*;
-
-import javax.annotation.Resource;
-import java.math.BigDecimal;
-import java.util.Map;
-import java.util.Set;
-import java.util.concurrent.TimeUnit;
-
-/**
- * @Project : huimv.shiwan
- * @Package : com.huimv.biosafety.uface.controller
- * @Description : TODO
- * @Version : 1.0
- * @Author : ZhuoNing
- * @Create : 2020-12-25
- **/
-@RestController
-@RequestMapping("/redis")
-public class RedisContrller {
-    @Resource
-    private RedisTemplate redisTemplate;
-    @Autowired
-    private ICacheService cacheService;
-
-    @RequestMapping(value = "/get1",method = RequestMethod.GET)
-    public void get1(@RequestParam(value = "farmId",required = true) String farmId) {
-        //
-        Integer deviceTotal = cacheService.getDeviceTotal(farmId);
-        System.out.println("## deviceTotal>>"+deviceTotal);
-    }
-
-
-    @RequestMapping(value = "/set",method = RequestMethod.GET)
-    public void set1(@RequestParam(value = "name",required = true) String name,String company){
-        if(name == null || name == ""){
-            name="java";
-        }
-        String setKey = "testSet";
-        redisTemplate.opsForSet().add(setKey, name);
-
-        setKey = "set:online:device:101:2022-03-14";
-        Set<String> resultSet = redisTemplate.opsForSet().members(setKey);
-        System.out.println(setKey+" >>"+resultSet+", "+resultSet.size());
-        boolean memberStatus = redisTemplate.opsForSet().isMember(setKey,company);
-        System.out.println("memberStatus>>"+memberStatus);
-//        redisTemplate.expire(setKey,2, TimeUnit.HOURS);
-        redisTemplate.expire(setKey,2, TimeUnit.MINUTES);
-        //根据key获取过期时间
-        System.out.println("过期时间>>"+redisTemplate.getExpire(setKey));
-
-        setKey = "farm_earmark_online_101_2022-03-02";
-        Set<String> resultSet2 = redisTemplate.opsForSet().members(setKey);
-        System.out.println(setKey+" members >>"+resultSet2);
-
-        setKey = "farm_earmark_online_101_2022-03-02";
-        boolean memberStatus2 = redisTemplate.opsForSet().isMember(setKey,company);
-        System.out.println(setKey+" isMember >>"+memberStatus2);
-
-        String hashKey = BizConst.FARM_ALL_STATUS_PREFIX+"101";
-        System.out.println("hashKey>>>>>>>>>>>>>>>>>>>>>>>>"+hashKey);
-        Map allMap = redisTemplate.opsForHash().entries(hashKey);
-        System.out.println("allMap>>>>>>>>>>>>>>>>>>>>>>>>>"+allMap.toString());
-        if(allMap.size()==0){
-            System.out.println("==0");
-        }else{
-            System.out.println("!=0");
-        }
-    }
-
-    @RequestMapping(value = "/getSetSize",method = RequestMethod.GET)
-    public void getSetSize(){
-        String setKey = "set:online:device:101:2022-03-14";
-        Set<String> resultSet = redisTemplate.opsForSet().members(setKey);
-        System.out.println(setKey+" >>"+resultSet);
-        System.out.println(setKey+" 数量 >>"+resultSet.size());
-    }
-
-    @RequestMapping(value = "/countRate",method = RequestMethod.GET)
-    public void countRate(){
-        String temp = "2328";
-//        BigDecimal deviceRateBd= new BigDecimal(temp).divide(new BigDecimal(100),2,BigDecimal.ROUND_HALF_UP);
-        BigDecimal deviceRateBd = MathUtil.countEnvtemp(temp,2);
-
-        System.out.println("deviceRateBd 333 >>"+deviceRateBd);
-    }
-
-    @RequestMapping(value = "/getRegisterByFarmId",method = RequestMethod.GET)
-    public void getRegisterByFarmId(@RequestParam(value = "deviceCode",required = true) String deviceCode){
-        //202007239999869
-        Map<Object, Object> map = cacheService.getDeviceRegister(deviceCode);
-        System.out.println("map >>"+map.toString());
-
-        String deviceAlias = (String)cacheService.getDeviceRegisterProperty(deviceCode,"deviceAlias");
-        System.out.println("deviceAlias>>"+deviceAlias);
-    }
-}

+ 0 - 214
huimv-eartag2-platform/huimv-eartag2-process2/src/main/java/com/huimv/eartag2/process2/listener/DeviceListener.java

@@ -1,214 +0,0 @@
-package com.huimv.eartag2.process2.listener;
-
-import com.alibaba.fastjson.JSON;
-import com.alibaba.fastjson.JSONObject;
-import com.huimv.eartag2.common.mq.Const;
-import com.huimv.eartag2.common.utils.DateUtil;
-import com.huimv.eartag2.process2.service.ICacheService;
-import com.huimv.eartag2.process2.service.IDeviceService;
-import lombok.extern.slf4j.Slf4j;
-import org.springframework.amqp.rabbit.annotation.RabbitHandler;
-import org.springframework.amqp.rabbit.annotation.RabbitListener;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.data.redis.core.RedisTemplate;
-import org.springframework.stereotype.Component;
-
-import java.sql.Date;
-import java.sql.Timestamp;
-import java.text.ParseException;
-import java.util.Map;
-
-/**
- * @Project : huimv.shiwan
- * @Package : com.huimv.biosafety.uface.controller
- * @Description : TODO
- * @Version : 1.0
- * @Author : ZhuoNing
- * @Create : 2020-12-25
- **/
-@Component
-@Slf4j
-public class DeviceListener {
-    @Autowired
-    private RedisTemplate redisTemplate;
-    @Autowired
-    private IDeviceService deviceService;
-    @Autowired
-    private ICacheService cacheService;
-
-    /**
-     * @Method : processDeviceHeartbeat
-     * @Description : 处理设备心跳数据
-     * @Params : [RawMap]
-     * @Return : void
-     * @Author : ZhuoNing
-     * @Date : 2022/2/15
-     * @Time : 8:56
-     */
-//    @RabbitListener(queues = Const.QUEUE_DEVICE_HEARTBEAT)
-    @RabbitHandler
-    public void processDeviceHeartbeat(Map DeviceMap) throws ParseException {
-        System.out.println("222 <<<<<<<<<<<<<<< 处理设备心跳数据>>" + DeviceMap.toString());
-        //--更新设备注册数据(MySQL,Redis)-
-        //--保存设备在线统计数据(MySQL,Redis)-
-        //--保存设备状态数据(MySQL,Redis)-
-        JSONObject deviceJo = JSON.parseObject(DeviceMap.get("heartbeat").toString());
-        String deviceCode = deviceJo.getString("device");
-        System.out.println("deviceCode>>" + deviceCode);
-        //获取牧场id
-        String farmId = deviceService.getFarmIdByDeviceCode(deviceCode);
-        String todayDateText = new DateUtil().getTodayDateText();
-        Date todayDate = new Date(new java.util.Date().getTime());
-        Timestamp nowTimestamp = new Timestamp(new java.util.Date().getTime());
-
-        //判断该设备编号是否存在缓存在线集合当中;
-        if (cacheService.isExistDeviceOnlineSet(farmId, deviceCode, todayDateText)) {
-            //Step1:更新设备注册表[设置活动状态为1,设置活动状态更新时间]
-            //Step2:更新在线统计[心跳数+1,心跳第一次上传时间,心跳最后一次时间],预先判断该数据是否存在,如果不存在要先添加记录,如果存在就修改数据
-            System.out.println("## 心跳 1");
-            //# 更新设备注册表 #
-            deviceService.updateDeviceRegister(farmId, deviceCode,nowTimestamp);
-
-            //# 更新在线统计 #
-            deviceService.updateDeviceOnlineCount(farmId, deviceCode,todayDateText,nowTimestamp,todayDate);
-        } else {
-            System.out.println("## 心跳 2");
-            //Step1:更新总状态表[device_online+1,device_offline-1,device_rate],预先判断该数据是否存在,如果不存在要先添加记录,如果存在就修改数据
-            //Step2:更新设备注册表[active_status=1,active_time=当前时间]
-            //Step3:更新在线统计[],预先判断该数据是否存在,如果不存在要先添加记录,如果存在就修改数据
-            //Step4:将新设备编号加入缓存[]
-
-            //# 更新设备注册表 #
-            deviceService.updateDeviceRegister(farmId, deviceCode,nowTimestamp);
-
-            //# 更新在线统计 #【重写完成】
-            deviceService.updateDeviceOnlineCount(farmId, deviceCode, todayDateText, nowTimestamp, todayDate);
-
-            //# 更新总状态表 # 【重写】
-            deviceService.updateDeviceAllStatus(farmId, deviceCode,todayDateText,nowTimestamp,todayDate);
-
-            //# 将新设备编号加入在线缓存 #
-            cacheService.putDeviceToOnline(farmId, deviceCode,todayDateText);
-        }
-
-        //--设备在线统计表
-        //--设备状态每日统计表
-        //--设备和耳标总状态表
-
-//        test1(farmId,deviceCode);
-
-//        //# 心跳数加1,更改在线统计数据表(MySQL),更新Redis; #
-//        deviceService.updateDeviceRegister(deviceCode);
-//
-//        //# 心跳数加1,更改在线统计数据表(MySQL),更新Redis; #
-//        deviceService.updateDeviceOnline(deviceCode);
-//
-//        //# 处理状态数据 #
-//        deviceService.updateFarmDeviceStatus(deviceCode);
-    }
-
-//    private void test1(String farmId, String deviceCode) {
-////            String deviceCode = "202007239999869";
-//////            Map map = new HashMap<>();
-//////            map.put("name","栋舍");
-//////            map.put("id","001");
-//////            System.out.println("map>>"+map.toString());
-////            String deviceRegHashKey = "device_register_"+deviceCode;
-////            //为hash结构设置多个键值对(hmset)
-//////        redisTemplate.opsForHash().putAll(deviceRegHashKey, map);
-////
-////
-//////            Object actObj = redisTemplate.opsForHash().get(deviceCode, "act");
-//////            System.out.println("actObj>>"+actObj);
-////        Object nameObj = redisTemplate.opsForHash().get(deviceRegHashKey,"name");
-////        System.out.println("nameObj>>"+nameObj.toString());
-//
-////        System.out.println("test1()");
-////        redisTemplate.opsForSet().add("testSet", "java");
-////
-////        //定义一个set集合并设置集合值
-////         SetOperations<String, String> set = redisTemplate.opsForSet();
-////         set.add("set1","22");
-////         set.add("set1","33");
-////         set.add("set1","44");
-////         // 通过key获取set集合中的对象值
-////         Set<String> resultSet = redisTemplate.opsForSet().members("set1");
-////         System.out.println("resultSet>>"+resultSet);
-//        SetOperations<String, String> set = redisTemplate.opsForSet();
-//        set.add(BizConst.SET_FARM_DEVICE_ONLINE_PREFIX + farmId, deviceCode);
-//
-//        Set<String> resultSet = redisTemplate.opsForSet().members(BizConst.SET_FARM_DEVICE_ONLINE_PREFIX + farmId);
-//        System.out.println(BizConst.SET_FARM_DEVICE_ONLINE_PREFIX + farmId + " >>" + resultSet);
-//    }
-
-    /**
-     * @Method : processDeviceTemp
-     * @Description : 处理设备温度数据
-     * @Params : [RawMap]
-     * @Return : void
-     * @Author : ZhuoNing
-     * @Date : 2022/2/15
-     * @Time : 9:05
-     */
-//    @RabbitListener(queues = Const.QUEUE_DEVICE_TEMP)
-    @RabbitHandler
-    public void processDeviceTemp(Map DeviceTempMap) throws ParseException {
-        System.out.println("333 <<<<<<<<<<<<<<< 处理设备温度数据>>" + DeviceTempMap.toString());
-        JSONObject deviceJo = JSON.parseObject(DeviceTempMap.get("deviceTemp").toString());
-        String deviceCode = deviceJo.getString("device");
-        System.out.println("333 设备编号>>" + deviceCode);
-        //--保存设备注册数据(MySQL,Redis)
-        //--保存设备状态数据(MySQL,Redis)
-
-        //--设备在线统计表
-        //--设备状态每日统计表
-        //--设备和耳标总状态表
-        //获取牧场id
-        String farmId = deviceService.getFarmIdByDeviceCode(deviceCode);
-
-//        test1(farmId,deviceCode);
-//        //# 处理状态数据 #
-//        deviceService.updateFarmDeviceStatus(deviceCode);
-
-        //# 判断在线缓存集合中是否存在该设备 #
-        //# 如果存在:
-        //      (1)更新设备在线数据[envtemp_total++,envtemp_first_time,envtemp_last_time]
-        //      (2)更新注册设备数据[active_status=1,active_time]
-        //# 如果不存在:
-        //      (A) 更新总状态表;
-        //      (B)更新设备注册表;
-        //      (C)更新在线统计;
-        //      (D)将设备好加入到在线缓存集合当中;
-        String todayDateText = new DateUtil().getTodayDateText();
-        Date todayDate = new Date(new java.util.Date().getTime());
-        Timestamp nowTimestamp = new Timestamp(new java.util.Date().getTime());
-        //判断该设备编号是否存在牧场缓存在线集合当中;
-        if (cacheService.isExistDeviceOnlineSet(farmId, deviceCode,todayDateText)) {
-//            System.out.println("## ++++");
-            //# 更新在线统计 #
-            deviceService.updateDeviceOnlineWithEnvtemp(farmId, deviceCode);
-//            System.out.println("## ++++1");
-            //# 更新设备注册表 #
-            deviceService.updateDeviceRegister(farmId, deviceCode,nowTimestamp);
-//            System.out.println("## ++++2");
-        } else {
-            //Step1:更新总状态表[device_online+1,device_offline-1,device_rate],预先判断该数据是否存在,如果不存在要先添加记录,如果存在就修改数据
-            //Step2:更新设备注册表[active_status=1,active_time=当前时间]
-            //Step3:更新在线统计[],预先判断该数据是否存在,如果不存在要先添加记录,如果存在就修改数据
-            //Step4:将新设备编号加入缓存
-//            System.out.println("## ----");
-            //# 更新总状态表 #
-            deviceService.updateEnvtempOfDeviceAllStatus(farmId, deviceCode);
-//            System.out.println("## ----1");
-            //# 更新设备注册表 #
-            deviceService.updateDeviceRegister(farmId, deviceCode,nowTimestamp);
-//            System.out.println("## ----2");
-            //# 更新在线统计 #
-            deviceService.updateDeviceOnlineWithEnvtemp(farmId, deviceCode);
-//            System.out.println("## ----3");
-            //# 将新设备编号加入在线缓存 #
-            cacheService.putDeviceToOnline(farmId, deviceCode, todayDateText);
-            System.out.println("## END");
-        }
-    }
-}

+ 0 - 124
huimv-eartag2-platform/huimv-eartag2-process2/src/main/java/com/huimv/eartag2/process2/listener/EartagListener.java

@@ -1,124 +0,0 @@
-package com.huimv.eartag2.process2.listener;
-
-import com.alibaba.fastjson.JSON;
-import com.alibaba.fastjson.JSONObject;
-import com.huimv.eartag2.common.dao.repo.EartagEartagRegisterRepo;
-import com.huimv.eartag2.common.mq.Const;
-import com.huimv.eartag2.common.utils.BizConst;
-import com.huimv.eartag2.common.utils.DateUtil;
-import com.huimv.eartag2.process2.producer.ProcessProducer;
-import com.huimv.eartag2.process2.service.ICacheService;
-import com.huimv.eartag2.process2.service.IDeviceService;
-import com.huimv.eartag2.process2.service.IEartagService;
-import lombok.extern.slf4j.Slf4j;
-import org.springframework.amqp.rabbit.annotation.RabbitHandler;
-import org.springframework.amqp.rabbit.annotation.RabbitListener;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.beans.factory.annotation.Value;
-import org.springframework.stereotype.Component;
-
-import java.sql.Date;
-import java.sql.Timestamp;
-import java.text.ParseException;
-import java.util.Map;
-
-/**
- * @Project : huimv.shiwan
- * @Package : com.huimv.biosafety.uface.controller
- * @Description : TODO
- * @Version : 1.0
- * @Author : ZhuoNing
- * @Create : 2020-12-25
- **/
-@Component
-@Slf4j
-public class EartagListener {
-    @Autowired
-    private ProcessProducer processProducer;
-    @Autowired
-    private ICacheService cacheService;
-    @Autowired
-    private IDeviceService deviceService;
-    @Autowired
-    private IEartagService eartagService;
-    @Autowired
-    private EartagEartagRegisterRepo eartagRegisterRepo;
-    @Value("${redis.expire.eartag_online_set}")
-    private Integer eartagOnlineSetExpire;
-
-    /**
-     * @Method : processRawdata
-     * @Description : 订阅耳标数据队列数据
-     * @Params : [RawMap]
-     * @Return : void
-     * @Author : ZhuoNing
-     * @Date : 2022/2/15
-     * @Time : 8:55
-     */
-//    @RabbitListener(queues = Const.QUEUE_EARTAG)
-    @RabbitHandler
-    public void processRawdata(Map RawMap) throws ParseException {
-        System.out.println("444 <<<<<<<<<<<<<<< 处理耳标数据>>" + RawMap.toString());
-        JSONObject eartagJo = JSON.parseObject(RawMap.get("eartag").toString());
-        //设备编码
-        String deviceCode = eartagJo.getString("device");
-//        System.out.println("444 设备编号>>" + deviceCode);
-        //耳标号
-        String earmark = eartagJo.getString("earmark");
-//        System.out.println("444 耳标号>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>" + earmark);
-
-        //--保存设备注册数据(MySQL,Redis)
-        //--保存设备状态数据(MySQL,Redis)
-        String todayDateText = new DateUtil().getTodayDateText();
-        Date todayDate = new Date(new java.util.Date().getTime());
-        Timestamp nowTimestamp = new Timestamp(new java.util.Date().getTime());
-
-//        System.out.println("## eartagOnlineSetExpire>>"+eartagOnlineSetExpire);
-        //--设备在线统计表
-        //--设备状态每日统计表
-        //--设备和耳标总状态表
-        //获取牧场id
-        String farmId = deviceService.getFarmIdByDeviceCode(deviceCode);
-//        String askText = RawMap.get("askText").toString();
-////        System.out.println("askText>>" + askText);
-////        JSONObject dataJo = new JSONObject();
-////        dataJo.put("name", "tony");
-////        processProducer.sendHeartbeat(dataJo);
-////        System.out.println("再发送心跳 >>>>>>>>>>>>>>>>>"+dataJo.toJSONString());
-        //--保存耳标注册数据(MySQL,Redis)-processProducer
-        //--保存耳标在线数据(MySQL,Redis)-processProducer
-        //--保存耳标状态数据(MySQL,Redis)-processProducer
-
-        //判断该设备编号是否存在牧场缓存在线集合当中;
-        if (cacheService.isExistEartagOnlineSet(farmId, earmark,todayDateText)) {
-            //Step1:更新耳标在线统计数据[上传记录数、最后上传时间、环境温度数据、耳标温度数据]
-            //Step2:更新耳标注册表中统计数据[活动状态、活动状态更新时间]
-
-            //Step1:更新耳标在线统计数据
-            eartagService.updateEartagOnline(earmark,deviceCode,todayDateText,todayDate,nowTimestamp,eartagJo,farmId);
-
-            //Step2:更新耳标注册表中统计数据
-            eartagService.updateEartagRegister(earmark,deviceCode,nowTimestamp,farmId);
-//            System.out.println("## 4.11111111111111111111111111");
-        } else {
-            //Step1:更新耳标注册数据
-            //Step2:更新耳标在线数据
-            //Step3:更新总状态数据
-            //Step4:将耳标号加入到耳标在线集合当中
-//            System.out.println("## 4.A");
-
-            //Step1:更新耳标注册数据
-            eartagService.updateEartagRegister(earmark,deviceCode,nowTimestamp,farmId);
-
-            //Step2:更新耳标在线数据
-            eartagService.updateEartagOnline(earmark,deviceCode,todayDateText,todayDate,nowTimestamp,eartagJo,farmId);
-
-            //Step3:更新总状态数据
-            eartagService.updateEartagOfAllStatus(earmark,deviceCode,todayDateText,farmId);
-
-            //Step4:将耳标号加入到耳标在线集合当中
-            cacheService.putEartagToOnlineInSet(farmId, earmark,todayDateText);
-        }
-
-    }
-}

+ 0 - 33
huimv-eartag2-platform/huimv-eartag2-process2/src/main/java/com/huimv/eartag2/process2/producer/ProcessProducer.java

@@ -1,33 +0,0 @@
-package com.huimv.eartag2.process2.producer;
-
-import com.alibaba.fastjson.JSONObject;
-import com.huimv.eartag2.common.mq.Const;
-import org.springframework.amqp.rabbit.core.RabbitTemplate;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.stereotype.Component;
-
-import java.util.HashMap;
-import java.util.Map;
-
-/**
- * @Project : huimv.shiwan
- * @Package : com.huimv.biosafety.uface.controller
- * @Description : TODO
- * @Version : 1.0
- * @Author : ZhuoNing
- * @Create : 2020-12-25
- **/
-@Component
-public class ProcessProducer {
-    @Autowired
-    RabbitTemplate rabbitTemplate;  //使用RabbitTemplate,这提供了接收/发送等等方法
-
-    //处理心跳数据
-    public String sendHeartbeat(JSONObject dataJo) {
-        Map map = new HashMap();
-        map.put("heartbeat",dataJo.toString());
-        rabbitTemplate.convertAndSend(Const.EXCHANGE_DEVICE, Const.ROUTING_KEY_DEVICE_HEARTBEAT, map);
-        System.out.println("sendHeartbeat>>>>>>>>>>>"+dataJo.toJSONString());
-        return "ok";
-    }
-}

+ 0 - 62
huimv-eartag2-platform/huimv-eartag2-process2/src/main/java/com/huimv/eartag2/process2/service/ICacheService.java

@@ -1,62 +0,0 @@
-package com.huimv.eartag2.process2.service;
-
-import com.huimv.eartag2.common.dao.entity.*;
-
-import java.text.ParseException;
-import java.util.Map;
-
-public interface ICacheService {
-    //证是否存在当天总状态数据
-    Boolean isExistTodayFarmAllStatus(String deviceCode) throws ParseException;
-
-    //
-    Object getFarmIdByDeviceCode(String deviceCode);
-
-    //
-    Object getCreateDateByFarmId(String farmId);
-
-    //
-    void putFarmAllStatusCache(String farmId, EartarFarmAllStatusEntity farmAllStatusEntity) throws ParseException;
-
-    //
-    void putAllFarmAllStatusCache(String farmId, EartarFarmAllStatusEntity farmAllStatusEntity) throws ParseException;
-
-    //
-    void flashAllStatusCache(String farmId, EartarFarmAllStatusEntity farmAllStatusEntity);
-
-    //判断是否在线状态
-    boolean isExistDeviceOnlineSet(String farmId, String deviceCode, String todayDateText);
-
-    //将deviceCode加入到在线缓存当中
-    void putDeviceToOnline(String farmId, String deviceCode, String todayDateText);
-
-    //
-    void putDeviceRegister(String deviceCode, EartagDeviceRegisterEntity deviceRegisterEntity);
-
-    //将设备数据保存到在线数据中
-    void putDeviceInOnline(String deviceOnlineHashKey, EartagDeviceOnlineEntity eartagDeviceOnlineEntity);
-
-    //
-    boolean isExistEartagOnlineSet(String farmId, String earmark, String todayDateText);
-
-
-    void putEartagToOnlineInSet(String farmId, String earmark, String todayDateText) throws ParseException;
-
-    //从缓存读取在线耳标数量
-    void getEartagOnlineTotalFromCache(String farmId, String todayDateText);
-
-    //更新耳标注册消息缓存
-    void putEartagRegister(String earmark, EartagEartagRegisterEntity eartagRegisterEntity);
-
-    //更新耳标在线统计
-    void putEartagOnlineCount(String earmark, EartagEartagOnlineEntity eartagOnlineEntity);
-
-    //
-    Integer getDeviceTotal(String farmId);
-
-    //读取全部注册信息
-    Map<Object, Object> getDeviceRegister(String farmId);
-
-    //读取属性
-    Object getDeviceRegisterProperty(String deviceCode, String deviceAlias);
-}

+ 0 - 41
huimv-eartag2-platform/huimv-eartag2-process2/src/main/java/com/huimv/eartag2/process2/service/IDeviceService.java

@@ -1,41 +0,0 @@
-package com.huimv.eartag2.process2.service;
-
-import java.sql.Date;
-import java.sql.Timestamp;
-import java.text.ParseException;
-import java.util.Map;
-
-public interface IDeviceService {
-    // 保存在线数据
-    void saveDeviceOnline(Map deviceMap);
-
-    //保存状态数据
-    void saveDeviceStatus(Map deviceMap);
-
-    //更新设备注册数据
-    void updateDeviceRegister(String deviceCode);
-
-    //更新设备在线数据
-    void updateDeviceOnline(String deviceCode) throws ParseException;
-
-    //处理状态数据
-    void updateFarmDeviceStatus(String deviceCode) throws ParseException;
-
-    //
-    String getFarmIdByDeviceCode(String deviceCode);
-
-    //更新设备注册信息
-    void updateDeviceRegister(String farmId, String deviceCode, Timestamp nowTimestamp);
-
-    //更新设备在线信息
-    void updateDeviceOnlineCount(String farmId, String deviceCode, String todayDateText, Timestamp nowTimestamp, Date todayDate) throws ParseException;
-
-    //更新设备总状态信息
-    void updateDeviceAllStatus(String farmId, String deviceCode, String todayDateText, Timestamp nowTimestamp, Date todayDate) throws ParseException;
-
-    //更新设备在线表中的环境温度参数
-    void updateDeviceOnlineWithEnvtemp(String farmId, String deviceCode) throws ParseException;
-
-    //更新总状态中的环境温度
-    void updateEnvtempOfDeviceAllStatus(String farmId, String deviceCode) throws ParseException;
-}

+ 0 - 22
huimv-eartag2-platform/huimv-eartag2-process2/src/main/java/com/huimv/eartag2/process2/service/IEartagService.java

@@ -1,22 +0,0 @@
-package com.huimv.eartag2.process2.service;
-
-import com.alibaba.fastjson.JSONObject;
-
-import java.sql.Date;
-import java.sql.Timestamp;
-
-public interface IEartagService {
-    //
-    void updateEartagRegister(String earmark, String deviceCode, Timestamp nowTimestamp, String farmId);
-    //
-    void updateEartagOnline(String earmark, String deviceCode, String todayDateText, Date todayDate, Timestamp nowTimestamp, JSONObject eartagJo, String farmId);
-    //
-    void updateEartagOfAllStatus(String earmark, String deviceCode, String todayDateText,String farmId);
-
-
-    //读取耳标注册数据
-    Integer getEartagRegTotalByFarmId(String farmId);
-
-    //计算耳标在线数量
-    int getEartagOnelineTotal(String farmId, String todayDateText);
-}

+ 0 - 377
huimv-eartag2-platform/huimv-eartag2-process2/src/main/java/com/huimv/eartag2/process2/service/impl/CacheServiceImpl.java

@@ -1,377 +0,0 @@
-package com.huimv.eartag2.process2.service.impl;
-
-import com.huimv.eartag2.common.dao.entity.*;
-import com.huimv.eartag2.common.dao.repo.EartagDeviceRegisterRepo;
-import com.huimv.eartag2.common.utils.BizConst;
-import com.huimv.eartag2.common.utils.DateUtil;
-import com.huimv.eartag2.process2.service.ICacheService;
-import lombok.extern.slf4j.Slf4j;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.beans.factory.annotation.Value;
-import org.springframework.data.redis.core.RedisTemplate;
-import org.springframework.stereotype.Service;
-
-import java.text.ParseException;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Set;
-import java.util.concurrent.TimeUnit;
-
-/**
- * @Project : huimv.shiwan
- * @Package : com.huimv.biosafety.uface.controller
- * @Description : TODO
- * @Version : 1.0
- * @Author : ZhuoNing
- * @Create : 2020-12-25
- **/
-@Service
-@Slf4j
-public class CacheServiceImpl implements ICacheService {
-    @Autowired
-    private RedisTemplate redisTemplate;
-    @Autowired
-    private EartagDeviceRegisterRepo eartagDeviceRegisterRepo;
-    @Value("${redis.expire.eartag_online_set}")
-    private Integer eartagOnlineSetExpire;
-
-    @Override
-    public Boolean isExistTodayFarmAllStatus(String deviceCode) throws ParseException {
-        System.out.println("isExistTodayFarmAllStatus 2.deviceCode>>"+deviceCode);
-
-        //(1)从注册表缓存中(device_register_牧场id)取出牧场id,(2)如果缓存没有则从注册表(eartag_device_register)中查询00
-        //(1)
-        Object farmIdObj = redisTemplate.opsForHash().get(BizConst.DEVICE_REGISTER_PREFIX + deviceCode,"farmId");
-        System.out.println("2.farmIdObj>>"+farmIdObj);
-        String farmId = "";
-        if(farmIdObj != null){
-            farmId = farmIdObj.toString();
-        }else{
-            //(2)
-            EartagDeviceRegisterEntity eartagDeviceRegisterEntity = eartagDeviceRegisterRepo.getDeviceRegister(deviceCode);
-            System.out.println("2.eartagDeviceRegisterEntity>>"+eartagDeviceRegisterEntity.toString());
-            if(eartagDeviceRegisterEntity == null){
-                log.error("设备编号:"+deviceCode+",不存在.");
-                return null;
-            }
-            farmId = eartagDeviceRegisterEntity.getFarmId();
-        }
-        System.out.println("2.farmId>>"+farmId);
-        //从牧场总状态缓存中获取最近一次日期
-        Object createDateObj = redisTemplate.opsForHash().get(BizConst.FARM_ALL_STATUS_PREFIX + farmId,"createDate");
-        System.out.println("2.createDateObj>>"+createDateObj);
-        if(createDateObj == null){
-            //--总状态记录记录不存在
-            System.out.println("A.");
-            return false;
-        }else{
-            //
-            String createDate = createDateObj.toString();
-            System.out.println("缓存中上次操作日期 createDate>>"+createDate);
-            if(new DateUtil().getTodayDateText().trim().equalsIgnoreCase(createDate)){
-                //--当天记录存在,就返回true;
-                System.out.println("B.");
-                return true;
-            }else{
-                //--当天记录不存在,就返回false;
-                System.out.println("C.");
-                return false;
-            }
-        }
-    }
-
-    //# 读根据设备编码读取牧场id
-    @Override
-    public Object getFarmIdByDeviceCode(String deviceCode) {
-        Object farmIdObj = redisTemplate.opsForHash().get(BizConst.DEVICE_REGISTER_PREFIX + deviceCode,"farmId");
-        return farmIdObj;
-    }
-
-    @Override
-    public Object getCreateDateByFarmId(String farmId) {
-        return redisTemplate.opsForHash().get(BizConst.FARM_ALL_STATUS_PREFIX + farmId,"createDate");
-    }
-
-    @Override
-    public void putFarmAllStatusCache(String farmId, EartarFarmAllStatusEntity farmAllStatusEntity) throws ParseException {
-        DateUtil duObj = new DateUtil();
-        redisTemplate.opsForHash().put(BizConst.FARM_ALL_STATUS_PREFIX+farmId,"deviceOnline",farmAllStatusEntity.getDeviceOnline());
-        redisTemplate.opsForHash().put(BizConst.FARM_ALL_STATUS_PREFIX+farmId,"deviceOffline",farmAllStatusEntity.getDeviceOffline());
-        redisTemplate.opsForHash().put(BizConst.FARM_ALL_STATUS_PREFIX+farmId,"deviceRate",farmAllStatusEntity.getDeviceRate());
-        redisTemplate.opsForHash().put(BizConst.FARM_ALL_STATUS_PREFIX+farmId,"updateTime",duObj.formatDateTime(duObj.getTodayText()));
-    }
-
-    @Override
-    public void putAllFarmAllStatusCache(String farmId, EartarFarmAllStatusEntity farmAllStatusEntity) throws ParseException {
-        Map allStatusMap = new HashMap();
-//        allStatusMap.put("id",farmAllStatusEntity.getId());
-        allStatusMap.put("deviceTotal",farmAllStatusEntity.getDeviceTotal());
-        allStatusMap.put("deviceOnline",farmAllStatusEntity.getDeviceOnline());
-        allStatusMap.put("deviceOffline",farmAllStatusEntity.getDeviceOffline());
-        allStatusMap.put("deviceRate",farmAllStatusEntity.getDeviceRate());
-        allStatusMap.put("deviceCancel",farmAllStatusEntity.getDeviceCancel());
-        allStatusMap.put("eartagTotal",farmAllStatusEntity.getEartagTotal());
-        allStatusMap.put("eartagOnline",farmAllStatusEntity.getEartagOnline());
-        allStatusMap.put("farmId",farmId);
-//        allStatusMap.put("updateTime",duObj.formatDateTime(duObj.getTodayText()));
-//        allStatusMap.put("createDate",duObj.getTodayDate());
-        allStatusMap.put("updateTime",farmAllStatusEntity.getUpdateTime());
-        allStatusMap.put("createDate",farmAllStatusEntity.getCreateDate());
-
-        System.out.println("allStatusMap>>"+allStatusMap.toString());
-        redisTemplate.opsForHash().putAll(BizConst.FARM_ALL_STATUS_PREFIX+farmId, allStatusMap);
-    }
-
-    @Override
-    public void flashAllStatusCache(String farmId, EartarFarmAllStatusEntity farmAllStatusEntity) {
-        Map allStatusMap = new HashMap();
-//        allStatusMap.put("id",farmAllStatusEntity.getId());
-        allStatusMap.put("deviceTotal",farmAllStatusEntity.getDeviceTotal());
-        allStatusMap.put("deviceOnline",farmAllStatusEntity.getDeviceOnline());
-        allStatusMap.put("deviceOffline",farmAllStatusEntity.getDeviceOffline());
-        allStatusMap.put("deviceRate",farmAllStatusEntity.getDeviceRate());
-        allStatusMap.put("deviceCancel",farmAllStatusEntity.getDeviceCancel());
-        allStatusMap.put("eartagTotal",farmAllStatusEntity.getEartagTotal());
-        allStatusMap.put("eartagOnline",farmAllStatusEntity.getEartagOnline());
-        allStatusMap.put("farmId",farmId);
-//        allStatusMap.put("updateTime",duObj.formatDateTime(duObj.getTodayText()));
-//        allStatusMap.put("createDate",duObj.getTodayDate());
-        allStatusMap.put("updateTime",farmAllStatusEntity.getUpdateTime());
-        allStatusMap.put("createDate",farmAllStatusEntity.getCreateDate());
-
-        System.out.println("allStatusMap>>"+allStatusMap.toString());
-        redisTemplate.opsForHash().putAll(BizConst.FARM_ALL_STATUS_PREFIX+farmId, allStatusMap);
-    }
-
-    @Override
-    public boolean isExistDeviceOnlineSet(String farmId, String deviceCode, String todayDateText) {
-        return redisTemplate.opsForSet().isMember(BizConst.SET_FARM_DEVICE_ONLINE_PREFIX + farmId+"_"+todayDateText, deviceCode);
-    }
-
-    /**
-     * @Method      : putDeviceCode
-     * @Description : 将新的设备编号加入到缓存当中;
-     * @Params      : [farmId, deviceCode]
-     * @Return      : void
-     *
-     * @Author      : ZhuoNing
-     * @Date        : 2022/3/1
-     * @Time        : 13:42
-     */
-    @Override
-    public void putDeviceToOnline(String farmId, String deviceCode, String todayDateText) {
-        System.out.println("## 心跳 2.4");
-        String setKey = BizConst.SET_FARM_DEVICE_ONLINE_PREFIX + farmId+"_"+todayDateText;
-        redisTemplate.opsForSet().add(setKey, deviceCode);
-        redisTemplate.expire(setKey,eartagOnlineSetExpire , TimeUnit.HOURS);
-    }
-
-    @Override
-    public void putDeviceRegister(String deviceCode, EartagDeviceRegisterEntity deviceRegisterEntity) {
-        //--更新redis中注册表数据
-        String deviceRegHashKey = BizConst.DEVICE_REGISTER_PREFIX + deviceCode;
-        //将Entity转为Map
-        Map registerMap = RegisterEntityToMap(deviceRegisterEntity);
-        redisTemplate.opsForHash().putAll(deviceRegHashKey, registerMap);
-    }
-
-    /**
-     * @Method      : putDeviceInOnline
-     * @Description : 将数据库中的在线数据更新对应的缓存数据中
-     * @Params      : [deviceOnlineHashKey, eartagDeviceOnlineEntity]
-     * @Return      : void
-     * 
-     * @Author      : ZhuoNing
-     * @Date        : 2022/3/1       
-     * @Time        : 16:07
-     */
-    @Override
-    public void putDeviceInOnline(String deviceCode, EartagDeviceOnlineEntity eartagDeviceOnlineEntity) {
-        Map map = new HashMap();
-//        map.put("id", eartagDeviceOnlineEntity.getId());
-        map.put("deviceCode", eartagDeviceOnlineEntity.getDeviceCode());
-        map.put("alias", eartagDeviceOnlineEntity.getAlias());
-        map.put("heartbeatTotal", eartagDeviceOnlineEntity.getHeartbeatTotal());
-        map.put("envtempTotal", eartagDeviceOnlineEntity.getEnvtempTotal());
-        map.put("eartagTotal", eartagDeviceOnlineEntity.getEartagTotal());
-        map.put("firstTime", eartagDeviceOnlineEntity.getFirstTime());
-        map.put("lastTime", eartagDeviceOnlineEntity.getLastTime());
-        map.put("lastEnvtemp", eartagDeviceOnlineEntity.getLastEnvtemp());
-        map.put("lastEartag", eartagDeviceOnlineEntity.getLastEartag());
-        map.put("addDate", eartagDeviceOnlineEntity.getAddDate());
-        map.put("farmId", eartagDeviceOnlineEntity.getFarmId());
-        //更新缓存
-        String deviceOnlineKey = BizConst.DEVICE_ONLINE_PREFIX + deviceCode;
-        redisTemplate.opsForHash().putAll(deviceOnlineKey, map);
-//        Map onlineMap = fromOnlineEntityToMap(newDeviceOnlineEntity);
-//        redisTemplate.opsForHash().putAll(deviceOnlineHashKey, onlineMap);
-    }
-
-    /**
-     * @Method      : isExistEartagOnlineStatus
-     * @Description : 
-     * @Params      : [farmId, earmark]
-     * @Return      : boolean
-     * 
-     * @Author      : ZhuoNing
-     * @Date        : 2022/3/1       
-     * @Time        : 21:18
-     */
-    @Override
-    public boolean isExistEartagOnlineSet(String farmId, String earmark, String todayDateText) {
-//        redisTemplate.opsForSet().add(BizConst.SET_FARM_DEVICE_ONLINE_PREFIX + farmId+"_"+todayDateText, earmark);
-        String setKey = BizConst.SET_FARM_EARMARK_ONLINE_PREFIX + farmId+"_"+todayDateText;
-        System.out.println("## eartag.setKey .isExistEartagOnlineSet >>"+setKey+",earmark>>"+earmark);
-        return redisTemplate.opsForSet().isMember(setKey, earmark);
-    }
-
-    @Override
-    public void putEartagToOnlineInSet(String farmId, String earmark, String todayDateText) throws ParseException {
-        String setKey = BizConst.SET_FARM_EARMARK_ONLINE_PREFIX + farmId+"_"+todayDateText;
-        System.out.println("## eartag.setKey .putEartagToOnlineInSet>>"+setKey+",earmark>>"+earmark);
-        redisTemplate.opsForSet().add(setKey, earmark);
-        redisTemplate.expire(setKey,eartagOnlineSetExpire , TimeUnit.HOURS);
-//        Set<String> resultSet = redisTemplate.opsForSet().members(setKey);
-//        System.out.println("## "+setKey+">>"+resultSet.size()+" >>"+resultSet);
-    }
-
-    /**
-     * @Method      : getEartagOnlineTotalFromCache
-     * @Description : 返回集合缓存的数量;
-     * @Params      : [farmId, todayDateText]
-     * @Return      : void
-     * 
-     * @Author      : ZhuoNing
-     * @Date        : 2022/3/3       
-     * @Time        : 10:55
-     */
-    @Override
-    public void getEartagOnlineTotalFromCache(String farmId, String todayDateText) {
-        String setKey = BizConst.SET_FARM_EARMARK_ONLINE_PREFIX + farmId+"_"+todayDateText;
-        redisTemplate.opsForSet().members(setKey).size();
-    }
-
-    /**
-     * @Method      : putEartagRegister
-     * @Description : 
-     * @Params      : [earmark, eartagRegisterEntity]
-     * @Return      : void
-     * 
-     * @Author      : ZhuoNing
-     * @Date        : 2022/3/3       
-     * @Time        : 15:29
-     */
-    @Override
-    public void putEartagRegister(String earmark, EartagEartagRegisterEntity eartagRegisterEntity) {
-        Map map = new HashMap();
-//        map.put("id", eartagRegisterEntity.getId());
-        map.put("earmark",eartagRegisterEntity.getEarmark());
-        map.put("firstTime",eartagRegisterEntity.getFirstTime());
-        map.put("lastTime",eartagRegisterEntity.getLastTime());
-        map.put("firstDevice",eartagRegisterEntity.getFirstDevice());
-        map.put("belongDevice",eartagRegisterEntity.getBelongDevice());
-        map.put("lastDevice",eartagRegisterEntity.getLastDevice());
-        map.put("registerTime",eartagRegisterEntity.getRegisterTime());
-        map.put("registerType",eartagRegisterEntity.getRegisterType());
-        map.put("remark",eartagRegisterEntity.getRemark());
-        map.put("farmId",eartagRegisterEntity.getFarmId());
-        map.put("activeStatus",eartagRegisterEntity.getActiveStatus());
-        map.put("activeTime",eartagRegisterEntity.getActiveTime());
-        map.put("liveStatus",eartagRegisterEntity.getLiveStatus());
-        //更新缓存
-        String earmarkOnlineKey = BizConst.EARTAG_REGISTER_PREFIX + earmark;
-        redisTemplate.opsForHash().putAll(earmarkOnlineKey, map);
-    }
-
-    /**
-     * @Method      : putEartagOnlineCount
-     * @Description : 
-     * @Params      : [earmark, eartagOnlineEntity]
-     * @Return      : void
-     * 
-     * @Author      : ZhuoNing
-     * @Date        : 2022/3/3       
-     * @Time        : 15:29
-     */
-    @Override
-    public void putEartagOnlineCount(String earmark, EartagEartagOnlineEntity eartagOnlineEntity) {
-        Map map = new HashMap();
-//        map.put("id", eartagRegisterEntity.getId());
-        map.put("earmark",eartagOnlineEntity.getEarmark());
-        map.put("total",eartagOnlineEntity.getTotal());
-        map.put("firstTime",eartagOnlineEntity.getFirstTime());
-        map.put("lastTime",eartagOnlineEntity.getLastTime());
-        map.put("envTemp",eartagOnlineEntity.getEnvTemp());
-        map.put("eartagTemp",eartagOnlineEntity.getEartagTemp());
-        map.put("addDate",eartagOnlineEntity.getAddDate());
-        map.put("farmId",eartagOnlineEntity.getFarmId());
-        //更新缓存
-        String earmarkOnlineKey = BizConst.EARTAG_ONLINE_PREFIX + earmark;
-        redisTemplate.opsForHash().putAll(earmarkOnlineKey, map);
-    }
-
-    @Override
-    public Integer getDeviceTotal(String farmId) {
-        String valueKey = BizConst.FARM_DEVICE_TOTAL_PREFIX+farmId;
-//        String value = (String) redisTemplate.opsForValue().get(valueKey);
-//        System.out.println("## value>>"+value);
-//        redisTemplate.opsForValue().set(valueKey,"50");
-        Object obj = redisTemplate.opsForValue().get(valueKey);
-        if(obj == null){
-            return null;
-        }else{
-            return Integer.parseInt(String.valueOf(obj));
-        }
-    }
-
-    @Override
-    public Map<Object, Object> getDeviceRegister(String deviceCode) {
-        String hashKey = BizConst.DEVICE_REGISTER_PREFIX+deviceCode;
-        Map<Object, Object> entriesMap = redisTemplate.opsForHash().entries(hashKey);
-        return entriesMap;
-    }
-
-    @Override
-    public Object getDeviceRegisterProperty(String deviceCode, String fieldName) {
-        String hashKey = BizConst.DEVICE_REGISTER_PREFIX+deviceCode;
-        Object obj = redisTemplate.opsForHash().get(hashKey, fieldName);
-        return obj;
-    }
-
-
-    /**
-     * @Method : RegisterEntityToMap
-     * @Description :
-     * @Params : [deviceRegisterEntity]
-     * @Return : java.util.Map
-     * @Author : ZhuoNing
-     * @Date : 2022/2/21
-     * @Time : 14:03
-     */
-    private Map RegisterEntityToMap(EartagDeviceRegisterEntity deviceRegisterEntity) {
-        Map map = new HashMap();
-        map.put("Id", deviceRegisterEntity.getId());
-        map.put("deviceCode", deviceRegisterEntity.getDeviceCode());
-        map.put("farmId", deviceRegisterEntity.getFarmId());
-        map.put("farmName", deviceRegisterEntity.getFarmName());
-        map.put("typeF", deviceRegisterEntity.getTypeF());
-        map.put("stage", deviceRegisterEntity.getStage());
-        map.put("pigpenId", deviceRegisterEntity.getPigpenId());
-        map.put("unitId", deviceRegisterEntity.getUnitId());
-        map.put("registerTime", deviceRegisterEntity.getRegisterTime());
-        map.put("lastTime", deviceRegisterEntity.getLastTime());
-        map.put("activeStatus", deviceRegisterEntity.getActiveStatus());
-        map.put("activeTime", deviceRegisterEntity.getActiveTime());
-        map.put("deviceStatus", deviceRegisterEntity.getDeviceStatus());
-        map.put("deviceAlias", deviceRegisterEntity.getDeviceAlias());
-        map.put("location", deviceRegisterEntity.getLocation());
-        map.put("remark", deviceRegisterEntity.getRemark());
-        return map;
-    }
-
-    //#
-    public Object getValByKey(String hashKey,String key){
-        Object valueObj = redisTemplate.opsForHash().get(hashKey,key);
-        return valueObj;
-    }
-}

+ 0 - 768
huimv-eartag2-platform/huimv-eartag2-process2/src/main/java/com/huimv/eartag2/process2/service/impl/DeviceServiceImpl.java

@@ -1,768 +0,0 @@
-package com.huimv.eartag2.process2.service.impl;
-
-//import cn.hutool.core.date.DateUtil;
-
-import com.huimv.eartag2.common.dao.entity.EartagDeviceOnlineEntity;
-import com.huimv.eartag2.common.dao.entity.EartagDeviceRegisterEntity;
-import com.huimv.eartag2.common.dao.entity.EartarFarmAllStatusEntity;
-import com.huimv.eartag2.common.dao.repo.*;
-import com.huimv.eartag2.common.utils.BizConst;
-import com.huimv.eartag2.common.utils.DateUtil;
-import com.huimv.eartag2.process2.service.IDeviceService;
-//import com.huimv.eartag2.process2.utils.DateUtil;
-import com.huimv.eartag2.process2.service.ICacheService;
-import com.huimv.eartag2.process2.service.IEartagService;
-import lombok.extern.slf4j.Slf4j;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.data.redis.core.RedisTemplate;
-import org.springframework.stereotype.Service;
-
-import java.math.BigDecimal;
-import java.sql.Timestamp;
-import java.text.ParseException;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-/**
- * @Project : huimv.shiwan
- * @Package : com.huimv.biosafety.uface.controller
- * @Description : TODO
- * @Version : 1.0
- * @Author : ZhuoNing
- * @Create : 2020-12-25
- **/
-@Service
-@Slf4j
-public class DeviceServiceImpl implements IDeviceService {
-    @Autowired
-    private RedisTemplate redisTemplate;
-    @Autowired
-    private EartagDeviceRegisterRepo deviceRegisterRepo;
-    @Autowired
-    private EartagHeartbeatRepo heartbeatRepo;
-    @Autowired
-    private EartagEnvRepo envRepo;
-    //    @Value("#{device.register.prefix}")
-//    private String deviceRegisterPrefix;
-    @Autowired
-    private EartagDeviceOnlineRepo eartagDeviceOnlineRepo;
-    @Autowired
-    private ICacheService cacheService;
-    @Autowired
-    private EartarFarmAllStatusRepo eartagFarmAllStatusRepo;
-    @Autowired
-    private EartagEartagRegisterRepo eartagRegisterRepo;
-//    @Autowired
-//    private EartagDeviceRegisterRepo deviceRegisterRepo;
-    @Autowired
-    private EartagDeviceOnlineRepo deviceOnlineRepo;
-    @Autowired
-    private EartarFarmAllStatusRepo farmAllStatusRepo;
-    @Autowired
-    private IEartagService eartagService;
-
-
-    // 保存在线数据
-    @Override
-    public void saveDeviceOnline(Map deviceMap) {
-
-    }
-
-    //保存状态数据
-    @Override
-    public void saveDeviceStatus(Map deviceMap) {
-
-    }
-
-    /**
-     * @Method : updateDeviceRegister
-     * @Description : 更新设备注册数据
-     * @Params : [deviceCode]
-     * @Return : void
-     * @Author : ZhuoNing
-     * @Date : 2022/2/21
-     * @Time : 15:13
-     */
-    @Override
-    public void updateDeviceRegister(String deviceCode) {
-        System.out.println("updateDeviceRegister");
-        //--更新设备注册表(eartag_device_register.active_status)同时更新对应的Redis
-        updateRegisterActiveStatus(deviceCode);
-    }
-
-    /**
-     * @Method : updateRegisterActiveStatus
-     * @Description : 更新注册表中的心跳状态
-     * @Params : [deviceCode]
-     * @Return : void
-     * @Author : ZhuoNing
-     * @Date : 2022/2/21
-     * @Time : 15:13
-     */
-    void updateRegisterActiveStatus(String deviceCode) {
-        //--更新mysql
-        EartagDeviceRegisterEntity deviceRegisterEntity = deviceRegisterRepo.getDeviceRegister(deviceCode);
-        if (deviceRegisterEntity != null) {
-//            if(deviceRegisterEntity.getActiveStatus() == 0){
-            deviceRegisterEntity.setActiveStatus(1);
-            deviceRegisterEntity.setActiveTime(new Timestamp(new Date().getTime()));
-            deviceRegisterRepo.saveAndFlush(deviceRegisterEntity);
-//            }
-        }
-        //--更新redis中注册表数据
-        String deviceRegHashKey = BizConst.DEVICE_REGISTER_PREFIX + deviceCode;
-        //将Entity转为Map
-        Map registerMap = RegisterEntityToMap(deviceRegisterEntity);
-        redisTemplate.opsForHash().putAll(deviceRegHashKey, registerMap);
-
-//        Object nameObj = redisTemplate.opsForHash().get(deviceRegHashKey,"activeTime");
-//        System.out.println("activeTime>>"+nameObj.toString());
-    }
-
-    /**
-     * @Method : RegisterEntityToMap
-     * @Description :
-     * @Params : [deviceRegisterEntity]
-     * @Return : java.util.Map
-     * @Author : ZhuoNing
-     * @Date : 2022/2/21
-     * @Time : 14:03
-     */
-    private Map RegisterEntityToMap(EartagDeviceRegisterEntity deviceRegisterEntity) {
-        Map map = new HashMap();
-        map.put("Id", deviceRegisterEntity.getId());
-        map.put("deviceCode", deviceRegisterEntity.getDeviceCode());
-        map.put("farmId", deviceRegisterEntity.getFarmId());
-        map.put("farmName", deviceRegisterEntity.getFarmName());
-        map.put("typeF", deviceRegisterEntity.getTypeF());
-        map.put("stage", deviceRegisterEntity.getStage());
-        map.put("pigpenId", deviceRegisterEntity.getPigpenId());
-        map.put("unitId", deviceRegisterEntity.getUnitId());
-        map.put("registerTime", deviceRegisterEntity.getRegisterTime());
-        map.put("lastTime", deviceRegisterEntity.getLastTime());
-        map.put("activeStatus", deviceRegisterEntity.getActiveStatus());
-        map.put("activeTime", deviceRegisterEntity.getActiveTime());
-        map.put("deviceStatus", deviceRegisterEntity.getDeviceStatus());
-        map.put("deviceAlias", deviceRegisterEntity.getDeviceAlias());
-        map.put("location", deviceRegisterEntity.getLocation());
-        map.put("remark", deviceRegisterEntity.getRemark());
-        return map;
-    }
-
-    //更新设备在线数据
-    @Override
-    public void updateDeviceOnline(String deviceCode) throws ParseException {
-        //设备在线表 eartag_device_online.heartbeat_total
-        //更新mysql
-        //更新redis
-        //# 更新设备在线数据 #
-        updateDeviceOnlineCount(deviceCode);
-
-        //# 更新设备注册表(eartag_device_register.active_status)同时更新对应的Redis #
-//        updateRegisterActiveStatus(deviceCode);
-    }
-
-    //更新设备在线Static
-    private void updateDeviceOnlineCount(String deviceCode) throws ParseException {
-        String todayText = new DateUtil().getTodayDateText();
-        //读取在线日期
-        EartagDeviceOnlineEntity eartagDeviceOnlineEntity = eartagDeviceOnlineRepo.getDeviceOnline(deviceCode, todayText);
-        String deviceOnlineHashKey = BizConst.DEVICE_ONLINE_PREFIX + deviceCode;
-        if (eartagDeviceOnlineEntity == null) {
-            //# 新建今天在线记录(1),并将记录同步到redis(2) #
-            //查询别名
-            Object deviceAliasObj = redisTemplate.opsForHash().get(BizConst.DEVICE_REGISTER_PREFIX + deviceCode, "deviceAlias");
-            System.out.println("TEST deviceAliasObj>>" + deviceAliasObj.toString());
-            String deviceAlias = "";
-            if (deviceAliasObj != null) {
-                deviceAlias = deviceAliasObj.toString();
-            } else {
-                //从设备注册表读取设备别名
-
-                //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
-            }
-            //# 查询牧场id #
-//            Object farmIdObj = redisTemplate.opsForHash().get(BizConst.DEVICE_REGISTER_PREFIX + deviceCode,"farmId");
-            Object farmIdObj = cacheService.getFarmIdByDeviceCode(deviceCode);
-            System.out.println("TEST farmIdObj>>" + farmIdObj.toString());
-            //(1)
-            EartagDeviceOnlineEntity newEartagDeviceOnlineEntity = new EartagDeviceOnlineEntity();
-            newEartagDeviceOnlineEntity.setDeviceCode(deviceCode);
-            newEartagDeviceOnlineEntity.setAlias(deviceAlias);
-            newEartagDeviceOnlineEntity.setHeartbeatTotal(1);
-            newEartagDeviceOnlineEntity.setEnvtempTotal(0);
-            newEartagDeviceOnlineEntity.setEartagTotal(0);
-            newEartagDeviceOnlineEntity.setFirstTime(new Timestamp(new Date().getTime()));
-            newEartagDeviceOnlineEntity.setLastTime(new Timestamp(new Date().getTime()));
-            newEartagDeviceOnlineEntity.setAddDate(new java.sql.Date(new Date().getTime()));
-            newEartagDeviceOnlineEntity.setFarmId(farmIdObj.toString());
-            eartagDeviceOnlineRepo.saveAndFlush(newEartagDeviceOnlineEntity);
-            //(2)
-            //将onlineEntity转为Map
-            Map onlineMap = fromOnlineEntityToMap(newEartagDeviceOnlineEntity);
-            redisTemplate.opsForHash().putAll(deviceOnlineHashKey, onlineMap);
-        } else {
-            //# 修改今天数据库在线记录(1),并将记录同步到缓存中(2) #
-            //(1)
-            int total = eartagDeviceOnlineEntity.getHeartbeatTotal();
-            eartagDeviceOnlineEntity.setHeartbeatTotal(total + 1);
-            eartagDeviceOnlineEntity.setLastTime(new Timestamp(new Date().getTime()));
-            eartagDeviceOnlineRepo.saveAndFlush(eartagDeviceOnlineEntity);
-            //(2)
-            //将onlineEntity转为Map
-            Map onlineMap = fromOnlineEntityToMap(eartagDeviceOnlineEntity);
-            redisTemplate.opsForHash().putAll(deviceOnlineHashKey, onlineMap);
-        }
-    }
-
-    //--将onlineEntity转为Map
-    private Map fromOnlineEntityToMap(EartagDeviceOnlineEntity newEartagDeviceOnlineEntity) {
-        Map map = new HashMap();
-        map.put("id", newEartagDeviceOnlineEntity.getId());
-        map.put("deviceCode", newEartagDeviceOnlineEntity.getDeviceCode());
-        map.put("alias", newEartagDeviceOnlineEntity.getAlias());
-        map.put("heartbeatTotal", newEartagDeviceOnlineEntity.getHeartbeatTotal());
-        map.put("envtempTotal", newEartagDeviceOnlineEntity.getEnvtempTotal());
-        map.put("eartagTotal", newEartagDeviceOnlineEntity.getEartagTotal());
-        map.put("firstTime", newEartagDeviceOnlineEntity.getFirstTime());
-        map.put("lastTime", newEartagDeviceOnlineEntity.getLastTime());
-        map.put("lastEnvtemp", newEartagDeviceOnlineEntity.getLastEnvtemp());
-        map.put("lastEartag", newEartagDeviceOnlineEntity.getLastEartag());
-        map.put("addDate", newEartagDeviceOnlineEntity.getAddDate());
-        map.put("farmId", newEartagDeviceOnlineEntity.getFarmId());
-        return map;
-    }
-
-    /**
-     * @Method : updateDeviceStatus
-     * @Description : 更新设备状态数据
-     * @Params : [deviceCode]
-     * @Return : void
-     * @Author : ZhuoNing
-     * @Date : 2022/2/21
-     * @Time : 16:04
-     */
-    @Override
-    public void updateFarmDeviceStatus(String deviceCode) throws ParseException {
-        System.out.println("updateDeviceStatus 1.deviceCode>>" + deviceCode);
-        String todayDateText = new DateUtil().getTodayDateText();
-        System.out.println("1.todayDateText>>" + todayDateText);
-
-        //(1)判断牧场总状态缓存是否存在
-        Object createDateObj = checkIsExistFarmAllStatusCache(deviceCode);
-        System.out.println("## createDateObj>>"+createDateObj);
-        if (createDateObj == null) {
-            log.error("这个设备(" + deviceCode + ")的注册数据不存在,请检查具体原因.");
-            System.out.println("1.");
-            //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
-        } else if (createDateObj.toString().equalsIgnoreCase("0")) {
-            System.out.println("牧场总状态缓存记录不存在.");
-            // B流程(新建缓存)
-            handleDeviceStatus(deviceCode);
-            System.out.println("2.");
-        }else if (createDateObj.toString().trim().equalsIgnoreCase(todayDateText)) {
-            //计算在线状态,并同步到缓存
-            Object farmIdObj = cacheService.getFarmIdByDeviceCode(deviceCode);
-            countAndFlashDeviceStatus(farmIdObj.toString(),deviceCode,todayDateText);
-            System.out.println("3.");
-            //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
-        } else {
-            //缓存日期非当日日期
-            // B流程
-            handleDeviceStatus(deviceCode);
-            System.out.println("4.");
-            //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
-        }
-    }
-
-    @Override
-    public String getFarmIdByDeviceCode(String deviceCode) {
-        EartagDeviceRegisterEntity deviceRegisterEntity = deviceRegisterRepo.getDeviceRegister(deviceCode);
-        return deviceRegisterEntity.getFarmId();
-    }
-
-    /**
-     * @Method      : updateDeviceRegister
-     * @Description : 
-     * @Params      : [farmId, deviceCode]
-     * @Return      : void
-     * 
-     * @Author      : ZhuoNing
-     * @Date        : 2022/3/1       
-     * @Time        : 10:56
-     */
-    @Override
-    public void updateDeviceRegister(String farmId, String deviceCode,Timestamp nowTimestamp) {
-        System.out.println("## 心跳 1.1/2.1");
-        //--更新mysql
-        EartagDeviceRegisterEntity deviceRegisterEntity = deviceRegisterRepo.getDeviceRegister(deviceCode);
-        if (deviceRegisterEntity != null) {
-            System.out.println("## 心跳 1.1.1/2.1.1");
-            //设备注册数据存在
-            deviceRegisterEntity.setActiveStatus(1);
-            deviceRegisterEntity.setActiveTime(new Timestamp(new Date().getTime()));
-            deviceRegisterRepo.saveAndFlush(deviceRegisterEntity);
-            //更新缓存中设备注册信息
-            cacheService.putDeviceRegister(deviceCode,deviceRegisterEntity);
-        }else{
-            System.out.println("## 心跳 1.1.2/12.1.2");
-            //设备注册数据不存在
-            //新建设备注册记录
-            EartagDeviceRegisterEntity newDeviceRegisterEntity = new EartagDeviceRegisterEntity();
-            newDeviceRegisterEntity.setDeviceCode(deviceCode);
-            newDeviceRegisterEntity.setFarmId(farmId);
-            newDeviceRegisterEntity.setRegisterTime(nowTimestamp);
-            newDeviceRegisterEntity.setActiveStatus(1);
-            newDeviceRegisterEntity.setActiveTime(nowTimestamp);
-            newDeviceRegisterEntity.setDeviceStatus(1);
-            deviceRegisterRepo.saveAndFlush(newDeviceRegisterEntity);
-            //更新缓存中设备注册信息
-            cacheService.putDeviceRegister(deviceCode,newDeviceRegisterEntity);
-        }
-    }
-
-    @Override
-    public void updateDeviceOnlineCount(String farmId, String deviceCode, String todayDateText, Timestamp nowTimestamp, java.sql.Date todayDate) throws ParseException {
-        //# 先判断今天在线记录是否存在 #
-        //# 更新数据表 #
-        //# 更新缓存 #
-        System.out.println("## 心跳 1.2/2.2");
-        //
-        EartagDeviceOnlineEntity deviceOnlineEntity = deviceOnlineRepo.getDeviceOnline(deviceCode,todayDateText);
-        if(deviceOnlineEntity == null){
-            System.out.println("## 心跳 1.2.1/2.2.1");
-            //不存在;
-            EartagDeviceOnlineEntity newDeviceOnlineEntity = new EartagDeviceOnlineEntity();
-            newDeviceOnlineEntity.setDeviceCode(deviceCode);
-            newDeviceOnlineEntity.setHeartbeatTotal(1);
-            newDeviceOnlineEntity.setEnvtempTotal(0);
-            newDeviceOnlineEntity.setEartagTotal(0);
-            newDeviceOnlineEntity.setAddDate(todayDate);
-            newDeviceOnlineEntity.setHeartbeatFirstTime(nowTimestamp);
-            newDeviceOnlineEntity.setHeartbeatLastTime(nowTimestamp);
-            newDeviceOnlineEntity.setFarmId(farmId);
-            deviceOnlineRepo.saveAndFlush(newDeviceOnlineEntity);
-            //更新每天在线统计缓存
-            cacheService.putDeviceInOnline(deviceCode,newDeviceOnlineEntity);
-        }else{
-            System.out.println("## 心跳 1.2.2/2.2.2");
-            //存在;
-            int total = deviceOnlineEntity.getHeartbeatTotal();
-            deviceOnlineEntity.setHeartbeatTotal(++total);
-            deviceOnlineEntity.setHeartbeatLastTime(nowTimestamp);
-            deviceOnlineRepo.saveAndFlush(deviceOnlineEntity);
-            //更新每天在线统计缓存
-            cacheService.putDeviceInOnline(deviceCode,deviceOnlineEntity);
-        }
-
-        //--(优化思路) --//
-//        updateDeviceOnlineCount(deviceCode);
-
-    }
-    
-    /**
-     * @Method      : updateDeviceAllStatus
-     * @Description : 更新总状态
-     * @Params      : [farmId, deviceCode]
-     * @Return      : void
-     * 
-     * @Author      : ZhuoNing
-     * @Date        : 2022/3/2       
-     * @Time        : 20:51
-     */
-    @Override
-    public void updateDeviceAllStatus(String farmId, String deviceCode, String todayDateText, Timestamp nowTimestamp, java.sql.Date todayDate) throws ParseException {
-        System.out.println("## 心跳 2.3");
-        //读取一条总状态记录;
-        EartarFarmAllStatusEntity farmAllStatusEntity = farmAllStatusRepo.getOneByFarmIdAndCreateDate(farmId,todayDateText);
-        if(farmAllStatusEntity == null){
-            System.out.println("## 心跳 2.3.1");
-            //总状态记录不存在;
-            //#创建一条新总状态记录;
-            //*计算设备在线数量、离线数量、在线率*
-            int deviceTotal = getDeviceTotalByFarmIdFromDeviceRegister(farmId);
-            int onlineNum = 1;
-            int offlineNum = deviceTotal-1;
-            BigDecimal reateBd= new BigDecimal(onlineNum).divide(new BigDecimal(deviceTotal),1,BigDecimal.ROUND_HALF_UP);
-            //*计算设备注销数量*
-            int cancelNum = getDeviceCancelTotalFromDeviceRegister(farmId);
-            //#计算耳标总数
-            int eartagTotal = eartagService.getEartagRegTotalByFarmId(farmId);
-            //计算耳标在线数量
-            int eartagOnlineTotal = eartagService.getEartagOnelineTotal(farmId,todayDateText);
-            //
-            EartarFarmAllStatusEntity newFarmAllStatusEntity = new EartarFarmAllStatusEntity();
-            newFarmAllStatusEntity.setDeviceTotal(deviceTotal);
-            newFarmAllStatusEntity.setDeviceOnline(onlineNum);
-            newFarmAllStatusEntity.setDeviceOffline(offlineNum);
-            newFarmAllStatusEntity.setDeviceRate(Float.parseFloat(reateBd.toString()));
-            newFarmAllStatusEntity.setDeviceCancel(cancelNum);
-            newFarmAllStatusEntity.setEartagTotal(eartagTotal);
-            newFarmAllStatusEntity.setEartagOnline(eartagOnlineTotal);
-            newFarmAllStatusEntity.setFarmId(farmId);
-            newFarmAllStatusEntity.setUpdateTime(nowTimestamp);
-            newFarmAllStatusEntity.setCreateDate(todayDate);
-            farmAllStatusRepo.saveAndFlush(newFarmAllStatusEntity);
-            //更新总状态表缓存
-            cacheService.putAllFarmAllStatusCache(farmId,newFarmAllStatusEntity);
-        }else{
-            System.out.println("## 心跳 2.3.2");
-            //总状态记录存在;
-            //#计算设备的在线、离线、在线率,更新时间
-            int onlineNum = farmAllStatusEntity.getDeviceOnline();
-            int offlineNum = farmAllStatusEntity.getDeviceOffline();
-            int total = farmAllStatusEntity.getDeviceTotal();
-            onlineNum++;
-            offlineNum--;
-            BigDecimal reateBd= new BigDecimal(onlineNum).divide(new BigDecimal(total),1,BigDecimal.ROUND_HALF_UP);
-            farmAllStatusEntity.setDeviceOnline(onlineNum);
-            farmAllStatusEntity.setDeviceOffline(offlineNum);
-            farmAllStatusEntity.setDeviceRate(Float.parseFloat(reateBd.toString()));
-            farmAllStatusEntity.setUpdateTime(nowTimestamp);
-            System.out.println("## farmAllStatusEntity>>"+farmAllStatusEntity);
-            eartagFarmAllStatusRepo.saveAndFlush(farmAllStatusEntity);
-            //更新总状态表缓存
-            cacheService.putAllFarmAllStatusCache(farmId,farmAllStatusEntity);
-        }
-    }
-
-    //计算注销设备数量
-    private int getDeviceCancelTotalFromDeviceRegister(String farmId) {
-        List<Object[]> deviceRegList = deviceRegisterRepo.getDeviceCountByFarmId(farmId);
-        Object[] deviceRegObj = (Object[]) deviceRegList.get(0);
-        //设备总数
-        return Integer.parseInt(deviceRegObj[0].toString());
-    }
-
-    //计算设备总数
-    public int getDeviceTotalByFarmIdFromDeviceRegister(String farmId){
-        List<Object[]> deviceRegList = deviceRegisterRepo.getDeviceCountByFarmId(farmId);
-        Object[] deviceRegObj = (Object[]) deviceRegList.get(0);
-        //设备总数
-        return Integer.parseInt(deviceRegObj[0].toString());
-    }
-
-//    @Override
-    public void updateDeviceAllStatus_old1(String farmId, String deviceCode) throws ParseException {
-        String todayDateText = new DateUtil().getTodayDateText();
-        System.out.println("1.todayDateText>>" + todayDateText);
-
-        //--(优化思路)--//
-
-        //(1)判断牧场总状态缓存是否存在
-        Object createDateObj = checkIsExistFarmAllStatusCache(deviceCode);
-        System.out.println("## createDateObj>>"+createDateObj);
-        if (createDateObj == null) {
-            log.error("这个设备(" + deviceCode + ")的注册数据不存在,请检查具体原因.");
-            System.out.println("1.");
-        } else if (createDateObj.toString().equalsIgnoreCase("0")) {
-            System.out.println("牧场总状态缓存记录不存在.");
-            // B流程(新建缓存)
-            handleDeviceStatus(deviceCode);
-            System.out.println("2.");
-        }else if (createDateObj.toString().trim().equalsIgnoreCase(todayDateText)) {
-            //计算在线状态,并同步到缓存
-            Object farmIdObj = cacheService.getFarmIdByDeviceCode(deviceCode);
-            countAndFlashDeviceStatus(farmIdObj.toString(),deviceCode,todayDateText);
-            System.out.println("3.");
-        } else {
-            //缓存日期非当日日期
-            // B流程
-            handleDeviceStatus(deviceCode);
-            System.out.println("4.");
-        }
-    }
-
-    /**
-     * @Method      : updateDeviceOnlineWithEnvtemp
-     * @Description : 更新设备在线当中的环境温度参数
-     * @Params      : [farmId, deviceCode]
-     * @Return      : void
-     *
-     * @Author      : ZhuoNing
-     * @Date        : 2022/3/1
-     * @Time        : 15:11
-     */
-    @Override
-    public void updateDeviceOnlineWithEnvtemp(String farmId, String deviceCode) throws ParseException {
-//        System.out.println("## (1)/(C)");
-        //# 更新数据库
-        //# 更新在线缓存
-        String todayDateText = new DateUtil().getTodayDateText();
-//        System.out.println("1.todayDateText>>" + todayDateText);
-        //读取在线日期
-        EartagDeviceOnlineEntity eartagDeviceOnlineEntity = eartagDeviceOnlineRepo.getDeviceOnline(deviceCode, todayDateText);
-        String deviceOnlineHashKey = BizConst.DEVICE_ONLINE_PREFIX + deviceCode;
-        if (eartagDeviceOnlineEntity == null) {
-//            System.out.println("## (1.1)");
-            //不存在设备在线统计
-            //创建设备在线统计并创建缓存
-            createNewDeviceOnline(farmId,deviceCode);
-        }else{
-//            System.out.println("## (1.2)");
-            int envtempTotal = eartagDeviceOnlineEntity.getEnvtempTotal();
-//            System.out.println(">>>>>>>>>>> envtempTotal>>"+envtempTotal);
-            eartagDeviceOnlineEntity.setEnvtempTotal(++envtempTotal);
-            eartagDeviceOnlineEntity.setLastTime(new Timestamp(new Date().getTime()));
-//            System.out.println(">>>>>>>>>>> eartagDeviceOnlineEntity>>"+eartagDeviceOnlineEntity);
-            eartagDeviceOnlineRepo.saveAndFlush(eartagDeviceOnlineEntity);
-            //更新设备在线缓存数据
-            cacheService.putDeviceInOnline(deviceOnlineHashKey,eartagDeviceOnlineEntity);
-        }
-    }
-
-    @Override
-    public void updateEnvtempOfDeviceAllStatus(String farmId, String deviceCode) throws ParseException {
-//        System.out.println("## (A)");
-        String todayDateText = new DateUtil().getTodayDateText();
-        //
-        EartarFarmAllStatusEntity farmAllStatusEntity = eartagFarmAllStatusRepo.getOneByFarmIdAndCreateDate(farmId,todayDateText);
-        if(farmAllStatusEntity == null){
-//            System.out.println("## (A.1)");
-            //设备总状态表信息不存在
-            //创建设备状态记录并更新缓存cache()
-            createNewFarmAllStatus(farmId,deviceCode);
-            //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
-        }else{
-//            System.out.println("## (A.2)");
-            //设备总状态表信息存在
-            //计算设备状态并更新缓存cache(在线数+1,离线数-1,计算设备在线率)
-            int onlineNum = farmAllStatusEntity.getDeviceOnline();
-            int offlineNum = farmAllStatusEntity.getDeviceOffline();
-            int total = farmAllStatusEntity.getDeviceTotal();
-            onlineNum++;
-            offlineNum--;
-            BigDecimal rateBd= new BigDecimal(onlineNum).divide(new BigDecimal(total),1,BigDecimal.ROUND_HALF_UP);
-            farmAllStatusEntity.setDeviceOnline(onlineNum);
-            farmAllStatusEntity.setDeviceOffline(offlineNum);
-            farmAllStatusEntity.setDeviceRate(Float.parseFloat(rateBd.toString()));
-            farmAllStatusEntity.setUpdateTime(new Timestamp(new Date().getTime()));
-            eartagFarmAllStatusRepo.saveAndFlush(farmAllStatusEntity);
-            //# 同步更新牧场总状态缓存相关字段 #
-            cacheService.flashAllStatusCache(farmId,farmAllStatusEntity);
-        }
-    }
-
-    /**
-     * @Method      : createNewDeviceOnline
-     * @Description : 
-     * @Params      : [farmId, deviceCode]
-     * @Return      : void
-     * 
-     * @Author      : ZhuoNing
-     * @Date        : 2022/3/1       
-     * @Time        : 16:33
-     */
-    private void createNewDeviceOnline(String farmId, String deviceCode) {
-//        System.out.println("## (1.1.1)");
-        EartagDeviceOnlineEntity newEartagDeviceOnlineEntity = new EartagDeviceOnlineEntity();
-        newEartagDeviceOnlineEntity.setDeviceCode(deviceCode);
-        newEartagDeviceOnlineEntity.setHeartbeatTotal(0);;
-        newEartagDeviceOnlineEntity.setEnvtempTotal(1);
-        newEartagDeviceOnlineEntity.setEartagTotal(0);
-        newEartagDeviceOnlineEntity.setAddDate(new java.sql.Date(new Date().getTime()));
-        newEartagDeviceOnlineEntity.setFarmId(farmId);
-        newEartagDeviceOnlineEntity.setEnvtempFirstTime(new Timestamp(new Date().getTime()));
-        newEartagDeviceOnlineEntity.setEnvtempLastTime(new Timestamp(new Date().getTime()));
-        eartagDeviceOnlineRepo.saveAndFlush(newEartagDeviceOnlineEntity);
-        //将新建的设备在线数据更新到设备在线缓存
-        cacheService.putDeviceInOnline(BizConst.DEVICE_ONLINE_PREFIX + deviceCode,newEartagDeviceOnlineEntity);
-    }
-
-    //# 处理设备状态 #
-    private void handleDeviceStatus(String deviceCode) throws ParseException {
-        //(1)判断今天的牧场总状态记录是否存在
-        //从设备注册表读取牧场id
-        EartagDeviceRegisterEntity deviceRegisterEntity = deviceRegisterRepo.getDeviceRegister(deviceCode);
-        String farmId = "";
-        if(deviceRegisterEntity == null){
-            log.error("这个设备(" + deviceCode + ")的注册数据不存在,请检查具体原因.");
-        }else{
-            farmId = deviceRegisterEntity.getFarmId();
-        }
-        String todayDateText = new DateUtil().getTodayDateText();
-        EartarFarmAllStatusEntity farmAllStatusEntity = eartagFarmAllStatusRepo.getOneByFarmIdAndCreateDate(farmId,todayDateText);
-        if(farmAllStatusEntity == null){
-            //设备注册表信息不存在
-            //创建设备状态记录并更新缓存cache()
-            createNewFarmAllStatus(farmId,deviceCode);
-        }else{
-            //设备注册表信息存在()
-            //计算设备状态并更新缓存cache()
-            countDeviceStatus(farmId,deviceCode,todayDateText);
-        }
-    }
-
-    //# 计算在线状态,并同步到缓存 #
-    private void countDeviceStatus(String farmId,String deviceCode,String todayDateText) throws ParseException {
-        //读取牧场总状态数据(数据库记录确定存在)
-        EartarFarmAllStatusEntity farmAllStatusEntity = eartagFarmAllStatusRepo.getOneByFarmIdAndCreateDate(farmId,todayDateText);
-        //在线数+1,离线数-1,计算设备在线率
-        int onlineNum = farmAllStatusEntity.getDeviceOnline();
-        int offlineNum = farmAllStatusEntity.getDeviceOffline();
-        int total = farmAllStatusEntity.getDeviceTotal();
-        onlineNum++;
-        offlineNum--;
-        BigDecimal reateBd= new BigDecimal(onlineNum).divide(new BigDecimal(total),1,BigDecimal.ROUND_HALF_UP);
-        farmAllStatusEntity.setDeviceOnline(onlineNum);
-        farmAllStatusEntity.setDeviceOffline(offlineNum);
-        farmAllStatusEntity.setDeviceRate(Float.parseFloat(reateBd.toString()));
-        farmAllStatusEntity.setUpdateTime(new Timestamp(new Date().getTime()));
-        System.out.println("## farmAllStatusEntity>>"+farmAllStatusEntity);
-        eartagFarmAllStatusRepo.saveAndFlush(farmAllStatusEntity);
-        //# 同步更新牧场总状态缓存相关字段 #
-//        cacheService.putAllFarmAllStatusCache(farmId,farmAllStatusEntity);
-        cacheService.flashAllStatusCache(farmId,farmAllStatusEntity);
-    }
-
-    //# 计算在线状态,并同步到缓存 #
-    private void countAndFlashDeviceStatus(String farmId,String deviceCode,String todayDateText) throws ParseException {
-        //读取牧场总状态数据(数据库记录确定存在)
-        EartarFarmAllStatusEntity farmAllStatusEntity = eartagFarmAllStatusRepo.getOneByFarmIdAndCreateDate(farmId,todayDateText);
-        if(farmAllStatusEntity == null){
-            System.out.println("## farmAllStatusEntity == null");
-        }else{
-            System.out.println("## farmAllStatusEntity != null");
-        }
-        System.out.println("## farmAllStatusEntity>>"+farmAllStatusEntity.toString());
-        //在线数+1,离线数-1,计算设备在线率
-        int onlineNum = farmAllStatusEntity.getDeviceOnline();
-        int offlineNum = farmAllStatusEntity.getDeviceOffline();
-        int total = farmAllStatusEntity.getDeviceTotal();
-        onlineNum++;
-        offlineNum--;
-        BigDecimal reateBd= new BigDecimal(onlineNum).divide(new BigDecimal(total),1,BigDecimal.ROUND_HALF_UP);
-        farmAllStatusEntity.setDeviceOnline(onlineNum);
-        farmAllStatusEntity.setDeviceOffline(offlineNum);
-        farmAllStatusEntity.setDeviceRate(Float.parseFloat(reateBd.toString()));
-        System.out.println("## farmAllStatusEntity>>"+farmAllStatusEntity.toString());
-        eartagFarmAllStatusRepo.saveAndFlush(farmAllStatusEntity);
-        //# 同步更新牧场总状态缓存相关字段 #
-        cacheService.putFarmAllStatusCache(farmId,farmAllStatusEntity);
-    }
-
-    //断牧场总状态缓存是否存在
-    private Object checkIsExistFarmAllStatusCache(String deviceCode) {
-        //从缓存中获取farmId
-        Object farmIdObj = cacheService.getFarmIdByDeviceCode(deviceCode);
-        System.out.println("22.farmIdObj>>" + farmIdObj);
-        String farmId = "";
-        if (farmIdObj != null) {
-            farmId = farmIdObj.toString();
-        } else {
-            log.info("设备注册缓存里没有设备编号为" + deviceCode + "的设备注册信息");
-            //(2)
-            EartagDeviceRegisterEntity eartagDeviceRegisterEntity = deviceRegisterRepo.getDeviceRegister(deviceCode);
-            System.out.println("22.eartagDeviceRegisterEntity>>" + eartagDeviceRegisterEntity.toString());
-            if (eartagDeviceRegisterEntity == null) {
-                log.error("设备注册记录不存在设备编号为" + deviceCode + "的设备注册信息.");
-                return null;
-            } else {
-                farmId = eartagDeviceRegisterEntity.getFarmId();
-            }
-        }
-        System.out.println("22.farmId>>" + farmId);
-        //从牧场总状态缓存中获取最近一次日期
-        Object createDateObj = cacheService.getCreateDateByFarmId(farmId);
-        System.out.println("22.createDateObj>>" + createDateObj);
-        if (createDateObj == null) {
-            return "0";
-        } else {
-            return createDateObj;
-        }
-    }
-
-//    public void updateDeviceStatus_old1(String deviceCode) throws ParseException {
-//        System.out.println("updateDeviceStatus 1.deviceCode>>" + deviceCode);
-//        //# 验证是否存在当天总状态记录
-//        //(1)
-//        if (cacheService.isExistTodayFarmAllStatus(deviceCode)) {
-//            //缓存中存在该牧场当当天的总状态记录
-//            System.out.println("缓存中存在该记录:Yes");
-//            //更新总状态记录
-////            autoUpdateFarmAllStatus(deviceCode);
-//        } else {
-//            System.out.println("缓存中存在该记录:No");
-//            //# 创建总状态记录 #(缓存中没有今天的记录)
-//            createFarmAllStatus(deviceCode);
-//        }
-//    }
-
-    //# 创建总状态记录 #
-    private void createNewFarmAllStatus(String farmId,String deviceCode) {
-        System.out.println("## (A.1.1)");
-        //# 计算处于工作状态的设备总数(设备注册表)
-        List<Object[]> deviceRegList = deviceRegisterRepo.getDeviceCountByFarmId(farmId);
-        Object[] deviceRegObj = (Object[]) deviceRegList.get(0);
-        //设备总数
-        int deviceTotal = 0;
-        deviceTotal = Integer.parseInt(deviceRegObj[0].toString());
-        System.out.println("## total>>"+deviceTotal);
-        if(deviceTotal == 0){
-            log.error("该牧场没有任何处于工作状态的采集器设备.");
-            System.out.println("## (A.1.1.1)");
-        }else{
-            System.out.println("## (A.1.1.2)");
-            //# 计算耳标总数(耳标注册表)
-            int eartagTotal = 0;
-            List<Object[]> eartagRegList = eartagRegisterRepo.getEartagCountByFarmId(farmId);
-            Object[] eartagRegObj = (Object[]) eartagRegList.get(0);
-            //处于工作状态的耳标总数
-            eartagTotal = Integer.parseInt(eartagRegObj[0].toString());
-
-            int onlineNum = 1;
-            int offlineNum = deviceTotal-1;
-            BigDecimal reateBd= new BigDecimal(onlineNum).divide(new BigDecimal(deviceTotal),1,BigDecimal.ROUND_HALF_UP);
-            //MySQL:farm_all_status
-            EartarFarmAllStatusEntity farmAllStatusEntity = new EartarFarmAllStatusEntity();
-            farmAllStatusEntity.setDeviceTotal(deviceTotal);
-            farmAllStatusEntity.setDeviceOnline(onlineNum);
-            farmAllStatusEntity.setDeviceOffline(offlineNum);
-            farmAllStatusEntity.setDeviceRate(Float.parseFloat(reateBd.toString()));
-            farmAllStatusEntity.setEartagTotal(eartagTotal);
-            farmAllStatusEntity.setEartagOnline(1);
-            farmAllStatusEntity.setUpdateTime(new Timestamp(new Date().getTime()));
-            farmAllStatusEntity.setCreateDate(new java.sql.Date(new Date().getTime()));
-            eartagFarmAllStatusRepo.saveAndFlush(farmAllStatusEntity);
-
-            //Redis Cache:farm_all_status_+farmId
-            cacheService.flashAllStatusCache(farmId,farmAllStatusEntity);
-        }
-    }
-
-    //#
-    private Map getLastFarmAllStatus(String deviceCode) {
-//        farmAllStatusRepo.getLastFarmAllStatus();
-        //获取farmId,然后用farmId获取最近一天的数据
-        Object farmIdObj = cacheService.getFarmIdByDeviceCode(deviceCode);
-        System.out.println("redis.farmIdObj>>" + farmIdObj);
-        if (farmIdObj == null) {
-            //# 初始化MySQL:farm_all_status
-            initFarmAllStatus();
-        }
-
-        //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
-        return null;
-    }
-
-    //# 初始化总状态表
-    private void initFarmAllStatus() {
-        //# 计算设备总数(设备注册表)
-        int deviceTotal = 0;
-//        deviceRegisterRepo.countTotal();
-
-        //# 计算耳标总数(耳标注册表)
-        int eartagTotal = 0;
-
-        EartarFarmAllStatusEntity farmAllStatusEntity = new EartarFarmAllStatusEntity();
-        farmAllStatusEntity.setDeviceTotal(deviceTotal);
-        farmAllStatusEntity.setEartagTotal(eartagTotal);
-        eartagFarmAllStatusRepo.saveAndFlush(farmAllStatusEntity);
-
-        //同步更新redis缓存
-
-        //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
-    }
-}

+ 0 - 146
huimv-eartag2-platform/huimv-eartag2-process2/src/main/java/com/huimv/eartag2/process2/service/impl/EartagServiceImpl.java

@@ -1,146 +0,0 @@
-package com.huimv.eartag2.process2.service.impl;
-
-import com.alibaba.fastjson.JSONObject;
-import com.huimv.eartag2.common.dao.entity.EartagEartagOnlineEntity;
-import com.huimv.eartag2.common.dao.entity.EartagEartagRegisterEntity;
-import com.huimv.eartag2.common.dao.entity.EartarFarmAllStatusEntity;
-import com.huimv.eartag2.common.dao.repo.EartagEartagOnlineRepo;
-import com.huimv.eartag2.common.dao.repo.EartagEartagRegisterRepo;
-import com.huimv.eartag2.common.dao.repo.EartarFarmAllStatusRepo;
-import com.huimv.eartag2.process2.service.ICacheService;
-import com.huimv.eartag2.process2.service.IEartagService;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.stereotype.Service;
-
-import java.sql.Date;
-import java.sql.Timestamp;
-import java.util.List;
-
-/**
- * @Project : huimv.shiwan
- * @Package : com.huimv.biosafety.uface.controller
- * @Description : TODO
- * @Version : 1.0
- * @Author : ZhuoNing
- * @Create : 2020-12-25
- **/
-@Service
-public class EartagServiceImpl implements IEartagService {
-    @Autowired
-    private EartagEartagRegisterRepo eartagRegisterRepo;
-    @Autowired
-    private EartagEartagOnlineRepo eartagOnlineRepo;
-    @Autowired
-    private EartarFarmAllStatusRepo farmAllStatusRepo;
-    @Autowired
-    private ICacheService cacheService;
-
-    @Override
-    public void updateEartagRegister(String earmark, String deviceCode, Timestamp nowTimestamp, String farmId) {
-        //# 判断耳标注册表是否存在;
-        //      如果不存在就注册耳标;
-        //      如果存在就更新活动状态(active_status)和活动状态更新时间(active_time)
-        //
-        EartagEartagRegisterEntity eartagRegisterEntity = eartagRegisterRepo.getOneByEarmark(earmark,farmId);
-        if(eartagRegisterEntity == null){
-            //#创建耳标注册记录#
-            EartagEartagRegisterEntity newEartagRegisterEntity = new EartagEartagRegisterEntity();
-            newEartagRegisterEntity.setEarmark(earmark);
-            newEartagRegisterEntity.setFirstTime(nowTimestamp);
-            newEartagRegisterEntity.setLastTime(nowTimestamp);
-            newEartagRegisterEntity.setFirstDevice(deviceCode);
-            newEartagRegisterEntity.setBelongDevice(deviceCode);
-            newEartagRegisterEntity.setLastDevice(deviceCode);
-            newEartagRegisterEntity.setRegisterTime(nowTimestamp);
-            newEartagRegisterEntity.setRegisterType(1);
-            newEartagRegisterEntity.setFarmId(farmId);
-            newEartagRegisterEntity.setActiveStatus(1);
-            newEartagRegisterEntity.setActiveTime(nowTimestamp);
-            newEartagRegisterEntity.setLiveStatus(1);
-            eartagRegisterRepo.saveAndFlush(newEartagRegisterEntity);
-            //更新耳标注册消息缓存
-            cacheService.putEartagRegister(earmark,newEartagRegisterEntity);
-        }else{
-            eartagRegisterEntity.setActiveStatus(1);
-            eartagRegisterEntity.setActiveTime(nowTimestamp);
-            eartagRegisterRepo.saveAndFlush(eartagRegisterEntity);
-            //更新耳标注册消息缓存
-            cacheService.putEartagRegister(earmark,eartagRegisterEntity);
-        }
-    }
-
-    @Override
-    public void updateEartagOnline(String earmark, String deviceCode, String todayDateText, Date todayDate, Timestamp nowTimestamp, JSONObject eartagJo, String farmId) {
-        //# 判断耳标在线统计数据是否存在
-        //      存在,则更新上传记录数、最后上传时间、环境温度,耳根温度,并将上面数据更新到缓存数据中;
-        //      不存在,则创建耳标在线记录,并更新到缓存数据中;
-        //耳根温度
-        String earTemp =  eartagJo.getString("earTemp1");
-        //环境温度
-        String envTemp =  eartagJo.getString("envTemp");
-        EartagEartagOnlineEntity eartagOnlineEntity = eartagOnlineRepo.getOneByEarmarkAndFarmId(earmark,todayDateText,farmId);
-        if(eartagOnlineEntity == null){
-            //# 不存在
-            EartagEartagOnlineEntity newEartagOnlineEntity = new EartagEartagOnlineEntity();
-            newEartagOnlineEntity.setEarmark(earmark);
-            newEartagOnlineEntity.setTotal(1);
-            newEartagOnlineEntity.setFirstTime(nowTimestamp);
-            newEartagOnlineEntity.setLastTime(nowTimestamp);
-            newEartagOnlineEntity.setEnvTemp(envTemp);
-            newEartagOnlineEntity.setEartagTemp(earTemp);
-            newEartagOnlineEntity.setAddDate(todayDate);
-            newEartagOnlineEntity.setFarmId(farmId);
-            eartagOnlineRepo.saveAndFlush(newEartagOnlineEntity);
-            //更新耳标在线统计
-            cacheService.putEartagOnlineCount(earmark,newEartagOnlineEntity);
-        }else{
-            //# 存在
-            int total = eartagOnlineEntity.getTotal();
-            eartagOnlineEntity.setTotal(++total);
-            eartagOnlineEntity.setLastTime(nowTimestamp);
-            eartagOnlineEntity.setEnvTemp(envTemp);
-            eartagOnlineEntity.setEartagTemp(earTemp);
-            eartagOnlineRepo.saveAndFlush(eartagOnlineEntity);
-            //更新耳标在线统计
-            cacheService.putEartagOnlineCount(earmark,eartagOnlineEntity);
-        }
-    }
-
-    @Override
-    public void updateEartagOfAllStatus(String earmark, String deviceCode,String todayDateText, String farmId) {
-        //# 判断设备和耳标总状态表是否存在
-        //      存在:更新在线耳标数量;
-        //      不存在:创建状态
-        EartarFarmAllStatusEntity farmAllStatusEntity = farmAllStatusRepo.getOneByFarmIdAndCreateDate(farmId,todayDateText);
-        if(farmAllStatusEntity == null){
-            //#获取耳标注册数量#
-            int eartagTotal =  getEartagRegTotalByFarmId(farmId);
-            //#总状态记录不存在;
-            EartarFarmAllStatusEntity newFarmAllStatusEntity = new EartarFarmAllStatusEntity();
-            newFarmAllStatusEntity.setEartagTotal(eartagTotal);
-            newFarmAllStatusEntity.setEartagOnline(1);
-            farmAllStatusRepo.saveAndFlush(newFarmAllStatusEntity);
-        }else{
-            //#存在;
-            int total = farmAllStatusEntity.getEartagOnline();
-            farmAllStatusEntity.setEartagOnline(++total);
-            farmAllStatusRepo.saveAndFlush(farmAllStatusEntity);
-        }
-    }
-
-    //读取耳标注册数据
-    @Override
-    public Integer getEartagRegTotalByFarmId(String farmId){
-        int eartagTotal = 0;
-        List<Object[]> eartagRegList = eartagRegisterRepo.getEartagCountByFarmId(farmId);
-        Object[] eartagRegObj = (Object[]) eartagRegList.get(0);
-        //处于工作状态的耳标总数
-        return Integer.parseInt(eartagRegObj[0].toString());
-    }
-
-    @Override
-    public int getEartagOnelineTotal(String farmId, String todayDateText) {
-        cacheService.getEartagOnlineTotalFromCache(farmId,todayDateText);
-        return 0;
-    }
-}

+ 0 - 187
huimv-eartag2-platform/huimv-eartag2-process2/src/main/java/com/huimv/eartag2/process2/utils/DateUtil.java

@@ -1,187 +0,0 @@
-package com.huimv.eartag2.process2.utils;
-
-import cn.hutool.core.date.DateTime;
-import lombok.extern.slf4j.Slf4j;
-import org.springframework.stereotype.Component;
-
-import java.text.ParseException;
-import java.text.SimpleDateFormat;
-import java.util.ArrayList;
-import java.util.Calendar;
-import java.util.Date;
-
-/**
- * @Project : huimv.shiwan
- * @Package : com.huimv.biosafety.uface.controller
- * @Description : TODO
- * @Version : 1.0
- * @Author : ZhuoNing
- * @Create : 2020-12-25
- **/
-@Component
-@Slf4j
-public class DateUtil {
-
-    //格式化日期(Long --> Date)
-    public String formatLongToDate(Long longDate){
-        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
-        Date date= new Date(longDate);
-        return df.format(date);
-    }
-
-    //格式化本年
-    public String getThisYear(){
-        Calendar cal = Calendar.getInstance();
-        int year = cal.get(Calendar.YEAR);
-        return String.valueOf(year);
-    }
-
-    //格式化本月
-    public String getThisMonth(){
-        Calendar cal = Calendar.getInstance();
-        int month = cal.get(Calendar.MONTH) + 1;
-        if(String.valueOf(month).length()==1)
-        {
-            return "0"+String.valueOf(month);
-        }else{
-            return String.valueOf(month);
-        }
-    }
-
-    //格式化日期时间
-    public String formatDateTime(String dateText) throws ParseException {
-        if(dateText.indexOf("T") != -1){
-            dateText = dateText.replace("T"," ");
-        }
-        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
-        Date date = sdf.parse(dateText);
-        return sdf.format(date);
-    }
-
-    public Date parseDateTime(String dateText) throws ParseException {
-        if(dateText.indexOf("T") != -1){
-            dateText = dateText.replace("T"," ");
-        }
-        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
-        return sdf.parse(dateText);
-    }
-
-    public Long parseDateTimeLong(String dateText) throws ParseException {
-        if(dateText.indexOf("T") != -1){
-            dateText = dateText.replace("T"," ");
-        }
-        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
-        Date date = sdf.parse(dateText);
-        return date.getTime();
-    }
-
-    //
-    public Date getTodayDate() throws ParseException {
-        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
-        return sdf.parse(sdf.format(new Date()));
-    }
-
-    public Date getTodayDatetime() throws ParseException {
-        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
-        return sdf.parse(sdf.format(new Date()));
-    }
-
-    public String getTodayDateText() throws ParseException {
-        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
-        return sdf.format(new Date());
-    }
-
-    public String getTodayText() throws ParseException {
-        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
-        return sdf.format(new Date());
-    }
-
-    public String getNowText() throws ParseException {
-        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
-        return sdf.format(new Date());
-    }
-
-    public String getTodayMissionText() throws ParseException {
-        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
-        return sdf.format(new Date());
-    }
-
-    public String getStartDateInThisMonth(){
-        DateTime date = cn.hutool.core.date.DateUtil.date();
-        return (cn.hutool.core.date.DateUtil.beginOfMonth(date) + "").substring(0, 10);
-    }
-
-    public String getEndDateInThisMonth(){
-        DateTime date = cn.hutool.core.date.DateUtil.date();
-        return (date + "").substring(0, 10);
-    }
-
-    /**
-     * 获取过去或者未来 任意天内的日期数组
-     * @param intervals      intervals天内
-     * @return              日期数组
-     */
-    public ArrayList<String> test(int intervals ) {
-        ArrayList<String> pastDaysList = new ArrayList<>();
-        ArrayList<String> fetureDaysList = new ArrayList<>();
-        for (int i = 0; i <intervals; i++) {
-            pastDaysList.add(getPastDate(i));
-            fetureDaysList.add(getFetureDate(i));
-        }
-        return pastDaysList;
-    }
-
-    /**
-     * 获取过去第几天的日期
-     *
-     * @param past
-     * @return
-     */
-    public String getPastDate(int past) {
-        Calendar calendar = Calendar.getInstance();
-        calendar.set(Calendar.DAY_OF_YEAR, calendar.get(Calendar.DAY_OF_YEAR) - past);
-        Date today = calendar.getTime();
-        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
-        String result = format.format(today);
-        return result;
-    }
-
-    /**
-     * 获取未来 第 past 天的日期
-     * @param past
-     * @return
-     */
-    public String getFetureDate(int past) {
-        Calendar calendar = Calendar.getInstance();
-        calendar.set(Calendar.DAY_OF_YEAR, calendar.get(Calendar.DAY_OF_YEAR) + past);
-        Date today = calendar.getTime();
-        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
-        String result = format.format(today);
-        return result;
-    }
-
-    //重新构建日期
-    public String rebuildDateTime(String text){
-        return text.substring(0,4)+"-"+text.substring(4,6)+"-"+text.substring(6,8)+" "+text.substring(8,10)+":"+text.substring(10,12)+":"+text.substring(12,14);
-    }
-
-    public static void main(String[] args){
-        DateUtil du = new DateUtil();
-        //
-        du.test1();
-    }
-
-    private void test1() {
-        String text = "20211201104300";
-//        String text = "1234567890abcd";
-        String date = text.substring(0,4)+"-"+text.substring(4,6)+"-"+text.substring(6,8)+" "+text.substring(8,10)+":"+text.substring(10,12)+":"+text.substring(12,14);
-        System.out.println("date="+date);
-    }
-
-    //获取long时间
-    public Long getNowLong(){
-        Calendar calendar = Calendar.getInstance();
-        calendar.set(calendar.get(Calendar.YEAR),calendar.get(Calendar.MONTH),calendar.get(Calendar.DAY_OF_MONTH)-1,0,0,0);
-        return calendar.getTime().getTime();
-    }
-}

+ 0 - 107
huimv-eartag2-platform/huimv-eartag2-process2/src/main/resources/application-dev.yml

@@ -1,107 +0,0 @@
-server:
-  port: 8094
-spring:
-  application:
-    name: huimv-eartag2-process
-
-  datasource:
-    url: jdbc:mysql://192.168.1.7:3306/huimv-demo-eartag20?useUnicode=true&characterEncoding=UTF-8&useSSL=false&autoReconnect=true&serverTimezone=Asia/Shanghai
-    username: root
-    password: hm123456
-    driver-class-name: com.mysql.cj.jdbc.Driver
-  jpa:
-    show-sql: true
-    database: mysql
-    hibernate:
-      ddl-auto: update
-    database-platform: org.hibernate.dialect.MySQL5InnoDBDialect
-    open-in-view: true
-
-  #配置rabbitMq 服务器
-#  rabbitmq:
-#    host: 10.0.0.4
-#    port: 5672
-#    username: huimv
-#    password: hm123456
-#    #虚拟host 可以不设置,使用server默认host
-#    virtual-host: /
-  rabbitmq:
-    host: 192.168.1.170
-    port: 5672
-    username: admin
-    password: admin
-    #虚拟host 可以不设置,使用server默认host
-    virtual-host: /
-    listener:
-      simple:
-        acknowledge-mode: none
-
-  #redis
-  redis:
-    database: 0
-    host: 192.168.1.68
-    port: 6379
-    password: hm123456
-    timeout: 5000ms
-    jedis:
-      pool:
-        max-active: 20
-        max-wait: -1
-        max-idle: 10
-        min-idle: 0
-
-  #redis
-#  redis:
-#    database: 0
-#    host: 192.168.1.68
-#    port: 6379
-#    password: hm123456
-#    timeout: 5000ms
-#    jedis:
-#      pool:
-#        max-active: 20
-#        max-wait: -1
-#        max-idle: 10
-#        min-idle: 0
-#    lettuce:
-#      pool:
-#        max-active: 3
-#        min-idle: 2
-#        max-idle: 3
-#        max-wait: 1
-#      shutdown-timeout: 100
-
-#  data:
-#    redis:
-#      repositories:
-#        enabled: false
-
-  #是否缓存空值
-#  cache:
-#    redis:
-#      cache-null-values: false
-    #server:
-#  port: 9110
-#spring:
-#  application:
-#    name: huimv-hy-autoGetData
-#
-#  datasource:
-##    url: jdbc:mysql://47.98.175.112:3306/huimv_ql_farm_haiyan?useUnicode=true&characterEncoding=UTF-8&useSSL=false&autoReconnect=true&serverTimezone=Asia/Shanghai
-#    #    url: jdbc:mysql://36.22.189.214:3306/huimv_ql_farm?useUnicode=true&characterEncoding=UTF-8&useSSL=false&autoReconnect=true&serverTimezone=Asia/Shanghai
-#        url: jdbc:mysql://192.168.1.7:3306/huimv_ql_farm?useUnicode=true&characterEncoding=UTF-8&useSSL=false&autoReconnect=true&serverTimezone=Asia/Shanghai
-#    username: root
-#    password: hm123456
-#    driver-class-name: com.mysql.cj.jdbc.Driver
-#  jpa:
-#    properties:
-#      hibernate:
-#        enable_lazy_load_no_trans: true
-#    show-sql: true
-#    database: mysql
-#    hibernate:
-#      ddl-auto: update
-#    database-platform: org.hibernate.dialect.MySQL5InnoDBDialect
-#    open-in-view: true
-
-

+ 0 - 3
huimv-eartag2-platform/huimv-eartag2-process2/src/main/resources/application.properties

@@ -1,3 +0,0 @@
-spring.profiles.active=dev
-device.register.prefix=device_register_
-redis.expire.eartag_online_set=25

+ 0 - 68
huimv-eartag2-platform/huimv-eartag2-process2/src/test/java/com/huimv/eartag2/process2/utils/RedisUtil.java

@@ -1,68 +0,0 @@
-package com.huimv.eartag2.process2.utils;
-
-import org.junit.Assert;
-import org.junit.Test;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.boot.test.context.SpringBootTest;
-import org.springframework.data.redis.core.RedisTemplate;
-
-import javax.annotation.Resource;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Map;
-import java.util.Set;
-
-/**
- * @Project : huimv.shiwan
- * @Package : com.huimv.biosafety.uface.controller
- * @Description : TODO
- * @Version : 1.0
- * @Author : ZhuoNing
- * @Create : 2020-12-25
- **/
-@SpringBootTest
-public class RedisUtil {
-//    @Autowired
-//    private RedisTemplate redisTemplate;
-    @Resource
-    private RedisTemplate redisTemplate;
-
-    @Test
-    public void redisSetTest() {
-        redisTemplate.opsForSet().add("testSet", "java");
-        Assert.assertTrue(redisTemplate.opsForSet().isMember("testSet", "java"));
-        redisTemplate.opsForSet().add("testSet", "python");
-        Assert.assertTrue(redisTemplate.opsForSet().isMember("testSet", "python"));
-        redisTemplate.opsForSet().add("testSet", "perl");
-        Assert.assertTrue(redisTemplate.opsForSet().isMember("testSet", "perl"));
-        Set<String> stringSet = new HashSet<>();
-        stringSet.add("java");
-        stringSet.add("python");
-        stringSet.add("perl");
-        Assert.assertEquals(redisTemplate.opsForSet().members("testSet"), stringSet);
-        Assert.assertFalse(redisTemplate.opsForSet().isMember("testSet",
-                redisTemplate.opsForSet().pop("testSet")));
-        Assert.assertFalse(redisTemplate.opsForSet().isMember("testSet",
-                redisTemplate.opsForSet().pop("testSet")));
-        Assert.assertFalse(redisTemplate.opsForSet().isMember("testSet",
-                redisTemplate.opsForSet().pop("testSet")));
-    }
-
-    @Test
-    public void test1(){
-//        System.out.println("test1");
-//        String deviceCode = "202007239999869";
-//        Map map = new HashMap<>();
-//        map.put("name","栋舍");
-//        map.put("id","001");
-//        System.out.println("map>>"+map.toString());
-//        //为hash结构设置多个键值对(hmset)
-////        redisTemplate.opsForHash().putAll("device_register_"+deviceCode, map);
-//
-//
-//        Object actObj = redisTemplate.opsForHash().get(deviceCode, "act");
-//        System.out.println("actObj>>"+actObj);
-        System.out.println("test1");
-    }
-
-}

+ 0 - 26
huimv-eartag2-platform/huimv-eartag2-process2/src/test/java/com/huimv/eartag2/process2/utils/TypeTest.java

@@ -1,26 +0,0 @@
-package com.huimv.eartag2.process2.utils;
-
-import org.junit.Test;
-import org.springframework.boot.test.context.SpringBootTest;
-
-/**
- * @Project : huimv.shiwan
- * @Package : com.huimv.biosafety.uface.controller
- * @Description : TODO
- * @Version : 1.0
- * @Author : ZhuoNing
- * @Create : 2020-12-25
- **/
-@SpringBootTest
-public class TypeTest {
-    @Test
-    public void test(){
-        String deviceCode= "202007239999869";
-        System.out.println("deviceCode>>"+deviceCode);
-//        int deviceCodeInt = Integer.parseInt(deviceCode);
-//        System.out.println("deviceCodeInt>>"+deviceCodeInt);
-        Long deviceCodeLong = Long.parseLong(deviceCode);
-        System.out.println("deviceCodeLong>>"+deviceCodeLong);
-
-    }
-}