base_distributor.go 37 KB

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