This commit is contained in:
2025-12-09 18:55:28 +08:00
parent 8d00d67540
commit c23ab8338b
209 changed files with 5445 additions and 3963 deletions

View File

@@ -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 (
agentRealNameFieldNames = builder.RawFieldNames(&AgentRealName{})
agentRealNameRows = strings.Join(agentRealNameFieldNames, ",")
agentRealNameRowsExpectAutoSet = strings.Join(stringx.Remove(agentRealNameFieldNames, "`id`", "`create_time`", "`update_time`"), ",")
agentRealNameRowsExpectAutoSet = strings.Join(stringx.Remove(agentRealNameFieldNames, "`create_time`", "`update_time`"), ",")
agentRealNameRowsWithPlaceHolder = strings.Join(stringx.Remove(agentRealNameFieldNames, "`id`", "`create_time`", "`update_time`"), "=?,") + "=?"
cacheYccAgentRealNameIdPrefix = "cache:ycc:agentRealName:id:"
@@ -33,8 +35,8 @@ var (
type (
agentRealNameModel interface {
Insert(ctx context.Context, session sqlx.Session, data *AgentRealName) (sql.Result, error)
FindOne(ctx context.Context, id int64) (*AgentRealName, error)
FindOneByAgentId(ctx context.Context, agentId int64) (*AgentRealName, error)
FindOne(ctx context.Context, id string) (*AgentRealName, error)
FindOneByAgentId(ctx context.Context, agentId string) (*AgentRealName, error)
Update(ctx context.Context, session sqlx.Session, data *AgentRealName) (sql.Result, error)
UpdateWithVersion(ctx context.Context, session sqlx.Session, data *AgentRealName) error
Trans(ctx context.Context, fn func(context context.Context, session sqlx.Session) error) error
@@ -47,7 +49,7 @@ type (
FindPageListByPageWithTotal(ctx context.Context, rowBuilder squirrel.SelectBuilder, page, pageSize int64, orderBy string) ([]*AgentRealName, int64, error)
FindPageListByIdDESC(ctx context.Context, rowBuilder squirrel.SelectBuilder, preMinId, pageSize int64) ([]*AgentRealName, error)
FindPageListByIdASC(ctx context.Context, rowBuilder squirrel.SelectBuilder, preMaxId, pageSize int64) ([]*AgentRealName, error)
Delete(ctx context.Context, session sqlx.Session, id int64) error
Delete(ctx context.Context, session sqlx.Session, id string) error
}
defaultAgentRealNameModel struct {
@@ -56,8 +58,8 @@ type (
}
AgentRealName struct {
Id int64 `db:"id"` // 主键ID
AgentId int64 `db:"agent_id"` // 代理ID
Id string `db:"id"`
AgentId string `db:"agent_id"`
Name string `db:"name"` // 真实姓名
IdCard string `db:"id_card"` // 身份证号(加密)
Mobile string `db:"mobile"` // 手机号(加密)
@@ -79,18 +81,35 @@ func newAgentRealNameModel(conn sqlx.SqlConn, c cache.CacheConf) *defaultAgentRe
func (m *defaultAgentRealNameModel) Insert(ctx context.Context, session sqlx.Session, data *AgentRealName) (sql.Result, error) {
data.DelState = globalkey.DelStateNo
m.insertUUID(data)
yccAgentRealNameAgentIdKey := fmt.Sprintf("%s%v", cacheYccAgentRealNameAgentIdPrefix, data.AgentId)
yccAgentRealNameIdKey := fmt.Sprintf("%s%v", cacheYccAgentRealNameIdPrefix, 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, agentRealNameRowsExpectAutoSet)
query := fmt.Sprintf("insert into %s (%s) values (?, ?, ?, ?, ?, ?, ?, ?, ?)", m.table, agentRealNameRowsExpectAutoSet)
if session != nil {
return session.ExecCtx(ctx, query, data.AgentId, data.Name, data.IdCard, data.Mobile, data.VerifyTime, data.DeleteTime, data.DelState, data.Version)
return session.ExecCtx(ctx, query, data.Id, data.AgentId, data.Name, data.IdCard, data.Mobile, data.VerifyTime, data.DeleteTime, data.DelState, data.Version)
}
return conn.ExecCtx(ctx, query, data.AgentId, data.Name, data.IdCard, data.Mobile, data.VerifyTime, data.DeleteTime, data.DelState, data.Version)
return conn.ExecCtx(ctx, query, data.Id, data.AgentId, data.Name, data.IdCard, data.Mobile, data.VerifyTime, data.DeleteTime, data.DelState, data.Version)
}, yccAgentRealNameAgentIdKey, yccAgentRealNameIdKey)
}
func (m *defaultAgentRealNameModel) insertUUID(data *AgentRealName) {
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 *defaultAgentRealNameModel) FindOne(ctx context.Context, id int64) (*AgentRealName, error) {
func (m *defaultAgentRealNameModel) FindOne(ctx context.Context, id string) (*AgentRealName, error) {
yccAgentRealNameIdKey := fmt.Sprintf("%s%v", cacheYccAgentRealNameIdPrefix, id)
var resp AgentRealName
err := m.QueryRowCtx(ctx, &resp, yccAgentRealNameIdKey, func(ctx context.Context, conn sqlx.SqlConn, v interface{}) error {
@@ -107,7 +126,7 @@ func (m *defaultAgentRealNameModel) FindOne(ctx context.Context, id int64) (*Age
}
}
func (m *defaultAgentRealNameModel) FindOneByAgentId(ctx context.Context, agentId int64) (*AgentRealName, error) {
func (m *defaultAgentRealNameModel) FindOneByAgentId(ctx context.Context, agentId string) (*AgentRealName, error) {
yccAgentRealNameAgentIdKey := fmt.Sprintf("%s%v", cacheYccAgentRealNameAgentIdPrefix, agentId)
var resp AgentRealName
err := m.QueryRowIndexCtx(ctx, &resp, yccAgentRealNameAgentIdKey, m.formatPrimary, func(ctx context.Context, conn sqlx.SqlConn, v interface{}) (i interface{}, e error) {
@@ -380,7 +399,7 @@ func (m *defaultAgentRealNameModel) Trans(ctx context.Context, fn func(ctx conte
func (m *defaultAgentRealNameModel) SelectBuilder() squirrel.SelectBuilder {
return squirrel.Select().From(m.table)
}
func (m *defaultAgentRealNameModel) Delete(ctx context.Context, session sqlx.Session, id int64) error {
func (m *defaultAgentRealNameModel) Delete(ctx context.Context, session sqlx.Session, id string) error {
data, err := m.FindOne(ctx, id)
if err != nil {
return err