refactor: 对齐后端样例工程规范

This commit is contained in:
2026-07-26 18:24:13 +08:00
parent 4382641e19
commit 4f2bb7e88b
66 changed files with 1869 additions and 660 deletions

View File

@@ -0,0 +1,54 @@
// Package idn_account 提供用户账户最小必要查询逻辑。
package idn_account
import (
"git.apinb.com/bsm-sdk/core/infra"
"git.apinb.com/bsm-sdk/core/utils"
"git.apinb.com/heqiapp/platforms/backend/api/internal/models"
"github.com/gin-gonic/gin"
)
// AccountView 是 idn_account 的最小必要输出,手机号始终脱敏。
type AccountView struct {
Identity string `json:"identity"` // 用户主键
PhoneMasked string `json:"phone_masked"` // 脱敏手机号
AccountType string `json:"account_type"` // 账户类型
Status string `json:"status"` // 账户状态
ServiceArea string `json:"service_area"` // 服务区域
}
// ListReply 是 idn_account 的标准分页响应。
type ListReply struct {
Total int64 `json:"total"`
List []AccountView `json:"list"`
}
// List 查询普通用户账户列表。
func List(ctx *gin.Context) {
page := utils.String2Int(ctx.DefaultQuery("page", "1"))
size := utils.String2Int(ctx.DefaultQuery("size", "20"))
if page < 1 {
page = 1
}
if size < 1 || size > 100 {
size = 20
}
list, total, err := models.ListIdnAccount(page, size)
if err != nil {
infra.Response.Error(ctx, err)
return
}
views := make([]AccountView, 0, len(list))
for _, item := range list {
views = append(views, AccountView{Identity: item.Identity.String(), PhoneMasked: maskPhone(item.Phone), AccountType: item.AccountType, Status: item.Status, ServiceArea: item.ServiceArea})
}
infra.Response.Success(ctx, ListReply{Total: total, List: views})
}
// maskPhone 遵循敏感数据最小展示原则。
func maskPhone(phone string) string {
if len(phone) < 7 {
return "***"
}
return phone[:3] + "****" + phone[len(phone)-4:]
}