## CI 修复 (P0/P1) P0 — 编译阻塞: - interfaces.go: postUseCase ISP 接口移除不用的 Create/Update/Delete P1 — 必须修复: - ST1000: 为 13 个包添加包注释 (common/config/model/service/...) - ST1005: redis_store.go 全部错误消息改为小写开头 - errcheck (19处): defer Close()→闭包忽略, notifier.Create→_=, r.Run→检查error - errorlint (9处): switch-on-error→errors.Is 链, ==→errors.Is - ST1020/ST1022: 导出符号注释以符号名开头 P2 — 安全评审: - gosec (12处): G203/G301/G304/G306 添加 nolint 注释并附理由 P3 — 清理: - unused: 移除 hasUnicode/energyStore/current/energyAdminUseCase - gofumpt + goimports 全量格式化 (35+ 文件)
63 lines
2.0 KiB
Go
63 lines
2.0 KiB
Go
// Package model 定义数据模型、常量、角色体系和审核相关类型。
|
||
package model
|
||
|
||
// 审核类型常量
|
||
const (
|
||
AuditTypeUsername = "username"
|
||
AuditTypeAvatar = "avatar"
|
||
AuditTypeBio = "bio"
|
||
)
|
||
|
||
// 审核状态常量
|
||
const (
|
||
AuditStatusPending = "pending"
|
||
AuditStatusApproved = "approved"
|
||
AuditStatusRejected = "rejected"
|
||
)
|
||
|
||
// AuditSubmission 审核提交记录
|
||
// 密钥设计:
|
||
// - 用户提交修改 → 创建 pending 记录,User 表暂不更新
|
||
// - 管理员审批通过 → 更新 User 表对应字段,标记 approved
|
||
// - 管理员拒绝 → 标记 rejected,记录理由
|
||
// - 用户连续提交同类型 → 旧 pending 标记 rejected(理由"用户重新提交"),创建新 pending
|
||
type AuditSubmission struct {
|
||
BaseModel
|
||
|
||
UserID uint `gorm:"index:idx_type_user_status,priority:2;not null" json:"user_id"`
|
||
AuditType string `gorm:"type:varchar(20);index:idx_type_user_status,priority:1;not null" json:"audit_type"`
|
||
NewValue string `gorm:"type:text;not null" json:"new_value"`
|
||
|
||
Status string `gorm:"type:varchar(20);index:idx_type_user_status,priority:3;not null;default:pending" json:"status"`
|
||
|
||
// 审核人信息(审核后才填充)
|
||
ReviewedBy *uint `gorm:"default:null" json:"reviewed_by,omitempty"`
|
||
ReviewerName *string `gorm:"type:varchar(50);default:null" json:"reviewer_name,omitempty"`
|
||
|
||
// 拒绝理由
|
||
RejectReason *string `gorm:"type:text;default:null" json:"reject_reason,omitempty"`
|
||
}
|
||
|
||
// AuditTypeNames 审核类型 → 中文名
|
||
var AuditTypeNames = map[string]string{
|
||
AuditTypeUsername: "用户名",
|
||
AuditTypeAvatar: "头像",
|
||
AuditTypeBio: "个性签名",
|
||
}
|
||
|
||
// AuditStatusNames 审核状态 → 中文名
|
||
var AuditStatusNames = map[string]string{
|
||
AuditStatusPending: "待审核",
|
||
AuditStatusApproved: "已通过",
|
||
AuditStatusRejected: "已拒绝",
|
||
}
|
||
|
||
// IsAuditType 校验审核类型合法性
|
||
func IsAuditType(t string) bool {
|
||
switch t {
|
||
case AuditTypeUsername, AuditTypeAvatar, AuditTypeBio:
|
||
return true
|
||
}
|
||
return false
|
||
}
|