Pull latest changes from upstream/main (GitHub) including: - Purchase RPC service (proto, server, logic, models) - Gateway route updates for purchase endpoints - SQL migration and config updates Excludes deploy/bin/ pre-compiled arm64 binaries (builds use multi-stage Dockerfiles targeting amd64).
101 lines
4.1 KiB
Go
101 lines
4.1 KiB
Go
package model
|
|
|
|
import (
|
|
"context"
|
|
"database/sql"
|
|
"fmt"
|
|
"strings"
|
|
|
|
"github.com/zeromicro/go-zero/core/stores/builder"
|
|
"github.com/zeromicro/go-zero/core/stores/sqlx"
|
|
"github.com/zeromicro/go-zero/core/stringx"
|
|
)
|
|
|
|
var (
|
|
purPurchaseOrderDetailFieldNames = builder.RawFieldNames(&PurPurchaseOrderDetail{})
|
|
purPurchaseOrderDetailRows = strings.Join(purPurchaseOrderDetailFieldNames, ",")
|
|
purPurchaseOrderDetailRowsExpectAutoSet = strings.Join(stringx.Remove(purPurchaseOrderDetailFieldNames, "`id`", "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), ",")
|
|
purPurchaseOrderDetailRowsWithPlaceHolder = strings.Join(stringx.Remove(purPurchaseOrderDetailFieldNames, "`id`", "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), "=?,") + "=?"
|
|
)
|
|
|
|
type (
|
|
purPurchaseOrderDetailModel interface {
|
|
Insert(ctx context.Context, data *PurPurchaseOrderDetail) (sql.Result, error)
|
|
FindOne(ctx context.Context, id int64) (*PurPurchaseOrderDetail, error)
|
|
FindOneByDetailId(ctx context.Context, detailId string) (*PurPurchaseOrderDetail, error)
|
|
Update(ctx context.Context, data *PurPurchaseOrderDetail) error
|
|
Delete(ctx context.Context, id int64) error
|
|
}
|
|
|
|
defaultPurPurchaseOrderDetailModel struct {
|
|
conn sqlx.SqlConn
|
|
table string
|
|
}
|
|
|
|
PurPurchaseOrderDetail struct {
|
|
Id int64 `db:"id"`
|
|
DetailId string `db:"detail_id"`
|
|
TenantId string `db:"tenant_id"`
|
|
OrderId string `db:"order_id"`
|
|
ProductId string `db:"product_id"`
|
|
ProductName string `db:"product_name"`
|
|
Spec string `db:"spec"`
|
|
Color string `db:"color"`
|
|
Quantity float64 `db:"quantity"`
|
|
UnitPrice float64 `db:"unit_price"`
|
|
Amount float64 `db:"amount"`
|
|
ReceivedQty float64 `db:"received_qty"`
|
|
Remark sql.NullString `db:"remark"`
|
|
}
|
|
)
|
|
|
|
func newPurPurchaseOrderDetailModel(conn sqlx.SqlConn) *defaultPurPurchaseOrderDetailModel {
|
|
return &defaultPurPurchaseOrderDetailModel{
|
|
conn: conn,
|
|
table: "`pur_purchase_order_detail`",
|
|
}
|
|
}
|
|
|
|
func (m *defaultPurPurchaseOrderDetailModel) Insert(ctx context.Context, data *PurPurchaseOrderDetail) (sql.Result, error) {
|
|
query := fmt.Sprintf("INSERT INTO %s (%s) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", m.table, purPurchaseOrderDetailRowsExpectAutoSet)
|
|
return m.conn.ExecCtx(ctx, query,
|
|
data.DetailId, data.TenantId, data.OrderId, data.ProductId, data.ProductName, data.Spec,
|
|
data.Color, data.Quantity, data.UnitPrice, data.Amount, data.ReceivedQty, data.Remark)
|
|
}
|
|
|
|
func (m *defaultPurPurchaseOrderDetailModel) FindOne(ctx context.Context, id int64) (*PurPurchaseOrderDetail, error) {
|
|
query := fmt.Sprintf("SELECT %s FROM %s WHERE `id` = ? LIMIT 1", purPurchaseOrderDetailRows, m.table)
|
|
var resp PurPurchaseOrderDetail
|
|
if err := m.conn.QueryRowCtx(ctx, &resp, query, id); err != nil {
|
|
return nil, err
|
|
}
|
|
return &resp, nil
|
|
}
|
|
|
|
func (m *defaultPurPurchaseOrderDetailModel) FindOneByDetailId(ctx context.Context, detailId string) (*PurPurchaseOrderDetail, error) {
|
|
query := fmt.Sprintf("SELECT %s FROM %s WHERE `detail_id` = ? LIMIT 1", purPurchaseOrderDetailRows, m.table)
|
|
var resp PurPurchaseOrderDetail
|
|
if err := m.conn.QueryRowCtx(ctx, &resp, query, detailId); err != nil {
|
|
return nil, err
|
|
}
|
|
return &resp, nil
|
|
}
|
|
|
|
func (m *defaultPurPurchaseOrderDetailModel) Update(ctx context.Context, data *PurPurchaseOrderDetail) error {
|
|
query := fmt.Sprintf("UPDATE %s SET %s WHERE `id` = ?", m.table, purPurchaseOrderDetailRowsWithPlaceHolder)
|
|
_, err := m.conn.ExecCtx(ctx, query,
|
|
data.DetailId, data.TenantId, data.OrderId, data.ProductId, data.ProductName, data.Spec,
|
|
data.Color, data.Quantity, data.UnitPrice, data.Amount, data.ReceivedQty, data.Remark, data.Id)
|
|
return err
|
|
}
|
|
|
|
func (m *defaultPurPurchaseOrderDetailModel) 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 *defaultPurPurchaseOrderDetailModel) tableName() string {
|
|
return m.table
|
|
}
|