|
|
|
|
using DS.Module.Core;
|
|
|
|
|
using DS.Module.Core.Extensions;
|
|
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
|
using Newtonsoft.Json;
|
|
|
|
|
using NLog;
|
|
|
|
|
|
|
|
|
|
namespace DS.Module.DjyServiceStatus
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
///
|
|
|
|
|
/// </summary>
|
|
|
|
|
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();
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 构造函数
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="serviceProvider"></param>
|
|
|
|
|
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();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 保存服务状态
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="req">修改服务状态详情</param>
|
|
|
|
|
/// <returns>返回回执</returns>
|
|
|
|
|
public async Task<DjyResult> 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(DjyResult.Failed("请求失败,请联系管理员"));
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
var res = JsonConvert.DeserializeObject<DjyResult>(result);
|
|
|
|
|
// Console.WriteLine(System.Text.Encoding.UTF8.GetString(result));
|
|
|
|
|
return await Task.FromResult(res);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 取消服务状态
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="req">修改服务状态详情</param>
|
|
|
|
|
/// <returns>返回回执</returns>
|
|
|
|
|
public async Task<DjyResult> 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(DjyResult.Failed("请求失败,请联系管理员"));
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
var res = JsonConvert.DeserializeObject<DjyResult>(result);
|
|
|
|
|
// Console.WriteLine(System.Text.Encoding.UTF8.GetString(result));
|
|
|
|
|
return await Task.FromResult(res);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 获取服务项目列表
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="req">查询服务项目和状态详情</param>
|
|
|
|
|
/// <returns>返回回执</returns>
|
|
|
|
|
public async Task<DjyResult> 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(DjyResult.Failed("请求失败,请联系管理员"));
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
var res = JsonConvert.DeserializeObject<DjyResult>(result);
|
|
|
|
|
// Console.WriteLine(System.Text.Encoding.UTF8.GetString(result));
|
|
|
|
|
return await Task.FromResult(res);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 获取服务项目下的状态列表
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="req">查询服务项目和状态详情</param>
|
|
|
|
|
/// <returns>返回回执</returns>
|
|
|
|
|
public async Task<DjyResult> 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(DjyResult.Failed("请求失败,请联系管理员"));
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
var res = JsonConvert.DeserializeObject<DjyResult>(result);
|
|
|
|
|
// Console.WriteLine(System.Text.Encoding.UTF8.GetString(result));
|
|
|
|
|
return await Task.FromResult(res);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 保存服务状态
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="req">修改服务状态详情</param>
|
|
|
|
|
/// <returns>返回回执</returns>
|
|
|
|
|
public async Task<DjyResult> 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(DjyResult.Failed("请求失败,请联系管理员"));
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
var res = JsonConvert.DeserializeObject<DjyResult>(result);
|
|
|
|
|
// Console.WriteLine(System.Text.Encoding.UTF8.GetString(result));
|
|
|
|
|
return await Task.FromResult(res);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 取消服务状态
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="req">修改服务状态详情</param>
|
|
|
|
|
/// <returns>返回回执</returns>
|
|
|
|
|
public async Task<DjyResult> 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(DjyResult.Failed("请求失败,请联系管理员"));
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
var res = JsonConvert.DeserializeObject<DjyResult>(result);
|
|
|
|
|
// Console.WriteLine(System.Text.Encoding.UTF8.GetString(result));
|
|
|
|
|
return await Task.FromResult(res);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|