买卖猪记录表

This commit is contained in:
2025-10-05 22:09:25 +08:00
parent 1652df1533
commit c76c976cc8
3 changed files with 49 additions and 0 deletions

View File

@@ -169,6 +169,8 @@ func (ps *PostgresStorage) creatingHyperTable() error {
{models.WeighingRecord{}, "weighing_time"}, {models.WeighingRecord{}, "weighing_time"},
{models.PigTransferLog{}, "transfer_time"}, {models.PigTransferLog{}, "transfer_time"},
{models.PigBatchSickPigLog{}, "happened_at"}, {models.PigBatchSickPigLog{}, "happened_at"},
{models.PigPurchase{}, "purchase_date"},
{models.PigSale{}, "sale_date"},
} }
for _, table := range tablesToConvert { for _, table := range tablesToConvert {
@@ -207,6 +209,8 @@ func (ps *PostgresStorage) applyCompressionPolicies() error {
{models.WeighingRecord{}, "weighing_batch_id"}, {models.WeighingRecord{}, "weighing_batch_id"},
{models.PigTransferLog{}, "pig_batch_id"}, {models.PigTransferLog{}, "pig_batch_id"},
{models.PigBatchSickPigLog{}, "pig_batch_id"}, {models.PigBatchSickPigLog{}, "pig_batch_id"},
{models.PigPurchase{}, "pig_batch_id"},
{models.PigSale{}, "pig_batch_id"},
} }
for _, policy := range policies { for _, policy := range policies {

View File

@@ -44,6 +44,10 @@ func GetAllModels() []interface{} {
&PigTransferLog{}, &PigTransferLog{},
&PigBatchSickPigLog{}, &PigBatchSickPigLog{},
// Pig Buy & Sell
&PigPurchase{},
&PigSale{},
// Feed Models // Feed Models
&RawMaterial{}, &RawMaterial{},
&RawMaterialPurchase{}, &RawMaterialPurchase{},

View File

@@ -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"
}