Compare commits
	
		
			2 Commits
		
	
	
		
			b1e1dcdcad
			...
			c76c976cc8
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| c76c976cc8 | |||
| 1652df1533 | 
@@ -168,6 +168,9 @@ func (ps *PostgresStorage) creatingHyperTable() error {
 | 
				
			|||||||
		{models.WeighingBatch{}, "weighing_time"},
 | 
							{models.WeighingBatch{}, "weighing_time"},
 | 
				
			||||||
		{models.WeighingRecord{}, "weighing_time"},
 | 
							{models.WeighingRecord{}, "weighing_time"},
 | 
				
			||||||
		{models.PigTransferLog{}, "transfer_time"},
 | 
							{models.PigTransferLog{}, "transfer_time"},
 | 
				
			||||||
 | 
							{models.PigBatchSickPigLog{}, "happened_at"},
 | 
				
			||||||
 | 
							{models.PigPurchase{}, "purchase_date"},
 | 
				
			||||||
 | 
							{models.PigSale{}, "sale_date"},
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	for _, table := range tablesToConvert {
 | 
						for _, table := range tablesToConvert {
 | 
				
			||||||
@@ -205,6 +208,9 @@ func (ps *PostgresStorage) applyCompressionPolicies() error {
 | 
				
			|||||||
		{models.WeighingBatch{}, "pig_batch_id"},
 | 
							{models.WeighingBatch{}, "pig_batch_id"},
 | 
				
			||||||
		{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.PigPurchase{}, "pig_batch_id"},
 | 
				
			||||||
 | 
							{models.PigSale{}, "pig_batch_id"},
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	for _, policy := range policies {
 | 
						for _, policy := range policies {
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -42,6 +42,11 @@ func GetAllModels() []interface{} {
 | 
				
			|||||||
		&WeighingBatch{},
 | 
							&WeighingBatch{},
 | 
				
			||||||
		&WeighingRecord{},
 | 
							&WeighingRecord{},
 | 
				
			||||||
		&PigTransferLog{},
 | 
							&PigTransferLog{},
 | 
				
			||||||
 | 
							&PigBatchSickPigLog{},
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							// Pig Buy & Sell
 | 
				
			||||||
 | 
							&PigPurchase{},
 | 
				
			||||||
 | 
							&PigSale{},
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		// Feed Models
 | 
							// Feed Models
 | 
				
			||||||
		&RawMaterial{},
 | 
							&RawMaterial{},
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -105,3 +105,51 @@ type WeighingRecord struct {
 | 
				
			|||||||
func (WeighingRecord) TableName() string {
 | 
					func (WeighingRecord) TableName() string {
 | 
				
			||||||
	return "weighing_records"
 | 
						return "weighing_records"
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// PigBatchSickPigLogChangeType 定义了病猪变化日志的类型
 | 
				
			||||||
 | 
					type PigBatchSickPigLogChangeType string
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					const (
 | 
				
			||||||
 | 
						SickPigChangeTypeAdd    PigBatchSickPigLogChangeType = "新增" // 新增病猪
 | 
				
			||||||
 | 
						SickPigChangeTypeRemove PigBatchSickPigLogChangeType = "移除" // 移除病猪 (康复, 死亡, 转出等)
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// PigBatchSickPigTreatmentLocation 定义了病猪治疗地点
 | 
				
			||||||
 | 
					type PigBatchSickPigTreatmentLocation string
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					const (
 | 
				
			||||||
 | 
						TreatmentLocationOnSite  PigBatchSickPigTreatmentLocation = "原地治疗"
 | 
				
			||||||
 | 
						TreatmentLocationSickBay PigBatchSickPigTreatmentLocation = "病猪栏治疗"
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// PigBatchSickPigReasonType 定义了病猪变化的原因类型
 | 
				
			||||||
 | 
					type PigBatchSickPigReasonType string
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					const (
 | 
				
			||||||
 | 
						SickPigReasonTypeIllness     PigBatchSickPigReasonType = "患病" // 猪只患病
 | 
				
			||||||
 | 
						SickPigReasonTypeRecovery    PigBatchSickPigReasonType = "康复" // 猪只康复
 | 
				
			||||||
 | 
						SickPigReasonTypeDeath       PigBatchSickPigReasonType = "死亡" // 猪只死亡
 | 
				
			||||||
 | 
						SickPigReasonTypeEliminate   PigBatchSickPigReasonType = "淘汰" // 猪只淘汰
 | 
				
			||||||
 | 
						SickPigReasonTypeTransferIn  PigBatchSickPigReasonType = "转入" // 病猪转入当前批次
 | 
				
			||||||
 | 
						SickPigReasonTypeTransferOut PigBatchSickPigReasonType = "转出" // 病猪转出当前批次 (例如转到其他批次或出售)
 | 
				
			||||||
 | 
						SickPigReasonTypeOther       PigBatchSickPigReasonType = "其他" // 其他原因
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// PigBatchSickPigLog 记录了猪批次中病猪数量的变化日志
 | 
				
			||||||
 | 
					type PigBatchSickPigLog struct {
 | 
				
			||||||
 | 
						gorm.Model
 | 
				
			||||||
 | 
						PigBatchID        uint                             `gorm:"primaryKey;comment:关联的猪批次ID"`
 | 
				
			||||||
 | 
						PenID             uint                             `gorm:"not null;index;comment:所在猪圈ID"`
 | 
				
			||||||
 | 
						PigIDs            string                           `gorm:"size:500;comment:涉及的猪只ID列表,逗号分隔"`
 | 
				
			||||||
 | 
						ChangeType        PigBatchSickPigLogChangeType     `gorm:"size:20;not null;comment:变化类型 (新增, 移除)"`
 | 
				
			||||||
 | 
						ChangeCount       int                              `gorm:"not null;comment:变化数量, 正数表示新增, 负数表示移除"`
 | 
				
			||||||
 | 
						Reason            PigBatchSickPigReasonType        `gorm:"size:20;not null;comment:变化原因 (如: 患病, 康复, 死亡, 转入, 转出, 其他)"`
 | 
				
			||||||
 | 
						Remarks           string                           `gorm:"size:255;comment:备注"`
 | 
				
			||||||
 | 
						TreatmentLocation PigBatchSickPigTreatmentLocation `gorm:"size:50;comment:治疗地点"`
 | 
				
			||||||
 | 
						OperatorID        uint                             `gorm:"comment:操作员ID"`
 | 
				
			||||||
 | 
						HappenedAt        time.Time                        `gorm:"primaryKey;comment:事件发生时间"`
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (PigBatchSickPigLog) TableName() string {
 | 
				
			||||||
 | 
						return "pig_batch_sick_pig_logs"
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										41
									
								
								internal/infra/models/pig_buy_sell.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										41
									
								
								internal/infra/models/pig_buy_sell.go
									
									
									
									
									
										Normal 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"
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
		Reference in New Issue
	
	Block a user