sys_user.go 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459
  1. // ==========================================================================
  2. // This is auto-generated by gf cli tool. DO NOT EDIT THIS FILE MANUALLY.
  3. // ==========================================================================
  4. package internal
  5. import (
  6. "context"
  7. "database/sql"
  8. "github.com/gogf/gf/database/gdb"
  9. "github.com/gogf/gf/frame/g"
  10. "github.com/gogf/gf/frame/gmvc"
  11. "time"
  12. model "dashoo.cn/micro/app/model/sys"
  13. )
  14. // SysUserDao is the manager for logic model data accessing
  15. // and custom defined data operations functions management.
  16. type SysUserDao struct {
  17. gmvc.M
  18. DB gdb.DB
  19. Table string
  20. Columns sysUserColumns
  21. }
  22. // SysUserColumns defines and stores column names for table sys_user.
  23. type sysUserColumns struct {
  24. Id string // 用户ID
  25. DeptId string // 部门ID
  26. UserName string // 用户账号
  27. NickName string // 用户昵称
  28. UserType string // 用户类型(00系统用户)
  29. Email string // 用户邮箱
  30. Phone string // 手机号码
  31. Sex string // 用户性别(10男20女30未知)
  32. Avatar string // 头像地址
  33. Password string // 密码
  34. LoginIp string // 最后登录IP
  35. LoginDate string // 最后登录时间
  36. Remark string // 备注
  37. CreatedBy string // 创建者
  38. CreatedName string // 创建人
  39. CreatedTime string // 创建时间
  40. UpdatedBy string // 更新者
  41. UpdatedName string // 更新人
  42. UpdatedTime string // 更新时间
  43. DeletedTime string // 删除时间
  44. Status string // 帐号状态(10正常20停用)
  45. UserSalt string // 加密盐
  46. }
  47. var (
  48. // SysUser is globally public accessible object for table sys_user operations.
  49. SysUser = SysUserDao{
  50. M: g.DB("default").Model("sys_user").Safe(),
  51. DB: g.DB("default"),
  52. Table: "sys_user",
  53. Columns: sysUserColumns{
  54. Id: "id",
  55. DeptId: "dept_id",
  56. UserName: "user_name",
  57. NickName: "nick_name",
  58. UserType: "user_type",
  59. Email: "email",
  60. Phone: "phone",
  61. Sex: "sex",
  62. Avatar: "avatar",
  63. Password: "password",
  64. LoginIp: "login_ip",
  65. LoginDate: "login_date",
  66. Remark: "remark",
  67. CreatedBy: "created_by",
  68. CreatedName: "created_name",
  69. CreatedTime: "created_time",
  70. UpdatedBy: "updated_by",
  71. UpdatedName: "updated_name",
  72. UpdatedTime: "updated_time",
  73. DeletedTime: "deleted_time",
  74. Status: "status",
  75. UserSalt: "user_salt",
  76. },
  77. }
  78. )
  79. func NewSysUserDao(tenant string) SysUserDao {
  80. var dao SysUserDao
  81. dao = SysUserDao{
  82. M: g.DB(tenant).Model("sys_user").Safe(),
  83. DB: g.DB(tenant),
  84. Table: "sys_user",
  85. Columns: sysUserColumns{
  86. Id: "id",
  87. DeptId: "dept_id",
  88. UserName: "user_name",
  89. NickName: "nick_name",
  90. UserType: "user_type",
  91. Email: "email",
  92. Phone: "phone",
  93. Sex: "sex",
  94. Avatar: "avatar",
  95. Password: "password",
  96. LoginIp: "login_ip",
  97. LoginDate: "login_date",
  98. Remark: "remark",
  99. CreatedBy: "created_by",
  100. CreatedName: "created_name",
  101. CreatedTime: "created_time",
  102. UpdatedBy: "updated_by",
  103. UpdatedName: "updated_name",
  104. UpdatedTime: "updated_time",
  105. DeletedTime: "deleted_time",
  106. Status: "status",
  107. UserSalt: "user_salt",
  108. },
  109. }
  110. return dao
  111. }
  112. // Ctx is a chaining function, which creates and returns a new DB that is a shallow copy
  113. // of current DB object and with given context in it.
  114. // Note that this returned DB object can be used only once, so do not assign it to
  115. // a global or package variable for long using.
  116. func (d *SysUserDao) Ctx(ctx context.Context) *SysUserDao {
  117. return &SysUserDao{M: d.M.Ctx(ctx)}
  118. }
  119. // As sets an alias name for current table.
  120. func (d *SysUserDao) As(as string) *SysUserDao {
  121. return &SysUserDao{M: d.M.As(as)}
  122. }
  123. // TX sets the transaction for current operation.
  124. func (d *SysUserDao) TX(tx *gdb.TX) *SysUserDao {
  125. return &SysUserDao{M: d.M.TX(tx)}
  126. }
  127. // Master marks the following operation on master node.
  128. func (d *SysUserDao) Master() *SysUserDao {
  129. return &SysUserDao{M: d.M.Master()}
  130. }
  131. // Slave marks the following operation on slave node.
  132. // Note that it makes sense only if there's any slave node configured.
  133. func (d *SysUserDao) Slave() *SysUserDao {
  134. return &SysUserDao{M: d.M.Slave()}
  135. }
  136. // Args sets custom arguments for model operation.
  137. func (d *SysUserDao) Args(args ...interface{}) *SysUserDao {
  138. return &SysUserDao{M: d.M.Args(args...)}
  139. }
  140. // LeftJoin does "LEFT JOIN ... ON ..." statement on the model.
  141. // The parameter <table> can be joined table and its joined condition,
  142. // and also with its alias name, like:
  143. // Table("user").LeftJoin("user_detail", "user_detail.uid=user.uid")
  144. // Table("user", "u").LeftJoin("user_detail", "ud", "ud.uid=u.uid")
  145. func (d *SysUserDao) LeftJoin(table ...string) *SysUserDao {
  146. return &SysUserDao{M: d.M.LeftJoin(table...)}
  147. }
  148. // RightJoin does "RIGHT JOIN ... ON ..." statement on the model.
  149. // The parameter <table> can be joined table and its joined condition,
  150. // and also with its alias name, like:
  151. // Table("user").RightJoin("user_detail", "user_detail.uid=user.uid")
  152. // Table("user", "u").RightJoin("user_detail", "ud", "ud.uid=u.uid")
  153. func (d *SysUserDao) RightJoin(table ...string) *SysUserDao {
  154. return &SysUserDao{M: d.M.RightJoin(table...)}
  155. }
  156. // InnerJoin does "INNER JOIN ... ON ..." statement on the model.
  157. // The parameter <table> can be joined table and its joined condition,
  158. // and also with its alias name, like:
  159. // Table("user").InnerJoin("user_detail", "user_detail.uid=user.uid")
  160. // Table("user", "u").InnerJoin("user_detail", "ud", "ud.uid=u.uid")
  161. func (d *SysUserDao) InnerJoin(table ...string) *SysUserDao {
  162. return &SysUserDao{M: d.M.InnerJoin(table...)}
  163. }
  164. // Fields sets the operation fields of the model, multiple fields joined using char ','.
  165. // The parameter <fieldNamesOrMapStruct> can be type of string/map/*map/struct/*struct.
  166. func (d *SysUserDao) Fields(fieldNamesOrMapStruct ...interface{}) *SysUserDao {
  167. return &SysUserDao{M: d.M.Fields(fieldNamesOrMapStruct...)}
  168. }
  169. // FieldsEx sets the excluded operation fields of the model, multiple fields joined using char ','.
  170. // The parameter <fieldNamesOrMapStruct> can be type of string/map/*map/struct/*struct.
  171. func (d *SysUserDao) FieldsEx(fieldNamesOrMapStruct ...interface{}) *SysUserDao {
  172. return &SysUserDao{M: d.M.FieldsEx(fieldNamesOrMapStruct...)}
  173. }
  174. // Option sets the extra operation option for the model.
  175. func (d *SysUserDao) Option(option int) *SysUserDao {
  176. return &SysUserDao{M: d.M.Option(option)}
  177. }
  178. // OmitEmpty sets OPTION_OMITEMPTY option for the model, which automatically filers
  179. // the data and where attributes for empty values.
  180. func (d *SysUserDao) OmitEmpty() *SysUserDao {
  181. return &SysUserDao{M: d.M.OmitEmpty()}
  182. }
  183. // Filter marks filtering the fields which does not exist in the fields of the operated table.
  184. func (d *SysUserDao) Filter() *SysUserDao {
  185. return &SysUserDao{M: d.M.Filter()}
  186. }
  187. // Where sets the condition statement for the model. The parameter <where> can be type of
  188. // string/map/gmap/slice/struct/*struct, etc. Note that, if it's called more than one times,
  189. // multiple conditions will be joined into where statement using "AND".
  190. // Eg:
  191. // Where("uid=10000")
  192. // Where("uid", 10000)
  193. // Where("money>? AND name like ?", 99999, "vip_%")
  194. // Where("uid", 1).Where("name", "john")
  195. // Where("status IN (?)", g.Slice{1,2,3})
  196. // Where("age IN(?,?)", 18, 50)
  197. // Where(User{ Id : 1, UserName : "john"})
  198. func (d *SysUserDao) Where(where interface{}, args ...interface{}) *SysUserDao {
  199. return &SysUserDao{M: d.M.Where(where, args...)}
  200. }
  201. // WherePri does the same logic as M.Where except that if the parameter <where>
  202. // is a single condition like int/string/float/slice, it treats the condition as the primary
  203. // key value. That is, if primary key is "id" and given <where> parameter as "123", the
  204. // WherePri function treats the condition as "id=123", but M.Where treats the condition
  205. // as string "123".
  206. func (d *SysUserDao) WherePri(where interface{}, args ...interface{}) *SysUserDao {
  207. return &SysUserDao{M: d.M.WherePri(where, args...)}
  208. }
  209. // And adds "AND" condition to the where statement.
  210. func (d *SysUserDao) And(where interface{}, args ...interface{}) *SysUserDao {
  211. return &SysUserDao{M: d.M.And(where, args...)}
  212. }
  213. // Or adds "OR" condition to the where statement.
  214. func (d *SysUserDao) Or(where interface{}, args ...interface{}) *SysUserDao {
  215. return &SysUserDao{M: d.M.Or(where, args...)}
  216. }
  217. // Group sets the "GROUP BY" statement for the model.
  218. func (d *SysUserDao) Group(groupBy string) *SysUserDao {
  219. return &SysUserDao{M: d.M.Group(groupBy)}
  220. }
  221. // Order sets the "ORDER BY" statement for the model.
  222. func (d *SysUserDao) Order(orderBy ...string) *SysUserDao {
  223. return &SysUserDao{M: d.M.Order(orderBy...)}
  224. }
  225. // Limit sets the "LIMIT" statement for the model.
  226. // The parameter <limit> can be either one or two number, if passed two number is passed,
  227. // it then sets "LIMIT limit[0],limit[1]" statement for the model, or else it sets "LIMIT limit[0]"
  228. // statement.
  229. func (d *SysUserDao) Limit(limit ...int) *SysUserDao {
  230. return &SysUserDao{M: d.M.Limit(limit...)}
  231. }
  232. // Offset sets the "OFFSET" statement for the model.
  233. // It only makes sense for some databases like SQLServer, PostgreSQL, etc.
  234. func (d *SysUserDao) Offset(offset int) *SysUserDao {
  235. return &SysUserDao{M: d.M.Offset(offset)}
  236. }
  237. // Page sets the paging number for the model.
  238. // The parameter <page> is started from 1 for paging.
  239. // Note that, it differs that the Limit function start from 0 for "LIMIT" statement.
  240. func (d *SysUserDao) Page(page, limit int) *SysUserDao {
  241. return &SysUserDao{M: d.M.Page(page, limit)}
  242. }
  243. // Batch sets the batch operation number for the model.
  244. func (d *SysUserDao) Batch(batch int) *SysUserDao {
  245. return &SysUserDao{M: d.M.Batch(batch)}
  246. }
  247. // Cache sets the cache feature for the model. It caches the result of the sql, which means
  248. // if there's another same sql request, it just reads and returns the result from cache, it
  249. // but not committed and executed into the database.
  250. //
  251. // If the parameter <duration> < 0, which means it clear the cache with given <name>.
  252. // If the parameter <duration> = 0, which means it never expires.
  253. // If the parameter <duration> > 0, which means it expires after <duration>.
  254. //
  255. // The optional parameter <name> is used to bind a name to the cache, which means you can later
  256. // control the cache like changing the <duration> or clearing the cache with specified <name>.
  257. //
  258. // Note that, the cache feature is disabled if the model is operating on a transaction.
  259. func (d *SysUserDao) Cache(duration time.Duration, name ...string) *SysUserDao {
  260. return &SysUserDao{M: d.M.Cache(duration, name...)}
  261. }
  262. // Data sets the operation data for the model.
  263. // The parameter <data> can be type of string/map/gmap/slice/struct/*struct, etc.
  264. // Eg:
  265. // Data("uid=10000")
  266. // Data("uid", 10000)
  267. // Data(g.Map{"uid": 10000, "name":"john"})
  268. // Data(g.Slice{g.Map{"uid": 10000, "name":"john"}, g.Map{"uid": 20000, "name":"smith"})
  269. func (d *SysUserDao) Data(data ...interface{}) *SysUserDao {
  270. return &SysUserDao{M: d.M.Data(data...)}
  271. }
  272. // All does "SELECT FROM ..." statement for the model.
  273. // It retrieves the records from table and returns the result as []*model.SysUser.
  274. // It returns nil if there's no record retrieved with the given conditions from table.
  275. //
  276. // The optional parameter <where> is the same as the parameter of M.Where function,
  277. // see M.Where.
  278. func (d *SysUserDao) All(where ...interface{}) ([]*model.SysUser, error) {
  279. all, err := d.M.All(where...)
  280. if err != nil {
  281. return nil, err
  282. }
  283. var entities []*model.SysUser
  284. if err = all.Structs(&entities); err != nil && err != sql.ErrNoRows {
  285. return nil, err
  286. }
  287. return entities, nil
  288. }
  289. // One retrieves one record from table and returns the result as *model.SysUser.
  290. // It returns nil if there's no record retrieved with the given conditions from table.
  291. //
  292. // The optional parameter <where> is the same as the parameter of M.Where function,
  293. // see M.Where.
  294. func (d *SysUserDao) One(where ...interface{}) (*model.SysUser, error) {
  295. one, err := d.M.One(where...)
  296. if err != nil {
  297. return nil, err
  298. }
  299. var entity *model.SysUser
  300. if err = one.Struct(&entity); err != nil && err != sql.ErrNoRows {
  301. return nil, err
  302. }
  303. return entity, nil
  304. }
  305. // FindOne retrieves and returns a single Record by M.WherePri and M.One.
  306. // Also see M.WherePri and M.One.
  307. func (d *SysUserDao) FindOne(where ...interface{}) (*model.SysUser, error) {
  308. one, err := d.M.FindOne(where...)
  309. if err != nil {
  310. return nil, err
  311. }
  312. var entity *model.SysUser
  313. if err = one.Struct(&entity); err != nil && err != sql.ErrNoRows {
  314. return nil, err
  315. }
  316. return entity, nil
  317. }
  318. // FindAll retrieves and returns Result by by M.WherePri and M.All.
  319. // Also see M.WherePri and M.All.
  320. func (d *SysUserDao) FindAll(where ...interface{}) ([]*model.SysUser, error) {
  321. all, err := d.M.FindAll(where...)
  322. if err != nil {
  323. return nil, err
  324. }
  325. var entities []*model.SysUser
  326. if err = all.Structs(&entities); err != nil && err != sql.ErrNoRows {
  327. return nil, err
  328. }
  329. return entities, nil
  330. }
  331. // Struct retrieves one record from table and converts it into given struct.
  332. // The parameter <pointer> should be type of *struct/**struct. If type **struct is given,
  333. // it can create the struct internally during converting.
  334. //
  335. // The optional parameter <where> is the same as the parameter of Model.Where function,
  336. // see Model.Where.
  337. //
  338. // Note that it returns sql.ErrNoRows if there's no record retrieved with the given conditions
  339. // from table and <pointer> is not nil.
  340. //
  341. // Eg:
  342. // user := new(User)
  343. // err := dao.User.Where("id", 1).Struct(user)
  344. //
  345. // user := (*User)(nil)
  346. // err := dao.User.Where("id", 1).Struct(&user)
  347. func (d *SysUserDao) Struct(pointer interface{}, where ...interface{}) error {
  348. return d.M.Struct(pointer, where...)
  349. }
  350. // Structs retrieves records from table and converts them into given struct slice.
  351. // The parameter <pointer> should be type of *[]struct/*[]*struct. It can create and fill the struct
  352. // slice internally during converting.
  353. //
  354. // The optional parameter <where> is the same as the parameter of Model.Where function,
  355. // see Model.Where.
  356. //
  357. // Note that it returns sql.ErrNoRows if there's no record retrieved with the given conditions
  358. // from table and <pointer> is not empty.
  359. //
  360. // Eg:
  361. // users := ([]User)(nil)
  362. // err := dao.User.Structs(&users)
  363. //
  364. // users := ([]*User)(nil)
  365. // err := dao.User.Structs(&users)
  366. func (d *SysUserDao) Structs(pointer interface{}, where ...interface{}) error {
  367. return d.M.Structs(pointer, where...)
  368. }
  369. // Scan automatically calls Struct or Structs function according to the type of parameter <pointer>.
  370. // It calls function Struct if <pointer> is type of *struct/**struct.
  371. // It calls function Structs if <pointer> is type of *[]struct/*[]*struct.
  372. //
  373. // The optional parameter <where> is the same as the parameter of Model.Where function,
  374. // see Model.Where.
  375. //
  376. // Note that it returns sql.ErrNoRows if there's no record retrieved and given pointer is not empty or nil.
  377. //
  378. // Eg:
  379. // user := new(User)
  380. // err := dao.User.Where("id", 1).Scan(user)
  381. //
  382. // user := (*User)(nil)
  383. // err := dao.User.Where("id", 1).Scan(&user)
  384. //
  385. // users := ([]User)(nil)
  386. // err := dao.User.Scan(&users)
  387. //
  388. // users := ([]*User)(nil)
  389. // err := dao.User.Scan(&users)
  390. func (d *SysUserDao) Scan(pointer interface{}, where ...interface{}) error {
  391. return d.M.Scan(pointer, where...)
  392. }
  393. // Chunk iterates the table with given size and callback function.
  394. func (d *SysUserDao) Chunk(limit int, callback func(entities []*model.SysUser, err error) bool) {
  395. d.M.Chunk(limit, func(result gdb.Result, err error) bool {
  396. var entities []*model.SysUser
  397. err = result.Structs(&entities)
  398. if err == sql.ErrNoRows {
  399. return false
  400. }
  401. return callback(entities, err)
  402. })
  403. }
  404. // LockUpdate sets the lock for update for current operation.
  405. func (d *SysUserDao) LockUpdate() *SysUserDao {
  406. return &SysUserDao{M: d.M.LockUpdate()}
  407. }
  408. // LockShared sets the lock in share mode for current operation.
  409. func (d *SysUserDao) LockShared() *SysUserDao {
  410. return &SysUserDao{M: d.M.LockShared()}
  411. }
  412. // Unscoped enables/disables the soft deleting feature.
  413. func (d *SysUserDao) Unscoped() *SysUserDao {
  414. return &SysUserDao{M: d.M.Unscoped()}
  415. }