代码质量改进:修复架构违规、完善文档注释和清理冗余代码

- 修复 health.go handler 直接操作响应的架构违规问题
- 为 model 字段添加 GORM comment 标签(account_role、base、role_permission)
- 为 handler、service、store 包添加包级文档注释
- 清理 customer service 和 personal_customer handler 中注释掉的代码

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
2026-01-12 16:28:48 +08:00
parent 590614aecc
commit 4507de577b
17 changed files with 50 additions and 41 deletions

View File

@@ -1,3 +1,5 @@
// Package admin 提供管理后台的 HTTP 处理器
// 包含账号管理、角色管理、权限管理、任务管理等功能的 Handler 实现
package admin package admin
import ( import (

View File

@@ -1,3 +1,5 @@
// Package app 提供移动端H5/小程序)的 HTTP 处理器
// 包含个人客户认证、注册、微信绑定等功能的 Handler 实现
package app package app
import ( import (
@@ -120,16 +122,10 @@ func (h *PersonalCustomerHandler) BindWechat(c *fiber.Ctx) error {
return errors.New(errors.CodeInvalidParam, "请求参数解析失败") return errors.New(errors.CodeInvalidParam, "请求参数解析失败")
} }
// TODO: 从 context 中获取当前登录的客户 ID // TODO: 实现完整的微信绑定流程
// customerID := c.Locals("customer_id").(uint) // 1. 从 context 中获取当前登录的客户 ID
// 2. 使用微信授权码换取 OpenID 和 UnionID
// TODO: 使用微信授权码换取 OpenID 和 UnionID // 3. 调用 service 层的 BindWechat 方法绑定微信
// wxOpenID, wxUnionID, err := wechatService.GetUserInfo(req.Code)
// TODO: 绑定微信
// if err := h.service.BindWechat(c.Context(), customerID, wxOpenID, wxUnionID); err != nil {
// return errors.Wrap(errors.CodeInternalError, "绑定微信失败", err)
// }
return response.Success(c, fiber.Map{ return response.Success(c, fiber.Map{
"message": "微信绑定功能暂未实现,待微信 SDK 对接后启用", "message": "微信绑定功能暂未实现,待微信 SDK 对接后启用",

View File

@@ -102,10 +102,12 @@ func (h *HealthHandler) Check(c *fiber.Ctx) error {
if !allHealthy { if !allHealthy {
healthStatus["status"] = "degraded" healthStatus["status"] = "degraded"
h.logger.Warn("健康检查失败: 部分服务不可用") h.logger.Warn("健康检查失败: 部分服务不可用")
return c.Status(fiber.StatusServiceUnavailable).JSON(healthStatus) } else {
h.logger.Info("健康检查成功: 所有服务正常")
} }
h.logger.Info("健康检查成功: 所有服务正常") // 统一使用 response.Success 返回,状态信息在 data.status 中标记
// 健康检查端点本身能响应即视为成功,具体服务状态由 data.status 字段表示
return response.Success(c, healthStatus) return response.Success(c, healthStatus)
} }

View File

@@ -8,15 +8,15 @@ import (
// AccountRole 账号-角色关联模型 // AccountRole 账号-角色关联模型
type AccountRole struct { type AccountRole struct {
ID uint `gorm:"column:id;primarykey" json:"id"` ID uint `gorm:"column:id;primarykey;comment:主键ID" json:"id"`
AccountID uint `gorm:"column:account_id;not null;index;uniqueIndex:idx_account_role_unique,where:deleted_at IS NULL" json:"account_id"` AccountID uint `gorm:"column:account_id;not null;index;uniqueIndex:idx_account_role_unique,where:deleted_at IS NULL;comment:账号ID" json:"account_id"`
RoleID uint `gorm:"column:role_id;not null;index;uniqueIndex:idx_account_role_unique,where:deleted_at IS NULL" json:"role_id"` RoleID uint `gorm:"column:role_id;not null;index;uniqueIndex:idx_account_role_unique,where:deleted_at IS NULL;comment:角色ID" json:"role_id"`
Status int `gorm:"column:status;not null;default:1" json:"status"` Status int `gorm:"column:status;not null;default:1;comment:状态 0=禁用 1=启用" json:"status"`
Creator uint `gorm:"column:creator;not null" json:"creator"` Creator uint `gorm:"column:creator;not null;comment:创建人ID" json:"creator"`
Updater uint `gorm:"column:updater;not null" json:"updater"` Updater uint `gorm:"column:updater;not null;comment:更新人ID" json:"updater"`
CreatedAt time.Time `gorm:"column:created_at;not null" json:"created_at"` CreatedAt time.Time `gorm:"column:created_at;not null;comment:创建时间" json:"created_at"`
UpdatedAt time.Time `gorm:"column:updated_at;not null" json:"updated_at"` UpdatedAt time.Time `gorm:"column:updated_at;not null;comment:更新时间" json:"updated_at"`
DeletedAt gorm.DeletedAt `gorm:"column:deleted_at;index" json:"deleted_at,omitempty"` DeletedAt gorm.DeletedAt `gorm:"column:deleted_at;index;comment:删除时间" json:"deleted_at,omitempty"`
} }
// TableName 指定表名 // TableName 指定表名

View File

@@ -4,6 +4,6 @@ package model
// //
// BaseModel 基础模型,包含通用字段 // BaseModel 基础模型,包含通用字段
type BaseModel struct { type BaseModel struct {
Creator uint `gorm:"column:creator;not null" json:"creator"` Creator uint `gorm:"column:creator;not null;comment:创建人ID" json:"creator"`
Updater uint `gorm:"column:updater;not null" json:"updater"` Updater uint `gorm:"column:updater;not null;comment:更新人ID" json:"updater"`
} }

View File

@@ -9,9 +9,9 @@ type RolePermission struct {
gorm.Model gorm.Model
BaseModel `gorm:"embedded"` BaseModel `gorm:"embedded"`
RoleID uint `gorm:"column:role_id;not null;index;uniqueIndex:idx_role_permission_unique,where:deleted_at IS NULL" json:"role_id"` RoleID uint `gorm:"column:role_id;not null;index;uniqueIndex:idx_role_permission_unique,where:deleted_at IS NULL;comment:角色ID" json:"role_id"`
PermID uint `gorm:"column:perm_id;not null;index;uniqueIndex:idx_role_permission_unique,where:deleted_at IS NULL" json:"perm_id"` PermID uint `gorm:"column:perm_id;not null;index;uniqueIndex:idx_role_permission_unique,where:deleted_at IS NULL;comment:权限ID" json:"perm_id"`
Status int `gorm:"column:status;not null;default:1" json:"status"` Status int `gorm:"column:status;not null;default:1;comment:状态 0=禁用 1=启用" json:"status"`
} }
// TableName 指定表名 // TableName 指定表名

View File

@@ -1,3 +1,5 @@
// Package account 提供账号管理的业务逻辑服务
// 包含账号创建、查询、更新、删除、密码管理等功能
package account package account
import ( import (

View File

@@ -1,3 +1,5 @@
// Package customer 提供客户管理的业务逻辑服务
// 包含客户信息管理、客户查询等功能
package customer package customer
import ( import (
@@ -47,16 +49,7 @@ func (s *Service) Create(ctx context.Context, req *model.CreatePersonalCustomerR
return nil, err return nil, err
} }
// TODO: 创建 PersonalCustomerPhone 记录 // TODO: 创建 PersonalCustomerPhone 记录,需要通过 PersonalCustomerPhoneStore 创建手机号关联
// if req.Phone != "" {
// phoneRecord := &model.PersonalCustomerPhone{
// CustomerID: customer.ID,
// Phone: req.Phone,
// IsPrimary: true,
// Status: constants.StatusEnabled,
// }
// // 需要通过 PersonalCustomerPhoneStore 创建
// }
return customer, nil return customer, nil
} }
@@ -69,11 +62,7 @@ func (s *Service) Update(ctx context.Context, id uint, req *model.UpdatePersonal
return nil, errors.New(errors.CodeCustomerNotFound, "个人客户不存在") return nil, errors.New(errors.CodeCustomerNotFound, "个人客户不存在")
} }
// 注意:手机号的更新逻辑需要通过 PersonalCustomerPhone 表处理 // TODO: 手机号的更新逻辑需要通过 PersonalCustomerPhoneStore 更新或创建手机号记录
// TODO: 实现手机号的更新逻辑
// if req.Phone != nil {
// // 通过 PersonalCustomerPhoneStore 更新或创建手机号记录
// }
// 更新字段 // 更新字段
if req.Nickname != nil { if req.Nickname != nil {

View File

@@ -1,3 +1,5 @@
// Package email 提供邮件发送的业务逻辑服务
// 包含邮件发送、邮件模板管理等功能
package email package email
import ( import (

View File

@@ -1,3 +1,5 @@
// Package enterprise 提供企业管理的业务逻辑服务
// 包含企业创建、查询、更新、删除等功能
package enterprise package enterprise
import ( import (

View File

@@ -1,3 +1,5 @@
// Package permission 提供权限管理的业务逻辑服务
// 包含权限创建、查询、更新、删除、权限检查等功能
package permission package permission
import ( import (

View File

@@ -1,3 +1,5 @@
// Package personal_customer 提供个人客户管理的业务逻辑服务
// 包含个人客户注册、登录、微信绑定、短信验证等功能
package personal_customer package personal_customer
import ( import (

View File

@@ -1,3 +1,5 @@
// Package role 提供角色管理的业务逻辑服务
// 包含角色创建、查询、更新、删除、角色权限关联等功能
package role package role
import ( import (

View File

@@ -1,3 +1,5 @@
// Package shop 提供店铺管理的业务逻辑服务
// 包含店铺创建、查询、更新、删除等功能
package shop package shop
import ( import (

View File

@@ -1,3 +1,5 @@
// Package sync 提供数据同步的业务逻辑服务
// 包含批量数据同步、任务调度等功能
package sync package sync
import ( import (

View File

@@ -1,3 +1,5 @@
// Package verification 提供验证码管理的业务逻辑服务
// 包含短信验证码生成、发送、验证等功能
package verification package verification
import ( import (

View File

@@ -1,3 +1,5 @@
// Package postgres 提供基于 PostgreSQL 的数据访问层实现
// 包含所有模型的 Store 接口实现,使用 GORM 进行数据库操作
package postgres package postgres
import ( import (