修bug
This commit is contained in:
@@ -20,7 +20,7 @@ log:
|
||||
max_backups: 5 # 保留的旧日志文件的最大数量
|
||||
max_age: 30 # 保留的旧日志文件的最大天数
|
||||
compress: false # 是否压缩/归档旧日志文件
|
||||
enable_trace: false # 是否启用调用链追踪
|
||||
enable_trace: true # 是否启用调用链追踪
|
||||
|
||||
# 数据库配置 (PostgreSQL)
|
||||
database:
|
||||
|
||||
@@ -76,7 +76,7 @@ func (r *gormDeviceRepository) Create(ctx context.Context, device *models.Device
|
||||
func (r *gormDeviceRepository) FindByID(ctx context.Context, id uint32) (*models.Device, error) {
|
||||
repoCtx := logs.AddFuncName(ctx, r.ctx, "FindByID")
|
||||
var device models.Device
|
||||
if err := r.db.WithContext(repoCtx).Preload("AreaControllers").Preload("DeviceTemplates").First(&device, id).Error; err != nil {
|
||||
if err := r.db.WithContext(repoCtx).Preload("AreaController").Preload("DeviceTemplate").First(&device, id).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &device, nil
|
||||
@@ -111,7 +111,7 @@ func (r *gormDeviceRepository) FindByIDString(ctx context.Context, id string) (*
|
||||
func (r *gormDeviceRepository) ListAll(ctx context.Context) ([]*models.Device, error) {
|
||||
repoCtx := logs.AddFuncName(ctx, r.ctx, "ListAll")
|
||||
var devices []*models.Device
|
||||
if err := r.db.WithContext(repoCtx).Preload("AreaControllers").Preload("DeviceTemplates").Find(&devices).Error; err != nil {
|
||||
if err := r.db.WithContext(repoCtx).Preload("AreaController").Preload("DeviceTemplate").Find(&devices).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return devices, nil
|
||||
@@ -121,7 +121,7 @@ func (r *gormDeviceRepository) ListAll(ctx context.Context) ([]*models.Device, e
|
||||
func (r *gormDeviceRepository) ListAllSensors(ctx context.Context) ([]*models.Device, error) {
|
||||
repoCtx := logs.AddFuncName(ctx, r.ctx, "ListAllSensors")
|
||||
var sensors []*models.Device
|
||||
err := r.db.WithContext(repoCtx).Preload("AreaControllers").Preload("DeviceTemplates").
|
||||
err := r.db.WithContext(repoCtx).Preload("AreaController").Preload("DeviceTemplate").
|
||||
Joins("JOIN device_templates ON device_templates.id = devices.device_template_id").
|
||||
Where("device_templates.category = ?", models.CategorySensor).
|
||||
Find(&sensors).Error
|
||||
@@ -135,7 +135,7 @@ func (r *gormDeviceRepository) ListAllSensors(ctx context.Context) ([]*models.De
|
||||
func (r *gormDeviceRepository) ListByAreaControllerID(ctx context.Context, areaControllerID uint32) ([]*models.Device, error) {
|
||||
repoCtx := logs.AddFuncName(ctx, r.ctx, "ListByAreaControllerID")
|
||||
var devices []*models.Device
|
||||
err := r.db.WithContext(repoCtx).Preload("AreaControllers").Preload("DeviceTemplates").Where("area_controller_id = ?", areaControllerID).Find(&devices).Error
|
||||
err := r.db.WithContext(repoCtx).Preload("AreaController").Preload("DeviceTemplate").Where("area_controller_id = ?", areaControllerID).Find(&devices).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -171,7 +171,7 @@ func (r *gormDeviceRepository) Delete(ctx context.Context, id uint32) error {
|
||||
func (r *gormDeviceRepository) FindByAreaControllerAndPhysicalAddress(ctx context.Context, areaControllerID uint32, busNumber int, busAddress int) (*models.Device, error) {
|
||||
repoCtx := logs.AddFuncName(ctx, r.ctx, "FindByAreaControllerAndPhysicalAddress")
|
||||
var device models.Device
|
||||
err := r.db.WithContext(repoCtx).Preload("AreaControllers").Preload("DeviceTemplates").
|
||||
err := r.db.WithContext(repoCtx).Preload("AreaController").Preload("DeviceTemplate").
|
||||
Where("area_controller_id = ?", areaControllerID).
|
||||
Where("properties->>'bus_number' = ?", strconv.Itoa(busNumber)).
|
||||
Where("properties->>'bus_address' = ?", strconv.Itoa(busAddress)).
|
||||
|
||||
@@ -165,7 +165,7 @@ func (r *gormExecutionLogRepository) ListTaskExecutionLogs(ctx context.Context,
|
||||
orderBy = opts.OrderBy
|
||||
}
|
||||
// 预加载关联的Task信息
|
||||
query = query.Order(orderBy).Preload("Tasks")
|
||||
query = query.Order(orderBy).Preload("Task")
|
||||
|
||||
offset := (page - 1) * pageSize
|
||||
err := query.Limit(pageSize).Offset(offset).Find(&results).Error
|
||||
@@ -231,8 +231,8 @@ func (r *gormExecutionLogRepository) UpdateTaskExecutionLog(ctx context.Context,
|
||||
func (r *gormExecutionLogRepository) FindTaskExecutionLogByID(ctx context.Context, id uint32) (*models.TaskExecutionLog, error) {
|
||||
repoCtx := logs.AddFuncName(ctx, r.ctx, "FindTaskExecutionLogByID")
|
||||
var log models.TaskExecutionLog
|
||||
// 使用 Preload("Tasks") 来确保关联的任务信息被一并加载
|
||||
err := r.db.WithContext(repoCtx).Preload("Tasks").First(&log, id).Error
|
||||
// 使用 Preload("Task") 来确保关联的任务信息被一并加载
|
||||
err := r.db.WithContext(repoCtx).Preload("Task").First(&log, id).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -154,8 +154,8 @@ func (r *gormPendingTaskRepository) ClaimNextAvailableTask(ctx context.Context,
|
||||
return err
|
||||
}
|
||||
|
||||
// 在 Preload("Tasks") 时,使用 Unscoped() 来忽略 Task 的软删除状态
|
||||
if err := tx.WithContext(repoCtx).Preload("Tasks", func(db *gorm.DB) *gorm.DB {
|
||||
// 在 Preload("Task") 时,使用 Unscoped() 来忽略 Task 的软删除状态
|
||||
if err := tx.WithContext(repoCtx).Preload("Task", func(db *gorm.DB) *gorm.DB {
|
||||
return db.Unscoped()
|
||||
}).First(&log, pendingTask.TaskExecutionLogID).Error; err != nil {
|
||||
return err
|
||||
|
||||
@@ -90,7 +90,7 @@ func (r *gormRawMaterialRepository) ListRawMaterialPurchases(ctx context.Context
|
||||
if opts.OrderBy != "" {
|
||||
orderBy = opts.OrderBy
|
||||
}
|
||||
query = query.Order(orderBy).Preload("RawMaterials")
|
||||
query = query.Order(orderBy).Preload("RawMaterial")
|
||||
|
||||
offset := (page - 1) * pageSize
|
||||
err := query.Limit(pageSize).Offset(offset).Find(&results).Error
|
||||
@@ -178,7 +178,7 @@ func (r *gormRawMaterialRepository) ListFeedUsageRecords(ctx context.Context, op
|
||||
if opts.OrderBy != "" {
|
||||
orderBy = opts.OrderBy
|
||||
}
|
||||
query = query.Order(orderBy).Preload("Pens").Preload("FeedFormulas")
|
||||
query = query.Order(orderBy).Preload("Pen").Preload("FeedFormula")
|
||||
|
||||
offset := (page - 1) * pageSize
|
||||
err := query.Limit(pageSize).Offset(offset).Find(&results).Error
|
||||
|
||||
Reference in New Issue
Block a user