cust_customer.go 33 KB

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