ningshuxia
2022-12-12 e81ca048ef4e9345e904b74ffffd3e8413d18a7e
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
using IStation.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
namespace IStation.DataDockingApi
{
    public class HandleHelper : IDataDockingApi.IHandleHelper
    {
        public void HandleData(List<DataDockingConfigure.Mapper> mappers, Action<List<Model.MonitorDataDockingReceiveRecord>> receive)
        {
            if (mappers == null || mappers.Count < 1)
                return;
            var appParas = AppParasHelper.Get();
            if (appParas == null)
            {
                LogHelper.Error("宝山航务 Api 数据对接中,缺少对接配置文件");
                return;
            }
            var token = "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJleHAiOjE2MjcyNTMyOTYsInVzZXJuYW1lIjoiYmdqIn0.aj6nIng4R00QEiF5-HoA1qfBcQwXXZCmP0Dspl-1giw";
            if (appParas.verify)
            {
                token = TokenHelper.Get();
                if (string.IsNullOrEmpty(token))
                {
                    LogHelper.Error("宝山航务 Api 数据对接中,获取Token失败");
                    return;
                }
            }
            var responseText = HttpRequestHelper.Get(appParas.url.data, token);
            var result = JsonHelper.Json2Object<Result<Record>>(responseText);
            if (result.code != 0)
            {
                LogHelper.Info("宝山航务 Api 数据对接中,获取实时数据失败(code !=0)");
                return;
            }
            var apiModel = GetData(result.data);
            if (apiModel == null || apiModel.Count < 1)
            {
                LogHelper.Info("宝山航务 Api 数据对接中,获取实时数据失败(数据为空)");
                return;
            }
 
 
            var record_receive_list = new List<Model.MonitorDataDockingReceiveRecord>();
            foreach (var mapper in mappers)
            {
                var src = apiModel.Find(x => x.tagName == mapper.SignId);
                if (src != null)
                {
                    var record = new Model.MonitorDataDockingReceiveRecord();
                    record.SysId = mapper.SysId;
                    record.RecordType = eMonitorType.General;
                    record.SrcTime = src.time;
                    record.SrcValue = src.value.ToString();
                    record_receive_list.Add(record);
                }
            }
            receive(record_receive_list);
 
            if (appParas.src)
            {
                SrcHelper.Src(responseText);
            }
            if (appParas.debug)
            {
                DebugHelper.Debug(apiModel);
            }
        }
 
        //获取数据
        private List<BaseValue> GetData(Record data)
        {
            var list = new List<BaseValue>();
            if (data.@base != null && data.@base.Count > 0)
                list.AddRange(data.@base);
 
            if (data.beng != null && data.beng.Count > 0)
                foreach (var item in data.beng)
                {
                    if (item.status != null)
                        list.Add(item.status);
                    if (item.dataList != null && item.dataList.Count > 0)
                        list.AddRange(item.dataList);
                }
 
            if (data.bianpin != null && data.bianpin.Count > 0)
                foreach (var item in data.bianpin)
                {
                    if (item.status != null)
                        list.Add(item.status);
                    if (item.dataList != null && item.dataList.Count > 0)
                        list.AddRange(item.dataList);
                }
 
            if (data.kongyuan != null && data.kongyuan.Count > 0)
                foreach (var item in data.kongyuan)
                    if (item.dataList != null && item.dataList.Count > 0)
                        list.AddRange(item.dataList);
 
            if (data.error != null && data.error.Count > 0)
                list.AddRange(data.error);
 
            if (data.other != null && data.other.Count > 0)
                list.AddRange(data.other);
 
            return list;
        }
    }
 
}