71 lines
2.4 KiB
Go
71 lines
2.4 KiB
Go
|
|
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 (
|
||
|
|
proShareLinkFieldNames = builder.RawFieldNames(&ProShareLink{})
|
||
|
|
proShareLinkRows = strings.Join(proShareLinkFieldNames, ",")
|
||
|
|
proShareLinkRowsExpectAutoSet = strings.Join(stringx.Remove(proShareLinkFieldNames, "`id`", "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), ",")
|
||
|
|
)
|
||
|
|
|
||
|
|
type (
|
||
|
|
proShareLinkModel interface {
|
||
|
|
Insert(ctx context.Context, data *ProShareLink) (sql.Result, error)
|
||
|
|
Delete(ctx context.Context, id int64) error
|
||
|
|
}
|
||
|
|
|
||
|
|
defaultProShareLinkModel struct {
|
||
|
|
conn sqlx.SqlConn
|
||
|
|
table string
|
||
|
|
}
|
||
|
|
|
||
|
|
ProShareLink struct {
|
||
|
|
Id int64 `db:"id"`
|
||
|
|
LinkId string `db:"link_id"`
|
||
|
|
TenantId string `db:"tenant_id"`
|
||
|
|
PlanId string `db:"plan_id"`
|
||
|
|
ShortCode string `db:"short_code"`
|
||
|
|
Token string `db:"token"`
|
||
|
|
FactoryType string `db:"factory_type"`
|
||
|
|
HideSensitive int64 `db:"hide_sensitive"`
|
||
|
|
Status int64 `db:"status"`
|
||
|
|
ClickCount int64 `db:"click_count"`
|
||
|
|
ClickedAt sql.NullTime `db:"clicked_at"`
|
||
|
|
RespondedAt sql.NullTime `db:"responded_at"`
|
||
|
|
RejectReason string `db:"reject_reason"`
|
||
|
|
ExpiresAt time.Time `db:"expires_at"`
|
||
|
|
CreatedBy string `db:"created_by"`
|
||
|
|
CreatedAt time.Time `db:"created_at"`
|
||
|
|
UpdatedAt time.Time `db:"updated_at"`
|
||
|
|
}
|
||
|
|
)
|
||
|
|
|
||
|
|
func newProShareLinkModel(conn sqlx.SqlConn) *defaultProShareLinkModel {
|
||
|
|
return &defaultProShareLinkModel{conn: conn, table: "`pro_share_link`"}
|
||
|
|
}
|
||
|
|
|
||
|
|
func (m *defaultProShareLinkModel) Insert(ctx context.Context, data *ProShareLink) (sql.Result, error) {
|
||
|
|
query := fmt.Sprintf("INSERT INTO %s (%s) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
|
||
|
|
m.table, proShareLinkRowsExpectAutoSet)
|
||
|
|
return m.conn.ExecCtx(ctx, query, data.LinkId, data.TenantId, data.PlanId,
|
||
|
|
data.ShortCode, data.Token, data.FactoryType, data.HideSensitive,
|
||
|
|
data.Status, data.ClickCount, data.ClickedAt, data.RespondedAt,
|
||
|
|
data.RejectReason, data.ExpiresAt, data.CreatedBy)
|
||
|
|
}
|
||
|
|
|
||
|
|
func (m *defaultProShareLinkModel) Delete(ctx context.Context, id int64) error {
|
||
|
|
query := fmt.Sprintf("DELETE FROM %s WHERE `id` = ?", m.table)
|
||
|
|
_, err := m.conn.ExecCtx(ctx, query, id)
|
||
|
|
return err
|
||
|
|
}
|