Align origin/main with upstream/main (GitHub). The two branches diverged due to pre-rebase vs post-rebase merge commits for the k8s-amd64-dockerfiles feature. Includes: multi-stage Go compilation Dockerfiles, pan-bolt inventory features, CRM relations, Excel import tooling, proto/gRPC updates, migration scripts, and tools/ directory. Excludes deploy/bin/ pre-compiled binaries (arm64, not needed for amd64 K3s cluster; builds use multi-stage Dockerfiles now).
96 lines
3.3 KiB
Go
96 lines
3.3 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 (
|
|
invProductPanFieldNames = builder.RawFieldNames(&InvProductPan{})
|
|
invProductPanRows = strings.Join(invProductPanFieldNames, ",")
|
|
invProductPanRowsExpectAutoSet = strings.Join(stringx.Remove(invProductPanFieldNames, "`id`", "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), ",")
|
|
invProductPanRowsWithPlaceHolder = strings.Join(stringx.Remove(invProductPanFieldNames, "`id`", "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), "=?,") + "=?"
|
|
)
|
|
|
|
type (
|
|
invProductPanModel interface {
|
|
Insert(ctx context.Context, data *InvProductPan) (sql.Result, error)
|
|
FindOne(ctx context.Context, id int64) (*InvProductPan, error)
|
|
FindOneByPanId(ctx context.Context, panId string) (*InvProductPan, error)
|
|
Update(ctx context.Context, data *InvProductPan) error
|
|
Delete(ctx context.Context, id int64) error
|
|
}
|
|
|
|
defaultInvProductPanModel struct {
|
|
conn sqlx.SqlConn
|
|
table string
|
|
}
|
|
|
|
InvProductPan struct {
|
|
Id int64 `db:"id"`
|
|
PanId string `db:"pan_id"`
|
|
ProductId string `db:"product_id"`
|
|
Name string `db:"name"`
|
|
Position string `db:"position"`
|
|
SortOrder int64 `db:"sort_order"`
|
|
TenantId string `db:"tenant_id"`
|
|
CreatedAt time.Time `db:"created_at"`
|
|
UpdatedAt time.Time `db:"updated_at"`
|
|
}
|
|
)
|
|
|
|
func newInvProductPanModel(conn sqlx.SqlConn) *defaultInvProductPanModel {
|
|
return &defaultInvProductPanModel{
|
|
conn: conn,
|
|
table: "`inv_product_pan`",
|
|
}
|
|
}
|
|
|
|
func (m *defaultInvProductPanModel) Insert(ctx context.Context, data *InvProductPan) (sql.Result, error) {
|
|
query := fmt.Sprintf("INSERT INTO %s (%s) VALUES (?, ?, ?, ?, ?, ?)", m.table, invProductPanRowsExpectAutoSet)
|
|
return m.conn.ExecCtx(ctx, query, data.PanId, data.ProductId, data.Name, data.Position, data.SortOrder, data.TenantId)
|
|
}
|
|
|
|
func (m *defaultInvProductPanModel) FindOne(ctx context.Context, id int64) (*InvProductPan, error) {
|
|
query := fmt.Sprintf("SELECT %s FROM %s WHERE `id` = ? LIMIT 1", invProductPanRows, m.table)
|
|
var resp InvProductPan
|
|
err := m.conn.QueryRowCtx(ctx, &resp, query, id)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return &resp, nil
|
|
}
|
|
|
|
func (m *defaultInvProductPanModel) FindOneByPanId(ctx context.Context, panId string) (*InvProductPan, error) {
|
|
query := fmt.Sprintf("SELECT %s FROM %s WHERE `pan_id` = ? LIMIT 1", invProductPanRows, m.table)
|
|
var resp InvProductPan
|
|
err := m.conn.QueryRowCtx(ctx, &resp, query, panId)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return &resp, nil
|
|
}
|
|
|
|
func (m *defaultInvProductPanModel) Update(ctx context.Context, data *InvProductPan) error {
|
|
query := fmt.Sprintf("UPDATE %s SET %s WHERE `id` = ?", m.table, invProductPanRowsWithPlaceHolder)
|
|
_, err := m.conn.ExecCtx(ctx, query, data.PanId, data.ProductId, data.Name, data.Position, data.SortOrder, data.TenantId, data.Id)
|
|
return err
|
|
}
|
|
|
|
func (m *defaultInvProductPanModel) 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 *defaultInvProductPanModel) tableName() string {
|
|
return m.table
|
|
}
|