refactor: 文件行数超标拆解(Service + Controller 9/16 完成)

- Service 层:energy_service → energize/operations/admin/query 四文件
- Service 层:post_service → helpers/audit + 核心 CRUD 保留
- Service 层:favorite_service → items + 核心文件夹操作保留
- Service 层:auth_service → password + 核心注册/登录保留
- Service 层:notification_service → notify + 核心列表/已读保留
- Service 层:audit_service → review + 核心列表/详情保留
- Controller 层:studio_controller → page/write/api/post_api/action 五文件
- Controller 层:post_controller → page/api/upload 三文件
- Controller 层:comment_controller → list/write/action/upload 四文件
- 清理未使用导入(notification_service.go 移除 fmt)
This commit is contained in:
2026-06-02 15:45:54 +08:00
parent 7cdb4d6698
commit ff9886f08b
31 changed files with 2409 additions and 2237 deletions

View File

@ -0,0 +1,125 @@
package service
import (
"fmt"
"sort"
"metazone.cc/metalab/internal/model"
)
// checkAndNotifyAggregation 检查并生成点赞聚合通知
func (s *NotificationService) checkAndNotifyAggregation(userID uint) {
summaries, err := s.repo.GetUnnotifiedDailyLikeSummaries(userID)
if err != nil || len(summaries) == 0 {
return
}
for _, sm := range summaries {
count := countUIDs(sm.LikerUIDs)
var content string
if count <= 3 {
content = fmt.Sprintf("你的文章被 %d 人点赞了", count)
} else {
content = fmt.Sprintf("你的文章被 %d 人点赞了", count)
}
_ = s.Create(userID, model.NotifyLikeAggregated,
"点赞汇总通知",
content,
nil, nil)
_ = s.repo.MarkDailyLikeSummaryNotified(sm.ID)
}
}
func countUIDs(uids string) int {
if uids == "" {
return 0
}
count := 1
for _, c := range uids {
if c == ',' {
count++
}
}
return count
}
// categoryTypes 分类→通知类型列表
func categoryTypes(category string) []string {
switch category {
case "system":
return []string{model.NotifyAuditApproved, model.NotifyAuditRejected, model.NotifyPostApproved, model.NotifyPostRejected, model.NotifyLevelUp}
case "mention":
return []string{model.NotifyComment, model.NotifyCommentReply}
case "like":
return []string{model.NotifyLikeAggregated}
case "follow":
return []string{model.NotifyFollow}
default:
return []string{}
}
}
// sortNotifications 按 CreatedAt 降序排序
func sortNotifications(items []model.Notification) {
sort.Slice(items, func(i, j int) bool {
return items[i].CreatedAt.After(items[j].CreatedAt)
})
}
// NotifyAuditApproved 审核通过通知
func (s *NotificationService) NotifyAuditApproved(userID uint, auditType string, relatedID uint) {
typeName := model.AuditTypeNames[auditType]
if typeName == "" {
typeName = auditType
}
_ = s.Create(userID, model.NotifyAuditApproved,
"审核已通过",
"你的"+typeName+"修改已通过审核",
&relatedID, nil)
}
// NotifyAuditRejected 审核拒绝通知
func (s *NotificationService) NotifyAuditRejected(userID uint, auditType, reason string, relatedID uint) {
typeName := model.AuditTypeNames[auditType]
if typeName == "" {
typeName = auditType
}
content := "你的" + typeName + "修改被拒绝"
if reason != "" {
content += ",理由:" + reason
}
_ = s.Create(userID, model.NotifyAuditRejected,
"审核未通过",
content,
&relatedID, nil)
}
// NotifyPostApproved 稿件审核通过通知
func (s *NotificationService) NotifyPostApproved(userID uint, postTitle string, postID uint) {
title := "稿件审核通过"
content := "你的稿件《" + postTitle + "》已通过审核,现已公开发布"
_ = s.Create(userID, model.NotifyPostApproved, title, content, &postID, nil)
}
// NotifyPostRejected 稿件审核拒绝通知
func (s *NotificationService) NotifyPostRejected(userID uint, postTitle, reason string, postID uint) {
title := "稿件审核未通过"
content := "你的稿件《" + postTitle + "》未通过审核"
if reason != "" {
content += ",理由:" + reason
}
_ = s.Create(userID, model.NotifyPostRejected, title, content, &postID, nil)
}
// NotifyFollow 关注通知followerID 关注了 followeeID
func (s *NotificationService) NotifyFollow(followerID, followeeID uint) {
// 获取关注者用户名
followerName := s.getUsername(followerID)
if followerName == "" {
followerName = "一位用户"
}
title := "关注通知"
content := followerName + " 关注了你"
relID := followerID
_ = s.Create(followeeID, model.NotifyFollow, title, content, &relID, nil)
}