sys_message.go 32 KB

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