Browse Source

新建电子秤取数、保存并转发功能。

zhuoning 3 năm trước cách đây
mục cha
commit
6d0c8d7ef0
20 tập tin đã thay đổi với 1333 bổ sung21 xóa
  1. 6 0
      huimv-farm-device/huimv-farm-local-weight/pom.xml
  2. 2 0
      huimv-farm-device/huimv-farm-local-weight/src/main/java/com/huimv/weight/HuimvWeightApplication.java
  3. 1 1
      huimv-farm-device/huimv-farm-local-weight/src/main/java/com/huimv/weight/client/EchoClient.java
  4. 5 1
      huimv-farm-device/huimv-farm-local-weight/src/main/java/com/huimv/weight/client/EchoClientHandler.java
  5. 119 0
      huimv-farm-device/huimv-farm-local-weight/src/main/java/com/huimv/weight/dao/entity/ProdDayWeightEntity.java
  6. 119 0
      huimv-farm-device/huimv-farm-local-weight/src/main/java/com/huimv/weight/dao/entity/ProdWeightEntity.java
  7. 24 0
      huimv-farm-device/huimv-farm-local-weight/src/main/java/com/huimv/weight/dao/repo/ProdDayWeightRepo.java
  8. 17 0
      huimv-farm-device/huimv-farm-local-weight/src/main/java/com/huimv/weight/dao/repo/ProdWeightRepo.java
  9. 28 0
      huimv-farm-device/huimv-farm-local-weight/src/main/java/com/huimv/weight/server/WeightDataHandle.java
  10. 0 12
      huimv-farm-device/huimv-farm-local-weight/src/main/java/com/huimv/weight/server/WeightDataHandler.java
  11. 4 1
      huimv-farm-device/huimv-farm-local-weight/src/main/java/com/huimv/weight/server/WeightServer.java
  12. 15 3
      huimv-farm-device/huimv-farm-local-weight/src/main/java/com/huimv/weight/server/WeightServerHandler.java
  13. 11 0
      huimv-farm-device/huimv-farm-local-weight/src/main/java/com/huimv/weight/service/IWeight.java
  14. 203 0
      huimv-farm-device/huimv-farm-local-weight/src/main/java/com/huimv/weight/service/impl/WeightImpl.java
  15. 34 0
      huimv-farm-device/huimv-farm-local-weight/src/main/java/com/huimv/weight/task/WeightTask.java
  16. 191 0
      huimv-farm-device/huimv-farm-local-weight/src/main/java/com/huimv/weight/utils/DateUtil.java
  17. 496 0
      huimv-farm-device/huimv-farm-local-weight/src/main/java/com/huimv/weight/utils/HttpTemplete.java
  18. 1 1
      huimv-farm-device/huimv-farm-local-weight/src/main/resources/application-prod.yml
  19. 9 2
      huimv-farm-device/huimv-farm-local-weight/src/main/resources/application.properties
  20. 48 0
      huimv-farm-device/huimv-farm-local-weight/src/test/java/com/huimv/weight/server/WeightDataHandlerTest.java

+ 6 - 0
huimv-farm-device/huimv-farm-local-weight/pom.xml

@@ -33,6 +33,12 @@
             <groupId>mysql</groupId>
             <artifactId>mysql-connector-java</artifactId>
         </dependency>
+        <dependency>
+            <groupId>cn.hutool</groupId>
+            <artifactId>hutool-all</artifactId>
+            <version>5.7.16</version>
+            <scope>compile</scope>
+        </dependency>
 
     </dependencies>
 </project>

+ 2 - 0
huimv-farm-device/huimv-farm-local-weight/src/main/java/com/huimv/weight/HuimvWeightApplication.java

@@ -4,6 +4,7 @@ import com.huimv.weight.server.WeightServer;
 import org.springframework.boot.SpringApplication;
 import org.springframework.boot.autoconfigure.SpringBootApplication;
 import org.springframework.context.ApplicationContext;
+import org.springframework.scheduling.annotation.EnableScheduling;
 
 /**
  * @Project : huimv.shiwan
@@ -14,6 +15,7 @@ import org.springframework.context.ApplicationContext;
  * @Create : 2020-12-25
  **/
 @SpringBootApplication
+@EnableScheduling
 public class HuimvWeightApplication {
     public static void main(String[] args) {
         ApplicationContext applicationContext = SpringApplication.run(HuimvWeightApplication.class, args);

+ 1 - 1
huimv-farm-device/huimv-farm-local-weight/src/main/java/com/huimv/weight/client/EchoClient.java

@@ -21,7 +21,7 @@ import java.net.InetSocketAddress;
  **/
 public class EchoClient {
     private final static String HOST = "36.26.62.70";
-    private final static int PORT = 10020;
+    private final static int PORT = 10070;
 
     public static void start() {
         EventLoopGroup group = new NioEventLoopGroup();

+ 5 - 1
huimv-farm-device/huimv-farm-local-weight/src/main/java/com/huimv/weight/client/EchoClientHandler.java

@@ -21,7 +21,11 @@ public class EchoClientHandler extends SimpleChannelInboundHandler<ByteBuf> {
     @Override
     public void channelActive(ChannelHandlerContext ctx) throws Exception {
         //当被通知Channel是活跃的时候,发送一条消息
-        ctx.writeAndFlush(Unpooled.copiedBuffer("Netty rocks!", CharsetUtil.UTF_8));
+//        ctx.writeAndFlush(Unpooled.copiedBuffer("Netty rocks!", CharsetUtil.UTF_8));
+        String text1 = "         6 kg " +
+                "         0 kg T " +
+                "         6 kg N";
+        ctx.writeAndFlush(Unpooled.copiedBuffer(text1, CharsetUtil.UTF_8));
     }
 
     @Override

+ 119 - 0
huimv-farm-device/huimv-farm-local-weight/src/main/java/com/huimv/weight/dao/entity/ProdDayWeightEntity.java

@@ -0,0 +1,119 @@
+package com.huimv.weight.dao.entity;
+
+import javax.persistence.*;
+import java.io.Serializable;
+import java.sql.Timestamp;
+
+@Entity
+@Table(name = "prod_day_weight")
+public class ProdDayWeightEntity implements Serializable {
+
+    private static final long serialVersionUID = 1L;
+
+    @Id
+    @GeneratedValue(strategy = GenerationType.IDENTITY)
+    @Column(name = "id", nullable = false)
+    private Integer id;
+
+    @Column(name = "add_time")
+    private Timestamp addTime;
+
+    /**
+     * 毛重
+     */
+    @Column(name = "gross_weight")
+    private Float grossWeight;
+
+    /**
+     * 皮重
+     */
+    @Column(name = "tare_weight")
+    private Float tareWeight;
+
+    /**
+     * 净重
+     */
+    @Column(name = "net_weight")
+    private Float netWeight;
+
+    @Column(name = "farm_id")
+    private Integer farmId;
+
+    public void setId(Integer id) {
+        this.id = id;
+    }
+
+    public Integer getId() {
+        return id;
+    }
+
+    public void setAddTime(Timestamp addTime) {
+        this.addTime = addTime;
+    }
+
+    public Timestamp getAddTime() {
+        return addTime;
+    }
+
+    /**
+     * 毛重
+     */
+    public void setGrossWeight(Float grossWeight) {
+        this.grossWeight = grossWeight;
+    }
+
+    /**
+     * 毛重
+     */
+    public Float getGrossWeight() {
+        return grossWeight;
+    }
+
+    /**
+     * 皮重
+     */
+    public void setTareWeight(Float tareWeight) {
+        this.tareWeight = tareWeight;
+    }
+
+    /**
+     * 皮重
+     */
+    public Float getTareWeight() {
+        return tareWeight;
+    }
+
+    /**
+     * 净重
+     */
+    public void setNetWeight(Float netWeight) {
+        this.netWeight = netWeight;
+    }
+
+    /**
+     * 净重
+     */
+    public Float getNetWeight() {
+        return netWeight;
+    }
+
+    public void setFarmId(Integer farmId) {
+        this.farmId = farmId;
+    }
+
+    public Integer getFarmId() {
+        return farmId;
+    }
+
+    @Override
+    public String toString() {
+        return "ProdDayWeightEntity{" +
+                "id=" + id + '\'' +
+                "addTime=" + addTime + '\'' +
+                "grossWeight=" + grossWeight + '\'' +
+                "tareWeight=" + tareWeight + '\'' +
+                "netWeight=" + netWeight + '\'' +
+                "farmId=" + farmId + '\'' +
+                '}';
+    }
+}

+ 119 - 0
huimv-farm-device/huimv-farm-local-weight/src/main/java/com/huimv/weight/dao/entity/ProdWeightEntity.java

@@ -0,0 +1,119 @@
+package com.huimv.weight.dao.entity;
+
+import javax.persistence.*;
+import java.io.Serializable;
+import java.sql.Timestamp;
+
+@Entity
+@Table(name = "prod_weight")
+public class ProdWeightEntity implements Serializable {
+
+    private static final long serialVersionUID = 1L;
+
+    @Id
+    @GeneratedValue(strategy = GenerationType.IDENTITY)
+    @Column(name = "id", nullable = false)
+    private Integer id;
+
+    @Column(name = "add_time")
+    private Timestamp addTime;
+
+    /**
+     * 毛重
+     */
+    @Column(name = "gross_weight")
+    private Float grossWeight;
+
+    /**
+     * 皮重
+     */
+    @Column(name = "tare_weight")
+    private Float tareWeight;
+
+    /**
+     * 净重
+     */
+    @Column(name = "net_weight")
+    private Float netWeight;
+
+    @Column(name = "farm_id")
+    private Integer farmId;
+
+    public void setId(Integer id) {
+        this.id = id;
+    }
+
+    public Integer getId() {
+        return id;
+    }
+
+    public void setAddTime(Timestamp addTime) {
+        this.addTime = addTime;
+    }
+
+    public Timestamp getAddTime() {
+        return addTime;
+    }
+
+    /**
+     * 毛重
+     */
+    public void setGrossWeight(Float grossWeight) {
+        this.grossWeight = grossWeight;
+    }
+
+    /**
+     * 毛重
+     */
+    public Float getGrossWeight() {
+        return grossWeight;
+    }
+
+    /**
+     * 皮重
+     */
+    public void setTareWeight(Float tareWeight) {
+        this.tareWeight = tareWeight;
+    }
+
+    /**
+     * 皮重
+     */
+    public Float getTareWeight() {
+        return tareWeight;
+    }
+
+    /**
+     * 净重
+     */
+    public void setNetWeight(Float netWeight) {
+        this.netWeight = netWeight;
+    }
+
+    /**
+     * 净重
+     */
+    public Float getNetWeight() {
+        return netWeight;
+    }
+
+    public Integer getFarmId() {
+        return farmId;
+    }
+
+    public void setFarmId(Integer farmId) {
+        this.farmId = farmId;
+    }
+
+    @Override
+    public String toString() {
+        return "ProdWeightEntity{" +
+                "id=" + id +
+                ", addTime=" + addTime +
+                ", grossWeight=" + grossWeight +
+                ", tareWeight=" + tareWeight +
+                ", netWeight=" + netWeight +
+                ", farmId=" + farmId +
+                '}';
+    }
+}

+ 24 - 0
huimv-farm-device/huimv-farm-local-weight/src/main/java/com/huimv/weight/dao/repo/ProdDayWeightRepo.java

@@ -0,0 +1,24 @@
+package com.huimv.weight.dao.repo;
+
+import com.huimv.weight.dao.entity.ProdDayWeightEntity;
+import org.springframework.data.jpa.repository.JpaRepository;
+import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
+import org.springframework.data.jpa.repository.Modifying;
+import org.springframework.data.jpa.repository.Query;
+import org.springframework.transaction.annotation.Transactional;
+
+import java.util.List;
+
+public interface ProdDayWeightRepo extends JpaRepository<ProdDayWeightEntity, Integer>, JpaSpecificationExecutor<ProdDayWeightEntity> {
+
+    @Query(nativeQuery = true,value ="SELECT * FROM prod_day_weight WHERE DATE_FORMAT(add_time,'%Y-%m-%d') = DATE_FORMAT(?1,'%Y-%m-%d') AND farm_id=?2")
+    List<ProdDayWeightEntity> findByFarmIdAndAddTime(String fromLongToDate,Integer farmID);
+
+    @Transactional
+    @Modifying(clearAutomatically = true, flushAutomatically = true)
+    @Query(nativeQuery = true,value = "DELETE FROM prod_day_weight WHERE DATE_FORMAT(add_time,'%Y-%m-%d') = DATE_FORMAT(?1,'%Y-%m-%d') AND farm_id=?2")
+    void removeByDateAndFarmId(String todayDateText, Integer farmID);
+
+    @Query(nativeQuery = true,value = "SELECT * FROM prod_day_weight WHERE DATE_FORMAT(add_time,'%Y-%m-%d') = DATE_FORMAT(?1,'%Y-%m-%d') AND farm_id=?2")
+    ProdDayWeightEntity findByDateAndFarmId(String todayDateText, Integer farmID);
+}

+ 17 - 0
huimv-farm-device/huimv-farm-local-weight/src/main/java/com/huimv/weight/dao/repo/ProdWeightRepo.java

@@ -0,0 +1,17 @@
+package com.huimv.weight.dao.repo;
+
+import com.huimv.weight.dao.entity.ProdWeightEntity;
+import org.springframework.data.jpa.repository.JpaRepository;
+import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
+import org.springframework.data.jpa.repository.Query;
+
+import java.util.List;
+
+public interface ProdWeightRepo extends JpaRepository<ProdWeightEntity, Integer>, JpaSpecificationExecutor<ProdWeightEntity> {
+
+    @Query(nativeQuery = true,value ="SELECT DATE_FORMAT(add_time,'%Y-%m-%d') AS add_time, SUM(gross_weight) AS gross_wegith,SUM(tare_weight) AS tare_weight,SUM(net_weight) AS net_weight,farm_id  FROM prod_weight WHERE DATE_FORMAT(add_time,'%Y-%m-%d')=DATE_FORMAT(?1,'%Y-%m-%d') AND farm_id=?2")
+    List<Object[]> countDayWeight(String todayDateText,Integer farmID);
+
+    @Query(nativeQuery = true,value ="SELECT * FROM prod_weight WHERE DATE_FORMAT(add_time,'%Y-%m-%d')=DATE_FORMAT(?1,'%Y-%m-%d') AND farm_id=?2")
+    List<ProdWeightEntity> countDayWeight2(String todayDateText,Integer farmID);
+}

+ 28 - 0
huimv-farm-device/huimv-farm-local-weight/src/main/java/com/huimv/weight/server/WeightDataHandle.java

@@ -0,0 +1,28 @@
+package com.huimv.weight.server;
+
+import com.huimv.weight.service.IWeight;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+import java.text.ParseException;
+
+/**
+ * @Project : huimv.shiwan
+ * @Package : com.huimv.biosafety.uface.controller
+ * @Description : TODO
+ * @Version : 1.0
+ * @Author : ZhuoNing
+ * @Create : 2020-12-25
+ **/
+@Component
+public class WeightDataHandle {
+    @Autowired
+    private IWeight weight;
+
+    //
+    public void handleReceiveData(String data) throws ParseException {
+        System.out.println("WeightDataHandle.data=" + data);
+        //
+        weight.handleReceiveData(data);
+    }
+}

+ 0 - 12
huimv-farm-device/huimv-farm-local-weight/src/main/java/com/huimv/weight/server/WeightDataHandler.java

@@ -1,12 +0,0 @@
-package com.huimv.weight.server;
-
-/**
- * @Project :
- * @Package :
- * @Description : TODO
- * @Version : 1.0
- * @Author : ZhuoNing
- * @Create : 2020-12-25
- **/
-public class WeightDataHandler {
-}

+ 4 - 1
huimv-farm-device/huimv-farm-local-weight/src/main/java/com/huimv/weight/server/WeightServer.java

@@ -7,6 +7,7 @@ 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.Component;
 
 import java.net.InetSocketAddress;
@@ -22,6 +23,8 @@ import java.net.InetSocketAddress;
 @Component
 public class WeightServer {
     private final static int port = 10070;
+    @Autowired
+    private WeightServerHandler serverHandler;
 
     public static void main(String[] args) {
         WeightServer dataServer = new WeightServer();
@@ -30,7 +33,7 @@ public class WeightServer {
 
     public void start() {
         System.out.println("# 监听端口      :" + port);
-        final WeightServerHandler serverHandler = new WeightServerHandler();
+//        final WeightServerHandler serverHandler = new WeightServerHandler();
         // 创建EventLoopGroup
         EventLoopGroup bossGroup = new NioEventLoopGroup();
         EventLoopGroup workerGroup = new NioEventLoopGroup();

+ 15 - 3
huimv-farm-device/huimv-farm-local-weight/src/main/java/com/huimv/weight/server/WeightServerHandler.java

@@ -1,5 +1,6 @@
 package com.huimv.weight.server;
 
+import com.huimv.weight.service.IWeight;
 import io.netty.buffer.ByteBuf;
 import io.netty.buffer.Unpooled;
 import io.netty.channel.ChannelFutureListener;
@@ -7,6 +8,8 @@ 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
@@ -18,16 +21,25 @@ import io.netty.util.CharsetUtil;
  **/
 
 @Sharable
+@Component
 public class WeightServerHandler extends ChannelInboundHandlerAdapter{
+//    @Autowired
+//    private IWeight weight;
+    @Autowired
+    private WeightDataHandle weightDataHandle;
     @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)
-        );
+//        System.out.println(
+//                "Server received: " + in.toString(CharsetUtil.UTF_8)
+//        );
+        String receiveInfo = in.toString(CharsetUtil.UTF_8);
+        //处理数据
+        weightDataHandle.handleReceiveData(receiveInfo);
+
         //将接收到的消息写给发送者,而不冲刷出站消息 (应答)
         ctx.write(in);
     }

+ 11 - 0
huimv-farm-device/huimv-farm-local-weight/src/main/java/com/huimv/weight/service/IWeight.java

@@ -0,0 +1,11 @@
+package com.huimv.weight.service;
+
+import java.text.ParseException;
+
+public interface IWeight {
+    //
+    void handleReceiveData(String receiveInfo) throws ParseException;
+
+    //发送日总重
+    void sendDayWeightToCenter();
+}

+ 203 - 0
huimv-farm-device/huimv-farm-local-weight/src/main/java/com/huimv/weight/service/impl/WeightImpl.java

@@ -0,0 +1,203 @@
+package com.huimv.weight.service.impl;
+
+import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONObject;
+import com.huimv.weight.dao.entity.ProdDayWeightEntity;
+import com.huimv.weight.dao.entity.ProdWeightEntity;
+import com.huimv.weight.dao.repo.ProdDayWeightRepo;
+import com.huimv.weight.dao.repo.ProdWeightRepo;
+import com.huimv.weight.service.IWeight;
+import com.huimv.weight.utils.DateUtil;
+import com.huimv.weight.utils.HttpTemplete;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.stereotype.Service;
+
+import java.io.IOException;
+import java.math.BigDecimal;
+import java.sql.Timestamp;
+import java.text.ParseException;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * @Project : huimv.shiwan
+ * @Package : com.huimv.biosafety.uface.controller
+ * @Description : TODO
+ * @Version : 1.0
+ * @Author : ZhuoNing
+ * @Create : 2020-12-25
+ **/
+@Service
+@Slf4j
+public class WeightImpl implements IWeight {
+    @Autowired
+    private DateUtil dateUtil;
+    @Autowired
+    private ProdWeightRepo weightRepo;
+    @Autowired
+    private ProdDayWeightRepo dayWeightRepo;
+    @Autowired
+    private HttpTemplete httpTemplete;
+    //牧场ID
+    @Value("${local.farmID}")
+    private Integer farmID;
+    //数据中心地址
+    @Value("${dataCenter.ipAddr}")
+    private String ipAddr ;
+    //数据中心地址
+    @Value("${dataCenter.port}")
+    private String port ;
+    //发送称重服务
+    @Value("${dataCenter.service.weight}")
+    private String weightService;
+
+    @Override
+    public void handleReceiveData(String receiveInfo) throws ParseException {
+//        dateUtil.fromLongToDate(new Date().getTime(),"yyyy-MM-dd HH:mm:ss");
+        System.out.println(dateUtil.fromLongToDate(new Date().getTime(),"yyyy-MM-dd HH:mm:ss")+",当前收到数据>>"+receiveInfo);
+        //解析数据
+        String data = receiveInfo.trim();
+        if(data.length() == 1){
+            if(Integer.parseInt(data) == 0){
+                System.out.println("当前接收到数据为0,为无效数据。");
+            }else{
+                //电子秤输出的数据模板有问题。
+                System.out.println("电子秤输出模板>>"+data);
+            }
+        }else{
+            //解析收到的质量毛重,皮重,净重
+            Map weightMap = _parseReceiveWeight(receiveInfo);
+//            System.out.println("weightMap>>"+weightMap.toString());
+            if(weightMap.size()>0){
+                //保存称重数据
+//                ProdWeightEntity addeightEntity = _saveWeight(farmID,weightMap);
+                _saveWeight(weightMap);
+
+                //计算每天总重
+//                _sendWeightToCenter(JSON.toJSON(addeightEntity).toString());
+                _countDayWeight();
+
+                //转发数据到数据中心
+                sendDayWeightToCenter();
+            }
+        }
+    }
+
+    @Override
+    public void sendDayWeightToCenter() {
+//        System.out.println("sendDayWeightToCenter 发送每日总重数据到数据中心。");
+        //查找日总重
+        List<ProdDayWeightEntity> dayWeightEntityList = dayWeightRepo.findByFarmIdAndAddTime(dateUtil.fromLongToDate(new Date().getTime(),"yyyy-MM-dd"),farmID);
+//        System.out.println("每天总称重数据>>"+dayWeightEntityList.size());
+        if(dayWeightEntityList.size()>0){
+            ProdDayWeightEntity dayWeightEntity = dayWeightEntityList.get(0);
+            System.out.println("dayWeightEntity.toString>>"+dayWeightEntity.toString());
+            //发送数据
+            _doPostSimple(JSON.toJSONString(dayWeightEntity));
+        }
+    }
+
+    //发送简单数据
+    public void _doPostSimple(String data){
+        String url = ipAddr + port + weightService;
+        log.info("推送数据地址:"+url);
+        //
+        Map<String,String> paramsMap = new HashMap<String,String>();
+        paramsMap.put("data", data);
+        //
+        Map<String,Integer> timeoutMap = new HashMap<String,Integer>();
+        timeoutMap.put("connectTimeout", 5000);
+        timeoutMap.put("requestTimeout", 5000);
+        timeoutMap.put("socketTimeout", 5000);
+        try{
+            // 用Post方法推送接口数据
+            httpTemplete.doPost(url,paramsMap,timeoutMap);
+        } catch (IOException e) {
+            System.out.println("###错误信息:"+e.getMessage());
+        }
+    }
+
+    // 计算每天总重
+    private void _countDayWeight()  {
+        //
+        String todayDateText = dateUtil.fromLongToDate(new Date().getTime(),"yyyy-MM-dd");
+        //计算当天总重
+//        List<Object[]> dayWeightList = weightRepo.countDayWeight(todayDateText,farmID);
+//        JSONObject weightJo = new JSONObject();
+//        for(int a=0;a<dayWeightList.size();a++){
+//            Object[] weihtObj = (Object[]) dayWeightList.get(a);
+//            weightJo.put("addTime",weihtObj[0]);
+//            weightJo.put("grossWegith",weihtObj[1]);
+//            weightJo.put("tareWeight",weihtObj[2]);
+//            weightJo.put("netWeight",weihtObj[3]);
+//        }
+        List<ProdWeightEntity> dayWeightEntityList = weightRepo.countDayWeight2(todayDateText,farmID);
+        if(dayWeightEntityList.size()>0){
+            //查找数据
+            ProdDayWeightEntity dayWeightEntity = dayWeightRepo.findByDateAndFarmId(todayDateText,farmID);
+            if(dayWeightEntity != null){
+                BigDecimal grossBd = new BigDecimal(0);
+                BigDecimal tareBd = new BigDecimal(0);
+                BigDecimal netBd = new BigDecimal(0);
+                for(ProdWeightEntity weightEntity:dayWeightEntityList){
+                    grossBd = new BigDecimal(weightEntity.getGrossWeight()).add(grossBd);
+                    tareBd = new BigDecimal(weightEntity.getTareWeight()).add(tareBd);
+                    netBd = new BigDecimal(weightEntity.getNetWeight()).add(netBd);
+                }
+//                ProdDayWeightEntity dayWeightEntity = new ProdDayWeightEntity();
+                dayWeightEntity.setAddTime(new Timestamp(new Date().getTime()));
+                dayWeightEntity.setFarmId(farmID);
+                dayWeightEntity.setGrossWeight(Float.parseFloat(grossBd.toString()));
+                dayWeightEntity.setTareWeight(Float.parseFloat(tareBd.toString()));
+                dayWeightEntity.setNetWeight(Float.parseFloat(netBd.toString()));
+                dayWeightRepo.save(dayWeightEntity);
+            }else{
+                BigDecimal grossBd = new BigDecimal(0);
+                BigDecimal tareBd = new BigDecimal(0);
+                BigDecimal netBd = new BigDecimal(0);
+                for(ProdWeightEntity weightEntity:dayWeightEntityList){
+                    grossBd = new BigDecimal(weightEntity.getGrossWeight()).add(grossBd);
+                    tareBd = new BigDecimal(weightEntity.getTareWeight()).add(tareBd);
+                    netBd = new BigDecimal(weightEntity.getNetWeight()).add(netBd);
+                }
+                ProdDayWeightEntity dayWeightEntity1 = new ProdDayWeightEntity();
+                dayWeightEntity1.setAddTime(new Timestamp(new Date().getTime()));
+                dayWeightEntity1.setFarmId(farmID);
+                dayWeightEntity1.setGrossWeight(Float.parseFloat(grossBd.toString()));
+                dayWeightEntity1.setTareWeight(Float.parseFloat(tareBd.toString()));
+                dayWeightEntity1.setNetWeight(Float.parseFloat(netBd.toString()));
+                dayWeightRepo.save(dayWeightEntity1);
+            }
+        }
+    }
+
+    //保存重量
+    private ProdWeightEntity _saveWeight(Map weightMap) {
+        ProdWeightEntity weightEntity = new ProdWeightEntity();
+        weightEntity.setFarmId(farmID);
+        weightEntity.setAddTime(new Timestamp(new Date().getTime()));
+        weightEntity.setGrossWeight(Float.parseFloat(weightMap.get("grossWeight").toString()));
+        weightEntity.setTareWeight(Float.parseFloat(weightMap.get("tareWeight").toString()));
+        weightEntity.setNetWeight(Float.parseFloat(weightMap.get("netWeight").toString()));
+        return weightRepo.save(weightEntity);
+    }
+
+    //
+    private Map _parseReceiveWeight(String receiveInfo) {
+        receiveInfo = receiveInfo.replace("T","").replace("N","").replace("\n","");
+        String[] weightArray = receiveInfo.split("kg");
+
+//        for(int a=0;a<weightArray.length;a++){
+//            System.out.println((a+1)+","+weightArray[a].trim());
+//        }
+        Map weightMap = new HashMap();
+        weightMap.put("grossWeight",weightArray[0].trim());
+        weightMap.put("tareWeight",weightArray[1].trim());
+        weightMap.put("netWeight",weightArray[2].trim());
+        return weightMap;
+    }
+}

+ 34 - 0
huimv-farm-device/huimv-farm-local-weight/src/main/java/com/huimv/weight/task/WeightTask.java

@@ -0,0 +1,34 @@
+package com.huimv.weight.task;
+
+import com.huimv.weight.service.IWeight;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.scheduling.annotation.EnableScheduling;
+import org.springframework.scheduling.annotation.Scheduled;
+import org.springframework.web.bind.annotation.RestController;
+
+import java.io.IOException;
+
+/**
+ * @Project : huimv.shiwan
+ * @Package : com.huimv.biosafety.uface.controller
+ * @Description : TODO
+ * @Version : 1.0
+ * @Author : ZhuoNing
+ * @Create : 2020-12-25
+ **/
+@Configuration
+@EnableScheduling
+@RestController
+public class WeightTask {
+
+    @Autowired
+    private IWeight weight;
+
+//    @Scheduled(cron = "0/2 * * * * ?")
+    private void sendDayWeight()  {
+        System.out.println("sendDayWeight......");
+        //
+        weight.sendDayWeightToCenter();
+    }
+}

+ 191 - 0
huimv-farm-device/huimv-farm-local-weight/src/main/java/com/huimv/weight/utils/DateUtil.java

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

+ 496 - 0
huimv-farm-device/huimv-farm-local-weight/src/main/java/com/huimv/weight/utils/HttpTemplete.java

@@ -0,0 +1,496 @@
+package com.huimv.weight.utils;
+
+import com.alibaba.fastjson.JSONObject;
+import org.apache.http.HttpEntity;
+import org.apache.http.NameValuePair;
+import org.apache.http.client.config.RequestConfig;
+import org.apache.http.client.entity.UrlEncodedFormEntity;
+import org.apache.http.client.methods.*;
+import org.apache.http.impl.client.CloseableHttpClient;
+import org.apache.http.impl.client.HttpClients;
+import org.apache.http.message.BasicNameValuePair;
+import org.apache.http.util.EntityUtils;
+import org.springframework.stereotype.Component;
+
+import java.io.IOException;
+import java.util.*;
+
+/**
+ * @Project : huimv.shiwan
+ * @Package : com.huimv.biosafety.uface.controller
+ * @Description : TODO
+ * @Version : 1.0
+ * @Author : ZhuoNing
+ * @Create : 2020-12-25
+ **/
+@Component
+public class HttpTemplete {
+    private String testHttpIp = "http://localhost:9105";
+
+//    public static void main(String[] args) throws Exception {
+//        //
+//        HttpTemplete client = new HttpTemplete();
+////        client.testGetRequest1();
+//        client.testGetRequest2();
+//    }
+    private Integer connectTimeout = null;
+    private Integer requestTimeout = null;
+    private Integer socketTimeout = null;
+
+    static {
+    }
+
+    /**
+     * @Method      : doPost
+     * @Description : post方式推送接口
+     * @Params      : [url, paramsMap, timeoutMap]
+     * @Return      : com.alibaba.fastjson.JSONObject
+     * 
+     * @Author      : ZhuoNing
+     * @Date        : 2021/11/19       
+     * @Time        : 14:55
+     */
+    public JSONObject doPost(String url, Map<String, String> paramsMap, Map<String, Integer> timeoutMap) throws IOException {
+        // 创建默认的httpClient实例.
+        CloseableHttpClient httpClient = getHttpClientConnection();
+        //
+        int connectTimeout = timeoutMap.get("connectTimeout");
+        int requestTimeout = timeoutMap.get("requestTimeout");
+        int socketTimeout = timeoutMap.get("socketTimeout");
+        // 创建httpPost
+        HttpPost httpPost = new HttpPost(url);
+        RequestConfig requestConfig = RequestConfig.custom()
+                .setSocketTimeout(socketTimeout) //服务器响应超时时间
+                .setConnectTimeout(connectTimeout) //连接服务器超时时间
+                .setConnectionRequestTimeout(requestTimeout)
+                .build();
+        httpPost.setConfig(requestConfig);
+        // 创建参数队列
+        List<NameValuePair> paramsList = new ArrayList<NameValuePair>();
+        Set<Map.Entry<String, String>> entrySet = paramsMap.entrySet();
+        for (Map.Entry<String, String> e : entrySet) {
+            String name = e.getKey();
+            String value = e.getValue();
+            NameValuePair pair = new BasicNameValuePair(name, value);
+            paramsList.add(pair);
+        }
+        UrlEncodedFormEntity content = new UrlEncodedFormEntity(paramsList, "UTF-8");
+        //处理乱码
+//        StringEntity content = new StringEntity(paramsList.toString(), Charset.forName("UTF-8"));// 第二个参数,设置后才会对,内容进行编码
+//        content.setContentType("application/soap+xml; charset=UTF-8");
+//        content.setContentEncoding("UTF-8");
+        httpPost.setEntity(content);
+//        HttpUriRequest httpPost = RequestBuilder.post().setUri(url).setEntity(content).setConfig(requestConfig);
+        CloseableHttpResponse response = httpClient.execute(httpPost);
+        // 获取响应实体
+        HttpEntity entity = response.getEntity();
+        try {
+            if (response.getStatusLine().getStatusCode() == 200) {
+                // 打印响应内容
+                String text = EntityUtils.toString(entity, "utf-8");
+                JSONObject resultJo = new JSONObject();
+                resultJo.put("status", true);
+                resultJo.put("content", text);
+                return resultJo;
+            }else{
+                String text = EntityUtils.toString(entity, "utf-8");
+                JSONObject resultJo = new JSONObject();
+                resultJo.put("status", false);
+                resultJo.put("content", text);
+                return resultJo;
+            }
+        } finally {
+            //释放资源
+            if (response != null) {
+                response.close();
+            }
+            if (httpClient != null) {
+                httpClient.close();
+            }
+        }
+    }
+
+    /**
+     * @Method      : setTimeout
+     * @Description : 
+     * @Params      : [connectTimeout, requestTimeout, socketTimeout]
+     * @Return      : void
+     * 
+     * @Author      : ZhuoNing
+     * @Date        : 2021/11/23       
+     * @Time        : 9:36
+     */
+    public Map<String, Integer> setTimeout(Integer connectTimeout, Integer requestTimeout, Integer socketTimeout){
+        //
+        if(connectTimeout == null){
+            this.connectTimeout = 3000;
+        }else{
+            this.connectTimeout = connectTimeout;
+        }
+        //
+        if(requestTimeout == null){
+            this.requestTimeout = 3000;
+        }else{
+            this.requestTimeout = requestTimeout;
+        }
+        //
+        if(socketTimeout == null){
+            this.socketTimeout = 3000;
+        }else{
+            this.socketTimeout = socketTimeout;
+        }
+        Map<String, Integer> timeoutMap = new HashMap<String, Integer>();
+        timeoutMap.put("connectTimeout", this.connectTimeout);
+        timeoutMap.put("requestTimeout", this.requestTimeout);
+        timeoutMap.put("socketTimeout", this.socketTimeout);
+        return timeoutMap;
+    }
+
+    /**
+     * @Method      : setTimeout
+     * @Description : 
+     * @Params      : [connectTimeout, requestTimeout, socketTimeout]
+     * @Return      : java.util.Map<java.lang.String,java.lang.Integer>
+     * 
+     * @Author      : ZhuoNing
+     * @Date        : 2021/11/23       
+     * @Time        : 9:41
+     */
+    public Map<String, Integer> setTimeout(String connectTimeout, String requestTimeout, String socketTimeout){
+        //
+        if(connectTimeout == null){
+            this.connectTimeout = 3000;
+        }else{
+            this.connectTimeout = Integer.parseInt(connectTimeout);
+        }
+        //
+        if(requestTimeout == null){
+            this.requestTimeout = 3000;
+        }else{
+            this.requestTimeout = Integer.parseInt(requestTimeout);
+        }
+        //
+        if(socketTimeout == null){
+            this.socketTimeout = 3000;
+        }else{
+            this.socketTimeout = Integer.parseInt(socketTimeout);
+        }
+        Map<String, Integer> timeoutMap = new HashMap<String, Integer>();
+        timeoutMap.put("connectTimeout", this.connectTimeout);
+        timeoutMap.put("requestTimeout", this.requestTimeout);
+        timeoutMap.put("socketTimeout", this.socketTimeout);
+        return timeoutMap;
+    }
+
+    /**
+     * @Method      : doGet
+     * @Description : 
+     * @Params      : [url, paramsMap]
+     * @Return      : com.alibaba.fastjson.JSONObject
+     * 
+     * @Author      : ZhuoNing
+     * @Date        : 2021/11/23       
+     * @Time        : 9:34
+     */
+    public JSONObject doGet(String url, Map<String, String> paramsMap) throws IOException {
+        //
+        if(this.connectTimeout == null){
+            this.connectTimeout = 3000;
+        }
+        //
+        if(this.requestTimeout == null)
+        {
+            this.requestTimeout = 3000;
+        }
+        //
+        if(this.socketTimeout == null){
+            this.socketTimeout = 3000;
+        }
+        Map<String, Integer> timeoutMap = new HashMap<String, Integer>();
+        timeoutMap.put("connectTimeout", this.connectTimeout);
+        timeoutMap.put("requestTimeout", this.requestTimeout);
+        timeoutMap.put("socketTimeout", this.socketTimeout);
+        //
+        CloseableHttpClient httpClient = getHttpClientConnection();
+        //执行//获取请求内容
+        CloseableHttpResponse response = httpClient.execute(getHttpRequest(url, paramsMap, timeoutMap));
+        try {
+            // 获取响应实体
+            HttpEntity entity = response.getEntity();
+            // 打印响应状态
+            if (response.getStatusLine().getStatusCode() == 200) {
+                // 打印响应内容
+                String text = EntityUtils.toString(entity, "utf-8");
+                JSONObject resultJo = new JSONObject();
+                resultJo.put("status", true);
+                resultJo.put("content", text);
+                return resultJo;
+            } else {
+                String text = EntityUtils.toString(entity, "utf-8");
+                JSONObject resultJo = new JSONObject();
+                resultJo.put("status", false);
+                resultJo.put("content", text);
+                return resultJo;
+            }
+        } finally {
+            //释放资源
+            if (response != null) {
+                response.close();
+            }
+            if (httpClient != null) {
+                httpClient.close();
+            }
+        }
+    }
+
+    private CloseableHttpClient httpClient = null;
+    private CloseableHttpResponse response = null;
+
+    public JSONObject doGetBatch(String url, Map<String, String> paramsMap) throws IOException {
+        //
+        if(this.connectTimeout == null){
+            this.connectTimeout = 3000;
+        }
+        //
+        if(this.requestTimeout == null)
+        {
+            this.requestTimeout = 3000;
+        }
+        //
+        if(this.socketTimeout == null){
+            this.socketTimeout = 3000;
+        }
+        Map<String, Integer> timeoutMap = new HashMap<String, Integer>();
+        timeoutMap.put("connectTimeout", this.connectTimeout);
+        timeoutMap.put("requestTimeout", this.requestTimeout);
+        timeoutMap.put("socketTimeout", this.socketTimeout);
+        //
+        httpClient = getHttpClientConnection();
+        //执行//获取请求内容
+        response = httpClient.execute(getHttpRequest(url, paramsMap, timeoutMap));
+        // 获取响应实体
+        HttpEntity entity = response.getEntity();
+        // 打印响应状态
+        if (response.getStatusLine().getStatusCode() == 200) {
+                // 打印响应内容
+                String text = EntityUtils.toString(entity, "utf-8");
+                JSONObject resultJo = new JSONObject();
+                resultJo.put("status", true);
+                resultJo.put("content", text);
+                return resultJo;
+        } else {
+                String text = EntityUtils.toString(entity, "utf-8");
+                JSONObject resultJo = new JSONObject();
+                resultJo.put("status", false);
+                resultJo.put("content", text);
+                return resultJo;
+        }
+    }
+
+    //关闭http连接
+    public void closeHttpConn() throws IOException {
+        System.out.println("开始释放http连接资源");
+        //释放资源
+        if (response != null) {
+            response.close();
+        }
+        if (httpClient != null) {
+            httpClient.close();
+        }
+    }
+
+    /**
+     * @Method : doGet
+     * @Description :get方式推送接口
+     * @Params : [url, paramsMap, timeoutMap]
+     * @Return : com.alibaba.fastjson.JSONObject
+     * @Author : ZhuoNing
+     * @Date : 2021/11/18
+     * @Time : 17:39
+     */
+    public JSONObject doGet(String url, Map<String, String> paramsMap, Map<String, Integer> timeoutMap) throws IOException {
+        if (timeoutMap == null) {
+            timeoutMap.put("connectTimeout", 5000);
+            timeoutMap.put("requestTimeout", 5000);
+            timeoutMap.put("socketTimeout", 5000);
+        }
+        //
+        CloseableHttpClient httpClient = getHttpClientConnection();
+        //执行//获取请求内容
+        CloseableHttpResponse response = httpClient.execute(getHttpRequest(url, paramsMap, timeoutMap));
+        try {
+            // 获取响应实体
+            HttpEntity entity = response.getEntity();
+            // 打印响应状态
+            if (response.getStatusLine().getStatusCode() == 200) {
+                // 打印响应内容
+                String text = EntityUtils.toString(entity, "utf-8");
+                JSONObject resultJo = new JSONObject();
+                resultJo.put("status", true);
+                resultJo.put("content", text);
+                return resultJo;
+            } else {
+                String text = EntityUtils.toString(entity, "utf-8");
+                JSONObject resultJo = new JSONObject();
+                resultJo.put("status", false);
+                resultJo.put("content", text);
+                return resultJo;
+            }
+        } finally {
+            //释放资源
+            if (response != null) {
+                response.close();
+            }
+            if (httpClient != null) {
+                httpClient.close();
+            }
+        }
+    }
+
+    private void testGetRequest1() throws IOException {
+        Map<String, Integer> timeoutMap = new HashMap<String, Integer>();
+        timeoutMap.put("connectTimeout", 5000);
+        timeoutMap.put("requestTimeout", 5000);
+        timeoutMap.put("socketTimeout", 5000);
+        String url = testHttpIp + "/token/getToken?userId=20210501&timestamp=45546546454&random=1156&sign=7fa431325504e01e9fa87ed0e274c40c";
+        // test error
+        url = testHttpIp + "/token/getToken?userId=20210501&timestamp=45546546454&random=1156&sign=7fa431325504e01e9fa87ed0e274c40c&userId=20210501&timestamp=45546546454&random=1156&sign=7fa431325504e01e9fa87ed0e274c40c";
+        CloseableHttpClient httpClient = getHttpClientConnection();
+        CloseableHttpResponse response = httpClient.execute(getHttpRequest(url, timeoutMap));
+        // 打印响应状态
+        System.out.println("响应状态1 =" + response.getStatusLine());
+        try {
+            if (response.getStatusLine().getStatusCode() == 200) {
+                // 获取响应实体
+                HttpEntity entity = response.getEntity();
+                // 打印响应内容
+                String text = EntityUtils.toString(entity, "utf-8");
+                System.out.println("响应内容=" + text);
+
+                JSONObject resultJo = JSONObject.parseObject(text);
+                System.out.println("accessToken=" + resultJo.getString("accessToken"));
+            } else {
+                System.out.println("请求失败");
+            }
+        } finally {
+            //释放资源
+            if (response != null) {
+                response.close();
+            }
+            if (httpClient != null) {
+                httpClient.close();
+            }
+        }
+    }
+
+    //
+    private CloseableHttpClient getHttpClientConnection() {
+        //创建默认实例
+        CloseableHttpClient httpclient = HttpClients.createDefault();
+        //
+//        CloseableHttpClient httpClient = HttpClientBuilder.create().build();
+        return httpclient;
+    }
+    //
+    private HttpUriRequest getHttpRequest(String url, Map<String, String> map, Map<String, Integer> timeoutMap) {
+        int connectTimeout = timeoutMap.get("connectTimeout");
+        int requestTimeout = timeoutMap.get("requestTimeout");
+        int socketTimeout = timeoutMap.get("socketTimeout");
+//        System.out.println("core connectTimeout="+connectTimeout);
+//        System.out.println("core requestTimeout="+requestTimeout);
+//        System.out.println("core socketTimeout="+socketTimeout);
+
+        List<NameValuePair> params = new ArrayList<NameValuePair>();
+        Set<Map.Entry<String, String>> entrySet = map.entrySet();
+        for (Map.Entry<String, String> e : entrySet) {
+            String name = e.getKey();
+            String value = e.getValue();
+            NameValuePair pair = new BasicNameValuePair(name, value);
+            params.add(pair);
+        }
+        //
+        RequestConfig requestConfig = RequestConfig.custom()
+                .setConnectTimeout(connectTimeout).setConnectionRequestTimeout(requestTimeout)
+                .setSocketTimeout(socketTimeout).build();
+        HttpUriRequest httpGet = RequestBuilder.get().setUri(url)
+                .addParameters(params.toArray(new BasicNameValuePair[params.size()]))
+                .setConfig(requestConfig).build();
+        return httpGet;
+    }
+    //
+    private HttpGet getHttpRequest(String url, Map<String, Integer> timeoutMap) {
+        int connectTimeout = timeoutMap.get("connectTimeout");
+        int requestTimeout = timeoutMap.get("requestTimeout");
+        int socketTimeout = timeoutMap.get("socketTimeout");
+
+        HttpGet httpGet = new HttpGet(url);
+        //设置超时时间
+        RequestConfig requestConfig = RequestConfig.custom()
+                .setConnectTimeout(connectTimeout).setConnectionRequestTimeout(requestTimeout)
+                .setSocketTimeout(socketTimeout).build();
+        httpGet.setConfig(requestConfig);
+        return httpGet;
+    }
+
+    //test
+    private void get() {
+//        CloseableHttpClient httpclient = HttpClients.createDefault();
+//        try {
+//            // 创建httpget.
+//            HttpGet httpget = new HttpGet(httpIp + "/token/getToken?userId=20210501&timestamp=45546546454&random=1156&sign=7fa431325504e01e9fa87ed0e274c40c");
+//            System.out.println("executing request " + httpget.getURI());
+//            // 执行get请求.
+//            CloseableHttpResponse response = httpclient.execute(httpget);
+//            try {
+//                // 获取响应实体
+//                HttpEntity entity = response.getEntity();
+//                System.out.println("--------------------------------------");
+//                // 打印响应状态
+//                System.out.println(response.getStatusLine());
+//                if (entity != null) {
+//                    // 打印响应内容长度
+//                    System.out.println("Response content length: " + entity.getContentLength());
+//                    // 打印响应内容
+//                    System.out.println("Response content: " + EntityUtils.toString(entity));
+//                }
+//                System.out.println("------------------------------------");
+//            } finally {
+//                response.close();
+//            }
+//        } catch (ClientProtocolException e) {
+//            e.printStackTrace();
+//        } catch (ParseException e) {
+//            e.printStackTrace();
+//        } catch (IOException e) {
+//            e.printStackTrace();
+//        } finally {
+//            // 关闭连接,释放资源
+//            try {
+//                httpclient.close();
+//            } catch (IOException e) {
+//                e.printStackTrace();
+//            }
+//        }
+    }
+
+
+    private void getRequest() throws IOException {
+//        //1.打开浏览器
+//        CloseableHttpClient httpClient = HttpClients.createDefault();
+//        //2.声明get请求
+//        HttpGet httpGet = new HttpGet(httpIp + "/token/getToken?userId=20210501&timestamp=45546546454&random=1156&sign=7fa431325504e01e9fa87ed0e274c40c");
+//        //3.发送请求
+//        CloseableHttpResponse response = httpClient.execute(httpGet);
+//        System.out.println("StatusCode=" + response.getStatusLine().getStatusCode());
+//        //4.判断状态码
+//        if (response.getStatusLine().getStatusCode() == 200) {
+//            HttpEntity entity = response.getEntity();
+//            //使用工具类EntityUtils,从响应中取出实体表示的内容并转换成字符串
+//            String string = EntityUtils.toString(entity, "utf-8");
+//            System.out.println(string);
+//        }
+//        //5.关闭资源
+//        response.close();
+//        httpClient.close();
+    }
+}

Những thai đổi đã bị hủy bỏ vì nó quá lớn
+ 1 - 1
huimv-farm-device/huimv-farm-local-weight/src/main/resources/application-prod.yml


+ 9 - 2
huimv-farm-device/huimv-farm-local-weight/src/main/resources/application.properties

@@ -1,7 +1,14 @@
+#spring.profiles.active=dev
 spring.profiles.active=prod
+
 #时间格式配置
 spring.jackson.date-format=yyyy-MM-dd HH:mm:ss
 spring.jackson.time-zone=GMT+8
-#spring.profiles.active=test
-
 
+# 数据中心数据推送地址
+dataCenter.ipAddr=http://115.238.57.190
+dataCenter.port=:10091
+# 称重数据服务
+dataCenter.service.weight=/receiver/farm/weight/putDayWeight
+# 部署牧场ID(base_farm.id)
+local.farmID=1

+ 48 - 0
huimv-farm-device/huimv-farm-local-weight/src/test/java/com/huimv/weight/server/WeightDataHandlerTest.java

@@ -0,0 +1,48 @@
+package com.huimv.weight.server;
+
+import com.huimv.weight.service.IWeight;
+import org.junit.jupiter.api.Test;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.transaction.event.TransactionalEventListener;
+
+import java.text.ParseException;
+
+/**
+ * @Project : huimv.shiwan
+ * @Package : com.huimv.biosafety.uface.controller
+ * @Description : TODO
+ * @Version : 1.0
+ * @Author : ZhuoNing
+ * @Create : 2020-12-25
+ **/
+@SpringBootTest
+public class WeightDataHandlerTest {
+    @Autowired
+    private com.huimv.weight.service.IWeight iWeight;
+
+    @Test
+    public void handleReceiveInfo() throws ParseException {
+//        String text = "模拟电子秤数据 ##weight=213,date=2021-12-05,id=123456";
+        // 真实数据
+        String text = "         6 kg \n" +
+                "         1 kg T \n" +
+                "         5 kg N\n" +
+                "\n" +
+                "\n";
+        //去掉换行字符
+        String text1 = "         6 kg " +
+                "         0 kg T " +
+                "         6 kg N";
+//        text1 = text1.replace("T","").replace("N","");
+//        String[] textArray = text1.split("kg");
+//
+//        for(int a=0;a<textArray.length;a++){
+//            System.out.println((a+1)+","+textArray[a].trim());
+//        }
+        //皮重=tare weight,毛重=gross weight,净重=Net Weight
+//        weightDataHandler.handleReceiveData("             0     ");
+        iWeight.handleReceiveData(text1);
+
+    }
+}