using Newtonsoft.Json; using System; using System.Collections.Generic; using System.Linq; using System.Net.Http; using System.Net.Http.Json; using System.Text; using System.Text.Json; using System.Threading.Tasks; namespace Emergency_platform { public class Patrol { public async void PatrolD() { DAY day = new DAY(); int j = 0; while (true) { using (var httpClient = new HttpClient()) { //发送post请求 var response = await httpClient.GetAsync("http://192.168.10.104:8080/api/Patrol"); if (response.IsSuccessStatusCode) { var responseBody = await response.Content.ReadAsStringAsync(); //Console.WriteLine(responseBody); JsonDocument jsonDocument = JsonDocument.Parse(responseBody); var dataElement = jsonDocument.RootElement.GetProperty("data").ToString(); List dataList = JsonConvert.DeserializeObject>(dataElement); foreach (var item in dataList) { bool state = item.State; //Console.WriteLine(state); if (state == true) { if (item.RunRule == "每日") { await TimedTask.DailyJob(item.StartTime.ToString(), "2,2;3,3;4,4"); } else { j++; List dayOfWeeks = day.DayOfWeeks(item); var daysOfWeek = new HashSet(); foreach (var i in dayOfWeeks) { daysOfWeek.Add(i); } await TimedTask.WeeklyJob(daysOfWeek, item.StartTime.ToString(),j, "2,2;3,3;4,4"); } } } } else { //处理错误响应 Console.WriteLine("请求失败"); } } await Task.Delay(TimeSpan.FromDays(1)); } } } }