using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WIDESEAWCS_Core;
using WIDESEAWCS_Core.Helper;
using WIDESEAWCS_Model.Models;
namespace WIDESEAWCS_DTO.WMSInfo
{
public class RequestWMS
{
private static DateTime _BeginDate;
private static DateTime _EndDate;
///
/// 向WMS申请并记录日志
///
/// 请求地址
/// 请求参数
///
///
///
///
public static WebResponseContent PostWMSLog(string serviceAddress, string requestJson = null, string Remark = null, string contentType = "application/json", Dictionary? headers = null)
{
WebResponseContent content = new WebResponseContent();
Stopwatch stopwatch = new Stopwatch();
int taskSeconds = 0;
try
{
stopwatch.Start();
_BeginDate = DateTime.Now;
var ResultData = HttpHelper.PostAsync(serviceAddress, requestJson, contentType, headers);
stopwatch.Stop();
_EndDate = DateTime.Now;
if (ResultData.Result == null) throw new Exception($"{Remark}响应异常");
content = JsonConvert.DeserializeObject(ResultData.Result);
}
catch (Exception ex)
{
content.Error(ex.Message);
}
finally
{
taskSeconds = (int)Math.Round(stopwatch.Elapsed.TotalSeconds);
Dt_Interfacerecord interfacerecord = new Dt_Interfacerecord()
{
Request = "WCS",
RequestParam = requestJson,
Response = "WMS",
ResponseParam = content.ToJson(),
Success = content.Status ? 1 : 2,
BeginDate = _BeginDate,
ElapsedTime = taskSeconds,
EndDate = _EndDate,
Url = serviceAddress,
};
}
return content;
}
}
}