cust_customer.go 17 KB

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