base_distributor.go 37 KB

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