实现交易管理器主服务入口
This commit is contained in:
@@ -57,6 +57,7 @@ const (
|
||||
ChangeTypeDeath LogChangeType = "死亡"
|
||||
ChangeTypeCull LogChangeType = "淘汰"
|
||||
ChangeTypeSale LogChangeType = "销售"
|
||||
ChangeTypeBuy LogChangeType = "购买"
|
||||
ChangeTypeTransferIn LogChangeType = "转入"
|
||||
ChangeTypeTransferOut LogChangeType = "转出"
|
||||
ChangeTypeCorrection LogChangeType = "盘点校正"
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package repository
|
||||
|
||||
import (
|
||||
"time" // 引入 time 包
|
||||
|
||||
"git.huangwc.com/pig/pig-farm-controller/internal/infra/models"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
@@ -9,6 +11,12 @@ import (
|
||||
type PigBatchLogRepository interface {
|
||||
// Create 在指定的事务中创建一条新的猪批次日志。
|
||||
Create(tx *gorm.DB, log *models.PigBatchLog) error
|
||||
|
||||
// GetLogsByBatchIDAndDateRangeTx 在指定的事务中,获取指定批次在特定时间范围内的所有日志记录。
|
||||
GetLogsByBatchIDAndDateRangeTx(tx *gorm.DB, batchID uint, startDate, endDate time.Time) ([]*models.PigBatchLog, error)
|
||||
|
||||
// GetLastLogByBatchIDTx 在指定的事务中,获取某批次的最后一条日志记录。
|
||||
GetLastLogByBatchIDTx(tx *gorm.DB, batchID uint) (*models.PigBatchLog, error)
|
||||
}
|
||||
|
||||
// gormPigBatchLogRepository 是 PigBatchLogRepository 的 GORM 实现。
|
||||
@@ -25,3 +33,23 @@ func NewGormPigBatchLogRepository(db *gorm.DB) PigBatchLogRepository {
|
||||
func (r *gormPigBatchLogRepository) Create(tx *gorm.DB, log *models.PigBatchLog) error {
|
||||
return tx.Create(log).Error
|
||||
}
|
||||
|
||||
// GetLogsByBatchIDAndDateRangeTx 实现了在指定的事务中,获取指定批次在特定时间范围内的所有日志记录的逻辑。
|
||||
func (r *gormPigBatchLogRepository) GetLogsByBatchIDAndDateRangeTx(tx *gorm.DB, batchID uint, startDate, endDate time.Time) ([]*models.PigBatchLog, error) {
|
||||
var logs []*models.PigBatchLog
|
||||
err := tx.Where("pig_batch_id = ? AND created_at >= ? AND created_at <= ?", batchID, startDate, endDate).Find(&logs).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return logs, nil
|
||||
}
|
||||
|
||||
// GetLastLogByBatchIDTx 实现了在指定的事务中,获取某批次的最后一条日志记录的逻辑。
|
||||
func (r *gormPigBatchLogRepository) GetLastLogByBatchIDTx(tx *gorm.DB, batchID uint) (*models.PigBatchLog, error) {
|
||||
var log models.PigBatchLog
|
||||
err := tx.Where("pig_batch_id = ?", batchID).Order("id DESC").First(&log).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &log, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user