feat: 新增sandbox-full支持

This commit is contained in:
FamousMai
2025-03-28 15:18:33 +08:00
parent ca19bd31d4
commit b5aa970766
869 changed files with 99420 additions and 6830 deletions
+36
View File
@@ -0,0 +1,36 @@
package common
import (
"database/sql/driver"
"encoding/json"
"errors"
)
type JSONMap map[string]interface{}
func (m JSONMap) Value() (driver.Value, error) {
if m == nil {
return nil, nil
}
return json.Marshal(m)
}
func (m *JSONMap) Scan(value interface{}) error {
if value == nil {
*m = make(map[string]interface{})
return nil
}
var err error
switch value.(type) {
case []byte:
err = json.Unmarshal(value.([]byte), m)
case string:
err = json.Unmarshal([]byte(value.(string)), m)
default:
err = errors.New("basetypes.JSONMap.Scan: invalid value type")
}
if err != nil {
return err
}
return nil
}
+7
View File
@@ -0,0 +1,7 @@
package common
type ClearDB struct {
TableName string
CompareField string
Interval string
}
@@ -0,0 +1,48 @@
package request
import (
"gorm.io/gorm"
)
// PageInfo Paging common input parameter structure
type PageInfo struct {
Page int `json:"page" form:"page"` // 页码
PageSize int `json:"pageSize" form:"pageSize"` // 每页大小
Keyword string `json:"keyword" form:"keyword"` // 关键字
}
func (r *PageInfo) Paginate() func(db *gorm.DB) *gorm.DB {
return func(db *gorm.DB) *gorm.DB {
if r.Page <= 0 {
r.Page = 1
}
switch {
case r.PageSize > 100:
r.PageSize = 100
case r.PageSize <= 0:
r.PageSize = 10
}
offset := (r.Page - 1) * r.PageSize
return db.Offset(offset).Limit(r.PageSize)
}
}
// GetById Find by id structure
type GetById struct {
ID int `json:"id" form:"id"` // 主键ID
}
func (r *GetById) Uint() uint {
return uint(r.ID)
}
type IdsReq struct {
Ids []int `json:"ids" form:"ids"`
}
// GetAuthorityId Get role by id structure
type GetAuthorityId struct {
AuthorityId uint `json:"authorityId" form:"authorityId"` // 角色ID
}
type Empty struct{}
@@ -0,0 +1,8 @@
package response
type PageResult struct {
List interface{} `json:"list"`
Total int64 `json:"total"`
Page int `json:"page"`
PageSize int `json:"pageSize"`
}
@@ -0,0 +1,63 @@
package response
import (
"net/http"
"github.com/gin-gonic/gin"
)
type Response struct {
Code int `json:"code"`
Data interface{} `json:"data"`
Msg string `json:"msg"`
}
const (
ERROR = 7
SUCCESS = 0
)
func Result(code int, data interface{}, msg string, c *gin.Context) {
// 开始时间
c.JSON(http.StatusOK, Response{
code,
data,
msg,
})
}
func Ok(c *gin.Context) {
Result(SUCCESS, map[string]interface{}{}, "操作成功", c)
}
func OkWithMessage(message string, c *gin.Context) {
Result(SUCCESS, map[string]interface{}{}, message, c)
}
func OkWithData(data interface{}, c *gin.Context) {
Result(SUCCESS, data, "成功", c)
}
func OkWithDetailed(data interface{}, message string, c *gin.Context) {
Result(SUCCESS, data, message, c)
}
func Fail(c *gin.Context) {
Result(ERROR, map[string]interface{}{}, "操作失败", c)
}
func FailWithMessage(message string, c *gin.Context) {
Result(ERROR, map[string]interface{}{}, message, c)
}
func NoAuth(message string, c *gin.Context) {
c.JSON(http.StatusUnauthorized, Response{
7,
nil,
message,
})
}
func FailWithDetailed(data interface{}, message string, c *gin.Context) {
Result(ERROR, data, message, c)
}
@@ -0,0 +1,24 @@
package example
import (
"github.com/flipped-aurora/gin-vue-admin/server/global"
)
// file struct, 文件结构体
type ExaFile struct {
global.GVA_MODEL
FileName string
FileMd5 string
FilePath string
ExaFileChunk []ExaFileChunk
ChunkTotal int
IsFinish bool
}
// file chunk struct, 切片结构体
type ExaFileChunk struct {
global.GVA_MODEL
ExaFileID uint
FileChunkNumber int
FileChunkPath string
}
@@ -0,0 +1,15 @@
package example
import (
"github.com/flipped-aurora/gin-vue-admin/server/global"
"github.com/flipped-aurora/gin-vue-admin/server/model/system"
)
type ExaCustomer struct {
global.GVA_MODEL
CustomerName string `json:"customerName" form:"customerName" gorm:"comment:客户名"` // 客户名
CustomerPhoneData string `json:"customerPhoneData" form:"customerPhoneData" gorm:"comment:客户手机号"` // 客户手机号
SysUserID uint `json:"sysUserId" form:"sysUserId" gorm:"comment:管理ID"` // 管理ID
SysUserAuthorityID uint `json:"sysUserAuthorityID" form:"sysUserAuthorityID" gorm:"comment:管理角色ID"` // 管理角色ID
SysUser system.SysUser `json:"sysUser" form:"sysUser" gorm:"comment:管理详情"` // 管理详情
}
@@ -0,0 +1,17 @@
package example
import (
"github.com/flipped-aurora/gin-vue-admin/server/global"
)
type ExaFileUploadAndDownload struct {
global.GVA_MODEL
Name string `json:"name" gorm:"comment:文件名"` // 文件名
Url string `json:"url" gorm:"comment:文件地址"` // 文件地址
Tag string `json:"tag" gorm:"comment:文件标签"` // 文件标签
Key string `json:"key" gorm:"comment:编号"` // 编号
}
func (ExaFileUploadAndDownload) TableName() string {
return "exa_file_upload_and_downloads"
}
@@ -0,0 +1,11 @@
package response
import "github.com/flipped-aurora/gin-vue-admin/server/model/example"
type FilePathResponse struct {
FilePath string `json:"filePath"`
}
type FileResponse struct {
File example.ExaFile `json:"file"`
}
@@ -0,0 +1,7 @@
package response
import "github.com/flipped-aurora/gin-vue-admin/server/model/example"
type ExaCustomerResponse struct {
Customer example.ExaCustomer `json:"customer"`
}
@@ -0,0 +1,7 @@
package response
import "github.com/flipped-aurora/gin-vue-admin/server/model/example"
type ExaFileResponse struct {
File example.ExaFileUploadAndDownload `json:"file"`
}
@@ -0,0 +1,48 @@
package gaia
import (
"github.com/goccy/go-json"
"github.com/gofrs/uuid/v5"
"github.com/richardlehane/msoleps/types"
"time"
)
type ForwardingExtend struct {
ID uuid.UUID `gorm:"column:id;type:uuid;primary_key;default:uuid_generate_v4()" json:"id"` // 唯一标识符
Path string `gorm:"column:path;type:varchar(255);not null" json:"path"` // 转发路径
Address string `gorm:"column:address;type:varchar(255);not null" json:"address"` // 转发地址
Header string `gorm:"column:header;type:text;not null;default:'[]'::text" json:"header"` // 请求头信息
Description string `gorm:"column:description;type:text;not null;default:''::character varying" json:"description"` // 描述信息
}
func (ForwardingExtend) TableName() string {
return "forwarding_extend"
}
type ForwardingAddressExtend struct {
ID uuid.UUID `gorm:"column:id;primary_key;type:uuid;default:uuid_generate_v4()" json:"id"` // 唯一标识符
ForwardingID uuid.UUID `gorm:"column:forwarding_id;type:uuid;not null" json:"forwarding_id"` // 转发ID
Path string `gorm:"column:path;type:varchar(255);not null" json:"path"` // 路径
Models string `gorm:"column:models;type:varchar(255);not null" json:"models"` // 模型
Description string `gorm:"column:description;type:text;default:''" json:"description"` // 描述
ContentType int `gorm:"column:content_type;type:integer;not null;default:0" json:"content_type"` // 内容类型
Billing string `gorm:"column:billing;type:text;default:'[]'" json:"billing"` // 计费信息
Status bool `gorm:"column:status;type:boolean;default:true" json:"status"` // 状态
}
func (ForwardingAddressExtend) TableName() string {
return "public.forwarding_address_extend"
}
type AccountLayoverRecordExtend struct {
ID uuid.UUID `gorm:"column:id;type:uuid;primary_key;default:uuid_generate_v4()" json:"id"` // 记录ID
AccountID uuid.UUID `gorm:"column:account_id;type:uuid;not null" json:"account_id"` // 账户ID
ForwardingID uuid.UUID `gorm:"column:forwarding_id;type:uuid;not null" json:"forwarding_id"` // 转发ID
Money types.Decimal `gorm:"column:money;type:numeric(16,7)" json:"money"` // 金额
Info json.RawMessage `gorm:"column:info;type:json" json:"info"` // 附加信息
CreatedAt time.Time `gorm:"column:created_at;type:timestamp(6);not null;default:CURRENT_TIMESTAMP" json:"created_at"` // 创建时间
}
func (AccountLayoverRecordExtend) TableName() string {
return "account_layover_record_extend"
}
+82
View File
@@ -0,0 +1,82 @@
package gaia
import (
"errors"
"github.com/flipped-aurora/gin-vue-admin/server/global"
"github.com/gofrs/uuid/v5"
"time"
)
const UserActive = "active" // 用户状态: 活跃
const UserPending = "pending" // 用户状态: 待办的
const UserUninitialized = "uninitialized" // 用户状态: 未初始化
const UserBanned = "banned" // 用户状态: 禁止
const UserClosed = "closed" // 用户状态: 关闭
const DefaultProviderType = "oauth2" // 默认提供者类型: oauth2
// Account gaia 用户表
type Account struct {
ID uuid.UUID `json:"id" gorm:"primaryKey;comment:账户唯一标识符"`
Name string `json:"name" gorm:"not null;comment:账户名称"`
Email string `json:"email" gorm:"not null;index:account_email_idx;comment:账户邮箱"`
Password string `json:"password" gorm:"comment:账户密码"`
PasswordSalt string `json:"password_salt" gorm:"comment:加密密码的盐值"`
Avatar string `json:"avatar" gorm:"comment:头像URL"`
InterfaceLanguage string `json:"interface_language" gorm:"comment:用户界面语言"`
InterfaceTheme string `json:"interface_theme" gorm:"comment:用户界面主题"`
Timezone string `json:"timezone" gorm:"comment:用户时区"`
LastLoginAt time.Time `json:"last_login_at" gorm:"comment:最后登录时间"`
LastLoginIP string `json:"last_login_ip" gorm:"comment:最后登录的IP地址"`
Status string `json:"status" gorm:"default:'active';not null;comment:账户状态"`
InitializedAt time.Time `json:"initialized_at" gorm:"comment:账户初始化时间"`
CreatedAt time.Time `json:"created_at" gorm:"not null;default:CURRENT_TIMESTAMP;comment:账户创建时间"`
UpdatedAt time.Time `json:"updated_at" gorm:"not null;default:CURRENT_TIMESTAMP;comment:账户更新时间"`
LastActiveAt time.Time `json:"last_active_at" gorm:"not null;default:CURRENT_TIMESTAMP;comment:最后活跃时间"`
}
// AccountIntegrate gaia 用户提供者关联表
type AccountIntegrate struct {
ID uuid.UUID `json:"id" gorm:"index;comment:唯一标识"`
AccountID uuid.UUID `json:"account_id" gorm:"not null;comment:账户ID"`
Provider string `json:"provider" gorm:"not null;comment:提供者类型"`
OpenID string `json:"open_id" gorm:"not null;comment:开放ID"`
EncryptedToken string `json:"encrypted_token" gorm:"not null;comment:加密令牌"`
CreatedAt time.Time `json:"created_at" gorm:"not null;comment:创建时间"`
UpdatedAt time.Time `json:"updated_at" gorm:"not null;comment:更新时间"`
}
// TenantAccountJoin gaia 用户和命名空间关联表
type TenantAccountJoin struct {
ID string `json:"id" gorm:"primary_key;comment:租户账户连接ID"`
TenantID string `json:"tenant_id" gorm:"not null;comment:租户ID"`
AccountID string `json:"account_id" gorm:"not null;comment:账户ID"`
Role string `json:"role" gorm:"not null;default:normal;comment:角色"`
InvitedBy *string `json:"invited_by" gorm:"comment:邀请人ID"`
CreatedAt time.Time `json:"created_at" gorm:"not null;default:CURRENT_TIMESTAMP;comment:创建时间"`
UpdatedAt time.Time `json:"updated_at" gorm:"not null;default:CURRENT_TIMESTAMP;comment:更新时间"`
Current bool `json:"current" gorm:"not null;default:false;comment:当前状态"`
}
// AccountDingTalkExtend gaia钉钉关联表
type AccountDingTalkExtend struct {
ID uuid.UUID `json:"id" gorm:"primaryKey;comment:账户唯一标识符"`
DingTalk string `json:"ding_talk" gorm:"index:account_ding_talk_idx;comment:关联钉钉id"`
}
func (Account) TableName() string { return "accounts" }
func (AccountIntegrate) TableName() string { return "account_integrates" }
func (TenantAccountJoin) TableName() string { return "tenant_account_joins" }
func (AccountDingTalkExtend) TableName() string { return "account_ding_talk_extend" }
// GetAccount
// @description: Get user information through the user provider relationship table
// @return account, err error
func (i Account) GetAccount(username string) (integrate AccountIntegrate, err error) {
// init
if err = global.GVA_DB.Where("account_id IN (?) AND provider=?",
[]string{i.ID.String(), username}, DefaultProviderType).First(&integrate).Error; err != nil {
return integrate, errors.New("the query for the user-provider relationship could not be found")
}
// return
return integrate, nil
}
@@ -0,0 +1,22 @@
// 自动生成模板AccountMoneyExtend
package gaia
import (
"github.com/gofrs/uuid/v5"
"time"
)
// accountMoneyExtend表 结构体 AccountMoneyExtend
type AccountMoneyExtend struct {
Id *string `json:"id" form:"id" gorm:"primarykey;column:id;comment:;"` //id字段
AccountId uuid.UUID `json:"accountId" form:"accountId" gorm:"uniqueIndex;column:account_id;comment:;"` //accountId字段
TotalQuota float64 `json:"totalQuota" form:"totalQuota" gorm:"column:total_quota;comment:;"` //totalQuota字段
UsedQuota float64 `json:"usedQuota" form:"usedQuota" gorm:"column:used_quota;comment:;"` //usedQuota字段
CreatedAt *time.Time `json:"createdAt" form:"createdAt" gorm:"column:created_at;comment:;size:6;"` //createdAt字段
UpdatedAt *time.Time `json:"updatedAt" form:"updatedAt" gorm:"column:updated_at;comment:;size:6;"` //updatedAt字段
}
// TableName accountMoneyExtend表 AccountMoneyExtend自定义表名 account_money_extend
func (AccountMoneyExtend) TableName() string {
return "account_money_extend"
}
+71
View File
@@ -0,0 +1,71 @@
package gaia
import (
"github.com/gofrs/uuid/v5"
"time"
)
type ApiTokens struct {
ID uuid.UUID `gorm:"column:id;type:uuid;primary_key;default:uuid_generate_v4()" json:"id"` // 主键ID
AppID uuid.UUID `gorm:"column:app_id;type:uuid" json:"app_id"` // 应用ID
Type string `gorm:"column:type;type:varchar(16);not null" json:"type"` // 令牌类型
Token string `gorm:"column:token;type:varchar(255);not null" json:"token"` // 令牌值
LastUsedAt *time.Time `gorm:"column:last_used_at;type:timestamp(6)" json:"last_used_at"` // 最后使用时间
CreatedAt time.Time `gorm:"column:created_at;type:timestamp(6);not null;default:CURRENT_TIMESTAMP" json:"created_at"` // 创建时间
TenantID uuid.UUID `gorm:"column:tenant_id;type:uuid" json:"tenant_id"` // 工作空间ID
}
func (*ApiTokens) TableName() string {
return "api_tokens"
}
func (a *ApiTokens) GenerateToken() string {
return a.Token[:3] + "..." + a.Token[len(a.Token)-23:]
}
type ApiTokenMoneyDailyStatExtend struct {
ID uuid.UUID `gorm:"column:id;type:uuid;primary_key;default:uuid_generate_v4()" json:"id"` // 主键ID
AppTokenID uuid.UUID `gorm:"column:app_token_id;type:uuid;not null" json:"app_token_id"` // 应用令牌ID
AccumulatedQuota float64 `gorm:"column:accumulated_quota;type:numeric(16,7)" json:"accumulated_quota"` // 累计配额
DayUsedQuota float64 `gorm:"column:day_used_quota;type:numeric(16,7)" json:"day_used_quota"` // 日使用配额
DayLimitQuota float64 `gorm:"column:day_limit_quota;type:numeric(16,7)" json:"day_limit_quota"` // 日限额配额
StatAt time.Time `gorm:"column:stat_at;type:timestamp(6);not null" json:"stat_at"` // 统计时间
CreatedAt time.Time `gorm:"column:created_at;type:timestamp(6);not null;default:CURRENT_TIMESTAMP" json:"created_at"` // 创建时间
UpdatedAt time.Time `gorm:"column:updated_at;type:timestamp(6);not null;default:CURRENT_TIMESTAMP" json:"updated_at"` // 更新时间
}
func (*ApiTokenMoneyDailyStatExtend) TableName() string {
return "api_token_money_daily_stat_extend"
}
type ApiTokenMoneyMonthlyStatExtend struct {
ID uuid.UUID `gorm:"column:id;type:uuid;primary_key;default:uuid_generate_v4()" json:"id"` // 主键ID
AppTokenID uuid.UUID `gorm:"column:app_token_id;type:uuid;not null" json:"app_token_id"` // 应用令牌ID
AccumulatedQuota float64 `gorm:"column:accumulated_quota;type:numeric(16,7)" json:"accumulated_quota"` // 累计配额
MonthUsedQuota float64 `gorm:"column:month_used_quota;type:numeric(16,7)" json:"month_used_quota"` // 月使用配额
MonthLimitQuota float64 `gorm:"column:month_limit_quota;type:numeric(16,7)" json:"month_limit_quota"` // 月限额配额
StatAt time.Time `gorm:"column:stat_at;type:timestamp(6);not null" json:"stat_at"` // 统计时间
CreatedAt time.Time `gorm:"column:created_at;type:timestamp(6);not null;default:CURRENT_TIMESTAMP" json:"created_at"` // 创建时间
UpdatedAt time.Time `gorm:"column:updated_at;type:timestamp(6);not null;default:CURRENT_TIMESTAMP" json:"updated_at"` // 更新时间
}
func (*ApiTokenMoneyMonthlyStatExtend) TableName() string {
return "api_token_money_monthly_stat_extend"
}
type ApiTokenMoneyExtend struct {
ID uuid.UUID `gorm:"column:id;type:uuid;primary_key;default:uuid_generate_v4()" json:"id"` // 主键ID
AppTokenID uuid.UUID `gorm:"column:app_token_id;type:uuid" json:"app_token_id"` // 应用令牌ID
AccumulatedQuota float64 `gorm:"column:accumulated_quota;type:numeric(16,7)" json:"accumulated_quota"` // 累计配额
DayUsedQuota float64 `gorm:"column:day_used_quota;type:numeric(16,7)" json:"day_used_quota"` // 日使用配额
MonthUsedQuota float64 `gorm:"column:month_used_quota;type:numeric(16,7)" json:"month_used_quota"` // 月使用配额
DayLimitQuota float64 `gorm:"column:day_limit_quota;type:numeric(16,7)" json:"day_limit_quota"` // 日限额配额
MonthLimitQuota float64 `gorm:"column:month_limit_quota;type:numeric(16,7)" json:"month_limit_quota"` // 月限额配额
IsDeleted bool `gorm:"column:is_deleted;type:bool;not null;default:false" json:"is_deleted"` // 是否删除
UpdatedAt time.Time `gorm:"column:updated_at;type:timestamp(6);not null;default:CURRENT_TIMESTAMP" json:"updated_at"` // 更新时间
CreatedAt time.Time `gorm:"column:created_at;type:timestamp(6);not null;default:CURRENT_TIMESTAMP" json:"created_at"` // 创建时间
Description string `gorm:"column:description;type:varchar(50)" json:"description"` // 描述
}
func (*ApiTokenMoneyExtend) TableName() string {
return "api_token_money_extend"
}
+48
View File
@@ -0,0 +1,48 @@
package gaia
import (
"github.com/gofrs/uuid/v5"
"time"
)
type Apps struct {
ID uuid.UUID `gorm:"column:id;type:uuid;primary_key;default:uuid_generate_v4()" json:"id"` // 应用ID
TenantID uuid.UUID `gorm:"column:tenant_id;type:uuid;not null" json:"tenant_id"` // 工作空间ID
Name string `gorm:"column:name;type:varchar(255);not null" json:"name"` // 应用名称
Mode string `gorm:"column:mode;type:varchar(255);not null" json:"mode"` // 应用模式
Icon string `gorm:"column:icon;type:varchar(255)" json:"icon"` // 应用图标
IconBackground string `gorm:"column:icon_background;type:varchar(255)" json:"icon_background"` // 应用图标背景
AppModelConfigID uuid.UUID `gorm:"column:app_model_config_id;type:uuid" json:"app_model_config_id"` // 应用模型配置ID
Status string `gorm:"column:status;type:varchar(255);not null;default:normal" json:"status"` // 应用状态
EnableSite bool `gorm:"column:enable_site;not null" json:"enable_site"` // 是否启用站点
EnableAPI bool `gorm:"column:enable_api;not null" json:"enable_api"` // 是否启用API
APIRPM int `gorm:"column:api_rpm;type:int4;not null;default:0" json:"api_rpm"` // API每分钟请求限制
APIRPH int `gorm:"column:api_rph;type:int4;not null;default:0" json:"api_rph"` // API每小时请求限制
IsDemo bool `gorm:"column:is_demo;not null;default:false" json:"is_demo"` // 是否为演示应用
IsPublic bool `gorm:"column:is_public;not null;default:false" json:"is_public"` // 是否为公开应用
CreatedAt time.Time `gorm:"column:created_at;type:timestamp(6);not null;default:CURRENT_TIMESTAMP(0)" json:"created_at"` // 创建时间
UpdatedAt time.Time `gorm:"column:updated_at;type:timestamp(6);not null;default:CURRENT_TIMESTAMP(0)" json:"updated_at"` // 更新时间
IsUniversal bool `gorm:"column:is_universal;not null;default:false" json:"is_universal"` // 是否为通用应用
WorkflowID uuid.UUID `gorm:"column:workflow_id;type:uuid" json:"workflow_id"` // 工作流ID
Description string `gorm:"column:description;type:text;not null;default:''" json:"description"` // 应用描述
Tracing string `gorm:"column:tracing;type:text" json:"tracing"` // 追踪信息
MaxActiveRequests int `gorm:"column:max_active_requests;type:int4" json:"max_active_requests"` // 最大活跃请求数
IconType string `gorm:"column:icon_type;type:varchar(255)" json:"icon_type"` // 图标类型
CreatedBy uuid.UUID `gorm:"column:created_by;type:uuid" json:"created_by"` // 创建者ID
UpdatedBy uuid.UUID `gorm:"column:updated_by;type:uuid" json:"updated_by"` // 更新者ID
UseIconAsAnswerIcon bool `gorm:"column:use_icon_as_answer_icon;not null;default:false" json:"use_icon_as_answer_icon"` // 是否使用图标作为回答图标
}
func (Apps) TableName() string {
return "apps"
}
type AppStatisticsExtend struct {
ID uuid.UUID `gorm:"column:id;type:uuid;primary_key;default:uuid_generate_v4()" json:"id"` // 唯一标识符
AppID uuid.UUID `gorm:"column:app_id;type:uuid;not null" json:"app_id"` // 应用ID
Number int `gorm:"column:number;type:integer;not null" json:"number"` // 统计数量
}
func (AppStatisticsExtend) TableName() string {
return "app_statistics_extend"
}
+22
View File
@@ -0,0 +1,22 @@
package gaia
import "time"
const IndirectAccessUser = "end_user"
const UserUsingApiRequest = "service_api"
const UsernameUsingApiRequest = "gaia_test_api_user"
type EndUser struct {
ID string `json:"id" gorm:"primary_key;comment:用户唯一标识"`
TenantID string `json:"tenant_id" gorm:"comment:租户唯一标识"`
AppID string `json:"app_id" gorm:"comment:应用唯一标识"` // 使用指针允许该字段为NULL
Type string `json:"type" gorm:"comment:用户类型"`
ExternalUserID string `json:"external_user_id" gorm:"comment:外部用户唯一标识"` // 使用指针允许该字段为NULL
Name string `json:"name" gorm:"comment:用户名称"` // 使用指针允许该字段为NULL
IsAnonymous bool `json:"is_anonymous" gorm:"comment:是否匿名"`
SessionID string `json:"session_id" gorm:"comment:会话唯一标识"`
CreatedAt time.Time `json:"created_at" gorm:"comment:创建时间"`
UpdatedAt time.Time `json:"updated_at" gorm:"comment:更新时间"`
}
func (EndUser) TableName() string { return "end_users" }
+46
View File
@@ -0,0 +1,46 @@
package gaia
import (
"github.com/gofrs/uuid/v5"
"time"
)
const ChatRequestTypeApi = "api" // 聊天请求类型为api
const MessagesSucceeded = "normal" // 聊天状态成功
type Messages struct {
ID uuid.UUID `gorm:"column:id;primary_key;default:uuid_generate_v4()" json:"id"` // 消息ID
AppID uuid.UUID `gorm:"column:app_id;not null" json:"app_id"` // 应用ID
ModelProvider string `gorm:"column:model_provider" json:"model_provider"` // 模型提供商
ModelID string `gorm:"column:model_id" json:"model_id"` // 模型ID
OverrideModelConfigs string `gorm:"column:override_model_configs" json:"override_model_configs"` // 覆盖模型配置
ConversationID uuid.UUID `gorm:"column:conversation_id;not null" json:"conversation_id"` // 对话ID
Inputs string `gorm:"column:inputs" json:"inputs"` // 输入数据
Query string `gorm:"column:query;not null" json:"query"` // 查询内容
Message string `gorm:"column:message;not null" json:"message"` // 消息内容
MessageTokens int `gorm:"column:message_tokens;not null;default:0" json:"message_tokens"` // 消息令牌数
MessageUnitPrice float64 `gorm:"column:message_unit_price;not null" json:"message_unit_price"` // 消息单价
Answer string `gorm:"column:answer;not null" json:"answer"` // 回答内容
AnswerTokens int `gorm:"column:answer_tokens;not null;default:0" json:"answer_tokens"` // 回答令牌数
AnswerUnitPrice float64 `gorm:"column:answer_unit_price;not null" json:"answer_unit_price"` // 回答单价
ProviderResponseLatency float64 `gorm:"column:provider_response_latency;not null;default:0" json:"provider_response_latency"` // 提供商响应延迟
TotalPrice float64 `gorm:"column:total_price" json:"total_price"` // 总价格
Currency string `gorm:"column:currency;not null" json:"currency"` // 货币
FromSource string `gorm:"column:from_source;not null" json:"from_source"` // 来源
FromEndUserID uuid.UUID `gorm:"column:from_end_user_id" json:"from_end_user_id"` // 来自最终用户ID
FromAccountID uuid.UUID `gorm:"column:from_account_id" json:"from_account_id"` // 来自账户ID
CreatedAt time.Time `gorm:"column:created_at;not null;default:CURRENT_TIMESTAMP" json:"created_at"` // 创建时间
UpdatedAt time.Time `gorm:"column:updated_at;not null;default:CURRENT_TIMESTAMP" json:"updated_at"` // 更新时间
AgentBased bool `gorm:"column:agent_based;not null;default:false" json:"agent_based"` // 是否基于代理
MessagePriceUnit float64 `gorm:"column:message_price_unit;not null;default:0.001" json:"message_price_unit"` // 消息价格单位
AnswerPriceUnit float64 `gorm:"column:answer_price_unit;not null;default:0.001" json:"answer_price_unit"` // 回答价格单位
WorkflowRunID uuid.UUID `gorm:"column:workflow_run_id" json:"workflow_run_id"` // 工作流运行ID
Status string `gorm:"column:status;not null;default:normal" json:"status"` // 状态
Error string `gorm:"column:error" json:"error"` // 错误信息
MessageMetadata string `gorm:"column:message_metadata" json:"message_metadata"` // 消息元数据
InvokeFrom string `gorm:"column:invoke_from" json:"invoke_from"` // 调用来源
}
func (Messages) TableName() string {
return "messages"
}
@@ -0,0 +1,36 @@
package request
import (
"github.com/flipped-aurora/gin-vue-admin/server/model/common/request"
"time"
)
type DashboardSearch struct {
request.PageInfo
}
type GetAccountQuotaRankingDataReq struct {
request.PageInfo
}
// GetAppQuotaRankingDataReq 获取应用配额排名数据
type GetAppQuotaRankingDataReq struct {
request.PageInfo
}
// GetAppTokenQuotaRankingDataReq 获取应用配额排名数据
type GetAppTokenQuotaRankingDataReq struct {
request.PageInfo
}
type GetAppTokenDailyQuotaDataReq struct {
request.PageInfo
AppId string `json:"app_id" form:"app_id"` // 应用ID
StatAt time.Time `json:"stat_at" form:"stat_at"` // 统计时间
}
// GetAiImageQuotaRankingDataReq 获取AI图片使用量排名数据
type GetAiImageQuotaRankingDataReq struct {
request.PageInfo
StatAt time.Time `json:"stat_at" form:"stat_at"` // 统计时间
}
+6
View File
@@ -0,0 +1,6 @@
package request
type SetUserQuotaRequest struct {
Uid string `json:"uid" form:"uid"` // 用户id
Quota float64 `json:"quota" form:"quota"` // 额度
}
@@ -0,0 +1,11 @@
package request
import (
"github.com/flipped-aurora/gin-vue-admin/server/model/common/request"
)
type TenantsSearch struct{
request.PageInfo
}
+39
View File
@@ -0,0 +1,39 @@
package request
import "github.com/flipped-aurora/gin-vue-admin/server/model/common/request"
const GetAppRequestFilterSuccess = 1 // 筛选成功
const GetAppRequestFilterFailure = 2 // 筛选失败
const PostgreSQLDataLimit = 1000 // 查询数据限制
const PostgreSQLDataTypeUUID = "uuid" // uuid类型
const PostgreSQLDataTypeCharacterVarying = "character varying" // 可变字符类型
const PostgreSQLDataTypeText = "text" // 文本类型
const PostgreSQLDataTypeJSON = "json" // JSON类型
const PostgreSQLDataTypeInteger = "integer" // 整数类型
const PostgreSQLDataTypeDoublePrecision = "double precision" // 双精度浮点数类型
const PostgreSQLDataTypeNumeric = "numeric" // 数值类型
const PostgreSQLDataTypeTimestampWithoutTZ = "timestamp without time zone" // 不带时区的时间戳类型
const PostgreSQLDataTypeBoolean = "boolean" // 布尔类型
const PostgreSQLDefaultSchema = "public" // 默认环境
// SyncDatabaseTableData 同步数据库表数据
type SyncDatabaseTableData struct {
LogTable string `json:"log_table" form:"log_table" gorm:"comment:旧表"`
NewTable string `json:"new_table" form:"new_table" gorm:"comment:要同步数据到的旧表"`
KeyName string `json:"key_name" form:"key_name" gorm:"comment:表主键名"`
OrderName string `json:"order_name" form:"order_name" gorm:"comment:排序索引名"`
GroupName string `json:"group_name" form:"group_name" gorm:"comment:表分组名(可为空)"`
}
type GetAppRequestTestRequest struct {
request.PageInfo
Apps []string `json:"apps[]" form:"apps[]" gorm:"comment:检索app"`
Status uint `json:"status" form:"status" gorm:"index;comment:状态"`
BatchId uint `json:"batch_id" form:"batch_id" gorm:"index;comment:批次ID"`
}
type DatabaseTableColumn struct {
ColumnName string `json:"column_name" form:"column_name" gorm:"comment:列名"`
DataType string `json:"data_type" form:"data_type" gorm:"comment:数据类型"`
IsNullable bool `json:"is_nullable" form:"is_nullable" gorm:"comment:是否为空"`
}
@@ -0,0 +1,51 @@
package response
// GetAccountQuotaRankingDataRes 获取账户配额排名数据的响应结构
type GetAccountQuotaRankingDataRes struct {
Ranking int `json:"ranking"` // 排名
Name string `json:"name"` // 姓名
UsedQuota float64 `json:"used_quota"` // 已使用配额
TotalQuota float64 `json:"total_quota"` // 总配额
}
// GetAppQuotaRankingDataRes 获取应用配额排名数据的响应结构
type GetAppQuotaRankingDataRes struct {
Ranking int `json:"ranking"` // 排名
Name string `json:"name"` // 应用名称
Mode string `json:"mode"` // 应用类型
AccountName string `json:"account_name"` // 账号名称
UsedQuota float64 `json:"used_quota"` // 已使用配额
AppID string `json:"app_id"`
TotalCost float64 `json:"total_cost"`
MessageCost float64 `json:"message_cost"`
WorkflowCost float64 `json:"workflow_cost"`
RecordNum float64 `json:"record_num"`
UseNum int `json:"use_num"`
}
// GetAppTokenQuotaRankingDataRes 获取应用密钥配额排名数据的响应结构
type GetAppTokenQuotaRankingDataRes struct {
Ranking int `json:"ranking"` // 排名
Name string `json:"name"` // 对应应用名称
AppToken string `json:"app_token"` // 密钥(需要加密显示)
AccumulatedQuota float64 `json:"accumulated_quota"` // 累计使用
DayUsedQuota float64 `json:"day_used_quota"` // 日使用
MonthUsedQuota float64 `json:"month_used_quota"` // 月使用
DayLimitQuota float64 `json:"day_limit_quota"` // 日限额
MonthLimitQuota float64 `json:"month_limit_quota"` // 月限额
}
type GetAppTokenDailyQuotaDataRes struct {
StatDate string `json:"stat_date"`
TotalUsed float64 `json:"total_used"`
}
// GetAiImageQuotaRankingRes 获取AI图片配额排名数据的响应结构
type GetAiImageQuotaRankingRes struct {
Ranking int `json:"ranking"` // 排名
Address string `json:"address"` // 域名
Path string `json:"path"` // 路径
Model string `json:"model"` // 模型
TotalCost float64 `json:"total_cost"` // 总花费
RecordNum int `json:"record_num"` // 调用次数
}
@@ -0,0 +1,9 @@
package response
type GetQuotaManagementDataResponse struct {
Uid string `json:"uid"` // 用户id
Ranking int `json:"ranking"` // 排名
Name string `json:"name"` // 姓名
UsedQuota float64 `json:"used_quota"` // 已使用配额
TotalQuota float64 `json:"total_quota"` // 总配额
}
+12
View File
@@ -0,0 +1,12 @@
package response
type GetAppRequestTestDataResponse struct {
Name string `json:"name" gorm:"comment:应用名"`
Status bool `json:"status" gorm:"comment:状态"`
Inputs string `json:"inputs" gorm:"comment:输入"`
Outputs string `json:"outputs" gorm:"comment:输出"`
Error string `json:"error" gorm:"comment:错误信息"`
Comparison string `json:"comparison" gorm:"comment:历史对照"`
LogTime float64 `json:"log_time" gorm:"not null;default:0;comment:旧耗时"`
ElapsedTime float64 `json:"elapsed_time" gorm:"not null;default:0;comment:耗时"`
}
@@ -0,0 +1,23 @@
package gaia
const SystemIntegrationDingTalk = uint(1) // 钉钉集成
const SystemIntegrationWeiXin = uint(2) // 微信集成
const SystemIntegrationFeiShu = uint(3) // 飞书集成
// SystemIntegration 系统集成表
type SystemIntegration struct {
Id uint `json:"id" form:"id" gorm:"primarykey;column:id;comment:id;"`
Classify uint `json:"classify" gorm:"column:classify;default:1;comment:集成类型"`
Status bool `json:"status" gorm:"column:status;default:f;comment:配置启用状态"`
CorpID string `json:"corp_id" gorm:"default:;comment:企业id"`
AgentID string `json:"agent_id" gorm:"default:;comment:代理Id"`
AppID string `json:"app_id" gorm:"default:;comment:应用ID"`
AppKey string `json:"app_key" gorm:"default:;comment:加密key"`
AppSecret string `json:"app_secret" gorm:"default:;comment:加密密钥"`
Test bool `json:"test" gorm:"default:0;comment:是否测试链接联通性"`
}
// TableName system_integration_extend表 SystemIntegration自定义表名 system_integration_extend
func (SystemIntegration) TableName() string {
return "system_integration_extend"
}
+48
View File
@@ -0,0 +1,48 @@
// 自动生成模板Tenants
package gaia
import (
"github.com/flipped-aurora/gin-vue-admin/server/global"
"github.com/gofrs/uuid/v5"
"time"
)
// tenants表 结构体 Tenants
type Tenants struct {
Id string `gorm:"column:id;type:uuid;primary_key;default:uuid_generate_v4()" json:"id"` // 工作空间唯一标识
Name string `gorm:"column:name;type:varchar(255);not null" json:"name"` // 工作空间名称
EncryptPublicKey string `gorm:"column:encrypt_public_key;type:text" json:"encrypt_public_key"` // 加密公钥
Plan string `gorm:"column:plan;type:varchar(255);not null;default:basic" json:"plan"` // 套餐类型
Status string `gorm:"column:status;type:varchar(255);not null;default:normal" json:"status"` // 工作空间状态
CreatedAt time.Time `gorm:"column:created_at;type:timestamp(6);not null;default:CURRENT_TIMESTAMP" json:"created_at"` // 创建时间
UpdatedAt time.Time `gorm:"column:updated_at;type:timestamp(6);not null;default:CURRENT_TIMESTAMP" json:"updated_at"` // 更新时间
CustomConfig string `gorm:"column:custom_config;type:text" json:"custom_config"` // 自定义配置
}
func (*Tenants) TableName() string {
return "tenants"
}
func (t *Tenants) GetSuperAdminTenantId() string {
err := global.GVA_DB.Order("created_at ASC").First(&t).Error
if err != nil {
global.GVA_LOG.Error("GetSuperAdminTenantId gaia表查询失败,原因: " + err.Error())
return ""
}
return t.Id
}
type TenantAccountJoins struct {
ID uuid.UUID `gorm:"column:id;type:uuid;primary_key;default:uuid_generate_v4()" json:"id"` // 唯一标识符
TenantID uuid.UUID `gorm:"column:tenant_id;type:uuid;not null" json:"tenant_id"` // 工作空间ID
AccountID uuid.UUID `gorm:"column:account_id;type:uuid;not null" json:"account_id"` // 账户ID
Role string `gorm:"column:role;type:varchar(16);not null;default:normal" json:"role"` // 角色
InvitedBy uuid.UUID `gorm:"column:invited_by;type:uuid" json:"invited_by"` // 邀请人ID
CreatedAt time.Time `gorm:"column:created_at;type:timestamp(6);not null;default:CURRENT_TIMESTAMP" json:"created_at"` // 创建时间
UpdatedAt time.Time `gorm:"column:updated_at;type:timestamp(6);not null;default:CURRENT_TIMESTAMP" json:"updated_at"` // 更新时间
Current bool `gorm:"column:current;type:bool;not null;default:false" json:"current"` // 是否当前
}
func (TenantAccountJoins) TableName() string {
return "tenant_account_joins"
}
+34
View File
@@ -0,0 +1,34 @@
package gaia
const TestDefaultNumber = 2 // 默认测试执行次数
const BatchStatusInProgress = 1 // 批次状态:执行中
const BatchStatusCompleted = 2 // 批次状态:已结束
// AppRequestTest APP请求测试表
type AppRequestTest struct {
ID uint `json:"id" gorm:"primarykey;comment:主键"`
AppID string `json:"app_id" gorm:"index;comment:应用ID"`
BatchId uint `json:"batch_id" gorm:"index;comment:批次ID"`
Status string `json:"status" gorm:"index;comment:状态"`
Inputs string `json:"inputs" gorm:"comment:输入"`
Outputs string `json:"outputs" gorm:"comment:输出"`
Error string `json:"error" gorm:"comment:错误信息"`
Comparison string `json:"comparison" gorm:"comment:历史对照"`
LogTime float64 `json:"log_time" gorm:"not null;default:0;comment:旧耗时"`
ElapsedTime float64 `json:"elapsed_time" gorm:"not null;default:0;comment:耗时"`
}
// AppRequestTestBatch APP请求测试批次表
type AppRequestTestBatch struct {
ID uint `json:"id" gorm:"primarykey;comment:主键"`
Status uint `json:"status" gorm:"index;comment:状态"`
App uint `json:"app" gorm:"comment:app测试数"`
Sum uint `json:"sum" gorm:"comment:累计测试数"`
CreateTime int64 `json:"create_time" gorm:"comment:创建时间"`
EndTime int64 `json:"end_time" gorm:"comment:结束时间"`
SuccessCount uint `json:"success_count" gorm:"comment:成功数"`
FailureCount uint `json:"failure_count" gorm:"comment:失败数"`
}
func (AppRequestTest) TableName() string { return "app_request_tests_extend" }
func (AppRequestTestBatch) TableName() string { return "app_request_test_batches_extend" }
@@ -0,0 +1,32 @@
package gaia
import (
"github.com/gofrs/uuid/v5"
"time"
)
type WorkflowNodeExecutions struct {
ID uuid.UUID `gorm:"column:id;primaryKey" json:"id"` // 唯一标识
TenantID uuid.UUID `gorm:"column:tenant_id" json:"tenant_id"` // 工作空间ID
AppID uuid.UUID `gorm:"column:app_id" json:"app_id"` // 应用ID
WorkflowID uuid.UUID `gorm:"column:workflow_id" json:"workflow_id"` // 工作流ID
TriggeredFrom string `gorm:"column:triggered_from" json:"triggered_from"` // 触发来源
WorkflowRunID *uuid.UUID `gorm:"column:workflow_run_id" json:"workflow_run_id"` // 工作流运行ID
Index int `gorm:"column:index" json:"index"` // 索引
PredecessorNodeID *string `gorm:"column:predecessor_node_id" json:"predecessor_node_id"` // 前置节点ID
NodeID string `gorm:"column:node_id" json:"node_id"` // 节点ID
NodeType string `gorm:"column:node_type" json:"node_type"` // 节点类型
Title string `gorm:"column:title" json:"title"` // 标题
Inputs *string `gorm:"column:inputs" json:"inputs"` // 输入数据
ProcessData *string `gorm:"column:process_data" json:"process_data"` // 处理数据
Outputs *string `gorm:"column:outputs" json:"outputs"` // 输出数据
Status string `gorm:"column:status" json:"status"` // 状态
Error *string `gorm:"column:error" json:"error"` // 错误信息
ElapsedTime float64 `gorm:"column:elapsed_time" json:"elapsed_time"` // 执行耗时
ExecutionMetadata *string `gorm:"column:execution_metadata" json:"execution_metadata"` // 执行元数据
CreatedAt time.Time `gorm:"column:created_at" json:"created_at"` // 创建时间
CreatedByRole string `gorm:"column:created_by_role" json:"created_by_role"` // 创建者角色
CreatedBy uuid.UUID `gorm:"column:created_by" json:"created_by"` // 创建者ID
FinishedAt *time.Time `gorm:"column:finished_at" json:"finished_at"` // 完成时间
NodeExecutionID *string `gorm:"column:node_execution_id" json:"node_execution_id"` // 节点执行ID
}
+32
View File
@@ -0,0 +1,32 @@
package gaia
import "time"
const WorkflowSucceeded = "succeeded" // 工作流状态成功
const WorkflowRunning = "running" // 工作流状态运行中
// WorkflowRun 工作流运行
type WorkflowRun struct {
ID string `json:"id" gorm:"index;comment:工作流运行ID"`
TenantID string `json:"tenant_id" gorm:"not null;comment:租户ID"`
AppID string `json:"app_id" gorm:"not null;comment:应用ID"`
SequenceNumber int `json:"sequence_number" gorm:"not null;comment:序列号"`
WorkflowID string `json:"workflow_id" gorm:"not null;comment:工作流ID"`
Type string `json:"type" gorm:"not null;comment:类型"`
TriggeredFrom string `json:"triggered_from" gorm:"not null;comment:触发来源"`
Version string `json:"version" gorm:"not null;comment:版本"`
Graph string `json:"graph" gorm:"comment:图形表示"`
Inputs string `json:"inputs" gorm:"comment:输入"`
Status string `json:"status" gorm:"not null;comment:状态"`
Outputs string `json:"outputs" gorm:"comment:输出"`
Error string `json:"error" gorm:"comment:错误信息"`
ElapsedTime float64 `json:"elapsed_time" gorm:"not null;default:0;comment:耗时"`
TotalTokens int `json:"total_tokens" gorm:"not null;default:0;comment:总令牌数"`
TotalSteps int `json:"total_steps" gorm:"default:0;comment:总步骤数"`
CreatedByRole string `json:"created_by_role" gorm:"not null;comment:创建者角色"`
CreatedBy string `json:"created_by" gorm:"not null;comment:创建者ID"`
CreatedAt time.Time `json:"created_at" gorm:"not null;default:CURRENT_TIMESTAMP(0);comment:创建时间"`
FinishedAt time.Time `json:"finished_at" gorm:"comment:完成时间"`
}
func (WorkflowRun) TableName() string { return "workflow_runs" }
+33
View File
@@ -0,0 +1,33 @@
package request
import (
"github.com/gofrs/uuid/v5"
jwt "github.com/golang-jwt/jwt/v4"
)
// Custom claims structure
type CustomClaims struct {
BaseClaims
BufferTime int64
jwt.RegisteredClaims
// Extend Start: add gaia token
UserId string `json:"user_id"`
Exp int64 `json:"exp"`
Sub string `json:"sub"`
Email string `json:"email,omitempty"`
// Extend Start: add gaia token
}
type BaseClaims struct {
UUID uuid.UUID
ID uint
Username string
NickName string
AuthorityId uint
// Extend Start: add gaia token
UserId string `json:"user_id,omitempty"`
Exp int64 `json:"exp,omitempty"`
Email string `json:"email,omitempty"`
Sub string `json:"sub,omitempty"`
// Extend Start: add gaia token
}
@@ -0,0 +1,5 @@
package request
type OaLoginReq struct {
AuthorizeCode string `json:"authorize_code" form:"authorize_code"` // OA返回的授权验证码,用于请求用户信息
}
@@ -0,0 +1,14 @@
package request
import (
"github.com/flipped-aurora/gin-vue-admin/server/model/common/request"
"github.com/flipped-aurora/gin-vue-admin/server/model/system"
)
// api分页条件查询及排序结构体
type SearchApiParams struct {
system.SysApi
request.PageInfo
OrderKey string `json:"orderKey"` // 排序
Desc bool `json:"desc"` // 排序方式:升序false(默认)|降序true
}
@@ -0,0 +1,7 @@
package request
type SysAuthorityBtnReq struct {
MenuID uint `json:"menuID"`
AuthorityId uint `json:"authorityId"`
Selected []uint `json:"selected"`
}
@@ -0,0 +1,282 @@
package request
import (
"encoding/json"
"fmt"
"github.com/flipped-aurora/gin-vue-admin/server/global"
model "github.com/flipped-aurora/gin-vue-admin/server/model/system"
"github.com/pkg/errors"
"go/token"
"strings"
)
type AutoCode struct {
Package string `json:"package"`
PackageT string `json:"-"`
TableName string `json:"tableName" example:"表名"` // 表名
BusinessDB string `json:"businessDB" example:"业务数据库"` // 业务数据库
StructName string `json:"structName" example:"Struct名称"` // Struct名称
PackageName string `json:"packageName" example:"文件名称"` // 文件名称
Description string `json:"description" example:"Struct中文名称"` // Struct中文名称
Abbreviation string `json:"abbreviation" example:"Struct简称"` // Struct简称
HumpPackageName string `json:"humpPackageName" example:"go文件名称"` // go文件名称
GvaModel bool `json:"gvaModel" example:"false"` // 是否使用gva默认Model
AutoMigrate bool `json:"autoMigrate" example:"false"` // 是否自动迁移表结构
AutoCreateResource bool `json:"autoCreateResource" example:"false"` // 是否自动创建资源标识
AutoCreateApiToSql bool `json:"autoCreateApiToSql" example:"false"` // 是否自动创建api
AutoCreateMenuToSql bool `json:"autoCreateMenuToSql" example:"false"` // 是否自动创建menu
AutoCreateBtnAuth bool `json:"autoCreateBtnAuth" example:"false"` // 是否自动创建按钮权限
OnlyTemplate bool `json:"onlyTemplate" example:"false"` // 是否只生成模板
IsAdd bool `json:"isAdd" example:"false"` // 是否新增
Fields []*AutoCodeField `json:"fields"`
Module string `json:"-"`
DictTypes []string `json:"-"`
PrimaryField *AutoCodeField `json:"primaryField"`
DataSourceMap map[string]*DataSource `json:"-"`
HasPic bool `json:"-"`
HasFile bool `json:"-"`
HasTimer bool `json:"-"`
NeedSort bool `json:"-"`
NeedJSON bool `json:"-"`
HasRichText bool `json:"-"`
HasDataSource bool `json:"-"`
HasSearchTimer bool `json:"-"`
HasArray bool `json:"-"`
HasExcel bool `json:"-"`
}
type DataSource struct {
DBName string `json:"dbName"`
Table string `json:"table"`
Label string `json:"label"`
Value string `json:"value"`
Association int `json:"association"` // 关联关系 1 一对一 2 一对多
HasDeletedAt bool `json:"hasDeletedAt"`
}
func (r *AutoCode) Apis() []model.SysApi {
return []model.SysApi{
{
Path: "/" + r.Abbreviation + "/" + "create" + r.StructName,
Description: "新增" + r.Description,
ApiGroup: r.Description,
Method: "POST",
},
{
Path: "/" + r.Abbreviation + "/" + "delete" + r.StructName,
Description: "删除" + r.Description,
ApiGroup: r.Description,
Method: "DELETE",
},
{
Path: "/" + r.Abbreviation + "/" + "delete" + r.StructName + "ByIds",
Description: "批量删除" + r.Description,
ApiGroup: r.Description,
Method: "DELETE",
},
{
Path: "/" + r.Abbreviation + "/" + "update" + r.StructName,
Description: "更新" + r.Description,
ApiGroup: r.Description,
Method: "PUT",
},
{
Path: "/" + r.Abbreviation + "/" + "find" + r.StructName,
Description: "根据ID获取" + r.Description,
ApiGroup: r.Description,
Method: "GET",
},
{
Path: "/" + r.Abbreviation + "/" + "get" + r.StructName + "List",
Description: "获取" + r.Description + "列表",
ApiGroup: r.Description,
Method: "GET",
},
}
}
func (r *AutoCode) Menu(template string) model.SysBaseMenu {
component := fmt.Sprintf("view/%s/%s/%s.vue", r.Package, r.PackageName, r.PackageName)
if template != "package" {
component = fmt.Sprintf("plugin/%s/view/%s.vue", r.Package, r.PackageName)
}
return model.SysBaseMenu{
ParentId: 0,
Path: r.Abbreviation,
Name: r.Abbreviation,
Component: component,
Meta: model.Meta{
Title: r.Description,
},
}
}
// Pretreatment 预处理
// Author [SliverHorn](https://github.com/SliverHorn)
func (r *AutoCode) Pretreatment() error {
r.Module = global.GVA_CONFIG.AutoCode.Module
if token.IsKeyword(r.Abbreviation) {
r.Abbreviation = r.Abbreviation + "_"
} // go 关键字处理
if strings.HasSuffix(r.HumpPackageName, "test") {
r.HumpPackageName = r.HumpPackageName + "_"
} // test
length := len(r.Fields)
dict := make(map[string]string, length)
r.DataSourceMap = make(map[string]*DataSource, length)
for i := 0; i < length; i++ {
if r.Fields[i].Excel {
r.HasExcel = true
}
if r.Fields[i].DictType != "" {
dict[r.Fields[i].DictType] = ""
}
if r.Fields[i].Sort {
r.NeedSort = true
}
switch r.Fields[i].FieldType {
case "file":
r.HasFile = true
r.NeedJSON = true
case "json":
r.NeedJSON = true
case "array":
r.NeedJSON = true
r.HasArray = true
case "video":
r.HasPic = true
case "richtext":
r.HasRichText = true
case "picture":
r.HasPic = true
case "pictures":
r.HasPic = true
r.NeedJSON = true
case "time.Time":
r.HasTimer = true
if r.Fields[i].FieldSearchType != "" {
r.HasSearchTimer = true
}
}
if r.Fields[i].DataSource != nil {
if r.Fields[i].DataSource.Table != "" && r.Fields[i].DataSource.Label != "" && r.Fields[i].DataSource.Value != "" {
r.HasDataSource = true
r.Fields[i].CheckDataSource = true
r.DataSourceMap[r.Fields[i].FieldJson] = r.Fields[i].DataSource
}
}
if !r.GvaModel && r.PrimaryField == nil && r.Fields[i].PrimaryKey {
r.PrimaryField = r.Fields[i]
} // 自定义主键
}
{
for key := range dict {
r.DictTypes = append(r.DictTypes, key)
}
} // DictTypes => 字典
{
if r.GvaModel {
r.PrimaryField = &AutoCodeField{
FieldName: "ID",
FieldType: "uint",
FieldDesc: "ID",
FieldJson: "ID",
DataTypeLong: "20",
Comment: "主键ID",
ColumnName: "id",
}
}
} // GvaModel
{
if r.IsAdd && r.PrimaryField == nil {
r.PrimaryField = new(AutoCodeField)
}
} // 新增字段模式下不关注主键
if r.Package == "" {
return errors.New("Package为空!")
} // 增加判断:Package不为空
packages := []rune(r.Package)
if len(packages) > 0 {
if packages[0] >= 97 && packages[0] <= 122 {
packages[0] = packages[0] - 32
}
r.PackageT = string(packages)
} // PackageT 是 Package 的首字母大写
return nil
}
func (r *AutoCode) History() SysAutoHistoryCreate {
bytes, _ := json.Marshal(r)
return SysAutoHistoryCreate{
Table: r.TableName,
Package: r.Package,
Request: string(bytes),
StructName: r.StructName,
BusinessDB: r.BusinessDB,
Description: r.Description,
}
}
type AutoCodeField struct {
FieldName string `json:"fieldName"` // Field名
FieldDesc string `json:"fieldDesc"` // 中文名
FieldType string `json:"fieldType"` // Field数据类型
FieldJson string `json:"fieldJson"` // FieldJson
DataTypeLong string `json:"dataTypeLong"` // 数据库字段长度
Comment string `json:"comment"` // 数据库字段描述
ColumnName string `json:"columnName"` // 数据库字段
FieldSearchType string `json:"fieldSearchType"` // 搜索条件
FieldSearchHide bool `json:"fieldSearchHide"` // 是否隐藏查询条件
DictType string `json:"dictType"` // 字典
//Front bool `json:"front"` // 是否前端可见
Form bool `json:"form"` // 是否前端新建/编辑
Table bool `json:"table"` // 是否前端表格列
Desc bool `json:"desc"` // 是否前端详情
Excel bool `json:"excel"` // 是否导入/导出
Require bool `json:"require"` // 是否必填
DefaultValue string `json:"defaultValue"` // 是否必填
ErrorText string `json:"errorText"` // 校验失败文字
Clearable bool `json:"clearable"` // 是否可清空
Sort bool `json:"sort"` // 是否增加排序
PrimaryKey bool `json:"primaryKey"` // 是否主键
DataSource *DataSource `json:"dataSource"` // 数据源
CheckDataSource bool `json:"checkDataSource"` // 是否检查数据源
FieldIndexType string `json:"fieldIndexType"` // 索引类型
}
type AutoFunc struct {
Package string `json:"package"`
FuncName string `json:"funcName"` // 方法名称
Router string `json:"router"` // 路由名称
FuncDesc string `json:"funcDesc"` // 方法介绍
BusinessDB string `json:"businessDB"` // 业务库
StructName string `json:"structName"` // Struct名称
PackageName string `json:"packageName"` // 文件名称
Description string `json:"description"` // Struct中文名称
Abbreviation string `json:"abbreviation"` // Struct简称
HumpPackageName string `json:"humpPackageName"` // go文件名称
Method string `json:"method"` // 方法
IsPlugin bool `json:"isPlugin"` // 是否插件
IsAuth bool `json:"isAuth"` // 是否鉴权
IsPreview bool `json:"isPreview"` // 是否预览
IsAi bool `json:"isAi"` // 是否AI
ApiFunc string `json:"apiFunc"` // API方法
ServerFunc string `json:"serverFunc"` // 服务方法
JsFunc string `json:"jsFunc"` // JS方法
}
type InitMenu struct {
PlugName string `json:"plugName"`
ParentMenu string `json:"parentMenu"`
Menus []uint `json:"menus"`
}
type InitApi struct {
PlugName string `json:"plugName"`
APIs []uint `json:"apis"`
}
type LLMAutoCode struct {
Prompt string `json:"prompt" form:"prompt" gorm:"column:prompt;comment:提示语;type:text;"` //提示语
Mode string `json:"mode" form:"mode" gorm:"column:mode;comment:模式;type:text;"` //模式
}
@@ -0,0 +1,31 @@
package request
import (
"github.com/flipped-aurora/gin-vue-admin/server/global"
model "github.com/flipped-aurora/gin-vue-admin/server/model/system"
)
type SysAutoCodePackageCreate struct {
Desc string `json:"desc" example:"描述"`
Label string `json:"label" example:"展示名"`
Template string `json:"template" example:"模版"`
PackageName string `json:"packageName" example:"包名"`
Module string `json:"-" example:"模块"`
}
func (r *SysAutoCodePackageCreate) AutoCode() AutoCode {
return AutoCode{
Package: r.PackageName,
Module: global.GVA_CONFIG.AutoCode.Module,
}
}
func (r *SysAutoCodePackageCreate) Create() model.SysAutoCodePackage {
return model.SysAutoCodePackage{
Desc: r.Desc,
Label: r.Label,
Template: r.Template,
PackageName: r.PackageName,
Module: global.GVA_CONFIG.AutoCode.Module,
}
}
@@ -0,0 +1,56 @@
package request
import (
common "github.com/flipped-aurora/gin-vue-admin/server/model/common/request"
model "github.com/flipped-aurora/gin-vue-admin/server/model/system"
)
type SysAutoHistoryCreate struct {
Table string // 表名
Package string // 模块名/插件名
Request string // 前端传入的结构化信息
StructName string // 结构体名称
BusinessDB string // 业务库
Description string // Struct中文名称
Injections map[string]string // 注入路径
Templates map[string]string // 模板信息
ApiIDs []uint // api表注册内容
MenuID uint // 菜单ID
ExportTemplateID uint // 导出模板ID
}
func (r *SysAutoHistoryCreate) Create() model.SysAutoCodeHistory {
entity := model.SysAutoCodeHistory{
Package: r.Package,
Request: r.Request,
Table: r.Table,
StructName: r.StructName,
BusinessDB: r.BusinessDB,
Description: r.Description,
Injections: r.Injections,
Templates: r.Templates,
ApiIDs: r.ApiIDs,
MenuID: r.MenuID,
ExportTemplateID: r.ExportTemplateID,
}
if entity.Table == "" {
entity.Table = r.StructName
}
return entity
}
type SysAutoHistoryRollBack struct {
common.GetById
DeleteApi bool `json:"deleteApi" form:"deleteApi"` // 是否删除接口
DeleteMenu bool `json:"deleteMenu" form:"deleteMenu"` // 是否删除菜单
DeleteTable bool `json:"deleteTable" form:"deleteTable"` // 是否删除表
}
func (r *SysAutoHistoryRollBack) ApiIds(entity model.SysAutoCodeHistory) common.IdsReq {
length := len(entity.ApiIDs)
ids := make([]int, 0)
for i := 0; i < length; i++ {
ids = append(ids, int(entity.ApiIDs[i]))
}
return common.IdsReq{Ids: ids}
}
@@ -0,0 +1,27 @@
package request
// Casbin info structure
type CasbinInfo struct {
Path string `json:"path"` // 路径
Method string `json:"method"` // 方法
}
// Casbin structure for input parameters
type CasbinInReceive struct {
AuthorityId uint `json:"authorityId"` // 权限id
CasbinInfos []CasbinInfo `json:"casbinInfos"`
}
func DefaultCasbin() []CasbinInfo {
return []CasbinInfo{
{Path: "/menu/getMenu", Method: "POST"},
{Path: "/jwt/jsonInBlacklist", Method: "POST"},
{Path: "/base/login", Method: "POST"},
{Path: "/user/changePassword", Method: "POST"},
{Path: "/user/setUserAuthority", Method: "POST"},
{Path: "/user/getUserInfo", Method: "GET"},
{Path: "/user/setSelfInfo", Method: "PUT"},
{Path: "/fileUploadAndDownload/upload", Method: "POST"},
{Path: "/sysDictionary/findSysDictionary", Method: "GET"},
}
}
@@ -0,0 +1,11 @@
package request
import (
"github.com/flipped-aurora/gin-vue-admin/server/model/common/request"
"github.com/flipped-aurora/gin-vue-admin/server/model/system"
)
type SysDictionaryDetailSearch struct {
system.SysDictionaryDetail
request.PageInfo
}
@@ -0,0 +1,14 @@
package request
import (
"github.com/flipped-aurora/gin-vue-admin/server/model/common/request"
"github.com/flipped-aurora/gin-vue-admin/server/model/system"
"time"
)
type SysExportTemplateSearch struct {
system.SysExportTemplate
StartCreatedAt *time.Time `json:"startCreatedAt" form:"startCreatedAt"`
EndCreatedAt *time.Time `json:"endCreatedAt" form:"endCreatedAt"`
request.PageInfo
}
@@ -0,0 +1,123 @@
package request
import (
"fmt"
"github.com/flipped-aurora/gin-vue-admin/server/config"
"os"
)
type InitDB struct {
AdminPassword string `json:"adminPassword" binding:"required"`
DBType string `json:"dbType"` // 数据库类型
Host string `json:"host"` // 服务器地址
Port string `json:"port"` // 数据库连接端口
UserName string `json:"userName"` // 数据库用户名
Password string `json:"password"` // 数据库密码
DBName string `json:"dbName" binding:"required"` // 数据库名
DBPath string `json:"dbPath"` // sqlite数据库文件路径
}
// MysqlEmptyDsn msyql 空数据库 建库链接
// Author SliverHorn
func (i *InitDB) MysqlEmptyDsn() string {
if i.Host == "" {
i.Host = "127.0.0.1"
}
if i.Port == "" {
i.Port = "3306"
}
return fmt.Sprintf("%s:%s@tcp(%s:%s)/", i.UserName, i.Password, i.Host, i.Port)
}
// PgsqlEmptyDsn pgsql 空数据库 建库链接
// Author SliverHorn
func (i *InitDB) PgsqlEmptyDsn() string {
if i.Host == "" {
i.Host = "127.0.0.1"
}
if i.Port == "" {
i.Port = "5432"
}
return "host=" + i.Host + " user=" + i.UserName + " password=" + i.Password + " port=" + i.Port + " dbname=" + "postgres" + " " + "sslmode=disable TimeZone=Asia/Shanghai"
}
// SqliteEmptyDsn sqlite 空数据库 建库链接
// Author Kafumio
func (i *InitDB) SqliteEmptyDsn() string {
separator := string(os.PathSeparator)
return i.DBPath + separator + i.DBName + ".db"
}
func (i *InitDB) MssqlEmptyDsn() string {
return "sqlserver://" + i.UserName + ":" + i.Password + "@" + i.Host + ":" + i.Port + "?database=" + i.DBName + "&encrypt=disable"
}
// ToMysqlConfig 转换 config.Mysql
// Author [SliverHorn](https://github.com/SliverHorn)
func (i *InitDB) ToMysqlConfig() config.Mysql {
return config.Mysql{
GeneralDB: config.GeneralDB{
Path: i.Host,
Port: i.Port,
Dbname: i.DBName,
Username: i.UserName,
Password: i.Password,
MaxIdleConns: 10,
MaxOpenConns: 100,
LogMode: "error",
Config: "charset=utf8mb4&parseTime=True&loc=Local",
},
}
}
// ToPgsqlConfig 转换 config.Pgsql
// Author [SliverHorn](https://github.com/SliverHorn)
func (i *InitDB) ToPgsqlConfig() config.Pgsql {
return config.Pgsql{
GeneralDB: config.GeneralDB{
Path: i.Host,
Port: i.Port,
Dbname: i.DBName,
Username: i.UserName,
Password: i.Password,
MaxIdleConns: 10,
MaxOpenConns: 100,
LogMode: "error",
Config: "sslmode=disable TimeZone=Asia/Shanghai",
},
}
}
// ToSqliteConfig 转换 config.Sqlite
// Author [Kafumio](https://github.com/Kafumio)
func (i *InitDB) ToSqliteConfig() config.Sqlite {
return config.Sqlite{
GeneralDB: config.GeneralDB{
Path: i.DBPath,
Port: i.Port,
Dbname: i.DBName,
Username: i.UserName,
Password: i.Password,
MaxIdleConns: 10,
MaxOpenConns: 100,
LogMode: "error",
Config: "",
},
}
}
func (i *InitDB) ToMssqlConfig() config.Mssql {
return config.Mssql{
GeneralDB: config.GeneralDB{
Path: i.DBPath,
Port: i.Port,
Dbname: i.DBName,
Username: i.UserName,
Password: i.Password,
MaxIdleConns: 10,
MaxOpenConns: 100,
LogMode: "error",
Config: "",
},
}
}
@@ -0,0 +1,27 @@
package request
import (
"github.com/flipped-aurora/gin-vue-admin/server/global"
"github.com/flipped-aurora/gin-vue-admin/server/model/system"
)
// Add menu authority info structure
type AddMenuAuthorityInfo struct {
Menus []system.SysBaseMenu `json:"menus"`
AuthorityId uint `json:"authorityId"` // 角色ID
}
func DefaultMenu() []system.SysBaseMenu {
return []system.SysBaseMenu{{
GVA_MODEL: global.GVA_MODEL{ID: 1},
ParentId: 0,
Path: "dashboard",
Name: "dashboard",
Component: "view/dashboard/index.vue",
Sort: 1,
Meta: system.Meta{
Title: "仪表盘",
Icon: "setting",
},
}}
}
@@ -0,0 +1,11 @@
package request
import (
"github.com/flipped-aurora/gin-vue-admin/server/model/common/request"
"github.com/flipped-aurora/gin-vue-admin/server/model/system"
)
type SysOperationRecordSearch struct {
system.SysOperationRecord
request.PageInfo
}
@@ -0,0 +1,14 @@
package request
import (
"github.com/flipped-aurora/gin-vue-admin/server/model/common/request"
"time"
)
type SysParamsSearch struct {
StartCreatedAt *time.Time `json:"startCreatedAt" form:"startCreatedAt"`
EndCreatedAt *time.Time `json:"endCreatedAt" form:"endCreatedAt"`
Name string `json:"name" form:"name" `
Key string `json:"key" form:"key" `
request.PageInfo
}
@@ -0,0 +1,86 @@
package request
import (
common "github.com/flipped-aurora/gin-vue-admin/server/model/common/request"
"github.com/flipped-aurora/gin-vue-admin/server/model/system"
)
// Register User register structure
type Register struct {
Username string `json:"userName" example:"用户名"`
Password string `json:"passWord" example:"密码"`
NickName string `json:"nickName" example:"昵称"`
HeaderImg string `json:"headerImg" example:"头像链接"`
AuthorityId uint `json:"authorityId" swaggertype:"string" example:"int 角色id"`
Enable int `json:"enable" swaggertype:"string" example:"int 是否启用"`
AuthorityIds []uint `json:"authorityIds" swaggertype:"string" example:"[]uint 角色id"`
Phone string `json:"phone" example:"电话号码"`
Email string `json:"email" example:"电子邮箱"`
}
// User login structure
type Login struct {
Username string `json:"username"` // 用户名
Password string `json:"password"` // 密码
Captcha string `json:"captcha"` // 验证码
CaptchaId string `json:"captchaId"` // 验证码ID
}
// Modify password structure
type ChangePasswordReq struct {
ID uint `json:"-"` // 从 JWT 中提取 user id,避免越权
Password string `json:"password"` // 密码
NewPassword string `json:"newPassword"` // 新密码
}
// Modify user's auth structure
type SetUserAuth struct {
AuthorityId uint `json:"authorityId"` // 角色ID
}
// Modify user's auth structure
type SetUserAuthorities struct {
ID uint
AuthorityIds []uint `json:"authorityIds"` // 角色ID
}
type ChangeUserInfo struct {
ID uint `gorm:"primarykey"` // 主键ID
NickName string `json:"nickName" gorm:"default:系统用户;comment:用户昵称"` // 用户昵称
Phone string `json:"phone" gorm:"comment:用户手机号"` // 用户手机号
AuthorityIds []uint `json:"authorityIds" gorm:"-"` // 角色ID
Email string `json:"email" gorm:"comment:用户邮箱"` // 用户邮箱
HeaderImg string `json:"headerImg" gorm:"default:https://qmplusimg.henrongyi.top/gva_header.jpg;comment:用户头像"` // 用户头像
SideMode string `json:"sideMode" gorm:"comment:用户侧边主题"` // 用户侧边主题
Enable int `json:"enable" gorm:"comment:冻结用户"` //冻结用户
GlobalCode bool `json:"global_code" gorm:"comment:全局代码执行权限"` //全局代码执行权限 Extend global code
Authorities []system.SysAuthority `json:"-" gorm:"many2many:sys_user_authority;"`
}
type GetUserList struct {
common.PageInfo
Username string `json:"username" form:"username"`
NickName string `json:"nickName" form:"nickName"`
Phone string `json:"phone" form:"phone"`
Email string `json:"email" form:"email"`
}
// Extend Start GetUserInfoByUserName
// GetUserInfoByUserName DingTalk API: Get User Info By UserName
type GetUserInfoByUserName struct {
ResList struct {
Name string `json:"name"`
UserID string `json:"userId"`
Mobile string `json:"mobile"`
WorkPlace string `json:"workPlace"`
} `json:"resList"`
}
// UpdateUserPasswd update user pass my
type UpdateUserPasswd struct {
ID uint `json:"ID"` // id
Password string `json:"Password"` // 密码
}
// Extend Stop GetUserInfoByUserName
@@ -0,0 +1,18 @@
package response
// OaUserInfoRes 请求OA用户信息接口返回值
type OaUserInfoRes struct {
Code int `json:"code"`
Info string `json:"info"`
Data struct {
Username string `json:"username"`
Name string `json:"name"`
Email string `json:"email"`
} `json:"data"`
}
// OaAccessTokenRes 请求OA access-token接口返回值
type OaAccessTokenRes struct {
AccessToken string `json:"access_token"`
ExpiresIn int `json:"expires_in"`
}
@@ -0,0 +1,18 @@
package response
import (
"github.com/flipped-aurora/gin-vue-admin/server/model/system"
)
type SysAPIResponse struct {
Api system.SysApi `json:"api"`
}
type SysAPIListResponse struct {
Apis []system.SysApi `json:"apis"`
}
type SysSyncApis struct {
NewApis []system.SysApi `json:"newApis"`
DeleteApis []system.SysApi `json:"deleteApis"`
}
@@ -0,0 +1,12 @@
package response
import "github.com/flipped-aurora/gin-vue-admin/server/model/system"
type SysAuthorityResponse struct {
Authority system.SysAuthority `json:"authority"`
}
type SysAuthorityCopyResponse struct {
Authority system.SysAuthority `json:"authority"`
OldAuthorityId uint `json:"oldAuthorityId"` // 旧角色ID
}
@@ -0,0 +1,5 @@
package response
type SysAuthorityBtnRes struct {
Selected []uint `json:"selected"`
}
@@ -0,0 +1,17 @@
package response
type Db struct {
Database string `json:"database" gorm:"column:database"`
}
type Table struct {
TableName string `json:"tableName" gorm:"column:table_name"`
}
type Column struct {
DataType string `json:"dataType" gorm:"column:data_type"`
ColumnName string `json:"columnName" gorm:"column:column_name"`
DataTypeLong string `json:"dataTypeLong" gorm:"column:data_type_long"`
ColumnComment string `json:"columnComment" gorm:"column:column_comment"`
PrimaryKey bool `json:"primaryKey" gorm:"column:primary_key"`
}
@@ -0,0 +1,8 @@
package response
type SysCaptchaResponse struct {
CaptchaId string `json:"captchaId"`
PicPath string `json:"picPath"`
CaptchaLength int `json:"captchaLength"`
OpenCaptcha bool `json:"openCaptcha"`
}
@@ -0,0 +1,9 @@
package response
import (
"github.com/flipped-aurora/gin-vue-admin/server/model/system/request"
)
type PolicyPathResponse struct {
Paths []request.CasbinInfo `json:"paths"`
}
@@ -0,0 +1,15 @@
package response
import "github.com/flipped-aurora/gin-vue-admin/server/model/system"
type SysMenusResponse struct {
Menus []system.SysMenu `json:"menus"`
}
type SysBaseMenusResponse struct {
Menus []system.SysBaseMenu `json:"menus"`
}
type SysBaseMenuResponse struct {
Menu system.SysBaseMenu `json:"menu"`
}
@@ -0,0 +1,7 @@
package response
import "github.com/flipped-aurora/gin-vue-admin/server/config"
type SysConfigResponse struct {
Config config.Server `json:"config"`
}
@@ -0,0 +1,15 @@
package response
import (
"github.com/flipped-aurora/gin-vue-admin/server/model/system"
)
type SysUserResponse struct {
User system.SysUser `json:"user"`
}
type LoginResponse struct {
User system.SysUser `json:"user"`
Token string `json:"token"`
ExpiresAt int64 `json:"expiresAt"`
}
+28
View File
@@ -0,0 +1,28 @@
package system
import (
"github.com/flipped-aurora/gin-vue-admin/server/global"
)
type SysApi struct {
global.GVA_MODEL
Path string `json:"path" gorm:"comment:api路径"` // api路径
Description string `json:"description" gorm:"comment:api中文描述"` // api中文描述
ApiGroup string `json:"apiGroup" gorm:"comment:api组"` // api组
Method string `json:"method" gorm:"default:POST;comment:方法"` // 方法:创建POST(默认)|查看GET|更新PUT|删除DELETE
}
func (SysApi) TableName() string {
return "sys_apis"
}
type SysIgnoreApi struct {
global.GVA_MODEL
Path string `json:"path" gorm:"comment:api路径"` // api路径
Method string `json:"method" gorm:"default:POST;comment:方法"` // 方法:创建POST(默认)|查看GET|更新PUT|删除DELETE
Flag bool `json:"flag" gorm:"-"` // 是否忽略
}
func (SysIgnoreApi) TableName() string {
return "sys_ignore_apis"
}
@@ -0,0 +1,23 @@
package system
import (
"time"
)
type SysAuthority struct {
CreatedAt time.Time // 创建时间
UpdatedAt time.Time // 更新时间
DeletedAt *time.Time `sql:"index"`
AuthorityId uint `json:"authorityId" gorm:"not null;unique;primary_key;comment:角色ID;size:90"` // 角色ID
AuthorityName string `json:"authorityName" gorm:"comment:角色名"` // 角色名
ParentId *uint `json:"parentId" gorm:"comment:父角色ID"` // 父角色ID
DataAuthorityId []*SysAuthority `json:"dataAuthorityId" gorm:"many2many:sys_data_authority_id;"`
Children []SysAuthority `json:"children" gorm:"-"`
SysBaseMenus []SysBaseMenu `json:"menus" gorm:"many2many:sys_authority_menus;"`
Users []SysUser `json:"-" gorm:"many2many:sys_user_authority;"`
DefaultRouter string `json:"defaultRouter" gorm:"comment:默认菜单;default:dashboard"` // 默认菜单(默认dashboard)
}
func (SysAuthority) TableName() string {
return "sys_authorities"
}
@@ -0,0 +1,8 @@
package system
type SysAuthorityBtn struct {
AuthorityId uint `gorm:"comment:角色ID"`
SysMenuID uint `gorm:"comment:菜单ID"`
SysBaseMenuBtnID uint `gorm:"comment:菜单按钮ID"`
SysBaseMenuBtn SysBaseMenuBtn ` gorm:"comment:按钮详情"`
}
@@ -0,0 +1,19 @@
package system
type SysMenu struct {
SysBaseMenu
MenuId uint `json:"menuId" gorm:"comment:菜单ID"`
AuthorityId uint `json:"-" gorm:"comment:角色ID"`
Children []SysMenu `json:"children" gorm:"-"`
Parameters []SysBaseMenuParameter `json:"parameters" gorm:"foreignKey:SysBaseMenuID;references:MenuId"`
Btns map[string]uint `json:"btns" gorm:"-"`
}
type SysAuthorityMenu struct {
MenuId string `json:"menuId" gorm:"comment:菜单ID;column:sys_base_menu_id"`
AuthorityId string `json:"-" gorm:"comment:角色ID;column:sys_authority_authority_id"`
}
func (s SysAuthorityMenu) TableName() string {
return "sys_authority_menus"
}
@@ -0,0 +1,67 @@
package system
import (
"github.com/flipped-aurora/gin-vue-admin/server/global"
"gorm.io/gorm"
"os"
"path"
"path/filepath"
"strings"
)
// SysAutoCodeHistory 自动迁移代码记录,用于回滚,重放使用
type SysAutoCodeHistory struct {
global.GVA_MODEL
Table string `json:"tableName" gorm:"column:table_name;comment:表名"`
Package string `json:"package" gorm:"column:package;comment:模块名/插件名"`
Request string `json:"request" gorm:"type:text;column:request;comment:前端传入的结构化信息"`
StructName string `json:"structName" gorm:"column:struct_name;comment:结构体名称"`
BusinessDB string `json:"businessDb" gorm:"column:business_db;comment:业务库"`
Description string `json:"description" gorm:"column:description;comment:Struct中文名称"`
Templates map[string]string `json:"template" gorm:"serializer:json;type:text;column:templates;comment:模板信息"`
Injections map[string]string `json:"injections" gorm:"serializer:json;type:text;column:Injections;comment:注入路径"`
Flag int `json:"flag" gorm:"column:flag;comment:[0:创建,1:回滚]"`
ApiIDs []uint `json:"apiIDs" gorm:"serializer:json;column:api_ids;comment:api表注册内容"`
MenuID uint `json:"menuId" gorm:"column:menu_id;comment:菜单ID"`
ExportTemplateID uint `json:"exportTemplateID" gorm:"column:export_template_id;comment:导出模板ID"`
AutoCodePackage SysAutoCodePackage `json:"autoCodePackage" gorm:"foreignKey:ID;references:PackageID"`
PackageID uint `json:"packageID" gorm:"column:package_id;comment:包ID"`
}
func (s *SysAutoCodeHistory) BeforeCreate(db *gorm.DB) error {
templates := make(map[string]string, len(s.Templates))
for key, value := range s.Templates {
server := filepath.Join(global.GVA_CONFIG.AutoCode.Root, global.GVA_CONFIG.AutoCode.Server)
{
hasServer := strings.Index(key, server)
if hasServer != -1 {
key = strings.TrimPrefix(key, server)
keys := strings.Split(key, string(os.PathSeparator))
key = path.Join(keys...)
}
} // key
web := filepath.Join(global.GVA_CONFIG.AutoCode.Root, global.GVA_CONFIG.AutoCode.WebRoot())
hasWeb := strings.Index(value, web)
if hasWeb != -1 {
value = strings.TrimPrefix(value, web)
values := strings.Split(value, string(os.PathSeparator))
value = path.Join(values...)
templates[key] = value
continue
}
hasServer := strings.Index(value, server)
if hasServer != -1 {
value = strings.TrimPrefix(value, server)
values := strings.Split(value, string(os.PathSeparator))
value = path.Join(values...)
templates[key] = value
continue
}
}
s.Templates = templates
return nil
}
func (s *SysAutoCodeHistory) TableName() string {
return "sys_auto_code_histories"
}
@@ -0,0 +1,18 @@
package system
import (
"github.com/flipped-aurora/gin-vue-admin/server/global"
)
type SysAutoCodePackage struct {
global.GVA_MODEL
Desc string `json:"desc" gorm:"comment:描述"`
Label string `json:"label" gorm:"comment:展示名"`
Template string `json:"template" gorm:"comment:模版"`
PackageName string `json:"packageName" gorm:"comment:包名"`
Module string `json:"-" example:"模块"`
}
func (s *SysAutoCodePackage) TableName() string {
return "sys_auto_code_packages"
}
@@ -0,0 +1,42 @@
package system
import (
"github.com/flipped-aurora/gin-vue-admin/server/global"
)
type SysBaseMenu struct {
global.GVA_MODEL
MenuLevel uint `json:"-"`
ParentId uint `json:"parentId" gorm:"comment:父菜单ID"` // 父菜单ID
Path string `json:"path" gorm:"comment:路由path"` // 路由path
Name string `json:"name" gorm:"comment:路由name"` // 路由name
Hidden bool `json:"hidden" gorm:"comment:是否在列表隐藏"` // 是否在列表隐藏
Component string `json:"component" gorm:"comment:对应前端文件路径"` // 对应前端文件路径
Sort int `json:"sort" gorm:"comment:排序标记"` // 排序标记
Meta `json:"meta" gorm:"embedded;comment:附加属性"` // 附加属性
SysAuthoritys []SysAuthority `json:"authoritys" gorm:"many2many:sys_authority_menus;"`
Children []SysBaseMenu `json:"children" gorm:"-"`
Parameters []SysBaseMenuParameter `json:"parameters"`
MenuBtn []SysBaseMenuBtn `json:"menuBtn"`
}
type Meta struct {
ActiveName string `json:"activeName" gorm:"comment:高亮菜单"`
KeepAlive bool `json:"keepAlive" gorm:"comment:是否缓存"` // 是否缓存
DefaultMenu bool `json:"defaultMenu" gorm:"comment:是否是基础路由(开发中)"` // 是否是基础路由(开发中)
Title string `json:"title" gorm:"comment:菜单名"` // 菜单名
Icon string `json:"icon" gorm:"comment:菜单图标"` // 菜单图标
CloseTab bool `json:"closeTab" gorm:"comment:自动关闭tab"` // 自动关闭tab
}
type SysBaseMenuParameter struct {
global.GVA_MODEL
SysBaseMenuID uint
Type string `json:"type" gorm:"comment:地址栏携带参数为params还是query"` // 地址栏携带参数为params还是query
Key string `json:"key" gorm:"comment:地址栏携带参数的key"` // 地址栏携带参数的key
Value string `json:"value" gorm:"comment:地址栏携带参数的值"` // 地址栏携带参数的值
}
func (SysBaseMenu) TableName() string {
return "sys_base_menus"
}
@@ -0,0 +1,20 @@
// 自动生成模板SysDictionary
package system
import (
"github.com/flipped-aurora/gin-vue-admin/server/global"
)
// 如果含有time.Time 请自行import time包
type SysDictionary struct {
global.GVA_MODEL
Name string `json:"name" form:"name" gorm:"column:name;comment:字典名(中)"` // 字典名(中)
Type string `json:"type" form:"type" gorm:"column:type;comment:字典名(英)"` // 字典名(英)
Status *bool `json:"status" form:"status" gorm:"column:status;comment:状态"` // 状态
Desc string `json:"desc" form:"desc" gorm:"column:desc;comment:描述"` // 描述
SysDictionaryDetails []SysDictionaryDetail `json:"sysDictionaryDetails" form:"sysDictionaryDetails"`
}
func (SysDictionary) TableName() string {
return "sys_dictionaries"
}
@@ -0,0 +1,21 @@
// 自动生成模板SysDictionaryDetail
package system
import (
"github.com/flipped-aurora/gin-vue-admin/server/global"
)
// 如果含有time.Time 请自行import time包
type SysDictionaryDetail struct {
global.GVA_MODEL
Label string `json:"label" form:"label" gorm:"column:label;comment:展示值"` // 展示值
Value string `json:"value" form:"value" gorm:"column:value;comment:字典值"` // 字典值
Extend string `json:"extend" form:"extend" gorm:"column:extend;comment:扩展值"` // 扩展值
Status *bool `json:"status" form:"status" gorm:"column:status;comment:启用状态"` // 启用状态
Sort int `json:"sort" form:"sort" gorm:"column:sort;comment:排序标记"` // 排序标记
SysDictionaryID int `json:"sysDictionaryID" form:"sysDictionaryID" gorm:"column:sys_dictionary_id;comment:关联标记"` // 关联标记
}
func (SysDictionaryDetail) TableName() string {
return "sys_dictionary_details"
}
@@ -0,0 +1,44 @@
// 自动生成模板SysExportTemplate
package system
import (
"github.com/flipped-aurora/gin-vue-admin/server/global"
)
// 导出模板 结构体 SysExportTemplate
type SysExportTemplate struct {
global.GVA_MODEL
DBName string `json:"dbName" form:"dbName" gorm:"column:db_name;comment:数据库名称;"` //数据库名称
Name string `json:"name" form:"name" gorm:"column:name;comment:模板名称;"` //模板名称
TableName string `json:"tableName" form:"tableName" gorm:"column:table_name;comment:表名称;"` //表名称
TemplateID string `json:"templateID" form:"templateID" gorm:"column:template_id;comment:模板标识;"` //模板标识
TemplateInfo string `json:"templateInfo" form:"templateInfo" gorm:"column:template_info;type:text;"` //模板信息
Limit *int `json:"limit" form:"limit" gorm:"column:limit;comment:导出限制"`
Order string `json:"order" form:"order" gorm:"column:order;comment:排序"`
Conditions []Condition `json:"conditions" form:"conditions" gorm:"foreignKey:TemplateID;references:TemplateID;comment:条件"`
JoinTemplate []JoinTemplate `json:"joinTemplate" form:"joinTemplate" gorm:"foreignKey:TemplateID;references:TemplateID;comment:关联"`
}
type JoinTemplate struct {
global.GVA_MODEL
TemplateID string `json:"templateID" form:"templateID" gorm:"column:template_id;comment:模板标识"`
JOINS string `json:"joins" form:"joins" gorm:"column:joins;comment:关联"`
Table string `json:"table" form:"table" gorm:"column:table;comment:关联表"`
ON string `json:"on" form:"on" gorm:"column:on;comment:关联条件"`
}
func (JoinTemplate) TableName() string {
return "sys_export_template_join"
}
type Condition struct {
global.GVA_MODEL
TemplateID string `json:"templateID" form:"templateID" gorm:"column:template_id;comment:模板标识"`
From string `json:"from" form:"from" gorm:"column:from;comment:条件取的key"`
Column string `json:"column" form:"column" gorm:"column:column;comment:作为查询条件的字段"`
Operator string `json:"operator" form:"operator" gorm:"column:operator;comment:操作符"`
}
func (Condition) TableName() string {
return "sys_export_template_condition"
}
@@ -0,0 +1,10 @@
package system
import (
"github.com/flipped-aurora/gin-vue-admin/server/global"
)
type JwtBlacklist struct {
global.GVA_MODEL
Jwt string `gorm:"type:text;comment:jwt"`
}
+10
View File
@@ -0,0 +1,10 @@
package system
import "github.com/flipped-aurora/gin-vue-admin/server/global"
type SysBaseMenuBtn struct {
global.GVA_MODEL
Name string `json:"name" gorm:"comment:按钮关键key"`
Desc string `json:"desc" gorm:"按钮备注"`
SysBaseMenuID uint `json:"sysBaseMenuID" gorm:"comment:菜单ID"`
}
@@ -0,0 +1,24 @@
// 自动生成模板SysOperationRecord
package system
import (
"time"
"github.com/flipped-aurora/gin-vue-admin/server/global"
)
// 如果含有time.Time 请自行import time包
type SysOperationRecord struct {
global.GVA_MODEL
Ip string `json:"ip" form:"ip" gorm:"column:ip;comment:请求ip"` // 请求ip
Method string `json:"method" form:"method" gorm:"column:method;comment:请求方法"` // 请求方法
Path string `json:"path" form:"path" gorm:"column:path;comment:请求路径"` // 请求路径
Status int `json:"status" form:"status" gorm:"column:status;comment:请求状态"` // 请求状态
Latency time.Duration `json:"latency" form:"latency" gorm:"column:latency;comment:延迟" swaggertype:"string"` // 延迟
Agent string `json:"agent" form:"agent" gorm:"type:text;column:agent;comment:代理"` // 代理
ErrorMessage string `json:"error_message" form:"error_message" gorm:"column:error_message;comment:错误信息"` // 错误信息
Body string `json:"body" form:"body" gorm:"type:text;column:body;comment:请求Body"` // 请求Body
Resp string `json:"resp" form:"resp" gorm:"type:text;column:resp;comment:响应Body"` // 响应Body
UserID int `json:"user_id" form:"user_id" gorm:"column:user_id;comment:用户id"` // 用户id
User SysUser `json:"user"`
}
+20
View File
@@ -0,0 +1,20 @@
// 自动生成模板SysParams
package system
import (
"github.com/flipped-aurora/gin-vue-admin/server/global"
)
// 参数 结构体 SysParams
type SysParams struct {
global.GVA_MODEL
Name string `json:"name" form:"name" gorm:"column:name;comment:参数名称;" binding:"required"` //参数名称
Key string `json:"key" form:"key" gorm:"column:key;comment:参数键;" binding:"required"` //参数键
Value string `json:"value" form:"value" gorm:"column:value;comment:参数值;" binding:"required"` //参数值
Desc string `json:"desc" form:"desc" gorm:"column:desc;comment:参数说明;"` //参数说明
}
// TableName 参数 SysParams自定义表名 sys_params
func (SysParams) TableName() string {
return "sys_params"
}
+10
View File
@@ -0,0 +1,10 @@
package system
import (
"github.com/flipped-aurora/gin-vue-admin/server/config"
)
// 配置文件结构体
type System struct {
Config config.Server `json:"config"`
}
+116
View File
@@ -0,0 +1,116 @@
package system
import (
"context"
"errors"
"fmt"
"github.com/flipped-aurora/gin-vue-admin/server/global"
"github.com/flipped-aurora/gin-vue-admin/server/model/common"
"github.com/flipped-aurora/gin-vue-admin/server/model/gaia"
"github.com/gofrs/uuid/v5"
"time"
)
type Login interface {
GetUsername() string
GetNickname() string
GetUUID() uuid.UUID
GetUserId() uint
GetAuthorityId() uint
GetUserInfo() any
GetUserEmail() string // Extend add mail
}
var _ Login = new(SysUser)
type SysUser struct {
global.GVA_MODEL
UUID uuid.UUID `json:"uuid" gorm:"index;comment:用户UUID"` // 用户UUID
Username string `json:"userName" gorm:"index;comment:用户登录名"` // 用户登录名
Password string `json:"-" gorm:"comment:用户登录密码"` // 用户登录密码
NickName string `json:"nickName" gorm:"default:系统用户;comment:用户昵称"` // 用户昵称
HeaderImg string `json:"headerImg" gorm:"default:https://qmplusimg.henrongyi.top/gva_header.jpg;comment:用户头像"` // 用户头像
AuthorityId uint `json:"authorityId" gorm:"default:888;comment:用户角色ID"` // 用户角色ID
Authority SysAuthority `json:"authority" gorm:"foreignKey:AuthorityId;references:AuthorityId;comment:用户角色"` // 用户角色
Authorities []SysAuthority `json:"authorities" gorm:"many2many:sys_user_authority;"` // 多用户角色
Phone string `json:"phone" gorm:"comment:用户手机号"` // 用户手机号
Email string `json:"email" gorm:"comment:用户邮箱"` // 用户邮箱
Enable int `json:"enable" gorm:"default:1;comment:用户是否被冻结 1正常 2冻结"` //用户是否被冻结 1正常 2冻结
OriginSetting common.JSONMap `json:"originSetting" form:"originSetting" gorm:"type:text;default:null;column:origin_setting;comment:配置;"` //配置
}
func (SysUser) TableName() string {
return "sys_users"
}
func (s *SysUser) GetUsername() string {
return s.Username
}
func (s *SysUser) GetNickname() string {
return s.NickName
}
func (s *SysUser) GetUUID() uuid.UUID {
return s.UUID
}
func (s *SysUser) GetUserId() uint {
return s.ID
}
func (s *SysUser) GetAuthorityId() uint {
return s.AuthorityId
}
func (s *SysUser) GetUserInfo() any {
return *s
}
// Extend: Start Get the corresponding GAIA platform user information
func (s *SysUser) GetUserEmail() string {
return s.Email
}
const UserActive = 1 // 用户状态: 活跃
const UserDeactivate = 2 // 用户状态: 停用
const AdminGroupID = uint(888) // 管理员组ID
const DefaultGroupID = uint(1) // 普通用户组ID
// GetAccount
// @description: Get user information through the user provider relationship table
// @return account gaia.Account, err error
func (s SysUser) GetAccount() (account gaia.Account, err error) {
// init
// get account
if err = global.GVA_DB.Where("email=?", s.Email).First(&account).Error; err != nil {
return account, errors.New("cannot find a user related to the database")
}
// return
return account, nil
}
// SyncGaiaStatus
// @description: Sync user status to GAIA platform
// @return enable int
func (s SysUser) SyncGaiaStatus(enable int) {
key := fmt.Sprintf("login_error_rate_limit:%s", s.Email)
if enable == UserActive {
global.GVA_REDIS.Del(context.Background(), key)
} else {
global.GVA_REDIS.Set(context.Background(), key, global.GVA_CONFIG.Gaia.LoginMaxErrorLimit, time.Hour*24)
}
}
// Extend: Stop Get the corresponding GAIA platform user information
// Extend: Start global code
type SysUserGlobalCode struct {
global.GVA_MODEL
UserID uint `json:"user_id" gorm:"index;comment:用户id"`
}
// Extend: Stop global code
@@ -0,0 +1,11 @@
package system
// SysUserAuthority 是 sysUser 和 sysAuthority 的连接表
type SysUserAuthority struct {
SysUserId uint `gorm:"column:sys_user_id"`
SysAuthorityAuthorityId uint `gorm:"column:sys_authority_authority_id"`
}
func (s *SysUserAuthority) TableName() string {
return "sys_user_authority"
}
@@ -0,0 +1,4 @@
package system
const AdminAuthorityId = 888
const NormalAuthorityId = 1 // 普通用户权限(默认注册的用户都是普通用户)