using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using WIDESEA_Core.Enums; using WIDESEA_Core; using WIDESEA_DTO.Stock; using WIDESEA_Model.Models; using WIDESEA_Core.Helper; using Microsoft.AspNetCore.Http; using System.Reflection.Metadata; using OfficeOpenXml.FormulaParsing.Excel.Functions.RefAndLookup; using System.Diagnostics; using Newtonsoft.Json; using System.Security.Policy; using static WIDESEA_ITaskInfoService.ITaskService; using MailKit.Search; using WIDESEA_Common.Log; using OfficeOpenXml.FormulaParsing.Excel.Functions.DateTime; namespace WIDESEA_TaskInfoService { public partial class TaskService { /// /// 库存数据转出库任务 /// /// /// public List GetTasks(List stockInfos) { List tasks = new List(); for (int i = 0; i < stockInfos.Count; i++) { Dt_StockInfo stockInfo = stockInfos[i]; if (stockInfo != null) { Dt_LocationInfo locationInfo = _basicService.LocationInfoService.Repository.QueryFirst(x => x.LocationCode == stockInfo.LocationCode); Dt_RoadwayInfo roadwayInfo = _basicService.RoadwayInfoService.Repository.QueryFirst(x => x.RoadwayNo == locationInfo.RoadwayNo); if (roadwayInfo != null) { Dt_Task task = new() { CurrentAddress = stockInfo.LocationCode, Grade = 0, PalletCode = stockInfo.PalletCode, NextAddress = roadwayInfo.OutSCStationCode, Roadway = locationInfo.RoadwayNo, SourceAddress = stockInfo.LocationCode, TargetAddress = roadwayInfo.OutStationCode, TaskStatus = OutTaskStatusEnum.OutNew.ObjToInt(), TaskType = TaskTypeEnum.Outbound.ObjToInt(), Depth = locationInfo.Depth, TaskNum = BaseDal.GetTaskNum(nameof(SequenceEnum.SeqTaskNum)) }; tasks.Add(task); } } } return tasks; } /// /// 出库任务数据处理 /// /// /// /// /// public (List, List?, List?, List?, List?) OutboundTaskDataHandle(int orderDetailId, List stockSelectViews) { List tasks = new List(); Dt_OutboundOrderDetail outboundOrderDetail = _outboundService.OutboundOrderDetailService.Repository.QueryFirst(x => x.Id == orderDetailId); if (outboundOrderDetail == null) { throw new Exception("未找到出库单明细信息"); } if (stockSelectViews.Sum(x => x.UseableQuantity) > outboundOrderDetail.OrderQuantity - outboundOrderDetail.LockQuantity) { throw new Exception("选择数量超出单据数量"); } List? stockInfos = null; Dt_OutboundOrderDetail? orderDetail = null; List? outStockLockInfos = null; List? locationInfos = null; if (outboundOrderDetail.OrderDetailStatus == OrderDetailStatusEnum.New.ObjToInt()) { (List, Dt_OutboundOrderDetail, List, List) result = _outboundService.OutboundOrderDetailService.AssignStockOutbound(outboundOrderDetail, stockSelectViews); if (result.Item1 != null && result.Item1.Count > 0) { tasks = GetTasks(result.Item1); result.Item2.OrderDetailStatus = OrderDetailStatusEnum.Outbound.ObjToInt(); result.Item3.ForEach(x => { x.Status = OutStockStatus.出库中.ObjToInt(); }); stockInfos = result.Item1; orderDetail = result.Item2; outStockLockInfos = result.Item3; locationInfos = result.Item4; } else { throw new Exception("无库存"); } } else { List stockLockInfos = _outboundService.OutboundStockLockInfoService.GetByOrderDetailId(outboundOrderDetail.OrderId); if (stockLockInfos != null && stockLockInfos.Count > 0) { List stocks = _stockService.StockInfoService.Repository.GetStockInfosByPalletCodes(stockLockInfos.Select(x => x.PalletCode).Distinct().ToList()); tasks = GetTasks(stocks); } } return (tasks, stockInfos, orderDetail == null ? null : new List { orderDetail }, outStockLockInfos, locationInfos); } /// /// 生成出库任务 /// /// /// /// public WebResponseContent GenerateOutboundTask(int orderDetailId, List stockSelectViews) { try { (List, List?, List?, List?, List?) result = OutboundTaskDataHandle(orderDetailId, stockSelectViews); WebResponseContent content = GenerateOutboundTaskDataUpdate(result.Item1, result.Item2, result.Item3, result.Item4, result.Item5); return content; } catch (Exception ex) { return WebResponseContent.Instance.Error(ex.Message); } } /// /// 生成出库任务后数据更新到数据库 /// /// /// /// /// /// /// public WebResponseContent GenerateOutboundTaskDataUpdate(List tasks, List? stockInfos = null, List? outboundOrderDetails = null, List? outStockLockInfos = null, List? locationInfos = null) { try { WebResponseContent content = new WebResponseContent(); _unitOfWorkManage.BeginTran(); //判断移库 content = RelocationTasks(tasks.OrderBy(x => x.Depth).ToList()); if (content.Status) { _unitOfWorkManage.CommitTran(); } else { _unitOfWorkManage.RollbackTran(); return content; } //BaseDal.AddData(tasks); if (stockInfos != null && outboundOrderDetails != null && outStockLockInfos != null && locationInfos != null) { content = _outboundService.OutboundOrderDetailService.LockOutboundStockDataUpdate(stockInfos, outboundOrderDetails, outStockLockInfos, locationInfos, tasks: tasks); if (content.Status) { _unitOfWorkManage.CommitTran(); } else { _unitOfWorkManage.RollbackTran(); } return content; } else if (outboundOrderDetails != null && outboundOrderDetails.Count > 0) { outboundOrderDetails.ForEach(x => { x.OrderDetailStatus = OrderDetailStatusEnum.Outbound.ObjToInt(); }); _outboundService.OutboundOrderDetailService.Repository.UpdateData(outboundOrderDetails); } _unitOfWorkManage.CommitTran(); return WebResponseContent.Instance.OK(); } catch (Exception ex) { _unitOfWorkManage.RollbackTran(); return WebResponseContent.Instance.Error(ex.Message); } } public WebResponseContent RelocationTasks(List task) { WebResponseContent content = new WebResponseContent(); try { _unitOfWorkManage.BeginTran(); for (int i = 0; i < task.Count; i++) { Dt_LocationInfo location = _basicService.LocationInfoService.Repository.QueryFirst(x => x.LocationCode == task[i].SourceAddress && x.RoadwayNo == task[i].Roadway); if (location != null) { //(Dt_LocationInfo?, int?) result = _basicService.LocationInfoService.isDepth(location); (Dt_LocationInfo?, int?) result = isDepth(location); if (result.Item1 != null && result.Item2 != LocationStatusEnum.Lock.ObjToInt() && result.Item2 != LocationStatusEnum.PalletLock.ObjToInt() && result.Item2 != LocationStatusEnum.Free.ObjToInt()) { int sum = 0; for (int j = 0; j < task.Count; j++) { if (result.Item1.LocationCode == task[j].SourceAddress) { sum++; } } if (sum == 0) { return content = RelocationTask(task[i]); } else { BaseDal.AddData(task[i]); _basicService.LocationInfoService.UpdateLocationLock(location, task[i].TaskNum, StockChangeType.Outbound.ObjToInt(), true); } } else if (result.Item1 == null && result.Item2 == LocationStatusEnum.Free.ObjToInt()) { BaseDal.AddData(task[i]); location.LocationStatus = LocationStatusEnum.Lock.ObjToInt(); _basicService.LocationInfoService.UpdateData(location); content = WebResponseContent.Instance.OK(); } else if (result.Item1 != null && result.Item2 == LocationStatusEnum.Free.ObjToInt()) { BaseDal.AddData(task[i]); location.LocationStatus = LocationStatusEnum.Lock.ObjToInt(); _basicService.LocationInfoService.UpdateData(location); _basicService.LocationInfoService.UpdateLocationLock(location, task[i].TaskNum, StockChangeType.Outbound.ObjToInt(), false); content = WebResponseContent.Instance.OK(); } else if (result.Item1 != null && (result.Item2 == LocationStatusEnum.Lock.ObjToInt() || result.Item2 == LocationStatusEnum.PalletLock.ObjToInt())) { Dt_Task TaskInfo = BaseDal.QueryFirst(x => x.SourceAddress == result.Item1.LocationCode); if (TaskInfo == null) { return content = WebResponseContent.Instance.Error("货位被锁定不可出库"); } else { BaseDal.AddData(task[i]); location.LocationStatus = LocationStatusEnum.Lock.ObjToInt(); _basicService.LocationInfoService.UpdateData(location); content = WebResponseContent.Instance.OK(); } } } else { return content = WebResponseContent.Instance.OK("任务异常"); } } _unitOfWorkManage.CommitTran(); return content; } catch (Exception ex) { _unitOfWorkManage.RollbackTran(); return content = WebResponseContent.Instance.Error(ex.Message); } } /// /// 移库任务 /// /// /// public WebResponseContent RelocationTask(Dt_Task task) { WebResponseContent content = new WebResponseContent(); try { Dt_LocationInfo locationInfo = _basicService.LocationInfoService.Repository.QueryFirst(x => x.LocationCode == task.SourceAddress && x.RoadwayNo == task.Roadway); if (locationInfo != null) { int beforeStatus = locationInfo.LocationStatus; //(Dt_LocationInfo?,int?) Result = _basicService.LocationInfoService.isDepth(locationInfo); (Dt_LocationInfo?, int?) Result = isDepth(locationInfo); if (Result.Item1 != null && Result.Item2 == LocationStatusEnum.InStock.ObjToInt()) { Dt_StockInfo stockInfo = _stockService.StockInfoService.Repository.QueryFirst(x => x.LocationCode == Result.Item1.LocationCode); Dt_StockInfoDetail stockInfoDetail = _stockService.StockInfoDetailService.Repository.QueryFirst(x => x.StockId == stockInfo.Id); if (stockInfo != null && stockInfoDetail != null) { (Dt_Task?, Dt_LocationInfo?) result = AddRelocationTask(Result.Item1, stockInfo, task); if (result.Item1 != null && result.Item2 != null) { _basicService.LocationInfoService.RelocationLock(Result.Item1, result.Item2, result.Item1.TaskNum); locationInfo.LocationStatus = LocationStatusEnum.Lock.ObjToInt(); _basicService.LocationInfoService.UpdateData(locationInfo); _recordService.LocationStatusChangeRecordSetvice.AddLocationStatusChangeRecord(locationInfo, beforeStatus, StockChangeType.Relocation.ObjToInt(), "", task.TaskNum); return content = WebResponseContent.Instance.OK(); } else { return content = WebResponseContent.Instance.Error("移库任务生成失败"); } } else { return content = WebResponseContent.Instance.Error("未找到库存信息"); } } else if (Result.Item1 != null && Result.Item2 == LocationStatusEnum.Pallet.ObjToInt()) { Dt_StockInfo stockInfo = _stockService.StockInfoService.Repository.QueryFirst(x => x.LocationCode == Result.Item1.LocationCode); if (stockInfo != null) { (Dt_Task?, Dt_LocationInfo?) result = AddRelocationTask(Result.Item1, stockInfo, task); if (result.Item1 != null && result.Item2 != null) { _basicService.LocationInfoService.RelocationLock(Result.Item1, result.Item2, result.Item1.TaskNum); locationInfo.LocationStatus = LocationStatusEnum.Lock.ObjToInt(); _basicService.LocationInfoService.UpdateData(locationInfo); _recordService.LocationStatusChangeRecordSetvice.AddLocationStatusChangeRecord(locationInfo, beforeStatus, StockChangeType.Relocation.ObjToInt(), "", task.TaskNum); return content = WebResponseContent.Instance.OK(); } else { return content = WebResponseContent.Instance.Error("移库任务生成失败"); } } else { return content = WebResponseContent.Instance.Error("未找到库存信息"); } } else { return content = WebResponseContent.Instance.Error("异常"); } } else { return content = WebResponseContent.Instance.Error("任务信息异常"); } } catch (Exception ex) { return content = WebResponseContent.Instance.Error(ex.Message); } finally { } } /// /// 判断巷道内移库 /// /// /// /// public WebResponseContent IsRelocations(int TaskNum, string SourceAddress) { try { WebResponseContent content = new WebResponseContent(); List loca = new List(); Dt_Task task = BaseDal.QueryFirst(x => x.TaskNum == TaskNum); if (task == null) { return content = WebResponseContent.Instance.Error($"未找到该任务信息,任务号:{TaskNum}"); } else { //判断是否需要移库 string[] targetCodes = SourceAddress.Split("-"); if (targetCodes[1] == "001") { targetCodes[1] = "002"; } else if (targetCodes[1] == "004") { targetCodes[1] = "003"; } else { return content = WebResponseContent.Instance.Error($"货位解析失败,货位编号:{SourceAddress}"); } targetCodes[4] = "01"; string LocationCode = string.Join("-", targetCodes); //组装浅库位地址 Dt_LocationInfo locationInfos = _basicService.LocationInfoService.Repository.QueryFirst(x => x.LocationCode == LocationCode && (x.LocationStatus == (int)LocationStatusEnum.Free || x.LocationStatus == (int)LocationStatusEnum.InStock)); if (locationInfos == null) { return content = WebResponseContent.Instance.Error($"未找到该货位信息,货位编号:{locationInfos}"); } else { if (locationInfos.LocationStatus == (int)LocationStatusEnum.Free) //判断浅货位是否有货 { return content = WebResponseContent.Instance.OK(); } else { Dt_StockInfo dt_StockInfo = _stockService.StockInfoService.Repository.QueryFirst(x => x.LocationCode == LocationCode && x.StockStatus== (int)StockStatusEmun.已入库); if (dt_StockInfo == null) { return content = WebResponseContent.Instance.Error($"未找到该货位的库存信息,货位编号:{LocationCode}"); } else { Dt_LocationInfo newLocation; //查走货位,进行生成移库任务 int Locationtype = 9; //默认为9 if (dt_StockInfo.MaterialType == (int)InventoryMaterialType.成品) { Locationtype = 11; } else if (dt_StockInfo.MaterialType == (int)InventoryMaterialType.原材料) { Locationtype = 10; } //newLocation = _basicService.LocationInfoService.GetLocation(locationInfos.RoadwayNo,Locationtype); //拿到了移库后的货位 if (dt_StockInfo.MaterialType == (int)InventoryMaterialType.成品) { string[] targetCodesst = dt_StockInfo.PalletCode.Split("*"); Dt_InboundOrder dt_Inbound = _inboundService.InbounOrderService.Repository.QueryFirst(x => x.OrderName == targetCodesst[0]); if (dt_Inbound.Startingcolumn != 0 || dt_Inbound.Terminationcolumn != 0) { newLocation = _basicService.LocationInfoService.GetLocation2(locationInfos.RoadwayNo, Locationtype, dt_Inbound.Startingcolumn, dt_Inbound.Terminationcolumn); } else { newLocation = _basicService.LocationInfoService.GetLocation(locationInfos.RoadwayNo, Locationtype); } } else { newLocation = _basicService.LocationInfoService.GetLocation(locationInfos.RoadwayNo, Locationtype); } //目标货位查找库位是否有货 Dt_StockInfo dt_StockCurren = _stockService.StockInfoService.Repository.QueryFirst(x => x.LocationCode == newLocation.LocationCode); if (dt_StockCurren != null) return content = WebResponseContent.Instance.Error($"入库失败,托盘条码:{dt_StockInfo.PalletCode},查找出的货位信息对应已有库存"); Dt_Task taskcurren = BaseDal.QueryFirst(x => x.TargetAddress == newLocation.LocationCode); if (taskcurren != null) return content = WebResponseContent.Instance.Error($"入库失败,托盘条码:{dt_StockInfo.PalletCode},查找出的货位信息已有入库任务"); bool crutaskthy = _taskHtyService.CrueeTaskHty(newLocation.LocationCode); if (crutaskthy) return content = WebResponseContent.Instance.Error($"入库失败,托盘条码:{dt_StockInfo.PalletCode},查找出的货位在任务历史信息中,有入库或移库信息"); if (newLocation != null) { Dt_Task dt_Task = new() { PalletCode = dt_StockInfo.PalletCode, Roadway = locationInfos.RoadwayNo, TaskType = TaskTypeEnum.RelocationIn.ObjToInt(), TaskStatus = OutTaskStatusEnum.OutNew.ObjToInt(), SourceAddress = locationInfos.LocationCode, TargetAddress = newLocation.LocationCode, CurrentAddress = locationInfos.LocationCode, NextAddress = newLocation.LocationCode, Grade = 2, Creater = "WMS", CreateDate = DateTime.Now, TaskNum = BaseDal.GetTaskNum(nameof(SequenceEnum.SeqTaskNum)), MaterialType = dt_StockInfo.MaterialType }; _unitOfWorkManage.BeginTran(); if (locationInfos.LocationStatus == LocationStatusEnum.InStock.ObjToInt()) { locationInfos.LocationStatus = LocationStatusEnum.Lock.ObjToInt(); newLocation.LocationStatus = LocationStatusEnum.Lock.ObjToInt(); } else if (locationInfos.LocationStatus == LocationStatusEnum.Pallet.ObjToInt()) { locationInfos.LocationStatus = LocationStatusEnum.PalletLock.ObjToInt(); newLocation.LocationStatus = LocationStatusEnum.PalletLock.ObjToInt(); } loca.Add(newLocation); loca.Add(locationInfos); _basicService.LocationInfoService.UpdateData(loca); BaseDal.AddData(dt_Task); _unitOfWorkManage.CommitTran(); return content = WebResponseContent.Instance.OK(data: dt_Task); } else { return content = WebResponseContent.Instance.Error($"未找到巷道内可移库的货位"); } } } } } } catch (Exception ex) { _unitOfWorkManage.RollbackTran(); throw; } } public string ReceiveWMSTask = WIDESEA_Core.Helper.AppSettings.Configuration["ReceiveWMSTask"]; /// /// 接收起点需要的空托盘进行出库 /// /// /// public WebResponseContent Empty_outbound(GenerateInv generate) { WebResponseContent content = new WebResponseContent(); try { Dt_Task task = BaseDal.QueryFirst(x => x.TargetAddress == generate.SourceAddress); if (task == null) { string RoadwayNo = "1"; if (generate.SourceAddress != "R01-002-041-001-01") { RoadwayNo = "2"; } Dt_LocationInfo locationInfos = _basicService.LocationInfoService.Repository.QueryFirst(x => x.RoadwayNo == RoadwayNo && x.EnableStatus != (int)EnableStatusEnum.Disable && x.Depth==1 && x.LocationStatus == LocationStatusEnum.Pallet.ObjToInt()); if(locationInfos == null) { locationInfos = _basicService.LocationInfoService.Repository.QueryFirst(x => x.RoadwayNo == RoadwayNo && x.Depth == 2 && x.EnableStatus != (int)EnableStatusEnum.Disable && x.LocationStatus == LocationStatusEnum.Pallet.ObjToInt()); } if (locationInfos != null) { Dt_StockInfo dt_StockInfo = _stockService.StockInfoService.Repository.QueryFirst(x => x.LocationCode == locationInfos.LocationCode); if (dt_StockInfo != null && dt_StockInfo.MaterialType == (int)InventoryMaterialType.空托) { Dt_LocationInfo newSourceAddress; newSourceAddress = _basicService.LocationInfoService.GetLocationplatform(generate.SourceAddress); if (newSourceAddress != null) { Dt_Task dt_Task = new() { PalletCode = dt_StockInfo.PalletCode, TaskNum = BaseDal.GetTaskNum(nameof(SequenceEnum.SeqTaskNum)), Roadway = locationInfos.RoadwayNo, TaskType = TaskTypeEnum.PalletOutbound.ObjToInt(), TaskStatus = InTaskStatusEnum.InNew.ObjToInt(), SourceAddress = locationInfos.LocationCode, TargetAddress = newSourceAddress.LocationCode, CurrentAddress = locationInfos.LocationCode, NextAddress = newSourceAddress.LocationCode, Grade = 1, Creater = "WMS", Depth = locationInfos.Depth, CreateDate = DateTime.Now, PalletCodequantity = (int)dt_StockInfo.Materialweight, MaterialType = dt_StockInfo.MaterialType }; _unitOfWorkManage.BeginTran(); dt_StockInfo.StockStatus = (int)StockStatusEmun.出库锁定; dt_StockInfo.Remark = "等待堆垛机完成出库任务"; if (locationInfos.LocationStatus == LocationStatusEnum.Pallet.ObjToInt()) { locationInfos.LocationStatus = LocationStatusEnum.PalletLock.ObjToInt(); } BaseDal.AddData(dt_Task); _basicService.LocationInfoService.UpdateData(locationInfos); _stockService.StockInfoService.Repository.UpdateData(dt_StockInfo); _unitOfWorkManage.CommitTran(); return content = WebResponseContent.Instance.OK(data: dt_Task); } else { return content = WebResponseContent.Instance.Error($"未找到站台编号,编号:{generate.SourceAddress}"); } } else { return content = WebResponseContent.Instance.Error($"无该库位空托为库存信息,库位编号:{locationInfos.LocationCode}"); } } else { return content = WebResponseContent.Instance.Error($"该巷道已无空托盘,巷道号:{RoadwayNo}巷道"); } } else { return content = WebResponseContent.Instance.Error($"已有该站台的空托出库任务,站台编号{generate.SourceAddress}"); } } catch (Exception ex) { _unitOfWorkManage.RollbackTran(); return content = WebResponseContent.Instance.Error($"出库失败,报错信息:{ex.Message}"); throw; } } /// /// 接收起点需要的空托盘进行出库 /// /// /// public WebResponseContent Rawmaterialout(GenerateInv3 generate) { WebResponseContent content = new WebResponseContent(); List dt_StockInfo = _stockService.StockInfoService.Repository.QueryData(x => x.PalletCode.Contains(generate.PalletCode) && x.MaterialType== (int)InventoryMaterialType.原材料).OrderBy(x=>x.CreateDate).Take(generate.outCount).ToList(); if(dt_StockInfo.Count > 0) { for (int i = 0; i < dt_StockInfo.Count; i++) { Dt_LocationInfo locationinfo = _basicService.LocationInfoService.Repository.QueryFirst(x => x.LocationCode == dt_StockInfo[i].LocationCode); //确认货位信息是否对上 if (locationinfo != null) { Dt_Task dt_Task = new() { PalletCode = dt_StockInfo[i].PalletCode, TaskNum = BaseDal.GetTaskNum(nameof(SequenceEnum.SeqTaskNum)), Roadway = locationinfo.RoadwayNo, TaskType = TaskTypeEnum.Outbound.ObjToInt(), TaskStatus = InTaskStatusEnum.InNew.ObjToInt(), SourceAddress = locationinfo.LocationCode, TargetAddress = locationinfo.RoadwayNo == "1" ? "R01-002-041-011-01" : "R02-002-027-011-01", CurrentAddress = locationinfo.LocationCode, NextAddress = locationinfo.RoadwayNo == "1" ? "R01-002-041-011-01" : "R02-002-027-011-01", Grade = 1, Creater = "WMS", Depth = locationinfo.Depth, CreateDate = DateTime.Now, PalletCodequantity = (int)dt_StockInfo[i].Materialweight, PLCTo = generate.TargetAddress == "R01-002-041-011-01" ? 1 : 2, MaterialType = dt_StockInfo[i].MaterialType }; _unitOfWorkManage.BeginTran(); dt_StockInfo[i].StockStatus = (int)StockStatusEmun.出库锁定; dt_StockInfo[i].Remark = "等待堆垛机完成出库任务"; if (locationinfo.LocationStatus == LocationStatusEnum.InStock.ObjToInt()) { locationinfo.LocationStatus = LocationStatusEnum.Lock.ObjToInt(); } BaseDal.AddData(dt_Task); _basicService.LocationInfoService.UpdateData(locationinfo); _stockService.StockInfoService.Repository.UpdateData(dt_StockInfo); _unitOfWorkManage.CommitTran(); content = WebResponseContent.Instance.OK(data: dt_Task); } else { content = WebResponseContent.Instance.Error($"物料信息与货位信息不对,托盘号:{dt_StockInfo[i].PalletCode}"); } } return content; } else { return content = WebResponseContent.Instance.Error($"未找到出库的库存信息"); } } /// /// 手动生成出库任务 /// /// /// public WebResponseContent ManualOutbound(SaveModel saveModel) { WebResponseContent content = new WebResponseContent(); try { List dtstockt = new List(); List locations = new List(); List taskdt = new List(); List dtstocktdetail = new List(); for (int i = 0; i < saveModel.DelKeys.Count; i++) { Dt_StockInfo stockt = _stockService.StockInfoService.Repository.QueryFirst(x => x.PalletCode == saveModel.DelKeys[i].ToString()); if (stockt.StockStatus == (int)StockStatusEmun.已入库 && (stockt.Wlstatus == (int)InventoryMaterialStatus.合格 || stockt.Wlstatus == (int)InventoryMaterialStatus.返工 || stockt.Wlstatus == (int)InventoryMaterialStatus.特采) ) { if(stockt.MaterialType != (int)InventoryMaterialType.原材料) { Dt_StockInfoDetail stocktdetail = _stockService.StockInfoDetailService.Repository.QueryFirst(x => x.StockId == stockt.Id); stockt.StockStatus = (int)StockStatusEmun.出库锁定; if (stockt.MaterialType != (int)InventoryMaterialType.空托) { stocktdetail.Status = (int)StockStatusEmun.出库锁定; } Dt_LocationInfo locationinfo = _basicService.LocationInfoService.Repository.QueryFirst(x => x.LocationCode == stockt.LocationCode); if (locationinfo.RoadwayNo == "1") { if (locationinfo.LocationStatus == LocationStatusEnum.InStock.ObjToInt()) { locationinfo.LocationStatus = LocationStatusEnum.Lock.ObjToInt(); } else if (locationinfo.LocationStatus == LocationStatusEnum.Pallet.ObjToInt()) { locationinfo.LocationStatus = LocationStatusEnum.PalletLock.ObjToInt(); } string LocationName = "R01-002-044-001-01"; if (stockt.MaterialType == (int)InventoryMaterialType.空托) { LocationName = "R01-002-043-001-01"; } Dt_LocationInfo newTargetAddress; newTargetAddress = _basicService.LocationInfoService.GetLocationplatform(LocationName); Dt_Task dt_Task = new() { PalletCode = stockt.PalletCode, TaskNum = BaseDal.GetTaskNum(nameof(SequenceEnum.SeqTaskNum)), Roadway = newTargetAddress.RoadwayNo, TaskType = TaskTypeEnum.Outbound.ObjToInt(), TaskStatus = InTaskStatusEnum.InNew.ObjToInt(), SourceAddress = locationinfo.LocationCode, TargetAddress = newTargetAddress.LocationCode, CurrentAddress = locationinfo.LocationCode, NextAddress = newTargetAddress.LocationCode, Grade = 1, Creater = "WMS", Depth = locationinfo.Depth, CreateDate = DateTime.Now, MaterialType= stockt.MaterialType }; dtstockt.Add(stockt); locations.Add(locationinfo); taskdt.Add(dt_Task); if (stockt.MaterialType != (int)InventoryMaterialType.空托) { dtstocktdetail.Add(stocktdetail); } } else { return content = WebResponseContent.Instance.Error($"出库失败,只可出库1巷道的托盘和成品,出库条码:{saveModel.DelKeys[i].ToString()}"); } } else { return content = WebResponseContent.Instance.Error($"出库失败,请不要选择原材料出库,出库条码:{saveModel.DelKeys[i].ToString()}"); } } else { return content = WebResponseContent.Instance.Error($"出库失败,请选择已入库且(合格,返工,特采)的物料出库!!!,出库条码:{saveModel.DelKeys[i].ToString()}"); } } var responses = HttpHelper.Post(ReceiveWMSTask, taskdt, "下发任务入库"); _unitOfWorkManage.BeginTran(); if (dtstockt.Count > 0) { _stockService.StockInfoService.Repository.UpdateData(dtstockt); _stockService.StockInfoDetailService.Repository.UpdateData(dtstocktdetail); _basicService.LocationInfoService.Repository.UpdateData(locations); BaseDal.AddData(taskdt); } _unitOfWorkManage.CommitTran(); content = WebResponseContent.Instance.OK(); return content; } catch (Exception ex) { _unitOfWorkManage.RollbackTran(); return content = WebResponseContent.Instance.Error($"出库失败,报错信息:{ex.Message}"); throw; } } public WebResponseContent ManualOutbound2(SaveModel saveModel) { WebResponseContent content = new WebResponseContent(); try { List dtstockt = new List(); List locations = new List(); List taskdt = new List(); List dtstocktdetail = new List(); List stocktData= _stockService.StockInfoService.Repository.QueryData(x=>x.StockStatus== (int)StockStatusEmun.已入库 && x.MaterialType == (int)InventoryMaterialType.原材料); List locationinfoData = _basicService.LocationInfoService.Repository.QueryData(x =>x.LocationStatus == LocationStatusEnum.InStock.ObjToInt()); List StockInfoDetailData = _stockService.StockInfoDetailService.Repository.QueryData(x => x.Status == (int)StockStatusEmun.已入库); string json = saveModel.DelKeys[0].ToString(); List palletCodes = JsonConvert.DeserializeObject>(json); foreach (var palletCode in palletCodes) { Dt_StockInfo stockt = stocktData.FirstOrDefault(x => x.PalletCode == palletCode); if (stockt !=null) { if (stockt.StockStatus == (int)StockStatusEmun.已入库 && (stockt.Wlstatus == (int)InventoryMaterialStatus.合格 || stockt.Wlstatus == (int)InventoryMaterialStatus.退货 || stockt.Wlstatus == (int)InventoryMaterialStatus.特采)) { Dt_StockInfoDetail stocktdetail = StockInfoDetailData.FirstOrDefault(x => x.StockId == stockt.Id); if(stocktdetail != null) { Dt_LocationInfo locationinfo = locationinfoData.FirstOrDefault(x => x.LocationCode == stockt.LocationCode); if(locationinfo != null) { stockt.StockStatus = (int)StockStatusEmun.出库锁定; if (locationinfo.LocationStatus == LocationStatusEnum.InStock.ObjToInt()) { locationinfo.LocationStatus = LocationStatusEnum.Lock.ObjToInt(); } string TargetAdd = ""; if (saveModel.DelKeys[1].ToString()=="20") { TargetAdd = "R02-001-021-001-02"; }else if(saveModel.DelKeys[1].ToString() == "30") { TargetAdd = "R02-001-022-001-02"; } else if (saveModel.DelKeys[1].ToString() == "40") { TargetAdd = "R01-002-044-001-01"; } else { TargetAdd = locationinfo.RoadwayNo == "2" ? "R02-002-027-011-01" : "R01-002-041-011-01"; } Dt_Task dt_Task = new() { PalletCode = stockt.PalletCode, TaskNum = BaseDal.GetTaskNum(nameof(SequenceEnum.SeqTaskNum)), Roadway = locationinfo.RoadwayNo, TaskType = TaskTypeEnum.Outbound.ObjToInt(), TaskStatus = InTaskStatusEnum.InNew.ObjToInt(), SourceAddress = locationinfo.LocationCode, TargetAddress = TargetAdd, CurrentAddress = locationinfo.LocationCode, NextAddress = TargetAdd, Grade = 1, Creater = "WMS", Depth = locationinfo.Depth, CreateDate = DateTime.Now, PLCTo = int.Parse(saveModel.DelKeys[1].ToString()), MaterialType=stockt.MaterialType }; dtstockt.Add(stockt); locations.Add(locationinfo); taskdt.Add(dt_Task); dtstocktdetail.Add(stocktdetail); } else { return content = WebResponseContent.Instance.Error($"出库失败,未找到对应的库位信息,请核对!!!,出库条码:{palletCode}"); } } else { return content = WebResponseContent.Instance.Error($"出库失败,未找到对应的库存详情信息,请核对!!!,出库条码:{palletCode}"); } } else { return content = WebResponseContent.Instance.Error($"出库失败,请选择已入库且(合格,特采,退货)的物料出库!!!,出库条码:{palletCode}"); } } else { return content = WebResponseContent.Instance.Error($"出库失败,未找到对应条码的库存信息,出库条码:{palletCode}"); } } var responses = HttpHelper.Post(ReceiveWMSTask, taskdt, "下发任务入库"); _unitOfWorkManage.BeginTran(); if(dtstockt.Count > 0) { _stockService.StockInfoService.Repository.UpdateData(dtstockt); _stockService.StockInfoDetailService.Repository.UpdateData(dtstocktdetail); _basicService.LocationInfoService.Repository.UpdateData(locations); BaseDal.AddData(taskdt); } _unitOfWorkManage.CommitTran(); content = WebResponseContent.Instance.OK($"出库成功,出库总数:{palletCodes.Count},成功数量:{dtstockt.Count}"); return content; } catch (Exception ex) { _unitOfWorkManage.RollbackTran(); return content = WebResponseContent.Instance.Error($"出库失败,报错信息:{ex.Message}"); throw; } } public WebResponseContent ManualOutbound3(SaveModel saveModel) { WebResponseContent content = new WebResponseContent(); try { List dtstockt = new List(); List stocktData = _stockService.StockInfoService.Repository.QueryData(x => x.StockStatus == (int)StockStatusEmun.已入库); string json = saveModel.DelKeys[0].ToString(); List palletCodes = JsonConvert.DeserializeObject>(json); foreach (int pallid in palletCodes) { Dt_StockInfo stockt = stocktData.FirstOrDefault(x => x.Id == pallid); if (stockt != null) { stockt.Wlstatus = int.Parse(saveModel.DelKeys[1].ToString()); dtstockt.Add(stockt); } else { return content = WebResponseContent.Instance.Error($"修改失败,未找到对应的库存信息,库存编号:{pallid}"); } } _unitOfWorkManage.BeginTran(); if (dtstockt.Count > 0) { _stockService.StockInfoService.Repository.UpdateData(dtstockt); } _unitOfWorkManage.CommitTran(); content = WebResponseContent.Instance.OK($"修改成功"); return content; } catch (Exception ex) { _unitOfWorkManage.RollbackTran(); return content = WebResponseContent.Instance.Error($"修改失败,报错信息:{ex.Message}"); throw; } } public WebResponseContent ManualOutbound4(SaveModel saveModel) { WebResponseContent content = new WebResponseContent(); try { List dtstockt = new List(); List stocktData = _stockService.StockInfoService.Repository.QueryData(x => x.StockStatus == (int)StockStatusEmun.已入库); string json = saveModel.DelKeys[0].ToString(); List palletCodes = JsonConvert.DeserializeObject>(json); foreach (int pallid in palletCodes) { Dt_StockInfo stockt = stocktData.FirstOrDefault(x => x.Id == pallid); if (stockt != null) { stockt.Mgeneratetime = DateTime.Parse(saveModel.DelKeys[1].ToString()); dtstockt.Add(stockt); } else { return content = WebResponseContent.Instance.Error($"修改失败,未找到对应的库存信息,库存编号:{pallid}"); } } _unitOfWorkManage.BeginTran(); if (dtstockt.Count > 0) { _stockService.StockInfoService.Repository.UpdateData(dtstockt); } _unitOfWorkManage.CommitTran(); content = WebResponseContent.Instance.OK($"修改成功"); return content; } catch (Exception ex) { _unitOfWorkManage.RollbackTran(); return content = WebResponseContent.Instance.Error($"修改失败,报错信息:{ex.Message}"); throw; } } public class PalletCodeList { public string PalletCode { get; set; } } public (Dt_Task?, Dt_LocationInfo?) AddRelocationTask(Dt_LocationInfo location, Dt_StockInfo stockInfo, Dt_Task task) { Dt_LocationInfo? locationInfos = _basicService.LocationInfoService.AssignLocation(location.RoadwayNo); if (locationInfos != null) { Dt_Task tasks = new() { CurrentAddress = location.LocationCode, Grade = 0, PalletCode = stockInfo.PalletCode, NextAddress = locationInfos.LocationCode, Roadway = location.RoadwayNo, SourceAddress = location.LocationCode, TargetAddress = locationInfos.LocationCode, TaskStatus = InTaskStatusEnum.RelocationNew.ObjToInt(), TaskType = TaskTypeEnum.Relocation.ObjToInt(), TaskNum = BaseDal.GetTaskNum(nameof(SequenceEnum.SeqTaskNum)) }; BaseDal.AddData(tasks); BaseDal.AddData(task); stockInfo.StockStatus = StockStatusEmun.移库锁定.ObjToInt(); _stockService.StockInfoService.UpdateData(stockInfo); } return (task, locationInfos); } /// /// 生成出库任务 /// /// /// public WebResponseContent GenerateOutboundTask(int[] keys) { try { List tasks = new List(); List stockSelectViews = new List(); List stockInfos = new List(); List outboundOrderDetails = new List(); List outStockLockInfos = new List(); List locationInfos = new List(); foreach (int key in keys) { (List, List?, List?, List?, List?) result = OutboundTaskDataHandle(key, stockSelectViews); if (result.Item2 != null && result.Item2.Count > 0) { stockInfos.AddRange(result.Item2); } if (result.Item3 != null && result.Item3.Count > 0) { outboundOrderDetails.AddRange(result.Item3); } if (result.Item4 != null && result.Item4.Count > 0) { outStockLockInfos.AddRange(result.Item4); } if (result.Item5 != null && result.Item5.Count > 0) { locationInfos.AddRange(result.Item5); } if (result.Item1 != null && result.Item1.Count > 0) { tasks.AddRange(result.Item1); } } WebResponseContent content = GenerateOutboundTaskDataUpdate(tasks, stockInfos, outboundOrderDetails, outStockLockInfos, locationInfos); return content; } catch (Exception ex) { _unitOfWorkManage.RollbackTran(); return WebResponseContent.Instance.Error(ex.Message); } } /// /// 空托盘出库任务 /// /// /// public WebResponseContent PalletOutboundTask(string roadwayNo, string endStation) { try { Dt_StockInfo stockInfo = _stockService.StockInfoService.Repository.GetPalletStockInfo(roadwayNo); if (stockInfo == null) { return WebResponseContent.Instance.Error("未找到空托盘库存"); } Dt_LocationInfo locationInfo = _basicService.LocationInfoService.Repository.QueryFirst(x => x.LocationCode == stockInfo.LocationCode && x.RoadwayNo == roadwayNo); if (locationInfo == null) { return WebResponseContent.Instance.Error("未找到空托盘库存对应的货位信息"); } Dt_RoadwayInfo roadwayInfo = _basicService.RoadwayInfoService.Repository.QueryFirst(x => x.InStationCode == endStation && x.RoadwayNo == roadwayNo); if (roadwayInfo == null) { return WebResponseContent.Instance.Error("未找到终点巷道信息"); } Dt_Task task = new Dt_Task() { CurrentAddress = stockInfo.LocationCode, Grade = 0, NextAddress = endStation, PalletCode = stockInfo.PalletCode, Roadway = roadwayNo, SourceAddress = stockInfo.LocationCode, TargetAddress = endStation, TaskStatus = OutTaskStatusEnum.OutNew.ObjToInt(), TaskType = TaskTypeEnum.PalletOutbound.ObjToInt(), Depth = locationInfo.Depth, TaskNum = BaseDal.GetTaskNum(nameof(SequenceEnum.SeqTaskNum)) }; int beforeStatus = locationInfo.LocationStatus; _unitOfWorkManage.BeginTran(); stockInfo.StockStatus = StockStatusEmun.出库锁定.ObjToInt(); locationInfo.LocationStatus = LocationStatusEnum.Lock.ObjToInt(); BaseDal.AddData(task); _stockService.StockInfoService.UpdateData(stockInfo); _basicService.LocationInfoService.UpdateData(locationInfo); _basicService.LocationInfoService.UpdateLocationLock(locationInfo, task.TaskNum, StockChangeType.Outbound.ObjToInt(), false); _recordService.LocationStatusChangeRecordSetvice.AddLocationStatusChangeRecord(locationInfo, beforeStatus, StockChangeType.Outbound.ObjToInt(), "", task.TaskNum); _unitOfWorkManage.CommitTran(); return WebResponseContent.Instance.OK(); } catch (Exception ex) { return WebResponseContent.Instance.Error(ex.Message); } } public (Dt_LocationInfo?, int?) isDepth(Dt_LocationInfo locationInfo) { if (locationInfo.Depth == 2) { if (locationInfo.Row == 1 || locationInfo.Row == 5) { Dt_LocationInfo dt_LocationInfo = _basicService.LocationInfoService.Repository.QueryFirst(x => x.Row == locationInfo.Row + 1 && x.Layer == locationInfo.Layer && x.Column == locationInfo.Column && x.RoadwayNo == locationInfo.RoadwayNo); if (dt_LocationInfo != null && dt_LocationInfo.LocationStatus == LocationStatusEnum.InStock.ObjToInt()) { return (dt_LocationInfo, LocationStatusEnum.InStock.ObjToInt()); } if (dt_LocationInfo != null && dt_LocationInfo.LocationStatus == LocationStatusEnum.Free.ObjToInt()) { return (dt_LocationInfo, LocationStatusEnum.Free.ObjToInt()); } if (dt_LocationInfo != null && dt_LocationInfo.LocationStatus == LocationStatusEnum.Lock.ObjToInt()) { return (dt_LocationInfo, LocationStatusEnum.Lock.ObjToInt()); } if (dt_LocationInfo != null && dt_LocationInfo.LocationStatus == LocationStatusEnum.PalletLock.ObjToInt()) { return (dt_LocationInfo, LocationStatusEnum.PalletLock.ObjToInt()); } if (dt_LocationInfo != null && dt_LocationInfo.LocationStatus == LocationStatusEnum.Pallet.ObjToInt()) { return (dt_LocationInfo, LocationStatusEnum.Pallet.ObjToInt()); } } else if (locationInfo.Row == 4 || locationInfo.Row == 8) { Dt_LocationInfo dt_LocationInfo = _basicService.LocationInfoService.Repository.QueryFirst(x => x.Row == locationInfo.Row + 1 && x.Layer == locationInfo.Layer && x.Column == locationInfo.Column && x.RoadwayNo == locationInfo.RoadwayNo); if (dt_LocationInfo != null && dt_LocationInfo.LocationStatus == LocationStatusEnum.InStock.ObjToInt()) { return (dt_LocationInfo, LocationStatusEnum.InStock.ObjToInt()); } if (dt_LocationInfo != null && dt_LocationInfo.LocationStatus == LocationStatusEnum.Free.ObjToInt()) { return (dt_LocationInfo, LocationStatusEnum.Free.ObjToInt()); } if (dt_LocationInfo != null && dt_LocationInfo.LocationStatus == LocationStatusEnum.Lock.ObjToInt()) { return (dt_LocationInfo, LocationStatusEnum.Lock.ObjToInt()); } if (dt_LocationInfo != null && dt_LocationInfo.LocationStatus == LocationStatusEnum.PalletLock.ObjToInt()) { return (dt_LocationInfo, LocationStatusEnum.PalletLock.ObjToInt()); } if (dt_LocationInfo != null && dt_LocationInfo.LocationStatus == LocationStatusEnum.Pallet.ObjToInt()) { return (dt_LocationInfo, LocationStatusEnum.Pallet.ObjToInt()); } } } return (null, LocationStatusEnum.Free.ObjToInt()); } /// /// 人工手动出库(删除库存) /// /// /// public WebResponseContent ManualOutboundDeleteinventory(SaveModel saveModel) { WebResponseContent content = new WebResponseContent(); try { List dtstockt = new List(); List locations = new List(); List dtstocktdetail = new List(); for (int i = 0; i < saveModel.DelKeys.Count; i++) { Dt_StockInfo stockt = _stockService.StockInfoService.Repository.QueryFirst(x => x.PalletCode == saveModel.DelKeys[i].ToString()); if (stockt.StockStatus == (int)StockStatusEmun.已入库) { Dt_StockInfoDetail stocktdetail = _stockService.StockInfoDetailService.Repository.QueryFirst(x => x.StockId == stockt.Id); Dt_LocationInfo locationinfo = _basicService.LocationInfoService.Repository.QueryFirst(x => x.LocationCode == stockt.LocationCode); Dt_Task_Hty task_Hty = new Dt_Task_Hty() { TaskNum = 001, PalletCode = stockt.PalletCode, Roadway = locationinfo.RoadwayNo, TaskType = (int)TaskTypeEnum.Outbound, TaskStatus = (int)OutTaskStatusEnum.OutFinish, SourceAddress = locationinfo.LocationCode, TargetAddress = locationinfo.LocationCode, CurrentAddress = locationinfo.LocationCode, NextAddress = locationinfo.LocationCode, Grade = 1, Dispatchertime = DateTime.Now, Creater = App.User.UserName, CreateDate = DateTime.Now, ModifyDate = DateTime.Now, Modifier = App.User.UserName, Remark = "人工出库", PLCTo = 1, PalletCodequantity = 1, MaterialType = 1 }; _taskHtyService.AddData(task_Hty); locationinfo.LocationStatus = LocationStatusEnum.Free.ObjToInt(); dtstockt.Add(stockt); locations.Add(locationinfo); if (stockt.MaterialType != (int)InventoryMaterialType.空托) { dtstocktdetail.Add(stocktdetail); } WriteLog.GetLog("人工手动删除库存信息").Write($"托盘条码:{stockt.PalletCode},库位编号:{stockt.LocationCode}", $"人工出库库存"); } else { return content = WebResponseContent.Instance.Error($"出库失败,该库存信息不可进行出库"); } } _unitOfWorkManage.BeginTran(); _stockService.StockInfoService.Repository.DeleteData(dtstockt); _stockService.StockInfoDetailService.Repository.DeleteData(dtstocktdetail); _basicService.LocationInfoService.Repository.UpdateData(locations); _unitOfWorkManage.CommitTran(); content = WebResponseContent.Instance.OK(); return content; } catch (Exception ex) { _unitOfWorkManage.RollbackTran(); return content = WebResponseContent.Instance.Error($"手动出库信息失败,报错信息:{ex.Message}"); throw; } } /// /// 任务取消 /// /// /// public WebResponseContent Cancelinventory(int taskNum) { WebResponseContent content = new WebResponseContent(); Dt_Task task = BaseDal.QueryFirst(x => x.TaskNum == taskNum); if(task != null) { if(task.TaskType== (int)TaskTypeEnum.Outbound || task.TaskType == (int)TaskTypeEnum.PalletOutbound) { //处理出库的逻辑 Dt_LocationInfo locationinfo = _basicService.LocationInfoService.Repository.QueryFirst(x => x.LocationCode == task.SourceAddress); if (locationinfo.LocationStatus == LocationStatusEnum.Lock.ObjToInt()) { locationinfo.LocationStatus = LocationStatusEnum.InStock.ObjToInt(); } if (locationinfo.LocationStatus == LocationStatusEnum.PalletLock.ObjToInt()) { locationinfo.LocationStatus = LocationStatusEnum.Pallet.ObjToInt(); } _basicService.LocationInfoService.Repository.UpdateData(locationinfo); Dt_StockInfo stockInfo = _stockService.StockInfoService.Repository.QueryFirst(x => x.PalletCode == task.PalletCode); stockInfo.StockStatus = (int)StockStatusEmun.已入库; _stockService.StockInfoService.Repository.UpdateData(stockInfo); Dt_StockInfoDetail stocktdetail = _stockService.StockInfoDetailService.Repository.QueryFirst(x => x.StockId == stockInfo.Id); if(stocktdetail != null) { stocktdetail.Status = (int)StockStatusEmun.已入库; _stockService.StockInfoDetailService.Repository.UpdateData(stocktdetail); } BaseDal.DeleteData(task); BaseDal.DeleteAndMoveIntoHty(task, OperateType.人工删除); WriteLog.GetLog("任务日志").Write($"出库任务取消成功,托盘条码:{task.PalletCode}", $"任务取消"); WebResponseContent webResponseContent = HttpHelper.Post(ReceiveWCSTask, task.TaskNum, "任务删除"); return content = WebResponseContent.Instance.Error($"出库任务取消成功"); } else if(task.TaskType == (int)TaskTypeEnum.Inbound || task.TaskType == (int)TaskTypeEnum.PalletInbound) { //处理出库的逻辑 Dt_LocationInfo locationinfo = _basicService.LocationInfoService.Repository.QueryFirst(x => x.LocationCode == task.TargetAddress); if (locationinfo.LocationStatus == LocationStatusEnum.Lock.ObjToInt() || locationinfo.LocationStatus == LocationStatusEnum.PalletLock.ObjToInt()) { locationinfo.LocationStatus = LocationStatusEnum.Free.ObjToInt(); } _basicService.LocationInfoService.Repository.UpdateData(locationinfo); Dt_StockInfo stockInfo = _stockService.StockInfoService.Repository.QueryFirst(x => x.PalletCode == task.PalletCode); _stockService.StockInfoService.Repository.DeleteData(stockInfo); Dt_StockInfoDetail stocktdetail = _stockService.StockInfoDetailService.Repository.QueryFirst(x => x.StockId == stockInfo.Id); if (stocktdetail != null) { _stockService.StockInfoDetailService.Repository.DeleteData(stocktdetail); } BaseDal.DeleteData(task); BaseDal.DeleteAndMoveIntoHty(task, OperateType.人工删除); WriteLog.GetLog("任务日志").Write($"入库任务取消成功,托盘条码:{task.PalletCode}", $"任务取消"); WebResponseContent webResponseContent = HttpHelper.Post(ReceiveWCSTask, task.TaskNum, "任务删除"); return content = WebResponseContent.Instance.Error($"入库任务取消成功"); } else if (task.TaskType == (int)TaskTypeEnum.RelocationIn) //库内移库 { //处理出库的逻辑 Dt_LocationInfo locationinfo = _basicService.LocationInfoService.Repository.QueryFirst(x => x.LocationCode == task.TargetAddress); if (locationinfo.LocationStatus == LocationStatusEnum.Lock.ObjToInt() || locationinfo.LocationStatus == LocationStatusEnum.PalletLock.ObjToInt()) { locationinfo.LocationStatus = LocationStatusEnum.Free.ObjToInt(); } _basicService.LocationInfoService.Repository.UpdateData(locationinfo); Dt_LocationInfo locationinfo2 = _basicService.LocationInfoService.Repository.QueryFirst(x => x.LocationCode == task.SourceAddress); if (locationinfo2.LocationStatus == LocationStatusEnum.Lock.ObjToInt()) { locationinfo2.LocationStatus = LocationStatusEnum.InStock.ObjToInt(); } if (locationinfo2.LocationStatus == LocationStatusEnum.PalletLock.ObjToInt()) { locationinfo2.LocationStatus = LocationStatusEnum.Pallet.ObjToInt(); } _basicService.LocationInfoService.Repository.UpdateData(locationinfo2); Dt_StockInfo stockInfo = _stockService.StockInfoService.Repository.QueryFirst(x => x.PalletCode == task.PalletCode); stockInfo.StockStatus = (int)StockStatusEmun.已入库; _stockService.StockInfoService.Repository.UpdateData(stockInfo); Dt_StockInfoDetail stocktdetail = _stockService.StockInfoDetailService.Repository.QueryFirst(x => x.StockId == stockInfo.Id); if (stocktdetail != null) { stocktdetail.Status = (int)StockStatusEmun.已入库; _stockService.StockInfoDetailService.Repository.UpdateData(stocktdetail); } BaseDal.DeleteData(task); BaseDal.DeleteAndMoveIntoHty(task, OperateType.人工删除); WriteLog.GetLog("任务日志").Write($"入库任务取消成功,托盘条码:{task.PalletCode}", $"任务取消"); WebResponseContent webResponseContent = HttpHelper.Post(ReceiveWCSTask, task.TaskNum, "任务删除"); return content = WebResponseContent.Instance.Error($"入库任务取消成功"); } else { return content = WebResponseContent.Instance.Error($"该任务的任务类型异常,取消失败"); } } else { return content = WebResponseContent.Instance.Error($"未找到任务号"); } } } }