You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
67 lines
2.6 KiB
67 lines
2.6 KiB
8 months ago
|
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<PatrolClass> dataList = JsonConvert.DeserializeObject<List<PatrolClass>>(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<DayOfWeek> dayOfWeeks = day.DayOfWeeks(item);
|
||
|
var daysOfWeek = new HashSet<DayOfWeek>();
|
||
|
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));
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|