fix
This commit is contained in:
470
app/main/model/complaintAlipayModel_gen.go
Normal file
470
app/main/model/complaintAlipayModel_gen.go
Normal file
@@ -0,0 +1,470 @@
|
||||
// Code generated by goctl. DO NOT EDIT!
|
||||
|
||||
package model
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"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"
|
||||
"github.com/zeromicro/go-zero/core/stores/sqlc"
|
||||
"github.com/zeromicro/go-zero/core/stores/sqlx"
|
||||
"github.com/zeromicro/go-zero/core/stringx"
|
||||
"ycc-server/common/globalkey"
|
||||
)
|
||||
|
||||
var (
|
||||
complaintAlipayFieldNames = builder.RawFieldNames(&ComplaintAlipay{})
|
||||
complaintAlipayRows = strings.Join(complaintAlipayFieldNames, ",")
|
||||
complaintAlipayRowsExpectAutoSet = strings.Join(stringx.Remove(complaintAlipayFieldNames, "`create_time`", "`update_time`"), ",")
|
||||
complaintAlipayRowsWithPlaceHolder = strings.Join(stringx.Remove(complaintAlipayFieldNames, "`id`", "`create_time`", "`update_time`"), "=?,") + "=?"
|
||||
|
||||
cacheYccComplaintAlipayIdPrefix = "cache:ycc:complaintAlipay:id:"
|
||||
cacheYccComplaintAlipayAlipayIdPrefix = "cache:ycc:complaintAlipay:alipayId:"
|
||||
cacheYccComplaintAlipayTaskIdPrefix = "cache:ycc:complaintAlipay:taskId:"
|
||||
)
|
||||
|
||||
type (
|
||||
complaintAlipayModel interface {
|
||||
Insert(ctx context.Context, session sqlx.Session, data *ComplaintAlipay) (sql.Result, error)
|
||||
FindOne(ctx context.Context, id string) (*ComplaintAlipay, error)
|
||||
FindOneByAlipayId(ctx context.Context, alipayId int64) (*ComplaintAlipay, error)
|
||||
FindOneByTaskId(ctx context.Context, taskId string) (*ComplaintAlipay, error)
|
||||
Update(ctx context.Context, session sqlx.Session, data *ComplaintAlipay) (sql.Result, error)
|
||||
UpdateWithVersion(ctx context.Context, session sqlx.Session, data *ComplaintAlipay) error
|
||||
Trans(ctx context.Context, fn func(context context.Context, session sqlx.Session) error) error
|
||||
SelectBuilder() squirrel.SelectBuilder
|
||||
DeleteSoft(ctx context.Context, session sqlx.Session, data *ComplaintAlipay) error
|
||||
FindSum(ctx context.Context, sumBuilder squirrel.SelectBuilder, field string) (float64, error)
|
||||
FindCount(ctx context.Context, countBuilder squirrel.SelectBuilder, field string) (int64, error)
|
||||
FindAll(ctx context.Context, rowBuilder squirrel.SelectBuilder, orderBy string) ([]*ComplaintAlipay, error)
|
||||
FindPageListByPage(ctx context.Context, rowBuilder squirrel.SelectBuilder, page, pageSize int64, orderBy string) ([]*ComplaintAlipay, error)
|
||||
FindPageListByPageWithTotal(ctx context.Context, rowBuilder squirrel.SelectBuilder, page, pageSize int64, orderBy string) ([]*ComplaintAlipay, int64, error)
|
||||
FindPageListByIdDESC(ctx context.Context, rowBuilder squirrel.SelectBuilder, preMinId, pageSize int64) ([]*ComplaintAlipay, error)
|
||||
FindPageListByIdASC(ctx context.Context, rowBuilder squirrel.SelectBuilder, preMaxId, pageSize int64) ([]*ComplaintAlipay, error)
|
||||
Delete(ctx context.Context, session sqlx.Session, id string) error
|
||||
}
|
||||
|
||||
defaultComplaintAlipayModel struct {
|
||||
sqlc.CachedConn
|
||||
table string
|
||||
}
|
||||
|
||||
ComplaintAlipay struct {
|
||||
Id string `db:"id"` // UUID主键
|
||||
CreateTime time.Time `db:"create_time"` // 创建时间
|
||||
UpdateTime time.Time `db:"update_time"` // 更新时间
|
||||
DeleteTime sql.NullTime `db:"delete_time"` // 删除时间
|
||||
DelState int64 `db:"del_state"` // 删除状态:0=未删除,1=已删除
|
||||
Version int64 `db:"version"` // 版本号(乐观锁)
|
||||
ComplaintId string `db:"complaint_id"` // 关联投诉主表ID(关联complaint_main.id)
|
||||
AlipayId int64 `db:"alipay_id"` // 支付宝投诉主表的主键id(支付宝返回的id)
|
||||
TaskId string `db:"task_id"` // 投诉单号id(支付宝返回的task_id,用于唯一标识)
|
||||
OppositePid sql.NullString `db:"opposite_pid"` // 被投诉人pid
|
||||
OppositeName sql.NullString `db:"opposite_name"` // 投诉单中被投诉方的名称
|
||||
ComplainAmount sql.NullFloat64 `db:"complain_amount"` // 投诉单涉及交易总金额(单位:人民币元)
|
||||
GmtComplain sql.NullTime `db:"gmt_complain"` // 投诉时间
|
||||
GmtProcess sql.NullTime `db:"gmt_process"` // 处理时间
|
||||
GmtOverdue sql.NullTime `db:"gmt_overdue"` // 过期时间
|
||||
ComplainContent sql.NullString `db:"complain_content"` // 用户投诉内容
|
||||
TradeNo sql.NullString `db:"trade_no"` // 投诉交易单号
|
||||
Status sql.NullString `db:"status"` // 投诉状态(支付宝返回的状态)
|
||||
StatusDescription sql.NullString `db:"status_description"` // 投诉单状态枚举值描述
|
||||
ProcessCode sql.NullString `db:"process_code"` // 商家处理结果码
|
||||
ProcessMessage sql.NullString `db:"process_message"` // 商家处理结果码对应描述
|
||||
ProcessRemark sql.NullString `db:"process_remark"` // 商家处理备注
|
||||
ProcessImgUrlList sql.NullString `db:"process_img_url_list"` // 商家处理备注图片url列表(JSON数组字符串)
|
||||
GmtRiskFinishTime sql.NullTime `db:"gmt_risk_finish_time"` // 推送时间
|
||||
ComplainUrl sql.NullString `db:"complain_url"` // 投诉网址
|
||||
CertifyInfo sql.NullString `db:"certify_info"` // 投诉凭证图片信息(JSON数组字符串)
|
||||
}
|
||||
)
|
||||
|
||||
func newComplaintAlipayModel(conn sqlx.SqlConn, c cache.CacheConf) *defaultComplaintAlipayModel {
|
||||
return &defaultComplaintAlipayModel{
|
||||
CachedConn: sqlc.NewConn(conn, c),
|
||||
table: "`complaint_alipay`",
|
||||
}
|
||||
}
|
||||
|
||||
func (m *defaultComplaintAlipayModel) Insert(ctx context.Context, session sqlx.Session, data *ComplaintAlipay) (sql.Result, error) {
|
||||
data.DelState = globalkey.DelStateNo
|
||||
m.insertUUID(data)
|
||||
yccComplaintAlipayAlipayIdKey := fmt.Sprintf("%s%v", cacheYccComplaintAlipayAlipayIdPrefix, data.AlipayId)
|
||||
yccComplaintAlipayIdKey := fmt.Sprintf("%s%v", cacheYccComplaintAlipayIdPrefix, data.Id)
|
||||
yccComplaintAlipayTaskIdKey := fmt.Sprintf("%s%v", cacheYccComplaintAlipayTaskIdPrefix, data.TaskId)
|
||||
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, complaintAlipayRowsExpectAutoSet)
|
||||
if session != nil {
|
||||
return session.ExecCtx(ctx, query, data.Id, data.DeleteTime, data.DelState, data.Version, data.ComplaintId, data.AlipayId, data.TaskId, data.OppositePid, data.OppositeName, data.ComplainAmount, data.GmtComplain, data.GmtProcess, data.GmtOverdue, data.ComplainContent, data.TradeNo, data.Status, data.StatusDescription, data.ProcessCode, data.ProcessMessage, data.ProcessRemark, data.ProcessImgUrlList, data.GmtRiskFinishTime, data.ComplainUrl, data.CertifyInfo)
|
||||
}
|
||||
return conn.ExecCtx(ctx, query, data.Id, data.DeleteTime, data.DelState, data.Version, data.ComplaintId, data.AlipayId, data.TaskId, data.OppositePid, data.OppositeName, data.ComplainAmount, data.GmtComplain, data.GmtProcess, data.GmtOverdue, data.ComplainContent, data.TradeNo, data.Status, data.StatusDescription, data.ProcessCode, data.ProcessMessage, data.ProcessRemark, data.ProcessImgUrlList, data.GmtRiskFinishTime, data.ComplainUrl, data.CertifyInfo)
|
||||
}, yccComplaintAlipayAlipayIdKey, yccComplaintAlipayIdKey, yccComplaintAlipayTaskIdKey)
|
||||
}
|
||||
func (m *defaultComplaintAlipayModel) insertUUID(data *ComplaintAlipay) {
|
||||
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 *defaultComplaintAlipayModel) FindOne(ctx context.Context, id string) (*ComplaintAlipay, error) {
|
||||
yccComplaintAlipayIdKey := fmt.Sprintf("%s%v", cacheYccComplaintAlipayIdPrefix, id)
|
||||
var resp ComplaintAlipay
|
||||
err := m.QueryRowCtx(ctx, &resp, yccComplaintAlipayIdKey, func(ctx context.Context, conn sqlx.SqlConn, v interface{}) error {
|
||||
query := fmt.Sprintf("select %s from %s where `id` = ? and del_state = ? limit 1", complaintAlipayRows, m.table)
|
||||
return conn.QueryRowCtx(ctx, v, query, id, globalkey.DelStateNo)
|
||||
})
|
||||
switch err {
|
||||
case nil:
|
||||
return &resp, nil
|
||||
case sqlc.ErrNotFound:
|
||||
return nil, ErrNotFound
|
||||
default:
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
func (m *defaultComplaintAlipayModel) FindOneByAlipayId(ctx context.Context, alipayId int64) (*ComplaintAlipay, error) {
|
||||
yccComplaintAlipayAlipayIdKey := fmt.Sprintf("%s%v", cacheYccComplaintAlipayAlipayIdPrefix, alipayId)
|
||||
var resp ComplaintAlipay
|
||||
err := m.QueryRowIndexCtx(ctx, &resp, yccComplaintAlipayAlipayIdKey, m.formatPrimary, func(ctx context.Context, conn sqlx.SqlConn, v interface{}) (i interface{}, e error) {
|
||||
query := fmt.Sprintf("select %s from %s where `alipay_id` = ? and del_state = ? limit 1", complaintAlipayRows, m.table)
|
||||
if err := conn.QueryRowCtx(ctx, &resp, query, alipayId, globalkey.DelStateNo); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return resp.Id, nil
|
||||
}, m.queryPrimary)
|
||||
switch err {
|
||||
case nil:
|
||||
return &resp, nil
|
||||
case sqlc.ErrNotFound:
|
||||
return nil, ErrNotFound
|
||||
default:
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
func (m *defaultComplaintAlipayModel) FindOneByTaskId(ctx context.Context, taskId string) (*ComplaintAlipay, error) {
|
||||
yccComplaintAlipayTaskIdKey := fmt.Sprintf("%s%v", cacheYccComplaintAlipayTaskIdPrefix, taskId)
|
||||
var resp ComplaintAlipay
|
||||
err := m.QueryRowIndexCtx(ctx, &resp, yccComplaintAlipayTaskIdKey, m.formatPrimary, func(ctx context.Context, conn sqlx.SqlConn, v interface{}) (i interface{}, e error) {
|
||||
query := fmt.Sprintf("select %s from %s where `task_id` = ? and del_state = ? limit 1", complaintAlipayRows, m.table)
|
||||
if err := conn.QueryRowCtx(ctx, &resp, query, taskId, globalkey.DelStateNo); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return resp.Id, nil
|
||||
}, m.queryPrimary)
|
||||
switch err {
|
||||
case nil:
|
||||
return &resp, nil
|
||||
case sqlc.ErrNotFound:
|
||||
return nil, ErrNotFound
|
||||
default:
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
func (m *defaultComplaintAlipayModel) Update(ctx context.Context, session sqlx.Session, newData *ComplaintAlipay) (sql.Result, error) {
|
||||
data, err := m.FindOne(ctx, newData.Id)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
yccComplaintAlipayAlipayIdKey := fmt.Sprintf("%s%v", cacheYccComplaintAlipayAlipayIdPrefix, data.AlipayId)
|
||||
yccComplaintAlipayIdKey := fmt.Sprintf("%s%v", cacheYccComplaintAlipayIdPrefix, data.Id)
|
||||
yccComplaintAlipayTaskIdKey := fmt.Sprintf("%s%v", cacheYccComplaintAlipayTaskIdPrefix, data.TaskId)
|
||||
return m.ExecCtx(ctx, func(ctx context.Context, conn sqlx.SqlConn) (result sql.Result, err error) {
|
||||
query := fmt.Sprintf("update %s set %s where `id` = ?", m.table, complaintAlipayRowsWithPlaceHolder)
|
||||
if session != nil {
|
||||
return session.ExecCtx(ctx, query, newData.DeleteTime, newData.DelState, newData.Version, newData.ComplaintId, newData.AlipayId, newData.TaskId, newData.OppositePid, newData.OppositeName, newData.ComplainAmount, newData.GmtComplain, newData.GmtProcess, newData.GmtOverdue, newData.ComplainContent, newData.TradeNo, newData.Status, newData.StatusDescription, newData.ProcessCode, newData.ProcessMessage, newData.ProcessRemark, newData.ProcessImgUrlList, newData.GmtRiskFinishTime, newData.ComplainUrl, newData.CertifyInfo, newData.Id)
|
||||
}
|
||||
return conn.ExecCtx(ctx, query, newData.DeleteTime, newData.DelState, newData.Version, newData.ComplaintId, newData.AlipayId, newData.TaskId, newData.OppositePid, newData.OppositeName, newData.ComplainAmount, newData.GmtComplain, newData.GmtProcess, newData.GmtOverdue, newData.ComplainContent, newData.TradeNo, newData.Status, newData.StatusDescription, newData.ProcessCode, newData.ProcessMessage, newData.ProcessRemark, newData.ProcessImgUrlList, newData.GmtRiskFinishTime, newData.ComplainUrl, newData.CertifyInfo, newData.Id)
|
||||
}, yccComplaintAlipayAlipayIdKey, yccComplaintAlipayIdKey, yccComplaintAlipayTaskIdKey)
|
||||
}
|
||||
|
||||
func (m *defaultComplaintAlipayModel) UpdateWithVersion(ctx context.Context, session sqlx.Session, newData *ComplaintAlipay) error {
|
||||
|
||||
oldVersion := newData.Version
|
||||
newData.Version += 1
|
||||
|
||||
var sqlResult sql.Result
|
||||
var err error
|
||||
|
||||
data, err := m.FindOne(ctx, newData.Id)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
yccComplaintAlipayAlipayIdKey := fmt.Sprintf("%s%v", cacheYccComplaintAlipayAlipayIdPrefix, data.AlipayId)
|
||||
yccComplaintAlipayIdKey := fmt.Sprintf("%s%v", cacheYccComplaintAlipayIdPrefix, data.Id)
|
||||
yccComplaintAlipayTaskIdKey := fmt.Sprintf("%s%v", cacheYccComplaintAlipayTaskIdPrefix, data.TaskId)
|
||||
sqlResult, err = m.ExecCtx(ctx, func(ctx context.Context, conn sqlx.SqlConn) (result sql.Result, err error) {
|
||||
query := fmt.Sprintf("update %s set %s where `id` = ? and version = ? ", m.table, complaintAlipayRowsWithPlaceHolder)
|
||||
if session != nil {
|
||||
return session.ExecCtx(ctx, query, newData.DeleteTime, newData.DelState, newData.Version, newData.ComplaintId, newData.AlipayId, newData.TaskId, newData.OppositePid, newData.OppositeName, newData.ComplainAmount, newData.GmtComplain, newData.GmtProcess, newData.GmtOverdue, newData.ComplainContent, newData.TradeNo, newData.Status, newData.StatusDescription, newData.ProcessCode, newData.ProcessMessage, newData.ProcessRemark, newData.ProcessImgUrlList, newData.GmtRiskFinishTime, newData.ComplainUrl, newData.CertifyInfo, newData.Id, oldVersion)
|
||||
}
|
||||
return conn.ExecCtx(ctx, query, newData.DeleteTime, newData.DelState, newData.Version, newData.ComplaintId, newData.AlipayId, newData.TaskId, newData.OppositePid, newData.OppositeName, newData.ComplainAmount, newData.GmtComplain, newData.GmtProcess, newData.GmtOverdue, newData.ComplainContent, newData.TradeNo, newData.Status, newData.StatusDescription, newData.ProcessCode, newData.ProcessMessage, newData.ProcessRemark, newData.ProcessImgUrlList, newData.GmtRiskFinishTime, newData.ComplainUrl, newData.CertifyInfo, newData.Id, oldVersion)
|
||||
}, yccComplaintAlipayAlipayIdKey, yccComplaintAlipayIdKey, yccComplaintAlipayTaskIdKey)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
updateCount, err := sqlResult.RowsAffected()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if updateCount == 0 {
|
||||
return ErrNoRowsUpdate
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *defaultComplaintAlipayModel) DeleteSoft(ctx context.Context, session sqlx.Session, data *ComplaintAlipay) error {
|
||||
data.DelState = globalkey.DelStateYes
|
||||
data.DeleteTime = sql.NullTime{Time: time.Now(), Valid: true}
|
||||
if err := m.UpdateWithVersion(ctx, session, data); err != nil {
|
||||
return errors.Wrapf(errors.New("delete soft failed "), "ComplaintAlipayModel delete err : %+v", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *defaultComplaintAlipayModel) FindSum(ctx context.Context, builder squirrel.SelectBuilder, field string) (float64, error) {
|
||||
|
||||
if len(field) == 0 {
|
||||
return 0, errors.Wrapf(errors.New("FindSum Least One Field"), "FindSum Least One Field")
|
||||
}
|
||||
|
||||
builder = builder.Columns("IFNULL(SUM(" + field + "),0)")
|
||||
|
||||
query, values, err := builder.Where("del_state = ?", globalkey.DelStateNo).ToSql()
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
var resp float64
|
||||
err = m.QueryRowNoCacheCtx(ctx, &resp, query, values...)
|
||||
switch err {
|
||||
case nil:
|
||||
return resp, nil
|
||||
default:
|
||||
return 0, err
|
||||
}
|
||||
}
|
||||
|
||||
func (m *defaultComplaintAlipayModel) FindCount(ctx context.Context, builder squirrel.SelectBuilder, field string) (int64, error) {
|
||||
|
||||
if len(field) == 0 {
|
||||
return 0, errors.Wrapf(errors.New("FindCount Least One Field"), "FindCount Least One Field")
|
||||
}
|
||||
|
||||
builder = builder.Columns("COUNT(" + field + ")")
|
||||
|
||||
query, values, err := builder.Where("del_state = ?", globalkey.DelStateNo).ToSql()
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
var resp int64
|
||||
err = m.QueryRowNoCacheCtx(ctx, &resp, query, values...)
|
||||
switch err {
|
||||
case nil:
|
||||
return resp, nil
|
||||
default:
|
||||
return 0, err
|
||||
}
|
||||
}
|
||||
|
||||
func (m *defaultComplaintAlipayModel) FindAll(ctx context.Context, builder squirrel.SelectBuilder, orderBy string) ([]*ComplaintAlipay, error) {
|
||||
|
||||
builder = builder.Columns(complaintAlipayRows)
|
||||
|
||||
if orderBy == "" {
|
||||
builder = builder.OrderBy("id DESC")
|
||||
} else {
|
||||
builder = builder.OrderBy(orderBy)
|
||||
}
|
||||
|
||||
query, values, err := builder.Where("del_state = ?", globalkey.DelStateNo).ToSql()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var resp []*ComplaintAlipay
|
||||
err = m.QueryRowsNoCacheCtx(ctx, &resp, query, values...)
|
||||
switch err {
|
||||
case nil:
|
||||
return resp, nil
|
||||
default:
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
func (m *defaultComplaintAlipayModel) FindPageListByPage(ctx context.Context, builder squirrel.SelectBuilder, page, pageSize int64, orderBy string) ([]*ComplaintAlipay, error) {
|
||||
|
||||
builder = builder.Columns(complaintAlipayRows)
|
||||
|
||||
if orderBy == "" {
|
||||
builder = builder.OrderBy("id DESC")
|
||||
} else {
|
||||
builder = builder.OrderBy(orderBy)
|
||||
}
|
||||
|
||||
if page < 1 {
|
||||
page = 1
|
||||
}
|
||||
offset := (page - 1) * pageSize
|
||||
|
||||
query, values, err := builder.Where("del_state = ?", globalkey.DelStateNo).Offset(uint64(offset)).Limit(uint64(pageSize)).ToSql()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var resp []*ComplaintAlipay
|
||||
err = m.QueryRowsNoCacheCtx(ctx, &resp, query, values...)
|
||||
switch err {
|
||||
case nil:
|
||||
return resp, nil
|
||||
default:
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
func (m *defaultComplaintAlipayModel) FindPageListByPageWithTotal(ctx context.Context, builder squirrel.SelectBuilder, page, pageSize int64, orderBy string) ([]*ComplaintAlipay, int64, error) {
|
||||
|
||||
total, err := m.FindCount(ctx, builder, "id")
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
|
||||
builder = builder.Columns(complaintAlipayRows)
|
||||
|
||||
if orderBy == "" {
|
||||
builder = builder.OrderBy("id DESC")
|
||||
} else {
|
||||
builder = builder.OrderBy(orderBy)
|
||||
}
|
||||
|
||||
if page < 1 {
|
||||
page = 1
|
||||
}
|
||||
offset := (page - 1) * pageSize
|
||||
|
||||
query, values, err := builder.Where("del_state = ?", globalkey.DelStateNo).Offset(uint64(offset)).Limit(uint64(pageSize)).ToSql()
|
||||
if err != nil {
|
||||
return nil, total, err
|
||||
}
|
||||
|
||||
var resp []*ComplaintAlipay
|
||||
err = m.QueryRowsNoCacheCtx(ctx, &resp, query, values...)
|
||||
switch err {
|
||||
case nil:
|
||||
return resp, total, nil
|
||||
default:
|
||||
return nil, total, err
|
||||
}
|
||||
}
|
||||
|
||||
func (m *defaultComplaintAlipayModel) FindPageListByIdDESC(ctx context.Context, builder squirrel.SelectBuilder, preMinId, pageSize int64) ([]*ComplaintAlipay, error) {
|
||||
|
||||
builder = builder.Columns(complaintAlipayRows)
|
||||
|
||||
if preMinId > 0 {
|
||||
builder = builder.Where(" id < ? ", preMinId)
|
||||
}
|
||||
|
||||
query, values, err := builder.Where("del_state = ?", globalkey.DelStateNo).OrderBy("id DESC").Limit(uint64(pageSize)).ToSql()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var resp []*ComplaintAlipay
|
||||
err = m.QueryRowsNoCacheCtx(ctx, &resp, query, values...)
|
||||
switch err {
|
||||
case nil:
|
||||
return resp, nil
|
||||
default:
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
func (m *defaultComplaintAlipayModel) FindPageListByIdASC(ctx context.Context, builder squirrel.SelectBuilder, preMaxId, pageSize int64) ([]*ComplaintAlipay, error) {
|
||||
|
||||
builder = builder.Columns(complaintAlipayRows)
|
||||
|
||||
if preMaxId > 0 {
|
||||
builder = builder.Where(" id > ? ", preMaxId)
|
||||
}
|
||||
|
||||
query, values, err := builder.Where("del_state = ?", globalkey.DelStateNo).OrderBy("id ASC").Limit(uint64(pageSize)).ToSql()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var resp []*ComplaintAlipay
|
||||
err = m.QueryRowsNoCacheCtx(ctx, &resp, query, values...)
|
||||
switch err {
|
||||
case nil:
|
||||
return resp, nil
|
||||
default:
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
func (m *defaultComplaintAlipayModel) Trans(ctx context.Context, fn func(ctx context.Context, session sqlx.Session) error) error {
|
||||
|
||||
return m.TransactCtx(ctx, func(ctx context.Context, session sqlx.Session) error {
|
||||
return fn(ctx, session)
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
func (m *defaultComplaintAlipayModel) SelectBuilder() squirrel.SelectBuilder {
|
||||
return squirrel.Select().From(m.table)
|
||||
}
|
||||
func (m *defaultComplaintAlipayModel) Delete(ctx context.Context, session sqlx.Session, id string) error {
|
||||
data, err := m.FindOne(ctx, id)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
yccComplaintAlipayAlipayIdKey := fmt.Sprintf("%s%v", cacheYccComplaintAlipayAlipayIdPrefix, data.AlipayId)
|
||||
yccComplaintAlipayIdKey := fmt.Sprintf("%s%v", cacheYccComplaintAlipayIdPrefix, id)
|
||||
yccComplaintAlipayTaskIdKey := fmt.Sprintf("%s%v", cacheYccComplaintAlipayTaskIdPrefix, data.TaskId)
|
||||
_, 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)
|
||||
if session != nil {
|
||||
return session.ExecCtx(ctx, query, id)
|
||||
}
|
||||
return conn.ExecCtx(ctx, query, id)
|
||||
}, yccComplaintAlipayAlipayIdKey, yccComplaintAlipayIdKey, yccComplaintAlipayTaskIdKey)
|
||||
return err
|
||||
}
|
||||
func (m *defaultComplaintAlipayModel) formatPrimary(primary interface{}) string {
|
||||
return fmt.Sprintf("%s%v", cacheYccComplaintAlipayIdPrefix, primary)
|
||||
}
|
||||
func (m *defaultComplaintAlipayModel) queryPrimary(ctx context.Context, conn sqlx.SqlConn, v, primary interface{}) error {
|
||||
query := fmt.Sprintf("select %s from %s where `id` = ? and del_state = ? limit 1", complaintAlipayRows, m.table)
|
||||
return conn.QueryRowCtx(ctx, v, query, primary, globalkey.DelStateNo)
|
||||
}
|
||||
|
||||
func (m *defaultComplaintAlipayModel) tableName() string {
|
||||
return m.table
|
||||
}
|
||||
Reference in New Issue
Block a user