Просмотр исходного кода

同步更新牧场端数据功能:对部分代码进行了修复。

zhuoning 3 лет назад
Родитель
Сommit
0573d8f057

+ 12 - 0
huimv-farm-device/huimv-farm-business/pom.xml

@@ -44,5 +44,17 @@
             <artifactId>huimv-common</artifactId>
             <version>0.0.1</version>
         </dependency>
+        <dependency>
+            <groupId>cn.hutool</groupId>
+            <artifactId>hutool-all</artifactId>
+            <version>5.7.17</version>
+            <scope>compile</scope>
+        </dependency>
+        <dependency>
+            <groupId>cn.hutool</groupId>
+            <artifactId>hutool-all</artifactId>
+            <version>5.7.17</version>
+            <scope>compile</scope>
+        </dependency>
     </dependencies>
 </project>

+ 102 - 1
huimv-farm-device/huimv-farm-business/src/main/java/com/huimv/business/farm/service/impl/FarmDeviceImpl.java

@@ -5,6 +5,7 @@ import com.alibaba.fastjson.JSONObject;
 import com.huimv.business.farm.service.IFarmDevice;
 import com.huimv.business.server.dao.entity.FarmDeviceEntity;
 import com.huimv.business.server.dao.repo.FarmDeviceRepo;
+import com.huimv.business.utils.DateUtil;
 import com.huimv.business.utils.HttpTemplete;
 import com.huimv.business.utils.SnowflakeIdWorker;
 import com.huimv.business.utils.TextUtil;
@@ -13,11 +14,18 @@ import com.huimv.common.utils.ResultCode;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
+import org.springframework.data.domain.PageRequest;
+import org.springframework.data.domain.Pageable;
+import org.springframework.data.jpa.domain.Specification;
 import org.springframework.stereotype.Service;
 
+import javax.persistence.criteria.Order;
+import javax.persistence.criteria.Predicate;
 import java.io.UnsupportedEncodingException;
 import java.sql.Timestamp;
+import java.util.ArrayList;
 import java.util.Date;
+import java.util.List;
 import java.util.Optional;
 
 /**
@@ -37,6 +45,8 @@ public class FarmDeviceImpl implements IFarmDevice {
     private TextUtil textUtil;
     @Autowired
     private HttpTemplete httpTemplete;
+    @Autowired
+    private DateUtil dateUtil;
     @Value("${dataCenter.ipAddr}")
     private String DATA_CENTER_IP_ADDR;
     @Value("${dataCenter.device.port}")
@@ -52,6 +62,16 @@ public class FarmDeviceImpl implements IFarmDevice {
     @Value("${local.farmID}")
     private Integer FARM_ID;
 
+    /**
+     * @Method      : newDevice
+     * @Description : 新建设备信息
+     * @Params      : [deviceData]
+     * @Return      : com.huimv.common.utils.Result
+     * 
+     * @Author      : ZhuoNing
+     * @Date        : 2021/12/17       
+     * @Time        : 11:00
+     */
     @Override
     public Result newDevice(String deviceData) throws UnsupportedEncodingException {
         //
@@ -86,6 +106,16 @@ public class FarmDeviceImpl implements IFarmDevice {
         return new Result(ResultCode.SUCCESS, addDeviceEntity);
     }
 
+    /**
+     * @Method      : editDevice
+     * @Description : 编辑设备信息
+     * @Params      : [deviceData]
+     * @Return      : com.huimv.common.utils.Result
+     * 
+     * @Author      : ZhuoNing
+     * @Date        : 2021/12/17       
+     * @Time        : 11:00
+     */
     @Override
     public Result editDevice(String deviceData) throws UnsupportedEncodingException {
         //
@@ -126,6 +156,16 @@ public class FarmDeviceImpl implements IFarmDevice {
         return new Result(ResultCode.SUCCESS, addDeviceEntity);
     }
 
+    /**
+     * @Method      : removeDevice
+     * @Description : 删除设备信息
+     * @Params      : [deviceData]
+     * @Return      : com.huimv.common.utils.Result
+     * 
+     * @Author      : ZhuoNing
+     * @Date        : 2021/12/17       
+     * @Time        : 11:00
+     */
     @Override
     public Result removeDevice(String deviceData) throws UnsupportedEncodingException {
         JSONObject deviceDataJo = JSON.parseObject(deviceData);
@@ -153,9 +193,70 @@ public class FarmDeviceImpl implements IFarmDevice {
         return new Result(ResultCode.SUCCESS);
     }
 
+    /**
+     * @Method      : listDevice
+     * @Description : 设备信息列表展示
+     * @Params      : [deviceData]
+     * @Return      : com.huimv.common.utils.Result
+     * 
+     * @Author      : ZhuoNing
+     * @Date        : 2021/12/17       
+     * @Time        : 9:22
+     */
     @Override
     public Result listDevice(String deviceData){
+        JSONObject deviceDataJo = JSON.parseObject(deviceData);
+        String deviceName= deviceDataJo.getString("deviceName");
+        String deviceCode = deviceDataJo.getString("deviceCode");
+        String deviceType=deviceDataJo.getString("deviceType");
+        String factory = deviceDataJo.getString("factory");
+        String worker = deviceDataJo.getString("worker");
+        Integer state = deviceDataJo.getInteger("state");
+        Integer farmId = deviceDataJo.getInteger("farmId");
+        String startDateText =  deviceDataJo.getString("startDate");
+        String endDateText =  deviceDataJo.getString("endDate");
+        Integer pageNo = deviceDataJo.getInteger("pageNo");
+        Integer pageSize = deviceDataJo.getInteger("pageSize");
 
-        return new Result(ResultCode.SUCCESS);
+        Specification<FarmDeviceEntity> sf = (Specification<FarmDeviceEntity>) (root, criteriaQuery, criteriaBuilder) -> {
+            //
+            List<Predicate> predList = new ArrayList<>();
+            if (null != farmId) {
+                predList.add(criteriaBuilder.equal(root.get("farmId").as(Integer.class), farmId));
+            }
+            if (null != deviceName) {
+                predList.add(criteriaBuilder.equal(root.get("deviceName").as(String.class), deviceName));
+            }
+            if (null != deviceCode) {
+                predList.add(criteriaBuilder.equal(root.get("deviceCode").as(String.class), deviceCode));
+            }
+            if (null != factory) {
+                predList.add(criteriaBuilder.equal(root.get("factory").as(String.class), factory));
+            }
+            if (null != worker) {
+                predList.add(criteriaBuilder.equal(root.get("worker").as(String.class), worker));
+            }
+            if (null != startDateText) {
+                Date startDate = dateUtil.parseDate(startDateText);
+                predList.add(criteriaBuilder.greaterThanOrEqualTo(root.get("lastTime").as(Date.class), startDate));
+            }
+            if (null != endDateText) {
+                Date endDate = dateUtil.parseDatePlus(endDateText);
+                predList.add(criteriaBuilder.lessThanOrEqualTo(root.get("lastTime").as(Date.class), endDate));
+            }
+            if (null != state) {
+                predList.add(criteriaBuilder.equal(root.get("state").as(Integer.class), state));
+            }
+            //
+            Predicate[] pred = new Predicate[predList.size()];
+            Predicate and = criteriaBuilder.and(predList.toArray(pred));
+            criteriaQuery.where(and);
+            //
+            List<Order> orders = new ArrayList<>();
+            orders.add(criteriaBuilder.desc(root.get("id")));
+            return criteriaQuery.orderBy(orders).getRestriction();
+        };
+        Pageable pageable = PageRequest.of(pageNo - 1, pageSize);
+        return new Result(ResultCode.SUCCESS, deviceRepo.findAll(sf, pageable));
     }
 }

+ 7 - 1
huimv-farm-device/huimv-farm-business/src/main/java/com/huimv/business/server/dao/repo/FarmDeviceRepo.java

@@ -5,10 +5,16 @@ import org.springframework.data.jpa.repository.JpaRepository;
 import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
 import org.springframework.data.jpa.repository.Query;
 
+import javax.swing.text.html.Option;
 import java.util.List;
+import java.util.Optional;
 
 public interface FarmDeviceRepo extends JpaRepository<FarmDeviceEntity, Integer>, JpaSpecificationExecutor<FarmDeviceEntity> {
     //
     @Query(nativeQuery = true,value = "SELECT id FROM farm_device WHERE data_id=?1")
-    List<Object[]> getDevice(Integer dataId);
+    List<Object[]> getDevice(Long dataId);
+
+    //
+    @Query(nativeQuery = true,value = "SELECT * FROM farm_device WHERE data_id=?1")
+    Optional<FarmDeviceEntity> getDeviceByDataId(Long dataId);
 }

+ 64 - 37
huimv-farm-device/huimv-farm-business/src/main/java/com/huimv/business/server/service/impl/DeviceImpl.java

@@ -16,6 +16,7 @@ import java.io.UnsupportedEncodingException;
 import java.sql.Date;
 import java.sql.Timestamp;
 import java.util.List;
+import java.util.Optional;
 
 /**
  * @Project : huimv.shiwan
@@ -33,27 +34,37 @@ public class DeviceImpl implements IDevice {
     @Autowired
     private TextUtil textUtil;
 
+    /**
+     * @Method      : syncAddFarmDevice
+     * @Description : 同步添加牧场端设备数据
+     * @Params      : [deviceData]
+     * @Return      : com.huimv.common.utils.Result
+     * 
+     * @Author      : ZhuoNing
+     * @Date        : 2021/12/17       
+     * @Time        : 14:22
+     */
     @Override
     public Result syncAddFarmDevice(String deviceData) throws UnsupportedEncodingException {
         //转义符号处理
         JSONObject deviceDataJo = JSON.parseObject(textUtil.translateSymbol(deviceData));
         FarmDeviceEntity deviceEntity = new FarmDeviceEntity();
-        deviceEntity.setDataId(deviceDataJo.getLong("id"));
+        deviceEntity.setDataId(deviceDataJo.getLong("dataId"));
         deviceEntity.setDeviceCode(deviceDataJo.getString("deviceCode"));
         deviceEntity.setDeviceName(deviceDataJo.getString("deviceName"));
         deviceEntity.setDeviceType(deviceDataJo.getString("deviceType"));
-        deviceEntity.setDownTime(new Timestamp(new  java.util.Date().getTime()));
+        deviceEntity.setDownTime(new Timestamp(new java.util.Date().getTime()));
         deviceEntity.setFactory(deviceDataJo.getString("factory"));
         deviceEntity.setFarmId(deviceDataJo.getInteger("farmId"));
-        deviceEntity.setLastTime(new Timestamp(new  java.util.Date().getTime()));
+        deviceEntity.setLastTime(new Timestamp(new java.util.Date().getTime()));
         deviceEntity.setLockinState(2);
         deviceEntity.setMainParams(deviceDataJo.getString("mainParams"));
         deviceEntity.setRecord(deviceDataJo.getString("record"));
         deviceEntity.setState(deviceDataJo.getInteger("state"));
         deviceEntity.setWorker(deviceDataJo.getString("worker"));
         FarmDeviceEntity addEntity = deviceRepo.saveAndFlush(deviceEntity);
-        log.info("同步添加牧场端设备数据>>"+addEntity);
-        return new Result(ResultCode.SUCCESS,addEntity);
+        log.info("同步添加牧场端设备数据>>" + addEntity);
+        return new Result(ResultCode.SUCCESS, addEntity);
     }
 
     //转义处理
@@ -61,57 +72,73 @@ public class DeviceImpl implements IDevice {
 //        return textUtil.decode(data.replace("data=","").replace("%3D","="));
 //    }
 
+    /**
+     * @Method      : syncEditFarmDevice
+     * @Description : 同步更新牧场端设备数据
+     * @Params      : [deviceData]
+     * @Return      : com.huimv.common.utils.Result
+     * 
+     * @Author      : ZhuoNing
+     * @Date        : 2021/12/17       
+     * @Time        : 14:21
+     */
     @Override
     public Result syncEditFarmDevice(String deviceData) throws UnsupportedEncodingException {
         //转义符号处理
         JSONObject deviceDataJo = JSON.parseObject(textUtil.translateSymbol(deviceData));
-        Integer dataId = deviceDataJo.getInteger("id");
+        Long dataId = deviceDataJo.getLong("dataId");
         //查询目标设备数据
-        List<Object[]> existList = deviceRepo.getDevice(dataId);
-        if(existList.size()>0) {
-            Object[] object = existList.get(0);
-            Integer id = (Integer) object[0];
-            //更新目标设备数据
-            FarmDeviceEntity deviceEntity = new FarmDeviceEntity();
-            deviceEntity.setId(id);
-            deviceEntity.setDataId(deviceDataJo.getLong("id"));
-            deviceEntity.setDeviceCode(deviceDataJo.getString("deviceCode"));
-            deviceEntity.setDeviceName(deviceDataJo.getString("deviceName"));
-            deviceEntity.setDeviceType(deviceDataJo.getString("deviceType"));
-            deviceEntity.setDownTime(new Timestamp(new java.util.Date().getTime()));
-            deviceEntity.setFactory(deviceDataJo.getString("factory"));
-            deviceEntity.setFarmId(deviceDataJo.getInteger("farmId"));
-            deviceEntity.setLastTime(new Timestamp(new java.util.Date().getTime()));
-            deviceEntity.setLockinState(2);
-            deviceEntity.setMainParams(deviceDataJo.getString("mainParams"));
-            deviceEntity.setRecord(deviceDataJo.getString("record"));
-            deviceEntity.setState(deviceDataJo.getInteger("state"));
-            deviceEntity.setWorker(deviceDataJo.getString("worker"));
-            FarmDeviceEntity editEntity = deviceRepo.saveAndFlush(deviceEntity);
-            log.info("同步编辑牧场端设备数据>>" + editEntity);
-            return new Result(ResultCode.SUCCESS,editEntity);
-        }else{
-            log.info("错误:牧场端不存在data_id为"+dataId+"的记录。");
-            return new Result(ResultCode.SUCCESS);
+        Optional<FarmDeviceEntity> optional = deviceRepo.getDeviceByDataId(dataId);
+        if (!optional.isPresent()) {
+            String ERR_NOEXIST = "错误:牧场端不存在data_id为" + dataId + "的记录。";
+            log.info(ERR_NOEXIST);
+            return new Result(10001, ERR_NOEXIST, false);
         }
+        //更新目标设备数据
+        FarmDeviceEntity deviceEntity = optional.get();
+        deviceEntity.setDeviceCode(deviceDataJo.getString("deviceCode"));
+        deviceEntity.setDeviceName(deviceDataJo.getString("deviceName"));
+        deviceEntity.setDeviceType(deviceDataJo.getString("deviceType"));
+        deviceEntity.setDownTime(new Timestamp(new java.util.Date().getTime()));
+        deviceEntity.setFactory(deviceDataJo.getString("factory"));
+        deviceEntity.setFarmId(deviceDataJo.getInteger("farmId"));
+        deviceEntity.setLastTime(new Timestamp(new java.util.Date().getTime()));
+        deviceEntity.setLockinState(2);
+        deviceEntity.setMainParams(deviceDataJo.getString("mainParams"));
+        deviceEntity.setRecord(deviceDataJo.getString("record"));
+        deviceEntity.setState(deviceDataJo.getInteger("state"));
+        deviceEntity.setWorker(deviceDataJo.getString("worker"));
+        FarmDeviceEntity editEntity = deviceRepo.saveAndFlush(deviceEntity);
+        log.info("同步编辑牧场端设备数据>>" + editEntity);
+        return new Result(ResultCode.SUCCESS, editEntity);
     }
 
+    /**
+     * @Method      : syncRemoveFarmDevice
+     * @Description : 同步删除牧场端设备数据
+     * @Params      : [deviceData]
+     * @Return      : com.huimv.common.utils.Result
+     * 
+     * @Author      : ZhuoNing
+     * @Date        : 2021/12/17       
+     * @Time        : 14:20
+     */
     @Override
     public Result syncRemoveFarmDevice(String deviceData) throws UnsupportedEncodingException {
         //转义符号处理
-        Integer dataId = Integer.parseInt(textUtil.translateSymbol(deviceData));
+        Long dataId = Long.parseLong(textUtil.translateSymbol(deviceData));
         //查询目标设备数据
         List<Object[]> existList = deviceRepo.getDevice(dataId);
-        if(existList.size()>0) {
+        if (existList.size() > 0) {
             Object[] object = existList.get(0);
             Integer id = (Integer) object[0];
             deviceRepo.deleteById(id);
             log.info("同步删除牧场端设备数据.");
             return new Result(ResultCode.SUCCESS);
-        }else{
-            String ERR_INFO="暂无需要删除的设备数据.";
+        } else {
+            String ERR_INFO = "暂无需要删除的设备数据.";
             log.info(ERR_INFO);
-            return new Result(10001,ERR_INFO,false);
+            return new Result(10001, ERR_INFO, false);
         }
     }
 }

+ 321 - 0
huimv-farm-device/huimv-farm-business/src/main/java/com/huimv/business/utils/DateUtil.java

@@ -0,0 +1,321 @@
+package com.huimv.business.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 {
+    /**
+     * 获取今天
+     *
+     * @return String
+     */
+    public String getToday() {
+        return new SimpleDateFormat("yyyy-MM-dd").format(new Date());
+    }
+
+    /**
+     * 获取昨天
+     *
+     * @return String
+     */
+    public String getYestoday() {
+        Calendar cal = Calendar.getInstance();
+        cal.add(Calendar.DATE, -1);
+        Date time = cal.getTime();
+        return new SimpleDateFormat("yyyy-MM-dd").format(time);
+    }
+
+    /**
+     * 获取本月开始日期
+     *
+     * @return String
+     **/
+    public String getMonthStart() {
+        Calendar cal = Calendar.getInstance();
+        cal.add(Calendar.MONTH, 0);
+        cal.set(Calendar.DAY_OF_MONTH, 1);
+        Date time = cal.getTime();
+        return new SimpleDateFormat("yyyy-MM-dd").format(time);
+    }
+
+    /**
+     * 获取本月最后一天
+     *
+     * @return String
+     **/
+    public String getMonthEnd() {
+        Calendar cal = Calendar.getInstance();
+        cal.set(Calendar.DAY_OF_MONTH, cal.getActualMaximum(Calendar.DAY_OF_MONTH));
+        Date time = cal.getTime();
+        return new SimpleDateFormat("yyyy-MM-dd").format(time);
+    }
+
+    /**
+     * 获取本周的第一天
+     *
+     * @return String
+     **/
+    public String getWeekStart() {
+        Calendar cal = Calendar.getInstance();
+        cal.add(Calendar.WEEK_OF_MONTH, 0);
+        cal.set(Calendar.DAY_OF_WEEK, 2);
+        Date time = cal.getTime();
+        return new SimpleDateFormat("yyyy-MM-dd").format(time);
+    }
+
+    /**
+     * 获取本周的最后一天
+     *
+     * @return String
+     **/
+    public String getWeekEnd() {
+        Calendar cal = Calendar.getInstance();
+        cal.set(Calendar.DAY_OF_WEEK, cal.getActualMaximum(Calendar.DAY_OF_WEEK));
+        cal.add(Calendar.DAY_OF_WEEK, 1);
+        Date time = cal.getTime();
+        return new SimpleDateFormat("yyyy-MM-dd").format(time);
+    }
+
+    /**
+     * 获取本年的第一天
+     *
+     * @return String
+     **/
+    public String getYearStart() {
+        return new SimpleDateFormat("yyyy").format(new Date()) + "-01-01";
+    }
+
+    /**
+     * 获取本年的最后一天
+     *
+     * @return String
+     **/
+    public String getYearEnd() {
+        Calendar calendar = Calendar.getInstance();
+        calendar.set(Calendar.MONTH, calendar.getActualMaximum(Calendar.MONTH));
+        calendar.set(Calendar.DAY_OF_MONTH, calendar.getActualMaximum(Calendar.DAY_OF_MONTH));
+        Date currYearLast = calendar.getTime();
+        return new SimpleDateFormat("yyyy-MM-dd").format(currYearLast);
+    }
+
+    //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 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) {
+        if (dateText.indexOf("T") != -1) {
+            dateText = dateText.replace("T", " ");
+        }
+        try {
+            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
+            return sdf.parse(dateText);
+        } catch (Exception e) {
+            return null;
+        }
+    }
+
+
+    public Date parseDatePlus(String dateText) {
+        try {
+            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
+            Calendar cd = Calendar.getInstance();
+            cd.setTime(sdf.parse(dateText));
+            cd.add(Calendar.DATE, 1);//增加一天
+            //cd.add(Calendar.MONTH, n);//增加一个月
+            return sdf.parse(sdf.format(cd.getTime()));
+        } catch (Exception e) {
+            return null;
+        }
+    }
+
+    public Date parseDate2(String dateText) throws ParseException {
+        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);
+    }
+}