Add classification annotations

This commit is contained in:
2025-10-27 23:12:15 +08:00
parent 3990ec01c6
commit 5aacb88c22
44 changed files with 2769 additions and 2241 deletions

View File

@@ -8,11 +8,63 @@ import (
"gorm.io/gorm"
)
// ============================================================================
// 常量定义
// ============================================================================
// API类型常量定义
const (
// 基础信息
APITypeGetBulletin = 1 // 获取程序公告
APITypeGetUpdateUrl = 2 // 获取更新地址
APITypeCheckAppVersion = 3 // 检测最新版本
APITypeGetCardInfo = 4 // 获取卡密信息
// 卡密相关
APITypeSingleLogin = 10 // 卡密登录
// 账号管理
APITypeUserLogin = 20 // 用户登录
APITypeUserRegin = 21 // 用户注册
APITypeUserRecharge = 22 // 用户充值
// 登出操作
APITypeLogOut = 30 // 退出登录
// 状态查询
APITypeGetExpired = 40 // 获取到期时间
APITypeCheckUserStatus = 41 // 检测账号状态
APITypeGetAppData = 42 // 获取程序数据
APITypeGetVariable = 43 // 获取变量数据
APITypeExecuteFunction = 44 // 执行远程函数
// 用户操作
APITypeUpdatePwd = 50 // 修改账号密码
APITypeMacChangeBind = 51 // 机器码转绑
APITypeIPChangeBind = 52 // IP转绑
// 风控操作
APITypeDisableUser = 60 // 封停用户
APITypeBlackUser = 61 // 添加黑名单
APITypeUserDeductedTime = 62 // 扣除时间
)
// 算法类型常量
const (
AlgorithmNone = 0 // 不加密
AlgorithmRC4 = 1 // RC4
AlgorithmRSA = 2 // RSA
AlgorithmRSADynamic = 3 // RSA动态
AlgorithmEasy = 4 // 易加密
)
// ============================================================================
// 结构体定义
// ============================================================================
// API 接口表模型
// 用于管理API接口的配置信息
// 包含加密算法配置、密钥管理等功能
// 支持多种加密算法不加密、RC4、RSA、RSA动态
// CreatedAt/UpdatedAt 由 GORM 自动维护
type API struct {
// ID主键自增
ID uint `gorm:"primaryKey;comment:API接口ID自增主键" json:"id"`
@@ -54,6 +106,10 @@ type API struct {
UpdatedAt time.Time `gorm:"comment:更新时间" json:"updated_at"`
}
// ============================================================================
// 结构体方法
// ============================================================================
// BeforeCreate 在创建记录前自动生成UUID
func (api *API) BeforeCreate(tx *gorm.DB) error {
if api.UUID == "" {
@@ -67,51 +123,9 @@ func (API) TableName() string {
return "apis"
}
// API类型常量定义
const (
// 基础信息获取类API
APITypeGetBulletin = 1 // 获取程序公告
APITypeGetUpdateUrl = 2 // 获取更新地址
APITypeCheckAppVersion = 3 // 检测最新版本
APITypeGetCardInfo = 4 // 获取卡密信息
// 登录相关API
APITypeSingleLogin = 10 // 卡密登录
// 用户账号管理API
APITypeUserLogin = 20 // 用户登录
APITypeUserRegin = 21 // 用户注册
APITypeUserRecharge = 22 // 用户充值
APITypeCardRegin = 23 // 卡密注册
// 登出API
APITypeLogOut = 30 // 退出登录
// 用户状态查询API
APITypeGetExpired = 40 // 获取到期时间
APITypeCheckUserStatus = 41 // 检测账号状态
APITypeGetAppData = 42 // 获取程序数据
APITypeGetVariable = 43 // 获取变量数据
// 用户操作API
APITypeUpdatePwd = 50 // 修改账号密码
APITypeMacChangeBind = 51 // 机器码转绑
APITypeIPChangeBind = 52 // IP转绑
// 管理员操作API
APITypeDisableUser = 60 // 封停用户
APITypeBlackUser = 61 // 添加黑名单
APITypeUserDeductedTime = 62 // 扣除时间
)
// 算法类型常量
const (
AlgorithmNone = 0 // 不加密
AlgorithmRC4 = 1 // RC4
AlgorithmRSA = 2 // RSA
AlgorithmRSADynamic = 3 // RSA动态
AlgorithmEasy = 4 // 易加密
)
// ============================================================================
// 独立函数
// ============================================================================
// GetAlgorithmName 获取算法名称
func GetAlgorithmName(algorithm int) string {
@@ -131,84 +145,134 @@ func GetAlgorithmName(algorithm int) string {
}
}
// ============================================================================
// 基础结构体定义
// ============================================================================
// APITypeInfo 接口类型信息
type APITypeInfo struct {
Type int `json:"type"` // 接口类型
Name string `json:"name"` // 接口名称
}
// APICategoryInfo 接口分类信息
type APICategoryInfo struct {
Name string `json:"name"` // 分类名称
Types []APITypeInfo `json:"types"` // 该分类下的接口类型列表
}
// ============================================================================
// 核心功能函数
// ============================================================================
// GetAPITypes 获取API接口类型支持按分类返回或返回完整列表
// categorized: true=按分类返回[]APICategoryInfo, false=返回完整列表[]int
func GetAPITypes(categorized bool) interface{} {
// 层次化的接口类型组织结构
apiCategories := []APICategoryInfo{
{
Name: "基础信息",
Types: []APITypeInfo{
{Type: APITypeGetBulletin, Name: "获取程序公告"},
{Type: APITypeGetUpdateUrl, Name: "获取更新地址"},
{Type: APITypeCheckAppVersion, Name: "检测最新版本"},
{Type: APITypeGetCardInfo, Name: "获取卡密信息"},
},
},
{
Name: "卡密相关",
Types: []APITypeInfo{
{Type: APITypeSingleLogin, Name: "卡密登录"},
},
},
{
Name: "账号管理",
Types: []APITypeInfo{
{Type: APITypeUserLogin, Name: "用户登录"},
{Type: APITypeUserRegin, Name: "用户注册"},
{Type: APITypeUserRecharge, Name: "用户充值"},
},
},
{
Name: "登出操作",
Types: []APITypeInfo{
{Type: APITypeLogOut, Name: "退出登录"},
},
},
{
Name: "状态查询",
Types: []APITypeInfo{
{Type: APITypeGetExpired, Name: "获取到期时间"},
{Type: APITypeCheckUserStatus, Name: "检测账号状态"},
{Type: APITypeGetAppData, Name: "获取程序数据"},
{Type: APITypeGetVariable, Name: "获取变量数据"},
{Type: APITypeExecuteFunction, Name: "执行远程函数"},
},
},
{
Name: "用户操作",
Types: []APITypeInfo{
{Type: APITypeUpdatePwd, Name: "修改账号密码"},
{Type: APITypeMacChangeBind, Name: "机器码转绑"},
{Type: APITypeIPChangeBind, Name: "IP转绑"},
},
},
{
Name: "风控操作",
Types: []APITypeInfo{
{Type: APITypeDisableUser, Name: "封停用户"},
{Type: APITypeBlackUser, Name: "添加黑名单"},
{Type: APITypeUserDeductedTime, Name: "扣除时间"},
},
},
}
if categorized {
// 返回层次化的分类结构
return apiCategories
}
// 返回所有接口类型的扁平列表
var allTypes []int
for _, category := range apiCategories {
for _, typeInfo := range category.Types {
allTypes = append(allTypes, typeInfo.Type)
}
}
return allTypes
}
// GetAPITypeName 获取API类型名称
// 通过调用GetAPITypes函数来获取名称避免重复维护数据
func GetAPITypeName(apiType int) string {
// 获取分类化的API类型数据
categories := GetAPITypes(true).([]APICategoryInfo)
// 遍历所有分类和类型查找匹配的API类型
for _, category := range categories {
for _, typeInfo := range category.Types {
if typeInfo.Type == apiType {
return typeInfo.Name
}
}
}
// 如果没有找到匹配的类型,返回默认值
return "未知API类型"
}
// ============================================================================
// 验证函数
// ============================================================================
// IsValidAlgorithm 验证算法类型是否有效
func IsValidAlgorithm(algorithm int) bool {
return algorithm >= AlgorithmNone && algorithm <= AlgorithmEasy
}
// GetAPITypeName 获取API类型名称
func GetAPITypeName(apiType int) string {
switch apiType {
// 基础信息获取类API
case APITypeGetBulletin:
return "获取程序公告"
case APITypeGetUpdateUrl:
return "获取更新地址"
case APITypeCheckAppVersion:
return "检测最新版本"
case APITypeGetCardInfo:
return "获取卡密信息"
// 登录相关API
case APITypeSingleLogin:
return "卡密登录"
// 用户账号管理API
case APITypeUserLogin:
return "用户登录"
case APITypeUserRegin:
return "用户注册"
case APITypeUserRecharge:
return "用户充值"
case APITypeCardRegin:
return "卡密注册"
// 登出API
case APITypeLogOut:
return "退出登录"
// 用户状态查询API
case APITypeGetExpired:
return "获取到期时间"
case APITypeCheckUserStatus:
return "检测账号状态"
case APITypeGetAppData:
return "获取程序数据"
case APITypeGetVariable:
return "获取变量数据"
// 用户操作API
case APITypeUpdatePwd:
return "修改账号密码"
case APITypeMacChangeBind:
return "机器码转绑"
case APITypeIPChangeBind:
return "IP转绑"
// 管理员操作API
case APITypeDisableUser:
return "封停用户"
case APITypeBlackUser:
return "添加黑名单"
case APITypeUserDeductedTime:
return "扣除时间"
default:
return "未知API类型"
}
}
// IsValidAPIType 验证API类型是否有效
func IsValidAPIType(apiType int) bool {
validTypes := []int{
APITypeGetBulletin, APITypeGetUpdateUrl, APITypeCheckAppVersion, APITypeGetCardInfo,
APITypeSingleLogin,
APITypeUserLogin, APITypeUserRegin, APITypeUserRecharge, APITypeCardRegin,
APITypeLogOut,
APITypeGetExpired, APITypeCheckUserStatus, APITypeGetAppData, APITypeGetVariable,
APITypeUpdatePwd, APITypeMacChangeBind, APITypeIPChangeBind,
APITypeDisableUser, APITypeBlackUser, APITypeUserDeductedTime,
}
validTypes := GetDefaultAPITypes()
for _, validType := range validTypes {
if apiType == validType {
@@ -218,15 +282,34 @@ func IsValidAPIType(apiType int) bool {
return false
}
// GetAPITypesByCategory 根据分类获取API类型列表
func GetAPITypesByCategory() map[string][]int {
return map[string][]int{
"基础信息获取": {APITypeGetBulletin, APITypeGetUpdateUrl, APITypeCheckAppVersion, APITypeGetCardInfo},
"登录相关": {APITypeSingleLogin},
"用户账号管理": {APITypeUserLogin, APITypeUserRegin, APITypeUserRecharge, APITypeCardRegin},
"登出": {APITypeLogOut},
"用户状态查询": {APITypeGetExpired, APITypeCheckUserStatus, APITypeGetAppData, APITypeGetVariable},
"用户操作": {APITypeUpdatePwd, APITypeMacChangeBind, APITypeIPChangeBind},
"管理员操作": {APITypeDisableUser, APITypeBlackUser, APITypeUserDeductedTime},
}
// ============================================================================
// 兼容性函数
// ============================================================================
// GetDefaultAPITypes 获取默认创建的API接口类型列表兼容性函数
func GetDefaultAPITypes() []int {
return GetAPITypes(false).([]int)
}
// GetAPITypesByCategory 根据分类获取API类型列表兼容性函数
// 返回传统的 map[string][]int 格式以保持向后兼容
func GetAPITypesByCategory() map[string][]int {
categories := GetAPITypes(true).([]APICategoryInfo)
result := make(map[string][]int)
for _, category := range categories {
var types []int
for _, typeInfo := range category.Types {
types = append(types, typeInfo.Type)
}
result[category.Name] = types
}
return result
}
// GetAPICategoriesInfo 获取完整的层次化分类信息
// 返回新的 []APICategoryInfo 格式,包含完整的类型名称信息
func GetAPICategoriesInfo() []APICategoryInfo {
return GetAPITypes(true).([]APICategoryInfo)
}

View File

@@ -10,15 +10,13 @@ import (
"gorm.io/gorm"
)
// ============================================================================
// 结构体定义
// ============================================================================
// App 应用表模型
// 用于管理应用程序的基本信息
// UUID 为应用的唯一标识符,自动生成
// Status 为应用状态1:启用 0:禁用默认为1
// Name 为应用名称
// Secret 为应用密钥用于API认证
// Version 为应用版本号
// CreatedAt/UpdatedAt 由 GORM 自动维护
type App struct {
// ID主键自增同时通过 json 标签保证前端接收为 id
ID uint `gorm:"primaryKey;comment:应用ID自增主键" json:"id"`
@@ -107,6 +105,10 @@ type App struct {
UpdatedAt time.Time `gorm:"comment:更新时间" json:"updated_at"`
}
// ============================================================================
// 结构体方法
// ============================================================================
// BeforeCreate 在创建记录前自动生成UUID和密钥
func (app *App) BeforeCreate(tx *gorm.DB) error {
if app.UUID == "" {

View File

@@ -9,14 +9,13 @@ import (
"gorm.io/gorm"
)
// ============================================================================
// 结构体定义
// ============================================================================
// Function 函数表模型
// 用于管理应用程序的函数代码
// UUID 为函数的唯一标识符,自动生成并转换为大写
// Alias 为函数别名,便于识别和管理
// Code 为函数代码内容
// Remark 为备注信息,用于描述函数用途
// CreatedAt/UpdatedAt 由 GORM 自动维护
type Function struct {
// ID主键自增
ID uint `gorm:"primaryKey;comment:函数ID自增主键" json:"id"`
@@ -44,6 +43,10 @@ type Function struct {
UpdatedAt time.Time `gorm:"comment:更新时间" json:"updated_at"`
}
// ============================================================================
// 结构体方法
// ============================================================================
// BeforeCreate 在创建记录前自动生成UUID和Number
func (function *Function) BeforeCreate(tx *gorm.DB) error {
// 生成UUID
@@ -59,4 +62,4 @@ func (function *Function) BeforeCreate(tx *gorm.DB) error {
// TableName 指定表名
func (Function) TableName() string {
return "functions"
}
}

View File

@@ -2,13 +2,13 @@ package models
import "time"
// ============================================================================
// 结构体定义
// ============================================================================
// Settings 系统设置表模型
// 用于存储应用的配置参数
// Name 为配置项名称,唯一索引
// Value 为配置项的值
// Description 为配置项描述说明
// CreatedAt/UpdatedAt 由 GORM 自动维护
type Settings struct {
ID uint `gorm:"primaryKey;comment:设置ID自增主键"`
Name string `gorm:"uniqueIndex;size:64;not null;comment:配置项名称,唯一索引"`

View File

@@ -1,31 +1,39 @@
package models
import (
"strings"
"time"
"github.com/google/uuid"
"gorm.io/gorm"
)
// User 用户表模型
// 说明PasswordSalt 使用 32 字节随机盐(以 16 进制存储为 64 个字符),因此列长度设置为 64
// 注意此表只存储普通用户管理员账号存储在settings表中
type User struct {
ID uint `gorm:"primaryKey;comment:用户ID自增主键"`
UUID string `gorm:"uniqueIndex;size:36;not null;comment:用户的唯一标识符" json:"uuid"`
Username string `gorm:"uniqueIndex;size:64;not null;comment:用户名,唯一索引"`
Password string `gorm:"size:255;not null;comment:密码哈希值"`
PasswordSalt string `gorm:"size:64;not null;comment:密码加密盐值"`
CreatedAt time.Time `gorm:"comment:创建时间"`
UpdatedAt time.Time `gorm:"comment:更新时间"`
}
// BeforeCreate 在创建记录前自动生成UUID
func (user *User) BeforeCreate(tx *gorm.DB) error {
// 生成UUID
if user.UUID == "" {
user.UUID = strings.ToUpper(uuid.New().String())
}
return nil
}
package models
import (
"strings"
"time"
"github.com/google/uuid"
"gorm.io/gorm"
)
// ============================================================================
// 结构体定义
// ============================================================================
// User 用户表模型
// 此表只存储普通用户管理员账号存储在settings表中
// CreatedAt/UpdatedAt 由 GORM 自动维护
type User struct {
ID uint `gorm:"primaryKey;comment:用户ID自增主键"`
UUID string `gorm:"uniqueIndex;size:36;not null;comment:用户的唯一标识符" json:"uuid"`
Username string `gorm:"uniqueIndex;size:64;not null;comment:用户名,唯一索引"`
Password string `gorm:"size:255;not null;comment:密码哈希值"`
PasswordSalt string `gorm:"size:64;not null;comment:密码加密盐值"`
CreatedAt time.Time `gorm:"comment:创建时间"`
UpdatedAt time.Time `gorm:"comment:更新时间"`
}
// ============================================================================
// 结构体方法
// ============================================================================
// BeforeCreate 在创建记录前自动生成UUID
func (user *User) BeforeCreate(tx *gorm.DB) error {
// 生成UUID
if user.UUID == "" {
user.UUID = strings.ToUpper(uuid.New().String())
}
return nil
}

View File

@@ -9,14 +9,13 @@ import (
"gorm.io/gorm"
)
// ============================================================================
// 结构体定义
// ============================================================================
// Variable 变量表模型
// 用于管理应用程序的变量数据
// UUID 为变量的唯一标识符,自动生成并转换为大写
// Alias 为变量别名,便于识别和管理
// Data 为变量数据内容
// Remark 为备注信息,用于描述变量用途
// CreatedAt/UpdatedAt 由 GORM 自动维护
type Variable struct {
// ID主键自增
ID uint `gorm:"primaryKey;comment:变量ID自增主键" json:"id"`
@@ -44,6 +43,10 @@ type Variable struct {
UpdatedAt time.Time `gorm:"comment:更新时间" json:"updated_at"`
}
// ============================================================================
// 结构体方法
// ============================================================================
// BeforeCreate 在创建记录前自动生成UUID和Number
func (variable *Variable) BeforeCreate(tx *gorm.DB) error {
// 生成UUID