Forráskód Böngészése

新建添加温度数据功能。

zhuoning 2 éve
szülő
commit
105914c675

+ 4 - 0
huimv-env-platform/huimv-env-common/pom.xml

@@ -83,6 +83,10 @@
             <artifactId>lombok</artifactId>
             <scope>compile</scope>
         </dependency>
+        <dependency>
+            <groupId>cn.hutool</groupId>
+            <artifactId>hutool-all</artifactId>
+        </dependency>
     </dependencies>
 
 </project>

+ 2 - 0
huimv-env-platform/huimv-env-common/src/main/java/com/huimv/env/common/service/IDeviceRegisterService.java

@@ -5,4 +5,6 @@ public interface IDeviceRegisterService {
     String getDeviceCodeByChipId(String chipId);
     //
     boolean isExistByDeviceCode(String idCode);
+
+    String getFarmCodeByDeviceCode(String deviceCode);
 }

+ 12 - 0
huimv-env-platform/huimv-env-common/src/main/java/com/huimv/env/common/service/impl/DeviceRegisterServiceImpl.java

@@ -46,4 +46,16 @@ public class DeviceRegisterServiceImpl implements IDeviceRegisterService {
             return true;
         }
     }
+
+    @Override
+    public String getFarmCodeByDeviceCode(String deviceCode){
+        //
+        Optional<EnvDeviceRegisterEntity> optional =  envDeviceRegisterEntityRepo.getDeviceRegisterByDeviceCode(deviceCode);
+        if(!optional.isPresent()){
+            log.error("该设备[设备编码:"+deviceCode+"]未注册.");
+            return optional.get().getFarmCode();
+        }else{
+            return null;
+        }
+    }
 }

+ 315 - 0
huimv-env-platform/huimv-env-common/src/main/java/com/huimv/env/common/utils/DateUtil.java

@@ -0,0 +1,315 @@
+package com.huimv.env.common.utils;
+
+import cn.hutool.core.date.DateTime;
+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;
+import java.util.List;
+
+/**
+ * @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 {
+
+    public int getNowHour(){
+        Calendar cal = Calendar.getInstance();
+        return cal.get(Calendar.HOUR_OF_DAY);
+    }
+
+    //格式化日期(Long --> Date)
+    public String formatLongToDate(Long longDate){
+        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+        Date date= new Date(longDate);
+        return df.format(date);
+    }
+
+    //格式化本年
+    public String getThisYear(){
+        Calendar cal = Calendar.getInstance();
+        int year = cal.get(Calendar.YEAR);
+        return String.valueOf(year);
+    }
+
+    //格式化本月
+    public String getThisMonth(){
+        Calendar cal = Calendar.getInstance();
+        int month = cal.get(Calendar.MONTH) + 1;
+        if(String.valueOf(month).length()==1)
+        {
+            return "0"+String.valueOf(month);
+        }else{
+            return String.valueOf(month);
+        }
+    }
+
+    //格式化日期时间
+    public String formatDateTime(String dateText) throws ParseException {
+        if(dateText.indexOf("T") != -1){
+            dateText = dateText.replace("T"," ");
+        }
+        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+        Date date = sdf.parse(dateText);
+        return sdf.format(date);
+    }
+
+    //格式化日期时间
+    public String formatDateText(String dateText) throws ParseException {
+        if(dateText.indexOf("T") != -1){
+            dateText = dateText.replace("T"," ");
+        }
+        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
+        Date date = sdf.parse(dateText);
+        return sdf.format(date);
+    }
+//    public String formatDateText(Date date) throws ParseException {
+//        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
+//        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 parseDateTimeTextToLong(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 Long parseDateTextToLong(String dateText) throws ParseException {
+        if(dateText.indexOf("T") != -1){
+            dateText = dateText.replace("T"," ");
+        }
+        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
+        Date date = sdf.parse(dateText);
+        return date.getTime();
+    }
+
+    //
+    public Date getTodayDate() throws ParseException {
+        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
+        return sdf.parse(sdf.format(new Date()));
+    }
+
+    public Date getTodayDatetime() throws ParseException {
+        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+        return sdf.parse(sdf.format(new Date()));
+    }
+
+    public String getTodayDateText() throws ParseException {
+        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
+        return sdf.format(new Date());
+    }
+
+    public java.sql.Date getTodayMySQLDate(){
+        java.sql.Date todayDate = new java.sql.Date(new Date().getTime());
+        return todayDate;
+    }
+
+    public Timestamp getTimestamp(){
+        Timestamp nowTimestamp = new Timestamp(new Date().getTime());
+        return nowTimestamp;
+    }
+
+    public String getTodayText() throws ParseException {
+        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+        return sdf.format(new Date());
+    }
+
+    public String formatDateText(Date date) throws ParseException {
+        if(date == null){
+            return "";
+        }
+        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
+        return sdf.format(date);
+    }
+
+    public String formatDatetimeText(Date date) throws ParseException {
+        if(date == null || date.toString().length()==0){
+            return "";
+        }
+        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+        return sdf.format(date);
+    }
+
+    public String getNowText() throws ParseException {
+        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
+        return sdf.format(new Date());
+    }
+
+    public String getTodayMissionText() throws ParseException {
+        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
+        return sdf.format(new Date());
+    }
+
+    public String getStartDateInThisMonth(){
+        DateTime date = cn.hutool.core.date.DateUtil.date();
+        return (cn.hutool.core.date.DateUtil.beginOfMonth(date) + "").substring(0, 10);
+    }
+
+    public String getEndDateInThisMonth(){
+        DateTime date = cn.hutool.core.date.DateUtil.date();
+        return (date + "").substring(0, 10);
+    }
+
+    /**
+     * 获取过去或者未来 任意天内的日期数组
+     * @param intervals      intervals天内
+     * @return              日期数组
+     */
+    public ArrayList<String> test(int intervals ) {
+        ArrayList<String> pastDaysList = new ArrayList<>();
+        ArrayList<String> fetureDaysList = new ArrayList<>();
+        for (int i = 0; i <intervals; i++) {
+            pastDaysList.add(getPastDate(i));
+            fetureDaysList.add(getFetureDate(i));
+        }
+        return pastDaysList;
+    }
+
+    /**
+     * @Method      : getPastIntervals
+     * @Description : 返回过去N天日期(倒排序)
+     * @Params      : [intervals]
+     * @Return      : java.util.ArrayList<java.lang.String>
+     * 
+     * @Author      : ZhuoNing
+     * @Date        : 2022/3/7       
+     * @Time        : 15:27
+     */
+    public ArrayList<String> getPastIntervals(int intervals ) {
+        ArrayList<String> pastDaysList = new ArrayList<>();
+        for (int i = 0; i <intervals; i++) {
+            pastDaysList.add(getPastDate(i));
+        }
+        return pastDaysList;
+    }
+
+    /**
+     * @Method      : getPastIntervalsASC
+     * @Description : 正排序
+     * @Params      : [intervals]
+     * @Return      : java.util.ArrayList<java.lang.String>
+     * 
+     * @Author      : ZhuoNing
+     * @Date        : 2022/3/7       
+     * @Time        : 16:33
+     */
+    public ArrayList<String> getPastIntervalsASC(int intervals ) {
+        ArrayList<String> pastDaysList = new ArrayList<>();
+        for (int i = intervals-1; i >=0; i--) {
+            pastDaysList.add(getPastDate(i));
+        }
+        return pastDaysList;
+    }
+
+    /**
+     * @Method      : getFetureIntervals
+     * @Description : 获取未来N天日期
+     * @Params      : [intervals]
+     * @Return      : java.util.ArrayList<java.lang.String>
+     * 
+     * @Author      : ZhuoNing
+     * @Date        : 2022/3/7       
+     * @Time        : 15:28
+     */
+    public ArrayList<String> getFetureIntervals(int intervals ) {
+        ArrayList<String> fetureDaysList = new ArrayList<>();
+        for (int i = 0; i <intervals; i++) {
+            fetureDaysList.add(getFetureDate(i));
+        }
+        return fetureDaysList;
+    }
+
+
+    /**
+     * 获取过去第几天的日期
+     *
+     * @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();
+        List<String> pastList = du.getPastIntervalsASC(5);
+        for(String pastDate:pastList){
+            System.out.println("pastDate>>"+pastDate);
+        }
+
+        List<String> fetureList = du.getFetureIntervals(5);
+        for(String fetureDate:fetureList){
+            System.out.println("fetureDate>>"+fetureDate);
+        }
+
+    }
+
+    private void test1() {
+        String text = "20211201104300";
+//        String text = "1234567890abcd";
+        String date = text.substring(0,4)+"-"+text.substring(4,6)+"-"+text.substring(6,8)+" "+text.substring(8,10)+":"+text.substring(10,12)+":"+text.substring(12,14);
+        System.out.println("date="+date);
+    }
+
+    //获取long时间
+    public Long getNowLong(){
+        Calendar calendar = Calendar.getInstance();
+        calendar.set(calendar.get(Calendar.YEAR),calendar.get(Calendar.MONTH),calendar.get(Calendar.DAY_OF_MONTH)-1,0,0,0);
+        return calendar.getTime().getTime();
+    }
+}

+ 110 - 0
huimv-env-platform/huimv-env-device/pom.xml

@@ -0,0 +1,110 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+    <parent>
+        <artifactId>huimv-env-platform</artifactId>
+        <groupId>com.huimv</groupId>
+        <version>1.0-SNAPSHOT</version>
+    </parent>
+    <modelVersion>4.0.0</modelVersion>
+
+    <groupId>com.huimv</groupId>
+    <artifactId>huimv-env-device</artifactId>
+    <version>0.0.1-SNAPSHOT</version>
+
+    <dependencies>
+        <!-- 排除Tomcat容器 -->
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-starter-web</artifactId>
+            <!-- 移除掉默认支持的 Tomcat -->
+            <exclusions>
+                <exclusion>
+                    <groupId>org.springframework.boot</groupId>
+                    <artifactId>spring-boot-starter-tomcat</artifactId>
+                </exclusion>
+            </exclusions>
+        </dependency>
+        <!-- 添加 Undertow 容器 -->
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-starter-undertow</artifactId>
+        </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>
+        <!--rabbitmq-->
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-starter-amqp</artifactId>
+        </dependency>
+        <!-- redis -->
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-starter-data-redis</artifactId>
+        </dependency>
+        <!-- actuator -->
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-starter-actuator</artifactId>
+        </dependency>
+        <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>
+        <dependency>
+            <groupId>org.projectlombok</groupId>
+            <artifactId>lombok</artifactId>
+            <scope>compile</scope>
+        </dependency>
+        <!-- fastjson -->
+        <dependency>
+            <groupId>com.alibaba</groupId>
+            <artifactId>fastjson</artifactId>
+        </dependency>
+
+        <!--hutool-->
+        <dependency>
+            <groupId>cn.hutool</groupId>
+            <artifactId>hutool-all</artifactId>
+        </dependency>
+        <!-- 一方包统一版本管理 -->
+        <dependency>
+            <groupId>com.huimv</groupId>
+            <artifactId>huimv-env-common</artifactId>
+        </dependency>
+        <!-- 二方包统一版本管理 -->
+        <dependency>
+            <groupId>com.huimv</groupId>
+            <artifactId>huimv-common</artifactId>
+        </dependency>
+    </dependencies>
+
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>org.springframework.boot</groupId>
+                <artifactId>spring-boot-maven-plugin</artifactId>
+            </plugin>
+
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-resources-plugin</artifactId>
+                <version>2.6</version>
+            </plugin>
+        </plugins>
+    </build>
+</project>

+ 2 - 1
huimv-env-platform/huimv-env-input/src/main/java/com/huimv/env/input/HuimvEnvInputApplication.java

@@ -17,7 +17,8 @@ import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
  * @Author : ZhuoNing
  * @Create : 2020-12-25
  **/
-@ComponentScans({@ComponentScan("com.huimv.env.common.utils"),@ComponentScan("com.huimv.env.common.service")})
+@ComponentScans({@ComponentScan("com.huimv.env.common.utils"),
+        @ComponentScan("com.huimv.env.common.service")})
 @EntityScan(value = "com.huimv.env.common.dao.entity")
 @EnableJpaRepositories(basePackages = "com.huimv.env.common.dao.repo")
 @SpringBootApplication

+ 2 - 0
huimv-env-platform/huimv-env-input/src/main/java/com/huimv/env/input/server/EnvInputServerHandler.java

@@ -339,6 +339,7 @@ public class EnvInputServerHandler extends ChannelInboundHandlerAdapter {
             System.out.println("##时间同步请求-未注册设备 idCode=" + deviceCode);
             return;
         }
+        System.out.println(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"+dateUtil.getNowText() );
         String answerText = "hm+2+" + dateUtil.getNowText() + "+0+4+end";
         log.info(">>时间同步请求-应答数据>>" + answerText);
         answerCmd(answerText, ctx);
@@ -360,6 +361,7 @@ public class EnvInputServerHandler extends ChannelInboundHandlerAdapter {
         answerCmd(answerText, ctx);
     }
 
+    //应答
     public void answerCmd(String answerText, ChannelHandlerContext ctx) {
         ctx.writeAndFlush(Unpooled.copiedBuffer(answerText.getBytes()));
     }

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

@@ -3,7 +3,7 @@ server:
 
 spring:
   application:
-    name: huimv-eartag2-input
+    name: huimv-env-input
 
   datasource:
     url: jdbc:mysql://192.168.1.7:3306/huimv-env-platform?useUnicode=true&characterEncoding=UTF-8&useSSL=false&autoReconnect=true&serverTimezone=Asia/Shanghai

+ 1 - 0
huimv-env-platform/pom.xml

@@ -18,6 +18,7 @@
         <module>huimv-env-common</module>
         <module>huimv-env-input</module>
         <module>huimv-env-manage</module>
+        <module>huimv-env-device</module>
     </modules>
 
     <properties>