sys_user.go 30 KB

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