ソースを参照

新建接收设备请求命令执行器功能

zhuoning 2 年 前
コミット
3b472f6fef

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

@@ -80,6 +80,10 @@
             <groupId>com.huimv</groupId>
             <artifactId>huimv-env-common</artifactId>
         </dependency>
+        <dependency>
+            <groupId>cn.hutool</groupId>
+            <artifactId>hutool-all</artifactId>
+        </dependency>
     </dependencies>
 
     <build>

+ 1 - 1
huimv-env-platform/huimv-env-input/src/main/java/com/huimv/env/input/server/EnvInputServer.java

@@ -23,7 +23,7 @@ public class EnvInputServer {
     @Autowired
     private EnvInputServerHandler serverHandler;
     //监听端口
-    private int port = 8012;
+    private int port = 3721;
     //创建构造方法
     public EnvInputServer(){
     }

+ 180 - 125
huimv-env-platform/huimv-env-input/src/main/java/com/huimv/env/input/server/EnvInputServerHandler.java

@@ -2,6 +2,9 @@ package com.huimv.env.input.server;
 
 import com.alibaba.fastjson.JSONArray;
 import com.huimv.env.common.utils.RegexUtil;
+import com.huimv.env.input.service.ICommandProcessorService;
+import com.huimv.env.input.utils.DateUtil2;
+import freemarker.template.utility.DateUtil;
 import io.netty.buffer.ByteBuf;
 import io.netty.buffer.Unpooled;
 import io.netty.channel.ChannelHandler;
@@ -37,12 +40,15 @@ import java.util.regex.Pattern;
 public class EnvInputServerHandler extends ChannelInboundHandlerAdapter {
     @Autowired
     private RegexUtil regexUtil;
+    @Autowired
+    private ICommandProcessorService cmdProService;
+    @Autowired
+    private DateUtil2 dateUtil;
     private StringBuilder askTextSb = null;
-    private int num = 0;
 
     //
-    public void appendClientAsk(String text){
-        if(this.askTextSb == null){
+    public void appendClientAsk(String text) {
+        if (this.askTextSb == null) {
             askTextSb = new StringBuilder();
         }
         askTextSb.append(text);
@@ -52,7 +58,6 @@ public class EnvInputServerHandler extends ChannelInboundHandlerAdapter {
     public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
         ByteBuf data = (ByteBuf) msg;
         String clientAskText = data.toString(CharsetUtil.UTF_8);
-//        System.out.println((++num)+"次, 客户端消息clientAskText>>"+clientAskText);
         //保存实例内的客户端请求
         appendClientAsk(clientAskText);
         //临时写入耳标数据到文件
@@ -61,67 +66,52 @@ public class EnvInputServerHandler extends ChannelInboundHandlerAdapter {
 
     @Override
     public void channelReadComplete(ChannelHandlerContext ctx) throws Exception {
-//        ctx.writeAndFlush("111");
-//        System.out.println("EchoServerHandle channelReadComplete");
-        if(askTextSb.toString().indexOf("end") != -1){
-//            System.out.println("askTextSb.内容()>>"+askTextSb.toString());
-//            System.out.println("askTextSb.内容长度>>"+askTextSb.length());
-//            System.out.println("输入完成.");
-            // 处理客户端消息
-            handleClientEartagMessage(askTextSb.toString(),ctx);
+        if (askTextSb.toString().indexOf("end") != -1) {
+            // {处理客户端消息}
+            handleClientAskCmd(askTextSb.toString(), ctx);
             //清空重置;
-            askTextSb.delete(0,askTextSb.length());
-            num = 0;
-//            System.out.println("清空sb实例. 长度>>"+askTextSb.length());
+            askTextSb.delete(0, askTextSb.length());
         }
     }
 
     @Override
     public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
-//        System.out.println("cause.getMessage()>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"+cause.getMessage());
-        if(cause.getMessage().indexOf("Connection reset") != -1){
-            log.info("相关采集器设备正在重启:"+cause.toString());
+        if (cause.getMessage().indexOf("Connection reset") != -1) {
+            log.info("相关采集器设备正在重启:" + cause.toString());
         }
 //        cause.printStackTrace();
         ctx.close();
     }
 
     /**
-     * @Method      : handleClientMessage
+     * @Method : handleClientAskCmd
      * @Description : 处理请求小心
-     * @Params      : [clientAskText, ctx]
-     * @Return      : void
-     * 
-     * @Author      : ZhuoNing
-     * @Date        : 2022/3/28       
-     * @Time        : 17:36
+     * @Params : [clientAskText, ctx]
+     * @Return : void
+     * @Author : ZhuoNing
+     * @Date : 2022/3/28
+     * @Time : 17:36
      */
-    private void handleClientEartagMessage(String clientAskText,ChannelHandlerContext ctx) throws ParseException, IOException {
-        clientAskText = clientAskText.replaceAll("\r","").replaceAll("\n","");
-
-        //{}
-        int countPlus = regexUtil.countPlus(clientAskText);
-        if (countPlus < 4) {
-            System.out.println("当前数据为不完整数据,故丢弃.>>" + clientAskText);
-        } else {
-            //--处理客户端请求数据
-            //{拆分粘包数据}
-            JSONArray askJa = getPerData(clientAskText);
-            for (int a = 0; a < askJa.size(); a++) {
-                String askText = askJa.getString(a);
-//                if (dataInputFlow == 1) {
-//                    //{处理请求内容}
-//                    handleAskText(askText, ctx);
-//                } else {
-                    //{处理请求内容2}
-                    handleAskText2(askText, ctx);
-//                }
-            }
+    private void handleClientAskCmd(String clientAskText, ChannelHandlerContext ctx) throws ParseException, IOException {
+        clientAskText = clientAskText.replaceAll("\r", "").replaceAll("\n", "");
+        //{处理非正常命令}
+//        int countPlus = regexUtil.countPlus(clientAskText);
+//        if (countPlus < 4) {
+//            System.out.println("当前数据为不完整数据,故丢弃.>>" + clientAskText);
+//        } else {
+        //--处理客户端请求数据
+        //{拆分粘包数据}
+        JSONArray askJa = parseAskCmdPackage(clientAskText);
+        for (int a = 0; a < askJa.size(); a++) {
+            String askText = askJa.getString(a);
+            //{处理请求命令}
+            askCmdActuator(askText, ctx);
         }
+//        }
     }
 
     /**
-     * @Method : handleAskText2
+     * @Method : askCmdActuator
      * @Description :
      * @Params : [askText, ctx]
      * @Return : void
@@ -129,102 +119,167 @@ public class EnvInputServerHandler extends ChannelInboundHandlerAdapter {
      * @Date : 2022/3/23
      * @Time : 18:08
      */
-    private void handleAskText2(String askText, ChannelHandlerContext ctx) throws ParseException, IOException {
+    private void askCmdActuator(String askText, ChannelHandlerContext ctx) throws ParseException, IOException {
+        System.out.println("======>接收设备请求:" + askText);
         String[] dataArray = askText.split("\\+");
         String cmdHeader = dataArray[0];
+        if (!cmdHeader.trim().equalsIgnoreCase("hm")) {
+            log.info("当前命令是非hm命令[" + askText + "]");
+            return;
+        }
         //芯片id/设备编码
         String idCode = dataArray[1];
         String cmd = dataArray[2];
         Map map = new HashMap();
         map.put("askText", askText);
         if (cmdHeader.trim().equalsIgnoreCase("hm")) {
-            //采集器应答数据
-            if (cmd.trim().equalsIgnoreCase("0")) {
-                //不需要处理
-                System.out.println("==>命令0");
-            } else if (cmd.trim().equalsIgnoreCase("1")) {
-//                System.out.println("==>命令1请求 askText>>" + askText.trim());
-//                //处理获取设备编码命令
+            if (cmd.trim().equalsIgnoreCase("1")) {
+                System.out.println("==>获取远程设备编码请求:" + askText.trim());
 //                //{读取设备编码}
-//                String deviceCode = dataService.getDeviceCodeByChipId(idCode);
-//                log.info("获取设备编码结果,芯片id>>" + idCode + " ,deviceCode>>" + deviceCode);
-//                if (deviceCode != null) {
-//                    String answer = "hm+1+0+" + deviceCode + "+123+8+end";
-//                    log.info(">>命令1设备编码-应答数据>>" + answer);
-//                    ctx.writeAndFlush(Unpooled.copiedBuffer(answer.getBytes()));
-//                } else {
-//                    log.error("检测到未注册的采集器设备,已舍弃请求.");
-//                }
+                String deviceCode = cmdProService.getDeviceCodeByChipId(idCode);
+                log.info("获取远程设备编码请求,芯片id>>" + idCode + " ,deviceCode>>" + deviceCode);
+                if (deviceCode != null) {
+                    String answerText = "hm+1+0+" + deviceCode + "+123+8+end";
+                    log.info("<<获取远程设备编码请求-应答数据:" + answerText);
+                    //{应答指令}
+                    answerCmd(answerText, ctx);
+                } else {
+                    log.error("该设备未注册,已舍弃请求.");
+                }
             } else if (cmd.trim().equalsIgnoreCase("2")) {
-//                System.out.println("==>命令2获取服务器时间请求 askText>>" + askText);
-//                if (dataService.isEffectiveDevice(idCode)) {
-//                    //处理服务器时间命令
-//                    String answer = "hm+2+" + dateUtil.getNowText() + "+4+end";
-//                    log.info(">>命令2服务器时间-应答数据>>" + answer);
-//                    ctx.writeAndFlush(Unpooled.copiedBuffer(answer.getBytes()));
-//                }else {
-//                    System.out.println("##获取服务器时间-无效设备编码 idCode=" + idCode);
-//                }
+                System.out.println("==>时间同步请求:" + askText);
+                if (cmdProService.isEffectiveDevice(idCode)) {
+                    //时间同步请求
+                    String answerText = "hm+2+" + dateUtil.getNowText() + "+4+end";
+                    log.info(">>时间同步请求-应答数据>>" + answerText);
+                    answerCmd(answerText, ctx);
+                } else {
+                    System.out.println("##时间同步请求-未注册设备 idCode=" + idCode);
+                }
             } else if (cmd.trim().equalsIgnoreCase("3")) {
-//                System.out.println("==>命令3心跳包请求 askText>>" + askText);
-//                //处理心跳包命令
-//                //{设备心跳应答}
-//                if (dataService.isEffectiveDevice(idCode)) {
-//                    String answer = "hm+3+6+end";
-//                    log.info(">>命令3心跳包-应答数据>>" + answer);
-//                    ctx.writeAndFlush(Unpooled.copiedBuffer(answer.getBytes()));
-//
-//                    //{发送到设备处理消息队列}
-//                    dataService.sendDeviceMQ(map);
-//                    log.info(">>发送设备心跳数据消息到MQ."+map);
-//                } else {
-//                    System.out.println("##心跳包-无效设备编码(" + idCode+"),请求拒绝。");
-//                }
+                System.out.println("==>温度度上传请求 askText>>" + askText);
+                if (cmdProService.isEffectiveDevice(idCode)) {
+                    //温度度上传请求
+                    String answerText = "hm+3+0+7+end";
+                    log.info(">>温度度上传请求-应答数据>>" + answerText);
+                    answerCmd(answerText, ctx);
+                } else {
+                    System.out.println("##温度度上传请求-未注册设备 idCode=" + idCode);
+                }
             } else if (cmd.trim().equalsIgnoreCase("4")) {
-                System.out.println("==>命令4环境温度请求 askText>>" + askText);
-                //处理设备环境温度命令
-                //{设备环境温度应答}
-//                if (dataService.isEffectiveDevice(idCode)) {
-//                    String answer = "hm+4+7+end";
-//                    log.info(">>命令4环境温度-应答数据>>" + answer);
-//                    ctx.writeAndFlush(Unpooled.copiedBuffer(answer.getBytes()));
-//
-//                    //{发送到设备处理消息队列}
-//                    dataService.sendDeviceMQ(map);
-//                    log.info(">>发送设备环境温度数据消息到MQ."+map);
-//                } else {
-//                    System.out.println("##环境温度-无效设备编码(" + idCode+"),请求拒绝。");
-//                }
+                System.out.println("==>湿度度上传请求 askText>>" + askText);
+                if (cmdProService.isEffectiveDevice(idCode)) {
+                    //湿度度上传请求
+                    String answerText = "hm+4+0+8+end";
+                    log.info(">>湿度度上传请求-应答数据>>" + answerText);
+                    answerCmd(answerText, ctx);
+                } else {
+                    System.out.println("##湿度度上传请求-未注册设备 idCode=" + idCode);
+                }
+            } else if (cmd.trim().equalsIgnoreCase("5")) {
+                System.out.println("==>氨气度上传请求 askText>>" + askText);
+                if (cmdProService.isEffectiveDevice(idCode)) {
+                    //氨气度上传请求
+                    String answerText = "hm+5+0+8+end";
+                    log.info(">>氨气度上传请求-应答数据>>" + answerText);
+                    answerCmd(answerText, ctx);
+                } else {
+                    System.out.println("##氨气度上传请求-未注册设备 idCode=" + idCode);
+                }
+            } else if (cmd.trim().equalsIgnoreCase("6")) {
+                System.out.println("==>获取喷雾除臭配置请求 askText>>" + askText);
+                if (cmdProService.isEffectiveDevice(idCode)) {
+                    //获取喷雾除臭配置请求
+                    String answerText = "hm+158+6+1+1+(201708080101,60,10,10)(201708080202,60,10,10)(201708080303,60,10,10)(201708080404,60,10,10)...+60+201702081523+6+end";
+                    log.info(">>获取喷雾除臭配置请求-应答数据>>" + answerText);
+                    answerCmd(answerText, ctx);
+                } else {
+                    System.out.println("##获取喷雾除臭配置请求-未注册设备 idCode=" + idCode);
+                }
+            } else if (cmd.trim().equalsIgnoreCase("7")) {
+                System.out.println("==>上报喷雾除臭状态请求 askText>>" + askText);
+                //上报喷雾除臭状态请求
+                if (cmdProService.isEffectiveDevice(idCode)) {
+                    String answerText = "hm+158+7+6+end";
+                    log.info(">>上报喷雾除臭状态请求-应答数据>>" + answerText);
+                    answerCmd(answerText, ctx);
+                } else {
+                    System.out.println("##上报喷雾除臭状态请求-未注册设备 idCode=" + idCode);
+                }
+            } else if (cmd.trim().equalsIgnoreCase("14")) {
+                //获取报警使能请求
+                System.out.println("==>获取报警使能请求 askText>>" + askText);
+                if (cmdProService.isEffectiveDevice(idCode)) {
+                    String answerText = "hm+158+14+1(122)1(122)1(122)1(122)1(122)1(122)1(122)1(122)1(122)1(122)1(122)1(122)1(122)1(122)+0+4+end";
+                    log.info(">>获取报警使能请求-应答数据>>" + answerText);
+                    answerCmd(answerText, ctx);
+                } else {
+                    System.out.println("##获取报警使能请求-未注册设备 idCode=" + idCode);
+                }
+            } else if (cmd.trim().equalsIgnoreCase("15")) {
+                //短信发送请求
+                System.out.println("==>短信发送请求 askText>>" + askText);
+                if (cmdProService.isEffectiveDevice(idCode)) {
+                    String answerText = "hm+15+0+2+end";
+                    log.info(">>>短信发送请求-应答数据>>" + answerText);
+                    answerCmd(answerText, ctx);
+                } else {
+                    System.out.println("##>短信发送请求-未注册设备 idCode=" + idCode);
+                }
+            } else if (cmd.trim().equalsIgnoreCase("16")) {
+                System.out.println("==>声光报警短信发送请求 askText>>" + askText);
+                if (cmdProService.isEffectiveDevice(idCode)) {
+                    //声光报警短信发送请求
+                    String answerText = "hm+16+0+2+end";
+                    log.info(">>声光报警短信发送请求-应答数据>>" + answerText);
+                    answerCmd(answerText, ctx);
+                } else {
+                    System.out.println("##声光报警短信发送请求-未注册设备 idCode=" + idCode);
+                }
+            } else if (cmd.trim().equalsIgnoreCase("17")) {
+                System.out.println("==>报警器打电话请求 askText>>" + askText);
+                if (cmdProService.isEffectiveDevice(idCode)) {
+                    //报警器打电话请求
+                    String answerText = "hm+17+0+2+end";
+                    log.info(">>报警器打电话请求-应答数据>>" + answerText);
+                    answerCmd(answerText, ctx);
+                } else {
+                    System.out.println("##报警器打电话请求-未注册设备 idCode=" + idCode);
+                }
+            } else if (cmd.trim().equalsIgnoreCase("18")) {
+                System.out.println("==>高温,低温报警参数请求 askText>>" + askText);
+                if (cmdProService.isEffectiveDevice(idCode)) {
+                    //高温,低温报警参数请求
+                    String answerText = "hm+158+18+265+12+6+end";
+                    log.info(">>高温,低温报警参数请求-应答数据>>" + answerText);
+                    answerCmd(answerText, ctx);
+                } else {
+                    System.out.println("##高温,低温报警参数请求-未注册设备 idCode=" + idCode);
+                }
+            } else if (cmd.trim().equalsIgnoreCase("19")) {
+                System.out.println("==>平台消息推送请求 askText>>" + askText);
+                if (cmdProService.isEffectiveDevice(idCode)) {
+                    //平台消息推送请求
+                    String answerText = "hm+19+0+2+end";
+                    log.info(">>平台消息推送请求-应答数据>>" + answerText);
+                    answerCmd(answerText, ctx);
+                } else {
+                    System.out.println("##平台消息推送请求-未注册设备 idCode=" + idCode);
+                }
             } else {
                 System.out.println("==>未知命令");
-                log.error(">>当前数据为非法数据>>" + askText);
-            }
-        } else if (cmdHeader.trim().equalsIgnoreCase("zj")) {
-            System.out.println("==>耳标命令请求 askText>>"+askText);
-            //测试-临时写入耳标数据到文件
-            if(askText.trim().indexOf("330110002000002") != -1){
-//                writeTxt(askText,"input");
+                log.error(">>当前数据为非法数据-未知命令>>" + askText);
             }
-            //耳标应答数据(不需要应答)
-//            if (checkValidEarmark(cmd)) {
-//                log.error(">>舍弃掉未配置耳标号的耳标," + askText + "");
-//            } else {
-                //{检查设备是否在处于工作状态或待机状态}
-//                if (dataService.isWorkStatusDevice(idCode)) {
-//                if (dataService.isEffectiveDevice(idCode)) {
-//                    //{发送到耳标处理消息队列}
-//                    dataService.sendEartagMQ(map);
-//                    log.info(">>发送耳标数据消息到MQ."+map);
-//                }else{
-//                    System.out.println("无效设备编码 idCode="+idCode);
-//                }
-//            }
         } else {
-            System.out.println("==>未知命令");
-            log.error("##当前请求数据为非法数据>>" + askText);
+            System.out.println("==>未知命令头");
+            log.error("##当前请求数据为非法数据-未知命令头>>" + askText);
         }
     }
 
+    public void answerCmd(String answerText, ChannelHandlerContext ctx) {
+        ctx.writeAndFlush(Unpooled.copiedBuffer(answerText.getBytes()));
+    }
+
     //检查无效耳标
     public boolean checkValidEarmark(String earmark) {
         if (earmark.trim().equalsIgnoreCase("ffffffffffffffff") || earmark.trim().equalsIgnoreCase("0000000000000000")) {
@@ -235,7 +290,7 @@ public class EnvInputServerHandler extends ChannelInboundHandlerAdapter {
     }
 
     //拆分粘包数据
-    public JSONArray getPerData(String text) {
+    public JSONArray parseAskCmdPackage(String text) {
         String key = "end";
         Pattern pattern = Pattern.compile(key);
         Matcher matcher = pattern.matcher(text);

+ 25 - 0
huimv-env-platform/huimv-env-input/src/main/java/com/huimv/env/input/service/CommandProcessorServiceImpl.java

@@ -0,0 +1,25 @@
+package com.huimv.env.input.service;
+
+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 CommandProcessorServiceImpl implements  ICommandProcessorService {
+
+    @Override
+    public String getDeviceCodeByChipId(String idCode) {
+        return "115";
+    }
+
+    @Override
+    public boolean isEffectiveDevice(String idCode) {
+        return true;
+    }
+}

+ 8 - 0
huimv-env-platform/huimv-env-input/src/main/java/com/huimv/env/input/service/ICommandProcessorService.java

@@ -0,0 +1,8 @@
+package com.huimv.env.input.service;
+
+public interface ICommandProcessorService {
+
+    String getDeviceCodeByChipId(String idCode);
+
+    boolean isEffectiveDevice(String idCode);
+}

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

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