完善任务接口逻辑以及Eran事件上报接入
This commit is contained in:
@@ -14,7 +14,7 @@ type (
|
||||
// and implement the added methods in customNhTaskAssetModel.
|
||||
NhTaskAssetModel interface {
|
||||
nhTaskAssetModel
|
||||
withSession(session sqlx.Session) NhTaskAssetModel
|
||||
WithSession(session sqlx.Session) NhTaskAssetModel
|
||||
AddUserPoint(ctx context.Context, uid int, points int) error
|
||||
}
|
||||
|
||||
@@ -30,7 +30,7 @@ func NewNhTaskAssetModel(conn sqlx.SqlConn) NhTaskAssetModel {
|
||||
}
|
||||
}
|
||||
|
||||
func (m *customNhTaskAssetModel) withSession(session sqlx.Session) NhTaskAssetModel {
|
||||
func (m *customNhTaskAssetModel) WithSession(session sqlx.Session) NhTaskAssetModel {
|
||||
return NewNhTaskAssetModel(sqlx.NewSqlConnFromSession(session))
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,13 @@
|
||||
package model
|
||||
|
||||
import "github.com/zeromicro/go-zero/core/stores/sqlx"
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"fmt"
|
||||
"github.com/zeromicro/go-zero/core/stores/sqlx"
|
||||
"github.com/zeromicro/go-zero/core/stringx"
|
||||
"strings"
|
||||
)
|
||||
|
||||
var _ NhTaskAssetRecordModel = (*customNhTaskAssetRecordModel)(nil)
|
||||
|
||||
@@ -27,3 +34,10 @@ func NewNhTaskAssetRecordModel(conn sqlx.SqlConn) NhTaskAssetRecordModel {
|
||||
func (m *customNhTaskAssetRecordModel) withSession(session sqlx.Session) NhTaskAssetRecordModel {
|
||||
return NewNhTaskAssetRecordModel(sqlx.NewSqlConnFromSession(session))
|
||||
}
|
||||
|
||||
func (m *customNhTaskAssetRecordModel) Insert(ctx context.Context, data *NhTaskAssetRecord) (sql.Result, error) {
|
||||
rows := strings.Join(stringx.Remove(nhTaskAssetRecordFieldNames, "`id`"), ",")
|
||||
query := fmt.Sprintf("insert into %s (%s) values (?, ?, ?, ?, ?, ?, ?)", m.table, rows)
|
||||
ret, err := m.conn.ExecCtx(ctx, query, data.Uid, data.EventId, data.AssetField, data.Count, data.Remark, data.ProvideUid, data.CreateTime)
|
||||
return ret, err
|
||||
}
|
||||
|
||||
@@ -38,7 +38,7 @@ type (
|
||||
)
|
||||
|
||||
func (m *customNhTaskModel) FindTasksByCommunity(ctx context.Context, communityId uint) ([]*NhTask, error) {
|
||||
query := fmt.Sprintf("select %s from %s where community_id = ?", nhTaskRows, m.table)
|
||||
query := fmt.Sprintf("select %s from %s where community_id = 0 or community_id = ?", nhTaskRows, m.table)
|
||||
var tasks []*NhTask
|
||||
err := m.conn.QueryRowsCtx(ctx, &tasks, query, communityId)
|
||||
if err != nil && !errors.Is(err, sqlx.ErrNotFound) {
|
||||
|
||||
@@ -17,7 +17,7 @@ type (
|
||||
// and implement the added methods in customNhTaskProgressModel.
|
||||
NhTaskProgressModel interface {
|
||||
nhTaskProgressModel
|
||||
withSession(session sqlx.Session) NhTaskProgressModel
|
||||
WithSession(session sqlx.Session) NhTaskProgressModel
|
||||
}
|
||||
|
||||
customNhTaskProgressModel struct {
|
||||
@@ -32,6 +32,6 @@ func NewNhTaskProgressModel(conn sqlx.SqlConn) NhTaskProgressModel {
|
||||
}
|
||||
}
|
||||
|
||||
func (m *customNhTaskProgressModel) withSession(session sqlx.Session) NhTaskProgressModel {
|
||||
func (m *customNhTaskProgressModel) WithSession(session sqlx.Session) NhTaskProgressModel {
|
||||
return NewNhTaskProgressModel(sqlx.NewSqlConnFromSession(session))
|
||||
}
|
||||
|
||||
29
internal/model/nh_twitter_model.go
Executable file
29
internal/model/nh_twitter_model.go
Executable file
@@ -0,0 +1,29 @@
|
||||
package model
|
||||
|
||||
import "github.com/zeromicro/go-zero/core/stores/sqlx"
|
||||
|
||||
var _ NhTwitterModel = (*customNhTwitterModel)(nil)
|
||||
|
||||
type (
|
||||
// NhTwitterModel is an interface to be customized, add more methods here,
|
||||
// and implement the added methods in customNhTwitterModel.
|
||||
NhTwitterModel interface {
|
||||
nhTwitterModel
|
||||
withSession(session sqlx.Session) NhTwitterModel
|
||||
}
|
||||
|
||||
customNhTwitterModel struct {
|
||||
*defaultNhTwitterModel
|
||||
}
|
||||
)
|
||||
|
||||
// NewNhTwitterModel returns a model for the database table.
|
||||
func NewNhTwitterModel(conn sqlx.SqlConn) NhTwitterModel {
|
||||
return &customNhTwitterModel{
|
||||
defaultNhTwitterModel: newNhTwitterModel(conn),
|
||||
}
|
||||
}
|
||||
|
||||
func (m *customNhTwitterModel) withSession(session sqlx.Session) NhTwitterModel {
|
||||
return NewNhTwitterModel(sqlx.NewSqlConnFromSession(session))
|
||||
}
|
||||
121
internal/model/nh_twitter_model_gen.go
Executable file
121
internal/model/nh_twitter_model_gen.go
Executable file
@@ -0,0 +1,121 @@
|
||||
// Code generated by goctl. DO NOT EDIT.
|
||||
// versions:
|
||||
// goctl version: 1.7.3
|
||||
|
||||
package model
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"fmt"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/stores/builder"
|
||||
"github.com/zeromicro/go-zero/core/stores/sqlx"
|
||||
"github.com/zeromicro/go-zero/core/stringx"
|
||||
)
|
||||
|
||||
var (
|
||||
nhTwitterFieldNames = builder.RawFieldNames(&NhTwitter{})
|
||||
nhTwitterRows = strings.Join(nhTwitterFieldNames, ",")
|
||||
nhTwitterRowsExpectAutoSet = strings.Join(stringx.Remove(nhTwitterFieldNames, "`id`", "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), ",")
|
||||
nhTwitterRowsWithPlaceHolder = strings.Join(stringx.Remove(nhTwitterFieldNames, "`id`", "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), "=?,") + "=?"
|
||||
)
|
||||
|
||||
type (
|
||||
nhTwitterModel interface {
|
||||
Insert(ctx context.Context, data *NhTwitter) (sql.Result, error)
|
||||
FindOne(ctx context.Context, id uint) (*NhTwitter, error)
|
||||
FindOneByTwitterId(ctx context.Context, twitterId string) (*NhTwitter, error)
|
||||
FindOneByUid(ctx context.Context, uid uint) (*NhTwitter, error)
|
||||
Update(ctx context.Context, data *NhTwitter) error
|
||||
Delete(ctx context.Context, id uint) error
|
||||
}
|
||||
|
||||
defaultNhTwitterModel struct {
|
||||
conn sqlx.SqlConn
|
||||
table string
|
||||
}
|
||||
|
||||
NhTwitter struct {
|
||||
Id uint `db:"id"`
|
||||
Uid uint `db:"uid"` // 用户ID
|
||||
TwitterId string `db:"twitter_id"` // twitter_id
|
||||
Name string `db:"name"` // name
|
||||
Username string `db:"username"` // username
|
||||
CreatedAt time.Time `db:"created_at"` // 创建时间
|
||||
UpdatedAt time.Time `db:"updated_at"` // 修改时间
|
||||
}
|
||||
)
|
||||
|
||||
func newNhTwitterModel(conn sqlx.SqlConn) *defaultNhTwitterModel {
|
||||
return &defaultNhTwitterModel{
|
||||
conn: conn,
|
||||
table: "`nh_twitter`",
|
||||
}
|
||||
}
|
||||
|
||||
func (m *defaultNhTwitterModel) Delete(ctx context.Context, id uint) error {
|
||||
query := fmt.Sprintf("delete from %s where `id` = ?", m.table)
|
||||
_, err := m.conn.ExecCtx(ctx, query, id)
|
||||
return err
|
||||
}
|
||||
|
||||
func (m *defaultNhTwitterModel) FindOne(ctx context.Context, id uint) (*NhTwitter, error) {
|
||||
query := fmt.Sprintf("select %s from %s where `id` = ? limit 1", nhTwitterRows, m.table)
|
||||
var resp NhTwitter
|
||||
err := m.conn.QueryRowCtx(ctx, &resp, query, id)
|
||||
switch err {
|
||||
case nil:
|
||||
return &resp, nil
|
||||
case sqlx.ErrNotFound:
|
||||
return nil, ErrNotFound
|
||||
default:
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
func (m *defaultNhTwitterModel) FindOneByTwitterId(ctx context.Context, twitterId string) (*NhTwitter, error) {
|
||||
var resp NhTwitter
|
||||
query := fmt.Sprintf("select %s from %s where `twitter_id` = ? limit 1", nhTwitterRows, m.table)
|
||||
err := m.conn.QueryRowCtx(ctx, &resp, query, twitterId)
|
||||
switch err {
|
||||
case nil:
|
||||
return &resp, nil
|
||||
case sqlx.ErrNotFound:
|
||||
return nil, ErrNotFound
|
||||
default:
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
func (m *defaultNhTwitterModel) FindOneByUid(ctx context.Context, uid uint) (*NhTwitter, error) {
|
||||
var resp NhTwitter
|
||||
query := fmt.Sprintf("select %s from %s where `uid` = ? limit 1", nhTwitterRows, m.table)
|
||||
err := m.conn.QueryRowCtx(ctx, &resp, query, uid)
|
||||
switch err {
|
||||
case nil:
|
||||
return &resp, nil
|
||||
case sqlx.ErrNotFound:
|
||||
return nil, ErrNotFound
|
||||
default:
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
func (m *defaultNhTwitterModel) Insert(ctx context.Context, data *NhTwitter) (sql.Result, error) {
|
||||
query := fmt.Sprintf("insert into %s (%s) values (?, ?, ?, ?)", m.table, nhTwitterRowsExpectAutoSet)
|
||||
ret, err := m.conn.ExecCtx(ctx, query, data.Uid, data.TwitterId, data.Name, data.Username)
|
||||
return ret, err
|
||||
}
|
||||
|
||||
func (m *defaultNhTwitterModel) Update(ctx context.Context, newData *NhTwitter) error {
|
||||
query := fmt.Sprintf("update %s set %s where `id` = ?", m.table, nhTwitterRowsWithPlaceHolder)
|
||||
_, err := m.conn.ExecCtx(ctx, query, newData.Uid, newData.TwitterId, newData.Name, newData.Username, newData.Id)
|
||||
return err
|
||||
}
|
||||
|
||||
func (m *defaultNhTwitterModel) tableName() string {
|
||||
return m.table
|
||||
}
|
||||
Reference in New Issue
Block a user