Browse Source

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

gaoyagang 1 year ago
parent
commit
303eb1184a

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

@@ -63,9 +63,9 @@ func transDeviceChestData(datas []model.DcDeviceBind) ([]model.DcWorkingChest, e
 			DeviceCode:          data.DeviceCode,
 			Switch:              data.Items.GetItemInt64Value("switch"),
 			Level:               data.Items.GetItemFloat64Value("level"),
-			AgitatorStatus:      data.Items.GetItemInt64Value("level"),
-			AgitatorDuration:    data.Items.GetItemInt64Value("level"),
-			AgitatorFaultStatus: data.Items.GetItemInt64Value("level"),
+			AgitatorStatus:      data.Items.GetItemInt64Value("agitator_status"),
+			AgitatorDuration:    data.Items.GetItemInt64Value("agitator_duration"),
+			AgitatorFaultStatus: data.Items.GetItemInt64Value("agitator_fault_status"),
 			CTime:               time.Now(),
 		}
 	}

+ 27 - 27
app/cmd/organization/internal/logic/handler/nf.go

@@ -62,33 +62,33 @@ func transDeviceNfData(datas []model.DcDeviceBind) ([]model.DcWorkingNf, error)
 			ProjectId:          data.ProjectId,
 			DeviceCode:         data.DeviceCode,
 			WaterTemperature:   data.Items.GetItemFloat64Value("water_temperature"),
-			FeedFlow1St:        data.Items.GetItemFloat64Value("feed_wq_turbidity"),
-			ConFlow1St:         data.Items.GetItemFloat64Value("feed_wq_turbidity"),
-			ProductFlow1St:     data.Items.GetItemFloat64Value("feed_wq_turbidity"),
-			FeedPressure1St:    data.Items.GetItemFloat64Value("feed_wq_turbidity"),
-			ConPressure1St:     data.Items.GetItemFloat64Value("feed_wq_turbidity"),
-			ProductPressure1St: data.Items.GetItemFloat64Value("feed_wq_turbidity"),
-			Tmp1St:             data.Items.GetItemFloat64Value("feed_wq_turbidity"),
-			Flux1St:            data.Items.GetItemFloat64Value("feed_wq_turbidity"),
-			Permeability1St:    data.Items.GetItemFloat64Value("feed_wq_turbidity"),
-			FeedFlow2Nd:        data.Items.GetItemFloat64Value("feed_wq_turbidity"),
-			ConFlow2Nd:         data.Items.GetItemFloat64Value("feed_wq_turbidity"),
-			ProductFlow2Nd:     data.Items.GetItemFloat64Value("feed_wq_turbidity"),
-			FeedPressure2Nd:    data.Items.GetItemFloat64Value("feed_wq_turbidity"),
-			ConPressure2Nd:     data.Items.GetItemFloat64Value("feed_wq_turbidity"),
-			ProductPressure2Nd: data.Items.GetItemFloat64Value("feed_wq_turbidity"),
-			Tmp2Nd:             data.Items.GetItemFloat64Value("feed_wq_turbidity"),
-			Flux2Nd:            data.Items.GetItemFloat64Value("feed_wq_turbidity"),
-			Permeability2Nd:    data.Items.GetItemFloat64Value("feed_wq_turbidity"),
-			FeedFlow3Th:        data.Items.GetItemFloat64Value("feed_wq_turbidity"),
-			ConFlow3Th:         data.Items.GetItemFloat64Value("feed_wq_turbidity"),
-			ProductFlow3Th:     data.Items.GetItemFloat64Value("feed_wq_turbidity"),
-			FeedPressure3Th:    data.Items.GetItemFloat64Value("feed_wq_turbidity"),
-			ConPressure3Th:     data.Items.GetItemFloat64Value("feed_wq_turbidity"),
-			ProductPressure3Th: data.Items.GetItemFloat64Value("feed_wq_turbidity"),
-			Tmp3Th:             data.Items.GetItemFloat64Value("feed_wq_turbidity"),
-			Flux3Th:            data.Items.GetItemFloat64Value("feed_wq_turbidity"),
-			Permeability3Th:    data.Items.GetItemFloat64Value("feed_wq_turbidity"),
+			FeedFlow1St:        data.Items.GetItemFloat64Value("feed_flow_1st"),
+			ConFlow1St:         data.Items.GetItemFloat64Value("con_flow_1st"),
+			ProductFlow1St:     data.Items.GetItemFloat64Value("product_flow_1st"),
+			FeedPressure1St:    data.Items.GetItemFloat64Value("feed_pressure_1st"),
+			ConPressure1St:     data.Items.GetItemFloat64Value("con_pressure_1st"),
+			ProductPressure1St: data.Items.GetItemFloat64Value("product_pressure_1st"),
+			Tmp1St:             data.Items.GetItemFloat64Value("tmp_1st"),
+			Flux1St:            data.Items.GetItemFloat64Value("flux_1st"),
+			Permeability1St:    data.Items.GetItemFloat64Value("permeability_1st"),
+			FeedFlow2Nd:        data.Items.GetItemFloat64Value("feed_flow_2nd"),
+			ConFlow2Nd:         data.Items.GetItemFloat64Value("con_flow_2nd"),
+			ProductFlow2Nd:     data.Items.GetItemFloat64Value("product_flow_2nd"),
+			FeedPressure2Nd:    data.Items.GetItemFloat64Value("feed_pressure_2nd"),
+			ConPressure2Nd:     data.Items.GetItemFloat64Value("con_pressure_2nd"),
+			ProductPressure2Nd: data.Items.GetItemFloat64Value("product_pressure_2nd"),
+			Tmp2Nd:             data.Items.GetItemFloat64Value("tmp_2nd"),
+			Flux2Nd:            data.Items.GetItemFloat64Value("flux_2nd"),
+			Permeability2Nd:    data.Items.GetItemFloat64Value("permeability_2nd"),
+			FeedFlow3Th:        data.Items.GetItemFloat64Value("feed_flow_3th"),
+			ConFlow3Th:         data.Items.GetItemFloat64Value("con_flow_3th"),
+			ProductFlow3Th:     data.Items.GetItemFloat64Value("product_flow_3th"),
+			FeedPressure3Th:    data.Items.GetItemFloat64Value("feed_pressure_3th"),
+			ConPressure3Th:     data.Items.GetItemFloat64Value("con_pressure_3th"),
+			ProductPressure3Th: data.Items.GetItemFloat64Value("product_pressure_3th"),
+			Tmp3Th:             data.Items.GetItemFloat64Value("tmp_3th"),
+			Flux3Th:            data.Items.GetItemFloat64Value("flux_3th"),
+			Permeability3Th:    data.Items.GetItemFloat64Value("permeability_3th"),
 			FeedWqTurbidity:    data.Items.GetItemFloat64Value("feed_wq_turbidity"),
 			FeedWqPh:           data.Items.GetItemInt64Value("feed_wq_ph"),
 			ProductWqPh:        data.Items.GetItemInt64Value("product_wq_ph"),

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

@@ -60,15 +60,15 @@ func transDevicePumpData(datas []model.DcDeviceBind) ([]model.DcWorkingPump, err
 		ts[i] = model.DcWorkingPump{
 			ProjectId:    data.ProjectId,
 			DeviceCode:   data.DeviceCode,
-			FeedPressure: data.Items.GetItemFloat64Value("FeedPressure"),
-			OutPressure:  data.Items.GetItemFloat64Value("FeedPressure"),
-			Duration:     data.Items.GetItemInt64Value("FeedPressure"),
-			Current:      data.Items.GetItemFloat64Value("FeedPressure"),
-			Frequency:    data.Items.GetItemFloat64Value("FeedPressure"),
-			Lift:         data.Items.GetItemFloat64Value("FeedPressure"),
-			Efficiency:   data.Items.GetItemFloat64Value("FeedPressure"),
-			RunStatus:    data.Items.GetItemInt64Value("FeedPressure"),
-			FaultStatus:  data.Items.GetItemInt64Value("FeedPressure"),
+			FeedPressure: data.Items.GetItemFloat64Value("feed_pressure"),
+			OutPressure:  data.Items.GetItemFloat64Value("out_pressure"),
+			Duration:     data.Items.GetItemInt64Value("duration"),
+			Current:      data.Items.GetItemFloat64Value("current"),
+			Frequency:    data.Items.GetItemFloat64Value("frequency"),
+			Lift:         data.Items.GetItemFloat64Value("lift"),
+			Efficiency:   data.Items.GetItemFloat64Value("efficiency"),
+			RunStatus:    data.Items.GetItemInt64Value("run_status"),
+			FaultStatus:  data.Items.GetItemInt64Value("fault_status"),
 			CTime:        time.Now(),
 		}
 	}

+ 27 - 27
app/cmd/organization/internal/logic/handler/ro.go

@@ -62,33 +62,33 @@ func transDeviceRoData(datas []model.DcDeviceBind) ([]model.DcWorkingRo, error)
 			ProjectId:          data.ProjectId,
 			DeviceCode:         data.DeviceCode,
 			WaterTemperature:   data.Items.GetItemFloat64Value("water_temperature"),
-			FeedFlow1St:        data.Items.GetItemFloat64Value("water_temperature"),
-			ConFlow1St:         data.Items.GetItemFloat64Value("water_temperature"),
-			ProductFlow1St:     data.Items.GetItemFloat64Value("water_temperature"),
-			FeedPressure1St:    data.Items.GetItemFloat64Value("water_temperature"),
-			ConPressure1St:     data.Items.GetItemFloat64Value("water_temperature"),
-			ProductPressure1St: data.Items.GetItemFloat64Value("water_temperature"),
-			Tmp1St:             data.Items.GetItemFloat64Value("water_temperature"),
-			Flux1St:            data.Items.GetItemFloat64Value("water_temperature"),
-			Permeability1St:    data.Items.GetItemFloat64Value("water_temperature"),
-			FeedFlow2Nd:        data.Items.GetItemFloat64Value("water_temperature"),
-			ConFlow2Nd:         data.Items.GetItemFloat64Value("water_temperature"),
-			ProductFlow2Nd:     data.Items.GetItemFloat64Value("water_temperature"),
-			FeedPressure2Nd:    data.Items.GetItemFloat64Value("water_temperature"),
-			ConPressure2Nd:     data.Items.GetItemFloat64Value("water_temperature"),
-			ProductPressure2Nd: data.Items.GetItemFloat64Value("water_temperature"),
-			Tmp2Nd:             data.Items.GetItemFloat64Value("water_temperature"),
-			Flux2Nd:            data.Items.GetItemFloat64Value("water_temperature"),
-			Permeability2Nd:    data.Items.GetItemFloat64Value("water_temperature"),
-			FeedFlow3Th:        data.Items.GetItemFloat64Value("water_temperature"),
-			ConFlow3Th:         data.Items.GetItemFloat64Value("water_temperature"),
-			ProductFlow3Th:     data.Items.GetItemFloat64Value("water_temperature"),
-			FeedPressure3Th:    data.Items.GetItemFloat64Value("water_temperature"),
-			ConPressure3Th:     data.Items.GetItemFloat64Value("water_temperature"),
-			ProductPressure3Th: data.Items.GetItemFloat64Value("water_temperature"),
-			Tmp3Th:             data.Items.GetItemFloat64Value("water_temperature"),
-			Flux3Th:            data.Items.GetItemFloat64Value("water_temperature"),
-			Permeability3Th:    data.Items.GetItemFloat64Value("water_temperature"),
+			FeedFlow1St:        data.Items.GetItemFloat64Value("feed_flow_1st"),
+			ConFlow1St:         data.Items.GetItemFloat64Value("con_flow_1st"),
+			ProductFlow1St:     data.Items.GetItemFloat64Value("product_flow_1st"),
+			FeedPressure1St:    data.Items.GetItemFloat64Value("feed_pressure_1st"),
+			ConPressure1St:     data.Items.GetItemFloat64Value("con_pressure_1st"),
+			ProductPressure1St: data.Items.GetItemFloat64Value("product_pressure_1st"),
+			Tmp1St:             data.Items.GetItemFloat64Value("tmp_1st"),
+			Flux1St:            data.Items.GetItemFloat64Value("flux_1st"),
+			Permeability1St:    data.Items.GetItemFloat64Value("permeability_1st"),
+			FeedFlow2Nd:        data.Items.GetItemFloat64Value("feed_flow_2nd"),
+			ConFlow2Nd:         data.Items.GetItemFloat64Value("con_flow_2nd"),
+			ProductFlow2Nd:     data.Items.GetItemFloat64Value("product_flow_2nd"),
+			FeedPressure2Nd:    data.Items.GetItemFloat64Value("feed_pressure_2nd"),
+			ConPressure2Nd:     data.Items.GetItemFloat64Value("con_pressure_2nd"),
+			ProductPressure2Nd: data.Items.GetItemFloat64Value("product_pressure_2nd"),
+			Tmp2Nd:             data.Items.GetItemFloat64Value("tmp_2nd"),
+			Flux2Nd:            data.Items.GetItemFloat64Value("flux_2nd"),
+			Permeability2Nd:    data.Items.GetItemFloat64Value("permeability_2nd"),
+			FeedFlow3Th:        data.Items.GetItemFloat64Value("feed_flow_3th"),
+			ConFlow3Th:         data.Items.GetItemFloat64Value("con_flow_3th"),
+			ProductFlow3Th:     data.Items.GetItemFloat64Value("product_flow_3th"),
+			FeedPressure3Th:    data.Items.GetItemFloat64Value("feed_pressure_3th"),
+			ConPressure3Th:     data.Items.GetItemFloat64Value("con_pressure_3th"),
+			ProductPressure3Th: data.Items.GetItemFloat64Value("product_pressure_3th"),
+			Tmp3Th:             data.Items.GetItemFloat64Value("tmp_3th"),
+			Flux3Th:            data.Items.GetItemFloat64Value("flux_3th"),
+			Permeability3Th:    data.Items.GetItemFloat64Value("permeability_3th"),
 			FeedWqTurbidity:    data.Items.GetItemFloat64Value("feed_wq_turbidity"),
 			FeedWqPh:           data.Items.GetItemInt64Value("feed_wq_ph"),
 			ProductWqPh:        data.Items.GetItemInt64Value("product_wq_ph"),

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

@@ -61,10 +61,10 @@ func transDeviceValveData(datas []model.DcDeviceBind) ([]model.DcWorkingValve, e
 			ProjectId:   data.ProjectId,
 			DeviceCode:  data.DeviceCode,
 			Adjust:      data.Items.GetItemInt64Value("adjust"),
-			Opening:     data.Items.GetItemFloat64Value("adjust"),
-			Closed:      data.Items.GetItemInt64Value("adjust"),
-			Opened:      data.Items.GetItemInt64Value("adjust"),
-			FaultStatus: data.Items.GetItemInt64Value("adjust"),
+			Opening:     data.Items.GetItemFloat64Value("opening"),
+			Closed:      data.Items.GetItemInt64Value("closed"),
+			Opened:      data.Items.GetItemInt64Value("opened"),
+			FaultStatus: data.Items.GetItemInt64Value("fault_status"),
 			CTime:       time.Now(),
 		}
 	}

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

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

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

@@ -50,7 +50,7 @@ func main() {
 			defer func() {
 				fmt.Print("async organization job stop.....\n")
 			}()
-			j := job.NewJob(1, "organization", ctx, handler.DeviceHandlerTable, handler.DeviceIntervalTable)
+			j := job.NewJob(1, "organization-"+c.Mode, ctx, handler.DeviceHandlerTable, handler.DeviceIntervalTable)
 			j.Run()
 		}()
 	}

+ 7 - 0
common/envitem/func.go

@@ -78,6 +78,13 @@ func (m MultiEnvItem) GetItemStringValue(key string) string {
 	return ""
 }
 
+func (m MultiEnvItem) GetItemHtime(key string) *time.Time {
+	if envItem, ok := m[key]; ok {
+		return envItem.GetItemHtime()
+	}
+	return nil
+}
+
 func (m MultiEnvItem) FindString() map[string]string {
 	a := make(map[string]string)
 	for _, item := range m {

+ 25 - 6
common/envitem/func_test.go

@@ -3,6 +3,7 @@ package envitem
 import (
 	"encoding/json"
 	"testing"
+	"time"
 )
 
 func TestEnvItem_GetCurrentData(t *testing.T) {
@@ -40,18 +41,36 @@ func TestMultiEnvItem_FillCurrentValue(t *testing.T) {
 
 func TestMultiEnvItem_FillCurrentValue2(t *testing.T) {
 	SetOptions(Options{GtServerIp: "47.96.12.136:8788"})
-	js := `{"tmp":{"project_id":92,"item":"C.M.UF2_DB@press_PV"},"feed_flow":{"project_id":92,"item":"C.M.UF2_FT_JS@out"},"feed_pressure":{"project_id":92,"item":"C.M.UF2_PT_JS@out"},"product_pressure":{"project_id":92,"item":"C.M.UF2_PT_CS@out"},"feed_wq_turbidity":{"project_id":92,"item":"C.M.UF_Tur_ZJS@out"},"water_temperature":{"project_id":92,"item":"C.M.RO_TT_ZJS@out"},"product_wq_ph":{"project_id":92,"item":"C.M.UF_PH_ZCS@out"}}`
+	js := `{"tmp":{"project_id":92,"device_code":"UF-4001A","plc_device_id":"0","item":"C.M.UF1_DB@press_PV","default_val":0},"feed_flow":{"project_id":92,"device_code":"UF-4001A","plc_device_id":"0","item":"C.M.UF1_FT_JS@out","default_val":0},"feed_pressure":{"project_id":92,"device_code":"UF-4001A","plc_device_id":"0","item":"C.M.UF1_PT_JS@out","default_val":0},"product_pressure":{"project_id":92,"device_code":"UF-4001A","plc_device_id":"0","item":"C.M.UF1_PT_CS@out","default_val":0},"feed_wq_turbidity":{"project_id":92,"device_code":"AIT-94061","plc_device_id":"0","item":"C.M.UF_Tur_ZJS@out","default_val":0},"water_temperature":{"project_id":92,"device_code":"TIT-34061","plc_device_id":"0","item":"C.M.RO_TT_ZJS@out","default_val":0},"product_wq_ph":{"project_id":92,"device_code":"AIT-95065b","plc_device_id":"0","item":"C.M.UF_PH_ZCS@out","default_val":0},"step":{"project_id":92,"device_code":"HB","plc_device_id":"0","item":"C.M.UF1_DB@word_control","default_val":0}}`
 	var multiEnvItems MultiEnvItem
 
-	json.Unmarshal([]byte(js), &multiEnvItems)
+	_ = json.Unmarshal([]byte(js), &multiEnvItems)
 
 	t.Log(multiEnvItems)
 
-	err := multiEnvItems.FillCurrentValue()
-	t.Log(err)
+	for {
+		_ = multiEnvItems.FillCurrentValue()
+		time.Sleep(2 * time.Second)
 
-	for s, item := range multiEnvItems {
-		t.Logf("item: %s value: %s htime: %s", s, item.Value, item.Htime)
+		ms := multiEnvItems.FindString()
+
+		t.Logf("%+v", ms)
+		//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"))
+		//
+		//t.Logf("early: %v, advanced: %v, step: %s filterNumber: %s Display_Time: %s Filter_Time_Set: %s", early, advanced, multiEnvItems.GetItemStringValue("Step"), multiEnvItems.GetItemStringValue("Filter_Number"), multiEnvItems.GetItemStringValue("Display_Time"), multiEnvItems.GetItemStringValue("Filter_Time_Set"))
+		//t.Log(err)
+		//for s, item := range multiEnvItems {
+		//	t.Logf("item: %s value: %s htime: %s", s, item.Value, item.Htime)
+		//}
 	}
 
 }
+
+func checkEarly(ft, fst float64, step string) bool {
+	return step == "26" && ft >= 360 && ft <= 660
+}
+
+func checkAdvanced(ft, fst float64, step string) bool {
+	return step == "26" && ft+360 >= fst && ft+60 <= fst
+}

+ 51 - 0
deploy/test.sh

@@ -0,0 +1,51 @@
+#!/usr/bin/env bash
+# 发布测试服务到测试机器
+# 机器: 192.168.60.201
+# 账号: gaoyagang 互信已添加
+user="gt"
+target="192.168.60.201"
+
+# 编译
+build () {
+    echo ${1}
+
+    echo "build for ${1}"
+    rm -f ${1}
+    GOOS=linux GOARCH=amd64 go build -o ${1} app/cmd/${1}/${1}.go
+    # shellcheck disable=SC2181
+    if [ "$?" != "0" ]; then
+        exit $?
+    fi
+}
+
+# 上传
+upload () {
+    echo "start upload ${1}..."
+    rsync -av ./${1} ${user}@${target}:/home/${user}/${1}
+
+    if [ "$?" != "0" ]; then
+        exit $?
+    fi
+}
+
+# 清理中间资源
+clear () {
+    rm -rf ${1}
+}
+
+# 重启服务
+restart () {
+    echo "restart ${1} and wait 2 seconds..."
+    sleep 2
+    ssh ${user}@${target} supervisorctl restart ${1}
+}
+
+deploy () {
+    build $1;
+
+    upload $1;
+
+    restart $1;
+}
+
+deploy 'organization'