using DocumentFormat.OpenXml.EMMA; using Elastic.Clients.Elasticsearch; using Furion.Logging; using Furion.RemoteRequest.Extensions; using Newtonsoft.Json; using System.Text; using WCS.Application.Entity; using static SKIT.FlurlHttpClient.Wechat.Api.Models.ComponentTCBBatchCreateContainerServiceVersionResponse.Types; namespace WCS.Application; public class HttpService { private dynamic Urls; private static readonly ISqlSugarClient _db = SqlSugarSetup.ITenant.GetConnectionScope(SqlSugarConst.MainConfigId); public HttpService() { var _sysConfigService = App.GetService();//todo 这里需要测试下生命周期问题 Urls = _sysConfigService.GetSystemInfo().Result; } /// /// 调用WMS接口申请巷道接口 /// /// /// /// /// /// /// /// public string RequestRoadWay(string palletNo, string startLocat, string taskModel, string ceng, ref string endLocat, ref string taskNo) { string returnStr = ""; var task = _db.Queryable().First(m => m.IsDelete == false && (m.Status == TaskStatusEnum.Wait || m.Status == TaskStatusEnum.Doing) && m.TaskType == TaskTypeEnum.In && m.PalletNo == palletNo); if (task == null) { var model = new RequestAsnTask() { PalletNo = palletNo, HouseNo = "W01", TaskModel = taskModel }; string url = Urls.WMSAddress + ":" + Urls.WMSPort; var result = (url + "/api/DownAPi/RequestRoadWay").SetBody(model, "application/json", Encoding.UTF8).PostAsAsync().Result; Log.Information("调用WMS接口反馈任务接口" + result.ToJson()); if (result.Success == 0) { var taskAdd = new WcsTask() { TaskType = TaskTypeEnum.In, Status = TaskStatusEnum.Wait, Origin = "WMS", StartLocate = startLocat, PalletNo = palletNo, TaskNo = result.TaskList.TaskNo, EndLocate = result.TaskList.EndLocate, EndRoadway = result.TaskList.EndRoadway }; _db.Insertable(taskAdd).ExecuteCommand(); endLocat = result.TaskList.EndRoadway; returnStr = result.TaskList.EndLocate; } else { returnStr = "-1:" + result.Message; return returnStr; } } else { returnStr = task.EndLocate; endLocat = task.EndRoadway; taskNo = task.TaskNo; } endLocat = PLCCommon.RoadwayToStationNum(endLocat, ceng); return returnStr; } /// /// 调用WMS接口自动码垛绑定信息返回巷道口 /// /// public string BindRequestRoadWay(string orderNo, string palletNo,decimal qty ,string type,string skuNo, string lotNo, string lotText, string supplierLot, List detail, string startLocat, string taskModel, string ceng, ref string endLocat, ref string taskNo) { string returnStr = ""; var task = _db.Queryable().First(m => m.IsDelete == false && (m.Status == TaskStatusEnum.Wait || m.Status == TaskStatusEnum.Doing) && m.TaskType == TaskTypeEnum.In && m.PalletNo == palletNo); if (task == null) { var model = new BoxPalletBindVm() { OrderCode= "",//暂无上游系统编号 AsnNo= orderNo, AsnDetailNo=0,//暂无入库单明细编号,WMS根据物料批次查找 PalletNo=palletNo, Qty= qty, Type=type, SkuNo=skuNo, LotNo= lotNo, LotText= lotText, SupplierLot= supplierLot, Detail=detail }; string url = Urls.WMSAddress + ":" + Urls.WMSPort; var result = (url + "/api/DownAPi/BindRequestRoadWay").SetBody(model, "application/json", Encoding.UTF8).PostAsAsync().Result; Log.Information("调用WMS接口反馈任务接口" + result.ToJson()); if (result.Success == 0) { var taskAdd = new WcsTask() { TaskType = TaskTypeEnum.In, Status = TaskStatusEnum.Wait, Origin = "WMS", StartLocate = startLocat, PalletNo = palletNo, TaskNo = result.TaskList.TaskNo, EndLocate = result.TaskList.EndLocate, EndRoadway = result.TaskList.EndRoadway }; _db.Insertable(taskAdd).ExecuteCommand(); endLocat = result.TaskList.EndRoadway; returnStr = result.TaskList.EndLocate; } else { returnStr = "-1:" + result.Message; return returnStr; } } else { returnStr = task.EndLocate; endLocat = task.EndRoadway; taskNo = task.TaskNo; } endLocat = PLCCommon.RoadwayToStationNum(endLocat, ceng); return returnStr; } /// /// 调用WMS接口申请储位接口 /// /// /// /// /// /// /// public string RequestLocate(string palletNo, string startLocat, string taskModel, string starRoadWay, ref string taskNo) { string returnStr = ""; var task = _db.Queryable().First(m => m.IsDelete == false && (m.Status == TaskStatusEnum.Wait || m.Status == TaskStatusEnum.Doing) && m.TaskType == TaskTypeEnum.In && m.PalletNo == palletNo && !string.IsNullOrWhiteSpace(m.EndLocate)); if (task == null) { var model = new RequestAsnTask() { PalletNo = palletNo, HouseNo = "W01", RoadWayNo = starRoadWay, TaskModel = taskModel }; string url = Urls.WMSAddress + ":" + Urls.WMSPort; var result = (url + "/api/DownAPi/RequestLocation").SetBody(model, "application/json", Encoding.UTF8).PostAsAsync().Result; Log.Information("调用WMS申请储位接口反馈任务接口" + result.ToJson()); if (result.Success == 0) { var taskUp = _db.Queryable().First(m => m.IsDelete == false && m.TaskNo == result.TaskList.TaskNo); if (taskUp == null) { var taskAdd = new WcsTask() { TaskNo = result.TaskList.TaskNo, TaskType = TaskTypeEnum.In, Status = TaskStatusEnum.Wait, //IsSuccess =TaskSuccessEnum.Success, Origin = "WMS", StartLocate = startLocat, PalletNo = palletNo, EndLocate = result.TaskList.EndLocate, EndRoadway = result.TaskList.EndRoadway }; _db.Insertable(taskAdd).ExecuteCommand(); HubUtil.PublicTask(taskAdd.Adapt()); } else { taskUp.EndRoadway = result.TaskList.EndRoadway; taskUp.EndLocate = result.TaskList.EndLocate; _db.Updateable(taskUp).ExecuteCommand(); HubUtil.PublicTask(taskUp.Adapt()); } returnStr = result.TaskList.EndLocate; taskNo = result.TaskList.TaskNo; } else { returnStr = "-1:" + result.Message; return returnStr; } } else { returnStr = task.EndLocate; taskNo = task.TaskNo; } return returnStr; } /// /// 调用WMS接口 反馈任务接口 /// /// 任务完成状态 /// public async Task RequestTask(TaskRequestWMS model) { string url = Urls.WMSAddress + ":" + Urls.WMSPort; var result = await (url + "/api/DownAPi/ReceiveWcsSignal").SetBody(model, "application/json", Encoding.UTF8).PostAsAsync(); Log.Information("调用WMS接口反馈任务接口" + result.ToJson()); return result; } /// /// 调用WMS接口反馈空取异常接口 /// /// 任务信息 /// public async Task RequestEmptyException(TaskRequest model) { string url = Urls.WMSAddress + ":" + Urls.WMSPort; var result = await (url + "/api/DownAPi/EmptyException").SetBody(model, "application/json", Encoding.UTF8).PostAsAsync(); Log.Information("调用WMS接口反馈空取异常接口" + result.ToJson()); return result; } /// /// 调用WMS接口反馈满取异常接口 /// /// 任务信息 /// public async Task RequestFullException(TaskRequest model) { string url = Urls.WMSAddress + ":" + Urls.WMSPort; var result = await (url + "/api/DownAPi/FullException").SetBody(model, "application/json", Encoding.UTF8).PostAsAsync(); Log.Information("调用WMS接口反馈满取异常接口" + result.ToJson()); return result; } }