using Furion.Logging; using Furion.RemoteRequest.Extensions; using Newtonsoft.Json; using System.Text; 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.StatusCode == "0") { var taskAdd = new WcsTask() { TaskType = TaskTypeEnum.In, Origin = "WMS", StartLocate = startLocat, 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; // 确定目标工位//需添加层数确认 //switch (endLocat) //{ // case "R01": // if (ceng == "1") // { // endLocat = "145"; // } // else if (ceng == "2") // { // endLocat = "252"; // } // else if (ceng == "3") // { // endLocat = "101"; // } // break; // case "R02": // if (ceng == "1") // { // endLocat = "137"; // } // else if (ceng == "2") // { // endLocat = "260"; // } // else if (ceng == "3") // { // endLocat = "405"; // } // break; // case "R03": // if (ceng == "1") // { // endLocat = "127"; // } // else if (ceng == "2") // { // endLocat = "270"; // } // else if (ceng == "3") // { // endLocat = "409"; // } // break; // case "R04": // if (ceng == "1") // { // endLocat = "119"; // } // else if (ceng == "2") // { // endLocat = "278"; // } // else if (ceng == "3") // { // endLocat = "413"; // } // break; // case "R05": // if (ceng == "1") // { // endLocat = "109"; // } // else if (ceng == "2") // { // endLocat = "288"; // } // else if (ceng == "3") // { // endLocat = "417"; // } // break; // case "R06": // if (ceng == "1") // { // endLocat = "101"; // } // else if (ceng == "2") // { // endLocat = "301"; // } // else if (ceng == "3") // { // endLocat = "421"; // } // break; // case "R07": // if (ceng == "1") // { // endLocat = "091"; // } // else if (ceng == "2") // { // endLocat = "307"; // } // else if (ceng == "3") // { // endLocat = "425"; // } // break; // case "R08": // if (ceng == "1") // { // endLocat = "083"; // } // else if (ceng == "2") // { // endLocat = "315"; // } // else if (ceng == "3") // { // endLocat = "429"; // } // break; // case "R09": // if (ceng == "1") // { // endLocat = "073"; // } // else if (ceng == "2") // { // endLocat = "325"; // } // else if (ceng == "3") // { // endLocat = "433"; // } // break; // case "R10": // if (ceng == "1") // { // endLocat = "065"; // } // else if (ceng == "2") // { // endLocat = "337"; // } // else if (ceng == "3") // { // endLocat = "437"; // } // break; //} } /// /// 调用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.StatusCode == "0") { var taskAdd = new WcsTask() { TaskType = TaskTypeEnum.In, Origin = "WMS", StartLocate = startLocat, TaskNo = result.TaskList.TaskNo, EndLocate = result.TaskList.EndLocate, EndRoadway = result.TaskList.EndRoadway }; _db.Updateable(taskAdd).ExecuteCommand(); 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(TaskRequest 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; } }