岗位业务逻辑完善
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
package com.vetti.common.enums;
|
||||
|
||||
/**
|
||||
* 岗位操作步骤
|
||||
*/
|
||||
public enum RoleOperStepsEnum {
|
||||
|
||||
STEPS_1("1", "第一步"),
|
||||
STEPS_2("2", "第二步"),
|
||||
STEPS_3("3", "第三步"),
|
||||
STEPS_4("4", "第四步"),
|
||||
STEPS_5("5", "第五步"),
|
||||
STEPS_6("6", "第六步"),
|
||||
;
|
||||
|
||||
private final String code;
|
||||
private final String info;
|
||||
|
||||
RoleOperStepsEnum(String code, String info)
|
||||
{
|
||||
this.code = code;
|
||||
this.info = info;
|
||||
}
|
||||
|
||||
public String getCode()
|
||||
{
|
||||
return code;
|
||||
}
|
||||
|
||||
public String getInfo()
|
||||
{
|
||||
return info;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
package com.vetti.common.enums;
|
||||
|
||||
/**
|
||||
* 岗位状态
|
||||
*/
|
||||
public enum RoleStatusEnum {
|
||||
|
||||
PAUSE("pause", "暂停"),
|
||||
OPEN("open", "发布"),
|
||||
EDITING("editing", "编辑中"),
|
||||
ARCHIVED("archived", "已归档"),
|
||||
;
|
||||
|
||||
private final String code;
|
||||
private final String info;
|
||||
|
||||
RoleStatusEnum(String code, String info)
|
||||
{
|
||||
this.code = code;
|
||||
this.info = info;
|
||||
}
|
||||
|
||||
public String getCode()
|
||||
{
|
||||
return code;
|
||||
}
|
||||
|
||||
public String getInfo()
|
||||
{
|
||||
return info;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -3,11 +3,7 @@ package com.vetti.common.utils;
|
||||
import java.lang.management.ManagementFactory;
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.LocalTime;
|
||||
import java.time.ZoneId;
|
||||
import java.time.ZonedDateTime;
|
||||
import java.time.*;
|
||||
import java.util.Date;
|
||||
|
||||
import org.apache.commons.lang3.time.DateFormatUtils;
|
||||
@@ -217,4 +213,52 @@ public class DateUtils extends org.apache.commons.lang3.time.DateUtils {
|
||||
return calculateDifference(startDate, endDate, unit);
|
||||
}
|
||||
|
||||
/**
|
||||
* 计算指定时间距离当前时间的相对描述(小时前/天前/周前)
|
||||
* @param createTime 创建时间(Date类型)
|
||||
* @return 相对时间描述(如:2小时前、3天前、1周前)
|
||||
*/
|
||||
public static String getTimeAgo(Date createTime) {
|
||||
// 空值校验
|
||||
if (createTime == null) {
|
||||
return "Unknown time";
|
||||
}
|
||||
|
||||
// 将Date转换为LocalDateTime(默认使用系统时区)
|
||||
LocalDateTime createLocalTime = createTime.toInstant()
|
||||
.atZone(ZoneId.systemDefault())
|
||||
.toLocalDateTime();
|
||||
LocalDateTime now = LocalDateTime.now();
|
||||
|
||||
// 计算时间差(秒)
|
||||
Duration duration = Duration.between(createLocalTime, now);
|
||||
long seconds = duration.getSeconds();
|
||||
|
||||
// 处理未来时间的情况
|
||||
if (seconds < 0) {
|
||||
return "Future time";
|
||||
}
|
||||
|
||||
// 定义时间单位换算
|
||||
long secondsPerHour = 3600;
|
||||
long secondsPerDay = secondsPerHour * 24;
|
||||
long secondsPerWeek = secondsPerDay * 7;
|
||||
|
||||
// 计算不同维度的时间差
|
||||
long hours = seconds / secondsPerHour;
|
||||
long days = seconds / secondsPerDay;
|
||||
long weeks = seconds / secondsPerWeek;
|
||||
|
||||
// 按优先级返回(周 > 天 > 小时)
|
||||
if (weeks >= 1) {
|
||||
return weeks + "weeks ago";
|
||||
} else if (days >= 1) {
|
||||
return days + "days ago";
|
||||
} else if (hours >= 1) {
|
||||
return hours + "hours ago";
|
||||
} else {
|
||||
return "Just now"; // 1小时内
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user