using System; using System.Collections.Generic; using System.Text; using System.Threading.Tasks; using Microsoft.AspNetCore.Mvc; using Newtonsoft.Json.Linq; using ShowTrend3.Libs; namespace ShowTrend3.Controllers { public class APIController : Controller { [HttpPost] public IActionResult DirBrowse([FromBody] JObject date) { string[] dateArr = date["date"].ToString().Split('-'); DateTime dateRequest = new DateTime(Int32.Parse(dateArr[0]), Int32.Parse(dateArr[1]), Int32.Parse(dateArr[2])); string request = dateArr[0] + "/" + dateArr[1] + "/" + dateArr[2]; NetClient netClient = new NetClient(); Queue dir1 = netClient.DirBrowse(request); Queue dir2 = new Queue(); if (dateRequest.Year == DateTime.Now.Year && dateRequest.Month == DateTime.Now.Month && dateRequest.Day == DateTime.Now.Day) dir2 = netClient.DirBrowse("current"); JArray result = new JArray(); while(dir1.Count != 0) { string r = dir1.Dequeue(); if (string.IsNullOrEmpty(r.Split('.')[0])) continue; string name = r.Split('.')[0]; string[] temp = name.Split('-'); name = temp[1]; for (int j = 2; j < temp.Length; j++) name += "-" + temp[j]; JObject val = new JObject { ["Dir"] = request + "/" + r, ["Name"] = name }; result.Add(val); } List nameTemp = new List(); while(dir2.Count != 0) { string r = dir2.Dequeue(); if (!string.IsNullOrEmpty(r.Split('.')[1])) nameTemp.Add(Int32.Parse(r.Split('.')[1])); } nameTemp.Sort(); for (int i = 0; i < nameTemp.Count; i++) { JObject val = new JObject { ["Dir"] = "current/VDP." + nameTemp[i].ToString().PadLeft(2, '0'), ["Name"] = "Печь №" + nameTemp[i] }; result.Add(val); } return Content(result.ToString()); } [HttpPost] public IActionResult Pasport([FromBody] JObject date) { NetClient netClient = new NetClient(); PasportVDP pasp = netClient.PaspDownload(date["pasport"].ToString()); JObject result = new JObject() { ["have_date"] = pasp.HaveDate, ["have_pasport"] = pasp.HavePasport, ["time_start"] = pasp.TimeStart.ToString(), ["time_end"] = pasp.TimeEnd.ToString() }; if (!pasp.HavePasport) return Content(result.ToString()); result.Add("num_plav", pasp.NPlav); result.Add("splav", pasp.Splav); result.Add("is", pasp._is); result.Add("pereplav", pasp.PrPl); result.Add("naznachenie", pasp.Nazn); result.Add("kategory", pasp.Kat); result.Add("zakaz", pasp.Zakaz); result.Add("ves_slit", pasp.VesSlit); result.Add("kompl", pasp.Kompl); result.Add("diam_krist", pasp.Dkr); result.Add("diam_electr", pasp.Diam); result.Add("num_kontract", pasp.Nkon); result.Add("ukazanie", pasp.Ukaz); result.Add("kod_npl", pasp.KodNPlav.ToString()); result.Add("rm", pasp.RM); result.Add("notd", pasp.Notd.ToString()); result.Add("tin", pasp.Tin); result.Add("dzap", pasp.Dzap); result.Add("dlog", pasp.Dlog.ToString()); result.Add("last", pasp.Last.ToString()); result.Add("dlper", pasp.Dlper.ToString()); result.Add("izl", pasp.Izl.ToString()); result.Add("robm", pasp.Robm.ToString()); result.Add("rizol", pasp.Rizol.ToString()); result.Add("pos", pasp.Pos); result.Add("pril", pasp.Pril); return Content(result.ToString()); } public async Task TechCycle([FromBody] JObject date) { NetClient netClient = new NetClient(); if (!int.TryParse(date["vdp"].ToString(), out int vdp) || !DateTime.TryParse(date["timeStart"].ToString(), out DateTime timeStart) || !DateTime.TryParse(date["timeEnd"].ToString(), out DateTime timeEnd)) return Content("[]"); var techCycle = await netClient.TechCycle(vdp, timeStart, timeEnd); JArray result = new JArray(); foreach (var e in techCycle) { if (e.Key < timeStart || e.Key > timeEnd) continue; var x = new TechCycle(); result.Add(new JObject() { ["date"] = e.Key.ToString(), ["value"] = x.CycleName[e.Value], ["color"] = x.ConvertColorHexToRGB(x.CycleColorHex[e.Value]) }); } return Content(result.ToString()); } [HttpPost] public async Task Analog([FromBody] JObject date) { TempDir.Clear(); NetClient netClient = new NetClient(); if (date.Type != JTokenType.Object || date["vdp"].Type != JTokenType.Integer || date["timeStart"].Type != JTokenType.String || date["timeEnd"].Type != JTokenType.String || date["signals"].Type != JTokenType.Array) return Content("[]"); if (!DateTime.TryParse(date.Value("timeStart"), out DateTime timeStart) || !DateTime.TryParse(date.Value("timeEnd"), out DateTime timeEnd)) return Content("[]"); List vdp = new List { date.Value("vdp") }; if (date.Value("vdp") >= 1 && date.Value("vdp") <= 48) { vdp.Add(49); vdp.Add(0); } StringBuilder res = new StringBuilder(); res.Append("[]"); int correct = 0; for (int i = 0; i < vdp.Count; i++) { int analogLength = new AnalogSignals(vdp[i]).analogs.Count; List signals = new List(); foreach (var e in date["signals"]) if (e.Type == JTokenType.Integer && e.Value() - correct >= 0 && e.Value() - correct < analogLength) signals.Add(e.Value() - correct); var a = await netClient.Analog(vdp[i], timeStart.ToUniversalTime(), timeEnd.ToUniversalTime(), signals.ToArray()); CustomConverters.CompareStringBuilder(ref res, a.ReturnResultJson()); correct += analogLength; } return Content(res.ToString()); } [HttpPost] public IActionResult ListAnalog([FromBody] JObject date) { if (date.Type != JTokenType.Object || date["vdp"].Type != JTokenType.Integer) return Content("[]"); StringBuilder res = new AnalogSignals(date.Value("vdp")).ReturnListJson(); if (date.Value("vdp") >= 1 && date.Value("vdp") <= 48) { CustomConverters.CompareStringBuilder(ref res, new AnalogSignals(49).ReturnListJson()); CustomConverters.CompareStringBuilder(ref res, new AnalogSignals(0).ReturnListJson()); } return Content(res.ToString()); } } }