refactor(internal): 分离runner
This commit is contained in:
@@ -15,3 +15,38 @@ func DeleteRuleByID(id uint, uid uint) error {
|
||||
result := gormDB.Where("id = ? AND uid = ?", id, uid).Delete(&model.Rule{})
|
||||
return result.Error
|
||||
}
|
||||
|
||||
// 检查关联账号和 Timer 是否存在(可以没有关联账号)
|
||||
func checkRuleConfigAccountAndTimerExist(rule model.Rule) (exist bool, err error) {
|
||||
gormDB, err := db.GetGormDB()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
if rule.TimerID == 0 {
|
||||
return false, nil
|
||||
}
|
||||
|
||||
var count int64
|
||||
if rule.AccountID != 0 {
|
||||
result := gormDB.Model(&model.Account{}).Where("id = ? AND uid = ?", rule.AccountID, rule.UID).Count(&count)
|
||||
if result.Error != nil {
|
||||
return false, result.Error
|
||||
}
|
||||
if count == 0 {
|
||||
return false, nil
|
||||
}
|
||||
}
|
||||
|
||||
if rule.TimerID != 0 {
|
||||
result := gormDB.Model(&model.Timer{}).Where("id = ? AND uid = ?", rule.TimerID, rule.UID).Count(&count)
|
||||
if result.Error != nil {
|
||||
return false, result.Error
|
||||
}
|
||||
if count == 0 {
|
||||
return false, nil
|
||||
}
|
||||
}
|
||||
|
||||
return true, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user