mirror of
https://github.com/continew-org/continew-admin.git
synced 2025-09-12 05:01:39 +08:00
refactor: 优化公告状态判断
This commit is contained in:
@@ -21,6 +21,8 @@ import lombok.RequiredArgsConstructor;
|
||||
import top.continew.admin.common.constant.UiConstants;
|
||||
import top.continew.starter.data.mybatis.plus.base.IBaseEnum;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* 公告状态枚举
|
||||
*
|
||||
@@ -49,4 +51,22 @@ public enum NoticeStatusEnum implements IBaseEnum<Integer> {
|
||||
private final Integer value;
|
||||
private final String description;
|
||||
private final String color;
|
||||
|
||||
/**
|
||||
* 获取公告状态
|
||||
*
|
||||
* @param effectiveTime 生效时间
|
||||
* @param terminateTime 终止时间
|
||||
* @return 公告状态
|
||||
*/
|
||||
public static NoticeStatusEnum getStatus(LocalDateTime effectiveTime, LocalDateTime terminateTime) {
|
||||
LocalDateTime now = LocalDateTime.now();
|
||||
if (effectiveTime != null && effectiveTime.isAfter(now)) {
|
||||
return PENDING_RELEASE;
|
||||
}
|
||||
if (terminateTime != null && terminateTime.isBefore(now)) {
|
||||
return EXPIRED;
|
||||
}
|
||||
return PUBLISHED;
|
||||
}
|
||||
}
|
||||
|
@@ -68,12 +68,6 @@ public class NoticeResp extends BaseResp {
|
||||
*/
|
||||
@Schema(description = "状态(1:待发布;2:已发布;3:已过期)", type = "Integer", allowableValues = {"1", "2", "3"}, example = "1")
|
||||
public NoticeStatusEnum getStatus() {
|
||||
if (null != this.effectiveTime && this.effectiveTime.isAfter(LocalDateTime.now())) {
|
||||
return NoticeStatusEnum.PENDING_RELEASE;
|
||||
}
|
||||
if (null != this.terminateTime && this.terminateTime.isBefore(LocalDateTime.now())) {
|
||||
return NoticeStatusEnum.EXPIRED;
|
||||
}
|
||||
return NoticeStatusEnum.PUBLISHED;
|
||||
return NoticeStatusEnum.getStatus(effectiveTime, terminateTime);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user