Browse Source

解决循环引用问题

liuxiulin 12 hours ago
parent
commit
957888c91e

+ 0 - 23
services/knowoapi/controllers/device.go

@@ -516,26 +516,3 @@ func (a *DeviceController) PostSendcommand() {
 	}
 	done(a.Ctx, params.DeviceId)
 }
-
-// PostSendcommand 下发指令
-// POST /device/sendcommand
-func (a *DeviceController) PostSendcommand() {
-	params := new(models.SendCommandParams)
-	if err := parseBody(a.Ctx, params); err != nil {
-		badRequest(a.Ctx, err)
-		return
-	}
-
-	err := a.Service.GetScenes(rpcs.ArgsSendCommand{
-		DeviceId:  params.DeviceId,
-		SubDevice: params.SunDeviceId,
-		Cmd:       params.Cmd,
-		Params:    params.Params,
-	})
-
-	if err != nil {
-		responseError(a.Ctx, ErrNormal, err.Error())
-		return
-	}
-	done(a.Ctx, params.DeviceId)
-}

+ 2 - 3
services/scene-service/internal/service/manager/device_status.go

@@ -9,7 +9,6 @@ import (
 	"sparrow/pkg/rpcs"
 	"sparrow/pkg/server"
 	"sparrow/pkg/utils"
-	"sparrow/services/scene-service/internal/service"
 	"time"
 )
 
@@ -17,7 +16,7 @@ type DeviceSceneConfig struct {
 	SceneId      string             `json:"scene_id"`
 	DecisionExpr string             `json:"decision_expr"` // 条件表达式 and or
 	Conditions   []*DeviceCondition `json:"conditions"`    // 条件
-	Actions      []*service.Action  `json:"actions"`       // 执行动作
+	Actions      []*Action          `json:"actions"`       // 执行动作
 	Interval     int                `json:"interval"`      // 检查间隔(秒)
 	ticker       *time.Ticker       `json:"-"`             // 定时器
 	stopChan     chan struct{}      `json:"-"`             // 停止信号通道
@@ -125,7 +124,7 @@ func (d *DeviceSceneService) monitorTask(config DeviceSceneConfig) {
 				server.Log.Errorf("compare weather condition error :%s", err.Error())
 			}
 			if result {
-				if err = service.NewTaskExecutor(config.Actions).Do(); err != nil {
+				if err = NewTaskExecutor(config.Actions).Do(); err != nil {
 					server.Log.Errorf("weather do taskid :%s error:%s", config.SceneId, err.Error())
 				}
 			}

+ 1 - 1
services/scene-service/internal/service/executer.go → services/scene-service/internal/service/manager/executer.go

@@ -1,4 +1,4 @@
-package service
+package manager
 
 import (
 	"sparrow/pkg/rpcs"

+ 3 - 4
services/scene-service/internal/service/manager/timer.go

@@ -7,13 +7,12 @@ import (
 	"github.com/gogf/gf/container/gmap"
 	"github.com/gogf/gf/v2/os/gcron"
 	"sparrow/pkg/server"
-	"sparrow/services/scene-service/internal/service"
 )
 
 type TimerSceneConfig struct {
 	SceneId    string                `json:"scene_id"`
 	Conditions []*TimerTaskCondition `json:"conditions"`
-	Actions    []*service.Action     `json:"actions"`
+	Actions    []*Action             `json:"actions"`
 }
 
 type TimerTaskCondition struct {
@@ -58,9 +57,9 @@ func (t *TimerSceneService) Add(config string) error {
 	//server.Log.Debugf("AddTimeScene :%s", c.SceneId)
 	return nil
 }
-func (t *TimerSceneService) addTask(c *TimerTaskCondition, actions []*service.Action) error {
+func (t *TimerSceneService) addTask(c *TimerTaskCondition, actions []*Action) error {
 	_, err := t.cron.AddTimes(context.Background(), c.Cron, c.Times, func(ctx context.Context) {
-		if err := service.NewTaskExecutor(actions).Do(); err != nil {
+		if err := NewTaskExecutor(actions).Do(); err != nil {
 			server.Log.Errorf("do task :%s error:%s", c.TaskId, err.Error())
 		}
 	}, c.TaskId)

+ 2 - 3
services/scene-service/internal/service/manager/weather.go

@@ -8,7 +8,6 @@ import (
 	"github.com/gogf/gf/encoding/gjson"
 	"sparrow/pkg/server"
 	"sparrow/pkg/utils"
-	"sparrow/services/scene-service/internal/service"
 	"time"
 	weather "weather-api-sdk"
 )
@@ -19,7 +18,7 @@ type WeatherSceneConfig struct {
 	DecisionExpr string              `json:"decision_expr"` // 条件表达式 and or
 	Conditions   []*WeatherCondition `json:"conditions"`    // 条件
 	Interval     int                 `json:"interval"`      // 检查间隔(分钟)
-	Actions      []*service.Action   `json:"actions"`       // 执行动作
+	Actions      []*Action           `json:"actions"`       // 执行动作
 	ticker       *time.Ticker        `json:"-"`             // 定时器
 	stopChan     chan struct{}       `json:"-"`             // 停止信号通道
 }
@@ -70,7 +69,7 @@ func (w *WeatherSceneService) monitorTask(task WeatherSceneConfig) {
 				server.Log.Errorf("compare weather condition error :%s", err.Error())
 			}
 			if result {
-				if err = service.NewTaskExecutor(task.Actions).Do(); err != nil {
+				if err = NewTaskExecutor(task.Actions).Do(); err != nil {
 					server.Log.Errorf("weather do taskid :%s error:%s", task.SceneId, err.Error())
 				}
 			}

+ 2 - 2
services/scene-service/internal/service/scene.go

@@ -124,13 +124,13 @@ func (m *SceneService) SubmitAction(args rpcs.ArgsSubmitSceneAction, reply *rpcs
 }
 
 func (m *SceneService) doAction(action string) error {
-	var actions []*Action
+	var actions []*service2.Action
 	err := json.Unmarshal([]byte(action), &actions)
 	if err != nil {
 		server.Log.Errorf("unmarshal actions error :%v", err)
 		return err
 	}
-	return NewTaskExecutor(actions).Do()
+	return service2.NewTaskExecutor(actions).Do()
 }
 
 func (m *SceneService) saveSceneRedis(scene SceneInfo) error {