Browse Source
- 新增 DateTimeUtil 工具类,用于统一处理日期时间格式化- 移除 ShopCouponController 中的 PreAuthorize 注解 -重构 ShopOrderServiceImpl 中的支付成功后业务逻辑处理 - 添加处理支付成功后业务逻辑的 handlePaymentSuccess 方法 - 新增标记优惠券为已使用的 markCouponAsUsed 方法 - 新增累计商品销量的 updateGoodsSales 和 updateSingleGoodsSales 方法 - 更新测试账号配置和生产环境配置dev
5 changed files with 189 additions and 12 deletions
@ -0,0 +1,93 @@ |
|||
package com.gxwebsoft.common.core.utils; |
|||
|
|||
import java.time.LocalDateTime; |
|||
import java.time.format.DateTimeFormatter; |
|||
|
|||
/** |
|||
* 时间格式化工具类 |
|||
* 用于统一处理LocalDateTime的格式化 |
|||
* |
|||
* @author WebSoft |
|||
* @since 2025-08-23 |
|||
*/ |
|||
public class DateTimeUtil { |
|||
|
|||
/** |
|||
* 默认的日期时间格式 |
|||
*/ |
|||
public static final String DEFAULT_DATETIME_PATTERN = "yyyy-MM-dd HH:mm:ss"; |
|||
|
|||
/** |
|||
* 默认的日期格式 |
|||
*/ |
|||
public static final String DEFAULT_DATE_PATTERN = "yyyy-MM-dd"; |
|||
|
|||
/** |
|||
* 默认的时间格式 |
|||
*/ |
|||
public static final String DEFAULT_TIME_PATTERN = "HH:mm:ss"; |
|||
|
|||
/** |
|||
* 默认的日期时间格式化器 |
|||
*/ |
|||
private static final DateTimeFormatter DEFAULT_DATETIME_FORMATTER = |
|||
DateTimeFormatter.ofPattern(DEFAULT_DATETIME_PATTERN); |
|||
|
|||
/** |
|||
* 格式化LocalDateTime为字符串 |
|||
* 使用默认格式:yyyy-MM-dd HH:mm:ss |
|||
* |
|||
* @param dateTime 要格式化的时间 |
|||
* @return 格式化后的字符串,如果输入为null则返回null |
|||
*/ |
|||
public static String formatDateTime(LocalDateTime dateTime) { |
|||
if (dateTime == null) { |
|||
return null; |
|||
} |
|||
return dateTime.format(DEFAULT_DATETIME_FORMATTER); |
|||
} |
|||
|
|||
/** |
|||
* 格式化LocalDateTime为字符串 |
|||
* 使用指定格式 |
|||
* |
|||
* @param dateTime 要格式化的时间 |
|||
* @param pattern 格式模式 |
|||
* @return 格式化后的字符串,如果输入为null则返回null |
|||
*/ |
|||
public static String formatDateTime(LocalDateTime dateTime, String pattern) { |
|||
if (dateTime == null) { |
|||
return null; |
|||
} |
|||
return dateTime.format(DateTimeFormatter.ofPattern(pattern)); |
|||
} |
|||
|
|||
/** |
|||
* 解析字符串为LocalDateTime |
|||
* 使用默认格式:yyyy-MM-dd HH:mm:ss |
|||
* |
|||
* @param dateTimeStr 时间字符串 |
|||
* @return LocalDateTime对象,如果输入为null或空字符串则返回null |
|||
*/ |
|||
public static LocalDateTime parseDateTime(String dateTimeStr) { |
|||
if (dateTimeStr == null || dateTimeStr.trim().isEmpty()) { |
|||
return null; |
|||
} |
|||
return LocalDateTime.parse(dateTimeStr, DEFAULT_DATETIME_FORMATTER); |
|||
} |
|||
|
|||
/** |
|||
* 解析字符串为LocalDateTime |
|||
* 使用指定格式 |
|||
* |
|||
* @param dateTimeStr 时间字符串 |
|||
* @param pattern 格式模式 |
|||
* @return LocalDateTime对象,如果输入为null或空字符串则返回null |
|||
*/ |
|||
public static LocalDateTime parseDateTime(String dateTimeStr, String pattern) { |
|||
if (dateTimeStr == null || dateTimeStr.trim().isEmpty()) { |
|||
return null; |
|||
} |
|||
return LocalDateTime.parse(dateTimeStr, DateTimeFormatter.ofPattern(pattern)); |
|||
} |
|||
} |
Loading…
Reference in new issue