2 Commits fbb7ca3649 ... 59e68d27ad

Auteur SHA1 Bericht Datum
  gaoyagang 59e68d27ad Merge remote-tracking branch 'origin/master' 1 jaar geleden
  gaoyagang 61724c313e fit: 1 jaar geleden

+ 1 - 1
app/cmd/events/events.go

@@ -36,7 +36,7 @@ func main() {
 	defer s.Stop()
 	fmt.Printf("Starting rpc server at %s...\n", c.ListenOn)
 
-	envitem.SetOptions(envitem.Options{GtServerIp: c.GtServerIp, Cache: ctx.Cache})
+	envitem.SetOptions(envitem.Options{GtServerIp: c.GtServerIp, Cache: ctx.Cache, AdjustValue: true})
 
 	if c.Mode != "dev" {
 		go func() {

+ 5 - 4
app/cmd/events/internal/logic/handler/handler.go

@@ -58,7 +58,6 @@ func (h *EventHandler) adjustFilterCycle(message []byte) error {
 	if err := json.Unmarshal(message, &entInfo); err != nil {
 		return err
 	}
-	fmt.Printf("adjustFilterCycle Start")
 
 	// 获得一个时间窗口中的许可, 如果获得失败, 则说明事件重复, 不处理  600的是因为 超滤膜反洗时间不会超过600秒
 	if h.canExec(entInfo.ProjectId, entInfo.DeviceCode, "adjustFilterCycle", "", 600*time.Second) == false {
@@ -103,9 +102,11 @@ func (h *EventHandler) adjustFilterCycle(message []byte) error {
 	}
 
 	// 通过上面的判断, 得知自控系统的filterCycle值阻塞了, 需要调整
-	key := fmt.Sprintf("events:adjust:%d:%s:%s:%s", entInfo.ProjectId, entInfo.DeviceCode, "filter_cycle", "")
-	h.svcCtx.Cache.Incr(context.Background(), key)
-	h.svcCtx.Cache.Expire(context.Background(), key, 86400*time.Second)
+	adjustValue, err := filterCycleItem.IncreAdjust(86400 * time.Second)
+	fmt.Printf("projectId: %d, item: %s, adjustValue: %d\n", entInfo.ProjectId, filterCycleItem.Item, adjustValue)
+	//key := fmt.Sprintf("events:adjust:%d:%s:%s:%s", entInfo.ProjectId, entInfo.DeviceCode, "filter_cycle", "")
+	//h.svcCtx.Cache.Incr(context.Background(), key)
+	//h.svcCtx.Cache.Expire(context.Background(), key, 86400*time.Second)
 
 	return nil
 }

+ 3 - 12
app/cmd/organization/internal/logic/handler/uf.go

@@ -5,9 +5,7 @@ import (
 	"GtDataStore/app/cmd/organization/internal/svc"
 	"GtDataStore/app/model"
 	"context"
-	"fmt"
 	"github.com/zeromicro/go-zero/core/logx"
-	"strconv"
 	"time"
 )
 
@@ -33,7 +31,7 @@ func DeviceUf(ctx context.Context, task *job.Task, technologyName string) error
 	//wg.Wait()
 
 	// 3. 转换为存储对象
-	workings, err := transDeviceUfData(task.Job.SvcCtx, devices)
+	workings, err := transDeviceUfData(devices)
 	if err != nil {
 		return err
 	}
@@ -58,17 +56,10 @@ func findDeviceUf(svcCtx *svc.ServiceContext, projectId int64) ([]model.DcDevice
 	}
 }
 
-func transDeviceUfData(svcCtx *svc.ServiceContext, datas []model.DcDeviceBind) ([]model.DcWorkingUf, error) {
+func transDeviceUfData(datas []model.DcDeviceBind) ([]model.DcWorkingUf, error) {
 	ts := make([]model.DcWorkingUf, len(datas))
 
 	for i, data := range datas {
-		var filterCycleAdjust int64 = 0
-
-		key := fmt.Sprintf("events:adjust:%d:%s:%s:%s", data.ProjectId, data.DeviceCode, "filter_cycle", "")
-		if adjustString, err := svcCtx.Cache.Get(key); err == nil && adjustString != "" {
-			filterCycleAdjust, _ = strconv.ParseInt(adjustString, 10, 64)
-		}
-
 		ts[i] = model.DcWorkingUf{
 			ProjectId:        data.ProjectId,
 			DeviceCode:       data.DeviceCode,
@@ -99,7 +90,7 @@ func transDeviceUfData(svcCtx *svc.ServiceContext, datas []model.DcDeviceBind) (
 			ProductWqP:       data.Items.GetItemFloat64Value("product_wq_p"),
 			Step:             data.Items.GetItemInt64Value("step"),
 			FilterTime:       data.Items.GetItemFloat64Value("filter_time"),
-			FilterCycle:      data.Items.GetItemInt64Value("filter_cycle") + filterCycleAdjust,
+			FilterCycle:      data.Items.GetItemInt64Value("filter_cycle"),
 			CTime:            time.Now(),
 		}
 	}

+ 2 - 1
app/cmd/organization/organization.go

@@ -6,6 +6,7 @@ import (
 	"GtDataStore/app/cmd/organization/internal/logic/job"
 	"GtDataStore/app/cmd/organization/internal/server"
 	"GtDataStore/app/cmd/organization/pb"
+	"github.com/go-redis/redis/v8"
 	"github.com/zeromicro/go-zero/core/service"
 	"github.com/zeromicro/go-zero/zrpc"
 	"google.golang.org/grpc"
@@ -44,7 +45,7 @@ func main() {
 	defer s.Stop()
 
 	if c.Mode == "pro" {
-		envitem.SetOptions(envitem.Options{GtServerIp: c.GtServerIp})
+		envitem.SetOptions(envitem.Options{GtServerIp: c.GtServerIp, AdjustValue: true, Cache: redis.NewClient(&redis.Options{Addr: c.Cache[0].Host, Password: c.Cache[0].Pass, MaxRetries: 5})})
 
 		go func() {
 			defer func() {

+ 2 - 3
go.mod

@@ -4,12 +4,12 @@ go 1.19
 
 require (
 	github.com/go-redis/redis/v8 v8.11.5
-	github.com/jinzhu/copier v0.4.0
 	github.com/pkg/errors v0.9.1
 	github.com/zeromicro/go-zero v1.6.0
 	google.golang.org/grpc v1.59.0
 	google.golang.org/protobuf v1.31.0
-	metawant.greentech.com.cn/gaoyagang/gt-common v1.2.4
+	k8s.io/apimachinery v0.28.3
+	metawant.greentech.com.cn/gaoyagang/gt-common v1.2.15
 )
 
 require (
@@ -86,7 +86,6 @@ require (
 	gopkg.in/yaml.v2 v2.4.0 // indirect
 	gopkg.in/yaml.v3 v3.0.1 // indirect
 	k8s.io/api v0.28.3 // indirect
-	k8s.io/apimachinery v0.28.3 // indirect
 	k8s.io/client-go v0.28.3 // indirect
 	k8s.io/klog/v2 v2.100.1 // indirect
 	k8s.io/kube-openapi v0.0.0-20231010175941-2dd684a91f00 // indirect

+ 2 - 4
go.sum

@@ -68,8 +68,6 @@ github.com/google/uuid v1.4.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+
 github.com/grpc-ecosystem/grpc-gateway/v2 v2.18.0 h1:RtRsiaGvWxcwd8y3BiRZxsylPT8hLWZ5SPcfI+3IDNk=
 github.com/grpc-ecosystem/grpc-gateway/v2 v2.18.0/go.mod h1:TzP6duP4Py2pHLVPPQp42aoYI92+PCrVotyR5e8Vqlk=
 github.com/h2non/parth v0.0.0-20190131123155-b4df798d6542 h1:2VTzZjLZBgl62/EtslCrtky5vbi9dd7HrQPQIx6wqiw=
-github.com/jinzhu/copier v0.4.0 h1:w3ciUoD19shMCRargcpm0cm91ytaBhDvuRpz1ODO/U8=
-github.com/jinzhu/copier v0.4.0/go.mod h1:DfbEm0FYsaqBcKcFuvmOZb218JkPGtvSHsKg8S8hyyg=
 github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8HmY=
 github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y=
 github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM=
@@ -279,8 +277,8 @@ k8s.io/kube-openapi v0.0.0-20231010175941-2dd684a91f00 h1:aVUu9fTY98ivBPKR9Y5w/A
 k8s.io/kube-openapi v0.0.0-20231010175941-2dd684a91f00/go.mod h1:AsvuZPBlUDVuCdzJ87iajxtXuR9oktsTctW/R9wwouA=
 k8s.io/utils v0.0.0-20230726121419-3b25d923346b h1:sgn3ZU783SCgtaSJjpcVVlRqd6GSnlTLKgpAAttJvpI=
 k8s.io/utils v0.0.0-20230726121419-3b25d923346b/go.mod h1:OLgZIPagt7ERELqWJFomSt595RzquPNLL48iOWgYOg0=
-metawant.greentech.com.cn/gaoyagang/gt-common v1.2.4 h1:2I8ikGEjLZjVLkm3vlBgarGQ/j2Z3nAE0QeQSWrP8Tw=
-metawant.greentech.com.cn/gaoyagang/gt-common v1.2.4/go.mod h1:TiS/E+b6WFW/0Ei4H/djoguRTnfeBsiUnt5odj1C9n4=
+metawant.greentech.com.cn/gaoyagang/gt-common v1.2.15 h1:x8T7M4J8euqzI9f6Q/oizQTqkOYN8ozquPm3KH2u7FI=
+metawant.greentech.com.cn/gaoyagang/gt-common v1.2.15/go.mod h1:TiS/E+b6WFW/0Ei4H/djoguRTnfeBsiUnt5odj1C9n4=
 sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd h1:EDPBXCAspyGV4jQlpZSudPeMmr1bNJefnuqLsRAsHZo=
 sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd/go.mod h1:B8JuhiUyNFVKdsE8h686QcCxMaH6HrOAZj4vswFpcB0=
 sigs.k8s.io/structured-merge-diff/v4 v4.2.3 h1:PRbqxJClWWYMNV1dhaG4NsibJbArud9kFxnAMREiWFE=