sys_dept.go 15 KB

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