add timed

This commit is contained in:
2025-09-02 16:37:28 +08:00
parent 2f3817c8f0
commit c7c4ab7a19
28 changed files with 478 additions and 2373 deletions

View File

@@ -0,0 +1,6 @@
package commands
// CancelScheduleCommand 取消定时发布命令
type CancelScheduleCommand struct {
ID string `json:"-" uri:"id" binding:"required" comment:"文章ID"`
}

View File

@@ -1,9 +1,39 @@
package commands
import "time"
import (
"fmt"
"time"
)
// SchedulePublishCommand 定时发布文章命令
type SchedulePublishCommand struct {
ID string `json:"-" uri:"id" binding:"required" comment:"文章ID"`
ScheduledTime time.Time `json:"scheduled_time" binding:"required" comment:"定时发布时间"`
ID string `json:"-" uri:"id" binding:"required" comment:"文章ID"`
ScheduledTime string `json:"scheduled_time" binding:"required" comment:"定时发布时间"`
}
// GetScheduledTime 获取解析后的定时发布时间
func (cmd *SchedulePublishCommand) GetScheduledTime() (time.Time, error) {
// 定义中国东八区时区
cst := time.FixedZone("CST", 8*3600)
// 支持多种时间格式
formats := []string{
"2006-01-02 15:04:05", // "2025-09-02 14:12:01"
"2006-01-02T15:04:05", // "2025-09-02T14:12:01"
"2006-01-02T15:04:05Z", // "2025-09-02T14:12:01Z"
"2006-01-02 15:04", // "2025-09-02 14:12"
time.RFC3339, // "2025-09-02T14:12:01+08:00"
}
for _, format := range formats {
if t, err := time.Parse(format, cmd.ScheduledTime); err == nil {
// 如果解析的时间没有时区信息,则设置为中国东八区
if t.Location() == time.UTC {
t = t.In(cst)
}
return t, nil
}
}
return time.Time{}, fmt.Errorf("不支持的时间格式: %s请使用 YYYY-MM-DD HH:mm:ss 格式", cmd.ScheduledTime)
}

View File

@@ -17,6 +17,7 @@ type ArticleInfoResponse struct {
Status string `json:"status" comment:"文章状态"`
IsFeatured bool `json:"is_featured" comment:"是否推荐"`
PublishedAt *time.Time `json:"published_at" comment:"发布时间"`
ScheduledAt *time.Time `json:"scheduled_at" comment:"定时发布时间"`
ViewCount int `json:"view_count" comment:"阅读量"`
Tags []TagInfoResponse `json:"tags" comment:"标签列表"`
CreatedAt time.Time `json:"created_at" comment:"创建时间"`
@@ -34,6 +35,7 @@ type ArticleListItemResponse struct {
Status string `json:"status" comment:"文章状态"`
IsFeatured bool `json:"is_featured" comment:"是否推荐"`
PublishedAt *time.Time `json:"published_at" comment:"发布时间"`
ScheduledAt *time.Time `json:"scheduled_at" comment:"定时发布时间"`
ViewCount int `json:"view_count" comment:"阅读量"`
Tags []TagInfoResponse `json:"tags" comment:"标签列表"`
CreatedAt time.Time `json:"created_at" comment:"创建时间"`
@@ -103,6 +105,7 @@ func FromArticleEntity(article *entities.Article) *ArticleInfoResponse {
Status: string(article.Status),
IsFeatured: article.IsFeatured,
PublishedAt: article.PublishedAt,
ScheduledAt: article.ScheduledAt,
ViewCount: article.ViewCount,
CreatedAt: article.CreatedAt,
UpdatedAt: article.UpdatedAt,
@@ -150,6 +153,7 @@ func FromArticleEntityToListItem(article *entities.Article) *ArticleListItemResp
Status: string(article.Status),
IsFeatured: article.IsFeatured,
PublishedAt: article.PublishedAt,
ScheduledAt: article.ScheduledAt,
ViewCount: article.ViewCount,
CreatedAt: article.CreatedAt,
UpdatedAt: article.UpdatedAt,