cust_customer.go 17 KB

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