issue_29 #32
| @@ -78,6 +78,8 @@ func NewApplication(configPath string) (*Application, error) { | |||||||
| 	pigPenRepo := repository.NewGormPigPenRepository(storage.GetDB()) | 	pigPenRepo := repository.NewGormPigPenRepository(storage.GetDB()) | ||||||
| 	pigTransferLogRepo := repository.NewGormPigTransferLogRepository(storage.GetDB()) | 	pigTransferLogRepo := repository.NewGormPigTransferLogRepository(storage.GetDB()) | ||||||
| 	pigTradeRepo := repository.NewGormPigTradeRepository(storage.GetDB()) | 	pigTradeRepo := repository.NewGormPigTradeRepository(storage.GetDB()) | ||||||
|  | 	pigSickPigLogRepo := repository.NewGormPigSickLogRepository(storage.GetDB()) | ||||||
|  | 	pigGroupMedicationLogRepo := repository.NewGormGroupMedicationLogRepository(storage.GetDB()) | ||||||
|  |  | ||||||
| 	// 初始化事务管理器 | 	// 初始化事务管理器 | ||||||
| 	unitOfWork := repository.NewGormUnitOfWork(storage.GetDB(), logger) | 	unitOfWork := repository.NewGormUnitOfWork(storage.GetDB(), logger) | ||||||
|   | |||||||
							
								
								
									
										1
									
								
								internal/domain/pig/pig_sick_manager.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										1
									
								
								internal/domain/pig/pig_sick_manager.go
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1 @@ | |||||||
|  | package pig | ||||||
| @@ -27,20 +27,22 @@ const ( | |||||||
| 	SickPigReasonTypeOther       PigBatchSickPigReasonType = "其他" // 其他原因 | 	SickPigReasonTypeOther       PigBatchSickPigReasonType = "其他" // 其他原因 | ||||||
| ) | ) | ||||||
|  |  | ||||||
| // PigBatchSickPigLog 记录了猪批次中病猪数量的变化日志 | // PigSickLog 记录了猪批次中病猪数量的变化日志 | ||||||
| type PigBatchSickPigLog struct { | type PigSickLog struct { | ||||||
| 	gorm.Model | 	gorm.Model | ||||||
| 	PigBatchID        uint                             `gorm:"primaryKey;comment:关联的猪批次ID"` | 	PigBatchID        uint                             `gorm:"primaryKey;comment:关联的猪批次ID"` | ||||||
| 	PenID             uint                             `gorm:"not null;index;comment:所在猪圈ID"` | 	PenID             uint                             `gorm:"not null;index;comment:所在猪圈ID"` | ||||||
| 	PigIDs            string                           `gorm:"size:500;comment:涉及的猪只ID列表,逗号分隔"` | 	PigIDs            string                           `gorm:"size:500;comment:涉及的猪只ID列表,逗号分隔"` | ||||||
| 	ChangeCount       int                              `gorm:"not null;comment:变化数量, 正数表示新增, 负数表示移除"` | 	ChangeCount       int                              `gorm:"not null;comment:变化数量, 正数表示新增, 负数表示移除"` | ||||||
| 	Reason            PigBatchSickPigReasonType        `gorm:"size:20;not null;comment:变化原因 (如: 患病, 康复, 死亡, 转入, 转出, 其他)"` | 	Reason            PigBatchSickPigReasonType        `gorm:"size:20;not null;comment:变化原因 (如: 患病, 康复, 死亡, 转入, 转出, 其他)"` | ||||||
|  | 	BeforeCount       int                              `gorm:"comment:变化前的数量"` | ||||||
|  | 	AfterCount        int                              `gorm:"comment:变化后的数量"` | ||||||
| 	Remarks           string                           `gorm:"size:255;comment:备注"` | 	Remarks           string                           `gorm:"size:255;comment:备注"` | ||||||
| 	TreatmentLocation PigBatchSickPigTreatmentLocation `gorm:"size:50;comment:治疗地点"` | 	TreatmentLocation PigBatchSickPigTreatmentLocation `gorm:"size:50;comment:治疗地点"` | ||||||
| 	OperatorID        uint                             `gorm:"comment:操作员ID"` | 	OperatorID        uint                             `gorm:"comment:操作员ID"` | ||||||
| 	HappenedAt        time.Time                        `gorm:"primaryKey;comment:事件发生时间"` | 	HappenedAt        time.Time                        `gorm:"primaryKey;comment:事件发生时间"` | ||||||
| } | } | ||||||
|  |  | ||||||
| func (PigBatchSickPigLog) TableName() string { | func (PigSickLog) TableName() string { | ||||||
| 	return "pig_batch_sick_pig_logs" | 	return "pig_sick_logs" | ||||||
| } | } | ||||||
|   | |||||||
							
								
								
									
										26
									
								
								internal/infra/repository/group_medication_log_repository.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										26
									
								
								internal/infra/repository/group_medication_log_repository.go
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,26 @@ | |||||||
|  | package repository | ||||||
|  |  | ||||||
|  | import ( | ||||||
|  | 	"git.huangwc.com/pig/pig-farm-controller/internal/infra/models" | ||||||
|  | 	"gorm.io/gorm" | ||||||
|  | ) | ||||||
|  |  | ||||||
|  | // GroupMedicationLogRepository 定义了与群体用药日志模型相关的数据库操作接口。 | ||||||
|  | type GroupMedicationLogRepository interface { | ||||||
|  | 	CreateGroupMedicationLog(log *models.GroupMedicationLog) error | ||||||
|  | } | ||||||
|  |  | ||||||
|  | // gormGroupMedicationLogRepository 是 GroupMedicationLogRepository 接口的 GORM 实现。 | ||||||
|  | type gormGroupMedicationLogRepository struct { | ||||||
|  | 	db *gorm.DB | ||||||
|  | } | ||||||
|  |  | ||||||
|  | // NewGormGroupMedicationLogRepository 创建一个新的 GroupMedicationLogRepository GORM 实现实例。 | ||||||
|  | func NewGormGroupMedicationLogRepository(db *gorm.DB) GroupMedicationLogRepository { | ||||||
|  | 	return &gormGroupMedicationLogRepository{db: db} | ||||||
|  | } | ||||||
|  |  | ||||||
|  | // CreateGroupMedicationLog 创建一条新的群体用药日志记录 | ||||||
|  | func (r *gormGroupMedicationLogRepository) CreateGroupMedicationLog(log *models.GroupMedicationLog) error { | ||||||
|  | 	return r.db.Create(log).Error | ||||||
|  | } | ||||||
							
								
								
									
										26
									
								
								internal/infra/repository/pig_sick_repository.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										26
									
								
								internal/infra/repository/pig_sick_repository.go
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,26 @@ | |||||||
|  | package repository | ||||||
|  |  | ||||||
|  | import ( | ||||||
|  | 	"git.huangwc.com/pig/pig-farm-controller/internal/infra/models" | ||||||
|  | 	"gorm.io/gorm" | ||||||
|  | ) | ||||||
|  |  | ||||||
|  | // PigSickLogRepository 定义了与病猪日志模型相关的数据库操作接口。 | ||||||
|  | type PigSickLogRepository interface { | ||||||
|  | 	CreatePigSickLog(log *models.PigSickLog) error | ||||||
|  | } | ||||||
|  |  | ||||||
|  | // gormPigSickLogRepository 是 PigSickLogRepository 接口的 GORM 实现。 | ||||||
|  | type gormPigSickLogRepository struct { | ||||||
|  | 	db *gorm.DB | ||||||
|  | } | ||||||
|  |  | ||||||
|  | // NewGormPigSickLogRepository 创建一个新的 PigSickLogRepository GORM 实现实例。 | ||||||
|  | func NewGormPigSickLogRepository(db *gorm.DB) PigSickLogRepository { | ||||||
|  | 	return &gormPigSickLogRepository{db: db} | ||||||
|  | } | ||||||
|  |  | ||||||
|  | // CreatePigSickLog 创建一条新的病猪日志记录 | ||||||
|  | func (r *gormPigSickLogRepository) CreatePigSickLog(log *models.PigSickLog) error { | ||||||
|  | 	return r.db.Create(log).Error | ||||||
|  | } | ||||||
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							
		Reference in New Issue
	
	Block a user