lixiaojun
2023-04-12 2be5d90e96f163c67101571f6865b17effcb0f3f
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
using Dapper;
using IStation.Model;
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
namespace IStation.DataDockingMiddleLib
{
    public class HandleHelper : IDataDockingMiddleLib.IHandleHelper
    {
 
        public void HandleData(List<Model.DataDockingConfigure.Mapper> mappers, Action<List<Model.MonitorDataDockingReceiveRecord>> receive)
        {
            if (mappers == null || mappers.Count < 1)
                return;
            var appParas = AppParasHelper.Get();
            if (appParas == null)
            {
                LogHelper.Error("YS 中间库数据对接中,缺少对接配置文件!");
                return;
            }
            List<IDictionary<string, object>> dynamic_list = null;
            using (var conn = new SqlConnection(appParas.ConnectionString))
            {
                conn.Open();
                var strSql = string.Format("SELECT * FROM {0} ", appParas.TableName);
                var list = conn.Query(strSql)?.ToList();
                if (list == null || list.Count < 1)
                    return;
                dynamic_list = list.Select(x => x as IDictionary<string, object>).ToList();
            }
 
            if (dynamic_list != null && dynamic_list.Count > 0)
            {
                var receiveList = new List<Model.MonitorDataDockingReceiveRecord>();
                foreach (var mapper in mappers)
                {
                    var src = dynamic_list.Find(x => x[appParas.SignColumnName]?.ToString() == mapper.SignId);
                    if (src != null)
                    {
                        var record = new Model.MonitorDataDockingReceiveRecord();
                        record.SysId = mapper.SysId;
                        record.RecordType = Model.eMonitorType.General;
                        var srcTime = src[appParas.DataTimeColumnName]?.ToString();
                        if (!string.IsNullOrEmpty(srcTime))
                            record.SrcTime = Convert.ToDateTime(srcTime);
                        record.SrcValue = src[appParas.DataValueColumnName]?.ToString();
                        receiveList.Add(record);
                    }
                }
                receive(receiveList);
            }
 
            if (appParas.Debug)
            {
                DebugHelper.Debug(dynamic_list);
            }
        }
 
        //Data Source =10.197.10.113; Initial Catalog = SCADA_DATA; UID=sa; PWD=p@ssw0rd;
        //server=10.197.10.113;database=SCADA_DATA;integrated security=true;
    }
 
 
}