* feat: support product yarn batches * feat: improve product yarn ratio workflow * Potential fix for pull request finding Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> * Potential fix for pull request finding Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> * Potential fix for pull request finding Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> * Potential fix for pull request finding Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> --------- Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
101 lines
3.6 KiB
Go
101 lines
3.6 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 (
|
|
invYarnFieldNames = builder.RawFieldNames(&InvYarn{})
|
|
invYarnRows = strings.Join(invYarnFieldNames, ",")
|
|
invYarnRowsExpectAutoSet = strings.Join(stringx.Remove(invYarnFieldNames, "`id`", "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), ",")
|
|
invYarnRowsWithPlaceHolder = strings.Join(stringx.Remove(invYarnFieldNames, "`id`", "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), "=?,") + "=?"
|
|
)
|
|
|
|
type (
|
|
invYarnModel interface {
|
|
Insert(ctx context.Context, data *InvYarn) (sql.Result, error)
|
|
FindOne(ctx context.Context, id int64) (*InvYarn, error)
|
|
FindOneByYarnId(ctx context.Context, yarnId string) (*InvYarn, error)
|
|
Update(ctx context.Context, data *InvYarn) error
|
|
Delete(ctx context.Context, id int64) error
|
|
}
|
|
|
|
defaultInvYarnModel struct {
|
|
conn sqlx.SqlConn
|
|
table string
|
|
}
|
|
|
|
InvYarn struct {
|
|
Id int64 `db:"id"`
|
|
YarnId string `db:"yarn_id"`
|
|
TenantId string `db:"tenant_id"`
|
|
YarnName string `db:"yarn_name"`
|
|
Color string `db:"color"`
|
|
WeightGM float64 `db:"weight_g_m"`
|
|
SupplierId string `db:"supplier_id"`
|
|
DyeFactory string `db:"dye_factory"`
|
|
ImageUrl string `db:"image_url"`
|
|
Remark sql.NullString `db:"remark"`
|
|
Status int64 `db:"status"`
|
|
CreatedAt time.Time `db:"created_at"`
|
|
UpdatedAt time.Time `db:"updated_at"`
|
|
DeletedAt sql.NullTime `db:"deleted_at"`
|
|
}
|
|
)
|
|
|
|
func newInvYarnModel(conn sqlx.SqlConn) *defaultInvYarnModel {
|
|
return &defaultInvYarnModel{
|
|
conn: conn,
|
|
table: "`inv_yarn`",
|
|
}
|
|
}
|
|
|
|
func (m *defaultInvYarnModel) Insert(ctx context.Context, data *InvYarn) (sql.Result, error) {
|
|
query := fmt.Sprintf("INSERT INTO %s (%s) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", m.table, invYarnRowsExpectAutoSet)
|
|
return m.conn.ExecCtx(ctx, query, data.YarnId, data.TenantId, data.YarnName, data.Color, data.WeightGM, data.SupplierId, data.DyeFactory, data.ImageUrl, data.Remark, data.Status, data.DeletedAt)
|
|
}
|
|
|
|
func (m *defaultInvYarnModel) FindOne(ctx context.Context, id int64) (*InvYarn, error) {
|
|
query := fmt.Sprintf("SELECT %s FROM %s WHERE `id` = ? LIMIT 1", invYarnRows, m.table)
|
|
var resp InvYarn
|
|
err := m.conn.QueryRowCtx(ctx, &resp, query, id)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return &resp, nil
|
|
}
|
|
|
|
func (m *defaultInvYarnModel) FindOneByYarnId(ctx context.Context, yarnId string) (*InvYarn, error) {
|
|
query := fmt.Sprintf("SELECT %s FROM %s WHERE `yarn_id` = ? AND `deleted_at` IS NULL LIMIT 1", invYarnRows, m.table)
|
|
var resp InvYarn
|
|
err := m.conn.QueryRowCtx(ctx, &resp, query, yarnId)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return &resp, nil
|
|
}
|
|
|
|
func (m *defaultInvYarnModel) Update(ctx context.Context, data *InvYarn) error {
|
|
query := fmt.Sprintf("UPDATE %s SET %s WHERE `id` = ?", m.table, invYarnRowsWithPlaceHolder)
|
|
_, err := m.conn.ExecCtx(ctx, query, data.YarnId, data.TenantId, data.YarnName, data.Color, data.WeightGM, data.SupplierId, data.DyeFactory, data.ImageUrl, data.Remark, data.Status, data.DeletedAt, data.Id)
|
|
return err
|
|
}
|
|
|
|
func (m *defaultInvYarnModel) 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 *defaultInvYarnModel) tableName() string {
|
|
return m.table
|
|
}
|