i2billacquirerstudentmodel.go 4.2 KB

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