using DS.Module.Core; using DS.Module.Core.Extensions; using Microsoft.Extensions.DependencyInjection; using Newtonsoft.Json; using NLog; namespace DS.Module.DjyServiceStatus { /// /// /// public class DjyServiceStatusService: IDjyServiceStatusService { private readonly IServiceProvider _serviceProvider; private readonly string ip; private readonly int port; private readonly string accessKey; private readonly string accessSecret; private readonly string saveServiceProjectUrl; private readonly string cancelServiceProjectUrl; private readonly string getServiceProjectListUrl; private readonly string getServiceStatusListUrl; private readonly string saveServiceStatusUrl; private readonly string cancelServiceStatusUrl; private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); /// /// 构造函数 /// /// public DjyServiceStatusService(IServiceProvider serviceProvider) { _serviceProvider = serviceProvider; ip = AppSetting.app(new string[] { "DjyService", "IP" }).ObjToString(); port = AppSetting.app(new string[] { "DjyService", "Port" }).ToInt(); accessKey = AppSetting.app(new string[] { "DjyService", "AccessKey" }).ObjToString(); accessSecret = AppSetting.app(new string[] { "DjyService", "AccessSecret" }).ObjToString(); saveServiceProjectUrl = AppSetting.app(new string[] { "DjyService", "SaveServiceProjectUrl" }).ObjToString(); cancelServiceProjectUrl = AppSetting.app(new string[] { "DjyService", "CancelServiceProjectUrl" }).ObjToString(); getServiceProjectListUrl = AppSetting.app(new string[] { "DjyService", "GetServiceProjectListUrl" }).ObjToString(); getServiceStatusListUrl = AppSetting.app(new string[] { "DjyService", "GetServiceStatusListUrl" }).ObjToString(); saveServiceStatusUrl = AppSetting.app(new string[] { "DjyService", "SaveServiceStatusUrl" }).ObjToString(); cancelServiceStatusUrl = AppSetting.app(new string[] { "DjyService", "CancelServiceStatusUrl" }).ObjToString(); } /// /// 保存服务状态 /// /// 修改服务状态详情 /// 返回回执 public async Task SaveServiceProject(EmbedServiceProjectDto req) { // 只要平台信息参数一致,多个请求只需设置一次参数 DjyHttpUtillib.SetPlatformInfo(accessKey, accessSecret, ip, port, false); // 发起POST请求,超时时间15秒,返回响应字节数组 string result = DjyHttpUtillib.HttpPost(saveServiceProjectUrl, JsonConvert.SerializeObject(req), 30); if (null == result) { return await Task.FromResult(TaskManageOrderResultDto.Failed("请求失败,请联系管理员")); } else { var res = JsonConvert.DeserializeObject(result); // Console.WriteLine(System.Text.Encoding.UTF8.GetString(result)); return await Task.FromResult(res); } } /// /// 取消服务状态 /// /// 修改服务状态详情 /// 返回回执 public async Task CancelServiceProject(EmbedServiceProjectDto req) { // 只要平台信息参数一致,多个请求只需设置一次参数 DjyHttpUtillib.SetPlatformInfo(accessKey, accessSecret, ip, port, false); // 发起POST请求,超时时间15秒,返回响应字节数组 string result = DjyHttpUtillib.HttpPost(cancelServiceProjectUrl, JsonConvert.SerializeObject(req), 30); if (null == result) { return await Task.FromResult(TaskManageOrderResultDto.Failed("请求失败,请联系管理员")); } else { var res = JsonConvert.DeserializeObject(result); // Console.WriteLine(System.Text.Encoding.UTF8.GetString(result)); return await Task.FromResult(res); } } /// /// 获取服务项目列表 /// /// 查询服务项目和状态详情 /// 返回回执 public async Task GetServiceProjectList(EmbedQueryServiceProjectWithStatus req) { // 只要平台信息参数一致,多个请求只需设置一次参数 DjyHttpUtillib.SetPlatformInfo(accessKey, accessSecret, ip, port, false); // 发起POST请求,超时时间15秒,返回响应字节数组 string result = DjyHttpUtillib.HttpPost(getServiceProjectListUrl, JsonConvert.SerializeObject(req), 30); if (null == result) { return await Task.FromResult(TaskManageOrderResultDto.Failed("请求失败,请联系管理员")); } else { var res = JsonConvert.DeserializeObject(result); // Console.WriteLine(System.Text.Encoding.UTF8.GetString(result)); return await Task.FromResult(res); } } /// /// 获取服务项目下的状态列表 /// /// 查询服务项目和状态详情 /// 返回回执 public async Task GetServiceStatusList(EmbedQueryServiceProjectWithStatus req) { // 只要平台信息参数一致,多个请求只需设置一次参数 DjyHttpUtillib.SetPlatformInfo(accessKey, accessSecret, ip, port, false); // 发起POST请求,超时时间15秒,返回响应字节数组 string result = DjyHttpUtillib.HttpPost(getServiceStatusListUrl, JsonConvert.SerializeObject(req), 30); if (null == result) { return await Task.FromResult(TaskManageOrderResultDto.Failed("请求失败,请联系管理员")); } else { var res = JsonConvert.DeserializeObject(result); // Console.WriteLine(System.Text.Encoding.UTF8.GetString(result)); return await Task.FromResult(res); } } /// /// 保存服务状态 /// /// 修改服务状态详情 /// 返回回执 public async Task SaveServiceStatus(EmbedServiceProjectStatusDto req) { // 只要平台信息参数一致,多个请求只需设置一次参数 DjyHttpUtillib.SetPlatformInfo(accessKey, accessSecret, ip, port, false); // 发起POST请求,超时时间15秒,返回响应字节数组 string result = DjyHttpUtillib.HttpPost(saveServiceStatusUrl, JsonConvert.SerializeObject(req), 30); if (null == result) { return await Task.FromResult(TaskManageOrderResultDto.Failed("请求失败,请联系管理员")); } else { var res = JsonConvert.DeserializeObject(result); // Console.WriteLine(System.Text.Encoding.UTF8.GetString(result)); return await Task.FromResult(res); } } /// /// 取消服务状态 /// /// 修改服务状态详情 /// 返回回执 public async Task CancelServiceStatus(EmbedServiceProjectStatusDto req) { // 只要平台信息参数一致,多个请求只需设置一次参数 DjyHttpUtillib.SetPlatformInfo(accessKey, accessSecret, ip, port, false); // 发起POST请求,超时时间15秒,返回响应字节数组 string result = DjyHttpUtillib.HttpPost(cancelServiceStatusUrl, JsonConvert.SerializeObject(req), 30); if (null == result) { return await Task.FromResult(TaskManageOrderResultDto.Failed("请求失败,请联系管理员")); } else { var res = JsonConvert.DeserializeObject(result); // Console.WriteLine(System.Text.Encoding.UTF8.GetString(result)); return await Task.FromResult(res); } } } }