Go workspace (go.work) with 5 microservices + shared library: - gateway (8080), auth-service (8081), purchaser-service (8082) - textile-service (8083), washing-service (8084) - shared: proto definitions, common packages Infrastructure: docker-compose for local dev, K8s manifests for K3s cluster deployment (mysql/redis/etcd + traefik ingress). Frontend (iloom-flatten) added as git submodule. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
60 lines
1.6 KiB
Go
60 lines
1.6 KiB
Go
package repository
|
|
|
|
import (
|
|
"context"
|
|
"database/sql"
|
|
|
|
"github.com/muyuqingfeng/iloom/textile-service/internal/model"
|
|
)
|
|
|
|
type InventoryRepo struct {
|
|
db *sql.DB
|
|
}
|
|
|
|
func NewInventoryRepo(db *sql.DB) *InventoryRepo {
|
|
return &InventoryRepo{db: db}
|
|
}
|
|
|
|
func (r *InventoryRepo) Create(ctx context.Context, rec *model.InventoryRecord) error {
|
|
query := `
|
|
INSERT INTO ilm_inventory_record
|
|
(id, plan_id, warehouse_id, quantity, rolls, price_per_meter, price_note, warehouse_location, operator_id, company_id, created_at)
|
|
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`
|
|
|
|
_, err := r.db.ExecContext(ctx, query,
|
|
rec.ID, rec.PlanID, rec.WarehouseID, rec.Quantity, rec.Rolls,
|
|
rec.PricePerMeter, rec.PriceNote, rec.WarehouseLocation,
|
|
rec.OperatorID, rec.CompanyID, rec.CreatedAt,
|
|
)
|
|
return err
|
|
}
|
|
|
|
func (r *InventoryRepo) ListByPlan(ctx context.Context, planID string) ([]model.InventoryRecord, error) {
|
|
query := `
|
|
SELECT id, plan_id, warehouse_id, quantity, rolls, price_per_meter,
|
|
price_note, warehouse_location, operator_id, company_id, created_at
|
|
FROM ilm_inventory_record
|
|
WHERE plan_id = ?
|
|
ORDER BY created_at DESC`
|
|
|
|
rows, err := r.db.QueryContext(ctx, query, planID)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
|
|
var records []model.InventoryRecord
|
|
for rows.Next() {
|
|
var r model.InventoryRecord
|
|
if err := rows.Scan(
|
|
&r.ID, &r.PlanID, &r.WarehouseID, &r.Quantity, &r.Rolls,
|
|
&r.PricePerMeter, &r.PriceNote, &r.WarehouseLocation,
|
|
&r.OperatorID, &r.CompanyID, &r.CreatedAt,
|
|
); err != nil {
|
|
return nil, err
|
|
}
|
|
records = append(records, r)
|
|
}
|
|
return records, rows.Err()
|
|
}
|