feat: Studio 概览/分析补上阅读量 + 详情页 meta 行改版

- StudioOverview 新增 TotalViews 字段,GetOverviewByUserID 查询含 SUM(views_count)
- 新增 ViewTrendStore 接口和 AggregateViewsByAuthor,UNION ALL 合并已登录+访客阅读日志按日期聚合
- 数据分析页面新增阅读量趋势折线图(绿色,Chart.js)
- 概览和数据分析页面新增总阅读量统计卡片
- 详情页 meta 行改为标签格式:作者/阅读/点赞/收藏/评论/发布时间
- 移除详情页公开状态徽章,已锁定+理由仅作者可见
This commit is contained in:
2026-06-02 23:26:48 +08:00
parent ea2f196ff7
commit fcff28ab60
8 changed files with 88 additions and 18 deletions

View File

@ -132,11 +132,12 @@ type StudioOverview struct {
PendingCount int64 `json:"pending_count"`
ApprovedCount int64 `json:"approved_count"`
RejectedCount int64 `json:"rejected_count"`
TotalViews int64 `json:"total_views"`
}
// GetOverview 获取创作中心数据概览(单次 GROUP BY 查询)
func (s *PostService) GetOverview(userID uint) (*StudioOverview, error) {
totalPosts, draftCount, pendingCount, approvedCount, rejectedCount, err := s.repo.GetOverviewByUserID(userID)
totalPosts, draftCount, pendingCount, approvedCount, rejectedCount, totalViews, err := s.repo.GetOverviewByUserID(userID)
if err != nil {
return nil, err
}
@ -146,6 +147,7 @@ func (s *PostService) GetOverview(userID uint) (*StudioOverview, error) {
PendingCount: pendingCount,
ApprovedCount: approvedCount,
RejectedCount: rejectedCount,
TotalViews: totalViews,
}, nil
}

View File

@ -37,7 +37,7 @@ type postStore interface {
FindPageable(keyword string, offset, limit int) ([]model.Post, int64, error)
FindAdminPageable(keyword, status string, offset, limit int) ([]model.Post, int64, error)
FindByUserIDAndStatus(userID uint, status string, offset, limit int) ([]model.Post, int64, error)
GetOverviewByUserID(userID uint) (totalPosts, draftCount, pendingCount, approvedCount, rejectedCount int64, err error)
GetOverviewByUserID(userID uint) (totalPosts, draftCount, pendingCount, approvedCount, rejectedCount, totalViews int64, err error)
FindPendingRevisions(keyword string, offset, limit int) ([]model.Post, int64, error)
Update(post *model.Post) error
SoftDelete(id uint) error
@ -231,3 +231,8 @@ type LikeTrendStore interface {
type FavoriteTrendStore interface {
AggregateFavoritesByAuthor(userID uint, since string) ([]TrendPoint, error)
}
// ViewTrendStore 阅读量趋势聚合ISP
type ViewTrendStore interface {
AggregateViewsByAuthor(userID uint, since string) ([]TrendPoint, error)
}

View File

@ -12,6 +12,7 @@ type TrendResult struct {
Comments []TrendPoint `json:"comments"`
Likes []TrendPoint `json:"likes"`
Favorites []TrendPoint `json:"favorites"`
Views []TrendPoint `json:"views"`
}
// TrendsService Studio 趋势分析服务
@ -20,15 +21,17 @@ type TrendsService struct {
commentRepo CommentTrendStore
likeRepo LikeTrendStore
favoriteRepo FavoriteTrendStore
viewRepo ViewTrendStore
}
// NewTrendsService 构造函数
func NewTrendsService(energyRepo EnergyTrendStore, commentRepo CommentTrendStore, likeRepo LikeTrendStore, favoriteRepo FavoriteTrendStore) *TrendsService {
func NewTrendsService(energyRepo EnergyTrendStore, commentRepo CommentTrendStore, likeRepo LikeTrendStore, favoriteRepo FavoriteTrendStore, viewRepo ViewTrendStore) *TrendsService {
return &TrendsService{
energyRepo: energyRepo,
commentRepo: commentRepo,
likeRepo: likeRepo,
favoriteRepo: favoriteRepo,
viewRepo: viewRepo,
}
}
@ -73,6 +76,15 @@ func (s *TrendsService) GetTrends(userID uint, since string) (*TrendResult, erro
return nil
})
g.Go(func() error {
var err error
result.Views, err = s.viewRepo.AggregateViewsByAuthor(userID, since)
if err != nil {
return fmt.Errorf("查询阅读趋势: %w", err)
}
return nil
})
if err := g.Wait(); err != nil {
return nil, err
}