base_distributor.go 33 KB

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