diff --git a/internal/consts/consts.go b/internal/consts/consts.go index 1cc9613..b4f4bd4 100644 --- a/internal/consts/consts.go +++ b/internal/consts/consts.go @@ -2,8 +2,8 @@ package consts const ( // 笑门官网查询英雄名称和神器名称,用作中文翻译 - SimileHeroName = "https://static.smilegatemegaport.com/gameRecord/epic7/epic7_hero.json?_=1729322698936" - SimileArtifactName = "https://static.smilegatemegaport.com/gameRecord/epic7/epic7_artifact.json?_=1729322698936" + SimileHeroName = "https://static.smilegatemegaport.com/gameRecord/epic7/epic7_hero.json" + SimileArtifactName = "https://static.smilegatemegaport.com/gameRecord/epic7/epic7_artifact.json" // 获取角色信息 HeroListURL = "https://e7-optimizer-game-data.s3-accelerate.amazonaws.com/herodata.json" diff --git a/internal/dao/internal/epic_artifact_info.go b/internal/dao/internal/epic_artifact_info.go index e3df147..f20baff 100644 --- a/internal/dao/internal/epic_artifact_info.go +++ b/internal/dao/internal/epic_artifact_info.go @@ -11,14 +11,15 @@ import ( "github.com/gogf/gf/v2/frame/g" ) -// EpicArtifactInfoDao is the data access object for table epic_artifact_info. +// EpicArtifactInfoDao is the data access object for the table epic_artifact_info. type EpicArtifactInfoDao struct { - table string // table is the underlying table name of the DAO. - group string // group is the database configuration group name of current DAO. - columns EpicArtifactInfoColumns // columns contains all the column names of Table for convenient usage. + table string // table is the underlying table name of the DAO. + group string // group is the database configuration group name of the current DAO. + columns EpicArtifactInfoColumns // columns contains all the column names of Table for convenient usage. + handlers []gdb.ModelHandler // handlers for customized model modification. } -// EpicArtifactInfoColumns defines and stores column names for table epic_artifact_info. +// EpicArtifactInfoColumns defines and stores column names for the table epic_artifact_info. type EpicArtifactInfoColumns struct { Id string // 文件编号 ArtifactName string // 配置编号 @@ -37,7 +38,7 @@ type EpicArtifactInfoColumns struct { ImageUrl string // 图片地址 } -// epicArtifactInfoColumns holds the columns for table epic_artifact_info. +// epicArtifactInfoColumns holds the columns for the table epic_artifact_info. var epicArtifactInfoColumns = EpicArtifactInfoColumns{ Id: "id", ArtifactName: "artifact_name", @@ -57,44 +58,49 @@ var epicArtifactInfoColumns = EpicArtifactInfoColumns{ } // NewEpicArtifactInfoDao creates and returns a new DAO object for table data access. -func NewEpicArtifactInfoDao() *EpicArtifactInfoDao { +func NewEpicArtifactInfoDao(handlers ...gdb.ModelHandler) *EpicArtifactInfoDao { return &EpicArtifactInfoDao{ - group: "default", - table: "epic_artifact_info", - columns: epicArtifactInfoColumns, + group: "default", + table: "epic_artifact_info", + columns: epicArtifactInfoColumns, + handlers: handlers, } } -// DB retrieves and returns the underlying raw database management object of current DAO. +// DB retrieves and returns the underlying raw database management object of the current DAO. func (dao *EpicArtifactInfoDao) DB() gdb.DB { return g.DB(dao.group) } -// Table returns the table name of current dao. +// Table returns the table name of the current DAO. func (dao *EpicArtifactInfoDao) Table() string { return dao.table } -// Columns returns all column names of current dao. +// Columns returns all column names of the current DAO. func (dao *EpicArtifactInfoDao) Columns() EpicArtifactInfoColumns { return dao.columns } -// Group returns the configuration group name of database of current dao. +// Group returns the database configuration group name of the current DAO. func (dao *EpicArtifactInfoDao) Group() string { return dao.group } -// Ctx creates and returns the Model for current DAO, It automatically sets the context for current operation. +// Ctx creates and returns a Model for the current DAO. It automatically sets the context for the current operation. func (dao *EpicArtifactInfoDao) Ctx(ctx context.Context) *gdb.Model { - return dao.DB().Model(dao.table).Safe().Ctx(ctx) + model := dao.DB().Model(dao.table) + for _, handler := range dao.handlers { + model = handler(model) + } + return model.Safe().Ctx(ctx) } // Transaction wraps the transaction logic using function f. -// It rollbacks the transaction and returns the error from function f if it returns non-nil error. +// It rolls back the transaction and returns the error if function f returns a non-nil error. // It commits the transaction and returns nil if function f returns nil. // -// Note that, you should not Commit or Rollback the transaction in function f +// Note: Do not commit or roll back the transaction in function f, // as it is automatically handled by this function. func (dao *EpicArtifactInfoDao) Transaction(ctx context.Context, f func(ctx context.Context, tx gdb.TX) error) (err error) { return dao.Ctx(ctx).Transaction(ctx, f) diff --git a/internal/dao/internal/epic_gvg_attack_teams.go b/internal/dao/internal/epic_gvg_attack_teams.go index d350ee5..3b09acf 100644 --- a/internal/dao/internal/epic_gvg_attack_teams.go +++ b/internal/dao/internal/epic_gvg_attack_teams.go @@ -11,14 +11,15 @@ import ( "github.com/gogf/gf/v2/frame/g" ) -// EpicGvgAttackTeamsDao is the data access object for table epic_gvg_attack_teams. +// EpicGvgAttackTeamsDao is the data access object for the table epic_gvg_attack_teams. type EpicGvgAttackTeamsDao struct { - table string // table is the underlying table name of the DAO. - group string // group is the database configuration group name of current DAO. - columns EpicGvgAttackTeamsColumns // columns contains all the column names of Table for convenient usage. + table string // table is the underlying table name of the DAO. + group string // group is the database configuration group name of the current DAO. + columns EpicGvgAttackTeamsColumns // columns contains all the column names of Table for convenient usage. + handlers []gdb.ModelHandler // handlers for customized model modification. } -// EpicGvgAttackTeamsColumns defines and stores column names for table epic_gvg_attack_teams. +// EpicGvgAttackTeamsColumns defines and stores column names for the table epic_gvg_attack_teams. type EpicGvgAttackTeamsColumns struct { Id string // id AttackHeroes string // 进攻角色 @@ -29,7 +30,7 @@ type EpicGvgAttackTeamsColumns struct { Deleted string // 是否删除 } -// epicGvgAttackTeamsColumns holds the columns for table epic_gvg_attack_teams. +// epicGvgAttackTeamsColumns holds the columns for the table epic_gvg_attack_teams. var epicGvgAttackTeamsColumns = EpicGvgAttackTeamsColumns{ Id: "id", AttackHeroes: "attack_heroes", @@ -41,44 +42,49 @@ var epicGvgAttackTeamsColumns = EpicGvgAttackTeamsColumns{ } // NewEpicGvgAttackTeamsDao creates and returns a new DAO object for table data access. -func NewEpicGvgAttackTeamsDao() *EpicGvgAttackTeamsDao { +func NewEpicGvgAttackTeamsDao(handlers ...gdb.ModelHandler) *EpicGvgAttackTeamsDao { return &EpicGvgAttackTeamsDao{ - group: "default", - table: "epic_gvg_attack_teams", - columns: epicGvgAttackTeamsColumns, + group: "default", + table: "epic_gvg_attack_teams", + columns: epicGvgAttackTeamsColumns, + handlers: handlers, } } -// DB retrieves and returns the underlying raw database management object of current DAO. +// DB retrieves and returns the underlying raw database management object of the current DAO. func (dao *EpicGvgAttackTeamsDao) DB() gdb.DB { return g.DB(dao.group) } -// Table returns the table name of current dao. +// Table returns the table name of the current DAO. func (dao *EpicGvgAttackTeamsDao) Table() string { return dao.table } -// Columns returns all column names of current dao. +// Columns returns all column names of the current DAO. func (dao *EpicGvgAttackTeamsDao) Columns() EpicGvgAttackTeamsColumns { return dao.columns } -// Group returns the configuration group name of database of current dao. +// Group returns the database configuration group name of the current DAO. func (dao *EpicGvgAttackTeamsDao) Group() string { return dao.group } -// Ctx creates and returns the Model for current DAO, It automatically sets the context for current operation. +// Ctx creates and returns a Model for the current DAO. It automatically sets the context for the current operation. func (dao *EpicGvgAttackTeamsDao) Ctx(ctx context.Context) *gdb.Model { - return dao.DB().Model(dao.table).Safe().Ctx(ctx) + model := dao.DB().Model(dao.table) + for _, handler := range dao.handlers { + model = handler(model) + } + return model.Safe().Ctx(ctx) } // Transaction wraps the transaction logic using function f. -// It rollbacks the transaction and returns the error from function f if it returns non-nil error. +// It rolls back the transaction and returns the error if function f returns a non-nil error. // It commits the transaction and returns nil if function f returns nil. // -// Note that, you should not Commit or Rollback the transaction in function f +// Note: Do not commit or roll back the transaction in function f, // as it is automatically handled by this function. func (dao *EpicGvgAttackTeamsDao) Transaction(ctx context.Context, f func(ctx context.Context, tx gdb.TX) error) (err error) { return dao.Ctx(ctx).Transaction(ctx, f) diff --git a/internal/dao/internal/epic_gvg_defense_attack_mapping.go b/internal/dao/internal/epic_gvg_defense_attack_mapping.go index fa4973c..56769ad 100644 --- a/internal/dao/internal/epic_gvg_defense_attack_mapping.go +++ b/internal/dao/internal/epic_gvg_defense_attack_mapping.go @@ -11,14 +11,15 @@ import ( "github.com/gogf/gf/v2/frame/g" ) -// EpicGvgDefenseAttackMappingDao is the data access object for table epic_gvg_defense_attack_mapping. +// EpicGvgDefenseAttackMappingDao is the data access object for the table epic_gvg_defense_attack_mapping. type EpicGvgDefenseAttackMappingDao struct { - table string // table is the underlying table name of the DAO. - group string // group is the database configuration group name of current DAO. - columns EpicGvgDefenseAttackMappingColumns // columns contains all the column names of Table for convenient usage. + table string // table is the underlying table name of the DAO. + group string // group is the database configuration group name of the current DAO. + columns EpicGvgDefenseAttackMappingColumns // columns contains all the column names of Table for convenient usage. + handlers []gdb.ModelHandler // handlers for customized model modification. } -// EpicGvgDefenseAttackMappingColumns defines and stores column names for table epic_gvg_defense_attack_mapping. +// EpicGvgDefenseAttackMappingColumns defines and stores column names for the table epic_gvg_defense_attack_mapping. type EpicGvgDefenseAttackMappingColumns struct { Id string // id DefenseId string // 防守阵容 @@ -35,7 +36,7 @@ type EpicGvgDefenseAttackMappingColumns struct { Deleted string // 是否删除 } -// epicGvgDefenseAttackMappingColumns holds the columns for table epic_gvg_defense_attack_mapping. +// epicGvgDefenseAttackMappingColumns holds the columns for the table epic_gvg_defense_attack_mapping. var epicGvgDefenseAttackMappingColumns = EpicGvgDefenseAttackMappingColumns{ Id: "id", DefenseId: "defense_id", @@ -53,44 +54,49 @@ var epicGvgDefenseAttackMappingColumns = EpicGvgDefenseAttackMappingColumns{ } // NewEpicGvgDefenseAttackMappingDao creates and returns a new DAO object for table data access. -func NewEpicGvgDefenseAttackMappingDao() *EpicGvgDefenseAttackMappingDao { +func NewEpicGvgDefenseAttackMappingDao(handlers ...gdb.ModelHandler) *EpicGvgDefenseAttackMappingDao { return &EpicGvgDefenseAttackMappingDao{ - group: "default", - table: "epic_gvg_defense_attack_mapping", - columns: epicGvgDefenseAttackMappingColumns, + group: "default", + table: "epic_gvg_defense_attack_mapping", + columns: epicGvgDefenseAttackMappingColumns, + handlers: handlers, } } -// DB retrieves and returns the underlying raw database management object of current DAO. +// DB retrieves and returns the underlying raw database management object of the current DAO. func (dao *EpicGvgDefenseAttackMappingDao) DB() gdb.DB { return g.DB(dao.group) } -// Table returns the table name of current dao. +// Table returns the table name of the current DAO. func (dao *EpicGvgDefenseAttackMappingDao) Table() string { return dao.table } -// Columns returns all column names of current dao. +// Columns returns all column names of the current DAO. func (dao *EpicGvgDefenseAttackMappingDao) Columns() EpicGvgDefenseAttackMappingColumns { return dao.columns } -// Group returns the configuration group name of database of current dao. +// Group returns the database configuration group name of the current DAO. func (dao *EpicGvgDefenseAttackMappingDao) Group() string { return dao.group } -// Ctx creates and returns the Model for current DAO, It automatically sets the context for current operation. +// Ctx creates and returns a Model for the current DAO. It automatically sets the context for the current operation. func (dao *EpicGvgDefenseAttackMappingDao) Ctx(ctx context.Context) *gdb.Model { - return dao.DB().Model(dao.table).Safe().Ctx(ctx) + model := dao.DB().Model(dao.table) + for _, handler := range dao.handlers { + model = handler(model) + } + return model.Safe().Ctx(ctx) } // Transaction wraps the transaction logic using function f. -// It rollbacks the transaction and returns the error from function f if it returns non-nil error. +// It rolls back the transaction and returns the error if function f returns a non-nil error. // It commits the transaction and returns nil if function f returns nil. // -// Note that, you should not Commit or Rollback the transaction in function f +// Note: Do not commit or roll back the transaction in function f, // as it is automatically handled by this function. func (dao *EpicGvgDefenseAttackMappingDao) Transaction(ctx context.Context, f func(ctx context.Context, tx gdb.TX) error) (err error) { return dao.Ctx(ctx).Transaction(ctx, f) diff --git a/internal/dao/internal/epic_gvg_defense_teams.go b/internal/dao/internal/epic_gvg_defense_teams.go index c3b625b..9ed63f1 100644 --- a/internal/dao/internal/epic_gvg_defense_teams.go +++ b/internal/dao/internal/epic_gvg_defense_teams.go @@ -11,14 +11,15 @@ import ( "github.com/gogf/gf/v2/frame/g" ) -// EpicGvgDefenseTeamsDao is the data access object for table epic_gvg_defense_teams. +// EpicGvgDefenseTeamsDao is the data access object for the table epic_gvg_defense_teams. type EpicGvgDefenseTeamsDao struct { - table string // table is the underlying table name of the DAO. - group string // group is the database configuration group name of current DAO. - columns EpicGvgDefenseTeamsColumns // columns contains all the column names of Table for convenient usage. + table string // table is the underlying table name of the DAO. + group string // group is the database configuration group name of the current DAO. + columns EpicGvgDefenseTeamsColumns // columns contains all the column names of Table for convenient usage. + handlers []gdb.ModelHandler // handlers for customized model modification. } -// EpicGvgDefenseTeamsColumns defines and stores column names for table epic_gvg_defense_teams. +// EpicGvgDefenseTeamsColumns defines and stores column names for the table epic_gvg_defense_teams. type EpicGvgDefenseTeamsColumns struct { Id string // id DefenseHeroes string // 防守角色 @@ -29,7 +30,7 @@ type EpicGvgDefenseTeamsColumns struct { Deleted string // 是否删除 } -// epicGvgDefenseTeamsColumns holds the columns for table epic_gvg_defense_teams. +// epicGvgDefenseTeamsColumns holds the columns for the table epic_gvg_defense_teams. var epicGvgDefenseTeamsColumns = EpicGvgDefenseTeamsColumns{ Id: "id", DefenseHeroes: "defense_heroes", @@ -41,44 +42,49 @@ var epicGvgDefenseTeamsColumns = EpicGvgDefenseTeamsColumns{ } // NewEpicGvgDefenseTeamsDao creates and returns a new DAO object for table data access. -func NewEpicGvgDefenseTeamsDao() *EpicGvgDefenseTeamsDao { +func NewEpicGvgDefenseTeamsDao(handlers ...gdb.ModelHandler) *EpicGvgDefenseTeamsDao { return &EpicGvgDefenseTeamsDao{ - group: "default", - table: "epic_gvg_defense_teams", - columns: epicGvgDefenseTeamsColumns, + group: "default", + table: "epic_gvg_defense_teams", + columns: epicGvgDefenseTeamsColumns, + handlers: handlers, } } -// DB retrieves and returns the underlying raw database management object of current DAO. +// DB retrieves and returns the underlying raw database management object of the current DAO. func (dao *EpicGvgDefenseTeamsDao) DB() gdb.DB { return g.DB(dao.group) } -// Table returns the table name of current dao. +// Table returns the table name of the current DAO. func (dao *EpicGvgDefenseTeamsDao) Table() string { return dao.table } -// Columns returns all column names of current dao. +// Columns returns all column names of the current DAO. func (dao *EpicGvgDefenseTeamsDao) Columns() EpicGvgDefenseTeamsColumns { return dao.columns } -// Group returns the configuration group name of database of current dao. +// Group returns the database configuration group name of the current DAO. func (dao *EpicGvgDefenseTeamsDao) Group() string { return dao.group } -// Ctx creates and returns the Model for current DAO, It automatically sets the context for current operation. +// Ctx creates and returns a Model for the current DAO. It automatically sets the context for the current operation. func (dao *EpicGvgDefenseTeamsDao) Ctx(ctx context.Context) *gdb.Model { - return dao.DB().Model(dao.table).Safe().Ctx(ctx) + model := dao.DB().Model(dao.table) + for _, handler := range dao.handlers { + model = handler(model) + } + return model.Safe().Ctx(ctx) } // Transaction wraps the transaction logic using function f. -// It rollbacks the transaction and returns the error from function f if it returns non-nil error. +// It rolls back the transaction and returns the error if function f returns a non-nil error. // It commits the transaction and returns nil if function f returns nil. // -// Note that, you should not Commit or Rollback the transaction in function f +// Note: Do not commit or roll back the transaction in function f, // as it is automatically handled by this function. func (dao *EpicGvgDefenseTeamsDao) Transaction(ctx context.Context, f func(ctx context.Context, tx gdb.TX) error) (err error) { return dao.Ctx(ctx).Transaction(ctx, f) diff --git a/internal/dao/internal/epic_hero_info.go b/internal/dao/internal/epic_hero_info.go index 3738a80..dc1f96d 100644 --- a/internal/dao/internal/epic_hero_info.go +++ b/internal/dao/internal/epic_hero_info.go @@ -11,14 +11,15 @@ import ( "github.com/gogf/gf/v2/frame/g" ) -// EpicHeroInfoDao is the data access object for table epic_hero_info. +// EpicHeroInfoDao is the data access object for the table epic_hero_info. type EpicHeroInfoDao struct { - table string // table is the underlying table name of the DAO. - group string // group is the database configuration group name of current DAO. - columns EpicHeroInfoColumns // columns contains all the column names of Table for convenient usage. + table string // table is the underlying table name of the DAO. + group string // group is the database configuration group name of the current DAO. + columns EpicHeroInfoColumns // columns contains all the column names of Table for convenient usage. + handlers []gdb.ModelHandler // handlers for customized model modification. } -// EpicHeroInfoColumns defines and stores column names for table epic_hero_info. +// EpicHeroInfoColumns defines and stores column names for the table epic_hero_info. type EpicHeroInfoColumns struct { Id string // 文件编号 HeroName string // 配置编号 @@ -41,7 +42,7 @@ type EpicHeroInfoColumns struct { SetUpdateTime string // 配装更新时间 } -// epicHeroInfoColumns holds the columns for table epic_hero_info. +// epicHeroInfoColumns holds the columns for the table epic_hero_info. var epicHeroInfoColumns = EpicHeroInfoColumns{ Id: "id", HeroName: "hero_name", @@ -65,44 +66,49 @@ var epicHeroInfoColumns = EpicHeroInfoColumns{ } // NewEpicHeroInfoDao creates and returns a new DAO object for table data access. -func NewEpicHeroInfoDao() *EpicHeroInfoDao { +func NewEpicHeroInfoDao(handlers ...gdb.ModelHandler) *EpicHeroInfoDao { return &EpicHeroInfoDao{ - group: "default", - table: "epic_hero_info", - columns: epicHeroInfoColumns, + group: "default", + table: "epic_hero_info", + columns: epicHeroInfoColumns, + handlers: handlers, } } -// DB retrieves and returns the underlying raw database management object of current DAO. +// DB retrieves and returns the underlying raw database management object of the current DAO. func (dao *EpicHeroInfoDao) DB() gdb.DB { return g.DB(dao.group) } -// Table returns the table name of current dao. +// Table returns the table name of the current DAO. func (dao *EpicHeroInfoDao) Table() string { return dao.table } -// Columns returns all column names of current dao. +// Columns returns all column names of the current DAO. func (dao *EpicHeroInfoDao) Columns() EpicHeroInfoColumns { return dao.columns } -// Group returns the configuration group name of database of current dao. +// Group returns the database configuration group name of the current DAO. func (dao *EpicHeroInfoDao) Group() string { return dao.group } -// Ctx creates and returns the Model for current DAO, It automatically sets the context for current operation. +// Ctx creates and returns a Model for the current DAO. It automatically sets the context for the current operation. func (dao *EpicHeroInfoDao) Ctx(ctx context.Context) *gdb.Model { - return dao.DB().Model(dao.table).Safe().Ctx(ctx) + model := dao.DB().Model(dao.table) + for _, handler := range dao.handlers { + model = handler(model) + } + return model.Safe().Ctx(ctx) } // Transaction wraps the transaction logic using function f. -// It rollbacks the transaction and returns the error from function f if it returns non-nil error. +// It rolls back the transaction and returns the error if function f returns a non-nil error. // It commits the transaction and returns nil if function f returns nil. // -// Note that, you should not Commit or Rollback the transaction in function f +// Note: Do not commit or roll back the transaction in function f, // as it is automatically handled by this function. func (dao *EpicHeroInfoDao) Transaction(ctx context.Context, f func(ctx context.Context, tx gdb.TX) error) (err error) { return dao.Ctx(ctx).Transaction(ctx, f) diff --git a/internal/dao/internal/epic_hero_user_build.go b/internal/dao/internal/epic_hero_user_build.go index de47130..618b697 100644 --- a/internal/dao/internal/epic_hero_user_build.go +++ b/internal/dao/internal/epic_hero_user_build.go @@ -11,14 +11,15 @@ import ( "github.com/gogf/gf/v2/frame/g" ) -// EpicHeroUserBuildDao is the data access object for table epic_hero_user_build. +// EpicHeroUserBuildDao is the data access object for the table epic_hero_user_build. type EpicHeroUserBuildDao struct { - table string // table is the underlying table name of the DAO. - group string // group is the database configuration group name of current DAO. - columns EpicHeroUserBuildColumns // columns contains all the column names of Table for convenient usage. + table string // table is the underlying table name of the DAO. + group string // group is the database configuration group name of the current DAO. + columns EpicHeroUserBuildColumns // columns contains all the column names of Table for convenient usage. + handlers []gdb.ModelHandler // handlers for customized model modification. } -// EpicHeroUserBuildColumns defines and stores column names for table epic_hero_user_build. +// EpicHeroUserBuildColumns defines and stores column names for the table epic_hero_user_build. type EpicHeroUserBuildColumns struct { Id string // 文件编号 ArtifactCode string // 配置编号 @@ -33,7 +34,7 @@ type EpicHeroUserBuildColumns struct { Deleted string // 是否删除 } -// epicHeroUserBuildColumns holds the columns for table epic_hero_user_build. +// epicHeroUserBuildColumns holds the columns for the table epic_hero_user_build. var epicHeroUserBuildColumns = EpicHeroUserBuildColumns{ Id: "id", ArtifactCode: "artifact_code", @@ -49,44 +50,49 @@ var epicHeroUserBuildColumns = EpicHeroUserBuildColumns{ } // NewEpicHeroUserBuildDao creates and returns a new DAO object for table data access. -func NewEpicHeroUserBuildDao() *EpicHeroUserBuildDao { +func NewEpicHeroUserBuildDao(handlers ...gdb.ModelHandler) *EpicHeroUserBuildDao { return &EpicHeroUserBuildDao{ - group: "default", - table: "epic_hero_user_build", - columns: epicHeroUserBuildColumns, + group: "default", + table: "epic_hero_user_build", + columns: epicHeroUserBuildColumns, + handlers: handlers, } } -// DB retrieves and returns the underlying raw database management object of current DAO. +// DB retrieves and returns the underlying raw database management object of the current DAO. func (dao *EpicHeroUserBuildDao) DB() gdb.DB { return g.DB(dao.group) } -// Table returns the table name of current dao. +// Table returns the table name of the current DAO. func (dao *EpicHeroUserBuildDao) Table() string { return dao.table } -// Columns returns all column names of current dao. +// Columns returns all column names of the current DAO. func (dao *EpicHeroUserBuildDao) Columns() EpicHeroUserBuildColumns { return dao.columns } -// Group returns the configuration group name of database of current dao. +// Group returns the database configuration group name of the current DAO. func (dao *EpicHeroUserBuildDao) Group() string { return dao.group } -// Ctx creates and returns the Model for current DAO, It automatically sets the context for current operation. +// Ctx creates and returns a Model for the current DAO. It automatically sets the context for the current operation. func (dao *EpicHeroUserBuildDao) Ctx(ctx context.Context) *gdb.Model { - return dao.DB().Model(dao.table).Safe().Ctx(ctx) + model := dao.DB().Model(dao.table) + for _, handler := range dao.handlers { + model = handler(model) + } + return model.Safe().Ctx(ctx) } // Transaction wraps the transaction logic using function f. -// It rollbacks the transaction and returns the error from function f if it returns non-nil error. +// It rolls back the transaction and returns the error if function f returns a non-nil error. // It commits the transaction and returns nil if function f returns nil. // -// Note that, you should not Commit or Rollback the transaction in function f +// Note: Do not commit or roll back the transaction in function f, // as it is automatically handled by this function. func (dao *EpicHeroUserBuildDao) Transaction(ctx context.Context, f func(ctx context.Context, tx gdb.TX) error) (err error) { return dao.Ctx(ctx).Transaction(ctx, f) diff --git a/internal/dao/internal/epic_i_18_n_mappings.go b/internal/dao/internal/epic_i_18_n_mappings.go index 444cfc2..26fbc3e 100644 --- a/internal/dao/internal/epic_i_18_n_mappings.go +++ b/internal/dao/internal/epic_i_18_n_mappings.go @@ -11,14 +11,15 @@ import ( "github.com/gogf/gf/v2/frame/g" ) -// EpicI18NMappingsDao is the data access object for table epic_i18n_mappings. +// EpicI18NMappingsDao is the data access object for the table epic_i18n_mappings. type EpicI18NMappingsDao struct { - table string // table is the underlying table name of the DAO. - group string // group is the database configuration group name of current DAO. - columns EpicI18NMappingsColumns // columns contains all the column names of Table for convenient usage. + table string // table is the underlying table name of the DAO. + group string // group is the database configuration group name of the current DAO. + columns EpicI18NMappingsColumns // columns contains all the column names of Table for convenient usage. + handlers []gdb.ModelHandler // handlers for customized model modification. } -// EpicI18NMappingsColumns defines and stores column names for table epic_i18n_mappings. +// EpicI18NMappingsColumns defines and stores column names for the table epic_i18n_mappings. type EpicI18NMappingsColumns struct { Id string // 主键ID KeyName string // 英文key @@ -31,9 +32,10 @@ type EpicI18NMappingsColumns struct { Updater string // 更新者 UpdateTime string // 更新时间 Deleted string // 是否删除 + Code string // 编码 } -// epicI18NMappingsColumns holds the columns for table epic_i18n_mappings. +// epicI18NMappingsColumns holds the columns for the table epic_i18n_mappings. var epicI18NMappingsColumns = EpicI18NMappingsColumns{ Id: "id", KeyName: "key_name", @@ -46,47 +48,53 @@ var epicI18NMappingsColumns = EpicI18NMappingsColumns{ Updater: "updater", UpdateTime: "update_time", Deleted: "deleted", + Code: "code", } // NewEpicI18NMappingsDao creates and returns a new DAO object for table data access. -func NewEpicI18NMappingsDao() *EpicI18NMappingsDao { +func NewEpicI18NMappingsDao(handlers ...gdb.ModelHandler) *EpicI18NMappingsDao { return &EpicI18NMappingsDao{ - group: "default", - table: "epic_i18n_mappings", - columns: epicI18NMappingsColumns, + group: "default", + table: "epic_i18n_mappings", + columns: epicI18NMappingsColumns, + handlers: handlers, } } -// DB retrieves and returns the underlying raw database management object of current DAO. +// DB retrieves and returns the underlying raw database management object of the current DAO. func (dao *EpicI18NMappingsDao) DB() gdb.DB { return g.DB(dao.group) } -// Table returns the table name of current dao. +// Table returns the table name of the current DAO. func (dao *EpicI18NMappingsDao) Table() string { return dao.table } -// Columns returns all column names of current dao. +// Columns returns all column names of the current DAO. func (dao *EpicI18NMappingsDao) Columns() EpicI18NMappingsColumns { return dao.columns } -// Group returns the configuration group name of database of current dao. +// Group returns the database configuration group name of the current DAO. func (dao *EpicI18NMappingsDao) Group() string { return dao.group } -// Ctx creates and returns the Model for current DAO, It automatically sets the context for current operation. +// Ctx creates and returns a Model for the current DAO. It automatically sets the context for the current operation. func (dao *EpicI18NMappingsDao) Ctx(ctx context.Context) *gdb.Model { - return dao.DB().Model(dao.table).Safe().Ctx(ctx) + model := dao.DB().Model(dao.table) + for _, handler := range dao.handlers { + model = handler(model) + } + return model.Safe().Ctx(ctx) } // Transaction wraps the transaction logic using function f. -// It rollbacks the transaction and returns the error from function f if it returns non-nil error. +// It rolls back the transaction and returns the error if function f returns a non-nil error. // It commits the transaction and returns nil if function f returns nil. // -// Note that, you should not Commit or Rollback the transaction in function f +// Note: Do not commit or roll back the transaction in function f, // as it is automatically handled by this function. func (dao *EpicI18NMappingsDao) Transaction(ctx context.Context, f func(ctx context.Context, tx gdb.TX) error) (err error) { return dao.Ctx(ctx).Transaction(ctx, f) diff --git a/internal/dao/internal/fribble_hero_set.go b/internal/dao/internal/fribble_hero_set.go index 5b120de..8366b9a 100644 --- a/internal/dao/internal/fribble_hero_set.go +++ b/internal/dao/internal/fribble_hero_set.go @@ -11,14 +11,15 @@ import ( "github.com/gogf/gf/v2/frame/g" ) -// FribbleHeroSetDao is the data access object for table fribble_hero_set. +// FribbleHeroSetDao is the data access object for the table fribble_hero_set. type FribbleHeroSetDao struct { - table string // table is the underlying table name of the DAO. - group string // group is the database configuration group name of current DAO. - columns FribbleHeroSetColumns // columns contains all the column names of Table for convenient usage. + table string // table is the underlying table name of the DAO. + group string // group is the database configuration group name of the current DAO. + columns FribbleHeroSetColumns // columns contains all the column names of Table for convenient usage. + handlers []gdb.ModelHandler // handlers for customized model modification. } -// FribbleHeroSetColumns defines and stores column names for table fribble_hero_set. +// FribbleHeroSetColumns defines and stores column names for the table fribble_hero_set. type FribbleHeroSetColumns struct { Id string // 文件编号 HeroCode string // 配置编号 @@ -32,7 +33,7 @@ type FribbleHeroSetColumns struct { SuccessGet string // } -// fribbleHeroSetColumns holds the columns for table fribble_hero_set. +// fribbleHeroSetColumns holds the columns for the table fribble_hero_set. var fribbleHeroSetColumns = FribbleHeroSetColumns{ Id: "id", HeroCode: "hero_code", @@ -47,44 +48,49 @@ var fribbleHeroSetColumns = FribbleHeroSetColumns{ } // NewFribbleHeroSetDao creates and returns a new DAO object for table data access. -func NewFribbleHeroSetDao() *FribbleHeroSetDao { +func NewFribbleHeroSetDao(handlers ...gdb.ModelHandler) *FribbleHeroSetDao { return &FribbleHeroSetDao{ - group: "default", - table: "fribble_hero_set", - columns: fribbleHeroSetColumns, + group: "default", + table: "fribble_hero_set", + columns: fribbleHeroSetColumns, + handlers: handlers, } } -// DB retrieves and returns the underlying raw database management object of current DAO. +// DB retrieves and returns the underlying raw database management object of the current DAO. func (dao *FribbleHeroSetDao) DB() gdb.DB { return g.DB(dao.group) } -// Table returns the table name of current dao. +// Table returns the table name of the current DAO. func (dao *FribbleHeroSetDao) Table() string { return dao.table } -// Columns returns all column names of current dao. +// Columns returns all column names of the current DAO. func (dao *FribbleHeroSetDao) Columns() FribbleHeroSetColumns { return dao.columns } -// Group returns the configuration group name of database of current dao. +// Group returns the database configuration group name of the current DAO. func (dao *FribbleHeroSetDao) Group() string { return dao.group } -// Ctx creates and returns the Model for current DAO, It automatically sets the context for current operation. +// Ctx creates and returns a Model for the current DAO. It automatically sets the context for the current operation. func (dao *FribbleHeroSetDao) Ctx(ctx context.Context) *gdb.Model { - return dao.DB().Model(dao.table).Safe().Ctx(ctx) + model := dao.DB().Model(dao.table) + for _, handler := range dao.handlers { + model = handler(model) + } + return model.Safe().Ctx(ctx) } // Transaction wraps the transaction logic using function f. -// It rollbacks the transaction and returns the error from function f if it returns non-nil error. +// It rolls back the transaction and returns the error if function f returns a non-nil error. // It commits the transaction and returns nil if function f returns nil. // -// Note that, you should not Commit or Rollback the transaction in function f +// Note: Do not commit or roll back the transaction in function f, // as it is automatically handled by this function. func (dao *FribbleHeroSetDao) Transaction(ctx context.Context, f func(ctx context.Context, tx gdb.TX) error) (err error) { return dao.Ctx(ctx).Transaction(ctx, f) diff --git a/internal/dao/internal/gear_set_info.go b/internal/dao/internal/gear_set_info.go index 17ce58d..ac1b652 100644 --- a/internal/dao/internal/gear_set_info.go +++ b/internal/dao/internal/gear_set_info.go @@ -11,14 +11,15 @@ import ( "github.com/gogf/gf/v2/frame/g" ) -// GearSetInfoDao is the data access object for table gear_set_info. +// GearSetInfoDao is the data access object for the table gear_set_info. type GearSetInfoDao struct { - table string // table is the underlying table name of the DAO. - group string // group is the database configuration group name of current DAO. - columns GearSetInfoColumns // columns contains all the column names of Table for convenient usage. + table string // table is the underlying table name of the DAO. + group string // group is the database configuration group name of the current DAO. + columns GearSetInfoColumns // columns contains all the column names of Table for convenient usage. + handlers []gdb.ModelHandler // handlers for customized model modification. } -// GearSetInfoColumns defines and stores column names for table gear_set_info. +// GearSetInfoColumns defines and stores column names for the table gear_set_info. type GearSetInfoColumns struct { Id string // 装备ID Level string // 装备等级 @@ -45,7 +46,7 @@ type GearSetInfoColumns struct { TenantId string // 租户编号 } -// gearSetInfoColumns holds the columns for table gear_set_info. +// gearSetInfoColumns holds the columns for the table gear_set_info. var gearSetInfoColumns = GearSetInfoColumns{ Id: "id", Level: "level", @@ -73,44 +74,49 @@ var gearSetInfoColumns = GearSetInfoColumns{ } // NewGearSetInfoDao creates and returns a new DAO object for table data access. -func NewGearSetInfoDao() *GearSetInfoDao { +func NewGearSetInfoDao(handlers ...gdb.ModelHandler) *GearSetInfoDao { return &GearSetInfoDao{ - group: "default", - table: "gear_set_info", - columns: gearSetInfoColumns, + group: "default", + table: "gear_set_info", + columns: gearSetInfoColumns, + handlers: handlers, } } -// DB retrieves and returns the underlying raw database management object of current DAO. +// DB retrieves and returns the underlying raw database management object of the current DAO. func (dao *GearSetInfoDao) DB() gdb.DB { return g.DB(dao.group) } -// Table returns the table name of current dao. +// Table returns the table name of the current DAO. func (dao *GearSetInfoDao) Table() string { return dao.table } -// Columns returns all column names of current dao. +// Columns returns all column names of the current DAO. func (dao *GearSetInfoDao) Columns() GearSetInfoColumns { return dao.columns } -// Group returns the configuration group name of database of current dao. +// Group returns the database configuration group name of the current DAO. func (dao *GearSetInfoDao) Group() string { return dao.group } -// Ctx creates and returns the Model for current DAO, It automatically sets the context for current operation. +// Ctx creates and returns a Model for the current DAO. It automatically sets the context for the current operation. func (dao *GearSetInfoDao) Ctx(ctx context.Context) *gdb.Model { - return dao.DB().Model(dao.table).Safe().Ctx(ctx) + model := dao.DB().Model(dao.table) + for _, handler := range dao.handlers { + model = handler(model) + } + return model.Safe().Ctx(ctx) } // Transaction wraps the transaction logic using function f. -// It rollbacks the transaction and returns the error from function f if it returns non-nil error. +// It rolls back the transaction and returns the error if function f returns a non-nil error. // It commits the transaction and returns nil if function f returns nil. // -// Note that, you should not Commit or Rollback the transaction in function f +// Note: Do not commit or roll back the transaction in function f, // as it is automatically handled by this function. func (dao *GearSetInfoDao) Transaction(ctx context.Context, f func(ctx context.Context, tx gdb.TX) error) (err error) { return dao.Ctx(ctx).Transaction(ctx, f) diff --git a/internal/dao/internal/infra_api_access_log.go b/internal/dao/internal/infra_api_access_log.go index d4a60bc..97240c1 100644 --- a/internal/dao/internal/infra_api_access_log.go +++ b/internal/dao/internal/infra_api_access_log.go @@ -11,14 +11,15 @@ import ( "github.com/gogf/gf/v2/frame/g" ) -// InfraApiAccessLogDao is the data access object for table infra_api_access_log. +// InfraApiAccessLogDao is the data access object for the table infra_api_access_log. type InfraApiAccessLogDao struct { - table string // table is the underlying table name of the DAO. - group string // group is the database configuration group name of current DAO. - columns InfraApiAccessLogColumns // columns contains all the column names of Table for convenient usage. + table string // table is the underlying table name of the DAO. + group string // group is the database configuration group name of the current DAO. + columns InfraApiAccessLogColumns // columns contains all the column names of Table for convenient usage. + handlers []gdb.ModelHandler // handlers for customized model modification. } -// InfraApiAccessLogColumns defines and stores column names for table infra_api_access_log. +// InfraApiAccessLogColumns defines and stores column names for the table infra_api_access_log. type InfraApiAccessLogColumns struct { Id string // 日志主键 TraceId string // 链路追踪编号 @@ -47,7 +48,7 @@ type InfraApiAccessLogColumns struct { TenantId string // 租户编号 } -// infraApiAccessLogColumns holds the columns for table infra_api_access_log. +// infraApiAccessLogColumns holds the columns for the table infra_api_access_log. var infraApiAccessLogColumns = InfraApiAccessLogColumns{ Id: "id", TraceId: "trace_id", @@ -77,44 +78,49 @@ var infraApiAccessLogColumns = InfraApiAccessLogColumns{ } // NewInfraApiAccessLogDao creates and returns a new DAO object for table data access. -func NewInfraApiAccessLogDao() *InfraApiAccessLogDao { +func NewInfraApiAccessLogDao(handlers ...gdb.ModelHandler) *InfraApiAccessLogDao { return &InfraApiAccessLogDao{ - group: "default", - table: "infra_api_access_log", - columns: infraApiAccessLogColumns, + group: "default", + table: "infra_api_access_log", + columns: infraApiAccessLogColumns, + handlers: handlers, } } -// DB retrieves and returns the underlying raw database management object of current DAO. +// DB retrieves and returns the underlying raw database management object of the current DAO. func (dao *InfraApiAccessLogDao) DB() gdb.DB { return g.DB(dao.group) } -// Table returns the table name of current dao. +// Table returns the table name of the current DAO. func (dao *InfraApiAccessLogDao) Table() string { return dao.table } -// Columns returns all column names of current dao. +// Columns returns all column names of the current DAO. func (dao *InfraApiAccessLogDao) Columns() InfraApiAccessLogColumns { return dao.columns } -// Group returns the configuration group name of database of current dao. +// Group returns the database configuration group name of the current DAO. func (dao *InfraApiAccessLogDao) Group() string { return dao.group } -// Ctx creates and returns the Model for current DAO, It automatically sets the context for current operation. +// Ctx creates and returns a Model for the current DAO. It automatically sets the context for the current operation. func (dao *InfraApiAccessLogDao) Ctx(ctx context.Context) *gdb.Model { - return dao.DB().Model(dao.table).Safe().Ctx(ctx) + model := dao.DB().Model(dao.table) + for _, handler := range dao.handlers { + model = handler(model) + } + return model.Safe().Ctx(ctx) } // Transaction wraps the transaction logic using function f. -// It rollbacks the transaction and returns the error from function f if it returns non-nil error. +// It rolls back the transaction and returns the error if function f returns a non-nil error. // It commits the transaction and returns nil if function f returns nil. // -// Note that, you should not Commit or Rollback the transaction in function f +// Note: Do not commit or roll back the transaction in function f, // as it is automatically handled by this function. func (dao *InfraApiAccessLogDao) Transaction(ctx context.Context, f func(ctx context.Context, tx gdb.TX) error) (err error) { return dao.Ctx(ctx).Transaction(ctx, f) diff --git a/internal/dao/internal/infra_api_error_log.go b/internal/dao/internal/infra_api_error_log.go index c301137..9bf8920 100644 --- a/internal/dao/internal/infra_api_error_log.go +++ b/internal/dao/internal/infra_api_error_log.go @@ -11,14 +11,15 @@ import ( "github.com/gogf/gf/v2/frame/g" ) -// InfraApiErrorLogDao is the data access object for table infra_api_error_log. +// InfraApiErrorLogDao is the data access object for the table infra_api_error_log. type InfraApiErrorLogDao struct { - table string // table is the underlying table name of the DAO. - group string // group is the database configuration group name of current DAO. - columns InfraApiErrorLogColumns // columns contains all the column names of Table for convenient usage. + table string // table is the underlying table name of the DAO. + group string // group is the database configuration group name of the current DAO. + columns InfraApiErrorLogColumns // columns contains all the column names of Table for convenient usage. + handlers []gdb.ModelHandler // handlers for customized model modification. } -// InfraApiErrorLogColumns defines and stores column names for table infra_api_error_log. +// InfraApiErrorLogColumns defines and stores column names for the table infra_api_error_log. type InfraApiErrorLogColumns struct { Id string // 编号 TraceId string // 链路追踪编号 @@ -50,7 +51,7 @@ type InfraApiErrorLogColumns struct { TenantId string // 租户编号 } -// infraApiErrorLogColumns holds the columns for table infra_api_error_log. +// infraApiErrorLogColumns holds the columns for the table infra_api_error_log. var infraApiErrorLogColumns = InfraApiErrorLogColumns{ Id: "id", TraceId: "trace_id", @@ -83,44 +84,49 @@ var infraApiErrorLogColumns = InfraApiErrorLogColumns{ } // NewInfraApiErrorLogDao creates and returns a new DAO object for table data access. -func NewInfraApiErrorLogDao() *InfraApiErrorLogDao { +func NewInfraApiErrorLogDao(handlers ...gdb.ModelHandler) *InfraApiErrorLogDao { return &InfraApiErrorLogDao{ - group: "default", - table: "infra_api_error_log", - columns: infraApiErrorLogColumns, + group: "default", + table: "infra_api_error_log", + columns: infraApiErrorLogColumns, + handlers: handlers, } } -// DB retrieves and returns the underlying raw database management object of current DAO. +// DB retrieves and returns the underlying raw database management object of the current DAO. func (dao *InfraApiErrorLogDao) DB() gdb.DB { return g.DB(dao.group) } -// Table returns the table name of current dao. +// Table returns the table name of the current DAO. func (dao *InfraApiErrorLogDao) Table() string { return dao.table } -// Columns returns all column names of current dao. +// Columns returns all column names of the current DAO. func (dao *InfraApiErrorLogDao) Columns() InfraApiErrorLogColumns { return dao.columns } -// Group returns the configuration group name of database of current dao. +// Group returns the database configuration group name of the current DAO. func (dao *InfraApiErrorLogDao) Group() string { return dao.group } -// Ctx creates and returns the Model for current DAO, It automatically sets the context for current operation. +// Ctx creates and returns a Model for the current DAO. It automatically sets the context for the current operation. func (dao *InfraApiErrorLogDao) Ctx(ctx context.Context) *gdb.Model { - return dao.DB().Model(dao.table).Safe().Ctx(ctx) + model := dao.DB().Model(dao.table) + for _, handler := range dao.handlers { + model = handler(model) + } + return model.Safe().Ctx(ctx) } // Transaction wraps the transaction logic using function f. -// It rollbacks the transaction and returns the error from function f if it returns non-nil error. +// It rolls back the transaction and returns the error if function f returns a non-nil error. // It commits the transaction and returns nil if function f returns nil. // -// Note that, you should not Commit or Rollback the transaction in function f +// Note: Do not commit or roll back the transaction in function f, // as it is automatically handled by this function. func (dao *InfraApiErrorLogDao) Transaction(ctx context.Context, f func(ctx context.Context, tx gdb.TX) error) (err error) { return dao.Ctx(ctx).Transaction(ctx, f) diff --git a/internal/dao/internal/infra_codegen_column.go b/internal/dao/internal/infra_codegen_column.go index 27d92f2..de2109d 100644 --- a/internal/dao/internal/infra_codegen_column.go +++ b/internal/dao/internal/infra_codegen_column.go @@ -11,14 +11,15 @@ import ( "github.com/gogf/gf/v2/frame/g" ) -// InfraCodegenColumnDao is the data access object for table infra_codegen_column. +// InfraCodegenColumnDao is the data access object for the table infra_codegen_column. type InfraCodegenColumnDao struct { - table string // table is the underlying table name of the DAO. - group string // group is the database configuration group name of current DAO. - columns InfraCodegenColumnColumns // columns contains all the column names of Table for convenient usage. + table string // table is the underlying table name of the DAO. + group string // group is the database configuration group name of the current DAO. + columns InfraCodegenColumnColumns // columns contains all the column names of Table for convenient usage. + handlers []gdb.ModelHandler // handlers for customized model modification. } -// InfraCodegenColumnColumns defines and stores column names for table infra_codegen_column. +// InfraCodegenColumnColumns defines and stores column names for the table infra_codegen_column. type InfraCodegenColumnColumns struct { Id string // 编号 TableId string // 表编号 @@ -45,7 +46,7 @@ type InfraCodegenColumnColumns struct { Deleted string // 是否删除 } -// infraCodegenColumnColumns holds the columns for table infra_codegen_column. +// infraCodegenColumnColumns holds the columns for the table infra_codegen_column. var infraCodegenColumnColumns = InfraCodegenColumnColumns{ Id: "id", TableId: "table_id", @@ -73,44 +74,49 @@ var infraCodegenColumnColumns = InfraCodegenColumnColumns{ } // NewInfraCodegenColumnDao creates and returns a new DAO object for table data access. -func NewInfraCodegenColumnDao() *InfraCodegenColumnDao { +func NewInfraCodegenColumnDao(handlers ...gdb.ModelHandler) *InfraCodegenColumnDao { return &InfraCodegenColumnDao{ - group: "default", - table: "infra_codegen_column", - columns: infraCodegenColumnColumns, + group: "default", + table: "infra_codegen_column", + columns: infraCodegenColumnColumns, + handlers: handlers, } } -// DB retrieves and returns the underlying raw database management object of current DAO. +// DB retrieves and returns the underlying raw database management object of the current DAO. func (dao *InfraCodegenColumnDao) DB() gdb.DB { return g.DB(dao.group) } -// Table returns the table name of current dao. +// Table returns the table name of the current DAO. func (dao *InfraCodegenColumnDao) Table() string { return dao.table } -// Columns returns all column names of current dao. +// Columns returns all column names of the current DAO. func (dao *InfraCodegenColumnDao) Columns() InfraCodegenColumnColumns { return dao.columns } -// Group returns the configuration group name of database of current dao. +// Group returns the database configuration group name of the current DAO. func (dao *InfraCodegenColumnDao) Group() string { return dao.group } -// Ctx creates and returns the Model for current DAO, It automatically sets the context for current operation. +// Ctx creates and returns a Model for the current DAO. It automatically sets the context for the current operation. func (dao *InfraCodegenColumnDao) Ctx(ctx context.Context) *gdb.Model { - return dao.DB().Model(dao.table).Safe().Ctx(ctx) + model := dao.DB().Model(dao.table) + for _, handler := range dao.handlers { + model = handler(model) + } + return model.Safe().Ctx(ctx) } // Transaction wraps the transaction logic using function f. -// It rollbacks the transaction and returns the error from function f if it returns non-nil error. +// It rolls back the transaction and returns the error if function f returns a non-nil error. // It commits the transaction and returns nil if function f returns nil. // -// Note that, you should not Commit or Rollback the transaction in function f +// Note: Do not commit or roll back the transaction in function f, // as it is automatically handled by this function. func (dao *InfraCodegenColumnDao) Transaction(ctx context.Context, f func(ctx context.Context, tx gdb.TX) error) (err error) { return dao.Ctx(ctx).Transaction(ctx, f) diff --git a/internal/dao/internal/infra_codegen_table.go b/internal/dao/internal/infra_codegen_table.go index 0577a5a..5940e07 100644 --- a/internal/dao/internal/infra_codegen_table.go +++ b/internal/dao/internal/infra_codegen_table.go @@ -11,14 +11,15 @@ import ( "github.com/gogf/gf/v2/frame/g" ) -// InfraCodegenTableDao is the data access object for table infra_codegen_table. +// InfraCodegenTableDao is the data access object for the table infra_codegen_table. type InfraCodegenTableDao struct { - table string // table is the underlying table name of the DAO. - group string // group is the database configuration group name of current DAO. - columns InfraCodegenTableColumns // columns contains all the column names of Table for convenient usage. + table string // table is the underlying table name of the DAO. + group string // group is the database configuration group name of the current DAO. + columns InfraCodegenTableColumns // columns contains all the column names of Table for convenient usage. + handlers []gdb.ModelHandler // handlers for customized model modification. } -// InfraCodegenTableColumns defines and stores column names for table infra_codegen_table. +// InfraCodegenTableColumns defines and stores column names for the table infra_codegen_table. type InfraCodegenTableColumns struct { Id string // 编号 DataSourceConfigId string // 数据源配置的编号 @@ -46,7 +47,7 @@ type InfraCodegenTableColumns struct { Deleted string // 是否删除 } -// infraCodegenTableColumns holds the columns for table infra_codegen_table. +// infraCodegenTableColumns holds the columns for the table infra_codegen_table. var infraCodegenTableColumns = InfraCodegenTableColumns{ Id: "id", DataSourceConfigId: "data_source_config_id", @@ -75,44 +76,49 @@ var infraCodegenTableColumns = InfraCodegenTableColumns{ } // NewInfraCodegenTableDao creates and returns a new DAO object for table data access. -func NewInfraCodegenTableDao() *InfraCodegenTableDao { +func NewInfraCodegenTableDao(handlers ...gdb.ModelHandler) *InfraCodegenTableDao { return &InfraCodegenTableDao{ - group: "default", - table: "infra_codegen_table", - columns: infraCodegenTableColumns, + group: "default", + table: "infra_codegen_table", + columns: infraCodegenTableColumns, + handlers: handlers, } } -// DB retrieves and returns the underlying raw database management object of current DAO. +// DB retrieves and returns the underlying raw database management object of the current DAO. func (dao *InfraCodegenTableDao) DB() gdb.DB { return g.DB(dao.group) } -// Table returns the table name of current dao. +// Table returns the table name of the current DAO. func (dao *InfraCodegenTableDao) Table() string { return dao.table } -// Columns returns all column names of current dao. +// Columns returns all column names of the current DAO. func (dao *InfraCodegenTableDao) Columns() InfraCodegenTableColumns { return dao.columns } -// Group returns the configuration group name of database of current dao. +// Group returns the database configuration group name of the current DAO. func (dao *InfraCodegenTableDao) Group() string { return dao.group } -// Ctx creates and returns the Model for current DAO, It automatically sets the context for current operation. +// Ctx creates and returns a Model for the current DAO. It automatically sets the context for the current operation. func (dao *InfraCodegenTableDao) Ctx(ctx context.Context) *gdb.Model { - return dao.DB().Model(dao.table).Safe().Ctx(ctx) + model := dao.DB().Model(dao.table) + for _, handler := range dao.handlers { + model = handler(model) + } + return model.Safe().Ctx(ctx) } // Transaction wraps the transaction logic using function f. -// It rollbacks the transaction and returns the error from function f if it returns non-nil error. +// It rolls back the transaction and returns the error if function f returns a non-nil error. // It commits the transaction and returns nil if function f returns nil. // -// Note that, you should not Commit or Rollback the transaction in function f +// Note: Do not commit or roll back the transaction in function f, // as it is automatically handled by this function. func (dao *InfraCodegenTableDao) Transaction(ctx context.Context, f func(ctx context.Context, tx gdb.TX) error) (err error) { return dao.Ctx(ctx).Transaction(ctx, f) diff --git a/internal/dao/internal/infra_config.go b/internal/dao/internal/infra_config.go index 366a6a1..5cab566 100644 --- a/internal/dao/internal/infra_config.go +++ b/internal/dao/internal/infra_config.go @@ -11,14 +11,15 @@ import ( "github.com/gogf/gf/v2/frame/g" ) -// InfraConfigDao is the data access object for table infra_config. +// InfraConfigDao is the data access object for the table infra_config. type InfraConfigDao struct { - table string // table is the underlying table name of the DAO. - group string // group is the database configuration group name of current DAO. - columns InfraConfigColumns // columns contains all the column names of Table for convenient usage. + table string // table is the underlying table name of the DAO. + group string // group is the database configuration group name of the current DAO. + columns InfraConfigColumns // columns contains all the column names of Table for convenient usage. + handlers []gdb.ModelHandler // handlers for customized model modification. } -// InfraConfigColumns defines and stores column names for table infra_config. +// InfraConfigColumns defines and stores column names for the table infra_config. type InfraConfigColumns struct { Id string // 参数主键 Category string // 参数分组 @@ -35,7 +36,7 @@ type InfraConfigColumns struct { Deleted string // 是否删除 } -// infraConfigColumns holds the columns for table infra_config. +// infraConfigColumns holds the columns for the table infra_config. var infraConfigColumns = InfraConfigColumns{ Id: "id", Category: "category", @@ -53,44 +54,49 @@ var infraConfigColumns = InfraConfigColumns{ } // NewInfraConfigDao creates and returns a new DAO object for table data access. -func NewInfraConfigDao() *InfraConfigDao { +func NewInfraConfigDao(handlers ...gdb.ModelHandler) *InfraConfigDao { return &InfraConfigDao{ - group: "default", - table: "infra_config", - columns: infraConfigColumns, + group: "default", + table: "infra_config", + columns: infraConfigColumns, + handlers: handlers, } } -// DB retrieves and returns the underlying raw database management object of current DAO. +// DB retrieves and returns the underlying raw database management object of the current DAO. func (dao *InfraConfigDao) DB() gdb.DB { return g.DB(dao.group) } -// Table returns the table name of current dao. +// Table returns the table name of the current DAO. func (dao *InfraConfigDao) Table() string { return dao.table } -// Columns returns all column names of current dao. +// Columns returns all column names of the current DAO. func (dao *InfraConfigDao) Columns() InfraConfigColumns { return dao.columns } -// Group returns the configuration group name of database of current dao. +// Group returns the database configuration group name of the current DAO. func (dao *InfraConfigDao) Group() string { return dao.group } -// Ctx creates and returns the Model for current DAO, It automatically sets the context for current operation. +// Ctx creates and returns a Model for the current DAO. It automatically sets the context for the current operation. func (dao *InfraConfigDao) Ctx(ctx context.Context) *gdb.Model { - return dao.DB().Model(dao.table).Safe().Ctx(ctx) + model := dao.DB().Model(dao.table) + for _, handler := range dao.handlers { + model = handler(model) + } + return model.Safe().Ctx(ctx) } // Transaction wraps the transaction logic using function f. -// It rollbacks the transaction and returns the error from function f if it returns non-nil error. +// It rolls back the transaction and returns the error if function f returns a non-nil error. // It commits the transaction and returns nil if function f returns nil. // -// Note that, you should not Commit or Rollback the transaction in function f +// Note: Do not commit or roll back the transaction in function f, // as it is automatically handled by this function. func (dao *InfraConfigDao) Transaction(ctx context.Context, f func(ctx context.Context, tx gdb.TX) error) (err error) { return dao.Ctx(ctx).Transaction(ctx, f) diff --git a/internal/dao/internal/infra_data_source_config.go b/internal/dao/internal/infra_data_source_config.go index b16cdfd..9e7ebb4 100644 --- a/internal/dao/internal/infra_data_source_config.go +++ b/internal/dao/internal/infra_data_source_config.go @@ -11,14 +11,15 @@ import ( "github.com/gogf/gf/v2/frame/g" ) -// InfraDataSourceConfigDao is the data access object for table infra_data_source_config. +// InfraDataSourceConfigDao is the data access object for the table infra_data_source_config. type InfraDataSourceConfigDao struct { - table string // table is the underlying table name of the DAO. - group string // group is the database configuration group name of current DAO. - columns InfraDataSourceConfigColumns // columns contains all the column names of Table for convenient usage. + table string // table is the underlying table name of the DAO. + group string // group is the database configuration group name of the current DAO. + columns InfraDataSourceConfigColumns // columns contains all the column names of Table for convenient usage. + handlers []gdb.ModelHandler // handlers for customized model modification. } -// InfraDataSourceConfigColumns defines and stores column names for table infra_data_source_config. +// InfraDataSourceConfigColumns defines and stores column names for the table infra_data_source_config. type InfraDataSourceConfigColumns struct { Id string // 主键编号 Name string // 参数名称 @@ -32,7 +33,7 @@ type InfraDataSourceConfigColumns struct { Deleted string // 是否删除 } -// infraDataSourceConfigColumns holds the columns for table infra_data_source_config. +// infraDataSourceConfigColumns holds the columns for the table infra_data_source_config. var infraDataSourceConfigColumns = InfraDataSourceConfigColumns{ Id: "id", Name: "name", @@ -47,44 +48,49 @@ var infraDataSourceConfigColumns = InfraDataSourceConfigColumns{ } // NewInfraDataSourceConfigDao creates and returns a new DAO object for table data access. -func NewInfraDataSourceConfigDao() *InfraDataSourceConfigDao { +func NewInfraDataSourceConfigDao(handlers ...gdb.ModelHandler) *InfraDataSourceConfigDao { return &InfraDataSourceConfigDao{ - group: "default", - table: "infra_data_source_config", - columns: infraDataSourceConfigColumns, + group: "default", + table: "infra_data_source_config", + columns: infraDataSourceConfigColumns, + handlers: handlers, } } -// DB retrieves and returns the underlying raw database management object of current DAO. +// DB retrieves and returns the underlying raw database management object of the current DAO. func (dao *InfraDataSourceConfigDao) DB() gdb.DB { return g.DB(dao.group) } -// Table returns the table name of current dao. +// Table returns the table name of the current DAO. func (dao *InfraDataSourceConfigDao) Table() string { return dao.table } -// Columns returns all column names of current dao. +// Columns returns all column names of the current DAO. func (dao *InfraDataSourceConfigDao) Columns() InfraDataSourceConfigColumns { return dao.columns } -// Group returns the configuration group name of database of current dao. +// Group returns the database configuration group name of the current DAO. func (dao *InfraDataSourceConfigDao) Group() string { return dao.group } -// Ctx creates and returns the Model for current DAO, It automatically sets the context for current operation. +// Ctx creates and returns a Model for the current DAO. It automatically sets the context for the current operation. func (dao *InfraDataSourceConfigDao) Ctx(ctx context.Context) *gdb.Model { - return dao.DB().Model(dao.table).Safe().Ctx(ctx) + model := dao.DB().Model(dao.table) + for _, handler := range dao.handlers { + model = handler(model) + } + return model.Safe().Ctx(ctx) } // Transaction wraps the transaction logic using function f. -// It rollbacks the transaction and returns the error from function f if it returns non-nil error. +// It rolls back the transaction and returns the error if function f returns a non-nil error. // It commits the transaction and returns nil if function f returns nil. // -// Note that, you should not Commit or Rollback the transaction in function f +// Note: Do not commit or roll back the transaction in function f, // as it is automatically handled by this function. func (dao *InfraDataSourceConfigDao) Transaction(ctx context.Context, f func(ctx context.Context, tx gdb.TX) error) (err error) { return dao.Ctx(ctx).Transaction(ctx, f) diff --git a/internal/dao/internal/infra_file.go b/internal/dao/internal/infra_file.go index 4110dc9..52d2450 100644 --- a/internal/dao/internal/infra_file.go +++ b/internal/dao/internal/infra_file.go @@ -11,14 +11,15 @@ import ( "github.com/gogf/gf/v2/frame/g" ) -// InfraFileDao is the data access object for table infra_file. +// InfraFileDao is the data access object for the table infra_file. type InfraFileDao struct { - table string // table is the underlying table name of the DAO. - group string // group is the database configuration group name of current DAO. - columns InfraFileColumns // columns contains all the column names of Table for convenient usage. + table string // table is the underlying table name of the DAO. + group string // group is the database configuration group name of the current DAO. + columns InfraFileColumns // columns contains all the column names of Table for convenient usage. + handlers []gdb.ModelHandler // handlers for customized model modification. } -// InfraFileColumns defines and stores column names for table infra_file. +// InfraFileColumns defines and stores column names for the table infra_file. type InfraFileColumns struct { Id string // 文件编号 ConfigId string // 配置编号 @@ -34,7 +35,7 @@ type InfraFileColumns struct { Deleted string // 是否删除 } -// infraFileColumns holds the columns for table infra_file. +// infraFileColumns holds the columns for the table infra_file. var infraFileColumns = InfraFileColumns{ Id: "id", ConfigId: "config_id", @@ -51,44 +52,49 @@ var infraFileColumns = InfraFileColumns{ } // NewInfraFileDao creates and returns a new DAO object for table data access. -func NewInfraFileDao() *InfraFileDao { +func NewInfraFileDao(handlers ...gdb.ModelHandler) *InfraFileDao { return &InfraFileDao{ - group: "default", - table: "infra_file", - columns: infraFileColumns, + group: "default", + table: "infra_file", + columns: infraFileColumns, + handlers: handlers, } } -// DB retrieves and returns the underlying raw database management object of current DAO. +// DB retrieves and returns the underlying raw database management object of the current DAO. func (dao *InfraFileDao) DB() gdb.DB { return g.DB(dao.group) } -// Table returns the table name of current dao. +// Table returns the table name of the current DAO. func (dao *InfraFileDao) Table() string { return dao.table } -// Columns returns all column names of current dao. +// Columns returns all column names of the current DAO. func (dao *InfraFileDao) Columns() InfraFileColumns { return dao.columns } -// Group returns the configuration group name of database of current dao. +// Group returns the database configuration group name of the current DAO. func (dao *InfraFileDao) Group() string { return dao.group } -// Ctx creates and returns the Model for current DAO, It automatically sets the context for current operation. +// Ctx creates and returns a Model for the current DAO. It automatically sets the context for the current operation. func (dao *InfraFileDao) Ctx(ctx context.Context) *gdb.Model { - return dao.DB().Model(dao.table).Safe().Ctx(ctx) + model := dao.DB().Model(dao.table) + for _, handler := range dao.handlers { + model = handler(model) + } + return model.Safe().Ctx(ctx) } // Transaction wraps the transaction logic using function f. -// It rollbacks the transaction and returns the error from function f if it returns non-nil error. +// It rolls back the transaction and returns the error if function f returns a non-nil error. // It commits the transaction and returns nil if function f returns nil. // -// Note that, you should not Commit or Rollback the transaction in function f +// Note: Do not commit or roll back the transaction in function f, // as it is automatically handled by this function. func (dao *InfraFileDao) Transaction(ctx context.Context, f func(ctx context.Context, tx gdb.TX) error) (err error) { return dao.Ctx(ctx).Transaction(ctx, f) diff --git a/internal/dao/internal/infra_file_config.go b/internal/dao/internal/infra_file_config.go index 0dae19c..de216e7 100644 --- a/internal/dao/internal/infra_file_config.go +++ b/internal/dao/internal/infra_file_config.go @@ -11,14 +11,15 @@ import ( "github.com/gogf/gf/v2/frame/g" ) -// InfraFileConfigDao is the data access object for table infra_file_config. +// InfraFileConfigDao is the data access object for the table infra_file_config. type InfraFileConfigDao struct { - table string // table is the underlying table name of the DAO. - group string // group is the database configuration group name of current DAO. - columns InfraFileConfigColumns // columns contains all the column names of Table for convenient usage. + table string // table is the underlying table name of the DAO. + group string // group is the database configuration group name of the current DAO. + columns InfraFileConfigColumns // columns contains all the column names of Table for convenient usage. + handlers []gdb.ModelHandler // handlers for customized model modification. } -// InfraFileConfigColumns defines and stores column names for table infra_file_config. +// InfraFileConfigColumns defines and stores column names for the table infra_file_config. type InfraFileConfigColumns struct { Id string // 编号 Name string // 配置名 @@ -33,7 +34,7 @@ type InfraFileConfigColumns struct { Deleted string // 是否删除 } -// infraFileConfigColumns holds the columns for table infra_file_config. +// infraFileConfigColumns holds the columns for the table infra_file_config. var infraFileConfigColumns = InfraFileConfigColumns{ Id: "id", Name: "name", @@ -49,44 +50,49 @@ var infraFileConfigColumns = InfraFileConfigColumns{ } // NewInfraFileConfigDao creates and returns a new DAO object for table data access. -func NewInfraFileConfigDao() *InfraFileConfigDao { +func NewInfraFileConfigDao(handlers ...gdb.ModelHandler) *InfraFileConfigDao { return &InfraFileConfigDao{ - group: "default", - table: "infra_file_config", - columns: infraFileConfigColumns, + group: "default", + table: "infra_file_config", + columns: infraFileConfigColumns, + handlers: handlers, } } -// DB retrieves and returns the underlying raw database management object of current DAO. +// DB retrieves and returns the underlying raw database management object of the current DAO. func (dao *InfraFileConfigDao) DB() gdb.DB { return g.DB(dao.group) } -// Table returns the table name of current dao. +// Table returns the table name of the current DAO. func (dao *InfraFileConfigDao) Table() string { return dao.table } -// Columns returns all column names of current dao. +// Columns returns all column names of the current DAO. func (dao *InfraFileConfigDao) Columns() InfraFileConfigColumns { return dao.columns } -// Group returns the configuration group name of database of current dao. +// Group returns the database configuration group name of the current DAO. func (dao *InfraFileConfigDao) Group() string { return dao.group } -// Ctx creates and returns the Model for current DAO, It automatically sets the context for current operation. +// Ctx creates and returns a Model for the current DAO. It automatically sets the context for the current operation. func (dao *InfraFileConfigDao) Ctx(ctx context.Context) *gdb.Model { - return dao.DB().Model(dao.table).Safe().Ctx(ctx) + model := dao.DB().Model(dao.table) + for _, handler := range dao.handlers { + model = handler(model) + } + return model.Safe().Ctx(ctx) } // Transaction wraps the transaction logic using function f. -// It rollbacks the transaction and returns the error from function f if it returns non-nil error. +// It rolls back the transaction and returns the error if function f returns a non-nil error. // It commits the transaction and returns nil if function f returns nil. // -// Note that, you should not Commit or Rollback the transaction in function f +// Note: Do not commit or roll back the transaction in function f, // as it is automatically handled by this function. func (dao *InfraFileConfigDao) Transaction(ctx context.Context, f func(ctx context.Context, tx gdb.TX) error) (err error) { return dao.Ctx(ctx).Transaction(ctx, f) diff --git a/internal/dao/internal/infra_file_content.go b/internal/dao/internal/infra_file_content.go index b3bd7c9..60308df 100644 --- a/internal/dao/internal/infra_file_content.go +++ b/internal/dao/internal/infra_file_content.go @@ -11,14 +11,15 @@ import ( "github.com/gogf/gf/v2/frame/g" ) -// InfraFileContentDao is the data access object for table infra_file_content. +// InfraFileContentDao is the data access object for the table infra_file_content. type InfraFileContentDao struct { - table string // table is the underlying table name of the DAO. - group string // group is the database configuration group name of current DAO. - columns InfraFileContentColumns // columns contains all the column names of Table for convenient usage. + table string // table is the underlying table name of the DAO. + group string // group is the database configuration group name of the current DAO. + columns InfraFileContentColumns // columns contains all the column names of Table for convenient usage. + handlers []gdb.ModelHandler // handlers for customized model modification. } -// InfraFileContentColumns defines and stores column names for table infra_file_content. +// InfraFileContentColumns defines and stores column names for the table infra_file_content. type InfraFileContentColumns struct { Id string // 编号 ConfigId string // 配置编号 @@ -31,7 +32,7 @@ type InfraFileContentColumns struct { Deleted string // 是否删除 } -// infraFileContentColumns holds the columns for table infra_file_content. +// infraFileContentColumns holds the columns for the table infra_file_content. var infraFileContentColumns = InfraFileContentColumns{ Id: "id", ConfigId: "config_id", @@ -45,44 +46,49 @@ var infraFileContentColumns = InfraFileContentColumns{ } // NewInfraFileContentDao creates and returns a new DAO object for table data access. -func NewInfraFileContentDao() *InfraFileContentDao { +func NewInfraFileContentDao(handlers ...gdb.ModelHandler) *InfraFileContentDao { return &InfraFileContentDao{ - group: "default", - table: "infra_file_content", - columns: infraFileContentColumns, + group: "default", + table: "infra_file_content", + columns: infraFileContentColumns, + handlers: handlers, } } -// DB retrieves and returns the underlying raw database management object of current DAO. +// DB retrieves and returns the underlying raw database management object of the current DAO. func (dao *InfraFileContentDao) DB() gdb.DB { return g.DB(dao.group) } -// Table returns the table name of current dao. +// Table returns the table name of the current DAO. func (dao *InfraFileContentDao) Table() string { return dao.table } -// Columns returns all column names of current dao. +// Columns returns all column names of the current DAO. func (dao *InfraFileContentDao) Columns() InfraFileContentColumns { return dao.columns } -// Group returns the configuration group name of database of current dao. +// Group returns the database configuration group name of the current DAO. func (dao *InfraFileContentDao) Group() string { return dao.group } -// Ctx creates and returns the Model for current DAO, It automatically sets the context for current operation. +// Ctx creates and returns a Model for the current DAO. It automatically sets the context for the current operation. func (dao *InfraFileContentDao) Ctx(ctx context.Context) *gdb.Model { - return dao.DB().Model(dao.table).Safe().Ctx(ctx) + model := dao.DB().Model(dao.table) + for _, handler := range dao.handlers { + model = handler(model) + } + return model.Safe().Ctx(ctx) } // Transaction wraps the transaction logic using function f. -// It rollbacks the transaction and returns the error from function f if it returns non-nil error. +// It rolls back the transaction and returns the error if function f returns a non-nil error. // It commits the transaction and returns nil if function f returns nil. // -// Note that, you should not Commit or Rollback the transaction in function f +// Note: Do not commit or roll back the transaction in function f, // as it is automatically handled by this function. func (dao *InfraFileContentDao) Transaction(ctx context.Context, f func(ctx context.Context, tx gdb.TX) error) (err error) { return dao.Ctx(ctx).Transaction(ctx, f) diff --git a/internal/dao/internal/infra_job.go b/internal/dao/internal/infra_job.go index 7c1609a..638e969 100644 --- a/internal/dao/internal/infra_job.go +++ b/internal/dao/internal/infra_job.go @@ -11,14 +11,15 @@ import ( "github.com/gogf/gf/v2/frame/g" ) -// InfraJobDao is the data access object for table infra_job. +// InfraJobDao is the data access object for the table infra_job. type InfraJobDao struct { - table string // table is the underlying table name of the DAO. - group string // group is the database configuration group name of current DAO. - columns InfraJobColumns // columns contains all the column names of Table for convenient usage. + table string // table is the underlying table name of the DAO. + group string // group is the database configuration group name of the current DAO. + columns InfraJobColumns // columns contains all the column names of Table for convenient usage. + handlers []gdb.ModelHandler // handlers for customized model modification. } -// InfraJobColumns defines and stores column names for table infra_job. +// InfraJobColumns defines and stores column names for the table infra_job. type InfraJobColumns struct { Id string // 任务编号 Name string // 任务名称 @@ -36,7 +37,7 @@ type InfraJobColumns struct { Deleted string // 是否删除 } -// infraJobColumns holds the columns for table infra_job. +// infraJobColumns holds the columns for the table infra_job. var infraJobColumns = InfraJobColumns{ Id: "id", Name: "name", @@ -55,44 +56,49 @@ var infraJobColumns = InfraJobColumns{ } // NewInfraJobDao creates and returns a new DAO object for table data access. -func NewInfraJobDao() *InfraJobDao { +func NewInfraJobDao(handlers ...gdb.ModelHandler) *InfraJobDao { return &InfraJobDao{ - group: "default", - table: "infra_job", - columns: infraJobColumns, + group: "default", + table: "infra_job", + columns: infraJobColumns, + handlers: handlers, } } -// DB retrieves and returns the underlying raw database management object of current DAO. +// DB retrieves and returns the underlying raw database management object of the current DAO. func (dao *InfraJobDao) DB() gdb.DB { return g.DB(dao.group) } -// Table returns the table name of current dao. +// Table returns the table name of the current DAO. func (dao *InfraJobDao) Table() string { return dao.table } -// Columns returns all column names of current dao. +// Columns returns all column names of the current DAO. func (dao *InfraJobDao) Columns() InfraJobColumns { return dao.columns } -// Group returns the configuration group name of database of current dao. +// Group returns the database configuration group name of the current DAO. func (dao *InfraJobDao) Group() string { return dao.group } -// Ctx creates and returns the Model for current DAO, It automatically sets the context for current operation. +// Ctx creates and returns a Model for the current DAO. It automatically sets the context for the current operation. func (dao *InfraJobDao) Ctx(ctx context.Context) *gdb.Model { - return dao.DB().Model(dao.table).Safe().Ctx(ctx) + model := dao.DB().Model(dao.table) + for _, handler := range dao.handlers { + model = handler(model) + } + return model.Safe().Ctx(ctx) } // Transaction wraps the transaction logic using function f. -// It rollbacks the transaction and returns the error from function f if it returns non-nil error. +// It rolls back the transaction and returns the error if function f returns a non-nil error. // It commits the transaction and returns nil if function f returns nil. // -// Note that, you should not Commit or Rollback the transaction in function f +// Note: Do not commit or roll back the transaction in function f, // as it is automatically handled by this function. func (dao *InfraJobDao) Transaction(ctx context.Context, f func(ctx context.Context, tx gdb.TX) error) (err error) { return dao.Ctx(ctx).Transaction(ctx, f) diff --git a/internal/dao/internal/infra_job_log.go b/internal/dao/internal/infra_job_log.go index 5de1eb7..f745504 100644 --- a/internal/dao/internal/infra_job_log.go +++ b/internal/dao/internal/infra_job_log.go @@ -11,14 +11,15 @@ import ( "github.com/gogf/gf/v2/frame/g" ) -// InfraJobLogDao is the data access object for table infra_job_log. +// InfraJobLogDao is the data access object for the table infra_job_log. type InfraJobLogDao struct { - table string // table is the underlying table name of the DAO. - group string // group is the database configuration group name of current DAO. - columns InfraJobLogColumns // columns contains all the column names of Table for convenient usage. + table string // table is the underlying table name of the DAO. + group string // group is the database configuration group name of the current DAO. + columns InfraJobLogColumns // columns contains all the column names of Table for convenient usage. + handlers []gdb.ModelHandler // handlers for customized model modification. } -// InfraJobLogColumns defines and stores column names for table infra_job_log. +// InfraJobLogColumns defines and stores column names for the table infra_job_log. type InfraJobLogColumns struct { Id string // 日志编号 JobId string // 任务编号 @@ -37,7 +38,7 @@ type InfraJobLogColumns struct { Deleted string // 是否删除 } -// infraJobLogColumns holds the columns for table infra_job_log. +// infraJobLogColumns holds the columns for the table infra_job_log. var infraJobLogColumns = InfraJobLogColumns{ Id: "id", JobId: "job_id", @@ -57,44 +58,49 @@ var infraJobLogColumns = InfraJobLogColumns{ } // NewInfraJobLogDao creates and returns a new DAO object for table data access. -func NewInfraJobLogDao() *InfraJobLogDao { +func NewInfraJobLogDao(handlers ...gdb.ModelHandler) *InfraJobLogDao { return &InfraJobLogDao{ - group: "default", - table: "infra_job_log", - columns: infraJobLogColumns, + group: "default", + table: "infra_job_log", + columns: infraJobLogColumns, + handlers: handlers, } } -// DB retrieves and returns the underlying raw database management object of current DAO. +// DB retrieves and returns the underlying raw database management object of the current DAO. func (dao *InfraJobLogDao) DB() gdb.DB { return g.DB(dao.group) } -// Table returns the table name of current dao. +// Table returns the table name of the current DAO. func (dao *InfraJobLogDao) Table() string { return dao.table } -// Columns returns all column names of current dao. +// Columns returns all column names of the current DAO. func (dao *InfraJobLogDao) Columns() InfraJobLogColumns { return dao.columns } -// Group returns the configuration group name of database of current dao. +// Group returns the database configuration group name of the current DAO. func (dao *InfraJobLogDao) Group() string { return dao.group } -// Ctx creates and returns the Model for current DAO, It automatically sets the context for current operation. +// Ctx creates and returns a Model for the current DAO. It automatically sets the context for the current operation. func (dao *InfraJobLogDao) Ctx(ctx context.Context) *gdb.Model { - return dao.DB().Model(dao.table).Safe().Ctx(ctx) + model := dao.DB().Model(dao.table) + for _, handler := range dao.handlers { + model = handler(model) + } + return model.Safe().Ctx(ctx) } // Transaction wraps the transaction logic using function f. -// It rollbacks the transaction and returns the error from function f if it returns non-nil error. +// It rolls back the transaction and returns the error if function f returns a non-nil error. // It commits the transaction and returns nil if function f returns nil. // -// Note that, you should not Commit or Rollback the transaction in function f +// Note: Do not commit or roll back the transaction in function f, // as it is automatically handled by this function. func (dao *InfraJobLogDao) Transaction(ctx context.Context, f func(ctx context.Context, tx gdb.TX) error) (err error) { return dao.Ctx(ctx).Transaction(ctx, f) diff --git a/internal/dao/internal/qrtz_blob_triggers.go b/internal/dao/internal/qrtz_blob_triggers.go index 7bbe8f8..fd6f54d 100644 --- a/internal/dao/internal/qrtz_blob_triggers.go +++ b/internal/dao/internal/qrtz_blob_triggers.go @@ -11,14 +11,15 @@ import ( "github.com/gogf/gf/v2/frame/g" ) -// QrtzBlobTriggersDao is the data access object for table qrtz_blob_triggers. +// QrtzBlobTriggersDao is the data access object for the table qrtz_blob_triggers. type QrtzBlobTriggersDao struct { - table string // table is the underlying table name of the DAO. - group string // group is the database configuration group name of current DAO. - columns QrtzBlobTriggersColumns // columns contains all the column names of Table for convenient usage. + table string // table is the underlying table name of the DAO. + group string // group is the database configuration group name of the current DAO. + columns QrtzBlobTriggersColumns // columns contains all the column names of Table for convenient usage. + handlers []gdb.ModelHandler // handlers for customized model modification. } -// QrtzBlobTriggersColumns defines and stores column names for table qrtz_blob_triggers. +// QrtzBlobTriggersColumns defines and stores column names for the table qrtz_blob_triggers. type QrtzBlobTriggersColumns struct { SchedName string // TriggerName string // @@ -26,7 +27,7 @@ type QrtzBlobTriggersColumns struct { BlobData string // } -// qrtzBlobTriggersColumns holds the columns for table qrtz_blob_triggers. +// qrtzBlobTriggersColumns holds the columns for the table qrtz_blob_triggers. var qrtzBlobTriggersColumns = QrtzBlobTriggersColumns{ SchedName: "SCHED_NAME", TriggerName: "TRIGGER_NAME", @@ -35,44 +36,49 @@ var qrtzBlobTriggersColumns = QrtzBlobTriggersColumns{ } // NewQrtzBlobTriggersDao creates and returns a new DAO object for table data access. -func NewQrtzBlobTriggersDao() *QrtzBlobTriggersDao { +func NewQrtzBlobTriggersDao(handlers ...gdb.ModelHandler) *QrtzBlobTriggersDao { return &QrtzBlobTriggersDao{ - group: "default", - table: "qrtz_blob_triggers", - columns: qrtzBlobTriggersColumns, + group: "default", + table: "qrtz_blob_triggers", + columns: qrtzBlobTriggersColumns, + handlers: handlers, } } -// DB retrieves and returns the underlying raw database management object of current DAO. +// DB retrieves and returns the underlying raw database management object of the current DAO. func (dao *QrtzBlobTriggersDao) DB() gdb.DB { return g.DB(dao.group) } -// Table returns the table name of current dao. +// Table returns the table name of the current DAO. func (dao *QrtzBlobTriggersDao) Table() string { return dao.table } -// Columns returns all column names of current dao. +// Columns returns all column names of the current DAO. func (dao *QrtzBlobTriggersDao) Columns() QrtzBlobTriggersColumns { return dao.columns } -// Group returns the configuration group name of database of current dao. +// Group returns the database configuration group name of the current DAO. func (dao *QrtzBlobTriggersDao) Group() string { return dao.group } -// Ctx creates and returns the Model for current DAO, It automatically sets the context for current operation. +// Ctx creates and returns a Model for the current DAO. It automatically sets the context for the current operation. func (dao *QrtzBlobTriggersDao) Ctx(ctx context.Context) *gdb.Model { - return dao.DB().Model(dao.table).Safe().Ctx(ctx) + model := dao.DB().Model(dao.table) + for _, handler := range dao.handlers { + model = handler(model) + } + return model.Safe().Ctx(ctx) } // Transaction wraps the transaction logic using function f. -// It rollbacks the transaction and returns the error from function f if it returns non-nil error. +// It rolls back the transaction and returns the error if function f returns a non-nil error. // It commits the transaction and returns nil if function f returns nil. // -// Note that, you should not Commit or Rollback the transaction in function f +// Note: Do not commit or roll back the transaction in function f, // as it is automatically handled by this function. func (dao *QrtzBlobTriggersDao) Transaction(ctx context.Context, f func(ctx context.Context, tx gdb.TX) error) (err error) { return dao.Ctx(ctx).Transaction(ctx, f) diff --git a/internal/dao/internal/qrtz_calendars.go b/internal/dao/internal/qrtz_calendars.go index 5d729cb..4de1abf 100644 --- a/internal/dao/internal/qrtz_calendars.go +++ b/internal/dao/internal/qrtz_calendars.go @@ -11,21 +11,22 @@ import ( "github.com/gogf/gf/v2/frame/g" ) -// QrtzCalendarsDao is the data access object for table qrtz_calendars. +// QrtzCalendarsDao is the data access object for the table qrtz_calendars. type QrtzCalendarsDao struct { - table string // table is the underlying table name of the DAO. - group string // group is the database configuration group name of current DAO. - columns QrtzCalendarsColumns // columns contains all the column names of Table for convenient usage. + table string // table is the underlying table name of the DAO. + group string // group is the database configuration group name of the current DAO. + columns QrtzCalendarsColumns // columns contains all the column names of Table for convenient usage. + handlers []gdb.ModelHandler // handlers for customized model modification. } -// QrtzCalendarsColumns defines and stores column names for table qrtz_calendars. +// QrtzCalendarsColumns defines and stores column names for the table qrtz_calendars. type QrtzCalendarsColumns struct { SchedName string // CalendarName string // Calendar string // } -// qrtzCalendarsColumns holds the columns for table qrtz_calendars. +// qrtzCalendarsColumns holds the columns for the table qrtz_calendars. var qrtzCalendarsColumns = QrtzCalendarsColumns{ SchedName: "SCHED_NAME", CalendarName: "CALENDAR_NAME", @@ -33,44 +34,49 @@ var qrtzCalendarsColumns = QrtzCalendarsColumns{ } // NewQrtzCalendarsDao creates and returns a new DAO object for table data access. -func NewQrtzCalendarsDao() *QrtzCalendarsDao { +func NewQrtzCalendarsDao(handlers ...gdb.ModelHandler) *QrtzCalendarsDao { return &QrtzCalendarsDao{ - group: "default", - table: "qrtz_calendars", - columns: qrtzCalendarsColumns, + group: "default", + table: "qrtz_calendars", + columns: qrtzCalendarsColumns, + handlers: handlers, } } -// DB retrieves and returns the underlying raw database management object of current DAO. +// DB retrieves and returns the underlying raw database management object of the current DAO. func (dao *QrtzCalendarsDao) DB() gdb.DB { return g.DB(dao.group) } -// Table returns the table name of current dao. +// Table returns the table name of the current DAO. func (dao *QrtzCalendarsDao) Table() string { return dao.table } -// Columns returns all column names of current dao. +// Columns returns all column names of the current DAO. func (dao *QrtzCalendarsDao) Columns() QrtzCalendarsColumns { return dao.columns } -// Group returns the configuration group name of database of current dao. +// Group returns the database configuration group name of the current DAO. func (dao *QrtzCalendarsDao) Group() string { return dao.group } -// Ctx creates and returns the Model for current DAO, It automatically sets the context for current operation. +// Ctx creates and returns a Model for the current DAO. It automatically sets the context for the current operation. func (dao *QrtzCalendarsDao) Ctx(ctx context.Context) *gdb.Model { - return dao.DB().Model(dao.table).Safe().Ctx(ctx) + model := dao.DB().Model(dao.table) + for _, handler := range dao.handlers { + model = handler(model) + } + return model.Safe().Ctx(ctx) } // Transaction wraps the transaction logic using function f. -// It rollbacks the transaction and returns the error from function f if it returns non-nil error. +// It rolls back the transaction and returns the error if function f returns a non-nil error. // It commits the transaction and returns nil if function f returns nil. // -// Note that, you should not Commit or Rollback the transaction in function f +// Note: Do not commit or roll back the transaction in function f, // as it is automatically handled by this function. func (dao *QrtzCalendarsDao) Transaction(ctx context.Context, f func(ctx context.Context, tx gdb.TX) error) (err error) { return dao.Ctx(ctx).Transaction(ctx, f) diff --git a/internal/dao/internal/qrtz_cron_triggers.go b/internal/dao/internal/qrtz_cron_triggers.go index 45c1faa..c83e04b 100644 --- a/internal/dao/internal/qrtz_cron_triggers.go +++ b/internal/dao/internal/qrtz_cron_triggers.go @@ -11,14 +11,15 @@ import ( "github.com/gogf/gf/v2/frame/g" ) -// QrtzCronTriggersDao is the data access object for table qrtz_cron_triggers. +// QrtzCronTriggersDao is the data access object for the table qrtz_cron_triggers. type QrtzCronTriggersDao struct { - table string // table is the underlying table name of the DAO. - group string // group is the database configuration group name of current DAO. - columns QrtzCronTriggersColumns // columns contains all the column names of Table for convenient usage. + table string // table is the underlying table name of the DAO. + group string // group is the database configuration group name of the current DAO. + columns QrtzCronTriggersColumns // columns contains all the column names of Table for convenient usage. + handlers []gdb.ModelHandler // handlers for customized model modification. } -// QrtzCronTriggersColumns defines and stores column names for table qrtz_cron_triggers. +// QrtzCronTriggersColumns defines and stores column names for the table qrtz_cron_triggers. type QrtzCronTriggersColumns struct { SchedName string // TriggerName string // @@ -27,7 +28,7 @@ type QrtzCronTriggersColumns struct { TimeZoneId string // } -// qrtzCronTriggersColumns holds the columns for table qrtz_cron_triggers. +// qrtzCronTriggersColumns holds the columns for the table qrtz_cron_triggers. var qrtzCronTriggersColumns = QrtzCronTriggersColumns{ SchedName: "SCHED_NAME", TriggerName: "TRIGGER_NAME", @@ -37,44 +38,49 @@ var qrtzCronTriggersColumns = QrtzCronTriggersColumns{ } // NewQrtzCronTriggersDao creates and returns a new DAO object for table data access. -func NewQrtzCronTriggersDao() *QrtzCronTriggersDao { +func NewQrtzCronTriggersDao(handlers ...gdb.ModelHandler) *QrtzCronTriggersDao { return &QrtzCronTriggersDao{ - group: "default", - table: "qrtz_cron_triggers", - columns: qrtzCronTriggersColumns, + group: "default", + table: "qrtz_cron_triggers", + columns: qrtzCronTriggersColumns, + handlers: handlers, } } -// DB retrieves and returns the underlying raw database management object of current DAO. +// DB retrieves and returns the underlying raw database management object of the current DAO. func (dao *QrtzCronTriggersDao) DB() gdb.DB { return g.DB(dao.group) } -// Table returns the table name of current dao. +// Table returns the table name of the current DAO. func (dao *QrtzCronTriggersDao) Table() string { return dao.table } -// Columns returns all column names of current dao. +// Columns returns all column names of the current DAO. func (dao *QrtzCronTriggersDao) Columns() QrtzCronTriggersColumns { return dao.columns } -// Group returns the configuration group name of database of current dao. +// Group returns the database configuration group name of the current DAO. func (dao *QrtzCronTriggersDao) Group() string { return dao.group } -// Ctx creates and returns the Model for current DAO, It automatically sets the context for current operation. +// Ctx creates and returns a Model for the current DAO. It automatically sets the context for the current operation. func (dao *QrtzCronTriggersDao) Ctx(ctx context.Context) *gdb.Model { - return dao.DB().Model(dao.table).Safe().Ctx(ctx) + model := dao.DB().Model(dao.table) + for _, handler := range dao.handlers { + model = handler(model) + } + return model.Safe().Ctx(ctx) } // Transaction wraps the transaction logic using function f. -// It rollbacks the transaction and returns the error from function f if it returns non-nil error. +// It rolls back the transaction and returns the error if function f returns a non-nil error. // It commits the transaction and returns nil if function f returns nil. // -// Note that, you should not Commit or Rollback the transaction in function f +// Note: Do not commit or roll back the transaction in function f, // as it is automatically handled by this function. func (dao *QrtzCronTriggersDao) Transaction(ctx context.Context, f func(ctx context.Context, tx gdb.TX) error) (err error) { return dao.Ctx(ctx).Transaction(ctx, f) diff --git a/internal/dao/internal/qrtz_fired_triggers.go b/internal/dao/internal/qrtz_fired_triggers.go index 55b78b8..8b17bf2 100644 --- a/internal/dao/internal/qrtz_fired_triggers.go +++ b/internal/dao/internal/qrtz_fired_triggers.go @@ -11,14 +11,15 @@ import ( "github.com/gogf/gf/v2/frame/g" ) -// QrtzFiredTriggersDao is the data access object for table qrtz_fired_triggers. +// QrtzFiredTriggersDao is the data access object for the table qrtz_fired_triggers. type QrtzFiredTriggersDao struct { - table string // table is the underlying table name of the DAO. - group string // group is the database configuration group name of current DAO. - columns QrtzFiredTriggersColumns // columns contains all the column names of Table for convenient usage. + table string // table is the underlying table name of the DAO. + group string // group is the database configuration group name of the current DAO. + columns QrtzFiredTriggersColumns // columns contains all the column names of Table for convenient usage. + handlers []gdb.ModelHandler // handlers for customized model modification. } -// QrtzFiredTriggersColumns defines and stores column names for table qrtz_fired_triggers. +// QrtzFiredTriggersColumns defines and stores column names for the table qrtz_fired_triggers. type QrtzFiredTriggersColumns struct { SchedName string // EntryId string // @@ -35,7 +36,7 @@ type QrtzFiredTriggersColumns struct { RequestsRecovery string // } -// qrtzFiredTriggersColumns holds the columns for table qrtz_fired_triggers. +// qrtzFiredTriggersColumns holds the columns for the table qrtz_fired_triggers. var qrtzFiredTriggersColumns = QrtzFiredTriggersColumns{ SchedName: "SCHED_NAME", EntryId: "ENTRY_ID", @@ -53,44 +54,49 @@ var qrtzFiredTriggersColumns = QrtzFiredTriggersColumns{ } // NewQrtzFiredTriggersDao creates and returns a new DAO object for table data access. -func NewQrtzFiredTriggersDao() *QrtzFiredTriggersDao { +func NewQrtzFiredTriggersDao(handlers ...gdb.ModelHandler) *QrtzFiredTriggersDao { return &QrtzFiredTriggersDao{ - group: "default", - table: "qrtz_fired_triggers", - columns: qrtzFiredTriggersColumns, + group: "default", + table: "qrtz_fired_triggers", + columns: qrtzFiredTriggersColumns, + handlers: handlers, } } -// DB retrieves and returns the underlying raw database management object of current DAO. +// DB retrieves and returns the underlying raw database management object of the current DAO. func (dao *QrtzFiredTriggersDao) DB() gdb.DB { return g.DB(dao.group) } -// Table returns the table name of current dao. +// Table returns the table name of the current DAO. func (dao *QrtzFiredTriggersDao) Table() string { return dao.table } -// Columns returns all column names of current dao. +// Columns returns all column names of the current DAO. func (dao *QrtzFiredTriggersDao) Columns() QrtzFiredTriggersColumns { return dao.columns } -// Group returns the configuration group name of database of current dao. +// Group returns the database configuration group name of the current DAO. func (dao *QrtzFiredTriggersDao) Group() string { return dao.group } -// Ctx creates and returns the Model for current DAO, It automatically sets the context for current operation. +// Ctx creates and returns a Model for the current DAO. It automatically sets the context for the current operation. func (dao *QrtzFiredTriggersDao) Ctx(ctx context.Context) *gdb.Model { - return dao.DB().Model(dao.table).Safe().Ctx(ctx) + model := dao.DB().Model(dao.table) + for _, handler := range dao.handlers { + model = handler(model) + } + return model.Safe().Ctx(ctx) } // Transaction wraps the transaction logic using function f. -// It rollbacks the transaction and returns the error from function f if it returns non-nil error. +// It rolls back the transaction and returns the error if function f returns a non-nil error. // It commits the transaction and returns nil if function f returns nil. // -// Note that, you should not Commit or Rollback the transaction in function f +// Note: Do not commit or roll back the transaction in function f, // as it is automatically handled by this function. func (dao *QrtzFiredTriggersDao) Transaction(ctx context.Context, f func(ctx context.Context, tx gdb.TX) error) (err error) { return dao.Ctx(ctx).Transaction(ctx, f) diff --git a/internal/dao/internal/qrtz_job_details.go b/internal/dao/internal/qrtz_job_details.go index ada1ee9..e7de9f6 100644 --- a/internal/dao/internal/qrtz_job_details.go +++ b/internal/dao/internal/qrtz_job_details.go @@ -11,14 +11,15 @@ import ( "github.com/gogf/gf/v2/frame/g" ) -// QrtzJobDetailsDao is the data access object for table qrtz_job_details. +// QrtzJobDetailsDao is the data access object for the table qrtz_job_details. type QrtzJobDetailsDao struct { - table string // table is the underlying table name of the DAO. - group string // group is the database configuration group name of current DAO. - columns QrtzJobDetailsColumns // columns contains all the column names of Table for convenient usage. + table string // table is the underlying table name of the DAO. + group string // group is the database configuration group name of the current DAO. + columns QrtzJobDetailsColumns // columns contains all the column names of Table for convenient usage. + handlers []gdb.ModelHandler // handlers for customized model modification. } -// QrtzJobDetailsColumns defines and stores column names for table qrtz_job_details. +// QrtzJobDetailsColumns defines and stores column names for the table qrtz_job_details. type QrtzJobDetailsColumns struct { SchedName string // JobName string // @@ -32,7 +33,7 @@ type QrtzJobDetailsColumns struct { JobData string // } -// qrtzJobDetailsColumns holds the columns for table qrtz_job_details. +// qrtzJobDetailsColumns holds the columns for the table qrtz_job_details. var qrtzJobDetailsColumns = QrtzJobDetailsColumns{ SchedName: "SCHED_NAME", JobName: "JOB_NAME", @@ -47,44 +48,49 @@ var qrtzJobDetailsColumns = QrtzJobDetailsColumns{ } // NewQrtzJobDetailsDao creates and returns a new DAO object for table data access. -func NewQrtzJobDetailsDao() *QrtzJobDetailsDao { +func NewQrtzJobDetailsDao(handlers ...gdb.ModelHandler) *QrtzJobDetailsDao { return &QrtzJobDetailsDao{ - group: "default", - table: "qrtz_job_details", - columns: qrtzJobDetailsColumns, + group: "default", + table: "qrtz_job_details", + columns: qrtzJobDetailsColumns, + handlers: handlers, } } -// DB retrieves and returns the underlying raw database management object of current DAO. +// DB retrieves and returns the underlying raw database management object of the current DAO. func (dao *QrtzJobDetailsDao) DB() gdb.DB { return g.DB(dao.group) } -// Table returns the table name of current dao. +// Table returns the table name of the current DAO. func (dao *QrtzJobDetailsDao) Table() string { return dao.table } -// Columns returns all column names of current dao. +// Columns returns all column names of the current DAO. func (dao *QrtzJobDetailsDao) Columns() QrtzJobDetailsColumns { return dao.columns } -// Group returns the configuration group name of database of current dao. +// Group returns the database configuration group name of the current DAO. func (dao *QrtzJobDetailsDao) Group() string { return dao.group } -// Ctx creates and returns the Model for current DAO, It automatically sets the context for current operation. +// Ctx creates and returns a Model for the current DAO. It automatically sets the context for the current operation. func (dao *QrtzJobDetailsDao) Ctx(ctx context.Context) *gdb.Model { - return dao.DB().Model(dao.table).Safe().Ctx(ctx) + model := dao.DB().Model(dao.table) + for _, handler := range dao.handlers { + model = handler(model) + } + return model.Safe().Ctx(ctx) } // Transaction wraps the transaction logic using function f. -// It rollbacks the transaction and returns the error from function f if it returns non-nil error. +// It rolls back the transaction and returns the error if function f returns a non-nil error. // It commits the transaction and returns nil if function f returns nil. // -// Note that, you should not Commit or Rollback the transaction in function f +// Note: Do not commit or roll back the transaction in function f, // as it is automatically handled by this function. func (dao *QrtzJobDetailsDao) Transaction(ctx context.Context, f func(ctx context.Context, tx gdb.TX) error) (err error) { return dao.Ctx(ctx).Transaction(ctx, f) diff --git a/internal/dao/internal/qrtz_locks.go b/internal/dao/internal/qrtz_locks.go index b6e9b6b..7ec200e 100644 --- a/internal/dao/internal/qrtz_locks.go +++ b/internal/dao/internal/qrtz_locks.go @@ -11,64 +11,70 @@ import ( "github.com/gogf/gf/v2/frame/g" ) -// QrtzLocksDao is the data access object for table qrtz_locks. +// QrtzLocksDao is the data access object for the table qrtz_locks. type QrtzLocksDao struct { - table string // table is the underlying table name of the DAO. - group string // group is the database configuration group name of current DAO. - columns QrtzLocksColumns // columns contains all the column names of Table for convenient usage. + table string // table is the underlying table name of the DAO. + group string // group is the database configuration group name of the current DAO. + columns QrtzLocksColumns // columns contains all the column names of Table for convenient usage. + handlers []gdb.ModelHandler // handlers for customized model modification. } -// QrtzLocksColumns defines and stores column names for table qrtz_locks. +// QrtzLocksColumns defines and stores column names for the table qrtz_locks. type QrtzLocksColumns struct { SchedName string // LockName string // } -// qrtzLocksColumns holds the columns for table qrtz_locks. +// qrtzLocksColumns holds the columns for the table qrtz_locks. var qrtzLocksColumns = QrtzLocksColumns{ SchedName: "SCHED_NAME", LockName: "LOCK_NAME", } // NewQrtzLocksDao creates and returns a new DAO object for table data access. -func NewQrtzLocksDao() *QrtzLocksDao { +func NewQrtzLocksDao(handlers ...gdb.ModelHandler) *QrtzLocksDao { return &QrtzLocksDao{ - group: "default", - table: "qrtz_locks", - columns: qrtzLocksColumns, + group: "default", + table: "qrtz_locks", + columns: qrtzLocksColumns, + handlers: handlers, } } -// DB retrieves and returns the underlying raw database management object of current DAO. +// DB retrieves and returns the underlying raw database management object of the current DAO. func (dao *QrtzLocksDao) DB() gdb.DB { return g.DB(dao.group) } -// Table returns the table name of current dao. +// Table returns the table name of the current DAO. func (dao *QrtzLocksDao) Table() string { return dao.table } -// Columns returns all column names of current dao. +// Columns returns all column names of the current DAO. func (dao *QrtzLocksDao) Columns() QrtzLocksColumns { return dao.columns } -// Group returns the configuration group name of database of current dao. +// Group returns the database configuration group name of the current DAO. func (dao *QrtzLocksDao) Group() string { return dao.group } -// Ctx creates and returns the Model for current DAO, It automatically sets the context for current operation. +// Ctx creates and returns a Model for the current DAO. It automatically sets the context for the current operation. func (dao *QrtzLocksDao) Ctx(ctx context.Context) *gdb.Model { - return dao.DB().Model(dao.table).Safe().Ctx(ctx) + model := dao.DB().Model(dao.table) + for _, handler := range dao.handlers { + model = handler(model) + } + return model.Safe().Ctx(ctx) } // Transaction wraps the transaction logic using function f. -// It rollbacks the transaction and returns the error from function f if it returns non-nil error. +// It rolls back the transaction and returns the error if function f returns a non-nil error. // It commits the transaction and returns nil if function f returns nil. // -// Note that, you should not Commit or Rollback the transaction in function f +// Note: Do not commit or roll back the transaction in function f, // as it is automatically handled by this function. func (dao *QrtzLocksDao) Transaction(ctx context.Context, f func(ctx context.Context, tx gdb.TX) error) (err error) { return dao.Ctx(ctx).Transaction(ctx, f) diff --git a/internal/dao/internal/qrtz_paused_trigger_grps.go b/internal/dao/internal/qrtz_paused_trigger_grps.go index 0dae9d4..59f8307 100644 --- a/internal/dao/internal/qrtz_paused_trigger_grps.go +++ b/internal/dao/internal/qrtz_paused_trigger_grps.go @@ -11,64 +11,70 @@ import ( "github.com/gogf/gf/v2/frame/g" ) -// QrtzPausedTriggerGrpsDao is the data access object for table qrtz_paused_trigger_grps. +// QrtzPausedTriggerGrpsDao is the data access object for the table qrtz_paused_trigger_grps. type QrtzPausedTriggerGrpsDao struct { - table string // table is the underlying table name of the DAO. - group string // group is the database configuration group name of current DAO. - columns QrtzPausedTriggerGrpsColumns // columns contains all the column names of Table for convenient usage. + table string // table is the underlying table name of the DAO. + group string // group is the database configuration group name of the current DAO. + columns QrtzPausedTriggerGrpsColumns // columns contains all the column names of Table for convenient usage. + handlers []gdb.ModelHandler // handlers for customized model modification. } -// QrtzPausedTriggerGrpsColumns defines and stores column names for table qrtz_paused_trigger_grps. +// QrtzPausedTriggerGrpsColumns defines and stores column names for the table qrtz_paused_trigger_grps. type QrtzPausedTriggerGrpsColumns struct { SchedName string // TriggerGroup string // } -// qrtzPausedTriggerGrpsColumns holds the columns for table qrtz_paused_trigger_grps. +// qrtzPausedTriggerGrpsColumns holds the columns for the table qrtz_paused_trigger_grps. var qrtzPausedTriggerGrpsColumns = QrtzPausedTriggerGrpsColumns{ SchedName: "SCHED_NAME", TriggerGroup: "TRIGGER_GROUP", } // NewQrtzPausedTriggerGrpsDao creates and returns a new DAO object for table data access. -func NewQrtzPausedTriggerGrpsDao() *QrtzPausedTriggerGrpsDao { +func NewQrtzPausedTriggerGrpsDao(handlers ...gdb.ModelHandler) *QrtzPausedTriggerGrpsDao { return &QrtzPausedTriggerGrpsDao{ - group: "default", - table: "qrtz_paused_trigger_grps", - columns: qrtzPausedTriggerGrpsColumns, + group: "default", + table: "qrtz_paused_trigger_grps", + columns: qrtzPausedTriggerGrpsColumns, + handlers: handlers, } } -// DB retrieves and returns the underlying raw database management object of current DAO. +// DB retrieves and returns the underlying raw database management object of the current DAO. func (dao *QrtzPausedTriggerGrpsDao) DB() gdb.DB { return g.DB(dao.group) } -// Table returns the table name of current dao. +// Table returns the table name of the current DAO. func (dao *QrtzPausedTriggerGrpsDao) Table() string { return dao.table } -// Columns returns all column names of current dao. +// Columns returns all column names of the current DAO. func (dao *QrtzPausedTriggerGrpsDao) Columns() QrtzPausedTriggerGrpsColumns { return dao.columns } -// Group returns the configuration group name of database of current dao. +// Group returns the database configuration group name of the current DAO. func (dao *QrtzPausedTriggerGrpsDao) Group() string { return dao.group } -// Ctx creates and returns the Model for current DAO, It automatically sets the context for current operation. +// Ctx creates and returns a Model for the current DAO. It automatically sets the context for the current operation. func (dao *QrtzPausedTriggerGrpsDao) Ctx(ctx context.Context) *gdb.Model { - return dao.DB().Model(dao.table).Safe().Ctx(ctx) + model := dao.DB().Model(dao.table) + for _, handler := range dao.handlers { + model = handler(model) + } + return model.Safe().Ctx(ctx) } // Transaction wraps the transaction logic using function f. -// It rollbacks the transaction and returns the error from function f if it returns non-nil error. +// It rolls back the transaction and returns the error if function f returns a non-nil error. // It commits the transaction and returns nil if function f returns nil. // -// Note that, you should not Commit or Rollback the transaction in function f +// Note: Do not commit or roll back the transaction in function f, // as it is automatically handled by this function. func (dao *QrtzPausedTriggerGrpsDao) Transaction(ctx context.Context, f func(ctx context.Context, tx gdb.TX) error) (err error) { return dao.Ctx(ctx).Transaction(ctx, f) diff --git a/internal/dao/internal/qrtz_scheduler_state.go b/internal/dao/internal/qrtz_scheduler_state.go index 3884fc1..ba09ca6 100644 --- a/internal/dao/internal/qrtz_scheduler_state.go +++ b/internal/dao/internal/qrtz_scheduler_state.go @@ -11,14 +11,15 @@ import ( "github.com/gogf/gf/v2/frame/g" ) -// QrtzSchedulerStateDao is the data access object for table qrtz_scheduler_state. +// QrtzSchedulerStateDao is the data access object for the table qrtz_scheduler_state. type QrtzSchedulerStateDao struct { - table string // table is the underlying table name of the DAO. - group string // group is the database configuration group name of current DAO. - columns QrtzSchedulerStateColumns // columns contains all the column names of Table for convenient usage. + table string // table is the underlying table name of the DAO. + group string // group is the database configuration group name of the current DAO. + columns QrtzSchedulerStateColumns // columns contains all the column names of Table for convenient usage. + handlers []gdb.ModelHandler // handlers for customized model modification. } -// QrtzSchedulerStateColumns defines and stores column names for table qrtz_scheduler_state. +// QrtzSchedulerStateColumns defines and stores column names for the table qrtz_scheduler_state. type QrtzSchedulerStateColumns struct { SchedName string // InstanceName string // @@ -26,7 +27,7 @@ type QrtzSchedulerStateColumns struct { CheckinInterval string // } -// qrtzSchedulerStateColumns holds the columns for table qrtz_scheduler_state. +// qrtzSchedulerStateColumns holds the columns for the table qrtz_scheduler_state. var qrtzSchedulerStateColumns = QrtzSchedulerStateColumns{ SchedName: "SCHED_NAME", InstanceName: "INSTANCE_NAME", @@ -35,44 +36,49 @@ var qrtzSchedulerStateColumns = QrtzSchedulerStateColumns{ } // NewQrtzSchedulerStateDao creates and returns a new DAO object for table data access. -func NewQrtzSchedulerStateDao() *QrtzSchedulerStateDao { +func NewQrtzSchedulerStateDao(handlers ...gdb.ModelHandler) *QrtzSchedulerStateDao { return &QrtzSchedulerStateDao{ - group: "default", - table: "qrtz_scheduler_state", - columns: qrtzSchedulerStateColumns, + group: "default", + table: "qrtz_scheduler_state", + columns: qrtzSchedulerStateColumns, + handlers: handlers, } } -// DB retrieves and returns the underlying raw database management object of current DAO. +// DB retrieves and returns the underlying raw database management object of the current DAO. func (dao *QrtzSchedulerStateDao) DB() gdb.DB { return g.DB(dao.group) } -// Table returns the table name of current dao. +// Table returns the table name of the current DAO. func (dao *QrtzSchedulerStateDao) Table() string { return dao.table } -// Columns returns all column names of current dao. +// Columns returns all column names of the current DAO. func (dao *QrtzSchedulerStateDao) Columns() QrtzSchedulerStateColumns { return dao.columns } -// Group returns the configuration group name of database of current dao. +// Group returns the database configuration group name of the current DAO. func (dao *QrtzSchedulerStateDao) Group() string { return dao.group } -// Ctx creates and returns the Model for current DAO, It automatically sets the context for current operation. +// Ctx creates and returns a Model for the current DAO. It automatically sets the context for the current operation. func (dao *QrtzSchedulerStateDao) Ctx(ctx context.Context) *gdb.Model { - return dao.DB().Model(dao.table).Safe().Ctx(ctx) + model := dao.DB().Model(dao.table) + for _, handler := range dao.handlers { + model = handler(model) + } + return model.Safe().Ctx(ctx) } // Transaction wraps the transaction logic using function f. -// It rollbacks the transaction and returns the error from function f if it returns non-nil error. +// It rolls back the transaction and returns the error if function f returns a non-nil error. // It commits the transaction and returns nil if function f returns nil. // -// Note that, you should not Commit or Rollback the transaction in function f +// Note: Do not commit or roll back the transaction in function f, // as it is automatically handled by this function. func (dao *QrtzSchedulerStateDao) Transaction(ctx context.Context, f func(ctx context.Context, tx gdb.TX) error) (err error) { return dao.Ctx(ctx).Transaction(ctx, f) diff --git a/internal/dao/internal/qrtz_simple_triggers.go b/internal/dao/internal/qrtz_simple_triggers.go index 59e9a31..db0d815 100644 --- a/internal/dao/internal/qrtz_simple_triggers.go +++ b/internal/dao/internal/qrtz_simple_triggers.go @@ -11,14 +11,15 @@ import ( "github.com/gogf/gf/v2/frame/g" ) -// QrtzSimpleTriggersDao is the data access object for table qrtz_simple_triggers. +// QrtzSimpleTriggersDao is the data access object for the table qrtz_simple_triggers. type QrtzSimpleTriggersDao struct { - table string // table is the underlying table name of the DAO. - group string // group is the database configuration group name of current DAO. - columns QrtzSimpleTriggersColumns // columns contains all the column names of Table for convenient usage. + table string // table is the underlying table name of the DAO. + group string // group is the database configuration group name of the current DAO. + columns QrtzSimpleTriggersColumns // columns contains all the column names of Table for convenient usage. + handlers []gdb.ModelHandler // handlers for customized model modification. } -// QrtzSimpleTriggersColumns defines and stores column names for table qrtz_simple_triggers. +// QrtzSimpleTriggersColumns defines and stores column names for the table qrtz_simple_triggers. type QrtzSimpleTriggersColumns struct { SchedName string // TriggerName string // @@ -28,7 +29,7 @@ type QrtzSimpleTriggersColumns struct { TimesTriggered string // } -// qrtzSimpleTriggersColumns holds the columns for table qrtz_simple_triggers. +// qrtzSimpleTriggersColumns holds the columns for the table qrtz_simple_triggers. var qrtzSimpleTriggersColumns = QrtzSimpleTriggersColumns{ SchedName: "SCHED_NAME", TriggerName: "TRIGGER_NAME", @@ -39,44 +40,49 @@ var qrtzSimpleTriggersColumns = QrtzSimpleTriggersColumns{ } // NewQrtzSimpleTriggersDao creates and returns a new DAO object for table data access. -func NewQrtzSimpleTriggersDao() *QrtzSimpleTriggersDao { +func NewQrtzSimpleTriggersDao(handlers ...gdb.ModelHandler) *QrtzSimpleTriggersDao { return &QrtzSimpleTriggersDao{ - group: "default", - table: "qrtz_simple_triggers", - columns: qrtzSimpleTriggersColumns, + group: "default", + table: "qrtz_simple_triggers", + columns: qrtzSimpleTriggersColumns, + handlers: handlers, } } -// DB retrieves and returns the underlying raw database management object of current DAO. +// DB retrieves and returns the underlying raw database management object of the current DAO. func (dao *QrtzSimpleTriggersDao) DB() gdb.DB { return g.DB(dao.group) } -// Table returns the table name of current dao. +// Table returns the table name of the current DAO. func (dao *QrtzSimpleTriggersDao) Table() string { return dao.table } -// Columns returns all column names of current dao. +// Columns returns all column names of the current DAO. func (dao *QrtzSimpleTriggersDao) Columns() QrtzSimpleTriggersColumns { return dao.columns } -// Group returns the configuration group name of database of current dao. +// Group returns the database configuration group name of the current DAO. func (dao *QrtzSimpleTriggersDao) Group() string { return dao.group } -// Ctx creates and returns the Model for current DAO, It automatically sets the context for current operation. +// Ctx creates and returns a Model for the current DAO. It automatically sets the context for the current operation. func (dao *QrtzSimpleTriggersDao) Ctx(ctx context.Context) *gdb.Model { - return dao.DB().Model(dao.table).Safe().Ctx(ctx) + model := dao.DB().Model(dao.table) + for _, handler := range dao.handlers { + model = handler(model) + } + return model.Safe().Ctx(ctx) } // Transaction wraps the transaction logic using function f. -// It rollbacks the transaction and returns the error from function f if it returns non-nil error. +// It rolls back the transaction and returns the error if function f returns a non-nil error. // It commits the transaction and returns nil if function f returns nil. // -// Note that, you should not Commit or Rollback the transaction in function f +// Note: Do not commit or roll back the transaction in function f, // as it is automatically handled by this function. func (dao *QrtzSimpleTriggersDao) Transaction(ctx context.Context, f func(ctx context.Context, tx gdb.TX) error) (err error) { return dao.Ctx(ctx).Transaction(ctx, f) diff --git a/internal/dao/internal/qrtz_simprop_triggers.go b/internal/dao/internal/qrtz_simprop_triggers.go index b339332..b29a5e4 100644 --- a/internal/dao/internal/qrtz_simprop_triggers.go +++ b/internal/dao/internal/qrtz_simprop_triggers.go @@ -11,14 +11,15 @@ import ( "github.com/gogf/gf/v2/frame/g" ) -// QrtzSimpropTriggersDao is the data access object for table qrtz_simprop_triggers. +// QrtzSimpropTriggersDao is the data access object for the table qrtz_simprop_triggers. type QrtzSimpropTriggersDao struct { - table string // table is the underlying table name of the DAO. - group string // group is the database configuration group name of current DAO. - columns QrtzSimpropTriggersColumns // columns contains all the column names of Table for convenient usage. + table string // table is the underlying table name of the DAO. + group string // group is the database configuration group name of the current DAO. + columns QrtzSimpropTriggersColumns // columns contains all the column names of Table for convenient usage. + handlers []gdb.ModelHandler // handlers for customized model modification. } -// QrtzSimpropTriggersColumns defines and stores column names for table qrtz_simprop_triggers. +// QrtzSimpropTriggersColumns defines and stores column names for the table qrtz_simprop_triggers. type QrtzSimpropTriggersColumns struct { SchedName string // TriggerName string // @@ -36,7 +37,7 @@ type QrtzSimpropTriggersColumns struct { BoolProp2 string // } -// qrtzSimpropTriggersColumns holds the columns for table qrtz_simprop_triggers. +// qrtzSimpropTriggersColumns holds the columns for the table qrtz_simprop_triggers. var qrtzSimpropTriggersColumns = QrtzSimpropTriggersColumns{ SchedName: "SCHED_NAME", TriggerName: "TRIGGER_NAME", @@ -55,44 +56,49 @@ var qrtzSimpropTriggersColumns = QrtzSimpropTriggersColumns{ } // NewQrtzSimpropTriggersDao creates and returns a new DAO object for table data access. -func NewQrtzSimpropTriggersDao() *QrtzSimpropTriggersDao { +func NewQrtzSimpropTriggersDao(handlers ...gdb.ModelHandler) *QrtzSimpropTriggersDao { return &QrtzSimpropTriggersDao{ - group: "default", - table: "qrtz_simprop_triggers", - columns: qrtzSimpropTriggersColumns, + group: "default", + table: "qrtz_simprop_triggers", + columns: qrtzSimpropTriggersColumns, + handlers: handlers, } } -// DB retrieves and returns the underlying raw database management object of current DAO. +// DB retrieves and returns the underlying raw database management object of the current DAO. func (dao *QrtzSimpropTriggersDao) DB() gdb.DB { return g.DB(dao.group) } -// Table returns the table name of current dao. +// Table returns the table name of the current DAO. func (dao *QrtzSimpropTriggersDao) Table() string { return dao.table } -// Columns returns all column names of current dao. +// Columns returns all column names of the current DAO. func (dao *QrtzSimpropTriggersDao) Columns() QrtzSimpropTriggersColumns { return dao.columns } -// Group returns the configuration group name of database of current dao. +// Group returns the database configuration group name of the current DAO. func (dao *QrtzSimpropTriggersDao) Group() string { return dao.group } -// Ctx creates and returns the Model for current DAO, It automatically sets the context for current operation. +// Ctx creates and returns a Model for the current DAO. It automatically sets the context for the current operation. func (dao *QrtzSimpropTriggersDao) Ctx(ctx context.Context) *gdb.Model { - return dao.DB().Model(dao.table).Safe().Ctx(ctx) + model := dao.DB().Model(dao.table) + for _, handler := range dao.handlers { + model = handler(model) + } + return model.Safe().Ctx(ctx) } // Transaction wraps the transaction logic using function f. -// It rollbacks the transaction and returns the error from function f if it returns non-nil error. +// It rolls back the transaction and returns the error if function f returns a non-nil error. // It commits the transaction and returns nil if function f returns nil. // -// Note that, you should not Commit or Rollback the transaction in function f +// Note: Do not commit or roll back the transaction in function f, // as it is automatically handled by this function. func (dao *QrtzSimpropTriggersDao) Transaction(ctx context.Context, f func(ctx context.Context, tx gdb.TX) error) (err error) { return dao.Ctx(ctx).Transaction(ctx, f) diff --git a/internal/dao/internal/qrtz_triggers.go b/internal/dao/internal/qrtz_triggers.go index c80efff..b40b5c8 100644 --- a/internal/dao/internal/qrtz_triggers.go +++ b/internal/dao/internal/qrtz_triggers.go @@ -11,14 +11,15 @@ import ( "github.com/gogf/gf/v2/frame/g" ) -// QrtzTriggersDao is the data access object for table qrtz_triggers. +// QrtzTriggersDao is the data access object for the table qrtz_triggers. type QrtzTriggersDao struct { - table string // table is the underlying table name of the DAO. - group string // group is the database configuration group name of current DAO. - columns QrtzTriggersColumns // columns contains all the column names of Table for convenient usage. + table string // table is the underlying table name of the DAO. + group string // group is the database configuration group name of the current DAO. + columns QrtzTriggersColumns // columns contains all the column names of Table for convenient usage. + handlers []gdb.ModelHandler // handlers for customized model modification. } -// QrtzTriggersColumns defines and stores column names for table qrtz_triggers. +// QrtzTriggersColumns defines and stores column names for the table qrtz_triggers. type QrtzTriggersColumns struct { SchedName string // TriggerName string // @@ -38,7 +39,7 @@ type QrtzTriggersColumns struct { JobData string // } -// qrtzTriggersColumns holds the columns for table qrtz_triggers. +// qrtzTriggersColumns holds the columns for the table qrtz_triggers. var qrtzTriggersColumns = QrtzTriggersColumns{ SchedName: "SCHED_NAME", TriggerName: "TRIGGER_NAME", @@ -59,44 +60,49 @@ var qrtzTriggersColumns = QrtzTriggersColumns{ } // NewQrtzTriggersDao creates and returns a new DAO object for table data access. -func NewQrtzTriggersDao() *QrtzTriggersDao { +func NewQrtzTriggersDao(handlers ...gdb.ModelHandler) *QrtzTriggersDao { return &QrtzTriggersDao{ - group: "default", - table: "qrtz_triggers", - columns: qrtzTriggersColumns, + group: "default", + table: "qrtz_triggers", + columns: qrtzTriggersColumns, + handlers: handlers, } } -// DB retrieves and returns the underlying raw database management object of current DAO. +// DB retrieves and returns the underlying raw database management object of the current DAO. func (dao *QrtzTriggersDao) DB() gdb.DB { return g.DB(dao.group) } -// Table returns the table name of current dao. +// Table returns the table name of the current DAO. func (dao *QrtzTriggersDao) Table() string { return dao.table } -// Columns returns all column names of current dao. +// Columns returns all column names of the current DAO. func (dao *QrtzTriggersDao) Columns() QrtzTriggersColumns { return dao.columns } -// Group returns the configuration group name of database of current dao. +// Group returns the database configuration group name of the current DAO. func (dao *QrtzTriggersDao) Group() string { return dao.group } -// Ctx creates and returns the Model for current DAO, It automatically sets the context for current operation. +// Ctx creates and returns a Model for the current DAO. It automatically sets the context for the current operation. func (dao *QrtzTriggersDao) Ctx(ctx context.Context) *gdb.Model { - return dao.DB().Model(dao.table).Safe().Ctx(ctx) + model := dao.DB().Model(dao.table) + for _, handler := range dao.handlers { + model = handler(model) + } + return model.Safe().Ctx(ctx) } // Transaction wraps the transaction logic using function f. -// It rollbacks the transaction and returns the error from function f if it returns non-nil error. +// It rolls back the transaction and returns the error if function f returns a non-nil error. // It commits the transaction and returns nil if function f returns nil. // -// Note that, you should not Commit or Rollback the transaction in function f +// Note: Do not commit or roll back the transaction in function f, // as it is automatically handled by this function. func (dao *QrtzTriggersDao) Transaction(ctx context.Context, f func(ctx context.Context, tx gdb.TX) error) (err error) { return dao.Ctx(ctx).Transaction(ctx, f) diff --git a/internal/dao/internal/system_dept.go b/internal/dao/internal/system_dept.go index c37bc5d..6183de6 100644 --- a/internal/dao/internal/system_dept.go +++ b/internal/dao/internal/system_dept.go @@ -11,14 +11,15 @@ import ( "github.com/gogf/gf/v2/frame/g" ) -// SystemDeptDao is the data access object for table system_dept. +// SystemDeptDao is the data access object for the table system_dept. type SystemDeptDao struct { - table string // table is the underlying table name of the DAO. - group string // group is the database configuration group name of current DAO. - columns SystemDeptColumns // columns contains all the column names of Table for convenient usage. + table string // table is the underlying table name of the DAO. + group string // group is the database configuration group name of the current DAO. + columns SystemDeptColumns // columns contains all the column names of Table for convenient usage. + handlers []gdb.ModelHandler // handlers for customized model modification. } -// SystemDeptColumns defines and stores column names for table system_dept. +// SystemDeptColumns defines and stores column names for the table system_dept. type SystemDeptColumns struct { Id string // 部门id Name string // 部门名称 @@ -36,7 +37,7 @@ type SystemDeptColumns struct { TenantId string // 租户编号 } -// systemDeptColumns holds the columns for table system_dept. +// systemDeptColumns holds the columns for the table system_dept. var systemDeptColumns = SystemDeptColumns{ Id: "id", Name: "name", @@ -55,44 +56,49 @@ var systemDeptColumns = SystemDeptColumns{ } // NewSystemDeptDao creates and returns a new DAO object for table data access. -func NewSystemDeptDao() *SystemDeptDao { +func NewSystemDeptDao(handlers ...gdb.ModelHandler) *SystemDeptDao { return &SystemDeptDao{ - group: "default", - table: "system_dept", - columns: systemDeptColumns, + group: "default", + table: "system_dept", + columns: systemDeptColumns, + handlers: handlers, } } -// DB retrieves and returns the underlying raw database management object of current DAO. +// DB retrieves and returns the underlying raw database management object of the current DAO. func (dao *SystemDeptDao) DB() gdb.DB { return g.DB(dao.group) } -// Table returns the table name of current dao. +// Table returns the table name of the current DAO. func (dao *SystemDeptDao) Table() string { return dao.table } -// Columns returns all column names of current dao. +// Columns returns all column names of the current DAO. func (dao *SystemDeptDao) Columns() SystemDeptColumns { return dao.columns } -// Group returns the configuration group name of database of current dao. +// Group returns the database configuration group name of the current DAO. func (dao *SystemDeptDao) Group() string { return dao.group } -// Ctx creates and returns the Model for current DAO, It automatically sets the context for current operation. +// Ctx creates and returns a Model for the current DAO. It automatically sets the context for the current operation. func (dao *SystemDeptDao) Ctx(ctx context.Context) *gdb.Model { - return dao.DB().Model(dao.table).Safe().Ctx(ctx) + model := dao.DB().Model(dao.table) + for _, handler := range dao.handlers { + model = handler(model) + } + return model.Safe().Ctx(ctx) } // Transaction wraps the transaction logic using function f. -// It rollbacks the transaction and returns the error from function f if it returns non-nil error. +// It rolls back the transaction and returns the error if function f returns a non-nil error. // It commits the transaction and returns nil if function f returns nil. // -// Note that, you should not Commit or Rollback the transaction in function f +// Note: Do not commit or roll back the transaction in function f, // as it is automatically handled by this function. func (dao *SystemDeptDao) Transaction(ctx context.Context, f func(ctx context.Context, tx gdb.TX) error) (err error) { return dao.Ctx(ctx).Transaction(ctx, f) diff --git a/internal/dao/internal/system_dict_data.go b/internal/dao/internal/system_dict_data.go index 654ce33..a9885d4 100644 --- a/internal/dao/internal/system_dict_data.go +++ b/internal/dao/internal/system_dict_data.go @@ -11,14 +11,15 @@ import ( "github.com/gogf/gf/v2/frame/g" ) -// SystemDictDataDao is the data access object for table system_dict_data. +// SystemDictDataDao is the data access object for the table system_dict_data. type SystemDictDataDao struct { - table string // table is the underlying table name of the DAO. - group string // group is the database configuration group name of current DAO. - columns SystemDictDataColumns // columns contains all the column names of Table for convenient usage. + table string // table is the underlying table name of the DAO. + group string // group is the database configuration group name of the current DAO. + columns SystemDictDataColumns // columns contains all the column names of Table for convenient usage. + handlers []gdb.ModelHandler // handlers for customized model modification. } -// SystemDictDataColumns defines and stores column names for table system_dict_data. +// SystemDictDataColumns defines and stores column names for the table system_dict_data. type SystemDictDataColumns struct { Id string // 字典编码 Sort string // 字典排序 @@ -36,7 +37,7 @@ type SystemDictDataColumns struct { Deleted string // 是否删除 } -// systemDictDataColumns holds the columns for table system_dict_data. +// systemDictDataColumns holds the columns for the table system_dict_data. var systemDictDataColumns = SystemDictDataColumns{ Id: "id", Sort: "sort", @@ -55,44 +56,49 @@ var systemDictDataColumns = SystemDictDataColumns{ } // NewSystemDictDataDao creates and returns a new DAO object for table data access. -func NewSystemDictDataDao() *SystemDictDataDao { +func NewSystemDictDataDao(handlers ...gdb.ModelHandler) *SystemDictDataDao { return &SystemDictDataDao{ - group: "default", - table: "system_dict_data", - columns: systemDictDataColumns, + group: "default", + table: "system_dict_data", + columns: systemDictDataColumns, + handlers: handlers, } } -// DB retrieves and returns the underlying raw database management object of current DAO. +// DB retrieves and returns the underlying raw database management object of the current DAO. func (dao *SystemDictDataDao) DB() gdb.DB { return g.DB(dao.group) } -// Table returns the table name of current dao. +// Table returns the table name of the current DAO. func (dao *SystemDictDataDao) Table() string { return dao.table } -// Columns returns all column names of current dao. +// Columns returns all column names of the current DAO. func (dao *SystemDictDataDao) Columns() SystemDictDataColumns { return dao.columns } -// Group returns the configuration group name of database of current dao. +// Group returns the database configuration group name of the current DAO. func (dao *SystemDictDataDao) Group() string { return dao.group } -// Ctx creates and returns the Model for current DAO, It automatically sets the context for current operation. +// Ctx creates and returns a Model for the current DAO. It automatically sets the context for the current operation. func (dao *SystemDictDataDao) Ctx(ctx context.Context) *gdb.Model { - return dao.DB().Model(dao.table).Safe().Ctx(ctx) + model := dao.DB().Model(dao.table) + for _, handler := range dao.handlers { + model = handler(model) + } + return model.Safe().Ctx(ctx) } // Transaction wraps the transaction logic using function f. -// It rollbacks the transaction and returns the error from function f if it returns non-nil error. +// It rolls back the transaction and returns the error if function f returns a non-nil error. // It commits the transaction and returns nil if function f returns nil. // -// Note that, you should not Commit or Rollback the transaction in function f +// Note: Do not commit or roll back the transaction in function f, // as it is automatically handled by this function. func (dao *SystemDictDataDao) Transaction(ctx context.Context, f func(ctx context.Context, tx gdb.TX) error) (err error) { return dao.Ctx(ctx).Transaction(ctx, f) diff --git a/internal/dao/internal/system_dict_type.go b/internal/dao/internal/system_dict_type.go index 4e9d525..9564a2e 100644 --- a/internal/dao/internal/system_dict_type.go +++ b/internal/dao/internal/system_dict_type.go @@ -11,14 +11,15 @@ import ( "github.com/gogf/gf/v2/frame/g" ) -// SystemDictTypeDao is the data access object for table system_dict_type. +// SystemDictTypeDao is the data access object for the table system_dict_type. type SystemDictTypeDao struct { - table string // table is the underlying table name of the DAO. - group string // group is the database configuration group name of current DAO. - columns SystemDictTypeColumns // columns contains all the column names of Table for convenient usage. + table string // table is the underlying table name of the DAO. + group string // group is the database configuration group name of the current DAO. + columns SystemDictTypeColumns // columns contains all the column names of Table for convenient usage. + handlers []gdb.ModelHandler // handlers for customized model modification. } -// SystemDictTypeColumns defines and stores column names for table system_dict_type. +// SystemDictTypeColumns defines and stores column names for the table system_dict_type. type SystemDictTypeColumns struct { Id string // 字典主键 Name string // 字典名称 @@ -33,7 +34,7 @@ type SystemDictTypeColumns struct { DeletedTime string // 删除时间 } -// systemDictTypeColumns holds the columns for table system_dict_type. +// systemDictTypeColumns holds the columns for the table system_dict_type. var systemDictTypeColumns = SystemDictTypeColumns{ Id: "id", Name: "name", @@ -49,44 +50,49 @@ var systemDictTypeColumns = SystemDictTypeColumns{ } // NewSystemDictTypeDao creates and returns a new DAO object for table data access. -func NewSystemDictTypeDao() *SystemDictTypeDao { +func NewSystemDictTypeDao(handlers ...gdb.ModelHandler) *SystemDictTypeDao { return &SystemDictTypeDao{ - group: "default", - table: "system_dict_type", - columns: systemDictTypeColumns, + group: "default", + table: "system_dict_type", + columns: systemDictTypeColumns, + handlers: handlers, } } -// DB retrieves and returns the underlying raw database management object of current DAO. +// DB retrieves and returns the underlying raw database management object of the current DAO. func (dao *SystemDictTypeDao) DB() gdb.DB { return g.DB(dao.group) } -// Table returns the table name of current dao. +// Table returns the table name of the current DAO. func (dao *SystemDictTypeDao) Table() string { return dao.table } -// Columns returns all column names of current dao. +// Columns returns all column names of the current DAO. func (dao *SystemDictTypeDao) Columns() SystemDictTypeColumns { return dao.columns } -// Group returns the configuration group name of database of current dao. +// Group returns the database configuration group name of the current DAO. func (dao *SystemDictTypeDao) Group() string { return dao.group } -// Ctx creates and returns the Model for current DAO, It automatically sets the context for current operation. +// Ctx creates and returns a Model for the current DAO. It automatically sets the context for the current operation. func (dao *SystemDictTypeDao) Ctx(ctx context.Context) *gdb.Model { - return dao.DB().Model(dao.table).Safe().Ctx(ctx) + model := dao.DB().Model(dao.table) + for _, handler := range dao.handlers { + model = handler(model) + } + return model.Safe().Ctx(ctx) } // Transaction wraps the transaction logic using function f. -// It rollbacks the transaction and returns the error from function f if it returns non-nil error. +// It rolls back the transaction and returns the error if function f returns a non-nil error. // It commits the transaction and returns nil if function f returns nil. // -// Note that, you should not Commit or Rollback the transaction in function f +// Note: Do not commit or roll back the transaction in function f, // as it is automatically handled by this function. func (dao *SystemDictTypeDao) Transaction(ctx context.Context, f func(ctx context.Context, tx gdb.TX) error) (err error) { return dao.Ctx(ctx).Transaction(ctx, f) diff --git a/internal/dao/internal/system_login_log.go b/internal/dao/internal/system_login_log.go index 299a665..412371e 100644 --- a/internal/dao/internal/system_login_log.go +++ b/internal/dao/internal/system_login_log.go @@ -11,14 +11,15 @@ import ( "github.com/gogf/gf/v2/frame/g" ) -// SystemLoginLogDao is the data access object for table system_login_log. +// SystemLoginLogDao is the data access object for the table system_login_log. type SystemLoginLogDao struct { - table string // table is the underlying table name of the DAO. - group string // group is the database configuration group name of current DAO. - columns SystemLoginLogColumns // columns contains all the column names of Table for convenient usage. + table string // table is the underlying table name of the DAO. + group string // group is the database configuration group name of the current DAO. + columns SystemLoginLogColumns // columns contains all the column names of Table for convenient usage. + handlers []gdb.ModelHandler // handlers for customized model modification. } -// SystemLoginLogColumns defines and stores column names for table system_login_log. +// SystemLoginLogColumns defines and stores column names for the table system_login_log. type SystemLoginLogColumns struct { Id string // 访问ID LogType string // 日志类型 @@ -37,7 +38,7 @@ type SystemLoginLogColumns struct { TenantId string // 租户编号 } -// systemLoginLogColumns holds the columns for table system_login_log. +// systemLoginLogColumns holds the columns for the table system_login_log. var systemLoginLogColumns = SystemLoginLogColumns{ Id: "id", LogType: "log_type", @@ -57,44 +58,49 @@ var systemLoginLogColumns = SystemLoginLogColumns{ } // NewSystemLoginLogDao creates and returns a new DAO object for table data access. -func NewSystemLoginLogDao() *SystemLoginLogDao { +func NewSystemLoginLogDao(handlers ...gdb.ModelHandler) *SystemLoginLogDao { return &SystemLoginLogDao{ - group: "default", - table: "system_login_log", - columns: systemLoginLogColumns, + group: "default", + table: "system_login_log", + columns: systemLoginLogColumns, + handlers: handlers, } } -// DB retrieves and returns the underlying raw database management object of current DAO. +// DB retrieves and returns the underlying raw database management object of the current DAO. func (dao *SystemLoginLogDao) DB() gdb.DB { return g.DB(dao.group) } -// Table returns the table name of current dao. +// Table returns the table name of the current DAO. func (dao *SystemLoginLogDao) Table() string { return dao.table } -// Columns returns all column names of current dao. +// Columns returns all column names of the current DAO. func (dao *SystemLoginLogDao) Columns() SystemLoginLogColumns { return dao.columns } -// Group returns the configuration group name of database of current dao. +// Group returns the database configuration group name of the current DAO. func (dao *SystemLoginLogDao) Group() string { return dao.group } -// Ctx creates and returns the Model for current DAO, It automatically sets the context for current operation. +// Ctx creates and returns a Model for the current DAO. It automatically sets the context for the current operation. func (dao *SystemLoginLogDao) Ctx(ctx context.Context) *gdb.Model { - return dao.DB().Model(dao.table).Safe().Ctx(ctx) + model := dao.DB().Model(dao.table) + for _, handler := range dao.handlers { + model = handler(model) + } + return model.Safe().Ctx(ctx) } // Transaction wraps the transaction logic using function f. -// It rollbacks the transaction and returns the error from function f if it returns non-nil error. +// It rolls back the transaction and returns the error if function f returns a non-nil error. // It commits the transaction and returns nil if function f returns nil. // -// Note that, you should not Commit or Rollback the transaction in function f +// Note: Do not commit or roll back the transaction in function f, // as it is automatically handled by this function. func (dao *SystemLoginLogDao) Transaction(ctx context.Context, f func(ctx context.Context, tx gdb.TX) error) (err error) { return dao.Ctx(ctx).Transaction(ctx, f) diff --git a/internal/dao/internal/system_mail_account.go b/internal/dao/internal/system_mail_account.go index d2ccfb6..b7f1580 100644 --- a/internal/dao/internal/system_mail_account.go +++ b/internal/dao/internal/system_mail_account.go @@ -11,14 +11,15 @@ import ( "github.com/gogf/gf/v2/frame/g" ) -// SystemMailAccountDao is the data access object for table system_mail_account. +// SystemMailAccountDao is the data access object for the table system_mail_account. type SystemMailAccountDao struct { - table string // table is the underlying table name of the DAO. - group string // group is the database configuration group name of current DAO. - columns SystemMailAccountColumns // columns contains all the column names of Table for convenient usage. + table string // table is the underlying table name of the DAO. + group string // group is the database configuration group name of the current DAO. + columns SystemMailAccountColumns // columns contains all the column names of Table for convenient usage. + handlers []gdb.ModelHandler // handlers for customized model modification. } -// SystemMailAccountColumns defines and stores column names for table system_mail_account. +// SystemMailAccountColumns defines and stores column names for the table system_mail_account. type SystemMailAccountColumns struct { Id string // 主键 Mail string // 邮箱 @@ -35,7 +36,7 @@ type SystemMailAccountColumns struct { Deleted string // 是否删除 } -// systemMailAccountColumns holds the columns for table system_mail_account. +// systemMailAccountColumns holds the columns for the table system_mail_account. var systemMailAccountColumns = SystemMailAccountColumns{ Id: "id", Mail: "mail", @@ -53,44 +54,49 @@ var systemMailAccountColumns = SystemMailAccountColumns{ } // NewSystemMailAccountDao creates and returns a new DAO object for table data access. -func NewSystemMailAccountDao() *SystemMailAccountDao { +func NewSystemMailAccountDao(handlers ...gdb.ModelHandler) *SystemMailAccountDao { return &SystemMailAccountDao{ - group: "default", - table: "system_mail_account", - columns: systemMailAccountColumns, + group: "default", + table: "system_mail_account", + columns: systemMailAccountColumns, + handlers: handlers, } } -// DB retrieves and returns the underlying raw database management object of current DAO. +// DB retrieves and returns the underlying raw database management object of the current DAO. func (dao *SystemMailAccountDao) DB() gdb.DB { return g.DB(dao.group) } -// Table returns the table name of current dao. +// Table returns the table name of the current DAO. func (dao *SystemMailAccountDao) Table() string { return dao.table } -// Columns returns all column names of current dao. +// Columns returns all column names of the current DAO. func (dao *SystemMailAccountDao) Columns() SystemMailAccountColumns { return dao.columns } -// Group returns the configuration group name of database of current dao. +// Group returns the database configuration group name of the current DAO. func (dao *SystemMailAccountDao) Group() string { return dao.group } -// Ctx creates and returns the Model for current DAO, It automatically sets the context for current operation. +// Ctx creates and returns a Model for the current DAO. It automatically sets the context for the current operation. func (dao *SystemMailAccountDao) Ctx(ctx context.Context) *gdb.Model { - return dao.DB().Model(dao.table).Safe().Ctx(ctx) + model := dao.DB().Model(dao.table) + for _, handler := range dao.handlers { + model = handler(model) + } + return model.Safe().Ctx(ctx) } // Transaction wraps the transaction logic using function f. -// It rollbacks the transaction and returns the error from function f if it returns non-nil error. +// It rolls back the transaction and returns the error if function f returns a non-nil error. // It commits the transaction and returns nil if function f returns nil. // -// Note that, you should not Commit or Rollback the transaction in function f +// Note: Do not commit or roll back the transaction in function f, // as it is automatically handled by this function. func (dao *SystemMailAccountDao) Transaction(ctx context.Context, f func(ctx context.Context, tx gdb.TX) error) (err error) { return dao.Ctx(ctx).Transaction(ctx, f) diff --git a/internal/dao/internal/system_mail_log.go b/internal/dao/internal/system_mail_log.go index 282fc12..330c4f7 100644 --- a/internal/dao/internal/system_mail_log.go +++ b/internal/dao/internal/system_mail_log.go @@ -11,14 +11,15 @@ import ( "github.com/gogf/gf/v2/frame/g" ) -// SystemMailLogDao is the data access object for table system_mail_log. +// SystemMailLogDao is the data access object for the table system_mail_log. type SystemMailLogDao struct { - table string // table is the underlying table name of the DAO. - group string // group is the database configuration group name of current DAO. - columns SystemMailLogColumns // columns contains all the column names of Table for convenient usage. + table string // table is the underlying table name of the DAO. + group string // group is the database configuration group name of the current DAO. + columns SystemMailLogColumns // columns contains all the column names of Table for convenient usage. + handlers []gdb.ModelHandler // handlers for customized model modification. } -// SystemMailLogColumns defines and stores column names for table system_mail_log. +// SystemMailLogColumns defines and stores column names for the table system_mail_log. type SystemMailLogColumns struct { Id string // 编号 UserId string // 用户编号 @@ -43,7 +44,7 @@ type SystemMailLogColumns struct { Deleted string // 是否删除 } -// systemMailLogColumns holds the columns for table system_mail_log. +// systemMailLogColumns holds the columns for the table system_mail_log. var systemMailLogColumns = SystemMailLogColumns{ Id: "id", UserId: "user_id", @@ -69,44 +70,49 @@ var systemMailLogColumns = SystemMailLogColumns{ } // NewSystemMailLogDao creates and returns a new DAO object for table data access. -func NewSystemMailLogDao() *SystemMailLogDao { +func NewSystemMailLogDao(handlers ...gdb.ModelHandler) *SystemMailLogDao { return &SystemMailLogDao{ - group: "default", - table: "system_mail_log", - columns: systemMailLogColumns, + group: "default", + table: "system_mail_log", + columns: systemMailLogColumns, + handlers: handlers, } } -// DB retrieves and returns the underlying raw database management object of current DAO. +// DB retrieves and returns the underlying raw database management object of the current DAO. func (dao *SystemMailLogDao) DB() gdb.DB { return g.DB(dao.group) } -// Table returns the table name of current dao. +// Table returns the table name of the current DAO. func (dao *SystemMailLogDao) Table() string { return dao.table } -// Columns returns all column names of current dao. +// Columns returns all column names of the current DAO. func (dao *SystemMailLogDao) Columns() SystemMailLogColumns { return dao.columns } -// Group returns the configuration group name of database of current dao. +// Group returns the database configuration group name of the current DAO. func (dao *SystemMailLogDao) Group() string { return dao.group } -// Ctx creates and returns the Model for current DAO, It automatically sets the context for current operation. +// Ctx creates and returns a Model for the current DAO. It automatically sets the context for the current operation. func (dao *SystemMailLogDao) Ctx(ctx context.Context) *gdb.Model { - return dao.DB().Model(dao.table).Safe().Ctx(ctx) + model := dao.DB().Model(dao.table) + for _, handler := range dao.handlers { + model = handler(model) + } + return model.Safe().Ctx(ctx) } // Transaction wraps the transaction logic using function f. -// It rollbacks the transaction and returns the error from function f if it returns non-nil error. +// It rolls back the transaction and returns the error if function f returns a non-nil error. // It commits the transaction and returns nil if function f returns nil. // -// Note that, you should not Commit or Rollback the transaction in function f +// Note: Do not commit or roll back the transaction in function f, // as it is automatically handled by this function. func (dao *SystemMailLogDao) Transaction(ctx context.Context, f func(ctx context.Context, tx gdb.TX) error) (err error) { return dao.Ctx(ctx).Transaction(ctx, f) diff --git a/internal/dao/internal/system_mail_template.go b/internal/dao/internal/system_mail_template.go index 31be969..8bc5b37 100644 --- a/internal/dao/internal/system_mail_template.go +++ b/internal/dao/internal/system_mail_template.go @@ -11,14 +11,15 @@ import ( "github.com/gogf/gf/v2/frame/g" ) -// SystemMailTemplateDao is the data access object for table system_mail_template. +// SystemMailTemplateDao is the data access object for the table system_mail_template. type SystemMailTemplateDao struct { - table string // table is the underlying table name of the DAO. - group string // group is the database configuration group name of current DAO. - columns SystemMailTemplateColumns // columns contains all the column names of Table for convenient usage. + table string // table is the underlying table name of the DAO. + group string // group is the database configuration group name of the current DAO. + columns SystemMailTemplateColumns // columns contains all the column names of Table for convenient usage. + handlers []gdb.ModelHandler // handlers for customized model modification. } -// SystemMailTemplateColumns defines and stores column names for table system_mail_template. +// SystemMailTemplateColumns defines and stores column names for the table system_mail_template. type SystemMailTemplateColumns struct { Id string // 编号 Name string // 模板名称 @@ -37,7 +38,7 @@ type SystemMailTemplateColumns struct { Deleted string // 是否删除 } -// systemMailTemplateColumns holds the columns for table system_mail_template. +// systemMailTemplateColumns holds the columns for the table system_mail_template. var systemMailTemplateColumns = SystemMailTemplateColumns{ Id: "id", Name: "name", @@ -57,44 +58,49 @@ var systemMailTemplateColumns = SystemMailTemplateColumns{ } // NewSystemMailTemplateDao creates and returns a new DAO object for table data access. -func NewSystemMailTemplateDao() *SystemMailTemplateDao { +func NewSystemMailTemplateDao(handlers ...gdb.ModelHandler) *SystemMailTemplateDao { return &SystemMailTemplateDao{ - group: "default", - table: "system_mail_template", - columns: systemMailTemplateColumns, + group: "default", + table: "system_mail_template", + columns: systemMailTemplateColumns, + handlers: handlers, } } -// DB retrieves and returns the underlying raw database management object of current DAO. +// DB retrieves and returns the underlying raw database management object of the current DAO. func (dao *SystemMailTemplateDao) DB() gdb.DB { return g.DB(dao.group) } -// Table returns the table name of current dao. +// Table returns the table name of the current DAO. func (dao *SystemMailTemplateDao) Table() string { return dao.table } -// Columns returns all column names of current dao. +// Columns returns all column names of the current DAO. func (dao *SystemMailTemplateDao) Columns() SystemMailTemplateColumns { return dao.columns } -// Group returns the configuration group name of database of current dao. +// Group returns the database configuration group name of the current DAO. func (dao *SystemMailTemplateDao) Group() string { return dao.group } -// Ctx creates and returns the Model for current DAO, It automatically sets the context for current operation. +// Ctx creates and returns a Model for the current DAO. It automatically sets the context for the current operation. func (dao *SystemMailTemplateDao) Ctx(ctx context.Context) *gdb.Model { - return dao.DB().Model(dao.table).Safe().Ctx(ctx) + model := dao.DB().Model(dao.table) + for _, handler := range dao.handlers { + model = handler(model) + } + return model.Safe().Ctx(ctx) } // Transaction wraps the transaction logic using function f. -// It rollbacks the transaction and returns the error from function f if it returns non-nil error. +// It rolls back the transaction and returns the error if function f returns a non-nil error. // It commits the transaction and returns nil if function f returns nil. // -// Note that, you should not Commit or Rollback the transaction in function f +// Note: Do not commit or roll back the transaction in function f, // as it is automatically handled by this function. func (dao *SystemMailTemplateDao) Transaction(ctx context.Context, f func(ctx context.Context, tx gdb.TX) error) (err error) { return dao.Ctx(ctx).Transaction(ctx, f) diff --git a/internal/dao/internal/system_menu.go b/internal/dao/internal/system_menu.go index c513232..807b6e0 100644 --- a/internal/dao/internal/system_menu.go +++ b/internal/dao/internal/system_menu.go @@ -11,14 +11,15 @@ import ( "github.com/gogf/gf/v2/frame/g" ) -// SystemMenuDao is the data access object for table system_menu. +// SystemMenuDao is the data access object for the table system_menu. type SystemMenuDao struct { - table string // table is the underlying table name of the DAO. - group string // group is the database configuration group name of current DAO. - columns SystemMenuColumns // columns contains all the column names of Table for convenient usage. + table string // table is the underlying table name of the DAO. + group string // group is the database configuration group name of the current DAO. + columns SystemMenuColumns // columns contains all the column names of Table for convenient usage. + handlers []gdb.ModelHandler // handlers for customized model modification. } -// SystemMenuColumns defines and stores column names for table system_menu. +// SystemMenuColumns defines and stores column names for the table system_menu. type SystemMenuColumns struct { Id string // 菜单ID Name string // 菜单名称 @@ -41,7 +42,7 @@ type SystemMenuColumns struct { Deleted string // 是否删除 } -// systemMenuColumns holds the columns for table system_menu. +// systemMenuColumns holds the columns for the table system_menu. var systemMenuColumns = SystemMenuColumns{ Id: "id", Name: "name", @@ -65,44 +66,49 @@ var systemMenuColumns = SystemMenuColumns{ } // NewSystemMenuDao creates and returns a new DAO object for table data access. -func NewSystemMenuDao() *SystemMenuDao { +func NewSystemMenuDao(handlers ...gdb.ModelHandler) *SystemMenuDao { return &SystemMenuDao{ - group: "default", - table: "system_menu", - columns: systemMenuColumns, + group: "default", + table: "system_menu", + columns: systemMenuColumns, + handlers: handlers, } } -// DB retrieves and returns the underlying raw database management object of current DAO. +// DB retrieves and returns the underlying raw database management object of the current DAO. func (dao *SystemMenuDao) DB() gdb.DB { return g.DB(dao.group) } -// Table returns the table name of current dao. +// Table returns the table name of the current DAO. func (dao *SystemMenuDao) Table() string { return dao.table } -// Columns returns all column names of current dao. +// Columns returns all column names of the current DAO. func (dao *SystemMenuDao) Columns() SystemMenuColumns { return dao.columns } -// Group returns the configuration group name of database of current dao. +// Group returns the database configuration group name of the current DAO. func (dao *SystemMenuDao) Group() string { return dao.group } -// Ctx creates and returns the Model for current DAO, It automatically sets the context for current operation. +// Ctx creates and returns a Model for the current DAO. It automatically sets the context for the current operation. func (dao *SystemMenuDao) Ctx(ctx context.Context) *gdb.Model { - return dao.DB().Model(dao.table).Safe().Ctx(ctx) + model := dao.DB().Model(dao.table) + for _, handler := range dao.handlers { + model = handler(model) + } + return model.Safe().Ctx(ctx) } // Transaction wraps the transaction logic using function f. -// It rollbacks the transaction and returns the error from function f if it returns non-nil error. +// It rolls back the transaction and returns the error if function f returns a non-nil error. // It commits the transaction and returns nil if function f returns nil. // -// Note that, you should not Commit or Rollback the transaction in function f +// Note: Do not commit or roll back the transaction in function f, // as it is automatically handled by this function. func (dao *SystemMenuDao) Transaction(ctx context.Context, f func(ctx context.Context, tx gdb.TX) error) (err error) { return dao.Ctx(ctx).Transaction(ctx, f) diff --git a/internal/dao/internal/system_notice.go b/internal/dao/internal/system_notice.go index 23055a9..85ce9b1 100644 --- a/internal/dao/internal/system_notice.go +++ b/internal/dao/internal/system_notice.go @@ -11,14 +11,15 @@ import ( "github.com/gogf/gf/v2/frame/g" ) -// SystemNoticeDao is the data access object for table system_notice. +// SystemNoticeDao is the data access object for the table system_notice. type SystemNoticeDao struct { - table string // table is the underlying table name of the DAO. - group string // group is the database configuration group name of current DAO. - columns SystemNoticeColumns // columns contains all the column names of Table for convenient usage. + table string // table is the underlying table name of the DAO. + group string // group is the database configuration group name of the current DAO. + columns SystemNoticeColumns // columns contains all the column names of Table for convenient usage. + handlers []gdb.ModelHandler // handlers for customized model modification. } -// SystemNoticeColumns defines and stores column names for table system_notice. +// SystemNoticeColumns defines and stores column names for the table system_notice. type SystemNoticeColumns struct { Id string // 公告ID Title string // 公告标题 @@ -33,7 +34,7 @@ type SystemNoticeColumns struct { TenantId string // 租户编号 } -// systemNoticeColumns holds the columns for table system_notice. +// systemNoticeColumns holds the columns for the table system_notice. var systemNoticeColumns = SystemNoticeColumns{ Id: "id", Title: "title", @@ -49,44 +50,49 @@ var systemNoticeColumns = SystemNoticeColumns{ } // NewSystemNoticeDao creates and returns a new DAO object for table data access. -func NewSystemNoticeDao() *SystemNoticeDao { +func NewSystemNoticeDao(handlers ...gdb.ModelHandler) *SystemNoticeDao { return &SystemNoticeDao{ - group: "default", - table: "system_notice", - columns: systemNoticeColumns, + group: "default", + table: "system_notice", + columns: systemNoticeColumns, + handlers: handlers, } } -// DB retrieves and returns the underlying raw database management object of current DAO. +// DB retrieves and returns the underlying raw database management object of the current DAO. func (dao *SystemNoticeDao) DB() gdb.DB { return g.DB(dao.group) } -// Table returns the table name of current dao. +// Table returns the table name of the current DAO. func (dao *SystemNoticeDao) Table() string { return dao.table } -// Columns returns all column names of current dao. +// Columns returns all column names of the current DAO. func (dao *SystemNoticeDao) Columns() SystemNoticeColumns { return dao.columns } -// Group returns the configuration group name of database of current dao. +// Group returns the database configuration group name of the current DAO. func (dao *SystemNoticeDao) Group() string { return dao.group } -// Ctx creates and returns the Model for current DAO, It automatically sets the context for current operation. +// Ctx creates and returns a Model for the current DAO. It automatically sets the context for the current operation. func (dao *SystemNoticeDao) Ctx(ctx context.Context) *gdb.Model { - return dao.DB().Model(dao.table).Safe().Ctx(ctx) + model := dao.DB().Model(dao.table) + for _, handler := range dao.handlers { + model = handler(model) + } + return model.Safe().Ctx(ctx) } // Transaction wraps the transaction logic using function f. -// It rollbacks the transaction and returns the error from function f if it returns non-nil error. +// It rolls back the transaction and returns the error if function f returns a non-nil error. // It commits the transaction and returns nil if function f returns nil. // -// Note that, you should not Commit or Rollback the transaction in function f +// Note: Do not commit or roll back the transaction in function f, // as it is automatically handled by this function. func (dao *SystemNoticeDao) Transaction(ctx context.Context, f func(ctx context.Context, tx gdb.TX) error) (err error) { return dao.Ctx(ctx).Transaction(ctx, f) diff --git a/internal/dao/internal/system_notify_message.go b/internal/dao/internal/system_notify_message.go index 6eb2e2e..12c66a3 100644 --- a/internal/dao/internal/system_notify_message.go +++ b/internal/dao/internal/system_notify_message.go @@ -11,14 +11,15 @@ import ( "github.com/gogf/gf/v2/frame/g" ) -// SystemNotifyMessageDao is the data access object for table system_notify_message. +// SystemNotifyMessageDao is the data access object for the table system_notify_message. type SystemNotifyMessageDao struct { - table string // table is the underlying table name of the DAO. - group string // group is the database configuration group name of current DAO. - columns SystemNotifyMessageColumns // columns contains all the column names of Table for convenient usage. + table string // table is the underlying table name of the DAO. + group string // group is the database configuration group name of the current DAO. + columns SystemNotifyMessageColumns // columns contains all the column names of Table for convenient usage. + handlers []gdb.ModelHandler // handlers for customized model modification. } -// SystemNotifyMessageColumns defines and stores column names for table system_notify_message. +// SystemNotifyMessageColumns defines and stores column names for the table system_notify_message. type SystemNotifyMessageColumns struct { Id string // 用户ID UserId string // 用户id @@ -39,7 +40,7 @@ type SystemNotifyMessageColumns struct { TenantId string // 租户编号 } -// systemNotifyMessageColumns holds the columns for table system_notify_message. +// systemNotifyMessageColumns holds the columns for the table system_notify_message. var systemNotifyMessageColumns = SystemNotifyMessageColumns{ Id: "id", UserId: "user_id", @@ -61,44 +62,49 @@ var systemNotifyMessageColumns = SystemNotifyMessageColumns{ } // NewSystemNotifyMessageDao creates and returns a new DAO object for table data access. -func NewSystemNotifyMessageDao() *SystemNotifyMessageDao { +func NewSystemNotifyMessageDao(handlers ...gdb.ModelHandler) *SystemNotifyMessageDao { return &SystemNotifyMessageDao{ - group: "default", - table: "system_notify_message", - columns: systemNotifyMessageColumns, + group: "default", + table: "system_notify_message", + columns: systemNotifyMessageColumns, + handlers: handlers, } } -// DB retrieves and returns the underlying raw database management object of current DAO. +// DB retrieves and returns the underlying raw database management object of the current DAO. func (dao *SystemNotifyMessageDao) DB() gdb.DB { return g.DB(dao.group) } -// Table returns the table name of current dao. +// Table returns the table name of the current DAO. func (dao *SystemNotifyMessageDao) Table() string { return dao.table } -// Columns returns all column names of current dao. +// Columns returns all column names of the current DAO. func (dao *SystemNotifyMessageDao) Columns() SystemNotifyMessageColumns { return dao.columns } -// Group returns the configuration group name of database of current dao. +// Group returns the database configuration group name of the current DAO. func (dao *SystemNotifyMessageDao) Group() string { return dao.group } -// Ctx creates and returns the Model for current DAO, It automatically sets the context for current operation. +// Ctx creates and returns a Model for the current DAO. It automatically sets the context for the current operation. func (dao *SystemNotifyMessageDao) Ctx(ctx context.Context) *gdb.Model { - return dao.DB().Model(dao.table).Safe().Ctx(ctx) + model := dao.DB().Model(dao.table) + for _, handler := range dao.handlers { + model = handler(model) + } + return model.Safe().Ctx(ctx) } // Transaction wraps the transaction logic using function f. -// It rollbacks the transaction and returns the error from function f if it returns non-nil error. +// It rolls back the transaction and returns the error if function f returns a non-nil error. // It commits the transaction and returns nil if function f returns nil. // -// Note that, you should not Commit or Rollback the transaction in function f +// Note: Do not commit or roll back the transaction in function f, // as it is automatically handled by this function. func (dao *SystemNotifyMessageDao) Transaction(ctx context.Context, f func(ctx context.Context, tx gdb.TX) error) (err error) { return dao.Ctx(ctx).Transaction(ctx, f) diff --git a/internal/dao/internal/system_notify_template.go b/internal/dao/internal/system_notify_template.go index 6ec6505..c495800 100644 --- a/internal/dao/internal/system_notify_template.go +++ b/internal/dao/internal/system_notify_template.go @@ -11,14 +11,15 @@ import ( "github.com/gogf/gf/v2/frame/g" ) -// SystemNotifyTemplateDao is the data access object for table system_notify_template. +// SystemNotifyTemplateDao is the data access object for the table system_notify_template. type SystemNotifyTemplateDao struct { - table string // table is the underlying table name of the DAO. - group string // group is the database configuration group name of current DAO. - columns SystemNotifyTemplateColumns // columns contains all the column names of Table for convenient usage. + table string // table is the underlying table name of the DAO. + group string // group is the database configuration group name of the current DAO. + columns SystemNotifyTemplateColumns // columns contains all the column names of Table for convenient usage. + handlers []gdb.ModelHandler // handlers for customized model modification. } -// SystemNotifyTemplateColumns defines and stores column names for table system_notify_template. +// SystemNotifyTemplateColumns defines and stores column names for the table system_notify_template. type SystemNotifyTemplateColumns struct { Id string // 主键 Name string // 模板名称 @@ -36,7 +37,7 @@ type SystemNotifyTemplateColumns struct { Deleted string // 是否删除 } -// systemNotifyTemplateColumns holds the columns for table system_notify_template. +// systemNotifyTemplateColumns holds the columns for the table system_notify_template. var systemNotifyTemplateColumns = SystemNotifyTemplateColumns{ Id: "id", Name: "name", @@ -55,44 +56,49 @@ var systemNotifyTemplateColumns = SystemNotifyTemplateColumns{ } // NewSystemNotifyTemplateDao creates and returns a new DAO object for table data access. -func NewSystemNotifyTemplateDao() *SystemNotifyTemplateDao { +func NewSystemNotifyTemplateDao(handlers ...gdb.ModelHandler) *SystemNotifyTemplateDao { return &SystemNotifyTemplateDao{ - group: "default", - table: "system_notify_template", - columns: systemNotifyTemplateColumns, + group: "default", + table: "system_notify_template", + columns: systemNotifyTemplateColumns, + handlers: handlers, } } -// DB retrieves and returns the underlying raw database management object of current DAO. +// DB retrieves and returns the underlying raw database management object of the current DAO. func (dao *SystemNotifyTemplateDao) DB() gdb.DB { return g.DB(dao.group) } -// Table returns the table name of current dao. +// Table returns the table name of the current DAO. func (dao *SystemNotifyTemplateDao) Table() string { return dao.table } -// Columns returns all column names of current dao. +// Columns returns all column names of the current DAO. func (dao *SystemNotifyTemplateDao) Columns() SystemNotifyTemplateColumns { return dao.columns } -// Group returns the configuration group name of database of current dao. +// Group returns the database configuration group name of the current DAO. func (dao *SystemNotifyTemplateDao) Group() string { return dao.group } -// Ctx creates and returns the Model for current DAO, It automatically sets the context for current operation. +// Ctx creates and returns a Model for the current DAO. It automatically sets the context for the current operation. func (dao *SystemNotifyTemplateDao) Ctx(ctx context.Context) *gdb.Model { - return dao.DB().Model(dao.table).Safe().Ctx(ctx) + model := dao.DB().Model(dao.table) + for _, handler := range dao.handlers { + model = handler(model) + } + return model.Safe().Ctx(ctx) } // Transaction wraps the transaction logic using function f. -// It rollbacks the transaction and returns the error from function f if it returns non-nil error. +// It rolls back the transaction and returns the error if function f returns a non-nil error. // It commits the transaction and returns nil if function f returns nil. // -// Note that, you should not Commit or Rollback the transaction in function f +// Note: Do not commit or roll back the transaction in function f, // as it is automatically handled by this function. func (dao *SystemNotifyTemplateDao) Transaction(ctx context.Context, f func(ctx context.Context, tx gdb.TX) error) (err error) { return dao.Ctx(ctx).Transaction(ctx, f) diff --git a/internal/dao/internal/system_oauth_2_access_token.go b/internal/dao/internal/system_oauth_2_access_token.go index c53ebb1..10b0a5a 100644 --- a/internal/dao/internal/system_oauth_2_access_token.go +++ b/internal/dao/internal/system_oauth_2_access_token.go @@ -11,14 +11,15 @@ import ( "github.com/gogf/gf/v2/frame/g" ) -// SystemOauth2AccessTokenDao is the data access object for table system_oauth2_access_token. +// SystemOauth2AccessTokenDao is the data access object for the table system_oauth2_access_token. type SystemOauth2AccessTokenDao struct { - table string // table is the underlying table name of the DAO. - group string // group is the database configuration group name of current DAO. - columns SystemOauth2AccessTokenColumns // columns contains all the column names of Table for convenient usage. + table string // table is the underlying table name of the DAO. + group string // group is the database configuration group name of the current DAO. + columns SystemOauth2AccessTokenColumns // columns contains all the column names of Table for convenient usage. + handlers []gdb.ModelHandler // handlers for customized model modification. } -// SystemOauth2AccessTokenColumns defines and stores column names for table system_oauth2_access_token. +// SystemOauth2AccessTokenColumns defines and stores column names for the table system_oauth2_access_token. type SystemOauth2AccessTokenColumns struct { Id string // 编号 UserId string // 用户编号 @@ -37,7 +38,7 @@ type SystemOauth2AccessTokenColumns struct { TenantId string // 租户编号 } -// systemOauth2AccessTokenColumns holds the columns for table system_oauth2_access_token. +// systemOauth2AccessTokenColumns holds the columns for the table system_oauth2_access_token. var systemOauth2AccessTokenColumns = SystemOauth2AccessTokenColumns{ Id: "id", UserId: "user_id", @@ -57,44 +58,49 @@ var systemOauth2AccessTokenColumns = SystemOauth2AccessTokenColumns{ } // NewSystemOauth2AccessTokenDao creates and returns a new DAO object for table data access. -func NewSystemOauth2AccessTokenDao() *SystemOauth2AccessTokenDao { +func NewSystemOauth2AccessTokenDao(handlers ...gdb.ModelHandler) *SystemOauth2AccessTokenDao { return &SystemOauth2AccessTokenDao{ - group: "default", - table: "system_oauth2_access_token", - columns: systemOauth2AccessTokenColumns, + group: "default", + table: "system_oauth2_access_token", + columns: systemOauth2AccessTokenColumns, + handlers: handlers, } } -// DB retrieves and returns the underlying raw database management object of current DAO. +// DB retrieves and returns the underlying raw database management object of the current DAO. func (dao *SystemOauth2AccessTokenDao) DB() gdb.DB { return g.DB(dao.group) } -// Table returns the table name of current dao. +// Table returns the table name of the current DAO. func (dao *SystemOauth2AccessTokenDao) Table() string { return dao.table } -// Columns returns all column names of current dao. +// Columns returns all column names of the current DAO. func (dao *SystemOauth2AccessTokenDao) Columns() SystemOauth2AccessTokenColumns { return dao.columns } -// Group returns the configuration group name of database of current dao. +// Group returns the database configuration group name of the current DAO. func (dao *SystemOauth2AccessTokenDao) Group() string { return dao.group } -// Ctx creates and returns the Model for current DAO, It automatically sets the context for current operation. +// Ctx creates and returns a Model for the current DAO. It automatically sets the context for the current operation. func (dao *SystemOauth2AccessTokenDao) Ctx(ctx context.Context) *gdb.Model { - return dao.DB().Model(dao.table).Safe().Ctx(ctx) + model := dao.DB().Model(dao.table) + for _, handler := range dao.handlers { + model = handler(model) + } + return model.Safe().Ctx(ctx) } // Transaction wraps the transaction logic using function f. -// It rollbacks the transaction and returns the error from function f if it returns non-nil error. +// It rolls back the transaction and returns the error if function f returns a non-nil error. // It commits the transaction and returns nil if function f returns nil. // -// Note that, you should not Commit or Rollback the transaction in function f +// Note: Do not commit or roll back the transaction in function f, // as it is automatically handled by this function. func (dao *SystemOauth2AccessTokenDao) Transaction(ctx context.Context, f func(ctx context.Context, tx gdb.TX) error) (err error) { return dao.Ctx(ctx).Transaction(ctx, f) diff --git a/internal/dao/internal/system_oauth_2_approve.go b/internal/dao/internal/system_oauth_2_approve.go index 4834b50..99fba67 100644 --- a/internal/dao/internal/system_oauth_2_approve.go +++ b/internal/dao/internal/system_oauth_2_approve.go @@ -11,14 +11,15 @@ import ( "github.com/gogf/gf/v2/frame/g" ) -// SystemOauth2ApproveDao is the data access object for table system_oauth2_approve. +// SystemOauth2ApproveDao is the data access object for the table system_oauth2_approve. type SystemOauth2ApproveDao struct { - table string // table is the underlying table name of the DAO. - group string // group is the database configuration group name of current DAO. - columns SystemOauth2ApproveColumns // columns contains all the column names of Table for convenient usage. + table string // table is the underlying table name of the DAO. + group string // group is the database configuration group name of the current DAO. + columns SystemOauth2ApproveColumns // columns contains all the column names of Table for convenient usage. + handlers []gdb.ModelHandler // handlers for customized model modification. } -// SystemOauth2ApproveColumns defines and stores column names for table system_oauth2_approve. +// SystemOauth2ApproveColumns defines and stores column names for the table system_oauth2_approve. type SystemOauth2ApproveColumns struct { Id string // 编号 UserId string // 用户编号 @@ -35,7 +36,7 @@ type SystemOauth2ApproveColumns struct { TenantId string // 租户编号 } -// systemOauth2ApproveColumns holds the columns for table system_oauth2_approve. +// systemOauth2ApproveColumns holds the columns for the table system_oauth2_approve. var systemOauth2ApproveColumns = SystemOauth2ApproveColumns{ Id: "id", UserId: "user_id", @@ -53,44 +54,49 @@ var systemOauth2ApproveColumns = SystemOauth2ApproveColumns{ } // NewSystemOauth2ApproveDao creates and returns a new DAO object for table data access. -func NewSystemOauth2ApproveDao() *SystemOauth2ApproveDao { +func NewSystemOauth2ApproveDao(handlers ...gdb.ModelHandler) *SystemOauth2ApproveDao { return &SystemOauth2ApproveDao{ - group: "default", - table: "system_oauth2_approve", - columns: systemOauth2ApproveColumns, + group: "default", + table: "system_oauth2_approve", + columns: systemOauth2ApproveColumns, + handlers: handlers, } } -// DB retrieves and returns the underlying raw database management object of current DAO. +// DB retrieves and returns the underlying raw database management object of the current DAO. func (dao *SystemOauth2ApproveDao) DB() gdb.DB { return g.DB(dao.group) } -// Table returns the table name of current dao. +// Table returns the table name of the current DAO. func (dao *SystemOauth2ApproveDao) Table() string { return dao.table } -// Columns returns all column names of current dao. +// Columns returns all column names of the current DAO. func (dao *SystemOauth2ApproveDao) Columns() SystemOauth2ApproveColumns { return dao.columns } -// Group returns the configuration group name of database of current dao. +// Group returns the database configuration group name of the current DAO. func (dao *SystemOauth2ApproveDao) Group() string { return dao.group } -// Ctx creates and returns the Model for current DAO, It automatically sets the context for current operation. +// Ctx creates and returns a Model for the current DAO. It automatically sets the context for the current operation. func (dao *SystemOauth2ApproveDao) Ctx(ctx context.Context) *gdb.Model { - return dao.DB().Model(dao.table).Safe().Ctx(ctx) + model := dao.DB().Model(dao.table) + for _, handler := range dao.handlers { + model = handler(model) + } + return model.Safe().Ctx(ctx) } // Transaction wraps the transaction logic using function f. -// It rollbacks the transaction and returns the error from function f if it returns non-nil error. +// It rolls back the transaction and returns the error if function f returns a non-nil error. // It commits the transaction and returns nil if function f returns nil. // -// Note that, you should not Commit or Rollback the transaction in function f +// Note: Do not commit or roll back the transaction in function f, // as it is automatically handled by this function. func (dao *SystemOauth2ApproveDao) Transaction(ctx context.Context, f func(ctx context.Context, tx gdb.TX) error) (err error) { return dao.Ctx(ctx).Transaction(ctx, f) diff --git a/internal/dao/internal/system_oauth_2_client.go b/internal/dao/internal/system_oauth_2_client.go index b12f9a0..caddc54 100644 --- a/internal/dao/internal/system_oauth_2_client.go +++ b/internal/dao/internal/system_oauth_2_client.go @@ -11,14 +11,15 @@ import ( "github.com/gogf/gf/v2/frame/g" ) -// SystemOauth2ClientDao is the data access object for table system_oauth2_client. +// SystemOauth2ClientDao is the data access object for the table system_oauth2_client. type SystemOauth2ClientDao struct { - table string // table is the underlying table name of the DAO. - group string // group is the database configuration group name of current DAO. - columns SystemOauth2ClientColumns // columns contains all the column names of Table for convenient usage. + table string // table is the underlying table name of the DAO. + group string // group is the database configuration group name of the current DAO. + columns SystemOauth2ClientColumns // columns contains all the column names of Table for convenient usage. + handlers []gdb.ModelHandler // handlers for customized model modification. } -// SystemOauth2ClientColumns defines and stores column names for table system_oauth2_client. +// SystemOauth2ClientColumns defines and stores column names for the table system_oauth2_client. type SystemOauth2ClientColumns struct { Id string // 编号 ClientId string // 客户端编号 @@ -43,7 +44,7 @@ type SystemOauth2ClientColumns struct { Deleted string // 是否删除 } -// systemOauth2ClientColumns holds the columns for table system_oauth2_client. +// systemOauth2ClientColumns holds the columns for the table system_oauth2_client. var systemOauth2ClientColumns = SystemOauth2ClientColumns{ Id: "id", ClientId: "client_id", @@ -69,44 +70,49 @@ var systemOauth2ClientColumns = SystemOauth2ClientColumns{ } // NewSystemOauth2ClientDao creates and returns a new DAO object for table data access. -func NewSystemOauth2ClientDao() *SystemOauth2ClientDao { +func NewSystemOauth2ClientDao(handlers ...gdb.ModelHandler) *SystemOauth2ClientDao { return &SystemOauth2ClientDao{ - group: "default", - table: "system_oauth2_client", - columns: systemOauth2ClientColumns, + group: "default", + table: "system_oauth2_client", + columns: systemOauth2ClientColumns, + handlers: handlers, } } -// DB retrieves and returns the underlying raw database management object of current DAO. +// DB retrieves and returns the underlying raw database management object of the current DAO. func (dao *SystemOauth2ClientDao) DB() gdb.DB { return g.DB(dao.group) } -// Table returns the table name of current dao. +// Table returns the table name of the current DAO. func (dao *SystemOauth2ClientDao) Table() string { return dao.table } -// Columns returns all column names of current dao. +// Columns returns all column names of the current DAO. func (dao *SystemOauth2ClientDao) Columns() SystemOauth2ClientColumns { return dao.columns } -// Group returns the configuration group name of database of current dao. +// Group returns the database configuration group name of the current DAO. func (dao *SystemOauth2ClientDao) Group() string { return dao.group } -// Ctx creates and returns the Model for current DAO, It automatically sets the context for current operation. +// Ctx creates and returns a Model for the current DAO. It automatically sets the context for the current operation. func (dao *SystemOauth2ClientDao) Ctx(ctx context.Context) *gdb.Model { - return dao.DB().Model(dao.table).Safe().Ctx(ctx) + model := dao.DB().Model(dao.table) + for _, handler := range dao.handlers { + model = handler(model) + } + return model.Safe().Ctx(ctx) } // Transaction wraps the transaction logic using function f. -// It rollbacks the transaction and returns the error from function f if it returns non-nil error. +// It rolls back the transaction and returns the error if function f returns a non-nil error. // It commits the transaction and returns nil if function f returns nil. // -// Note that, you should not Commit or Rollback the transaction in function f +// Note: Do not commit or roll back the transaction in function f, // as it is automatically handled by this function. func (dao *SystemOauth2ClientDao) Transaction(ctx context.Context, f func(ctx context.Context, tx gdb.TX) error) (err error) { return dao.Ctx(ctx).Transaction(ctx, f) diff --git a/internal/dao/internal/system_oauth_2_code.go b/internal/dao/internal/system_oauth_2_code.go index db3d32b..8481730 100644 --- a/internal/dao/internal/system_oauth_2_code.go +++ b/internal/dao/internal/system_oauth_2_code.go @@ -11,14 +11,15 @@ import ( "github.com/gogf/gf/v2/frame/g" ) -// SystemOauth2CodeDao is the data access object for table system_oauth2_code. +// SystemOauth2CodeDao is the data access object for the table system_oauth2_code. type SystemOauth2CodeDao struct { - table string // table is the underlying table name of the DAO. - group string // group is the database configuration group name of current DAO. - columns SystemOauth2CodeColumns // columns contains all the column names of Table for convenient usage. + table string // table is the underlying table name of the DAO. + group string // group is the database configuration group name of the current DAO. + columns SystemOauth2CodeColumns // columns contains all the column names of Table for convenient usage. + handlers []gdb.ModelHandler // handlers for customized model modification. } -// SystemOauth2CodeColumns defines and stores column names for table system_oauth2_code. +// SystemOauth2CodeColumns defines and stores column names for the table system_oauth2_code. type SystemOauth2CodeColumns struct { Id string // 编号 UserId string // 用户编号 @@ -37,7 +38,7 @@ type SystemOauth2CodeColumns struct { TenantId string // 租户编号 } -// systemOauth2CodeColumns holds the columns for table system_oauth2_code. +// systemOauth2CodeColumns holds the columns for the table system_oauth2_code. var systemOauth2CodeColumns = SystemOauth2CodeColumns{ Id: "id", UserId: "user_id", @@ -57,44 +58,49 @@ var systemOauth2CodeColumns = SystemOauth2CodeColumns{ } // NewSystemOauth2CodeDao creates and returns a new DAO object for table data access. -func NewSystemOauth2CodeDao() *SystemOauth2CodeDao { +func NewSystemOauth2CodeDao(handlers ...gdb.ModelHandler) *SystemOauth2CodeDao { return &SystemOauth2CodeDao{ - group: "default", - table: "system_oauth2_code", - columns: systemOauth2CodeColumns, + group: "default", + table: "system_oauth2_code", + columns: systemOauth2CodeColumns, + handlers: handlers, } } -// DB retrieves and returns the underlying raw database management object of current DAO. +// DB retrieves and returns the underlying raw database management object of the current DAO. func (dao *SystemOauth2CodeDao) DB() gdb.DB { return g.DB(dao.group) } -// Table returns the table name of current dao. +// Table returns the table name of the current DAO. func (dao *SystemOauth2CodeDao) Table() string { return dao.table } -// Columns returns all column names of current dao. +// Columns returns all column names of the current DAO. func (dao *SystemOauth2CodeDao) Columns() SystemOauth2CodeColumns { return dao.columns } -// Group returns the configuration group name of database of current dao. +// Group returns the database configuration group name of the current DAO. func (dao *SystemOauth2CodeDao) Group() string { return dao.group } -// Ctx creates and returns the Model for current DAO, It automatically sets the context for current operation. +// Ctx creates and returns a Model for the current DAO. It automatically sets the context for the current operation. func (dao *SystemOauth2CodeDao) Ctx(ctx context.Context) *gdb.Model { - return dao.DB().Model(dao.table).Safe().Ctx(ctx) + model := dao.DB().Model(dao.table) + for _, handler := range dao.handlers { + model = handler(model) + } + return model.Safe().Ctx(ctx) } // Transaction wraps the transaction logic using function f. -// It rollbacks the transaction and returns the error from function f if it returns non-nil error. +// It rolls back the transaction and returns the error if function f returns a non-nil error. // It commits the transaction and returns nil if function f returns nil. // -// Note that, you should not Commit or Rollback the transaction in function f +// Note: Do not commit or roll back the transaction in function f, // as it is automatically handled by this function. func (dao *SystemOauth2CodeDao) Transaction(ctx context.Context, f func(ctx context.Context, tx gdb.TX) error) (err error) { return dao.Ctx(ctx).Transaction(ctx, f) diff --git a/internal/dao/internal/system_oauth_2_refresh_token.go b/internal/dao/internal/system_oauth_2_refresh_token.go index 2387627..2434f9b 100644 --- a/internal/dao/internal/system_oauth_2_refresh_token.go +++ b/internal/dao/internal/system_oauth_2_refresh_token.go @@ -11,14 +11,15 @@ import ( "github.com/gogf/gf/v2/frame/g" ) -// SystemOauth2RefreshTokenDao is the data access object for table system_oauth2_refresh_token. +// SystemOauth2RefreshTokenDao is the data access object for the table system_oauth2_refresh_token. type SystemOauth2RefreshTokenDao struct { - table string // table is the underlying table name of the DAO. - group string // group is the database configuration group name of current DAO. - columns SystemOauth2RefreshTokenColumns // columns contains all the column names of Table for convenient usage. + table string // table is the underlying table name of the DAO. + group string // group is the database configuration group name of the current DAO. + columns SystemOauth2RefreshTokenColumns // columns contains all the column names of Table for convenient usage. + handlers []gdb.ModelHandler // handlers for customized model modification. } -// SystemOauth2RefreshTokenColumns defines and stores column names for table system_oauth2_refresh_token. +// SystemOauth2RefreshTokenColumns defines and stores column names for the table system_oauth2_refresh_token. type SystemOauth2RefreshTokenColumns struct { Id string // 编号 UserId string // 用户编号 @@ -35,7 +36,7 @@ type SystemOauth2RefreshTokenColumns struct { TenantId string // 租户编号 } -// systemOauth2RefreshTokenColumns holds the columns for table system_oauth2_refresh_token. +// systemOauth2RefreshTokenColumns holds the columns for the table system_oauth2_refresh_token. var systemOauth2RefreshTokenColumns = SystemOauth2RefreshTokenColumns{ Id: "id", UserId: "user_id", @@ -53,44 +54,49 @@ var systemOauth2RefreshTokenColumns = SystemOauth2RefreshTokenColumns{ } // NewSystemOauth2RefreshTokenDao creates and returns a new DAO object for table data access. -func NewSystemOauth2RefreshTokenDao() *SystemOauth2RefreshTokenDao { +func NewSystemOauth2RefreshTokenDao(handlers ...gdb.ModelHandler) *SystemOauth2RefreshTokenDao { return &SystemOauth2RefreshTokenDao{ - group: "default", - table: "system_oauth2_refresh_token", - columns: systemOauth2RefreshTokenColumns, + group: "default", + table: "system_oauth2_refresh_token", + columns: systemOauth2RefreshTokenColumns, + handlers: handlers, } } -// DB retrieves and returns the underlying raw database management object of current DAO. +// DB retrieves and returns the underlying raw database management object of the current DAO. func (dao *SystemOauth2RefreshTokenDao) DB() gdb.DB { return g.DB(dao.group) } -// Table returns the table name of current dao. +// Table returns the table name of the current DAO. func (dao *SystemOauth2RefreshTokenDao) Table() string { return dao.table } -// Columns returns all column names of current dao. +// Columns returns all column names of the current DAO. func (dao *SystemOauth2RefreshTokenDao) Columns() SystemOauth2RefreshTokenColumns { return dao.columns } -// Group returns the configuration group name of database of current dao. +// Group returns the database configuration group name of the current DAO. func (dao *SystemOauth2RefreshTokenDao) Group() string { return dao.group } -// Ctx creates and returns the Model for current DAO, It automatically sets the context for current operation. +// Ctx creates and returns a Model for the current DAO. It automatically sets the context for the current operation. func (dao *SystemOauth2RefreshTokenDao) Ctx(ctx context.Context) *gdb.Model { - return dao.DB().Model(dao.table).Safe().Ctx(ctx) + model := dao.DB().Model(dao.table) + for _, handler := range dao.handlers { + model = handler(model) + } + return model.Safe().Ctx(ctx) } // Transaction wraps the transaction logic using function f. -// It rollbacks the transaction and returns the error from function f if it returns non-nil error. +// It rolls back the transaction and returns the error if function f returns a non-nil error. // It commits the transaction and returns nil if function f returns nil. // -// Note that, you should not Commit or Rollback the transaction in function f +// Note: Do not commit or roll back the transaction in function f, // as it is automatically handled by this function. func (dao *SystemOauth2RefreshTokenDao) Transaction(ctx context.Context, f func(ctx context.Context, tx gdb.TX) error) (err error) { return dao.Ctx(ctx).Transaction(ctx, f) diff --git a/internal/dao/internal/system_operate_log.go b/internal/dao/internal/system_operate_log.go index 8e4fea1..e5b08e9 100644 --- a/internal/dao/internal/system_operate_log.go +++ b/internal/dao/internal/system_operate_log.go @@ -11,14 +11,15 @@ import ( "github.com/gogf/gf/v2/frame/g" ) -// SystemOperateLogDao is the data access object for table system_operate_log. +// SystemOperateLogDao is the data access object for the table system_operate_log. type SystemOperateLogDao struct { - table string // table is the underlying table name of the DAO. - group string // group is the database configuration group name of current DAO. - columns SystemOperateLogColumns // columns contains all the column names of Table for convenient usage. + table string // table is the underlying table name of the DAO. + group string // group is the database configuration group name of the current DAO. + columns SystemOperateLogColumns // columns contains all the column names of Table for convenient usage. + handlers []gdb.ModelHandler // handlers for customized model modification. } -// SystemOperateLogColumns defines and stores column names for table system_operate_log. +// SystemOperateLogColumns defines and stores column names for the table system_operate_log. type SystemOperateLogColumns struct { Id string // 日志主键 TraceId string // 链路追踪编号 @@ -41,7 +42,7 @@ type SystemOperateLogColumns struct { TenantId string // 租户编号 } -// systemOperateLogColumns holds the columns for table system_operate_log. +// systemOperateLogColumns holds the columns for the table system_operate_log. var systemOperateLogColumns = SystemOperateLogColumns{ Id: "id", TraceId: "trace_id", @@ -65,44 +66,49 @@ var systemOperateLogColumns = SystemOperateLogColumns{ } // NewSystemOperateLogDao creates and returns a new DAO object for table data access. -func NewSystemOperateLogDao() *SystemOperateLogDao { +func NewSystemOperateLogDao(handlers ...gdb.ModelHandler) *SystemOperateLogDao { return &SystemOperateLogDao{ - group: "default", - table: "system_operate_log", - columns: systemOperateLogColumns, + group: "default", + table: "system_operate_log", + columns: systemOperateLogColumns, + handlers: handlers, } } -// DB retrieves and returns the underlying raw database management object of current DAO. +// DB retrieves and returns the underlying raw database management object of the current DAO. func (dao *SystemOperateLogDao) DB() gdb.DB { return g.DB(dao.group) } -// Table returns the table name of current dao. +// Table returns the table name of the current DAO. func (dao *SystemOperateLogDao) Table() string { return dao.table } -// Columns returns all column names of current dao. +// Columns returns all column names of the current DAO. func (dao *SystemOperateLogDao) Columns() SystemOperateLogColumns { return dao.columns } -// Group returns the configuration group name of database of current dao. +// Group returns the database configuration group name of the current DAO. func (dao *SystemOperateLogDao) Group() string { return dao.group } -// Ctx creates and returns the Model for current DAO, It automatically sets the context for current operation. +// Ctx creates and returns a Model for the current DAO. It automatically sets the context for the current operation. func (dao *SystemOperateLogDao) Ctx(ctx context.Context) *gdb.Model { - return dao.DB().Model(dao.table).Safe().Ctx(ctx) + model := dao.DB().Model(dao.table) + for _, handler := range dao.handlers { + model = handler(model) + } + return model.Safe().Ctx(ctx) } // Transaction wraps the transaction logic using function f. -// It rollbacks the transaction and returns the error from function f if it returns non-nil error. +// It rolls back the transaction and returns the error if function f returns a non-nil error. // It commits the transaction and returns nil if function f returns nil. // -// Note that, you should not Commit or Rollback the transaction in function f +// Note: Do not commit or roll back the transaction in function f, // as it is automatically handled by this function. func (dao *SystemOperateLogDao) Transaction(ctx context.Context, f func(ctx context.Context, tx gdb.TX) error) (err error) { return dao.Ctx(ctx).Transaction(ctx, f) diff --git a/internal/dao/internal/system_post.go b/internal/dao/internal/system_post.go index 02a3ac9..c8bdeb9 100644 --- a/internal/dao/internal/system_post.go +++ b/internal/dao/internal/system_post.go @@ -11,14 +11,15 @@ import ( "github.com/gogf/gf/v2/frame/g" ) -// SystemPostDao is the data access object for table system_post. +// SystemPostDao is the data access object for the table system_post. type SystemPostDao struct { - table string // table is the underlying table name of the DAO. - group string // group is the database configuration group name of current DAO. - columns SystemPostColumns // columns contains all the column names of Table for convenient usage. + table string // table is the underlying table name of the DAO. + group string // group is the database configuration group name of the current DAO. + columns SystemPostColumns // columns contains all the column names of Table for convenient usage. + handlers []gdb.ModelHandler // handlers for customized model modification. } -// SystemPostColumns defines and stores column names for table system_post. +// SystemPostColumns defines and stores column names for the table system_post. type SystemPostColumns struct { Id string // 岗位ID Code string // 岗位编码 @@ -34,7 +35,7 @@ type SystemPostColumns struct { TenantId string // 租户编号 } -// systemPostColumns holds the columns for table system_post. +// systemPostColumns holds the columns for the table system_post. var systemPostColumns = SystemPostColumns{ Id: "id", Code: "code", @@ -51,44 +52,49 @@ var systemPostColumns = SystemPostColumns{ } // NewSystemPostDao creates and returns a new DAO object for table data access. -func NewSystemPostDao() *SystemPostDao { +func NewSystemPostDao(handlers ...gdb.ModelHandler) *SystemPostDao { return &SystemPostDao{ - group: "default", - table: "system_post", - columns: systemPostColumns, + group: "default", + table: "system_post", + columns: systemPostColumns, + handlers: handlers, } } -// DB retrieves and returns the underlying raw database management object of current DAO. +// DB retrieves and returns the underlying raw database management object of the current DAO. func (dao *SystemPostDao) DB() gdb.DB { return g.DB(dao.group) } -// Table returns the table name of current dao. +// Table returns the table name of the current DAO. func (dao *SystemPostDao) Table() string { return dao.table } -// Columns returns all column names of current dao. +// Columns returns all column names of the current DAO. func (dao *SystemPostDao) Columns() SystemPostColumns { return dao.columns } -// Group returns the configuration group name of database of current dao. +// Group returns the database configuration group name of the current DAO. func (dao *SystemPostDao) Group() string { return dao.group } -// Ctx creates and returns the Model for current DAO, It automatically sets the context for current operation. +// Ctx creates and returns a Model for the current DAO. It automatically sets the context for the current operation. func (dao *SystemPostDao) Ctx(ctx context.Context) *gdb.Model { - return dao.DB().Model(dao.table).Safe().Ctx(ctx) + model := dao.DB().Model(dao.table) + for _, handler := range dao.handlers { + model = handler(model) + } + return model.Safe().Ctx(ctx) } // Transaction wraps the transaction logic using function f. -// It rollbacks the transaction and returns the error from function f if it returns non-nil error. +// It rolls back the transaction and returns the error if function f returns a non-nil error. // It commits the transaction and returns nil if function f returns nil. // -// Note that, you should not Commit or Rollback the transaction in function f +// Note: Do not commit or roll back the transaction in function f, // as it is automatically handled by this function. func (dao *SystemPostDao) Transaction(ctx context.Context, f func(ctx context.Context, tx gdb.TX) error) (err error) { return dao.Ctx(ctx).Transaction(ctx, f) diff --git a/internal/dao/internal/system_role.go b/internal/dao/internal/system_role.go index b6f8c6a..fb3a3f4 100644 --- a/internal/dao/internal/system_role.go +++ b/internal/dao/internal/system_role.go @@ -11,14 +11,15 @@ import ( "github.com/gogf/gf/v2/frame/g" ) -// SystemRoleDao is the data access object for table system_role. +// SystemRoleDao is the data access object for the table system_role. type SystemRoleDao struct { - table string // table is the underlying table name of the DAO. - group string // group is the database configuration group name of current DAO. - columns SystemRoleColumns // columns contains all the column names of Table for convenient usage. + table string // table is the underlying table name of the DAO. + group string // group is the database configuration group name of the current DAO. + columns SystemRoleColumns // columns contains all the column names of Table for convenient usage. + handlers []gdb.ModelHandler // handlers for customized model modification. } -// SystemRoleColumns defines and stores column names for table system_role. +// SystemRoleColumns defines and stores column names for the table system_role. type SystemRoleColumns struct { Id string // 角色ID Name string // 角色名称 @@ -37,7 +38,7 @@ type SystemRoleColumns struct { TenantId string // 租户编号 } -// systemRoleColumns holds the columns for table system_role. +// systemRoleColumns holds the columns for the table system_role. var systemRoleColumns = SystemRoleColumns{ Id: "id", Name: "name", @@ -57,44 +58,49 @@ var systemRoleColumns = SystemRoleColumns{ } // NewSystemRoleDao creates and returns a new DAO object for table data access. -func NewSystemRoleDao() *SystemRoleDao { +func NewSystemRoleDao(handlers ...gdb.ModelHandler) *SystemRoleDao { return &SystemRoleDao{ - group: "default", - table: "system_role", - columns: systemRoleColumns, + group: "default", + table: "system_role", + columns: systemRoleColumns, + handlers: handlers, } } -// DB retrieves and returns the underlying raw database management object of current DAO. +// DB retrieves and returns the underlying raw database management object of the current DAO. func (dao *SystemRoleDao) DB() gdb.DB { return g.DB(dao.group) } -// Table returns the table name of current dao. +// Table returns the table name of the current DAO. func (dao *SystemRoleDao) Table() string { return dao.table } -// Columns returns all column names of current dao. +// Columns returns all column names of the current DAO. func (dao *SystemRoleDao) Columns() SystemRoleColumns { return dao.columns } -// Group returns the configuration group name of database of current dao. +// Group returns the database configuration group name of the current DAO. func (dao *SystemRoleDao) Group() string { return dao.group } -// Ctx creates and returns the Model for current DAO, It automatically sets the context for current operation. +// Ctx creates and returns a Model for the current DAO. It automatically sets the context for the current operation. func (dao *SystemRoleDao) Ctx(ctx context.Context) *gdb.Model { - return dao.DB().Model(dao.table).Safe().Ctx(ctx) + model := dao.DB().Model(dao.table) + for _, handler := range dao.handlers { + model = handler(model) + } + return model.Safe().Ctx(ctx) } // Transaction wraps the transaction logic using function f. -// It rollbacks the transaction and returns the error from function f if it returns non-nil error. +// It rolls back the transaction and returns the error if function f returns a non-nil error. // It commits the transaction and returns nil if function f returns nil. // -// Note that, you should not Commit or Rollback the transaction in function f +// Note: Do not commit or roll back the transaction in function f, // as it is automatically handled by this function. func (dao *SystemRoleDao) Transaction(ctx context.Context, f func(ctx context.Context, tx gdb.TX) error) (err error) { return dao.Ctx(ctx).Transaction(ctx, f) diff --git a/internal/dao/internal/system_role_menu.go b/internal/dao/internal/system_role_menu.go index 4732ba3..d80b314 100644 --- a/internal/dao/internal/system_role_menu.go +++ b/internal/dao/internal/system_role_menu.go @@ -11,14 +11,15 @@ import ( "github.com/gogf/gf/v2/frame/g" ) -// SystemRoleMenuDao is the data access object for table system_role_menu. +// SystemRoleMenuDao is the data access object for the table system_role_menu. type SystemRoleMenuDao struct { - table string // table is the underlying table name of the DAO. - group string // group is the database configuration group name of current DAO. - columns SystemRoleMenuColumns // columns contains all the column names of Table for convenient usage. + table string // table is the underlying table name of the DAO. + group string // group is the database configuration group name of the current DAO. + columns SystemRoleMenuColumns // columns contains all the column names of Table for convenient usage. + handlers []gdb.ModelHandler // handlers for customized model modification. } -// SystemRoleMenuColumns defines and stores column names for table system_role_menu. +// SystemRoleMenuColumns defines and stores column names for the table system_role_menu. type SystemRoleMenuColumns struct { Id string // 自增编号 RoleId string // 角色ID @@ -31,7 +32,7 @@ type SystemRoleMenuColumns struct { TenantId string // 租户编号 } -// systemRoleMenuColumns holds the columns for table system_role_menu. +// systemRoleMenuColumns holds the columns for the table system_role_menu. var systemRoleMenuColumns = SystemRoleMenuColumns{ Id: "id", RoleId: "role_id", @@ -45,44 +46,49 @@ var systemRoleMenuColumns = SystemRoleMenuColumns{ } // NewSystemRoleMenuDao creates and returns a new DAO object for table data access. -func NewSystemRoleMenuDao() *SystemRoleMenuDao { +func NewSystemRoleMenuDao(handlers ...gdb.ModelHandler) *SystemRoleMenuDao { return &SystemRoleMenuDao{ - group: "default", - table: "system_role_menu", - columns: systemRoleMenuColumns, + group: "default", + table: "system_role_menu", + columns: systemRoleMenuColumns, + handlers: handlers, } } -// DB retrieves and returns the underlying raw database management object of current DAO. +// DB retrieves and returns the underlying raw database management object of the current DAO. func (dao *SystemRoleMenuDao) DB() gdb.DB { return g.DB(dao.group) } -// Table returns the table name of current dao. +// Table returns the table name of the current DAO. func (dao *SystemRoleMenuDao) Table() string { return dao.table } -// Columns returns all column names of current dao. +// Columns returns all column names of the current DAO. func (dao *SystemRoleMenuDao) Columns() SystemRoleMenuColumns { return dao.columns } -// Group returns the configuration group name of database of current dao. +// Group returns the database configuration group name of the current DAO. func (dao *SystemRoleMenuDao) Group() string { return dao.group } -// Ctx creates and returns the Model for current DAO, It automatically sets the context for current operation. +// Ctx creates and returns a Model for the current DAO. It automatically sets the context for the current operation. func (dao *SystemRoleMenuDao) Ctx(ctx context.Context) *gdb.Model { - return dao.DB().Model(dao.table).Safe().Ctx(ctx) + model := dao.DB().Model(dao.table) + for _, handler := range dao.handlers { + model = handler(model) + } + return model.Safe().Ctx(ctx) } // Transaction wraps the transaction logic using function f. -// It rollbacks the transaction and returns the error from function f if it returns non-nil error. +// It rolls back the transaction and returns the error if function f returns a non-nil error. // It commits the transaction and returns nil if function f returns nil. // -// Note that, you should not Commit or Rollback the transaction in function f +// Note: Do not commit or roll back the transaction in function f, // as it is automatically handled by this function. func (dao *SystemRoleMenuDao) Transaction(ctx context.Context, f func(ctx context.Context, tx gdb.TX) error) (err error) { return dao.Ctx(ctx).Transaction(ctx, f) diff --git a/internal/dao/internal/system_sms_channel.go b/internal/dao/internal/system_sms_channel.go index 5d7ba90..44788dc 100644 --- a/internal/dao/internal/system_sms_channel.go +++ b/internal/dao/internal/system_sms_channel.go @@ -11,14 +11,15 @@ import ( "github.com/gogf/gf/v2/frame/g" ) -// SystemSmsChannelDao is the data access object for table system_sms_channel. +// SystemSmsChannelDao is the data access object for the table system_sms_channel. type SystemSmsChannelDao struct { - table string // table is the underlying table name of the DAO. - group string // group is the database configuration group name of current DAO. - columns SystemSmsChannelColumns // columns contains all the column names of Table for convenient usage. + table string // table is the underlying table name of the DAO. + group string // group is the database configuration group name of the current DAO. + columns SystemSmsChannelColumns // columns contains all the column names of Table for convenient usage. + handlers []gdb.ModelHandler // handlers for customized model modification. } -// SystemSmsChannelColumns defines and stores column names for table system_sms_channel. +// SystemSmsChannelColumns defines and stores column names for the table system_sms_channel. type SystemSmsChannelColumns struct { Id string // 编号 Signature string // 短信签名 @@ -35,7 +36,7 @@ type SystemSmsChannelColumns struct { Deleted string // 是否删除 } -// systemSmsChannelColumns holds the columns for table system_sms_channel. +// systemSmsChannelColumns holds the columns for the table system_sms_channel. var systemSmsChannelColumns = SystemSmsChannelColumns{ Id: "id", Signature: "signature", @@ -53,44 +54,49 @@ var systemSmsChannelColumns = SystemSmsChannelColumns{ } // NewSystemSmsChannelDao creates and returns a new DAO object for table data access. -func NewSystemSmsChannelDao() *SystemSmsChannelDao { +func NewSystemSmsChannelDao(handlers ...gdb.ModelHandler) *SystemSmsChannelDao { return &SystemSmsChannelDao{ - group: "default", - table: "system_sms_channel", - columns: systemSmsChannelColumns, + group: "default", + table: "system_sms_channel", + columns: systemSmsChannelColumns, + handlers: handlers, } } -// DB retrieves and returns the underlying raw database management object of current DAO. +// DB retrieves and returns the underlying raw database management object of the current DAO. func (dao *SystemSmsChannelDao) DB() gdb.DB { return g.DB(dao.group) } -// Table returns the table name of current dao. +// Table returns the table name of the current DAO. func (dao *SystemSmsChannelDao) Table() string { return dao.table } -// Columns returns all column names of current dao. +// Columns returns all column names of the current DAO. func (dao *SystemSmsChannelDao) Columns() SystemSmsChannelColumns { return dao.columns } -// Group returns the configuration group name of database of current dao. +// Group returns the database configuration group name of the current DAO. func (dao *SystemSmsChannelDao) Group() string { return dao.group } -// Ctx creates and returns the Model for current DAO, It automatically sets the context for current operation. +// Ctx creates and returns a Model for the current DAO. It automatically sets the context for the current operation. func (dao *SystemSmsChannelDao) Ctx(ctx context.Context) *gdb.Model { - return dao.DB().Model(dao.table).Safe().Ctx(ctx) + model := dao.DB().Model(dao.table) + for _, handler := range dao.handlers { + model = handler(model) + } + return model.Safe().Ctx(ctx) } // Transaction wraps the transaction logic using function f. -// It rollbacks the transaction and returns the error from function f if it returns non-nil error. +// It rolls back the transaction and returns the error if function f returns a non-nil error. // It commits the transaction and returns nil if function f returns nil. // -// Note that, you should not Commit or Rollback the transaction in function f +// Note: Do not commit or roll back the transaction in function f, // as it is automatically handled by this function. func (dao *SystemSmsChannelDao) Transaction(ctx context.Context, f func(ctx context.Context, tx gdb.TX) error) (err error) { return dao.Ctx(ctx).Transaction(ctx, f) diff --git a/internal/dao/internal/system_sms_code.go b/internal/dao/internal/system_sms_code.go index 7c1d75d..6184dbb 100644 --- a/internal/dao/internal/system_sms_code.go +++ b/internal/dao/internal/system_sms_code.go @@ -11,14 +11,15 @@ import ( "github.com/gogf/gf/v2/frame/g" ) -// SystemSmsCodeDao is the data access object for table system_sms_code. +// SystemSmsCodeDao is the data access object for the table system_sms_code. type SystemSmsCodeDao struct { - table string // table is the underlying table name of the DAO. - group string // group is the database configuration group name of current DAO. - columns SystemSmsCodeColumns // columns contains all the column names of Table for convenient usage. + table string // table is the underlying table name of the DAO. + group string // group is the database configuration group name of the current DAO. + columns SystemSmsCodeColumns // columns contains all the column names of Table for convenient usage. + handlers []gdb.ModelHandler // handlers for customized model modification. } -// SystemSmsCodeColumns defines and stores column names for table system_sms_code. +// SystemSmsCodeColumns defines and stores column names for the table system_sms_code. type SystemSmsCodeColumns struct { Id string // 编号 Mobile string // 手机号 @@ -37,7 +38,7 @@ type SystemSmsCodeColumns struct { TenantId string // 租户编号 } -// systemSmsCodeColumns holds the columns for table system_sms_code. +// systemSmsCodeColumns holds the columns for the table system_sms_code. var systemSmsCodeColumns = SystemSmsCodeColumns{ Id: "id", Mobile: "mobile", @@ -57,44 +58,49 @@ var systemSmsCodeColumns = SystemSmsCodeColumns{ } // NewSystemSmsCodeDao creates and returns a new DAO object for table data access. -func NewSystemSmsCodeDao() *SystemSmsCodeDao { +func NewSystemSmsCodeDao(handlers ...gdb.ModelHandler) *SystemSmsCodeDao { return &SystemSmsCodeDao{ - group: "default", - table: "system_sms_code", - columns: systemSmsCodeColumns, + group: "default", + table: "system_sms_code", + columns: systemSmsCodeColumns, + handlers: handlers, } } -// DB retrieves and returns the underlying raw database management object of current DAO. +// DB retrieves and returns the underlying raw database management object of the current DAO. func (dao *SystemSmsCodeDao) DB() gdb.DB { return g.DB(dao.group) } -// Table returns the table name of current dao. +// Table returns the table name of the current DAO. func (dao *SystemSmsCodeDao) Table() string { return dao.table } -// Columns returns all column names of current dao. +// Columns returns all column names of the current DAO. func (dao *SystemSmsCodeDao) Columns() SystemSmsCodeColumns { return dao.columns } -// Group returns the configuration group name of database of current dao. +// Group returns the database configuration group name of the current DAO. func (dao *SystemSmsCodeDao) Group() string { return dao.group } -// Ctx creates and returns the Model for current DAO, It automatically sets the context for current operation. +// Ctx creates and returns a Model for the current DAO. It automatically sets the context for the current operation. func (dao *SystemSmsCodeDao) Ctx(ctx context.Context) *gdb.Model { - return dao.DB().Model(dao.table).Safe().Ctx(ctx) + model := dao.DB().Model(dao.table) + for _, handler := range dao.handlers { + model = handler(model) + } + return model.Safe().Ctx(ctx) } // Transaction wraps the transaction logic using function f. -// It rollbacks the transaction and returns the error from function f if it returns non-nil error. +// It rolls back the transaction and returns the error if function f returns a non-nil error. // It commits the transaction and returns nil if function f returns nil. // -// Note that, you should not Commit or Rollback the transaction in function f +// Note: Do not commit or roll back the transaction in function f, // as it is automatically handled by this function. func (dao *SystemSmsCodeDao) Transaction(ctx context.Context, f func(ctx context.Context, tx gdb.TX) error) (err error) { return dao.Ctx(ctx).Transaction(ctx, f) diff --git a/internal/dao/internal/system_sms_log.go b/internal/dao/internal/system_sms_log.go index 11aee1a..f67db09 100644 --- a/internal/dao/internal/system_sms_log.go +++ b/internal/dao/internal/system_sms_log.go @@ -11,14 +11,15 @@ import ( "github.com/gogf/gf/v2/frame/g" ) -// SystemSmsLogDao is the data access object for table system_sms_log. +// SystemSmsLogDao is the data access object for the table system_sms_log. type SystemSmsLogDao struct { - table string // table is the underlying table name of the DAO. - group string // group is the database configuration group name of current DAO. - columns SystemSmsLogColumns // columns contains all the column names of Table for convenient usage. + table string // table is the underlying table name of the DAO. + group string // group is the database configuration group name of the current DAO. + columns SystemSmsLogColumns // columns contains all the column names of Table for convenient usage. + handlers []gdb.ModelHandler // handlers for customized model modification. } -// SystemSmsLogColumns defines and stores column names for table system_sms_log. +// SystemSmsLogColumns defines and stores column names for the table system_sms_log. type SystemSmsLogColumns struct { Id string // 编号 ChannelId string // 短信渠道编号 @@ -49,7 +50,7 @@ type SystemSmsLogColumns struct { Deleted string // 是否删除 } -// systemSmsLogColumns holds the columns for table system_sms_log. +// systemSmsLogColumns holds the columns for the table system_sms_log. var systemSmsLogColumns = SystemSmsLogColumns{ Id: "id", ChannelId: "channel_id", @@ -81,44 +82,49 @@ var systemSmsLogColumns = SystemSmsLogColumns{ } // NewSystemSmsLogDao creates and returns a new DAO object for table data access. -func NewSystemSmsLogDao() *SystemSmsLogDao { +func NewSystemSmsLogDao(handlers ...gdb.ModelHandler) *SystemSmsLogDao { return &SystemSmsLogDao{ - group: "default", - table: "system_sms_log", - columns: systemSmsLogColumns, + group: "default", + table: "system_sms_log", + columns: systemSmsLogColumns, + handlers: handlers, } } -// DB retrieves and returns the underlying raw database management object of current DAO. +// DB retrieves and returns the underlying raw database management object of the current DAO. func (dao *SystemSmsLogDao) DB() gdb.DB { return g.DB(dao.group) } -// Table returns the table name of current dao. +// Table returns the table name of the current DAO. func (dao *SystemSmsLogDao) Table() string { return dao.table } -// Columns returns all column names of current dao. +// Columns returns all column names of the current DAO. func (dao *SystemSmsLogDao) Columns() SystemSmsLogColumns { return dao.columns } -// Group returns the configuration group name of database of current dao. +// Group returns the database configuration group name of the current DAO. func (dao *SystemSmsLogDao) Group() string { return dao.group } -// Ctx creates and returns the Model for current DAO, It automatically sets the context for current operation. +// Ctx creates and returns a Model for the current DAO. It automatically sets the context for the current operation. func (dao *SystemSmsLogDao) Ctx(ctx context.Context) *gdb.Model { - return dao.DB().Model(dao.table).Safe().Ctx(ctx) + model := dao.DB().Model(dao.table) + for _, handler := range dao.handlers { + model = handler(model) + } + return model.Safe().Ctx(ctx) } // Transaction wraps the transaction logic using function f. -// It rollbacks the transaction and returns the error from function f if it returns non-nil error. +// It rolls back the transaction and returns the error if function f returns a non-nil error. // It commits the transaction and returns nil if function f returns nil. // -// Note that, you should not Commit or Rollback the transaction in function f +// Note: Do not commit or roll back the transaction in function f, // as it is automatically handled by this function. func (dao *SystemSmsLogDao) Transaction(ctx context.Context, f func(ctx context.Context, tx gdb.TX) error) (err error) { return dao.Ctx(ctx).Transaction(ctx, f) diff --git a/internal/dao/internal/system_sms_template.go b/internal/dao/internal/system_sms_template.go index 0576727..c2e71fe 100644 --- a/internal/dao/internal/system_sms_template.go +++ b/internal/dao/internal/system_sms_template.go @@ -11,14 +11,15 @@ import ( "github.com/gogf/gf/v2/frame/g" ) -// SystemSmsTemplateDao is the data access object for table system_sms_template. +// SystemSmsTemplateDao is the data access object for the table system_sms_template. type SystemSmsTemplateDao struct { - table string // table is the underlying table name of the DAO. - group string // group is the database configuration group name of current DAO. - columns SystemSmsTemplateColumns // columns contains all the column names of Table for convenient usage. + table string // table is the underlying table name of the DAO. + group string // group is the database configuration group name of the current DAO. + columns SystemSmsTemplateColumns // columns contains all the column names of Table for convenient usage. + handlers []gdb.ModelHandler // handlers for customized model modification. } -// SystemSmsTemplateColumns defines and stores column names for table system_sms_template. +// SystemSmsTemplateColumns defines and stores column names for the table system_sms_template. type SystemSmsTemplateColumns struct { Id string // 编号 Type string // 模板类型 @@ -38,7 +39,7 @@ type SystemSmsTemplateColumns struct { Deleted string // 是否删除 } -// systemSmsTemplateColumns holds the columns for table system_sms_template. +// systemSmsTemplateColumns holds the columns for the table system_sms_template. var systemSmsTemplateColumns = SystemSmsTemplateColumns{ Id: "id", Type: "type", @@ -59,44 +60,49 @@ var systemSmsTemplateColumns = SystemSmsTemplateColumns{ } // NewSystemSmsTemplateDao creates and returns a new DAO object for table data access. -func NewSystemSmsTemplateDao() *SystemSmsTemplateDao { +func NewSystemSmsTemplateDao(handlers ...gdb.ModelHandler) *SystemSmsTemplateDao { return &SystemSmsTemplateDao{ - group: "default", - table: "system_sms_template", - columns: systemSmsTemplateColumns, + group: "default", + table: "system_sms_template", + columns: systemSmsTemplateColumns, + handlers: handlers, } } -// DB retrieves and returns the underlying raw database management object of current DAO. +// DB retrieves and returns the underlying raw database management object of the current DAO. func (dao *SystemSmsTemplateDao) DB() gdb.DB { return g.DB(dao.group) } -// Table returns the table name of current dao. +// Table returns the table name of the current DAO. func (dao *SystemSmsTemplateDao) Table() string { return dao.table } -// Columns returns all column names of current dao. +// Columns returns all column names of the current DAO. func (dao *SystemSmsTemplateDao) Columns() SystemSmsTemplateColumns { return dao.columns } -// Group returns the configuration group name of database of current dao. +// Group returns the database configuration group name of the current DAO. func (dao *SystemSmsTemplateDao) Group() string { return dao.group } -// Ctx creates and returns the Model for current DAO, It automatically sets the context for current operation. +// Ctx creates and returns a Model for the current DAO. It automatically sets the context for the current operation. func (dao *SystemSmsTemplateDao) Ctx(ctx context.Context) *gdb.Model { - return dao.DB().Model(dao.table).Safe().Ctx(ctx) + model := dao.DB().Model(dao.table) + for _, handler := range dao.handlers { + model = handler(model) + } + return model.Safe().Ctx(ctx) } // Transaction wraps the transaction logic using function f. -// It rollbacks the transaction and returns the error from function f if it returns non-nil error. +// It rolls back the transaction and returns the error if function f returns a non-nil error. // It commits the transaction and returns nil if function f returns nil. // -// Note that, you should not Commit or Rollback the transaction in function f +// Note: Do not commit or roll back the transaction in function f, // as it is automatically handled by this function. func (dao *SystemSmsTemplateDao) Transaction(ctx context.Context, f func(ctx context.Context, tx gdb.TX) error) (err error) { return dao.Ctx(ctx).Transaction(ctx, f) diff --git a/internal/dao/internal/system_social_client.go b/internal/dao/internal/system_social_client.go index bd3bad4..61bdf7e 100644 --- a/internal/dao/internal/system_social_client.go +++ b/internal/dao/internal/system_social_client.go @@ -11,14 +11,15 @@ import ( "github.com/gogf/gf/v2/frame/g" ) -// SystemSocialClientDao is the data access object for table system_social_client. +// SystemSocialClientDao is the data access object for the table system_social_client. type SystemSocialClientDao struct { - table string // table is the underlying table name of the DAO. - group string // group is the database configuration group name of current DAO. - columns SystemSocialClientColumns // columns contains all the column names of Table for convenient usage. + table string // table is the underlying table name of the DAO. + group string // group is the database configuration group name of the current DAO. + columns SystemSocialClientColumns // columns contains all the column names of Table for convenient usage. + handlers []gdb.ModelHandler // handlers for customized model modification. } -// SystemSocialClientColumns defines and stores column names for table system_social_client. +// SystemSocialClientColumns defines and stores column names for the table system_social_client. type SystemSocialClientColumns struct { Id string // 编号 Name string // 应用名 @@ -36,7 +37,7 @@ type SystemSocialClientColumns struct { TenantId string // 租户编号 } -// systemSocialClientColumns holds the columns for table system_social_client. +// systemSocialClientColumns holds the columns for the table system_social_client. var systemSocialClientColumns = SystemSocialClientColumns{ Id: "id", Name: "name", @@ -55,44 +56,49 @@ var systemSocialClientColumns = SystemSocialClientColumns{ } // NewSystemSocialClientDao creates and returns a new DAO object for table data access. -func NewSystemSocialClientDao() *SystemSocialClientDao { +func NewSystemSocialClientDao(handlers ...gdb.ModelHandler) *SystemSocialClientDao { return &SystemSocialClientDao{ - group: "default", - table: "system_social_client", - columns: systemSocialClientColumns, + group: "default", + table: "system_social_client", + columns: systemSocialClientColumns, + handlers: handlers, } } -// DB retrieves and returns the underlying raw database management object of current DAO. +// DB retrieves and returns the underlying raw database management object of the current DAO. func (dao *SystemSocialClientDao) DB() gdb.DB { return g.DB(dao.group) } -// Table returns the table name of current dao. +// Table returns the table name of the current DAO. func (dao *SystemSocialClientDao) Table() string { return dao.table } -// Columns returns all column names of current dao. +// Columns returns all column names of the current DAO. func (dao *SystemSocialClientDao) Columns() SystemSocialClientColumns { return dao.columns } -// Group returns the configuration group name of database of current dao. +// Group returns the database configuration group name of the current DAO. func (dao *SystemSocialClientDao) Group() string { return dao.group } -// Ctx creates and returns the Model for current DAO, It automatically sets the context for current operation. +// Ctx creates and returns a Model for the current DAO. It automatically sets the context for the current operation. func (dao *SystemSocialClientDao) Ctx(ctx context.Context) *gdb.Model { - return dao.DB().Model(dao.table).Safe().Ctx(ctx) + model := dao.DB().Model(dao.table) + for _, handler := range dao.handlers { + model = handler(model) + } + return model.Safe().Ctx(ctx) } // Transaction wraps the transaction logic using function f. -// It rollbacks the transaction and returns the error from function f if it returns non-nil error. +// It rolls back the transaction and returns the error if function f returns a non-nil error. // It commits the transaction and returns nil if function f returns nil. // -// Note that, you should not Commit or Rollback the transaction in function f +// Note: Do not commit or roll back the transaction in function f, // as it is automatically handled by this function. func (dao *SystemSocialClientDao) Transaction(ctx context.Context, f func(ctx context.Context, tx gdb.TX) error) (err error) { return dao.Ctx(ctx).Transaction(ctx, f) diff --git a/internal/dao/internal/system_social_user.go b/internal/dao/internal/system_social_user.go index c79ad60..fd05175 100644 --- a/internal/dao/internal/system_social_user.go +++ b/internal/dao/internal/system_social_user.go @@ -11,14 +11,15 @@ import ( "github.com/gogf/gf/v2/frame/g" ) -// SystemSocialUserDao is the data access object for table system_social_user. +// SystemSocialUserDao is the data access object for the table system_social_user. type SystemSocialUserDao struct { - table string // table is the underlying table name of the DAO. - group string // group is the database configuration group name of current DAO. - columns SystemSocialUserColumns // columns contains all the column names of Table for convenient usage. + table string // table is the underlying table name of the DAO. + group string // group is the database configuration group name of the current DAO. + columns SystemSocialUserColumns // columns contains all the column names of Table for convenient usage. + handlers []gdb.ModelHandler // handlers for customized model modification. } -// SystemSocialUserColumns defines and stores column names for table system_social_user. +// SystemSocialUserColumns defines and stores column names for the table system_social_user. type SystemSocialUserColumns struct { Id string // 主键(自增策略) Type string // 社交平台的类型 @@ -38,7 +39,7 @@ type SystemSocialUserColumns struct { TenantId string // 租户编号 } -// systemSocialUserColumns holds the columns for table system_social_user. +// systemSocialUserColumns holds the columns for the table system_social_user. var systemSocialUserColumns = SystemSocialUserColumns{ Id: "id", Type: "type", @@ -59,44 +60,49 @@ var systemSocialUserColumns = SystemSocialUserColumns{ } // NewSystemSocialUserDao creates and returns a new DAO object for table data access. -func NewSystemSocialUserDao() *SystemSocialUserDao { +func NewSystemSocialUserDao(handlers ...gdb.ModelHandler) *SystemSocialUserDao { return &SystemSocialUserDao{ - group: "default", - table: "system_social_user", - columns: systemSocialUserColumns, + group: "default", + table: "system_social_user", + columns: systemSocialUserColumns, + handlers: handlers, } } -// DB retrieves and returns the underlying raw database management object of current DAO. +// DB retrieves and returns the underlying raw database management object of the current DAO. func (dao *SystemSocialUserDao) DB() gdb.DB { return g.DB(dao.group) } -// Table returns the table name of current dao. +// Table returns the table name of the current DAO. func (dao *SystemSocialUserDao) Table() string { return dao.table } -// Columns returns all column names of current dao. +// Columns returns all column names of the current DAO. func (dao *SystemSocialUserDao) Columns() SystemSocialUserColumns { return dao.columns } -// Group returns the configuration group name of database of current dao. +// Group returns the database configuration group name of the current DAO. func (dao *SystemSocialUserDao) Group() string { return dao.group } -// Ctx creates and returns the Model for current DAO, It automatically sets the context for current operation. +// Ctx creates and returns a Model for the current DAO. It automatically sets the context for the current operation. func (dao *SystemSocialUserDao) Ctx(ctx context.Context) *gdb.Model { - return dao.DB().Model(dao.table).Safe().Ctx(ctx) + model := dao.DB().Model(dao.table) + for _, handler := range dao.handlers { + model = handler(model) + } + return model.Safe().Ctx(ctx) } // Transaction wraps the transaction logic using function f. -// It rollbacks the transaction and returns the error from function f if it returns non-nil error. +// It rolls back the transaction and returns the error if function f returns a non-nil error. // It commits the transaction and returns nil if function f returns nil. // -// Note that, you should not Commit or Rollback the transaction in function f +// Note: Do not commit or roll back the transaction in function f, // as it is automatically handled by this function. func (dao *SystemSocialUserDao) Transaction(ctx context.Context, f func(ctx context.Context, tx gdb.TX) error) (err error) { return dao.Ctx(ctx).Transaction(ctx, f) diff --git a/internal/dao/internal/system_social_user_bind.go b/internal/dao/internal/system_social_user_bind.go index 682fa3a..e948b3d 100644 --- a/internal/dao/internal/system_social_user_bind.go +++ b/internal/dao/internal/system_social_user_bind.go @@ -11,14 +11,15 @@ import ( "github.com/gogf/gf/v2/frame/g" ) -// SystemSocialUserBindDao is the data access object for table system_social_user_bind. +// SystemSocialUserBindDao is the data access object for the table system_social_user_bind. type SystemSocialUserBindDao struct { - table string // table is the underlying table name of the DAO. - group string // group is the database configuration group name of current DAO. - columns SystemSocialUserBindColumns // columns contains all the column names of Table for convenient usage. + table string // table is the underlying table name of the DAO. + group string // group is the database configuration group name of the current DAO. + columns SystemSocialUserBindColumns // columns contains all the column names of Table for convenient usage. + handlers []gdb.ModelHandler // handlers for customized model modification. } -// SystemSocialUserBindColumns defines and stores column names for table system_social_user_bind. +// SystemSocialUserBindColumns defines and stores column names for the table system_social_user_bind. type SystemSocialUserBindColumns struct { Id string // 主键(自增策略) UserId string // 用户编号 @@ -33,7 +34,7 @@ type SystemSocialUserBindColumns struct { TenantId string // 租户编号 } -// systemSocialUserBindColumns holds the columns for table system_social_user_bind. +// systemSocialUserBindColumns holds the columns for the table system_social_user_bind. var systemSocialUserBindColumns = SystemSocialUserBindColumns{ Id: "id", UserId: "user_id", @@ -49,44 +50,49 @@ var systemSocialUserBindColumns = SystemSocialUserBindColumns{ } // NewSystemSocialUserBindDao creates and returns a new DAO object for table data access. -func NewSystemSocialUserBindDao() *SystemSocialUserBindDao { +func NewSystemSocialUserBindDao(handlers ...gdb.ModelHandler) *SystemSocialUserBindDao { return &SystemSocialUserBindDao{ - group: "default", - table: "system_social_user_bind", - columns: systemSocialUserBindColumns, + group: "default", + table: "system_social_user_bind", + columns: systemSocialUserBindColumns, + handlers: handlers, } } -// DB retrieves and returns the underlying raw database management object of current DAO. +// DB retrieves and returns the underlying raw database management object of the current DAO. func (dao *SystemSocialUserBindDao) DB() gdb.DB { return g.DB(dao.group) } -// Table returns the table name of current dao. +// Table returns the table name of the current DAO. func (dao *SystemSocialUserBindDao) Table() string { return dao.table } -// Columns returns all column names of current dao. +// Columns returns all column names of the current DAO. func (dao *SystemSocialUserBindDao) Columns() SystemSocialUserBindColumns { return dao.columns } -// Group returns the configuration group name of database of current dao. +// Group returns the database configuration group name of the current DAO. func (dao *SystemSocialUserBindDao) Group() string { return dao.group } -// Ctx creates and returns the Model for current DAO, It automatically sets the context for current operation. +// Ctx creates and returns a Model for the current DAO. It automatically sets the context for the current operation. func (dao *SystemSocialUserBindDao) Ctx(ctx context.Context) *gdb.Model { - return dao.DB().Model(dao.table).Safe().Ctx(ctx) + model := dao.DB().Model(dao.table) + for _, handler := range dao.handlers { + model = handler(model) + } + return model.Safe().Ctx(ctx) } // Transaction wraps the transaction logic using function f. -// It rollbacks the transaction and returns the error from function f if it returns non-nil error. +// It rolls back the transaction and returns the error if function f returns a non-nil error. // It commits the transaction and returns nil if function f returns nil. // -// Note that, you should not Commit or Rollback the transaction in function f +// Note: Do not commit or roll back the transaction in function f, // as it is automatically handled by this function. func (dao *SystemSocialUserBindDao) Transaction(ctx context.Context, f func(ctx context.Context, tx gdb.TX) error) (err error) { return dao.Ctx(ctx).Transaction(ctx, f) diff --git a/internal/dao/internal/system_tenant.go b/internal/dao/internal/system_tenant.go index 382c386..eec876e 100644 --- a/internal/dao/internal/system_tenant.go +++ b/internal/dao/internal/system_tenant.go @@ -11,14 +11,15 @@ import ( "github.com/gogf/gf/v2/frame/g" ) -// SystemTenantDao is the data access object for table system_tenant. +// SystemTenantDao is the data access object for the table system_tenant. type SystemTenantDao struct { - table string // table is the underlying table name of the DAO. - group string // group is the database configuration group name of current DAO. - columns SystemTenantColumns // columns contains all the column names of Table for convenient usage. + table string // table is the underlying table name of the DAO. + group string // group is the database configuration group name of the current DAO. + columns SystemTenantColumns // columns contains all the column names of Table for convenient usage. + handlers []gdb.ModelHandler // handlers for customized model modification. } -// SystemTenantColumns defines and stores column names for table system_tenant. +// SystemTenantColumns defines and stores column names for the table system_tenant. type SystemTenantColumns struct { Id string // 租户编号 Name string // 租户名 @@ -37,7 +38,7 @@ type SystemTenantColumns struct { Deleted string // 是否删除 } -// systemTenantColumns holds the columns for table system_tenant. +// systemTenantColumns holds the columns for the table system_tenant. var systemTenantColumns = SystemTenantColumns{ Id: "id", Name: "name", @@ -57,44 +58,49 @@ var systemTenantColumns = SystemTenantColumns{ } // NewSystemTenantDao creates and returns a new DAO object for table data access. -func NewSystemTenantDao() *SystemTenantDao { +func NewSystemTenantDao(handlers ...gdb.ModelHandler) *SystemTenantDao { return &SystemTenantDao{ - group: "default", - table: "system_tenant", - columns: systemTenantColumns, + group: "default", + table: "system_tenant", + columns: systemTenantColumns, + handlers: handlers, } } -// DB retrieves and returns the underlying raw database management object of current DAO. +// DB retrieves and returns the underlying raw database management object of the current DAO. func (dao *SystemTenantDao) DB() gdb.DB { return g.DB(dao.group) } -// Table returns the table name of current dao. +// Table returns the table name of the current DAO. func (dao *SystemTenantDao) Table() string { return dao.table } -// Columns returns all column names of current dao. +// Columns returns all column names of the current DAO. func (dao *SystemTenantDao) Columns() SystemTenantColumns { return dao.columns } -// Group returns the configuration group name of database of current dao. +// Group returns the database configuration group name of the current DAO. func (dao *SystemTenantDao) Group() string { return dao.group } -// Ctx creates and returns the Model for current DAO, It automatically sets the context for current operation. +// Ctx creates and returns a Model for the current DAO. It automatically sets the context for the current operation. func (dao *SystemTenantDao) Ctx(ctx context.Context) *gdb.Model { - return dao.DB().Model(dao.table).Safe().Ctx(ctx) + model := dao.DB().Model(dao.table) + for _, handler := range dao.handlers { + model = handler(model) + } + return model.Safe().Ctx(ctx) } // Transaction wraps the transaction logic using function f. -// It rollbacks the transaction and returns the error from function f if it returns non-nil error. +// It rolls back the transaction and returns the error if function f returns a non-nil error. // It commits the transaction and returns nil if function f returns nil. // -// Note that, you should not Commit or Rollback the transaction in function f +// Note: Do not commit or roll back the transaction in function f, // as it is automatically handled by this function. func (dao *SystemTenantDao) Transaction(ctx context.Context, f func(ctx context.Context, tx gdb.TX) error) (err error) { return dao.Ctx(ctx).Transaction(ctx, f) diff --git a/internal/dao/internal/system_tenant_package.go b/internal/dao/internal/system_tenant_package.go index cb4d9ba..97144e6 100644 --- a/internal/dao/internal/system_tenant_package.go +++ b/internal/dao/internal/system_tenant_package.go @@ -11,14 +11,15 @@ import ( "github.com/gogf/gf/v2/frame/g" ) -// SystemTenantPackageDao is the data access object for table system_tenant_package. +// SystemTenantPackageDao is the data access object for the table system_tenant_package. type SystemTenantPackageDao struct { - table string // table is the underlying table name of the DAO. - group string // group is the database configuration group name of current DAO. - columns SystemTenantPackageColumns // columns contains all the column names of Table for convenient usage. + table string // table is the underlying table name of the DAO. + group string // group is the database configuration group name of the current DAO. + columns SystemTenantPackageColumns // columns contains all the column names of Table for convenient usage. + handlers []gdb.ModelHandler // handlers for customized model modification. } -// SystemTenantPackageColumns defines and stores column names for table system_tenant_package. +// SystemTenantPackageColumns defines and stores column names for the table system_tenant_package. type SystemTenantPackageColumns struct { Id string // 套餐编号 Name string // 套餐名 @@ -32,7 +33,7 @@ type SystemTenantPackageColumns struct { Deleted string // 是否删除 } -// systemTenantPackageColumns holds the columns for table system_tenant_package. +// systemTenantPackageColumns holds the columns for the table system_tenant_package. var systemTenantPackageColumns = SystemTenantPackageColumns{ Id: "id", Name: "name", @@ -47,44 +48,49 @@ var systemTenantPackageColumns = SystemTenantPackageColumns{ } // NewSystemTenantPackageDao creates and returns a new DAO object for table data access. -func NewSystemTenantPackageDao() *SystemTenantPackageDao { +func NewSystemTenantPackageDao(handlers ...gdb.ModelHandler) *SystemTenantPackageDao { return &SystemTenantPackageDao{ - group: "default", - table: "system_tenant_package", - columns: systemTenantPackageColumns, + group: "default", + table: "system_tenant_package", + columns: systemTenantPackageColumns, + handlers: handlers, } } -// DB retrieves and returns the underlying raw database management object of current DAO. +// DB retrieves and returns the underlying raw database management object of the current DAO. func (dao *SystemTenantPackageDao) DB() gdb.DB { return g.DB(dao.group) } -// Table returns the table name of current dao. +// Table returns the table name of the current DAO. func (dao *SystemTenantPackageDao) Table() string { return dao.table } -// Columns returns all column names of current dao. +// Columns returns all column names of the current DAO. func (dao *SystemTenantPackageDao) Columns() SystemTenantPackageColumns { return dao.columns } -// Group returns the configuration group name of database of current dao. +// Group returns the database configuration group name of the current DAO. func (dao *SystemTenantPackageDao) Group() string { return dao.group } -// Ctx creates and returns the Model for current DAO, It automatically sets the context for current operation. +// Ctx creates and returns a Model for the current DAO. It automatically sets the context for the current operation. func (dao *SystemTenantPackageDao) Ctx(ctx context.Context) *gdb.Model { - return dao.DB().Model(dao.table).Safe().Ctx(ctx) + model := dao.DB().Model(dao.table) + for _, handler := range dao.handlers { + model = handler(model) + } + return model.Safe().Ctx(ctx) } // Transaction wraps the transaction logic using function f. -// It rollbacks the transaction and returns the error from function f if it returns non-nil error. +// It rolls back the transaction and returns the error if function f returns a non-nil error. // It commits the transaction and returns nil if function f returns nil. // -// Note that, you should not Commit or Rollback the transaction in function f +// Note: Do not commit or roll back the transaction in function f, // as it is automatically handled by this function. func (dao *SystemTenantPackageDao) Transaction(ctx context.Context, f func(ctx context.Context, tx gdb.TX) error) (err error) { return dao.Ctx(ctx).Transaction(ctx, f) diff --git a/internal/dao/internal/system_user_post.go b/internal/dao/internal/system_user_post.go index 5a85810..508ef37 100644 --- a/internal/dao/internal/system_user_post.go +++ b/internal/dao/internal/system_user_post.go @@ -11,14 +11,15 @@ import ( "github.com/gogf/gf/v2/frame/g" ) -// SystemUserPostDao is the data access object for table system_user_post. +// SystemUserPostDao is the data access object for the table system_user_post. type SystemUserPostDao struct { - table string // table is the underlying table name of the DAO. - group string // group is the database configuration group name of current DAO. - columns SystemUserPostColumns // columns contains all the column names of Table for convenient usage. + table string // table is the underlying table name of the DAO. + group string // group is the database configuration group name of the current DAO. + columns SystemUserPostColumns // columns contains all the column names of Table for convenient usage. + handlers []gdb.ModelHandler // handlers for customized model modification. } -// SystemUserPostColumns defines and stores column names for table system_user_post. +// SystemUserPostColumns defines and stores column names for the table system_user_post. type SystemUserPostColumns struct { Id string // id UserId string // 用户ID @@ -31,7 +32,7 @@ type SystemUserPostColumns struct { TenantId string // 租户编号 } -// systemUserPostColumns holds the columns for table system_user_post. +// systemUserPostColumns holds the columns for the table system_user_post. var systemUserPostColumns = SystemUserPostColumns{ Id: "id", UserId: "user_id", @@ -45,44 +46,49 @@ var systemUserPostColumns = SystemUserPostColumns{ } // NewSystemUserPostDao creates and returns a new DAO object for table data access. -func NewSystemUserPostDao() *SystemUserPostDao { +func NewSystemUserPostDao(handlers ...gdb.ModelHandler) *SystemUserPostDao { return &SystemUserPostDao{ - group: "default", - table: "system_user_post", - columns: systemUserPostColumns, + group: "default", + table: "system_user_post", + columns: systemUserPostColumns, + handlers: handlers, } } -// DB retrieves and returns the underlying raw database management object of current DAO. +// DB retrieves and returns the underlying raw database management object of the current DAO. func (dao *SystemUserPostDao) DB() gdb.DB { return g.DB(dao.group) } -// Table returns the table name of current dao. +// Table returns the table name of the current DAO. func (dao *SystemUserPostDao) Table() string { return dao.table } -// Columns returns all column names of current dao. +// Columns returns all column names of the current DAO. func (dao *SystemUserPostDao) Columns() SystemUserPostColumns { return dao.columns } -// Group returns the configuration group name of database of current dao. +// Group returns the database configuration group name of the current DAO. func (dao *SystemUserPostDao) Group() string { return dao.group } -// Ctx creates and returns the Model for current DAO, It automatically sets the context for current operation. +// Ctx creates and returns a Model for the current DAO. It automatically sets the context for the current operation. func (dao *SystemUserPostDao) Ctx(ctx context.Context) *gdb.Model { - return dao.DB().Model(dao.table).Safe().Ctx(ctx) + model := dao.DB().Model(dao.table) + for _, handler := range dao.handlers { + model = handler(model) + } + return model.Safe().Ctx(ctx) } // Transaction wraps the transaction logic using function f. -// It rollbacks the transaction and returns the error from function f if it returns non-nil error. +// It rolls back the transaction and returns the error if function f returns a non-nil error. // It commits the transaction and returns nil if function f returns nil. // -// Note that, you should not Commit or Rollback the transaction in function f +// Note: Do not commit or roll back the transaction in function f, // as it is automatically handled by this function. func (dao *SystemUserPostDao) Transaction(ctx context.Context, f func(ctx context.Context, tx gdb.TX) error) (err error) { return dao.Ctx(ctx).Transaction(ctx, f) diff --git a/internal/dao/internal/system_user_role.go b/internal/dao/internal/system_user_role.go index 85bf741..4f0b8ce 100644 --- a/internal/dao/internal/system_user_role.go +++ b/internal/dao/internal/system_user_role.go @@ -11,14 +11,15 @@ import ( "github.com/gogf/gf/v2/frame/g" ) -// SystemUserRoleDao is the data access object for table system_user_role. +// SystemUserRoleDao is the data access object for the table system_user_role. type SystemUserRoleDao struct { - table string // table is the underlying table name of the DAO. - group string // group is the database configuration group name of current DAO. - columns SystemUserRoleColumns // columns contains all the column names of Table for convenient usage. + table string // table is the underlying table name of the DAO. + group string // group is the database configuration group name of the current DAO. + columns SystemUserRoleColumns // columns contains all the column names of Table for convenient usage. + handlers []gdb.ModelHandler // handlers for customized model modification. } -// SystemUserRoleColumns defines and stores column names for table system_user_role. +// SystemUserRoleColumns defines and stores column names for the table system_user_role. type SystemUserRoleColumns struct { Id string // 自增编号 UserId string // 用户ID @@ -31,7 +32,7 @@ type SystemUserRoleColumns struct { TenantId string // 租户编号 } -// systemUserRoleColumns holds the columns for table system_user_role. +// systemUserRoleColumns holds the columns for the table system_user_role. var systemUserRoleColumns = SystemUserRoleColumns{ Id: "id", UserId: "user_id", @@ -45,44 +46,49 @@ var systemUserRoleColumns = SystemUserRoleColumns{ } // NewSystemUserRoleDao creates and returns a new DAO object for table data access. -func NewSystemUserRoleDao() *SystemUserRoleDao { +func NewSystemUserRoleDao(handlers ...gdb.ModelHandler) *SystemUserRoleDao { return &SystemUserRoleDao{ - group: "default", - table: "system_user_role", - columns: systemUserRoleColumns, + group: "default", + table: "system_user_role", + columns: systemUserRoleColumns, + handlers: handlers, } } -// DB retrieves and returns the underlying raw database management object of current DAO. +// DB retrieves and returns the underlying raw database management object of the current DAO. func (dao *SystemUserRoleDao) DB() gdb.DB { return g.DB(dao.group) } -// Table returns the table name of current dao. +// Table returns the table name of the current DAO. func (dao *SystemUserRoleDao) Table() string { return dao.table } -// Columns returns all column names of current dao. +// Columns returns all column names of the current DAO. func (dao *SystemUserRoleDao) Columns() SystemUserRoleColumns { return dao.columns } -// Group returns the configuration group name of database of current dao. +// Group returns the database configuration group name of the current DAO. func (dao *SystemUserRoleDao) Group() string { return dao.group } -// Ctx creates and returns the Model for current DAO, It automatically sets the context for current operation. +// Ctx creates and returns a Model for the current DAO. It automatically sets the context for the current operation. func (dao *SystemUserRoleDao) Ctx(ctx context.Context) *gdb.Model { - return dao.DB().Model(dao.table).Safe().Ctx(ctx) + model := dao.DB().Model(dao.table) + for _, handler := range dao.handlers { + model = handler(model) + } + return model.Safe().Ctx(ctx) } // Transaction wraps the transaction logic using function f. -// It rollbacks the transaction and returns the error from function f if it returns non-nil error. +// It rolls back the transaction and returns the error if function f returns a non-nil error. // It commits the transaction and returns nil if function f returns nil. // -// Note that, you should not Commit or Rollback the transaction in function f +// Note: Do not commit or roll back the transaction in function f, // as it is automatically handled by this function. func (dao *SystemUserRoleDao) Transaction(ctx context.Context, f func(ctx context.Context, tx gdb.TX) error) (err error) { return dao.Ctx(ctx).Transaction(ctx, f) diff --git a/internal/dao/internal/system_users.go b/internal/dao/internal/system_users.go index ebe2756..74c290b 100644 --- a/internal/dao/internal/system_users.go +++ b/internal/dao/internal/system_users.go @@ -11,14 +11,15 @@ import ( "github.com/gogf/gf/v2/frame/g" ) -// SystemUsersDao is the data access object for table system_users. +// SystemUsersDao is the data access object for the table system_users. type SystemUsersDao struct { - table string // table is the underlying table name of the DAO. - group string // group is the database configuration group name of current DAO. - columns SystemUsersColumns // columns contains all the column names of Table for convenient usage. + table string // table is the underlying table name of the DAO. + group string // group is the database configuration group name of the current DAO. + columns SystemUsersColumns // columns contains all the column names of Table for convenient usage. + handlers []gdb.ModelHandler // handlers for customized model modification. } -// SystemUsersColumns defines and stores column names for table system_users. +// SystemUsersColumns defines and stores column names for the table system_users. type SystemUsersColumns struct { Id string // 用户ID Username string // 用户账号 @@ -42,7 +43,7 @@ type SystemUsersColumns struct { TenantId string // 租户编号 } -// systemUsersColumns holds the columns for table system_users. +// systemUsersColumns holds the columns for the table system_users. var systemUsersColumns = SystemUsersColumns{ Id: "id", Username: "username", @@ -67,44 +68,49 @@ var systemUsersColumns = SystemUsersColumns{ } // NewSystemUsersDao creates and returns a new DAO object for table data access. -func NewSystemUsersDao() *SystemUsersDao { +func NewSystemUsersDao(handlers ...gdb.ModelHandler) *SystemUsersDao { return &SystemUsersDao{ - group: "default", - table: "system_users", - columns: systemUsersColumns, + group: "default", + table: "system_users", + columns: systemUsersColumns, + handlers: handlers, } } -// DB retrieves and returns the underlying raw database management object of current DAO. +// DB retrieves and returns the underlying raw database management object of the current DAO. func (dao *SystemUsersDao) DB() gdb.DB { return g.DB(dao.group) } -// Table returns the table name of current dao. +// Table returns the table name of the current DAO. func (dao *SystemUsersDao) Table() string { return dao.table } -// Columns returns all column names of current dao. +// Columns returns all column names of the current DAO. func (dao *SystemUsersDao) Columns() SystemUsersColumns { return dao.columns } -// Group returns the configuration group name of database of current dao. +// Group returns the database configuration group name of the current DAO. func (dao *SystemUsersDao) Group() string { return dao.group } -// Ctx creates and returns the Model for current DAO, It automatically sets the context for current operation. +// Ctx creates and returns a Model for the current DAO. It automatically sets the context for the current operation. func (dao *SystemUsersDao) Ctx(ctx context.Context) *gdb.Model { - return dao.DB().Model(dao.table).Safe().Ctx(ctx) + model := dao.DB().Model(dao.table) + for _, handler := range dao.handlers { + model = handler(model) + } + return model.Safe().Ctx(ctx) } // Transaction wraps the transaction logic using function f. -// It rollbacks the transaction and returns the error from function f if it returns non-nil error. +// It rolls back the transaction and returns the error if function f returns a non-nil error. // It commits the transaction and returns nil if function f returns nil. // -// Note that, you should not Commit or Rollback the transaction in function f +// Note: Do not commit or roll back the transaction in function f, // as it is automatically handled by this function. func (dao *SystemUsersDao) Transaction(ctx context.Context, f func(ctx context.Context, tx gdb.TX) error) (err error) { return dao.Ctx(ctx).Transaction(ctx, f) diff --git a/internal/dao/internal/yudao_demo_01_contact.go b/internal/dao/internal/yudao_demo_01_contact.go index 30bf149..29225e3 100644 --- a/internal/dao/internal/yudao_demo_01_contact.go +++ b/internal/dao/internal/yudao_demo_01_contact.go @@ -11,14 +11,15 @@ import ( "github.com/gogf/gf/v2/frame/g" ) -// YudaoDemo01ContactDao is the data access object for table yudao_demo01_contact. +// YudaoDemo01ContactDao is the data access object for the table yudao_demo01_contact. type YudaoDemo01ContactDao struct { - table string // table is the underlying table name of the DAO. - group string // group is the database configuration group name of current DAO. - columns YudaoDemo01ContactColumns // columns contains all the column names of Table for convenient usage. + table string // table is the underlying table name of the DAO. + group string // group is the database configuration group name of the current DAO. + columns YudaoDemo01ContactColumns // columns contains all the column names of Table for convenient usage. + handlers []gdb.ModelHandler // handlers for customized model modification. } -// YudaoDemo01ContactColumns defines and stores column names for table yudao_demo01_contact. +// YudaoDemo01ContactColumns defines and stores column names for the table yudao_demo01_contact. type YudaoDemo01ContactColumns struct { Id string // 编号 Name string // 名字 @@ -34,7 +35,7 @@ type YudaoDemo01ContactColumns struct { TenantId string // 租户编号 } -// yudaoDemo01ContactColumns holds the columns for table yudao_demo01_contact. +// yudaoDemo01ContactColumns holds the columns for the table yudao_demo01_contact. var yudaoDemo01ContactColumns = YudaoDemo01ContactColumns{ Id: "id", Name: "name", @@ -51,44 +52,49 @@ var yudaoDemo01ContactColumns = YudaoDemo01ContactColumns{ } // NewYudaoDemo01ContactDao creates and returns a new DAO object for table data access. -func NewYudaoDemo01ContactDao() *YudaoDemo01ContactDao { +func NewYudaoDemo01ContactDao(handlers ...gdb.ModelHandler) *YudaoDemo01ContactDao { return &YudaoDemo01ContactDao{ - group: "default", - table: "yudao_demo01_contact", - columns: yudaoDemo01ContactColumns, + group: "default", + table: "yudao_demo01_contact", + columns: yudaoDemo01ContactColumns, + handlers: handlers, } } -// DB retrieves and returns the underlying raw database management object of current DAO. +// DB retrieves and returns the underlying raw database management object of the current DAO. func (dao *YudaoDemo01ContactDao) DB() gdb.DB { return g.DB(dao.group) } -// Table returns the table name of current dao. +// Table returns the table name of the current DAO. func (dao *YudaoDemo01ContactDao) Table() string { return dao.table } -// Columns returns all column names of current dao. +// Columns returns all column names of the current DAO. func (dao *YudaoDemo01ContactDao) Columns() YudaoDemo01ContactColumns { return dao.columns } -// Group returns the configuration group name of database of current dao. +// Group returns the database configuration group name of the current DAO. func (dao *YudaoDemo01ContactDao) Group() string { return dao.group } -// Ctx creates and returns the Model for current DAO, It automatically sets the context for current operation. +// Ctx creates and returns a Model for the current DAO. It automatically sets the context for the current operation. func (dao *YudaoDemo01ContactDao) Ctx(ctx context.Context) *gdb.Model { - return dao.DB().Model(dao.table).Safe().Ctx(ctx) + model := dao.DB().Model(dao.table) + for _, handler := range dao.handlers { + model = handler(model) + } + return model.Safe().Ctx(ctx) } // Transaction wraps the transaction logic using function f. -// It rollbacks the transaction and returns the error from function f if it returns non-nil error. +// It rolls back the transaction and returns the error if function f returns a non-nil error. // It commits the transaction and returns nil if function f returns nil. // -// Note that, you should not Commit or Rollback the transaction in function f +// Note: Do not commit or roll back the transaction in function f, // as it is automatically handled by this function. func (dao *YudaoDemo01ContactDao) Transaction(ctx context.Context, f func(ctx context.Context, tx gdb.TX) error) (err error) { return dao.Ctx(ctx).Transaction(ctx, f) diff --git a/internal/dao/internal/yudao_demo_02_category.go b/internal/dao/internal/yudao_demo_02_category.go index 6fcdf82..1602156 100644 --- a/internal/dao/internal/yudao_demo_02_category.go +++ b/internal/dao/internal/yudao_demo_02_category.go @@ -11,14 +11,15 @@ import ( "github.com/gogf/gf/v2/frame/g" ) -// YudaoDemo02CategoryDao is the data access object for table yudao_demo02_category. +// YudaoDemo02CategoryDao is the data access object for the table yudao_demo02_category. type YudaoDemo02CategoryDao struct { - table string // table is the underlying table name of the DAO. - group string // group is the database configuration group name of current DAO. - columns YudaoDemo02CategoryColumns // columns contains all the column names of Table for convenient usage. + table string // table is the underlying table name of the DAO. + group string // group is the database configuration group name of the current DAO. + columns YudaoDemo02CategoryColumns // columns contains all the column names of Table for convenient usage. + handlers []gdb.ModelHandler // handlers for customized model modification. } -// YudaoDemo02CategoryColumns defines and stores column names for table yudao_demo02_category. +// YudaoDemo02CategoryColumns defines and stores column names for the table yudao_demo02_category. type YudaoDemo02CategoryColumns struct { Id string // 编号 Name string // 名字 @@ -31,7 +32,7 @@ type YudaoDemo02CategoryColumns struct { TenantId string // 租户编号 } -// yudaoDemo02CategoryColumns holds the columns for table yudao_demo02_category. +// yudaoDemo02CategoryColumns holds the columns for the table yudao_demo02_category. var yudaoDemo02CategoryColumns = YudaoDemo02CategoryColumns{ Id: "id", Name: "name", @@ -45,44 +46,49 @@ var yudaoDemo02CategoryColumns = YudaoDemo02CategoryColumns{ } // NewYudaoDemo02CategoryDao creates and returns a new DAO object for table data access. -func NewYudaoDemo02CategoryDao() *YudaoDemo02CategoryDao { +func NewYudaoDemo02CategoryDao(handlers ...gdb.ModelHandler) *YudaoDemo02CategoryDao { return &YudaoDemo02CategoryDao{ - group: "default", - table: "yudao_demo02_category", - columns: yudaoDemo02CategoryColumns, + group: "default", + table: "yudao_demo02_category", + columns: yudaoDemo02CategoryColumns, + handlers: handlers, } } -// DB retrieves and returns the underlying raw database management object of current DAO. +// DB retrieves and returns the underlying raw database management object of the current DAO. func (dao *YudaoDemo02CategoryDao) DB() gdb.DB { return g.DB(dao.group) } -// Table returns the table name of current dao. +// Table returns the table name of the current DAO. func (dao *YudaoDemo02CategoryDao) Table() string { return dao.table } -// Columns returns all column names of current dao. +// Columns returns all column names of the current DAO. func (dao *YudaoDemo02CategoryDao) Columns() YudaoDemo02CategoryColumns { return dao.columns } -// Group returns the configuration group name of database of current dao. +// Group returns the database configuration group name of the current DAO. func (dao *YudaoDemo02CategoryDao) Group() string { return dao.group } -// Ctx creates and returns the Model for current DAO, It automatically sets the context for current operation. +// Ctx creates and returns a Model for the current DAO. It automatically sets the context for the current operation. func (dao *YudaoDemo02CategoryDao) Ctx(ctx context.Context) *gdb.Model { - return dao.DB().Model(dao.table).Safe().Ctx(ctx) + model := dao.DB().Model(dao.table) + for _, handler := range dao.handlers { + model = handler(model) + } + return model.Safe().Ctx(ctx) } // Transaction wraps the transaction logic using function f. -// It rollbacks the transaction and returns the error from function f if it returns non-nil error. +// It rolls back the transaction and returns the error if function f returns a non-nil error. // It commits the transaction and returns nil if function f returns nil. // -// Note that, you should not Commit or Rollback the transaction in function f +// Note: Do not commit or roll back the transaction in function f, // as it is automatically handled by this function. func (dao *YudaoDemo02CategoryDao) Transaction(ctx context.Context, f func(ctx context.Context, tx gdb.TX) error) (err error) { return dao.Ctx(ctx).Transaction(ctx, f) diff --git a/internal/dao/internal/yudao_demo_03_course.go b/internal/dao/internal/yudao_demo_03_course.go index 6d6eec4..adbca80 100644 --- a/internal/dao/internal/yudao_demo_03_course.go +++ b/internal/dao/internal/yudao_demo_03_course.go @@ -11,14 +11,15 @@ import ( "github.com/gogf/gf/v2/frame/g" ) -// YudaoDemo03CourseDao is the data access object for table yudao_demo03_course. +// YudaoDemo03CourseDao is the data access object for the table yudao_demo03_course. type YudaoDemo03CourseDao struct { - table string // table is the underlying table name of the DAO. - group string // group is the database configuration group name of current DAO. - columns YudaoDemo03CourseColumns // columns contains all the column names of Table for convenient usage. + table string // table is the underlying table name of the DAO. + group string // group is the database configuration group name of the current DAO. + columns YudaoDemo03CourseColumns // columns contains all the column names of Table for convenient usage. + handlers []gdb.ModelHandler // handlers for customized model modification. } -// YudaoDemo03CourseColumns defines and stores column names for table yudao_demo03_course. +// YudaoDemo03CourseColumns defines and stores column names for the table yudao_demo03_course. type YudaoDemo03CourseColumns struct { Id string // 编号 StudentId string // 学生编号 @@ -32,7 +33,7 @@ type YudaoDemo03CourseColumns struct { TenantId string // 租户编号 } -// yudaoDemo03CourseColumns holds the columns for table yudao_demo03_course. +// yudaoDemo03CourseColumns holds the columns for the table yudao_demo03_course. var yudaoDemo03CourseColumns = YudaoDemo03CourseColumns{ Id: "id", StudentId: "student_id", @@ -47,44 +48,49 @@ var yudaoDemo03CourseColumns = YudaoDemo03CourseColumns{ } // NewYudaoDemo03CourseDao creates and returns a new DAO object for table data access. -func NewYudaoDemo03CourseDao() *YudaoDemo03CourseDao { +func NewYudaoDemo03CourseDao(handlers ...gdb.ModelHandler) *YudaoDemo03CourseDao { return &YudaoDemo03CourseDao{ - group: "default", - table: "yudao_demo03_course", - columns: yudaoDemo03CourseColumns, + group: "default", + table: "yudao_demo03_course", + columns: yudaoDemo03CourseColumns, + handlers: handlers, } } -// DB retrieves and returns the underlying raw database management object of current DAO. +// DB retrieves and returns the underlying raw database management object of the current DAO. func (dao *YudaoDemo03CourseDao) DB() gdb.DB { return g.DB(dao.group) } -// Table returns the table name of current dao. +// Table returns the table name of the current DAO. func (dao *YudaoDemo03CourseDao) Table() string { return dao.table } -// Columns returns all column names of current dao. +// Columns returns all column names of the current DAO. func (dao *YudaoDemo03CourseDao) Columns() YudaoDemo03CourseColumns { return dao.columns } -// Group returns the configuration group name of database of current dao. +// Group returns the database configuration group name of the current DAO. func (dao *YudaoDemo03CourseDao) Group() string { return dao.group } -// Ctx creates and returns the Model for current DAO, It automatically sets the context for current operation. +// Ctx creates and returns a Model for the current DAO. It automatically sets the context for the current operation. func (dao *YudaoDemo03CourseDao) Ctx(ctx context.Context) *gdb.Model { - return dao.DB().Model(dao.table).Safe().Ctx(ctx) + model := dao.DB().Model(dao.table) + for _, handler := range dao.handlers { + model = handler(model) + } + return model.Safe().Ctx(ctx) } // Transaction wraps the transaction logic using function f. -// It rollbacks the transaction and returns the error from function f if it returns non-nil error. +// It rolls back the transaction and returns the error if function f returns a non-nil error. // It commits the transaction and returns nil if function f returns nil. // -// Note that, you should not Commit or Rollback the transaction in function f +// Note: Do not commit or roll back the transaction in function f, // as it is automatically handled by this function. func (dao *YudaoDemo03CourseDao) Transaction(ctx context.Context, f func(ctx context.Context, tx gdb.TX) error) (err error) { return dao.Ctx(ctx).Transaction(ctx, f) diff --git a/internal/dao/internal/yudao_demo_03_grade.go b/internal/dao/internal/yudao_demo_03_grade.go index fbc495b..16d2c9d 100644 --- a/internal/dao/internal/yudao_demo_03_grade.go +++ b/internal/dao/internal/yudao_demo_03_grade.go @@ -11,14 +11,15 @@ import ( "github.com/gogf/gf/v2/frame/g" ) -// YudaoDemo03GradeDao is the data access object for table yudao_demo03_grade. +// YudaoDemo03GradeDao is the data access object for the table yudao_demo03_grade. type YudaoDemo03GradeDao struct { - table string // table is the underlying table name of the DAO. - group string // group is the database configuration group name of current DAO. - columns YudaoDemo03GradeColumns // columns contains all the column names of Table for convenient usage. + table string // table is the underlying table name of the DAO. + group string // group is the database configuration group name of the current DAO. + columns YudaoDemo03GradeColumns // columns contains all the column names of Table for convenient usage. + handlers []gdb.ModelHandler // handlers for customized model modification. } -// YudaoDemo03GradeColumns defines and stores column names for table yudao_demo03_grade. +// YudaoDemo03GradeColumns defines and stores column names for the table yudao_demo03_grade. type YudaoDemo03GradeColumns struct { Id string // 编号 StudentId string // 学生编号 @@ -32,7 +33,7 @@ type YudaoDemo03GradeColumns struct { TenantId string // 租户编号 } -// yudaoDemo03GradeColumns holds the columns for table yudao_demo03_grade. +// yudaoDemo03GradeColumns holds the columns for the table yudao_demo03_grade. var yudaoDemo03GradeColumns = YudaoDemo03GradeColumns{ Id: "id", StudentId: "student_id", @@ -47,44 +48,49 @@ var yudaoDemo03GradeColumns = YudaoDemo03GradeColumns{ } // NewYudaoDemo03GradeDao creates and returns a new DAO object for table data access. -func NewYudaoDemo03GradeDao() *YudaoDemo03GradeDao { +func NewYudaoDemo03GradeDao(handlers ...gdb.ModelHandler) *YudaoDemo03GradeDao { return &YudaoDemo03GradeDao{ - group: "default", - table: "yudao_demo03_grade", - columns: yudaoDemo03GradeColumns, + group: "default", + table: "yudao_demo03_grade", + columns: yudaoDemo03GradeColumns, + handlers: handlers, } } -// DB retrieves and returns the underlying raw database management object of current DAO. +// DB retrieves and returns the underlying raw database management object of the current DAO. func (dao *YudaoDemo03GradeDao) DB() gdb.DB { return g.DB(dao.group) } -// Table returns the table name of current dao. +// Table returns the table name of the current DAO. func (dao *YudaoDemo03GradeDao) Table() string { return dao.table } -// Columns returns all column names of current dao. +// Columns returns all column names of the current DAO. func (dao *YudaoDemo03GradeDao) Columns() YudaoDemo03GradeColumns { return dao.columns } -// Group returns the configuration group name of database of current dao. +// Group returns the database configuration group name of the current DAO. func (dao *YudaoDemo03GradeDao) Group() string { return dao.group } -// Ctx creates and returns the Model for current DAO, It automatically sets the context for current operation. +// Ctx creates and returns a Model for the current DAO. It automatically sets the context for the current operation. func (dao *YudaoDemo03GradeDao) Ctx(ctx context.Context) *gdb.Model { - return dao.DB().Model(dao.table).Safe().Ctx(ctx) + model := dao.DB().Model(dao.table) + for _, handler := range dao.handlers { + model = handler(model) + } + return model.Safe().Ctx(ctx) } // Transaction wraps the transaction logic using function f. -// It rollbacks the transaction and returns the error from function f if it returns non-nil error. +// It rolls back the transaction and returns the error if function f returns a non-nil error. // It commits the transaction and returns nil if function f returns nil. // -// Note that, you should not Commit or Rollback the transaction in function f +// Note: Do not commit or roll back the transaction in function f, // as it is automatically handled by this function. func (dao *YudaoDemo03GradeDao) Transaction(ctx context.Context, f func(ctx context.Context, tx gdb.TX) error) (err error) { return dao.Ctx(ctx).Transaction(ctx, f) diff --git a/internal/dao/internal/yudao_demo_03_student.go b/internal/dao/internal/yudao_demo_03_student.go index ede3199..4c8a272 100644 --- a/internal/dao/internal/yudao_demo_03_student.go +++ b/internal/dao/internal/yudao_demo_03_student.go @@ -11,14 +11,15 @@ import ( "github.com/gogf/gf/v2/frame/g" ) -// YudaoDemo03StudentDao is the data access object for table yudao_demo03_student. +// YudaoDemo03StudentDao is the data access object for the table yudao_demo03_student. type YudaoDemo03StudentDao struct { - table string // table is the underlying table name of the DAO. - group string // group is the database configuration group name of current DAO. - columns YudaoDemo03StudentColumns // columns contains all the column names of Table for convenient usage. + table string // table is the underlying table name of the DAO. + group string // group is the database configuration group name of the current DAO. + columns YudaoDemo03StudentColumns // columns contains all the column names of Table for convenient usage. + handlers []gdb.ModelHandler // handlers for customized model modification. } -// YudaoDemo03StudentColumns defines and stores column names for table yudao_demo03_student. +// YudaoDemo03StudentColumns defines and stores column names for the table yudao_demo03_student. type YudaoDemo03StudentColumns struct { Id string // 编号 Name string // 名字 @@ -33,7 +34,7 @@ type YudaoDemo03StudentColumns struct { TenantId string // 租户编号 } -// yudaoDemo03StudentColumns holds the columns for table yudao_demo03_student. +// yudaoDemo03StudentColumns holds the columns for the table yudao_demo03_student. var yudaoDemo03StudentColumns = YudaoDemo03StudentColumns{ Id: "id", Name: "name", @@ -49,44 +50,49 @@ var yudaoDemo03StudentColumns = YudaoDemo03StudentColumns{ } // NewYudaoDemo03StudentDao creates and returns a new DAO object for table data access. -func NewYudaoDemo03StudentDao() *YudaoDemo03StudentDao { +func NewYudaoDemo03StudentDao(handlers ...gdb.ModelHandler) *YudaoDemo03StudentDao { return &YudaoDemo03StudentDao{ - group: "default", - table: "yudao_demo03_student", - columns: yudaoDemo03StudentColumns, + group: "default", + table: "yudao_demo03_student", + columns: yudaoDemo03StudentColumns, + handlers: handlers, } } -// DB retrieves and returns the underlying raw database management object of current DAO. +// DB retrieves and returns the underlying raw database management object of the current DAO. func (dao *YudaoDemo03StudentDao) DB() gdb.DB { return g.DB(dao.group) } -// Table returns the table name of current dao. +// Table returns the table name of the current DAO. func (dao *YudaoDemo03StudentDao) Table() string { return dao.table } -// Columns returns all column names of current dao. +// Columns returns all column names of the current DAO. func (dao *YudaoDemo03StudentDao) Columns() YudaoDemo03StudentColumns { return dao.columns } -// Group returns the configuration group name of database of current dao. +// Group returns the database configuration group name of the current DAO. func (dao *YudaoDemo03StudentDao) Group() string { return dao.group } -// Ctx creates and returns the Model for current DAO, It automatically sets the context for current operation. +// Ctx creates and returns a Model for the current DAO. It automatically sets the context for the current operation. func (dao *YudaoDemo03StudentDao) Ctx(ctx context.Context) *gdb.Model { - return dao.DB().Model(dao.table).Safe().Ctx(ctx) + model := dao.DB().Model(dao.table) + for _, handler := range dao.handlers { + model = handler(model) + } + return model.Safe().Ctx(ctx) } // Transaction wraps the transaction logic using function f. -// It rollbacks the transaction and returns the error from function f if it returns non-nil error. +// It rolls back the transaction and returns the error if function f returns a non-nil error. // It commits the transaction and returns nil if function f returns nil. // -// Note that, you should not Commit or Rollback the transaction in function f +// Note: Do not commit or roll back the transaction in function f, // as it is automatically handled by this function. func (dao *YudaoDemo03StudentDao) Transaction(ctx context.Context, f func(ctx context.Context, tx gdb.TX) error) (err error) { return dao.Ctx(ctx).Transaction(ctx, f) diff --git a/internal/logic/cron/cron.go b/internal/logic/cron/cron.go index c543a9c..8ed19ad 100644 --- a/internal/logic/cron/cron.go +++ b/internal/logic/cron/cron.go @@ -3,6 +3,7 @@ package cron import ( "context" "epic/internal/dao" + "epic/internal/logic/i18n" "epic/internal/model/entity" "epic/internal/service" "epic/internal/util" @@ -173,13 +174,6 @@ func (l *Logic) registerDefaultJobs(ctx context.Context) error { return err } - // 每30分钟执行一次OSS预签名URL缓存刷新任务 - //if err := l.AddJob(ctx, "oss_presignurl_refresh", "0 0/30 * * * *", func() { - // l.refreshOssPresignUrlCacheJob(ctx) - //}); err != nil { - // return err - //} - // 每5天执行一次角色配装信息刷新任务 if err := l.AddJob(ctx, "hero_set_refresh_5days", "0 0 0 */5 * *", func() { l.refreshHeroSetContent(ctx) @@ -187,6 +181,18 @@ func (l *Logic) registerDefaultJobs(ctx context.Context) error { return err } + // 每天凌晨2点同步i18n远程翻译数据 + if err := l.AddJob(ctx, "i18n_remote_sync", "0 0 2 * * *", func() { + g.Log().Info(ctx, "开始同步i18n远程翻译数据...") + if err := i18n.GetI18nLogic().SyncI18nFromRemote(ctx); err != nil { + g.Log().Error(ctx, "i18n远程翻译数据同步失败:", err) + } else { + g.Log().Info(ctx, "i18n远程翻译数据同步完成") + } + }); err != nil { + return err + } + return nil } @@ -203,7 +209,7 @@ func (l *Logic) syncDataFromThirdParty(ctx context.Context) { g.Log().Info(ctx, "Data sync completed") } -//同步英雄数据 +// 同步英雄数据 func (l *Logic) syncHeroData(ctx context.Context) { g.Log().Info(ctx, "Starting hero data sync...") @@ -215,7 +221,7 @@ func (l *Logic) syncHeroData(ctx context.Context) { g.Log().Info(ctx, "Hero data sync completed") } -//同步神器数据 +// 同步神器数据 func (l *Logic) syncArtifactData(ctx context.Context) { g.Log().Info(ctx, "Starting artifact data sync...") diff --git a/internal/logic/cron/third_party_sync.go b/internal/logic/cron/third_party_sync.go index 4586a0f..d0c9fdf 100644 --- a/internal/logic/cron/third_party_sync.go +++ b/internal/logic/cron/third_party_sync.go @@ -732,3 +732,77 @@ func max(a, b int) int { } return b } + +// 修复历史数据,将epic_hero_info.hero_name和epic_artifact_info.artifact_name翻译为中文(基于code匹配) +func FixHeroAndArtifactNameToChinese(ctx context.Context) error { + // 1. 查询i18n hero映射(code->zh) + var heroMappings []*entity.EpicI18NMappings + err := dao.EpicI18NMappings.Ctx(ctx). + Where(dao.EpicI18NMappings.Columns().Language, "zh"). + Where(dao.EpicI18NMappings.Columns().Category, "hero"). + Where(dao.EpicI18NMappings.Columns().Status, 1). + Where(dao.EpicI18NMappings.Columns().Deleted, 0). + Scan(&heroMappings) + if err != nil { + return fmt.Errorf("查询i18n hero映射失败: %v", err) + } + heroCodeToZh := make(map[string]string) + for _, m := range heroMappings { + heroCodeToZh[m.Code] = m.Value + } + + // 2. 修复英雄表 + var heroes []*entity.EpicHeroInfo + err = dao.EpicHeroInfo.Ctx(ctx).Scan(&heroes) + if err != nil { + return fmt.Errorf("查询epic_hero_info失败: %v", err) + } + for _, h := range heroes { + if zh, ok := heroCodeToZh[h.HeroCode]; ok && zh != "" && zh != h.HeroName { + _, err := dao.EpicHeroInfo.Ctx(ctx). + Where(dao.EpicHeroInfo.Columns().HeroCode, h.HeroCode). + Data(g.Map{dao.EpicHeroInfo.Columns().HeroName: zh}). + Update() + if err != nil { + g.Log().Errorf(ctx, "更新英雄中文名失败: %s(%s) -> %s, err: %v", h.HeroName, h.HeroCode, zh, err) + } + } + } + g.Log().Info(ctx, "epic_hero_info英雄名修复完成") + + // 3. 查询i18n artifact映射(code->zh) + var artifactMappings []*entity.EpicI18NMappings + err = dao.EpicI18NMappings.Ctx(ctx). + Where(dao.EpicI18NMappings.Columns().Language, "zh"). + Where(dao.EpicI18NMappings.Columns().Category, "artifact"). + Where(dao.EpicI18NMappings.Columns().Status, 1). + Where(dao.EpicI18NMappings.Columns().Deleted, 0). + Scan(&artifactMappings) + if err != nil { + return fmt.Errorf("查询i18n artifact映射失败: %v", err) + } + artifactCodeToZh := make(map[string]string) + for _, m := range artifactMappings { + artifactCodeToZh[m.Code] = m.Value + } + + // 4. 修复神器表 + var artifacts []*entity.EpicArtifactInfo + err = dao.EpicArtifactInfo.Ctx(ctx).Scan(&artifacts) + if err != nil { + return fmt.Errorf("查询epic_artifact_info失败: %v", err) + } + for _, a := range artifacts { + if zh, ok := artifactCodeToZh[a.ArtifactCode]; ok && zh != "" && zh != a.ArtifactName { + _, err := dao.EpicArtifactInfo.Ctx(ctx). + Where(dao.EpicArtifactInfo.Columns().ArtifactCode, a.ArtifactCode). + Data(g.Map{dao.EpicArtifactInfo.Columns().ArtifactName: zh}). + Update() + if err != nil { + g.Log().Errorf(ctx, "更新神器中文名失败: %s(%s) -> %s, err: %v", a.ArtifactName, a.ArtifactCode, zh, err) + } + } + } + g.Log().Info(ctx, "epic_artifact_info神器名修复完成") + return nil +} diff --git a/internal/logic/cron/third_party_sync_test.go b/internal/logic/cron/third_party_sync_test.go index e687da4..4a8c93c 100644 --- a/internal/logic/cron/third_party_sync_test.go +++ b/internal/logic/cron/third_party_sync_test.go @@ -67,3 +67,22 @@ func TestInitI18nStaticToDB(t *testing.T) { } t.Logf("静态i18n数据导入成功,共%d条", len(i18n.I18nEnToZh)) } + +func TestSyncI18nFromRemote(t *testing.T) { + ctx := context.Background() + logic := i18n.GetI18nLogic() + err := logic.SyncI18nFromRemote(ctx) + if err != nil { + t.Fatalf("远程i18n数据同步失败: %v", err) + } + t.Logf("远程i18n数据同步成功") +} + +func TestFixHeroAndArtifactNameToChinese(t *testing.T) { + ctx := context.Background() + err := FixHeroAndArtifactNameToChinese(ctx) + if err != nil { + t.Fatalf("修复英雄/神器中文名失败: %v", err) + } + t.Logf("修复英雄/神器中文名成功") +} diff --git a/internal/logic/i18n/i18n.go b/internal/logic/i18n/i18n.go index 6f8c802..4732267 100644 --- a/internal/logic/i18n/i18n.go +++ b/internal/logic/i18n/i18n.go @@ -2,11 +2,14 @@ package i18n import ( "context" + "epic/internal/consts" "epic/internal/dao" "epic/internal/model/entity" "epic/internal/util" "fmt" + "github.com/gogf/gf/v2/encoding/gjson" "github.com/gogf/gf/v2/frame/g" + "github.com/gogf/gf/v2/net/gclient" "github.com/gogf/gf/v2/os/gtime" "sync" "time" @@ -603,14 +606,22 @@ var I18nZhToEn = func() map[string]string { return m }() +// Logic i18n主逻辑结构体 +// cache结构调整:lang -> { code -> value, key -> value } type Logic struct { - cache map[string]map[string]string // lang -> key -> value + cache map[string]struct { + ByCode map[string]string // code->value + ByKey map[string]string // key->value + } mutex sync.RWMutex } func New() *Logic { return &Logic{ - cache: make(map[string]map[string]string), + cache: make(map[string]struct { + ByCode map[string]string + ByKey map[string]string + }), } } @@ -645,16 +656,24 @@ func (l *Logic) LoadFromDB(ctx context.Context) error { defer l.mutex.Unlock() // 重新构建缓存 - l.cache = make(map[string]map[string]string) - // 新增:同步数据库内容到I18nEnToZh和I18nZhToEn备份 + l.cache = make(map[string]struct { + ByCode map[string]string + ByKey map[string]string + }) for _, m := range mappings { - if l.cache[m.Language] == nil { - l.cache[m.Language] = make(map[string]string) + if l.cache[m.Language].ByCode == nil { + l.cache[m.Language] = struct { + ByCode map[string]string + ByKey map[string]string + }{ByCode: make(map[string]string), ByKey: make(map[string]string)} } - l.cache[m.Language][m.KeyName] = m.Value + if m.Code != "" { + l.cache[m.Language].ByCode[m.Code] = m.Value + } + l.cache[m.Language].ByKey[m.KeyName] = m.Value if m.Language == "zh" { I18nEnToZh[m.KeyName] = m.Value - I18nZhToEn[m.Value] = m.KeyName // 新增:同步反向映射 + I18nZhToEn[m.Value] = m.KeyName } } @@ -662,13 +681,19 @@ func (l *Logic) LoadFromDB(ctx context.Context) error { return nil } -// Get 获取指定key的指定语言翻译 -func (l *Logic) Get(ctx context.Context, lang, key string) string { +// Get 获取指定key/code的指定语言翻译 +func (l *Logic) Get(ctx context.Context, lang, key string, code ...string) string { l.mutex.RLock() defer l.mutex.RUnlock() - + if len(code) > 0 && code[0] != "" { + if m, ok := l.cache[lang]; ok { + if v, ok := m.ByCode[code[0]]; ok { + return v + } + } + } if m, ok := l.cache[lang]; ok { - if v, ok := m[key]; ok { + if v, ok := m.ByKey[key]; ok { return v } } @@ -683,7 +708,7 @@ func (l *Logic) GetBatch(ctx context.Context, lang string, keys []string) map[st result := make(map[string]string) if m, ok := l.cache[lang]; ok { for _, key := range keys { - if v, ok := m[key]; ok { + if v, ok := m.ByKey[key]; ok { result[key] = v } else { result[key] = key // 找不到返回原文 @@ -724,10 +749,16 @@ func (l *Logic) Add(ctx context.Context, key, lang, value, category string) erro l.mutex.Lock() defer l.mutex.Unlock() - if l.cache[lang] == nil { - l.cache[lang] = make(map[string]string) + if _, exists := l.cache[lang]; !exists { + l.cache[lang] = struct { + ByCode map[string]string + ByKey map[string]string + }{ + ByCode: make(map[string]string), + ByKey: make(map[string]string), + } } - l.cache[lang][key] = value + l.cache[lang].ByKey[key] = value util.Info(ctx, "添加翻译:", lang, key, "->", value) return nil @@ -752,10 +783,16 @@ func (l *Logic) Update(ctx context.Context, key, lang, value string) error { l.mutex.Lock() defer l.mutex.Unlock() - if l.cache[lang] == nil { - l.cache[lang] = make(map[string]string) + if _, exists := l.cache[lang]; !exists { + l.cache[lang] = struct { + ByCode map[string]string + ByKey map[string]string + }{ + ByCode: make(map[string]string), + ByKey: make(map[string]string), + } } - l.cache[lang][key] = value + l.cache[lang].ByKey[key] = value util.Info(ctx, "更新翻译:", lang, key, "->", value) return nil @@ -781,7 +818,7 @@ func (l *Logic) Delete(ctx context.Context, key, lang string) error { defer l.mutex.Unlock() if m, ok := l.cache[lang]; ok { - delete(m, key) + delete(m.ByKey, key) } util.Info(ctx, "删除翻译:", lang, key) @@ -811,7 +848,7 @@ func (l *Logic) GetByCategory(ctx context.Context, lang, category string) (map[s return result, nil } -// ImportFromMap 从map批量导入翻译 +// 从map批量导入翻译 func (l *Logic) ImportFromMap(ctx context.Context, lang string, mappings map[string]string, category string) error { if len(mappings) == 0 { return nil @@ -840,11 +877,17 @@ func (l *Logic) ImportFromMap(ctx context.Context, lang string, mappings map[str l.mutex.Lock() defer l.mutex.Unlock() - if l.cache[lang] == nil { - l.cache[lang] = make(map[string]string) + if _, exists := l.cache[lang]; !exists { + l.cache[lang] = struct { + ByCode map[string]string + ByKey map[string]string + }{ + ByCode: make(map[string]string), + ByKey: make(map[string]string), + } } for key, value := range mappings { - l.cache[lang][key] = value + l.cache[lang].ByKey[key] = value } util.Info(ctx, "批量导入翻译完成:", lang, category, "共", len(mappings), "条") @@ -878,7 +921,7 @@ func (l *Logic) StartAutoRefresh(ctx context.Context) { // En2Zh 英文转中文(静态映射,仅降级时使用) func En2Zh(s string) string { - if v, ok := GetI18nLogic().cache["zh"][s]; ok { + if v, ok := GetI18nLogic().cache["zh"].ByKey[s]; ok { return v } // 仅降级时才用备份 @@ -890,7 +933,7 @@ func En2Zh(s string) string { // Zh2En 中文转英文(静态映射,仅降级时使用) func Zh2En(s string) string { - if v, ok := GetI18nLogic().cache["en"][s]; ok { + if v, ok := GetI18nLogic().cache["en"].ByKey[s]; ok { return v } // 仅降级时才用备份 @@ -975,3 +1018,158 @@ func ImportI18nFromMap(ctx context.Context, lang string, mappings map[string]str } return nil } + +// SyncI18nFromRemote 从远程接口拉取英雄和神器的中英文名称,写入数据库和内存缓存 +func (l *Logic) SyncI18nFromRemote(ctx context.Context) error { + client := gclient.New() + + types := []struct { + url string + category string + }{ + {consts.SimileHeroName, "hero"}, + {consts.SimileArtifactName, "artifact"}, + } + + for _, t := range types { + g.Log().Infof(ctx, "拉取i18n远程数据: %s", t.url) + resp, err := client.Get(ctx, t.url) + if err != nil { + g.Log().Errorf(ctx, "拉取远程i18n数据失败: %s, err: %v", t.url, err) + continue + } + content := resp.ReadAll() + j := gjson.New(content) + if j == nil || j.IsNil() { + g.Log().Errorf(ctx, "解析远程i18n数据失败: %s, 内容为空", t.url) + continue + } + var data map[string][]map[string]interface{} + if err := j.Var().Scan(&data); err != nil { + g.Log().Errorf(ctx, "解析远程i18n数据失败: %s, err: %v", t.url, err) + continue + } + enArr, enOk := data["en"] + zhArr, zhOk := data["zh-CN"] + if !enOk || !zhOk { + g.Log().Warningf(ctx, "远程i18n数据缺少en或zh-CN: %s", t.url) + continue + } + // code->en/zh + enMap := make(map[string]string) + zhMap := make(map[string]string) + for _, item := range enArr { + if code, ok := item["code"].(string); ok { + if name, ok := item["name"].(string); ok { + enMap[code] = name + } + } + } + for _, item := range zhArr { + if code, ok := item["code"].(string); ok { + if name, ok := item["name"].(string); ok { + zhMap[code] = name + } + } + } + // code->en/zh三元组 + type row struct{ code, en, zh string } + var rows []row + for code, enName := range enMap { + if zhName, ok := zhMap[code]; ok { + rows = append(rows, row{code, enName, zhName}) + } + } + if len(rows) == 0 { + g.Log().Warningf(ctx, "未生成任何en->zh映射: %s", t.url) + continue + } + + // 读取数据库现有映射,优先用code查找 + var dbMappings []*entity.EpicI18NMappings + err = dao.EpicI18NMappings.Ctx(ctx). + Where(dao.EpicI18NMappings.Columns().Language, "zh"). + Where(dao.EpicI18NMappings.Columns().Category, t.category). + Where(dao.EpicI18NMappings.Columns().Status, 1). + Where(dao.EpicI18NMappings.Columns().Deleted, 0). + Scan(&dbMappings) + if err != nil { + g.Log().Errorf(ctx, "查询i18n数据库失败: %v", err) + continue + } + dbMapByCode := make(map[string]*entity.EpicI18NMappings) + dbMapByKey := make(map[string]*entity.EpicI18NMappings) + for _, m := range dbMappings { + if m.Code != "" { + dbMapByCode[m.Code] = m + } + dbMapByKey[m.KeyName] = m + } + + var toInsert []g.Map + var toUpdate []struct{ code, en, zh string } + for _, r := range rows { + var exist *entity.EpicI18NMappings + if r.code != "" { + exist = dbMapByCode[r.code] + } + if exist == nil { + exist = dbMapByKey[r.en] + } + if exist == nil { + toInsert = append(toInsert, g.Map{ + dao.EpicI18NMappings.Columns().KeyName: r.en, + dao.EpicI18NMappings.Columns().Language: "zh", + dao.EpicI18NMappings.Columns().Value: r.zh, + dao.EpicI18NMappings.Columns().Category: t.category, + dao.EpicI18NMappings.Columns().Code: r.code, + dao.EpicI18NMappings.Columns().Status: 1, + dao.EpicI18NMappings.Columns().CreateTime: gtime.Now(), + dao.EpicI18NMappings.Columns().UpdateTime: gtime.Now(), + }) + } else if exist.Value != r.zh { + toUpdate = append(toUpdate, struct{ code, en, zh string }{r.code, r.en, r.zh}) + } + } + + if len(toInsert) > 0 { + _, err := dao.EpicI18NMappings.Ctx(ctx).Data(toInsert).Insert() + if err != nil { + g.Log().Errorf(ctx, "批量导入i18n数据失败: %s, err: %v", t.url, err) + } else { + g.Log().Infof(ctx, "远程i18n新增导入成功: %s, 共%d条", t.url, len(toInsert)) + // 更新缓存 + l.mutex.Lock() + if _, exists := l.cache["zh"]; !exists { + l.cache["zh"] = struct { + ByCode map[string]string + ByKey map[string]string + }{ + ByCode: make(map[string]string), + ByKey: make(map[string]string), + } + } + for _, item := range toInsert { + if keyName, ok := item[dao.EpicI18NMappings.Columns().KeyName].(string); ok { + if value, ok := item[dao.EpicI18NMappings.Columns().Value].(string); ok { + l.cache["zh"].ByKey[keyName] = value + if code, ok := item[dao.EpicI18NMappings.Columns().Code].(string); ok && code != "" { + l.cache["zh"].ByCode[code] = value + } + } + } + } + l.mutex.Unlock() + } + } + if len(toUpdate) > 0 { + for _, r := range toUpdate { + if err := l.Update(ctx, r.en, "zh", r.zh); err != nil { + g.Log().Errorf(ctx, "更新i18n数据失败: %s %s -> %s, err: %v", t.category, r.en, r.zh, err) + } + } + g.Log().Infof(ctx, "远程i18n更新成功: %s, 共%d条", t.url, len(toUpdate)) + } + } + return nil +} diff --git a/internal/model/do/epic_i_18_n_mappings.go b/internal/model/do/epic_i_18_n_mappings.go index 6c0c30d..640f53a 100644 --- a/internal/model/do/epic_i_18_n_mappings.go +++ b/internal/model/do/epic_i_18_n_mappings.go @@ -23,4 +23,5 @@ type EpicI18NMappings struct { Updater interface{} // 更新者 UpdateTime *gtime.Time // 更新时间 Deleted interface{} // 是否删除 + Code interface{} // 编码 } diff --git a/internal/model/entity/epic_i_18_n_mappings.go b/internal/model/entity/epic_i_18_n_mappings.go index 8b4b53d..1ee3bb4 100644 --- a/internal/model/entity/epic_i_18_n_mappings.go +++ b/internal/model/entity/epic_i_18_n_mappings.go @@ -21,4 +21,5 @@ type EpicI18NMappings struct { Updater string `json:"updater" orm:"updater" description:"更新者"` // 更新者 UpdateTime *gtime.Time `json:"updateTime" orm:"update_time" description:"更新时间"` // 更新时间 Deleted int `json:"deleted" orm:"deleted" description:"是否删除"` // 是否删除 + Code string `json:"code" orm:"code" description:"编码"` // 编码 }