Kaynağa Gözat

处理process2中保存心跳;

zhuoning 3 yıl önce
ebeveyn
işleme
39db78f11c
32 değiştirilmiş dosya ile 1152 ekleme ve 97 silme
  1. 15 2
      huimv-eartag2-platform/huimv-eartag2-common/src/main/java/com/huimv/eartag2/common/mq/Const.java
  2. 1 1
      huimv-eartag2-platform/huimv-eartag2-input/src/main/java/com/huimv/eartag2/utils/DateUtil.java
  3. 90 0
      huimv-eartag2-platform/huimv-eartag2-common/src/main/java/com/huimv/eartag2/common/utils/MathUtil.java
  4. 2 2
      huimv-eartag2-platform/huimv-eartag2-input/src/main/java/com/huimv/eartag2/config/TopicRabbitMQConfig.java
  5. 5 2
      huimv-eartag2-platform/huimv-eartag2-input/src/main/java/com/huimv/eartag2/producer/Producer.java
  6. 2 2
      huimv-eartag2-platform/huimv-eartag2-input/src/main/java/com/huimv/eartag2/server/EartagServerHandler.java
  7. 60 12
      huimv-eartag2-platform/huimv-eartag2-input/src/main/java/com/huimv/eartag2/server/EartagServerHandler2.java
  8. 9 3
      huimv-eartag2-platform/huimv-eartag2-input/src/main/java/com/huimv/eartag2/service/impl/DataServiceImpl.java
  9. 187 0
      huimv-eartag2-platform/huimv-eartag2-input/src/main/java/com/huimv/eartag2/utils/DateUtil2.java
  10. 1 1
      huimv-eartag2-platform/huimv-eartag2-input/src/main/java/com/huimv/eartag2/utils/MathUtil.java
  11. 31 0
      huimv-eartag2-platform/huimv-eartag2-input/src/main/java/com/huimv/eartag2/utils/RegexUtil.java
  12. 33 28
      huimv-eartag2-platform/huimv-eartag2-process/pom.xml
  13. 4 1
      huimv-eartag2-platform/huimv-eartag2-process/src/main/java/com/huimv/eartag2/process/HuimvEartag2ProcessApplication.java
  14. 68 0
      huimv-eartag2-platform/huimv-eartag2-process/src/main/java/com/huimv/eartag2/process/config/TopicRabbitMQConfig.java
  15. 33 34
      huimv-eartag2-platform/huimv-eartag2-process/src/main/java/com/huimv/eartag2/process/listener/DeviceListener.java
  16. 25 3
      huimv-eartag2-platform/huimv-eartag2-process/src/main/java/com/huimv/eartag2/process/producer/ProcessProducer.java
  17. 1 1
      huimv-eartag2-platform/huimv-eartag2-process/src/main/java/com/huimv/eartag2/process/service/IDeviceService.java
  18. 42 3
      huimv-eartag2-platform/huimv-eartag2-process/src/main/java/com/huimv/eartag2/process/service/impl/DeviceServiceImpl.java
  19. 43 1
      huimv-eartag2-platform/huimv-eartag2-process/src/main/java/com/huimv/eartag2/process/service/impl/EartagServiceImpl.java
  20. 2 1
      huimv-eartag2-platform/huimv-eartag2-process/src/main/java/com/huimv/eartag2/process/utils/MathUtil.java
  21. 3 0
      huimv-eartag2-platform/huimv-eartag2-process/src/main/resources/application-dev.yml
  22. 73 0
      huimv-eartag2-platform/huimv-eartag2-process2/pom.xml
  23. 24 0
      huimv-eartag2-platform/huimv-eartag2-process2/src/main/java/com/huimv/eartag2/process2/HuimvEartag2Process2Application.java
  24. 63 0
      huimv-eartag2-platform/huimv-eartag2-process2/src/main/java/com/huimv/eartag2/process2/config/TopicRabbitMQConfig.java
  25. 65 0
      huimv-eartag2-platform/huimv-eartag2-process2/src/main/java/com/huimv/eartag2/process2/listener/DeviceListener.java
  26. 55 0
      huimv-eartag2-platform/huimv-eartag2-process2/src/main/java/com/huimv/eartag2/process2/listener/EartagListener.java
  27. 33 0
      huimv-eartag2-platform/huimv-eartag2-process2/src/main/java/com/huimv/eartag2/process2/producer/ProcessProducer.java
  28. 11 0
      huimv-eartag2-platform/huimv-eartag2-process2/src/main/java/com/huimv/eartag2/process2/service/IDeviceService.java
  29. 31 0
      huimv-eartag2-platform/huimv-eartag2-process2/src/main/java/com/huimv/eartag2/process2/service/impl/DeviceServiceImpl.java
  30. 107 0
      huimv-eartag2-platform/huimv-eartag2-process2/src/main/resources/application-dev.yml
  31. 2 0
      huimv-eartag2-platform/huimv-eartag2-process2/src/main/resources/application.properties
  32. 31 0
      huimv-eartag2-platform/pom.xml

+ 15 - 2
huimv-eartag2-platform/huimv-eartag2-common/src/main/java/com/huimv/eartag2/common/mq/Const.java

@@ -12,6 +12,19 @@ import org.springframework.stereotype.Component;
  **/
 public class Const {
     public final static String ROUTING_KEY_ASK = "topic.ask.key";
-    public final static String QUEUE_NAME_ASK = "topic.ask.queue";
-    public final static String EXCHANGE_NAME_ASK = "topic.ask.exchange";
+    public final static String QUEUE_ASK = "topic.ask.queue";
+    public final static String EXCHANGE_ASK = "topic.ask.exchange";
+
+    public final static String EXCHANGE_DEVICE = "topic.device.exchange";
+
+    public final static String QUEUE_DEVICE_HEARTBEAT = "topic.device_heartbeat.queue";
+    public final static String ROUTING_KEY_DEVICE_HEARTBEAT = "topic.device_heartbeat.key";
+
+    public final static String QUEUE_DEVICE_TEMP = "topic.device_temp.queue";
+    public final static String ROUTING_KEY_DEVICE_TEMP = "topic.device_temp.key";
+
+    public final static String EXCHANGE_EARTAG = "topic.eartag.exchange";
+    public final static String QUEUE_EARTAG = "topic.eartag.queue";
+    public final static String ROUTING_KEY_EARTAG = "topic.eartag.key";
+
 }

+ 1 - 1
huimv-eartag2-platform/huimv-eartag2-input/src/main/java/com/huimv/eartag2/utils/DateUtil.java

@@ -1,4 +1,4 @@
-package com.huimv.eartag2.utils;
+package com.huimv.eartag2.common.utils;
 
 import cn.hutool.core.date.DateTime;
 import lombok.extern.slf4j.Slf4j;

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

@@ -0,0 +1,90 @@
+package com.huimv.eartag2.common.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);
+    }
+
+}

+ 2 - 2
huimv-eartag2-platform/huimv-eartag2-input/src/main/java/com/huimv/eartag2/config/TopicRabbitMQConfig.java

@@ -24,7 +24,7 @@ public class TopicRabbitMQConfig {
 //        return new Queue(ask);
 //    }
     public Queue askQueue() {
-        return new Queue(Const.QUEUE_NAME_ASK);
+        return new Queue(Const.QUEUE_ASK);
     }
 
     //原始交换机
@@ -33,7 +33,7 @@ public class TopicRabbitMQConfig {
 //        return new TopicExchange("askExchange");
 //    }
     TopicExchange askExchange() {
-        return new TopicExchange(Const.EXCHANGE_NAME_ASK);
+        return new TopicExchange(Const.EXCHANGE_ASK);
     }
 
     @Bean

+ 5 - 2
huimv-eartag2-platform/huimv-eartag2-input/src/main/java/com/huimv/eartag2/producer/Producer.java

@@ -33,10 +33,13 @@ public class Producer {
      */
     public String sendClientAsk(String askText){
         Map map = new HashMap();
+        System.out.println("000000000000000000 >>"+askText);
         map.put("askText",askText);
+        map.put("test","askText2222222");
+        System.out.println("111111111111111111>>"+map.toString());
 //        rabbitTemplate.convertAndSend("askExchange", "topic.askText.key", map);
-        rabbitTemplate.convertAndSend(Const.EXCHANGE_NAME_ASK, Const.ROUTING_KEY_ASK, map);
-        System.out.println("保存原始数据到rabbitMQ>>"+askText);
+        rabbitTemplate.convertAndSend(Const.EXCHANGE_ASK, Const.ROUTING_KEY_ASK, map);
+        System.out.println("保存原始数据到rabbitMQ>>"+map.toString());
         return "ok";
     }
 }

+ 2 - 2
huimv-eartag2-platform/huimv-eartag2-input/src/main/java/com/huimv/eartag2/server/EartagServerHandler.java

@@ -1,7 +1,7 @@
 package com.huimv.eartag2.server;
 
 import com.huimv.eartag2.service.IDataService;
-import com.huimv.eartag2.utils.DateUtil;
+import com.huimv.eartag2.utils.DateUtil2;
 import io.netty.buffer.ByteBuf;
 import io.netty.channel.ChannelHandler.Sharable;
 import io.netty.channel.ChannelHandlerContext;
@@ -24,7 +24,7 @@ public class EartagServerHandler extends ChannelInboundHandlerAdapter {
     @Autowired
     private IDataService eartagDataService;
     @Autowired
-    private DateUtil dateUtil;
+    private DateUtil2 dateUtil;
 
     @Override
     public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {

+ 60 - 12
huimv-eartag2-platform/huimv-eartag2-input/src/main/java/com/huimv/eartag2/server/EartagServerHandler2.java

@@ -2,7 +2,8 @@ package com.huimv.eartag2.server;
 
 import com.alibaba.fastjson.JSONArray;
 import com.huimv.eartag2.service.IDataService;
-import com.huimv.eartag2.utils.DateUtil;
+import com.huimv.eartag2.utils.DateUtil2;
+import com.huimv.eartag2.utils.RegexUtil;
 import io.netty.buffer.ByteBuf;
 import io.netty.buffer.Unpooled;
 import io.netty.channel.ChannelHandler;
@@ -31,7 +32,9 @@ public class EartagServerHandler2 extends ChannelInboundHandlerAdapter {
     @Autowired
     private IDataService eartagDataService;
     @Autowired
-    private DateUtil dateUtil;
+    private DateUtil2 dateUtil;
+    @Autowired
+    private RegexUtil regexUtil;
 
 //    @Override
 //    public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
@@ -47,18 +50,63 @@ public class EartagServerHandler2 extends ChannelInboundHandlerAdapter {
     @Override
     public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
         ByteBuf data = (ByteBuf) msg;
-        String clientAsk = data.toString(CharsetUtil.UTF_8);
-        //--拆分粘包数据
-        JSONArray askJa = getPerData(clientAsk);
-        for (int a = 0; a < askJa.size(); a++) {
+        String clientAskText = data.toString(CharsetUtil.UTF_8);
+        System.out.println("### 服务端接收数据 >>"+clientAskText);
+        int countPlus = regexUtil.countPlus(clientAskText);
+        //方式1
+//        if(clientAskText.length() <=18){
+        //方式2
+        if(countPlus < 4){
+            System.out.println("当前数据为不完整数据,故丢弃.>>"+clientAskText);
+        }else{
             //--处理客户端请求数据
-            String answer = eartagDataService.handleClientAsk(askJa.getString(a), ctx);
+            System.out.println("000拆分粘包之前数据 clientAskText>>"+clientAskText);
+            //--拆分粘包数据
+            JSONArray askJa = getPerData(clientAskText);
+            for (int a = 0; a < askJa.size(); a++) {
+                //--处理客户端请求数据
+                String answer = eartagDataService.handleClientAsk(askJa.getString(a), ctx);
+                if (answer != null) {
+                    log.info("###应答响应>>" + answer + "\n");
+                    ctx.writeAndFlush(Unpooled.copiedBuffer(answer.getBytes()));
+                } else {
+                    log.info("###应答数据>>" + answer + ",不需要应答。\n");
+                }
+            }
+        }
+    }
+
+//    @Override
+    public void channelRead_old1(ChannelHandlerContext ctx, Object msg) throws Exception {
+        ByteBuf data = (ByteBuf) msg;
+        String clientAskText = data.toString(CharsetUtil.UTF_8);
+        System.out.println("### 服务端接收数据 >>"+clientAskText);
+        if(clientAskText.length() <=18){
+            System.out.println("当前数据为不完整数据,故丢弃.>>"+clientAskText);
+        }else{
+            //--处理客户端请求数据
+//            String answer = eartagDataService.handleClientAsk(clientAskText, ctx);
+////            String answer = eartagDataService.handleClientAsk(clientAsk, ctx);
+//            if (answer != null) {
+//                log.info("###应答响应>>" + answer + "\n");
+//                ctx.writeAndFlush(Unpooled.copiedBuffer(answer.getBytes()));
+//            } else {
+//                log.info("###应答数据>>" + answer + ",不需要应答。\n");
+//            }
+
+            System.out.println("000拆分粘包之前数据 clientAskText>>"+clientAskText);
+//            --拆分粘包数据
+            JSONArray askJa = getPerData(clientAskText);
+            for (int a = 0; a < askJa.size(); a++) {
+                //--处理客户端请求数据
+                String answer = eartagDataService.handleClientAsk(askJa.getString(a), ctx);
 //            String answer = eartagDataService.handleClientAsk(clientAsk, ctx);
-            if (answer != null) {
-                log.info("###应答响应>>" + answer + "\n");
-                ctx.writeAndFlush(Unpooled.copiedBuffer(answer.getBytes()));
-            } else {
-                log.info("###应答数据>>" + answer + ",不需要应答。\n");
+                if (answer != null) {
+                    log.info("###应答响应>>" + answer + "\n");
+                    ctx.writeAndFlush(Unpooled.copiedBuffer(answer.getBytes()));
+                } else {
+                    log.info("###应答数据>>" + answer + ",不需要应答。\n");
+                }
             }
         }
     }

+ 9 - 3
huimv-eartag2-platform/huimv-eartag2-input/src/main/java/com/huimv/eartag2/service/impl/DataServiceImpl.java

@@ -14,7 +14,8 @@ import com.huimv.eartag2.producer.Producer;
 import com.huimv.eartag2.service.IDataService;
 import com.huimv.eartag2.service.IDeviceService;
 import com.huimv.eartag2.service.IEartagService;
-import com.huimv.eartag2.utils.DateUtil;
+import com.huimv.eartag2.utils.DateUtil2;
+import com.huimv.eartag2.utils.RegexUtil;
 import io.netty.channel.ChannelHandlerContext;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.amqp.rabbit.core.RabbitTemplate;
@@ -44,7 +45,7 @@ import java.util.Map;
 @Slf4j
 public class DataServiceImpl implements IDataService {
     @Autowired
-    private DateUtil dateUtil;
+    private DateUtil2 dateUtil;
     @Autowired
     private RedisTemplate redisTemplate;
     @Autowired
@@ -63,12 +64,17 @@ public class DataServiceImpl implements IDataService {
     private IEartagService eartagService;
     @Autowired
     private Producer producer;
+    @Autowired
+    private RegexUtil regexUtil;
 
     //处理接收数据
     @Override
     public String handleClientAsk(String askText, ChannelHandlerContext ctx) throws ParseException {
+        System.out.println("000拆分粘包之后数据>>"+askText);
         //--对接收的上报数据解析
         String answer = parseAskText2(askText);
+//        int countPlus = regexUtil.countPlus(askText);
+//        System.out.println("############### countPlus>>"+countPlus);
         //--将原始数据保存到rabbitMQ
         producer.sendClientAsk(askText);
         return answer;
@@ -327,7 +333,7 @@ public class DataServiceImpl implements IDataService {
             }
             return answer;
         } else if (cmdHeader.trim().equalsIgnoreCase("zj")) {
-            //应答数据
+            //耳标应答数据(不需要应答)
             answer = null;
         } else {
             log.error("##当前请求数据为非法数据>>" + askText);

+ 187 - 0
huimv-eartag2-platform/huimv-eartag2-input/src/main/java/com/huimv/eartag2/utils/DateUtil2.java

@@ -0,0 +1,187 @@
+package com.huimv.eartag2.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 DateUtil2 {
+
+    //格式化日期(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){
+        DateUtil2 du = new DateUtil2();
+        //
+        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();
+    }
+}

+ 1 - 1
huimv-eartag2-platform/huimv-eartag2-input/src/main/java/com/huimv/eartag2/utils/MathUtil.java

@@ -14,7 +14,7 @@ import java.text.NumberFormat;
  * @Create : 2020-12-25
  **/
 @Component
-public class MathUtil {
+public class MathUtil2 {
 
     public static double A = 0.00335396319311466;
     public static double B = 0.000256376549039663;

+ 31 - 0
huimv-eartag2-platform/huimv-eartag2-input/src/main/java/com/huimv/eartag2/utils/RegexUtil.java

@@ -0,0 +1,31 @@
+package com.huimv.eartag2.utils;
+
+import org.springframework.stereotype.Component;
+
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+/**
+ * @Project : huimv.shiwan
+ * @Package : com.huimv.biosafety.uface.controller
+ * @Description : TODO
+ * @Version : 1.0
+ * @Author : ZhuoNing
+ * @Create : 2020-12-25
+ **/
+@Component
+public class RegexUtil {
+
+    //计算+出现的次数
+    public int countPlus(String str) {//创建countSpace方法用于统计文本的空格个数
+        int count = 0;//创建一个返回值count
+//        Pattern p = Pattern.compile("\\s");//将给定的正则表达式编译并赋予给Pattern类
+        Pattern p = Pattern.compile("\\+");//将给定的正则表达式编译并赋予给Pattern类
+        Matcher m = p.matcher(str);//生成一个给定命名的Matcher对象
+        while(m.find()){//查找类似于Matcher对象的字符
+            count++;//count自加作为标记
+        }
+        return count;//返回count值
+    }
+
+}

+ 33 - 28
huimv-eartag2-platform/huimv-eartag2-process/pom.xml

@@ -24,37 +24,42 @@
             <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>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>

+ 4 - 1
huimv-eartag2-platform/huimv-eartag2-process/src/main/java/com/huimv/eartag2/process/HuimvEartag2ProcessApplication.java

@@ -3,6 +3,7 @@ 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.context.annotation.ComponentScan;
 import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
 
 /**
@@ -13,9 +14,11 @@ import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
  * @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")
+@SpringBootApplication
 public class HuimvEartag2ProcessApplication {
     public static void main(String[] args) {
         SpringApplication.run(HuimvEartag2ProcessApplication.class, args);

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

@@ -0,0 +1,68 @@
+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);
+    }
+
+}

+ 33 - 34
huimv-eartag2-platform/huimv-eartag2-process/src/main/java/com/huimv/eartag2/process/listener/DeviceListener.java

@@ -2,6 +2,7 @@ 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;
@@ -13,6 +14,7 @@ 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;
@@ -29,7 +31,7 @@ import java.util.Map;
 @Component
 @Slf4j
 //@RabbitListener(queues = "topic.device")
-public class DeviceListener {
+public class FlowListener {
     @Autowired
     private MathUtil mathUtil;
     @Autowired
@@ -53,58 +55,52 @@ public class DeviceListener {
     }
 
 //    @RabbitListener(queues = "topic.askText.queue")
-    @RabbitListener(queues = Const.QUEUE_NAME_ASK)
+    @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,Redis)-processProducer
-                //保存设备在线数据(MySQL,Redis)-processProducer
-                //保存设备状态数据(MySQL,Redis)-processProducer
-                //保存设备心跳流水数据(MySQL)
-                //++++++++++++++++++++++++++++++++++++++++++++++
-                //
-                deviceService.saveDeviceHartbeat(dataJo);
-                //
-                processProducer.sendDeviceMain(dataJo);
+                //--保存设备心跳流水数据(MySQL)
+
+                //保存心跳流水数据
+                deviceService.saveDeviceHeartbeat(dataJo);
+                //发送心跳数据到MQ
+                processProducer.sendHeartbeat(dataJo);
                 break;
             case "device-temp":
                 //--(2)处理环境数据
-                //保存设备注册数据(MySQL,Redis)-processProducer
-                //保存设备环境流水数据(MySQL)
-                //++++++++++++++++++++++++++++++++++++++++++++++
-                //
+                //--保存设备环境流水数据(MySQL)
+
+                //保存设备环境温度流水数据
                 deviceService.saveDeviceTemp(dataJo);
-                //
-                processProducer.sendRegisterMain(dataJo);
+                //发送设备环境温度数据到MQ
+                processProducer.sendDeviceTemp(dataJo);
                 break;
             case "eartag":
                 //--(3)处理耳标数据
-                //保存耳标注册数据(MySQL,Redis)-processProducer
-                //保存耳标在线数据(MySQL,Redis)-processProducer
-                //保存耳标状态数据(MySQL,Redis)-processProducer
-                //保存耳标流水数据(MySQL)
-                //++++++++++++++++++++++++++++++++++++++++++++++
-                //
+                //--保存耳标流水数据(MySQL)
+
+                //保存耳标流水数据
                 eartagService.saveEartag(dataJo);
-                //
-                processProducer.sendEartagMain(dataJo);
+                //发送耳标数据到MQ
+                processProducer.sendEartag(dataJo);
                 break;
             default:
         }
-        System.out.println(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
         //保存原始数据//
         deviceService.saveRawdata(askText);
     }
@@ -149,7 +145,7 @@ public class DeviceListener {
                 log.error("##当前数据为非法数据>>" + askText);
             }
         } else if (cmdHeader.trim().equalsIgnoreCase("zj")) {
-            String device = dataArray[1];
+//            String device = dataArray[1];
             //-- 耳标数据 --//
             //计算耳标温度
             Double earTemp = 0D;
@@ -157,8 +153,11 @@ public class DeviceListener {
             if (other != null && other.trim().length() > 0) {
                 String[] otherArray = other.split("#");
                 String resi = otherArray[2];
-                Double temp = MathUtil.ln(Integer.parseInt(resi));
-                earTemp = new BigDecimal(temp).setScale(1, BigDecimal.ROUND_HALF_UP).doubleValue();
+                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]);

+ 25 - 3
huimv-eartag2-platform/huimv-eartag2-process/src/main/java/com/huimv/eartag2/process/producer/ProcessProducer.java

@@ -1,10 +1,14 @@
 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
@@ -18,12 +22,30 @@ public class ProcessProducer {
     @Autowired
     RabbitTemplate rabbitTemplate;  //使用RabbitTemplate,这提供了接收/发送等等方法
 
-    public void sendDeviceMain(JSONObject dataJo) {
+    //处理心跳数据
+    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 void sendRegisterMain(JSONObject dataJo) {
+    //处理环境温度数据
+    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 void sendEartagMain(JSONObject dataJo) {
+    //处理耳标数据
+    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";
     }
 }

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

@@ -6,7 +6,7 @@ import java.text.ParseException;
 
 public interface IDeviceService {
     //保存心跳数据
-    void saveDeviceHartbeat(JSONObject dataJo);
+    void saveDeviceHeartbeat(JSONObject dataJo);
     //保存设备温度数据
     void saveDeviceTemp(JSONObject dataJo);
     //保存采集器上传的原始数据

+ 42 - 3
huimv-eartag2-platform/huimv-eartag2-process/src/main/java/com/huimv/eartag2/process/service/impl/DeviceServiceImpl.java

@@ -1,7 +1,11 @@
 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;
@@ -33,15 +37,50 @@ public class DeviceServiceImpl implements IDeviceService {
     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 saveDeviceHartbeat(JSONObject dataJo) {
-
+    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);
     }
 
     /**

+ 43 - 1
huimv-eartag2-platform/huimv-eartag2-process/src/main/java/com/huimv/eartag2/process/service/impl/EartagServiceImpl.java

@@ -10,6 +10,8 @@ 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;
 
@@ -68,8 +70,48 @@ public class EartagServiceImpl implements IEartagService {
      * @Time        : 14:33
      */
     @Override
-    public void saveEartag(JSONObject dataJo) {
+    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(Integer.parseInt(eartagJo.getString("envTemp")));
+        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;
     }
 
     /**

+ 2 - 1
huimv-eartag2-platform/huimv-eartag2-process/src/main/java/com/huimv/eartag2/process/utils/MathUtil.java

@@ -23,7 +23,7 @@ public class MathUtil {
     public static double E = -0.0000000204758173596178;
 
     //保留一位小数
-    public static double changeDouble(Double dou) {
+    public static  double changeDouble(Double dou) {
         NumberFormat nf = new DecimalFormat("0.0 ");
         dou = Double.parseDouble(nf.format(dou));
         return dou;
@@ -32,6 +32,7 @@ public class MathUtil {
     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;
     }

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

@@ -32,6 +32,9 @@ spring:
     password: admin
     #虚拟host 可以不设置,使用server默认host
     virtual-host: /
+    listener:
+      simple:
+        acknowledge-mode: none  #消费端不需要确认
 
   #redis
   redis:

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

@@ -11,5 +11,78 @@
 
     <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>

+ 24 - 0
huimv-eartag2-platform/huimv-eartag2-process2/src/main/java/com/huimv/eartag2/process2/HuimvEartag2Process2Application.java

@@ -0,0 +1,24 @@
+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
+@EntityScan(value = "com.huimv.eartag2.common.dao.entity")
+@EnableJpaRepositories(basePackages = "com.huimv.eartag2.common.dao.repo")
+public class HuimvEartag2Process2Application {
+    public static void main(String[] args) {
+        SpringApplication.run(HuimvEartag2Process2Application.class, args);
+    }
+
+}

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

@@ -0,0 +1,63 @@
+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);
+//    }
+
+}

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

@@ -0,0 +1,65 @@
+package com.huimv.eartag2.process2.listener;
+
+import com.huimv.eartag2.common.mq.Const;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.amqp.rabbit.annotation.RabbitHandler;
+import org.springframework.amqp.rabbit.annotation.RabbitListener;
+import org.springframework.stereotype.Component;
+
+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 {
+
+    /**
+     * @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 RawMap) throws ParseException {
+        System.out.println("222 <<<<<<<<<<<<<<< 处理设备心跳数据>>"+RawMap.toString());
+        //--保存设备注册数据(MySQL,Redis)-
+        //--保存设备在线数据(MySQL,Redis)-
+        //--保存设备状态数据(MySQL,Redis)-
+
+
+    }
+
+    /**
+     * @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 RawMap) throws ParseException {
+        System.out.println("333 <<<<<<<<<<<<<<< 处理设备温度数据>>"+RawMap.toString());
+        //--保存设备注册数据(MySQL,Redis)-processProducer
+        //--保存设备状态数据(MySQL,Redis)-processProducer
+
+
+
+    }
+}

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

@@ -0,0 +1,55 @@
+package com.huimv.eartag2.process2.listener;
+
+import com.alibaba.fastjson.JSONObject;
+import com.huimv.eartag2.common.mq.Const;
+import com.huimv.eartag2.process2.producer.ProcessProducer;
+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 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;
+
+    /**
+     * @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());
+//        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
+
+
+    }
+}

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

@@ -0,0 +1,33 @@
+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";
+    }
+}

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

@@ -0,0 +1,11 @@
+package com.huimv.eartag2.process2.service;
+
+import java.util.Map;
+
+public interface IDeviceService {
+    // 保存在线数据
+    void saveDeviceOnline(Map deviceMap);
+
+    //保存状态数据
+    void saveDeviceStatus(Map deviceMap);
+}

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

@@ -0,0 +1,31 @@
+package com.huimv.eartag2.process2.service.impl;
+
+import com.huimv.eartag2.process2.service.IDeviceService;
+import org.springframework.stereotype.Service;
+
+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
+public class DeviceServiceImpl implements IDeviceService {
+
+    // 保存在线数据
+    @Override
+    public void saveDeviceOnline(Map deviceMap){
+
+    }
+
+    //保存状态数据
+    @Override
+    public void saveDeviceStatus(Map deviceMap){
+
+    }
+
+}

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

@@ -0,0 +1,107 @@
+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
+
+

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

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

+ 31 - 0
huimv-eartag2-platform/pom.xml

@@ -58,8 +58,39 @@
             <groupId>org.springframework.boot</groupId>
             <artifactId>spring-boot-starter-data-redis</artifactId>
         </dependency>
+        <!-- lombok -->
+        <dependency>
+            <groupId>org.projectlombok</groupId>
+            <artifactId>lombok</artifactId>
+            <version>1.16.18</version>
+            <scope>provided</scope>
+        </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>-->
 <!--            &lt;!&ndash;  &ndash;&gt;-->