فهرست منبع

接收器电子秤和环境监测数据已经完成代码的重构迁移。

zhuoning 3 سال پیش
والد
کامیت
8e9cb1837a
20فایلهای تغییر یافته به همراه1421 افزوده شده و 18 حذف شده
  1. 9 0
      huimv-farm-receiver/doc/design.txt
  2. 58 0
      huimv-farm-receiver/pom.xml
  3. 36 0
      huimv-farm-receiver/src/main/java/com/huimv/receiver/cloud/controller/EnvironController.java
  4. 104 0
      huimv-farm-receiver/src/main/java/com/huimv/receiver/cloud/dao/entity/EnvDayEntity.java
  5. 309 0
      huimv-farm-receiver/src/main/java/com/huimv/receiver/cloud/dao/entity/EnvHourEntity.java
  6. 21 0
      huimv-farm-receiver/src/main/java/com/huimv/receiver/cloud/dao/repo/EnvDayRepo.java
  7. 25 0
      huimv-farm-receiver/src/main/java/com/huimv/receiver/cloud/dao/repo/EnvHourRepo.java
  8. 13 0
      huimv-farm-receiver/src/main/java/com/huimv/receiver/cloud/service/IEnviron.java
  9. 8 0
      huimv-farm-receiver/src/main/java/com/huimv/receiver/cloud/service/IWarningInfo.java
  10. 226 0
      huimv-farm-receiver/src/main/java/com/huimv/receiver/cloud/service/impl/EnvironImpl.java
  11. 29 0
      huimv-farm-receiver/src/main/java/com/huimv/receiver/cloud/service/impl/WarningInfoImpl.java
  12. 36 0
      huimv-farm-receiver/src/main/java/com/huimv/receiver/farm/controller/WeightController.java
  13. 128 0
      huimv-farm-receiver/src/main/java/com/huimv/receiver/farm/dao/entity/ProdBatchWeightEntity.java
  14. 92 0
      huimv-farm-receiver/src/main/java/com/huimv/receiver/farm/dao/entity/ProdDayWeightEntity.java
  15. 12 0
      huimv-farm-receiver/src/main/java/com/huimv/receiver/farm/dao/repo/ProdBatchWeightRepo.java
  16. 14 0
      huimv-farm-receiver/src/main/java/com/huimv/receiver/farm/dao/repo/ProdDayWeightRepo.java
  17. 9 0
      huimv-farm-receiver/src/main/java/com/huimv/receiver/farm/service/IWeight.java
  18. 99 0
      huimv-farm-receiver/src/main/java/com/huimv/receiver/farm/service/impl/WeightImpl.java
  19. 191 0
      huimv-farm-receiver/src/main/java/com/huimv/receiver/utils/DateUtil.java
  20. 2 18
      huimv-farm-receiver/src/main/resources/application-dev.yml

+ 9 - 0
huimv-farm-receiver/doc/design.txt

@@ -0,0 +1,9 @@
+中央应用接收器设计说明:(huimv-device-receiver)
+这个数据接收器分别接收牧场端设备数据和云端设备接收器。
+当前是集中式部署,以后根据实际需要可能拆分成2个独立的数据接收通道,分别部署牧场端设备接收器和云端设备接收器。
+
+
+
+
+
+

+ 58 - 0
huimv-farm-receiver/pom.xml

@@ -11,5 +11,63 @@
 
     <artifactId>huimv-farm-receiver</artifactId>
 
+    <description>Demo project for Spring Boot</description>
+    <properties>
+        <java.version>1.8</java.version>
+    </properties>
+    <dependencies>
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-starter-web</artifactId>
+        </dependency>
 
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-starter-test</artifactId>
+            <scope>test</scope>
+        </dependency>
+
+        <!-- fastjson -->
+        <dependency>
+            <groupId>com.alibaba</groupId>
+            <artifactId>fastjson</artifactId>
+            <version>1.2.62</version>
+        </dependency>
+        <!-- JPA -->
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-starter-data-jpa</artifactId>
+        </dependency>
+        <!-- mysql -->
+        <dependency>
+            <groupId>mysql</groupId>
+            <artifactId>mysql-connector-java</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.projectlombok</groupId>
+            <artifactId>lombok</artifactId>
+            <version>1.18.4</version>
+        </dependency>
+        <dependency>
+            <groupId>cn.hutool</groupId>
+            <artifactId>hutool-all</artifactId>
+            <version>5.7.16</version>
+            <scope>compile</scope>
+        </dependency>
+    </dependencies>
+
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>org.springframework.boot</groupId>
+                <artifactId>spring-boot-maven-plugin</artifactId>
+            </plugin>
+
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-resources-plugin</artifactId>
+                <version>2.6</version>
+            </plugin>
+        </plugins>
+    </build>
 </project>

+ 36 - 0
huimv-farm-receiver/src/main/java/com/huimv/receiver/cloud/controller/EnvironController.java

@@ -0,0 +1,36 @@
+package com.huimv.receiver.cloud.controller;
+
+import com.huimv.receiver.cloud.service.IEnviron;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.*;
+
+import java.text.ParseException;
+
+/**
+ * @Project : huimv.shiwan
+ * @Package : com.huimv.biosafety.uface.controller
+ * @Description : TODO
+ * @Version : 1.0
+ * @Author : ZhuoNing
+ * @Create : 2020-12-25
+ **/
+@CrossOrigin
+@RestController
+@RequestMapping(value = "/receiver/cloud/environ")
+public class EnvironController {
+    @Autowired
+    private IEnviron environ;
+
+    //接收小时环保
+    @RequestMapping(value = "/putHourEnviron",method = RequestMethod.POST)
+    public void receivetHourEnviron(@RequestParam(value = "data",required = true) String data) throws ParseException {
+        //
+        environ.handleEnvironJSONObject(data);
+    }
+
+    //接收实时环保数据
+    @RequestMapping(value = "/putRealTimeEnviron",method = RequestMethod.POST)
+    public void receiveRealTimeEnviron(@RequestParam(value = "data",required = true) String data){
+        System.out.println("处理实时环保数据:"+data);
+    }
+}

+ 104 - 0
huimv-farm-receiver/src/main/java/com/huimv/receiver/cloud/dao/entity/EnvDayEntity.java

@@ -0,0 +1,104 @@
+package com.huimv.receiver.cloud.dao.entity;
+
+import javax.persistence.*;
+import java.io.Serializable;
+import java.util.Date;
+
+@Entity
+@Table(name = "env_day")
+public class EnvDayEntity implements Serializable {
+
+    private static final long serialVersionUID = 1L;
+
+    @Id
+    @GeneratedValue(strategy = GenerationType.IDENTITY)
+    @Column(name = "id", nullable = false)
+    private Integer id;
+
+    @Column(name = "farm_id")
+    private Integer farmId;
+
+    @Column(name = "add_date")
+    private Date addDate;
+
+    @Column(name = "cod")
+    private String cod;
+
+    @Column(name = "ad")
+    private String ad;
+
+    @Column(name = "ph")
+    private String ph;
+
+    @Column(name = "ws")
+    private String ws;
+
+    public void setId(Integer id) {
+        this.id = id;
+    }
+
+    public Integer getId() {
+        return id;
+    }
+
+    public void setFarmId(Integer farmId) {
+        this.farmId = farmId;
+    }
+
+    public Integer getFarmId() {
+        return farmId;
+    }
+
+    public Date getAddDate() {
+        return addDate;
+    }
+
+    public void setAddDate(Date addDate) {
+        this.addDate = addDate;
+    }
+
+    public void setCod(String cod) {
+        this.cod = cod;
+    }
+
+    public String getCod() {
+        return cod;
+    }
+
+    public void setAd(String ad) {
+        this.ad = ad;
+    }
+
+    public String getAd() {
+        return ad;
+    }
+
+    public void setPh(String ph) {
+        this.ph = ph;
+    }
+
+    public String getPh() {
+        return ph;
+    }
+
+    public void setWs(String ws) {
+        this.ws = ws;
+    }
+
+    public String getWs() {
+        return ws;
+    }
+
+    @Override
+    public String toString() {
+        return "EnvDayEntity{" +
+                "id=" + id +
+                ", farmId=" + farmId +
+                ", addDate=" + addDate +
+                ", cod='" + cod + '\'' +
+                ", ad='" + ad + '\'' +
+                ", ph='" + ph + '\'' +
+                ", ws='" + ws + '\'' +
+                '}';
+    }
+}

+ 309 - 0
huimv-farm-receiver/src/main/java/com/huimv/receiver/cloud/dao/entity/EnvHourEntity.java

@@ -0,0 +1,309 @@
+package com.huimv.receiver.cloud.dao.entity;
+
+import javax.persistence.*;
+import java.io.Serializable;
+import java.sql.Timestamp;
+
+@Entity
+@Table(name = "env_hour")
+public class EnvHourEntity implements Serializable {
+
+    private static final long serialVersionUID = 1L;
+
+    @Id
+    @GeneratedValue(strategy = GenerationType.IDENTITY)
+    @Column(name = "id", nullable = false)
+    private Integer id;
+
+    @Column(name = "qn")
+    private String qn;
+
+    @Column(name = "st")
+    private String st;
+
+    @Column(name = "cn")
+    private String cn;
+
+    @Column(name = "mn")
+    private String mn;
+
+    @Column(name = "datetime")
+    private Timestamp datetime;
+
+    @Column(name = "hxxyl_zx")
+    private String hxxylZx;
+
+    @Column(name = "hxxyl_zd")
+    private String hxxylZd;
+
+    @Column(name = "hxxyl_pj")
+    private String hxxylPj;
+
+    @Column(name = "hxxylzt")
+    private String hxxylzt;
+
+    @Column(name = "ad_zx")
+    private String adZx;
+
+    @Column(name = "ad_zd")
+    private String adZd;
+
+    @Column(name = "ad_pj")
+    private String adPj;
+
+    @Column(name = "adzt")
+    private String adzt;
+
+    @Column(name = "ph_zx")
+    private String phZx;
+
+    @Column(name = "ph_zd")
+    private String phZd;
+
+    @Column(name = "ph_pj")
+    private String phPj;
+
+    @Column(name = "phzt")
+    private String phzt;
+
+    @Column(name = "ws_zx")
+    private String wsZx;
+
+    @Column(name = "ws_zd")
+    private String wsZd;
+
+    @Column(name = "ws_pj")
+    private String wsPj;
+
+    @Column(name = "wszt")
+    private String wszt;
+
+    @Column(name = "add_time")
+    private Timestamp addTime;
+
+    @Column(name = "farm_id")
+    private Integer farmId;
+
+    public Integer getFarmId() {
+        return farmId;
+    }
+
+    @Override
+    public String toString() {
+        return "EnvHourEntity{" +
+                "id=" + id +
+                ", qn='" + qn + '\'' +
+                ", st='" + st + '\'' +
+                ", cn='" + cn + '\'' +
+                ", mn='" + mn + '\'' +
+                ", datetime=" + datetime +
+                ", hxxylZx='" + hxxylZx + '\'' +
+                ", hxxylZd='" + hxxylZd + '\'' +
+                ", hxxylPj='" + hxxylPj + '\'' +
+                ", hxxylzt='" + hxxylzt + '\'' +
+                ", adZx='" + adZx + '\'' +
+                ", adZd='" + adZd + '\'' +
+                ", adPj='" + adPj + '\'' +
+                ", adzt='" + adzt + '\'' +
+                ", phZx='" + phZx + '\'' +
+                ", phZd='" + phZd + '\'' +
+                ", phPj='" + phPj + '\'' +
+                ", phzt='" + phzt + '\'' +
+                ", wsZx='" + wsZx + '\'' +
+                ", wsZd='" + wsZd + '\'' +
+                ", wsPj='" + wsPj + '\'' +
+                ", wszt='" + wszt + '\'' +
+                ", addTime=" + addTime +
+                ", farmId=" + farmId +
+                '}';
+    }
+
+    public void setFarmId(Integer farmId) {
+        this.farmId = farmId;
+    }
+
+    public void setId(Integer id) {
+        this.id = id;
+    }
+
+    public Integer getId() {
+        return id;
+    }
+
+    public void setQn(String qn) {
+        this.qn = qn;
+    }
+
+    public String getQn() {
+        return qn;
+    }
+
+    public void setSt(String st) {
+        this.st = st;
+    }
+
+    public String getSt() {
+        return st;
+    }
+
+    public void setCn(String cn) {
+        this.cn = cn;
+    }
+
+    public String getCn() {
+        return cn;
+    }
+
+    public void setMn(String mn) {
+        this.mn = mn;
+    }
+
+    public String getMn() {
+        return mn;
+    }
+
+    public void setDatetime(Timestamp datetime) {
+        this.datetime = datetime;
+    }
+
+    public Timestamp getDatetime() {
+        return datetime;
+    }
+
+    public void setHxxylZx(String hxxylZx) {
+        this.hxxylZx = hxxylZx;
+    }
+
+    public String getHxxylZx() {
+        return hxxylZx;
+    }
+
+    public void setHxxylZd(String hxxylZd) {
+        this.hxxylZd = hxxylZd;
+    }
+
+    public String getHxxylZd() {
+        return hxxylZd;
+    }
+
+    public void setHxxylPj(String hxxylPj) {
+        this.hxxylPj = hxxylPj;
+    }
+
+    public String getHxxylPj() {
+        return hxxylPj;
+    }
+
+    public void setHxxylzt(String hxxylzt) {
+        this.hxxylzt = hxxylzt;
+    }
+
+    public String getHxxylzt() {
+        return hxxylzt;
+    }
+
+    public void setAdZx(String adZx) {
+        this.adZx = adZx;
+    }
+
+    public String getAdZx() {
+        return adZx;
+    }
+
+    public void setAdZd(String adZd) {
+        this.adZd = adZd;
+    }
+
+    public String getAdZd() {
+        return adZd;
+    }
+
+    public void setAdPj(String adPj) {
+        this.adPj = adPj;
+    }
+
+    public String getAdPj() {
+        return adPj;
+    }
+
+    public void setAdzt(String adzt) {
+        this.adzt = adzt;
+    }
+
+    public String getAdzt() {
+        return adzt;
+    }
+
+    public void setPhZx(String phZx) {
+        this.phZx = phZx;
+    }
+
+    public String getPhZx() {
+        return phZx;
+    }
+
+    public void setPhZd(String phZd) {
+        this.phZd = phZd;
+    }
+
+    public String getPhZd() {
+        return phZd;
+    }
+
+    public void setPhPj(String phPj) {
+        this.phPj = phPj;
+    }
+
+    public String getPhPj() {
+        return phPj;
+    }
+
+    public void setPhzt(String phzt) {
+        this.phzt = phzt;
+    }
+
+    public String getPhzt() {
+        return phzt;
+    }
+
+    public void setWsZx(String wsZx) {
+        this.wsZx = wsZx;
+    }
+
+    public String getWsZx() {
+        return wsZx;
+    }
+
+    public void setWsZd(String wsZd) {
+        this.wsZd = wsZd;
+    }
+
+    public String getWsZd() {
+        return wsZd;
+    }
+
+    public void setWsPj(String wsPj) {
+        this.wsPj = wsPj;
+    }
+
+    public String getWsPj() {
+        return wsPj;
+    }
+
+    public void setWszt(String wszt) {
+        this.wszt = wszt;
+    }
+
+    public String getWszt() {
+        return wszt;
+    }
+
+    public void setAddTime(Timestamp addTime) {
+        this.addTime = addTime;
+    }
+
+    public Timestamp getAddTime() {
+        return addTime;
+    }
+
+}

+ 21 - 0
huimv-farm-receiver/src/main/java/com/huimv/receiver/cloud/dao/repo/EnvDayRepo.java

@@ -0,0 +1,21 @@
+package com.huimv.receiver.cloud.dao.repo;
+
+import com.huimv.receiver.cloud.dao.entity.EnvDayEntity;
+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.Optional;
+
+public interface EnvDayRepo extends JpaRepository<EnvDayEntity, Integer>, JpaSpecificationExecutor<EnvDayEntity> {
+
+    @Transactional
+    @Modifying(clearAutomatically = true, flushAutomatically = true)
+    @Query(nativeQuery = true,value ="DELETE FROM env_day WHERE farm_id=?1 AND DATE_FORMAT(add_date,'%Y-%m-%d')=DATE_FORMAT(?2,'%Y-%m-%d')")
+    void removeByFarmIdAndDate(Integer farmId, String todayDateText);
+
+    @Query(nativeQuery = true,value ="SELECT * FROM env_day WHERE farm_id=?1 AND DATE_FORMAT(add_date,'%Y-%m-%d')=DATE_FORMAT(?2,'%Y-%m-%d')")
+    Optional<EnvDayEntity> findByFarmIdAndDate(Integer farmId, String todayDateText);
+}

+ 25 - 0
huimv-farm-receiver/src/main/java/com/huimv/receiver/cloud/dao/repo/EnvHourRepo.java

@@ -0,0 +1,25 @@
+package com.huimv.receiver.cloud.dao.repo;
+
+import com.huimv.receiver.cloud.dao.entity.EnvHourEntity;
+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 EnvHourRepo extends JpaRepository<EnvHourEntity, Integer>, JpaSpecificationExecutor<EnvHourEntity> {
+
+    @Query(nativeQuery = true,value ="SELECT AVG(hxxyl_pj) AS hxxyl,AVG(ad_pj) AS ad,AVG(ph_pj) AS ph,AVG(ws_pj) AS ws FROM env_hour WHERE farm_id=?1 AND DATE_FORMAT(datetime,'%m-%d-%Y')=DATE_FORMAT(?2,'%m-%d-%Y')")
+    List<Object[]> findByFarmIdAndDate_old1(Integer farmId, String todayDateText);
+
+    //
+    @Query(nativeQuery = true,value ="SELECT farm_id,datetime, hxxyl_pj AS hxxyl,ad_pj AS ad,ph_pj AS ph,ws_pj AS ws FROM env_hour WHERE farm_id=?1 AND DATE_FORMAT(datetime,'%Y-%m-%d')=DATE_FORMAT(?2,'%Y-%m-%d')")
+    List<Object[]> findByFarmIdAndDate(Integer farmId, String todayDateText);
+
+    @Transactional
+    @Modifying(clearAutomatically = true, flushAutomatically = true)
+    @Query(nativeQuery = true,value ="DELETE FROM env_day WHERE farm_id=?1 AND DATE_FORMAT(add_date,'%Y-%m-%d')=DATE_FORMAT(?2,'%Y-%m-%d')")
+    void removeByFarmIdAndDate(Integer farmId, String todayDateText);
+}

+ 13 - 0
huimv-farm-receiver/src/main/java/com/huimv/receiver/cloud/service/IEnviron.java

@@ -0,0 +1,13 @@
+package com.huimv.receiver.cloud.service;
+
+import java.text.ParseException;
+
+public interface IEnviron {
+    //
+    void handleEnvironJSONArray(String data);
+
+    //
+    void handleEnvironJSONObject(String data) throws ParseException;
+
+    void countDayAvgEnviron(Integer farmId, String todayDateText) throws ParseException;
+}

+ 8 - 0
huimv-farm-receiver/src/main/java/com/huimv/receiver/cloud/service/IWarningInfo.java

@@ -0,0 +1,8 @@
+package com.huimv.receiver.cloud.service;
+
+import com.huimv.receiver.cloud.dao.entity.EnvHourEntity;
+
+public interface IWarningInfo {
+    //处理报警信息
+    void handleWarningInfo(EnvHourEntity envHourEntity);
+}

+ 226 - 0
huimv-farm-receiver/src/main/java/com/huimv/receiver/cloud/service/impl/EnvironImpl.java

@@ -0,0 +1,226 @@
+package com.huimv.receiver.cloud.service.impl;
+
+import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
+import com.huimv.receiver.cloud.dao.entity.EnvDayEntity;
+import com.huimv.receiver.cloud.dao.entity.EnvHourEntity;
+import com.huimv.receiver.cloud.dao.repo.EnvDayRepo;
+import com.huimv.receiver.cloud.dao.repo.EnvHourRepo;
+import com.huimv.receiver.cloud.service.IEnviron;
+import com.huimv.receiver.cloud.service.IWarningInfo;
+import com.huimv.receiver.utils.DateUtil;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.math.BigDecimal;
+import java.sql.Timestamp;
+import java.text.ParseException;
+import java.util.Date;
+import java.util.List;
+import java.util.Optional;
+
+/**
+ * @Project : huimv.shiwan
+ * @Package : com.huimv.biosafety.uface.controller
+ * @Description : TODO
+ * @Version : 1.0
+ * @Author : ZhuoNing
+ * @Create : 2020-12-25
+ **/
+@Service
+public class EnvironImpl implements IEnviron {
+    @Autowired
+    private EnvHourRepo envHourRepo;
+    @Autowired
+    private EnvDayRepo envDayRepo;
+    @Autowired
+    private IWarningInfo warningInfo;
+    @Autowired
+    private DateUtil dateUtil;
+
+    @Override
+    public void handleEnvironJSONArray(String data) {
+        //JSON数组转化对象
+        List<EnvHourEntity> envHourEntityList = JSON.parseArray(data, EnvHourEntity.class);
+        int a = 0;
+        for (EnvHourEntity envHourEntity : envHourEntityList) {
+            envHourRepo.save(envHourEntity);
+//            System.out.println(""+(++a));
+        }
+    }
+
+    /**
+     * @Method : handleEnvironJSONObject
+     * @Description :
+     * @Params : [data]
+     * @Return : void
+     * @Author : ZhuoNing
+     * @Date : 2021/12/2
+     * @Time : 23:46
+     */
+    @Override
+    public void handleEnvironJSONObject(String data) throws ParseException {
+        System.out.println("接收数据>>"+data);
+//        JSONObject deviceJo = JSON.parseObject(data);
+        EnvHourEntity envHourEntity = JSON.parseObject(data, EnvHourEntity.class);
+        envHourRepo.save(envHourEntity);
+
+        Integer farmId = envHourEntity.getFarmId();
+//        String todayDateText = dateUtil.formatTimestampToDate(envHourEntity.getAddTime());
+//        String todayDateTimeText = dateUtil.formatTimestampToDatetime(envHourEntity.getDatetime());
+//        System.out.println(">>>>>>>>>>> 采样时间 todayDateTimeText>>"+todayDateTimeText);
+        String todayDateText = dateUtil.formatTimestampToDate(envHourEntity.getDatetime());
+//        System.out.println(">>>>>>>>>>> 采样日期 todayDateText>>"+todayDateText);
+
+        //计算每天平均数据
+        countDayAvgEnviron2(farmId, todayDateText);
+    }
+
+    // 计算每天都平均数据
+    public void countDayAvgEnviron2(Integer farmId, String todayDateText) throws ParseException {
+        System.out.println("计算每天的环保数据");
+        System.out.println("farmId="+farmId);
+        System.out.println("todayDateText="+todayDateText);
+        //计算平均数
+        List<Object[]> envHourEntityList = envHourRepo.findByFarmIdAndDate(farmId, todayDateText);
+        System.out.println("每天小时采集数envHourEntityList.size>>"+envHourEntityList.size());
+
+        if (envHourEntityList.size() > 0) {
+            //更新新数据
+            JSONArray dataJa = new JSONArray();
+            for (int a = 0; a < envHourEntityList.size(); a++) {
+                JSONObject dataJo = new JSONObject();
+                dataJa.add(dataJo);
+                Object[] avgObj = (Object[]) envHourEntityList.get(a);
+                dataJo.put("cod", avgObj[2]);
+                dataJo.put("ad", avgObj[3]);
+                dataJo.put("ph", avgObj[4]);
+                dataJo.put("ws", avgObj[5]);
+            }
+            BigDecimal codBd = new BigDecimal(0);
+            BigDecimal adBd = new BigDecimal(0);
+            BigDecimal phBd = new BigDecimal(0);
+            BigDecimal wsBd = new BigDecimal(0);
+
+            for (int a = 0; a < dataJa.size(); a++) {
+                JSONObject dataJo = dataJa.getJSONObject(a);
+                codBd = new BigDecimal(dataJo.getString("cod")).add(codBd);
+                adBd = new BigDecimal(dataJo.getString("ad")).add(adBd);
+                phBd = new BigDecimal(dataJo.getString("ph")).add(phBd);
+                wsBd = new BigDecimal(dataJo.getString("ws")).add(wsBd);
+            }
+            //精度位数
+            int bit = 3;
+            double codDouble = codBd.divide(new BigDecimal(dataJa.size()), 3, BigDecimal.ROUND_HALF_UP).setScale(bit, BigDecimal.ROUND_HALF_UP).doubleValue();
+            double adDouble = adBd.divide(new BigDecimal(dataJa.size()), 3, BigDecimal.ROUND_HALF_UP).setScale(bit, BigDecimal.ROUND_HALF_UP).doubleValue();
+            double phDouble = phBd.divide(new BigDecimal(dataJa.size()), 3, BigDecimal.ROUND_HALF_UP).setScale(bit, BigDecimal.ROUND_HALF_UP).doubleValue();
+            double wsDouble = wsBd.divide(new BigDecimal(dataJa.size()), 3, BigDecimal.ROUND_HALF_UP).setScale(bit, BigDecimal.ROUND_HALF_UP).doubleValue();
+            Optional<EnvDayEntity> option = envDayRepo.findByFarmIdAndDate(farmId, todayDateText);
+            if(option.isPresent()){
+                System.out.println("更新数据");
+                //更新数据
+                EnvDayEntity envDayEntity = option.get();
+                envDayEntity.setAd(String.valueOf(adDouble));
+                envDayEntity.setCod(String.valueOf(codDouble));
+                envDayEntity.setPh(String.valueOf(phDouble));
+                envDayEntity.setWs(String.valueOf(wsDouble));
+                envDayEntity.setFarmId(farmId);
+                envDayEntity.setAddDate(dateUtil.parseDate(todayDateText));
+                //保存
+                envDayRepo.saveAndFlush(envDayEntity);
+            }else{
+                System.out.println("增加新数据");
+                //增加新数据
+                EnvDayEntity envDayEntity = new EnvDayEntity();
+                envDayEntity.setAd(String.valueOf(adDouble));
+                envDayEntity.setCod(String.valueOf(codDouble));
+                envDayEntity.setPh(String.valueOf(phDouble));
+                envDayEntity.setWs(String.valueOf(wsDouble));
+                envDayEntity.setFarmId(farmId);
+                envDayEntity.setAddDate(dateUtil.parseDate(todayDateText));
+                //保存
+                envDayRepo.saveAndFlush(envDayEntity);
+            }
+        }
+    }
+
+    @Override
+    public void countDayAvgEnviron(Integer farmId, String todayDateText) throws ParseException {
+        System.out.println("计算每天的环保数据");
+        System.out.println("farmId="+farmId);
+        System.out.println("todayDateText="+todayDateText);
+        //计算平均数
+        List<Object[]> envHourEntityList = envHourRepo.findByFarmIdAndDate(farmId, todayDateText);
+        System.out.println("每天小时采集数envHourEntityList.size>>"+envHourEntityList.size());
+
+        if (envHourEntityList.size() > 0) {
+            //删除旧数据
+//            envHourRepo.removeByFarmIdAndDate(farmId, todayDateText);
+            envDayRepo.removeByFarmIdAndDate(farmId, todayDateText);
+
+            JSONArray dataJa = new JSONArray();
+            for (int a = 0; a < envHourEntityList.size(); a++) {
+                JSONObject dataJo = new JSONObject();
+                dataJa.add(dataJo);
+                Object[] avgObj = (Object[]) envHourEntityList.get(a);
+                dataJo.put("cod", avgObj[2]);
+                dataJo.put("ad", avgObj[3]);
+                dataJo.put("ph", avgObj[4]);
+                dataJo.put("ws", avgObj[5]);
+            }
+            BigDecimal codBd = new BigDecimal(0);
+            BigDecimal adBd = new BigDecimal(0);
+            BigDecimal phBd = new BigDecimal(0);
+            BigDecimal wsBd = new BigDecimal(0);
+
+            for (int a = 0; a < dataJa.size(); a++) {
+                JSONObject dataJo = dataJa.getJSONObject(a);
+                codBd = new BigDecimal(dataJo.getString("cod")).add(codBd);
+                adBd = new BigDecimal(dataJo.getString("ad")).add(adBd);
+                phBd = new BigDecimal(dataJo.getString("ph")).add(phBd);
+                wsBd = new BigDecimal(dataJo.getString("ws")).add(wsBd);
+            }
+            //精度位数
+            int bit = 3;
+            double codDouble = codBd.divide(new BigDecimal(dataJa.size()), 3, BigDecimal.ROUND_HALF_UP).setScale(bit, BigDecimal.ROUND_HALF_UP).doubleValue();
+            double adDouble = adBd.divide(new BigDecimal(dataJa.size()), 3, BigDecimal.ROUND_HALF_UP).setScale(bit, BigDecimal.ROUND_HALF_UP).doubleValue();
+            double phDouble = phBd.divide(new BigDecimal(dataJa.size()), 3, BigDecimal.ROUND_HALF_UP).setScale(bit, BigDecimal.ROUND_HALF_UP).doubleValue();
+            double wsDouble = wsBd.divide(new BigDecimal(dataJa.size()), 3, BigDecimal.ROUND_HALF_UP).setScale(bit, BigDecimal.ROUND_HALF_UP).doubleValue();
+            EnvDayEntity envDayEntity = new EnvDayEntity();
+            envDayEntity.setAd(String.valueOf(adDouble));
+            envDayEntity.setCod(String.valueOf(codDouble));
+            envDayEntity.setPh(String.valueOf(phDouble));
+            envDayEntity.setWs(String.valueOf(wsDouble));
+            envDayEntity.setFarmId(farmId);
+            envDayEntity.setAddDate(dateUtil.parseDate(todayDateText));
+            //保存
+            envDayRepo.saveAndFlush(envDayEntity);
+        }
+    }
+
+    public void countDayAvgEnviron_old1(Integer farmId, String todayDateText) {
+        System.out.println("farmId=" + farmId);
+        System.out.println("todayDateText=" + todayDateText);
+        //计算平均数
+        List<Object[]> avgList = envHourRepo.findByFarmIdAndDate_old1(farmId, todayDateText);
+        if (avgList.size() > 0) {
+            JSONObject dataJo = new JSONObject();
+            for (int a = 0; a < avgList.size(); a++) {
+                Object[] avgObj = (Object[]) avgList.get(a);
+                dataJo.put("farm_id", farmId);
+                dataJo.put("add_time", new Timestamp(new Date().getTime()));
+                dataJo.put("cod", avgObj[0]);
+                dataJo.put("ad", avgObj[1]);
+                dataJo.put("ph", avgObj[2]);
+                dataJo.put("ws", avgObj[3]);
+            }
+            System.out.println("dataJo>>" + dataJo);
+            EnvDayEntity envDayEntity = JSON.toJavaObject(dataJo, EnvDayEntity.class);
+            //保存
+            envDayRepo.save(envDayEntity);
+        }
+    }
+
+
+}

+ 29 - 0
huimv-farm-receiver/src/main/java/com/huimv/receiver/cloud/service/impl/WarningInfoImpl.java

@@ -0,0 +1,29 @@
+package com.huimv.receiver.cloud.service.impl;
+
+import com.huimv.receiver.cloud.dao.entity.EnvHourEntity;
+import com.huimv.receiver.cloud.service.IWarningInfo;
+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 WarningInfoImpl implements IWarningInfo {
+
+    //处理报警信息
+    @Override
+    public void handleWarningInfo(EnvHourEntity envHourEntity) {
+        //氨氮
+
+        //化学需氧量
+
+        //PH
+
+        //瞬时流量
+    }
+}

+ 36 - 0
huimv-farm-receiver/src/main/java/com/huimv/receiver/farm/controller/WeightController.java

@@ -0,0 +1,36 @@
+package com.huimv.receiver.farm.controller;
+
+import com.huimv.receiver.farm.service.IWeight;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.*;
+
+/**
+ * @Project : huimv.shiwan
+ * @Package : com.huimv.biosafety.uface.controller
+ * @Description : TODO
+ * @Version : 1.0
+ * @Author : ZhuoNing
+ * @Create : 2020-12-25
+ **/
+@CrossOrigin
+@RestController
+@RequestMapping(value = "/receiver/farm/weight")
+public class WeightController {
+    @Autowired
+    private IWeight weight;
+
+    //保存日总重
+    @RequestMapping(value = "/putDayWeight",method = RequestMethod.POST)
+    public void putDayWeight(@RequestParam(value = "data",required = true) String data){
+        //
+        weight.saveDayWeight(data);
+    }
+
+    //保存批次总重
+    @RequestMapping(value = "/putBatchWeight",method = RequestMethod.POST)
+    public void putBatchWeight(@RequestParam(value = "data",required = true) String data){
+        //
+        weight.saveBatchWeight(data);
+    }
+
+}

+ 128 - 0
huimv-farm-receiver/src/main/java/com/huimv/receiver/farm/dao/entity/ProdBatchWeightEntity.java

@@ -0,0 +1,128 @@
+package com.huimv.receiver.farm.dao.entity;
+
+import javax.persistence.*;
+import java.io.Serializable;
+import java.sql.Timestamp;
+
+@Entity
+@Table(name = "prod_batch_weight")
+public class ProdBatchWeightEntity implements Serializable {
+
+    private static final long serialVersionUID = 1L;
+
+    @Id
+    @GeneratedValue(strategy = GenerationType.IDENTITY)
+    @Column(name = "id", nullable = false)
+    private Integer id;
+
+    @Column(name = "batch_code")
+    private String batchCode;
+
+    @Column(name = "batch_sort")
+    private Integer batchSort;
+
+    @Column(name = "gross_weight")
+    private Float grossWeight;
+
+    @Column(name = "tare_weight")
+    private Float tareWeight;
+
+    @Column(name = "net_weight")
+    private Float netWeight;
+
+    @Column(name = "trade_id")
+    private Integer tradeId;
+
+    @Column(name = "farm_id")
+    private Integer farmId;
+
+    @Column(name = "add_time")
+    private Timestamp addTime;
+
+    public void setId(Integer id) {
+        this.id = id;
+    }
+
+    public Integer getId() {
+        return id;
+    }
+
+    public void setBatchCode(String batchCode) {
+        this.batchCode = batchCode;
+    }
+
+    public String getBatchCode() {
+        return batchCode;
+    }
+
+    public void setBatchSort(Integer batchSort) {
+        this.batchSort = batchSort;
+    }
+
+    public Integer getBatchSort() {
+        return batchSort;
+    }
+
+    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 setTradeId(Integer tradeId) {
+        this.tradeId = tradeId;
+    }
+
+    public Integer getTradeId() {
+        return tradeId;
+    }
+
+    public void setFarmId(Integer farmId) {
+        this.farmId = farmId;
+    }
+
+    public Integer getFarmId() {
+        return farmId;
+    }
+
+    public void setAddTime(Timestamp addTime) {
+        this.addTime = addTime;
+    }
+
+    public Timestamp getAddTime() {
+        return addTime;
+    }
+
+    @Override
+    public String toString() {
+        return "ProdBatchWeightEntity{" +
+                "id=" + id + '\'' +
+                "batchCode=" + batchCode + '\'' +
+                "batchSort=" + batchSort + '\'' +
+                "grossWeight=" + grossWeight + '\'' +
+                "tareWeight=" + tareWeight + '\'' +
+                "netWeight=" + netWeight + '\'' +
+                "tradeId=" + tradeId + '\'' +
+                "farmId=" + farmId + '\'' +
+                "addTime=" + addTime + '\'' +
+                '}';
+    }
+}

+ 92 - 0
huimv-farm-receiver/src/main/java/com/huimv/receiver/farm/dao/entity/ProdDayWeightEntity.java

@@ -0,0 +1,92 @@
+package com.huimv.receiver.farm.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 = "farm_id")
+    private Integer farmId;
+
+    @Column(name = "gross_weight")
+    private Float grossWeight;
+
+    @Column(name = "net_weight")
+    private Float netWeight;
+
+    @Column(name = "tare_weight")
+    private Float tareWeight;
+
+    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 setFarmId(Integer farmId) {
+        this.farmId = farmId;
+    }
+
+    public Integer getFarmId() {
+        return farmId;
+    }
+
+    public void setGrossWeight(Float grossWeight) {
+        this.grossWeight = grossWeight;
+    }
+
+    public Float getGrossWeight() {
+        return grossWeight;
+    }
+
+    public void setNetWeight(Float netWeight) {
+        this.netWeight = netWeight;
+    }
+
+    public Float getNetWeight() {
+        return netWeight;
+    }
+
+    public void setTareWeight(Float tareWeight) {
+        this.tareWeight = tareWeight;
+    }
+
+    public Float getTareWeight() {
+        return tareWeight;
+    }
+
+    @Override
+    public String toString() {
+        return "ProdDayWeightEntity{" +
+                "id=" + id + '\'' +
+                "addTime=" + addTime + '\'' +
+                "farmId=" + farmId + '\'' +
+                "grossWeight=" + grossWeight + '\'' +
+                "netWeight=" + netWeight + '\'' +
+                "tareWeight=" + tareWeight + '\'' +
+                '}';
+    }
+}

+ 12 - 0
huimv-farm-receiver/src/main/java/com/huimv/receiver/farm/dao/repo/ProdBatchWeightRepo.java

@@ -0,0 +1,12 @@
+package com.huimv.receiver.farm.dao.repo;
+
+import com.huimv.receiver.farm.dao.entity.ProdBatchWeightEntity;
+import org.springframework.data.jpa.repository.JpaRepository;
+import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
+import org.springframework.data.jpa.repository.Query;
+
+public interface ProdBatchWeightRepo extends JpaRepository<ProdBatchWeightEntity, Integer>, JpaSpecificationExecutor<ProdBatchWeightEntity> {
+
+    @Query(nativeQuery = true,value = "SELECT * FROM prod_batch_weight WHERE batch_code=?1")
+    ProdBatchWeightEntity findByBatchCode(String batchCode);
+}

+ 14 - 0
huimv-farm-receiver/src/main/java/com/huimv/receiver/farm/dao/repo/ProdDayWeightRepo.java

@@ -0,0 +1,14 @@
+package com.huimv.receiver.farm.dao.repo;
+
+import com.huimv.receiver.farm.dao.entity.ProdDayWeightEntity;
+import org.springframework.data.jpa.repository.JpaRepository;
+import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
+import org.springframework.data.jpa.repository.Query;
+
+import java.util.Date;
+
+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")
+    ProdDayWeightEntity findByDateAndFarmId(Date date, Integer farmId);
+}

+ 9 - 0
huimv-farm-receiver/src/main/java/com/huimv/receiver/farm/service/IWeight.java

@@ -0,0 +1,9 @@
+package com.huimv.receiver.farm.service;
+
+public interface IWeight {
+    //
+    void saveDayWeight(String data);
+
+    //
+    void saveBatchWeight(String data);
+}

+ 99 - 0
huimv-farm-receiver/src/main/java/com/huimv/receiver/farm/service/impl/WeightImpl.java

@@ -0,0 +1,99 @@
+package com.huimv.receiver.farm.service.impl;
+
+import com.alibaba.fastjson.JSONObject;
+import com.huimv.receiver.farm.dao.entity.ProdBatchWeightEntity;
+import com.huimv.receiver.farm.dao.entity.ProdDayWeightEntity;
+import com.huimv.receiver.farm.dao.repo.ProdBatchWeightRepo;
+import com.huimv.receiver.farm.dao.repo.ProdDayWeightRepo;
+import com.huimv.receiver.farm.service.IWeight;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.sql.Timestamp;
+import java.util.Date;
+
+/**
+ * @Project : huimv.shiwan
+ * @Package : com.huimv.biosafety.uface.controller
+ * @Description : TODO
+ * @Version : 1.0
+ * @Author : ZhuoNing
+ * @Create : 2020-12-25
+ **/
+@Service
+public class WeightImpl implements IWeight {
+    @Autowired
+    private ProdDayWeightRepo dayWeightRepo;
+    @Autowired
+    private ProdBatchWeightRepo batchWeightRepo;
+
+    /**
+     * @Method      : saveDayWeight
+     * @Description : 保存日总重数据
+     * @Params      : [data]
+     * @Return      : void
+     * 
+     * @Author      : ZhuoNing
+     * @Date        : 2021/12/7       
+     * @Time        : 19:48
+     */
+    @Override
+    public void saveDayWeight(String data) {
+        JSONObject dayWeightJo = JSONObject.parseObject(data);
+        Long date = dayWeightJo.getLong("addTime");
+        Integer farmId = dayWeightJo.getInteger("farmId");
+        //
+        ProdDayWeightEntity existDayWeightEntity = dayWeightRepo.findByDateAndFarmId(new Date(date),farmId);
+        if(existDayWeightEntity != null){
+            existDayWeightEntity.setAddTime(new Timestamp(new Date().getTime()));
+            existDayWeightEntity.setGrossWeight(dayWeightJo.getFloat("grossWeight"));
+            existDayWeightEntity.setTareWeight(dayWeightJo.getFloat("tareWeight"));
+            existDayWeightEntity.setNetWeight(dayWeightJo.getFloat("netWeight"));
+            dayWeightRepo.saveAndFlush(existDayWeightEntity);
+        }else{
+            ProdDayWeightEntity newDayWeightEntity = new ProdDayWeightEntity();
+            newDayWeightEntity.setAddTime(new Timestamp(new Date().getTime()));
+            newDayWeightEntity.setFarmId(dayWeightJo.getInteger("farmId"));
+            newDayWeightEntity.setGrossWeight(dayWeightJo.getFloat("grossWeight"));
+            newDayWeightEntity.setTareWeight(dayWeightJo.getFloat("tareWeight"));
+            newDayWeightEntity.setNetWeight(dayWeightJo.getFloat("netWeight"));
+            dayWeightRepo.saveAndFlush(newDayWeightEntity);
+        }
+
+    }
+
+    /**
+     * @Method      : saveBatchWeight
+     * @Description : 保存批次重量数据
+     * @Params      : [data]
+     * @Return      : void
+     * 
+     * @Author      : ZhuoNing
+     * @Date        : 2021/12/7       
+     * @Time        : 19:49
+     */
+    @Override
+    public void saveBatchWeight(String data) {
+        JSONObject batchWeightJo = JSONObject.parseObject(data);
+        String batchCode = batchWeightJo.getString("batchCode");
+        System.out.println("batchCode<<"+batchCode);
+        //查找批次称重数据
+        ProdBatchWeightEntity existBatchWeightEntity = batchWeightRepo.findByBatchCode(batchCode);
+        if(existBatchWeightEntity == null){
+            ProdBatchWeightEntity newBatchWeightEntity = new ProdBatchWeightEntity();
+            newBatchWeightEntity.setBatchCode(batchWeightJo.getString("batchCode"));
+            newBatchWeightEntity.setBatchSort(batchWeightJo.getInteger("batchSort"));
+            newBatchWeightEntity.setFarmId(batchWeightJo.getInteger("farmId"));
+            newBatchWeightEntity.setGrossWeight(batchWeightJo.getFloat("grossWeight"));
+            newBatchWeightEntity.setTareWeight(batchWeightJo.getFloat("tareWeight"));
+            newBatchWeightEntity.setNetWeight(batchWeightJo.getFloat("netWeight"));
+            newBatchWeightEntity.setAddTime(new Timestamp(new Date().getTime()));
+            batchWeightRepo.saveAndFlush(newBatchWeightEntity);
+        }else{
+            existBatchWeightEntity.setGrossWeight(batchWeightJo.getFloat("grossWeight"));
+            existBatchWeightEntity.setTareWeight(batchWeightJo.getFloat("tareWeight"));
+            existBatchWeightEntity.setNetWeight(batchWeightJo.getFloat("netWeight"));
+            batchWeightRepo.saveAndFlush(existBatchWeightEntity);
+        }
+    }
+}

+ 191 - 0
huimv-farm-receiver/src/main/java/com/huimv/receiver/utils/DateUtil.java

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

+ 2 - 18
huimv-farm-receiver/src/main/resources/application-dev.yml

@@ -1,8 +1,8 @@
 server:
-  port: 8097
+  port: 8098
 spring:
   application:
-    name: pigfarm-local-device
+    name: huimv-farm-receiver
   #------DataSource-----
   datasource:
     url: jdbc:mysql://192.168.1.7:3306/huimv-farm-device?useUnicode=true&characterEncoding=UTF-8&useSSL=false&autoReconnect=true&serverTimezone=Asia/Shanghai
@@ -14,19 +14,3 @@ spring:
     hibernate:
       ddl-auto: update
     database-platform: org.hibernate.dialect.MySQL5InnoDBDialect
-
-# Socket配置
-socket:
-  # 监听端口 9001
-#  listen:
-#    #ip: 192.168.16.3
-#    ip: 192.168.1.49
-#    port: 10020
-  # 线程池 - 保持线程数 20
-  #pool-keep: 20
-  # 线程池 - 核心线程数 10
-  #pool-core: 10
-  # 线程池 - 最大线程数 20
-  #pool-max: 30
-  # 线程队列容量 10
-  #pool-queue-init: 10