announcement.go 16 KB

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