i2bill_acquirer_student_model.go 4.3 KB

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