cust_customer.go 33 KB

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