Selaa lähdekoodia

1、修改部分bug

zhuoning 3 vuotta sitten
vanhempi
commit
a6842eeb83
33 muutettua tiedostoa jossa 1115 lisäystä ja 423 poistoa
  1. 13 1
      huimv-eartag2-platform/huimv-eartag2-common/src/main/java/com/huimv/eartag2/common/dao/entity/EartagDeviceRegisterEntity.java
  2. 78 69
      huimv-eartag2-platform/huimv-eartag2-common/src/main/java/com/huimv/eartag2/common/dao/entity/EartagRawEntity.java
  3. 8 15
      huimv-eartag2-platform/huimv-eartag2-common/src/main/java/com/huimv/eartag2/common/dao/repo/EartagDeviceRegisterRepo.java
  4. 8 0
      huimv-eartag2-platform/huimv-eartag2-common/src/main/java/com/huimv/eartag2/common/utils/BizConst.java
  5. 1 1
      huimv-eartag2-platform/huimv-eartag2-common/src/main/java/com/huimv/eartag2/common/utils/DateUtil.java
  6. 8 0
      huimv-eartag2-platform/huimv-eartag2-device/src/main/java/com/huimv/eartag2/device/service/impl/DeviceServiceImpl.java
  7. 107 0
      huimv-eartag2-platform/huimv-eartag2-device/src/main/resources/application-prod.yml
  8. 25 4
      huimv-eartag2-platform/huimv-eartag2-eartag/src/main/java/com/huimv/eartag2/eartag/listener/EartagListener.java
  9. 107 0
      huimv-eartag2-platform/huimv-eartag2-eartag/src/main/resources/application-prod.yml
  10. 10 6
      huimv-eartag2-platform/huimv-eartag2-input/src/main/java/com/huimv/eartag2/producer/Producer.java
  11. 0 71
      huimv-eartag2-platform/huimv-eartag2-input/src/main/java/com/huimv/eartag2/server/EartagServer.java
  12. 0 70
      huimv-eartag2-platform/huimv-eartag2-input/src/main/java/com/huimv/eartag2/server/EartagServerHandler.java
  13. 14 19
      huimv-eartag2-platform/huimv-eartag2-input/src/main/java/com/huimv/eartag2/server/EartagServerHandler2.java
  14. 6 0
      huimv-eartag2-platform/huimv-eartag2-input/src/main/java/com/huimv/eartag2/service/ICacheService.java
  15. 8 0
      huimv-eartag2-platform/huimv-eartag2-input/src/main/java/com/huimv/eartag2/service/IDeviceService.java
  16. 27 0
      huimv-eartag2-platform/huimv-eartag2-input/src/main/java/com/huimv/eartag2/service/impl/CacheServiceImpl.java
  17. 22 11
      huimv-eartag2-platform/huimv-eartag2-input/src/main/java/com/huimv/eartag2/service/impl/DataServiceImpl.java
  18. 51 0
      huimv-eartag2-platform/huimv-eartag2-input/src/main/java/com/huimv/eartag2/service/impl/DeviceServiceImpl.java
  19. 1 1
      huimv-eartag2-platform/huimv-eartag2-input/src/main/resources/application-dev.yml
  20. 107 0
      huimv-eartag2-platform/huimv-eartag2-input/src/main/resources/application-prod.yml
  21. 6 0
      huimv-eartag2-platform/huimv-eartag2-input/src/test/java/com/huimv/eartag2/DataTest.java
  22. 48 0
      huimv-eartag2-platform/huimv-eartag2-manage/src/main/java/com/huimv/eartag2/manage/config/CorsConfig.java
  23. 37 7
      huimv-eartag2-platform/huimv-eartag2-manage/src/main/java/com/huimv/eartag2/manage/controller/DeviceController.java
  24. 44 14
      huimv-eartag2-platform/huimv-eartag2-manage/src/main/java/com/huimv/eartag2/manage/controller/DeviceRegisterController.java
  25. 3 0
      huimv-eartag2-platform/huimv-eartag2-manage/src/main/java/com/huimv/eartag2/manage/service/ICacheService.java
  26. 5 2
      huimv-eartag2-platform/huimv-eartag2-manage/src/main/java/com/huimv/eartag2/manage/service/IDeviceRegisterService.java
  27. 3 1
      huimv-eartag2-platform/huimv-eartag2-manage/src/main/java/com/huimv/eartag2/manage/service/IDeviceService.java
  28. 8 0
      huimv-eartag2-platform/huimv-eartag2-manage/src/main/java/com/huimv/eartag2/manage/service/impl/CacheServiceImpl.java
  29. 46 12
      huimv-eartag2-platform/huimv-eartag2-manage/src/main/java/com/huimv/eartag2/manage/service/impl/DeviceRegisterServiceImpl.java
  30. 177 119
      huimv-eartag2-platform/huimv-eartag2-manage/src/main/java/com/huimv/eartag2/manage/service/impl/DeviceServiceImpl.java
  31. 4 0
      huimv-eartag2-platform/huimv-eartag2-manage/src/main/java/com/huimv/eartag2/manage/service/impl/EartagServiceImpl.java
  32. 107 0
      huimv-eartag2-platform/huimv-eartag2-manage/src/main/resources/application-prod.yml
  33. 26 0
      huimv-eartag2-platform/huimv-eartag2-manage/src/test/java/com/huimv/eartag2/manage/utils/MathUtilTest.java

+ 13 - 1
huimv-eartag2-platform/huimv-eartag2-common/src/main/java/com/huimv/eartag2/common/dao/entity/EartagDeviceRegisterEntity.java

@@ -19,6 +19,9 @@ public class EartagDeviceRegisterEntity implements Serializable {
     @Column(name = "device_code")
     private String deviceCode;
 
+    @Column(name = "chip_id")
+    private String chipId;
+
     @Column(name = "county_code")
     private String countyCode;
 
@@ -55,7 +58,7 @@ public class EartagDeviceRegisterEntity implements Serializable {
     @Column(name = "active_time")
     private Timestamp activeTime;
 
-    @Column(name = "device_status")
+    @Column(name = "device_status", nullable = false)
     private Integer deviceStatus;
 
     @Column(name = "device_alias")
@@ -89,6 +92,14 @@ public class EartagDeviceRegisterEntity implements Serializable {
         return deviceCode;
     }
 
+    public void setChipId(String chipId) {
+        this.chipId = chipId;
+    }
+
+    public String getChipId() {
+        return chipId;
+    }
+
     public void setCountyCode(String countyCode) {
         this.countyCode = countyCode;
     }
@@ -238,6 +249,7 @@ public class EartagDeviceRegisterEntity implements Serializable {
         return "EartagDeviceRegisterEntity{" +
                 "id=" + id + '\'' +
                 "deviceCode=" + deviceCode + '\'' +
+                "chipId=" + chipId + '\'' +
                 "countyCode=" + countyCode + '\'' +
                 "countyName=" + countyName + '\'' +
                 "farmId=" + farmId + '\'' +

+ 78 - 69
huimv-eartag2-platform/huimv-eartag2-common/src/main/java/com/huimv/eartag2/common/dao/entity/EartagRawEntity.java

@@ -1,96 +1,105 @@
 package com.huimv.eartag2.common.dao.entity;
 
-import javax.persistence.Entity;
-import javax.persistence.Column;
-import javax.persistence.GenerationType;
-import javax.persistence.Table;
-import javax.persistence.GeneratedValue;
-import java.sql.Timestamp;
+import javax.persistence.*;
 import java.io.Serializable;
-import javax.persistence.Id;
- 
+import java.sql.Date;
+import java.sql.Timestamp;
+
 @Entity
 @Table(name = "eartag_raw")
 public class EartagRawEntity implements Serializable {
 
-private static final long serialVersionUID = 1L;
+    private static final long serialVersionUID = 1L;
 
-@Id
-@GeneratedValue(strategy = GenerationType.IDENTITY)@Column(name = "id", nullable = false)
-private Integer id;
+    @Id
+    @GeneratedValue(strategy = GenerationType.IDENTITY)
+    @Column(name = "id", nullable = false)
+    private Integer id;
 
-@Column(name = "cmd_header")
-private String cmdHeader;
+    @Column(name = "cmd_header")
+    private String cmdHeader;
 
-@Column(name = "cmd")
-private String cmd;
+    @Column(name = "cmd")
+    private String cmd;
 
-@Column(name = "device")
-private String device;
+    @Column(name = "device")
+    private String device;
 
-@Column(name = "ask")
-private String ask;
+    @Column(name = "ask")
+    private String ask;
 
-@Column(name = "add_time")
-private Timestamp addTime;
+    @Column(name = "add_time")
+    private Timestamp addTime;
 
-public  void  setId(Integer id) {
-this.id = id;
-}
+    @Column(name = "create_date")
+    private Date createDate;
 
-public Integer getId() {
-return id;
-}
+    public void setId(Integer id) {
+        this.id = id;
+    }
 
-public  void  setCmdHeader(String cmdHeader) {
-this.cmdHeader = cmdHeader;
-}
+    public Integer getId() {
+        return id;
+    }
 
-public String getCmdHeader() {
-return cmdHeader;
-}
+    public void setCmdHeader(String cmdHeader) {
+        this.cmdHeader = cmdHeader;
+    }
 
-public  void  setCmd(String cmd) {
-this.cmd = cmd;
-}
+    public String getCmdHeader() {
+        return cmdHeader;
+    }
 
-public String getCmd() {
-return cmd;
-}
+    public void setCmd(String cmd) {
+        this.cmd = cmd;
+    }
 
-public  void  setDevice(String device) {
-this.device = device;
-}
+    public String getCmd() {
+        return cmd;
+    }
 
-public String getDevice() {
-return device;
-}
+    public void setDevice(String device) {
+        this.device = device;
+    }
 
-public  void  setAsk(String ask) {
-this.ask = ask;
-}
+    public String getDevice() {
+        return device;
+    }
 
-public String getAsk() {
-return ask;
-}
+    public void setAsk(String ask) {
+        this.ask = ask;
+    }
 
-public  void  setAddTime(Timestamp addTime) {
-this.addTime = addTime;
-}
+    public String getAsk() {
+        return ask;
+    }
 
-public Timestamp getAddTime() {
-return addTime;
-}
+    public void setAddTime(Timestamp addTime) {
+        this.addTime = addTime;
+    }
 
-@Override
-public String toString() {
-return "EartagRawEntity{" +
-    "id=" + id + '\'' +
-    "cmdHeader=" + cmdHeader + '\'' +
-    "cmd=" + cmd + '\'' +
-    "device=" + device + '\'' +
-    "ask=" + ask + '\'' +
-    "addTime=" + addTime + '\'' +
-    '}';
-}
+    public Timestamp getAddTime() {
+        return addTime;
+    }
+
+    public void setCreateDate(Date createDate) {
+        this.createDate = createDate;
+    }
+
+    public Date getCreateDate() {
+        return createDate;
+    }
+
+    @Override
+    public String toString() {
+        return "EartagRawEntity{" +
+                "id=" + id + '\'' +
+                "cmdHeader=" + cmdHeader + '\'' +
+                "cmd=" + cmd + '\'' +
+                "device=" + device + '\'' +
+                "ask=" + ask + '\'' +
+                "addTime=" + addTime + '\'' +
+                "createDate=" + createDate + '\'' +
+                '}';
+    }
 }

+ 8 - 15
huimv-eartag2-platform/huimv-eartag2-common/src/main/java/com/huimv/eartag2/common/dao/repo/EartagDeviceRegisterRepo.java

@@ -8,13 +8,13 @@ import org.springframework.data.jpa.repository.Query;
 import java.util.List;
 
 public interface EartagDeviceRegisterRepo extends JpaRepository<EartagDeviceRegisterEntity, Integer>, JpaSpecificationExecutor<EartagDeviceRegisterEntity> {
-
-//    @Query(nativeQuery = true,value = "UPDATE ")
-//    void updateActiveStatus(String deviceCode);
-
     @Query(nativeQuery = true,value = "SELECT * FROM eartag_device_register WHERE device_code=?1")
     EartagDeviceRegisterEntity getDeviceRegister(String deviceCode);
 
+    @Query(nativeQuery = true,value = "SELECT * FROM eartag_device_register WHERE id=?1")
+    EartagDeviceRegisterEntity getDeviceRegisterByRowId(String id);
+
+
     @Query(nativeQuery = true,value = "SELECT COUNT(*) total FROM eartag_device_register WHERE farm_id=?1 AND device_status=1")
     List<Object[]> getDeviceCountByFarmId(String farmId);
 
@@ -24,16 +24,9 @@ public interface EartagDeviceRegisterRepo extends JpaRepository<EartagDeviceRegi
     @Query(nativeQuery = true,value = "SELECT device_code FROM eartag_device_register WHERE device_status=1")
     List<Object[]> getDeviceCodeFromDeviceRegister();
 
-    @Query(nativeQuery = true,value = "DELETE FROM eartag_device_register WHERE id IN(?1)")
-    void removeDevice(List idList);
-
-    @Query(nativeQuery = true,value = "DELETE FROM eartag_device_register")
-    void removeDevice();
-
-    @Query(nativeQuery = true,value = "SELECT device_code FROM eartag_device_register WHERE id IN(?1)")
-    List<EartagDeviceRegisterEntity> getDeviceRegisterByIds(List idList);
-
-    @Query(nativeQuery = true,value = "DELETE FROM eartag_device_register WHERE id IN(?1)")
-    void deleteBatch(List<Integer> idList);
+    @Query(nativeQuery = true,value = "SELECT * FROM eartag_device_register WHERE id=?1")
+    EartagDeviceRegisterEntity getDeviceRegisterById(Integer id);
 
+    @Query(nativeQuery = true,value = "SELECT * FROM eartag_device_register WHERE chip_id=?1")
+    EartagDeviceRegisterEntity getByChipId(String chipId);
 }

+ 8 - 0
huimv-eartag2-platform/huimv-eartag2-common/src/main/java/com/huimv/eartag2/common/utils/BizConst.java

@@ -66,6 +66,9 @@ public class BizConst {
     //耳标最新流水
     public final static String EARTAG_FLOW_PREFIX = "hash:eartag.flow:earmark:";
 
+    //芯片id和设备编码的映射
+    public final static String CHIP_DEVICE_PREFIX = "hash:chipId";
+
 
     public final static Integer CODE_DEVICE_ONLINE_NO_EXIST = 10001;
     public final static String MSG_DEVICE_ONLINE_NO_EXIST = "今天无在线设备.";
@@ -91,4 +94,9 @@ public class BizConst {
     public final static Integer CODE_DEVICE_CODE_EXIST = 10008;
     public final static String MSG_DEVICE_CODE_EXIST = "该设备编号已经存在.";
 
+    public final static Integer CODE_DEVICE_STATUS_EXIST = 10009;
+
+//    public final static Integer CODE_DEVICE_REGISTER_NO_EXIST = 10009;
+//    public final static Integer CODE_DEVICE_STATUS_EXIST = 10009;
+
 }

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

@@ -134,7 +134,7 @@ public class DateUtil {
     }
 
     public String formatDatetimeText(Date date) throws ParseException {
-        if(date == null){
+        if(date == null || date.toString().length()==0){
             return "";
         }
         SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

+ 8 - 0
huimv-eartag2-platform/huimv-eartag2-device/src/main/java/com/huimv/eartag2/device/service/impl/DeviceServiceImpl.java

@@ -334,7 +334,11 @@ public class DeviceServiceImpl implements IDeviceService {
         //3、更新在线统计表(环境温度计数,环境温度最早上传时间,最新环境温度,环境温度最后一次上传时间)
         //4、更新总状态表
         String deviceCode = dataJo.getString("device");
+        //{通过设备编码取货牧场id}
         String farmId = getFarmIdByDeviceCode(deviceCode);
+        if(farmId == null){
+            log.error("该设备编码["+deviceCode+"]的设备已经不存在。");
+        }
         String temp = dataJo.getString("temp");
         String envtemp = com.huimv.eartag2.common.utils.MathUtil.countEnvtemp(temp,2).toString();
         String todayDateText = new com.huimv.eartag2.common.utils.DateUtil().getTodayDateText();
@@ -599,6 +603,10 @@ public class DeviceServiceImpl implements IDeviceService {
     @Override
     public String getFarmIdByDeviceCode(String deviceCode) {
         EartagDeviceRegisterEntity deviceRegisterEntity = deviceRegisterRepo.getDeviceRegister(deviceCode);
+        if(deviceRegisterEntity == null){
+            log.error("该设备编码["+deviceCode+"]的设备已经不存在。");
+            return null;
+        }
         return deviceRegisterEntity.getFarmId();
     }
     /**

+ 107 - 0
huimv-eartag2-platform/huimv-eartag2-device/src/main/resources/application-prod.yml

@@ -0,0 +1,107 @@
+server:
+  port: 8092
+spring:
+  application:
+    name: huimv-eartag2-process
+
+  datasource:
+    url: jdbc:mysql://192.168.1.7:3306/huimv-eartag2-platform?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
+
+

+ 25 - 4
huimv-eartag2-platform/huimv-eartag2-eartag/src/main/java/com/huimv/eartag2/eartag/listener/EartagListener.java

@@ -59,11 +59,32 @@ public class EartagListener {
         String type = askMap.get("type").toString();
         JSONObject dataJo = (JSONObject) askMap.get("data");
         System.out.println("## dataJo>>"+dataJo);
-        if(type.trim().equalsIgnoreCase("eartag")){
-            System.out.println("askText>>"+askText);
-            //{处理耳标数据}
-            eartagService.handleEartag(dataJo);
+        //
+        String earmark = dataJo.getString("earmark");
+        System.out.println("earmark>>"+earmark);
+        //测试代码(属于测试耳标才能进行测试)
+        if(checkTestRange(earmark)){
+            if(type.trim().equalsIgnoreCase("eartag")){
+                System.out.println("askText>>"+askText);
+                //{处理耳标数据}
+                eartagService.handleEartag(dataJo);
+            }
+        }else{
+            System.out.println("非测试耳标>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
         }
+//        //正式代码
+//        if(type.trim().equalsIgnoreCase("eartag")){
+//            System.out.println("askText>>"+askText);
+//            //{处理耳标数据}
+//            eartagService.handleEartag(dataJo);
+//        }
+    }
+
+    private boolean checkTestRange(String earmark) {
+        Long c = Long.parseLong(earmark);
+        Long a = 122083123610001L;
+        Long b = 122083123610100L;
+        return (c>=a && c<b) || (c>a && c<=b);
     }
 
     /**

+ 107 - 0
huimv-eartag2-platform/huimv-eartag2-eartag/src/main/resources/application-prod.yml

@@ -0,0 +1,107 @@
+server:
+  port: 8092
+spring:
+  application:
+    name: huimv-eartag2-process
+
+  datasource:
+    url: jdbc:mysql://192.168.1.7:3306/huimv-eartag2-platform?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
+
+

+ 10 - 6
huimv-eartag2-platform/huimv-eartag2-input/src/main/java/com/huimv/eartag2/producer/Producer.java

@@ -2,6 +2,7 @@ package com.huimv.eartag2.producer;
 
 import com.alibaba.fastjson.JSONObject;
 import com.huimv.eartag2.common.mq.Const;
+import lombok.extern.slf4j.Slf4j;
 import org.springframework.amqp.rabbit.core.RabbitTemplate;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
@@ -18,6 +19,7 @@ import java.util.Map;
  * @Create : 2020-12-25
  **/
 @Component
+@Slf4j
 public class Producer {
     @Autowired
     RabbitTemplate rabbitTemplate;  //使用RabbitTemplate,这提供了接收/发送等等方法
@@ -81,11 +83,9 @@ public class Producer {
      * @Time        : 18:30
      */
     public String sendClientAsk2(String askText) {
+        askText = askText.replaceAll("\r","").replaceAll("\n","");
         Map map = new HashMap();
         map.put("askText",askText);
-
-        System.out.println("<sendClientAsk2>.map.toString()>>"+map.toString());
-
         String[] dataArray = askText.split("\\+");
         String cmdHeader = dataArray[0];
         if (cmdHeader.trim().equalsIgnoreCase("hm")) {
@@ -93,9 +93,13 @@ public class Producer {
             rabbitTemplate.convertAndSend(Const.EXCHANGE_ASK_DEVICE, Const.ROUTING_KEY_ASK_DEVICE, map);
             System.out.println("## >> 发送设备处理 ...");
         } else if (cmdHeader.trim().equalsIgnoreCase("zj")) {
-            //发送到耳标处理消息队列
-            rabbitTemplate.convertAndSend(Const.EXCHANGE_ASK_EARTAG, Const.ROUTING_KEY_ASK_EARTAG, map);
-            System.out.println("## >> 发送耳标处理 ...");
+            if(dataArray[2].trim().equalsIgnoreCase("ffffffffffffffff") || dataArray[2].trim().equalsIgnoreCase("0000000000000000")){
+                log.error("舍弃掉未配置耳标号的耳标,"+askText+"");
+            }else{
+                //发送到耳标处理消息队列
+                rabbitTemplate.convertAndSend(Const.EXCHANGE_ASK_EARTAG, Const.ROUTING_KEY_ASK_EARTAG, map);
+                System.out.println("## >> 发送耳标处理 ...");
+            }
         }
         return "ok";
     }

+ 0 - 71
huimv-eartag2-platform/huimv-eartag2-input/src/main/java/com/huimv/eartag2/server/EartagServer.java

@@ -1,71 +0,0 @@
-package com.huimv.eartag2.server;
-
-import io.netty.bootstrap.ServerBootstrap;
-import io.netty.channel.ChannelFuture;
-import io.netty.channel.ChannelInitializer;
-import io.netty.channel.EventLoopGroup;
-import io.netty.channel.nio.NioEventLoopGroup;
-import io.netty.channel.socket.SocketChannel;
-import io.netty.channel.socket.nio.NioServerSocketChannel;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.stereotype.Service;
-
-import java.net.InetSocketAddress;
-
-/**
- * @Project : huimv.shiwan
- * @Package : com.huimv.biosafety.uface.controller
- * @Description : TODO
- * @Version : 1.0
- * @Author : ZhuoNing
- * @Create : 2020-12-25
- **/
-
-//@Component
-@Service
-public class EartagServer {
-    private final static int LISTEN_PORT = 8011;
-    @Autowired
-    private EartagServerHandler serverHandler;
-
-    public static void main(String[] args) {
-        EartagServer dataServer = new EartagServer();
-        dataServer.start();
-    }
-
-    public void start() {
-        System.out.println("# 监听端口      :" + LISTEN_PORT);
-//        final EnvironServerHandler serverHandler = new EnvironServerHandler();
-        // 创建EventLoopGroup
-        EventLoopGroup bossGroup = new NioEventLoopGroup();
-        EventLoopGroup workerGroup = new NioEventLoopGroup();
-        // 创建EventLoopGroup
-        ServerBootstrap b = new ServerBootstrap();
-        b.group(bossGroup, workerGroup)
-                //指定所使用的NIO传输Channel
-                .channel(NioServerSocketChannel.class)
-                //使用指定的端口设置套接字地址
-                .localAddress(new InetSocketAddress(LISTEN_PORT))
-                // 添加一个EchoServerHandler到Channle的ChannelPipeline
-                .childHandler(new ChannelInitializer<SocketChannel>() {
-                    @Override
-                    protected void initChannel(SocketChannel socketChannel) throws Exception {
-                        //EchoServerHandler被标注为@shareable,所以我们可以总是使用同样的案例
-                        socketChannel.pipeline().addLast(serverHandler);
-                    }
-                });
-
-        try {
-            // 异步地绑定服务器;调用sync方法阻塞等待直到绑定完成
-            ChannelFuture f = b.bind().sync();
-            // 获取Channel的CloseFuture,并且阻塞当前线程直到它完成
-            f.channel().closeFuture().sync();
-        } catch (InterruptedException e) {
-            e.printStackTrace();
-        } finally {
-            // 优雅的关闭EventLoopGroup,释放所有的资源
-            bossGroup.shutdownGracefully();
-            workerGroup.shutdownGracefully();
-        }
-    }
-}

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

@@ -1,70 +0,0 @@
-package com.huimv.eartag2.server;
-
-import com.huimv.eartag2.service.IDataService;
-import com.huimv.eartag2.utils.DateUtil2;
-import io.netty.buffer.ByteBuf;
-import io.netty.channel.ChannelHandler.Sharable;
-import io.netty.channel.ChannelHandlerContext;
-import io.netty.channel.ChannelInboundHandlerAdapter;
-import io.netty.util.CharsetUtil;
-import org.springframework.beans.factory.annotation.Autowired;
-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
- **/
-@Sharable
-@Component
-public class EartagServerHandler extends ChannelInboundHandlerAdapter {
-    @Autowired
-    private IDataService eartagDataService;
-    @Autowired
-    private DateUtil2 dateUtil;
-
-    @Override
-    public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
-        //将客户端传入的消息转换为Netty的ByteBuf类型
-        ByteBuf in = (ByteBuf) msg;
-        // 在控制台打印传入的消息
-//        System.out.println(
-//                "Server received: " + in.toString(CharsetUtil.UTF_8)
-//        );
-        String askText = in.toString(CharsetUtil.UTF_8);
-        System.out.println("askText>>"+askText);
-
-        //处理接收环保实时数据
-//        eartagDataService.handleAsk(askText,ctx);
-
-        //将接收到的消息写给发送者,而不冲刷出站消息 (应答)
-//        ctx.write(askText);
-        ctx.writeAndFlush(askText);
-    }
-
-    @Override
-    public void channelReadComplete(ChannelHandlerContext ctx) throws Exception {
-        // 将未处决消息冲刷到远程节点, 并且关闭该Channel
-//        ctx.writeAndFlush(Unpooled.EMPTY_BUFFER)
-//                .addListener(ChannelFutureListener.CLOSE);
-        ctx.writeAndFlush("111");
-    }
-
-    /**
-     * 异常处理
-     *
-     * @param ctx
-     * @param cause
-     * @throws Exception
-     */
-    @Override
-    public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
-        //打印异常栈跟踪
-        cause.printStackTrace();
-        // 关闭该Channel
-        ctx.close();
-    }
-}

+ 14 - 19
huimv-eartag2-platform/huimv-eartag2-input/src/main/java/com/huimv/eartag2/server/EartagServerHandler2.java

@@ -2,6 +2,7 @@ package com.huimv.eartag2.server;
 
 import com.alibaba.fastjson.JSONArray;
 import com.huimv.eartag2.service.IDataService;
+import com.huimv.eartag2.service.IDeviceService;
 import com.huimv.eartag2.utils.DateUtil2;
 import com.huimv.eartag2.utils.RegexUtil;
 import io.netty.buffer.ByteBuf;
@@ -35,39 +36,34 @@ public class EartagServerHandler2 extends ChannelInboundHandlerAdapter {
     private DateUtil2 dateUtil;
     @Autowired
     private RegexUtil regexUtil;
-
-//    @Override
-//    public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
-//        ByteBuf data = (ByteBuf) msg;
-//        System.out.println("收到的信息为:"+data.toString(CharsetUtil.UTF_8));
-//        ctx.writeAndFlush(msg);
-////        ctx.write(msg);
-    // ctx.writeAndFlush(msg);
-// ctx.writeAndFlush(data);
-// ctx.writeAndFlush(Unpooled.copiedBuffer(askText.getBytes()));
-//    }
+    @Autowired
+    private IDeviceService deviceService;
 
     @Override
     public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
         ByteBuf data = (ByteBuf) msg;
         String clientAskText = data.toString(CharsetUtil.UTF_8);
+//        clientAskText = clientAskText.replaceAll("\r","").replaceAll("\n","");
         System.out.println("### 服务端接收数据 >>"+clientAskText);
+
+        //test-saveRawData()
+        deviceService.saveRawData(clientAskText);
+
+        //{}
         int countPlus = regexUtil.countPlus(clientAskText);
-        //方式1
-//        if(clientAskText.length() <=18){
-        //方式2
         if(countPlus < 4){
             System.out.println("当前数据为不完整数据,故丢弃.>>"+clientAskText);
         }else{
             //--处理客户端请求数据
-            System.out.println("000拆分粘包之前数据 clientAskText>>"+clientAskText);
-            //--拆分粘包数据
+//            System.out.println("000拆分粘包之前数据 clientAskText>>"+clientAskText);
+            //{拆分粘包数据}
             JSONArray askJa = getPerData(clientAskText);
             for (int a = 0; a < askJa.size(); a++) {
                 //先判断是否再所有牧场的集合当中,未登记都过滤掉;
 //                cacheService.isValidDevice(deviceCode);
-                //--处理客户端请求数据
+                //{处理客户端请求数据}
                 String answer = eartagDataService.handleClientAsk(askJa.getString(a), ctx);
+                System.out.println("## 返回应答>>"+answer);
                 if (answer != null) {
                     log.info("###应答响应>>" + answer + "\n");
                     ctx.writeAndFlush(Unpooled.copiedBuffer(answer.getBytes()));
@@ -95,8 +91,7 @@ public class EartagServerHandler2 extends ChannelInboundHandlerAdapter {
 //            } else {
 //                log.info("###应答数据>>" + answer + ",不需要应答。\n");
 //            }
-
-            System.out.println("000拆分粘包之前数据 clientAskText>>"+clientAskText);
+//            System.out.println("000拆分粘包之前数据 clientAskText>>"+clientAskText);
 //            --拆分粘包数据
             JSONArray askJa = getPerData(clientAskText);
             for (int a = 0; a < askJa.size(); a++) {

+ 6 - 0
huimv-eartag2-platform/huimv-eartag2-input/src/main/java/com/huimv/eartag2/service/ICacheService.java

@@ -0,0 +1,6 @@
+package com.huimv.eartag2.service;
+
+public interface ICacheService {
+    //{}
+    Object getDeviceCodeByChipId(String chipId);
+}

+ 8 - 0
huimv-eartag2-platform/huimv-eartag2-input/src/main/java/com/huimv/eartag2/service/IDeviceService.java

@@ -1,5 +1,7 @@
 package com.huimv.eartag2.service;
 
+import java.text.ParseException;
+
 /**
  * @Project : huimv.shiwan
  * @Package : com.huimv.biosafety.uface.controller
@@ -11,4 +13,10 @@ package com.huimv.eartag2.service;
 public interface IDeviceService {
     //处理采集器设备信息
     void handleDeviceInfo();
+
+    //保存原始数据
+    void saveRawData(String askText) throws ParseException;
+
+    //{根据芯片id读取设备编码}
+    String getDeviceCodeByChipId(String chipId);
 }

+ 27 - 0
huimv-eartag2-platform/huimv-eartag2-input/src/main/java/com/huimv/eartag2/service/impl/CacheServiceImpl.java

@@ -0,0 +1,27 @@
+package com.huimv.eartag2.service.impl;
+
+import com.huimv.eartag2.common.utils.BizConst;
+import com.huimv.eartag2.service.ICacheService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.data.redis.core.RedisTemplate;
+import org.springframework.stereotype.Service;
+
+/**
+ * @Project : huimv.shiwan
+ * @Package : com.huimv.biosafety.uface.controller
+ * @Description : TODO
+ * @Version : 1.0
+ * @Author : ZhuoNing
+ * @Create : 2020-12-25
+ **/
+@Service
+public class CacheServiceImpl implements ICacheService {
+    @Autowired
+    private RedisTemplate redisTemplate;
+
+    @Override
+    public Object getDeviceCodeByChipId(String chipId) {
+        String  hashKey = BizConst.CHIP_DEVICE_PREFIX;
+        return redisTemplate.opsForHash().get(hashKey,chipId);
+    }
+}

+ 22 - 11
huimv-eartag2-platform/huimv-eartag2-input/src/main/java/com/huimv/eartag2/service/impl/DataServiceImpl.java

@@ -70,13 +70,10 @@ public class DataServiceImpl implements IDataService {
     //处理接收数据
     @Override
     public String handleClientAsk(String askText, ChannelHandlerContext ctx) throws ParseException {
-        System.out.println("000拆分粘包之后数据>>"+askText);
+//        System.out.println("000拆分粘包之后数据>>"+askText);
         //--对接收的上报数据解析
         String answer = parseAskText2(askText);
 
-        //--将原始数据保存到rabbitMQ(重构之前代码)
-//        producer.sendClientAsk(askText);
-
         //--将原始数据保存到rabbitMQ(重构之后代码)
         producer.sendClientAsk2(askText);
 
@@ -285,11 +282,24 @@ public class DataServiceImpl implements IDataService {
     }
 
     /* 根本设备id获取设备编码 */
-    private String getDeviceCode(String deviceId) {
-        ValueOperations ops = redisTemplate.opsForValue();
-        ops.set("deviceCode", "202007239999869");
-        String deviceCode = (String) ops.get("deviceCode");
-        System.out.println("redis->deviceCode>>" + deviceCode);
+    private String getDeviceCode(String chipId) {
+//        ValueOperations ops = redisTemplate.opsForValue();
+//        ops.set("deviceCode", "202007239999869");
+//        String deviceCode = (String) ops.get("deviceCode");
+//        System.out.println("redis->deviceCode>>" + deviceCode);
+
+//        String deviceCode = "";
+//        if (chipId.trim().equalsIgnoreCase("a848fad42b8a")) {
+//            deviceCode = "202007239999866";
+//        } else if (chipId.trim().equalsIgnoreCase("a848fad3fefb")) {
+//            deviceCode = "202007239999873";
+//        } else {
+//            deviceCode = "202007239999869";
+//        }
+
+        //{根据芯片id读取设备编码}
+        String deviceCode = deviceService.getDeviceCodeByChipId(chipId);
+        System.out.println("chipId>>" + chipId + " ,deviceCode>>" + deviceCode);
         return deviceCode;
     }
 
@@ -303,7 +313,8 @@ public class DataServiceImpl implements IDataService {
         String answer = null;
         if (cmdHeader.trim().equalsIgnoreCase("hm")) {
             //采集器原始数据
-            String device = dataArray[1];
+            //芯片id/设备编码
+            String idCode = dataArray[1];
             String cmd = dataArray[2];
             //采集器应答数据
             if (cmd.trim().equalsIgnoreCase("0")) {
@@ -312,7 +323,7 @@ public class DataServiceImpl implements IDataService {
             } else if (cmd.trim().equalsIgnoreCase("1")) {
                 //获取设备编码
                 /* 读取设备编码 */
-                String deviceCode = getDeviceCode(device);
+                String deviceCode = getDeviceCode(idCode);
                 answer = "hm+1+0+" + deviceCode + "+123+8+end";
                 log.info("##获取设备编码-应答数据>>" + answer);
             } else if (cmd.trim().equalsIgnoreCase("2")) {

+ 51 - 0
huimv-eartag2-platform/huimv-eartag2-input/src/main/java/com/huimv/eartag2/service/impl/DeviceServiceImpl.java

@@ -1,10 +1,21 @@
 package com.huimv.eartag2.service.impl;
 
+import com.huimv.eartag2.common.dao.entity.EartagDeviceRegisterEntity;
+import com.huimv.eartag2.common.dao.entity.EartagRawEntity;
+import com.huimv.eartag2.common.dao.repo.EartagDeviceRegisterRepo;
+import com.huimv.eartag2.common.dao.repo.EartagRawRepo;
+import com.huimv.eartag2.common.utils.DateUtil;
+import com.huimv.eartag2.service.ICacheService;
 import com.huimv.eartag2.service.IDeviceService;
+import lombok.extern.slf4j.Slf4j;
 import org.springframework.amqp.rabbit.core.RabbitTemplate;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
+import java.sql.Date;
+import java.sql.Timestamp;
+import java.text.ParseException;
+
 /**
  * @Project : huimv.shiwan
  * @Package : com.huimv.biosafety.uface.controller
@@ -14,9 +25,16 @@ import org.springframework.stereotype.Service;
  * @Create : 2020-12-25
  **/
 @Service
+@Slf4j
 public class DeviceServiceImpl implements IDeviceService {
     @Autowired
     RabbitTemplate rabbitTemplate;  //使用RabbitTemplate,这提供了接收/发送等等方法
+    @Autowired
+    private EartagRawRepo eartagRawRepo;
+    @Autowired
+    private EartagDeviceRegisterRepo deviceRegisterRepo;
+    @Autowired
+    private ICacheService cacheService;
 
     //处理采集器设备信息
     @Override
@@ -29,6 +47,39 @@ public class DeviceServiceImpl implements IDeviceService {
         handleEartagAllState();
     }
 
+    @Override
+    public void saveRawData(String askText) throws ParseException {
+        DateUtil dateUtil = new DateUtil();
+        EartagRawEntity eartagRawEntity = new EartagRawEntity();
+        eartagRawEntity.setAsk(askText);
+        eartagRawEntity.setAddTime(dateUtil.getTimestamp());
+        eartagRawEntity.setCreateDate(new Date(dateUtil.getTodayDate().getTime()));
+        eartagRawRepo.saveAndFlush(eartagRawEntity);
+    }
+
+    @Override
+    public String getDeviceCodeByChipId(String chipId) {
+        //{}
+        Object deviceCodeObj = cacheService.getDeviceCodeByChipId(chipId);
+        if(deviceCodeObj != null){
+            return (String)deviceCodeObj;
+        }else{
+            return getDeviceCodeByChipIdFromMySQL(chipId);
+        }
+    }
+
+    //从数据库读取deviceCode
+    private String getDeviceCodeByChipIdFromMySQL(String chipId) {
+        //{}
+        EartagDeviceRegisterEntity deviceRegisterEntity = deviceRegisterRepo.getByChipId(chipId);
+        if(deviceRegisterEntity == null){
+            log.error("该芯片id不存在.");
+            return null;
+        }else{
+            return deviceRegisterEntity.getDeviceCode();
+        }
+    }
+
     //--处理状态数据
     private void handleEartagAllState() {
 

+ 1 - 1
huimv-eartag2-platform/huimv-eartag2-input/src/main/resources/application-dev.yml

@@ -6,7 +6,7 @@ spring:
     name: huimv-eartag2-input
 
   datasource:
-    url: jdbc:mysql://192.168.1.7:3306/huimv-eartag2-platform?useUnicode=true&characterEncoding=UTF-8&useSSL=false&autoReconnect=true&serverTimezone=Asia/Shanghai
+    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

+ 107 - 0
huimv-eartag2-platform/huimv-eartag2-input/src/main/resources/application-prod.yml

@@ -0,0 +1,107 @@
+server:
+  port: 8092
+spring:
+  application:
+    name: huimv-eartag2-process
+
+  datasource:
+    url: jdbc:mysql://192.168.1.7:3306/huimv-eartag2-platform?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
+
+

+ 6 - 0
huimv-eartag2-platform/huimv-eartag2-input/src/test/java/com/huimv/eartag2/DataTest.java

@@ -19,6 +19,12 @@ import java.util.regex.Pattern;
 public class DataTest {
 
     @Test
+    public void test1(){
+        String text = "zj+202007239999869+122083123610063+94+0+2468+6825+85+20220318151841+1.1#1.0#10119+0+end";
+
+    }
+
+    @Test
     public void testData() {
         String text = "zj+202007239999869+133083123611032+93+0+2368+216+67+20220119172038+1.1#1.0#10464+0+endzj+202111111111111111+133083123611032+93+0+2368+216+67+20220119172038+1.1#1.0#10464+0+endzj+2023333333333333+133083123611032+93+0+2368+216+67+20220119172038+1.1#1.0#10464+0+endzj+202444444444444+133083123611032+93+0+2368+216+67+20220119172038+1.1#1.0#10464+0+end";
 //        String text = "zj+202007239999869+133083123611032+93+0+2368+216+67+20220119172038+1.1#1.0#10464+0+end";

+ 48 - 0
huimv-eartag2-platform/huimv-eartag2-manage/src/main/java/com/huimv/eartag2/manage/config/CorsConfig.java

@@ -0,0 +1,48 @@
+package com.huimv.eartag2.manage.config;
+
+import org.springframework.context.annotation.Configuration;
+import org.springframework.web.servlet.config.annotation.CorsRegistry;
+import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
+
+/**
+ * @Project : huimv.shiwan
+ * @Package : com.huimv.biosafety.uface.controller
+ * @Description : TODO
+ * @Version : 1.0
+ * @Author : ZhuoNing
+ * @Create : 2020-12-25
+ **/
+@Configuration
+public class CorsConfig implements WebMvcConfigurer {
+
+    /**
+     * 开启跨域
+     */
+    @Override
+    public void addCorsMappings(CorsRegistry registry) {
+        // 设置允许跨域的路由
+        registry.addMapping("/**")
+                // 设置允许跨域请求的域名
+                .allowedOriginPatterns("*")
+                // 是否允许证书(cookies)
+                .allowCredentials(true)
+                // 设置允许的方法
+                .allowedMethods("*")
+                // 跨域允许时间
+                .maxAge(3600);
+    }
+
+//    @Override
+//    public void addCorsMappings(CorsRegistry registry) {
+////        设置允许跨域的路径
+//        registry.addMapping("/**")
+////                设置允许跨域请求的域名
+//                .allowedOrigins("*")
+////                是否允许证书
+//                .allowCredentials(true)
+//                .allowedMethods("GET", "POST", "DELETE", "PUT","OPTIONS")
+//                .allowedHeaders("*")
+////                跨域允许时间
+//                .maxAge(3600);
+//    }
+}

+ 37 - 7
huimv-eartag2-platform/huimv-eartag2-manage/src/main/java/com/huimv/eartag2/manage/controller/DeviceController.java

@@ -171,7 +171,7 @@ public class DeviceController {
 
     /**
      * @Method      : listManyDaysOnlineByDeviceCode
-     * @Description : 查询单个设备N天在线记录-showMode:1(记录) ,2(图表
+     * @Description : F1接口-查询单个设备N天在线图表
      * @Params      : [deviceCode]
      * @Return      : com.huimv.eartag2.common.utils.Result
      * 
@@ -180,18 +180,48 @@ public class DeviceController {
      * @Time        : 14:07
      */
     @RequestMapping(value = "/listDeviceOnlineCountByDeviceCode",method = RequestMethod.GET)
-    public Result listDeviceOnlineCountByDeviceCode(@RequestParam(value = "deviceCode",required = true) String deviceCode,@RequestParam(value = "pastDays",required = true) Integer pastDays,@RequestParam(value = "showMode",required = true) Integer showMode) throws ParseException {
+    public Result listDeviceOnlineCountByDeviceCode(@RequestParam(value = "deviceCode",required = true) String deviceCode,
+                                                    @RequestParam(value = "pastDays",required = false) Integer pastDays) throws ParseException {
         log.info("<listManyDaysOnlineByDeviceCode>输入参数 deviceCode>>"+deviceCode);
         log.info("<listManyDaysOnlineByDeviceCode>输入参数 pastDays>>"+pastDays);
-        log.info("<listManyDaysOnlineByDeviceCode>输入参数 showMode>>"+showMode);
         if(pastDays == null){
             pastDays = 7;
         }
-        if(showMode == null){
-            showMode = 1;
-        }
         //查询单个设备N天在线记录
-        return deviceService.listDeviceOnlineCountByDeviceCode(deviceCode,pastDays,showMode);
+        return deviceService.listDeviceOnlineCountByDeviceCode(deviceCode,pastDays);
+    }
+
+    /**
+     * @Method      : listDeviceOnlineCountByDeviceCodeInPager
+     * @Description : F2接口-查询单个设备在线记录
+     * @Params      : [deviceCode, startDate, endDate, pageNo, pageSize]
+     * @Return      : com.huimv.eartag2.common.utils.Result
+     * 
+     * @Author      : ZhuoNing
+     * @Date        : 2022/3/18       
+     * @Time        : 14:31
+     */
+    @RequestMapping(value = "/listDeviceOnlineCountByDeviceCodeInPager",method = RequestMethod.GET)
+    public Result listDeviceOnlineCountByDeviceCodeInPager(@RequestParam(value = "deviceCode",required = true) String deviceCode,
+                                                    @RequestParam(value = "startDate",required = false) String startDate,
+                                                    @RequestParam(value = "endDate",required = false) String endDate,
+                                                    @RequestParam(value = "pageNo",required = true) Integer pageNo,
+                                                    @RequestParam(value = "pageSize",required = true) Integer pageSize ) throws ParseException {
+        log.info("<listManyDaysOnlineByDeviceCode>输入参数 deviceCode>>"+deviceCode);
+        log.info("<listManyDaysOnlineByDeviceCode>输入参数 startDate>>"+startDate);
+        log.info("<listManyDaysOnlineByDeviceCode>输入参数 endDate>>"+endDate);
+        log.info("<listManyDaysOnlineByDeviceCode>输入参数 pageNo>>"+pageNo);
+        log.info("<listManyDaysOnlineByDeviceCode>输入参数 pageSize>>"+pageSize);
+        DateUtil dateUtil = new DateUtil();
+        if(startDate == null || startDate.trim().length() == 0){
+            startDate = dateUtil.getTodayDateText();
+        }
+        //endDate
+        if(endDate == null || endDate.trim().length() == 0){
+            endDate = dateUtil.getTodayDateText();
+        }
+        //查询单个设备N天在线记录(,endDate)
+        return deviceService.listDeviceOnlineCountByDeviceCodeInPager(deviceCode,startDate,endDate,pageNo,pageSize);
     }
 
     /**

+ 44 - 14
huimv-eartag2-platform/huimv-eartag2-manage/src/main/java/com/huimv/eartag2/manage/controller/DeviceRegisterController.java

@@ -19,7 +19,7 @@ import java.text.ParseException;
  * @Author : ZhuoNing
  * @Create : 2020-12-25
  **/
-@CrossOrigin
+//@CrossOrigin
 @RestController
 @RequestMapping(value = "/deviceRegister")
 @Slf4j
@@ -27,9 +27,17 @@ public class DeviceRegisterController {
     @Autowired
     private IDeviceRegisterService deviceRegisterService;
 
-    @PostMapping("/addDevice")
-    public Result addDevice(String deviceCode, Integer deviceStatus, Integer activeStatus, String deviceAlias, String location, String remark, String farmId) throws ParseException {
+    @GetMapping("/addDevice")
+    public Result addDevice(@RequestParam(value = "deviceCode",required = true) String deviceCode,
+                            @RequestParam(value = "chipId",required = true) String chipId,
+                            @RequestParam(value = "deviceStatus",required = true) Integer deviceStatus,
+                            @RequestParam(value = "activeStatus",required = true) Integer activeStatus,
+                            @RequestParam(value = "deviceAlias",required = false) String deviceAlias,
+                            @RequestParam(value = "location",required = false) String location,
+                            @RequestParam(value = "remark",required = false) String remark,
+                            @RequestParam(value = "farmId",required = true) String farmId) throws ParseException {
         log.info("farmId>>"+farmId);
+        log.info("chipId>>"+chipId);
         log.info("deviceCode>>"+deviceCode);
         log.info("deviceStatus>>"+deviceStatus);
         log.info("activeStatus>>"+activeStatus);
@@ -44,7 +52,7 @@ public class DeviceRegisterController {
             activeStatus = 0;
         }
         //{添加设备}
-        return deviceRegisterService.addDevice(deviceCode,deviceStatus,activeStatus,deviceAlias,location,remark,farmId);
+        return deviceRegisterService.addDevice(chipId,deviceCode,deviceStatus,activeStatus,deviceAlias,location,remark,farmId);
     }
 
     @PostMapping("/addDevice1")
@@ -54,22 +62,36 @@ public class DeviceRegisterController {
         return new Result(ResultCode.SUCCESS,msg);
     }
 
-    @PostMapping("/editDevice")
-    public Result editDevice(String deviceCode, Integer deviceStatus, Integer activeStatus, String deviceAlias, String location, String remark, String id){
+    @GetMapping("/editDevice")
+    public Result editDevice(@RequestParam(value = "deviceCode",required = true) String deviceCode,
+                             @RequestParam(value = "chipId",required = true) String chipId,
+                             @RequestParam(value = "deviceStatus",required = true) Integer deviceStatus,
+                             @RequestParam(value = "activeStatus",required = true) Integer activeStatus,
+                             @RequestParam(value = "deviceAlias",required = false) String deviceAlias,
+                             @RequestParam(value = "location",required = false) String location,
+                             @RequestParam(value = "remark",required = false) String remark,
+                             @RequestParam(value = "id",required = true) Integer id){
         //{编辑}
-        return deviceRegisterService.editDevice(deviceCode,deviceStatus,activeStatus,deviceAlias,location,remark,id);
+        return deviceRegisterService.editDevice(chipId,deviceCode,deviceStatus,activeStatus,deviceAlias,location,remark,id);
     }
 
-    @PostMapping("/removeDevice")
-    public Result remove(String ids){
+    @GetMapping("/removeDevice")
+    public Result remove(@RequestParam(value = "ids",required = true) String ids){
         //{移除设备}
-//        return deviceRegisterService.removeDevice(ids);
-//        return deviceRegisterService.removeDevice(ids);
-        return deviceRegisterService.removeBatchDevice(ids);
+        return deviceRegisterService.removeDevice(ids);
     }
 
-    @GetMapping("/listDevice")
-    public Result listDevice(String farmId,String deviceCode,Integer deviceStatus,Integer activeStatus,String deviceAlias,String location,Integer pageNo,Integer pageSize){
+//    @GetMapping("/listDevice")
+    @RequestMapping(value = "/listAllDeviceInPager",method = RequestMethod.GET)
+    public Result listDevice(@RequestParam(value = "farmId",required = true) String farmId,
+                             @RequestParam(value = "deviceCode",required = true) String deviceCode,
+                             @RequestParam(value = "deviceStatus",required = false) Integer deviceStatus,
+                             @RequestParam(value = "activeStatus",required = false) Integer activeStatus,
+                             @RequestParam(value = "deviceAlias",required = false) String deviceAlias,
+                             @RequestParam(value = "location",required = false) String location,
+                             @RequestParam(value = "pageNo",required = true) Integer pageNo,
+                             @RequestParam(value = "pageSize",required = true) Integer pageSize){
+        //
         if(pageNo == null || pageNo.toString().length()==0 || pageSize == null || pageSize.toString().length() == 0){
             return new Result(10010,"页码或页码尺寸不能为空.",false);
         }
@@ -77,5 +99,13 @@ public class DeviceRegisterController {
         return deviceRegisterService.listDevice(farmId,deviceCode,deviceStatus,activeStatus,deviceAlias,location,pageNo,pageSize);
     }
 
+    @GetMapping("/setDeviceStatus")
+    public Result cancelDevice(@RequestParam(value = "id",required = true) Integer id,
+                               @RequestParam(value = "deviceStatus",required = true) Integer deviceStatus){
+        log.info("(cancelDevice).id>>"+id);
+        log.info("(cancelDevice).deviceStatus>>"+deviceStatus);
+        //{注销设备}
+        return deviceRegisterService.cancelDevice(id,deviceStatus);
+    }
 
 }

+ 3 - 0
huimv-eartag2-platform/huimv-eartag2-manage/src/main/java/com/huimv/eartag2/manage/service/ICacheService.java

@@ -29,4 +29,7 @@ public interface ICacheService {
     void putAllDeviceSet(List list);
 
     void putAllDeviceSet(String deviceCode);
+
+    //将芯片ID加入到缓存中
+    void putChipIdToCache(String chipId, String deviceCode);
 }

+ 5 - 2
huimv-eartag2-platform/huimv-eartag2-manage/src/main/java/com/huimv/eartag2/manage/service/IDeviceRegisterService.java

@@ -6,10 +6,10 @@ import java.text.ParseException;
 
 public interface IDeviceRegisterService {
     //添加设备
-    Result addDevice(String deviceCode, Integer deviceStatus, Integer activeStatus, String deviceAlias, String location, String remark, String farmId) throws ParseException;
+    Result addDevice(String chipId, String deviceCode, Integer deviceStatus, Integer activeStatus, String deviceAlias, String location, String remark, String farmId) throws ParseException;
 
     //编辑设备
-    Result editDevice(String deviceCode, Integer deviceStatus, Integer activeStatus, String deviceAlias, String location, String remark, String id);
+    Result editDevice(String chipId, String deviceCode, Integer deviceStatus, Integer activeStatus, String deviceAlias, String location, String remark, Integer id);
 
     //移除设备
     Result removeDevice(String ids);
@@ -19,4 +19,7 @@ public interface IDeviceRegisterService {
 
     //批量删除
     Result removeBatchDevice(String ids);
+
+    //注销设备
+    Result cancelDevice(Integer id, Integer deviceStatus);
 }

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

@@ -18,7 +18,7 @@ public interface IDeviceService {
     Result getDeviceRegisterByDeviceCode(String deviceCode) throws ParseException;
 
     //查询单个设备N天在线记录
-    Result listDeviceOnlineCountByDeviceCode(String deviceCode, Integer pastDays,Integer showMode) throws ParseException;
+    Result listDeviceOnlineCountByDeviceCode(String deviceCode, Integer pastDays) throws ParseException;
 
     //查询设备在线状态
     Result listDeviceOnlineStatusByDeviceCode(String deviceCode, Integer pastDays) throws ParseException;
@@ -44,4 +44,6 @@ public interface IDeviceService {
     //分页查询列表
     Result listDeviceRegisterInPager(String farmId, String deviceCode, String alias, String startDate, String endDate, Integer activeStatus, Integer liveStatus, Integer pageNo, Integer pageSize) throws ParseException;
 
+    //单个耳标指定
+    Result listDeviceOnlineCountByDeviceCodeInPager(String deviceCode, String startDate, String endDate, Integer pageNo, Integer pageSize) throws ParseException;
 }

+ 8 - 0
huimv-eartag2-platform/huimv-eartag2-manage/src/main/java/com/huimv/eartag2/manage/service/impl/CacheServiceImpl.java

@@ -97,4 +97,12 @@ public class CacheServiceImpl implements ICacheService {
         String setKey = BizConst.SET_ALL_DEVICE_PREFIX;
         redisTemplate.opsForSet().add(setKey,deviceCode);
     }
+
+    @Override
+    public void putChipIdToCache(String chipId, String deviceCode) {
+        String key = BizConst.CHIP_DEVICE_PREFIX;
+        String hashKey = chipId;
+        //
+        redisTemplate.opsForHash().put(key,hashKey,deviceCode);
+    }
 }

+ 46 - 12
huimv-eartag2-platform/huimv-eartag2-manage/src/main/java/com/huimv/eartag2/manage/service/impl/DeviceRegisterServiceImpl.java

@@ -1,6 +1,5 @@
 package com.huimv.eartag2.manage.service.impl;
 
-import com.huimv.eartag2.common.dao.entity.EartagDataEntity;
 import com.huimv.eartag2.common.dao.entity.EartagDeviceRegisterEntity;
 import com.huimv.eartag2.common.dao.repo.EartagDeviceRegisterRepo;
 import com.huimv.eartag2.common.utils.BizConst;
@@ -9,6 +8,7 @@ import com.huimv.eartag2.common.utils.Result;
 import com.huimv.eartag2.common.utils.ResultCode;
 import com.huimv.eartag2.manage.service.ICacheService;
 import com.huimv.eartag2.manage.service.IDeviceRegisterService;
+import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.data.domain.Page;
 import org.springframework.data.domain.PageRequest;
@@ -33,6 +33,7 @@ import java.util.List;
  * @Create : 2020-12-25
  **/
 @Service
+@Slf4j
 public class DeviceRegisterServiceImpl implements IDeviceRegisterService {
     @Autowired
     private EartagDeviceRegisterRepo deviceRegisterRepo;
@@ -40,36 +41,40 @@ public class DeviceRegisterServiceImpl implements IDeviceRegisterService {
     private ICacheService cacheService;
 
     @Override
-    public Result addDevice(String deviceCode, Integer deviceStatus, Integer activeStatus, String deviceAlias, String location, String remark, String farmId) throws ParseException {
+    public Result addDevice(String chipId, String deviceCode, Integer deviceStatus, Integer activeStatus, String deviceAlias, String location, String remark, String farmId) throws ParseException {
         DateUtil dateUtil = new DateUtil();
         Date todayDate = dateUtil.getTodayDate();
         Timestamp nowTimestamp = dateUtil.getTimestamp();
-
         //判断是否存在相同的设备编码
         if(isExistSameDevice(deviceCode)){
             return new Result(BizConst.CODE_DEVICE_CODE_EXIST,BizConst.MSG_DEVICE_CODE_EXIST,false);
         }
         //
         EartagDeviceRegisterEntity deviceRegisterEntity = new EartagDeviceRegisterEntity();
-        deviceRegisterEntity.setDeviceCode(deviceCode);
-        deviceRegisterEntity.setFarmId(farmId);
+        deviceRegisterEntity.setChipId(chipId.trim());
+        deviceRegisterEntity.setDeviceCode(deviceCode.trim());
+        deviceRegisterEntity.setFarmId(farmId.trim());
         deviceRegisterEntity.setRegisterTime(nowTimestamp);
         deviceRegisterEntity.setActiveStatus(activeStatus);
         deviceRegisterEntity.setDeviceStatus(deviceStatus);
-        deviceRegisterEntity.setDeviceAlias(deviceAlias);
-        deviceRegisterEntity.setLocation(location);
-        deviceRegisterEntity.setRemark(remark);
+        deviceRegisterEntity.setDeviceAlias(deviceAlias.trim());
+        deviceRegisterEntity.setLocation(location.trim());
+        deviceRegisterEntity.setRemark(remark.trim());
         deviceRegisterEntity.setCreateDate(new java.sql.Date(todayDate.getTime()));
         deviceRegisterRepo.saveAndFlush(deviceRegisterEntity);
         //加入缓存
         cacheService.putAllDeviceSet(deviceCode);
+        //加入缓存
+        cacheService.putChipIdToCache(chipId,deviceCode);
         return new Result(ResultCode.SUCCESS);
     }
 
     @Override
-    public Result editDevice(String deviceCode, Integer deviceStatus, Integer activeStatus, String deviceAlias, String location, String remark, String id) {
+    public Result editDevice(String chipId, String deviceCode, Integer deviceStatus, Integer activeStatus, String deviceAlias, String location, String remark, Integer id) {
         //
-        EartagDeviceRegisterEntity deviceRegisterEntity = deviceRegisterRepo.getDeviceRegister(id);
+        EartagDeviceRegisterEntity deviceRegisterEntity = deviceRegisterRepo.getById(id);
+//        deviceRegisterEntity.setChipId(chipId);
+//        deviceRegisterEntity.setDeviceCode(deviceCode);
         deviceRegisterEntity.setDeviceStatus(deviceStatus);
         deviceRegisterEntity.setActiveStatus(activeStatus);
         deviceRegisterEntity.setDeviceAlias(deviceAlias);
@@ -157,12 +162,41 @@ public class DeviceRegisterServiceImpl implements IDeviceRegisterService {
     }
 
     @Override
+    public Result cancelDevice(Integer id, Integer deviceStatus) {
+        //
+        EartagDeviceRegisterEntity deviceRegisterEntity = deviceRegisterRepo.getById(id);
+        if(deviceRegisterEntity == null){
+            log.error(BizConst.MSG_DEVICE_REGISTER_NO_EXIST);
+            return new Result(BizConst.CODE_DEVICE_REGISTER_NO_EXIST,BizConst.MSG_DEVICE_REGISTER_NO_EXIST,false);
+        }
+        deviceRegisterEntity.setDeviceStatus(deviceStatus);
+        deviceRegisterRepo.saveAndFlush(deviceRegisterEntity);
+        return new Result(ResultCode.SUCCESS);
+    }
+
+    @Override
     public Result removeDevice(String ids) {
         String[] idArray = ids.split(",");
+        List deviceCodeList = new ArrayList();
         for(int a=0;a<idArray.length;a++){
-            deviceRegisterRepo.delete(deviceRegisterRepo.getById(Integer.parseInt(idArray[a])));
+            EartagDeviceRegisterEntity deviceRegisterEntity = deviceRegisterRepo.getById(Integer.parseInt(idArray[a]));
+            if(deviceRegisterEntity == null){
+                //暂不确定这里怎么写
+                //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
+            }else{
+                if(deviceRegisterEntity.getDeviceStatus()==2){
+                    deviceRegisterRepo.delete(deviceRegisterEntity);
+                }else{
+                    deviceCodeList.add(deviceRegisterEntity.getDeviceCode());
+                }
+            }
         }
-        return new Result(ResultCode.SUCCESS);
+        if(deviceCodeList.size()==0){
+            return new Result(ResultCode.SUCCESS);
+        }else{
+            return new Result(BizConst.CODE_DEVICE_STATUS_EXIST,"这些设备["+deviceCodeList.toString()+"]要先注销再删除.",false);
+        }
+
     }
 
     //

+ 177 - 119
huimv-eartag2-platform/huimv-eartag2-manage/src/main/java/com/huimv/eartag2/manage/service/impl/DeviceServiceImpl.java

@@ -59,45 +59,42 @@ public class DeviceServiceImpl implements IDeviceService {
     private EartagHeartbeatRepo heartbeatRepo;
 
 
-
     /**
-     * @Method      : listDeviceEnvtempByDeviceCode
-     * @Description : 
-     * @Params      : [deviceCode]
-     * @Return      : com.huimv.eartag2.common.utils.Result
-     * 
-     * @Author      : ZhuoNing
-     * @Date        : 2022/3/8       
-     * @Time        : 20:55
+     * @Method : listDeviceEnvtempByDeviceCode
+     * @Description :
+     * @Params : [deviceCode]
+     * @Return : com.huimv.eartag2.common.utils.Result
+     * @Author : ZhuoNing
+     * @Date : 2022/3/8
+     * @Time : 20:55
      */
     @Override
     public Result listDeviceEnvtempByDeviceCode(String deviceCode) throws ParseException {
         DateUtil du = new DateUtil();
         String todayDateText = du.getTodayDateText();
         //
-        List<EartagEnvEntity> eartagEnvEntityList = eartagEnvRepo.getDeviceEnvtempByDeviceCode(deviceCode,todayDateText);
-        if(eartagEnvEntityList.size()==0){
-            return new Result(BizConst.CODE_ENVTEMP_FLOW_NO_EXIST,BizConst.MSG_ENVTEMP_FLOW_NO_EXIST,false);
-        }else{
+        List<EartagEnvEntity> eartagEnvEntityList = eartagEnvRepo.getDeviceEnvtempByDeviceCode(deviceCode, todayDateText);
+        if (eartagEnvEntityList.size() == 0) {
+            return new Result(BizConst.CODE_ENVTEMP_FLOW_NO_EXIST, BizConst.MSG_ENVTEMP_FLOW_NO_EXIST, false);
+        } else {
             JSONArray dataJa = new JSONArray();
-            for(EartagEnvEntity eartagEnvEntity:eartagEnvEntityList){
+            for (EartagEnvEntity eartagEnvEntity : eartagEnvEntityList) {
                 JSONObject eartagEnvJo = JSONUtil.convertEntityToJSONObject(eartagEnvEntity);
-                eartagEnvJo.put("addTime",du.formatDatetimeText(eartagEnvJo.getDate("addTime")));
+                eartagEnvJo.put("addTime", du.formatDatetimeText(eartagEnvJo.getDate("addTime")));
                 dataJa.add(eartagEnvJo);
             }
-            return new Result(ResultCode.SUCCESS,dataJa);
+            return new Result(ResultCode.SUCCESS, dataJa);
         }
     }
 
     /**
-     * @Method      : listDeviceEartagOnlineCountByDeviceCodeInPager
+     * @Method : listDeviceEartagOnlineCountByDeviceCodeInPager
      * @Description : 显示设备关联耳标统计(带分页)
-     * @Params      : [deviceCode, earmark, addDate, pageNo, pageSize]
-     * @Return      : com.huimv.eartag2.common.utils.Result
-     * 
-     * @Author      : ZhuoNing
-     * @Date        : 2022/3/9       
-     * @Time        : 20:08
+     * @Params : [deviceCode, earmark, addDate, pageNo, pageSize]
+     * @Return : com.huimv.eartag2.common.utils.Result
+     * @Author : ZhuoNing
+     * @Date : 2022/3/9
+     * @Time : 20:08
      */
     @Override
     public Result listDeviceEartagOnlineCountByDeviceCodeInPager(String deviceCode, String earmark, String addDate, Integer pageNo, Integer pageSize) throws ParseException {
@@ -105,15 +102,15 @@ public class DeviceServiceImpl implements IDeviceService {
         Specification<EartagDeviceEartagCountEntity> sf = (Specification<EartagDeviceEartagCountEntity>) (root, criteriaQuery, criteriaBuilder) -> {
             //
             List<Predicate> predList = new ArrayList<>();
-            if (null != earmark && earmark.trim().length()>0) {
+            if (null != earmark && earmark.trim().length() > 0) {
                 predList.add(criteriaBuilder.equal(root.get("earmark").as(String.class), earmark));
             }
             //
-            if (null != deviceCode && deviceCode.trim().length()>0) {
+            if (null != deviceCode && deviceCode.trim().length() > 0) {
                 predList.add(criteriaBuilder.equal(root.get("deviceCode").as(String.class), deviceCode));
             }
             //
-            if (null != addDate && addDate.trim().length()>0) {
+            if (null != addDate && addDate.trim().length() > 0) {
                 try {
                     predList.add(criteriaBuilder.equal(root.get("createDate").as(Date.class), new Date(new DateUtil().parseDateTextToLong(addDate))));
                 } catch (ParseException e) {
@@ -134,17 +131,17 @@ public class DeviceServiceImpl implements IDeviceService {
 
     @Override
     public Result listHeartbeatByDeviceCodeAndDateInPager(String deviceCode, String addDate, Integer pageNo, Integer pageSize) {
-        System.out.println("## addDate>>"+addDate);
+        System.out.println("## addDate>>" + addDate);
         //
         Specification<EartagHeartbeatEntity> sf = (Specification<EartagHeartbeatEntity>) (root, criteriaQuery, criteriaBuilder) -> {
             //
             List<Predicate> predList = new ArrayList<>();
             //
-            if (null != deviceCode && deviceCode.trim().length()>0) {
+            if (null != deviceCode && deviceCode.trim().length() > 0) {
                 predList.add(criteriaBuilder.equal(root.get("deviceCode").as(String.class), deviceCode));
             }
             //
-            if (null != addDate && addDate.trim().length()>0) {
+            if (null != addDate && addDate.trim().length() > 0) {
                 try {
                     predList.add(criteriaBuilder.equal(root.get("createDate").as(Date.class), new Date(new DateUtil().parseDateTextToLong(addDate))));
                 } catch (ParseException e) {
@@ -164,14 +161,13 @@ public class DeviceServiceImpl implements IDeviceService {
     }
 
     /**
-     * @Method      : listDeviceEnvtempByDeviceCodeInPager
+     * @Method : listDeviceEnvtempByDeviceCodeInPager
      * @Description : 分页查询设备温度
-     * @Params      : [deviceCode, addDate, pageNo, pageSize]
-     * @Return      : com.huimv.eartag2.common.utils.Result
-     * 
-     * @Author      : ZhuoNing
-     * @Date        : 2022/3/9       
-     * @Time        : 21:27
+     * @Params : [deviceCode, addDate, pageNo, pageSize]
+     * @Return : com.huimv.eartag2.common.utils.Result
+     * @Author : ZhuoNing
+     * @Date : 2022/3/9
+     * @Time : 21:27
      */
     @Override
     public Result listDeviceEnvtempByDeviceCodeInPager(String deviceCode, String addDate, Integer pageNo, Integer pageSize) {
@@ -180,11 +176,11 @@ public class DeviceServiceImpl implements IDeviceService {
             //
             List<Predicate> predList = new ArrayList<>();
             //
-            if (null != deviceCode && deviceCode.trim().length()>0) {
+            if (null != deviceCode && deviceCode.trim().length() > 0) {
                 predList.add(criteriaBuilder.equal(root.get("deviceCode").as(String.class), deviceCode));
             }
             //
-            if (null != addDate && addDate.trim().length()>0) {
+            if (null != addDate && addDate.trim().length() > 0) {
                 try {
                     predList.add(criteriaBuilder.equal(root.get("createDate").as(Date.class), new Date(new DateUtil().parseDateTextToLong(addDate))));
                 } catch (ParseException e) {
@@ -204,14 +200,13 @@ public class DeviceServiceImpl implements IDeviceService {
     }
 
     /**
-     * @Method      : listDeviceRegisterInPager
+     * @Method : listDeviceRegisterInPager
      * @Description : 列表查询分页信息(分页)
-     * @Params      : [farmId, deviceCode, alias, startDate, endDate, activeStatus, liveStatus, pageNo, pageSize]
-     * @Return      : com.huimv.eartag2.common.utils.Result
-     * 
-     * @Author      : ZhuoNing
-     * @Date        : 2022/3/9       
-     * @Time        : 22:28
+     * @Params : [farmId, deviceCode, alias, startDate, endDate, activeStatus, liveStatus, pageNo, pageSize]
+     * @Return : com.huimv.eartag2.common.utils.Result
+     * @Author : ZhuoNing
+     * @Date : 2022/3/9
+     * @Time : 22:28
      */
     @Override
     public Result listDeviceRegisterInPager(String farmId, String deviceCode, String alias, String startDate, String endDate, Integer activeStatus, Integer liveStatus, Integer pageNo, Integer pageSize) throws ParseException {
@@ -229,19 +224,19 @@ public class DeviceServiceImpl implements IDeviceService {
             //
             List<Predicate> predList = new ArrayList<>();
             //farmId
-            if (null != farmId && farmId.trim().length()>0) {
+            if (null != farmId && farmId.trim().length() > 0) {
                 predList.add(criteriaBuilder.equal(root.get("farmId").as(String.class), farmId));
             }
             //deviceCode
-            if (null != deviceCode && deviceCode.trim().length()>0) {
+            if (null != deviceCode && deviceCode.trim().length() > 0) {
                 predList.add(criteriaBuilder.equal(root.get("deviceCode").as(String.class), deviceCode));
             }
             //alias
-            if (null != alias && alias.trim().length()>0) {
+            if (null != alias && alias.trim().length() > 0) {
                 predList.add(criteriaBuilder.like(root.get("deviceAlias").as(String.class), alias));
             }
             //startDate
-            if (null != startDate && startDate.trim().length()>0) {
+            if (null != startDate && startDate.trim().length() > 0) {
                 try {
                     predList.add(criteriaBuilder.greaterThanOrEqualTo(root.get("createDate").as(Date.class), new Date(new DateUtil().parseDateTextToLong(startDate))));
                 } catch (ParseException e) {
@@ -249,7 +244,7 @@ public class DeviceServiceImpl implements IDeviceService {
                 }
             }
             //endDate
-            if (null != endDate && endDate.trim().length()>0) {
+            if (null != endDate && endDate.trim().length() > 0) {
                 try {
                     predList.add(criteriaBuilder.lessThanOrEqualTo(root.get("createDate").as(Date.class), new Date(new DateUtil().parseDateTextToLong(endDate))));
                 } catch (ParseException e) {
@@ -277,58 +272,132 @@ public class DeviceServiceImpl implements IDeviceService {
         //{}
         Page<EartagDeviceRegisterEntity> pageDeviceRegister = deviceRegisterRepo.findAll(sf, pageable);
         JSONObject outDataJo = new JSONObject();
-        outDataJo.put("pageable",pageDeviceRegister.getPageable());
-        outDataJo.put("last",pageDeviceRegister.isLast());
-        outDataJo.put("totalElements",pageDeviceRegister.getTotalElements());
-        outDataJo.put("totalPages",pageDeviceRegister.getTotalPages());
-        outDataJo.put("number",pageDeviceRegister.getNumber());
-        outDataJo.put("size",pageDeviceRegister.getSize());
-        outDataJo.put("sort",pageDeviceRegister.getSort());
-        outDataJo.put("numberOfElements",pageDeviceRegister.getNumberOfElements());
-        outDataJo.put("first",pageDeviceRegister.isFirst());
-        outDataJo.put("empty",pageDeviceRegister.isEmpty());
+        outDataJo.put("pageable", pageDeviceRegister.getPageable());
+        outDataJo.put("last", pageDeviceRegister.isLast());
+        outDataJo.put("totalElements", pageDeviceRegister.getTotalElements());
+        outDataJo.put("totalPages", pageDeviceRegister.getTotalPages());
+        outDataJo.put("number", pageDeviceRegister.getNumber());
+        outDataJo.put("size", pageDeviceRegister.getSize());
+        outDataJo.put("sort", pageDeviceRegister.getSort());
+        outDataJo.put("numberOfElements", pageDeviceRegister.getNumberOfElements());
+        outDataJo.put("first", pageDeviceRegister.isFirst());
+        outDataJo.put("empty", pageDeviceRegister.isEmpty());
 
         List<EartagDeviceRegisterEntity> deviceRegisterEntityList = pageDeviceRegister.getContent();
 //        System.out.println("## deviceRegisterEntityList.size>>"+deviceRegisterEntityList.size());
         JSONArray outJa = new JSONArray();
-        outDataJo.put("content",outJa);
-        for(EartagDeviceRegisterEntity deviceRegisterEntity:deviceRegisterEntityList){
+        outDataJo.put("content", outJa);
+        for (EartagDeviceRegisterEntity deviceRegisterEntity : deviceRegisterEntityList) {
             JSONObject outJo = new JSONObject();
             outJa.add(outJo);
-            outJo.put("id",deviceRegisterEntity.getId());
-            outJo.put("deviceCode",deviceRegisterEntity.getDeviceCode());
-            outJo.put("countyCode",deviceRegisterEntity.getCountyCode());
-            outJo.put("countyName",deviceRegisterEntity.getCountyName());
-            outJo.put("farmId",deviceRegisterEntity.getFarmId());
-            outJo.put("farmName",deviceRegisterEntity.getFarmName());
-            outJo.put("typeF",deviceRegisterEntity.getTypeF());
-            outJo.put("stage",deviceRegisterEntity.getStage());
-            outJo.put("pigpenId",deviceRegisterEntity.getPigpenId());
-            outJo.put("unitId",deviceRegisterEntity.getUnitId());
-            outJo.put("registerTime",deviceRegisterEntity.getRegisterTime());
-            outJo.put("lastTime",deviceRegisterEntity.getLastTime());
-            outJo.put("activeStatus",deviceRegisterEntity.getActiveStatus());
-            outJo.put("activeTime",dateUtil.formatDatetimeText(deviceRegisterEntity.getActiveTime()));
-            outJo.put("deviceStatus",deviceRegisterEntity.getDeviceStatus());
-            outJo.put("deviceAlias",deviceRegisterEntity.getDeviceAlias());
-            outJo.put("location",deviceRegisterEntity.getLocation());
-            outJo.put("remark",deviceRegisterEntity.getRemark());
-            outJo.put("createDate",deviceRegisterEntity.getCreateDate());
-            outJo.put("updateType",deviceRegisterEntity.getUpdateType());
+            outJo.put("id", deviceRegisterEntity.getId());
+            outJo.put("deviceCode", deviceRegisterEntity.getDeviceCode());
+            outJo.put("countyCode", deviceRegisterEntity.getCountyCode());
+            outJo.put("countyName", deviceRegisterEntity.getCountyName());
+            outJo.put("farmId", deviceRegisterEntity.getFarmId());
+            outJo.put("farmName", deviceRegisterEntity.getFarmName());
+            outJo.put("typeF", deviceRegisterEntity.getTypeF());
+            outJo.put("stage", deviceRegisterEntity.getStage());
+            outJo.put("pigpenId", deviceRegisterEntity.getPigpenId());
+            outJo.put("unitId", deviceRegisterEntity.getUnitId());
+            outJo.put("registerTime", deviceRegisterEntity.getRegisterTime());
+            outJo.put("lastTime", deviceRegisterEntity.getLastTime());
+            outJo.put("activeStatus", deviceRegisterEntity.getActiveStatus());
+            outJo.put("activeTime", dateUtil.formatDatetimeText(deviceRegisterEntity.getActiveTime()));
+            outJo.put("deviceStatus", deviceRegisterEntity.getDeviceStatus());
+            outJo.put("deviceAlias", deviceRegisterEntity.getDeviceAlias());
+            outJo.put("location", deviceRegisterEntity.getLocation());
+            outJo.put("remark", deviceRegisterEntity.getRemark());
+            outJo.put("createDate", deviceRegisterEntity.getCreateDate());
+            outJo.put("updateType", deviceRegisterEntity.getUpdateType());
         }
         return new Result(ResultCode.SUCCESS, outDataJo);
 //        return new Result(ResultCode.SUCCESS, deviceRegisterRepo.findAll(sf, pageable));
     }
-    
+
+    @Override
+    public Result listDeviceOnlineCountByDeviceCodeInPager(String deviceCode, String startDate, String endDate, Integer pageNo, Integer pageSize) throws ParseException {
+        //
+        Specification<EartagDeviceOnlineEntity> sf = (Specification<EartagDeviceOnlineEntity>) (root, criteriaQuery, criteriaBuilder) -> {
+            List<Predicate> predList = new ArrayList<>();
+            //deviceCode
+            if (null != deviceCode && deviceCode.trim().length() > 0) {
+                predList.add(criteriaBuilder.equal(root.get("deviceCode").as(String.class), deviceCode));
+            }
+            //startDate
+            if (null != startDate && startDate.trim().length() > 0) {
+                try {
+                    predList.add(criteriaBuilder.greaterThanOrEqualTo(root.get("addDate").as(Date.class), new Date(new DateUtil().parseDateTextToLong(startDate))));
+                } catch (ParseException e) {
+                    e.printStackTrace();
+                }
+            }
+            //endDate
+            if (null != endDate && endDate.trim().length() > 0) {
+                try {
+                    predList.add(criteriaBuilder.lessThanOrEqualTo(root.get("addDate").as(Date.class), new Date(new DateUtil().parseDateTextToLong(endDate))));
+                } catch (ParseException e) {
+                    e.printStackTrace();
+                }
+            }
+            Predicate[] pred = new Predicate[predList.size()];
+            Predicate and = criteriaBuilder.and(predList.toArray(pred));
+            criteriaQuery.where(and);
+            //
+            List<Order> orders = new ArrayList<>();
+            orders.add(criteriaBuilder.desc(root.get("id")));
+            return criteriaQuery.orderBy(orders).getRestriction();
+        };
+        Pageable pageable = PageRequest.of(pageNo - 1, pageSize);
+        DateUtil dateUtil = new DateUtil();
+        //{}
+        Page<EartagDeviceOnlineEntity> pageDeviceOnline = deviceOnlineRepo.findAll(sf, pageable);
+        JSONObject outDataJo = new JSONObject();
+        JSONArray outJa = new JSONArray();
+        outDataJo.put("content", outJa);
+        List<EartagDeviceOnlineEntity> deviceRegisterEntityList = pageDeviceOnline.getContent();
+//        System.out.println("## deviceRegisterEntityList.size>>"+deviceRegisterEntityList.size());
+        for (EartagDeviceOnlineEntity deviceRegisterEntity : deviceRegisterEntityList) {
+            JSONObject outJo = new JSONObject();
+            outJa.add(outJo);
+            outJo.put("id", deviceRegisterEntity.getId());
+            outJo.put("deviceCode", deviceRegisterEntity.getDeviceCode());
+            outJo.put("alias", deviceRegisterEntity.getAlias());
+            outJo.put("heartbeatTotal", deviceRegisterEntity.getHeartbeatTotal());
+            outJo.put("envtempTotal", deviceRegisterEntity.getEnvtempTotal());
+            outJo.put("eartagTotal", deviceRegisterEntity.getEartagTotal());
+            outJo.put("lastEnvtemp", deviceRegisterEntity.getLastEnvtemp());
+            outJo.put("lastEartag", deviceRegisterEntity.getLastEartag());
+            outJo.put("heartbeatFirstTime", dateUtil.formatDatetimeText(deviceRegisterEntity.getHeartbeatFirstTime()));
+            outJo.put("heartbeatLastTime", dateUtil.formatDatetimeText(deviceRegisterEntity.getHeartbeatLastTime()));
+            outJo.put("envtempFirstTime", dateUtil.formatDatetimeText(deviceRegisterEntity.getEnvtempFirstTime()));
+            outJo.put("envtempLastTime", dateUtil.formatDatetimeText(deviceRegisterEntity.getEnvtempLastTime()));
+            outJo.put("eartagFirstTime", dateUtil.formatDatetimeText(deviceRegisterEntity.getEartagFirstTime()));
+            outJo.put("eartagLastTime", dateUtil.formatDatetimeText(deviceRegisterEntity.getEartagLastTime()));
+            outJo.put("addDate", deviceRegisterEntity.getAddDate());
+            outJo.put("farmId", deviceRegisterEntity.getFarmId());
+        }
+        outDataJo.put("pageable", pageDeviceOnline.getPageable());
+        outDataJo.put("last", pageDeviceOnline.isLast());
+        outDataJo.put("totalElements", pageDeviceOnline.getTotalElements());
+        outDataJo.put("totalPages", pageDeviceOnline.getTotalPages());
+        outDataJo.put("number", pageDeviceOnline.getNumber());
+        outDataJo.put("size", pageDeviceOnline.getSize());
+        outDataJo.put("sort", pageDeviceOnline.getSort());
+        outDataJo.put("numberOfElements", pageDeviceOnline.getNumberOfElements());
+        outDataJo.put("first", pageDeviceOnline.isFirst());
+        outDataJo.put("empty", pageDeviceOnline.isEmpty());
+        return new Result(ResultCode.SUCCESS, outDataJo);
+    }
+
     /**
-     * @Method      : listOnlineDevice
-     * @Description : 
-     * @Params      : [farmId, deviceCode, alias, addDate, pageNo, pageSize]
-     * @Return      : com.huimv.eartag2.common.utils.Result
-     * 
-     * @Author      : ZhuoNing
-     * @Date        : 2022/3/8       
-     * @Time        : 20:55
+     * @Method : listOnlineDevice
+     * @Description :
+     * @Params : [farmId, deviceCode, alias, addDate, pageNo, pageSize]
+     * @Return : com.huimv.eartag2.common.utils.Result
+     * @Author : ZhuoNing
+     * @Date : 2022/3/8
+     * @Time : 20:55
      */
     @Override
     public Result listOnlineDevice(String farmId, String deviceCode, String alias, String addDate, Integer pageNo, Integer pageSize) throws ParseException {
@@ -338,7 +407,7 @@ public class DeviceServiceImpl implements IDeviceService {
         System.out.println("deviceOnlineAccessMode>>" + deviceOnlineAccessMode);
         if (deviceOnlineAccessMode.trim().equalsIgnoreCase("mysql")) {
             //
-            return listDeviceOnlineFromMySQL(farmId,addDate , deviceCode, alias, pageNo, pageSize);
+            return listDeviceOnlineFromMySQL(farmId, addDate, deviceCode, alias, pageNo, pageSize);
         } else {
             //
             return listDeviceOnlineFromCache(farmId, todayDate);
@@ -360,15 +429,15 @@ public class DeviceServiceImpl implements IDeviceService {
             //
             List<Predicate> predList = new ArrayList<>();
             //
-            if (null != farmId && farmId.trim().length()>0) {
+            if (null != farmId && farmId.trim().length() > 0) {
                 predList.add(criteriaBuilder.equal(root.get("farmId").as(String.class), farmId));
             }
             //
-            if (null != deviceCode && deviceCode.trim().length()>0) {
+            if (null != deviceCode && deviceCode.trim().length() > 0) {
                 predList.add(criteriaBuilder.equal(root.get("deviceCode").as(String.class), deviceCode));
             }
             //
-            if (null != addDate && addDate.trim().length()>0) {
+            if (null != addDate && addDate.trim().length() > 0) {
                 try {
                     predList.add(criteriaBuilder.equal(root.get("addDate").as(Date.class), new Date(dateUtil.parseDateTextToLong(addDate))));
                 } catch (ParseException e) {
@@ -376,7 +445,7 @@ public class DeviceServiceImpl implements IDeviceService {
                 }
             }
             //
-            if (null != alias && alias.trim().length()>0) {
+            if (null != alias && alias.trim().length() > 0) {
                 predList.add(criteriaBuilder.equal(root.get("alias").as(String.class), alias));
             }
             Predicate[] pred = new Predicate[predList.size()];
@@ -391,7 +460,7 @@ public class DeviceServiceImpl implements IDeviceService {
         Page<EartagDeviceOnlineEntity> pageDeviceOnlineEntity = deviceOnlineRepo.findAll(sf, pageable);
 
         List<EartagDeviceOnlineEntity> deviceOnlineEntityList = pageDeviceOnlineEntity.getContent();
-        for(EartagDeviceOnlineEntity deviceOnlineEntity:deviceOnlineEntityList){
+        for (EartagDeviceOnlineEntity deviceOnlineEntity : deviceOnlineEntityList) {
 
         }
 
@@ -473,22 +542,12 @@ public class DeviceServiceImpl implements IDeviceService {
      * @Time : 14:08
      */
     @Override
-    public Result listDeviceOnlineCountByDeviceCode(String deviceCode, Integer pastDays, Integer showMode) throws ParseException {
+    public Result listDeviceOnlineCountByDeviceCode(String deviceCode, Integer pastDays) throws ParseException {
         DateUtil dateUtil = new DateUtil();
         String pastDate = dateUtil.getPastDate(pastDays);
         String todayDate = dateUtil.getTodayDateText();
-        //
-        List<EartagDeviceOnlineEntity> deviceOnlineEntityList = deviceOnlineRepo.getDeviceOnlineByDeviceCode(deviceCode, pastDate, todayDate);
-        if (deviceOnlineEntityList.size() > 0) {
-            if (showMode == 1) {
-                JSONArray resultJa = (JSONArray) JSON.toJSON(deviceOnlineEntityList);
-                for(int a=0;a<resultJa.size();a++){
-                    JSONObject resultJo = resultJa.getJSONObject(a);
-                    resultJo.put("envtempFirstTime",dateUtil.formatDatetimeText(resultJo.getDate("envtempFirstTime")));
-                    resultJo.put("envtempLastTime",dateUtil.formatDatetimeText(resultJo.getDate("envtempLastTime")));
-                }
-                return new Result(ResultCode.SUCCESS, resultJa);
-            } else {
+            List<EartagDeviceOnlineEntity> deviceOnlineEntityList = deviceOnlineRepo.getDeviceOnlineByDeviceCode(deviceCode, pastDate, todayDate);
+            if (deviceOnlineEntityList.size() > 0) {
                 JSONArray dataJa = new JSONArray();
                 for (EartagDeviceOnlineEntity deviceOnlineEntity : deviceOnlineEntityList) {
                     JSONObject newJo = new JSONObject();
@@ -497,10 +556,9 @@ public class DeviceServiceImpl implements IDeviceService {
                     newJo.put("value", deviceOnlineEntity.getEartagTotal());
                 }
                 return new Result(ResultCode.SUCCESS, dataJa);
+            } else {
+                return new Result(BizConst.CODE_DEVICE_ONLINE_NO_EXIST, BizConst.MSG_DEVICE_ONLINE_NO_EXIST, false);
             }
-        } else {
-            return new Result(BizConst.CODE_DEVICE_ONLINE_NO_EXIST, BizConst.MSG_DEVICE_ONLINE_NO_EXIST, false);
-        }
     }
 
     /**
@@ -522,7 +580,7 @@ public class DeviceServiceImpl implements IDeviceService {
             return new Result(BizConst.CODE_DEVICE_REGISTER_NO_EXIST, BizConst.MSG_DEVICE_REGISTER_NO_EXIST, false);
         } else {
             JSONObject resultJo = (JSONObject) JSON.toJSON(deviceRegisterEntity);
-            resultJo.put("activeTime",dateUtil.formatDatetimeText(resultJo.getDate("activeTime")));
+            resultJo.put("activeTime", dateUtil.formatDatetimeText(resultJo.getDate("activeTime")));
 
             return new Result(ResultCode.SUCCESS, resultJo);
         }
@@ -538,9 +596,9 @@ public class DeviceServiceImpl implements IDeviceService {
      * @Time : 13:21
      */
     @Override
-    public Result listOnlineDevice(String farmId,String date) throws ParseException {
+    public Result listOnlineDevice(String farmId, String date) throws ParseException {
         DateUtil dateUtil = new DateUtil();
-        if(date == null){
+        if (date == null) {
             date = dateUtil.getTodayDateText();
         }
         //* 这里提供2种方式:1、从数据库读取 2、从缓存中取数(后期优化),但是同时提供2种方式都可用,防止缓存方式失效 */
@@ -574,10 +632,10 @@ public class DeviceServiceImpl implements IDeviceService {
 //                deviceOnlineEntity.setHeartbeatFirstTime(du.formatDatetimeText());
 //            }
             JSONArray resultJa = (JSONArray) JSON.toJSON(deviceOnlineEntityList);
-            for(int a=0;a<resultJa.size();a++){
+            for (int a = 0; a < resultJa.size(); a++) {
                 JSONObject resultJo = resultJa.getJSONObject(a);
-                resultJo.put("envtempFirstTime",du.formatDateText(resultJo.getTimestamp("envtempFirstTime")));
-                resultJo.put("envtempLastTime",du.formatDateText(resultJo.getTimestamp("envtempLastTime")));
+                resultJo.put("envtempFirstTime", du.formatDateText(resultJo.getTimestamp("envtempFirstTime")));
+                resultJo.put("envtempLastTime", du.formatDateText(resultJo.getTimestamp("envtempLastTime")));
             }
             return new Result(ResultCode.SUCCESS, resultJa);
         }

+ 4 - 0
huimv-eartag2-platform/huimv-eartag2-manage/src/main/java/com/huimv/eartag2/manage/service/impl/EartagServiceImpl.java

@@ -328,6 +328,10 @@ public class EartagServiceImpl implements IEartagService {
      * @Time : 21:54
      */
     private Result listEartagOnlineInRecords(String farmId, String addDate, Integer pageNo, Integer pageSize) throws ParseException {
+        System.out.println("# addDate>>"+addDate);
+        System.out.println("# farmId>>"+farmId);
+        System.out.println("# pageNo>>"+pageNo);
+        System.out.println("# pageSize>>"+pageSize);
         //
         Specification<EartagEartagOnlineEntity> sf = (Specification<EartagEartagOnlineEntity>) (root, criteriaQuery, criteriaBuilder) -> {
             //

+ 107 - 0
huimv-eartag2-platform/huimv-eartag2-manage/src/main/resources/application-prod.yml

@@ -0,0 +1,107 @@
+server:
+  port: 8092
+spring:
+  application:
+    name: huimv-eartag2-process
+
+  datasource:
+    url: jdbc:mysql://192.168.1.7:3306/huimv-eartag2-platform?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
+
+

+ 26 - 0
huimv-eartag2-platform/huimv-eartag2-manage/src/test/java/com/huimv/eartag2/manage/utils/MathUtilTest.java

@@ -0,0 +1,26 @@
+package com.huimv.eartag2.manage.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 MathUtilTest {
+    @Test
+    public void test_1(){
+        Long a = 122083123610001L;
+        Long b = 122083123610100L;
+//        Long c = 133108202895003L;
+        Long c = 122083123610105L;
+        boolean result = (c>=a && c<b) || (c>a && c<=b);
+        System.out.println("result>>"+result);
+
+    }
+}