cust_customer.go 32 KB

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