浏览代码

fit:
1. 修正job snyc的问题
2. 单点位判断支持改变判断

gaoyagang 1 年之前
父节点
当前提交
6c207d1c75

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

@@ -42,7 +42,7 @@ func main() {
 
 			// 启动事件识别
 			fmt.Print("start new job for events.....\n")
-			j := job.NewJob(1, "events", ctx, handler.EventHandlerTable, handler.EventIntervalTable)
+			j := job.NewJob(1, "events-"+c.Mode, ctx, handler.EventHandlerTable, handler.EventIntervalTable)
 			j.Run()
 		}()
 	}

+ 6 - 0
app/cmd/events/internal/logic/handler/event.go

@@ -30,6 +30,12 @@ func HandlerEventNotify(svcCtx *svc.ServiceContext) error {
 func toMQ(queue *redis.Client, info eventInfo) {
 	channel := fmt.Sprintf(EVTNE_NOTIFY_KEY_FORMAT, info.ProjectId, info.EventName)
 	if bs, err := json.Marshal(info); err == nil {
+		//queue.XAdd(context.Background(), &redis.XAddArgs{
+		//	Stream: channel,
+		//	MaxLen: 5000,
+		//	Values: ``,
+		//})
+
 		if intCmd := queue.Publish(context.Background(), channel, string(bs)); intCmd == nil {
 			logx.Errorf("handlerEvent queue.Publish toMQ error: %s %+v", channel, info)
 		}

+ 1 - 1
app/cmd/events/internal/logic/handler/vars.go

@@ -33,7 +33,7 @@ var (
 	eventChan chan eventInfo
 
 	EventIntervalTable = map[string]time.Duration{
-		EVENT_SINGLE_ITEM: 60 * time.Second,
+		EVENT_SINGLE_ITEM: 1 * time.Second,
 		EVENT_MULTI_ITEM:  60 * time.Second,
 	}
 

+ 1 - 1
app/cmd/organization/internal/logic/handler/pump.go

@@ -45,7 +45,7 @@ func DevicePump(ctx context.Context, task *job.Task, technologyName string) erro
 }
 
 func findDevicePump(svcCtx *svc.ServiceContext, projectId int64) ([]model.DcDeviceBind, error) {
-	if devices, err := svcCtx.DeviceBind.FindByProjectIdDeviceType(context.Background(), projectId, DEVICE_UF); err != nil {
+	if devices, err := svcCtx.DeviceBind.FindByProjectIdDeviceType(context.Background(), projectId, DEVICE_PUMP); err != nil {
 		logx.Infof("findDevicePump not found devices")
 		return nil, err
 	} else {

+ 1 - 1
app/cmd/organization/internal/logic/handler/valve.go

@@ -45,7 +45,7 @@ func DeviceValve(ctx context.Context, task *job.Task, technologyName string) err
 }
 
 func findDeviceValve(svcCtx *svc.ServiceContext, projectId int64) ([]model.DcDeviceBind, error) {
-	if devices, err := svcCtx.DeviceBind.FindByProjectIdDeviceType(context.Background(), projectId, DEVICE_UF); err != nil {
+	if devices, err := svcCtx.DeviceBind.FindByProjectIdDeviceType(context.Background(), projectId, DEVICE_VALVE); err != nil {
 		logx.Infof("findDeviceValve not found devices")
 		return nil, err
 	} else {

+ 7 - 7
app/cmd/organization/internal/logic/handler/vars.go

@@ -18,13 +18,13 @@ const (
 
 var (
 	DeviceIntervalTable = map[string]time.Duration{
-		DEVICE_UF:    1,
-		DEVICE_MF:    1,
-		DEVICE_NF:    1,
-		DEVICE_RO:    1,
-		DEVICE_VALVE: 1,
-		DEVICE_PUMP:  1,
-		DEVICE_CHEST: 1,
+		DEVICE_UF:    1 * time.Second,
+		DEVICE_MF:    1 * time.Second,
+		DEVICE_NF:    1 * time.Second,
+		DEVICE_RO:    1 * time.Second,
+		DEVICE_VALVE: 1 * time.Second,
+		DEVICE_PUMP:  1 * time.Second,
+		DEVICE_CHEST: 1 * time.Second,
 	}
 
 	DeviceHandlerTable = map[string]func(ctx context.Context, task *job.Task, technologyName string) error{

+ 10 - 4
common/envitem/func.go

@@ -238,8 +238,11 @@ func (e *EnvItem) GetItemFloat64Val() float64 {
 		e.getCurrentValue()
 	}
 
-	if v, ok := e.Value.(float64); ok {
-		return v
+	switch e.Value.(type) {
+	case string:
+		if v, e := strconv.ParseFloat(e.Value.(string), 64); e == nil {
+			return v
+		}
 	}
 
 	return 0
@@ -250,8 +253,11 @@ func (e *EnvItem) GetItemInt64Val() int64 {
 		e.getCurrentValue()
 	}
 
-	if v, ok := e.Value.(int64); ok {
-		return v
+	switch e.Value.(type) {
+	case string:
+		if v, e := strconv.ParseInt(e.Value.(string), 10, 64); e == nil {
+			return v
+		}
 	}
 
 	return 0

+ 4 - 2
common/envitem/func_test.go

@@ -52,9 +52,11 @@ func TestMultiEnvItem_FillCurrentValue2(t *testing.T) {
 		_ = multiEnvItems.FillCurrentValue()
 		time.Sleep(2 * time.Second)
 
-		ms := multiEnvItems.FindString()
+		//ms := multiEnvItems.FindString()
 
-		t.Logf("%+v", ms)
+		t.Logf("%+v", multiEnvItems)
+
+		t.Logf("step: %d", multiEnvItems.GetItemInt64Value("step"))
 		//early := checkEarly(multiEnvItems.GetItemFloat64Value("Display_Time"), multiEnvItems.GetItemFloat64Value("Filter_Time_Set"), multiEnvItems.GetItemStringValue("Step"))
 		//advanced := checkAdvanced(multiEnvItems.GetItemFloat64Value("Display_Time"), multiEnvItems.GetItemFloat64Value("Filter_Time_Set"), multiEnvItems.GetItemStringValue("Step"))
 		//