using Newtonsoft.Json; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using WIDESEA_Common.APIEnum; using WIDESEA_Common.CommonEnum; using WIDESEA_Common.LocationEnum; using WIDESEA_Common.OtherEnum; using WIDESEA_Common.StockEnum; using WIDESEA_Common.TaskEnum; using WIDESEA_Core; using WIDESEA_Core.Helper; using WIDESEA_DTO.Task; using WIDESEA_External.Model; using WIDESEA_Model.Models; namespace WIDESEA_TaskInfoService { public partial class TaskService { public async Task TaskCompleted(int taskNum) { try { Dt_Task task = await Repository.QueryFirstAsync(x => x.TaskNum == taskNum); if (task == null) { return await Task.FromResult(WebResponseContent.Instance.Error($"未找到任务信息")); } else if (task.TaskType.GetTaskTypeGroup() == TaskTypeGroup.InboundGroup) { return await Task.FromResult(InboundTaskCompleted(task)); } else if (task.TaskType.GetTaskTypeGroup() == TaskTypeGroup.OutbondGroup) { return await Task.FromResult(OutboundTaskCompleted(task)); } else if (task.TaskType.GetTaskTypeGroup() == TaskTypeGroup.RelocationGroup) { return await Task.FromResult(RelocationTaskCompleted(task)); } else { return await Task.FromResult(WebResponseContent.Instance.Error($"未找到该类型任务,任务类型:{task.TaskType}")); } } catch (Exception ex) { return await Task.FromResult(WebResponseContent.Instance.Error(ex.Message)); } } /// /// 任务信息推送至WCS /// /// public WebResponseContent PushTasksToWCSSingle(int taskNum, string agvDescription = "") { try { Dt_Task task = BaseDal.QueryFirst(x => x.TaskNum == taskNum); if (task == null) { return WebResponseContent.Instance.Error($"错误,未找到该任务信息"); } List taskDTOs = new List { _mapper.Map(task) }; taskDTOs.ForEach(x => { x.AGVArea = agvDescription; }); string url = AppSettings.Get("WCS"); if (string.IsNullOrEmpty(url)) { throw new Exception($"未找到WCSAApi地址,请检查配置文件"); } string response = HttpHelper.Post($"{url}/api/Task/ReceiveTask", taskDTOs.Serialize()); return JsonConvert.DeserializeObject(response) ?? WebResponseContent.Instance.Error("返回错误"); } catch (Exception ex) { return WebResponseContent.Instance.Error(ex.Message); } } /// /// 修改任务状态 /// /// /// public WebResponseContent UpdateTaskInfo(WCSTaskDTO task) { try { Dt_Task wmsTask = BaseDal.QueryFirst(x=>x.TaskNum == task.TaskNum); string oldPalletCode = wmsTask.PalletCode; if (wmsTask != null) { wmsTask.PalletCode= task.PalletCode; wmsTask.Roadway = task.Roadway; wmsTask.TaskStatus = task.TaskState; wmsTask.CurrentAddress = task.CurrentAddress; wmsTask.NextAddress = task.NextAddress; wmsTask.Dispatchertime = task.Dispatchertime; wmsTask.TaskType = task.TaskType; wmsTask.TargetAddress = task.TargetAddress; ////成品入库更新托盘条码 //if (wmsTask.TaskType == TaskTypeEnum.InProduct.ObjToInt() && oldPalletCode != task.PalletCode) //{ // Dt_ProStockInfo stockInfo = _stockRepository.ProStockInfoRepository.QueryFirst(x => x.PalletCode == oldPalletCode); // //判断重复托盘 // stockInfo.PalletCode = task.PalletCode; // _stockRepository.ProStockInfoRepository.UpdateData(stockInfo); //} BaseDal.UpdateData(wmsTask); //推送MES接驳成功接口 if (wmsTask.TaskType.GetTaskTypeGroup() == TaskTypeGroup.InboundGroup && !wmsTask.WorkCentreCode.IsNullOrEmpty() && wmsTask.TaskStatus == TaskStatusEnum.AGV_TakeFinish.ObjToInt()) { Dt_AGVStationInfo? aGVStationInfo = null; aGVStationInfo = _basicRepository.AGVStationInfoRepository.QueryFirst(x=>x.AGVStationCode==wmsTask.CurrentAddress || x.MESPointCode == wmsTask.CurrentAddress); MESRecepNoticeModel mESRecepNoticeModel = new MESRecepNoticeModel() { WorkCentreEmptyPalletNotice = new List() { new RecepNotice() { LocationCode = aGVStationInfo.MESPointCode, CompleteFlag=true } } }; //推送MES接驳 //_invokeMESService.MESRecepNotice(mESRecepNoticeModel); } //推送ERP半成品入库 //if (wmsTask.TaskType>=TaskTypeEnum.WFBYLInbound.ObjToInt() && wmsTask.TaskType <= TaskTypeEnum.PrintYLInbound.ObjToInt() && wmsTask.TaskStatus==TaskStatusEnum.AGV_TakeFinish.ObjToInt()) //{ // Dt_StockInfo stockInfo = _stockRepository.StockInfoRepository.QueryFirst(x=>x.PalletCode== wmsTask.PalletCode); // string request = _invokeERPService.ERPSemiProInUp( // new ERPProInUpModel() // { // PB_INV_PRODUCT_IN = new List() // { // new PB_INV_PRODUCT_INItem() // { // WP_ID = 0, // INV_BARCODE = wmsTask.PalletCode, // REMARK = "半成品入库", // QTY=(int)stockInfo.StockLength // } // } // }) ?? throw new Exception("半成品入库接口请求失败"); //} } return WebResponseContent.Instance.OK(); } catch(Exception ex) { return WebResponseContent.Instance.Error(ex.Message); } } /// /// 回调wcs手动完成任务 /// /// /// public WebResponseContent FeedBackWCSTaskCompleted(int taskNum) { try { Dt_ApiInfo? url = _basicRepository.ApiInfoRepository.QueryData(x => x.ApiCode == APIEnum.FeedBackWCSTaskCompleted.ToString()).First(); string? apiAddress = url.ApiAddress; if (string.IsNullOrEmpty(apiAddress)) { return WebResponseContent.Instance.Error($"{taskNum},未找到WCS任务完成接口,请检查接口配置"); } string responseStr = HttpHelper.Get(apiAddress + "?taskNum=" + taskNum); WebResponseContent content = JsonConvert.DeserializeObject(responseStr) ?? WebResponseContent.Instance.Error("未找到任务完成返回值"); return content; } catch (Exception ex) { return WebResponseContent.Instance.Error(ex.Message); } } } }