repair.go 15 KB

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