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 mappers, Action> receive) { if (mappers == null || mappers.Count < 1) return; var appParas = AppParasHelper.Get(); if (appParas == null) { LogHelper.Error("YS 中间库数据对接中,缺少对接配置文件!"); return; } List> 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).ToList(); } if (dynamic_list != null && dynamic_list.Count > 0) { var receiveList = new List(); 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; } }