66 lines
2.0 KiB
Go
66 lines
2.0 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 (
|
||
|
|
proPlanYarnRatioFieldNames = builder.RawFieldNames(&ProPlanYarnRatio{})
|
||
|
|
proPlanYarnRatioRows = strings.Join(proPlanYarnRatioFieldNames, ",")
|
||
|
|
proPlanYarnRatioRowsExpectAutoSet = strings.Join(stringx.Remove(proPlanYarnRatioFieldNames, "`id`", "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), ",")
|
||
|
|
)
|
||
|
|
|
||
|
|
type (
|
||
|
|
proPlanYarnRatioModel interface {
|
||
|
|
Insert(ctx context.Context, data *ProPlanYarnRatio) (sql.Result, error)
|
||
|
|
Delete(ctx context.Context, id int64) error
|
||
|
|
}
|
||
|
|
|
||
|
|
defaultProPlanYarnRatioModel struct {
|
||
|
|
conn sqlx.SqlConn
|
||
|
|
table string
|
||
|
|
}
|
||
|
|
|
||
|
|
ProPlanYarnRatio struct {
|
||
|
|
Id int64 `db:"id"`
|
||
|
|
RatioId string `db:"ratio_id"`
|
||
|
|
PlanId string `db:"plan_id"`
|
||
|
|
YarnName string `db:"yarn_name"`
|
||
|
|
Ratio float64 `db:"ratio"`
|
||
|
|
AmountPerMeter float64 `db:"amount_per_meter"`
|
||
|
|
TotalAmount float64 `db:"total_amount"`
|
||
|
|
CreatedAt time.Time `db:"created_at"`
|
||
|
|
}
|
||
|
|
)
|
||
|
|
|
||
|
|
func newProPlanYarnRatioModel(conn sqlx.SqlConn) *defaultProPlanYarnRatioModel {
|
||
|
|
return &defaultProPlanYarnRatioModel{
|
||
|
|
conn: conn,
|
||
|
|
table: "`pro_plan_yarn_ratio`",
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
func (m *defaultProPlanYarnRatioModel) Insert(ctx context.Context, data *ProPlanYarnRatio) (sql.Result, error) {
|
||
|
|
query := fmt.Sprintf("INSERT INTO %s (%s) VALUES (?, ?, ?, ?, ?, ?)", m.table, proPlanYarnRatioRowsExpectAutoSet)
|
||
|
|
return m.conn.ExecCtx(ctx, query,
|
||
|
|
data.RatioId, data.PlanId, data.YarnName, data.Ratio, data.AmountPerMeter, data.TotalAmount)
|
||
|
|
}
|
||
|
|
|
||
|
|
func (m *defaultProPlanYarnRatioModel) 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 *defaultProPlanYarnRatioModel) tableName() string {
|
||
|
|
return m.table
|
||
|
|
}
|