diff --git a/app/controller/admin/auth.go b/app/controller/admin/auth.go index f0ad647..9140219 100644 --- a/app/controller/admin/auth.go +++ b/app/controller/admin/auth.go @@ -490,7 +490,7 @@ func (c *Auth) EditUser(r *ghttp.Request) { } response.SusJson(true, r, "修改管理员成功") } - id := r.GetRequestInt("id") + id := r.GetUint64("id") //用户用户信息 userEntity, err := user.Model.Where("id=?", id).One() if err != nil { @@ -511,7 +511,7 @@ func (c *Auth) EditUser(r *ghttp.Request) { response.FailJson(true, r, "获取用户角色数据失败") } if checkedRoleIds == nil { - checkedRoleIds = g.SliceInt{} + checkedRoleIds = []uint{} } //获取岗位信息 posts, err := post_service.GetUsedPost() diff --git a/app/controller/admin/config_dict.go b/app/controller/admin/config_dict.go index b839663..fbf1cda 100644 --- a/app/controller/admin/config_dict.go +++ b/app/controller/admin/config_dict.go @@ -9,6 +9,7 @@ import ( "gfast/library/response" "github.com/gogf/gf/frame/g" "github.com/gogf/gf/net/ghttp" + "github.com/gogf/gf/util/gconv" "github.com/gogf/gf/util/gvalid" ) @@ -158,7 +159,7 @@ func (c *Dict) DataAdd(r *ghttp.Request) { response.FailJson(true, r, err.(*gvalid.Error).FirstString()) } userId := user_service.GetLoginID(r) //获取登陆用户id - _, err := dict_service.AddSaveData(req, userId) + _, err := dict_service.AddSaveData(req, gconv.Uint64(userId)) if err != nil { response.FailJson(true, r, err.Error()) } @@ -183,7 +184,7 @@ func (c *Dict) DataEdit(r *ghttp.Request) { response.FailJson(true, r, err.(*gvalid.Error).FirstString()) } userId := user_service.GetLoginID(r) - _, err := dict_service.EditSaveData(req, userId) + _, err := dict_service.EditSaveData(req, gconv.Uint64(userId)) if err != nil { response.FailJson(true, r, err.Error()) } diff --git a/app/controller/admin/dept.go b/app/controller/admin/dept.go index bf4bcf3..103d123 100644 --- a/app/controller/admin/dept.go +++ b/app/controller/admin/dept.go @@ -87,7 +87,7 @@ func (c *Dept) EditDept(r *ghttp.Request) { response.SusJson(true, r, "编辑成功") } - id := r.GetInt64("id") + id := r.GetUint64("id") if id == 0 { response.FailJson(true, r, "参数错误") } diff --git a/app/controller/admin/index.go b/app/controller/admin/index.go index f9d4d23..e4fe9ac 100644 --- a/app/controller/admin/index.go +++ b/app/controller/admin/index.go @@ -38,7 +38,7 @@ func (c *Index) GetInfo(r *ghttp.Request) { roles, err := user_service.GetAdminRole(userId, allRoles) if err == nil { name := make([]string, len(roles)) - roleIds := make([]int, len(roles)) + roleIds := make([]uint, len(roles)) for k, v := range roles { name[k] = v.Name roleIds[k] = v.Id @@ -79,7 +79,7 @@ func (c *Index) GetRouters(r *ghttp.Request) { //获取无需验证权限的用户id for _, v := range service.NotCheckAuthAdminIds { - if v == userId { + if gconv.Uint64(v) == userId { isSuperAdmin = true break } @@ -91,7 +91,7 @@ func (c *Index) GetRouters(r *ghttp.Request) { roles, err := user_service.GetAdminRole(userId, allRoles) if err == nil { name := make([]string, len(roles)) - roleIds := make([]int, len(roles)) + roleIds := make([]uint, len(roles)) for k, v := range roles { name[k] = v.Name roleIds[k] = v.Id diff --git a/app/model/admin/auth_rule/auth_rule_entity.go b/app/model/admin/auth_rule/auth_rule_entity.go index ccb328a..61de4a2 100644 --- a/app/model/admin/auth_rule/auth_rule_entity.go +++ b/app/model/admin/auth_rule/auth_rule_entity.go @@ -11,22 +11,24 @@ import ( // Entity is the golang structure for table auth_rule. type Entity struct { - Id uint `orm:"id,primary" json:"id"` // - Pid uint `orm:"pid" json:"pid"` // 父ID - Name string `orm:"name,unique" json:"name"` // 规则名称 - Title string `orm:"title" json:"title"` // 规则名称 - Icon string `orm:"icon" json:"icon"` // 图标 - Condition string `orm:"condition" json:"condition"` // 条件 - Remark string `orm:"remark" json:"remark"` // 备注 - MenuType uint `orm:"menu_type" json:"menu_type"` // 类型 0目录 1菜单 2按钮 - Createtime uint `orm:"createtime" json:"createtime"` // 创建时间 - Updatetime uint `orm:"updatetime" json:"updatetime"` // 更新时间 - Weigh int `orm:"weigh" json:"weigh"` // 权重 - Status uint `orm:"status" json:"status"` // 状态 - AlwaysShow uint `orm:"always_show" json:"alwaysShow"` //显示状态 0隐藏 1显示 - Path string `orm:"path" json:"path"` //路由地址 - Component string `orm:"component" json:"component"` //组件路径 - IsFrame uint `orm:"is_frame" json:"isFrame"` //是否外链 1是 0否 + Id uint `orm:"id,primary" json:"id"` // + Pid uint `orm:"pid" json:"pid"` // 父ID + Name string `orm:"name,unique" json:"name"` // 规则名称 + Title string `orm:"title" json:"title"` // 规则名称 + Icon string `orm:"icon" json:"icon"` // 图标 + Condition string `orm:"condition" json:"condition"` // 条件 + Remark string `orm:"remark" json:"remark"` // 备注 + MenuType uint `orm:"menu_type" json:"menu_type"` // 类型 0目录 1菜单 2按钮 + Createtime uint `orm:"createtime" json:"createtime"` // 创建时间 + Updatetime uint `orm:"updatetime" json:"updatetime"` // 更新时间 + Weigh int `orm:"weigh" json:"weigh"` // 权重 + Status uint `orm:"status" json:"status"` // 状态 + AlwaysShow uint `orm:"always_show" json:"always_show"` // 显示状态 + Path string `orm:"path" json:"path"` // 路由地址 + Component string `orm:"component" json:"component"` // 组件路径 + IsFrame uint `orm:"is_frame" json:"is_frame"` // 是否外链 1是 0否 + ModuleType string `orm:"module_type" json:"module_type"` // 所属模块 + ModelId uint `orm:"model_id" json:"model_id"` // 模型ID } // OmitEmpty sets OPTION_OMITEMPTY option for the model, which automatically filers @@ -40,6 +42,11 @@ func (r *Entity) Insert() (result sql.Result, err error) { return Model.Data(r).Insert() } +// InsertIgnore does "INSERT IGNORE INTO ..." statement for inserting current object into table. +func (r *Entity) InsertIgnore() (result sql.Result, err error) { + return Model.Data(r).InsertIgnore() +} + // Replace does "REPLACE...INTO..." statement for inserting current object into table. // If there's already another same record in the table (it checks using primary key or unique index), // it deletes it and insert this one. diff --git a/app/model/admin/auth_rule/auth_rule_model.go b/app/model/admin/auth_rule/auth_rule_model.go index 545f3a5..fcde0ae 100644 --- a/app/model/admin/auth_rule/auth_rule_model.go +++ b/app/model/admin/auth_rule/auth_rule_model.go @@ -8,12 +8,13 @@ import ( "database/sql" "github.com/gogf/gf/database/gdb" "github.com/gogf/gf/frame/g" + "github.com/gogf/gf/frame/gmvc" "time" ) // arModel is a active record design model for table auth_rule operations. type arModel struct { - M *gdb.Model + gmvc.M } var ( @@ -21,6 +22,46 @@ var ( Table = "auth_rule" // Model is the model object of auth_rule. Model = &arModel{g.DB("default").Table(Table).Safe()} + // Columns defines and stores column names for table auth_rule. + Columns = struct { + Id string // + Pid string // 父ID + Name string // 规则名称 + Title string // 规则名称 + Icon string // 图标 + Condition string // 条件 + Remark string // 备注 + MenuType string // 类型 0目录 1菜单 2按钮 + Createtime string // 创建时间 + Updatetime string // 更新时间 + Weigh string // 权重 + Status string // 状态 + AlwaysShow string // 显示状态 + Path string // 路由地址 + Component string // 组件路径 + IsFrame string // 是否外链 1是 0否 + ModuleType string // 所属模块 + ModelId string // 模型ID + }{ + Id: "id", + Pid: "pid", + Name: "name", + Title: "title", + Icon: "icon", + Condition: "condition", + Remark: "remark", + MenuType: "menu_type", + Createtime: "createtime", + Updatetime: "updatetime", + Weigh: "weigh", + Status: "status", + AlwaysShow: "always_show", + Path: "path", + Component: "component", + IsFrame: "is_frame", + ModuleType: "module_type", + ModelId: "model_id", + } ) // FindOne is a convenience method for Model.FindOne. @@ -41,6 +82,12 @@ func FindValue(fieldsAndWhere ...interface{}) (gdb.Value, error) { return Model.FindValue(fieldsAndWhere...) } +// FindArray is a convenience method for Model.FindArray. +// See Model.FindArray. +func FindArray(fieldsAndWhere ...interface{}) ([]gdb.Value, error) { + return Model.FindArray(fieldsAndWhere...) +} + // FindCount is a convenience method for Model.FindCount. // See Model.FindCount. func FindCount(where ...interface{}) (int, error) { @@ -52,6 +99,11 @@ func Insert(data ...interface{}) (result sql.Result, err error) { return Model.Insert(data...) } +// InsertIgnore is a convenience method for Model.InsertIgnore. +func InsertIgnore(data ...interface{}) (result sql.Result, err error) { + return Model.InsertIgnore(data...) +} + // Replace is a convenience method for Model.Replace. func Replace(data ...interface{}) (result sql.Result, err error) { return Model.Replace(data...) @@ -94,18 +146,30 @@ func (m *arModel) Slave() *arModel { } // LeftJoin does "LEFT JOIN ... ON ..." statement on the model. -func (m *arModel) LeftJoin(joinTable string, on string) *arModel { - return &arModel{m.M.LeftJoin(joinTable, on)} +// The parameter can be joined table and its joined condition, +// and also with its alias name, like: +// Table("user").LeftJoin("user_detail", "user_detail.uid=user.uid") +// Table("user", "u").LeftJoin("user_detail", "ud", "ud.uid=u.uid") +func (m *arModel) LeftJoin(table ...string) *arModel { + return &arModel{m.M.LeftJoin(table...)} } // RightJoin does "RIGHT JOIN ... ON ..." statement on the model. -func (m *arModel) RightJoin(joinTable string, on string) *arModel { - return &arModel{m.M.RightJoin(joinTable, on)} +// The parameter
can be joined table and its joined condition, +// and also with its alias name, like: +// Table("user").RightJoin("user_detail", "user_detail.uid=user.uid") +// Table("user", "u").RightJoin("user_detail", "ud", "ud.uid=u.uid") +func (m *arModel) RightJoin(table ...string) *arModel { + return &arModel{m.M.RightJoin(table...)} } // InnerJoin does "INNER JOIN ... ON ..." statement on the model. -func (m *arModel) InnerJoin(joinTable string, on string) *arModel { - return &arModel{m.M.InnerJoin(joinTable, on)} +// The parameter
can be joined table and its joined condition, +// and also with its alias name, like: +// Table("user").InnerJoin("user_detail", "user_detail.uid=user.uid") +// Table("user", "u").InnerJoin("user_detail", "ud", "ud.uid=u.uid") +func (m *arModel) InnerJoin(table ...string) *arModel { + return &arModel{m.M.InnerJoin(table...)} } // Fields sets the operation fields of the model, multiple fields joined using char ','. @@ -165,8 +229,8 @@ func (m *arModel) Group(groupBy string) *arModel { } // Order sets the "ORDER BY" statement for the model. -func (m *arModel) Order(orderBy string) *arModel { - return &arModel{m.M.Order(orderBy)} +func (m *arModel) Order(orderBy ...string) *arModel { + return &arModel{m.M.Order(orderBy...)} } // Limit sets the "LIMIT" statement for the model. @@ -207,8 +271,8 @@ func (m *arModel) Batch(batch int) *arModel { // control the cache like changing the or clearing the cache with specified . // // Note that, the cache feature is disabled if the model is operating on a transaction. -func (m *arModel) Cache(expire time.Duration, name ...string) *arModel { - return &arModel{m.M.Cache(expire, name...)} +func (m *arModel) Cache(duration time.Duration, name ...string) *arModel { + return &arModel{m.M.Cache(duration, name...)} } // Data sets the operation data for the model. @@ -222,53 +286,6 @@ func (m *arModel) Data(data ...interface{}) *arModel { return &arModel{m.M.Data(data...)} } -// Insert does "INSERT INTO ..." statement for the model. -// The optional parameter is the same as the parameter of Model.Data function, -// see Model.Data. -func (m *arModel) Insert(data ...interface{}) (result sql.Result, err error) { - return m.M.Insert(data...) -} - -// Replace does "REPLACE INTO ..." statement for the model. -// The optional parameter is the same as the parameter of Model.Data function, -// see Model.Data. -func (m *arModel) Replace(data ...interface{}) (result sql.Result, err error) { - return m.M.Replace(data...) -} - -// Save does "INSERT INTO ... ON DUPLICATE KEY UPDATE..." statement for the model. -// It updates the record if there's primary or unique index in the saving data, -// or else it inserts a new record into the table. -// -// The optional parameter is the same as the parameter of Model.Data function, -// see Model.Data. -func (m *arModel) Save(data ...interface{}) (result sql.Result, err error) { - return m.M.Save(data...) -} - -// Update does "UPDATE ... " statement for the model. -// -// If the optional parameter is given, the dataAndWhere[0] is the updated -// data field, and dataAndWhere[1:] is treated as where condition fields. -// Also see Model.Data and Model.Where functions. -func (m *arModel) Update(dataAndWhere ...interface{}) (result sql.Result, err error) { - return m.M.Update(dataAndWhere...) -} - -// Delete does "DELETE FROM ... " statement for the model. -// The optional parameter is the same as the parameter of Model.Where function, -// see Model.Where. -func (m *arModel) Delete(where ...interface{}) (result sql.Result, err error) { - return m.M.Delete(where...) -} - -// Count does "SELECT COUNT(x) FROM ..." statement for the model. -// The optional parameter is the same as the parameter of Model.Where function, -// see Model.Where. -func (m *arModel) Count(where ...interface{}) (int, error) { - return m.M.Count(where...) -} - // All does "SELECT FROM ..." statement for the model. // It retrieves the records from table and returns the result as []*Entity. // It returns nil if there's no record retrieved with the given conditions from table. @@ -304,16 +321,6 @@ func (m *arModel) One(where ...interface{}) (*Entity, error) { return entity, nil } -// Value retrieves a specified record value from table and returns the result as interface type. -// It returns nil if there's no record found with the given conditions from table. -// -// If the optional parameter is given, the fieldsAndWhere[0] is the selected fields -// and fieldsAndWhere[1:] is treated as where condition fields. -// Also see Model.Fields and Model.Where functions. -func (m *arModel) Value(fieldsAndWhere ...interface{}) (gdb.Value, error) { - return m.M.Value(fieldsAndWhere...) -} - // FindOne retrieves and returns a single Record by Model.WherePri and Model.One. // Also see Model.WherePri and Model.One. func (m *arModel) FindOne(where ...interface{}) (*Entity, error) { @@ -342,18 +349,6 @@ func (m *arModel) FindAll(where ...interface{}) ([]*Entity, error) { return entities, nil } -// FindValue retrieves and returns single field value by Model.WherePri and Model.Value. -// Also see Model.WherePri and Model.Value. -func (m *arModel) FindValue(fieldsAndWhere ...interface{}) (gdb.Value, error) { - return m.M.FindValue(fieldsAndWhere...) -} - -// FindCount retrieves and returns the record number by Model.WherePri and Model.Count. -// Also see Model.WherePri and Model.Count. -func (m *arModel) FindCount(where ...interface{}) (int, error) { - return m.M.FindCount(where...) -} - // Chunk iterates the table with given size and callback function. func (m *arModel) Chunk(limit int, callback func(entities []*Entity, err error) bool) { m.M.Chunk(limit, func(result gdb.Result, err error) bool { @@ -365,3 +360,18 @@ func (m *arModel) Chunk(limit int, callback func(entities []*Entity, err error) return callback(entities, err) }) } + +// LockUpdate sets the lock for update for current operation. +func (m *arModel) LockUpdate() *arModel { + return &arModel{m.M.LockUpdate()} +} + +// LockShared sets the lock in share mode for current operation. +func (m *arModel) LockShared() *arModel { + return &arModel{m.M.LockShared()} +} + +// Unscoped enables/disables the soft deleting feature. +func (m *arModel) Unscoped() *arModel { + return &arModel{m.M.Unscoped()} +} diff --git a/app/model/admin/casbin_rule/casbin_rule_entity.go b/app/model/admin/casbin_rule/casbin_rule_entity.go index 116111e..028a5e2 100644 --- a/app/model/admin/casbin_rule/casbin_rule_entity.go +++ b/app/model/admin/casbin_rule/casbin_rule_entity.go @@ -31,6 +31,11 @@ func (r *Entity) Insert() (result sql.Result, err error) { return Model.Data(r).Insert() } +// InsertIgnore does "INSERT IGNORE INTO ..." statement for inserting current object into table. +func (r *Entity) InsertIgnore() (result sql.Result, err error) { + return Model.Data(r).InsertIgnore() +} + // Replace does "REPLACE...INTO..." statement for inserting current object into table. // If there's already another same record in the table (it checks using primary key or unique index), // it deletes it and insert this one. diff --git a/app/model/admin/casbin_rule/casbin_rule_model.go b/app/model/admin/casbin_rule/casbin_rule_model.go index 3123c49..f109310 100644 --- a/app/model/admin/casbin_rule/casbin_rule_model.go +++ b/app/model/admin/casbin_rule/casbin_rule_model.go @@ -8,12 +8,13 @@ import ( "database/sql" "github.com/gogf/gf/database/gdb" "github.com/gogf/gf/frame/g" + "github.com/gogf/gf/frame/gmvc" "time" ) // arModel is a active record design model for table casbin_rule operations. type arModel struct { - M *gdb.Model + gmvc.M } var ( @@ -21,6 +22,24 @@ var ( Table = "casbin_rule" // Model is the model object of casbin_rule. Model = &arModel{g.DB("default").Table(Table).Safe()} + // Columns defines and stores column names for table casbin_rule. + Columns = struct { + Ptype string // + V0 string // + V1 string // + V2 string // + V3 string // + V4 string // + V5 string // + }{ + Ptype: "ptype", + V0: "v0", + V1: "v1", + V2: "v2", + V3: "v3", + V4: "v4", + V5: "v5", + } ) // FindOne is a convenience method for Model.FindOne. @@ -41,6 +60,12 @@ func FindValue(fieldsAndWhere ...interface{}) (gdb.Value, error) { return Model.FindValue(fieldsAndWhere...) } +// FindArray is a convenience method for Model.FindArray. +// See Model.FindArray. +func FindArray(fieldsAndWhere ...interface{}) ([]gdb.Value, error) { + return Model.FindArray(fieldsAndWhere...) +} + // FindCount is a convenience method for Model.FindCount. // See Model.FindCount. func FindCount(where ...interface{}) (int, error) { @@ -52,6 +77,11 @@ func Insert(data ...interface{}) (result sql.Result, err error) { return Model.Insert(data...) } +// InsertIgnore is a convenience method for Model.InsertIgnore. +func InsertIgnore(data ...interface{}) (result sql.Result, err error) { + return Model.InsertIgnore(data...) +} + // Replace is a convenience method for Model.Replace. func Replace(data ...interface{}) (result sql.Result, err error) { return Model.Replace(data...) @@ -94,18 +124,30 @@ func (m *arModel) Slave() *arModel { } // LeftJoin does "LEFT JOIN ... ON ..." statement on the model. -func (m *arModel) LeftJoin(joinTable string, on string) *arModel { - return &arModel{m.M.LeftJoin(joinTable, on)} +// The parameter
can be joined table and its joined condition, +// and also with its alias name, like: +// Table("user").LeftJoin("user_detail", "user_detail.uid=user.uid") +// Table("user", "u").LeftJoin("user_detail", "ud", "ud.uid=u.uid") +func (m *arModel) LeftJoin(table ...string) *arModel { + return &arModel{m.M.LeftJoin(table...)} } // RightJoin does "RIGHT JOIN ... ON ..." statement on the model. -func (m *arModel) RightJoin(joinTable string, on string) *arModel { - return &arModel{m.M.RightJoin(joinTable, on)} +// The parameter
can be joined table and its joined condition, +// and also with its alias name, like: +// Table("user").RightJoin("user_detail", "user_detail.uid=user.uid") +// Table("user", "u").RightJoin("user_detail", "ud", "ud.uid=u.uid") +func (m *arModel) RightJoin(table ...string) *arModel { + return &arModel{m.M.RightJoin(table...)} } // InnerJoin does "INNER JOIN ... ON ..." statement on the model. -func (m *arModel) InnerJoin(joinTable string, on string) *arModel { - return &arModel{m.M.InnerJoin(joinTable, on)} +// The parameter
can be joined table and its joined condition, +// and also with its alias name, like: +// Table("user").InnerJoin("user_detail", "user_detail.uid=user.uid") +// Table("user", "u").InnerJoin("user_detail", "ud", "ud.uid=u.uid") +func (m *arModel) InnerJoin(table ...string) *arModel { + return &arModel{m.M.InnerJoin(table...)} } // Fields sets the operation fields of the model, multiple fields joined using char ','. @@ -165,8 +207,8 @@ func (m *arModel) Group(groupBy string) *arModel { } // Order sets the "ORDER BY" statement for the model. -func (m *arModel) Order(orderBy string) *arModel { - return &arModel{m.M.Order(orderBy)} +func (m *arModel) Order(orderBy ...string) *arModel { + return &arModel{m.M.Order(orderBy...)} } // Limit sets the "LIMIT" statement for the model. @@ -207,8 +249,8 @@ func (m *arModel) Batch(batch int) *arModel { // control the cache like changing the or clearing the cache with specified . // // Note that, the cache feature is disabled if the model is operating on a transaction. -func (m *arModel) Cache(expire time.Duration, name ...string) *arModel { - return &arModel{m.M.Cache(expire, name...)} +func (m *arModel) Cache(duration time.Duration, name ...string) *arModel { + return &arModel{m.M.Cache(duration, name...)} } // Data sets the operation data for the model. @@ -222,53 +264,6 @@ func (m *arModel) Data(data ...interface{}) *arModel { return &arModel{m.M.Data(data...)} } -// Insert does "INSERT INTO ..." statement for the model. -// The optional parameter is the same as the parameter of Model.Data function, -// see Model.Data. -func (m *arModel) Insert(data ...interface{}) (result sql.Result, err error) { - return m.M.Insert(data...) -} - -// Replace does "REPLACE INTO ..." statement for the model. -// The optional parameter is the same as the parameter of Model.Data function, -// see Model.Data. -func (m *arModel) Replace(data ...interface{}) (result sql.Result, err error) { - return m.M.Replace(data...) -} - -// Save does "INSERT INTO ... ON DUPLICATE KEY UPDATE..." statement for the model. -// It updates the record if there's primary or unique index in the saving data, -// or else it inserts a new record into the table. -// -// The optional parameter is the same as the parameter of Model.Data function, -// see Model.Data. -func (m *arModel) Save(data ...interface{}) (result sql.Result, err error) { - return m.M.Save(data...) -} - -// Update does "UPDATE ... " statement for the model. -// -// If the optional parameter is given, the dataAndWhere[0] is the updated -// data field, and dataAndWhere[1:] is treated as where condition fields. -// Also see Model.Data and Model.Where functions. -func (m *arModel) Update(dataAndWhere ...interface{}) (result sql.Result, err error) { - return m.M.Update(dataAndWhere...) -} - -// Delete does "DELETE FROM ... " statement for the model. -// The optional parameter is the same as the parameter of Model.Where function, -// see Model.Where. -func (m *arModel) Delete(where ...interface{}) (result sql.Result, err error) { - return m.M.Delete(where...) -} - -// Count does "SELECT COUNT(x) FROM ..." statement for the model. -// The optional parameter is the same as the parameter of Model.Where function, -// see Model.Where. -func (m *arModel) Count(where ...interface{}) (int, error) { - return m.M.Count(where...) -} - // All does "SELECT FROM ..." statement for the model. // It retrieves the records from table and returns the result as []*Entity. // It returns nil if there's no record retrieved with the given conditions from table. @@ -304,16 +299,6 @@ func (m *arModel) One(where ...interface{}) (*Entity, error) { return entity, nil } -// Value retrieves a specified record value from table and returns the result as interface type. -// It returns nil if there's no record found with the given conditions from table. -// -// If the optional parameter is given, the fieldsAndWhere[0] is the selected fields -// and fieldsAndWhere[1:] is treated as where condition fields. -// Also see Model.Fields and Model.Where functions. -func (m *arModel) Value(fieldsAndWhere ...interface{}) (gdb.Value, error) { - return m.M.Value(fieldsAndWhere...) -} - // FindOne retrieves and returns a single Record by Model.WherePri and Model.One. // Also see Model.WherePri and Model.One. func (m *arModel) FindOne(where ...interface{}) (*Entity, error) { @@ -342,18 +327,6 @@ func (m *arModel) FindAll(where ...interface{}) ([]*Entity, error) { return entities, nil } -// FindValue retrieves and returns single field value by Model.WherePri and Model.Value. -// Also see Model.WherePri and Model.Value. -func (m *arModel) FindValue(fieldsAndWhere ...interface{}) (gdb.Value, error) { - return m.M.FindValue(fieldsAndWhere...) -} - -// FindCount retrieves and returns the record number by Model.WherePri and Model.Count. -// Also see Model.WherePri and Model.Count. -func (m *arModel) FindCount(where ...interface{}) (int, error) { - return m.M.FindCount(where...) -} - // Chunk iterates the table with given size and callback function. func (m *arModel) Chunk(limit int, callback func(entities []*Entity, err error) bool) { m.M.Chunk(limit, func(result gdb.Result, err error) bool { @@ -365,3 +338,18 @@ func (m *arModel) Chunk(limit int, callback func(entities []*Entity, err error) return callback(entities, err) }) } + +// LockUpdate sets the lock for update for current operation. +func (m *arModel) LockUpdate() *arModel { + return &arModel{m.M.LockUpdate()} +} + +// LockShared sets the lock in share mode for current operation. +func (m *arModel) LockShared() *arModel { + return &arModel{m.M.LockShared()} +} + +// Unscoped enables/disables the soft deleting feature. +func (m *arModel) Unscoped() *arModel { + return &arModel{m.M.Unscoped()} +} diff --git a/app/model/admin/cms_category/cms_category_entity.go b/app/model/admin/cms_category/cms_category_entity.go index cf68552..0fe3347 100644 --- a/app/model/admin/cms_category/cms_category_entity.go +++ b/app/model/admin/cms_category/cms_category_entity.go @@ -13,12 +13,12 @@ import ( type Entity struct { Id uint64 `orm:"id,primary" json:"id"` // 分类id ParentId int64 `orm:"parent_id" json:"parent_id"` // 分类父id - ModelId uint `orm:"model_id" json:"model_id"` // 模型id + ModelId uint `orm:"model_id" json:"model_id"` // 模型ID Status uint `orm:"status" json:"status"` // 状态,1:发布,0:不发布 DeleteTime uint `orm:"delete_time" json:"delete_time"` // 删除时间 ListOrder float64 `orm:"list_order" json:"list_order"` // 排序 Name string `orm:"name" json:"name"` // 分类名称 - Alias string `orm:"alias" json:"alias"` // 分类别名 + Alias string `orm:"alias" json:"alias"` // 栏目别名 Description string `orm:"description" json:"description"` // 分类描述 SeoTitle string `orm:"seo_title" json:"seo_title"` // SeoKeywords string `orm:"seo_keywords" json:"seo_keywords"` // @@ -42,6 +42,11 @@ func (r *Entity) Insert() (result sql.Result, err error) { return Model.Data(r).Insert() } +// InsertIgnore does "INSERT IGNORE INTO ..." statement for inserting current object into table. +func (r *Entity) InsertIgnore() (result sql.Result, err error) { + return Model.Data(r).InsertIgnore() +} + // Replace does "REPLACE...INTO..." statement for inserting current object into table. // If there's already another same record in the table (it checks using primary key or unique index), // it deletes it and insert this one. diff --git a/app/model/admin/cms_category/cms_category_model.go b/app/model/admin/cms_category/cms_category_model.go index 2ae6b74..b6dd1d3 100644 --- a/app/model/admin/cms_category/cms_category_model.go +++ b/app/model/admin/cms_category/cms_category_model.go @@ -8,12 +8,13 @@ import ( "database/sql" "github.com/gogf/gf/database/gdb" "github.com/gogf/gf/frame/g" + "github.com/gogf/gf/frame/gmvc" "time" ) // arModel is a active record design model for table cms_category operations. type arModel struct { - M *gdb.Model + gmvc.M } var ( @@ -21,6 +22,46 @@ var ( Table = "cms_category" // Model is the model object of cms_category. Model = &arModel{g.DB("default").Table(Table).Safe()} + // Columns defines and stores column names for table cms_category. + Columns = struct { + Id string // 分类id + ParentId string // 分类父id + ModelId string // 模型ID + Status string // 状态,1:发布,0:不发布 + DeleteTime string // 删除时间 + ListOrder string // 排序 + Name string // 分类名称 + Alias string // 栏目别名 + Description string // 分类描述 + SeoTitle string // + SeoKeywords string // + SeoDescription string // + ListTpl string // 分类列表模板 + OneTpl string // 分类文章页模板 + More string // 扩展属性 + CateType string // 分类类型 + CateAddress string // 跳转地址 + CateContent string // 单页内容 + }{ + Id: "id", + ParentId: "parent_id", + ModelId: "model_id", + Status: "status", + DeleteTime: "delete_time", + ListOrder: "list_order", + Name: "name", + Alias: "alias", + Description: "description", + SeoTitle: "seo_title", + SeoKeywords: "seo_keywords", + SeoDescription: "seo_description", + ListTpl: "list_tpl", + OneTpl: "one_tpl", + More: "more", + CateType: "cate_type", + CateAddress: "cate_address", + CateContent: "cate_content", + } ) // FindOne is a convenience method for Model.FindOne. @@ -41,6 +82,12 @@ func FindValue(fieldsAndWhere ...interface{}) (gdb.Value, error) { return Model.FindValue(fieldsAndWhere...) } +// FindArray is a convenience method for Model.FindArray. +// See Model.FindArray. +func FindArray(fieldsAndWhere ...interface{}) ([]gdb.Value, error) { + return Model.FindArray(fieldsAndWhere...) +} + // FindCount is a convenience method for Model.FindCount. // See Model.FindCount. func FindCount(where ...interface{}) (int, error) { @@ -52,6 +99,11 @@ func Insert(data ...interface{}) (result sql.Result, err error) { return Model.Insert(data...) } +// InsertIgnore is a convenience method for Model.InsertIgnore. +func InsertIgnore(data ...interface{}) (result sql.Result, err error) { + return Model.InsertIgnore(data...) +} + // Replace is a convenience method for Model.Replace. func Replace(data ...interface{}) (result sql.Result, err error) { return Model.Replace(data...) @@ -94,18 +146,30 @@ func (m *arModel) Slave() *arModel { } // LeftJoin does "LEFT JOIN ... ON ..." statement on the model. -func (m *arModel) LeftJoin(joinTable string, on string) *arModel { - return &arModel{m.M.LeftJoin(joinTable, on)} +// The parameter
can be joined table and its joined condition, +// and also with its alias name, like: +// Table("user").LeftJoin("user_detail", "user_detail.uid=user.uid") +// Table("user", "u").LeftJoin("user_detail", "ud", "ud.uid=u.uid") +func (m *arModel) LeftJoin(table ...string) *arModel { + return &arModel{m.M.LeftJoin(table...)} } // RightJoin does "RIGHT JOIN ... ON ..." statement on the model. -func (m *arModel) RightJoin(joinTable string, on string) *arModel { - return &arModel{m.M.RightJoin(joinTable, on)} +// The parameter
can be joined table and its joined condition, +// and also with its alias name, like: +// Table("user").RightJoin("user_detail", "user_detail.uid=user.uid") +// Table("user", "u").RightJoin("user_detail", "ud", "ud.uid=u.uid") +func (m *arModel) RightJoin(table ...string) *arModel { + return &arModel{m.M.RightJoin(table...)} } // InnerJoin does "INNER JOIN ... ON ..." statement on the model. -func (m *arModel) InnerJoin(joinTable string, on string) *arModel { - return &arModel{m.M.InnerJoin(joinTable, on)} +// The parameter
can be joined table and its joined condition, +// and also with its alias name, like: +// Table("user").InnerJoin("user_detail", "user_detail.uid=user.uid") +// Table("user", "u").InnerJoin("user_detail", "ud", "ud.uid=u.uid") +func (m *arModel) InnerJoin(table ...string) *arModel { + return &arModel{m.M.InnerJoin(table...)} } // Fields sets the operation fields of the model, multiple fields joined using char ','. @@ -165,8 +229,8 @@ func (m *arModel) Group(groupBy string) *arModel { } // Order sets the "ORDER BY" statement for the model. -func (m *arModel) Order(orderBy string) *arModel { - return &arModel{m.M.Order(orderBy)} +func (m *arModel) Order(orderBy ...string) *arModel { + return &arModel{m.M.Order(orderBy...)} } // Limit sets the "LIMIT" statement for the model. @@ -207,8 +271,8 @@ func (m *arModel) Batch(batch int) *arModel { // control the cache like changing the or clearing the cache with specified . // // Note that, the cache feature is disabled if the model is operating on a transaction. -func (m *arModel) Cache(expire time.Duration, name ...string) *arModel { - return &arModel{m.M.Cache(expire, name...)} +func (m *arModel) Cache(duration time.Duration, name ...string) *arModel { + return &arModel{m.M.Cache(duration, name...)} } // Data sets the operation data for the model. @@ -222,53 +286,6 @@ func (m *arModel) Data(data ...interface{}) *arModel { return &arModel{m.M.Data(data...)} } -// Insert does "INSERT INTO ..." statement for the model. -// The optional parameter is the same as the parameter of Model.Data function, -// see Model.Data. -func (m *arModel) Insert(data ...interface{}) (result sql.Result, err error) { - return m.M.Insert(data...) -} - -// Replace does "REPLACE INTO ..." statement for the model. -// The optional parameter is the same as the parameter of Model.Data function, -// see Model.Data. -func (m *arModel) Replace(data ...interface{}) (result sql.Result, err error) { - return m.M.Replace(data...) -} - -// Save does "INSERT INTO ... ON DUPLICATE KEY UPDATE..." statement for the model. -// It updates the record if there's primary or unique index in the saving data, -// or else it inserts a new record into the table. -// -// The optional parameter is the same as the parameter of Model.Data function, -// see Model.Data. -func (m *arModel) Save(data ...interface{}) (result sql.Result, err error) { - return m.M.Save(data...) -} - -// Update does "UPDATE ... " statement for the model. -// -// If the optional parameter is given, the dataAndWhere[0] is the updated -// data field, and dataAndWhere[1:] is treated as where condition fields. -// Also see Model.Data and Model.Where functions. -func (m *arModel) Update(dataAndWhere ...interface{}) (result sql.Result, err error) { - return m.M.Update(dataAndWhere...) -} - -// Delete does "DELETE FROM ... " statement for the model. -// The optional parameter is the same as the parameter of Model.Where function, -// see Model.Where. -func (m *arModel) Delete(where ...interface{}) (result sql.Result, err error) { - return m.M.Delete(where...) -} - -// Count does "SELECT COUNT(x) FROM ..." statement for the model. -// The optional parameter is the same as the parameter of Model.Where function, -// see Model.Where. -func (m *arModel) Count(where ...interface{}) (int, error) { - return m.M.Count(where...) -} - // All does "SELECT FROM ..." statement for the model. // It retrieves the records from table and returns the result as []*Entity. // It returns nil if there's no record retrieved with the given conditions from table. @@ -304,16 +321,6 @@ func (m *arModel) One(where ...interface{}) (*Entity, error) { return entity, nil } -// Value retrieves a specified record value from table and returns the result as interface type. -// It returns nil if there's no record found with the given conditions from table. -// -// If the optional parameter is given, the fieldsAndWhere[0] is the selected fields -// and fieldsAndWhere[1:] is treated as where condition fields. -// Also see Model.Fields and Model.Where functions. -func (m *arModel) Value(fieldsAndWhere ...interface{}) (gdb.Value, error) { - return m.M.Value(fieldsAndWhere...) -} - // FindOne retrieves and returns a single Record by Model.WherePri and Model.One. // Also see Model.WherePri and Model.One. func (m *arModel) FindOne(where ...interface{}) (*Entity, error) { @@ -342,18 +349,6 @@ func (m *arModel) FindAll(where ...interface{}) ([]*Entity, error) { return entities, nil } -// FindValue retrieves and returns single field value by Model.WherePri and Model.Value. -// Also see Model.WherePri and Model.Value. -func (m *arModel) FindValue(fieldsAndWhere ...interface{}) (gdb.Value, error) { - return m.M.FindValue(fieldsAndWhere...) -} - -// FindCount retrieves and returns the record number by Model.WherePri and Model.Count. -// Also see Model.WherePri and Model.Count. -func (m *arModel) FindCount(where ...interface{}) (int, error) { - return m.M.FindCount(where...) -} - // Chunk iterates the table with given size and callback function. func (m *arModel) Chunk(limit int, callback func(entities []*Entity, err error) bool) { m.M.Chunk(limit, func(result gdb.Result, err error) bool { @@ -365,3 +360,18 @@ func (m *arModel) Chunk(limit int, callback func(entities []*Entity, err error) return callback(entities, err) }) } + +// LockUpdate sets the lock for update for current operation. +func (m *arModel) LockUpdate() *arModel { + return &arModel{m.M.LockUpdate()} +} + +// LockShared sets the lock in share mode for current operation. +func (m *arModel) LockShared() *arModel { + return &arModel{m.M.LockShared()} +} + +// Unscoped enables/disables the soft deleting feature. +func (m *arModel) Unscoped() *arModel { + return &arModel{m.M.Unscoped()} +} diff --git a/app/model/admin/cms_category_news/cms_category_news_entity.go b/app/model/admin/cms_category_news/cms_category_news_entity.go index 4b8cce7..ed91ed7 100644 --- a/app/model/admin/cms_category_news/cms_category_news_entity.go +++ b/app/model/admin/cms_category_news/cms_category_news_entity.go @@ -27,6 +27,11 @@ func (r *Entity) Insert() (result sql.Result, err error) { return Model.Data(r).Insert() } +// InsertIgnore does "INSERT IGNORE INTO ..." statement for inserting current object into table. +func (r *Entity) InsertIgnore() (result sql.Result, err error) { + return Model.Data(r).InsertIgnore() +} + // Replace does "REPLACE...INTO..." statement for inserting current object into table. // If there's already another same record in the table (it checks using primary key or unique index), // it deletes it and insert this one. diff --git a/app/model/admin/cms_category_news/cms_category_news_model.go b/app/model/admin/cms_category_news/cms_category_news_model.go index 8a35a6b..5f319bd 100644 --- a/app/model/admin/cms_category_news/cms_category_news_model.go +++ b/app/model/admin/cms_category_news/cms_category_news_model.go @@ -8,12 +8,13 @@ import ( "database/sql" "github.com/gogf/gf/database/gdb" "github.com/gogf/gf/frame/g" + "github.com/gogf/gf/frame/gmvc" "time" ) // arModel is a active record design model for table cms_category_news operations. type arModel struct { - M *gdb.Model + gmvc.M } var ( @@ -21,6 +22,16 @@ var ( Table = "cms_category_news" // Model is the model object of cms_category_news. Model = &arModel{g.DB("default").Table(Table).Safe()} + // Columns defines and stores column names for table cms_category_news. + Columns = struct { + Id string // + NewsId string // 文章id + CategoryId string // 分类id + }{ + Id: "id", + NewsId: "news_id", + CategoryId: "category_id", + } ) // FindOne is a convenience method for Model.FindOne. @@ -41,6 +52,12 @@ func FindValue(fieldsAndWhere ...interface{}) (gdb.Value, error) { return Model.FindValue(fieldsAndWhere...) } +// FindArray is a convenience method for Model.FindArray. +// See Model.FindArray. +func FindArray(fieldsAndWhere ...interface{}) ([]gdb.Value, error) { + return Model.FindArray(fieldsAndWhere...) +} + // FindCount is a convenience method for Model.FindCount. // See Model.FindCount. func FindCount(where ...interface{}) (int, error) { @@ -52,6 +69,11 @@ func Insert(data ...interface{}) (result sql.Result, err error) { return Model.Insert(data...) } +// InsertIgnore is a convenience method for Model.InsertIgnore. +func InsertIgnore(data ...interface{}) (result sql.Result, err error) { + return Model.InsertIgnore(data...) +} + // Replace is a convenience method for Model.Replace. func Replace(data ...interface{}) (result sql.Result, err error) { return Model.Replace(data...) @@ -94,18 +116,30 @@ func (m *arModel) Slave() *arModel { } // LeftJoin does "LEFT JOIN ... ON ..." statement on the model. -func (m *arModel) LeftJoin(joinTable string, on string) *arModel { - return &arModel{m.M.LeftJoin(joinTable, on)} +// The parameter
can be joined table and its joined condition, +// and also with its alias name, like: +// Table("user").LeftJoin("user_detail", "user_detail.uid=user.uid") +// Table("user", "u").LeftJoin("user_detail", "ud", "ud.uid=u.uid") +func (m *arModel) LeftJoin(table ...string) *arModel { + return &arModel{m.M.LeftJoin(table...)} } // RightJoin does "RIGHT JOIN ... ON ..." statement on the model. -func (m *arModel) RightJoin(joinTable string, on string) *arModel { - return &arModel{m.M.RightJoin(joinTable, on)} +// The parameter
can be joined table and its joined condition, +// and also with its alias name, like: +// Table("user").RightJoin("user_detail", "user_detail.uid=user.uid") +// Table("user", "u").RightJoin("user_detail", "ud", "ud.uid=u.uid") +func (m *arModel) RightJoin(table ...string) *arModel { + return &arModel{m.M.RightJoin(table...)} } // InnerJoin does "INNER JOIN ... ON ..." statement on the model. -func (m *arModel) InnerJoin(joinTable string, on string) *arModel { - return &arModel{m.M.InnerJoin(joinTable, on)} +// The parameter
can be joined table and its joined condition, +// and also with its alias name, like: +// Table("user").InnerJoin("user_detail", "user_detail.uid=user.uid") +// Table("user", "u").InnerJoin("user_detail", "ud", "ud.uid=u.uid") +func (m *arModel) InnerJoin(table ...string) *arModel { + return &arModel{m.M.InnerJoin(table...)} } // Fields sets the operation fields of the model, multiple fields joined using char ','. @@ -165,8 +199,8 @@ func (m *arModel) Group(groupBy string) *arModel { } // Order sets the "ORDER BY" statement for the model. -func (m *arModel) Order(orderBy string) *arModel { - return &arModel{m.M.Order(orderBy)} +func (m *arModel) Order(orderBy ...string) *arModel { + return &arModel{m.M.Order(orderBy...)} } // Limit sets the "LIMIT" statement for the model. @@ -207,8 +241,8 @@ func (m *arModel) Batch(batch int) *arModel { // control the cache like changing the or clearing the cache with specified . // // Note that, the cache feature is disabled if the model is operating on a transaction. -func (m *arModel) Cache(expire time.Duration, name ...string) *arModel { - return &arModel{m.M.Cache(expire, name...)} +func (m *arModel) Cache(duration time.Duration, name ...string) *arModel { + return &arModel{m.M.Cache(duration, name...)} } // Data sets the operation data for the model. @@ -222,53 +256,6 @@ func (m *arModel) Data(data ...interface{}) *arModel { return &arModel{m.M.Data(data...)} } -// Insert does "INSERT INTO ..." statement for the model. -// The optional parameter is the same as the parameter of Model.Data function, -// see Model.Data. -func (m *arModel) Insert(data ...interface{}) (result sql.Result, err error) { - return m.M.Insert(data...) -} - -// Replace does "REPLACE INTO ..." statement for the model. -// The optional parameter is the same as the parameter of Model.Data function, -// see Model.Data. -func (m *arModel) Replace(data ...interface{}) (result sql.Result, err error) { - return m.M.Replace(data...) -} - -// Save does "INSERT INTO ... ON DUPLICATE KEY UPDATE..." statement for the model. -// It updates the record if there's primary or unique index in the saving data, -// or else it inserts a new record into the table. -// -// The optional parameter is the same as the parameter of Model.Data function, -// see Model.Data. -func (m *arModel) Save(data ...interface{}) (result sql.Result, err error) { - return m.M.Save(data...) -} - -// Update does "UPDATE ... " statement for the model. -// -// If the optional parameter is given, the dataAndWhere[0] is the updated -// data field, and dataAndWhere[1:] is treated as where condition fields. -// Also see Model.Data and Model.Where functions. -func (m *arModel) Update(dataAndWhere ...interface{}) (result sql.Result, err error) { - return m.M.Update(dataAndWhere...) -} - -// Delete does "DELETE FROM ... " statement for the model. -// The optional parameter is the same as the parameter of Model.Where function, -// see Model.Where. -func (m *arModel) Delete(where ...interface{}) (result sql.Result, err error) { - return m.M.Delete(where...) -} - -// Count does "SELECT COUNT(x) FROM ..." statement for the model. -// The optional parameter is the same as the parameter of Model.Where function, -// see Model.Where. -func (m *arModel) Count(where ...interface{}) (int, error) { - return m.M.Count(where...) -} - // All does "SELECT FROM ..." statement for the model. // It retrieves the records from table and returns the result as []*Entity. // It returns nil if there's no record retrieved with the given conditions from table. @@ -304,16 +291,6 @@ func (m *arModel) One(where ...interface{}) (*Entity, error) { return entity, nil } -// Value retrieves a specified record value from table and returns the result as interface type. -// It returns nil if there's no record found with the given conditions from table. -// -// If the optional parameter is given, the fieldsAndWhere[0] is the selected fields -// and fieldsAndWhere[1:] is treated as where condition fields. -// Also see Model.Fields and Model.Where functions. -func (m *arModel) Value(fieldsAndWhere ...interface{}) (gdb.Value, error) { - return m.M.Value(fieldsAndWhere...) -} - // FindOne retrieves and returns a single Record by Model.WherePri and Model.One. // Also see Model.WherePri and Model.One. func (m *arModel) FindOne(where ...interface{}) (*Entity, error) { @@ -342,18 +319,6 @@ func (m *arModel) FindAll(where ...interface{}) ([]*Entity, error) { return entities, nil } -// FindValue retrieves and returns single field value by Model.WherePri and Model.Value. -// Also see Model.WherePri and Model.Value. -func (m *arModel) FindValue(fieldsAndWhere ...interface{}) (gdb.Value, error) { - return m.M.FindValue(fieldsAndWhere...) -} - -// FindCount retrieves and returns the record number by Model.WherePri and Model.Count. -// Also see Model.WherePri and Model.Count. -func (m *arModel) FindCount(where ...interface{}) (int, error) { - return m.M.FindCount(where...) -} - // Chunk iterates the table with given size and callback function. func (m *arModel) Chunk(limit int, callback func(entities []*Entity, err error) bool) { m.M.Chunk(limit, func(result gdb.Result, err error) bool { @@ -365,3 +330,18 @@ func (m *arModel) Chunk(limit int, callback func(entities []*Entity, err error) return callback(entities, err) }) } + +// LockUpdate sets the lock for update for current operation. +func (m *arModel) LockUpdate() *arModel { + return &arModel{m.M.LockUpdate()} +} + +// LockShared sets the lock in share mode for current operation. +func (m *arModel) LockShared() *arModel { + return &arModel{m.M.LockShared()} +} + +// Unscoped enables/disables the soft deleting feature. +func (m *arModel) Unscoped() *arModel { + return &arModel{m.M.Unscoped()} +} diff --git a/app/model/admin/cms_news/cms_news.go b/app/model/admin/cms_news/cms_news.go index 6868f56..724d4ca 100644 --- a/app/model/admin/cms_news/cms_news.go +++ b/app/model/admin/cms_news/cms_news.go @@ -49,7 +49,7 @@ type ReqEditParams struct { } //添加文章操作 -func AddNews(req *ReqAddParams, cateIds []int, userId int, tx *gdb.TX) (insId int64, err error) { +func AddNews(req *ReqAddParams, cateIds []int, userId uint64, tx *gdb.TX) (insId int64, err error) { if len(cateIds) == 0 { err = gerror.New("栏目不能为空") return diff --git a/app/model/admin/model_info/model_info.go b/app/model/admin/model_info/model_info.go index d9eea89..17e6b7c 100644 --- a/app/model/admin/model_info/model_info.go +++ b/app/model/admin/model_info/model_info.go @@ -21,7 +21,7 @@ type AddReq struct { ModelTitle string `p:"modelTitle" v:"required#模型名称不能为空"` ModelStatus uint `p:"modelStatus" v:"required#状态不能为空"` ModelEngine string `p:"modelEngine" ` - CreateBy int //添加人 + CreateBy uint64 //添加人 } // EditReq 用于存储修改请求参数 @@ -32,7 +32,7 @@ type EditReq struct { ModelTitle string `p:"modelTitle" ` ModelStatus int `p:"modelStatus" v:"required#状态不能为空"` ModelEngine string `p:"modelEngine" ` - UpdateBy int + UpdateBy uint64 } //模型字段属性修改请求参数 diff --git a/app/model/admin/role/role.go b/app/model/admin/role/role.go index 3c02dae..356b319 100644 --- a/app/model/admin/role/role.go +++ b/app/model/admin/role/role.go @@ -30,7 +30,7 @@ type SelectPageReq struct { //修改状态参数 type StatusSetReq struct { RoleId uint `p:"roleId" v:"required#角色ID不能为空"` - Status int `p:"status" v:"required#状态不能为空"` + Status uint `p:"status" v:"required#状态不能为空"` } //角色数据授权参数 @@ -90,7 +90,7 @@ func GetList() (list []*Entity, err error) { return } //从数据库获取 - list, err = Model.OrderBy("list_order asc,id asc").All() + list, err = Model.Order("list_order asc,id asc").All() //缓存数据 cache.Set(cache_service.AdminAuthRole, list, 0, cache_service.AdminAuthTag) return diff --git a/app/model/admin/role/role_entity.go b/app/model/admin/role/role_entity.go index 4bd9791..90decd8 100644 --- a/app/model/admin/role/role_entity.go +++ b/app/model/admin/role/role_entity.go @@ -9,21 +9,18 @@ import ( "github.com/gogf/gf/database/gdb" ) -// Entity is the golang structure for table _role. +// Entity is the golang structure for table role. type Entity struct { - Id int `orm:"id,primary" json:"id"` // - Status int `orm:"status" json:"status"` // 状态;0:禁用;1:正常 - CreateTime int `orm:"create_time" json:"create_time"` // 创建时间 - UpdateTime int `orm:"update_time" json:"update_time"` // 更新时间 - ListOrder float64 `orm:"list_order" json:"list_order"` // 排序 - Name string `orm:"name" json:"name"` // 角色名称 - Remark string `orm:"remark" json:"remark"` // 备注 - DataScope int `orm:"data_scope" json:"data_scope"` // 数据范围(1:全部数据权限 2:自定数据权限 3:本部门数据权限 4:本部门及以下数据权限) + Id uint `orm:"id,primary" json:"id"` // + Status uint `orm:"status" json:"status"` // 状态;0:禁用;1:正常 + CreateTime uint `orm:"create_time" json:"create_time"` // 创建时间 + UpdateTime uint `orm:"update_time" json:"update_time"` // 更新时间 + ListOrder float64 `orm:"list_order" json:"list_order"` // 排序 + Name string `orm:"name" json:"name"` // 角色名称 + Remark string `orm:"remark" json:"remark"` // 备注 + DataScope uint `orm:"data_scope" json:"data_scope"` // 数据范围(1:全部数据权限 2:自定数据权限 3:本部门数据权限 4:本部门及以下数据权限) } -// Role is alias of Entity, which some developers say they just want. -type Role = Entity - // OmitEmpty sets OPTION_OMITEMPTY option for the model, which automatically filers // the data and where attributes for empty values. func (r *Entity) OmitEmpty() *arModel { @@ -35,6 +32,11 @@ func (r *Entity) Insert() (result sql.Result, err error) { return Model.Data(r).Insert() } +// InsertIgnore does "INSERT IGNORE INTO ..." statement for inserting current object into table. +func (r *Entity) InsertIgnore() (result sql.Result, err error) { + return Model.Data(r).InsertIgnore() +} + // Replace does "REPLACE...INTO..." statement for inserting current object into table. // If there's already another same record in the table (it checks using primary key or unique index), // it deletes it and insert this one. diff --git a/app/model/admin/role/role_model.go b/app/model/admin/role/role_model.go index 6ad45df..1bf0012 100644 --- a/app/model/admin/role/role_model.go +++ b/app/model/admin/role/role_model.go @@ -8,21 +8,107 @@ import ( "database/sql" "github.com/gogf/gf/database/gdb" "github.com/gogf/gf/frame/g" + "github.com/gogf/gf/frame/gmvc" "time" ) -// arModel is a active record design model for table _role operations. +// arModel is a active record design model for table role operations. type arModel struct { - M *gdb.Model + gmvc.M } var ( - // Table is the table name of _role. + // Table is the table name of role. Table = "role" - // Model is the model object of _role. + // Model is the model object of role. Model = &arModel{g.DB("default").Table(Table).Safe()} + // Columns defines and stores column names for table role. + Columns = struct { + Id string // + Status string // 状态;0:禁用;1:正常 + CreateTime string // 创建时间 + UpdateTime string // 更新时间 + ListOrder string // 排序 + Name string // 角色名称 + Remark string // 备注 + DataScope string // 数据范围(1:全部数据权限 2:自定数据权限 3:本部门数据权限 4:本部门及以下数据权限) + }{ + Id: "id", + Status: "status", + CreateTime: "create_time", + UpdateTime: "update_time", + ListOrder: "list_order", + Name: "name", + Remark: "remark", + DataScope: "data_scope", + } ) +// FindOne is a convenience method for Model.FindOne. +// See Model.FindOne. +func FindOne(where ...interface{}) (*Entity, error) { + return Model.FindOne(where...) +} + +// FindAll is a convenience method for Model.FindAll. +// See Model.FindAll. +func FindAll(where ...interface{}) ([]*Entity, error) { + return Model.FindAll(where...) +} + +// FindValue is a convenience method for Model.FindValue. +// See Model.FindValue. +func FindValue(fieldsAndWhere ...interface{}) (gdb.Value, error) { + return Model.FindValue(fieldsAndWhere...) +} + +// FindArray is a convenience method for Model.FindArray. +// See Model.FindArray. +func FindArray(fieldsAndWhere ...interface{}) ([]gdb.Value, error) { + return Model.FindArray(fieldsAndWhere...) +} + +// FindCount is a convenience method for Model.FindCount. +// See Model.FindCount. +func FindCount(where ...interface{}) (int, error) { + return Model.FindCount(where...) +} + +// Insert is a convenience method for Model.Insert. +func Insert(data ...interface{}) (result sql.Result, err error) { + return Model.Insert(data...) +} + +// InsertIgnore is a convenience method for Model.InsertIgnore. +func InsertIgnore(data ...interface{}) (result sql.Result, err error) { + return Model.InsertIgnore(data...) +} + +// Replace is a convenience method for Model.Replace. +func Replace(data ...interface{}) (result sql.Result, err error) { + return Model.Replace(data...) +} + +// Save is a convenience method for Model.Save. +func Save(data ...interface{}) (result sql.Result, err error) { + return Model.Save(data...) +} + +// Update is a convenience method for Model.Update. +func Update(dataAndWhere ...interface{}) (result sql.Result, err error) { + return Model.Update(dataAndWhere...) +} + +// Delete is a convenience method for Model.Delete. +func Delete(where ...interface{}) (result sql.Result, err error) { + return Model.Delete(where...) +} + +// As sets an alias name for current table. +func (m *arModel) As(as string) *arModel { + return &arModel{m.M.As(as)} +} + // TX sets the transaction for current operation. func (m *arModel) TX(tx *gdb.TX) *arModel { return &arModel{m.M.TX(tx)} @@ -40,18 +126,30 @@ func (m *arModel) Slave() *arModel { } // LeftJoin does "LEFT JOIN ... ON ..." statement on the model. -func (m *arModel) LeftJoin(joinTable string, on string) *arModel { - return &arModel{m.M.LeftJoin(joinTable, on)} +// The parameter
can be joined table and its joined condition, +// and also with its alias name, like: +// Table("user").LeftJoin("user_detail", "user_detail.uid=user.uid") +// Table("user", "u").LeftJoin("user_detail", "ud", "ud.uid=u.uid") +func (m *arModel) LeftJoin(table ...string) *arModel { + return &arModel{m.M.LeftJoin(table...)} } // RightJoin does "RIGHT JOIN ... ON ..." statement on the model. -func (m *arModel) RightJoin(joinTable string, on string) *arModel { - return &arModel{m.M.RightJoin(joinTable, on)} +// The parameter
can be joined table and its joined condition, +// and also with its alias name, like: +// Table("user").RightJoin("user_detail", "user_detail.uid=user.uid") +// Table("user", "u").RightJoin("user_detail", "ud", "ud.uid=u.uid") +func (m *arModel) RightJoin(table ...string) *arModel { + return &arModel{m.M.RightJoin(table...)} } // InnerJoin does "INNER JOIN ... ON ..." statement on the model. -func (m *arModel) InnerJoin(joinTable string, on string) *arModel { - return &arModel{m.M.InnerJoin(joinTable, on)} +// The parameter
can be joined table and its joined condition, +// and also with its alias name, like: +// Table("user").InnerJoin("user_detail", "user_detail.uid=user.uid") +// Table("user", "u").InnerJoin("user_detail", "ud", "ud.uid=u.uid") +func (m *arModel) InnerJoin(table ...string) *arModel { + return &arModel{m.M.InnerJoin(table...)} } // Fields sets the operation fields of the model, multiple fields joined using char ','. @@ -105,14 +203,14 @@ func (m *arModel) Or(where interface{}, args ...interface{}) *arModel { return &arModel{m.M.Or(where, args...)} } -// GroupBy sets the "GROUP BY" statement for the model. -func (m *arModel) GroupBy(groupBy string) *arModel { - return &arModel{m.M.GroupBy(groupBy)} +// Group sets the "GROUP BY" statement for the model. +func (m *arModel) Group(groupBy string) *arModel { + return &arModel{m.M.Group(groupBy)} } -// OrderBy sets the "ORDER BY" statement for the model. -func (m *arModel) OrderBy(orderBy string) *arModel { - return &arModel{m.M.OrderBy(orderBy)} +// Order sets the "ORDER BY" statement for the model. +func (m *arModel) Order(orderBy ...string) *arModel { + return &arModel{m.M.Order(orderBy...)} } // Limit sets the "LIMIT" statement for the model. @@ -129,11 +227,11 @@ func (m *arModel) Offset(offset int) *arModel { return &arModel{m.M.Offset(offset)} } -// ForPage sets the paging number for the model. +// Page sets the paging number for the model. // The parameter is started from 1 for paging. // Note that, it differs that the Limit function start from 0 for "LIMIT" statement. -func (m *arModel) ForPage(page, limit int) *arModel { - return &arModel{m.M.ForPage(page, limit)} +func (m *arModel) Page(page, limit int) *arModel { + return &arModel{m.M.Page(page, limit)} } // Batch sets the batch operation number for the model. @@ -153,8 +251,8 @@ func (m *arModel) Batch(batch int) *arModel { // control the cache like changing the or clearing the cache with specified . // // Note that, the cache feature is disabled if the model is operating on a transaction. -func (m *arModel) Cache(expire time.Duration, name ...string) *arModel { - return &arModel{m.M.Cache(expire, name...)} +func (m *arModel) Cache(duration time.Duration, name ...string) *arModel { + return &arModel{m.M.Cache(duration, name...)} } // Data sets the operation data for the model. @@ -168,43 +266,14 @@ func (m *arModel) Data(data ...interface{}) *arModel { return &arModel{m.M.Data(data...)} } -// Insert does "INSERT INTO ..." statement for the model. -func (m *arModel) Insert() (result sql.Result, err error) { - return m.M.Insert() -} - -// Replace does "REPLACE INTO ..." statement for the model. -func (m *arModel) Replace() (result sql.Result, err error) { - return m.M.Replace() -} - -// Save does "INSERT INTO ... ON DUPLICATE KEY UPDATE..." statement for the model. -// It updates the record if there's primary or unique index in the saving data, -// or else it inserts a new record into the table. -func (m *arModel) Save() (result sql.Result, err error) { - return m.M.Save() -} - -// Update does "UPDATE ... " statement for the model. -func (m *arModel) Update() (result sql.Result, err error) { - return m.M.Update() -} - -// Delete does "DELETE FROM ... " statement for the model. -func (m *arModel) Delete() (result sql.Result, err error) { - return m.M.Delete() -} - -// Count does "SELECT COUNT(x) FROM ..." statement for the model. -func (m *arModel) Count() (int, error) { - return m.M.Count() -} - // All does "SELECT FROM ..." statement for the model. // It retrieves the records from table and returns the result as []*Entity. // It returns nil if there's no record retrieved with the given conditions from table. -func (m *arModel) All() ([]*Entity, error) { - all, err := m.M.All() +// +// The optional parameter is the same as the parameter of Model.Where function, +// see Model.Where. +func (m *arModel) All(where ...interface{}) ([]*Entity, error) { + all, err := m.M.All(where...) if err != nil { return nil, err } @@ -217,8 +286,11 @@ func (m *arModel) All() ([]*Entity, error) { // One retrieves one record from table and returns the result as *Entity. // It returns nil if there's no record retrieved with the given conditions from table. -func (m *arModel) One() (*Entity, error) { - one, err := m.M.One() +// +// The optional parameter is the same as the parameter of Model.Where function, +// see Model.Where. +func (m *arModel) One(where ...interface{}) (*Entity, error) { + one, err := m.M.One(where...) if err != nil { return nil, err } @@ -229,10 +301,32 @@ func (m *arModel) One() (*Entity, error) { return entity, nil } -// Value retrieves a specified record value from table and returns the result as interface type. -// It returns nil if there's no record found with the given conditions from table. -func (m *arModel) Value() (gdb.Value, error) { - return m.M.Value() +// FindOne retrieves and returns a single Record by Model.WherePri and Model.One. +// Also see Model.WherePri and Model.One. +func (m *arModel) FindOne(where ...interface{}) (*Entity, error) { + one, err := m.M.FindOne(where...) + if err != nil { + return nil, err + } + var entity *Entity + if err = one.Struct(&entity); err != nil && err != sql.ErrNoRows { + return nil, err + } + return entity, nil +} + +// FindAll retrieves and returns Result by by Model.WherePri and Model.All. +// Also see Model.WherePri and Model.All. +func (m *arModel) FindAll(where ...interface{}) ([]*Entity, error) { + all, err := m.M.FindAll(where...) + if err != nil { + return nil, err + } + var entities []*Entity + if err = all.Structs(&entities); err != nil && err != sql.ErrNoRows { + return nil, err + } + return entities, nil } // Chunk iterates the table with given size and callback function. @@ -247,14 +341,17 @@ func (m *arModel) Chunk(limit int, callback func(entities []*Entity, err error) }) } -// Page sets the paging number for the model. -// The parameter is started from 1 for paging. -// Note that, it differs that the Limit function start from 0 for "LIMIT" statement. -func (m *arModel) Page(page, limit int) *arModel { - return &arModel{m.M.Page(page, limit)} +// LockUpdate sets the lock for update for current operation. +func (m *arModel) LockUpdate() *arModel { + return &arModel{m.M.LockUpdate()} } -// Order sets the "ORDER BY" statement for the model. -func (m *arModel) Order(orderBy string) *arModel { - return &arModel{m.M.Order(orderBy)} +// LockShared sets the lock in share mode for current operation. +func (m *arModel) LockShared() *arModel { + return &arModel{m.M.LockShared()} +} + +// Unscoped enables/disables the soft deleting feature. +func (m *arModel) Unscoped() *arModel { + return &arModel{m.M.Unscoped()} } diff --git a/app/model/admin/sys_config/sys_config.go b/app/model/admin/sys_config/sys_config.go index dc73653..cf34cc3 100644 --- a/app/model/admin/sys_config/sys_config.go +++ b/app/model/admin/sys_config/sys_config.go @@ -37,7 +37,7 @@ type SelectPageReq struct { } //保存参数 -func AddSave(req *AddReq, userId int) (id int64, err error) { +func AddSave(req *AddReq, userId uint64) (id int64, err error) { var entity Entity entity.ConfigName = req.ConfigName entity.ConfigKey = req.ConfigKey @@ -62,7 +62,7 @@ func AddSave(req *AddReq, userId int) (id int64, err error) { } //修改保存 -func EditSave(req *EditReq, userId int) (int64, error) { +func EditSave(req *EditReq, userId uint64) (int64, error) { entity, err := GetParamsById(gconv.Int(req.ConfigId)) if err != nil { return 0, err diff --git a/app/model/admin/sys_config/sys_config_entity.go b/app/model/admin/sys_config/sys_config_entity.go index 43dc7bf..1bc6037 100644 --- a/app/model/admin/sys_config/sys_config_entity.go +++ b/app/model/admin/sys_config/sys_config_entity.go @@ -13,7 +13,7 @@ import ( type Entity struct { ConfigId uint `orm:"config_id,primary" json:"config_id"` // 参数主键 ConfigName string `orm:"config_name" json:"config_name"` // 参数名称 - ConfigKey string `orm:"config_key" json:"config_key"` // 参数键名 + ConfigKey string `orm:"config_key,unique" json:"config_key"` // 参数键名 ConfigValue string `orm:"config_value" json:"config_value"` // 参数键值 ConfigType int `orm:"config_type" json:"config_type"` // 系统内置(Y是 N否) CreateBy uint `orm:"create_by" json:"create_by"` // 创建者 @@ -34,6 +34,11 @@ func (r *Entity) Insert() (result sql.Result, err error) { return Model.Data(r).Insert() } +// InsertIgnore does "INSERT IGNORE INTO ..." statement for inserting current object into table. +func (r *Entity) InsertIgnore() (result sql.Result, err error) { + return Model.Data(r).InsertIgnore() +} + // Replace does "REPLACE...INTO..." statement for inserting current object into table. // If there's already another same record in the table (it checks using primary key or unique index), // it deletes it and insert this one. diff --git a/app/model/admin/sys_config/sys_config_model.go b/app/model/admin/sys_config/sys_config_model.go index 122d086..01b6a56 100644 --- a/app/model/admin/sys_config/sys_config_model.go +++ b/app/model/admin/sys_config/sys_config_model.go @@ -8,12 +8,13 @@ import ( "database/sql" "github.com/gogf/gf/database/gdb" "github.com/gogf/gf/frame/g" + "github.com/gogf/gf/frame/gmvc" "time" ) // arModel is a active record design model for table sys_config operations. type arModel struct { - M *gdb.Model + gmvc.M } var ( @@ -21,6 +22,30 @@ var ( Table = "sys_config" // Model is the model object of sys_config. Model = &arModel{g.DB("default").Table(Table).Safe()} + // Columns defines and stores column names for table sys_config. + Columns = struct { + ConfigId string // 参数主键 + ConfigName string // 参数名称 + ConfigKey string // 参数键名 + ConfigValue string // 参数键值 + ConfigType string // 系统内置(Y是 N否) + CreateBy string // 创建者 + CreateTime string // 创建时间 + UpdateBy string // 更新者 + UpdateTime string // 更新时间 + Remark string // 备注 + }{ + ConfigId: "config_id", + ConfigName: "config_name", + ConfigKey: "config_key", + ConfigValue: "config_value", + ConfigType: "config_type", + CreateBy: "create_by", + CreateTime: "create_time", + UpdateBy: "update_by", + UpdateTime: "update_time", + Remark: "remark", + } ) // FindOne is a convenience method for Model.FindOne. @@ -41,6 +66,12 @@ func FindValue(fieldsAndWhere ...interface{}) (gdb.Value, error) { return Model.FindValue(fieldsAndWhere...) } +// FindArray is a convenience method for Model.FindArray. +// See Model.FindArray. +func FindArray(fieldsAndWhere ...interface{}) ([]gdb.Value, error) { + return Model.FindArray(fieldsAndWhere...) +} + // FindCount is a convenience method for Model.FindCount. // See Model.FindCount. func FindCount(where ...interface{}) (int, error) { @@ -52,6 +83,11 @@ func Insert(data ...interface{}) (result sql.Result, err error) { return Model.Insert(data...) } +// InsertIgnore is a convenience method for Model.InsertIgnore. +func InsertIgnore(data ...interface{}) (result sql.Result, err error) { + return Model.InsertIgnore(data...) +} + // Replace is a convenience method for Model.Replace. func Replace(data ...interface{}) (result sql.Result, err error) { return Model.Replace(data...) @@ -94,18 +130,30 @@ func (m *arModel) Slave() *arModel { } // LeftJoin does "LEFT JOIN ... ON ..." statement on the model. -func (m *arModel) LeftJoin(joinTable string, on string) *arModel { - return &arModel{m.M.LeftJoin(joinTable, on)} +// The parameter
can be joined table and its joined condition, +// and also with its alias name, like: +// Table("user").LeftJoin("user_detail", "user_detail.uid=user.uid") +// Table("user", "u").LeftJoin("user_detail", "ud", "ud.uid=u.uid") +func (m *arModel) LeftJoin(table ...string) *arModel { + return &arModel{m.M.LeftJoin(table...)} } // RightJoin does "RIGHT JOIN ... ON ..." statement on the model. -func (m *arModel) RightJoin(joinTable string, on string) *arModel { - return &arModel{m.M.RightJoin(joinTable, on)} +// The parameter
can be joined table and its joined condition, +// and also with its alias name, like: +// Table("user").RightJoin("user_detail", "user_detail.uid=user.uid") +// Table("user", "u").RightJoin("user_detail", "ud", "ud.uid=u.uid") +func (m *arModel) RightJoin(table ...string) *arModel { + return &arModel{m.M.RightJoin(table...)} } // InnerJoin does "INNER JOIN ... ON ..." statement on the model. -func (m *arModel) InnerJoin(joinTable string, on string) *arModel { - return &arModel{m.M.InnerJoin(joinTable, on)} +// The parameter
can be joined table and its joined condition, +// and also with its alias name, like: +// Table("user").InnerJoin("user_detail", "user_detail.uid=user.uid") +// Table("user", "u").InnerJoin("user_detail", "ud", "ud.uid=u.uid") +func (m *arModel) InnerJoin(table ...string) *arModel { + return &arModel{m.M.InnerJoin(table...)} } // Fields sets the operation fields of the model, multiple fields joined using char ','. @@ -165,8 +213,8 @@ func (m *arModel) Group(groupBy string) *arModel { } // Order sets the "ORDER BY" statement for the model. -func (m *arModel) Order(orderBy string) *arModel { - return &arModel{m.M.Order(orderBy)} +func (m *arModel) Order(orderBy ...string) *arModel { + return &arModel{m.M.Order(orderBy...)} } // Limit sets the "LIMIT" statement for the model. @@ -207,8 +255,8 @@ func (m *arModel) Batch(batch int) *arModel { // control the cache like changing the or clearing the cache with specified . // // Note that, the cache feature is disabled if the model is operating on a transaction. -func (m *arModel) Cache(expire time.Duration, name ...string) *arModel { - return &arModel{m.M.Cache(expire, name...)} +func (m *arModel) Cache(duration time.Duration, name ...string) *arModel { + return &arModel{m.M.Cache(duration, name...)} } // Data sets the operation data for the model. @@ -222,53 +270,6 @@ func (m *arModel) Data(data ...interface{}) *arModel { return &arModel{m.M.Data(data...)} } -// Insert does "INSERT INTO ..." statement for the model. -// The optional parameter is the same as the parameter of Model.Data function, -// see Model.Data. -func (m *arModel) Insert(data ...interface{}) (result sql.Result, err error) { - return m.M.Insert(data...) -} - -// Replace does "REPLACE INTO ..." statement for the model. -// The optional parameter is the same as the parameter of Model.Data function, -// see Model.Data. -func (m *arModel) Replace(data ...interface{}) (result sql.Result, err error) { - return m.M.Replace(data...) -} - -// Save does "INSERT INTO ... ON DUPLICATE KEY UPDATE..." statement for the model. -// It updates the record if there's primary or unique index in the saving data, -// or else it inserts a new record into the table. -// -// The optional parameter is the same as the parameter of Model.Data function, -// see Model.Data. -func (m *arModel) Save(data ...interface{}) (result sql.Result, err error) { - return m.M.Save(data...) -} - -// Update does "UPDATE ... " statement for the model. -// -// If the optional parameter is given, the dataAndWhere[0] is the updated -// data field, and dataAndWhere[1:] is treated as where condition fields. -// Also see Model.Data and Model.Where functions. -func (m *arModel) Update(dataAndWhere ...interface{}) (result sql.Result, err error) { - return m.M.Update(dataAndWhere...) -} - -// Delete does "DELETE FROM ... " statement for the model. -// The optional parameter is the same as the parameter of Model.Where function, -// see Model.Where. -func (m *arModel) Delete(where ...interface{}) (result sql.Result, err error) { - return m.M.Delete(where...) -} - -// Count does "SELECT COUNT(x) FROM ..." statement for the model. -// The optional parameter is the same as the parameter of Model.Where function, -// see Model.Where. -func (m *arModel) Count(where ...interface{}) (int, error) { - return m.M.Count(where...) -} - // All does "SELECT FROM ..." statement for the model. // It retrieves the records from table and returns the result as []*Entity. // It returns nil if there's no record retrieved with the given conditions from table. @@ -304,16 +305,6 @@ func (m *arModel) One(where ...interface{}) (*Entity, error) { return entity, nil } -// Value retrieves a specified record value from table and returns the result as interface type. -// It returns nil if there's no record found with the given conditions from table. -// -// If the optional parameter is given, the fieldsAndWhere[0] is the selected fields -// and fieldsAndWhere[1:] is treated as where condition fields. -// Also see Model.Fields and Model.Where functions. -func (m *arModel) Value(fieldsAndWhere ...interface{}) (gdb.Value, error) { - return m.M.Value(fieldsAndWhere...) -} - // FindOne retrieves and returns a single Record by Model.WherePri and Model.One. // Also see Model.WherePri and Model.One. func (m *arModel) FindOne(where ...interface{}) (*Entity, error) { @@ -342,18 +333,6 @@ func (m *arModel) FindAll(where ...interface{}) ([]*Entity, error) { return entities, nil } -// FindValue retrieves and returns single field value by Model.WherePri and Model.Value. -// Also see Model.WherePri and Model.Value. -func (m *arModel) FindValue(fieldsAndWhere ...interface{}) (gdb.Value, error) { - return m.M.FindValue(fieldsAndWhere...) -} - -// FindCount retrieves and returns the record number by Model.WherePri and Model.Count. -// Also see Model.WherePri and Model.Count. -func (m *arModel) FindCount(where ...interface{}) (int, error) { - return m.M.FindCount(where...) -} - // Chunk iterates the table with given size and callback function. func (m *arModel) Chunk(limit int, callback func(entities []*Entity, err error) bool) { m.M.Chunk(limit, func(result gdb.Result, err error) bool { @@ -365,3 +344,18 @@ func (m *arModel) Chunk(limit int, callback func(entities []*Entity, err error) return callback(entities, err) }) } + +// LockUpdate sets the lock for update for current operation. +func (m *arModel) LockUpdate() *arModel { + return &arModel{m.M.LockUpdate()} +} + +// LockShared sets the lock in share mode for current operation. +func (m *arModel) LockShared() *arModel { + return &arModel{m.M.LockShared()} +} + +// Unscoped enables/disables the soft deleting feature. +func (m *arModel) Unscoped() *arModel { + return &arModel{m.M.Unscoped()} +} diff --git a/app/model/admin/sys_dept/sys_dept.go b/app/model/admin/sys_dept/sys_dept.go index 963640f..8cfe5a0 100644 --- a/app/model/admin/sys_dept/sys_dept.go +++ b/app/model/admin/sys_dept/sys_dept.go @@ -21,7 +21,7 @@ type Dept struct { Remark string `json:"remark"` DataScope interface{} `json:"dataScope"` Params map[string]interface{} `json:"params"` - DeptID int64 `json:"deptId" orm:"dept_id"` + DeptID uint64 `json:"deptId" orm:"dept_id"` ParentID int64 `json:"parentId" orm:"parent_id"` Ancestors string `json:"ancestors" orm:"ancestors"` DeptName string `json:"deptName" orm:"dept_name"` @@ -120,7 +120,7 @@ func DelDept(id int64) error { } //根据部门id获取部门信息 -func GetDeptById(id int64) (*Dept, error) { +func GetDeptById(id uint64) (*Dept, error) { dept := (*Dept)(nil) diff --git a/app/model/admin/sys_dict_data/sys_dict_data.go b/app/model/admin/sys_dict_data/sys_dict_data.go index 168c900..37b19ba 100644 --- a/app/model/admin/sys_dict_data/sys_dict_data.go +++ b/app/model/admin/sys_dict_data/sys_dict_data.go @@ -38,7 +38,7 @@ type SelectDataPageReq struct { } //添加字典数据操作 -func AddSaveData(req *AddDataReq, userId int) (int64, error) { +func AddSaveData(req *AddDataReq, userId uint64) (int64, error) { var entity Entity entity.DictType = req.DictType entity.Status = req.Status @@ -80,7 +80,7 @@ func GetById(dictCode int) (*Entity, error) { } //修改字典数据操作 -func EditSaveData(req *EditDataReq, userId int) (int64, error) { +func EditSaveData(req *EditDataReq, userId uint64) (int64, error) { entity, err := GetById(req.DictCode) if err != nil { return 0, err diff --git a/app/model/admin/sys_dict_data/sys_dict_data_entity.go b/app/model/admin/sys_dict_data/sys_dict_data_entity.go index f1c633e..5fb52b0 100644 --- a/app/model/admin/sys_dict_data/sys_dict_data_entity.go +++ b/app/model/admin/sys_dict_data/sys_dict_data_entity.go @@ -20,9 +20,9 @@ type Entity struct { ListClass string `orm:"list_class" json:"list_class"` // 表格回显样式 IsDefault int `orm:"is_default" json:"is_default"` // 是否默认(1是 0否) Status int `orm:"status" json:"status"` // 状态(0正常 1停用) - CreateBy int `orm:"create_by" json:"create_by"` // 创建者 + CreateBy uint64 `orm:"create_by" json:"create_by"` // 创建者 CreateTime uint64 `orm:"create_time" json:"create_time"` // 创建时间 - UpdateBy int `orm:"update_by" json:"update_by"` // 更新者 + UpdateBy uint64 `orm:"update_by" json:"update_by"` // 更新者 UpdateTime uint64 `orm:"update_time" json:"update_time"` // 更新时间 Remark string `orm:"remark" json:"remark"` // 备注 } @@ -38,6 +38,11 @@ func (r *Entity) Insert() (result sql.Result, err error) { return Model.Data(r).Insert() } +// InsertIgnore does "INSERT IGNORE INTO ..." statement for inserting current object into table. +func (r *Entity) InsertIgnore() (result sql.Result, err error) { + return Model.Data(r).InsertIgnore() +} + // Replace does "REPLACE...INTO..." statement for inserting current object into table. // If there's already another same record in the table (it checks using primary key or unique index), // it deletes it and insert this one. diff --git a/app/model/admin/sys_dict_data/sys_dict_data_model.go b/app/model/admin/sys_dict_data/sys_dict_data_model.go index e47fb2f..ed2c19d 100644 --- a/app/model/admin/sys_dict_data/sys_dict_data_model.go +++ b/app/model/admin/sys_dict_data/sys_dict_data_model.go @@ -8,12 +8,13 @@ import ( "database/sql" "github.com/gogf/gf/database/gdb" "github.com/gogf/gf/frame/g" + "github.com/gogf/gf/frame/gmvc" "time" ) // arModel is a active record design model for table sys_dict_data operations. type arModel struct { - M *gdb.Model + gmvc.M } var ( @@ -21,6 +22,38 @@ var ( Table = "sys_dict_data" // Model is the model object of sys_dict_data. Model = &arModel{g.DB("default").Table(Table).Safe()} + // Columns defines and stores column names for table sys_dict_data. + Columns = struct { + DictCode string // 字典编码 + DictSort string // 字典排序 + DictLabel string // 字典标签 + DictValue string // 字典键值 + DictType string // 字典类型 + CssClass string // 样式属性(其他样式扩展) + ListClass string // 表格回显样式 + IsDefault string // 是否默认(1是 0否) + Status string // 状态(0正常 1停用) + CreateBy string // 创建者 + CreateTime string // 创建时间 + UpdateBy string // 更新者 + UpdateTime string // 更新时间 + Remark string // 备注 + }{ + DictCode: "dict_code", + DictSort: "dict_sort", + DictLabel: "dict_label", + DictValue: "dict_value", + DictType: "dict_type", + CssClass: "css_class", + ListClass: "list_class", + IsDefault: "is_default", + Status: "status", + CreateBy: "create_by", + CreateTime: "create_time", + UpdateBy: "update_by", + UpdateTime: "update_time", + Remark: "remark", + } ) // FindOne is a convenience method for Model.FindOne. @@ -41,6 +74,12 @@ func FindValue(fieldsAndWhere ...interface{}) (gdb.Value, error) { return Model.FindValue(fieldsAndWhere...) } +// FindArray is a convenience method for Model.FindArray. +// See Model.FindArray. +func FindArray(fieldsAndWhere ...interface{}) ([]gdb.Value, error) { + return Model.FindArray(fieldsAndWhere...) +} + // FindCount is a convenience method for Model.FindCount. // See Model.FindCount. func FindCount(where ...interface{}) (int, error) { @@ -52,6 +91,11 @@ func Insert(data ...interface{}) (result sql.Result, err error) { return Model.Insert(data...) } +// InsertIgnore is a convenience method for Model.InsertIgnore. +func InsertIgnore(data ...interface{}) (result sql.Result, err error) { + return Model.InsertIgnore(data...) +} + // Replace is a convenience method for Model.Replace. func Replace(data ...interface{}) (result sql.Result, err error) { return Model.Replace(data...) @@ -94,18 +138,30 @@ func (m *arModel) Slave() *arModel { } // LeftJoin does "LEFT JOIN ... ON ..." statement on the model. -func (m *arModel) LeftJoin(joinTable string, on string) *arModel { - return &arModel{m.M.LeftJoin(joinTable, on)} +// The parameter
can be joined table and its joined condition, +// and also with its alias name, like: +// Table("user").LeftJoin("user_detail", "user_detail.uid=user.uid") +// Table("user", "u").LeftJoin("user_detail", "ud", "ud.uid=u.uid") +func (m *arModel) LeftJoin(table ...string) *arModel { + return &arModel{m.M.LeftJoin(table...)} } // RightJoin does "RIGHT JOIN ... ON ..." statement on the model. -func (m *arModel) RightJoin(joinTable string, on string) *arModel { - return &arModel{m.M.RightJoin(joinTable, on)} +// The parameter
can be joined table and its joined condition, +// and also with its alias name, like: +// Table("user").RightJoin("user_detail", "user_detail.uid=user.uid") +// Table("user", "u").RightJoin("user_detail", "ud", "ud.uid=u.uid") +func (m *arModel) RightJoin(table ...string) *arModel { + return &arModel{m.M.RightJoin(table...)} } // InnerJoin does "INNER JOIN ... ON ..." statement on the model. -func (m *arModel) InnerJoin(joinTable string, on string) *arModel { - return &arModel{m.M.InnerJoin(joinTable, on)} +// The parameter
can be joined table and its joined condition, +// and also with its alias name, like: +// Table("user").InnerJoin("user_detail", "user_detail.uid=user.uid") +// Table("user", "u").InnerJoin("user_detail", "ud", "ud.uid=u.uid") +func (m *arModel) InnerJoin(table ...string) *arModel { + return &arModel{m.M.InnerJoin(table...)} } // Fields sets the operation fields of the model, multiple fields joined using char ','. @@ -165,8 +221,8 @@ func (m *arModel) Group(groupBy string) *arModel { } // Order sets the "ORDER BY" statement for the model. -func (m *arModel) Order(orderBy string) *arModel { - return &arModel{m.M.Order(orderBy)} +func (m *arModel) Order(orderBy ...string) *arModel { + return &arModel{m.M.Order(orderBy...)} } // Limit sets the "LIMIT" statement for the model. @@ -207,8 +263,8 @@ func (m *arModel) Batch(batch int) *arModel { // control the cache like changing the or clearing the cache with specified . // // Note that, the cache feature is disabled if the model is operating on a transaction. -func (m *arModel) Cache(expire time.Duration, name ...string) *arModel { - return &arModel{m.M.Cache(expire, name...)} +func (m *arModel) Cache(duration time.Duration, name ...string) *arModel { + return &arModel{m.M.Cache(duration, name...)} } // Data sets the operation data for the model. @@ -222,53 +278,6 @@ func (m *arModel) Data(data ...interface{}) *arModel { return &arModel{m.M.Data(data...)} } -// Insert does "INSERT INTO ..." statement for the model. -// The optional parameter is the same as the parameter of Model.Data function, -// see Model.Data. -func (m *arModel) Insert(data ...interface{}) (result sql.Result, err error) { - return m.M.Insert(data...) -} - -// Replace does "REPLACE INTO ..." statement for the model. -// The optional parameter is the same as the parameter of Model.Data function, -// see Model.Data. -func (m *arModel) Replace(data ...interface{}) (result sql.Result, err error) { - return m.M.Replace(data...) -} - -// Save does "INSERT INTO ... ON DUPLICATE KEY UPDATE..." statement for the model. -// It updates the record if there's primary or unique index in the saving data, -// or else it inserts a new record into the table. -// -// The optional parameter is the same as the parameter of Model.Data function, -// see Model.Data. -func (m *arModel) Save(data ...interface{}) (result sql.Result, err error) { - return m.M.Save(data...) -} - -// Update does "UPDATE ... " statement for the model. -// -// If the optional parameter is given, the dataAndWhere[0] is the updated -// data field, and dataAndWhere[1:] is treated as where condition fields. -// Also see Model.Data and Model.Where functions. -func (m *arModel) Update(dataAndWhere ...interface{}) (result sql.Result, err error) { - return m.M.Update(dataAndWhere...) -} - -// Delete does "DELETE FROM ... " statement for the model. -// The optional parameter is the same as the parameter of Model.Where function, -// see Model.Where. -func (m *arModel) Delete(where ...interface{}) (result sql.Result, err error) { - return m.M.Delete(where...) -} - -// Count does "SELECT COUNT(x) FROM ..." statement for the model. -// The optional parameter is the same as the parameter of Model.Where function, -// see Model.Where. -func (m *arModel) Count(where ...interface{}) (int, error) { - return m.M.Count(where...) -} - // All does "SELECT FROM ..." statement for the model. // It retrieves the records from table and returns the result as []*Entity. // It returns nil if there's no record retrieved with the given conditions from table. @@ -304,16 +313,6 @@ func (m *arModel) One(where ...interface{}) (*Entity, error) { return entity, nil } -// Value retrieves a specified record value from table and returns the result as interface type. -// It returns nil if there's no record found with the given conditions from table. -// -// If the optional parameter is given, the fieldsAndWhere[0] is the selected fields -// and fieldsAndWhere[1:] is treated as where condition fields. -// Also see Model.Fields and Model.Where functions. -func (m *arModel) Value(fieldsAndWhere ...interface{}) (gdb.Value, error) { - return m.M.Value(fieldsAndWhere...) -} - // FindOne retrieves and returns a single Record by Model.WherePri and Model.One. // Also see Model.WherePri and Model.One. func (m *arModel) FindOne(where ...interface{}) (*Entity, error) { @@ -342,18 +341,6 @@ func (m *arModel) FindAll(where ...interface{}) ([]*Entity, error) { return entities, nil } -// FindValue retrieves and returns single field value by Model.WherePri and Model.Value. -// Also see Model.WherePri and Model.Value. -func (m *arModel) FindValue(fieldsAndWhere ...interface{}) (gdb.Value, error) { - return m.M.FindValue(fieldsAndWhere...) -} - -// FindCount retrieves and returns the record number by Model.WherePri and Model.Count. -// Also see Model.WherePri and Model.Count. -func (m *arModel) FindCount(where ...interface{}) (int, error) { - return m.M.FindCount(where...) -} - // Chunk iterates the table with given size and callback function. func (m *arModel) Chunk(limit int, callback func(entities []*Entity, err error) bool) { m.M.Chunk(limit, func(result gdb.Result, err error) bool { @@ -365,3 +352,18 @@ func (m *arModel) Chunk(limit int, callback func(entities []*Entity, err error) return callback(entities, err) }) } + +// LockUpdate sets the lock for update for current operation. +func (m *arModel) LockUpdate() *arModel { + return &arModel{m.M.LockUpdate()} +} + +// LockShared sets the lock in share mode for current operation. +func (m *arModel) LockShared() *arModel { + return &arModel{m.M.LockShared()} +} + +// Unscoped enables/disables the soft deleting feature. +func (m *arModel) Unscoped() *arModel { + return &arModel{m.M.Unscoped()} +} diff --git a/app/model/admin/sys_dict_type/sys_dict_type.go b/app/model/admin/sys_dict_type/sys_dict_type.go index a436ba7..488781c 100644 --- a/app/model/admin/sys_dict_type/sys_dict_type.go +++ b/app/model/admin/sys_dict_type/sys_dict_type.go @@ -40,7 +40,7 @@ type SelectPageReq struct { } //添加数据 -func AddSave(req *AddReq, userId int) (int64, error) { +func AddSave(req *AddReq, userId uint64) (int64, error) { var entity Entity entity.Status = req.Status entity.DictType = req.DictType @@ -76,7 +76,7 @@ func GetDictById(id int) (dict *Entity, err error) { } //修改保存字典类型 -func EditSave(req *EditReq, userId int) (int64, error) { +func EditSave(req *EditReq, userId uint64) (int64, error) { entity, err := GetDictById(gconv.Int(req.DictId)) if err != nil || entity == nil { return 0, err diff --git a/app/model/admin/sys_dict_type/sys_dict_type_entity.go b/app/model/admin/sys_dict_type/sys_dict_type_entity.go index 24e7f21..d6477df 100644 --- a/app/model/admin/sys_dict_type/sys_dict_type_entity.go +++ b/app/model/admin/sys_dict_type/sys_dict_type_entity.go @@ -33,6 +33,11 @@ func (r *Entity) Insert() (result sql.Result, err error) { return Model.Data(r).Insert() } +// InsertIgnore does "INSERT IGNORE INTO ..." statement for inserting current object into table. +func (r *Entity) InsertIgnore() (result sql.Result, err error) { + return Model.Data(r).InsertIgnore() +} + // Replace does "REPLACE...INTO..." statement for inserting current object into table. // If there's already another same record in the table (it checks using primary key or unique index), // it deletes it and insert this one. diff --git a/app/model/admin/sys_dict_type/sys_dict_type_model.go b/app/model/admin/sys_dict_type/sys_dict_type_model.go index 9f1bbb8..644defe 100644 --- a/app/model/admin/sys_dict_type/sys_dict_type_model.go +++ b/app/model/admin/sys_dict_type/sys_dict_type_model.go @@ -8,12 +8,13 @@ import ( "database/sql" "github.com/gogf/gf/database/gdb" "github.com/gogf/gf/frame/g" + "github.com/gogf/gf/frame/gmvc" "time" ) // arModel is a active record design model for table sys_dict_type operations. type arModel struct { - M *gdb.Model + gmvc.M } var ( @@ -21,6 +22,28 @@ var ( Table = "sys_dict_type" // Model is the model object of sys_dict_type. Model = &arModel{g.DB("default").Table(Table).Safe()} + // Columns defines and stores column names for table sys_dict_type. + Columns = struct { + DictId string // 字典主键 + DictName string // 字典名称 + DictType string // 字典类型 + Status string // 状态(0正常 1停用) + CreateBy string // 创建者 + CreateTime string // 创建时间 + UpdateBy string // 更新者 + UpdateTime string // 更新时间 + Remark string // 备注 + }{ + DictId: "dict_id", + DictName: "dict_name", + DictType: "dict_type", + Status: "status", + CreateBy: "create_by", + CreateTime: "create_time", + UpdateBy: "update_by", + UpdateTime: "update_time", + Remark: "remark", + } ) // FindOne is a convenience method for Model.FindOne. @@ -41,6 +64,12 @@ func FindValue(fieldsAndWhere ...interface{}) (gdb.Value, error) { return Model.FindValue(fieldsAndWhere...) } +// FindArray is a convenience method for Model.FindArray. +// See Model.FindArray. +func FindArray(fieldsAndWhere ...interface{}) ([]gdb.Value, error) { + return Model.FindArray(fieldsAndWhere...) +} + // FindCount is a convenience method for Model.FindCount. // See Model.FindCount. func FindCount(where ...interface{}) (int, error) { @@ -52,6 +81,11 @@ func Insert(data ...interface{}) (result sql.Result, err error) { return Model.Insert(data...) } +// InsertIgnore is a convenience method for Model.InsertIgnore. +func InsertIgnore(data ...interface{}) (result sql.Result, err error) { + return Model.InsertIgnore(data...) +} + // Replace is a convenience method for Model.Replace. func Replace(data ...interface{}) (result sql.Result, err error) { return Model.Replace(data...) @@ -94,18 +128,30 @@ func (m *arModel) Slave() *arModel { } // LeftJoin does "LEFT JOIN ... ON ..." statement on the model. -func (m *arModel) LeftJoin(joinTable string, on string) *arModel { - return &arModel{m.M.LeftJoin(joinTable, on)} +// The parameter
can be joined table and its joined condition, +// and also with its alias name, like: +// Table("user").LeftJoin("user_detail", "user_detail.uid=user.uid") +// Table("user", "u").LeftJoin("user_detail", "ud", "ud.uid=u.uid") +func (m *arModel) LeftJoin(table ...string) *arModel { + return &arModel{m.M.LeftJoin(table...)} } // RightJoin does "RIGHT JOIN ... ON ..." statement on the model. -func (m *arModel) RightJoin(joinTable string, on string) *arModel { - return &arModel{m.M.RightJoin(joinTable, on)} +// The parameter
can be joined table and its joined condition, +// and also with its alias name, like: +// Table("user").RightJoin("user_detail", "user_detail.uid=user.uid") +// Table("user", "u").RightJoin("user_detail", "ud", "ud.uid=u.uid") +func (m *arModel) RightJoin(table ...string) *arModel { + return &arModel{m.M.RightJoin(table...)} } // InnerJoin does "INNER JOIN ... ON ..." statement on the model. -func (m *arModel) InnerJoin(joinTable string, on string) *arModel { - return &arModel{m.M.InnerJoin(joinTable, on)} +// The parameter
can be joined table and its joined condition, +// and also with its alias name, like: +// Table("user").InnerJoin("user_detail", "user_detail.uid=user.uid") +// Table("user", "u").InnerJoin("user_detail", "ud", "ud.uid=u.uid") +func (m *arModel) InnerJoin(table ...string) *arModel { + return &arModel{m.M.InnerJoin(table...)} } // Fields sets the operation fields of the model, multiple fields joined using char ','. @@ -165,8 +211,8 @@ func (m *arModel) Group(groupBy string) *arModel { } // Order sets the "ORDER BY" statement for the model. -func (m *arModel) Order(orderBy string) *arModel { - return &arModel{m.M.Order(orderBy)} +func (m *arModel) Order(orderBy ...string) *arModel { + return &arModel{m.M.Order(orderBy...)} } // Limit sets the "LIMIT" statement for the model. @@ -207,8 +253,8 @@ func (m *arModel) Batch(batch int) *arModel { // control the cache like changing the or clearing the cache with specified . // // Note that, the cache feature is disabled if the model is operating on a transaction. -func (m *arModel) Cache(expire time.Duration, name ...string) *arModel { - return &arModel{m.M.Cache(expire, name...)} +func (m *arModel) Cache(duration time.Duration, name ...string) *arModel { + return &arModel{m.M.Cache(duration, name...)} } // Data sets the operation data for the model. @@ -222,53 +268,6 @@ func (m *arModel) Data(data ...interface{}) *arModel { return &arModel{m.M.Data(data...)} } -// Insert does "INSERT INTO ..." statement for the model. -// The optional parameter is the same as the parameter of Model.Data function, -// see Model.Data. -func (m *arModel) Insert(data ...interface{}) (result sql.Result, err error) { - return m.M.Insert(data...) -} - -// Replace does "REPLACE INTO ..." statement for the model. -// The optional parameter is the same as the parameter of Model.Data function, -// see Model.Data. -func (m *arModel) Replace(data ...interface{}) (result sql.Result, err error) { - return m.M.Replace(data...) -} - -// Save does "INSERT INTO ... ON DUPLICATE KEY UPDATE..." statement for the model. -// It updates the record if there's primary or unique index in the saving data, -// or else it inserts a new record into the table. -// -// The optional parameter is the same as the parameter of Model.Data function, -// see Model.Data. -func (m *arModel) Save(data ...interface{}) (result sql.Result, err error) { - return m.M.Save(data...) -} - -// Update does "UPDATE ... " statement for the model. -// -// If the optional parameter is given, the dataAndWhere[0] is the updated -// data field, and dataAndWhere[1:] is treated as where condition fields. -// Also see Model.Data and Model.Where functions. -func (m *arModel) Update(dataAndWhere ...interface{}) (result sql.Result, err error) { - return m.M.Update(dataAndWhere...) -} - -// Delete does "DELETE FROM ... " statement for the model. -// The optional parameter is the same as the parameter of Model.Where function, -// see Model.Where. -func (m *arModel) Delete(where ...interface{}) (result sql.Result, err error) { - return m.M.Delete(where...) -} - -// Count does "SELECT COUNT(x) FROM ..." statement for the model. -// The optional parameter is the same as the parameter of Model.Where function, -// see Model.Where. -func (m *arModel) Count(where ...interface{}) (int, error) { - return m.M.Count(where...) -} - // All does "SELECT FROM ..." statement for the model. // It retrieves the records from table and returns the result as []*Entity. // It returns nil if there's no record retrieved with the given conditions from table. @@ -304,16 +303,6 @@ func (m *arModel) One(where ...interface{}) (*Entity, error) { return entity, nil } -// Value retrieves a specified record value from table and returns the result as interface type. -// It returns nil if there's no record found with the given conditions from table. -// -// If the optional parameter is given, the fieldsAndWhere[0] is the selected fields -// and fieldsAndWhere[1:] is treated as where condition fields. -// Also see Model.Fields and Model.Where functions. -func (m *arModel) Value(fieldsAndWhere ...interface{}) (gdb.Value, error) { - return m.M.Value(fieldsAndWhere...) -} - // FindOne retrieves and returns a single Record by Model.WherePri and Model.One. // Also see Model.WherePri and Model.One. func (m *arModel) FindOne(where ...interface{}) (*Entity, error) { @@ -342,18 +331,6 @@ func (m *arModel) FindAll(where ...interface{}) ([]*Entity, error) { return entities, nil } -// FindValue retrieves and returns single field value by Model.WherePri and Model.Value. -// Also see Model.WherePri and Model.Value. -func (m *arModel) FindValue(fieldsAndWhere ...interface{}) (gdb.Value, error) { - return m.M.FindValue(fieldsAndWhere...) -} - -// FindCount retrieves and returns the record number by Model.WherePri and Model.Count. -// Also see Model.WherePri and Model.Count. -func (m *arModel) FindCount(where ...interface{}) (int, error) { - return m.M.FindCount(where...) -} - // Chunk iterates the table with given size and callback function. func (m *arModel) Chunk(limit int, callback func(entities []*Entity, err error) bool) { m.M.Chunk(limit, func(result gdb.Result, err error) bool { @@ -365,3 +342,18 @@ func (m *arModel) Chunk(limit int, callback func(entities []*Entity, err error) return callback(entities, err) }) } + +// LockUpdate sets the lock for update for current operation. +func (m *arModel) LockUpdate() *arModel { + return &arModel{m.M.LockUpdate()} +} + +// LockShared sets the lock in share mode for current operation. +func (m *arModel) LockShared() *arModel { + return &arModel{m.M.LockShared()} +} + +// Unscoped enables/disables the soft deleting feature. +func (m *arModel) Unscoped() *arModel { + return &arModel{m.M.Unscoped()} +} diff --git a/app/model/admin/sys_job/sys_job.go b/app/model/admin/sys_job/sys_job.go index 9cf44b9..e7a108c 100644 --- a/app/model/admin/sys_job/sys_job.go +++ b/app/model/admin/sys_job/sys_job.go @@ -47,7 +47,7 @@ func GetJobs() (jobs []*Entity, err error) { } //添加计划任务 -func Add(req *ReqAdd, userId int) (id int64, err error) { +func Add(req *ReqAdd, userId uint64) (id int64, err error) { entity := new(Entity) entity.JobName = req.JobName entity.JobGroup = req.JobGroup @@ -90,7 +90,7 @@ func GetJobInfoById(id int64) (job *Entity, err error) { } //修改计划任务 -func Edit(req *ReqEdit, userId int) (rows int64, err error) { +func Edit(req *ReqEdit, userId uint64) (rows int64, err error) { entity, err := GetJobInfoById(req.JobId) if err != nil { return diff --git a/app/model/admin/sys_job/sys_job_entity.go b/app/model/admin/sys_job/sys_job_entity.go index 1d2f1f8..438dc09 100644 --- a/app/model/admin/sys_job/sys_job_entity.go +++ b/app/model/admin/sys_job/sys_job_entity.go @@ -38,6 +38,11 @@ func (r *Entity) Insert() (result sql.Result, err error) { return Model.Data(r).Insert() } +// InsertIgnore does "INSERT IGNORE INTO ..." statement for inserting current object into table. +func (r *Entity) InsertIgnore() (result sql.Result, err error) { + return Model.Data(r).InsertIgnore() +} + // Replace does "REPLACE...INTO..." statement for inserting current object into table. // If there's already another same record in the table (it checks using primary key or unique index), // it deletes it and insert this one. diff --git a/app/model/admin/sys_job/sys_job_model.go b/app/model/admin/sys_job/sys_job_model.go index 32b0d55..fb4733e 100644 --- a/app/model/admin/sys_job/sys_job_model.go +++ b/app/model/admin/sys_job/sys_job_model.go @@ -8,12 +8,13 @@ import ( "database/sql" "github.com/gogf/gf/database/gdb" "github.com/gogf/gf/frame/g" + "github.com/gogf/gf/frame/gmvc" "time" ) // arModel is a active record design model for table sys_job operations. type arModel struct { - M *gdb.Model + gmvc.M } var ( @@ -21,6 +22,38 @@ var ( Table = "sys_job" // Model is the model object of sys_job. Model = &arModel{g.DB("default").Table(Table).Safe()} + // Columns defines and stores column names for table sys_job. + Columns = struct { + JobId string // 任务ID + JobName string // 任务名称 + JobParams string // 参数 + JobGroup string // 任务组名 + InvokeTarget string // 调用目标字符串 + CronExpression string // cron执行表达式 + MisfirePolicy string // 计划执行策略(1多次执行 2执行一次) + Concurrent string // 是否并发执行(0允许 1禁止) + Status string // 状态(0正常 1暂停) + CreateBy string // 创建者 + CreateTime string // 创建时间 + UpdateBy string // 更新者 + UpdateTime string // 更新时间 + Remark string // 备注信息 + }{ + JobId: "job_id", + JobName: "job_name", + JobParams: "job_params", + JobGroup: "job_group", + InvokeTarget: "invoke_target", + CronExpression: "cron_expression", + MisfirePolicy: "misfire_policy", + Concurrent: "concurrent", + Status: "status", + CreateBy: "create_by", + CreateTime: "create_time", + UpdateBy: "update_by", + UpdateTime: "update_time", + Remark: "remark", + } ) // FindOne is a convenience method for Model.FindOne. @@ -41,6 +74,12 @@ func FindValue(fieldsAndWhere ...interface{}) (gdb.Value, error) { return Model.FindValue(fieldsAndWhere...) } +// FindArray is a convenience method for Model.FindArray. +// See Model.FindArray. +func FindArray(fieldsAndWhere ...interface{}) ([]gdb.Value, error) { + return Model.FindArray(fieldsAndWhere...) +} + // FindCount is a convenience method for Model.FindCount. // See Model.FindCount. func FindCount(where ...interface{}) (int, error) { @@ -52,6 +91,11 @@ func Insert(data ...interface{}) (result sql.Result, err error) { return Model.Insert(data...) } +// InsertIgnore is a convenience method for Model.InsertIgnore. +func InsertIgnore(data ...interface{}) (result sql.Result, err error) { + return Model.InsertIgnore(data...) +} + // Replace is a convenience method for Model.Replace. func Replace(data ...interface{}) (result sql.Result, err error) { return Model.Replace(data...) @@ -94,18 +138,30 @@ func (m *arModel) Slave() *arModel { } // LeftJoin does "LEFT JOIN ... ON ..." statement on the model. -func (m *arModel) LeftJoin(joinTable string, on string) *arModel { - return &arModel{m.M.LeftJoin(joinTable, on)} +// The parameter
can be joined table and its joined condition, +// and also with its alias name, like: +// Table("user").LeftJoin("user_detail", "user_detail.uid=user.uid") +// Table("user", "u").LeftJoin("user_detail", "ud", "ud.uid=u.uid") +func (m *arModel) LeftJoin(table ...string) *arModel { + return &arModel{m.M.LeftJoin(table...)} } // RightJoin does "RIGHT JOIN ... ON ..." statement on the model. -func (m *arModel) RightJoin(joinTable string, on string) *arModel { - return &arModel{m.M.RightJoin(joinTable, on)} +// The parameter
can be joined table and its joined condition, +// and also with its alias name, like: +// Table("user").RightJoin("user_detail", "user_detail.uid=user.uid") +// Table("user", "u").RightJoin("user_detail", "ud", "ud.uid=u.uid") +func (m *arModel) RightJoin(table ...string) *arModel { + return &arModel{m.M.RightJoin(table...)} } // InnerJoin does "INNER JOIN ... ON ..." statement on the model. -func (m *arModel) InnerJoin(joinTable string, on string) *arModel { - return &arModel{m.M.InnerJoin(joinTable, on)} +// The parameter
can be joined table and its joined condition, +// and also with its alias name, like: +// Table("user").InnerJoin("user_detail", "user_detail.uid=user.uid") +// Table("user", "u").InnerJoin("user_detail", "ud", "ud.uid=u.uid") +func (m *arModel) InnerJoin(table ...string) *arModel { + return &arModel{m.M.InnerJoin(table...)} } // Fields sets the operation fields of the model, multiple fields joined using char ','. @@ -165,8 +221,8 @@ func (m *arModel) Group(groupBy string) *arModel { } // Order sets the "ORDER BY" statement for the model. -func (m *arModel) Order(orderBy string) *arModel { - return &arModel{m.M.Order(orderBy)} +func (m *arModel) Order(orderBy ...string) *arModel { + return &arModel{m.M.Order(orderBy...)} } // Limit sets the "LIMIT" statement for the model. @@ -207,8 +263,8 @@ func (m *arModel) Batch(batch int) *arModel { // control the cache like changing the or clearing the cache with specified . // // Note that, the cache feature is disabled if the model is operating on a transaction. -func (m *arModel) Cache(expire time.Duration, name ...string) *arModel { - return &arModel{m.M.Cache(expire, name...)} +func (m *arModel) Cache(duration time.Duration, name ...string) *arModel { + return &arModel{m.M.Cache(duration, name...)} } // Data sets the operation data for the model. @@ -222,53 +278,6 @@ func (m *arModel) Data(data ...interface{}) *arModel { return &arModel{m.M.Data(data...)} } -// Insert does "INSERT INTO ..." statement for the model. -// The optional parameter is the same as the parameter of Model.Data function, -// see Model.Data. -func (m *arModel) Insert(data ...interface{}) (result sql.Result, err error) { - return m.M.Insert(data...) -} - -// Replace does "REPLACE INTO ..." statement for the model. -// The optional parameter is the same as the parameter of Model.Data function, -// see Model.Data. -func (m *arModel) Replace(data ...interface{}) (result sql.Result, err error) { - return m.M.Replace(data...) -} - -// Save does "INSERT INTO ... ON DUPLICATE KEY UPDATE..." statement for the model. -// It updates the record if there's primary or unique index in the saving data, -// or else it inserts a new record into the table. -// -// The optional parameter is the same as the parameter of Model.Data function, -// see Model.Data. -func (m *arModel) Save(data ...interface{}) (result sql.Result, err error) { - return m.M.Save(data...) -} - -// Update does "UPDATE ... " statement for the model. -// -// If the optional parameter is given, the dataAndWhere[0] is the updated -// data field, and dataAndWhere[1:] is treated as where condition fields. -// Also see Model.Data and Model.Where functions. -func (m *arModel) Update(dataAndWhere ...interface{}) (result sql.Result, err error) { - return m.M.Update(dataAndWhere...) -} - -// Delete does "DELETE FROM ... " statement for the model. -// The optional parameter is the same as the parameter of Model.Where function, -// see Model.Where. -func (m *arModel) Delete(where ...interface{}) (result sql.Result, err error) { - return m.M.Delete(where...) -} - -// Count does "SELECT COUNT(x) FROM ..." statement for the model. -// The optional parameter is the same as the parameter of Model.Where function, -// see Model.Where. -func (m *arModel) Count(where ...interface{}) (int, error) { - return m.M.Count(where...) -} - // All does "SELECT FROM ..." statement for the model. // It retrieves the records from table and returns the result as []*Entity. // It returns nil if there's no record retrieved with the given conditions from table. @@ -304,16 +313,6 @@ func (m *arModel) One(where ...interface{}) (*Entity, error) { return entity, nil } -// Value retrieves a specified record value from table and returns the result as interface type. -// It returns nil if there's no record found with the given conditions from table. -// -// If the optional parameter is given, the fieldsAndWhere[0] is the selected fields -// and fieldsAndWhere[1:] is treated as where condition fields. -// Also see Model.Fields and Model.Where functions. -func (m *arModel) Value(fieldsAndWhere ...interface{}) (gdb.Value, error) { - return m.M.Value(fieldsAndWhere...) -} - // FindOne retrieves and returns a single Record by Model.WherePri and Model.One. // Also see Model.WherePri and Model.One. func (m *arModel) FindOne(where ...interface{}) (*Entity, error) { @@ -342,18 +341,6 @@ func (m *arModel) FindAll(where ...interface{}) ([]*Entity, error) { return entities, nil } -// FindValue retrieves and returns single field value by Model.WherePri and Model.Value. -// Also see Model.WherePri and Model.Value. -func (m *arModel) FindValue(fieldsAndWhere ...interface{}) (gdb.Value, error) { - return m.M.FindValue(fieldsAndWhere...) -} - -// FindCount retrieves and returns the record number by Model.WherePri and Model.Count. -// Also see Model.WherePri and Model.Count. -func (m *arModel) FindCount(where ...interface{}) (int, error) { - return m.M.FindCount(where...) -} - // Chunk iterates the table with given size and callback function. func (m *arModel) Chunk(limit int, callback func(entities []*Entity, err error) bool) { m.M.Chunk(limit, func(result gdb.Result, err error) bool { @@ -365,3 +352,18 @@ func (m *arModel) Chunk(limit int, callback func(entities []*Entity, err error) return callback(entities, err) }) } + +// LockUpdate sets the lock for update for current operation. +func (m *arModel) LockUpdate() *arModel { + return &arModel{m.M.LockUpdate()} +} + +// LockShared sets the lock in share mode for current operation. +func (m *arModel) LockShared() *arModel { + return &arModel{m.M.LockShared()} +} + +// Unscoped enables/disables the soft deleting feature. +func (m *arModel) Unscoped() *arModel { + return &arModel{m.M.Unscoped()} +} diff --git a/app/model/admin/sys_login_log/sys_login_log_entity.go b/app/model/admin/sys_login_log/sys_login_log_entity.go index f6266ed..861f3bc 100644 --- a/app/model/admin/sys_login_log/sys_login_log_entity.go +++ b/app/model/admin/sys_login_log/sys_login_log_entity.go @@ -20,7 +20,7 @@ type Entity struct { Status int `orm:"status" json:"status"` // 登录状态(0成功 1失败) Msg string `orm:"msg" json:"msg"` // 提示消息 LoginTime int64 `orm:"login_time" json:"login_time"` // 访问时间 - Module string `orm:"module" json:"module"` //登录模块 + Module string `orm:"module" json:"module"` // 登录模块 } // OmitEmpty sets OPTION_OMITEMPTY option for the model, which automatically filers @@ -34,6 +34,11 @@ func (r *Entity) Insert() (result sql.Result, err error) { return Model.Data(r).Insert() } +// InsertIgnore does "INSERT IGNORE INTO ..." statement for inserting current object into table. +func (r *Entity) InsertIgnore() (result sql.Result, err error) { + return Model.Data(r).InsertIgnore() +} + // Replace does "REPLACE...INTO..." statement for inserting current object into table. // If there's already another same record in the table (it checks using primary key or unique index), // it deletes it and insert this one. diff --git a/app/model/admin/sys_login_log/sys_login_log_model.go b/app/model/admin/sys_login_log/sys_login_log_model.go index 0fe4678..0772bd0 100644 --- a/app/model/admin/sys_login_log/sys_login_log_model.go +++ b/app/model/admin/sys_login_log/sys_login_log_model.go @@ -8,12 +8,13 @@ import ( "database/sql" "github.com/gogf/gf/database/gdb" "github.com/gogf/gf/frame/g" + "github.com/gogf/gf/frame/gmvc" "time" ) // arModel is a active record design model for table sys_login_log operations. type arModel struct { - M *gdb.Model + gmvc.M } var ( @@ -21,6 +22,30 @@ var ( Table = "sys_login_log" // Model is the model object of sys_login_log. Model = &arModel{g.DB("default").Table(Table).Safe()} + // Columns defines and stores column names for table sys_login_log. + Columns = struct { + InfoId string // 访问ID + LoginName string // 登录账号 + Ipaddr string // 登录IP地址 + LoginLocation string // 登录地点 + Browser string // 浏览器类型 + Os string // 操作系统 + Status string // 登录状态(0成功 1失败) + Msg string // 提示消息 + LoginTime string // 访问时间 + Module string // 登录模块 + }{ + InfoId: "info_id", + LoginName: "login_name", + Ipaddr: "ipaddr", + LoginLocation: "login_location", + Browser: "browser", + Os: "os", + Status: "status", + Msg: "msg", + LoginTime: "login_time", + Module: "module", + } ) // FindOne is a convenience method for Model.FindOne. @@ -41,6 +66,12 @@ func FindValue(fieldsAndWhere ...interface{}) (gdb.Value, error) { return Model.FindValue(fieldsAndWhere...) } +// FindArray is a convenience method for Model.FindArray. +// See Model.FindArray. +func FindArray(fieldsAndWhere ...interface{}) ([]gdb.Value, error) { + return Model.FindArray(fieldsAndWhere...) +} + // FindCount is a convenience method for Model.FindCount. // See Model.FindCount. func FindCount(where ...interface{}) (int, error) { @@ -52,6 +83,11 @@ func Insert(data ...interface{}) (result sql.Result, err error) { return Model.Insert(data...) } +// InsertIgnore is a convenience method for Model.InsertIgnore. +func InsertIgnore(data ...interface{}) (result sql.Result, err error) { + return Model.InsertIgnore(data...) +} + // Replace is a convenience method for Model.Replace. func Replace(data ...interface{}) (result sql.Result, err error) { return Model.Replace(data...) @@ -94,18 +130,30 @@ func (m *arModel) Slave() *arModel { } // LeftJoin does "LEFT JOIN ... ON ..." statement on the model. -func (m *arModel) LeftJoin(joinTable string, on string) *arModel { - return &arModel{m.M.LeftJoin(joinTable, on)} +// The parameter
can be joined table and its joined condition, +// and also with its alias name, like: +// Table("user").LeftJoin("user_detail", "user_detail.uid=user.uid") +// Table("user", "u").LeftJoin("user_detail", "ud", "ud.uid=u.uid") +func (m *arModel) LeftJoin(table ...string) *arModel { + return &arModel{m.M.LeftJoin(table...)} } // RightJoin does "RIGHT JOIN ... ON ..." statement on the model. -func (m *arModel) RightJoin(joinTable string, on string) *arModel { - return &arModel{m.M.RightJoin(joinTable, on)} +// The parameter
can be joined table and its joined condition, +// and also with its alias name, like: +// Table("user").RightJoin("user_detail", "user_detail.uid=user.uid") +// Table("user", "u").RightJoin("user_detail", "ud", "ud.uid=u.uid") +func (m *arModel) RightJoin(table ...string) *arModel { + return &arModel{m.M.RightJoin(table...)} } // InnerJoin does "INNER JOIN ... ON ..." statement on the model. -func (m *arModel) InnerJoin(joinTable string, on string) *arModel { - return &arModel{m.M.InnerJoin(joinTable, on)} +// The parameter
can be joined table and its joined condition, +// and also with its alias name, like: +// Table("user").InnerJoin("user_detail", "user_detail.uid=user.uid") +// Table("user", "u").InnerJoin("user_detail", "ud", "ud.uid=u.uid") +func (m *arModel) InnerJoin(table ...string) *arModel { + return &arModel{m.M.InnerJoin(table...)} } // Fields sets the operation fields of the model, multiple fields joined using char ','. @@ -165,8 +213,8 @@ func (m *arModel) Group(groupBy string) *arModel { } // Order sets the "ORDER BY" statement for the model. -func (m *arModel) Order(orderBy string) *arModel { - return &arModel{m.M.Order(orderBy)} +func (m *arModel) Order(orderBy ...string) *arModel { + return &arModel{m.M.Order(orderBy...)} } // Limit sets the "LIMIT" statement for the model. @@ -207,8 +255,8 @@ func (m *arModel) Batch(batch int) *arModel { // control the cache like changing the or clearing the cache with specified . // // Note that, the cache feature is disabled if the model is operating on a transaction. -func (m *arModel) Cache(expire time.Duration, name ...string) *arModel { - return &arModel{m.M.Cache(expire, name...)} +func (m *arModel) Cache(duration time.Duration, name ...string) *arModel { + return &arModel{m.M.Cache(duration, name...)} } // Data sets the operation data for the model. @@ -222,53 +270,6 @@ func (m *arModel) Data(data ...interface{}) *arModel { return &arModel{m.M.Data(data...)} } -// Insert does "INSERT INTO ..." statement for the model. -// The optional parameter is the same as the parameter of Model.Data function, -// see Model.Data. -func (m *arModel) Insert(data ...interface{}) (result sql.Result, err error) { - return m.M.Insert(data...) -} - -// Replace does "REPLACE INTO ..." statement for the model. -// The optional parameter is the same as the parameter of Model.Data function, -// see Model.Data. -func (m *arModel) Replace(data ...interface{}) (result sql.Result, err error) { - return m.M.Replace(data...) -} - -// Save does "INSERT INTO ... ON DUPLICATE KEY UPDATE..." statement for the model. -// It updates the record if there's primary or unique index in the saving data, -// or else it inserts a new record into the table. -// -// The optional parameter is the same as the parameter of Model.Data function, -// see Model.Data. -func (m *arModel) Save(data ...interface{}) (result sql.Result, err error) { - return m.M.Save(data...) -} - -// Update does "UPDATE ... " statement for the model. -// -// If the optional parameter is given, the dataAndWhere[0] is the updated -// data field, and dataAndWhere[1:] is treated as where condition fields. -// Also see Model.Data and Model.Where functions. -func (m *arModel) Update(dataAndWhere ...interface{}) (result sql.Result, err error) { - return m.M.Update(dataAndWhere...) -} - -// Delete does "DELETE FROM ... " statement for the model. -// The optional parameter is the same as the parameter of Model.Where function, -// see Model.Where. -func (m *arModel) Delete(where ...interface{}) (result sql.Result, err error) { - return m.M.Delete(where...) -} - -// Count does "SELECT COUNT(x) FROM ..." statement for the model. -// The optional parameter is the same as the parameter of Model.Where function, -// see Model.Where. -func (m *arModel) Count(where ...interface{}) (int, error) { - return m.M.Count(where...) -} - // All does "SELECT FROM ..." statement for the model. // It retrieves the records from table and returns the result as []*Entity. // It returns nil if there's no record retrieved with the given conditions from table. @@ -304,16 +305,6 @@ func (m *arModel) One(where ...interface{}) (*Entity, error) { return entity, nil } -// Value retrieves a specified record value from table and returns the result as interface type. -// It returns nil if there's no record found with the given conditions from table. -// -// If the optional parameter is given, the fieldsAndWhere[0] is the selected fields -// and fieldsAndWhere[1:] is treated as where condition fields. -// Also see Model.Fields and Model.Where functions. -func (m *arModel) Value(fieldsAndWhere ...interface{}) (gdb.Value, error) { - return m.M.Value(fieldsAndWhere...) -} - // FindOne retrieves and returns a single Record by Model.WherePri and Model.One. // Also see Model.WherePri and Model.One. func (m *arModel) FindOne(where ...interface{}) (*Entity, error) { @@ -342,18 +333,6 @@ func (m *arModel) FindAll(where ...interface{}) ([]*Entity, error) { return entities, nil } -// FindValue retrieves and returns single field value by Model.WherePri and Model.Value. -// Also see Model.WherePri and Model.Value. -func (m *arModel) FindValue(fieldsAndWhere ...interface{}) (gdb.Value, error) { - return m.M.FindValue(fieldsAndWhere...) -} - -// FindCount retrieves and returns the record number by Model.WherePri and Model.Count. -// Also see Model.WherePri and Model.Count. -func (m *arModel) FindCount(where ...interface{}) (int, error) { - return m.M.FindCount(where...) -} - // Chunk iterates the table with given size and callback function. func (m *arModel) Chunk(limit int, callback func(entities []*Entity, err error) bool) { m.M.Chunk(limit, func(result gdb.Result, err error) bool { @@ -365,3 +344,18 @@ func (m *arModel) Chunk(limit int, callback func(entities []*Entity, err error) return callback(entities, err) }) } + +// LockUpdate sets the lock for update for current operation. +func (m *arModel) LockUpdate() *arModel { + return &arModel{m.M.LockUpdate()} +} + +// LockShared sets the lock in share mode for current operation. +func (m *arModel) LockShared() *arModel { + return &arModel{m.M.LockShared()} +} + +// Unscoped enables/disables the soft deleting feature. +func (m *arModel) Unscoped() *arModel { + return &arModel{m.M.Unscoped()} +} diff --git a/app/model/admin/sys_oper_log/sys_oper_log_entity.go b/app/model/admin/sys_oper_log/sys_oper_log_entity.go index 9dbe178..e7fbfa9 100644 --- a/app/model/admin/sys_oper_log/sys_oper_log_entity.go +++ b/app/model/admin/sys_oper_log/sys_oper_log_entity.go @@ -40,6 +40,11 @@ func (r *Entity) Insert() (result sql.Result, err error) { return Model.Data(r).Insert() } +// InsertIgnore does "INSERT IGNORE INTO ..." statement for inserting current object into table. +func (r *Entity) InsertIgnore() (result sql.Result, err error) { + return Model.Data(r).InsertIgnore() +} + // Replace does "REPLACE...INTO..." statement for inserting current object into table. // If there's already another same record in the table (it checks using primary key or unique index), // it deletes it and insert this one. diff --git a/app/model/admin/sys_oper_log/sys_oper_log_model.go b/app/model/admin/sys_oper_log/sys_oper_log_model.go index 57dd6ef..ffd3604 100644 --- a/app/model/admin/sys_oper_log/sys_oper_log_model.go +++ b/app/model/admin/sys_oper_log/sys_oper_log_model.go @@ -8,12 +8,13 @@ import ( "database/sql" "github.com/gogf/gf/database/gdb" "github.com/gogf/gf/frame/g" + "github.com/gogf/gf/frame/gmvc" "time" ) // arModel is a active record design model for table sys_oper_log operations. type arModel struct { - M *gdb.Model + gmvc.M } var ( @@ -21,6 +22,42 @@ var ( Table = "sys_oper_log" // Model is the model object of sys_oper_log. Model = &arModel{g.DB("default").Table(Table).Safe()} + // Columns defines and stores column names for table sys_oper_log. + Columns = struct { + OperId string // 日志主键 + Title string // 模块标题 + BusinessType string // 业务类型(0其它 1新增 2修改 3删除) + Method string // 方法名称 + RequestMethod string // 请求方式 + OperatorType string // 操作类别(0其它 1后台用户 2手机端用户) + OperName string // 操作人员 + DeptName string // 部门名称 + OperUrl string // 请求URL + OperIp string // 主机地址 + OperLocation string // 操作地点 + OperParam string // 请求参数 + JsonResult string // 返回参数 + Status string // 操作状态(0正常 1异常) + ErrorMsg string // 错误消息 + OperTime string // 操作时间 + }{ + OperId: "oper_id", + Title: "title", + BusinessType: "business_type", + Method: "method", + RequestMethod: "request_method", + OperatorType: "operator_type", + OperName: "oper_name", + DeptName: "dept_name", + OperUrl: "oper_url", + OperIp: "oper_ip", + OperLocation: "oper_location", + OperParam: "oper_param", + JsonResult: "json_result", + Status: "status", + ErrorMsg: "error_msg", + OperTime: "oper_time", + } ) // FindOne is a convenience method for Model.FindOne. @@ -41,6 +78,12 @@ func FindValue(fieldsAndWhere ...interface{}) (gdb.Value, error) { return Model.FindValue(fieldsAndWhere...) } +// FindArray is a convenience method for Model.FindArray. +// See Model.FindArray. +func FindArray(fieldsAndWhere ...interface{}) ([]gdb.Value, error) { + return Model.FindArray(fieldsAndWhere...) +} + // FindCount is a convenience method for Model.FindCount. // See Model.FindCount. func FindCount(where ...interface{}) (int, error) { @@ -52,6 +95,11 @@ func Insert(data ...interface{}) (result sql.Result, err error) { return Model.Insert(data...) } +// InsertIgnore is a convenience method for Model.InsertIgnore. +func InsertIgnore(data ...interface{}) (result sql.Result, err error) { + return Model.InsertIgnore(data...) +} + // Replace is a convenience method for Model.Replace. func Replace(data ...interface{}) (result sql.Result, err error) { return Model.Replace(data...) @@ -94,18 +142,30 @@ func (m *arModel) Slave() *arModel { } // LeftJoin does "LEFT JOIN ... ON ..." statement on the model. -func (m *arModel) LeftJoin(joinTable string, on string) *arModel { - return &arModel{m.M.LeftJoin(joinTable, on)} +// The parameter
can be joined table and its joined condition, +// and also with its alias name, like: +// Table("user").LeftJoin("user_detail", "user_detail.uid=user.uid") +// Table("user", "u").LeftJoin("user_detail", "ud", "ud.uid=u.uid") +func (m *arModel) LeftJoin(table ...string) *arModel { + return &arModel{m.M.LeftJoin(table...)} } // RightJoin does "RIGHT JOIN ... ON ..." statement on the model. -func (m *arModel) RightJoin(joinTable string, on string) *arModel { - return &arModel{m.M.RightJoin(joinTable, on)} +// The parameter
can be joined table and its joined condition, +// and also with its alias name, like: +// Table("user").RightJoin("user_detail", "user_detail.uid=user.uid") +// Table("user", "u").RightJoin("user_detail", "ud", "ud.uid=u.uid") +func (m *arModel) RightJoin(table ...string) *arModel { + return &arModel{m.M.RightJoin(table...)} } // InnerJoin does "INNER JOIN ... ON ..." statement on the model. -func (m *arModel) InnerJoin(joinTable string, on string) *arModel { - return &arModel{m.M.InnerJoin(joinTable, on)} +// The parameter
can be joined table and its joined condition, +// and also with its alias name, like: +// Table("user").InnerJoin("user_detail", "user_detail.uid=user.uid") +// Table("user", "u").InnerJoin("user_detail", "ud", "ud.uid=u.uid") +func (m *arModel) InnerJoin(table ...string) *arModel { + return &arModel{m.M.InnerJoin(table...)} } // Fields sets the operation fields of the model, multiple fields joined using char ','. @@ -165,8 +225,8 @@ func (m *arModel) Group(groupBy string) *arModel { } // Order sets the "ORDER BY" statement for the model. -func (m *arModel) Order(orderBy string) *arModel { - return &arModel{m.M.Order(orderBy)} +func (m *arModel) Order(orderBy ...string) *arModel { + return &arModel{m.M.Order(orderBy...)} } // Limit sets the "LIMIT" statement for the model. @@ -207,8 +267,8 @@ func (m *arModel) Batch(batch int) *arModel { // control the cache like changing the or clearing the cache with specified . // // Note that, the cache feature is disabled if the model is operating on a transaction. -func (m *arModel) Cache(expire time.Duration, name ...string) *arModel { - return &arModel{m.M.Cache(expire, name...)} +func (m *arModel) Cache(duration time.Duration, name ...string) *arModel { + return &arModel{m.M.Cache(duration, name...)} } // Data sets the operation data for the model. @@ -222,53 +282,6 @@ func (m *arModel) Data(data ...interface{}) *arModel { return &arModel{m.M.Data(data...)} } -// Insert does "INSERT INTO ..." statement for the model. -// The optional parameter is the same as the parameter of Model.Data function, -// see Model.Data. -func (m *arModel) Insert(data ...interface{}) (result sql.Result, err error) { - return m.M.Insert(data...) -} - -// Replace does "REPLACE INTO ..." statement for the model. -// The optional parameter is the same as the parameter of Model.Data function, -// see Model.Data. -func (m *arModel) Replace(data ...interface{}) (result sql.Result, err error) { - return m.M.Replace(data...) -} - -// Save does "INSERT INTO ... ON DUPLICATE KEY UPDATE..." statement for the model. -// It updates the record if there's primary or unique index in the saving data, -// or else it inserts a new record into the table. -// -// The optional parameter is the same as the parameter of Model.Data function, -// see Model.Data. -func (m *arModel) Save(data ...interface{}) (result sql.Result, err error) { - return m.M.Save(data...) -} - -// Update does "UPDATE ... " statement for the model. -// -// If the optional parameter is given, the dataAndWhere[0] is the updated -// data field, and dataAndWhere[1:] is treated as where condition fields. -// Also see Model.Data and Model.Where functions. -func (m *arModel) Update(dataAndWhere ...interface{}) (result sql.Result, err error) { - return m.M.Update(dataAndWhere...) -} - -// Delete does "DELETE FROM ... " statement for the model. -// The optional parameter is the same as the parameter of Model.Where function, -// see Model.Where. -func (m *arModel) Delete(where ...interface{}) (result sql.Result, err error) { - return m.M.Delete(where...) -} - -// Count does "SELECT COUNT(x) FROM ..." statement for the model. -// The optional parameter is the same as the parameter of Model.Where function, -// see Model.Where. -func (m *arModel) Count(where ...interface{}) (int, error) { - return m.M.Count(where...) -} - // All does "SELECT FROM ..." statement for the model. // It retrieves the records from table and returns the result as []*Entity. // It returns nil if there's no record retrieved with the given conditions from table. @@ -304,16 +317,6 @@ func (m *arModel) One(where ...interface{}) (*Entity, error) { return entity, nil } -// Value retrieves a specified record value from table and returns the result as interface type. -// It returns nil if there's no record found with the given conditions from table. -// -// If the optional parameter is given, the fieldsAndWhere[0] is the selected fields -// and fieldsAndWhere[1:] is treated as where condition fields. -// Also see Model.Fields and Model.Where functions. -func (m *arModel) Value(fieldsAndWhere ...interface{}) (gdb.Value, error) { - return m.M.Value(fieldsAndWhere...) -} - // FindOne retrieves and returns a single Record by Model.WherePri and Model.One. // Also see Model.WherePri and Model.One. func (m *arModel) FindOne(where ...interface{}) (*Entity, error) { @@ -342,18 +345,6 @@ func (m *arModel) FindAll(where ...interface{}) ([]*Entity, error) { return entities, nil } -// FindValue retrieves and returns single field value by Model.WherePri and Model.Value. -// Also see Model.WherePri and Model.Value. -func (m *arModel) FindValue(fieldsAndWhere ...interface{}) (gdb.Value, error) { - return m.M.FindValue(fieldsAndWhere...) -} - -// FindCount retrieves and returns the record number by Model.WherePri and Model.Count. -// Also see Model.WherePri and Model.Count. -func (m *arModel) FindCount(where ...interface{}) (int, error) { - return m.M.FindCount(where...) -} - // Chunk iterates the table with given size and callback function. func (m *arModel) Chunk(limit int, callback func(entities []*Entity, err error) bool) { m.M.Chunk(limit, func(result gdb.Result, err error) bool { @@ -365,3 +356,18 @@ func (m *arModel) Chunk(limit int, callback func(entities []*Entity, err error) return callback(entities, err) }) } + +// LockUpdate sets the lock for update for current operation. +func (m *arModel) LockUpdate() *arModel { + return &arModel{m.M.LockUpdate()} +} + +// LockShared sets the lock in share mode for current operation. +func (m *arModel) LockShared() *arModel { + return &arModel{m.M.LockShared()} +} + +// Unscoped enables/disables the soft deleting feature. +func (m *arModel) Unscoped() *arModel { + return &arModel{m.M.Unscoped()} +} diff --git a/app/model/admin/sys_post/sys_post.go b/app/model/admin/sys_post/sys_post.go index eb1a5ac..bced508 100644 --- a/app/model/admin/sys_post/sys_post.go +++ b/app/model/admin/sys_post/sys_post.go @@ -39,13 +39,13 @@ type AddParams struct { PostSort int `p:"postSort" v:"required#岗位排序不能为空"` Status string `p:"status" v:"required#状态不能为空"` Remark string `p:"remark"` - AddUser int + AddUser uint64 } type EditParams struct { PostId int64 `p:"postId" v:"required#id必须"` AddParams - UpUser int + UpUser uint64 } func List(req *SearchParams) (total, page int, list gdb.Result, err error) { diff --git a/app/model/admin/user/user.go b/app/model/admin/user/user.go index 52fb5c6..e1c31e0 100644 --- a/app/model/admin/user/user.go +++ b/app/model/admin/user/user.go @@ -10,8 +10,8 @@ import ( //设置用户状态参数 type StatusReq struct { - Id int `p:"userId" v:"required#用户id不能为空"` - UserStatus int `p:"status" v:"required#用户状态不能为空"` + Id int `p:"userId" v:"required#用户id不能为空"` + UserStatus uint `p:"status" v:"required#用户状态不能为空"` } //重置用户密码状态参数 @@ -35,7 +35,7 @@ type SearchReq struct { //添加修改用户公用请求字段 type SetUserReq struct { - DeptId int64 `p:"deptId" v:"required#用户部门不能为空"` //所属部门 + DeptId uint64 `p:"deptId" v:"required#用户部门不能为空"` //所属部门 Email string `p:"email" v:"email#邮箱格式错误"` //邮箱 NickName string `p:"nickName" v:"required#用户昵称不能为空"` Phonenumber string `p:"phonenumber" v:"required|phone#手机号不能为空|手机号格式错误"` @@ -43,7 +43,7 @@ type SetUserReq struct { Remark string `p:"remark"` RoleIds []int64 `p:"roleIds"` Sex int `p:"sex"` - Status int `p:"status"` + Status uint `p:"status"` IsAdmin int `p:"is_admin"` // 是否后台管理员 1 是 0 否 } @@ -60,7 +60,7 @@ type EditUserReq struct { UserId int `p:"userId" v:"required#用户id不能为空"` } -func GetUserById(id int) (*Entity, error) { +func GetUserById(id uint64) (*Entity, error) { return Model.Where("id", id).One() } @@ -160,7 +160,7 @@ func GetAdminList(req *SearchReq) (total, page int, userList []*Entity, err erro req.PageNum = 1 } page = req.PageNum - userList, err = userModel.ForPage(page, req.PageSize).OrderBy("id asc").All() + userList, err = userModel.Page(page, req.PageSize).Order("id asc").All() return } diff --git a/app/model/admin/user/user_entity.go b/app/model/admin/user/user_entity.go index 6c723fb..0824a8e 100644 --- a/app/model/admin/user/user_entity.go +++ b/app/model/admin/user/user_entity.go @@ -11,27 +11,24 @@ import ( // Entity is the golang structure for table user. type Entity struct { - Id int `orm:"id,primary" json:"id"` // + Id uint64 `orm:"id,primary" json:"id"` // UserName string `orm:"user_name,unique" json:"user_name"` // 用户名 Mobile string `orm:"mobile,unique" json:"mobile"` // 中国手机不带国家代码,国际手机号格式为:国家代码-手机号 UserNickname string `orm:"user_nickname" json:"user_nickname"` // 用户昵称 Birthday int `orm:"birthday" json:"birthday"` // 生日 CreateTime int `orm:"create_time" json:"create_time"` // 注册时间 UserPassword string `orm:"user_password" json:"user_password"` // 登录密码;cmf_password加密 - UserStatus int `orm:"user_status" json:"user_status"` // 用户状态;0:禁用,1:正常,2:未验证 + UserStatus uint `orm:"user_status" json:"user_status"` // 用户状态;0:禁用,1:正常,2:未验证 UserEmail string `orm:"user_email" json:"user_email"` // 用户登录邮箱 Sex int `orm:"sex" json:"sex"` // 性别;0:保密,1:男,2:女 Avatar string `orm:"avatar" json:"avatar"` // 用户头像 LastLoginTime int `orm:"last_login_time" json:"last_login_time"` // 最后登录时间 LastLoginIp string `orm:"last_login_ip" json:"last_login_ip"` // 最后登录ip - DeptId int64 `orm:"dept_id" json:"dept_id"` //所属部门id + DeptId uint64 `orm:"dept_id" json:"dept_id"` // 部门id Remark string `orm:"remark" json:"remark"` // 备注 IsAdmin int `orm:"is_admin" json:"is_admin"` // 是否后台管理员 1 是 0 否 } -// User is alias of Entity, which some developers say they just want. -type User = Entity - // OmitEmpty sets OPTION_OMITEMPTY option for the model, which automatically filers // the data and where attributes for empty values. func (r *Entity) OmitEmpty() *arModel { @@ -43,6 +40,11 @@ func (r *Entity) Insert() (result sql.Result, err error) { return Model.Data(r).Insert() } +// InsertIgnore does "INSERT IGNORE INTO ..." statement for inserting current object into table. +func (r *Entity) InsertIgnore() (result sql.Result, err error) { + return Model.Data(r).InsertIgnore() +} + // Replace does "REPLACE...INTO..." statement for inserting current object into table. // If there's already another same record in the table (it checks using primary key or unique index), // it deletes it and insert this one. diff --git a/app/model/admin/user/user_model.go b/app/model/admin/user/user_model.go index 011928e..b7a2f01 100644 --- a/app/model/admin/user/user_model.go +++ b/app/model/admin/user/user_model.go @@ -8,12 +8,13 @@ import ( "database/sql" "github.com/gogf/gf/database/gdb" "github.com/gogf/gf/frame/g" + "github.com/gogf/gf/frame/gmvc" "time" ) // arModel is a active record design model for table user operations. type arModel struct { - Model *gdb.Model + gmvc.M } var ( @@ -21,63 +22,176 @@ var ( Table = "user" // Model is the model object of user. Model = &arModel{g.DB("default").Table(Table).Safe()} + // Columns defines and stores column names for table user. + Columns = struct { + Id string // + UserName string // 用户名 + Mobile string // 中国手机不带国家代码,国际手机号格式为:国家代码-手机号 + UserNickname string // 用户昵称 + Birthday string // 生日 + CreateTime string // 注册时间 + UserPassword string // 登录密码;cmf_password加密 + UserStatus string // 用户状态;0:禁用,1:正常,2:未验证 + UserEmail string // 用户登录邮箱 + Sex string // 性别;0:保密,1:男,2:女 + Avatar string // 用户头像 + LastLoginTime string // 最后登录时间 + LastLoginIp string // 最后登录ip + DeptId string // 部门id + Remark string // 备注 + IsAdmin string // 是否后台管理员 1 是 0 否 + }{ + Id: "id", + UserName: "user_name", + Mobile: "mobile", + UserNickname: "user_nickname", + Birthday: "birthday", + CreateTime: "create_time", + UserPassword: "user_password", + UserStatus: "user_status", + UserEmail: "user_email", + Sex: "sex", + Avatar: "avatar", + LastLoginTime: "last_login_time", + LastLoginIp: "last_login_ip", + DeptId: "dept_id", + Remark: "remark", + IsAdmin: "is_admin", + } ) +// FindOne is a convenience method for Model.FindOne. +// See Model.FindOne. +func FindOne(where ...interface{}) (*Entity, error) { + return Model.FindOne(where...) +} + +// FindAll is a convenience method for Model.FindAll. +// See Model.FindAll. +func FindAll(where ...interface{}) ([]*Entity, error) { + return Model.FindAll(where...) +} + +// FindValue is a convenience method for Model.FindValue. +// See Model.FindValue. +func FindValue(fieldsAndWhere ...interface{}) (gdb.Value, error) { + return Model.FindValue(fieldsAndWhere...) +} + +// FindArray is a convenience method for Model.FindArray. +// See Model.FindArray. +func FindArray(fieldsAndWhere ...interface{}) ([]gdb.Value, error) { + return Model.FindArray(fieldsAndWhere...) +} + +// FindCount is a convenience method for Model.FindCount. +// See Model.FindCount. +func FindCount(where ...interface{}) (int, error) { + return Model.FindCount(where...) +} + +// Insert is a convenience method for Model.Insert. +func Insert(data ...interface{}) (result sql.Result, err error) { + return Model.Insert(data...) +} + +// InsertIgnore is a convenience method for Model.InsertIgnore. +func InsertIgnore(data ...interface{}) (result sql.Result, err error) { + return Model.InsertIgnore(data...) +} + +// Replace is a convenience method for Model.Replace. +func Replace(data ...interface{}) (result sql.Result, err error) { + return Model.Replace(data...) +} + +// Save is a convenience method for Model.Save. +func Save(data ...interface{}) (result sql.Result, err error) { + return Model.Save(data...) +} + +// Update is a convenience method for Model.Update. +func Update(dataAndWhere ...interface{}) (result sql.Result, err error) { + return Model.Update(dataAndWhere...) +} + +// Delete is a convenience method for Model.Delete. +func Delete(where ...interface{}) (result sql.Result, err error) { + return Model.Delete(where...) +} + +// As sets an alias name for current table. +func (m *arModel) As(as string) *arModel { + return &arModel{m.M.As(as)} +} + // TX sets the transaction for current operation. func (m *arModel) TX(tx *gdb.TX) *arModel { - return &arModel{m.Model.TX(tx)} + return &arModel{m.M.TX(tx)} } // Master marks the following operation on master node. func (m *arModel) Master() *arModel { - return &arModel{m.Model.Master()} + return &arModel{m.M.Master()} } // Slave marks the following operation on slave node. // Note that it makes sense only if there's any slave node configured. func (m *arModel) Slave() *arModel { - return &arModel{m.Model.Slave()} + return &arModel{m.M.Slave()} } // LeftJoin does "LEFT JOIN ... ON ..." statement on the model. -func (m *arModel) LeftJoin(joinTable string, on string) *arModel { - return &arModel{m.Model.LeftJoin(joinTable, on)} +// The parameter
can be joined table and its joined condition, +// and also with its alias name, like: +// Table("user").LeftJoin("user_detail", "user_detail.uid=user.uid") +// Table("user", "u").LeftJoin("user_detail", "ud", "ud.uid=u.uid") +func (m *arModel) LeftJoin(table ...string) *arModel { + return &arModel{m.M.LeftJoin(table...)} } // RightJoin does "RIGHT JOIN ... ON ..." statement on the model. -func (m *arModel) RightJoin(joinTable string, on string) *arModel { - return &arModel{m.Model.RightJoin(joinTable, on)} +// The parameter
can be joined table and its joined condition, +// and also with its alias name, like: +// Table("user").RightJoin("user_detail", "user_detail.uid=user.uid") +// Table("user", "u").RightJoin("user_detail", "ud", "ud.uid=u.uid") +func (m *arModel) RightJoin(table ...string) *arModel { + return &arModel{m.M.RightJoin(table...)} } // InnerJoin does "INNER JOIN ... ON ..." statement on the model. -func (m *arModel) InnerJoin(joinTable string, on string) *arModel { - return &arModel{m.Model.InnerJoin(joinTable, on)} +// The parameter
can be joined table and its joined condition, +// and also with its alias name, like: +// Table("user").InnerJoin("user_detail", "user_detail.uid=user.uid") +// Table("user", "u").InnerJoin("user_detail", "ud", "ud.uid=u.uid") +func (m *arModel) InnerJoin(table ...string) *arModel { + return &arModel{m.M.InnerJoin(table...)} } // Fields sets the operation fields of the model, multiple fields joined using char ','. func (m *arModel) Fields(fields string) *arModel { - return &arModel{m.Model.Fields(fields)} + return &arModel{m.M.Fields(fields)} } // FieldsEx sets the excluded operation fields of the model, multiple fields joined using char ','. func (m *arModel) FieldsEx(fields string) *arModel { - return &arModel{m.Model.FieldsEx(fields)} + return &arModel{m.M.FieldsEx(fields)} } // Option sets the extra operation option for the model. func (m *arModel) Option(option int) *arModel { - return &arModel{m.Model.Option(option)} + return &arModel{m.M.Option(option)} } // OmitEmpty sets OPTION_OMITEMPTY option for the model, which automatically filers // the data and where attributes for empty values. func (m *arModel) OmitEmpty() *arModel { - return &arModel{m.Model.OmitEmpty()} + return &arModel{m.M.OmitEmpty()} } // Filter marks filtering the fields which does not exist in the fields of the operated table. func (m *arModel) Filter() *arModel { - return &arModel{m.Model.Filter()} + return &arModel{m.M.Filter()} } // Where sets the condition statement for the model. The parameter can be type of @@ -92,27 +206,27 @@ func (m *arModel) Filter() *arModel { // Where("age IN(?,?)", 18, 50) // Where(User{ Id : 1, UserName : "john"}) func (m *arModel) Where(where interface{}, args ...interface{}) *arModel { - return &arModel{m.Model.Where(where, args...)} + return &arModel{m.M.Where(where, args...)} } // And adds "AND" condition to the where statement. func (m *arModel) And(where interface{}, args ...interface{}) *arModel { - return &arModel{m.Model.And(where, args...)} + return &arModel{m.M.And(where, args...)} } // Or adds "OR" condition to the where statement. func (m *arModel) Or(where interface{}, args ...interface{}) *arModel { - return &arModel{m.Model.Or(where, args...)} + return &arModel{m.M.Or(where, args...)} } -// GroupBy sets the "GROUP BY" statement for the model. -func (m *arModel) GroupBy(groupBy string) *arModel { - return &arModel{m.Model.GroupBy(groupBy)} +// Group sets the "GROUP BY" statement for the model. +func (m *arModel) Group(groupBy string) *arModel { + return &arModel{m.M.Group(groupBy)} } -// OrderBy sets the "ORDER BY" statement for the model. -func (m *arModel) OrderBy(orderBy string) *arModel { - return &arModel{m.Model.OrderBy(orderBy)} +// Order sets the "ORDER BY" statement for the model. +func (m *arModel) Order(orderBy ...string) *arModel { + return &arModel{m.M.Order(orderBy...)} } // Limit sets the "LIMIT" statement for the model. @@ -120,25 +234,25 @@ func (m *arModel) OrderBy(orderBy string) *arModel { // it then sets "LIMIT limit[0],limit[1]" statement for the model, or else it sets "LIMIT limit[0]" // statement. func (m *arModel) Limit(limit ...int) *arModel { - return &arModel{m.Model.Limit(limit...)} + return &arModel{m.M.Limit(limit...)} } // Offset sets the "OFFSET" statement for the model. // It only makes sense for some databases like SQLServer, PostgreSQL, etc. func (m *arModel) Offset(offset int) *arModel { - return &arModel{m.Model.Offset(offset)} + return &arModel{m.M.Offset(offset)} } -// ForPage sets the paging number for the model. +// Page sets the paging number for the model. // The parameter is started from 1 for paging. // Note that, it differs that the Limit function start from 0 for "LIMIT" statement. -func (m *arModel) ForPage(page, limit int) *arModel { - return &arModel{m.Model.Page(page, limit)} +func (m *arModel) Page(page, limit int) *arModel { + return &arModel{m.M.Page(page, limit)} } // Batch sets the batch operation number for the model. func (m *arModel) Batch(batch int) *arModel { - return &arModel{m.Model.Batch(batch)} + return &arModel{m.M.Batch(batch)} } // Cache sets the cache feature for the model. It caches the result of the sql, which means @@ -153,8 +267,8 @@ func (m *arModel) Batch(batch int) *arModel { // control the cache like changing the or clearing the cache with specified . // // Note that, the cache feature is disabled if the model is operating on a transaction. -func (m *arModel) Cache(expire time.Duration, name ...string) *arModel { - return &arModel{m.Model.Cache(expire, name...)} +func (m *arModel) Cache(duration time.Duration, name ...string) *arModel { + return &arModel{m.M.Cache(duration, name...)} } // Data sets the operation data for the model. @@ -165,46 +279,17 @@ func (m *arModel) Cache(expire time.Duration, name ...string) *arModel { // Data(g.Map{"uid": 10000, "name":"john"}) // Data(g.Slice{g.Map{"uid": 10000, "name":"john"}, g.Map{"uid": 20000, "name":"smith"}) func (m *arModel) Data(data ...interface{}) *arModel { - return &arModel{m.Model.Data(data...)} -} - -// Insert does "INSERT INTO ..." statement for the model. -func (m *arModel) Insert() (result sql.Result, err error) { - return m.Model.Insert() -} - -// Replace does "REPLACE INTO ..." statement for the model. -func (m *arModel) Replace() (result sql.Result, err error) { - return m.Model.Replace() -} - -// Save does "INSERT INTO ... ON DUPLICATE KEY UPDATE..." statement for the model. -// It updates the record if there's primary or unique index in the saving data, -// or else it inserts a new record into the table. -func (m *arModel) Save() (result sql.Result, err error) { - return m.Model.Save() -} - -// Update does "UPDATE ... " statement for the model. -func (m *arModel) Update() (result sql.Result, err error) { - return m.Model.Update() -} - -// Delete does "DELETE FROM ... " statement for the model. -func (m *arModel) Delete() (result sql.Result, err error) { - return m.Model.Delete() -} - -// Count does "SELECT COUNT(x) FROM ..." statement for the model. -func (m *arModel) Count() (int, error) { - return m.Model.Count() + return &arModel{m.M.Data(data...)} } // All does "SELECT FROM ..." statement for the model. // It retrieves the records from table and returns the result as []*Entity. // It returns nil if there's no record retrieved with the given conditions from table. -func (m *arModel) All() ([]*Entity, error) { - all, err := m.Model.All() +// +// The optional parameter is the same as the parameter of Model.Where function, +// see Model.Where. +func (m *arModel) All(where ...interface{}) ([]*Entity, error) { + all, err := m.M.All(where...) if err != nil { return nil, err } @@ -217,8 +302,11 @@ func (m *arModel) All() ([]*Entity, error) { // One retrieves one record from table and returns the result as *Entity. // It returns nil if there's no record retrieved with the given conditions from table. -func (m *arModel) One() (*Entity, error) { - one, err := m.Model.One() +// +// The optional parameter is the same as the parameter of Model.Where function, +// see Model.Where. +func (m *arModel) One(where ...interface{}) (*Entity, error) { + one, err := m.M.One(where...) if err != nil { return nil, err } @@ -229,15 +317,37 @@ func (m *arModel) One() (*Entity, error) { return entity, nil } -// Value retrieves a specified record value from table and returns the result as interface type. -// It returns nil if there's no record found with the given conditions from table. -func (m *arModel) Value() (gdb.Value, error) { - return m.Model.Value() +// FindOne retrieves and returns a single Record by Model.WherePri and Model.One. +// Also see Model.WherePri and Model.One. +func (m *arModel) FindOne(where ...interface{}) (*Entity, error) { + one, err := m.M.FindOne(where...) + if err != nil { + return nil, err + } + var entity *Entity + if err = one.Struct(&entity); err != nil && err != sql.ErrNoRows { + return nil, err + } + return entity, nil +} + +// FindAll retrieves and returns Result by by Model.WherePri and Model.All. +// Also see Model.WherePri and Model.All. +func (m *arModel) FindAll(where ...interface{}) ([]*Entity, error) { + all, err := m.M.FindAll(where...) + if err != nil { + return nil, err + } + var entities []*Entity + if err = all.Structs(&entities); err != nil && err != sql.ErrNoRows { + return nil, err + } + return entities, nil } // Chunk iterates the table with given size and callback function. func (m *arModel) Chunk(limit int, callback func(entities []*Entity, err error) bool) { - m.Model.Chunk(limit, func(result gdb.Result, err error) bool { + m.M.Chunk(limit, func(result gdb.Result, err error) bool { var entities []*Entity err = result.Structs(&entities) if err == sql.ErrNoRows { @@ -246,3 +356,18 @@ func (m *arModel) Chunk(limit int, callback func(entities []*Entity, err error) return callback(entities, err) }) } + +// LockUpdate sets the lock for update for current operation. +func (m *arModel) LockUpdate() *arModel { + return &arModel{m.M.LockUpdate()} +} + +// LockShared sets the lock in share mode for current operation. +func (m *arModel) LockShared() *arModel { + return &arModel{m.M.LockShared()} +} + +// Unscoped enables/disables the soft deleting feature. +func (m *arModel) Unscoped() *arModel { + return &arModel{m.M.Unscoped()} +} diff --git a/app/model/admin/user_post/user_post.go b/app/model/admin/user_post/user_post.go index 711679d..0873fac 100644 --- a/app/model/admin/user_post/user_post.go +++ b/app/model/admin/user_post/user_post.go @@ -30,7 +30,7 @@ func AddUserPost(postIds []int64, userId int64) (err error) { } //获取用户岗位 -func GetAdminPosts(userId int) (postIds []int64, err error) { +func GetAdminPosts(userId uint64) (postIds []int64, err error) { list, e := Model.All(Columns.UserId, userId) if e != nil { g.Log().Error(e) @@ -44,7 +44,7 @@ func GetAdminPosts(userId int) (postIds []int64, err error) { } //根据用户id获取岗位信息详情 -func GetPostsByUserId(userId int) ([]*sys_post.Entity, error) { +func GetPostsByUserId(userId uint64) ([]*sys_post.Entity, error) { model := g.DB().Table(Table) datas := ([]*sys_post.Entity)(nil) err := model.As("a").InnerJoin("sys_post b", "a.post_id = b.post_id").Fields("b.*").Where(Columns.UserId, userId).Structs(&datas) diff --git a/app/service/admin/cms_service/news.go b/app/service/admin/cms_service/news.go index 11a2076..d9377cc 100644 --- a/app/service/admin/cms_service/news.go +++ b/app/service/admin/cms_service/news.go @@ -14,7 +14,7 @@ import ( ) //添加文章操作 -func AddNews(req *cms_news.ReqAddParams, cateIds []int, userId int) (insId int64, err error) { +func AddNews(req *cms_news.ReqAddParams, cateIds []int, userId uint64) (insId int64, err error) { cateIds, err = getPubCateIds(cateIds) if err != nil { return diff --git a/app/service/admin/dept_service/dept.go b/app/service/admin/dept_service/dept.go index c86e858..b05cc5a 100644 --- a/app/service/admin/dept_service/dept.go +++ b/app/service/admin/dept_service/dept.go @@ -29,7 +29,7 @@ func EditDept(data *sys_dept.EditParams) error { return sys_dept.EditDept(data) } -func GetDeptById(id int64) (*sys_dept.Dept, error) { +func GetDeptById(id uint64) (*sys_dept.Dept, error) { return sys_dept.GetDeptById(id) } diff --git a/app/service/admin/dict_service/dict_data.go b/app/service/admin/dict_service/dict_data.go index f3d2d7f..01604dc 100644 --- a/app/service/admin/dict_service/dict_data.go +++ b/app/service/admin/dict_service/dict_data.go @@ -5,12 +5,12 @@ import ( ) //添加字典数据操作 -func AddSaveData(req *sys_dict_data.AddDataReq, userId int) (int64, error) { +func AddSaveData(req *sys_dict_data.AddDataReq, userId uint64) (int64, error) { return sys_dict_data.AddSaveData(req, userId) } //修改字典数据操作 -func EditSaveData(req *sys_dict_data.EditDataReq, userId int) (int64, error) { +func EditSaveData(req *sys_dict_data.EditDataReq, userId uint64) (int64, error) { return sys_dict_data.EditSaveData(req, userId) } diff --git a/app/service/admin/dict_service/dict_type.go b/app/service/admin/dict_service/dict_type.go index 07f227a..2d122c3 100644 --- a/app/service/admin/dict_service/dict_type.go +++ b/app/service/admin/dict_service/dict_type.go @@ -19,12 +19,12 @@ func CheckDictTypeUnique(dictType *sys_dict_type.EditReq) bool { } //添加数据 -func AddSave(req *sys_dict_type.AddReq, userId int) (int64, error) { +func AddSave(req *sys_dict_type.AddReq, userId uint64) (int64, error) { return sys_dict_type.AddSave(req, userId) } //修改保存字典类型 -func EditSave(req *sys_dict_type.EditReq, userId int) (int64, error) { +func EditSave(req *sys_dict_type.EditReq, userId uint64) (int64, error) { return sys_dict_type.EditSave(req, userId) } diff --git a/app/service/admin/monitor_service/job.go b/app/service/admin/monitor_service/job.go index 52edc59..77e87c3 100644 --- a/app/service/admin/monitor_service/job.go +++ b/app/service/admin/monitor_service/job.go @@ -17,12 +17,12 @@ func init() { } //添加计划任务 -func AddJob(req *sys_job.ReqAdd, userId int) (id int64, err error) { +func AddJob(req *sys_job.ReqAdd, userId uint64) (id int64, err error) { return sys_job.Add(req, userId) } //修改计划任务 -func EditJob(req *sys_job.ReqEdit, userId int) (rows int64, err error) { +func EditJob(req *sys_job.ReqEdit, userId uint64) (rows int64, err error) { return sys_job.Edit(req, userId) } diff --git a/app/service/admin/params_service/params.go b/app/service/admin/params_service/params.go index 3daad51..16a00b9 100644 --- a/app/service/admin/params_service/params.go +++ b/app/service/admin/params_service/params.go @@ -7,12 +7,12 @@ import ( ) //保存参数 -func AddSave(req *sys_config.AddReq, userId int) (id int64, err error) { +func AddSave(req *sys_config.AddReq, userId uint64) (id int64, err error) { return sys_config.AddSave(req, userId) } //修改保存 -func EditSave(req *sys_config.EditReq, userId int) (int64, error) { +func EditSave(req *sys_config.EditReq, userId uint64) (int64, error) { return sys_config.EditSave(req, userId) } diff --git a/app/service/admin/user_service/user.go b/app/service/admin/user_service/user.go index 153bac6..d186d85 100644 --- a/app/service/admin/user_service/user.go +++ b/app/service/admin/user_service/user.go @@ -104,12 +104,12 @@ func GetCurrentUserInfo(r *ghttp.Request) (map[string]interface{}, error) { } -func GetPostsByUserId(id int) ([]*sys_post.Entity, error) { +func GetPostsByUserId(id uint64) ([]*sys_post.Entity, error) { return user_post.GetPostsByUserId(id) } //获取登陆用户ID -func GetLoginID(r *ghttp.Request) (userId int) { +func GetLoginID(r *ghttp.Request) (userId uint64) { userInfo := GetLoginAdminInfo(r) if userInfo != nil { userId = userInfo.Id @@ -156,7 +156,7 @@ func GetAdminList(req *user.SearchReq) (total, page int, userList []*user.Entity } //获取管理员的角色信息 -func GetAdminRole(userId int, allRoleList []*role.Entity) (roles []*role.Entity, err error) { +func GetAdminRole(userId uint64, allRoleList []*role.Entity) (roles []*role.Entity, err error) { roleIds, err := GetAdminRoleIds(userId) if err != nil { return @@ -173,7 +173,7 @@ func GetAdminRole(userId int, allRoleList []*role.Entity) (roles []*role.Entity, } //获取管理员对应的角色ids -func GetAdminRoleIds(userId int) (roleIds []int, err error) { +func GetAdminRoleIds(userId uint64) (roleIds []uint, err error) { enforcer, e := casbin_adapter_service.GetEnforcer() if e != nil { err = e @@ -182,16 +182,16 @@ func GetAdminRoleIds(userId int) (roleIds []int, err error) { //查询关联角色规则 groupPolicy := enforcer.GetFilteredGroupingPolicy(0, fmt.Sprintf("u_%d", userId)) if len(groupPolicy) > 0 { - roleIds = make([]int, len(groupPolicy)) + roleIds = make([]uint, len(groupPolicy)) //得到角色id的切片 for k, v := range groupPolicy { - roleIds[k] = gconv.Int(gstr.SubStr(v[1], 2)) + roleIds[k] = gconv.Uint(gstr.SubStr(v[1], 2)) } } return } -func GetAdminPosts(userId int) (postIds []int64, err error) { +func GetAdminPosts(userId uint64) (postIds []int64, err error) { return user_post.GetAdminPosts(userId) } @@ -213,7 +213,7 @@ func GetAllMenus() (menus g.List, err error) { } //获取管理员所属角色菜单 -func GetAdminMenusByRoleIds(roleIds []int) (menus g.List, err error) { +func GetAdminMenusByRoleIds(roleIds []uint) (menus g.List, err error) { //获取角色对应的菜单id enforcer, e := casbin_adapter_service.GetEnforcer() if e != nil { diff --git a/go.mod b/go.mod index 57063df..252d742 100644 --- a/go.mod +++ b/go.mod @@ -7,8 +7,8 @@ require ( github.com/go-ole/go-ole v1.2.4 // indirect github.com/go-openapi/spec v0.19.8 // indirect github.com/go-openapi/swag v0.19.9 // indirect - github.com/goflyfox/gtoken v1.3.18 - github.com/gogf/gf v1.13.3 + github.com/goflyfox/gtoken v1.3.19 + github.com/gogf/gf v1.13.6 github.com/mailru/easyjson v0.7.1 // indirect github.com/mojocn/base64Captcha v1.3.1 github.com/mssola/user_agent v0.5.1 diff --git a/go.sum b/go.sum index abce884..a1922ca 100644 --- a/go.sum +++ b/go.sum @@ -15,8 +15,6 @@ github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751 h1:JYp7IbQjafo github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= github.com/casbin/casbin/v2 v2.1.2 h1:bTwon/ECRx9dwBy2ewRVr5OiqjeXSGiTUY74sDPQi/g= github.com/casbin/casbin/v2 v2.1.2/go.mod h1:YcPU1XXisHhLzuxH9coDNf2FbKpjGlbCg3n9yuLkIJQ= -github.com/clbanning/mxj v1.8.4 h1:HuhwZtbyvyOw+3Z1AowPkU87JkJUSv751ELWaiTpj8I= -github.com/clbanning/mxj v1.8.4/go.mod h1:BVjHeAH+rl9rs6f+QIpeRl0tfu10SXn1pUSa5PVGJng= github.com/clbanning/mxj v1.8.5-0.20200714211355-ff02cfb8ea28 h1:LdXxtjzvZYhhUaonAaAKArG3pyC67kGL3YY+6hGG8G4= github.com/clbanning/mxj v1.8.5-0.20200714211355-ff02cfb8ea28/go.mod h1:BVjHeAH+rl9rs6f+QIpeRl0tfu10SXn1pUSa5PVGJng= github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU= @@ -24,12 +22,8 @@ github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8 github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/fatih/structs v1.1.0 h1:Q7juDM0QtcnhCpeyLGQKyg4TOIghuNXrkL32pHAUMxo= -github.com/fatih/structs v1.1.0/go.mod h1:9NiDSp5zOcgEDl+j00MP/WkGVPOlPRLejGD8Ga6PJ7M= github.com/fsnotify/fsnotify v1.4.7 h1:IXs+QLmnXW2CcXuY+8Mzv/fWEsPGWxqefPtCP5CnV9I= github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= -github.com/gf-third/yaml v1.0.1 h1:pqD4ix+65DqGphU1MDnToPZfGYk0tuuwRzuTSl3g0d0= -github.com/gf-third/yaml v1.0.1/go.mod h1:t443vj0txEw3+E0MOtkr83kt+PrZg2I8SRuYfn85NM0= github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04= github.com/gin-contrib/gzip v0.0.1/go.mod h1:fGBJBCdt6qCZuCAOwWuFhBB4OOq9EFqlo5dEaFhhu5w= github.com/gin-contrib/sse v0.0.0-20170109093832-22d885f9ecc7/go.mod h1:VJ0WA2NBN22VlZ2dKZQPAPnyWw5XTlK1KymzLKsr59s= @@ -61,11 +55,11 @@ github.com/go-openapi/swag v0.19.9 h1:1IxuqvBUU3S2Bi4YC7tlP9SJF1gVpCvqN0T2Qof4az github.com/go-openapi/swag v0.19.9/go.mod h1:ao+8BpOPyKdpQz3AOJfbeEVpLmWAvlT1IfTe5McPyhY= github.com/go-sql-driver/mysql v1.5.0 h1:ozyZYNQW3x3HtqT1jira07DN2PArx2v7/mN66gGcHOs= github.com/go-sql-driver/mysql v1.5.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg= -github.com/goflyfox/gtoken v1.3.18 h1:LD9FFWJxYRVlCw+Xw07UT/PBkLJC60hD3kQr+9KVF2A= -github.com/goflyfox/gtoken v1.3.18/go.mod h1:a9Q08qaHzoS+ko/AFrCBnq4KCesnRFZ/3eLIiERRhtU= -github.com/gogf/gf v1.12.1/go.mod h1:5ItmC5B/St8P4hp0/waKmnvHwAfAJ1uspMvR2wUD4UA= -github.com/gogf/gf v1.13.3 h1:wdyNAzOSztDkabTEqRmPeJJT93p2qBK/jPK5x+8CRSE= -github.com/gogf/gf v1.13.3/go.mod h1:dGX0/BElXDBYbdJGascqfrWScj8IMeOietDjVD6/5Fc= +github.com/goflyfox/gtoken v1.3.19 h1:p0fhXybMNwB1sFn+DnCOQkE/IbLaNE31rRLIGZ+qShk= +github.com/goflyfox/gtoken v1.3.19/go.mod h1:b1ffjYH5cBEtiEGwLsRxtl0s0ler06hAvbYKa9IkbR4= +github.com/gogf/gf v1.13.4/go.mod h1:dGX0/BElXDBYbdJGascqfrWScj8IMeOietDjVD6/5Fc= +github.com/gogf/gf v1.13.6 h1:wm/eaVdViAcO7KqZCOCc/lzgGdBSDTRn7cDQ5gWMddw= +github.com/gogf/gf v1.13.6/go.mod h1:dGX0/BElXDBYbdJGascqfrWScj8IMeOietDjVD6/5Fc= github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0 h1:DACJavvAHhabrF08vX0COfcOBJRhZ8lUbR+ZWIs0Y5g= github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0/go.mod h1:E/TSTwGwJL78qG/PmXZO1EjYhfJinVAhrmmHX6Z8B9k= github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= @@ -73,8 +67,6 @@ github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5y github.com/gomodule/redigo v2.0.0+incompatible h1:K/R+8tc58AaqLkqG2Ol3Qk+DR/TlNuhuh457pBFPtt0= github.com/gomodule/redigo v2.0.0+incompatible/go.mod h1:B4C85qUVwatsJoIUNIfCRsp7qO0iAmpGFZ4EELWSbC4= github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= -github.com/google/uuid v1.1.1 h1:Gkbcsh/GbpXz7lPftLA3P6TYMwjCLYm83jiFQZF/3gY= -github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/gorilla/websocket v1.4.1 h1:q7AeDBpnBk8AogcD4DSag/Ukw/KV+YhzLj2bP5HvKCM= github.com/gorilla/websocket v1.4.1/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= github.com/gqcn/structs v1.1.1 h1:cyzGRwfmn3d1d54fwW3KUNyG9QxR0ldIeqwFGeBt638= @@ -100,8 +92,6 @@ github.com/mailru/easyjson v0.7.1/go.mod h1:KAzv3t3aY1NaHWoQz1+4F1ccyAH66Jk7yos7 github.com/mattn/go-isatty v0.0.4/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4= github.com/mattn/go-isatty v0.0.7/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s= github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s= -github.com/mattn/go-runewidth v0.0.7 h1:Ei8KR0497xHyKJPAv59M1dkC+rOZCMBJ+t3fZ+twI54= -github.com/mattn/go-runewidth v0.0.7/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI= github.com/mattn/go-runewidth v0.0.9 h1:Lm995f3rfxdpd6TSmuVCHVb/QhupuXlYr8sCI/QdE+0= github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI= github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= @@ -174,8 +164,6 @@ golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5h golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190610200419-93c9922d18ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20190616124812-15dcb6c0061f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20191204072324-ce4227a45e2e h1:9vRrk9YW2BTzLP0VCB9ZDjU4cPqkg+IDWL7XgxA1yxQ= -golang.org/x/sys v0.0.0-20191204072324-ce4227a45e2e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200625212154-ddb9806d33ae h1:Ih9Yo4hSPImZOpfGuA4bR/ORKTAbhZo2AbWNRCnevdo= golang.org/x/sys v0.0.0-20200625212154-ddb9806d33ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= diff --git a/library/service/service.go b/library/service/service.go index 8fef372..1febe3b 100644 --- a/library/service/service.go +++ b/library/service/service.go @@ -127,7 +127,7 @@ func LoginOut(r *ghttp.Request) bool { } // 用户登录,成功返回用户信息,否则返回nil -func signIn(username, password string, r *ghttp.Request) (error, *user.User) { +func signIn(username, password string, r *ghttp.Request) (error, *user.Entity) { user, err := user.Model.Where("user_name=? and user_password=?", username, password).One() if err != nil && err != sql.ErrNoRows { return err, nil diff --git a/middleWare/middleware.go b/middleWare/middleware.go index 8477742..971419e 100644 --- a/middleWare/middleware.go +++ b/middleWare/middleware.go @@ -11,6 +11,7 @@ import ( "github.com/gogf/gf/frame/g" "github.com/gogf/gf/net/ghttp" "github.com/gogf/gf/text/gstr" + "github.com/gogf/gf/util/gconv" ) //跨域处理中间件 @@ -28,7 +29,7 @@ func Auth(r *ghttp.Request) { adminId := user_service.GetLoginID(r) //获取无需验证权限的用户id for _, v := range service.NotCheckAuthAdminIds { - if v == adminId { + if gconv.Uint64(v) == adminId { r.Middleware.Next() return }