base_distributor.go 33 KB

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