cust_customer.go 33 KB

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