63 lines
1.4 KiB
Go
63 lines
1.4 KiB
Go
package rpc
|
|
|
|
import (
|
|
"fmt"
|
|
"time"
|
|
)
|
|
|
|
// 自动化相关RPC
|
|
type Automation struct{}
|
|
|
|
// 获取自动化列表
|
|
func (a *Automation) GetList() (*[]AutomationTask, error) {
|
|
result := &Result[[]AutomationTask]{}
|
|
if err := GetRequest().Send("automation.list", map[string]any{}, result); err != nil {
|
|
return nil, err
|
|
}
|
|
if result.Code != 0 {
|
|
return nil, fmt.Errorf("%s", result.Message)
|
|
}
|
|
return &result.Data, nil
|
|
}
|
|
|
|
// 获取自动化详情
|
|
func (a *Automation) GetDetail(automationId uint32) (*AutomationTask, error) {
|
|
body := map[string]any{
|
|
"automation_id": automationId,
|
|
}
|
|
result := &Result[AutomationTask]{}
|
|
if err := GetRequest().Send("automation.detail", body, result); err != nil {
|
|
return nil, err
|
|
}
|
|
if result.Code != 0 {
|
|
return nil, fmt.Errorf("%s", result.Message)
|
|
}
|
|
return &result.Data, nil
|
|
}
|
|
|
|
// 更新条件最后执行时间
|
|
func (a *Automation) UpdateConditionLastExecuteTime(conditionId uint32, lastExecuteTime time.Time) error {
|
|
body := map[string]any{
|
|
"condition_id": conditionId,
|
|
"time": lastExecuteTime.Format(time.DateTime),
|
|
}
|
|
result := &Result[any]{}
|
|
if err := GetRequest().Send("automation.update_condition_last_execute_time", body, result); err != nil {
|
|
return err
|
|
}
|
|
if result.Code != 0 {
|
|
return fmt.Errorf("%s", result.Message)
|
|
}
|
|
return nil
|
|
}
|
|
|
|
var automation *Automation
|
|
|
|
// 获取自动化相关RPC
|
|
func GetAutomation() *Automation {
|
|
if automation == nil {
|
|
automation = &Automation{}
|
|
}
|
|
return automation
|
|
}
|