base_distributor.go 32 KB

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