v1.1
This commit is contained in:
@@ -8,9 +8,11 @@ import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"reflect"
|
||||
"time"
|
||||
|
||||
"github.com/Masterminds/squirrel"
|
||||
"github.com/google/uuid"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/zeromicro/go-zero/core/stores/builder"
|
||||
"github.com/zeromicro/go-zero/core/stores/cache"
|
||||
@@ -23,7 +25,7 @@ import (
|
||||
var (
|
||||
agentWithdrawalTaxFieldNames = builder.RawFieldNames(&AgentWithdrawalTax{})
|
||||
agentWithdrawalTaxRows = strings.Join(agentWithdrawalTaxFieldNames, ",")
|
||||
agentWithdrawalTaxRowsExpectAutoSet = strings.Join(stringx.Remove(agentWithdrawalTaxFieldNames, "`id`", "`create_time`", "`update_time`"), ",")
|
||||
agentWithdrawalTaxRowsExpectAutoSet = strings.Join(stringx.Remove(agentWithdrawalTaxFieldNames, "`create_time`", "`update_time`"), ",")
|
||||
agentWithdrawalTaxRowsWithPlaceHolder = strings.Join(stringx.Remove(agentWithdrawalTaxFieldNames, "`id`", "`create_time`", "`update_time`"), "=?,") + "=?"
|
||||
|
||||
cacheYccAgentWithdrawalTaxIdPrefix = "cache:ycc:agentWithdrawalTax:id:"
|
||||
@@ -32,7 +34,7 @@ var (
|
||||
type (
|
||||
agentWithdrawalTaxModel interface {
|
||||
Insert(ctx context.Context, session sqlx.Session, data *AgentWithdrawalTax) (sql.Result, error)
|
||||
FindOne(ctx context.Context, id int64) (*AgentWithdrawalTax, error)
|
||||
FindOne(ctx context.Context, id string) (*AgentWithdrawalTax, error)
|
||||
Update(ctx context.Context, session sqlx.Session, data *AgentWithdrawalTax) (sql.Result, error)
|
||||
UpdateWithVersion(ctx context.Context, session sqlx.Session, data *AgentWithdrawalTax) error
|
||||
Trans(ctx context.Context, fn func(context context.Context, session sqlx.Session) error) error
|
||||
@@ -45,7 +47,7 @@ type (
|
||||
FindPageListByPageWithTotal(ctx context.Context, rowBuilder squirrel.SelectBuilder, page, pageSize int64, orderBy string) ([]*AgentWithdrawalTax, int64, error)
|
||||
FindPageListByIdDESC(ctx context.Context, rowBuilder squirrel.SelectBuilder, preMinId, pageSize int64) ([]*AgentWithdrawalTax, error)
|
||||
FindPageListByIdASC(ctx context.Context, rowBuilder squirrel.SelectBuilder, preMaxId, pageSize int64) ([]*AgentWithdrawalTax, error)
|
||||
Delete(ctx context.Context, session sqlx.Session, id int64) error
|
||||
Delete(ctx context.Context, session sqlx.Session, id string) error
|
||||
}
|
||||
|
||||
defaultAgentWithdrawalTaxModel struct {
|
||||
@@ -54,9 +56,9 @@ type (
|
||||
}
|
||||
|
||||
AgentWithdrawalTax struct {
|
||||
Id int64 `db:"id"` // 主键ID
|
||||
AgentId int64 `db:"agent_id"` // 代理ID
|
||||
WithdrawalId int64 `db:"withdrawal_id"` // 提现记录ID
|
||||
Id string `db:"id"`
|
||||
AgentId string `db:"agent_id"`
|
||||
WithdrawalId string `db:"withdrawal_id"`
|
||||
YearMonth int64 `db:"year_month"` // 年月(格式:YYYYMM)
|
||||
WithdrawalAmount float64 `db:"withdrawal_amount"` // 提现金额
|
||||
TaxableAmount float64 `db:"taxable_amount"` // 应税金额
|
||||
@@ -83,17 +85,34 @@ func newAgentWithdrawalTaxModel(conn sqlx.SqlConn, c cache.CacheConf) *defaultAg
|
||||
|
||||
func (m *defaultAgentWithdrawalTaxModel) Insert(ctx context.Context, session sqlx.Session, data *AgentWithdrawalTax) (sql.Result, error) {
|
||||
data.DelState = globalkey.DelStateNo
|
||||
m.insertUUID(data)
|
||||
yccAgentWithdrawalTaxIdKey := fmt.Sprintf("%s%v", cacheYccAgentWithdrawalTaxIdPrefix, data.Id)
|
||||
return m.ExecCtx(ctx, func(ctx context.Context, conn sqlx.SqlConn) (result sql.Result, err error) {
|
||||
query := fmt.Sprintf("insert into %s (%s) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", m.table, agentWithdrawalTaxRowsExpectAutoSet)
|
||||
query := fmt.Sprintf("insert into %s (%s) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", m.table, agentWithdrawalTaxRowsExpectAutoSet)
|
||||
if session != nil {
|
||||
return session.ExecCtx(ctx, query, data.AgentId, data.WithdrawalId, data.YearMonth, data.WithdrawalAmount, data.TaxableAmount, data.TaxRate, data.TaxAmount, data.ActualAmount, data.TaxStatus, data.TaxTime, data.Remark, data.DeleteTime, data.DelState, data.Version)
|
||||
return session.ExecCtx(ctx, query, data.Id, data.AgentId, data.WithdrawalId, data.YearMonth, data.WithdrawalAmount, data.TaxableAmount, data.TaxRate, data.TaxAmount, data.ActualAmount, data.TaxStatus, data.TaxTime, data.Remark, data.DeleteTime, data.DelState, data.Version)
|
||||
}
|
||||
return conn.ExecCtx(ctx, query, data.AgentId, data.WithdrawalId, data.YearMonth, data.WithdrawalAmount, data.TaxableAmount, data.TaxRate, data.TaxAmount, data.ActualAmount, data.TaxStatus, data.TaxTime, data.Remark, data.DeleteTime, data.DelState, data.Version)
|
||||
return conn.ExecCtx(ctx, query, data.Id, data.AgentId, data.WithdrawalId, data.YearMonth, data.WithdrawalAmount, data.TaxableAmount, data.TaxRate, data.TaxAmount, data.ActualAmount, data.TaxStatus, data.TaxTime, data.Remark, data.DeleteTime, data.DelState, data.Version)
|
||||
}, yccAgentWithdrawalTaxIdKey)
|
||||
}
|
||||
func (m *defaultAgentWithdrawalTaxModel) insertUUID(data *AgentWithdrawalTax) {
|
||||
t := reflect.TypeOf(data).Elem()
|
||||
v := reflect.ValueOf(data).Elem()
|
||||
for i := 0; i < t.NumField(); i++ {
|
||||
sf := t.Field(i)
|
||||
if sf.Tag.Get("db") == "id" {
|
||||
f := v.Field(i)
|
||||
if f.IsValid() && f.CanSet() && f.Kind() == reflect.String {
|
||||
if f.String() == "" {
|
||||
f.SetString(uuid.NewString())
|
||||
}
|
||||
}
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (m *defaultAgentWithdrawalTaxModel) FindOne(ctx context.Context, id int64) (*AgentWithdrawalTax, error) {
|
||||
func (m *defaultAgentWithdrawalTaxModel) FindOne(ctx context.Context, id string) (*AgentWithdrawalTax, error) {
|
||||
yccAgentWithdrawalTaxIdKey := fmt.Sprintf("%s%v", cacheYccAgentWithdrawalTaxIdPrefix, id)
|
||||
var resp AgentWithdrawalTax
|
||||
err := m.QueryRowCtx(ctx, &resp, yccAgentWithdrawalTaxIdKey, func(ctx context.Context, conn sqlx.SqlConn, v interface{}) error {
|
||||
@@ -353,7 +372,7 @@ func (m *defaultAgentWithdrawalTaxModel) Trans(ctx context.Context, fn func(ctx
|
||||
func (m *defaultAgentWithdrawalTaxModel) SelectBuilder() squirrel.SelectBuilder {
|
||||
return squirrel.Select().From(m.table)
|
||||
}
|
||||
func (m *defaultAgentWithdrawalTaxModel) Delete(ctx context.Context, session sqlx.Session, id int64) error {
|
||||
func (m *defaultAgentWithdrawalTaxModel) Delete(ctx context.Context, session sqlx.Session, id string) error {
|
||||
yccAgentWithdrawalTaxIdKey := fmt.Sprintf("%s%v", cacheYccAgentWithdrawalTaxIdPrefix, id)
|
||||
_, err := m.ExecCtx(ctx, func(ctx context.Context, conn sqlx.SqlConn) (result sql.Result, err error) {
|
||||
query := fmt.Sprintf("delete from %s where `id` = ?", m.table)
|
||||
|
||||
Reference in New Issue
Block a user