Skip to content

Commit

Permalink
refactor: 优化公告状态判断
Browse files Browse the repository at this point in the history
  • Loading branch information
Charles7c committed May 28, 2024
1 parent 45396f2 commit a07aedb
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
import top.continew.admin.common.constant.UiConstants;
import top.continew.starter.data.mybatis.plus.base.IBaseEnum;

import java.time.LocalDateTime;

/**
* 公告状态枚举
*
Expand Down Expand Up @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

0 comments on commit a07aedb

Please sign in to comment.