package model import ( "database/sql" "fmt" "strings" "git.i2edu.net/i2/go-zero/core/stores/cache" "git.i2edu.net/i2/go-zero/core/stores/sqlc" "git.i2edu.net/i2/go-zero/core/stores/sqlx" "git.i2edu.net/i2/go-zero/core/stringx" "git.i2edu.net/i2/go-zero/tools/goctl/model/sql/builderx" ) var ( I2billAcquirerStudentFieldNames = builderx.RawFieldNames(&I2billAcquirerStudent{}) I2billAcquirerStudentRows = strings.Join(I2billAcquirerStudentFieldNames, ",") I2billAcquirerStudentRowsExpectAutoSet = strings.Join(stringx.Remove(I2billAcquirerStudentFieldNames, "`create_time`", "`update_time`"), ",") I2billAcquirerStudentRowsWithPlaceHolder = strings.Join(stringx.Remove(I2billAcquirerStudentFieldNames, "`id`", "`create_time`", "`update_time`"), "=?,") + "=?" cacheI2billAcquirerStudentIdPrefix = "cache:i2billAcquirerStudent:id:" ) type ( I2billAcquirerStudentModel interface { Insert(data I2billAcquirerStudent) (sql.Result, error) FindOne(id int64) (*I2billAcquirerStudent, error) Update(data I2billAcquirerStudent) error Delete(id int64) error } defaultI2billAcquirerStudentModel struct { sqlc.CachedConn table string } I2billAcquirerStudent struct { StuPhone sql.NullString `db:"stu_phone"` // 联系方式 SchId sql.NullInt64 `db:"sch_id"` // 意向校区 DelFlag sql.NullString `db:"del_flag"` CheckState sql.NullInt64 `db:"check_state"` // 收单宝状态 UserId sql.NullInt64 `db:"user_id"` // 收单宝用户id StuLinkPerson sql.NullString `db:"stu_link_person"` // 联系人 CheckTime sql.NullTime `db:"check_time"` // 审核日期 CheckBy sql.NullString `db:"check_by"` // 审核人 AgeGroup string `db:"age_group"` // 学员年龄 Address sql.NullString `db:"address"` // 当前位置 CreateTime sql.NullTime `db:"create_time"` Id int64 `db:"id"` // 主键 PartTimeUserId sql.NullInt64 `db:"part_time_user_id"` NetworkDetailId sql.NullString `db:"network_detail_id"` // 渠道 MkId sql.NullString `db:"mk_id"` // 所属mk erp id StuName sql.NullString `db:"stu_name"` // 学员名称 } ) func NewI2billAcquirerStudentModel(conn sqlx.SqlConn, c cache.CacheConf) I2billAcquirerStudentModel { return &defaultI2billAcquirerStudentModel{ CachedConn: sqlc.NewConn(conn, c), table: "`i2bill_acquirer_student`", } } func (m *defaultI2billAcquirerStudentModel) Insert(data I2billAcquirerStudent) (sql.Result, error) { query := fmt.Sprintf("insert into %s (%s) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", m.table, I2billAcquirerStudentRowsExpectAutoSet) ret, err := m.ExecNoCache(query, data.StuPhone, data.SchId, data.DelFlag, data.CheckState, data.UserId, data.StuLinkPerson, data.CheckTime, data.CheckBy, data.AgeGroup, data.Address, data.Id, data.PartTimeUserId, data.NetworkDetailId, data.MkId, data.StuName) return ret, err } func (m *defaultI2billAcquirerStudentModel) FindOne(id int64) (*I2billAcquirerStudent, error) { i2billAcquirerStudentIdKey := fmt.Sprintf("%s%v", cacheI2billAcquirerStudentIdPrefix, id) var resp I2billAcquirerStudent err := m.QueryRow(&resp, i2billAcquirerStudentIdKey, func(conn sqlx.SqlConn, v interface{}) error { query := fmt.Sprintf("select %s from %s where `id` = ? limit 1", I2billAcquirerStudentRows, m.table) return conn.QueryRow(v, query, id) }) switch err { case nil: return &resp, nil case sqlc.ErrNotFound: return nil, ErrNotFound default: return nil, err } } func (m *defaultI2billAcquirerStudentModel) Update(data I2billAcquirerStudent) error { i2billAcquirerStudentIdKey := fmt.Sprintf("%s%v", cacheI2billAcquirerStudentIdPrefix, data.Id) _, err := m.Exec(func(conn sqlx.SqlConn) (result sql.Result, err error) { query := fmt.Sprintf("update %s set %s where `id` = ?", m.table, I2billAcquirerStudentRowsWithPlaceHolder) return conn.Exec(query, data.StuPhone, data.SchId, data.DelFlag, data.CheckState, data.UserId, data.StuLinkPerson, data.CheckTime, data.CheckBy, data.AgeGroup, data.Address, data.PartTimeUserId, data.NetworkDetailId, data.MkId, data.StuName, data.Id) }, i2billAcquirerStudentIdKey) return err } func (m *defaultI2billAcquirerStudentModel) Delete(id int64) error { i2billAcquirerStudentIdKey := fmt.Sprintf("%s%v", cacheI2billAcquirerStudentIdPrefix, id) _, err := m.Exec(func(conn sqlx.SqlConn) (result sql.Result, err error) { query := fmt.Sprintf("delete from %s where `id` = ?", m.table) return conn.Exec(query, id) }, i2billAcquirerStudentIdKey) return err } func (m *defaultI2billAcquirerStudentModel) formatPrimary(primary interface{}) string { return fmt.Sprintf("%s%v", cacheI2billAcquirerStudentIdPrefix, primary) } func (m *defaultI2billAcquirerStudentModel) queryPrimary(conn sqlx.SqlConn, v, primary interface{}) error { query := fmt.Sprintf("select %s from %s where `id` = ? limit 1", I2billAcquirerStudentRows, m.table) return conn.QueryRow(v, query, primary) }