Kaynağa Gözat

地磅数据

chenxiaofei 1 ay önce
ebeveyn
işleme
08779b0893
18 değiştirilmiş dosya ile 2131 ekleme ve 45 silme
  1. 4 0
      iot-platform-common/pom.xml
  2. 64 0
      iot-platform-common/src/main/java/com/platform/result/BaseResult.java
  3. 80 0
      iot-platform-common/src/main/java/com/platform/result/PageDataResult.java
  4. 1195 0
      iot-platform-common/src/main/java/com/platform/utils/DateUtil.java
  5. 55 0
      iot-platform-common/src/main/java/com/platform/utils/EasyExcelUtil.java
  6. 26 0
      iot-platform-common/src/main/java/com/platform/utils/ExcelContext.java
  7. 30 0
      iot-platform-common/src/main/java/com/platform/utils/LocalDateTimeConverter.java
  8. 40 0
      iot-platform-common/src/main/java/com/platform/utils/LongStringConverter.java
  9. 36 0
      iot-platform-common/src/main/java/com/platform/utils/RowWriteHandlerImpl.java
  10. 14 12
      iot-platform-manager/src/main/java/com/platform/api/controller/KwsPrinterController.java
  11. 20 20
      iot-platform-manager/src/main/java/com/platform/api/controller/KwsWeighbridgeController.java
  12. 79 0
      iot-platform-manager/src/main/java/com/platform/api/controller/KwsWeighbridgeRecordController.java
  13. 3 2
      iot-platform-manager/src/main/java/com/platform/api/manager/KwsPrinterManageService.java
  14. 4 3
      iot-platform-manager/src/main/java/com/platform/api/manager/KwsWeighbridgeManageService.java
  15. 264 8
      iot-platform-manager/src/main/java/com/platform/api/manager/WeighbridgeRecordManage.java
  16. 88 0
      iot-platform-manager/src/main/java/com/platform/api/request/WeighbridgeRecordPageReqVo.java
  17. 46 0
      iot-platform-manager/src/main/java/com/platform/api/response/WeighbridgeRecordExcel.java
  18. 83 0
      iot-platform-manager/src/main/java/com/platform/api/response/WeighbridgeRecordResVo.java

+ 4 - 0
iot-platform-common/pom.xml

@@ -52,6 +52,10 @@
             <groupId>com.github.pagehelper</groupId>
             <artifactId>pagehelper</artifactId>
         </dependency>
+        <dependency>
+            <groupId>com.alibaba</groupId>
+            <artifactId>fastjson</artifactId>
+        </dependency>
     </dependencies>
     <build>
         <plugins>

+ 64 - 0
iot-platform-common/src/main/java/com/platform/result/BaseResult.java

@@ -0,0 +1,64 @@
+package com.platform.result;
+
+
+import lombok.Data;
+
+import java.io.Serial;
+import java.io.Serializable;
+
+
+@Data
+public class BaseResult<T> implements Serializable {
+
+    @Serial
+    private static final long serialVersionUID = -7714239361191848765L;
+    private int code = HttpV1Status.SUCCESS_CODE;
+	private String message = HttpV1Status.SUCCESS_MESSAGE;
+	private T data;
+
+    /**
+     * 成功响应 - 无数据
+     */
+    public static <T> BaseResult<T> success() {
+        return success(null);
+    }
+    /**
+     * 成功响应 - 有数据
+     */
+    public static <T> BaseResult<T> success(T data) {
+        BaseResult<T> result = new BaseResult<>();
+        result.setData(data);
+        return result;
+    }
+    public static <T> BaseResult<T> success(T data,String message) {
+        BaseResult<T> result = new BaseResult<>();
+        result.setData(data);
+        result.setMessage(message);
+        return result;
+    }
+
+    /**
+     * 失败响应 - 自定义消息
+     */
+    public static <T> BaseResult<T> failed(String message) {
+        BaseResult<T> result = new BaseResult<>();
+        result.setCode(500);
+        result.setMessage(message);
+        return result;
+    }
+
+    /**
+     * 失败响应 - 自定义码值和消息
+     */
+    public static <T> BaseResult<T> failed(int code, String message) {
+        BaseResult<T> result = new BaseResult<>();
+        result.setCode(code);
+        result.setMessage(message);
+        return result;
+    }
+
+
+    public boolean isSuccess() {
+        return code == HttpV1Status.SUCCESS_CODE;
+    }
+}

+ 80 - 0
iot-platform-common/src/main/java/com/platform/result/PageDataResult.java

@@ -0,0 +1,80 @@
+package com.platform.result;
+
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import lombok.Data;
+
+import java.io.Serial;
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.List;
+
+
+/**
+ * @author PC
+ */
+@Data
+public class PageDataResult<T> implements Serializable {
+
+    @Serial
+    private static final long serialVersionUID = 1803433537622129194L;
+    /** 总记录数 */
+    private long total;
+
+    /** 当前页码(从1开始) */
+    private int pageNum;
+
+    /** 每页显示条数 */
+    private int pageSize;
+
+    /**
+     * 总页数
+     */
+    private int pages;
+
+    /** 当前页的数据列表 */
+    private List<T> list;
+
+    public PageDataResult() {
+
+    }
+
+    // 创建空分页结果
+    public static <T> PageDataResult<T> empty(Integer pageNum, Integer pageSize) {
+        return new PageDataResult<>(pageNum, pageSize, 0L, new ArrayList<>());
+    }
+    public PageDataResult(Integer pageNum, Integer pageSize, Long total, List<T> data) {
+        this.pageNum = pageNum;
+        this.pageSize = pageSize;
+        this.total = total;
+        this.list = data;
+        this.pages = (int) Math.ceil((double) total / pageSize);
+    }
+
+    public static <T> PageDataResult<T> success(Integer pageNum, Integer pageSize, Long total, List<T> data) {
+        PageDataResult<T> pageResult = new PageDataResult<T>();
+        pageResult.setPageNum(pageNum);
+        pageResult.setPageSize(pageSize);
+        pageResult.setTotal(total);
+        // 修正总页数计算
+        if(total==0){
+            pageResult.setPages(0);
+        }else{
+            pageResult.setPages((int) ((total + pageSize - 1) / pageSize));
+        }
+        pageResult.setList(data);
+        return pageResult;
+    }
+
+    public static <T> PageDataResult<T> of(IPage page, List<T> records) {
+        PageDataResult<T> pageResult = new PageDataResult<T>();
+        pageResult.setPageNum((int)page.getCurrent());
+        pageResult.setPageSize((int) page.getSize());
+        pageResult.setTotal(page.getTotal());
+        // 修正总页数计算
+        pageResult.setPages((int) ((page.getTotal() + page.getSize() - 1) / page.getSize()));
+        pageResult.setList(records);
+        return pageResult;
+    }
+
+
+}

+ 1195 - 0
iot-platform-common/src/main/java/com/platform/utils/DateUtil.java

@@ -0,0 +1,1195 @@
+package com.platform.utils;
+
+
+import cn.hutool.core.date.DateField;
+import cn.hutool.core.date.DateTime;
+import com.platform.exception.IotException;
+import org.springframework.util.Assert;
+
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.time.*;
+import java.time.format.DateTimeFormatter;
+import java.util.*;
+
+/**
+ * @description: 时间工具类
+ * @author: LengFaQiang
+ * @copyright
+ * @create: 2022-01-27 16:04
+ **/
+public class DateUtil {
+    public static final String DEFAULT_DATE_PATTERN = "yyyy-MM-dd HH:mm:ss";
+    public static final String DEF_DATE_FORMAT = "yyyy-MM-dd";
+    public static final DateTimeFormatter YYYY_MM_DD_HH_MM_SS = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
+    public static final DateTimeFormatter YYYYMMDDHHMMSS = DateTimeFormatter.ofPattern("yyyyMMddHHmmss");
+    public static final DateTimeFormatter YYYY_MM_DD = DateTimeFormatter.ofPattern("yyyy-MM-dd");
+    public static final DateTimeFormatter HH_MM_SS = DateTimeFormatter.ofPattern("HH:mm:ss");
+
+    public DateUtil() {
+    }
+
+    /**
+     * 获取当前时间
+     *
+     * @return
+     */
+    public static long getSystemTimeMillis() {
+        Clock clock = Clock.systemDefaultZone();
+        return clock.millis();
+    }
+
+
+
+    /**
+     * 2023-07-14T09:43:40.511+00:00 -> 2023-07-14 09:13:40
+     *
+     * @param date
+     * @return
+     */
+    public static String getDateTime(Date date) {
+        if (date == null) {
+            return null;
+        }
+        Instant instant = date.toInstant();
+        ZoneId zoneId = ZoneId.systemDefault();
+        LocalDateTime localDateTime = instant.atZone(zoneId).toLocalDateTime();
+        return localDateTime.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
+    }
+
+    /**
+     * data
+     *
+     * @param date Date 时间
+     * @return
+     * @throws ParseException
+     */
+    public static String dateTimeFormatter(Date date) {
+        String format = new SimpleDateFormat(DEFAULT_DATE_PATTERN).format(date);
+        return format;
+    }
+
+    public static LocalDateTime localDateToLocalDateTimeEnd(LocalDate date) {
+        String str = dateToStr(date, "yyyy-MM-dd") + " 23:59:59";
+//        LocalDate localDate = parseLocalDate(str);
+        LocalDateTime localDateTime = LocalDateTime.parse(str, YYYY_MM_DD_HH_MM_SS);
+        return localDateTime;
+    }
+
+    public static LocalDateTime localDateToLocalDateTimeStart(LocalDate date) {
+        String str = dateToStr(date, "yyyy-MM-dd") + " 00:00:00";
+//        LocalDate localDate = parseLocalDate(str);
+        LocalDateTime localDateTime = LocalDateTime.parse(str, YYYY_MM_DD_HH_MM_SS);
+        return localDateTime;
+    }
+
+
+    public static String dateToStr(LocalDate date) {
+        return dateToStr(date, "yyyy-MM-dd");
+    }
+
+    public static String dateToStr(LocalDate date, String pattern) {
+        String dateStr = date.format(DateTimeFormatter.ofPattern(pattern));
+        return dateStr;
+    }
+
+    public static String timeToStr(LocalDateTime date) {
+        return timeToStr(date, "yyyy-MM-dd HH:mm:ss");
+    }
+
+    public static String timeToStr(LocalDateTime date, String pattern) {
+        String dateStr = date.format(DateTimeFormatter.ofPattern(pattern));
+        return dateStr;
+    }
+
+    public static LocalDateTime strToTime(String str) {
+        return LocalDateTime.parse(str, DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
+    }
+
+    /**
+     * yyyy-MM-dd 转换成 LocalDate
+     *
+     * @param str
+     * @return
+     */
+    public static LocalDate strToDate(String str) {
+        return LocalDate.parse(str, DateTimeFormatter.ofPattern("yyyy-MM-dd"));
+    }
+
+
+    public static String localDateTimeToString(LocalDateTime localDateTime) {
+        String localDateTimeNowStr = localDateTime.format(YYYYMMDDHHMMSS);
+        return localDateTimeNowStr;
+    }
+
+
+    /**
+     * yyyy-MM-dd 转换成 LocalDateTime-添加00:00:00
+     *
+     * @param str
+     * @return
+     */
+    public static LocalDateTime strToLocalDateTime(String str) {
+        LocalDate localDate = LocalDate.parse(str, DateTimeFormatter.ofPattern("yyyy-MM-dd"));
+        LocalDateTime localDateTime = localDate.atStartOfDay();
+        String format = localDateTime.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
+        LocalDateTime parse = LocalDateTime.parse(format, DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
+        return parse;
+    }
+
+    /**
+     * yyyyMMdd 转换成 LocalDate
+     *
+     * @param str
+     * @return
+     */
+    public static LocalDate stringToDate(String str) {
+        return LocalDate.parse(str, DateTimeFormatter.ofPattern("yyyyMMdd"));
+    }
+
+    /**
+     * yyyyMMdd 转换成 LocalDate
+     *
+     * @param str
+     * @return
+     */
+    public static LocalDate strToDateTime(String str) {
+        return LocalDate.parse(str, DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
+    }
+
+    /**
+     * yyyy-MM-dd HH:mm:ss 转换成 Date
+     *
+     * @param str
+     * @return
+     */
+    public static Date strDateTimeToDateTime(String str) {
+        SimpleDateFormat simpleDateFormat = new SimpleDateFormat(DEFAULT_DATE_PATTERN);
+        Date parse = null;
+        try {
+            parse = simpleDateFormat.parse(str);
+        } catch (ParseException e) {
+            throw new RuntimeException(e);
+        }
+        return parse;
+    }
+
+
+    /**
+     * 上个月
+     *
+     * @return 上个月
+     */
+    public static DateTime lastMonth(int offset) {
+        return offsetMonth(new DateTime(), -offset);
+    }
+
+    /**
+     * 偏移月
+     *
+     * @param date   日期
+     * @param offset 偏移月数,正数向未来偏移,负数向历史偏移
+     * @return 偏移后的日期
+     */
+    public static DateTime offsetMonth(Date date, int offset) {
+        return offset(date, DateField.MONTH, offset);
+    }
+
+    /**
+     * 获取指定日期偏移指定时间后的时间,生成的偏移日期不影响原日期
+     *
+     * @param date      基准日期
+     * @param dateField 偏移的粒度大小(小时、天、月等){@link DateField}
+     * @param offset    偏移量,正数为向后偏移,负数为向前偏移
+     * @return 偏移后的日期
+     */
+    public static DateTime offset(Date date, DateField dateField, int offset) {
+        return dateNew(date).offset(dateField, offset);
+    }
+
+    /**
+     * 根据已有{@link Date} 产生新的{@link DateTime}对象
+     *
+     * @param date Date对象,如果传入{@code null},返回{@code null}
+     * @return {@link DateTime}对象
+     * @since 4.3.1
+     */
+    public static DateTime dateNew(Date date) {
+        if (date == null) {
+            return null;
+        }
+        return new DateTime(date);
+    }
+
+    /**
+     * @param time yyyy-MM-dd
+     * @return String yyyy-MM-dd HH:mm:ss
+     * @throws RuntimeException
+     */
+    public static String fillStart(String time) {
+        formatCheck(time);
+        return time + " 00:00:00";
+    }
+
+    @SuppressWarnings("all")
+    private static void formatCheck(String time) {
+        try {
+            LocalDate.parse(time, YYYY_MM_DD);
+        } catch (Exception e) {
+            throw new IotException("时间格式化错误!");
+        }
+    }
+
+
+    /**
+     * 获取上周和上上周的开始时间和结束时间
+     *
+     * @return
+     */
+    private static Map<String, String> getLastWeekTime() {
+        cn.hutool.core.date.Week week = DateTime.now().dayOfWeekEnum();
+        switch (week) {
+            /** 周一 */
+            case MONDAY:
+                return getRealizeLastWeekTime(-14, -8, -7, -1);
+            /** 周二 */
+            case TUESDAY:
+                return getRealizeLastWeekTime(-15, -9, -8, -2);
+            /** 周三 */
+            case WEDNESDAY:
+                return getRealizeLastWeekTime(-16, -10, -9, -3);
+            /** 周四 */
+            case THURSDAY:
+                return getRealizeLastWeekTime(-17, -11, -10, -4);
+            /** 周五 */
+            case FRIDAY:
+                return getRealizeLastWeekTime(-18, -12, -11, -5);
+            /** 周六 */
+            case SATURDAY:
+                return getRealizeLastWeekTime(-19, -13, -12, -6);
+            /** 周日 */
+            case SUNDAY:
+                return getRealizeLastWeekTime(-20, -14, -13, -7);
+            default:
+                throw new RuntimeException("method:getLastWeekTime,获取当前时间是周几异常");
+        }
+    }
+
+
+    private static Map<String, String> getRealizeLastWeekTime(int upLastStartOffset, int upLastEndOffset, int lastStartOffset, int lastEndOffset) {
+        // 获取上上周的开始时间和结束时间
+        String startUpLastWeekTime = DateTime.now().offset(DateField.DAY_OF_YEAR, upLastStartOffset)
+                .setField(DateField.HOUR_OF_DAY, 0).setField(DateField.MINUTE, 0)
+                .setField(DateField.SECOND, 0).setField(DateField.MILLISECOND, 0).toString();
+        String endUpLastWeekTime = DateTime.now().offset(DateField.DAY_OF_YEAR, upLastEndOffset)
+                .setField(DateField.HOUR_OF_DAY, 23).setField(DateField.MINUTE, 59)
+                .setField(DateField.SECOND, 59).setField(DateField.MILLISECOND, 0).toString();
+        // 获取上周的开始时间和结束时间
+        String startLastWeekTime = DateTime.now().offset(DateField.DAY_OF_YEAR, lastStartOffset)
+                .setField(DateField.HOUR_OF_DAY, 0).setField(DateField.MINUTE, 0)
+                .setField(DateField.SECOND, 0).setField(DateField.MILLISECOND, 0).toString();
+        String endLastWeekTime = DateTime.now().offset(DateField.DAY_OF_YEAR, lastEndOffset)
+                .setField(DateField.HOUR_OF_DAY, 23).setField(DateField.MINUTE, 59)
+                .setField(DateField.SECOND, 59).setField(DateField.MILLISECOND, 0).toString();
+        Map<String, String> maps = new HashMap<>(16);
+        maps.put("startUpLastWeekTime", startUpLastWeekTime);
+        maps.put("endUpLastWeekTime", endUpLastWeekTime);
+        maps.put("startLastWeekTime", startLastWeekTime);
+        maps.put("endLastWeekTime", endLastWeekTime);
+        return maps;
+    }
+
+    /**
+     * yyyy-MM-dd 转换成 Date
+     *
+     * @param str
+     * @return
+     */
+    public static Date stringToDateTime(String str) {
+        SimpleDateFormat simpleDateFormat1 = new SimpleDateFormat(DEFAULT_DATE_PATTERN);
+        Date date = null;
+        try {
+            date = simpleDateFormat1.parse(str);
+        } catch (ParseException e) {
+            throw new RuntimeException(e);
+        }
+        return date;
+    }
+
+    /**
+     * yyyy-MM-dd 转换成 Date
+     *
+     * @param str
+     * @return
+     */
+    public static Date stringPatchingStartToDateTime(String str) {
+        str = str + " 00:00:00";
+        SimpleDateFormat simpleDateFormat1 = new SimpleDateFormat(DEFAULT_DATE_PATTERN);
+        Date date = null;
+        try {
+            date = simpleDateFormat1.parse(str);
+        } catch (ParseException e) {
+            throw new RuntimeException(e);
+        }
+        return date;
+    }
+
+    /**
+     * yyyy-MM-dd 转换成 Date
+     *
+     * @param str
+     * @return
+     */
+    public static Date stringPatchingEndToDateTime(String str) {
+        str = str + " 23:59:59";
+        SimpleDateFormat simpleDateFormat1 = new SimpleDateFormat(DEFAULT_DATE_PATTERN);
+        Date date = null;
+        try {
+            date = simpleDateFormat1.parse(str);
+        } catch (ParseException e) {
+            throw new RuntimeException(e);
+        }
+        return date;
+    }
+
+
+    /**
+     * 日期字符串转换为LocalDateTime方法
+     *
+     * @param dateString 日期字符串,格式:yyyyMMdd
+     * @return
+     */
+    public static LocalDateTime handleDateTimeString(String dateString) {
+        //日期字符串的长度
+        Integer dateLength = 10;
+        if (org.apache.commons.lang3.StringUtils.isNotBlank(dateString) && dateString.length() == dateLength) {
+            StringBuilder sb = new StringBuilder(dateString);
+            return LocalDateTime.parse(sb.toString() + "T00:00:00");
+        }
+        return null;
+    }
+
+    /**
+     * 日期字符串转换为LocalDateTime方法
+     *
+     * @param dateString 日期字符串,格式:yyyyMMdd
+     * @return
+     */
+    public static LocalDateTime handleDateString(String dateString) {
+        //日期字符串的长度
+        Integer dateLength = 8;
+        if (org.apache.commons.lang3.StringUtils.isNotBlank(dateString) && dateString.length() == dateLength) {
+            StringBuilder sb = new StringBuilder(dateString);
+            sb.insert(4, "-");
+            sb.insert(7, "-");
+            return LocalDateTime.parse(sb.toString() + "T00:00:00");
+        }
+        return null;
+    }
+
+    /**
+     * 日期字符串转换为LocalDateTime方法-添加00:00:00
+     *
+     * @param dateString 日期字符串,格式:yyyy-MM-dd
+     * @return
+     */
+    public static LocalDateTime strToLocalDateTimeStart(String dateString) {
+        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
+        LocalDateTime localDateTime = LocalDate.parse(dateString, formatter).atStartOfDay();
+//        LocalDateTime localDateTime1 = strToLocalDateTime(dateString);
+        return localDateTime;
+    }
+
+
+    /**
+     * 日期字符串转换为LocalDateTime方法-添加00:00:00
+     *
+     * @param dateString 日期字符串,格式:yyyy-MM-dd
+     * @return
+     */
+    public static LocalDateTime strToLocalDateTimeEnd(String dateString) {
+        String timeString = " 23:59:59";
+        String dateTimeString = timeString + timeString;
+        DateTimeFormatter formatter1 = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
+        LocalDateTime localDateTime = LocalDateTime.now();
+        try {
+            localDateTime = LocalDateTime.parse(dateTimeString, formatter1);
+            return localDateTime;
+        } catch (java.time.format.DateTimeParseException e) {
+            throw new RuntimeException("Invalid date strToLocalDateTimeEnd error" + e.getMessage());
+        }
+    }
+
+
+    public static String date() {
+        return LocalDate.now().format(YYYY_MM_DD);
+    }
+
+    public static int year() {
+        return LocalDate.now().getYear();
+    }
+
+    public static int month() {
+        return LocalDate.now().getMonthValue();
+    }
+
+    public static int dayOfMonth() {
+        return LocalDate.now().getDayOfMonth();
+    }
+
+    public static int dayOfYear() {
+        return LocalDate.now().getDayOfYear();
+    }
+
+    public static int dayOfWeek() {
+        return LocalDate.now().getDayOfWeek().getValue();
+    }
+
+    public static String newDate(int year, int month, int day) {
+        return LocalDate.of(year, month, day).toString();
+    }
+
+    public static String newDate(int year, int dayNum) {
+        return LocalDate.ofYearDay(year, dayNum).toString();
+    }
+
+    public static String time() {
+        return LocalTime.now().format(HH_MM_SS);
+    }
+
+    public static int hour() {
+        return LocalTime.now().getHour();
+    }
+
+    public static int minute() {
+        return LocalTime.now().getMinute();
+    }
+
+    public static int second() {
+        return LocalTime.now().getSecond();
+    }
+
+    public static String dateTime() {
+        return LocalDateTime.now().format(YYYY_MM_DD_HH_MM_SS);
+    }
+
+    public static LocalDateTime parseDateTime(long time) {
+        return LocalDateTime.ofInstant(Instant.ofEpochMilli(time), ZoneId.systemDefault());
+    }
+
+    public static LocalDateTime parseDateTime(String time) {
+        return LocalDateTime.parse(time, YYYY_MM_DD_HH_MM_SS);
+    }
+
+    public static LocalDate parseLocalDate(String time) {
+        return LocalDate.parse(time, YYYY_MM_DD_HH_MM_SS);
+    }
+
+
+    public static LocalDate parseDate(long time) {
+        return LocalDate.from(parseDateTime(time));
+    }
+
+    public static LocalDate parseDate(String time) {
+        return LocalDate.parse(time, YYYY_MM_DD);
+    }
+
+    public static String format(LocalDate date) {
+        return date.format(YYYY_MM_DD);
+    }
+
+    public static String format(LocalDateTime dateTime) {
+        return dateTime.format(YYYY_MM_DD_HH_MM_SS);
+    }
+
+    public static long millis(LocalDate date) {
+        return millis(date.atStartOfDay());
+    }
+
+    public static long millis(LocalDateTime dateTime) {
+        return dateTime.atZone(ZoneId.systemDefault()).toInstant().toEpochMilli();
+    }
+
+    public static String getDateString(Date date, String pattern) {
+        Instant instant = date.toInstant();
+        ZoneId zoneId = ZoneId.systemDefault();
+        LocalDateTime localDateTime = instant.atZone(zoneId).toLocalDateTime();
+        return localDateTime.format(DateTimeFormatter.ofPattern(pattern));
+    }
+
+    public static long getBetweenDays(Date startDate, Date endDate) {
+        return betweenDate(startDate, endDate).toDays();
+    }
+
+    public static long getBetweenHours(Date startDate, Date endDate) {
+        return betweenDate(startDate, endDate).toHours();
+    }
+
+    public static long getBetweenMinutes(Date startDate, Date endDate) {
+        return betweenDate(startDate, endDate).toMinutes();
+    }
+
+    private static Duration betweenDate(Date startDate, Date endDate) {
+        ZoneId zoneId = ZoneId.systemDefault();
+        Instant startDateInstant = startDate.toInstant();
+        LocalDateTime startDateLocalDateTime = startDateInstant.atZone(zoneId).toLocalDateTime();
+        Instant endDateInstant = endDate.toInstant();
+        LocalDateTime endDateLocalDateTime = endDateInstant.atZone(zoneId).toLocalDateTime();
+        return Duration.between(startDateLocalDateTime, endDateLocalDateTime);
+    }
+
+    /**
+     * 自定义 字符串转date
+     *
+     * @param dateStr
+     * @param pattern
+     * @return
+     * @throws ParseException
+     */
+    public static Date strToDate(String dateStr, String pattern) throws ParseException {
+        SimpleDateFormat dateFormat = new SimpleDateFormat();
+        if (pattern != null && !pattern.isEmpty()) {
+            dateFormat.applyPattern(pattern);
+        }
+
+        Date date = dateFormat.parse(dateStr);
+        return date;
+    }
+
+    public static void main(String[] args) throws ParseException {
+//        String lastTwoMonthDate = getLastTwoMonthDateStart();
+//        String lastTwoMonthDateEnd = getLastTwoMonthDateEnd();
+//        String s = "2023-12-12";
+//        Date date = DateUtil.stringPatchingStartToDateTime(s);
+//        Date date1 = DateUtil.stringPatchingEndToDateTime(s);
+//        System.out.println(date);
+//        System.out.println(date1);
+//        String lastWeekDateStart = getLastWeekDateStart();
+//        String lastWeekDateEnd = getLastWeekDateEnd();
+//        System.out.println(lastWeekDateStart);
+//        System.out.println(lastWeekDateEnd);
+//        String beforeWeekDate = DateUtil.getBeforeWeekDate(6) + " 00:00:00";
+//        String beforeWeekDate1 = DateUtil.getBeforeWeekDate(7) + " 23:59:59";
+//        ;
+//        System.out.println(beforeWeekDate);
+//        System.out.println(beforeWeekDate1);
+//        DateTime dateTime = lastMonth();
+//        System.out.println(dateTime);
+
+//        // 获取当前日期
+//        LocalDate currentDate = LocalDate.now();
+//        // 计算一年前的日期
+//        LocalDate oneYearAgo = currentDate.minusYears(1);
+//        LocalDateTime localDateTime = oneYearAgo.atStartOfDay();
+//        System.out.println(localDateTime);
+//        LocalDateTime beforeWeekDateEnd = getBeforeWeekDateEnd(6);
+//        System.out.println(beforeWeekDateEnd);
+//        String format = LocalDateTime.now().format(DateTimeFormatter.ofPattern(DEFAULT_DATE_PATTERN));
+//        System.out.println(format);
+//        DateTimeFormatter formatter = DateTimeFormatter.ofPattern(DEFAULT_DATE_PATTERN);
+//        LocalDateTime parse = LocalDateTime.parse(format, formatter);
+//        System.out.println(parse);
+//        LocalDateTime lastWeekDateStart = getLastWeekDateStart(6);
+//        System.out.println(lastWeekDateStart);
+//        LocalDateTime lastWeekDateEnd = getLastWeekDateEnd(6);
+//        System.out.println(lastWeekDateEnd);
+
+
+//        //本月
+//        //开始时间
+//
+//        String weekDateStart = getBeforeMonthDateAndDaysStartToString(1, -1);
+//        System.out.println(weekDateStart);
+//        //结束时间
+//        String weekDateEnd = getLastWeekDateEndToString(0);
+//        System.out.println(weekDateEnd);
+//        //环比本月
+//        //开始时间
+//        String beforeMonthDateAndDaysEndToString = getBeforeMonthDateAndDaysStartToString(2, -1);
+//        System.out.println(beforeMonthDateAndDaysEndToString);
+//        //结束时间
+//        String beforeMonthDateAndDaysEndToString1 = getBeforeMonthDateAndDaysEndToString(1, 0);
+//        System.out.println(beforeMonthDateAndDaysEndToString1);
+        String SS = cn.hutool.core.date.DateUtil.format(LocalDateTime.now(), "yyyy-MM-dd") + " 00:00:00";
+        //月
+        //开始时间
+        String monthDateStart = DateUtil.getBeforeMonthDateAndDaysStartToString(LocalDateTime.now(), 1, -1);
+        //结束时间
+        String monthDateEnd = DateUtil.getLastWeekDateEndToString(0);
+        //环比上月
+        //开始时间
+        String lastMonthDateStart = DateUtil.getBeforeMonthDateAndDaysStartToString(LocalDateTime.now(), 2, -1);
+        //结束时间
+        String lastMonthDateEnd = DateUtil.getBeforeMonthDateAndDaysEndToString(LocalDateTime.now(), 1, 0);
+
+    }
+
+    public static int getCurrentMonthDays() {
+        Calendar calendar = Calendar.getInstance();
+        calendar.set(5, 1);
+        calendar.roll(5, -1);
+        int days = calendar.get(5);
+        return days;
+    }
+
+    public static int getMonthDays(int year, int month) {
+        Calendar calendar = Calendar.getInstance();
+        calendar.set(1, year);
+        calendar.set(2, month - 1);
+        calendar.set(5, 1);
+        calendar.roll(5, -1);
+        int days = calendar.get(5);
+        return days;
+    }
+
+    public static Date subtractionOneDay(Date date) {
+        Calendar calendar = Calendar.getInstance();
+        calendar.setTime(date);
+        calendar.add(5, -1);
+        Date startDate = calendar.getTime();
+        return startDate;
+    }
+
+    public static Date getDay(int offset, Date date) {
+        Calendar calendar = Calendar.getInstance();
+        calendar.setTime(date);
+        calendar.add(5, offset);
+        return calendar.getTime();
+    }
+
+    public static Date getDelay(int offset, Date date) {
+        Calendar calendar = Calendar.getInstance();
+        calendar.setTime(date);
+        calendar.add(1, offset);
+        return calendar.getTime();
+    }
+
+    public static Date offsetDay(Date date, int offset) {
+        Calendar calendar = new GregorianCalendar();
+        calendar.setTime(date);
+        calendar.add(Calendar.DATE, offset);
+        return calendar.getTime();
+    }
+
+    public static String getWeekOfDate(Date date, Lanagues language) {
+        String name = "";
+        Calendar calendar = Calendar.getInstance();
+        calendar.setTime(date);
+        int weekIndex = calendar.get(7) - 1;
+        if (weekIndex < 0) {
+            weekIndex = 0;
+        }
+
+        switch (language) {
+            case CHINESE:
+                name = Week.getName(weekIndex);
+                break;
+            case ENGLISH:
+                name = Week.getEnName(weekIndex);
+        }
+
+        return name;
+    }
+
+    public static Date LocalDateTimeToDate(LocalDateTime localDateTime) {
+        return Date.from(localDateTime.atZone(ZoneId.systemDefault()).toInstant());
+    }
+
+    public static enum Week {
+        SUNDAY("星期日", "Sunday", 0),
+        MONDAY("星期一", "Monday", 1),
+        TUESDAY("星期二", "Tuesday", 2),
+        WEDNESDAY("星期三", "Sunday", 3),
+        THURSDAY("星期四", "Thursday", 4),
+        FRIDAY("星期五", "Friday ", 5),
+        SATURDAY("星期六", "Saturday", 6);
+
+        private String name;
+        private String enName;
+        private int index;
+
+        public static String getName(int index) {
+            String name = null;
+            Week[] var2 = values();
+            int var3 = var2.length;
+
+            for (int var4 = 0; var4 < var3; ++var4) {
+                Week week = var2[var4];
+                if (week.getIndex() == index) {
+                    name = week.getName();
+                }
+            }
+
+            return name;
+        }
+
+        public static String getEnName(int index) {
+            String name = null;
+            Week[] var2 = values();
+            int var3 = var2.length;
+
+            for (int var4 = 0; var4 < var3; ++var4) {
+                Week week = var2[var4];
+                if (week.getIndex() == index) {
+                    name = week.getEnName();
+                }
+            }
+
+            return name;
+        }
+
+        public String getName() {
+            return this.name;
+        }
+
+        public void setName(String name) {
+            this.name = name;
+        }
+
+        public String getEnName() {
+            return this.enName;
+        }
+
+        public void setEnName(String enName) {
+            this.enName = enName;
+        }
+
+        public int getIndex() {
+            return this.index;
+        }
+
+        public void setIndex(int index) {
+            this.index = index;
+        }
+
+        private Week(String name, String enName, int index) {
+            this.name = name;
+            this.enName = enName;
+            this.index = index;
+        }
+
+        @Override
+        public String toString() {
+            return "Week [name=" + this.name + ", enName=" + this.enName + ", index=" + this.index + "]";
+        }
+    }
+
+    public static enum Lanagues {
+        CHINESE,
+        ENGLISH;
+
+        private Lanagues() {
+        }
+    }
+
+    /**
+     * 当前时间的前一个星期
+     *
+     * @return
+     */
+    public static String getLastWeekDate() {
+        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+        Calendar c = Calendar.getInstance();
+        c.add(Calendar.DAY_OF_MONTH, -6);
+        String start = format.format(c.getTime());
+        System.out.println(start);
+        return start;
+    }
+
+    /**
+     * 当前时间的前一个星期[传递6即为一周]
+     *
+     * @return 2023-09-12 00:00:00
+     */
+    public static LocalDateTime getLastWeekDateStart(long amount) {
+//        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
+//        Calendar c = Calendar.getInstance();
+//        c.add(Calendar.DAY_OF_MONTH, -6);
+//        String start = format.format(c.getTime()) + " 00:00:00";
+//        DateTimeFormatter formatter = DateTimeFormatter.ofPattern(DEFAULT_DATE_PATTERN);
+//        LocalDateTime localDateTime = LocalDateTime.parse(start, formatter);
+        LocalDateTime localDateTime = LocalDate.now().minusDays(amount).atStartOfDay();
+        return localDateTime;
+    }
+
+    /**
+     * 当前时间的前一个星期[传递6即为一周]
+     *
+     * @return 2023-09-12 00:00:00
+     */
+    public static String getLastWeekDateStartToString(LocalDate localDate, long amount) {
+//        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
+//        Calendar c = Calendar.getInstance();
+//        c.add(Calendar.DAY_OF_MONTH, -6);
+//        String start = format.format(c.getTime()) + " 00:00:00";
+//        DateTimeFormatter formatter = DateTimeFormatter.ofPattern(DEFAULT_DATE_PATTERN);
+//        LocalDateTime localDateTime = LocalDateTime.parse(start, formatter);
+        LocalDateTime localDateTime = localDate.minusDays(amount).atStartOfDay();
+        String format = localDateTime.format(YYYY_MM_DD_HH_MM_SS);
+        return format;
+    }
+
+
+    /**
+     * 当前时间的前一个星期 [传递6即为一周]
+     *
+     * @return 2023-09-12 23:59:59
+     */
+    public static LocalDateTime getLastWeekDateEnd(int amount) {
+        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
+        Calendar c = Calendar.getInstance();
+        c.add(Calendar.DAY_OF_MONTH, -amount);
+        String start = format.format(c.getTime()) + " 23:59:59";
+        DateTimeFormatter formatter = DateTimeFormatter.ofPattern(DEFAULT_DATE_PATTERN);
+        LocalDateTime parse = LocalDateTime.parse(start, formatter);
+        return parse;
+    }
+
+    /**
+     * 当前时间的前一个星期 [传递6即为一周]
+     *
+     * @return 2023-09-12 23:59:59
+     */
+    public static String getLastWeekDateEndToString(int amount) {
+        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
+        Calendar c = Calendar.getInstance();
+        c.add(Calendar.DAY_OF_MONTH, -amount);
+        String start = format.format(c.getTime()) + " 23:59:59";
+        return start;
+    }
+
+    /**
+     * 当前时间的前一个星期
+     *
+     * @return
+     */
+    public static String getLastDateStart(Integer type) {
+        Assert.notNull(type, "获取上周/月结束时间,日期类型参数缺失");
+        int days = Objects.equals(type, 1) ? 6 : 29;
+        String start = LocalDate.now().atStartOfDay().minusDays(days).format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
+        return start;
+    }
+
+
+    /**
+     * 获取当前日期之前的时间
+     *
+     * @param amount 往前推多久时间[天为单位]
+     * @return
+     */
+    public static String getBeforeWeekDate(int amount) {
+        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
+        Calendar c = Calendar.getInstance();
+        c.add(Calendar.DAY_OF_MONTH, -amount);
+        String start = format.format(c.getTime());
+        return start;
+    }
+
+    /**
+     * 获取当前日期之前的时间
+     *
+     * @param amount 往前推多久时间[天为单位]
+     * @return
+     */
+    public static String getBeforeWeekDateStart(int amount) {
+        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
+        Calendar c = Calendar.getInstance();
+        c.add(Calendar.DAY_OF_MONTH, -amount);
+        String start = format.format(c.getTime()) + " 00:00:00";
+        return start;
+    }
+
+    /**
+     * 获取当前日期之前的时间
+     *
+     * @param amount 往前推多久时间[天为单位]
+     * @return
+     */
+    public static LocalDateTime getBeforeWeekDateEnd(int amount) {
+        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
+        Calendar c = Calendar.getInstance();
+        c.add(Calendar.DAY_OF_MONTH, -amount);
+        String start = format.format(c.getTime()) + " 23:59:59";
+        LocalDateTime parse = LocalDateTime.parse(start);
+        return parse;
+    }
+
+
+    /**
+     * 当天日期前一个月
+     *
+     * @return
+     */
+    public static String getLastMonthDate() {
+        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+        Calendar c = Calendar.getInstance();
+        c.add(Calendar.MONTH, -1);
+        String start = format.format(c.getTime());
+        System.out.println(start);
+        return start;
+    }
+
+
+    /**
+     * 当天日期前一个月
+     *
+     * @return 2023-09-06 00:00:00
+     */
+    public static String getLastMonthDateStart() {
+        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
+        Calendar c = Calendar.getInstance();
+        c.add(Calendar.MONTH, -1);
+        String start = format.format(c.getTime()) + " 00:00:00";
+        System.out.println(start);
+        return start;
+    }
+
+    /**
+     * 当天日期前一个月
+     *
+     * @return 2023-09-06 23:59:59
+     */
+    public static String getLastMonthDateEnd() {
+        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
+        Calendar c = Calendar.getInstance();
+        c.add(Calendar.MONTH, -1);
+        String start = format.format(c.getTime()) + " 23:59:59";
+        return start;
+    }
+
+
+    /**
+     * 获取当前日期之前的时间
+     *
+     * @param amount 往前推多久时间[月为单位]
+     * @return
+     */
+    public static String getBeforeMonthDate(int amount) {
+        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
+        Calendar c = Calendar.getInstance();
+        c.add(Calendar.MONTH, -amount);
+        String start = format.format(c.getTime());
+        return start;
+    }
+
+    /**
+     * 获取当前日期之前的时间
+     *
+     * @param amount 往前推多久时间[月为单位]
+     * @return 2023-09-13 00:00:00
+     */
+    public static LocalDateTime getBeforeMonthDateStart(int amount) {
+        LocalDateTime localDateTime = LocalDateTime.now().minusMonths(amount);
+        String start = localDateTime.format(DateTimeFormatter.ofPattern(DEF_DATE_FORMAT)) + " 00:00:00";
+        DateTimeFormatter formatter = DateTimeFormatter.ofPattern(DEFAULT_DATE_PATTERN);
+        LocalDateTime returnLocalDateTime = LocalDateTime.parse(start, formatter);
+        return returnLocalDateTime;
+    }
+
+    /**
+     * 获取当前日期之前的时间
+     *
+     * @param amount 往前推多久时间[月为单位]
+     * @return 2023-09-13 00:00:00
+     */
+    public static LocalDateTime getBeforeMonthDateAndDaysStart(int amount, long days) {
+        LocalDateTime localDateTime = LocalDateTime.now().minusMonths(amount).minusDays(days);
+        String start = localDateTime.format(DateTimeFormatter.ofPattern(DEF_DATE_FORMAT)) + " 00:00:00";
+        DateTimeFormatter formatter = DateTimeFormatter.ofPattern(DEFAULT_DATE_PATTERN);
+        LocalDateTime returnLocalDateTime = LocalDateTime.parse(start, formatter);
+        return returnLocalDateTime;
+    }
+
+    /**
+     * 获取当前日期之前的时间
+     *
+     * @param amount 往前推多久时间[月为单位]
+     * @return 2023-09-13 00:00:00
+     */
+    public static String getBeforeMonthDateStartToString(int amount) {
+        LocalDateTime localDateTime = LocalDateTime.now().minusMonths(amount);
+        String start = localDateTime.format(DateTimeFormatter.ofPattern(DEF_DATE_FORMAT)) + " 00:00:00";
+        return start;
+    }
+
+    /**
+     * 获取当前日期之前的时间
+     *
+     * @param amount 往前推多久时间[月为单位]
+     * @return 2023-09-13 00:00:00
+     */
+    public static String getBeforeMonthDateAndDaysStartToString(LocalDateTime localDateTime, int amount, long days) {
+        localDateTime = localDateTime.minusMonths(amount).minusDays(days);
+        String start = localDateTime.format(DateTimeFormatter.ofPattern(DEF_DATE_FORMAT)) + " 00:00:00";
+        return start;
+    }
+
+    /**
+     * 获取当前日期之前的时间
+     *
+     * @param amount 往前推多久时间[月为单位]
+     * @return 2023-09-13 23:59:59
+     */
+    public static LocalDateTime getBeforeMonthDateEnd(int amount) {
+        LocalDateTime localDateTime = LocalDateTime.now().minusMonths(amount);
+        String start = localDateTime.format(DateTimeFormatter.ofPattern(DEF_DATE_FORMAT)) + " 23:59:59";
+        DateTimeFormatter formatter = DateTimeFormatter.ofPattern(DEFAULT_DATE_PATTERN);
+        LocalDateTime returnLocalDateTime = LocalDateTime.parse(start, formatter);
+        return returnLocalDateTime;
+    }
+
+
+    /**
+     * 获取当前日期之前的时间
+     *
+     * @param amount 往前推多久时间[月为单位]
+     * @param days   减去几天
+     * @return 2023-09-13 23:59:59
+     */
+    public static String getBeforeMonthDateAndDaysEndToString(LocalDateTime localDateTime, int amount, long days) {
+        localDateTime = localDateTime.minusMonths(amount).minusDays(days);
+        String start = localDateTime.format(DateTimeFormatter.ofPattern(DEF_DATE_FORMAT)) + " 23:59:59";
+        return start;
+    }
+
+    /**
+     * 获取当前日期之前的时间
+     *
+     * @param amount 往前推多久时间[月为单位]
+     * @param days   减去几天
+     * @return 2023-09-13 23:59:59
+     */
+    public static LocalDateTime getBeforeMonthDateAndDaysEndToLocalDateTime(int amount, long days) {
+        LocalDateTime localDateTime = LocalDateTime.now().minusMonths(amount).minusDays(days);
+        String start = localDateTime.format(DateTimeFormatter.ofPattern(DEF_DATE_FORMAT)) + " 23:59:59";
+        DateTimeFormatter formatter = DateTimeFormatter.ofPattern(DEFAULT_DATE_PATTERN);
+        LocalDateTime returnLocalDateTime = LocalDateTime.parse(start, formatter);
+        return returnLocalDateTime;
+    }
+
+
+    /**
+     * 当天日期前两个月
+     *
+     * @return 2023-09-13 00:00:00
+     */
+    public static String getLastTwoMonthDateStart() {
+        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+        Calendar c = Calendar.getInstance();
+        c.setTime(strDateTimeToDateTime(getLastMonthDateStart()));
+        c.add(Calendar.MONTH, -1);
+        String start = format.format(c.getTime());
+        return start;
+    }
+
+    /**
+     * 当天日期前两个月
+     *
+     * @return 2023-09-13 23:59:59
+     */
+    public static String getLastTwoMonthDateEnd() {
+        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+        Calendar c = Calendar.getInstance();
+        c.setTime(strDateTimeToDateTime(getLastMonthDateEnd()));
+        c.add(Calendar.MONTH, -1);
+        String start = format.format(c.getTime());
+        return start;
+    }
+
+    /**
+     * 当前时间的前一年开始时间
+     *
+     * @return
+     */
+    public static String getLastYearDate() {
+        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+        Calendar c = Calendar.getInstance();
+        c.add(Calendar.YEAR, -1);
+        String start = format.format(c.getTime());
+        System.out.println(start);
+        return start;
+    }
+
+    /**
+     * 当天时间(含当天)往前推日期
+     * amount 传递29时,即固定往前推送30天
+     *
+     * @param dateTime 2023-07-17
+     * @return 2023-06-18
+     * @throws ParseException
+     */
+    public static String getThirtyDaysDate(String dateTime, int amount) throws ParseException {
+        //获取当前日期
+        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
+        //Date today = new Date();
+        Date parse = sdf.parse(dateTime);
+        //当前日期
+        String endDate = sdf.format(parse);
+        //获取三十天前日期
+        Calendar theCa = Calendar.getInstance();
+        theCa.setTime(parse);
+        //最后一个数字30可改,30天的意思
+        theCa.add(Calendar.DATE, -amount);
+        Date start = theCa.getTime();
+        //三十天之前日期
+        String startDate = sdf.format(start);
+        System.out.println(endDate);
+        System.out.println(startDate);
+        return startDate;
+    }
+
+    /**
+     * 计算两个Date之间的时长(毫秒)
+     */
+    public static Long getDifferenceInMillis(Date start, Date end) {
+        if (start == null || end == null) {
+            return null;
+        }
+        return Math.abs(end.getTime() - start.getTime());
+    }
+
+    /**
+     * 计算两个Date之间的时长(秒)
+     */
+    public static long getDifferenceInSeconds(Date start, Date end) {
+        Duration duration = Duration.between(
+                start.toInstant(),
+                end.toInstant()
+        );
+        return Math.abs(duration.getSeconds());
+    }
+
+    /**
+     * 计算两个Date之间的时长(分钟)
+     */
+    public static long getDifferenceInMinutes(Date start, Date end) {
+        Duration duration = Duration.between(
+                start.toInstant(),
+                end.toInstant()
+        );
+        return Math.abs(duration.toMinutes());
+    }
+
+    /**
+     * 计算两个Date之间的时长(小时)
+     */
+    public static long getDifferenceInHours(Date start, Date end) {
+        Duration duration = Duration.between(
+                start.toInstant(),
+                end.toInstant()
+        );
+        return Math.abs(duration.toHours());
+    }
+
+    /**
+     * 计算两个Date之间的时长(天)
+     */
+    public static long getDifferenceInDays(Date start, Date end) {
+        Duration duration = Duration.between(
+                start.toInstant(),
+                end.toInstant()
+        );
+        return Math.abs(duration.toDays());
+    }
+
+}

+ 55 - 0
iot-platform-common/src/main/java/com/platform/utils/EasyExcelUtil.java

@@ -7,11 +7,19 @@ import com.alibaba.excel.write.metadata.style.WriteCellStyle;
 import com.alibaba.excel.write.metadata.style.WriteFont;
 import com.alibaba.excel.write.style.HorizontalCellStyleStrategy;
 import com.alibaba.excel.write.style.column.LongestMatchColumnWidthStyleStrategy;
+import com.alibaba.fastjson.JSONObject;
+import com.platform.result.HttpV1Result;
 import jakarta.servlet.http.HttpServletResponse;
+import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.collections4.CollectionUtils;
 import org.apache.poi.ss.usermodel.HorizontalAlignment;
+import org.springframework.util.Assert;
+
 import java.io.InputStream;
+import java.io.PrintWriter;
+import java.io.UnsupportedEncodingException;
 import java.net.URLEncoder;
+import java.time.LocalDateTime;
 import java.util.ArrayList;
 import java.util.List;
 
@@ -23,6 +31,8 @@ import java.util.List;
  */
 
 
+
+@Slf4j
 public class EasyExcelUtil {
 
     public static <T> List<T> importExcel(InputStream inputStream, Class<T> clazz) {
@@ -117,4 +127,49 @@ public class EasyExcelUtil {
                 .doWrite(new ArrayList<>()); // 写入空列表,只生成表头
     }
 
+
+
+    public static <T> void download(HttpServletResponse response, Class<T> clazz, List<T> data) {
+//        StaticComponentContainer.Modules.exportAllToAll();
+        Assert.notNull(clazz, "clazz can't be null");
+        Assert.isTrue(data != null && !data.isEmpty(), "data can't be empty");
+        try {
+            ExcelContext excelContext = clazz.getAnnotation(ExcelContext.class);
+            buildResponse(response, excelContext.fileName());
+            EasyExcel.write(response.getOutputStream(), clazz)
+                    .registerConverter(new LocalDateTimeConverter())
+                    .registerWriteHandler(new RowWriteHandlerImpl())
+                    .registerWriteHandler(new LongestMatchColumnWidthStyleStrategy())
+                    .autoCloseStream(Boolean.FALSE).sheet(excelContext.sheetName())
+                    .doWrite(data);
+        } catch (Exception e) {
+            buildResponse(response, e);
+        }
+    }
+
+
+    private static void buildResponse(HttpServletResponse response, String fileName) throws UnsupportedEncodingException {
+        fileName = URLEncoder.encode(fileName + "-" + DateUtil.localDateTimeToString(LocalDateTime.now()), "UTF-8").replaceAll("\\+", "%20");
+        response.setContentType("application/vnd.ms-excel");
+        response.setCharacterEncoding("UTF-8");
+        response.setHeader("Access-Control-Expose-Headers", "Content-disposition");
+        //下面 浏览器下载正常,但是postman下载文件名称乱码
+        response.setHeader("Content-disposition", "attachment;filename=" + fileName + ".xlsx");
+        //下面这是用postman测名称正常,换到浏览器会多了filename_=utf-8等字样。。)
+//        response.setHeader("Content-disposition", "attachment;filename=" + URLEncoder.encode(fileName, "UTF-8")+ ".xlsx" + ";filename*=utf-8''" + URLEncoder.encode(fileName, "UTF-8")+ ".xlsx");
+    }
+
+    private static void buildResponse(HttpServletResponse response, Exception e) {
+        StackTraceElement[] stackTrace = e.getStackTrace();
+        log.error("Failed to export data. -> {}", String.valueOf(stackTrace[0]) + stackTrace[1] + stackTrace[2], e);
+        //response.reset();
+        response.setContentType("application/json");
+        response.setCharacterEncoding("UTF-8");
+        try (PrintWriter writer = response.getWriter()) {
+            writer.println(JSONObject.toJSONString(HttpV1Result.error("导出数据失败, " + e.toString())));
+        } catch (Exception ignored) {
+        }
+    }
+
+
 }

+ 26 - 0
iot-platform-common/src/main/java/com/platform/utils/ExcelContext.java

@@ -0,0 +1,26 @@
+package com.platform.utils;
+
+import java.lang.annotation.*;
+
+/**
+ * @author lfdc
+ * @version v1
+ * @create 2020-11-28 15:37:35
+ * @copyright
+ */
+@Target({ElementType.TYPE})
+@Retention(RetentionPolicy.RUNTIME)
+@Documented
+public @interface ExcelContext {
+
+    String fileName() default "";
+
+    String sheetName();
+
+    @Target({ElementType.TYPE})
+    @Retention(RetentionPolicy.RUNTIME)
+    @Documented
+    public @interface Query {
+        boolean combine() default false;
+    }
+}

+ 30 - 0
iot-platform-common/src/main/java/com/platform/utils/LocalDateTimeConverter.java

@@ -0,0 +1,30 @@
+package com.platform.utils;
+
+import com.alibaba.excel.converters.Converter;
+import com.alibaba.excel.enums.CellDataTypeEnum;
+
+import java.time.LocalDateTime;
+
+/**
+ *
+ * 导出时的字段类型转换
+ * LocalDateTime to「yyyy-MM-dd HH:mm:ss」
+ *
+ * @author LengFaQiang
+ * @version v1
+ * @create 2020-09-24 11:07:29
+ * @copyright
+ */
+public class LocalDateTimeConverter implements Converter<LocalDateTime> {
+
+    @Override
+    public Class<LocalDateTime> supportJavaTypeKey() {
+        return LocalDateTime.class;
+    }
+
+    @Override
+    public CellDataTypeEnum supportExcelTypeKey() {
+        return CellDataTypeEnum.STRING;
+    }
+
+}

+ 40 - 0
iot-platform-common/src/main/java/com/platform/utils/LongStringConverter.java

@@ -0,0 +1,40 @@
+package com.platform.utils;
+
+import cn.hutool.core.convert.Convert;
+import com.alibaba.excel.converters.Converter;
+import com.alibaba.excel.enums.CellDataTypeEnum;
+import com.alibaba.excel.metadata.GlobalConfiguration;
+import com.alibaba.excel.metadata.data.ReadCellData;
+import com.alibaba.excel.metadata.data.WriteCellData;
+import com.alibaba.excel.metadata.property.ExcelContentProperty;
+import lombok.extern.slf4j.Slf4j;
+
+import java.util.Objects;
+
+
+@Slf4j
+public class LongStringConverter implements Converter<Long> {
+    @Override
+    public Class<Long> supportJavaTypeKey() {
+        return Long.class;
+    }
+
+    @Override
+    public CellDataTypeEnum supportExcelTypeKey() {
+        return CellDataTypeEnum.STRING;
+    }
+
+    @Override
+    public Long convertToJavaData(ReadCellData cellData, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) {
+        return Convert.toLong(cellData.getData());
+    }
+
+    @Override
+    public WriteCellData<String> convertToExcelData(Long value, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) {
+        if (Objects.nonNull(value)) {
+            String str = Convert.toStr(value);
+            return new WriteCellData<>(str);
+        }
+        return new WriteCellData<>("");
+    }
+}

+ 36 - 0
iot-platform-common/src/main/java/com/platform/utils/RowWriteHandlerImpl.java

@@ -0,0 +1,36 @@
+package com.platform.utils;
+
+//import com.alibaba.excel.metadata.CellData;
+
+import com.alibaba.excel.metadata.Head;
+import com.alibaba.excel.write.handler.CellWriteHandler;
+import com.alibaba.excel.write.metadata.holder.WriteSheetHolder;
+import com.alibaba.excel.write.metadata.holder.WriteTableHolder;
+import org.apache.poi.ss.usermodel.*;
+
+/**
+ * @author LengFaQiang
+ * @version 1.0.0
+ * @ClassName RowWriteHandlerImpl.java
+ * @Description 设置导出excel的单元格格式为文本
+ * @createTime 2022年012月021日 10:15:00
+ */
+public class RowWriteHandlerImpl implements CellWriteHandler {
+
+    CellStyle cellStyle;
+    @Override
+    public void beforeCellCreate(WriteSheetHolder writeSheetHolder, WriteTableHolder writeTableHolder, Row row, Head head, Integer integer, Integer integer1, Boolean aBoolean) {
+
+    }
+
+    @Override
+    public void afterCellCreate(WriteSheetHolder writeSheetHolder, WriteTableHolder writeTableHolder, Cell cell, Head head, Integer integer, Boolean aBoolean) {
+        Workbook workbook = writeSheetHolder.getSheet().getWorkbook();
+        if (cellStyle == null){
+            cellStyle = workbook.createCellStyle();
+        }
+        DataFormat dataFormat = workbook.createDataFormat();
+        cellStyle.setDataFormat(dataFormat.getFormat("@"));
+        cell.setCellStyle(cellStyle);
+    }
+}

+ 14 - 12
iot-platform-manager/src/main/java/com/platform/api/controller/KwsPrinterController.java

@@ -4,9 +4,11 @@ import com.platform.api.manager.KwsPrinterManageService;
 import com.platform.api.request.PrinterPageReqVo;
 import com.platform.api.request.PrinterSaveReqVo;
 import com.platform.api.request.PrinterStatusReqVo;
-import com.platform.result.HttpV1Result;
-import com.platform.result.HttpV1Status;
+import com.platform.api.response.PrinterDetailResVo;
+import com.platform.api.response.PrinterPageResVo;
+import com.platform.result.BaseResult;
 
+import com.platform.result.PageDataResult;
 import io.swagger.v3.oas.annotations.Operation;
 import io.swagger.v3.oas.annotations.tags.Tag;
 import lombok.RequiredArgsConstructor;
@@ -25,35 +27,35 @@ public class KwsPrinterController {
 
     @PostMapping("/page")
     @Operation(summary = "打印机分页查询")
-    public HttpV1Result page(@RequestBody PrinterPageReqVo reqVo) {
-        return HttpV1Result.ok(kwsPrinterManageService.page(reqVo));
+    public BaseResult<PageDataResult<PrinterPageResVo>> page(@RequestBody PrinterPageReqVo reqVo) {
+        return BaseResult.success(kwsPrinterManageService.page(reqVo));
     }
 
     @GetMapping("/detail")
     @Operation(summary = "打印机详情")
-    public HttpV1Result detail(@RequestParam Long id) {
-        return HttpV1Result.ok(kwsPrinterManageService.detail(id));
+    public BaseResult<PrinterDetailResVo> detail(@RequestParam Long id) {
+        return BaseResult.success(kwsPrinterManageService.detail(id));
     }
 
     @PostMapping("/add")
     @Operation(summary = "新增打印机")
-    public HttpV1Result add(@RequestBody PrinterSaveReqVo reqVo) {
+    public BaseResult<Void> add(@RequestBody PrinterSaveReqVo reqVo) {
         kwsPrinterManageService.add(reqVo);
-        return HttpV1Result.ok(HttpV1Status.MSG_003);
+        return BaseResult.success();
     }
 
     @PostMapping("/update")
     @Operation(summary = "编辑打印机")
-    public HttpV1Result update(@RequestBody PrinterSaveReqVo reqVo) {
+    public BaseResult<Void> update(@RequestBody PrinterSaveReqVo reqVo) {
         kwsPrinterManageService.update(reqVo);
-        return HttpV1Result.ok(HttpV1Status.MSG_005);
+        return BaseResult.success();
     }
 
     @PostMapping("/updateStatus")
     @Operation(summary = "启用停用打印机")
-    public HttpV1Result updateStatus(@RequestBody PrinterStatusReqVo reqVo) {
+    public BaseResult<Void> updateStatus(@RequestBody PrinterStatusReqVo reqVo) {
         kwsPrinterManageService.updateStatus(reqVo);
-        return HttpV1Result.ok(HttpV1Status.MSG_005);
+        return BaseResult.success();
     }
 
 //    @GetMapping("/enterpriseOptions")

+ 20 - 20
iot-platform-manager/src/main/java/com/platform/api/controller/KwsWeighbridgeController.java

@@ -3,10 +3,10 @@ package com.platform.api.controller;
 
 import com.platform.api.manager.KwsWeighbridgeManageService;
 import com.platform.api.request.*;
-import com.platform.result.HttpResult;
-import com.platform.result.HttpStatus;
-import com.platform.result.HttpV1Result;
-import com.platform.result.HttpV1Status;
+import com.platform.api.response.WeighbridgeDetailResVo;
+import com.platform.api.response.WeighbridgeDiffConfigResVo;
+import com.platform.api.response.WeighbridgePageResVo;
+import com.platform.result.*;
 import io.swagger.v3.oas.annotations.Operation;
 import io.swagger.v3.oas.annotations.tags.Tag;
 import lombok.RequiredArgsConstructor;
@@ -25,55 +25,55 @@ public class KwsWeighbridgeController {
 
     @PostMapping("/page")
     @Operation(summary = "地磅分页查询")
-    public HttpV1Result page(@RequestBody WeighbridgePageReqVo reqVo) {
-        return HttpV1Result.ok(kwsWeighbridgeManageService.page(reqVo));
+    public BaseResult<PageDataResult<WeighbridgePageResVo>> page(@RequestBody WeighbridgePageReqVo reqVo) {
+        return BaseResult.success(kwsWeighbridgeManageService.page(reqVo));
     }
 
     @GetMapping("/detail")
     @Operation(summary = "地磅详情")
-    public HttpV1Result detail(@RequestParam Long id) {
-        return HttpV1Result.ok(kwsWeighbridgeManageService.detail(id));
+    public BaseResult<WeighbridgeDetailResVo> detail(@RequestParam Long id) {
+        return BaseResult.success(kwsWeighbridgeManageService.detail(id));
     }
 
     @PostMapping("/add")
     @Operation(summary = "新增地磅")
-    public HttpV1Result add(@RequestBody WeighbridgeSaveReqVo reqVo) {
+    public BaseResult<Void> add(@RequestBody WeighbridgeSaveReqVo reqVo) {
         kwsWeighbridgeManageService.add(reqVo);
-        return HttpV1Result.ok(HttpV1Status.MSG_003);
+        return BaseResult.success();
     }
 
     @PostMapping("/update")
     @Operation(summary = "更新地磅")
-    public HttpV1Result update(@RequestBody WeighbridgeSaveReqVo reqVo) {
+    public BaseResult<Void> update(@RequestBody WeighbridgeSaveReqVo reqVo) {
         kwsWeighbridgeManageService.update(reqVo);
-        return HttpV1Result.ok(HttpV1Status.MSG_005);
+        return BaseResult.success();
     }
 
     @PostMapping("/updateStatus")
     @Operation(summary = "更新地磅状态,停用启用接口")
-    public HttpV1Result updateStatus(@RequestBody WeighbridgeStatusReqVo reqVo) {
+    public BaseResult<Void> updateStatus(@RequestBody WeighbridgeStatusReqVo reqVo) {
         kwsWeighbridgeManageService.updateStatus(reqVo);
-        return HttpV1Result.ok(HttpV1Status.MSG_005);
+        return BaseResult.success();
     }
 
     @PostMapping("/updateDiffConfig")
     @Operation(summary = "保存地磅差值配置")
-    public HttpV1Result updateDiffConfig(@RequestBody WeighbridgeDiffConfigReqVo reqVo) {
+    public BaseResult<Void> updateDiffConfig(@RequestBody WeighbridgeDiffConfigReqVo reqVo) {
         kwsWeighbridgeManageService.updateDiffConfig(reqVo);
-        return HttpV1Result.ok(HttpV1Status.MSG_005);
+        return BaseResult.success();
     }
 
     @GetMapping("/diffConfigDetail")
     @Operation(summary = "获取地磅差值配置详情")
-    public HttpV1Result diffConfigDetail(@RequestParam Long entId) {
-        return HttpV1Result.ok(kwsWeighbridgeManageService.diffConfigDetail(entId));
+    public BaseResult<WeighbridgeDiffConfigResVo> diffConfigDetail(@RequestParam Long entId) {
+        return BaseResult.success(kwsWeighbridgeManageService.diffConfigDetail(entId));
     }
 
     @PostMapping("/restart")
     @Operation(summary = "重启地磅")
-    public HttpV1Result restart(@RequestBody WeighbridgeRestartReqVo reqVo) {
+    public BaseResult<Void> restart(@RequestBody WeighbridgeRestartReqVo reqVo) {
         kwsWeighbridgeManageService.restart(reqVo);
-        return HttpV1Result.ok("重启命令已记录");
+        return BaseResult.success();
     }
 
 //    @GetMapping("/enterpriseOptions")

+ 79 - 0
iot-platform-manager/src/main/java/com/platform/api/controller/KwsWeighbridgeRecordController.java

@@ -0,0 +1,79 @@
+package com.platform.api.controller;
+
+import com.alibaba.fastjson.JSONObject;
+import com.platform.api.manager.WeighbridgeRecordManage;
+import com.platform.api.request.WeighbridgeRecordPageReqVo;
+import com.platform.api.response.WeighbridgeRecordExcel;
+import com.platform.api.response.WeighbridgeRecordResVo;
+import com.platform.result.BaseResult;
+import com.platform.result.HttpV1Result;
+
+import com.platform.result.PageDataResult;
+import com.platform.utils.EasyExcelUtil;
+import io.swagger.v3.oas.annotations.Operation;
+import io.swagger.v3.oas.annotations.tags.Tag;
+import jakarta.servlet.http.HttpServletResponse;
+import lombok.RequiredArgsConstructor;
+import org.apache.commons.lang3.StringUtils;
+import org.springframework.web.bind.annotation.*;
+
+import java.io.IOException;
+import java.math.BigDecimal;
+import java.util.List;
+
+/**
+ * 地磅记录控制器
+ */
+@RestController
+@RequestMapping("/kwsWeighbridgeRecord")
+@Tag(name = "地磅记录")
+@RequiredArgsConstructor
+public class KwsWeighbridgeRecordController {
+
+    private final WeighbridgeRecordManage weighbridgeRecordManage;
+
+    @PostMapping("/page")
+    @Operation(summary = "地磅记录分页查询")
+    public BaseResult<PageDataResult<WeighbridgeRecordResVo>> page(@RequestBody WeighbridgeRecordPageReqVo reqVo) {
+        return BaseResult.success(weighbridgeRecordManage.page(reqVo));
+    }
+
+    @PostMapping("/export")
+    @Operation(summary = "导出地磅记录")
+    public void export(@RequestBody WeighbridgeRecordPageReqVo reqVo, HttpServletResponse response) throws IOException {
+        List<WeighbridgeRecordExcel> data = weighbridgeRecordManage.exportList(reqVo);
+        if (data == null || data.isEmpty()) {
+            response.setContentType("application/json");
+            response.setCharacterEncoding("UTF-8");
+            response.getWriter().write(JSONObject.toJSONString(HttpV1Result.error("没有可导出的地磅记录")));
+            return;
+        }
+        EasyExcelUtil.download(response, WeighbridgeRecordExcel.class, data);
+    }
+
+
+
+
+
+
+
+    private String sanitizeText(String value) {
+        if (StringUtils.isBlank(value)) {
+            return "";
+        }
+        return value.trim()
+                .replace("\r", "")
+                .replace("\n", "");
+    }
+
+    private BigDecimal parseBigDecimal(String value) {
+        String cleanedValue = sanitizeText(value);
+        return StringUtils.isBlank(cleanedValue) ? null : new BigDecimal(cleanedValue);
+    }
+
+    private Long parseLong(String value) {
+        String cleanedValue = sanitizeText(value);
+        return StringUtils.isBlank(cleanedValue) ? null : Long.valueOf(cleanedValue);
+    }
+
+}

+ 3 - 2
iot-platform-manager/src/main/java/com/platform/api/manager/KwsPrinterManageService.java

@@ -12,6 +12,7 @@ import com.platform.api.response.PrinterPageResVo;
 import com.platform.entity.KwsPrinter;
 import com.platform.exception.IotException;
 import com.platform.result.HttpV1Status;
+import com.platform.result.PageDataResult;
 import com.platform.result.PageResult;
 import com.platform.service.KwsPrinterRepository;
 import lombok.RequiredArgsConstructor;
@@ -41,7 +42,7 @@ public class KwsPrinterManageService {
      * @param reqVo 分页查询请求参数,包含页码、页大小、打印机名称模糊匹配、企业名称模糊匹配
      * @return 分页结果集
      */
-    public PageResult page(PrinterPageReqVo reqVo) {
+    public PageDataResult<PrinterPageResVo> page(PrinterPageReqVo reqVo) {
         log.info("分页查询打印机列表,参数:{}", JSON.toJSONString(reqVo));
         // 根据企业名称解析出有权限查看的企业ID集合
       //  Set<Long> entIds = resolveQueryEntIds(reqVo.getEnterpriseName());
@@ -53,7 +54,7 @@ public class KwsPrinterManageService {
         IPage<KwsPrinter> page = kwsPrinterRepository.pageQuery(reqVo.getPageNum(), reqVo.getPageSize(),
                 reqVo.getPrinterName(), reqVo.getEntId());
         // 构建返回结果,填充企业名称等额外信息
-        return PageResult.of(page, buildPageRes(page.getRecords()));
+        return PageDataResult.of(page, buildPageRes(page.getRecords()));
     }
 
     /**

+ 4 - 3
iot-platform-manager/src/main/java/com/platform/api/manager/KwsWeighbridgeManageService.java

@@ -15,6 +15,7 @@ import com.platform.entity.KwsWeighbridge;
 import com.platform.entity.KwsWeighbridgeDiffConfig;
 import com.platform.exception.IotException;
 import com.platform.result.HttpV1Status;
+import com.platform.result.PageDataResult;
 import com.platform.result.PageResult;
 import com.platform.service.*;
 import lombok.RequiredArgsConstructor;
@@ -67,19 +68,19 @@ public class KwsWeighbridgeManageService {
      * @param reqVo 分页查询请求参数,包含页码、每页大小、地磅名称、企业名称等
      * @return 分页结果,包含地磅列表及总数
      */
-    public PageResult page(WeighbridgePageReqVo reqVo) {
+    public PageDataResult<WeighbridgePageResVo> page(WeighbridgePageReqVo reqVo) {
         log.info("分页查询地磅列表, reqVo: {}", JSON.toJSONString(reqVo));
         // 根据企业名称解析有权限访问的企业ID集合
        // Set<Long> entIds = resolveQueryEntIds(reqVo.getEnterpriseName());
         if (Objects.isNull(reqVo.getEntId())) {
             // 若无有效企业ID,直接返回空分页结果
-            return PageResult.build(reqVo.getPageNum(), reqVo.getPageSize(), 0L, Collections.emptyList());
+            return PageDataResult.empty(reqVo.getPageNum(), reqVo.getPageSize());
         }
         // 执行数据库分页查询
         IPage<KwsWeighbridge> page = kwsWeighbridgeRepository.pageQuery(reqVo.getPageNum(), reqVo.getPageSize(),
                 reqVo.getWeighbridgeName(), reqVo.getEntId());
         // 构建并返回响应结果
-        return PageResult.of(page, buildPageRes(page.getRecords()));
+        return PageDataResult.of(page, buildPageRes(page.getRecords()));
     }
 
     /**

+ 264 - 8
iot-platform-manager/src/main/java/com/platform/api/manager/WeighbridgeRecordManage.java

@@ -1,23 +1,28 @@
 package com.platform.api.manager;
 
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.platform.api.request.LicensePlateValidateRequest;
 import com.platform.api.request.WeighbridgePushRequest;
+import com.platform.api.request.WeighbridgeRecordPageReqVo;
+import com.platform.api.response.WeighbridgeRecordExcel;
+import com.platform.api.response.WeighbridgeRecordResVo;
+import com.platform.entity.KwsWeighbridge;
 import com.platform.entity.ValidateLicensePlate;
 import com.platform.entity.WeighbridgeRecord;
 import com.platform.enums.ErrorCodeEnum;
 import com.platform.enums.WeighbridgeEnum;
 import com.platform.exception.IotException;
 import com.platform.api.response.LicensePlateValidateResponse;
+import com.platform.result.PageDataResult;
 import com.platform.service.ValidateLicensePlateService;
+import com.platform.service.KwsWeighbridgeRepository;
 import com.platform.service.WeighbridgeRecordService;
-import com.platform.utils.FileUtils;
 import jakarta.annotation.Resource;
 import lombok.RequiredArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang3.StringUtils;
-import org.springframework.beans.factory.annotation.Qualifier;
-import org.springframework.core.task.TaskExecutor;
-import org.springframework.scheduling.annotation.Async;
 import org.springframework.stereotype.Service;
 import org.springframework.web.multipart.MultipartFile;
 
@@ -26,7 +31,6 @@ import java.time.Instant;
 import java.time.LocalDateTime;
 import java.time.ZoneId;
 import java.util.*;
-import java.util.concurrent.CompletableFuture;
 import java.util.stream.Collectors;
 
 /**
@@ -40,10 +44,10 @@ public class WeighbridgeRecordManage {
 
     private final WeighbridgeRecordService weighbridgeRecordService;
 
-    private final ValidateLicensePlateService validateLicensePlateService;
+    private final KwsWeighbridgeRepository kwsWeighbridgeRepository;
 
-    @Qualifier("taskExecutor")
-    private final TaskExecutor taskExecutor;
+    private final ValidateLicensePlateService validateLicensePlateService;
+    
 
     @Resource
     private UploadService uploadService;
@@ -332,4 +336,256 @@ public class WeighbridgeRecordManage {
         return response;
     }
 
+
+    /**
+     * 分页查询地磅记录列表
+     * <p>
+     * 该方法首先根据请求参数查询符合条件的地磅设备,获取有效地磅编码集合。
+     * 然后根据地磅编码、车牌号、重量范围、时间范围等条件分页查询地磅记录。
+     * 最后将查询结果与地磅设备信息关联,组装成响应对象返回。
+     * </p>
+     *
+     * @param reqVo 分页查询请求参数,包含地磅信息、车牌号、重量范围、时间范围等过滤条件
+     * @return 分页后的地磅记录响应结果
+     */
+    public PageDataResult<WeighbridgeRecordResVo> page(WeighbridgeRecordPageReqVo reqVo) {
+        log.info("开始分页查询地磅记录,请求参数: {}", reqVo);
+
+        // 参数兜底,防止空请求触发空指针
+        if (Objects.isNull(reqVo)) {
+            reqVo = new WeighbridgeRecordPageReqVo();
+            log.debug("请求参数为空,使用默认空参数对象");
+        }
+
+        // 处理分页参数,设置默认值
+        int pageNum = reqVo.getPageNum() <= 0 ? 1 : reqVo.getPageNum();
+        int pageSize = reqVo.getPageSize() <= 0 ? 10 : reqVo.getPageSize();
+        log.debug("分页参数 - 页码: {}, 每页大小: {}", pageNum, pageSize);
+
+        // 第一步:查询符合条件的地磅设备
+        // 根据ID、名称、唯一编码等条件筛选未删除的地磅设备
+        log.debug("查询符合条件的地磅设备,地磅ID: {}, 地磅名称: {}, 唯一编码: {}", 
+                reqVo.getWeighbridgeId(), reqVo.getWeighbridgeName(), reqVo.getUniqueCode());
+        
+        List<KwsWeighbridge> weighbridgeList = kwsWeighbridgeRepository.list(Wrappers.<KwsWeighbridge>lambdaQuery()
+                .eq(KwsWeighbridge::getDelFlag, 0)
+                .eq(Objects.nonNull(reqVo.getWeighbridgeId()), KwsWeighbridge::getId, reqVo.getWeighbridgeId())
+                .like(StringUtils.isNotBlank(reqVo.getWeighbridgeName()), KwsWeighbridge::getWeighbridgeName, reqVo.getWeighbridgeName())
+                .like(StringUtils.isNotBlank(reqVo.getUniqueCode()), KwsWeighbridge::getUniqueCode, reqVo.getUniqueCode()));
+
+        // 如果没有找到符合条件的地磅设备,直接返回空结果
+        if (weighbridgeList == null || weighbridgeList.isEmpty()) {
+            log.warn("未查询到符合条件的地磅设备,返回空列表");
+            return PageDataResult.empty(pageNum, pageSize);
+        }
+        log.info("查询到 {} 个符合条件的地磅设备", weighbridgeList.size());
+
+        // 第二步:提取有效地磅编码集合
+        // 过滤掉唯一编码为空的地磅,构建编码集合用于后续关联查询
+        Set<String> weighbridgeCodes = weighbridgeList.stream()
+                .map(KwsWeighbridge::getUniqueCode)
+                .filter(StringUtils::isNotBlank)
+                .collect(Collectors.toCollection(LinkedHashSet::new));
+
+        // 如果有效地磅编码为空,返回空结果
+        if (weighbridgeCodes.isEmpty()) {
+            log.warn("地磅设备唯一编码为空,返回空列表");
+            return PageDataResult.empty(pageNum, pageSize);
+        }
+        log.debug("有效地磅编码数量: {}, 编码列表: {}", weighbridgeCodes.size(), weighbridgeCodes);
+
+        // 第三步:构建地磅编码到地磅实体的映射
+        // 便于后续快速查找地磅详细信息(如企业名称、地磅名称等)
+        Map<String, KwsWeighbridge> weighbridgeCodeMap = weighbridgeList.stream()
+                .filter(item -> StringUtils.isNotBlank(item.getUniqueCode()))
+                .collect(Collectors.toMap(KwsWeighbridge::getUniqueCode, item -> item, (a, b) -> a));
+
+        // 第四步:分页查询地磅记录
+        // 根据地磅编码集合、车牌号、重量范围、创建时间范围、称重时间范围等条件进行查询
+        log.debug("开始分页查询地磅记录,车牌号: {}, 最小重量: {}, 最大重量: {}, 创建开始时间: {}, 创建结束时间: {}, 称重开始时间: {}, 称重结束时间: {}",
+                reqVo.getTruckNo(), reqVo.getMinWeight(), reqVo.getMaxWeight(),
+                reqVo.getCreateStartTime(), reqVo.getCreateEndTime(),
+                reqVo.getReceiveStartTime(), reqVo.getReceiveEndTime());
+
+        IPage<WeighbridgeRecord> recordPage = weighbridgeRecordService.page(new Page<>(pageNum, pageSize),
+                Wrappers.<WeighbridgeRecord>lambdaQuery()
+                        // 地磅编码必须在有效地磅编码集合中
+                        .in(WeighbridgeRecord::getWeighbridgeCode, weighbridgeCodes)
+                        // 车牌号模糊匹配
+                        .like(StringUtils.isNotBlank(reqVo.getTruckNo()), WeighbridgeRecord::getLicensePlate, reqVo.getTruckNo())
+                        // 重量范围过滤
+                        .ge(Objects.nonNull(reqVo.getMinWeight()), WeighbridgeRecord::getWeight, reqVo.getMinWeight())
+                        .le(Objects.nonNull(reqVo.getMaxWeight()), WeighbridgeRecord::getWeight, reqVo.getMaxWeight())
+                        // 创建时间范围过滤
+                        .ge(Objects.nonNull(reqVo.getCreateStartTime()), WeighbridgeRecord::getCreatedAt,
+                                reqVo.getCreateStartTime().toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime())
+                        .le(Objects.nonNull(reqVo.getCreateEndTime()), WeighbridgeRecord::getCreatedAt,
+                                reqVo.getCreateEndTime().toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime())
+                        // 称重时间范围过滤
+                        .ge(Objects.nonNull(reqVo.getReceiveStartTime()), WeighbridgeRecord::getWeighTime,
+                                reqVo.getReceiveStartTime().toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime())
+                        .le(Objects.nonNull(reqVo.getReceiveEndTime()), WeighbridgeRecord::getWeighTime,
+                                reqVo.getReceiveEndTime().toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime())
+                        // 按创建时间和ID降序排列,确保最新记录在前
+                        .orderByDesc(WeighbridgeRecord::getCreatedAt)
+                        .orderByDesc(WeighbridgeRecord::getId));
+
+        log.info("地磅记录分页查询完成,总记录数: {}, 当前页记录数: {}", recordPage.getTotal(), recordPage.getRecords().size());
+
+        // 第五步:组装响应数据
+        // 将地磅记录实体转换为响应VO,并关联地磅设备的详细信息
+        List<WeighbridgeRecordResVo> resList = recordPage.getRecords().stream().map(record -> {
+            // 从映射中获取对应的地磅设备信息
+            KwsWeighbridge weighbridge = weighbridgeCodeMap.get(record.getWeighbridgeCode());
+            
+            WeighbridgeRecordResVo resVo = new WeighbridgeRecordResVo();
+            // 设置记录ID
+            resVo.setId(record.getId());
+            // 设置地磅ID,若地磅信息不存在则为null
+            resVo.setWeighbridgeId(Objects.isNull(weighbridge) ? null : weighbridge.getId());
+            // 设置地磅名称:优先使用地磅表中的名称,若不存在则使用记录中保存的名称
+            resVo.setWeighbridgeName(Objects.isNull(weighbridge) ? record.getWeighbridgeName() : weighbridge.getWeighbridgeName());
+            // 设置地磅唯一编码
+            resVo.setUniqueCode(record.getWeighbridgeCode());
+            // 设置企业ID,若地磅信息不存在则为null
+            resVo.setEntId(Objects.isNull(weighbridge) ? null : weighbridge.getEntId());
+            // 设置企业名称:若地磅信息存在则使用地磅关联的企业名称,否则为空字符串
+            resVo.setEnterpriseName(Objects.isNull(weighbridge) ? "" : weighbridge.getEntName());
+            // 设置车牌号
+            resVo.setTruckNo(record.getLicensePlate());
+            // 设置重量
+            resVo.setWeight(record.getWeight());
+            // 设置创建时间(LocalDateTime转Date)
+            resVo.setCreateTime(toDate(record.getCreatedAt()));
+            // 设置称重时间(LocalDateTime转Date)
+            resVo.setReceiveTime(toDate(record.getWeighTime()));
+            
+            return resVo;
+        }).collect(Collectors.toList());
+
+        log.info("地磅记录分页查询响应数据组装完成,共 {} 条数据", resList.size());
+        
+        // 返回分页结果
+        return PageDataResult.of(recordPage, resList);
+    }
+
+    private Date toDate(LocalDateTime time) {
+        if (Objects.isNull(time)) {
+            return null;
+        }
+        return Date.from(time.atZone(ZoneId.systemDefault()).toInstant());
+    }
+
+    /**
+     * 导出地磅记录列表
+     * 该方法根据查询条件获取地磅记录,并转换为Excel导出对象
+     *
+     * @param reqVo 查询请求参数,包含地磅信息、车牌号、重量范围、时间范围等过滤条件
+     * @return 地磅记录Excel导出对象列表
+     */
+    public List<WeighbridgeRecordExcel> exportList(WeighbridgeRecordPageReqVo reqVo) {
+        log.info("开始导出地磅记录列表,请求参数: {}", reqVo);
+        
+        // 参数兜底,防止空请求触发空指针
+        if (Objects.isNull(reqVo)) {
+            reqVo = new WeighbridgeRecordPageReqVo();
+            log.debug("请求参数为空,使用默认空参数对象");
+        }
+        
+        // 先查询可用地磅,后续按 uniqueCode 与 weighbridge_records.weighbridge_code 关联
+        log.debug("查询符合条件的地磅设备,地磅ID: {}, 地磅名称: {}, 唯一编码: {}", 
+                reqVo.getWeighbridgeId(), reqVo.getWeighbridgeName(), reqVo.getUniqueCode());
+        
+        List<KwsWeighbridge> weighbridgeList = kwsWeighbridgeRepository.list(Wrappers.<KwsWeighbridge>lambdaQuery()
+                .eq(KwsWeighbridge::getDelFlag, 0)
+                .eq(Objects.nonNull(reqVo.getWeighbridgeId()), KwsWeighbridge::getId, reqVo.getWeighbridgeId())
+                .like(StringUtils.isNotBlank(reqVo.getWeighbridgeName()), KwsWeighbridge::getWeighbridgeName, reqVo.getWeighbridgeName())
+                .like(StringUtils.isNotBlank(reqVo.getUniqueCode()), KwsWeighbridge::getUniqueCode, reqVo.getUniqueCode()));
+        
+        if (weighbridgeList == null || weighbridgeList.isEmpty()) {
+            log.warn("未查询到符合条件的地磅设备,返回空列表");
+            return Collections.emptyList();
+        }
+        log.info("查询到 {} 个符合条件的地磅设备", weighbridgeList.size());
+        
+        // 提取有效地磅编码集合,用于后续关联查询
+        Set<String> weighbridgeCodes = weighbridgeList.stream()
+                .map(KwsWeighbridge::getUniqueCode)
+                .filter(StringUtils::isNotBlank)
+                .collect(Collectors.toCollection(LinkedHashSet::new));
+        
+        if (weighbridgeCodes.isEmpty()) {
+            log.warn("地磅设备唯一编码为空,返回空列表");
+            return Collections.emptyList();
+        }
+        log.debug("有效地磅编码数量: {}", weighbridgeCodes.size());
+        
+        // 构建地磅编码到地磅实体的映射,便于后续快速查找
+        Map<String, KwsWeighbridge> weighbridgeCodeMap = weighbridgeList.stream()
+                .filter(item -> StringUtils.isNotBlank(item.getUniqueCode()))
+                .collect(Collectors.toMap(KwsWeighbridge::getUniqueCode, item -> item, (a, b) -> a));
+
+        // 构建地磅记录查询条件
+        log.debug("开始查询地磅记录,车牌号: {}, 最小重量: {}, 最大重量: {}, 创建开始时间: {}, 创建结束时间: {}, 称重开始时间: {}, 称重结束时间: {}",
+                reqVo.getTruckNo(), reqVo.getMinWeight(), reqVo.getMaxWeight(),
+                reqVo.getCreateStartTime(), reqVo.getCreateEndTime(),
+                reqVo.getReceiveStartTime(), reqVo.getReceiveEndTime());
+        
+        List<WeighbridgeRecord> records = weighbridgeRecordService.list(Wrappers.<WeighbridgeRecord>lambdaQuery()
+                .in(WeighbridgeRecord::getWeighbridgeCode, weighbridgeCodes)
+                .like(StringUtils.isNotBlank(reqVo.getTruckNo()), WeighbridgeRecord::getLicensePlate, reqVo.getTruckNo())
+                .ge(Objects.nonNull(reqVo.getMinWeight()), WeighbridgeRecord::getWeight, reqVo.getMinWeight())
+                .le(Objects.nonNull(reqVo.getMaxWeight()), WeighbridgeRecord::getWeight, reqVo.getMaxWeight())
+                .ge(Objects.nonNull(reqVo.getCreateStartTime()), WeighbridgeRecord::getCreatedAt,
+                        reqVo.getCreateStartTime().toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime())
+                .le(Objects.nonNull(reqVo.getCreateEndTime()), WeighbridgeRecord::getCreatedAt,
+                        reqVo.getCreateEndTime().toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime())
+                .ge(Objects.nonNull(reqVo.getReceiveStartTime()), WeighbridgeRecord::getWeighTime,
+                        reqVo.getReceiveStartTime().toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime())
+                .le(Objects.nonNull(reqVo.getReceiveEndTime()), WeighbridgeRecord::getWeighTime,
+                        reqVo.getReceiveEndTime().toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime())
+                .orderByDesc(WeighbridgeRecord::getCreatedAt)
+                .orderByDesc(WeighbridgeRecord::getId));
+        
+        if (records == null || records.isEmpty()) {
+            log.info("未查询到符合条件的地磅记录,返回空列表");
+            return Collections.emptyList();
+        }
+        log.info("查询到 {} 条地磅记录", records.size());
+        
+        // 将地磅记录转换为Excel导出对象
+        List<WeighbridgeRecordExcel> result = records.stream().map(record -> {
+            KwsWeighbridge weighbridge = weighbridgeCodeMap.get(record.getWeighbridgeCode());
+            WeighbridgeRecordExcel excel = new WeighbridgeRecordExcel();
+            
+            // 设置地磅名称:优先使用地磅表中的名称,若不存在则使用记录中保存的名称
+            excel.setWeighbridgeName(Objects.isNull(weighbridge) ? record.getWeighbridgeName() : weighbridge.getWeighbridgeName());
+            // 设置地磅唯一编码
+            excel.setUniqueCode(record.getWeighbridgeCode());
+            // 设置企业名称:若地磅信息存在则使用地磅关联的企业名称,否则为空字符串
+            excel.setEnterpriseName(Objects.isNull(weighbridge) ? "" : weighbridge.getEntName());
+            // 设置车牌号
+            excel.setTruckNo(record.getLicensePlate());
+            // 设置重量
+            excel.setWeight(record.getWeight());
+            // 设置创建时间
+            excel.setCreateTime(toDate(record.getCreatedAt()));
+            // 设置称重时间
+            excel.setReceiveTime(toDate(record.getWeighTime()));
+            
+            return excel;
+        }).collect(Collectors.toList());
+        
+        log.info("地磅记录导出列表构建完成,共 {} 条数据", result.size());
+        return result;
+    }
+
+
+
+ 
+
+
+
+
+
 }

+ 88 - 0
iot-platform-manager/src/main/java/com/platform/api/request/WeighbridgeRecordPageReqVo.java

@@ -0,0 +1,88 @@
+package com.platform.api.request;
+
+import com.platform.request.PageRequest;
+import io.swagger.v3.oas.annotations.media.Schema;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+import org.springframework.format.annotation.DateTimeFormat;
+
+import java.io.Serial;
+import java.io.Serializable;
+import java.math.BigDecimal;
+import java.util.Date;
+
+/**
+ * 地磅记录分页查询请求
+ */
+@EqualsAndHashCode(callSuper = true)
+@Data
+@Schema(description = "地磅记录分页查询请求")
+public class WeighbridgeRecordPageReqVo extends PageRequest implements Serializable {
+
+    @Serial
+    private static final long serialVersionUID = 1L;
+
+    /**
+     * 地磅ID
+     */
+    @Schema(description = "地磅ID")
+    private Long weighbridgeId;
+
+    /**
+     * 地磅名称模糊关键字
+     */
+    @Schema(description = "地磅名称模糊关键字")
+    private String weighbridgeName;
+
+    /**
+     * 唯一编码模糊关键字
+     */
+    @Schema(description = "唯一编码模糊关键字")
+    private String uniqueCode;
+
+    /**
+     * 车牌号模糊关键字
+     */
+    @Schema(description = "车牌号模糊关键字")
+    private String truckNo;
+
+    /**
+     * 最小重量
+     */
+    @Schema(description = "最小重量")
+    private BigDecimal minWeight;
+
+    /**
+     * 最大重量
+     */
+    @Schema(description = "最大重量")
+    private BigDecimal maxWeight;
+
+    /**
+     * 创建开始时间
+     */
+    @Schema(description = "创建开始时间,格式 yyyy-MM-dd HH:mm:ss")
+    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
+    private Date createStartTime;
+
+    /**
+     * 创建结束时间
+     */
+    @Schema(description = "创建结束时间,格式 yyyy-MM-dd HH:mm:ss")
+    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
+    private Date createEndTime;
+
+    /**
+     * 接收开始时间
+     */
+    @Schema(description = "接收开始时间,格式 yyyy-MM-dd HH:mm:ss")
+    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
+    private Date receiveStartTime;
+
+    /**
+     * 接收结束时间
+     */
+    @Schema(description = "接收结束时间,格式 yyyy-MM-dd HH:mm:ss")
+    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
+    private Date receiveEndTime;
+}

+ 46 - 0
iot-platform-manager/src/main/java/com/platform/api/response/WeighbridgeRecordExcel.java

@@ -0,0 +1,46 @@
+package com.platform.api.response;
+
+import com.alibaba.excel.annotation.ExcelProperty;
+import com.fasterxml.jackson.annotation.JsonFormat;
+
+import com.platform.utils.ExcelContext;
+import lombok.Data;
+
+import java.io.Serial;
+import java.io.Serializable;
+import java.math.BigDecimal;
+import java.util.Date;
+
+/**
+ * 地磅记录导出模型
+ */
+@Data
+@ExcelContext(fileName = "地磅数据", sheetName = "地磅数据")
+public class WeighbridgeRecordExcel implements Serializable {
+
+    @Serial
+    private static final long serialVersionUID = 1L;
+
+    @ExcelProperty("地磅名称")
+    private String weighbridgeName;
+
+    @ExcelProperty("唯一编码")
+    private String uniqueCode;
+
+    @ExcelProperty("企业名称")
+    private String enterpriseName;
+
+    @ExcelProperty("车牌号")
+    private String truckNo;
+
+    @ExcelProperty("重量")
+    private BigDecimal weight;
+
+    @ExcelProperty("创建时间")
+    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
+    private Date createTime;
+
+    @ExcelProperty("接收时间")
+    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
+    private Date receiveTime;
+}

+ 83 - 0
iot-platform-manager/src/main/java/com/platform/api/response/WeighbridgeRecordResVo.java

@@ -0,0 +1,83 @@
+package com.platform.api.response;
+
+import com.fasterxml.jackson.annotation.JsonFormat;
+import io.swagger.v3.oas.annotations.media.Schema;
+import lombok.Data;
+
+import java.io.Serial;
+import java.io.Serializable;
+import java.math.BigDecimal;
+import java.util.Date;
+
+/**
+ * Weighbridge record response.
+ */
+@Data
+@Schema(description = "Weighbridge record response")
+public class WeighbridgeRecordResVo implements Serializable {
+
+    @Serial
+    private static final long serialVersionUID = 1L;
+
+    /**
+     * Primary key.
+     */
+    @Schema(description = "Primary key")
+    private Long id;
+
+    /**
+     * Weighbridge id.
+     */
+    @Schema(description = "Weighbridge id")
+    private Long weighbridgeId;
+
+    /**
+     * Weighbridge name.
+     */
+    @Schema(description = "Weighbridge name")
+    private String weighbridgeName;
+
+    /**
+     * Unique code.
+     */
+    @Schema(description = "Unique code")
+    private String uniqueCode;
+
+    /**
+     * Enterprise id.
+     */
+    @Schema(description = "Enterprise id")
+    private Long entId;
+
+    /**
+     * Enterprise name.
+     */
+    @Schema(description = "Enterprise name")
+    private String enterpriseName;
+
+    /**
+     * Truck number.
+     */
+    @Schema(description = "Truck number")
+    private String truckNo;
+
+    /**
+     * Weight.
+     */
+    @Schema(description = "Weight")
+    private BigDecimal weight;
+
+    /**
+     * Create time.
+     */
+    @Schema(description = "Create time")
+    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
+    private Date createTime;
+
+    /**
+     * Receive time.
+     */
+    @Schema(description = "Receive time")
+    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
+    private Date receiveTime;
+}