123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234 |
- using Newtonsoft.Json;
- using Newtonsoft.Json.Linq;
- using Ropin.Inspection.Common.Helper;
- using Ropin.Inspection.Model;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Net.Http;
- using System.Text;
- using System.Threading.Tasks;
- using Microsoft.AspNetCore.NodeServices;
- using System.Net.Http.Headers;
- using System.Net;
- namespace Ropin.Inspection.Repository
- {
- public class FanyiRepository : IFanyiRepository
- {
- private readonly INodeServices _nodeServices;
- public FanyiRepository(INodeServices nodeServices)
- {
- _nodeServices = nodeServices;
- }
- public async Task<string> GetWebScadaDevSpotHisData(string devId, List<string> names, List<string> groupnames)
- {
- string jResult = String.Empty;
- if (DateTime.Now >= FanyiHelper.tokenTime)
- {
- FanyiHelper.tokenResult = FanyiHelper.GetToken(new AccessUser { client_id = "b19d14eeacb74522bd29627b79c18ab8", client_secret = "7b89e021586c43d3b79440ba6eea0b67" });
- FanyiHelper.tokenTime = DateTime.Now.AddSeconds(7200);
- using (HttpClient client = new HttpClient())
- {
- client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", FanyiHelper.tokenResult.access_token);
- var requestt = new HttpRequestMessage(HttpMethod.Get, "https://fbox360.com/api/client/box/grouped");
- requestt.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
- var response = await client.SendAsync(requestt);
- string result = await response.Content.ReadAsStringAsync();
- if (response.StatusCode != HttpStatusCode.OK)
- {
- }
- else
- {
- //todo
- }
- }
- }
- using (HttpClient client = new HttpClient())
- {
- string[] idarr = { "224872398136431165" };
- string postData = Newtonsoft.Json.JsonConvert.SerializeObject(new
- {
- type = 0,
- ids = idarr,
- g = 0,
- begin = DateTime.Now.AddDays(-5).Ticks,
- end = DateTime.Now.Ticks,
- tr = 3,
- limit = -500,
- tz = "Asia/Shanghai"
- });
- using (var httpClient = new HttpClient())
- {
- httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", FanyiHelper.tokenResult.access_token);
- //httpClient.BaseAddress = new Uri("https://fbox360.com/api/v2/hdata/get");
- httpClient.BaseAddress = new Uri("http://fbhs1.fbox360.com/api/v2/hdata/get");
- //httpClient.BaseAddress = new Uri("http://fbcs101.fbox360.com/api/v2/hdata/get");
- httpClient.DefaultRequestHeaders.Accept.Clear();
- httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
- var jsonString = postData;
- HttpResponseMessage esponse = await httpClient.PostAsync(httpClient.BaseAddress, new StringContent(jsonString, Encoding.UTF8, "application/json"));
- if (esponse.IsSuccessStatusCode)
- {
- string json = await esponse.Content.ReadAsStringAsync();
- List<DeviceVlue> deviceVueList = JsonConvert.DeserializeObject<List<DeviceVlue>>(json);
- }
- }
- return await Task.FromResult(jResult);
- }
- }
- Dictionary<string, DeviceVlue> alarmDic = new Dictionary<string, DeviceVlue>();
- public Dictionary<string, DeviceVlue> msgAlarmDic = new Dictionary<string, DeviceVlue>();
- public async Task<string> GetWebScadaDevSpotValue(string devId, string boxNo, string storeCode, List<string> names, List<string> groupnames, List<string> calFormula, INodeServices services, List<List<CalFormula>> calFormulaList)
- {
- //Dictionary<string, DeviceVlue> msgAlarmDic = new Dictionary<string, DeviceVlue>();
- string jResult = String.Empty;
- if (DateTime.Now >= FanyiHelper.tokenTime)
- {
- FanyiHelper.tokenResult = FanyiHelper.GetToken(new AccessUser { client_id = "b19d14eeacb74522bd29627b79c18ab8", client_secret = "7b89e021586c43d3b79440ba6eea0b67" });
- FanyiHelper.tokenTime = DateTime.Now.AddSeconds(7200);
- using (HttpClient client = new HttpClient())
- {
- client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", FanyiHelper.tokenResult.access_token);
- var requestt = new HttpRequestMessage(HttpMethod.Get, "https://fbox360.com/api/client/box/grouped");
- requestt.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
- var response = await client.SendAsync(requestt);
- string result = await response.Content.ReadAsStringAsync();
- if (response.StatusCode != HttpStatusCode.OK)
- {
- }
- else
- {
- //todo
- }
- }
- }
- using (HttpClient client = new HttpClient())
- {
- string postData = Newtonsoft.Json.JsonConvert.SerializeObject(new
- {
- names = names,
- groupnames = groupnames,
- timeOut = 6000
- });
- using (var httpClient = new HttpClient())
- {
- httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", FanyiHelper.tokenResult.access_token);
- httpClient.BaseAddress = new Uri("http://fbcs101.fbox360.com/api/v2/dmon/value/get?boxNo=" + boxNo);
- httpClient.DefaultRequestHeaders.Accept.Clear();
- httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
- var jsonString = postData;
- HttpResponseMessage esponse = await httpClient.PostAsync(httpClient.BaseAddress, new StringContent(jsonString, Encoding.UTF8, "application/json"));
- if (esponse.IsSuccessStatusCode)
- {
- string json = await esponse.Content.ReadAsStringAsync();
- List<DeviceVlue> deviceVueList = JsonConvert.DeserializeObject<List<DeviceVlue>>(json);
- List<decimal> li1 = new List<decimal>();
- var jarray = new JArray();
- var aljarray = new JArray();
- //aljarray.Add(new JObject { { "colour", "red" } });
- //aljarray.Add(new JObject { { "colour", "green" } });
- //aljarray.Add(new JObject { { "colour", "black" } });
- //aljarray.Add(new JValue("red") );
- //aljarray.Add(new JValue("green"));
- //aljarray.Add(new JValue("black"));
- for (int i = 0; i < deviceVueList.Count; i++)
- {
- if (null == deviceVueList[i])
- continue;
- deviceVueList[i].storeCode = storeCode;
- //JObject HS = new JObject { { "name" + i, deviceVueList[0]?.name }, { "value" + i, deviceVueList[i]?.value.ToString().Split('.')[0]} };
- //JObject HS = new JObject { { "name", deviceVueList[0]?.name }, { "value", deviceVueList[i]?.value.ToString().Split('.')[0] }, { "mix", calFormula?[i].Split(',')?[1] }, { "max", calFormula?[i].Split(',')?[2] } };
- //List<string> args = new List<string>();
- //args.Add(calFormula?[i]?.Split(',')?[1]);
- //args.Add(calFormula?[i]?.Split(',')?[2]);
- //args.Add(deviceVueList[i]?.value.ToString());
- //JObject HS = new JObject { { "name", deviceVueList[i]?.name }, { "value", deviceVueList[i]?.value.ToString().Split('.')[0] } };
- //JObject HS = new JObject { { "name", deviceVueList[i]?.name }, { "value", deviceVueList[i]?.value.ToString().Split('.')[0] }, { "colour", await services.InvokeAsync<string>(calFormula?[i].Split(',')?[0], args)} };
- if (null == calFormulaList)
- {
- JObject HS = new JObject { { "name", deviceVueList[i]?.name }, { "value", deviceVueList[i]?.value.ToString().Split('.')[0] } };
- //HS.Add(jo);
- jarray.Add(HS);
- }
- if (null != calFormulaList)
- if (i < calFormulaList.Count && null != calFormulaList.ElementAt(i))
- {
- foreach (var item in calFormulaList[i])
- {
- List<string> calargs = item.Value.ToList();
- calargs.Add(deviceVueList[i]?.value.ToString());
- //JObject jo = new JObject { item.Name, await services.InvokeAsync<string>("./wwwroot/uploads/scripts/" + item.Name, calargs) };
- bool bAlarm = false;
- if (item.Name == "changecolour")
- {
- string alarmColour = await services.InvokeAsync<string>("./wwwroot/uploads/scripts/" + item.Name, calargs);
- bAlarm = FanyiHelper.AlarmByColour(alarmColour, deviceVueList[i]);
- JObject HS = new JObject { { "name", deviceVueList[i]?.name }, { "value", deviceVueList[i]?.value.ToString().Split('.')[0] }, { item.Name, alarmColour } };
- //HS.Add(jo);
- jarray.Add(HS);
- }
- else if (item.Name == "alarmlight")
- {
- JObject HS = new JObject { { "name", deviceVueList[i]?.name }, { "value", deviceVueList[i]?.value.ToString().Split('.')[0] } };
- //HS.Add(jo);
- jarray.Add(HS);
- string alarmColour = await services.InvokeAsync<string>("./wwwroot/uploads/scripts/" + item.Name, calargs);
- bAlarm = FanyiHelper.AlarmByColour(alarmColour, deviceVueList[i]);
- JObject jo = new JObject { { "alarmcolour", alarmColour } };
- aljarray.Add(jo);
- }
- else if (item.Name == "noformula")
- {
- JObject HS = new JObject { { "name", deviceVueList[i]?.name }, { "value", deviceVueList[i]?.value.ToString().Split('.')[0] } };
- //HS.Add(jo);
- jarray.Add(HS);
- }
- }
- }
- //jarray.Add(HS);
- }
- var deviceJObject = new JObject();
- deviceJObject.Add("device", jarray);
- deviceJObject.Add("alarmlight", aljarray);
- jResult = JsonConvert.SerializeObject(deviceJObject);
- }
- }
- }
- return jResult;
- }
- }
- }
|