roles.go 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414
  1. // Code generated by gorm.io/gen. DO NOT EDIT.
  2. // Code generated by gorm.io/gen. DO NOT EDIT.
  3. // Code generated by gorm.io/gen. DO NOT EDIT.
  4. package model
  5. import (
  6. "context"
  7. "gorm.io/gorm"
  8. "gorm.io/gorm/clause"
  9. "gorm.io/gorm/schema"
  10. "gorm.io/gen"
  11. "gorm.io/gen/field"
  12. "gorm.io/plugin/dbresolver"
  13. "icloudapp.cn/tools/service/entity"
  14. )
  15. func newRole(db *gorm.DB, opts ...gen.DOOption) MRole {
  16. _MRole := MRole{}
  17. _MRole.MRoleDo.UseDB(db, opts...)
  18. _MRole.MRoleDo.UseModel(&entity.Role{})
  19. tableName := _MRole.MRoleDo.TableName()
  20. _MRole.ALL = field.NewAsterisk(tableName)
  21. _MRole.RoleID = field.NewInt64(tableName, "role_id")
  22. _MRole.RoleName = field.NewString(tableName, "role_name")
  23. _MRole.ModelIds = field.NewString(tableName, "model_ids")
  24. _MRole.RoleStatus = field.NewInt64(tableName, "role_status")
  25. _MRole.OperatorUID = field.NewInt64(tableName, "operator_uid")
  26. _MRole.CreateAt = field.NewTime(tableName, "create_at")
  27. _MRole.UpdateAt = field.NewTime(tableName, "update_at")
  28. _MRole.fillFieldMap()
  29. return _MRole
  30. }
  31. type MRole struct {
  32. MRoleDo MRoleDo
  33. ALL field.Asterisk
  34. RoleID field.Int64 // 权限ID
  35. RoleName field.String // 权限名称
  36. ModelIds field.String // 权限对应的模块名
  37. RoleStatus field.Int64 // 模块状态
  38. OperatorUID field.Int64 // 操作人
  39. CreateAt field.Time // 添加时间
  40. UpdateAt field.Time // 更新时间
  41. fieldMap map[string]field.Expr
  42. }
  43. func (r MRole) Table(newTableName string) *MRole {
  44. r.MRoleDo.UseTable(newTableName)
  45. return r.updateTableName(newTableName)
  46. }
  47. func (r MRole) As(alias string) *MRole {
  48. r.MRoleDo.DO = *(r.MRoleDo.As(alias).(*gen.DO))
  49. return r.updateTableName(alias)
  50. }
  51. func (r *MRole) updateTableName(table string) *MRole {
  52. r.ALL = field.NewAsterisk(table)
  53. r.RoleID = field.NewInt64(table, "role_id")
  54. r.RoleName = field.NewString(table, "role_name")
  55. r.ModelIds = field.NewString(table, "model_ids")
  56. r.RoleStatus = field.NewInt64(table, "role_status")
  57. r.OperatorUID = field.NewInt64(table, "operator_uid")
  58. r.CreateAt = field.NewTime(table, "create_at")
  59. r.UpdateAt = field.NewTime(table, "update_at")
  60. r.fillFieldMap()
  61. return r
  62. }
  63. func (r *MRole) WithContext(ctx context.Context) IRoleDo { return r.MRoleDo.WithContext(ctx) }
  64. func (r MRole) TableName() string { return r.MRoleDo.TableName() }
  65. func (r MRole) Alias() string { return r.MRoleDo.Alias() }
  66. func (r *MRole) GetFieldByName(fieldName string) (field.OrderExpr, bool) {
  67. _f, ok := r.fieldMap[fieldName]
  68. if !ok || _f == nil {
  69. return nil, false
  70. }
  71. _oe, ok := _f.(field.OrderExpr)
  72. return _oe, ok
  73. }
  74. func (r *MRole) fillFieldMap() {
  75. r.fieldMap = make(map[string]field.Expr, 7)
  76. r.fieldMap["role_id"] = r.RoleID
  77. r.fieldMap["role_name"] = r.RoleName
  78. r.fieldMap["model_ids"] = r.ModelIds
  79. r.fieldMap["role_status"] = r.RoleStatus
  80. r.fieldMap["operator_uid"] = r.OperatorUID
  81. r.fieldMap["create_at"] = r.CreateAt
  82. r.fieldMap["update_at"] = r.UpdateAt
  83. }
  84. func (r MRole) clone(db *gorm.DB) MRole {
  85. r.MRoleDo.ReplaceConnPool(db.Statement.ConnPool)
  86. return r
  87. }
  88. func (r MRole) replaceDB(db *gorm.DB) MRole {
  89. r.MRoleDo.ReplaceDB(db)
  90. return r
  91. }
  92. type MRoleDo struct{ gen.DO }
  93. type IRoleDo interface {
  94. gen.SubQuery
  95. Debug() IRoleDo
  96. WithContext(ctx context.Context) IRoleDo
  97. WithResult(fc func(tx gen.Dao)) gen.ResultInfo
  98. ReplaceDB(db *gorm.DB)
  99. ReadDB() IRoleDo
  100. WriteDB() IRoleDo
  101. As(alias string) gen.Dao
  102. Session(config *gorm.Session) IRoleDo
  103. Columns(cols ...field.Expr) gen.Columns
  104. Clauses(conds ...clause.Expression) IRoleDo
  105. Not(conds ...gen.Condition) IRoleDo
  106. Or(conds ...gen.Condition) IRoleDo
  107. Select(conds ...field.Expr) IRoleDo
  108. Where(conds ...gen.Condition) IRoleDo
  109. Order(conds ...field.Expr) IRoleDo
  110. Distinct(cols ...field.Expr) IRoleDo
  111. Omit(cols ...field.Expr) IRoleDo
  112. Join(table schema.Tabler, on ...field.Expr) IRoleDo
  113. LeftJoin(table schema.Tabler, on ...field.Expr) IRoleDo
  114. RightJoin(table schema.Tabler, on ...field.Expr) IRoleDo
  115. Group(cols ...field.Expr) IRoleDo
  116. Having(conds ...gen.Condition) IRoleDo
  117. Limit(limit int) IRoleDo
  118. Offset(offset int) IRoleDo
  119. Count() (count int64, err error)
  120. Scopes(funcs ...func(gen.Dao) gen.Dao) IRoleDo
  121. Unscoped() IRoleDo
  122. Create(values ...*entity.Role) error
  123. CreateInBatches(values []*entity.Role, batchSize int) error
  124. Save(values ...*entity.Role) error
  125. First() (*entity.Role, error)
  126. Take() (*entity.Role, error)
  127. Last() (*entity.Role, error)
  128. Find() ([]*entity.Role, error)
  129. FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*entity.Role, err error)
  130. FindInBatches(result *[]*entity.Role, batchSize int, fc func(tx gen.Dao, batch int) error) error
  131. Pluck(column field.Expr, dest interface{}) error
  132. Delete(...*entity.Role) (info gen.ResultInfo, err error)
  133. Update(column field.Expr, value interface{}) (info gen.ResultInfo, err error)
  134. UpdateSimple(columns ...field.AssignExpr) (info gen.ResultInfo, err error)
  135. Updates(value interface{}) (info gen.ResultInfo, err error)
  136. UpdateColumn(column field.Expr, value interface{}) (info gen.ResultInfo, err error)
  137. UpdateColumnSimple(columns ...field.AssignExpr) (info gen.ResultInfo, err error)
  138. UpdateColumns(value interface{}) (info gen.ResultInfo, err error)
  139. UpdateFrom(q gen.SubQuery) gen.Dao
  140. Attrs(attrs ...field.AssignExpr) IRoleDo
  141. Assign(attrs ...field.AssignExpr) IRoleDo
  142. Joins(fields ...field.RelationField) IRoleDo
  143. Preload(fields ...field.RelationField) IRoleDo
  144. FirstOrInit() (*entity.Role, error)
  145. FirstOrCreate() (*entity.Role, error)
  146. FindByPage(offset int, limit int) (result []*entity.Role, count int64, err error)
  147. ScanByPage(result interface{}, offset int, limit int) (count int64, err error)
  148. Scan(result interface{}) (err error)
  149. Returning(value interface{}, columns ...string) IRoleDo
  150. UnderlyingDB() *gorm.DB
  151. schema.Tabler
  152. }
  153. func (r MRoleDo) Debug() IRoleDo {
  154. return r.withDO(r.DO.Debug())
  155. }
  156. func (r MRoleDo) WithContext(ctx context.Context) IRoleDo {
  157. return r.withDO(r.DO.WithContext(ctx))
  158. }
  159. func (r MRoleDo) ReadDB() IRoleDo {
  160. return r.Clauses(dbresolver.Read)
  161. }
  162. func (r MRoleDo) WriteDB() IRoleDo {
  163. return r.Clauses(dbresolver.Write)
  164. }
  165. func (r MRoleDo) Session(config *gorm.Session) IRoleDo {
  166. return r.withDO(r.DO.Session(config))
  167. }
  168. func (r MRoleDo) Clauses(conds ...clause.Expression) IRoleDo {
  169. return r.withDO(r.DO.Clauses(conds...))
  170. }
  171. func (r MRoleDo) Returning(value interface{}, columns ...string) IRoleDo {
  172. return r.withDO(r.DO.Returning(value, columns...))
  173. }
  174. func (r MRoleDo) Not(conds ...gen.Condition) IRoleDo {
  175. return r.withDO(r.DO.Not(conds...))
  176. }
  177. func (r MRoleDo) Or(conds ...gen.Condition) IRoleDo {
  178. return r.withDO(r.DO.Or(conds...))
  179. }
  180. func (r MRoleDo) Select(conds ...field.Expr) IRoleDo {
  181. return r.withDO(r.DO.Select(conds...))
  182. }
  183. func (r MRoleDo) Where(conds ...gen.Condition) IRoleDo {
  184. return r.withDO(r.DO.Where(conds...))
  185. }
  186. func (r MRoleDo) Exists(subquery interface{ UnderlyingDB() *gorm.DB }) IRoleDo {
  187. return r.Where(field.CompareSubQuery(field.ExistsOp, nil, subquery.UnderlyingDB()))
  188. }
  189. func (r MRoleDo) Order(conds ...field.Expr) IRoleDo {
  190. return r.withDO(r.DO.Order(conds...))
  191. }
  192. func (r MRoleDo) Distinct(cols ...field.Expr) IRoleDo {
  193. return r.withDO(r.DO.Distinct(cols...))
  194. }
  195. func (r MRoleDo) Omit(cols ...field.Expr) IRoleDo {
  196. return r.withDO(r.DO.Omit(cols...))
  197. }
  198. func (r MRoleDo) Join(table schema.Tabler, on ...field.Expr) IRoleDo {
  199. return r.withDO(r.DO.Join(table, on...))
  200. }
  201. func (r MRoleDo) LeftJoin(table schema.Tabler, on ...field.Expr) IRoleDo {
  202. return r.withDO(r.DO.LeftJoin(table, on...))
  203. }
  204. func (r MRoleDo) RightJoin(table schema.Tabler, on ...field.Expr) IRoleDo {
  205. return r.withDO(r.DO.RightJoin(table, on...))
  206. }
  207. func (r MRoleDo) Group(cols ...field.Expr) IRoleDo {
  208. return r.withDO(r.DO.Group(cols...))
  209. }
  210. func (r MRoleDo) Having(conds ...gen.Condition) IRoleDo {
  211. return r.withDO(r.DO.Having(conds...))
  212. }
  213. func (r MRoleDo) Limit(limit int) IRoleDo {
  214. return r.withDO(r.DO.Limit(limit))
  215. }
  216. func (r MRoleDo) Offset(offset int) IRoleDo {
  217. return r.withDO(r.DO.Offset(offset))
  218. }
  219. func (r MRoleDo) Scopes(funcs ...func(gen.Dao) gen.Dao) IRoleDo {
  220. return r.withDO(r.DO.Scopes(funcs...))
  221. }
  222. func (r MRoleDo) Unscoped() IRoleDo {
  223. return r.withDO(r.DO.Unscoped())
  224. }
  225. func (r MRoleDo) Create(values ...*entity.Role) error {
  226. if len(values) == 0 {
  227. return nil
  228. }
  229. return r.DO.Create(values)
  230. }
  231. func (r MRoleDo) CreateInBatches(values []*entity.Role, batchSize int) error {
  232. return r.DO.CreateInBatches(values, batchSize)
  233. }
  234. // Save : !!! underlying implementation is different with GORM
  235. // The method is equivalent to executing the statement: db.Clauses(clause.OnConflict{UpdateAll: true}).Create(values)
  236. func (r MRoleDo) Save(values ...*entity.Role) error {
  237. if len(values) == 0 {
  238. return nil
  239. }
  240. return r.DO.Save(values)
  241. }
  242. func (r MRoleDo) First() (*entity.Role, error) {
  243. if result, err := r.DO.First(); err != nil {
  244. return nil, err
  245. } else {
  246. return result.(*entity.Role), nil
  247. }
  248. }
  249. func (r MRoleDo) Take() (*entity.Role, error) {
  250. if result, err := r.DO.Take(); err != nil {
  251. return nil, err
  252. } else {
  253. return result.(*entity.Role), nil
  254. }
  255. }
  256. func (r MRoleDo) Last() (*entity.Role, error) {
  257. if result, err := r.DO.Last(); err != nil {
  258. return nil, err
  259. } else {
  260. return result.(*entity.Role), nil
  261. }
  262. }
  263. func (r MRoleDo) Find() ([]*entity.Role, error) {
  264. result, err := r.DO.Find()
  265. return result.([]*entity.Role), err
  266. }
  267. func (r MRoleDo) FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*entity.Role, err error) {
  268. buf := make([]*entity.Role, 0, batchSize)
  269. err = r.DO.FindInBatches(&buf, batchSize, func(tx gen.Dao, batch int) error {
  270. defer func() { results = append(results, buf...) }()
  271. return fc(tx, batch)
  272. })
  273. return results, err
  274. }
  275. func (r MRoleDo) FindInBatches(result *[]*entity.Role, batchSize int, fc func(tx gen.Dao, batch int) error) error {
  276. return r.DO.FindInBatches(result, batchSize, fc)
  277. }
  278. func (r MRoleDo) Attrs(attrs ...field.AssignExpr) IRoleDo {
  279. return r.withDO(r.DO.Attrs(attrs...))
  280. }
  281. func (r MRoleDo) Assign(attrs ...field.AssignExpr) IRoleDo {
  282. return r.withDO(r.DO.Assign(attrs...))
  283. }
  284. func (r MRoleDo) Joins(fields ...field.RelationField) IRoleDo {
  285. for _, _f := range fields {
  286. r = *r.withDO(r.DO.Joins(_f))
  287. }
  288. return &r
  289. }
  290. func (r MRoleDo) Preload(fields ...field.RelationField) IRoleDo {
  291. for _, _f := range fields {
  292. r = *r.withDO(r.DO.Preload(_f))
  293. }
  294. return &r
  295. }
  296. func (r MRoleDo) FirstOrInit() (*entity.Role, error) {
  297. if result, err := r.DO.FirstOrInit(); err != nil {
  298. return nil, err
  299. } else {
  300. return result.(*entity.Role), nil
  301. }
  302. }
  303. func (r MRoleDo) FirstOrCreate() (*entity.Role, error) {
  304. if result, err := r.DO.FirstOrCreate(); err != nil {
  305. return nil, err
  306. } else {
  307. return result.(*entity.Role), nil
  308. }
  309. }
  310. func (r MRoleDo) FindByPage(offset int, limit int) (result []*entity.Role, count int64, err error) {
  311. result, err = r.Offset(offset).Limit(limit).Find()
  312. if err != nil {
  313. return
  314. }
  315. if size := len(result); 0 < limit && 0 < size && size < limit {
  316. count = int64(size + offset)
  317. return
  318. }
  319. count, err = r.Offset(-1).Limit(-1).Count()
  320. return
  321. }
  322. func (r MRoleDo) ScanByPage(result interface{}, offset int, limit int) (count int64, err error) {
  323. count, err = r.Count()
  324. if err != nil {
  325. return
  326. }
  327. err = r.Offset(offset).Limit(limit).Scan(result)
  328. return
  329. }
  330. func (r MRoleDo) Scan(result interface{}) (err error) {
  331. return r.DO.Scan(result)
  332. }
  333. func (r MRoleDo) Delete(models ...*entity.Role) (result gen.ResultInfo, err error) {
  334. return r.DO.Delete(models)
  335. }
  336. func (r *MRoleDo) withDO(do gen.Dao) *MRoleDo {
  337. r.DO = *do.(*gen.DO)
  338. return r
  339. }