using Cksoft.Data; using Cksoft.Data.Repository; using Cksoft.Unity.Log4NetConfig; using DllEapEntity; using DllEapEntity.OFILM; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Logging; using Newtonsoft.Json; using System; using System.Collections.Generic; using System.Linq; using System.Net; using System.Net.Http; using System.Text; using System.Threading.Tasks; namespace DllEapDal.OFILM { public class Parameter { public IConfiguration Configuration { get; set; } private ILogger myloger = null; public async Task GetParams(MacInfo m) { try { string url = "http://192.168.124.93:8606/eap/api/equipment/getOriginEquipmentParams"; HttpClient client = new HttpClient(new HttpClientHandler { AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate }); client.DefaultRequestHeaders.Add("Method", "POST"); client.DefaultRequestHeaders.Add("ContentType", "multipart/form-data; charset=utf-8"); var content = new MultipartFormDataContent(); var uri = new Uri(url); var equipmentId = new ByteArrayContent(Encoding.UTF8.GetBytes(m.EquipmentID)); content.Add(equipmentId, "EquipmentID"); for (int i = 0; i < m.parameters.Count(); i++) { var temp = new ByteArrayContent(Encoding.UTF8.GetBytes(m.parameters.ElementAt(i))); content.Add(temp, $"ParamsList[{i}]"); } client.Timeout = new TimeSpan(0, 0, 600); var result = await client.PostAsync(uri, content); if (result != null && result.IsSuccessStatusCode) { var bytes = result.Content.ReadAsByteArrayAsync().Result; return Deal(Encoding.UTF8.GetString(bytes), m); } return "请求超时"; } catch (Exception ex) { return "请求超时" + ex; } } private object Deal(string str, MacInfo m) { SampleRes s = JsonConvert.DeserializeObject(str); LogHelper.LogInfo(JsonConvert.SerializeObject(s), null, null); if (s.code=="ok") { switch (m.Pcode) { case "AA": return AASetdata(s, m); case "LHA": return LHASetdata(s, m); default: break; } } return "采集失败"; } private object LHASetdata(SampleRes s, MacInfo m) { LHAParameters LHA = new LHAParameters() { MacId = m.MacId, RecTime=DateTime.Now, RecCode="自动采集" }; foreach (var item in s.data.parameters) { switch (item.paramName) { case "19": LHA.Type = item.paramValue; break; case "1071": LHA.EW1_DspPressure = item.paramValue; break; case "1101": LHA.EW2_DspPressure = item.paramValue; break; case "1090": LHA.AEW1_DspPressure = item.paramValue; break; case "1060": LHA.AEW2_DspPressure = item.paramValue; break; default: break; } } using(IDatabase db = DbFactory.Base("eap")) { return db.InsertFor(LHA, "自动采集"); } } private object AASetdata(SampleRes s, MacInfo m) { AAParameters AA = new AAParameters() { MacId = m.MacId, RecTime = DateTime.Now, RecCode = "自动采集" }; foreach (var item in s.data.parameters) { switch (item.paramName) { case "19": AA.Type = item.paramValue; break; case "4002": AA.EW1_DspPressure = item.paramValue; break; case "4102": AA.EW2_DspPressure = item.paramValue; break; case "4202": AA.EW3_DspPressure = item.paramValue; break; case "4302": AA.EW4_DspPressure = item.paramValue; break; default: break; } } using (IDatabase db = DbFactory.Base("eap")) { return db.InsertFor(AA, "自动采集"); } } } }