i2bill_acquirer_student_model.go 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. package model
  2. import (
  3. "database/sql"
  4. "fmt"
  5. "strings"
  6. "time"
  7. "git.i2edu.net/i2/go-zero/core/stores/sqlc"
  8. "git.i2edu.net/i2/go-zero/core/stores/sqlx"
  9. "git.i2edu.net/i2/go-zero/core/stringx"
  10. "git.i2edu.net/i2/go-zero/tools/goctl/model/sql/builderx"
  11. )
  12. var (
  13. i2billAcquirerStudentFieldNames = builderx.RawFieldNames(&I2billAcquirerStudent{})
  14. i2billAcquirerStudentRows = strings.Join(i2billAcquirerStudentFieldNames, ",")
  15. I2billAcquirerStudentRows = strings.Join(i2billAcquirerStudentFieldNames, ",")
  16. i2billAcquirerStudentRowsExpectAutoSet = strings.Join(stringx.Remove(i2billAcquirerStudentFieldNames, "`create_time`", "`update_time`"), ",")
  17. i2billAcquirerStudentRowsWithPlaceHolder = strings.Join(stringx.Remove(i2billAcquirerStudentFieldNames, "`id`", "`create_time`", "`update_time`"), "=?,") + "=?"
  18. )
  19. type (
  20. I2billAcquirerStudentModel interface {
  21. Insert(data I2billAcquirerStudent) (sql.Result, error)
  22. FindOne(id int64) (*I2billAcquirerStudent, error)
  23. Update(data I2billAcquirerStudent) error
  24. Delete(id int64) error
  25. }
  26. defaultI2billAcquirerStudentModel struct {
  27. conn sqlx.SqlConn
  28. table string
  29. }
  30. I2billAcquirerStudent struct {
  31. StuLinkPerson sql.NullString `db:"stu_link_person" json:"stu_link_person"` // 联系人
  32. StuPhone sql.NullString `db:"stu_phone" json:"stu_phone"` // 联系方式
  33. CreateTime sql.NullTime `db:"create_time" json:"create_time"`
  34. CheckTime sql.NullTime `db:"check_time" json:"check_time"` // 审核日期
  35. CheckBy sql.NullString `db:"check_by" json:"check_by"` // 审核人
  36. MkId sql.NullString `db:"mk_id" json:"mk_id"` // 所属mk erp id
  37. UserId sql.NullInt64 `db:"user_id" json:"user_id"` // 收单宝用户id
  38. Address sql.NullString `db:"address" json:"address"` // 当前位置
  39. CheckState sql.NullInt64 `db:"check_state" json:"check_state"` // 收单宝状态
  40. Id int64 `db:"id" json:"id"` // 主键
  41. PartTimeUserId sql.NullInt64 `db:"part_time_user_id" json:"part_time_user_id"`
  42. StuName sql.NullString `db:"stu_name" json:"stu_name"` // 学员名称
  43. AgeGroup int64 `db:"age_group" json:"age_group"` // 学员年龄
  44. SchId sql.NullInt64 `db:"sch_id" json:"sch_id"` // 意向校区
  45. DelFlag int64 `db:"del_flag" json:"del_flag"`
  46. NetworkDetailId sql.NullInt64 `db:"network_detail_id" json:"network_detail_id"` // 渠道
  47. ActiveId sql.NullInt64 `db:"active_id" json:"active_id"` //活动
  48. }
  49. I2billAcquirerStudentXorm struct {
  50. StuLinkPerson string `db:"stu_link_person" json:"stu_link_person"` // 联系人
  51. StuPhone string `db:"stu_phone" json:"stu_phone"` // 联系方式
  52. CreateTime time.Time `db:"create_time" json:"create_time"`
  53. CheckTime time.Time `db:"check_time" json:"check_time"` // 审核日期
  54. CheckBy string `db:"check_by" json:"check_by"` // 审核人
  55. MkId string `db:"mk_id" json:"mk_id"` // 所属mk erp id
  56. UserId int64 `db:"user_id" json:"user_id"` // 收单宝用户id
  57. Address string `db:"address" json:"address"` // 当前位置
  58. CheckState int64 `db:"check_state" json:"check_state"` // 收单宝状态
  59. Id int64 `db:"id" json:"id"` // 主键
  60. PartTimeUserId int64 `db:"part_time_user_id" json:"part_time_user_id"`
  61. StuName string `db:"stu_name" json:"stu_name"` // 学员名称
  62. AgeGroup int64 `db:"age_group" json:"age_group"` // 学员年龄
  63. SchId int64 `db:"sch_id" json:"sch_id"` // 意向校区
  64. DelFlag int64 `db:"del_flag" json:"del_flag"`
  65. NetworkDetailId int64 `db:"network_detail_id" json:"network_detail_id"` // 渠道
  66. ActiveId int64 `db:"active_id" json:"active_id"` //活动
  67. }
  68. )
  69. func (t *I2billAcquirerStudentXorm) TableName() string {
  70. return "i2bill_acquirer_student"
  71. }
  72. func NewI2billAcquirerStudentModel(conn sqlx.SqlConn) I2billAcquirerStudentModel {
  73. return &defaultI2billAcquirerStudentModel{
  74. conn: conn,
  75. table: "`i2bill_acquirer_student`",
  76. }
  77. }
  78. func (m *defaultI2billAcquirerStudentModel) Insert(data I2billAcquirerStudent) (sql.Result, error) {
  79. query := fmt.Sprintf("insert into %s (%s) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", m.table, i2billAcquirerStudentRowsExpectAutoSet)
  80. ret, err := m.conn.Exec(query, data.StuLinkPerson, data.StuPhone, data.CheckTime, data.CheckBy, data.MkId, data.UserId, data.Address, data.CheckState, data.Id, data.PartTimeUserId, data.StuName, data.AgeGroup, data.SchId, data.DelFlag, data.NetworkDetailId)
  81. return ret, err
  82. }
  83. func (m *defaultI2billAcquirerStudentModel) FindOne(id int64) (*I2billAcquirerStudent, error) {
  84. query := fmt.Sprintf("select %s from %s where `id` = ? limit 1", i2billAcquirerStudentRows, m.table)
  85. var resp I2billAcquirerStudent
  86. err := m.conn.QueryRow(&resp, query, id)
  87. switch err {
  88. case nil:
  89. return &resp, nil
  90. case sqlc.ErrNotFound:
  91. return nil, ErrNotFound
  92. default:
  93. return nil, err
  94. }
  95. }
  96. func (m *defaultI2billAcquirerStudentModel) Update(data I2billAcquirerStudent) error {
  97. query := fmt.Sprintf("update %s set %s where `id` = ?", m.table, i2billAcquirerStudentRowsWithPlaceHolder)
  98. _, err := m.conn.Exec(query, data.StuLinkPerson, data.StuPhone, data.CheckTime, data.CheckBy, data.MkId, data.UserId, data.Address, data.CheckState, data.PartTimeUserId, data.StuName, data.AgeGroup, data.SchId, data.DelFlag, data.NetworkDetailId, data.Id)
  99. return err
  100. }
  101. func (m *defaultI2billAcquirerStudentModel) Delete(id int64) error {
  102. query := fmt.Sprintf("delete from %s where `id` = ?", m.table)
  103. _, err := m.conn.Exec(query, id)
  104. return err
  105. }