mirror of
https://gitee.com/dromara/RuoYi-Vue-Plus.git
synced 2026-09-18 01:25:28 +08:00
update 重构日期格式化方法,简化调用逻辑
This commit is contained in:
parent
487c413654
commit
52de92ea8c
@ -4,7 +4,6 @@ import cn.hutool.core.convert.Convert;
|
|||||||
import cn.hutool.core.date.BetweenFormatter;
|
import cn.hutool.core.date.BetweenFormatter;
|
||||||
import cn.hutool.core.date.DateUnit;
|
import cn.hutool.core.date.DateUnit;
|
||||||
import cn.hutool.core.date.DateUtil;
|
import cn.hutool.core.date.DateUtil;
|
||||||
import cn.hutool.core.lang.Assert;
|
|
||||||
import lombok.AccessLevel;
|
import lombok.AccessLevel;
|
||||||
import lombok.NoArgsConstructor;
|
import lombok.NoArgsConstructor;
|
||||||
import org.dromara.common.core.exception.ServiceException;
|
import org.dromara.common.core.exception.ServiceException;
|
||||||
@ -27,8 +26,8 @@ public class DateUtils extends DateUtil {
|
|||||||
* @param end 结束时间(支持 Date/LocalDateTime)
|
* @param end 结束时间(支持 Date/LocalDateTime)
|
||||||
* @return 时分秒格式时间差
|
* @return 时分秒格式时间差
|
||||||
*/
|
*/
|
||||||
public static String formatBetweenBySecond(Object start, Object end) {
|
public static String formatBetween(Object start, Object end) {
|
||||||
return formatTimeBetween(start, end, BetweenFormatter.Level.SECOND);
|
return formatBetween(start, end, BetweenFormatter.Level.SECOND);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -39,18 +38,10 @@ public class DateUtils extends DateUtil {
|
|||||||
* @param level 精度级别
|
* @param level 精度级别
|
||||||
* @return 格式化时长
|
* @return 格式化时长
|
||||||
*/
|
*/
|
||||||
public static String formatTimeBetween(Object startDate, Object endDate, BetweenFormatter.Level level) {
|
public static String formatBetween(Object startDate, Object endDate, BetweenFormatter.Level level) {
|
||||||
// 非空校验
|
|
||||||
Assert.notNull(startDate, "开始时间不能为空");
|
|
||||||
Assert.notNull(endDate, "结束时间不能为空");
|
|
||||||
Assert.notNull(level, "时间精度级别不能为空");
|
|
||||||
|
|
||||||
// 统一转为Date并校验格式合法性
|
// 统一转为Date并校验格式合法性
|
||||||
Date start = Convert.toDate(startDate);
|
Date start = Convert.toDate(startDate);
|
||||||
Date end = Convert.toDate(endDate);
|
Date end = Convert.toDate(endDate);
|
||||||
Assert.notNull(start, "开始时间格式错误,无法解析为时间");
|
|
||||||
Assert.notNull(end, "结束时间格式错误,无法解析为时间");
|
|
||||||
|
|
||||||
long diffMillis = Math.abs(end.getTime() - start.getTime());
|
long diffMillis = Math.abs(end.getTime() - start.getTime());
|
||||||
return formatBetween(diffMillis, level);
|
return formatBetween(diffMillis, level);
|
||||||
}
|
}
|
||||||
@ -64,16 +55,9 @@ public class DateUtils extends DateUtil {
|
|||||||
* @param unit 时间单位
|
* @param unit 时间单位
|
||||||
*/
|
*/
|
||||||
public static void validateDateRange(Object startDate, Object endDate, int maxValue, TimeUnit unit) {
|
public static void validateDateRange(Object startDate, Object endDate, int maxValue, TimeUnit unit) {
|
||||||
// 基础非空校验
|
|
||||||
Assert.notNull(startDate, "开始日期不能为空");
|
|
||||||
Assert.notNull(endDate, "结束日期不能为空");
|
|
||||||
Assert.notNull(unit, "时间单位不能为空");
|
|
||||||
|
|
||||||
// 统一转换并校验时间合法性
|
// 统一转换并校验时间合法性
|
||||||
Date start = Convert.toDate(startDate);
|
Date start = Convert.toDate(startDate);
|
||||||
Date end = Convert.toDate(endDate);
|
Date end = Convert.toDate(endDate);
|
||||||
Assert.notNull(start, "开始日期格式错误,无法解析为时间");
|
|
||||||
Assert.notNull(end, "结束日期格式错误,无法解析为时间");
|
|
||||||
|
|
||||||
// 校验结束时间不能早于开始时间
|
// 校验结束时间不能早于开始时间
|
||||||
if (end.before(start)) {
|
if (end.before(start)) {
|
||||||
|
|||||||
@ -239,7 +239,7 @@ public class FlowHisTaskVo implements Serializable {
|
|||||||
private void updateRunDuration() {
|
private void updateRunDuration() {
|
||||||
// 如果创建时间和更新时间均不为空,计算它们之间的时长
|
// 如果创建时间和更新时间均不为空,计算它们之间的时长
|
||||||
if (this.updateTime != null && this.createTime != null) {
|
if (this.updateTime != null && this.createTime != null) {
|
||||||
this.runDuration = DateUtils.formatBetweenBySecond(this.updateTime, this.createTime);
|
this.runDuration = DateUtils.formatBetween(this.updateTime, this.createTime);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -202,7 +202,7 @@ public class FlwChartExtServiceImpl implements ChartExtService {
|
|||||||
// 添加具体信息项:账号、耗时、时间
|
// 添加具体信息项:账号、耗时、时间
|
||||||
info.add(buildInfoItem("用户账号", userDTO.getUserName()));
|
info.add(buildInfoItem("用户账号", userDTO.getUserName()));
|
||||||
info.add(buildInfoItem("审批状态", dictType.get(task.getFlowStatus())));
|
info.add(buildInfoItem("审批状态", dictType.get(task.getFlowStatus())));
|
||||||
info.add(buildInfoItem("审批耗时", DateUtils.formatBetweenBySecond(task.getUpdateTime(), task.getCreateTime())));
|
info.add(buildInfoItem("审批耗时", DateUtils.formatBetween(task.getUpdateTime(), task.getCreateTime())));
|
||||||
info.add(buildInfoItem("办理时间", DateUtils.formatDateTime(task.getUpdateTime())));
|
info.add(buildInfoItem("办理时间", DateUtils.formatDateTime(task.getUpdateTime())));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user