cust_customer.go 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490
  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. "time"
  9. "github.com/gogf/gf/database/gdb"
  10. "github.com/gogf/gf/frame/g"
  11. "github.com/gogf/gf/frame/gmvc"
  12. model "dashoo.cn/micro/app/model/cust"
  13. )
  14. // CustCustomerDao is the manager for logic model data accessing
  15. // and custom defined data operations functions management.
  16. type CustCustomerDao struct {
  17. gmvc.M
  18. DB gdb.DB
  19. Table string
  20. Columns custCustomerColumns
  21. }
  22. // CustCustomerColumns defines and stores column names for table cust_customer.
  23. type custCustomerColumns struct {
  24. Id string // 主键
  25. CustCode string // 客户编号
  26. CustName string // 客户名称
  27. AbbrName string // 助记名
  28. CustDistCode string // 客户所在省级ID
  29. CustLocation 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. Columns: custCustomerColumns{
  64. Id: "id",
  65. CustCode: "cust_code",
  66. CustName: "cust_name",
  67. AbbrName: "abbr_name",
  68. CustDistCode: "cust_dist_code",
  69. CustLocation: "cust_location",
  70. CustAddress: "cust_address",
  71. CustProvinceId: "cust_province_id",
  72. CustProvince: "cust_province",
  73. CustCityId: "cust_city_id",
  74. CustCity: "cust_city",
  75. CustRegionId: "cust_region_id",
  76. CustRegion: "cust_region",
  77. CustIndustry: "cust_industry",
  78. CustLevel: "cust_level",
  79. CustStatus: "cust_status",
  80. CustSource: "cust_source",
  81. IsPublic: "is_public",
  82. DeptId: "dept_id",
  83. DeptName: "dept_name",
  84. SalesId: "sales_id",
  85. SalesName: "sales_name",
  86. FollowUpDate: "follow_up_date",
  87. FollowUpMan: "follow_up_man",
  88. 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. Columns: custCustomerColumns{
  106. Id: "id",
  107. CustCode: "cust_code",
  108. CustName: "cust_name",
  109. AbbrName: "abbr_name",
  110. CustDistCode: "cust_dist_code",
  111. CustLocation: "cust_location",
  112. CustAddress: "cust_address",
  113. CustProvinceId: "cust_province_id",
  114. CustProvince: "cust_province",
  115. CustCityId: "cust_city_id",
  116. CustCity: "cust_city",
  117. CustRegionId: "cust_region_id",
  118. CustRegion: "cust_region",
  119. CustIndustry: "cust_industry",
  120. CustLevel: "cust_level",
  121. CustStatus: "cust_status",
  122. CustSource: "cust_source",
  123. IsPublic: "is_public",
  124. DeptId: "dept_id",
  125. DeptName: "dept_name",
  126. SalesId: "sales_id",
  127. SalesName: "sales_name",
  128. FollowUpDate: "follow_up_date",
  129. FollowUpMan: "follow_up_man",
  130. Remark: "remark",
  131. CreatedBy: "created_by",
  132. CreatedName: "created_name",
  133. CreatedTime: "created_time",
  134. UpdatedBy: "updated_by",
  135. UpdatedName: "updated_name",
  136. UpdatedTime: "updated_time",
  137. DeletedTime: "deleted_time",
  138. },
  139. }
  140. return dao
  141. }
  142. // Ctx is a chaining function, which creates and returns a new DB that is a shallow copy
  143. // of current DB object and with given context in it.
  144. // Note that this returned DB object can be used only once, so do not assign it to
  145. // a global or package variable for long using.
  146. func (d *CustCustomerDao) Ctx(ctx context.Context) *CustCustomerDao {
  147. return &CustCustomerDao{M: d.M.Ctx(ctx)}
  148. }
  149. // As sets an alias name for current table.
  150. func (d *CustCustomerDao) As(as string) *CustCustomerDao {
  151. return &CustCustomerDao{M: d.M.As(as)}
  152. }
  153. // TX sets the transaction for current operation.
  154. func (d *CustCustomerDao) TX(tx *gdb.TX) *CustCustomerDao {
  155. return &CustCustomerDao{M: d.M.TX(tx)}
  156. }
  157. // Master marks the following operation on master node.
  158. func (d *CustCustomerDao) Master() *CustCustomerDao {
  159. return &CustCustomerDao{M: d.M.Master()}
  160. }
  161. // Slave marks the following operation on slave node.
  162. // Note that it makes sense only if there's any slave node configured.
  163. func (d *CustCustomerDao) Slave() *CustCustomerDao {
  164. return &CustCustomerDao{M: d.M.Slave()}
  165. }
  166. // Args sets custom arguments for model operation.
  167. func (d *CustCustomerDao) Args(args ...interface{}) *CustCustomerDao {
  168. return &CustCustomerDao{M: d.M.Args(args...)}
  169. }
  170. // LeftJoin does "LEFT JOIN ... ON ..." statement on the model.
  171. // The parameter <table> can be joined table and its joined condition,
  172. // and also with its alias name, like:
  173. // Table("user").LeftJoin("user_detail", "user_detail.uid=user.uid")
  174. // Table("user", "u").LeftJoin("user_detail", "ud", "ud.uid=u.uid")
  175. func (d *CustCustomerDao) LeftJoin(table ...string) *CustCustomerDao {
  176. return &CustCustomerDao{M: d.M.LeftJoin(table...)}
  177. }
  178. // RightJoin does "RIGHT JOIN ... ON ..." statement on the model.
  179. // The parameter <table> can be joined table and its joined condition,
  180. // and also with its alias name, like:
  181. // Table("user").RightJoin("user_detail", "user_detail.uid=user.uid")
  182. // Table("user", "u").RightJoin("user_detail", "ud", "ud.uid=u.uid")
  183. func (d *CustCustomerDao) RightJoin(table ...string) *CustCustomerDao {
  184. return &CustCustomerDao{M: d.M.RightJoin(table...)}
  185. }
  186. // InnerJoin does "INNER JOIN ... ON ..." statement on the model.
  187. // The parameter <table> can be joined table and its joined condition,
  188. // and also with its alias name, like:
  189. // Table("user").InnerJoin("user_detail", "user_detail.uid=user.uid")
  190. // Table("user", "u").InnerJoin("user_detail", "ud", "ud.uid=u.uid")
  191. func (d *CustCustomerDao) InnerJoin(table ...string) *CustCustomerDao {
  192. return &CustCustomerDao{M: d.M.InnerJoin(table...)}
  193. }
  194. // Fields sets the operation fields of the model, multiple fields joined using char ','.
  195. // The parameter <fieldNamesOrMapStruct> can be type of string/map/*map/struct/*struct.
  196. func (d *CustCustomerDao) Fields(fieldNamesOrMapStruct ...interface{}) *CustCustomerDao {
  197. return &CustCustomerDao{M: d.M.Fields(fieldNamesOrMapStruct...)}
  198. }
  199. // FieldsEx sets the excluded operation fields of the model, multiple fields joined using char ','.
  200. // The parameter <fieldNamesOrMapStruct> can be type of string/map/*map/struct/*struct.
  201. func (d *CustCustomerDao) FieldsEx(fieldNamesOrMapStruct ...interface{}) *CustCustomerDao {
  202. return &CustCustomerDao{M: d.M.FieldsEx(fieldNamesOrMapStruct...)}
  203. }
  204. // Option sets the extra operation option for the model.
  205. func (d *CustCustomerDao) Option(option int) *CustCustomerDao {
  206. return &CustCustomerDao{M: d.M.Option(option)}
  207. }
  208. // OmitEmpty sets OPTION_OMITEMPTY option for the model, which automatically filers
  209. // the data and where attributes for empty values.
  210. func (d *CustCustomerDao) OmitEmpty() *CustCustomerDao {
  211. return &CustCustomerDao{M: d.M.OmitEmpty()}
  212. }
  213. // Filter marks filtering the fields which does not exist in the fields of the operated table.
  214. func (d *CustCustomerDao) Filter() *CustCustomerDao {
  215. return &CustCustomerDao{M: d.M.Filter()}
  216. }
  217. // Where sets the condition statement for the model. The parameter <where> can be type of
  218. // string/map/gmap/slice/struct/*struct, etc. Note that, if it's called more than one times,
  219. // multiple conditions will be joined into where statement using "AND".
  220. // Eg:
  221. // Where("uid=10000")
  222. // Where("uid", 10000)
  223. // Where("money>? AND name like ?", 99999, "vip_%")
  224. // Where("uid", 1).Where("name", "john")
  225. // Where("status IN (?)", g.Slice{1,2,3})
  226. // Where("age IN(?,?)", 18, 50)
  227. // Where(User{ Id : 1, UserName : "john"})
  228. func (d *CustCustomerDao) Where(where interface{}, args ...interface{}) *CustCustomerDao {
  229. return &CustCustomerDao{M: d.M.Where(where, args...)}
  230. }
  231. // WherePri does the same logic as M.Where except that if the parameter <where>
  232. // is a single condition like int/string/float/slice, it treats the condition as the primary
  233. // key value. That is, if primary key is "id" and given <where> parameter as "123", the
  234. // WherePri function treats the condition as "id=123", but M.Where treats the condition
  235. // as string "123".
  236. func (d *CustCustomerDao) WherePri(where interface{}, args ...interface{}) *CustCustomerDao {
  237. return &CustCustomerDao{M: d.M.WherePri(where, args...)}
  238. }
  239. // And adds "AND" condition to the where statement.
  240. func (d *CustCustomerDao) And(where interface{}, args ...interface{}) *CustCustomerDao {
  241. return &CustCustomerDao{M: d.M.And(where, args...)}
  242. }
  243. // Or adds "OR" condition to the where statement.
  244. func (d *CustCustomerDao) Or(where interface{}, args ...interface{}) *CustCustomerDao {
  245. return &CustCustomerDao{M: d.M.Or(where, args...)}
  246. }
  247. // Group sets the "GROUP BY" statement for the model.
  248. func (d *CustCustomerDao) Group(groupBy string) *CustCustomerDao {
  249. return &CustCustomerDao{M: d.M.Group(groupBy)}
  250. }
  251. // Order sets the "ORDER BY" statement for the model.
  252. func (d *CustCustomerDao) Order(orderBy ...string) *CustCustomerDao {
  253. return &CustCustomerDao{M: d.M.Order(orderBy...)}
  254. }
  255. // Limit sets the "LIMIT" statement for the model.
  256. // The parameter <limit> can be either one or two number, if passed two number is passed,
  257. // it then sets "LIMIT limit[0],limit[1]" statement for the model, or else it sets "LIMIT limit[0]"
  258. // statement.
  259. func (d *CustCustomerDao) Limit(limit ...int) *CustCustomerDao {
  260. return &CustCustomerDao{M: d.M.Limit(limit...)}
  261. }
  262. // Offset sets the "OFFSET" statement for the model.
  263. // It only makes sense for some databases like SQLServer, PostgreSQL, etc.
  264. func (d *CustCustomerDao) Offset(offset int) *CustCustomerDao {
  265. return &CustCustomerDao{M: d.M.Offset(offset)}
  266. }
  267. // Page sets the paging number for the model.
  268. // The parameter <page> is started from 1 for paging.
  269. // Note that, it differs that the Limit function start from 0 for "LIMIT" statement.
  270. func (d *CustCustomerDao) Page(page, limit int) *CustCustomerDao {
  271. return &CustCustomerDao{M: d.M.Page(page, limit)}
  272. }
  273. // Batch sets the batch operation number for the model.
  274. func (d *CustCustomerDao) Batch(batch int) *CustCustomerDao {
  275. return &CustCustomerDao{M: d.M.Batch(batch)}
  276. }
  277. // Cache sets the cache feature for the model. It caches the result of the sql, which means
  278. // if there's another same sql request, it just reads and returns the result from cache, it
  279. // but not committed and executed into the database.
  280. //
  281. // If the parameter <duration> < 0, which means it clear the cache with given <name>.
  282. // If the parameter <duration> = 0, which means it never expires.
  283. // If the parameter <duration> > 0, which means it expires after <duration>.
  284. //
  285. // The optional parameter <name> is used to bind a name to the cache, which means you can later
  286. // control the cache like changing the <duration> or clearing the cache with specified <name>.
  287. //
  288. // Note that, the cache feature is disabled if the model is operating on a transaction.
  289. func (d *CustCustomerDao) Cache(duration time.Duration, name ...string) *CustCustomerDao {
  290. return &CustCustomerDao{M: d.M.Cache(duration, name...)}
  291. }
  292. // Data sets the operation data for the model.
  293. // The parameter <data> can be type of string/map/gmap/slice/struct/*struct, etc.
  294. // Eg:
  295. // Data("uid=10000")
  296. // Data("uid", 10000)
  297. // Data(g.Map{"uid": 10000, "name":"john"})
  298. // Data(g.Slice{g.Map{"uid": 10000, "name":"john"}, g.Map{"uid": 20000, "name":"smith"})
  299. func (d *CustCustomerDao) Data(data ...interface{}) *CustCustomerDao {
  300. return &CustCustomerDao{M: d.M.Data(data...)}
  301. }
  302. // All does "SELECT FROM ..." statement for the model.
  303. // It retrieves the records from table and returns the result as []*model.CustCustomer.
  304. // It returns nil if there's no record retrieved with the given conditions from table.
  305. //
  306. // The optional parameter <where> is the same as the parameter of M.Where function,
  307. // see M.Where.
  308. func (d *CustCustomerDao) All(where ...interface{}) ([]*model.CustCustomer, error) {
  309. all, err := d.M.All(where...)
  310. if err != nil {
  311. return nil, err
  312. }
  313. var entities []*model.CustCustomer
  314. if err = all.Structs(&entities); err != nil && err != sql.ErrNoRows {
  315. return nil, err
  316. }
  317. return entities, nil
  318. }
  319. // One retrieves one record from table and returns the result as *model.CustCustomer.
  320. // It returns nil if there's no record retrieved with the given conditions from table.
  321. //
  322. // The optional parameter <where> is the same as the parameter of M.Where function,
  323. // see M.Where.
  324. func (d *CustCustomerDao) One(where ...interface{}) (*model.CustCustomer, error) {
  325. one, err := d.M.One(where...)
  326. if err != nil {
  327. return nil, err
  328. }
  329. var entity *model.CustCustomer
  330. if err = one.Struct(&entity); err != nil && err != sql.ErrNoRows {
  331. return nil, err
  332. }
  333. return entity, nil
  334. }
  335. // FindOne retrieves and returns a single Record by M.WherePri and M.One.
  336. // Also see M.WherePri and M.One.
  337. func (d *CustCustomerDao) FindOne(where ...interface{}) (*model.CustCustomer, error) {
  338. one, err := d.M.FindOne(where...)
  339. if err != nil {
  340. return nil, err
  341. }
  342. var entity *model.CustCustomer
  343. if err = one.Struct(&entity); err != nil && err != sql.ErrNoRows {
  344. return nil, err
  345. }
  346. return entity, nil
  347. }
  348. // FindAll retrieves and returns Result by by M.WherePri and M.All.
  349. // Also see M.WherePri and M.All.
  350. func (d *CustCustomerDao) FindAll(where ...interface{}) ([]*model.CustCustomer, error) {
  351. all, err := d.M.FindAll(where...)
  352. if err != nil {
  353. return nil, err
  354. }
  355. var entities []*model.CustCustomer
  356. if err = all.Structs(&entities); err != nil && err != sql.ErrNoRows {
  357. return nil, err
  358. }
  359. return entities, nil
  360. }
  361. // Struct retrieves one record from table and converts it into given struct.
  362. // The parameter <pointer> should be type of *struct/**struct. If type **struct is given,
  363. // it can create the struct internally during converting.
  364. //
  365. // The optional parameter <where> is the same as the parameter of Model.Where function,
  366. // see Model.Where.
  367. //
  368. // Note that it returns sql.ErrNoRows if there's no record retrieved with the given conditions
  369. // from table and <pointer> is not nil.
  370. //
  371. // Eg:
  372. // user := new(User)
  373. // err := dao.User.Where("id", 1).Struct(user)
  374. //
  375. // user := (*User)(nil)
  376. // err := dao.User.Where("id", 1).Struct(&user)
  377. func (d *CustCustomerDao) Struct(pointer interface{}, where ...interface{}) error {
  378. return d.M.Struct(pointer, where...)
  379. }
  380. // Structs retrieves records from table and converts them into given struct slice.
  381. // The parameter <pointer> should be type of *[]struct/*[]*struct. It can create and fill the struct
  382. // slice internally during converting.
  383. //
  384. // The optional parameter <where> is the same as the parameter of Model.Where function,
  385. // see Model.Where.
  386. //
  387. // Note that it returns sql.ErrNoRows if there's no record retrieved with the given conditions
  388. // from table and <pointer> is not empty.
  389. //
  390. // Eg:
  391. // users := ([]User)(nil)
  392. // err := dao.User.Structs(&users)
  393. //
  394. // users := ([]*User)(nil)
  395. // err := dao.User.Structs(&users)
  396. func (d *CustCustomerDao) Structs(pointer interface{}, where ...interface{}) error {
  397. return d.M.Structs(pointer, where...)
  398. }
  399. // Scan automatically calls Struct or Structs function according to the type of parameter <pointer>.
  400. // It calls function Struct if <pointer> is type of *struct/**struct.
  401. // It calls function Structs if <pointer> is type of *[]struct/*[]*struct.
  402. //
  403. // The optional parameter <where> is the same as the parameter of Model.Where function,
  404. // see Model.Where.
  405. //
  406. // Note that it returns sql.ErrNoRows if there's no record retrieved and given pointer is not empty or nil.
  407. //
  408. // Eg:
  409. // user := new(User)
  410. // err := dao.User.Where("id", 1).Scan(user)
  411. //
  412. // user := (*User)(nil)
  413. // err := dao.User.Where("id", 1).Scan(&user)
  414. //
  415. // users := ([]User)(nil)
  416. // err := dao.User.Scan(&users)
  417. //
  418. // users := ([]*User)(nil)
  419. // err := dao.User.Scan(&users)
  420. func (d *CustCustomerDao) Scan(pointer interface{}, where ...interface{}) error {
  421. return d.M.Scan(pointer, where...)
  422. }
  423. // Chunk iterates the table with given size and callback function.
  424. func (d *CustCustomerDao) Chunk(limit int, callback func(entities []*model.CustCustomer, err error) bool) {
  425. d.M.Chunk(limit, func(result gdb.Result, err error) bool {
  426. var entities []*model.CustCustomer
  427. err = result.Structs(&entities)
  428. if err == sql.ErrNoRows {
  429. return false
  430. }
  431. return callback(entities, err)
  432. })
  433. }
  434. // LockUpdate sets the lock for update for current operation.
  435. func (d *CustCustomerDao) LockUpdate() *CustCustomerDao {
  436. return &CustCustomerDao{M: d.M.LockUpdate()}
  437. }
  438. // LockShared sets the lock in share mode for current operation.
  439. func (d *CustCustomerDao) LockShared() *CustCustomerDao {
  440. return &CustCustomerDao{M: d.M.LockShared()}
  441. }
  442. // Unscoped enables/disables the soft deleting feature.
  443. func (d *CustCustomerDao) Unscoped() *CustCustomerDao {
  444. return &CustCustomerDao{M: d.M.Unscoped()}
  445. }