cust_customer.go 17 KB

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