From c76c976cc84dc97fc88fdc23348a5aaf81796eda Mon Sep 17 00:00:00 2001 From: huang <1724659546@qq.com> Date: Sun, 5 Oct 2025 22:09:25 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B9=B0=E5=8D=96=E7=8C=AA=E8=AE=B0=E5=BD=95?= =?UTF-8?q?=E8=A1=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/infra/database/postgres.go | 4 +++ internal/infra/models/models.go | 4 +++ internal/infra/models/pig_buy_sell.go | 41 +++++++++++++++++++++++++++ 3 files changed, 49 insertions(+) create mode 100644 internal/infra/models/pig_buy_sell.go diff --git a/internal/infra/database/postgres.go b/internal/infra/database/postgres.go index 5f213d0..dff2280 100644 --- a/internal/infra/database/postgres.go +++ b/internal/infra/database/postgres.go @@ -169,6 +169,8 @@ func (ps *PostgresStorage) creatingHyperTable() error { {models.WeighingRecord{}, "weighing_time"}, {models.PigTransferLog{}, "transfer_time"}, {models.PigBatchSickPigLog{}, "happened_at"}, + {models.PigPurchase{}, "purchase_date"}, + {models.PigSale{}, "sale_date"}, } for _, table := range tablesToConvert { @@ -207,6 +209,8 @@ func (ps *PostgresStorage) applyCompressionPolicies() error { {models.WeighingRecord{}, "weighing_batch_id"}, {models.PigTransferLog{}, "pig_batch_id"}, {models.PigBatchSickPigLog{}, "pig_batch_id"}, + {models.PigPurchase{}, "pig_batch_id"}, + {models.PigSale{}, "pig_batch_id"}, } for _, policy := range policies { diff --git a/internal/infra/models/models.go b/internal/infra/models/models.go index 6f10dbc..38a319f 100644 --- a/internal/infra/models/models.go +++ b/internal/infra/models/models.go @@ -44,6 +44,10 @@ func GetAllModels() []interface{} { &PigTransferLog{}, &PigBatchSickPigLog{}, + // Pig Buy & Sell + &PigPurchase{}, + &PigSale{}, + // Feed Models &RawMaterial{}, &RawMaterialPurchase{}, diff --git a/internal/infra/models/pig_buy_sell.go b/internal/infra/models/pig_buy_sell.go new file mode 100644 index 0000000..4d4e835 --- /dev/null +++ b/internal/infra/models/pig_buy_sell.go @@ -0,0 +1,41 @@ +package models + +import ( + "time" + + "gorm.io/gorm" +) + +// PigPurchase 记录了猪只采购信息 +type PigPurchase struct { + gorm.Model + PigBatchID uint `gorm:"not null;index;comment:关联的猪批次ID"` + PurchaseDate time.Time `gorm:"primaryKey;comment:采购日期"` + Supplier string `gorm:"comment:供应商"` + Quantity int `gorm:"not null;comment:采购数量"` + UnitPrice float64 `gorm:"not null;comment:单价"` + TotalPrice float64 `gorm:"not null;comment:总价"` + Remarks string `gorm:"size:255;comment:备注"` + OperatorID uint `gorm:"comment:操作员ID"` +} + +func (PigPurchase) TableName() string { + return "pig_purchases" +} + +// PigSale 记录了猪只销售信息 +type PigSale struct { + gorm.Model + PigBatchID uint `gorm:"not null;index;comment:关联的猪批次ID"` + SaleDate time.Time `gorm:"primaryKey;comment:销售日期"` + Buyer string `gorm:"comment:购买方"` + Quantity int `gorm:"not null;comment:销售数量"` + UnitPrice float64 `gorm:"not null;comment:单价"` + TotalPrice float64 `gorm:"not null;comment:总价"` + Remarks string `gorm:"size:255;comment:备注"` + OperatorID uint `gorm:"comment:操作员ID"` +} + +func (PigSale) TableName() string { + return "pig_sales" +}