uint/uint64全部改为uint32
This commit is contained in:
@@ -13,18 +13,18 @@ import (
|
||||
type PigPenRepository interface {
|
||||
CreatePen(ctx context.Context, pen *models.Pen) error
|
||||
// GetPenByID 根据ID获取单个猪栏 (非事务性)
|
||||
GetPenByID(ctx context.Context, id uint) (*models.Pen, error)
|
||||
GetPenByID(ctx context.Context, id uint32) (*models.Pen, error)
|
||||
// GetPenByIDTx 根据ID获取单个猪栏 (事务性)
|
||||
GetPenByIDTx(ctx context.Context, tx *gorm.DB, id uint) (*models.Pen, error)
|
||||
GetPenByIDTx(ctx context.Context, tx *gorm.DB, id uint32) (*models.Pen, error)
|
||||
ListPens(ctx context.Context) ([]models.Pen, error)
|
||||
// UpdatePen 更新一个猪栏,返回受影响的行数和错误
|
||||
UpdatePen(ctx context.Context, pen *models.Pen) (int64, error)
|
||||
// DeletePen 根据ID删除一个猪栏,返回受影响的行数和错误
|
||||
DeletePen(ctx context.Context, id uint) (int64, error)
|
||||
DeletePen(ctx context.Context, id uint32) (int64, error)
|
||||
// GetPensByBatchIDTx 根据批次ID获取所有关联的猪栏 (事务性)
|
||||
GetPensByBatchIDTx(ctx context.Context, tx *gorm.DB, batchID uint) ([]*models.Pen, error)
|
||||
GetPensByBatchIDTx(ctx context.Context, tx *gorm.DB, batchID uint32) ([]*models.Pen, error)
|
||||
// UpdatePenFieldsTx 更新猪栏的指定字段 (事务性)
|
||||
UpdatePenFieldsTx(ctx context.Context, tx *gorm.DB, penID uint, updates map[string]interface{}) error
|
||||
UpdatePenFieldsTx(ctx context.Context, tx *gorm.DB, penID uint32, updates map[string]interface{}) error
|
||||
}
|
||||
|
||||
// gormPigPenRepository 是 PigPenRepository 接口的 GORM 实现。
|
||||
@@ -45,13 +45,13 @@ func (r *gormPigPenRepository) CreatePen(ctx context.Context, pen *models.Pen) e
|
||||
}
|
||||
|
||||
// GetPenByID 根据ID获取单个猪栏 (非事务性)
|
||||
func (r *gormPigPenRepository) GetPenByID(ctx context.Context, id uint) (*models.Pen, error) {
|
||||
func (r *gormPigPenRepository) GetPenByID(ctx context.Context, id uint32) (*models.Pen, error) {
|
||||
repoCtx := logs.AddFuncName(ctx, r.ctx, "GetPenByID")
|
||||
return r.GetPenByIDTx(repoCtx, r.db, id) // 非Tx方法直接调用Tx方法
|
||||
}
|
||||
|
||||
// GetPenByIDTx 在指定的事务中,通过ID获取单个猪栏信息。
|
||||
func (r *gormPigPenRepository) GetPenByIDTx(ctx context.Context, tx *gorm.DB, id uint) (*models.Pen, error) {
|
||||
func (r *gormPigPenRepository) GetPenByIDTx(ctx context.Context, tx *gorm.DB, id uint32) (*models.Pen, error) {
|
||||
repoCtx := logs.AddFuncName(ctx, r.ctx, "GetPenByIDTx")
|
||||
var pen models.Pen
|
||||
if err := tx.WithContext(repoCtx).First(&pen, id).Error; err != nil {
|
||||
@@ -81,7 +81,7 @@ func (r *gormPigPenRepository) UpdatePen(ctx context.Context, pen *models.Pen) (
|
||||
}
|
||||
|
||||
// DeletePen 根据ID删除一个猪栏,返回受影响的行数和错误
|
||||
func (r *gormPigPenRepository) DeletePen(ctx context.Context, id uint) (int64, error) {
|
||||
func (r *gormPigPenRepository) DeletePen(ctx context.Context, id uint32) (int64, error) {
|
||||
repoCtx := logs.AddFuncName(ctx, r.ctx, "DeletePen")
|
||||
result := r.db.WithContext(repoCtx).Delete(&models.Pen{}, id)
|
||||
if result.Error != nil {
|
||||
@@ -91,7 +91,7 @@ func (r *gormPigPenRepository) DeletePen(ctx context.Context, id uint) (int64, e
|
||||
}
|
||||
|
||||
// GetPensByBatchIDTx 在指定的事务中,获取一个猪群当前关联的所有猪栏。
|
||||
func (r *gormPigPenRepository) GetPensByBatchIDTx(ctx context.Context, tx *gorm.DB, batchID uint) ([]*models.Pen, error) {
|
||||
func (r *gormPigPenRepository) GetPensByBatchIDTx(ctx context.Context, tx *gorm.DB, batchID uint32) ([]*models.Pen, error) {
|
||||
repoCtx := logs.AddFuncName(ctx, r.ctx, "GetPensByBatchIDTx")
|
||||
var pens []*models.Pen
|
||||
// 注意:PigBatchID 是指针类型,需要处理 nil 值
|
||||
@@ -103,7 +103,7 @@ func (r *gormPigPenRepository) GetPensByBatchIDTx(ctx context.Context, tx *gorm.
|
||||
}
|
||||
|
||||
// UpdatePenFieldsTx 在指定的事务中,更新一个猪栏的指定字段。
|
||||
func (r *gormPigPenRepository) UpdatePenFieldsTx(ctx context.Context, tx *gorm.DB, penID uint, updates map[string]interface{}) error {
|
||||
func (r *gormPigPenRepository) UpdatePenFieldsTx(ctx context.Context, tx *gorm.DB, penID uint32, updates map[string]interface{}) error {
|
||||
repoCtx := logs.AddFuncName(ctx, r.ctx, "UpdatePenFieldsTx")
|
||||
result := tx.WithContext(repoCtx).Model(&models.Pen{}).Where("id = ?", penID).Updates(updates)
|
||||
return result.Error
|
||||
|
||||
Reference in New Issue
Block a user