sys_user.go 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764
  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. "github.com/gogf/gf/util/gconv"
  12. "strings"
  13. "time"
  14. "dashoo.cn/micro/app/model"
  15. )
  16. // SysUserDao is the manager for logic model data accessing and custom defined data operations functions management.
  17. type SysUserDao struct {
  18. gmvc.M // M is the core and embedded struct that inherits all chaining operations from gdb.Model.
  19. C sysUserColumns // C is the short type for Columns, which contains all the column names of Table for convenient usage.
  20. DB gdb.DB // DB is the raw underlying database management object.
  21. Table string // Table is the underlying table name of the DAO.
  22. TableAs string // TableAs is the underlying table alias name of the DAO.
  23. }
  24. // SysUserColumns defines and stores column names for table sys_user.
  25. type sysUserColumns struct {
  26. Id string // 用户ID
  27. DeptId string // 部门ID
  28. UserName string // 用户账号
  29. NickName string // 用户昵称
  30. UserType string // 用户类型(00系统用户)
  31. Email string // 用户邮箱
  32. Phone string // 手机号码
  33. Sex string // 用户性别(10男20女30未知)
  34. Avatar string // 头像地址
  35. Status string // 帐号状态(10正常20停用)
  36. UserSalt string // 加密盐
  37. Password string // 密码
  38. LoginIp string // 最后登录IP
  39. LoginDate string // 最后登录时间
  40. WechatId string // 微信open_id
  41. DingtalkId string // 钉钉union_id
  42. DingtalkUid string // 钉钉用户ID
  43. IsFirstLogin string // 首次登录(10是20否)
  44. AllowErrorNum string // 允许登录错误次数
  45. Remark string // 备注
  46. CreatedBy string // 创建者
  47. CreatedName string // 创建人
  48. CreatedTime string // 创建时间
  49. UpdatedBy string // 更新者
  50. UpdatedName string // 更新人
  51. UpdatedTime string // 更新时间
  52. DeletedTime string // 删除时间
  53. }
  54. var (
  55. // SysUser is globally public accessible object for table sys_user operations.
  56. SysUser = SysUserDao{
  57. M: g.DB("default").Model("sys_user").Safe(),
  58. DB: g.DB("default"),
  59. Table: "sys_user",
  60. C: sysUserColumns{
  61. Id: "id",
  62. DeptId: "dept_id",
  63. UserName: "user_name",
  64. NickName: "nick_name",
  65. UserType: "user_type",
  66. Email: "email",
  67. Phone: "phone",
  68. Sex: "sex",
  69. Avatar: "avatar",
  70. Status: "status",
  71. UserSalt: "user_salt",
  72. Password: "password",
  73. LoginIp: "login_ip",
  74. LoginDate: "login_date",
  75. WechatId: "wechat_id",
  76. DingtalkId: "dingtalk_id",
  77. DingtalkUid: "dingtalk_uid",
  78. IsFirstLogin: "is_first_login",
  79. AllowErrorNum: "allow_error_num",
  80. Remark: "remark",
  81. CreatedBy: "created_by",
  82. CreatedName: "created_name",
  83. CreatedTime: "created_time",
  84. UpdatedBy: "updated_by",
  85. UpdatedName: "updated_name",
  86. UpdatedTime: "updated_time",
  87. DeletedTime: "deleted_time",
  88. },
  89. }
  90. )
  91. func NewSysUserDao(tenant string) SysUserDao {
  92. var dao SysUserDao
  93. dao = SysUserDao{
  94. M: g.DB(tenant).Model("sys_user").Safe(),
  95. DB: g.DB(tenant),
  96. Table: "sys_user",
  97. C: sysUserColumns{
  98. Id: "id",
  99. DeptId: "dept_id",
  100. UserName: "user_name",
  101. NickName: "nick_name",
  102. UserType: "user_type",
  103. Email: "email",
  104. Phone: "phone",
  105. Sex: "sex",
  106. Avatar: "avatar",
  107. Status: "status",
  108. UserSalt: "user_salt",
  109. Password: "password",
  110. LoginIp: "login_ip",
  111. LoginDate: "login_date",
  112. WechatId: "wechat_id",
  113. DingtalkId: "dingtalk_id",
  114. DingtalkUid: "dingtalk_uid",
  115. IsFirstLogin: "is_first_login",
  116. AllowErrorNum: "allow_error_num",
  117. Remark: "remark",
  118. CreatedBy: "created_by",
  119. CreatedName: "created_name",
  120. CreatedTime: "created_time",
  121. UpdatedBy: "updated_by",
  122. UpdatedName: "updated_name",
  123. UpdatedTime: "updated_time",
  124. DeletedTime: "deleted_time",
  125. },
  126. }
  127. return dao
  128. }
  129. // Ctx is a chaining function, which creates and returns a new DB that is a shallow copy
  130. // of current DB object and with given context in it.
  131. // Note that this returned DB object can be used only once, so do not assign it to
  132. // a global or package variable for long using.
  133. func (d *SysUserDao) Ctx(ctx context.Context) *SysUserDao {
  134. return &SysUserDao{M: d.M.Ctx(ctx), Table: d.Table, TableAs: d.TableAs}
  135. }
  136. // GetCtx returns the context for current Model.
  137. // It returns "context.Background() i"s there's no context previously set.
  138. func (d *SysUserDao) GetCtx() context.Context {
  139. return d.M.GetCtx()
  140. }
  141. // As sets an alias name for current table.
  142. func (d *SysUserDao) As(as string) *SysUserDao {
  143. return &SysUserDao{M: d.M.As(as), Table: d.Table, TableAs: as}
  144. }
  145. // TX sets the transaction for current operation.
  146. func (d *SysUserDao) TX(tx *gdb.TX) *SysUserDao {
  147. return &SysUserDao{M: d.M.TX(tx), Table: d.Table, TableAs: d.TableAs}
  148. }
  149. // Master marks the following operation on master node.
  150. func (d *SysUserDao) Master() *SysUserDao {
  151. return &SysUserDao{M: d.M.Master(), Table: d.Table, TableAs: d.TableAs}
  152. }
  153. // Slave marks the following operation on slave node.
  154. // Note that it makes sense only if there's any slave node configured.
  155. func (d *SysUserDao) Slave() *SysUserDao {
  156. return &SysUserDao{M: d.M.Slave(), Table: d.Table, TableAs: d.TableAs}
  157. }
  158. // Args sets custom arguments for model operation.
  159. func (d *SysUserDao) Args(args ...interface{}) *SysUserDao {
  160. return &SysUserDao{M: d.M.Args(args...), Table: d.Table, TableAs: d.TableAs}
  161. }
  162. // Handler calls each of "handlers" on current Model and returns a new Model.
  163. // ModelHandler is a function that handles given Model and returns a new Model that is custom modified.
  164. func (d *SysUserDao) Handler(handlers ...gdb.ModelHandler) *SysUserDao {
  165. return &SysUserDao{M: d.M.Handler(handlers...), Table: d.Table, TableAs: d.TableAs}
  166. }
  167. // LeftJoin does "LEFT JOIN ... ON ..." statement on the model.
  168. // The parameter <table> can be joined table and its joined condition,
  169. // and also with its alias name, like:
  170. // Table("user").LeftJoin("user_detail", "user_detail.uid=user.uid")
  171. // Table("user", "u").LeftJoin("user_detail", "ud", "ud.uid=u.uid")
  172. func (d *SysUserDao) LeftJoin(table ...string) *SysUserDao {
  173. return &SysUserDao{M: d.M.LeftJoin(table...), Table: d.Table, TableAs: d.TableAs}
  174. }
  175. // RightJoin does "RIGHT JOIN ... ON ..." statement on the model.
  176. // The parameter <table> can be joined table and its joined condition,
  177. // and also with its alias name, like:
  178. // Table("user").RightJoin("user_detail", "user_detail.uid=user.uid")
  179. // Table("user", "u").RightJoin("user_detail", "ud", "ud.uid=u.uid")
  180. func (d *SysUserDao) RightJoin(table ...string) *SysUserDao {
  181. return &SysUserDao{M: d.M.RightJoin(table...), Table: d.Table, TableAs: d.TableAs}
  182. }
  183. // InnerJoin does "INNER JOIN ... ON ..." statement on the model.
  184. // The parameter <table> can be joined table and its joined condition,
  185. // and also with its alias name, like:
  186. // Table("user").InnerJoin("user_detail", "user_detail.uid=user.uid")
  187. // Table("user", "u").InnerJoin("user_detail", "ud", "ud.uid=u.uid")
  188. func (d *SysUserDao) InnerJoin(table ...string) *SysUserDao {
  189. return &SysUserDao{M: d.M.InnerJoin(table...), Table: d.Table, TableAs: d.TableAs}
  190. }
  191. // Fields sets the operation fields of the model, multiple fields joined using char ','.
  192. // The parameter <fieldNamesOrMapStruct> can be type of string/map/*map/struct/*struct.
  193. func (d *SysUserDao) Fields(fieldNamesOrMapStruct ...interface{}) *SysUserDao {
  194. return &SysUserDao{M: d.M.Fields(fieldNamesOrMapStruct...), Table: d.Table, TableAs: d.TableAs}
  195. }
  196. // FieldsEx sets the excluded operation fields of the model, multiple fields joined using char ','.
  197. // The parameter <fieldNamesOrMapStruct> can be type of string/map/*map/struct/*struct.
  198. func (d *SysUserDao) FieldsEx(fieldNamesOrMapStruct ...interface{}) *SysUserDao {
  199. return &SysUserDao{M: d.M.FieldsEx(fieldNamesOrMapStruct...), Table: d.Table, TableAs: d.TableAs}
  200. }
  201. // FieldCount formats and appends commonly used field "COUNT(column)" to the select fields of model.
  202. func (d *SysUserDao) FieldCount(column string, as ...string) *SysUserDao {
  203. return &SysUserDao{M: d.M.FieldCount(column, as...), Table: d.Table, TableAs: d.TableAs}
  204. }
  205. // FieldSum formats and appends commonly used field "SUM(column)" to the select fields of model.
  206. func (d *SysUserDao) FieldSum(column string, as ...string) *SysUserDao {
  207. return &SysUserDao{M: d.M.FieldSum(column, as...), Table: d.Table, TableAs: d.TableAs}
  208. }
  209. // FieldMin formats and appends commonly used field "MIN(column)" to the select fields of model.
  210. func (d *SysUserDao) FieldMin(column string, as ...string) *SysUserDao {
  211. return &SysUserDao{M: d.M.FieldMin(column, as...), Table: d.Table, TableAs: d.TableAs}
  212. }
  213. // FieldMax formats and appends commonly used field "MAX(column)" to the select fields of model.
  214. func (d *SysUserDao) FieldMax(column string, as ...string) *SysUserDao {
  215. return &SysUserDao{M: d.M.FieldMax(column, as...), Table: d.Table, TableAs: d.TableAs}
  216. }
  217. // FieldAvg formats and appends commonly used field "AVG(column)" to the select fields of model.
  218. func (d *SysUserDao) FieldAvg(column string, as ...string) *SysUserDao {
  219. return &SysUserDao{M: d.M.FieldAvg(column, as...), Table: d.Table, TableAs: d.TableAs}
  220. }
  221. // Option adds extra operation option for the model.
  222. // Deprecated, use separate operations instead.
  223. func (d *SysUserDao) Option(option int) *SysUserDao {
  224. return &SysUserDao{M: d.M.Option(option), Table: d.Table, TableAs: d.TableAs}
  225. }
  226. // OmitEmpty sets OPTION_OMITEMPTY option for the model, which automatically filers
  227. // the data and where attributes for empty values.
  228. func (d *SysUserDao) OmitEmpty() *SysUserDao {
  229. return &SysUserDao{M: d.M.OmitEmpty(), Table: d.Table, TableAs: d.TableAs}
  230. }
  231. // OmitEmptyWhere sets optionOmitEmptyWhere option for the model, which automatically filers
  232. // the Where/Having parameters for "empty" values.
  233. func (d *SysUserDao) OmitEmptyWhere() *SysUserDao {
  234. return &SysUserDao{M: d.M.OmitEmptyWhere(), Table: d.Table, TableAs: d.TableAs}
  235. }
  236. // OmitEmptyData sets optionOmitEmptyData option for the model, which automatically filers
  237. // the Data parameters for "empty" values.
  238. func (d *SysUserDao) OmitEmptyData() *SysUserDao {
  239. return &SysUserDao{M: d.M.OmitEmptyData(), Table: d.Table, TableAs: d.TableAs}
  240. }
  241. // OmitNil sets optionOmitNil option for the model, which automatically filers
  242. // the data and where parameters for "nil" values.
  243. func (d *SysUserDao) OmitNil() *SysUserDao {
  244. return &SysUserDao{M: d.M.OmitNil(), Table: d.Table, TableAs: d.TableAs}
  245. }
  246. // OmitNilWhere sets optionOmitNilWhere option for the model, which automatically filers
  247. // the Where/Having parameters for "nil" values.
  248. func (d *SysUserDao) OmitNilWhere() *SysUserDao {
  249. return &SysUserDao{M: d.M.OmitNilWhere(), Table: d.Table, TableAs: d.TableAs}
  250. }
  251. // OmitNilData sets optionOmitNilData option for the model, which automatically filers
  252. // the Data parameters for "nil" values.
  253. func (d *SysUserDao) OmitNilData() *SysUserDao {
  254. return &SysUserDao{M: d.M.OmitNilData(), Table: d.Table, TableAs: d.TableAs}
  255. }
  256. // Filter marks filtering the fields which does not exist in the fields of the operated table.
  257. // Note that this function supports only single table operations.
  258. // Deprecated, filter feature is automatically enabled from GoFrame v1.16.0, it is so no longer used.
  259. func (d *SysUserDao) Filter() *SysUserDao {
  260. return &SysUserDao{M: d.M.Filter(), Table: d.Table, TableAs: d.TableAs}
  261. }
  262. // Where sets the condition statement for the model. The parameter <where> can be type of
  263. // string/map/gmap/slice/struct/*struct, etc. Note that, if it's called more than one times,
  264. // multiple conditions will be joined into where statement using "AND".
  265. // Eg:
  266. // Where("uid=10000")
  267. // Where("uid", 10000)
  268. // Where("money>? AND name like ?", 99999, "vip_%")
  269. // Where("uid", 1).Where("name", "john")
  270. // Where("status IN (?)", g.Slice{1,2,3})
  271. // Where("age IN(?,?)", 18, 50)
  272. // Where(User{ Id : 1, UserName : "john"})
  273. func (d *SysUserDao) Where(where interface{}, args ...interface{}) *SysUserDao {
  274. return &SysUserDao{M: d.M.Where(where, args...), Table: d.Table, TableAs: d.TableAs}
  275. }
  276. // WherePri does the same logic as M.Where except that if the parameter <where>
  277. // is a single condition like int/string/float/slice, it treats the condition as the primary
  278. // key value. That is, if primary key is "id" and given <where> parameter as "123", the
  279. // WherePri function treats the condition as "id=123", but M.Where treats the condition
  280. // as string "123".
  281. func (d *SysUserDao) WherePri(where interface{}, args ...interface{}) *SysUserDao {
  282. return &SysUserDao{M: d.M.WherePri(where, args...), Table: d.Table, TableAs: d.TableAs}
  283. }
  284. // Having sets the having statement for the model.
  285. // The parameters of this function usage are as the same as function Where.
  286. // See Where.
  287. func (d *SysUserDao) Having(having interface{}, args ...interface{}) *SysUserDao {
  288. return &SysUserDao{M: d.M.Having(having, args...), Table: d.Table, TableAs: d.TableAs}
  289. }
  290. // Wheref builds condition string using fmt.Sprintf and arguments.
  291. // Note that if the number of "args" is more than the place holder in "format",
  292. // the extra "args" will be used as the where condition arguments of the Model.
  293. func (d *SysUserDao) Wheref(format string, args ...interface{}) *SysUserDao {
  294. return &SysUserDao{M: d.M.Wheref(format, args...), Table: d.Table, TableAs: d.TableAs}
  295. }
  296. // WhereLT builds "column < value" statement.
  297. func (d *SysUserDao) WhereLT(column string, value interface{}) *SysUserDao {
  298. return &SysUserDao{M: d.M.WhereLT(column, value), Table: d.Table, TableAs: d.TableAs}
  299. }
  300. // WhereLTE builds "column <= value" statement.
  301. func (d *SysUserDao) WhereLTE(column string, value interface{}) *SysUserDao {
  302. return &SysUserDao{M: d.M.WhereLTE(column, value), Table: d.Table, TableAs: d.TableAs}
  303. }
  304. // WhereGT builds "column > value" statement.
  305. func (d *SysUserDao) WhereGT(column string, value interface{}) *SysUserDao {
  306. return &SysUserDao{M: d.M.WhereGT(column, value), Table: d.Table, TableAs: d.TableAs}
  307. }
  308. // WhereGTE builds "column >= value" statement.
  309. func (d *SysUserDao) WhereGTE(column string, value interface{}) *SysUserDao {
  310. return &SysUserDao{M: d.M.WhereGTE(column, value), Table: d.Table, TableAs: d.TableAs}
  311. }
  312. // WhereBetween builds "column BETWEEN min AND max" statement.
  313. func (d *SysUserDao) WhereBetween(column string, min, max interface{}) *SysUserDao {
  314. return &SysUserDao{M: d.M.WhereBetween(column, min, max), Table: d.Table, TableAs: d.TableAs}
  315. }
  316. // WhereLike builds "column LIKE like" statement.
  317. func (d *SysUserDao) WhereLike(column string, like interface{}) *SysUserDao {
  318. return &SysUserDao{M: d.M.WhereLike(column, like), Table: d.Table, TableAs: d.TableAs}
  319. }
  320. // WhereIn builds "column IN (in)" statement.
  321. func (d *SysUserDao) WhereIn(column string, in interface{}) *SysUserDao {
  322. return &SysUserDao{M: d.M.WhereIn(column, in), Table: d.Table, TableAs: d.TableAs}
  323. }
  324. // WhereNull builds "columns[0] IS NULL AND columns[1] IS NULL ..." statement.
  325. func (d *SysUserDao) WhereNull(columns ...string) *SysUserDao {
  326. return &SysUserDao{M: d.M.WhereNull(columns...), Table: d.Table, TableAs: d.TableAs}
  327. }
  328. // WhereNotBetween builds "column NOT BETWEEN min AND max" statement.
  329. func (d *SysUserDao) WhereNotBetween(column string, min, max interface{}) *SysUserDao {
  330. return &SysUserDao{M: d.M.WhereNotBetween(column, min, max), Table: d.Table, TableAs: d.TableAs}
  331. }
  332. // WhereNotLike builds "column NOT LIKE like" statement.
  333. func (d *SysUserDao) WhereNotLike(column string, like interface{}) *SysUserDao {
  334. return &SysUserDao{M: d.M.WhereNotLike(column, like), Table: d.Table, TableAs: d.TableAs}
  335. }
  336. // WhereNot builds "column != value" statement.
  337. func (d *SysUserDao) WhereNot(column string, value interface{}) *SysUserDao {
  338. return &SysUserDao{M: d.M.WhereNot(column, value), Table: d.Table, TableAs: d.TableAs}
  339. }
  340. // WhereNotIn builds "column NOT IN (in)" statement.
  341. func (d *SysUserDao) WhereNotIn(column string, in interface{}) *SysUserDao {
  342. return &SysUserDao{M: d.M.WhereNotIn(column, in), Table: d.Table, TableAs: d.TableAs}
  343. }
  344. // WhereNotNull builds "columns[0] IS NOT NULL AND columns[1] IS NOT NULL ..." statement.
  345. func (d *SysUserDao) WhereNotNull(columns ...string) *SysUserDao {
  346. return &SysUserDao{M: d.M.WhereNotNull(columns...), Table: d.Table, TableAs: d.TableAs}
  347. }
  348. // WhereOr adds "OR" condition to the where statement.
  349. func (d *SysUserDao) WhereOr(where interface{}, args ...interface{}) *SysUserDao {
  350. return &SysUserDao{M: d.M.WhereOr(where, args...), Table: d.Table, TableAs: d.TableAs}
  351. }
  352. // WhereOrf builds "OR" condition string using fmt.Sprintf and arguments.
  353. func (d *SysUserDao) WhereOrf(format string, args ...interface{}) *SysUserDao {
  354. return &SysUserDao{M: d.M.WhereOrf(format, args...), Table: d.Table, TableAs: d.TableAs}
  355. }
  356. // WhereOrLT builds "column < value" statement in "OR" conditions..
  357. func (d *SysUserDao) WhereOrLT(column string, value interface{}) *SysUserDao {
  358. return &SysUserDao{M: d.M.WhereOrLT(column, value), Table: d.Table, TableAs: d.TableAs}
  359. }
  360. // WhereOrLTE builds "column <= value" statement in "OR" conditions..
  361. func (d *SysUserDao) WhereOrLTE(column string, value interface{}) *SysUserDao {
  362. return &SysUserDao{M: d.M.WhereOrLTE(column, value), Table: d.Table, TableAs: d.TableAs}
  363. }
  364. // WhereOrGT builds "column > value" statement in "OR" conditions..
  365. func (d *SysUserDao) WhereOrGT(column string, value interface{}) *SysUserDao {
  366. return &SysUserDao{M: d.M.WhereOrGT(column, value), Table: d.Table, TableAs: d.TableAs}
  367. }
  368. // WhereOrGTE builds "column >= value" statement in "OR" conditions..
  369. func (d *SysUserDao) WhereOrGTE(column string, value interface{}) *SysUserDao {
  370. return &SysUserDao{M: d.M.WhereOrGTE(column, value), Table: d.Table, TableAs: d.TableAs}
  371. }
  372. // WhereOrBetween builds "column BETWEEN min AND max" statement in "OR" conditions.
  373. func (d *SysUserDao) WhereOrBetween(column string, min, max interface{}) *SysUserDao {
  374. return &SysUserDao{M: d.M.WhereOrBetween(column, min, max), Table: d.Table, TableAs: d.TableAs}
  375. }
  376. // WhereOrLike builds "column LIKE like" statement in "OR" conditions.
  377. func (d *SysUserDao) WhereOrLike(column string, like interface{}) *SysUserDao {
  378. return &SysUserDao{M: d.M.WhereOrLike(column, like), Table: d.Table, TableAs: d.TableAs}
  379. }
  380. // WhereOrIn builds "column IN (in)" statement in "OR" conditions.
  381. func (d *SysUserDao) WhereOrIn(column string, in interface{}) *SysUserDao {
  382. return &SysUserDao{M: d.M.WhereOrIn(column, in), Table: d.Table, TableAs: d.TableAs}
  383. }
  384. // WhereOrNull builds "columns[0] IS NULL OR columns[1] IS NULL ..." statement in "OR" conditions.
  385. func (d *SysUserDao) WhereOrNull(columns ...string) *SysUserDao {
  386. return &SysUserDao{M: d.M.WhereOrNull(columns...), Table: d.Table, TableAs: d.TableAs}
  387. }
  388. // WhereOrNotBetween builds "column NOT BETWEEN min AND max" statement in "OR" conditions.
  389. func (d *SysUserDao) WhereOrNotBetween(column string, min, max interface{}) *SysUserDao {
  390. return &SysUserDao{M: d.M.WhereOrNotBetween(column, min, max), Table: d.Table, TableAs: d.TableAs}
  391. }
  392. // WhereOrNotLike builds "column NOT LIKE like" statement in "OR" conditions.
  393. func (d *SysUserDao) WhereOrNotLike(column string, like interface{}) *SysUserDao {
  394. return &SysUserDao{M: d.M.WhereOrNotLike(column, like), Table: d.Table, TableAs: d.TableAs}
  395. }
  396. // WhereOrNotIn builds "column NOT IN (in)" statement.
  397. func (d *SysUserDao) WhereOrNotIn(column string, in interface{}) *SysUserDao {
  398. return &SysUserDao{M: d.M.WhereOrNotIn(column, in), Table: d.Table, TableAs: d.TableAs}
  399. }
  400. // WhereOrNotNull builds "columns[0] IS NOT NULL OR columns[1] IS NOT NULL ..." statement in "OR" conditions.
  401. func (d *SysUserDao) WhereOrNotNull(columns ...string) *SysUserDao {
  402. return &SysUserDao{M: d.M.WhereOrNotNull(columns...), Table: d.Table, TableAs: d.TableAs}
  403. }
  404. // Group sets the "GROUP BY" statement for the model.
  405. func (d *SysUserDao) Group(groupBy ...string) *SysUserDao {
  406. return &SysUserDao{M: d.M.Group(groupBy...), Table: d.Table, TableAs: d.TableAs}
  407. }
  408. // And adds "AND" condition to the where statement.
  409. // Deprecated, use Where instead.
  410. func (d *SysUserDao) And(where interface{}, args ...interface{}) *SysUserDao {
  411. return &SysUserDao{M: d.M.And(where, args...), Table: d.Table, TableAs: d.TableAs}
  412. }
  413. // Or adds "OR" condition to the where statement.
  414. // Deprecated, use WhereOr instead.
  415. func (d *SysUserDao) Or(where interface{}, args ...interface{}) *SysUserDao {
  416. return &SysUserDao{M: d.M.Or(where, args...), Table: d.Table, TableAs: d.TableAs}
  417. }
  418. // GroupBy sets the "GROUP BY" statement for the model.
  419. func (d *SysUserDao) GroupBy(groupBy string) *SysUserDao {
  420. return &SysUserDao{M: d.M.Group(groupBy), Table: d.Table, TableAs: d.TableAs}
  421. }
  422. // Order sets the "ORDER BY" statement for the model.
  423. func (d *SysUserDao) Order(orderBy ...string) *SysUserDao {
  424. return &SysUserDao{M: d.M.Order(orderBy...), Table: d.Table, TableAs: d.TableAs}
  425. }
  426. // OrderAsc sets the "ORDER BY xxx ASC" statement for the model.
  427. func (d *SysUserDao) OrderAsc(column string) *SysUserDao {
  428. return &SysUserDao{M: d.M.OrderAsc(column), Table: d.Table, TableAs: d.TableAs}
  429. }
  430. // OrderDesc sets the "ORDER BY xxx DESC" statement for the model.
  431. func (d *SysUserDao) OrderDesc(column string) *SysUserDao {
  432. return &SysUserDao{M: d.M.OrderDesc(column), Table: d.Table, TableAs: d.TableAs}
  433. }
  434. // OrderRandom sets the "ORDER BY RANDOM()" statement for the model.
  435. func (d *SysUserDao) OrderRandom() *SysUserDao {
  436. return &SysUserDao{M: d.M.OrderRandom(), Table: d.Table, TableAs: d.TableAs}
  437. }
  438. // OrderBy is alias of Model.Order.
  439. // See Model.Order.
  440. // Deprecated, use Order instead.
  441. func (d *SysUserDao) OrderBy(orderBy string) *SysUserDao {
  442. return &SysUserDao{M: d.M.Order(orderBy), Table: d.Table, TableAs: d.TableAs}
  443. }
  444. // Limit sets the "LIMIT" statement for the model.
  445. // The parameter <limit> can be either one or two number, if passed two number is passed,
  446. // it then sets "LIMIT limit[0],limit[1]" statement for the model, or else it sets "LIMIT limit[0]"
  447. // statement.
  448. func (d *SysUserDao) Limit(limit ...int) *SysUserDao {
  449. return &SysUserDao{M: d.M.Limit(limit...), Table: d.Table, TableAs: d.TableAs}
  450. }
  451. // Offset sets the "OFFSET" statement for the model.
  452. // It only makes sense for some databases like SQLServer, PostgreSQL, etc.
  453. func (d *SysUserDao) Offset(offset int) *SysUserDao {
  454. return &SysUserDao{M: d.M.Offset(offset), Table: d.Table, TableAs: d.TableAs}
  455. }
  456. // Distinct forces the query to only return distinct results.
  457. func (d *SysUserDao) Distinct() *SysUserDao {
  458. return &SysUserDao{M: d.M.Distinct(), Table: d.Table, TableAs: d.TableAs}
  459. }
  460. // Page sets the paging number for the model.
  461. // The parameter <page> is started from 1 for paging.
  462. // Note that, it differs that the Limit function start from 0 for "LIMIT" statement.
  463. func (d *SysUserDao) Page(page, limit int) *SysUserDao {
  464. return &SysUserDao{M: d.M.Page(page, limit), Table: d.Table, TableAs: d.TableAs}
  465. }
  466. // Batch sets the batch operation number for the model.
  467. func (d *SysUserDao) Batch(batch int) *SysUserDao {
  468. return &SysUserDao{M: d.M.Batch(batch), Table: d.Table, TableAs: d.TableAs}
  469. }
  470. // Cache sets the cache feature for the model. It caches the result of the sql, which means
  471. // if there's another same sql request, it just reads and returns the result from cache, it
  472. // but not committed and executed into the database.
  473. //
  474. // If the parameter <duration> < 0, which means it clear the cache with given <name>.
  475. // If the parameter <duration> = 0, which means it never expires.
  476. // If the parameter <duration> > 0, which means it expires after <duration>.
  477. //
  478. // The optional parameter <name> is used to bind a name to the cache, which means you can later
  479. // control the cache like changing the <duration> or clearing the cache with specified <name>.
  480. //
  481. // Note that, the cache feature is disabled if the model is operating on a transaction.
  482. func (d *SysUserDao) Cache(duration time.Duration, name ...string) *SysUserDao {
  483. return &SysUserDao{M: d.M.Cache(duration, name...), Table: d.Table, TableAs: d.TableAs}
  484. }
  485. // Data sets the operation data for the model.
  486. // The parameter <data> can be type of string/map/gmap/slice/struct/*struct, etc.
  487. // Eg:
  488. // Data("uid=10000")
  489. // Data("uid", 10000)
  490. // Data(g.Map{"uid": 10000, "name":"john"})
  491. // Data(g.Slice{g.Map{"uid": 10000, "name":"john"}, g.Map{"uid": 20000, "name":"smith"})
  492. func (d *SysUserDao) Data(data ...interface{}) *SysUserDao {
  493. return &SysUserDao{M: d.M.Data(data...), Table: d.Table, TableAs: d.TableAs}
  494. }
  495. // All does "SELECT FROM ..." statement for the model.
  496. // It retrieves the records from table and returns the result as []*model.SysUser.
  497. // It returns nil if there's no record retrieved with the given conditions from table.
  498. //
  499. // The optional parameter <where> is the same as the parameter of M.Where function,
  500. // see M.Where.
  501. func (d *SysUserDao) All(where ...interface{}) ([]*model.SysUser, error) {
  502. all, err := d.M.All(where...)
  503. if err != nil {
  504. return nil, err
  505. }
  506. var entities []*model.SysUser
  507. if err = all.Structs(&entities); err != nil && err != sql.ErrNoRows {
  508. return nil, err
  509. }
  510. return entities, nil
  511. }
  512. // One retrieves one record from table and returns the result as *model.SysUser.
  513. // It returns nil if there's no record retrieved with the given conditions from table.
  514. //
  515. // The optional parameter <where> is the same as the parameter of M.Where function,
  516. // see M.Where.
  517. func (d *SysUserDao) One(where ...interface{}) (*model.SysUser, error) {
  518. one, err := d.M.One(where...)
  519. if err != nil {
  520. return nil, err
  521. }
  522. var entity *model.SysUser
  523. if err = one.Struct(&entity); err != nil && err != sql.ErrNoRows {
  524. return nil, err
  525. }
  526. return entity, nil
  527. }
  528. // FindOne retrieves and returns a single Record by M.WherePri and M.One.
  529. // Also see M.WherePri and M.One.
  530. func (d *SysUserDao) FindOne(where ...interface{}) (*model.SysUser, error) {
  531. one, err := d.M.FindOne(where...)
  532. if err != nil {
  533. return nil, err
  534. }
  535. var entity *model.SysUser
  536. if err = one.Struct(&entity); err != nil && err != sql.ErrNoRows {
  537. return nil, err
  538. }
  539. return entity, nil
  540. }
  541. // FindAll retrieves and returns Result by by M.WherePri and M.All.
  542. // Also see M.WherePri and M.All.
  543. func (d *SysUserDao) FindAll(where ...interface{}) ([]*model.SysUser, error) {
  544. all, err := d.M.FindAll(where...)
  545. if err != nil {
  546. return nil, err
  547. }
  548. var entities []*model.SysUser
  549. if err = all.Structs(&entities); err != nil && err != sql.ErrNoRows {
  550. return nil, err
  551. }
  552. return entities, nil
  553. }
  554. // Struct retrieves one record from table and converts it into given struct.
  555. // The parameter <pointer> should be type of *struct/**struct. If type **struct is given,
  556. // it can create the struct internally during converting.
  557. //
  558. // The optional parameter <where> is the same as the parameter of Model.Where function,
  559. // see Model.Where.
  560. //
  561. // Note that it returns sql.ErrNoRows if there's no record retrieved with the given conditions
  562. // from table and <pointer> is not nil.
  563. //
  564. // Eg:
  565. // user := new(User)
  566. // err := dao.User.Where("id", 1).Struct(user)
  567. //
  568. // user := (*User)(nil)
  569. // err := dao.User.Where("id", 1).Struct(&user)
  570. func (d *SysUserDao) Struct(pointer interface{}, where ...interface{}) error {
  571. return d.M.Struct(pointer, where...)
  572. }
  573. // Structs retrieves records from table and converts them into given struct slice.
  574. // The parameter <pointer> should be type of *[]struct/*[]*struct. It can create and fill the struct
  575. // slice internally during converting.
  576. //
  577. // The optional parameter <where> is the same as the parameter of Model.Where function,
  578. // see Model.Where.
  579. //
  580. // Note that it returns sql.ErrNoRows if there's no record retrieved with the given conditions
  581. // from table and <pointer> is not empty.
  582. //
  583. // Eg:
  584. // users := ([]User)(nil)
  585. // err := dao.User.Structs(&users)
  586. //
  587. // users := ([]*User)(nil)
  588. // err := dao.User.Structs(&users)
  589. func (d *SysUserDao) Structs(pointer interface{}, where ...interface{}) error {
  590. return d.M.Structs(pointer, where...)
  591. }
  592. // Scan automatically calls Struct or Structs function according to the type of parameter <pointer>.
  593. // It calls function Struct if <pointer> is type of *struct/**struct.
  594. // It calls function Structs if <pointer> is type of *[]struct/*[]*struct.
  595. //
  596. // The optional parameter <where> is the same as the parameter of Model.Where function,
  597. // see Model.Where.
  598. //
  599. // Note that it returns sql.ErrNoRows if there's no record retrieved and given pointer is not empty or nil.
  600. //
  601. // Eg:
  602. // user := new(User)
  603. // err := dao.User.Where("id", 1).Scan(user)
  604. //
  605. // user := (*User)(nil)
  606. // err := dao.User.Where("id", 1).Scan(&user)
  607. //
  608. // users := ([]User)(nil)
  609. // err := dao.User.Scan(&users)
  610. //
  611. // users := ([]*User)(nil)
  612. // err := dao.User.Scan(&users)
  613. func (d *SysUserDao) Scan(pointer interface{}, where ...interface{}) error {
  614. return d.M.Scan(pointer, where...)
  615. }
  616. // Chunk iterates the table with given size and callback function.
  617. func (d *SysUserDao) Chunk(limit int, callback func(entities []*model.SysUser, err error) bool) {
  618. d.M.Chunk(limit, func(result gdb.Result, err error) bool {
  619. var entities []*model.SysUser
  620. err = result.Structs(&entities)
  621. if err == sql.ErrNoRows {
  622. return false
  623. }
  624. return callback(entities, err)
  625. })
  626. }
  627. // LockUpdate sets the lock for update for current operation.
  628. func (d *SysUserDao) LockUpdate() *SysUserDao {
  629. return &SysUserDao{M: d.M.LockUpdate(), Table: d.Table, TableAs: d.TableAs}
  630. }
  631. // LockShared sets the lock in share mode for current operation.
  632. func (d *SysUserDao) LockShared() *SysUserDao {
  633. return &SysUserDao{M: d.M.LockShared(), Table: d.Table, TableAs: d.TableAs}
  634. }
  635. // Unscoped enables/disables the soft deleting feature.
  636. func (d *SysUserDao) Unscoped() *SysUserDao {
  637. return &SysUserDao{M: d.M.Unscoped(), Table: d.Table, TableAs: d.TableAs}
  638. }
  639. // DataScope enables the DataScope feature.
  640. func (d *SysUserDao) DataScope(ctx context.Context, userCol ...string) *SysUserDao {
  641. cs := ctx.Value("contextService")
  642. dataScope := gconv.Map(cs)["dataScope"].(g.Map)
  643. if dataScope != nil {
  644. userIds, ok := dataScope["userIds"]
  645. delete(dataScope, "userIds")
  646. var columns []string
  647. var values []interface{}
  648. if ok && userIds != "-1" {
  649. column := "created_by"
  650. if len(userCol) == 1 {
  651. column = userCol[0]
  652. }
  653. dataScope[column] = userIds
  654. if d.Table == "sys_user" {
  655. dataScope["id"] = userIds
  656. }
  657. }
  658. tableAs := d.TableAs
  659. if d.TableAs != "" {
  660. tableAs += "."
  661. }
  662. for k, v := range dataScope {
  663. if ok, _ := d.M.HasField(k); ok {
  664. columns = append(columns, tableAs+k+" IN (?) ")
  665. values = append(values, v)
  666. }
  667. }
  668. whereSql := strings.Join(columns, " OR ")
  669. return &SysUserDao{M: d.M.Where(whereSql, values).Ctx(ctx), Table: d.Table, TableAs: d.TableAs}
  670. }
  671. return d
  672. }