i2bill_mkt_part_time_user_model.go 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. package model
  2. import (
  3. "database/sql"
  4. "fmt"
  5. "strings"
  6. "time"
  7. "github.com/xormplus/xorm"
  8. "git.i2edu.net/i2/go-zero/core/stores/sqlc"
  9. "git.i2edu.net/i2/go-zero/core/stores/sqlx"
  10. "git.i2edu.net/i2/go-zero/core/stringx"
  11. "git.i2edu.net/i2/go-zero/tools/goctl/model/sql/builderx"
  12. )
  13. var (
  14. i2billMktPartTimeUserFieldNames = builderx.RawFieldNames(&I2billMktPartTimeUser{})
  15. i2billMktPartTimeUserRows = strings.Join(i2billMktPartTimeUserFieldNames, ",")
  16. i2billMktPartTimeUserRowsExpectAutoSet = strings.Join(stringx.Remove(i2billMktPartTimeUserFieldNames, "`id`", "`create_time`", "`update_time`"), ",")
  17. i2billMktPartTimeUserRowsWithPlaceHolder = strings.Join(stringx.Remove(i2billMktPartTimeUserFieldNames, "`id`", "`create_time`", "`update_time`"), "=?,") + "=?"
  18. )
  19. type (
  20. I2billMktPartTimeUserModel interface {
  21. Insert(data I2billMktPartTimeUser) (sql.Result, error)
  22. FindOne(id int64) (*I2billMktPartTimeUser, error)
  23. Update(data I2billMktPartTimeUser) error
  24. Delete(id int64) error
  25. }
  26. defaultI2billMktPartTimeUserModel struct {
  27. conn sqlx.SqlConn
  28. table string
  29. }
  30. I2billMktPartTimeUser struct {
  31. CheckDesc string `db:"check_desc" json:"check_desc"` // 审核失败描述
  32. UserId int64 `db:"user_id" json:"user_id"` // user_id
  33. DelFlag int64 `db:"del_flag" json:"del_flag"`
  34. Name string `db:"name" json:"name"`
  35. Sex int64 `db:"sex" json:"sex"`
  36. CheckState int64 `db:"check_state" json:"check_state"` // 审核状态
  37. CreateTime time.Time `db:"create_time" json:"create_time"`
  38. LastUpdateTime time.Time `db:"last_update_time" json:"last_update_time"`
  39. LastUpdateBy string `db:"last_update_by" json:"last_update_by"`
  40. Id int64 `db:"id" json:"id"`
  41. IponeNumber string `db:"ipone_number" json:"ipone_number"`
  42. Target int64 `db:"target" json:"target"` // 目标人数
  43. MkId string `db:"mk_id" json:"mk_id"` // 所属erp mk id
  44. CityId int64 `db:"city_id" json:"city_id"` // 城市
  45. CreateBy string `db:"create_by" json:"create_by"`
  46. }
  47. I2billMktPartTimeXorm struct {
  48. CheckDesc string `db:"check_desc" json:"check_desc"` // 审核失败描述
  49. UserId int64 `db:"user_id" json:"user_id"` // user_id
  50. DelFlag int64 `db:"del_flag" json:"del_flag"`
  51. Name string `db:"name" json:"name"`
  52. Sex int64 `db:"sex" json:"sex"`
  53. CheckState int64 `db:"check_state" json:"check_state"` // 审核状态
  54. CreateTime time.Time `db:"create_time" json:"create_time"`
  55. LastUpdateTime time.Time `db:"last_update_time" json:"last_update_time"`
  56. LastUpdateBy string `db:"last_update_by" json:"last_update_by"`
  57. Id int64 `db:"id" json:"id"`
  58. IponeNumber string `db:"ipone_number" json:"ipone_number"`
  59. Target int64 `db:"target" json:"target"` // 目标人数
  60. MkId string `db:"mk_id" json:"mk_id"` // 所属erp mk id
  61. CityId int64 `db:"city_id" json:"city_id"` // 城市
  62. CreateBy string `db:"create_by" json:"create_by"`
  63. }
  64. )
  65. func NewI2billMktPartTimeUserModel(conn sqlx.SqlConn) I2billMktPartTimeUserModel {
  66. return &defaultI2billMktPartTimeUserModel{
  67. conn: conn,
  68. table: "`i2bill_mkt_part_time_user`",
  69. }
  70. }
  71. func (t *I2billMktPartTimeXorm) TableName() string {
  72. return "i2bill_mkt_part_time_user"
  73. }
  74. func (m *defaultI2billMktPartTimeUserModel) Insert(data I2billMktPartTimeUser) (sql.Result, error) {
  75. query := fmt.Sprintf("insert into %s (%s) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", m.table, i2billMktPartTimeUserRowsExpectAutoSet)
  76. ret, err := m.conn.Exec(query, data.CheckDesc, data.UserId, data.DelFlag, data.Name, data.Sex, data.CheckState, data.LastUpdateTime, data.LastUpdateBy, data.IponeNumber, data.Target, data.MkId, data.CityId, data.CreateBy)
  77. return ret, err
  78. }
  79. func (m *defaultI2billMktPartTimeUserModel) FindOne(id int64) (*I2billMktPartTimeUser, error) {
  80. query := fmt.Sprintf("select %s from %s where `id` = ? limit 1", i2billMktPartTimeUserRows, m.table)
  81. var resp I2billMktPartTimeUser
  82. err := m.conn.QueryRow(&resp, query, id)
  83. switch err {
  84. case nil:
  85. return &resp, nil
  86. case sqlc.ErrNotFound:
  87. return nil, ErrNotFound
  88. default:
  89. return nil, err
  90. }
  91. }
  92. func (m *defaultI2billMktPartTimeUserModel) Update(data I2billMktPartTimeUser) error {
  93. query := fmt.Sprintf("update %s set %s where `id` = ?", m.table, i2billMktPartTimeUserRowsWithPlaceHolder)
  94. _, err := m.conn.Exec(query, data.CheckDesc, data.UserId, data.DelFlag, data.Name, data.Sex, data.CheckState, data.LastUpdateTime, data.LastUpdateBy, data.IponeNumber, data.Target, data.MkId, data.CityId, data.CreateBy, data.Id)
  95. return err
  96. }
  97. func (m *defaultI2billMktPartTimeUserModel) Delete(id int64) error {
  98. query := fmt.Sprintf("delete from %s where `id` = ?", m.table)
  99. _, err := m.conn.Exec(query, id)
  100. return err
  101. }
  102. func GetPartTimeXormByUserId(userId int64, engine *xorm.Engine) (*I2billMktPartTimeXorm, error) {
  103. partUser := new(I2billMktPartTimeXorm)
  104. _, err := engine.SQL("select * from i2bill_mkt_part_time_user where del_flag = 0 and check_state = 57 and user_id = ?", userId).Get(partUser)
  105. if err != nil {
  106. return nil, err
  107. }
  108. return partUser, nil
  109. }