using Autofac.Core;
using Newtonsoft.Json;
using Newtonsoft.Json.Serialization;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection.Metadata;
using System.Text;
using System.Threading.Tasks;
using WIDESEA_Common.Log;
using WIDESEAWCS_Common.APIEnum;
using WIDESEAWCS_Common.TaskEnum;
using WIDESEAWCS_Core;
using WIDESEAWCS_Core.Helper;
using WIDESEAWCS_DTO.Agv;
using WIDESEAWCS_DTO.TaskInfo;
using WIDESEAWCS_Model.Models;
namespace WIDESEAWCS_TaskInfoService
{
public partial class TaskService
{
// 创建一个使用小驼峰命名法的序列化设置
JsonSerializerSettings settings = new JsonSerializerSettings
{
ContractResolver = new CamelCasePropertyNamesContractResolver()
};
///
/// AGV任务发送
///
///
public WebResponseContent AgvSendTask(AgvTaskSendDTO taskModel, APIEnum SendTask = APIEnum.AgvSendTask)
{
WebResponseContent content = new WebResponseContent();
try
{
string? apiAddress = _apiInfoRepository.QueryFirst(x => x.ApiCode == SendTask.ToString())?.ApiAddress;
if (string.IsNullOrEmpty(apiAddress)) throw new Exception($"未找到发送AGV任务接口,请检查接口配置");
string request = JsonConvert.SerializeObject(taskModel, settings);
string response = HttpHelper.Post(apiAddress, request);
WriteLog.Write_Log("AGV入库任务下发", "出库任务下发接口", "请求任务", $"请求:{request},回传:{response}");
AgvResponseContent agvContent = response.DeserializeObject() ?? throw new Exception("AGV任务发送未返回结果");
if (agvContent.Success)
{
content.OK();
}
else
{
content.Error(agvContent.Message);
}
}
catch (Exception ex)
{
content.Error(ex.Message);
}
return content;
}
public WebResponseContent AgvCancelTask(AgvTaskCancelDTO taskModel, APIEnum SendTask = APIEnum.AgvTaskCancel)
{
WebResponseContent content = new WebResponseContent();
try
{
string? apiAddress = _apiInfoRepository.QueryFirst(x => x.ApiCode == SendTask.ToString())?.ApiAddress;
if (string.IsNullOrEmpty(apiAddress)) throw new Exception($"未找到发送AGV任务接口,请检查接口配置");
string request = JsonConvert.SerializeObject(taskModel, settings);
string response = HttpHelper.Post(apiAddress, request);
AgvResponseContent agvContent = response.DeserializeObject() ?? throw new Exception("AGV任务发送未返回结果");
if (agvContent.Success)
{
content.OK();
}
else
{
content.Error(agvContent.Message);
}
}
catch (Exception ex)
{
content.Error(ex.Message);
}
return content;
}
}
}