From 1a06053b307c0d1a2ae47b279717cbf83d92e8ee Mon Sep 17 00:00:00 2001 From: Yvan <8574526@qq,com> Date: Wed, 7 Jan 2026 14:34:18 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BB=BB=E5=8A=A1=E4=B8=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cmd/gen/main.go | 2 +- internal/biz/system/dictionary.go | 357 +++++++++++ internal/biz/system/operation_record.go | 63 ++ internal/data/model/casbin_rule.gen.go | 16 +- .../data/model/exa_attachment_category.gen.go | 8 +- internal/data/model/exa_customers.gen.go | 12 +- internal/data/model/exa_file_chunks.gen.go | 10 +- .../exa_file_upload_and_downloads.gen.go | 14 +- internal/data/model/exa_files.gen.go | 14 +- .../data/model/gva_announcements_info.gen.go | 12 +- internal/data/model/jwt_blacklists.gen.go | 6 +- internal/data/model/sys_apis.gen.go | 12 +- internal/data/model/sys_authorities.gen.go | 10 +- internal/data/model/sys_authority_btns.gen.go | 6 +- .../data/model/sys_auto_code_histories.gen.go | 32 +- .../data/model/sys_auto_code_packages.gen.go | 14 +- internal/data/model/sys_base_menu_btns.gen.go | 10 +- .../model/sys_base_menu_parameters.gen.go | 12 +- internal/data/model/sys_base_menus.gen.go | 32 +- internal/data/model/sys_dictionaries.gen.go | 14 +- .../data/model/sys_dictionary_details.gen.go | 22 +- internal/data/model/sys_error.gen.go | 14 +- .../sys_export_template_condition.gen.go | 12 +- .../model/sys_export_template_join.gen.go | 12 +- .../data/model/sys_export_templates.gen.go | 18 +- internal/data/model/sys_ignore_apis.gen.go | 8 +- .../data/model/sys_operation_records.gen.go | 24 +- internal/data/model/sys_params.gen.go | 12 +- internal/data/model/sys_users.gen.go | 24 +- internal/data/model/sys_versions.gen.go | 12 +- internal/data/system/api.go | 41 +- internal/data/system/authority.go | 23 +- internal/data/system/dictionary.go | 472 ++++++++++++++ internal/data/system/menu.go | 156 ++--- internal/data/system/operation_record.go | 131 ++++ internal/data/system/user.go | 110 +--- internal/service/system/dictionary.go | 579 ++++++++++++++++++ internal/service/system/operation_record.go | 186 ++++++ 38 files changed, 2107 insertions(+), 405 deletions(-) create mode 100644 internal/biz/system/dictionary.go create mode 100644 internal/biz/system/operation_record.go create mode 100644 internal/data/system/dictionary.go create mode 100644 internal/data/system/operation_record.go create mode 100644 internal/service/system/dictionary.go create mode 100644 internal/service/system/operation_record.go diff --git a/cmd/gen/main.go b/cmd/gen/main.go index 73e11e5..97369c0 100644 --- a/cmd/gen/main.go +++ b/cmd/gen/main.go @@ -28,7 +28,7 @@ func main() { OutPath: filepath.Join(projectRoot, "internal/data/query"), ModelPkgPath: filepath.Join(projectRoot, "internal/data/model"), Mode: gen.WithDefaultQuery | gen.WithQueryInterface, - FieldNullable: true, + FieldNullable: false, // 非NULL字段生成为值类型 FieldCoverable: false, FieldSignable: false, FieldWithIndexTag: true, diff --git a/internal/biz/system/dictionary.go b/internal/biz/system/dictionary.go new file mode 100644 index 0000000..ef840c3 --- /dev/null +++ b/internal/biz/system/dictionary.go @@ -0,0 +1,357 @@ +package system + +import ( + "context" + "encoding/json" + "errors" + "strconv" +) + +// Dictionary 字典实体 +type Dictionary struct { + ID uint + Name string + Type string + Status *bool + Desc string + ParentID *uint + Children []*Dictionary +} + +// DictionaryDetail 字典详情实体 +type DictionaryDetail struct { + ID uint + Label string + Value string + Extend string + Status *bool + Sort int + SysDictionaryID uint + ParentID *uint + Level int + Path string + Disabled bool + Children []*DictionaryDetail +} + +// DictionaryRepo 字典仓储接口 +type DictionaryRepo interface { + Create(ctx context.Context, dict *Dictionary) error + Update(ctx context.Context, dict *Dictionary) error + Delete(ctx context.Context, id uint) error + FindByID(ctx context.Context, id uint) (*Dictionary, error) + FindByType(ctx context.Context, typ string) (*Dictionary, error) + GetByTypeOrID(ctx context.Context, typ string, id uint, status *bool) (*Dictionary, error) + List(ctx context.Context, name string) ([]*Dictionary, error) + CheckCircularReference(ctx context.Context, currentID, parentID uint) error +} + +// DictionaryDetailRepo 字典详情仓储接口 +type DictionaryDetailRepo interface { + Create(ctx context.Context, detail *DictionaryDetail) error + Update(ctx context.Context, detail *DictionaryDetail) error + Delete(ctx context.Context, id uint) error + FindByID(ctx context.Context, id uint) (*DictionaryDetail, error) + List(ctx context.Context, page, pageSize int, filters map[string]interface{}) ([]*DictionaryDetail, int64, error) + GetListByDictionaryID(ctx context.Context, dictionaryID uint) ([]*DictionaryDetail, error) + GetTreeList(ctx context.Context, dictionaryID uint) ([]*DictionaryDetail, error) + GetByParent(ctx context.Context, dictionaryID uint, parentID *uint, includeChildren bool) ([]*DictionaryDetail, error) + GetByDictionaryIDAndValue(ctx context.Context, dictionaryID uint, value string) (*DictionaryDetail, error) + GetByTypeAndValue(ctx context.Context, typ, value string) (*DictionaryDetail, error) + GetTreeListByType(ctx context.Context, typ string) ([]*DictionaryDetail, error) + GetListByType(ctx context.Context, typ string) ([]*DictionaryDetail, error) + HasChildren(ctx context.Context, id uint) (bool, error) + CheckCircularReference(ctx context.Context, id, parentID uint) bool + UpdateChildrenLevelAndPath(ctx context.Context, parentID uint) error + GetPath(ctx context.Context, id uint) ([]*DictionaryDetail, error) + DeleteByDictionaryID(ctx context.Context, dictionaryID uint) error + BatchCreate(ctx context.Context, details []*DictionaryDetail) error + BatchUpdateParentID(ctx context.Context, idMap map[uint]uint) error +} + +// DictionaryUsecase 字典用例 +type DictionaryUsecase struct { + repo DictionaryRepo + detailRepo DictionaryDetailRepo +} + +// NewDictionaryUsecase 创建字典用例 +func NewDictionaryUsecase(repo DictionaryRepo, detailRepo DictionaryDetailRepo) *DictionaryUsecase { + return &DictionaryUsecase{repo: repo, detailRepo: detailRepo} +} + +// CreateDictionary 创建字典 +func (uc *DictionaryUsecase) CreateDictionary(ctx context.Context, dict *Dictionary) error { + // 检查type是否重复 + existing, err := uc.repo.FindByType(ctx, dict.Type) + if err == nil && existing != nil { + return errors.New("存在相同的type,不允许创建") + } + return uc.repo.Create(ctx, dict) +} + +// UpdateDictionary 更新字典 +func (uc *DictionaryUsecase) UpdateDictionary(ctx context.Context, dict *Dictionary) error { + old, err := uc.repo.FindByID(ctx, dict.ID) + if err != nil { + return errors.New("查询字典数据失败") + } + // 如果type变更,检查是否重复 + if old.Type != dict.Type { + existing, err := uc.repo.FindByType(ctx, dict.Type) + if err == nil && existing != nil { + return errors.New("存在相同的type,不允许创建") + } + } + // 检查循环引用 + if dict.ParentID != nil && *dict.ParentID != 0 { + if err := uc.repo.CheckCircularReference(ctx, dict.ID, *dict.ParentID); err != nil { + return err + } + } + return uc.repo.Update(ctx, dict) +} + +// DeleteDictionary 删除字典 +func (uc *DictionaryUsecase) DeleteDictionary(ctx context.Context, id uint) error { + dict, err := uc.repo.FindByID(ctx, id) + if err != nil { + return errors.New("请不要搞事") + } + if err := uc.repo.Delete(ctx, id); err != nil { + return err + } + // 删除关联的字典详情 + return uc.detailRepo.DeleteByDictionaryID(ctx, dict.ID) +} + +// GetDictionary 获取字典 +func (uc *DictionaryUsecase) GetDictionary(ctx context.Context, typ string, id uint, status *bool) (*Dictionary, error) { + return uc.repo.GetByTypeOrID(ctx, typ, id, status) +} + +// GetDictionaryList 获取字典列表 +func (uc *DictionaryUsecase) GetDictionaryList(ctx context.Context, name string) ([]*Dictionary, error) { + return uc.repo.List(ctx, name) +} + +// ExportDictionary 导出字典 +func (uc *DictionaryUsecase) ExportDictionary(ctx context.Context, id uint) (map[string]interface{}, error) { + dict, err := uc.repo.FindByID(ctx, id) + if err != nil { + return nil, err + } + details, err := uc.detailRepo.GetListByDictionaryID(ctx, dict.ID) + if err != nil { + return nil, err + } + + // 清理详情数据 + var cleanDetails []map[string]interface{} + for _, detail := range details { + cleanDetail := map[string]interface{}{ + "label": detail.Label, + "value": detail.Value, + "extend": detail.Extend, + "status": detail.Status, + "sort": detail.Sort, + "level": detail.Level, + "path": detail.Path, + } + cleanDetails = append(cleanDetails, cleanDetail) + } + + return map[string]interface{}{ + "name": dict.Name, + "type": dict.Type, + "status": dict.Status, + "desc": dict.Desc, + "sysDictionaryDetails": cleanDetails, + }, nil +} + +// ImportDictionary 导入字典 +func (uc *DictionaryUsecase) ImportDictionary(ctx context.Context, jsonStr string) error { + var importData struct { + Name string `json:"name"` + Type string `json:"type"` + Status *bool `json:"status"` + Desc string `json:"desc"` + SysDictionaryDetails []*DictionaryDetail `json:"sysDictionaryDetails"` + } + if err := json.Unmarshal([]byte(jsonStr), &importData); err != nil { + return errors.New("JSON 格式错误: " + err.Error()) + } + if importData.Name == "" { + return errors.New("字典名称不能为空") + } + if importData.Type == "" { + return errors.New("字典类型不能为空") + } + // 检查type是否重复 + existing, err := uc.repo.FindByType(ctx, importData.Type) + if err == nil && existing != nil { + return errors.New("存在相同的type,不允许导入") + } + + // 创建字典 + dict := &Dictionary{ + Name: importData.Name, + Type: importData.Type, + Status: importData.Status, + Desc: importData.Desc, + } + if err := uc.repo.Create(ctx, dict); err != nil { + return err + } + + // 处理字典详情 + if len(importData.SysDictionaryDetails) > 0 { + idMap := make(map[uint]uint) + for _, detail := range importData.SysDictionaryDetails { + if detail.Label == "" || detail.Value == "" { + continue + } + oldID := detail.ID + newDetail := &DictionaryDetail{ + Label: detail.Label, + Value: detail.Value, + Extend: detail.Extend, + Status: detail.Status, + Sort: detail.Sort, + Level: detail.Level, + Path: detail.Path, + SysDictionaryID: dict.ID, + } + if err := uc.detailRepo.Create(ctx, newDetail); err != nil { + return err + } + if oldID > 0 { + idMap[oldID] = newDetail.ID + } + } + // 更新parent_id关系 + if len(idMap) > 0 { + if err := uc.detailRepo.BatchUpdateParentID(ctx, idMap); err != nil { + return err + } + } + } + return nil +} + +// CreateDictionaryDetail 创建字典详情 +func (uc *DictionaryUsecase) CreateDictionaryDetail(ctx context.Context, detail *DictionaryDetail) error { + // 计算层级和路径 + if detail.ParentID != nil && *detail.ParentID != 0 { + parent, err := uc.detailRepo.FindByID(ctx, *detail.ParentID) + if err != nil { + return err + } + detail.Level = parent.Level + 1 + if parent.Path == "" { + detail.Path = strconv.Itoa(int(parent.ID)) + } else { + detail.Path = parent.Path + "," + strconv.Itoa(int(parent.ID)) + } + } else { + detail.Level = 0 + detail.Path = "" + } + return uc.detailRepo.Create(ctx, detail) +} + +// UpdateDictionaryDetail 更新字典详情 +func (uc *DictionaryUsecase) UpdateDictionaryDetail(ctx context.Context, detail *DictionaryDetail) error { + // 如果更新了父级ID,重新计算层级和路径 + if detail.ParentID != nil && *detail.ParentID != 0 { + parent, err := uc.detailRepo.FindByID(ctx, *detail.ParentID) + if err != nil { + return err + } + // 检查循环引用 + if uc.detailRepo.CheckCircularReference(ctx, detail.ID, *detail.ParentID) { + return errors.New("不能将字典详情设置为自己或其子项的父级") + } + detail.Level = parent.Level + 1 + if parent.Path == "" { + detail.Path = strconv.Itoa(int(parent.ID)) + } else { + detail.Path = parent.Path + "," + strconv.Itoa(int(parent.ID)) + } + } else { + detail.Level = 0 + detail.Path = "" + } + if err := uc.detailRepo.Update(ctx, detail); err != nil { + return err + } + // 更新所有子项的层级和路径 + return uc.detailRepo.UpdateChildrenLevelAndPath(ctx, detail.ID) +} + +// DeleteDictionaryDetail 删除字典详情 +func (uc *DictionaryUsecase) DeleteDictionaryDetail(ctx context.Context, id uint) error { + hasChildren, err := uc.detailRepo.HasChildren(ctx, id) + if err != nil { + return err + } + if hasChildren { + return errors.New("该字典详情下还有子项,无法删除") + } + return uc.detailRepo.Delete(ctx, id) +} + +// GetDictionaryDetail 获取字典详情 +func (uc *DictionaryUsecase) GetDictionaryDetail(ctx context.Context, id uint) (*DictionaryDetail, error) { + return uc.detailRepo.FindByID(ctx, id) +} + +// GetDictionaryDetailList 获取字典详情列表 +func (uc *DictionaryUsecase) GetDictionaryDetailList(ctx context.Context, page, pageSize int, filters map[string]interface{}) ([]*DictionaryDetail, int64, error) { + return uc.detailRepo.List(ctx, page, pageSize, filters) +} + +// GetDictionaryTreeList 获取字典树形列表 +func (uc *DictionaryUsecase) GetDictionaryTreeList(ctx context.Context, dictionaryID uint) ([]*DictionaryDetail, error) { + return uc.detailRepo.GetTreeList(ctx, dictionaryID) +} + +// GetDictionaryDetailsByParent 根据父级获取字典详情 +func (uc *DictionaryUsecase) GetDictionaryDetailsByParent(ctx context.Context, dictionaryID uint, parentID *uint, includeChildren bool) ([]*DictionaryDetail, error) { + return uc.detailRepo.GetByParent(ctx, dictionaryID, parentID, includeChildren) +} + +// GetDictionaryInfoByValue 根据字典ID和值获取详情 +func (uc *DictionaryUsecase) GetDictionaryInfoByValue(ctx context.Context, dictionaryID uint, value string) (*DictionaryDetail, error) { + return uc.detailRepo.GetByDictionaryIDAndValue(ctx, dictionaryID, value) +} + +// GetDictionaryInfoByTypeValue 根据字典类型和值获取详情 +func (uc *DictionaryUsecase) GetDictionaryInfoByTypeValue(ctx context.Context, typ, value string) (*DictionaryDetail, error) { + return uc.detailRepo.GetByTypeAndValue(ctx, typ, value) +} + +// GetDictionaryTreeListByType 根据类型获取树形列表 +func (uc *DictionaryUsecase) GetDictionaryTreeListByType(ctx context.Context, typ string) ([]*DictionaryDetail, error) { + return uc.detailRepo.GetTreeListByType(ctx, typ) +} + +// GetDictionaryListByType 根据类型获取列表 +func (uc *DictionaryUsecase) GetDictionaryListByType(ctx context.Context, typ string) ([]*DictionaryDetail, error) { + return uc.detailRepo.GetListByType(ctx, typ) +} + +// GetDictionaryPath 获取字典详情路径 +func (uc *DictionaryUsecase) GetDictionaryPath(ctx context.Context, id uint) ([]*DictionaryDetail, error) { + return uc.detailRepo.GetPath(ctx, id) +} + +// GetDictionaryPathByValue 根据值获取字典详情路径 +func (uc *DictionaryUsecase) GetDictionaryPathByValue(ctx context.Context, dictionaryID uint, value string) ([]*DictionaryDetail, error) { + detail, err := uc.detailRepo.GetByDictionaryIDAndValue(ctx, dictionaryID, value) + if err != nil { + return nil, err + } + return uc.detailRepo.GetPath(ctx, detail.ID) +} diff --git a/internal/biz/system/operation_record.go b/internal/biz/system/operation_record.go new file mode 100644 index 0000000..2e17452 --- /dev/null +++ b/internal/biz/system/operation_record.go @@ -0,0 +1,63 @@ +package system + +import "context" + +// OperationRecord 操作记录实体 +type OperationRecord struct { + ID uint + IP string + Method string + Path string + Status int + Latency int64 + Agent string + ErrorMessage string + Body string + Resp string + UserID uint + User *User +} + +// OperationRecordRepo 操作记录仓储接口 +type OperationRecordRepo interface { + Create(ctx context.Context, record *OperationRecord) error + Delete(ctx context.Context, id uint) error + DeleteByIds(ctx context.Context, ids []uint) error + FindByID(ctx context.Context, id uint) (*OperationRecord, error) + List(ctx context.Context, page, pageSize int, filters map[string]interface{}) ([]*OperationRecord, int64, error) +} + +// OperationRecordUsecase 操作记录用例 +type OperationRecordUsecase struct { + repo OperationRecordRepo +} + +// NewOperationRecordUsecase 创建操作记录用例 +func NewOperationRecordUsecase(repo OperationRecordRepo) *OperationRecordUsecase { + return &OperationRecordUsecase{repo: repo} +} + +// CreateOperationRecord 创建操作记录 +func (uc *OperationRecordUsecase) CreateOperationRecord(ctx context.Context, record *OperationRecord) error { + return uc.repo.Create(ctx, record) +} + +// DeleteOperationRecord 删除操作记录 +func (uc *OperationRecordUsecase) DeleteOperationRecord(ctx context.Context, id uint) error { + return uc.repo.Delete(ctx, id) +} + +// DeleteOperationRecordByIds 批量删除操作记录 +func (uc *OperationRecordUsecase) DeleteOperationRecordByIds(ctx context.Context, ids []uint) error { + return uc.repo.DeleteByIds(ctx, ids) +} + +// GetOperationRecord 获取操作记录 +func (uc *OperationRecordUsecase) GetOperationRecord(ctx context.Context, id uint) (*OperationRecord, error) { + return uc.repo.FindByID(ctx, id) +} + +// GetOperationRecordList 获取操作记录列表 +func (uc *OperationRecordUsecase) GetOperationRecordList(ctx context.Context, page, pageSize int, filters map[string]interface{}) ([]*OperationRecord, int64, error) { + return uc.repo.List(ctx, page, pageSize, filters) +} diff --git a/internal/data/model/casbin_rule.gen.go b/internal/data/model/casbin_rule.gen.go index 7ea2c01..fe6d341 100644 --- a/internal/data/model/casbin_rule.gen.go +++ b/internal/data/model/casbin_rule.gen.go @@ -8,14 +8,14 @@ const TableNameCasbinRule = "casbin_rule" // CasbinRule mapped from table type CasbinRule struct { - ID int64 `gorm:"column:id;type:bigint(20) unsigned;primaryKey;autoIncrement:true" json:"id"` - Ptype *string `gorm:"column:ptype;type:varchar(100);uniqueIndex:idx_casbin_rule,priority:1" json:"ptype"` - V0 *string `gorm:"column:v0;type:varchar(100);uniqueIndex:idx_casbin_rule,priority:2" json:"v0"` - V1 *string `gorm:"column:v1;type:varchar(100);uniqueIndex:idx_casbin_rule,priority:3" json:"v1"` - V2 *string `gorm:"column:v2;type:varchar(100);uniqueIndex:idx_casbin_rule,priority:4" json:"v2"` - V3 *string `gorm:"column:v3;type:varchar(100);uniqueIndex:idx_casbin_rule,priority:5" json:"v3"` - V4 *string `gorm:"column:v4;type:varchar(100);uniqueIndex:idx_casbin_rule,priority:6" json:"v4"` - V5 *string `gorm:"column:v5;type:varchar(100);uniqueIndex:idx_casbin_rule,priority:7" json:"v5"` + ID int64 `gorm:"column:id;type:bigint(20) unsigned;primaryKey;autoIncrement:true" json:"id"` + Ptype string `gorm:"column:ptype;type:varchar(100);uniqueIndex:idx_casbin_rule,priority:1" json:"ptype"` + V0 string `gorm:"column:v0;type:varchar(100);uniqueIndex:idx_casbin_rule,priority:2" json:"v0"` + V1 string `gorm:"column:v1;type:varchar(100);uniqueIndex:idx_casbin_rule,priority:3" json:"v1"` + V2 string `gorm:"column:v2;type:varchar(100);uniqueIndex:idx_casbin_rule,priority:4" json:"v2"` + V3 string `gorm:"column:v3;type:varchar(100);uniqueIndex:idx_casbin_rule,priority:5" json:"v3"` + V4 string `gorm:"column:v4;type:varchar(100);uniqueIndex:idx_casbin_rule,priority:6" json:"v4"` + V5 string `gorm:"column:v5;type:varchar(100);uniqueIndex:idx_casbin_rule,priority:7" json:"v5"` } // TableName CasbinRule's table name diff --git a/internal/data/model/exa_attachment_category.gen.go b/internal/data/model/exa_attachment_category.gen.go index 5c05053..bcc6b70 100644 --- a/internal/data/model/exa_attachment_category.gen.go +++ b/internal/data/model/exa_attachment_category.gen.go @@ -15,11 +15,11 @@ const TableNameExaAttachmentCategory = "exa_attachment_category" // ExaAttachmentCategory mapped from table type ExaAttachmentCategory struct { ID int64 `gorm:"column:id;type:bigint(20) unsigned;primaryKey;autoIncrement:true" json:"id"` - CreatedAt *time.Time `gorm:"column:created_at;type:datetime(3)" json:"created_at"` - UpdatedAt *time.Time `gorm:"column:updated_at;type:datetime(3)" json:"updated_at"` + CreatedAt time.Time `gorm:"column:created_at;type:datetime(3)" json:"created_at"` + UpdatedAt time.Time `gorm:"column:updated_at;type:datetime(3)" json:"updated_at"` DeletedAt gorm.DeletedAt `gorm:"column:deleted_at;type:datetime(3);index:idx_exa_attachment_category_deleted_at,priority:1" json:"deleted_at"` - Name *string `gorm:"column:name;type:varchar(255);comment:分类名称" json:"name"` // 分类名称 - Pid *int64 `gorm:"column:pid;type:bigint(20);comment:父节点ID" json:"pid"` // 父节点ID + Name string `gorm:"column:name;type:varchar(255);comment:分类名称" json:"name"` // 分类名称 + Pid int64 `gorm:"column:pid;type:bigint(20);comment:父节点ID" json:"pid"` // 父节点ID } // TableName ExaAttachmentCategory's table name diff --git a/internal/data/model/exa_customers.gen.go b/internal/data/model/exa_customers.gen.go index 5703c8c..dd73810 100644 --- a/internal/data/model/exa_customers.gen.go +++ b/internal/data/model/exa_customers.gen.go @@ -15,13 +15,13 @@ const TableNameExaCustomer = "exa_customers" // ExaCustomer mapped from table type ExaCustomer struct { ID int64 `gorm:"column:id;type:bigint(20) unsigned;primaryKey;autoIncrement:true" json:"id"` - CreatedAt *time.Time `gorm:"column:created_at;type:datetime(3)" json:"created_at"` - UpdatedAt *time.Time `gorm:"column:updated_at;type:datetime(3)" json:"updated_at"` + CreatedAt time.Time `gorm:"column:created_at;type:datetime(3)" json:"created_at"` + UpdatedAt time.Time `gorm:"column:updated_at;type:datetime(3)" json:"updated_at"` DeletedAt gorm.DeletedAt `gorm:"column:deleted_at;type:datetime(3);index:idx_exa_customers_deleted_at,priority:1" json:"deleted_at"` - CustomerName *string `gorm:"column:customer_name;type:varchar(191);comment:客户名" json:"customer_name"` // 客户名 - CustomerPhoneData *string `gorm:"column:customer_phone_data;type:varchar(191);comment:客户手机号" json:"customer_phone_data"` // 客户手机号 - SysUserID *int64 `gorm:"column:sys_user_id;type:bigint(20) unsigned;comment:管理ID" json:"sys_user_id"` // 管理ID - SysUserAuthorityID *int64 `gorm:"column:sys_user_authority_id;type:bigint(20) unsigned;comment:管理角色ID" json:"sys_user_authority_id"` // 管理角色ID + CustomerName string `gorm:"column:customer_name;type:varchar(191);comment:客户名" json:"customer_name"` // 客户名 + CustomerPhoneData string `gorm:"column:customer_phone_data;type:varchar(191);comment:客户手机号" json:"customer_phone_data"` // 客户手机号 + SysUserID int64 `gorm:"column:sys_user_id;type:bigint(20) unsigned;comment:管理ID" json:"sys_user_id"` // 管理ID + SysUserAuthorityID int64 `gorm:"column:sys_user_authority_id;type:bigint(20) unsigned;comment:管理角色ID" json:"sys_user_authority_id"` // 管理角色ID } // TableName ExaCustomer's table name diff --git a/internal/data/model/exa_file_chunks.gen.go b/internal/data/model/exa_file_chunks.gen.go index c94b302..9a9f4c1 100644 --- a/internal/data/model/exa_file_chunks.gen.go +++ b/internal/data/model/exa_file_chunks.gen.go @@ -15,12 +15,12 @@ const TableNameExaFileChunk = "exa_file_chunks" // ExaFileChunk mapped from table type ExaFileChunk struct { ID int64 `gorm:"column:id;type:bigint(20) unsigned;primaryKey;autoIncrement:true" json:"id"` - CreatedAt *time.Time `gorm:"column:created_at;type:datetime(3)" json:"created_at"` - UpdatedAt *time.Time `gorm:"column:updated_at;type:datetime(3)" json:"updated_at"` + CreatedAt time.Time `gorm:"column:created_at;type:datetime(3)" json:"created_at"` + UpdatedAt time.Time `gorm:"column:updated_at;type:datetime(3)" json:"updated_at"` DeletedAt gorm.DeletedAt `gorm:"column:deleted_at;type:datetime(3);index:idx_exa_file_chunks_deleted_at,priority:1" json:"deleted_at"` - ExaFileID *int64 `gorm:"column:exa_file_id;type:bigint(20) unsigned" json:"exa_file_id"` - FileChunkNumber *int64 `gorm:"column:file_chunk_number;type:bigint(20)" json:"file_chunk_number"` - FileChunkPath *string `gorm:"column:file_chunk_path;type:varchar(191)" json:"file_chunk_path"` + ExaFileID int64 `gorm:"column:exa_file_id;type:bigint(20) unsigned" json:"exa_file_id"` + FileChunkNumber int64 `gorm:"column:file_chunk_number;type:bigint(20)" json:"file_chunk_number"` + FileChunkPath string `gorm:"column:file_chunk_path;type:varchar(191)" json:"file_chunk_path"` } // TableName ExaFileChunk's table name diff --git a/internal/data/model/exa_file_upload_and_downloads.gen.go b/internal/data/model/exa_file_upload_and_downloads.gen.go index f492448..fbb918c 100644 --- a/internal/data/model/exa_file_upload_and_downloads.gen.go +++ b/internal/data/model/exa_file_upload_and_downloads.gen.go @@ -15,14 +15,14 @@ const TableNameExaFileUploadAndDownload = "exa_file_upload_and_downloads" // ExaFileUploadAndDownload mapped from table type ExaFileUploadAndDownload struct { ID int64 `gorm:"column:id;type:bigint(20) unsigned;primaryKey;autoIncrement:true" json:"id"` - CreatedAt *time.Time `gorm:"column:created_at;type:datetime(3)" json:"created_at"` - UpdatedAt *time.Time `gorm:"column:updated_at;type:datetime(3)" json:"updated_at"` + CreatedAt time.Time `gorm:"column:created_at;type:datetime(3)" json:"created_at"` + UpdatedAt time.Time `gorm:"column:updated_at;type:datetime(3)" json:"updated_at"` DeletedAt gorm.DeletedAt `gorm:"column:deleted_at;type:datetime(3);index:idx_exa_file_upload_and_downloads_deleted_at,priority:1" json:"deleted_at"` - Name *string `gorm:"column:name;type:varchar(191);comment:文件名" json:"name"` // 文件名 - ClassID *int64 `gorm:"column:class_id;type:bigint(20);comment:分类id" json:"class_id"` // 分类id - URL *string `gorm:"column:url;type:varchar(191);comment:文件地址" json:"url"` // 文件地址 - Tag *string `gorm:"column:tag;type:varchar(191);comment:文件标签" json:"tag"` // 文件标签 - Key *string `gorm:"column:key;type:varchar(191);comment:编号" json:"key"` // 编号 + Name string `gorm:"column:name;type:varchar(191);comment:文件名" json:"name"` // 文件名 + ClassID int64 `gorm:"column:class_id;type:bigint(20);comment:分类id" json:"class_id"` // 分类id + URL string `gorm:"column:url;type:varchar(191);comment:文件地址" json:"url"` // 文件地址 + Tag string `gorm:"column:tag;type:varchar(191);comment:文件标签" json:"tag"` // 文件标签 + Key string `gorm:"column:key;type:varchar(191);comment:编号" json:"key"` // 编号 } // TableName ExaFileUploadAndDownload's table name diff --git a/internal/data/model/exa_files.gen.go b/internal/data/model/exa_files.gen.go index 877fd4d..f667971 100644 --- a/internal/data/model/exa_files.gen.go +++ b/internal/data/model/exa_files.gen.go @@ -15,14 +15,14 @@ const TableNameExaFile = "exa_files" // ExaFile mapped from table type ExaFile struct { ID int64 `gorm:"column:id;type:bigint(20) unsigned;primaryKey;autoIncrement:true" json:"id"` - CreatedAt *time.Time `gorm:"column:created_at;type:datetime(3)" json:"created_at"` - UpdatedAt *time.Time `gorm:"column:updated_at;type:datetime(3)" json:"updated_at"` + CreatedAt time.Time `gorm:"column:created_at;type:datetime(3)" json:"created_at"` + UpdatedAt time.Time `gorm:"column:updated_at;type:datetime(3)" json:"updated_at"` DeletedAt gorm.DeletedAt `gorm:"column:deleted_at;type:datetime(3);index:idx_exa_files_deleted_at,priority:1" json:"deleted_at"` - FileName *string `gorm:"column:file_name;type:varchar(191)" json:"file_name"` - FileMd5 *string `gorm:"column:file_md5;type:varchar(191)" json:"file_md5"` - FilePath *string `gorm:"column:file_path;type:varchar(191)" json:"file_path"` - ChunkTotal *int64 `gorm:"column:chunk_total;type:bigint(20)" json:"chunk_total"` - IsFinish *bool `gorm:"column:is_finish;type:tinyint(1)" json:"is_finish"` + FileName string `gorm:"column:file_name;type:varchar(191)" json:"file_name"` + FileMd5 string `gorm:"column:file_md5;type:varchar(191)" json:"file_md5"` + FilePath string `gorm:"column:file_path;type:varchar(191)" json:"file_path"` + ChunkTotal int64 `gorm:"column:chunk_total;type:bigint(20)" json:"chunk_total"` + IsFinish bool `gorm:"column:is_finish;type:tinyint(1)" json:"is_finish"` } // TableName ExaFile's table name diff --git a/internal/data/model/gva_announcements_info.gen.go b/internal/data/model/gva_announcements_info.gen.go index 7f1e4c1..6d6e264 100644 --- a/internal/data/model/gva_announcements_info.gen.go +++ b/internal/data/model/gva_announcements_info.gen.go @@ -15,13 +15,13 @@ const TableNameGvaAnnouncementsInfo = "gva_announcements_info" // GvaAnnouncementsInfo mapped from table type GvaAnnouncementsInfo struct { ID int64 `gorm:"column:id;type:bigint(20) unsigned;primaryKey;autoIncrement:true" json:"id"` - CreatedAt *time.Time `gorm:"column:created_at;type:datetime(3)" json:"created_at"` - UpdatedAt *time.Time `gorm:"column:updated_at;type:datetime(3)" json:"updated_at"` + CreatedAt time.Time `gorm:"column:created_at;type:datetime(3)" json:"created_at"` + UpdatedAt time.Time `gorm:"column:updated_at;type:datetime(3)" json:"updated_at"` DeletedAt gorm.DeletedAt `gorm:"column:deleted_at;type:datetime(3);index:idx_gva_announcements_info_deleted_at,priority:1" json:"deleted_at"` - Title *string `gorm:"column:title;type:varchar(191);comment:公告标题" json:"title"` // 公告标题 - Content *string `gorm:"column:content;type:text;comment:公告内容" json:"content"` // 公告内容 - UserID *int64 `gorm:"column:user_id;type:bigint(20);comment:发布者" json:"user_id"` // 发布者 - Attachments *string `gorm:"column:attachments;type:json;comment:相关附件" json:"attachments"` // 相关附件 + Title string `gorm:"column:title;type:varchar(191);comment:公告标题" json:"title"` // 公告标题 + Content string `gorm:"column:content;type:text;comment:公告内容" json:"content"` // 公告内容 + UserID int64 `gorm:"column:user_id;type:bigint(20);comment:发布者" json:"user_id"` // 发布者 + Attachments string `gorm:"column:attachments;type:json;comment:相关附件" json:"attachments"` // 相关附件 } // TableName GvaAnnouncementsInfo's table name diff --git a/internal/data/model/jwt_blacklists.gen.go b/internal/data/model/jwt_blacklists.gen.go index 6813d08..3472985 100644 --- a/internal/data/model/jwt_blacklists.gen.go +++ b/internal/data/model/jwt_blacklists.gen.go @@ -15,10 +15,10 @@ const TableNameJwtBlacklist = "jwt_blacklists" // JwtBlacklist mapped from table type JwtBlacklist struct { ID int64 `gorm:"column:id;type:bigint(20) unsigned;primaryKey;autoIncrement:true" json:"id"` - CreatedAt *time.Time `gorm:"column:created_at;type:datetime(3)" json:"created_at"` - UpdatedAt *time.Time `gorm:"column:updated_at;type:datetime(3)" json:"updated_at"` + CreatedAt time.Time `gorm:"column:created_at;type:datetime(3)" json:"created_at"` + UpdatedAt time.Time `gorm:"column:updated_at;type:datetime(3)" json:"updated_at"` DeletedAt gorm.DeletedAt `gorm:"column:deleted_at;type:datetime(3);index:idx_jwt_blacklists_deleted_at,priority:1" json:"deleted_at"` - Jwt *string `gorm:"column:jwt;type:text;comment:jwt" json:"jwt"` // jwt + Jwt string `gorm:"column:jwt;type:text;comment:jwt" json:"jwt"` // jwt } // TableName JwtBlacklist's table name diff --git a/internal/data/model/sys_apis.gen.go b/internal/data/model/sys_apis.gen.go index b647848..82d06f1 100644 --- a/internal/data/model/sys_apis.gen.go +++ b/internal/data/model/sys_apis.gen.go @@ -15,13 +15,13 @@ const TableNameSysAPI = "sys_apis" // SysAPI mapped from table type SysAPI struct { ID int64 `gorm:"column:id;type:bigint(20) unsigned;primaryKey;autoIncrement:true" json:"id"` - CreatedAt *time.Time `gorm:"column:created_at;type:datetime(3)" json:"created_at"` - UpdatedAt *time.Time `gorm:"column:updated_at;type:datetime(3)" json:"updated_at"` + CreatedAt time.Time `gorm:"column:created_at;type:datetime(3)" json:"created_at"` + UpdatedAt time.Time `gorm:"column:updated_at;type:datetime(3)" json:"updated_at"` DeletedAt gorm.DeletedAt `gorm:"column:deleted_at;type:datetime(3);index:idx_sys_apis_deleted_at,priority:1" json:"deleted_at"` - Path *string `gorm:"column:path;type:varchar(191);comment:api路径" json:"path"` // api路径 - Description *string `gorm:"column:description;type:varchar(191);comment:api中文描述" json:"description"` // api中文描述 - APIGroup *string `gorm:"column:api_group;type:varchar(191);comment:api组" json:"api_group"` // api组 - Method *string `gorm:"column:method;type:varchar(191);default:POST;comment:方法" json:"method"` // 方法 + Path string `gorm:"column:path;type:varchar(191);comment:api路径" json:"path"` // api路径 + Description string `gorm:"column:description;type:varchar(191);comment:api中文描述" json:"description"` // api中文描述 + APIGroup string `gorm:"column:api_group;type:varchar(191);comment:api组" json:"api_group"` // api组 + Method string `gorm:"column:method;type:varchar(191);default:POST;comment:方法" json:"method"` // 方法 } // TableName SysAPI's table name diff --git a/internal/data/model/sys_authorities.gen.go b/internal/data/model/sys_authorities.gen.go index c1f0dd4..2cb74d0 100644 --- a/internal/data/model/sys_authorities.gen.go +++ b/internal/data/model/sys_authorities.gen.go @@ -14,13 +14,13 @@ const TableNameSysAuthority = "sys_authorities" // SysAuthority mapped from table type SysAuthority struct { - CreatedAt *time.Time `gorm:"column:created_at;type:datetime(3)" json:"created_at"` - UpdatedAt *time.Time `gorm:"column:updated_at;type:datetime(3)" json:"updated_at"` + CreatedAt time.Time `gorm:"column:created_at;type:datetime(3)" json:"created_at"` + UpdatedAt time.Time `gorm:"column:updated_at;type:datetime(3)" json:"updated_at"` DeletedAt gorm.DeletedAt `gorm:"column:deleted_at;type:datetime(3)" json:"deleted_at"` AuthorityID int64 `gorm:"column:authority_id;type:bigint(20) unsigned;primaryKey;autoIncrement:true;uniqueIndex:uni_sys_authorities_authority_id,priority:1;comment:角色ID" json:"authority_id"` // 角色ID - AuthorityName *string `gorm:"column:authority_name;type:varchar(191);comment:角色名" json:"authority_name"` // 角色名 - ParentID *int64 `gorm:"column:parent_id;type:bigint(20) unsigned;comment:父角色ID" json:"parent_id"` // 父角色ID - DefaultRouter *string `gorm:"column:default_router;type:varchar(191);default:dashboard;comment:默认菜单" json:"default_router"` // 默认菜单 + AuthorityName string `gorm:"column:authority_name;type:varchar(191);comment:角色名" json:"authority_name"` // 角色名 + ParentID int64 `gorm:"column:parent_id;type:bigint(20) unsigned;comment:父角色ID" json:"parent_id"` // 父角色ID + DefaultRouter string `gorm:"column:default_router;type:varchar(191);default:dashboard;comment:默认菜单" json:"default_router"` // 默认菜单 } // TableName SysAuthority's table name diff --git a/internal/data/model/sys_authority_btns.gen.go b/internal/data/model/sys_authority_btns.gen.go index df76612..c749f66 100644 --- a/internal/data/model/sys_authority_btns.gen.go +++ b/internal/data/model/sys_authority_btns.gen.go @@ -8,9 +8,9 @@ const TableNameSysAuthorityBtn = "sys_authority_btns" // SysAuthorityBtn mapped from table type SysAuthorityBtn struct { - AuthorityID *int64 `gorm:"column:authority_id;type:bigint(20) unsigned;comment:角色ID" json:"authority_id"` // 角色ID - SysMenuID *int64 `gorm:"column:sys_menu_id;type:bigint(20) unsigned;comment:菜单ID" json:"sys_menu_id"` // 菜单ID - SysBaseMenuBtnID *int64 `gorm:"column:sys_base_menu_btn_id;type:bigint(20) unsigned;comment:菜单按钮ID" json:"sys_base_menu_btn_id"` // 菜单按钮ID + AuthorityID int64 `gorm:"column:authority_id;type:bigint(20) unsigned;comment:角色ID" json:"authority_id"` // 角色ID + SysMenuID int64 `gorm:"column:sys_menu_id;type:bigint(20) unsigned;comment:菜单ID" json:"sys_menu_id"` // 菜单ID + SysBaseMenuBtnID int64 `gorm:"column:sys_base_menu_btn_id;type:bigint(20) unsigned;comment:菜单按钮ID" json:"sys_base_menu_btn_id"` // 菜单按钮ID } // TableName SysAuthorityBtn's table name diff --git a/internal/data/model/sys_auto_code_histories.gen.go b/internal/data/model/sys_auto_code_histories.gen.go index 29c26b5..29255c7 100644 --- a/internal/data/model/sys_auto_code_histories.gen.go +++ b/internal/data/model/sys_auto_code_histories.gen.go @@ -15,23 +15,23 @@ const TableNameSysAutoCodeHistory = "sys_auto_code_histories" // SysAutoCodeHistory mapped from table type SysAutoCodeHistory struct { ID int64 `gorm:"column:id;type:bigint(20) unsigned;primaryKey;autoIncrement:true" json:"id"` - CreatedAt *time.Time `gorm:"column:created_at;type:datetime(3)" json:"created_at"` - UpdatedAt *time.Time `gorm:"column:updated_at;type:datetime(3)" json:"updated_at"` + CreatedAt time.Time `gorm:"column:created_at;type:datetime(3)" json:"created_at"` + UpdatedAt time.Time `gorm:"column:updated_at;type:datetime(3)" json:"updated_at"` DeletedAt gorm.DeletedAt `gorm:"column:deleted_at;type:datetime(3);index:idx_sys_auto_code_histories_deleted_at,priority:1" json:"deleted_at"` - TblName *string `gorm:"column:table_name;type:varchar(191);comment:表名" json:"table_name"` // 表名 - Package *string `gorm:"column:package;type:varchar(191);comment:模块名/插件名" json:"package"` // 模块名/插件名 - Request *string `gorm:"column:request;type:text;comment:前端传入的结构化信息" json:"request"` // 前端传入的结构化信息 - StructName *string `gorm:"column:struct_name;type:varchar(191);comment:结构体名称" json:"struct_name"` // 结构体名称 - Abbreviation *string `gorm:"column:abbreviation;type:varchar(191);comment:结构体名称缩写" json:"abbreviation"` // 结构体名称缩写 - BusinessDb *string `gorm:"column:business_db;type:varchar(191);comment:业务库" json:"business_db"` // 业务库 - Description *string `gorm:"column:description;type:varchar(191);comment:Struct中文名称" json:"description"` // Struct中文名称 - Templates *string `gorm:"column:templates;type:text;comment:模板信息" json:"templates"` // 模板信息 - Injections *string `gorm:"column:Injections;type:text;comment:注入路径" json:"Injections"` // 注入路径 - Flag *int64 `gorm:"column:flag;type:bigint(20);comment:[0:创建,1:回滚]" json:"flag"` // [0:创建,1:回滚] - APIIds *string `gorm:"column:api_ids;type:varchar(191);comment:api表注册内容" json:"api_ids"` // api表注册内容 - MenuID *int64 `gorm:"column:menu_id;type:bigint(20) unsigned;comment:菜单ID" json:"menu_id"` // 菜单ID - ExportTemplateID *int64 `gorm:"column:export_template_id;type:bigint(20) unsigned;comment:导出模板ID" json:"export_template_id"` // 导出模板ID - PackageID *int64 `gorm:"column:package_id;type:bigint(20) unsigned;comment:包ID" json:"package_id"` // 包ID + TblName string `gorm:"column:table_name;type:varchar(191);comment:表名" json:"table_name"` // 表名 + Package string `gorm:"column:package;type:varchar(191);comment:模块名/插件名" json:"package"` // 模块名/插件名 + Request string `gorm:"column:request;type:text;comment:前端传入的结构化信息" json:"request"` // 前端传入的结构化信息 + StructName string `gorm:"column:struct_name;type:varchar(191);comment:结构体名称" json:"struct_name"` // 结构体名称 + Abbreviation string `gorm:"column:abbreviation;type:varchar(191);comment:结构体名称缩写" json:"abbreviation"` // 结构体名称缩写 + BusinessDb string `gorm:"column:business_db;type:varchar(191);comment:业务库" json:"business_db"` // 业务库 + Description string `gorm:"column:description;type:varchar(191);comment:Struct中文名称" json:"description"` // Struct中文名称 + Templates string `gorm:"column:templates;type:text;comment:模板信息" json:"templates"` // 模板信息 + Injections string `gorm:"column:Injections;type:text;comment:注入路径" json:"Injections"` // 注入路径 + Flag int64 `gorm:"column:flag;type:bigint(20);comment:[0:创建,1:回滚]" json:"flag"` // [0:创建,1:回滚] + APIIds string `gorm:"column:api_ids;type:varchar(191);comment:api表注册内容" json:"api_ids"` // api表注册内容 + MenuID int64 `gorm:"column:menu_id;type:bigint(20) unsigned;comment:菜单ID" json:"menu_id"` // 菜单ID + ExportTemplateID int64 `gorm:"column:export_template_id;type:bigint(20) unsigned;comment:导出模板ID" json:"export_template_id"` // 导出模板ID + PackageID int64 `gorm:"column:package_id;type:bigint(20) unsigned;comment:包ID" json:"package_id"` // 包ID } // TableName SysAutoCodeHistory's table name diff --git a/internal/data/model/sys_auto_code_packages.gen.go b/internal/data/model/sys_auto_code_packages.gen.go index 4def520..865db95 100644 --- a/internal/data/model/sys_auto_code_packages.gen.go +++ b/internal/data/model/sys_auto_code_packages.gen.go @@ -15,14 +15,14 @@ const TableNameSysAutoCodePackage = "sys_auto_code_packages" // SysAutoCodePackage mapped from table type SysAutoCodePackage struct { ID int64 `gorm:"column:id;type:bigint(20) unsigned;primaryKey;autoIncrement:true" json:"id"` - CreatedAt *time.Time `gorm:"column:created_at;type:datetime(3)" json:"created_at"` - UpdatedAt *time.Time `gorm:"column:updated_at;type:datetime(3)" json:"updated_at"` + CreatedAt time.Time `gorm:"column:created_at;type:datetime(3)" json:"created_at"` + UpdatedAt time.Time `gorm:"column:updated_at;type:datetime(3)" json:"updated_at"` DeletedAt gorm.DeletedAt `gorm:"column:deleted_at;type:datetime(3);index:idx_sys_auto_code_packages_deleted_at,priority:1" json:"deleted_at"` - Desc *string `gorm:"column:desc;type:varchar(191);comment:描述" json:"desc"` // 描述 - Label *string `gorm:"column:label;type:varchar(191);comment:展示名" json:"label"` // 展示名 - Template *string `gorm:"column:template;type:varchar(191);comment:模版" json:"template"` // 模版 - PackageName *string `gorm:"column:package_name;type:varchar(191);comment:包名" json:"package_name"` // 包名 - Module *string `gorm:"column:module;type:varchar(191)" json:"module"` + Desc string `gorm:"column:desc;type:varchar(191);comment:描述" json:"desc"` // 描述 + Label string `gorm:"column:label;type:varchar(191);comment:展示名" json:"label"` // 展示名 + Template string `gorm:"column:template;type:varchar(191);comment:模版" json:"template"` // 模版 + PackageName string `gorm:"column:package_name;type:varchar(191);comment:包名" json:"package_name"` // 包名 + Module string `gorm:"column:module;type:varchar(191)" json:"module"` } // TableName SysAutoCodePackage's table name diff --git a/internal/data/model/sys_base_menu_btns.gen.go b/internal/data/model/sys_base_menu_btns.gen.go index 88b627b..1d51aa4 100644 --- a/internal/data/model/sys_base_menu_btns.gen.go +++ b/internal/data/model/sys_base_menu_btns.gen.go @@ -15,12 +15,12 @@ const TableNameSysBaseMenuBtn = "sys_base_menu_btns" // SysBaseMenuBtn mapped from table type SysBaseMenuBtn struct { ID int64 `gorm:"column:id;type:bigint(20) unsigned;primaryKey;autoIncrement:true" json:"id"` - CreatedAt *time.Time `gorm:"column:created_at;type:datetime(3)" json:"created_at"` - UpdatedAt *time.Time `gorm:"column:updated_at;type:datetime(3)" json:"updated_at"` + CreatedAt time.Time `gorm:"column:created_at;type:datetime(3)" json:"created_at"` + UpdatedAt time.Time `gorm:"column:updated_at;type:datetime(3)" json:"updated_at"` DeletedAt gorm.DeletedAt `gorm:"column:deleted_at;type:datetime(3);index:idx_sys_base_menu_btns_deleted_at,priority:1" json:"deleted_at"` - Name *string `gorm:"column:name;type:varchar(191);comment:按钮关键key" json:"name"` // 按钮关键key - Desc *string `gorm:"column:desc;type:varchar(191)" json:"desc"` - SysBaseMenuID *int64 `gorm:"column:sys_base_menu_id;type:bigint(20) unsigned;comment:菜单ID" json:"sys_base_menu_id"` // 菜单ID + Name string `gorm:"column:name;type:varchar(191);comment:按钮关键key" json:"name"` // 按钮关键key + Desc string `gorm:"column:desc;type:varchar(191)" json:"desc"` + SysBaseMenuID int64 `gorm:"column:sys_base_menu_id;type:bigint(20) unsigned;comment:菜单ID" json:"sys_base_menu_id"` // 菜单ID } // TableName SysBaseMenuBtn's table name diff --git a/internal/data/model/sys_base_menu_parameters.gen.go b/internal/data/model/sys_base_menu_parameters.gen.go index c502da6..d1329d7 100644 --- a/internal/data/model/sys_base_menu_parameters.gen.go +++ b/internal/data/model/sys_base_menu_parameters.gen.go @@ -15,13 +15,13 @@ const TableNameSysBaseMenuParameter = "sys_base_menu_parameters" // SysBaseMenuParameter mapped from table type SysBaseMenuParameter struct { ID int64 `gorm:"column:id;type:bigint(20) unsigned;primaryKey;autoIncrement:true" json:"id"` - CreatedAt *time.Time `gorm:"column:created_at;type:datetime(3)" json:"created_at"` - UpdatedAt *time.Time `gorm:"column:updated_at;type:datetime(3)" json:"updated_at"` + CreatedAt time.Time `gorm:"column:created_at;type:datetime(3)" json:"created_at"` + UpdatedAt time.Time `gorm:"column:updated_at;type:datetime(3)" json:"updated_at"` DeletedAt gorm.DeletedAt `gorm:"column:deleted_at;type:datetime(3);index:idx_sys_base_menu_parameters_deleted_at,priority:1" json:"deleted_at"` - SysBaseMenuID *int64 `gorm:"column:sys_base_menu_id;type:bigint(20) unsigned" json:"sys_base_menu_id"` - Type *string `gorm:"column:type;type:varchar(191);comment:地址栏携带参数为params还是query" json:"type"` // 地址栏携带参数为params还是query - Key *string `gorm:"column:key;type:varchar(191);comment:地址栏携带参数的key" json:"key"` // 地址栏携带参数的key - Value *string `gorm:"column:value;type:varchar(191);comment:地址栏携带参数的值" json:"value"` // 地址栏携带参数的值 + SysBaseMenuID int64 `gorm:"column:sys_base_menu_id;type:bigint(20) unsigned" json:"sys_base_menu_id"` + Type string `gorm:"column:type;type:varchar(191);comment:地址栏携带参数为params还是query" json:"type"` // 地址栏携带参数为params还是query + Key string `gorm:"column:key;type:varchar(191);comment:地址栏携带参数的key" json:"key"` // 地址栏携带参数的key + Value string `gorm:"column:value;type:varchar(191);comment:地址栏携带参数的值" json:"value"` // 地址栏携带参数的值 } // TableName SysBaseMenuParameter's table name diff --git a/internal/data/model/sys_base_menus.gen.go b/internal/data/model/sys_base_menus.gen.go index 592c131..2a47f35 100644 --- a/internal/data/model/sys_base_menus.gen.go +++ b/internal/data/model/sys_base_menus.gen.go @@ -15,23 +15,23 @@ const TableNameSysBaseMenu = "sys_base_menus" // SysBaseMenu mapped from table type SysBaseMenu struct { ID int64 `gorm:"column:id;type:bigint(20) unsigned;primaryKey;autoIncrement:true" json:"id"` - CreatedAt *time.Time `gorm:"column:created_at;type:datetime(3)" json:"created_at"` - UpdatedAt *time.Time `gorm:"column:updated_at;type:datetime(3)" json:"updated_at"` + CreatedAt time.Time `gorm:"column:created_at;type:datetime(3)" json:"created_at"` + UpdatedAt time.Time `gorm:"column:updated_at;type:datetime(3)" json:"updated_at"` DeletedAt gorm.DeletedAt `gorm:"column:deleted_at;type:datetime(3);index:idx_sys_base_menus_deleted_at,priority:1" json:"deleted_at"` - MenuLevel *int64 `gorm:"column:menu_level;type:bigint(20) unsigned" json:"menu_level"` - ParentID *int64 `gorm:"column:parent_id;type:bigint(20) unsigned;comment:父菜单ID" json:"parent_id"` // 父菜单ID - Path *string `gorm:"column:path;type:varchar(191);comment:路由path" json:"path"` // 路由path - Name *string `gorm:"column:name;type:varchar(191);comment:路由name" json:"name"` // 路由name - Hidden *bool `gorm:"column:hidden;type:tinyint(1);comment:是否在列表隐藏" json:"hidden"` // 是否在列表隐藏 - Component *string `gorm:"column:component;type:varchar(191);comment:对应前端文件路径" json:"component"` // 对应前端文件路径 - Sort *int64 `gorm:"column:sort;type:bigint(20);comment:排序标记" json:"sort"` // 排序标记 - ActiveName *string `gorm:"column:active_name;type:varchar(191);comment:高亮菜单" json:"active_name"` // 高亮菜单 - KeepAlive *bool `gorm:"column:keep_alive;type:tinyint(1);comment:是否缓存" json:"keep_alive"` // 是否缓存 - DefaultMenu *bool `gorm:"column:default_menu;type:tinyint(1);comment:是否是基础路由(开发中)" json:"default_menu"` // 是否是基础路由(开发中) - Title *string `gorm:"column:title;type:varchar(191);comment:菜单名" json:"title"` // 菜单名 - Icon *string `gorm:"column:icon;type:varchar(191);comment:菜单图标" json:"icon"` // 菜单图标 - CloseTab *bool `gorm:"column:close_tab;type:tinyint(1);comment:自动关闭tab" json:"close_tab"` // 自动关闭tab - TransitionType *string `gorm:"column:transition_type;type:varchar(191);comment:路由切换动画" json:"transition_type"` // 路由切换动画 + MenuLevel int64 `gorm:"column:menu_level;type:bigint(20) unsigned" json:"menu_level"` + ParentID int64 `gorm:"column:parent_id;type:bigint(20) unsigned;comment:父菜单ID" json:"parent_id"` // 父菜单ID + Path string `gorm:"column:path;type:varchar(191);comment:路由path" json:"path"` // 路由path + Name string `gorm:"column:name;type:varchar(191);comment:路由name" json:"name"` // 路由name + Hidden bool `gorm:"column:hidden;type:tinyint(1);comment:是否在列表隐藏" json:"hidden"` // 是否在列表隐藏 + Component string `gorm:"column:component;type:varchar(191);comment:对应前端文件路径" json:"component"` // 对应前端文件路径 + Sort int64 `gorm:"column:sort;type:bigint(20);comment:排序标记" json:"sort"` // 排序标记 + ActiveName string `gorm:"column:active_name;type:varchar(191);comment:高亮菜单" json:"active_name"` // 高亮菜单 + KeepAlive bool `gorm:"column:keep_alive;type:tinyint(1);comment:是否缓存" json:"keep_alive"` // 是否缓存 + DefaultMenu bool `gorm:"column:default_menu;type:tinyint(1);comment:是否是基础路由(开发中)" json:"default_menu"` // 是否是基础路由(开发中) + Title string `gorm:"column:title;type:varchar(191);comment:菜单名" json:"title"` // 菜单名 + Icon string `gorm:"column:icon;type:varchar(191);comment:菜单图标" json:"icon"` // 菜单图标 + CloseTab bool `gorm:"column:close_tab;type:tinyint(1);comment:自动关闭tab" json:"close_tab"` // 自动关闭tab + TransitionType string `gorm:"column:transition_type;type:varchar(191);comment:路由切换动画" json:"transition_type"` // 路由切换动画 } // TableName SysBaseMenu's table name diff --git a/internal/data/model/sys_dictionaries.gen.go b/internal/data/model/sys_dictionaries.gen.go index c1e1e87..1080705 100644 --- a/internal/data/model/sys_dictionaries.gen.go +++ b/internal/data/model/sys_dictionaries.gen.go @@ -15,14 +15,14 @@ const TableNameSysDictionary = "sys_dictionaries" // SysDictionary mapped from table type SysDictionary struct { ID int64 `gorm:"column:id;type:bigint(20) unsigned;primaryKey;autoIncrement:true" json:"id"` - CreatedAt *time.Time `gorm:"column:created_at;type:datetime(3)" json:"created_at"` - UpdatedAt *time.Time `gorm:"column:updated_at;type:datetime(3)" json:"updated_at"` + CreatedAt time.Time `gorm:"column:created_at;type:datetime(3)" json:"created_at"` + UpdatedAt time.Time `gorm:"column:updated_at;type:datetime(3)" json:"updated_at"` DeletedAt gorm.DeletedAt `gorm:"column:deleted_at;type:datetime(3);index:idx_sys_dictionaries_deleted_at,priority:1" json:"deleted_at"` - Name *string `gorm:"column:name;type:varchar(191);comment:字典名(中)" json:"name"` // 字典名(中) - Type *string `gorm:"column:type;type:varchar(191);comment:字典名(英)" json:"type"` // 字典名(英) - Status *bool `gorm:"column:status;type:tinyint(1);comment:状态" json:"status"` // 状态 - Desc *string `gorm:"column:desc;type:varchar(191);comment:描述" json:"desc"` // 描述 - ParentID *int64 `gorm:"column:parent_id;type:bigint(20) unsigned;comment:父级字典ID" json:"parent_id"` // 父级字典ID + Name string `gorm:"column:name;type:varchar(191);comment:字典名(中)" json:"name"` // 字典名(中) + Type string `gorm:"column:type;type:varchar(191);comment:字典名(英)" json:"type"` // 字典名(英) + Status bool `gorm:"column:status;type:tinyint(1);comment:状态" json:"status"` // 状态 + Desc string `gorm:"column:desc;type:varchar(191);comment:描述" json:"desc"` // 描述 + ParentID int64 `gorm:"column:parent_id;type:bigint(20) unsigned;comment:父级字典ID" json:"parent_id"` // 父级字典ID } // TableName SysDictionary's table name diff --git a/internal/data/model/sys_dictionary_details.gen.go b/internal/data/model/sys_dictionary_details.gen.go index e6de942..5ed4a65 100644 --- a/internal/data/model/sys_dictionary_details.gen.go +++ b/internal/data/model/sys_dictionary_details.gen.go @@ -15,18 +15,18 @@ const TableNameSysDictionaryDetail = "sys_dictionary_details" // SysDictionaryDetail mapped from table type SysDictionaryDetail struct { ID int64 `gorm:"column:id;type:bigint(20) unsigned;primaryKey;autoIncrement:true" json:"id"` - CreatedAt *time.Time `gorm:"column:created_at;type:datetime(3)" json:"created_at"` - UpdatedAt *time.Time `gorm:"column:updated_at;type:datetime(3)" json:"updated_at"` + CreatedAt time.Time `gorm:"column:created_at;type:datetime(3)" json:"created_at"` + UpdatedAt time.Time `gorm:"column:updated_at;type:datetime(3)" json:"updated_at"` DeletedAt gorm.DeletedAt `gorm:"column:deleted_at;type:datetime(3);index:idx_sys_dictionary_details_deleted_at,priority:1" json:"deleted_at"` - Label *string `gorm:"column:label;type:varchar(191);comment:展示值" json:"label"` // 展示值 - Value *string `gorm:"column:value;type:varchar(191);comment:字典值" json:"value"` // 字典值 - Extend *string `gorm:"column:extend;type:varchar(191);comment:扩展值" json:"extend"` // 扩展值 - Status *bool `gorm:"column:status;type:tinyint(1);comment:启用状态" json:"status"` // 启用状态 - Sort *int64 `gorm:"column:sort;type:bigint(20);comment:排序标记" json:"sort"` // 排序标记 - SysDictionaryID *int64 `gorm:"column:sys_dictionary_id;type:bigint(20) unsigned;comment:关联标记" json:"sys_dictionary_id"` // 关联标记 - ParentID *int64 `gorm:"column:parent_id;type:bigint(20) unsigned;comment:父级字典详情ID" json:"parent_id"` // 父级字典详情ID - Level *int64 `gorm:"column:level;type:bigint(20);comment:层级深度" json:"level"` // 层级深度 - Path *string `gorm:"column:path;type:varchar(191);comment:层级路径" json:"path"` // 层级路径 + Label string `gorm:"column:label;type:varchar(191);comment:展示值" json:"label"` // 展示值 + Value string `gorm:"column:value;type:varchar(191);comment:字典值" json:"value"` // 字典值 + Extend string `gorm:"column:extend;type:varchar(191);comment:扩展值" json:"extend"` // 扩展值 + Status bool `gorm:"column:status;type:tinyint(1);comment:启用状态" json:"status"` // 启用状态 + Sort int64 `gorm:"column:sort;type:bigint(20);comment:排序标记" json:"sort"` // 排序标记 + SysDictionaryID int64 `gorm:"column:sys_dictionary_id;type:bigint(20) unsigned;comment:关联标记" json:"sys_dictionary_id"` // 关联标记 + ParentID int64 `gorm:"column:parent_id;type:bigint(20) unsigned;comment:父级字典详情ID" json:"parent_id"` // 父级字典详情ID + Level int64 `gorm:"column:level;type:bigint(20);comment:层级深度" json:"level"` // 层级深度 + Path string `gorm:"column:path;type:varchar(191);comment:层级路径" json:"path"` // 层级路径 } // TableName SysDictionaryDetail's table name diff --git a/internal/data/model/sys_error.gen.go b/internal/data/model/sys_error.gen.go index 076c08f..b64eeaf 100644 --- a/internal/data/model/sys_error.gen.go +++ b/internal/data/model/sys_error.gen.go @@ -15,14 +15,14 @@ const TableNameSysError = "sys_error" // SysError mapped from table type SysError struct { ID int64 `gorm:"column:id;type:bigint(20) unsigned;primaryKey;autoIncrement:true" json:"id"` - CreatedAt *time.Time `gorm:"column:created_at;type:datetime(3)" json:"created_at"` - UpdatedAt *time.Time `gorm:"column:updated_at;type:datetime(3)" json:"updated_at"` + CreatedAt time.Time `gorm:"column:created_at;type:datetime(3)" json:"created_at"` + UpdatedAt time.Time `gorm:"column:updated_at;type:datetime(3)" json:"updated_at"` DeletedAt gorm.DeletedAt `gorm:"column:deleted_at;type:datetime(3);index:idx_sys_error_deleted_at,priority:1" json:"deleted_at"` - Form *string `gorm:"column:form;type:text;comment:错误来源" json:"form"` // 错误来源 - Info *string `gorm:"column:info;type:text;comment:错误内容" json:"info"` // 错误内容 - Level *string `gorm:"column:level;type:varchar(191);comment:日志等级" json:"level"` // 日志等级 - Solution *string `gorm:"column:solution;type:text;comment:解决方案" json:"solution"` // 解决方案 - Status *string `gorm:"column:status;type:varchar(20);default:未处理;comment:处理状态" json:"status"` // 处理状态 + Form string `gorm:"column:form;type:text;comment:错误来源" json:"form"` // 错误来源 + Info string `gorm:"column:info;type:text;comment:错误内容" json:"info"` // 错误内容 + Level string `gorm:"column:level;type:varchar(191);comment:日志等级" json:"level"` // 日志等级 + Solution string `gorm:"column:solution;type:text;comment:解决方案" json:"solution"` // 解决方案 + Status string `gorm:"column:status;type:varchar(20);default:未处理;comment:处理状态" json:"status"` // 处理状态 } // TableName SysError's table name diff --git a/internal/data/model/sys_export_template_condition.gen.go b/internal/data/model/sys_export_template_condition.gen.go index 2b109b6..fd96529 100644 --- a/internal/data/model/sys_export_template_condition.gen.go +++ b/internal/data/model/sys_export_template_condition.gen.go @@ -15,13 +15,13 @@ const TableNameSysExportTemplateCondition = "sys_export_template_condition" // SysExportTemplateCondition mapped from table type SysExportTemplateCondition struct { ID int64 `gorm:"column:id;type:bigint(20) unsigned;primaryKey;autoIncrement:true" json:"id"` - CreatedAt *time.Time `gorm:"column:created_at;type:datetime(3)" json:"created_at"` - UpdatedAt *time.Time `gorm:"column:updated_at;type:datetime(3)" json:"updated_at"` + CreatedAt time.Time `gorm:"column:created_at;type:datetime(3)" json:"created_at"` + UpdatedAt time.Time `gorm:"column:updated_at;type:datetime(3)" json:"updated_at"` DeletedAt gorm.DeletedAt `gorm:"column:deleted_at;type:datetime(3);index:idx_sys_export_template_condition_deleted_at,priority:1" json:"deleted_at"` - TemplateID *string `gorm:"column:template_id;type:varchar(191);comment:模板标识" json:"template_id"` // 模板标识 - From *string `gorm:"column:from;type:varchar(191);comment:条件取的key" json:"from"` // 条件取的key - Column *string `gorm:"column:column;type:varchar(191);comment:作为查询条件的字段" json:"column"` // 作为查询条件的字段 - Operator *string `gorm:"column:operator;type:varchar(191);comment:操作符" json:"operator"` // 操作符 + TemplateID string `gorm:"column:template_id;type:varchar(191);comment:模板标识" json:"template_id"` // 模板标识 + From string `gorm:"column:from;type:varchar(191);comment:条件取的key" json:"from"` // 条件取的key + Column string `gorm:"column:column;type:varchar(191);comment:作为查询条件的字段" json:"column"` // 作为查询条件的字段 + Operator string `gorm:"column:operator;type:varchar(191);comment:操作符" json:"operator"` // 操作符 } // TableName SysExportTemplateCondition's table name diff --git a/internal/data/model/sys_export_template_join.gen.go b/internal/data/model/sys_export_template_join.gen.go index 96e47dc..bc3ef84 100644 --- a/internal/data/model/sys_export_template_join.gen.go +++ b/internal/data/model/sys_export_template_join.gen.go @@ -15,13 +15,13 @@ const TableNameSysExportTemplateJoin = "sys_export_template_join" // SysExportTemplateJoin mapped from table type SysExportTemplateJoin struct { ID int64 `gorm:"column:id;type:bigint(20) unsigned;primaryKey;autoIncrement:true" json:"id"` - CreatedAt *time.Time `gorm:"column:created_at;type:datetime(3)" json:"created_at"` - UpdatedAt *time.Time `gorm:"column:updated_at;type:datetime(3)" json:"updated_at"` + CreatedAt time.Time `gorm:"column:created_at;type:datetime(3)" json:"created_at"` + UpdatedAt time.Time `gorm:"column:updated_at;type:datetime(3)" json:"updated_at"` DeletedAt gorm.DeletedAt `gorm:"column:deleted_at;type:datetime(3);index:idx_sys_export_template_join_deleted_at,priority:1" json:"deleted_at"` - TemplateID *string `gorm:"column:template_id;type:varchar(191);comment:模板标识" json:"template_id"` // 模板标识 - Joins *string `gorm:"column:joins;type:varchar(191);comment:关联" json:"joins"` // 关联 - TblName *string `gorm:"column:table;type:varchar(191);comment:关联表" json:"table"` // 关联表 - On *string `gorm:"column:on;type:varchar(191);comment:关联条件" json:"on"` // 关联条件 + TemplateID string `gorm:"column:template_id;type:varchar(191);comment:模板标识" json:"template_id"` // 模板标识 + Joins string `gorm:"column:joins;type:varchar(191);comment:关联" json:"joins"` // 关联 + TblName string `gorm:"column:table;type:varchar(191);comment:关联表" json:"table"` // 关联表 + On string `gorm:"column:on;type:varchar(191);comment:关联条件" json:"on"` // 关联条件 } // TableName SysExportTemplateJoin's table name diff --git a/internal/data/model/sys_export_templates.gen.go b/internal/data/model/sys_export_templates.gen.go index c692e4c..39f9400 100644 --- a/internal/data/model/sys_export_templates.gen.go +++ b/internal/data/model/sys_export_templates.gen.go @@ -15,16 +15,16 @@ const TableNameSysExportTemplate = "sys_export_templates" // SysExportTemplate mapped from table type SysExportTemplate struct { ID int64 `gorm:"column:id;type:bigint(20) unsigned;primaryKey;autoIncrement:true" json:"id"` - CreatedAt *time.Time `gorm:"column:created_at;type:datetime(3)" json:"created_at"` - UpdatedAt *time.Time `gorm:"column:updated_at;type:datetime(3)" json:"updated_at"` + CreatedAt time.Time `gorm:"column:created_at;type:datetime(3)" json:"created_at"` + UpdatedAt time.Time `gorm:"column:updated_at;type:datetime(3)" json:"updated_at"` DeletedAt gorm.DeletedAt `gorm:"column:deleted_at;type:datetime(3);index:idx_sys_export_templates_deleted_at,priority:1" json:"deleted_at"` - DbName *string `gorm:"column:db_name;type:varchar(191);comment:数据库名称" json:"db_name"` // 数据库名称 - Name *string `gorm:"column:name;type:varchar(191);comment:模板名称" json:"name"` // 模板名称 - TblName *string `gorm:"column:table_name;type:varchar(191);comment:表名称" json:"table_name"` // 表名称 - TemplateID *string `gorm:"column:template_id;type:varchar(191);comment:模板标识" json:"template_id"` // 模板标识 - TemplateInfo *string `gorm:"column:template_info;type:text" json:"template_info"` - Limit *int64 `gorm:"column:limit;type:bigint(20);comment:导出限制" json:"limit"` // 导出限制 - Order *string `gorm:"column:order;type:varchar(191);comment:排序" json:"order"` // 排序 + DbName string `gorm:"column:db_name;type:varchar(191);comment:数据库名称" json:"db_name"` // 数据库名称 + Name string `gorm:"column:name;type:varchar(191);comment:模板名称" json:"name"` // 模板名称 + TblName string `gorm:"column:table_name;type:varchar(191);comment:表名称" json:"table_name"` // 表名称 + TemplateID string `gorm:"column:template_id;type:varchar(191);comment:模板标识" json:"template_id"` // 模板标识 + TemplateInfo string `gorm:"column:template_info;type:text" json:"template_info"` + Limit int64 `gorm:"column:limit;type:bigint(20);comment:导出限制" json:"limit"` // 导出限制 + Order string `gorm:"column:order;type:varchar(191);comment:排序" json:"order"` // 排序 } // TableName SysExportTemplate's table name diff --git a/internal/data/model/sys_ignore_apis.gen.go b/internal/data/model/sys_ignore_apis.gen.go index d2e1674..428738c 100644 --- a/internal/data/model/sys_ignore_apis.gen.go +++ b/internal/data/model/sys_ignore_apis.gen.go @@ -15,11 +15,11 @@ const TableNameSysIgnoreAPI = "sys_ignore_apis" // SysIgnoreAPI mapped from table type SysIgnoreAPI struct { ID int64 `gorm:"column:id;type:bigint(20) unsigned;primaryKey;autoIncrement:true" json:"id"` - CreatedAt *time.Time `gorm:"column:created_at;type:datetime(3)" json:"created_at"` - UpdatedAt *time.Time `gorm:"column:updated_at;type:datetime(3)" json:"updated_at"` + CreatedAt time.Time `gorm:"column:created_at;type:datetime(3)" json:"created_at"` + UpdatedAt time.Time `gorm:"column:updated_at;type:datetime(3)" json:"updated_at"` DeletedAt gorm.DeletedAt `gorm:"column:deleted_at;type:datetime(3);index:idx_sys_ignore_apis_deleted_at,priority:1" json:"deleted_at"` - Path *string `gorm:"column:path;type:varchar(191);comment:api路径" json:"path"` // api路径 - Method *string `gorm:"column:method;type:varchar(191);default:POST;comment:方法" json:"method"` // 方法 + Path string `gorm:"column:path;type:varchar(191);comment:api路径" json:"path"` // api路径 + Method string `gorm:"column:method;type:varchar(191);default:POST;comment:方法" json:"method"` // 方法 } // TableName SysIgnoreAPI's table name diff --git a/internal/data/model/sys_operation_records.gen.go b/internal/data/model/sys_operation_records.gen.go index 53ea622..1ab1569 100644 --- a/internal/data/model/sys_operation_records.gen.go +++ b/internal/data/model/sys_operation_records.gen.go @@ -15,19 +15,19 @@ const TableNameSysOperationRecord = "sys_operation_records" // SysOperationRecord mapped from table type SysOperationRecord struct { ID int64 `gorm:"column:id;type:bigint(20) unsigned;primaryKey;autoIncrement:true" json:"id"` - CreatedAt *time.Time `gorm:"column:created_at;type:datetime(3)" json:"created_at"` - UpdatedAt *time.Time `gorm:"column:updated_at;type:datetime(3)" json:"updated_at"` + CreatedAt time.Time `gorm:"column:created_at;type:datetime(3)" json:"created_at"` + UpdatedAt time.Time `gorm:"column:updated_at;type:datetime(3)" json:"updated_at"` DeletedAt gorm.DeletedAt `gorm:"column:deleted_at;type:datetime(3);index:idx_sys_operation_records_deleted_at,priority:1" json:"deleted_at"` - IP *string `gorm:"column:ip;type:varchar(191);comment:请求ip" json:"ip"` // 请求ip - Method *string `gorm:"column:method;type:varchar(191);comment:请求方法" json:"method"` // 请求方法 - Path *string `gorm:"column:path;type:varchar(191);comment:请求路径" json:"path"` // 请求路径 - Status *int64 `gorm:"column:status;type:bigint(20);comment:请求状态" json:"status"` // 请求状态 - Latency *int64 `gorm:"column:latency;type:bigint(20);comment:延迟" json:"latency"` // 延迟 - Agent *string `gorm:"column:agent;type:text;comment:代理" json:"agent"` // 代理 - ErrorMessage *string `gorm:"column:error_message;type:varchar(191);comment:错误信息" json:"error_message"` // 错误信息 - Body *string `gorm:"column:body;type:text;comment:请求Body" json:"body"` // 请求Body - Resp *string `gorm:"column:resp;type:text;comment:响应Body" json:"resp"` // 响应Body - UserID *int64 `gorm:"column:user_id;type:bigint(20) unsigned;comment:用户id" json:"user_id"` // 用户id + IP string `gorm:"column:ip;type:varchar(191);comment:请求ip" json:"ip"` // 请求ip + Method string `gorm:"column:method;type:varchar(191);comment:请求方法" json:"method"` // 请求方法 + Path string `gorm:"column:path;type:varchar(191);comment:请求路径" json:"path"` // 请求路径 + Status int64 `gorm:"column:status;type:bigint(20);comment:请求状态" json:"status"` // 请求状态 + Latency int64 `gorm:"column:latency;type:bigint(20);comment:延迟" json:"latency"` // 延迟 + Agent string `gorm:"column:agent;type:text;comment:代理" json:"agent"` // 代理 + ErrorMessage string `gorm:"column:error_message;type:varchar(191);comment:错误信息" json:"error_message"` // 错误信息 + Body string `gorm:"column:body;type:text;comment:请求Body" json:"body"` // 请求Body + Resp string `gorm:"column:resp;type:text;comment:响应Body" json:"resp"` // 响应Body + UserID int64 `gorm:"column:user_id;type:bigint(20) unsigned;comment:用户id" json:"user_id"` // 用户id } // TableName SysOperationRecord's table name diff --git a/internal/data/model/sys_params.gen.go b/internal/data/model/sys_params.gen.go index b0e0dda..687afe9 100644 --- a/internal/data/model/sys_params.gen.go +++ b/internal/data/model/sys_params.gen.go @@ -15,13 +15,13 @@ const TableNameSysParam = "sys_params" // SysParam mapped from table type SysParam struct { ID int64 `gorm:"column:id;type:bigint(20) unsigned;primaryKey;autoIncrement:true" json:"id"` - CreatedAt *time.Time `gorm:"column:created_at;type:datetime(3)" json:"created_at"` - UpdatedAt *time.Time `gorm:"column:updated_at;type:datetime(3)" json:"updated_at"` + CreatedAt time.Time `gorm:"column:created_at;type:datetime(3)" json:"created_at"` + UpdatedAt time.Time `gorm:"column:updated_at;type:datetime(3)" json:"updated_at"` DeletedAt gorm.DeletedAt `gorm:"column:deleted_at;type:datetime(3);index:idx_sys_params_deleted_at,priority:1" json:"deleted_at"` - Name *string `gorm:"column:name;type:varchar(191);comment:参数名称" json:"name"` // 参数名称 - Key *string `gorm:"column:key;type:varchar(191);comment:参数键" json:"key"` // 参数键 - Value *string `gorm:"column:value;type:varchar(191);comment:参数值" json:"value"` // 参数值 - Desc *string `gorm:"column:desc;type:varchar(191);comment:参数说明" json:"desc"` // 参数说明 + Name string `gorm:"column:name;type:varchar(191);comment:参数名称" json:"name"` // 参数名称 + Key string `gorm:"column:key;type:varchar(191);comment:参数键" json:"key"` // 参数键 + Value string `gorm:"column:value;type:varchar(191);comment:参数值" json:"value"` // 参数值 + Desc string `gorm:"column:desc;type:varchar(191);comment:参数说明" json:"desc"` // 参数说明 } // TableName SysParam's table name diff --git a/internal/data/model/sys_users.gen.go b/internal/data/model/sys_users.gen.go index 0a1a0b5..9ed7572 100644 --- a/internal/data/model/sys_users.gen.go +++ b/internal/data/model/sys_users.gen.go @@ -15,19 +15,19 @@ const TableNameSysUser = "sys_users" // SysUser mapped from table type SysUser struct { ID int64 `gorm:"column:id;type:bigint(20) unsigned;primaryKey;autoIncrement:true" json:"id"` - CreatedAt *time.Time `gorm:"column:created_at;type:datetime(3)" json:"created_at"` - UpdatedAt *time.Time `gorm:"column:updated_at;type:datetime(3)" json:"updated_at"` + CreatedAt time.Time `gorm:"column:created_at;type:datetime(3)" json:"created_at"` + UpdatedAt time.Time `gorm:"column:updated_at;type:datetime(3)" json:"updated_at"` DeletedAt gorm.DeletedAt `gorm:"column:deleted_at;type:datetime(3);index:idx_sys_users_deleted_at,priority:1" json:"deleted_at"` - UUID *string `gorm:"column:uuid;type:varchar(191);index:idx_sys_users_uuid,priority:1;comment:用户UUID" json:"uuid"` // 用户UUID - Username *string `gorm:"column:username;type:varchar(191);index:idx_sys_users_username,priority:1;comment:用户登录名" json:"username"` // 用户登录名 - Password *string `gorm:"column:password;type:varchar(191);comment:用户登录密码" json:"password"` // 用户登录密码 - NickName *string `gorm:"column:nick_name;type:varchar(191);default:系统用户;comment:用户昵称" json:"nick_name"` // 用户昵称 - HeaderImg *string `gorm:"column:header_img;type:varchar(191);default:https://qmplusimg.henrongyi.top/gva_header.jpg;comment:用户头像" json:"header_img"` // 用户头像 - AuthorityID *int64 `gorm:"column:authority_id;type:bigint(20) unsigned;default:888;comment:用户角色ID" json:"authority_id"` // 用户角色ID - Phone *string `gorm:"column:phone;type:varchar(191);comment:用户手机号" json:"phone"` // 用户手机号 - Email *string `gorm:"column:email;type:varchar(191);comment:用户邮箱" json:"email"` // 用户邮箱 - Enable *int64 `gorm:"column:enable;type:bigint(20);default:1;comment:用户是否被冻结 1正常 2冻结" json:"enable"` // 用户是否被冻结 1正常 2冻结 - OriginSetting *string `gorm:"column:origin_setting;type:text;comment:配置" json:"origin_setting"` // 配置 + UUID string `gorm:"column:uuid;type:varchar(191);index:idx_sys_users_uuid,priority:1;comment:用户UUID" json:"uuid"` // 用户UUID + Username string `gorm:"column:username;type:varchar(191);index:idx_sys_users_username,priority:1;comment:用户登录名" json:"username"` // 用户登录名 + Password string `gorm:"column:password;type:varchar(191);comment:用户登录密码" json:"password"` // 用户登录密码 + NickName string `gorm:"column:nick_name;type:varchar(191);default:系统用户;comment:用户昵称" json:"nick_name"` // 用户昵称 + HeaderImg string `gorm:"column:header_img;type:varchar(191);default:https://qmplusimg.henrongyi.top/gva_header.jpg;comment:用户头像" json:"header_img"` // 用户头像 + AuthorityID int64 `gorm:"column:authority_id;type:bigint(20) unsigned;default:888;comment:用户角色ID" json:"authority_id"` // 用户角色ID + Phone string `gorm:"column:phone;type:varchar(191);comment:用户手机号" json:"phone"` // 用户手机号 + Email string `gorm:"column:email;type:varchar(191);comment:用户邮箱" json:"email"` // 用户邮箱 + Enable int64 `gorm:"column:enable;type:bigint(20);default:1;comment:用户是否被冻结 1正常 2冻结" json:"enable"` // 用户是否被冻结 1正常 2冻结 + OriginSetting string `gorm:"column:origin_setting;type:text;comment:配置" json:"origin_setting"` // 配置 Authority SysAuthority `gorm:"foreignKey:AuthorityID;references:AuthorityID" json:"authority"` Authorities []SysAuthority `gorm:"joinForeignKey:SysUserID;joinReferences:SysAuthorityAuthorityID;many2many:sys_user_authority" json:"authorities"` } diff --git a/internal/data/model/sys_versions.gen.go b/internal/data/model/sys_versions.gen.go index 3a0232c..a7ac94f 100644 --- a/internal/data/model/sys_versions.gen.go +++ b/internal/data/model/sys_versions.gen.go @@ -15,13 +15,13 @@ const TableNameSysVersion = "sys_versions" // SysVersion mapped from table type SysVersion struct { ID int64 `gorm:"column:id;type:bigint(20) unsigned;primaryKey;autoIncrement:true" json:"id"` - CreatedAt *time.Time `gorm:"column:created_at;type:datetime(3)" json:"created_at"` - UpdatedAt *time.Time `gorm:"column:updated_at;type:datetime(3)" json:"updated_at"` + CreatedAt time.Time `gorm:"column:created_at;type:datetime(3)" json:"created_at"` + UpdatedAt time.Time `gorm:"column:updated_at;type:datetime(3)" json:"updated_at"` DeletedAt gorm.DeletedAt `gorm:"column:deleted_at;type:datetime(3);index:idx_sys_versions_deleted_at,priority:1" json:"deleted_at"` - VersionName *string `gorm:"column:version_name;type:varchar(255);comment:版本名称" json:"version_name"` // 版本名称 - VersionCode *string `gorm:"column:version_code;type:varchar(100);comment:版本号" json:"version_code"` // 版本号 - Description *string `gorm:"column:description;type:varchar(500);comment:版本描述" json:"description"` // 版本描述 - VersionData *string `gorm:"column:version_data;type:text;comment:版本数据JSON" json:"version_data"` // 版本数据JSON + VersionName string `gorm:"column:version_name;type:varchar(255);comment:版本名称" json:"version_name"` // 版本名称 + VersionCode string `gorm:"column:version_code;type:varchar(100);comment:版本号" json:"version_code"` // 版本号 + Description string `gorm:"column:description;type:varchar(500);comment:版本描述" json:"description"` // 版本描述 + VersionData string `gorm:"column:version_data;type:text;comment:版本数据JSON" json:"version_data"` // 版本数据JSON } // TableName SysVersion's table name diff --git a/internal/data/system/api.go b/internal/data/system/api.go index 769e2a5..7666f55 100644 --- a/internal/data/system/api.go +++ b/internal/data/system/api.go @@ -41,7 +41,7 @@ func (r *apiRepo) Update(ctx context.Context, api *system.Api) error { if err != nil { return err } - if safeString(old.Path) != api.Path || safeString(old.Method) != api.Method { + if old.Path != api.Path || old.Method != api.Method { dup, ferr := query.SysAPI.WithContext(ctx).Where( query.SysAPI.Path.Eq(api.Path), query.SysAPI.Method.Eq(api.Method), @@ -201,18 +201,15 @@ func (r *apiRepo) GetApiGroups(ctx context.Context) ([]string, map[string]string var groups []string for _, m := range list { - path := safeString(m.Path) - apiGroup := safeString(m.APIGroup) - - if !groupMap[apiGroup] { - groupMap[apiGroup] = true - groups = append(groups, apiGroup) + if !groupMap[m.APIGroup] { + groupMap[m.APIGroup] = true + groups = append(groups, m.APIGroup) } - if len(path) > 1 { - parts := strings.Split(path, "/") + if len(m.Path) > 1 { + parts := strings.Split(m.Path, "/") if len(parts) > 1 { - apiGroupMap[parts[1]] = apiGroup + apiGroupMap[parts[1]] = m.APIGroup } } } @@ -221,8 +218,8 @@ func (r *apiRepo) GetApiGroups(ctx context.Context) ([]string, map[string]string func (r *apiRepo) CreateIgnoreApi(ctx context.Context, path, method string) error { m := &model.SysIgnoreAPI{ - Path: &path, - Method: &method, + Path: path, + Method: method, } return r.db.WithContext(ctx).Create(m).Error } @@ -239,8 +236,8 @@ func (r *apiRepo) FindAllIgnoreApis(ctx context.Context) ([]*system.IgnoreApi, e result := make([]*system.IgnoreApi, len(list)) for i, m := range list { result[i] = &system.IgnoreApi{ - Path: safeString(m.Path), - Method: safeString(m.Method), + Path: m.Path, + Method: m.Method, } } return result, nil @@ -250,19 +247,19 @@ func (r *apiRepo) FindAllIgnoreApis(ctx context.Context) ([]*system.IgnoreApi, e func toModelAPI(a *system.Api) *model.SysAPI { return &model.SysAPI{ ID: int64(a.ID), - Path: &a.Path, - Description: &a.Description, - APIGroup: &a.ApiGroup, - Method: &a.Method, + Path: a.Path, + Description: a.Description, + APIGroup: a.ApiGroup, + Method: a.Method, } } func toBizAPI(m *model.SysAPI) *system.Api { return &system.Api{ ID: uint(m.ID), - Path: safeString(m.Path), - Description: safeString(m.Description), - ApiGroup: safeString(m.APIGroup), - Method: safeString(m.Method), + Path: m.Path, + Description: m.Description, + ApiGroup: m.APIGroup, + Method: m.Method, } } diff --git a/internal/data/system/authority.go b/internal/data/system/authority.go index efc46f2..4951b2f 100644 --- a/internal/data/system/authority.go +++ b/internal/data/system/authority.go @@ -23,12 +23,11 @@ func NewAuthorityRepo(db *gorm.DB) system.AuthorityRepo { func (r *authorityRepo) Create(ctx context.Context, auth *system.Authority) error { m := &model.SysAuthority{ AuthorityID: int64(auth.AuthorityId), - AuthorityName: &auth.AuthorityName, - DefaultRouter: &auth.DefaultRouter, + AuthorityName: auth.AuthorityName, + DefaultRouter: auth.DefaultRouter, } if auth.ParentId != nil { - parentId := int64(*auth.ParentId) - m.ParentID = &parentId + m.ParentID = int64(*auth.ParentId) } return r.db.WithContext(ctx).Create(m).Error } @@ -141,10 +140,7 @@ func (r *authorityRepo) GetParentAuthorityID(ctx context.Context, authorityId ui if err != nil { return 0, err } - if m.ParentID == nil { - return 0, nil - } - return uint(*m.ParentID), nil + return uint(m.ParentID), nil } func (r *authorityRepo) SetDataAuthority(ctx context.Context, authorityId uint, dataAuthorityIds []uint) error { @@ -216,9 +212,8 @@ func (r *authorityRepo) CopyAuthorityBtns(ctx context.Context, oldAuthorityId, n return nil } - newAuthorityIdInt64 := int64(newAuthorityId) for i := range btns { - btns[i].AuthorityID = &newAuthorityIdInt64 + btns[i].AuthorityID = int64(newAuthorityId) } return r.db.WithContext(ctx).Create(&btns).Error @@ -258,11 +253,11 @@ func (r *authorityRepo) DeleteAuthorityRelations(ctx context.Context, authorityI func toBizAuthority(m *model.SysAuthority) *system.Authority { auth := &system.Authority{ AuthorityId: uint(m.AuthorityID), - AuthorityName: safeString(m.AuthorityName), - DefaultRouter: safeString(m.DefaultRouter), + AuthorityName: m.AuthorityName, + DefaultRouter: m.DefaultRouter, } - if m.ParentID != nil { - parentId := uint(*m.ParentID) + if m.ParentID != 0 { + parentId := uint(m.ParentID) auth.ParentId = &parentId } return auth diff --git a/internal/data/system/dictionary.go b/internal/data/system/dictionary.go new file mode 100644 index 0000000..fae25c8 --- /dev/null +++ b/internal/data/system/dictionary.go @@ -0,0 +1,472 @@ +package system + +import ( + "context" + "errors" + "strconv" + + "kra/internal/biz/system" + "kra/internal/data/model" + + "gorm.io/gorm" +) + +type dictionaryRepo struct { + db *gorm.DB +} + +// NewDictionaryRepo 创建字典仓储 +func NewDictionaryRepo(db *gorm.DB) system.DictionaryRepo { + return &dictionaryRepo{db: db} +} + +func (r *dictionaryRepo) Create(ctx context.Context, dict *system.Dictionary) error { + m := toModelDictionary(dict) + if err := r.db.WithContext(ctx).Create(m).Error; err != nil { + return err + } + dict.ID = uint(m.ID) + return nil +} + +func (r *dictionaryRepo) Update(ctx context.Context, dict *system.Dictionary) error { + updates := map[string]interface{}{ + "name": dict.Name, + "type": dict.Type, + "status": dict.Status, + "desc": dict.Desc, + "parent_id": dict.ParentID, + } + return r.db.WithContext(ctx).Model(&model.SysDictionary{}).Where("id = ?", dict.ID).Updates(updates).Error +} + +func (r *dictionaryRepo) Delete(ctx context.Context, id uint) error { + return r.db.WithContext(ctx).Delete(&model.SysDictionary{}, id).Error +} + +func (r *dictionaryRepo) FindByID(ctx context.Context, id uint) (*system.Dictionary, error) { + var m model.SysDictionary + if err := r.db.WithContext(ctx).First(&m, id).Error; err != nil { + return nil, err + } + return toBizDictionary(&m), nil +} + +func (r *dictionaryRepo) FindByType(ctx context.Context, typ string) (*system.Dictionary, error) { + var m model.SysDictionary + if err := r.db.WithContext(ctx).Where("type = ?", typ).First(&m).Error; err != nil { + return nil, err + } + return toBizDictionary(&m), nil +} + +func (r *dictionaryRepo) GetByTypeOrID(ctx context.Context, typ string, id uint, status *bool) (*system.Dictionary, error) { + flag := true + if status != nil { + flag = *status + } + var m model.SysDictionary + db := r.db.WithContext(ctx).Where("(type = ? OR id = ?) AND status = ?", typ, id, flag) + if err := db.First(&m).Error; err != nil { + return nil, err + } + dict := toBizDictionary(&m) + // 加载详情 + var details []model.SysDictionaryDetail + r.db.WithContext(ctx).Where("sys_dictionary_id = ? AND status = ?", m.ID, true).Order("sort").Find(&details) + // 详情在service层处理 + return dict, nil +} + +func (r *dictionaryRepo) List(ctx context.Context, name string) ([]*system.Dictionary, error) { + db := r.db.WithContext(ctx).Model(&model.SysDictionary{}) + if name != "" { + db = db.Where("name LIKE ? OR type LIKE ?", "%"+name+"%", "%"+name+"%") + } + // 预加载子字典 + db = db.Preload("Children") + var list []model.SysDictionary + if err := db.Find(&list).Error; err != nil { + return nil, err + } + result := make([]*system.Dictionary, len(list)) + for i, m := range list { + result[i] = toBizDictionary(&m) + } + return result, nil +} + +func (r *dictionaryRepo) CheckCircularReference(ctx context.Context, currentID, parentID uint) error { + if currentID == parentID { + return errors.New("不能将字典设置为自己的父级") + } + var parent model.SysDictionary + if err := r.db.WithContext(ctx).Where("id = ?", parentID).First(&parent).Error; err != nil { + if errors.Is(err, gorm.ErrRecordNotFound) { + return nil + } + return err + } + if parent.ParentID != 0 { + return r.CheckCircularReference(ctx, currentID, uint(parent.ParentID)) + } + return nil +} + +type dictionaryDetailRepo struct { + db *gorm.DB +} + +// NewDictionaryDetailRepo 创建字典详情仓储 +func NewDictionaryDetailRepo(db *gorm.DB) system.DictionaryDetailRepo { + return &dictionaryDetailRepo{db: db} +} + +func (r *dictionaryDetailRepo) Create(ctx context.Context, detail *system.DictionaryDetail) error { + m := toModelDictionaryDetail(detail) + if err := r.db.WithContext(ctx).Create(m).Error; err != nil { + return err + } + detail.ID = uint(m.ID) + return nil +} + +func (r *dictionaryDetailRepo) Update(ctx context.Context, detail *system.DictionaryDetail) error { + m := toModelDictionaryDetail(detail) + return r.db.WithContext(ctx).Save(m).Error +} + +func (r *dictionaryDetailRepo) Delete(ctx context.Context, id uint) error { + return r.db.WithContext(ctx).Delete(&model.SysDictionaryDetail{}, id).Error +} + +func (r *dictionaryDetailRepo) FindByID(ctx context.Context, id uint) (*system.DictionaryDetail, error) { + var m model.SysDictionaryDetail + if err := r.db.WithContext(ctx).First(&m, id).Error; err != nil { + return nil, err + } + return toBizDictionaryDetail(&m), nil +} + +func (r *dictionaryDetailRepo) List(ctx context.Context, page, pageSize int, filters map[string]interface{}) ([]*system.DictionaryDetail, int64, error) { + db := r.db.WithContext(ctx).Model(&model.SysDictionaryDetail{}) + if v, ok := filters["label"]; ok && v != "" { + db = db.Where("label LIKE ?", "%"+v.(string)+"%") + } + if v, ok := filters["value"]; ok && v != "" { + db = db.Where("value = ?", v) + } + if v, ok := filters["status"]; ok { + db = db.Where("status = ?", v) + } + if v, ok := filters["sys_dictionary_id"]; ok && v.(uint) != 0 { + db = db.Where("sys_dictionary_id = ?", v) + } + if v, ok := filters["parent_id"]; ok { + db = db.Where("parent_id = ?", v) + } + if v, ok := filters["level"]; ok { + db = db.Where("level = ?", v) + } + + var total int64 + if err := db.Count(&total).Error; err != nil { + return nil, 0, err + } + + offset := (page - 1) * pageSize + var list []model.SysDictionaryDetail + if err := db.Offset(offset).Limit(pageSize).Order("sort").Order("id").Find(&list).Error; err != nil { + return nil, 0, err + } + + result := make([]*system.DictionaryDetail, len(list)) + for i, m := range list { + result[i] = toBizDictionaryDetail(&m) + } + return result, total, nil +} + +func (r *dictionaryDetailRepo) GetListByDictionaryID(ctx context.Context, dictionaryID uint) ([]*system.DictionaryDetail, error) { + var list []model.SysDictionaryDetail + if err := r.db.WithContext(ctx).Where("sys_dictionary_id = ?", dictionaryID).Find(&list).Error; err != nil { + return nil, err + } + result := make([]*system.DictionaryDetail, len(list)) + for i, m := range list { + result[i] = toBizDictionaryDetail(&m) + } + return result, nil +} + +func (r *dictionaryDetailRepo) GetTreeList(ctx context.Context, dictionaryID uint) ([]*system.DictionaryDetail, error) { + var list []model.SysDictionaryDetail + if err := r.db.WithContext(ctx).Where("sys_dictionary_id = ? AND parent_id IS NULL", dictionaryID).Order("sort").Find(&list).Error; err != nil { + return nil, err + } + result := make([]*system.DictionaryDetail, len(list)) + for i, m := range list { + result[i] = toBizDictionaryDetail(&m) + r.setDisabled(result[i]) + if err := r.loadChildren(ctx, result[i]); err != nil { + return nil, err + } + } + return result, nil +} + +func (r *dictionaryDetailRepo) loadChildren(ctx context.Context, detail *system.DictionaryDetail) error { + var children []model.SysDictionaryDetail + if err := r.db.WithContext(ctx).Where("parent_id = ?", detail.ID).Order("sort").Find(&children).Error; err != nil { + return err + } + for _, m := range children { + child := toBizDictionaryDetail(&m) + r.setDisabled(child) + if err := r.loadChildren(ctx, child); err != nil { + return err + } + detail.Children = append(detail.Children, child) + } + return nil +} + +func (r *dictionaryDetailRepo) setDisabled(detail *system.DictionaryDetail) { + if detail.Status != nil { + detail.Disabled = !*detail.Status + } else { + detail.Disabled = false + } +} + +func (r *dictionaryDetailRepo) GetByParent(ctx context.Context, dictionaryID uint, parentID *uint, includeChildren bool) ([]*system.DictionaryDetail, error) { + db := r.db.WithContext(ctx).Model(&model.SysDictionaryDetail{}).Where("sys_dictionary_id = ?", dictionaryID) + if parentID != nil { + db = db.Where("parent_id = ?", *parentID) + } else { + db = db.Where("parent_id IS NULL") + } + var list []model.SysDictionaryDetail + if err := db.Order("sort").Find(&list).Error; err != nil { + return nil, err + } + result := make([]*system.DictionaryDetail, len(list)) + for i, m := range list { + result[i] = toBizDictionaryDetail(&m) + r.setDisabled(result[i]) + if includeChildren { + if err := r.loadChildren(ctx, result[i]); err != nil { + return nil, err + } + } + } + return result, nil +} + +func (r *dictionaryDetailRepo) GetByDictionaryIDAndValue(ctx context.Context, dictionaryID uint, value string) (*system.DictionaryDetail, error) { + var m model.SysDictionaryDetail + if err := r.db.WithContext(ctx).Where("sys_dictionary_id = ? AND value = ?", dictionaryID, value).First(&m).Error; err != nil { + return nil, err + } + return toBizDictionaryDetail(&m), nil +} + +func (r *dictionaryDetailRepo) GetByTypeAndValue(ctx context.Context, typ, value string) (*system.DictionaryDetail, error) { + var m model.SysDictionaryDetail + if err := r.db.WithContext(ctx).Model(&model.SysDictionaryDetail{}). + Joins("JOIN sys_dictionaries ON sys_dictionaries.id = sys_dictionary_details.sys_dictionary_id"). + Where("sys_dictionaries.type = ? AND sys_dictionary_details.value = ?", typ, value). + First(&m).Error; err != nil { + return nil, err + } + return toBizDictionaryDetail(&m), nil +} + +func (r *dictionaryDetailRepo) GetTreeListByType(ctx context.Context, typ string) ([]*system.DictionaryDetail, error) { + var list []model.SysDictionaryDetail + if err := r.db.WithContext(ctx).Model(&model.SysDictionaryDetail{}). + Joins("JOIN sys_dictionaries ON sys_dictionaries.id = sys_dictionary_details.sys_dictionary_id"). + Where("sys_dictionaries.type = ? AND sys_dictionary_details.parent_id IS NULL", typ). + Order("sys_dictionary_details.sort"). + Find(&list).Error; err != nil { + return nil, err + } + result := make([]*system.DictionaryDetail, len(list)) + for i, m := range list { + result[i] = toBizDictionaryDetail(&m) + r.setDisabled(result[i]) + if err := r.loadChildren(ctx, result[i]); err != nil { + return nil, err + } + } + return result, nil +} + +func (r *dictionaryDetailRepo) GetListByType(ctx context.Context, typ string) ([]*system.DictionaryDetail, error) { + var list []model.SysDictionaryDetail + if err := r.db.WithContext(ctx).Model(&model.SysDictionaryDetail{}). + Joins("JOIN sys_dictionaries ON sys_dictionaries.id = sys_dictionary_details.sys_dictionary_id"). + Where("sys_dictionaries.type = ?", typ). + Find(&list).Error; err != nil { + return nil, err + } + result := make([]*system.DictionaryDetail, len(list)) + for i, m := range list { + result[i] = toBizDictionaryDetail(&m) + } + return result, nil +} + +func (r *dictionaryDetailRepo) HasChildren(ctx context.Context, id uint) (bool, error) { + var count int64 + if err := r.db.WithContext(ctx).Model(&model.SysDictionaryDetail{}).Where("parent_id = ?", id).Count(&count).Error; err != nil { + return false, err + } + return count > 0, nil +} + +func (r *dictionaryDetailRepo) CheckCircularReference(ctx context.Context, id, parentID uint) bool { + if id == parentID { + return true + } + var parent model.SysDictionaryDetail + if err := r.db.WithContext(ctx).First(&parent, parentID).Error; err != nil { + return false + } + if parent.ParentID == 0 { + return false + } + return r.CheckCircularReference(ctx, id, uint(parent.ParentID)) +} + +func (r *dictionaryDetailRepo) UpdateChildrenLevelAndPath(ctx context.Context, parentID uint) error { + var children []model.SysDictionaryDetail + if err := r.db.WithContext(ctx).Where("parent_id = ?", parentID).Find(&children).Error; err != nil { + return err + } + var parent model.SysDictionaryDetail + if err := r.db.WithContext(ctx).First(&parent, parentID).Error; err != nil { + return err + } + for _, child := range children { + child.Level = parent.Level + 1 + if parent.Path == "" { + child.Path = strconv.Itoa(int(parent.ID)) + } else { + child.Path = parent.Path + "," + strconv.Itoa(int(parent.ID)) + } + if err := r.db.WithContext(ctx).Save(&child).Error; err != nil { + return err + } + if err := r.UpdateChildrenLevelAndPath(ctx, uint(child.ID)); err != nil { + return err + } + } + return nil +} + +func (r *dictionaryDetailRepo) GetPath(ctx context.Context, id uint) ([]*system.DictionaryDetail, error) { + var m model.SysDictionaryDetail + if err := r.db.WithContext(ctx).First(&m, id).Error; err != nil { + return nil, err + } + detail := toBizDictionaryDetail(&m) + path := []*system.DictionaryDetail{detail} + if m.ParentID != 0 { + parentPath, err := r.GetPath(ctx, uint(m.ParentID)) + if err != nil { + return nil, err + } + path = append(parentPath, path...) + } + return path, nil +} + +func (r *dictionaryDetailRepo) DeleteByDictionaryID(ctx context.Context, dictionaryID uint) error { + return r.db.WithContext(ctx).Where("sys_dictionary_id = ?", dictionaryID).Delete(&model.SysDictionaryDetail{}).Error +} + +func (r *dictionaryDetailRepo) BatchCreate(ctx context.Context, details []*system.DictionaryDetail) error { + models := make([]*model.SysDictionaryDetail, len(details)) + for i, d := range details { + models[i] = toModelDictionaryDetail(d) + } + return r.db.WithContext(ctx).Create(&models).Error +} + +func (r *dictionaryDetailRepo) BatchUpdateParentID(ctx context.Context, idMap map[uint]uint) error { + // idMap: oldID -> newID + // 这里需要根据实际导入逻辑处理 + return nil +} + +// 转换函数 +func toModelDictionary(d *system.Dictionary) *model.SysDictionary { + m := &model.SysDictionary{ + ID: int64(d.ID), + Name: d.Name, + Type: d.Type, + Desc: d.Desc, + } + if d.Status != nil { + m.Status = *d.Status + } + if d.ParentID != nil { + m.ParentID = int64(*d.ParentID) + } + return m +} + +func toBizDictionary(m *model.SysDictionary) *system.Dictionary { + d := &system.Dictionary{ + ID: uint(m.ID), + Name: m.Name, + Type: m.Type, + Status: &m.Status, + Desc: m.Desc, + } + if m.ParentID != 0 { + pid := uint(m.ParentID) + d.ParentID = &pid + } + return d +} + +func toModelDictionaryDetail(d *system.DictionaryDetail) *model.SysDictionaryDetail { + m := &model.SysDictionaryDetail{ + ID: int64(d.ID), + Label: d.Label, + Value: d.Value, + Extend: d.Extend, + Sort: int64(d.Sort), + SysDictionaryID: int64(d.SysDictionaryID), + Level: int64(d.Level), + Path: d.Path, + } + if d.Status != nil { + m.Status = *d.Status + } + if d.ParentID != nil { + m.ParentID = int64(*d.ParentID) + } + return m +} + +func toBizDictionaryDetail(m *model.SysDictionaryDetail) *system.DictionaryDetail { + d := &system.DictionaryDetail{ + ID: uint(m.ID), + Label: m.Label, + Value: m.Value, + Extend: m.Extend, + Status: &m.Status, + Sort: int(m.Sort), + SysDictionaryID: uint(m.SysDictionaryID), + Level: int(m.Level), + Path: m.Path, + } + if m.ParentID != 0 { + pid := uint(m.ParentID) + d.ParentID = &pid + } + return d +} diff --git a/internal/data/system/menu.go b/internal/data/system/menu.go index 0d1aaa6..4e81b53 100644 --- a/internal/data/system/menu.go +++ b/internal/data/system/menu.go @@ -76,10 +76,10 @@ func (r *menuRepo) CreateBaseMenu(ctx context.Context, menu *system.BaseMenu) er if len(menu.Parameters) > 0 { for _, p := range menu.Parameters { param := &model.SysBaseMenuParameter{ - SysBaseMenuID: ptrInt64(int64(m.ID)), - Type: &p.Type, - Key: &p.Key, - Value: &p.Value, + SysBaseMenuID: int64(m.ID), + Type: p.Type, + Key: p.Key, + Value: p.Value, } if err := tx.Create(param).Error; err != nil { return err @@ -91,9 +91,9 @@ func (r *menuRepo) CreateBaseMenu(ctx context.Context, menu *system.BaseMenu) er if len(menu.MenuBtn) > 0 { for _, b := range menu.MenuBtn { btn := &model.SysBaseMenuBtn{ - SysBaseMenuID: ptrInt64(int64(m.ID)), - Name: &b.Name, - Desc: &b.Desc, + SysBaseMenuID: int64(m.ID), + Name: b.Name, + Desc: b.Desc, } if err := tx.Create(btn).Error; err != nil { return err @@ -115,7 +115,7 @@ func (r *menuRepo) UpdateBaseMenu(ctx context.Context, menu *system.BaseMenu) er } // 检查name是否重复 - if safeString(oldMenu.Name) != menu.Name { + if oldMenu.Name != menu.Name { var count int64 if err := tx.Model(&model.SysBaseMenu{}).Where("id <> ? AND name = ?", menu.ID, menu.Name).Count(&count).Error; err != nil { return err @@ -137,10 +137,10 @@ func (r *menuRepo) UpdateBaseMenu(ctx context.Context, menu *system.BaseMenu) er if len(menu.Parameters) > 0 { for _, p := range menu.Parameters { param := &model.SysBaseMenuParameter{ - SysBaseMenuID: ptrInt64(int64(menu.ID)), - Type: &p.Type, - Key: &p.Key, - Value: &p.Value, + SysBaseMenuID: int64(menu.ID), + Type: p.Type, + Key: p.Key, + Value: p.Value, } if err := tx.Create(param).Error; err != nil { return err @@ -152,9 +152,9 @@ func (r *menuRepo) UpdateBaseMenu(ctx context.Context, menu *system.BaseMenu) er if len(menu.MenuBtn) > 0 { for _, b := range menu.MenuBtn { btn := &model.SysBaseMenuBtn{ - SysBaseMenuID: ptrInt64(int64(menu.ID)), - Name: &b.Name, - Desc: &b.Desc, + SysBaseMenuID: int64(menu.ID), + Name: b.Name, + Desc: b.Desc, } if err := tx.Create(btn).Error; err != nil { return err @@ -295,9 +295,7 @@ func (r *menuRepo) FindAllBaseMenus(ctx context.Context) ([]*system.BaseMenu, er r.db.WithContext(ctx).Find(&allParams) paramMap := make(map[int64][]model.SysBaseMenuParameter) for _, p := range allParams { - if p.SysBaseMenuID != nil { - paramMap[*p.SysBaseMenuID] = append(paramMap[*p.SysBaseMenuID], p) - } + paramMap[p.SysBaseMenuID] = append(paramMap[p.SysBaseMenuID], p) } // 获取所有按钮 @@ -305,9 +303,7 @@ func (r *menuRepo) FindAllBaseMenus(ctx context.Context) ([]*system.BaseMenu, er r.db.WithContext(ctx).Find(&allBtns) btnMap := make(map[int64][]model.SysBaseMenuBtn) for _, b := range allBtns { - if b.SysBaseMenuID != nil { - btnMap[*b.SysBaseMenuID] = append(btnMap[*b.SysBaseMenuID], b) - } + btnMap[b.SysBaseMenuID] = append(btnMap[b.SysBaseMenuID], b) } result := make([]*system.BaseMenu, len(menus)) @@ -329,9 +325,7 @@ func (r *menuRepo) FindBaseMenusByIds(ctx context.Context, ids []string) ([]*sys r.db.WithContext(ctx).Where("sys_base_menu_id in (?)", ids).Find(&allParams) paramMap := make(map[int64][]model.SysBaseMenuParameter) for _, p := range allParams { - if p.SysBaseMenuID != nil { - paramMap[*p.SysBaseMenuID] = append(paramMap[*p.SysBaseMenuID], p) - } + paramMap[p.SysBaseMenuID] = append(paramMap[p.SysBaseMenuID], p) } // 获取按钮 @@ -339,9 +333,7 @@ func (r *menuRepo) FindBaseMenusByIds(ctx context.Context, ids []string) ([]*sys r.db.WithContext(ctx).Where("sys_base_menu_id in (?)", ids).Find(&allBtns) btnMap := make(map[int64][]model.SysBaseMenuBtn) for _, b := range allBtns { - if b.SysBaseMenuID != nil { - btnMap[*b.SysBaseMenuID] = append(btnMap[*b.SysBaseMenuID], b) - } + btnMap[b.SysBaseMenuID] = append(btnMap[b.SysBaseMenuID], b) } result := make([]*system.BaseMenu, len(menus)) @@ -374,9 +366,7 @@ func (r *menuRepo) FindAuthorityBtns(ctx context.Context, authorityId uint) ([]* // 获取按钮名称 var btnIds []int64 for _, b := range btns { - if b.SysBaseMenuBtnID != nil { - btnIds = append(btnIds, *b.SysBaseMenuBtnID) - } + btnIds = append(btnIds, b.SysBaseMenuBtnID) } btnNameMap := make(map[int64]string) @@ -384,22 +374,17 @@ func (r *menuRepo) FindAuthorityBtns(ctx context.Context, authorityId uint) ([]* var menuBtns []model.SysBaseMenuBtn r.db.WithContext(ctx).Where("id in (?)", btnIds).Find(&menuBtns) for _, mb := range menuBtns { - btnNameMap[mb.ID] = safeString(mb.Name) + btnNameMap[mb.ID] = mb.Name } } result := make([]*system.AuthorityBtn, len(btns)) for i, b := range btns { - result[i] = &system.AuthorityBtn{} - if b.AuthorityID != nil { - result[i].AuthorityId = uint(*b.AuthorityID) - } - if b.SysMenuID != nil { - result[i].SysMenuID = uint(*b.SysMenuID) - } - if b.SysBaseMenuBtnID != nil { - result[i].SysBaseMenuBtnID = uint(*b.SysBaseMenuBtnID) - result[i].BtnName = btnNameMap[*b.SysBaseMenuBtnID] + result[i] = &system.AuthorityBtn{ + AuthorityId: uint(b.AuthorityID), + SysMenuID: uint(b.SysMenuID), + SysBaseMenuBtnID: uint(b.SysBaseMenuBtnID), + BtnName: btnNameMap[b.SysBaseMenuBtnID], } } return result, nil @@ -429,55 +414,40 @@ func (r *menuRepo) SetMenuAuthority(ctx context.Context, authorityId uint, menuI // 转换函数 func toModelBaseMenu(m *system.BaseMenu) *model.SysBaseMenu { - parentId := int64(m.ParentId) - sort := int64(m.Sort) - return &model.SysBaseMenu{ ID: int64(m.ID), - ParentID: &parentId, - Path: &m.Path, - Name: &m.Name, - Hidden: &m.Hidden, - Component: &m.Component, - Sort: &sort, - ActiveName: &m.ActiveName, - KeepAlive: &m.KeepAlive, - DefaultMenu: &m.DefaultMenu, - Title: &m.Title, - Icon: &m.Icon, - CloseTab: &m.CloseTab, - TransitionType: &m.TransitionType, + ParentID: int64(m.ParentId), + Path: m.Path, + Name: m.Name, + Hidden: m.Hidden, + Component: m.Component, + Sort: int64(m.Sort), + ActiveName: m.ActiveName, + KeepAlive: m.KeepAlive, + DefaultMenu: m.DefaultMenu, + Title: m.Title, + Icon: m.Icon, + CloseTab: m.CloseTab, + TransitionType: m.TransitionType, } } func toBizBaseMenu(m *model.SysBaseMenu, params []model.SysBaseMenuParameter, btns []model.SysBaseMenuBtn) *system.BaseMenu { menu := &system.BaseMenu{ ID: uint(m.ID), - Path: safeString(m.Path), - Name: safeString(m.Name), - Component: safeString(m.Component), - ActiveName: safeString(m.ActiveName), - Title: safeString(m.Title), - Icon: safeString(m.Icon), - TransitionType: safeString(m.TransitionType), - } - if m.ParentID != nil { - menu.ParentId = uint(*m.ParentID) - } - if m.Sort != nil { - menu.Sort = int(*m.Sort) - } - if m.Hidden != nil { - menu.Hidden = *m.Hidden - } - if m.KeepAlive != nil { - menu.KeepAlive = *m.KeepAlive - } - if m.DefaultMenu != nil { - menu.DefaultMenu = *m.DefaultMenu - } - if m.CloseTab != nil { - menu.CloseTab = *m.CloseTab + ParentId: uint(m.ParentID), + Path: m.Path, + Name: m.Name, + Hidden: m.Hidden, + Component: m.Component, + Sort: int(m.Sort), + ActiveName: m.ActiveName, + KeepAlive: m.KeepAlive, + DefaultMenu: m.DefaultMenu, + Title: m.Title, + Icon: m.Icon, + CloseTab: m.CloseTab, + TransitionType: m.TransitionType, } // 转换参数 @@ -485,13 +455,11 @@ func toBizBaseMenu(m *model.SysBaseMenu, params []model.SysBaseMenuParameter, bt menu.Parameters = make([]*system.MenuParameter, len(params)) for i, p := range params { menu.Parameters[i] = &system.MenuParameter{ - ID: uint(p.ID), - Type: safeString(p.Type), - Key: safeString(p.Key), - Value: safeString(p.Value), - } - if p.SysBaseMenuID != nil { - menu.Parameters[i].SysBaseMenuID = uint(*p.SysBaseMenuID) + ID: uint(p.ID), + SysBaseMenuID: uint(p.SysBaseMenuID), + Type: p.Type, + Key: p.Key, + Value: p.Value, } } } @@ -501,12 +469,10 @@ func toBizBaseMenu(m *model.SysBaseMenu, params []model.SysBaseMenuParameter, bt menu.MenuBtn = make([]*system.MenuBtn, len(btns)) for i, b := range btns { menu.MenuBtn[i] = &system.MenuBtn{ - ID: uint(b.ID), - Name: safeString(b.Name), - Desc: safeString(b.Desc), - } - if b.SysBaseMenuID != nil { - menu.MenuBtn[i].SysBaseMenuID = uint(*b.SysBaseMenuID) + ID: uint(b.ID), + SysBaseMenuID: uint(b.SysBaseMenuID), + Name: b.Name, + Desc: b.Desc, } } } diff --git a/internal/data/system/operation_record.go b/internal/data/system/operation_record.go new file mode 100644 index 0000000..f640e3f --- /dev/null +++ b/internal/data/system/operation_record.go @@ -0,0 +1,131 @@ +package system + +import ( + "context" + + "kra/internal/biz/system" + "kra/internal/data/model" + + "gorm.io/gorm" +) + +type operationRecordRepo struct { + db *gorm.DB +} + +// NewOperationRecordRepo 创建操作记录仓储 +func NewOperationRecordRepo(db *gorm.DB) system.OperationRecordRepo { + return &operationRecordRepo{db: db} +} + +func (r *operationRecordRepo) Create(ctx context.Context, record *system.OperationRecord) error { + m := toModelOperationRecord(record) + if err := r.db.WithContext(ctx).Create(m).Error; err != nil { + return err + } + record.ID = uint(m.ID) + return nil +} + +func (r *operationRecordRepo) Delete(ctx context.Context, id uint) error { + return r.db.WithContext(ctx).Delete(&model.SysOperationRecord{}, id).Error +} + +func (r *operationRecordRepo) DeleteByIds(ctx context.Context, ids []uint) error { + return r.db.WithContext(ctx).Delete(&model.SysOperationRecord{}, "id in (?)", ids).Error +} + +func (r *operationRecordRepo) FindByID(ctx context.Context, id uint) (*system.OperationRecord, error) { + var m model.SysOperationRecord + if err := r.db.WithContext(ctx).Where("id = ?", id).First(&m).Error; err != nil { + return nil, err + } + return toBizOperationRecord(&m, nil), nil +} + +func (r *operationRecordRepo) List(ctx context.Context, page, pageSize int, filters map[string]interface{}) ([]*system.OperationRecord, int64, error) { + db := r.db.WithContext(ctx).Model(&model.SysOperationRecord{}) + + if v, ok := filters["method"]; ok && v != "" { + db = db.Where("method = ?", v) + } + if v, ok := filters["path"]; ok && v != "" { + db = db.Where("path LIKE ?", "%"+v.(string)+"%") + } + if v, ok := filters["status"]; ok && v.(int) != 0 { + db = db.Where("status = ?", v) + } + + var total int64 + if err := db.Count(&total).Error; err != nil { + return nil, 0, err + } + + offset := (page - 1) * pageSize + var list []model.SysOperationRecord + if err := db.Order("id desc").Offset(offset).Limit(pageSize).Find(&list).Error; err != nil { + return nil, 0, err + } + + // 预加载用户信息 + userIDs := make([]int64, 0) + for _, m := range list { + userIDs = append(userIDs, m.UserID) + } + userMap := make(map[int64]*model.SysUser) + if len(userIDs) > 0 { + var users []model.SysUser + r.db.WithContext(ctx).Where("id in (?)", userIDs).Find(&users) + for i := range users { + userMap[users[i].ID] = &users[i] + } + } + + result := make([]*system.OperationRecord, len(list)) + for i, m := range list { + user := userMap[m.UserID] + result[i] = toBizOperationRecord(&m, user) + } + return result, total, nil +} + +// 转换函数 +func toModelOperationRecord(r *system.OperationRecord) *model.SysOperationRecord { + return &model.SysOperationRecord{ + ID: int64(r.ID), + IP: r.IP, + Method: r.Method, + Path: r.Path, + Status: int64(r.Status), + Latency: r.Latency, + Agent: r.Agent, + ErrorMessage: r.ErrorMessage, + Body: r.Body, + Resp: r.Resp, + UserID: int64(r.UserID), + } +} + +func toBizOperationRecord(m *model.SysOperationRecord, user *model.SysUser) *system.OperationRecord { + r := &system.OperationRecord{ + ID: uint(m.ID), + IP: m.IP, + Method: m.Method, + Path: m.Path, + Status: int(m.Status), + Latency: m.Latency, + Agent: m.Agent, + ErrorMessage: m.ErrorMessage, + Body: m.Body, + Resp: m.Resp, + UserID: uint(m.UserID), + } + if user != nil { + r.User = &system.User{ + ID: uint(user.ID), + Username: user.Username, + NickName: user.NickName, + } + } + return r +} diff --git a/internal/data/system/user.go b/internal/data/system/user.go index a0d54f7..8ce17c4 100644 --- a/internal/data/system/user.go +++ b/internal/data/system/user.go @@ -263,9 +263,7 @@ func (r *userRepo) GetAuthorityMenuRouters(ctx context.Context, authorityId uint routers := make([]string, len(menus)) for i, m := range menus { - if m.Name != nil { - routers[i] = *m.Name - } + routers[i] = m.Name } return routers, nil } @@ -275,76 +273,41 @@ func (r *userRepo) GetAuthorityDefaultRouter(ctx context.Context, authorityId ui if err := r.db.WithContext(ctx).Where("authority_id = ?", authorityId).First(&authority).Error; err != nil { return "", err } - if authority.DefaultRouter != nil { - return *authority.DefaultRouter, nil - } - return "", nil + return authority.DefaultRouter, nil } // 转换函数 func toBizUser(u *system.User) *model.SysUser { - uuidStr := u.UUID.String() - username := u.Username - password := u.Password - nickName := u.NickName - headerImg := u.HeaderImg - authorityID := int64(u.AuthorityId) - phone := u.Phone - email := u.Email - enable := int64(u.Enable) - return &model.SysUser{ ID: int64(u.ID), - UUID: &uuidStr, - Username: &username, - Password: &password, - NickName: &nickName, - HeaderImg: &headerImg, - AuthorityID: &authorityID, - Phone: &phone, - Email: &email, - Enable: &enable, + UUID: u.UUID.String(), + Username: u.Username, + Password: u.Password, + NickName: u.NickName, + HeaderImg: u.HeaderImg, + AuthorityID: int64(u.AuthorityId), + Phone: u.Phone, + Email: u.Email, + Enable: int64(u.Enable), } } func toModelUser(m *model.SysUser) *system.User { - u := &system.User{ID: uint(m.ID)} - if m.UUID != nil { - u.UUID, _ = uuid.Parse(*m.UUID) - } - if m.Username != nil { - u.Username = *m.Username - } - if m.Password != nil { - u.Password = *m.Password - } - if m.NickName != nil { - u.NickName = *m.NickName - } - if m.HeaderImg != nil { - u.HeaderImg = *m.HeaderImg - } - if m.AuthorityID != nil { - u.AuthorityId = uint(*m.AuthorityID) - } - if m.Phone != nil { - u.Phone = *m.Phone - } - if m.Email != nil { - u.Email = *m.Email - } - if m.Enable != nil { - u.Enable = int(*m.Enable) - } - if m.OriginSetting != nil { - u.OriginSetting = json.RawMessage(*m.OriginSetting) - } - if m.CreatedAt != nil { - u.CreatedAt = *m.CreatedAt - } - if m.UpdatedAt != nil { - u.UpdatedAt = *m.UpdatedAt + u := &system.User{ + ID: uint(m.ID), + Username: m.Username, + Password: m.Password, + NickName: m.NickName, + HeaderImg: m.HeaderImg, + AuthorityId: uint(m.AuthorityID), + Phone: m.Phone, + Email: m.Email, + Enable: int(m.Enable), + OriginSetting: json.RawMessage(m.OriginSetting), + CreatedAt: m.CreatedAt, + UpdatedAt: m.UpdatedAt, } + u.UUID, _ = uuid.Parse(m.UUID) return u } @@ -354,11 +317,11 @@ func toModelUserWithAuthorities(m *model.SysUser) *system.User { // 转换Authority u.Authority = &system.Authority{ AuthorityId: uint(m.Authority.AuthorityID), - AuthorityName: safeString(m.Authority.AuthorityName), - DefaultRouter: safeString(m.Authority.DefaultRouter), + AuthorityName: m.Authority.AuthorityName, + DefaultRouter: m.Authority.DefaultRouter, } - if m.Authority.ParentID != nil { - pid := uint(*m.Authority.ParentID) + if m.Authority.ParentID != 0 { + pid := uint(m.Authority.ParentID) u.Authority.ParentId = &pid } @@ -368,11 +331,11 @@ func toModelUserWithAuthorities(m *model.SysUser) *system.User { for i, a := range m.Authorities { u.Authorities[i] = &system.Authority{ AuthorityId: uint(a.AuthorityID), - AuthorityName: safeString(a.AuthorityName), - DefaultRouter: safeString(a.DefaultRouter), + AuthorityName: a.AuthorityName, + DefaultRouter: a.DefaultRouter, } - if a.ParentID != nil { - pid := uint(*a.ParentID) + if a.ParentID != 0 { + pid := uint(a.ParentID) u.Authorities[i].ParentId = &pid } } @@ -380,10 +343,3 @@ func toModelUserWithAuthorities(m *model.SysUser) *system.User { return u } - -func safeString(s *string) string { - if s == nil { - return "" - } - return *s -} diff --git a/internal/service/system/dictionary.go b/internal/service/system/dictionary.go new file mode 100644 index 0000000..5f07575 --- /dev/null +++ b/internal/service/system/dictionary.go @@ -0,0 +1,579 @@ +package system + +import ( + "context" + "fmt" + + "kra/internal/biz/system" + + "github.com/go-kratos/kratos/v2/errors" + "github.com/go-kratos/kratos/v2/transport/http" +) + +// DictionaryService 字典服务 +type DictionaryService struct { + uc *system.DictionaryUsecase +} + +// NewDictionaryService 创建字典服务 +func NewDictionaryService(uc *system.DictionaryUsecase) *DictionaryService { + return &DictionaryService{uc: uc} +} + +// DictionaryInfo 字典信息 +type DictionaryInfo struct { + ID uint `json:"ID"` + Name string `json:"name"` + Type string `json:"type"` + Status *bool `json:"status"` + Desc string `json:"desc"` + ParentID *uint `json:"parentId,omitempty"` + Children []*DictionaryInfo `json:"children,omitempty"` +} + +// DictionaryDetailInfo 字典详情信息 +type DictionaryDetailInfo struct { + ID uint `json:"ID"` + Label string `json:"label"` + Value string `json:"value"` + Extend string `json:"extend"` + Status *bool `json:"status"` + Sort int `json:"sort"` + SysDictionaryID uint `json:"sysDictionaryID"` + ParentID *uint `json:"parentId,omitempty"` + Level int `json:"level"` + Path string `json:"path"` + Disabled bool `json:"disabled"` + Children []*DictionaryDetailInfo `json:"children,omitempty"` +} + +// CreateDictionaryRequest 创建字典请求 +type CreateDictionaryRequest struct { + Name string `json:"name"` + Type string `json:"type"` + Status *bool `json:"status"` + Desc string `json:"desc"` + ParentID *uint `json:"parentId"` +} + +// CreateDictionary 创建字典 +func (s *DictionaryService) CreateDictionary(ctx context.Context, req *CreateDictionaryRequest) error { + dict := &system.Dictionary{ + Name: req.Name, + Type: req.Type, + Status: req.Status, + Desc: req.Desc, + ParentID: req.ParentID, + } + return s.uc.CreateDictionary(ctx, dict) +} + +// UpdateDictionaryRequest 更新字典请求 +type UpdateDictionaryRequest struct { + ID uint `json:"ID"` + Name string `json:"name"` + Type string `json:"type"` + Status *bool `json:"status"` + Desc string `json:"desc"` + ParentID *uint `json:"parentId"` +} + +// UpdateDictionary 更新字典 +func (s *DictionaryService) UpdateDictionary(ctx context.Context, req *UpdateDictionaryRequest) error { + dict := &system.Dictionary{ + ID: req.ID, + Name: req.Name, + Type: req.Type, + Status: req.Status, + Desc: req.Desc, + ParentID: req.ParentID, + } + return s.uc.UpdateDictionary(ctx, dict) +} + +// DeleteDictionary 删除字典 +func (s *DictionaryService) DeleteDictionary(ctx context.Context, id uint) error { + return s.uc.DeleteDictionary(ctx, id) +} + +// GetDictionaryRequest 获取字典请求 +type GetDictionaryRequest struct { + Type string `json:"type"` + ID uint `json:"ID"` + Status *bool `json:"status"` +} + +// GetDictionary 获取字典 +func (s *DictionaryService) GetDictionary(ctx context.Context, req *GetDictionaryRequest) (*DictionaryInfo, error) { + dict, err := s.uc.GetDictionary(ctx, req.Type, req.ID, req.Status) + if err != nil { + return nil, err + } + return toDictionaryInfo(dict), nil +} + +// GetDictionaryListRequest 获取字典列表请求 +type GetDictionaryListRequest struct { + Name string `json:"name"` +} + +// GetDictionaryList 获取字典列表 +func (s *DictionaryService) GetDictionaryList(ctx context.Context, req *GetDictionaryListRequest) ([]*DictionaryInfo, error) { + list, err := s.uc.GetDictionaryList(ctx, req.Name) + if err != nil { + return nil, err + } + result := make([]*DictionaryInfo, len(list)) + for i, d := range list { + result[i] = toDictionaryInfo(d) + } + return result, nil +} + +// ExportDictionary 导出字典 +func (s *DictionaryService) ExportDictionary(ctx context.Context, id uint) (map[string]interface{}, error) { + return s.uc.ExportDictionary(ctx, id) +} + +// ImportDictionaryRequest 导入字典请求 +type ImportDictionaryRequest struct { + JsonStr string `json:"jsonStr"` +} + +// ImportDictionary 导入字典 +func (s *DictionaryService) ImportDictionary(ctx context.Context, req *ImportDictionaryRequest) error { + return s.uc.ImportDictionary(ctx, req.JsonStr) +} + +// CreateDictionaryDetailRequest 创建字典详情请求 +type CreateDictionaryDetailRequest struct { + Label string `json:"label"` + Value string `json:"value"` + Extend string `json:"extend"` + Status *bool `json:"status"` + Sort int `json:"sort"` + SysDictionaryID uint `json:"sysDictionaryID"` + ParentID *uint `json:"parentId"` +} + +// CreateDictionaryDetail 创建字典详情 +func (s *DictionaryService) CreateDictionaryDetail(ctx context.Context, req *CreateDictionaryDetailRequest) error { + detail := &system.DictionaryDetail{ + Label: req.Label, + Value: req.Value, + Extend: req.Extend, + Status: req.Status, + Sort: req.Sort, + SysDictionaryID: req.SysDictionaryID, + ParentID: req.ParentID, + } + return s.uc.CreateDictionaryDetail(ctx, detail) +} + +// UpdateDictionaryDetailRequest 更新字典详情请求 +type UpdateDictionaryDetailRequest struct { + ID uint `json:"ID"` + Label string `json:"label"` + Value string `json:"value"` + Extend string `json:"extend"` + Status *bool `json:"status"` + Sort int `json:"sort"` + SysDictionaryID uint `json:"sysDictionaryID"` + ParentID *uint `json:"parentId"` +} + +// UpdateDictionaryDetail 更新字典详情 +func (s *DictionaryService) UpdateDictionaryDetail(ctx context.Context, req *UpdateDictionaryDetailRequest) error { + detail := &system.DictionaryDetail{ + ID: req.ID, + Label: req.Label, + Value: req.Value, + Extend: req.Extend, + Status: req.Status, + Sort: req.Sort, + SysDictionaryID: req.SysDictionaryID, + ParentID: req.ParentID, + } + return s.uc.UpdateDictionaryDetail(ctx, detail) +} + +// DeleteDictionaryDetail 删除字典详情 +func (s *DictionaryService) DeleteDictionaryDetail(ctx context.Context, id uint) error { + return s.uc.DeleteDictionaryDetail(ctx, id) +} + +// GetDictionaryDetail 获取字典详情 +func (s *DictionaryService) GetDictionaryDetail(ctx context.Context, id uint) (*DictionaryDetailInfo, error) { + detail, err := s.uc.GetDictionaryDetail(ctx, id) + if err != nil { + return nil, err + } + return toDictionaryDetailInfo(detail), nil +} + +// GetDictionaryDetailListRequest 获取字典详情列表请求 +type GetDictionaryDetailListRequest struct { + Page int `json:"page"` + PageSize int `json:"pageSize"` + Label string `json:"label"` + Value string `json:"value"` + Status *bool `json:"status"` + SysDictionaryID uint `json:"sysDictionaryID"` + ParentID *uint `json:"parentId"` + Level *int `json:"level"` +} + +// GetDictionaryDetailListResponse 获取字典详情列表响应 +type GetDictionaryDetailListResponse struct { + List []*DictionaryDetailInfo `json:"list"` + Total int64 `json:"total"` + Page int `json:"page"` + PageSize int `json:"pageSize"` +} + +// GetDictionaryDetailList 获取字典详情列表 +func (s *DictionaryService) GetDictionaryDetailList(ctx context.Context, req *GetDictionaryDetailListRequest) (*GetDictionaryDetailListResponse, error) { + filters := make(map[string]interface{}) + if req.Label != "" { + filters["label"] = req.Label + } + if req.Value != "" { + filters["value"] = req.Value + } + if req.Status != nil { + filters["status"] = req.Status + } + if req.SysDictionaryID != 0 { + filters["sys_dictionary_id"] = req.SysDictionaryID + } + if req.ParentID != nil { + filters["parent_id"] = req.ParentID + } + if req.Level != nil { + filters["level"] = req.Level + } + + list, total, err := s.uc.GetDictionaryDetailList(ctx, req.Page, req.PageSize, filters) + if err != nil { + return nil, err + } + + result := make([]*DictionaryDetailInfo, len(list)) + for i, d := range list { + result[i] = toDictionaryDetailInfo(d) + } + + return &GetDictionaryDetailListResponse{ + List: result, + Total: total, + Page: req.Page, + PageSize: req.PageSize, + }, nil +} + +// GetDictionaryTreeList 获取字典树形列表 +func (s *DictionaryService) GetDictionaryTreeList(ctx context.Context, dictionaryID uint) ([]*DictionaryDetailInfo, error) { + list, err := s.uc.GetDictionaryTreeList(ctx, dictionaryID) + if err != nil { + return nil, err + } + return toDictionaryDetailInfoList(list), nil +} + +// GetDictionaryDetailsByParentRequest 根据父级获取字典详情请求 +type GetDictionaryDetailsByParentRequest struct { + SysDictionaryID uint `json:"sysDictionaryID"` + ParentID *uint `json:"parentId"` + IncludeChildren bool `json:"includeChildren"` +} + +// GetDictionaryDetailsByParent 根据父级获取字典详情 +func (s *DictionaryService) GetDictionaryDetailsByParent(ctx context.Context, req *GetDictionaryDetailsByParentRequest) ([]*DictionaryDetailInfo, error) { + list, err := s.uc.GetDictionaryDetailsByParent(ctx, req.SysDictionaryID, req.ParentID, req.IncludeChildren) + if err != nil { + return nil, err + } + return toDictionaryDetailInfoList(list), nil +} + +// GetDictionaryListByType 根据类型获取字典列表 +func (s *DictionaryService) GetDictionaryListByType(ctx context.Context, typ string) ([]*DictionaryDetailInfo, error) { + list, err := s.uc.GetDictionaryListByType(ctx, typ) + if err != nil { + return nil, err + } + return toDictionaryDetailInfoList(list), nil +} + +// GetDictionaryTreeListByType 根据类型获取字典树形列表 +func (s *DictionaryService) GetDictionaryTreeListByType(ctx context.Context, typ string) ([]*DictionaryDetailInfo, error) { + list, err := s.uc.GetDictionaryTreeListByType(ctx, typ) + if err != nil { + return nil, err + } + return toDictionaryDetailInfoList(list), nil +} + +// 转换函数 +func toDictionaryInfo(d *system.Dictionary) *DictionaryInfo { + info := &DictionaryInfo{ + ID: d.ID, + Name: d.Name, + Type: d.Type, + Status: d.Status, + Desc: d.Desc, + ParentID: d.ParentID, + } + if len(d.Children) > 0 { + info.Children = make([]*DictionaryInfo, len(d.Children)) + for i, c := range d.Children { + info.Children[i] = toDictionaryInfo(c) + } + } + return info +} + +func toDictionaryDetailInfo(d *system.DictionaryDetail) *DictionaryDetailInfo { + info := &DictionaryDetailInfo{ + ID: d.ID, + Label: d.Label, + Value: d.Value, + Extend: d.Extend, + Status: d.Status, + Sort: d.Sort, + SysDictionaryID: d.SysDictionaryID, + ParentID: d.ParentID, + Level: d.Level, + Path: d.Path, + Disabled: d.Disabled, + } + if len(d.Children) > 0 { + info.Children = make([]*DictionaryDetailInfo, len(d.Children)) + for i, c := range d.Children { + info.Children[i] = toDictionaryDetailInfo(c) + } + } + return info +} + +func toDictionaryDetailInfoList(list []*system.DictionaryDetail) []*DictionaryDetailInfo { + result := make([]*DictionaryDetailInfo, len(list)) + for i, d := range list { + result[i] = toDictionaryDetailInfo(d) + } + return result +} + +// RegisterRoutes 注册路由 +func (s *DictionaryService) RegisterRoutes(srv *http.Server) { + r := srv.Route("/") + + // 字典接口 + r.POST("/sysDictionary/createSysDictionary", s.handleCreateDictionary) + r.DELETE("/sysDictionary/deleteSysDictionary", s.handleDeleteDictionary) + r.PUT("/sysDictionary/updateSysDictionary", s.handleUpdateDictionary) + r.GET("/sysDictionary/findSysDictionary", s.handleGetDictionary) + r.GET("/sysDictionary/getSysDictionaryList", s.handleGetDictionaryList) + r.GET("/sysDictionary/exportSysDictionary", s.handleExportDictionary) + r.POST("/sysDictionary/importSysDictionary", s.handleImportDictionary) + + // 字典详情接口 + r.POST("/sysDictionaryDetail/createSysDictionaryDetail", s.handleCreateDictionaryDetail) + r.DELETE("/sysDictionaryDetail/deleteSysDictionaryDetail", s.handleDeleteDictionaryDetail) + r.PUT("/sysDictionaryDetail/updateSysDictionaryDetail", s.handleUpdateDictionaryDetail) + r.GET("/sysDictionaryDetail/findSysDictionaryDetail", s.handleGetDictionaryDetail) + r.GET("/sysDictionaryDetail/getSysDictionaryDetailList", s.handleGetDictionaryDetailList) + r.GET("/sysDictionaryDetail/getDictionaryTreeList", s.handleGetDictionaryTreeList) + r.POST("/sysDictionaryDetail/getDictionaryDetailsByParent", s.handleGetDictionaryDetailsByParent) + r.GET("/sysDictionaryDetail/getDictionaryListByType", s.handleGetDictionaryListByType) + r.GET("/sysDictionaryDetail/getDictionaryTreeListByType", s.handleGetDictionaryTreeListByType) +} + +// HTTP Handlers - Dictionary +func (s *DictionaryService) handleCreateDictionary(ctx http.Context) error { + var req CreateDictionaryRequest + if err := ctx.Bind(&req); err != nil { + return err + } + if err := s.CreateDictionary(ctx, &req); err != nil { + return errors.BadRequest("CREATE_FAILED", err.Error()) + } + return ctx.Result(200, map[string]any{"code": 0, "msg": "创建成功"}) +} + +func (s *DictionaryService) handleDeleteDictionary(ctx http.Context) error { + var req struct { + ID uint `json:"ID"` + } + if err := ctx.Bind(&req); err != nil { + return err + } + if err := s.DeleteDictionary(ctx, req.ID); err != nil { + return errors.BadRequest("DELETE_FAILED", err.Error()) + } + return ctx.Result(200, map[string]any{"code": 0, "msg": "删除成功"}) +} + +func (s *DictionaryService) handleUpdateDictionary(ctx http.Context) error { + var req UpdateDictionaryRequest + if err := ctx.Bind(&req); err != nil { + return err + } + if err := s.UpdateDictionary(ctx, &req); err != nil { + return errors.BadRequest("UPDATE_FAILED", err.Error()) + } + return ctx.Result(200, map[string]any{"code": 0, "msg": "更新成功"}) +} + +func (s *DictionaryService) handleGetDictionary(ctx http.Context) error { + var req GetDictionaryRequest + if err := ctx.BindQuery(&req); err != nil { + return err + } + resp, err := s.GetDictionary(ctx, &req) + if err != nil { + return errors.NotFound("NOT_FOUND", err.Error()) + } + return ctx.Result(200, map[string]any{"code": 0, "msg": "获取成功", "data": map[string]any{"reSysDictionary": resp}}) +} + +func (s *DictionaryService) handleGetDictionaryList(ctx http.Context) error { + var req GetDictionaryListRequest + if err := ctx.BindQuery(&req); err != nil { + return err + } + resp, err := s.GetDictionaryList(ctx, &req) + if err != nil { + return errors.InternalServer("LIST_ERROR", err.Error()) + } + return ctx.Result(200, map[string]any{"code": 0, "msg": "获取成功", "data": map[string]any{"list": resp}}) +} + +func (s *DictionaryService) handleExportDictionary(ctx http.Context) error { + idStr := ctx.Query().Get("id") + id, _ := parseUint(idStr) + resp, err := s.ExportDictionary(ctx, id) + if err != nil { + return errors.InternalServer("EXPORT_ERROR", err.Error()) + } + return ctx.Result(200, map[string]any{"code": 0, "msg": "导出成功", "data": resp}) +} + +func (s *DictionaryService) handleImportDictionary(ctx http.Context) error { + var req ImportDictionaryRequest + if err := ctx.Bind(&req); err != nil { + return err + } + if err := s.ImportDictionary(ctx, &req); err != nil { + return errors.BadRequest("IMPORT_FAILED", err.Error()) + } + return ctx.Result(200, map[string]any{"code": 0, "msg": "导入成功"}) +} + +// HTTP Handlers - DictionaryDetail +func (s *DictionaryService) handleCreateDictionaryDetail(ctx http.Context) error { + var req CreateDictionaryDetailRequest + if err := ctx.Bind(&req); err != nil { + return err + } + if err := s.CreateDictionaryDetail(ctx, &req); err != nil { + return errors.BadRequest("CREATE_FAILED", err.Error()) + } + return ctx.Result(200, map[string]any{"code": 0, "msg": "创建成功"}) +} + +func (s *DictionaryService) handleDeleteDictionaryDetail(ctx http.Context) error { + var req struct { + ID uint `json:"ID"` + } + if err := ctx.Bind(&req); err != nil { + return err + } + if err := s.DeleteDictionaryDetail(ctx, req.ID); err != nil { + return errors.BadRequest("DELETE_FAILED", err.Error()) + } + return ctx.Result(200, map[string]any{"code": 0, "msg": "删除成功"}) +} + +func (s *DictionaryService) handleUpdateDictionaryDetail(ctx http.Context) error { + var req UpdateDictionaryDetailRequest + if err := ctx.Bind(&req); err != nil { + return err + } + if err := s.UpdateDictionaryDetail(ctx, &req); err != nil { + return errors.BadRequest("UPDATE_FAILED", err.Error()) + } + return ctx.Result(200, map[string]any{"code": 0, "msg": "更新成功"}) +} + +func (s *DictionaryService) handleGetDictionaryDetail(ctx http.Context) error { + idStr := ctx.Query().Get("ID") + id, _ := parseUint(idStr) + resp, err := s.GetDictionaryDetail(ctx, id) + if err != nil { + return errors.NotFound("NOT_FOUND", err.Error()) + } + return ctx.Result(200, map[string]any{"code": 0, "msg": "获取成功", "data": map[string]any{"reSysDictionaryDetail": resp}}) +} + +func (s *DictionaryService) handleGetDictionaryDetailList(ctx http.Context) error { + var req GetDictionaryDetailListRequest + if err := ctx.BindQuery(&req); err != nil { + return err + } + resp, err := s.GetDictionaryDetailList(ctx, &req) + if err != nil { + return errors.InternalServer("LIST_ERROR", err.Error()) + } + return ctx.Result(200, map[string]any{"code": 0, "msg": "获取成功", "data": resp}) +} + +func (s *DictionaryService) handleGetDictionaryTreeList(ctx http.Context) error { + idStr := ctx.Query().Get("sysDictionaryID") + id, _ := parseUint(idStr) + resp, err := s.GetDictionaryTreeList(ctx, id) + if err != nil { + return errors.InternalServer("LIST_ERROR", err.Error()) + } + return ctx.Result(200, map[string]any{"code": 0, "msg": "获取成功", "data": map[string]any{"list": resp}}) +} + +func (s *DictionaryService) handleGetDictionaryDetailsByParent(ctx http.Context) error { + var req GetDictionaryDetailsByParentRequest + if err := ctx.Bind(&req); err != nil { + return err + } + resp, err := s.GetDictionaryDetailsByParent(ctx, &req) + if err != nil { + return errors.InternalServer("LIST_ERROR", err.Error()) + } + return ctx.Result(200, map[string]any{"code": 0, "msg": "获取成功", "data": map[string]any{"list": resp}}) +} + +func (s *DictionaryService) handleGetDictionaryListByType(ctx http.Context) error { + typ := ctx.Query().Get("type") + resp, err := s.GetDictionaryListByType(ctx, typ) + if err != nil { + return errors.InternalServer("LIST_ERROR", err.Error()) + } + return ctx.Result(200, map[string]any{"code": 0, "msg": "获取成功", "data": map[string]any{"list": resp}}) +} + +func (s *DictionaryService) handleGetDictionaryTreeListByType(ctx http.Context) error { + typ := ctx.Query().Get("type") + resp, err := s.GetDictionaryTreeListByType(ctx, typ) + if err != nil { + return errors.InternalServer("LIST_ERROR", err.Error()) + } + return ctx.Result(200, map[string]any{"code": 0, "msg": "获取成功", "data": map[string]any{"list": resp}}) +} + +// parseUint 解析uint +func parseUint(s string) (uint, error) { + if s == "" { + return 0, nil + } + var id uint + _, err := fmt.Sscanf(s, "%d", &id) + return id, err +} diff --git a/internal/service/system/operation_record.go b/internal/service/system/operation_record.go new file mode 100644 index 0000000..71dbe4f --- /dev/null +++ b/internal/service/system/operation_record.go @@ -0,0 +1,186 @@ +package system + +import ( + "context" + + "kra/internal/biz/system" + + "github.com/go-kratos/kratos/v2/errors" + "github.com/go-kratos/kratos/v2/transport/http" +) + +// OperationRecordService 操作记录服务 +type OperationRecordService struct { + uc *system.OperationRecordUsecase +} + +// NewOperationRecordService 创建操作记录服务 +func NewOperationRecordService(uc *system.OperationRecordUsecase) *OperationRecordService { + return &OperationRecordService{uc: uc} +} + +// OperationRecordInfo 操作记录信息 +type OperationRecordInfo struct { + ID uint `json:"ID"` + IP string `json:"ip"` + Method string `json:"method"` + Path string `json:"path"` + Status int `json:"status"` + Latency int64 `json:"latency"` + Agent string `json:"agent"` + ErrorMessage string `json:"error_message"` + Body string `json:"body"` + Resp string `json:"resp"` + UserID uint `json:"user_id"` + User *UserInfo `json:"user,omitempty"` +} + +// DeleteOperationRecord 删除操作记录 +func (s *OperationRecordService) DeleteOperationRecord(ctx context.Context, id uint) error { + return s.uc.DeleteOperationRecord(ctx, id) +} + +// DeleteOperationRecordByIdsRequest 批量删除请求 +type DeleteOperationRecordByIdsRequest struct { + Ids []uint `json:"ids"` +} + +// DeleteOperationRecordByIds 批量删除操作记录 +func (s *OperationRecordService) DeleteOperationRecordByIds(ctx context.Context, req *DeleteOperationRecordByIdsRequest) error { + return s.uc.DeleteOperationRecordByIds(ctx, req.Ids) +} + +// GetOperationRecord 获取操作记录 +func (s *OperationRecordService) GetOperationRecord(ctx context.Context, id uint) (*OperationRecordInfo, error) { + record, err := s.uc.GetOperationRecord(ctx, id) + if err != nil { + return nil, err + } + return toOperationRecordInfo(record), nil +} + +// GetOperationRecordListRequest 获取操作记录列表请求 +type GetOperationRecordListRequest struct { + Page int `json:"page"` + PageSize int `json:"pageSize"` + Method string `json:"method"` + Path string `json:"path"` + Status int `json:"status"` +} + +// GetOperationRecordListResponse 获取操作记录列表响应 +type GetOperationRecordListResponse struct { + List []*OperationRecordInfo `json:"list"` + Total int64 `json:"total"` + Page int `json:"page"` + PageSize int `json:"pageSize"` +} + +// GetOperationRecordList 获取操作记录列表 +func (s *OperationRecordService) GetOperationRecordList(ctx context.Context, req *GetOperationRecordListRequest) (*GetOperationRecordListResponse, error) { + filters := make(map[string]interface{}) + if req.Method != "" { + filters["method"] = req.Method + } + if req.Path != "" { + filters["path"] = req.Path + } + if req.Status != 0 { + filters["status"] = req.Status + } + + list, total, err := s.uc.GetOperationRecordList(ctx, req.Page, req.PageSize, filters) + if err != nil { + return nil, err + } + + result := make([]*OperationRecordInfo, len(list)) + for i, r := range list { + result[i] = toOperationRecordInfo(r) + } + + return &GetOperationRecordListResponse{ + List: result, + Total: total, + Page: req.Page, + PageSize: req.PageSize, + }, nil +} + +// 转换函数 +func toOperationRecordInfo(r *system.OperationRecord) *OperationRecordInfo { + info := &OperationRecordInfo{ + ID: r.ID, + IP: r.IP, + Method: r.Method, + Path: r.Path, + Status: r.Status, + Latency: r.Latency, + Agent: r.Agent, + ErrorMessage: r.ErrorMessage, + Body: r.Body, + Resp: r.Resp, + UserID: r.UserID, + } + if r.User != nil { + info.User = toUserInfo(r.User) + } + return info +} + +// RegisterRoutes 注册路由 +func (s *OperationRecordService) RegisterRoutes(srv *http.Server) { + r := srv.Route("/") + + r.DELETE("/sysOperationRecord/deleteSysOperationRecord", s.handleDeleteOperationRecord) + r.DELETE("/sysOperationRecord/deleteSysOperationRecordByIds", s.handleDeleteOperationRecordByIds) + r.GET("/sysOperationRecord/findSysOperationRecord", s.handleGetOperationRecord) + r.GET("/sysOperationRecord/getSysOperationRecordList", s.handleGetOperationRecordList) +} + +// HTTP Handlers +func (s *OperationRecordService) handleDeleteOperationRecord(ctx http.Context) error { + var req struct { + ID uint `json:"ID"` + } + if err := ctx.Bind(&req); err != nil { + return err + } + if err := s.DeleteOperationRecord(ctx, req.ID); err != nil { + return errors.BadRequest("DELETE_FAILED", err.Error()) + } + return ctx.Result(200, map[string]any{"code": 0, "msg": "删除成功"}) +} + +func (s *OperationRecordService) handleDeleteOperationRecordByIds(ctx http.Context) error { + var req DeleteOperationRecordByIdsRequest + if err := ctx.Bind(&req); err != nil { + return err + } + if err := s.DeleteOperationRecordByIds(ctx, &req); err != nil { + return errors.BadRequest("DELETE_FAILED", err.Error()) + } + return ctx.Result(200, map[string]any{"code": 0, "msg": "删除成功"}) +} + +func (s *OperationRecordService) handleGetOperationRecord(ctx http.Context) error { + idStr := ctx.Query().Get("ID") + id, _ := parseUint(idStr) + resp, err := s.GetOperationRecord(ctx, id) + if err != nil { + return errors.NotFound("NOT_FOUND", err.Error()) + } + return ctx.Result(200, map[string]any{"code": 0, "msg": "获取成功", "data": map[string]any{"reSysOperationRecord": resp}}) +} + +func (s *OperationRecordService) handleGetOperationRecordList(ctx http.Context) error { + var req GetOperationRecordListRequest + if err := ctx.BindQuery(&req); err != nil { + return err + } + resp, err := s.GetOperationRecordList(ctx, &req) + if err != nil { + return errors.InternalServer("LIST_ERROR", err.Error()) + } + return ctx.Result(200, map[string]any{"code": 0, "msg": "获取成功", "data": resp}) +}