liuxiulin il y a 10 heures
Parent
commit
4e3209b4e9

+ 2 - 2
go.sum

@@ -338,8 +338,8 @@ go.uber.org/zap v1.17.0 h1:MTjgFu6ZLKvY6Pvaqk97GlxNBuMpV4Hy/3P6tRGlI2U=
 go.uber.org/zap v1.17.0/go.mod h1:MXVU+bhUf/A7Xi2HNOnopQOrmycQ5Ih87HtOu4q5SSo=
 gogs.yehaoji.cn/yongxu/file-server-sdk.git v1.0.0 h1:Zjusu9Tq+WeFd59yJ01PPgX0e4smBGfJfeYiknzLAKA=
 gogs.yehaoji.cn/yongxu/file-server-sdk.git v1.0.0/go.mod h1:tGWbOVjXlvLPmVEZMDp+IfogSM7Y4094VrZ+y68K6qE=
-gogs.yongxulvjian.com/yongxu/weather-api-sdk.git v1.0.2 h1:URnwpqeQ1WBvql4QCha7Bv+JATwyvEfdq26sB0OiG8g=
-gogs.yongxulvjian.com/yongxu/weather-api-sdk.git v1.0.2/go.mod h1:pLHXQJPhIL2k5cBKn/Nzh775/ryTvVEpAtB2ezKZmt8=
+gogs.yongxulvjian.com/yongxu/weather-api-sdk.git v1.0.3 h1:pwmWtQI3k3KhFuVdMrAXwmXadSQE2EGCty5VQCj62Ac=
+gogs.yongxulvjian.com/yongxu/weather-api-sdk.git v1.0.3/go.mod h1:pLHXQJPhIL2k5cBKn/Nzh775/ryTvVEpAtB2ezKZmt8=
 golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
 golang.org/x/crypto v0.0.0-20190325154230-a5d413f7728c/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
 golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=

+ 7 - 8
services/scene-service/internal/service/manager/weather.go

@@ -50,7 +50,7 @@ func (w *WeatherSceneService) Add(config string) error {
 		return errors.New("天气监控任务配置错误:判断条件不能为空")
 	}
 	// 初始化Ticker和停止通道
-	c.ticker = time.NewTicker(time.Duration(c.Interval) * time.Minute)
+	c.ticker = time.NewTicker(20 * time.Second)
 	c.stopChan = make(chan struct{})
 
 	// 启动监控协程
@@ -99,13 +99,12 @@ func (w *WeatherSceneService) Update(config string) error {
 	return nil
 }
 
-func (w *WeatherSceneService) Remove(config string) error {
-	var c WeatherSceneConfig
-	err := json.Unmarshal([]byte(config), &c)
-	if err != nil {
-		server.Log.Errorf("config to timerConfig error :%s", err.Error())
-	}
-
+func (w *WeatherSceneService) Remove(id string) error {
+	fmt.Printf("task count--------------:%d", w.tasks.Size())
+	scene := w.tasks.Get(id)
+	fmt.Printf("scene-------------:%s", gjson.New(scene).MustToJsonString())
+	c := scene.(DeviceSceneConfig)
+	c.stopChan <- struct{}{}
 	w.tasks.Remove(c.SceneId)
 	server.Log.Debugf("RemoveTimeScene :%s", c.SceneId)
 	return nil

+ 1 - 1
vendor/modules.txt

@@ -926,6 +926,6 @@ labix.org/v2/mgo/bson
 labix.org/v2/mgo/sasl
 # launchpad.net/gocheck v0.0.0-20140225173054-000000000087
 ## explicit
-# weather-api-sdk v1.0.0 => gogs.yongxulvjian.com/yongxu/weather-api-sdk.git v1.0.2
+# weather-api-sdk v1.0.0 => gogs.yongxulvjian.com/yongxu/weather-api-sdk.git v1.0.3
 ## explicit; go 1.22
 weather-api-sdk

+ 12 - 0
vendor/weather-api-sdk/api.go

@@ -6,6 +6,7 @@ import (
 	"fmt"
 	"github.com/gogf/gf/v2/frame/g"
 	"strconv"
+	"strings"
 	"time"
 )
 
@@ -111,6 +112,7 @@ type WeatherInfoResp struct {
 	Humidity    int       `json:"humidity"`
 	AQI         int       `json:"aqi"`
 	PM25        int       `json:"pm25"`
+	PM25Text    string    `json:"pm25_text"`
 	PM10        int       `json:"pm10"`
 	Quality     string    `json:"quality"`
 	LastUpdate  time.Time `json:"last_update"`
@@ -136,9 +138,19 @@ func GetWeatherInfo(location, key string) (*WeatherInfoResp, error) {
 		return nil, err
 	}
 	result.PM25, _ = strconv.Atoi(airInfo.Results[0].Air.City.Pm25)
+	if result.PM25 <= 35 {
+		result.PM25Text = "优"
+	} else if result.PM25 <= 75 {
+		result.PM25Text = "良"
+	} else {
+		result.PM25Text = "污染"
+	}
 	result.AQI, _ = strconv.Atoi(airInfo.Results[0].Air.City.Aqi)
 	result.PM10, _ = strconv.Atoi(airInfo.Results[0].Air.City.Pm10)
 	result.Quality = airInfo.Results[0].Air.City.Quality
+	if strings.Contains(airInfo.Results[0].Air.City.Quality, "污染") {
+		result.Quality = "污染"
+	}
 	return result, nil
 }