70 lines
2.2 KiB
Go
70 lines
2.2 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 (
|
||
|
|
proPlanProcessStepFieldNames = builder.RawFieldNames(&ProPlanProcessStep{})
|
||
|
|
proPlanProcessStepRows = strings.Join(proPlanProcessStepFieldNames, ",")
|
||
|
|
proPlanProcessStepRowsExpectAutoSet = strings.Join(stringx.Remove(proPlanProcessStepFieldNames, "`id`", "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), ",")
|
||
|
|
)
|
||
|
|
|
||
|
|
type (
|
||
|
|
proPlanProcessStepModel interface {
|
||
|
|
Insert(ctx context.Context, data *ProPlanProcessStep) (sql.Result, error)
|
||
|
|
Delete(ctx context.Context, id int64) error
|
||
|
|
}
|
||
|
|
|
||
|
|
defaultProPlanProcessStepModel struct {
|
||
|
|
conn sqlx.SqlConn
|
||
|
|
table string
|
||
|
|
}
|
||
|
|
|
||
|
|
ProPlanProcessStep struct {
|
||
|
|
Id int64 `db:"id"`
|
||
|
|
StepId string `db:"step_id"`
|
||
|
|
PlanId string `db:"plan_id"`
|
||
|
|
StepType string `db:"step_type"`
|
||
|
|
StepOrder int64 `db:"step_order"`
|
||
|
|
Status int64 `db:"status"`
|
||
|
|
OperatorId string `db:"operator_id"`
|
||
|
|
CompletedAt sql.NullTime `db:"completed_at"`
|
||
|
|
Remark sql.NullString `db:"remark"`
|
||
|
|
CreatedAt time.Time `db:"created_at"`
|
||
|
|
UpdatedAt time.Time `db:"updated_at"`
|
||
|
|
}
|
||
|
|
)
|
||
|
|
|
||
|
|
func newProPlanProcessStepModel(conn sqlx.SqlConn) *defaultProPlanProcessStepModel {
|
||
|
|
return &defaultProPlanProcessStepModel{
|
||
|
|
conn: conn,
|
||
|
|
table: "`pro_plan_process_step`",
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
func (m *defaultProPlanProcessStepModel) Insert(ctx context.Context, data *ProPlanProcessStep) (sql.Result, error) {
|
||
|
|
query := fmt.Sprintf("INSERT INTO %s (%s) VALUES (?, ?, ?, ?, ?, ?, ?, ?)", m.table, proPlanProcessStepRowsExpectAutoSet)
|
||
|
|
return m.conn.ExecCtx(ctx, query,
|
||
|
|
data.StepId, data.PlanId, data.StepType, data.StepOrder, data.Status,
|
||
|
|
data.OperatorId, data.CompletedAt, data.Remark)
|
||
|
|
}
|
||
|
|
|
||
|
|
func (m *defaultProPlanProcessStepModel) 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
|
||
|
|
}
|
||
|
|
|
||
|
|
func (m *defaultProPlanProcessStepModel) tableName() string {
|
||
|
|
return m.table
|
||
|
|
}
|