From 7ca9651f81d7b84f054194d3d46fdbd1d9c8b922 Mon Sep 17 00:00:00 2001 From: dengjunjie <dengjunjie@hnkhzn.com> Date: 星期三, 09 七月 2025 22:55:27 +0800 Subject: [PATCH] 增加质检出入库逻辑 --- 项目代码/WMS/WIDESEA_WMSServer/WIDESEA_TaskInfoService/PartialTaskService_Inbound.cs | 425 ++++++++++++++++++++++++++++++++++++++++------------ 1 files changed, 322 insertions(+), 103 deletions(-) diff --git "a/\351\241\271\347\233\256\344\273\243\347\240\201/WMS/WIDESEA_WMSServer/WIDESEA_TaskInfoService/PartialTaskService_Inbound.cs" "b/\351\241\271\347\233\256\344\273\243\347\240\201/WMS/WIDESEA_WMSServer/WIDESEA_TaskInfoService/PartialTaskService_Inbound.cs" index 26748a6..40f37d5 100644 --- "a/\351\241\271\347\233\256\344\273\243\347\240\201/WMS/WIDESEA_WMSServer/WIDESEA_TaskInfoService/PartialTaskService_Inbound.cs" +++ "b/\351\241\271\347\233\256\344\273\243\347\240\201/WMS/WIDESEA_WMSServer/WIDESEA_TaskInfoService/PartialTaskService_Inbound.cs" @@ -10,6 +10,7 @@ using WIDESEA_Core.Helper; using WIDESEAWCS_DTO.WCSInfo; using System.Transactions; +using OfficeOpenXml.FormulaParsing.Excel.Functions.RefAndLookup; namespace WIDESEA_TaskInfoService { @@ -113,7 +114,7 @@ Roadway = locationInfo.RoadwayNo, SourceAddress = stationCode, TargetAddress = locationInfo.LocationCode, - TaskStatus = InTaskStatusEnum.InNew.ObjToInt(), + TaskState = InTaskStatusEnum.InNew.ObjToInt(), TaskType = taskType, }; BaseDal.AddData(task); @@ -122,7 +123,7 @@ locationInfo.LocationStatus = LocationStatusEnum.PalletLock.ObjToInt(); if (isUpdateStock) { - locationInfo.LocationStatus = LocationStatusEnum.Lock.ObjToInt(); + locationInfo.LocationStatus = LocationStatusEnum.OutLock.ObjToInt(); if (stockInfo != null && stockInfo.Details != null && stockInfo.Details.Count > 0) { orderNo = stockInfo.Details.FirstOrDefault()?.OrderNo ?? ""; @@ -148,145 +149,363 @@ } return content; } + /// <summary> + /// 鍫嗗灈鏈虹敵璇峰叆搴� + /// </summary> + /// <param name="lineDTO"></param> + /// <returns></returns> + public WebResponseContent NewStackerCraneRequestInbound(ConveyorLineDTO lineDTO) + { + WebResponseContent content = new WebResponseContent(); + try + { + Dt_RoadwayInfo roadwayInfo = _basicRepository.RoadwayInfoRepository.QueryFirst(x => x.InStationCode == lineDTO.stationCode) ?? throw new Exception("鏈壘鍒拌绔欏彴瀵瑰簲鐨勫贩閬擄紝璇锋鏌ュ熀纭�閰嶇疆淇℃伅"); + if (roadwayInfo.EnableStatus != EnableStatusEnum.Normal.ObjToInt() && roadwayInfo.EnableStatus != EnableStatusEnum.OnlyIn.ObjToInt()) + { + throw new Exception("璇ュ贩閬撲笉鍙叆搴擄紝璇锋鏌ュ贩閬撶鐢ㄤ俊鎭�"); + } + if (roadwayInfo.AreaId > 0) + { + Dt_AreaInfo areaInfo = _basicRepository.AreaInfoRepository.QueryFirst(x => x.Id == roadwayInfo.AreaId); + if (areaInfo != null && areaInfo.AreaStatus == EnableEnum.Disable.ObjToInt()) + { + throw new Exception("鍖哄煙琚鐢紝涓嶅彲鍏ュ簱"); + } + } + var task = BaseDal.QueryFirst(x => x.PalletCode == lineDTO.Barcode); + if (task == null) throw new Exception($"鏈壘鍒版墭鐩樺彿[{lineDTO.Barcode}]鐨勫叆搴撲换鍔�"); + if (task.TaskState >= (int)InTaskStatusEnum.SC_InExecuting) throw new Exception($"鎵樼洏鍙穂{lineDTO.Barcode}]鐨勫叆搴撲换鍔$姸鎬佷笉鍖归厤"); + + #region 鍒ゆ柇鏄惁涓虹┖鎵樺叆搴� + if (task.TaskType == TaskTypeEnum.PalletInbound.ObjToInt()) + return GetEmptyLocation(task); + #endregion + + Dt_InventoryInfo inventoryInfo = _stockService.InventoryInfoService.Repository.QueryFirst(x => x.PalletCode == lineDTO.Barcode); + if (inventoryInfo == null) throw new Exception($"鏈壘鍒版墭鐩榌{lineDTO.Barcode}]鐨勭粍鐩樹俊鎭�"); + if (inventoryInfo.StockStatus != StockStatusEmun.鍏ュ簱纭.ObjToInt()) throw new Exception($"鎵樼洏[{lineDTO.Barcode}],璇ョ粍鐩樼姸鎬佷笉鍙叆搴�"); + if (!string.IsNullOrEmpty(inventoryInfo.LocationCode)) throw new Exception($"鎵樼洏[{lineDTO.Barcode}],宸插垎閰嶇粓鐐瑰湴鍧�"); + + Dt_InboundOrderDetail inboundOrderDetail = _inboundService.InboundOrderDetailService.Repository.QueryFirst(x => x.BatchNo == inventoryInfo.BatchNo); + if (inboundOrderDetail == null) throw new Exception($"鏈壘鍒版墭鐩榌{lineDTO.Barcode}]鐨勫叆搴撳崟鏄庣粏淇℃伅"); + Dt_LocationInfo? locationInfo = null; + + if (!string.IsNullOrEmpty(inboundOrderDetail.LocationCode)) + { + locationInfo = _basicService.LocationInfoService.GetLocation(inboundOrderDetail.LocationCode); + } + else + { + Dt_InventoryInfo? _InventoryInfo = _stockService.InventoryInfoService.Repository.QueryData(x => x.BatchNo == inventoryInfo.BatchNo && (x.StockStatus == StockStatusEmun.鍏ュ簱涓�.ObjToInt() || x.StockStatus == StockStatusEmun.宸插叆搴�.ObjToInt())).OrderByDescending(x => x.ModifyDate).FirstOrDefault(); + + if (_InventoryInfo != null) + { + locationInfo = _basicService.LocationInfoService.GetLocation(_InventoryInfo.LocationCode); + if (locationInfo?.MaxQty <= locationInfo?.CurrentQty) locationInfo = null; + } + if (locationInfo == null)//鍒嗛厤鏂拌揣浣� + { + var Qty = Convert.ToInt32(inboundOrderDetail.OrderQuantity - inboundOrderDetail.OverInQuantity); + var ts = Qty / 320; + if (Qty % 320 > 0) ts++; + int inboundOrderCount = ts > 12 ? 2 : 1; + locationInfo = _basicService.LocationInfoService.AssignLocation(inboundOrderCount);//閲嶆柊鍒嗛厤璐т綅 + } + } + if (locationInfo == null) throw new Exception($"鏃犲彲鍏ヨ揣浣�"); + + #region 淇敼搴撳瓨鍙婅揣浣嶄俊鎭� + task.TaskState = (int)InTaskStatusEnum.SC_InExecuting; + task.CurrentAddress = task.NextAddress; + task.NextAddress = locationInfo.LocationCode; + task.TargetAddress = task.NextAddress; + task.TargetIsPickPlace = locationInfo.MaxQty - locationInfo.CurrentQty == 1; + task.SourceIsPickPlace = false; + inventoryInfo.LocationCode = locationInfo.LocationCode; + inventoryInfo.StockStatus = StockStatusEmun.鍏ュ簱涓�.ObjToInt(); + locationInfo.CurrentQty++; + if (locationInfo.MaxQty < locationInfo.CurrentQty) locationInfo.CurrentQty = locationInfo.MaxQty; + inventoryInfo.SerialNumber = locationInfo.CurrentQty; + inboundOrderDetail.OverInQuantity = inboundOrderDetail.OverInQuantity + inventoryInfo.StockQuantity; + if (inboundOrderDetail.OverInQuantity > inboundOrderDetail.ReceiptQuantity) + inboundOrderDetail.OverInQuantity = inboundOrderDetail.ReceiptQuantity; + locationInfo.EnableStatus = EnableStatusEnum.OnlyOut.ObjToInt(); + locationInfo.LocationStatus = LocationStatusEnum.Inbounding.ObjToInt(); + + Db.Ado.BeginTran(); + UpdateData(task); + _stockService.InventoryInfoService.Repository.UpdateData(inventoryInfo); + if (inboundOrderDetail.OverInQuantity == inboundOrderDetail.OrderQuantity) + { + inboundOrderDetail.OrderDetailStatus = OrderDetailStatusEnum.Over.ObjToInt(); + Dt_InboundOrder inboundOrder = _inboundService.InbounOrderService.Repository.QueryFirst(x => x.Id == inboundOrderDetail.OrderId); + inboundOrder.OrderStatus = InboundStatusEnum.鍏ュ簱瀹屾垚.ObjToInt(); + _inboundService.InbounOrderService.Repository.DeleteAndMoveIntoHty(inboundOrder, OperateType.鑷姩瀹屾垚); + _inboundService.InboundOrderDetailService.Repository.DeleteAndMoveIntoHty(inboundOrderDetail, OperateType.鑷姩瀹屾垚); + } + else + _inboundService.InboundOrderDetailService.Repository.UpdateData(inboundOrderDetail); + _basicService.LocationInfoService.Repository.UpdateData(locationInfo); + Db.Ado.CommitTran(); + #endregion + content.OK(data: new ReceiveWMSInfo() + { + TargetAddress = task.TargetAddress, + SourceIsPickPlace = task.SourceIsPickPlace, + TargetIsPickPlace = task.TargetIsPickPlace, + }); + } + catch (Exception ex) + { + Db.Ado.RollbackTran(); + content.Error(ex.Message); + } + return content; + } /// <summary> - /// 鍫嗗灈鏈虹敵璇峰叆搴擄紒锛侊紒锛侊紒锛侊紒鍏ュ簱鍒嗛厤閫昏緫寰呭畾 + /// 鍫嗗灈鏈虹敵璇峰叆搴� /// </summary> /// <param name="task"></param> /// <returns></returns> public WebResponseContent StackerCraneRequestInbound(ConveyorLineDTO lineDTO) { - WebResponseContent content = new WebResponseContent().OK(); + WebResponseContent content = new WebResponseContent(); try { + Dt_RoadwayInfo roadwayInfo = _basicRepository.RoadwayInfoRepository.QueryFirst(x => x.InStationCode == lineDTO.stationCode) ?? throw new Exception("鏈壘鍒拌绔欏彴瀵瑰簲鐨勫贩閬擄紝璇锋鏌ュ熀纭�閰嶇疆淇℃伅"); + if (roadwayInfo.EnableStatus != EnableStatusEnum.Normal.ObjToInt() && roadwayInfo.EnableStatus != EnableStatusEnum.OnlyIn.ObjToInt()) + { + throw new Exception("璇ュ贩閬撲笉鍙叆搴擄紝璇锋鏌ュ贩閬撶鐢ㄤ俊鎭�"); + } + if (roadwayInfo.AreaId > 0) + { + Dt_AreaInfo areaInfo = _basicRepository.AreaInfoRepository.QueryFirst(x => x.Id == roadwayInfo.AreaId); + if (areaInfo != null && areaInfo.AreaStatus == EnableEnum.Disable.ObjToInt()) + { + throw new Exception("鍖哄煙琚鐢紝涓嶅彲鍏ュ簱"); + } + } var task = BaseDal.QueryFirst(x => x.PalletCode == lineDTO.Barcode); if (task == null) throw new Exception($"鏈壘鍒版墭鐩樺彿[{lineDTO.Barcode}]鐨勫叆搴撲换鍔�"); - if (task.TaskStatus != (int)InTaskStatusEnum.Line_InFinish) throw new Exception($"鎵樼洏鍙穂{lineDTO.Barcode}]鐨勫叆搴撲换鍔$姸鎬佷笉鍖归厤"); + if (task.TaskState >= (int)InTaskStatusEnum.SC_InExecuting) throw new Exception($"鎵樼洏鍙穂{lineDTO.Barcode}]鐨勫叆搴撲换鍔$姸鎬佷笉鍖归厤"); + + #region 鍒ゆ柇鏄惁涓虹┖鎵樺叆搴� + if (task.TaskType == TaskTypeEnum.PalletInbound.ObjToInt()) + return GetEmptyLocation(task); + #endregion Dt_StockInfo stockInfo = _stockService.StockInfoService.Repository.GetStockInfo(lineDTO.Barcode); if (stockInfo == null) throw new Exception($"鏈壘鍒版墭鐩榌{lineDTO.Barcode}]鐨勭粍鐩樹俊鎭�"); - if (stockInfo.StockStatus != StockStatusEmun.鍏ュ簱纭.ObjToInt()) throw new Exception($"鎵樼洏[{lineDTO.Barcode}],璇ョ粍鐩樼姸鎬佷笉鍙叆搴�"); - Dt_LocationInfo? locationInfo = _basicService.LocationInfoService.AssignLocation(lineDTO.stationCode, TaskTypeEnum.Inbound.ObjToInt()); - if (locationInfo == null) throw new Exception($"鏃犲彲鍏ヨ揣浣�"); - locationInfo.LocationStatus = LocationStatusEnum.Inbounding.ObjToInt(); - stockInfo.StockStatus = StockStatusEmun.鍏ュ簱涓�.ObjToInt(); - using (TransactionScope scope = new TransactionScope()) - { - _basicService.LocationInfoService.Repository.UpdateData(locationInfo); - _stockService.StockInfoService.Repository.UpdateData(stockInfo); - scope.Complete(); - } - content.Data = new ReceiveWMSInfo() - { - TargetAddress = locationInfo.LocationCode, - IsPickPlace = locationInfo.MaxQty - locationInfo.CurrentQty == 1, - }; - } - catch (Exception ex) - { - content.Error(ex.Message); - } - return content; - } - /// <summary> - /// 杈撻�佺嚎鐢宠鍏ュ簱 - /// </summary> - /// <param name="lineDTO"></param> - /// <returns></returns> - public WebResponseContent ConveyorLineRequestInbound(ConveyorLineDTO lineDTO) - { - WebResponseContent content = new WebResponseContent().OK(); - try - { - var task = BaseDal.QueryFirst(x => x.PalletCode == lineDTO.Barcode); - if (task == null) throw new Exception($"鏈壘鍒版墭鐩樺彿[{lineDTO.Barcode}]鐨勫叆搴撲换鍔�"); - if (task.TaskStatus != (int)InTaskStatusEnum.AGV_InFinish) throw new Exception($"鎵樼洏鍙穂{lineDTO.Barcode}]鐨勫叆搴撲换鍔$姸鎬佷笉鍖归厤"); + Dt_StockInfoDetail? stockInfoDetail = stockInfo.Details.Where(x => x.StockId == stockInfo.Id).FirstOrDefault(); + if (stockInfoDetail == null) throw new Exception($"鏈壘鍒版墭鐩榌{lineDTO.Barcode}]鐨勭粍鐩樿鎯�"); + if (stockInfo.StockStatus != StockStatusEmun.鍏ュ簱纭.ObjToInt() || !string.IsNullOrEmpty(stockInfo.LocationCode)) + throw new Exception($"鎵樼洏[{lineDTO.Barcode}],璇ョ粍鐩樼姸鎬佷笉鍙叆搴�"); - Dt_StockInfo stockInfo = _stockService.StockInfoService.Repository.GetStockInfo(lineDTO.Barcode); - (bool, string) result = CheckRequestInbound(lineDTO.stationCode, lineDTO.Barcode, true, stockInfo); - if (!result.Item1) return content = WebResponseContent.Instance.Error(result.Item2); + Dt_InboundOrder inboundOrder = _inboundService.InbounOrderService.GetInboundOrder(stockInfoDetail.OrderNo); + if (inboundOrder == null) throw new Exception($"鏈壘鍒版墭鐩榌{lineDTO.Barcode}]鐨勫叆搴撳崟淇℃伅"); - if (lineDTO.Spec != 1 || lineDTO.Weight != 500)//鏉′欢闇�鏇存敼锛侊紒锛侊紒锛侊紒锛侊紒锛侊紒 + var BatchNo = stockInfoDetail.BatchNo; + #region 鍒ゆ柇鏄惁鎸囧畾璐т綅 + Dt_InboundOrderDetail? orderDetail = inboundOrder.Details.FirstOrDefault(x => x.BatchNo == stockInfoDetail.BatchNo); + if (orderDetail == null) throw new Exception($"鏈壘鍒版墭鐩榌{lineDTO.Barcode}]鐨勫叆搴撳崟鏄庣粏淇℃伅"); + Dt_LocationInfo? locationInfo = null; + if (!string.IsNullOrEmpty(orderDetail.LocationCode)) { - task.NextAddress = "101"; - task.TaskStatus = (int)InTaskStatusEnum.InException; - task.Remark = $"鎵樼洏[{lineDTO.Barcode}]淇℃伅涓嶅悎鏍�"; - stockInfo.StockStatus = StockStatusEmun.鍏ュ簱鎾ら攢.ObjToInt(); - } - else - { - task.NextAddress = "104"; - task.CurrentAddress = lineDTO.stationCode; - task.TaskStatus = (int)InTaskStatusEnum.Line_InExecuting; - stockInfo.StockStatus = StockStatusEmun.鍏ュ簱纭.ObjToInt(); - } - - #region 浜嬪姟 - using (TransactionScope scope = new TransactionScope()) - { - BaseDal.UpdateData(task); - Db.Updateable(stockInfo); - scope.Complete(); + locationInfo = _basicService.LocationInfoService.GetLocation(orderDetail.LocationCode); } #endregion - if (!string.IsNullOrEmpty(task.Remark)) throw new Exception(task.Remark); + else + { + #region 鍒ゆ柇褰撳墠鍏ュ簱鎵樼洏鎵规鍙锋槸鍚﹀瓨鍦ㄥ凡鍒嗛厤鍏ュ簱 + Dt_StockInfo? instockInfo = null; + Dt_StockInfoDetail instockInfoDetail = _stockService.StockInfoDetailService.Get_StockInfoDetail(stockInfoDetail.OrderNo, stockInfoDetail.BatchNo); + if (instockInfoDetail != null) instockInfo = _stockService.StockInfoService.Repository.GetStockInfo(instockInfoDetail.StockId); + if (instockInfo != null) + { + locationInfo = _basicService.LocationInfoService.GetLocation(instockInfo.LocationCode); + if (locationInfo?.MaxQty <= locationInfo?.CurrentQty) locationInfo = null; + } + #endregion + else + { + instockInfoDetail = _stockService.StockInfoDetailService.Get_StockInfoDetail(stockInfoDetail.OrderNo /*BatchNo*/);//鍏ュ簱鍗曞瓨鍦ㄥ簱瀛橈紝鍒ゆ柇璐т綅 + if (instockInfoDetail != null) instockInfo = _stockService.StockInfoService.Repository.GetStockInfo(instockInfoDetail.StockId); + if (instockInfo != null) + { + Dt_LocationInfo? location = _basicService.LocationInfoService.GetLocation(instockInfo.LocationCode);//鏌ヨ宸插瓨鍦ㄥ簱瀛樿揣浣嶇姸鎬� + if (location?.Row == 1) + { + var instockInfos = _stockService.StockInfoService.Repository.GetDt_StockInfos(instockInfo.LocationCode); + List<Dt_StockInfoDetail> Details = new List<Dt_StockInfoDetail>(); + foreach (var item in instockInfos) + { + Details.AddRange(item.Details); + } + var count = Details.GroupBy(x => x.BatchNo).Count(); + if (count <= 1) locationInfo = location; + } + } + } + + if (locationInfo == null)//鍒嗛厤鏂拌揣浣� + { + List<Dt_InboundOrderDetail> inboundOrderDetailList = inboundOrder.Details.Where(x => /*x.BatchNo.Contains(BatchNo) &&*/ x.OverInQuantity == 0).ToList(); + int inboundOrderCount = inboundOrderDetailList.Count; + locationInfo = _basicService.LocationInfoService.AssignLocation(inboundOrderCount);//閲嶆柊鍒嗛厤璐т綅 + } + } + + + if (locationInfo == null) throw new Exception($"鏃犲彲鍏ヨ揣浣�"); + + #region 淇敼搴撳瓨鍙婅揣浣嶄俊鎭� + task.TaskState = (int)InTaskStatusEnum.SC_InExecuting; + task.CurrentAddress = task.NextAddress; + task.NextAddress = locationInfo.LocationCode; + task.TargetAddress = task.NextAddress; + string[] targetCodes = task.NextAddress.Split("-"); + var Row = Convert.ToInt16(targetCodes[0]); + task.TargetIsPickPlace = locationInfo.MaxQty - locationInfo.CurrentQty == 1; + task.SourceIsPickPlace = false; + stockInfo.LocationCode = locationInfo.LocationCode; + stockInfo.StockStatus = StockStatusEmun.鍏ュ簱涓�.ObjToInt(); + stockInfoDetail.Status = StockStatusEmun.鍏ュ簱涓�.ObjToInt(); + locationInfo.CurrentQty++; + if (locationInfo.MaxQty < locationInfo.CurrentQty) locationInfo.CurrentQty = locationInfo.MaxQty; + stockInfo.SerialNumber = locationInfo.CurrentQty; + orderDetail.OverInQuantity++; + if (orderDetail.OverInQuantity > orderDetail.ReceiptQuantity) + orderDetail.OverInQuantity = orderDetail.ReceiptQuantity; + locationInfo.EnableStatus = EnableStatusEnum.OnlyOut.ObjToInt(); + locationInfo.LocationStatus = LocationStatusEnum.Inbounding.ObjToInt(); + + Db.Ado.BeginTran(); + UpdateData(task); + _stockService.StockInfoService.Repository.UpdateData(stockInfo); + _inboundService.InboundOrderDetailService.Repository.UpdateData(orderDetail); + _stockService.StockInfoDetailService.Repository.UpdateData(stockInfoDetail); + _basicService.LocationInfoService.Repository.UpdateData(locationInfo); + Db.Ado.CommitTran(); + #endregion + content.OK(data: new ReceiveWMSInfo() + { + TargetAddress = task.TargetAddress, + SourceIsPickPlace = task.SourceIsPickPlace, + TargetIsPickPlace = task.TargetIsPickPlace, + }); } catch (Exception ex) { - content.Code = 404; + Db.Ado.RollbackTran(); content.Error(ex.Message); } return content; } + /// <summary> - /// 楠岃瘉鏁版嵁 + /// 鑾峰彇绌烘墭鐩樺叆搴撹揣浣� /// </summary> - /// <param name="stationCode">璧峰鍦板潃</param> - /// <param name="palletCode">鎵樼洏缂栧彿</param> - /// <param name="isCheckStock">鏄惁妫�鏌ョ粍鐩樹俊鎭�--鍖哄垎鐗╂枡鍏ュ簱鍜岀┖鎵樺叆搴�</param> - /// <param name="stockInfo">缁勭洏淇℃伅--鍙┖</param> - /// <returns>杩斿洖澶勭悊缁撴灉</returns> - private (bool, string) CheckRequestInbound(string stationCode, string palletCode, bool isCheckStock = true, Dt_StockInfo? stockInfo = null) + /// <param name="task"></param> + /// <returns></returns> + public WebResponseContent GetEmptyLocation(Dt_Task task) { - //if (BaseDal.QueryFirst(x => x.PalletCode == palletCode) != null) - //{ - // return (false, "璇ユ墭鐩樺彿宸叉湁浠诲姟"); - //} - if (BaseDal.QueryFirst(x => (x.SourceAddress == stationCode || x.CurrentAddress == stationCode) && x.TaskStatus == InTaskStatusEnum.AGV_InFinish.ObjToInt()) != null) + try { - return (false, "褰撳墠鍏ュ簱绔欏彴宸叉湁涓�鏉′换鍔�"); - } - if (isCheckStock) - { - if (stockInfo == null) + Dt_StockInfo stockInfo = _stockService.StockInfoService.Repository.GetStockInfo(task.PalletCode); + if (stockInfo == null) throw new Exception($"鏈壘鍒版墭鐩榌{task.PalletCode}]鐨勭粍鐩樹俊鎭�"); + Dt_StockInfoDetail? stockInfoDetail = stockInfo.Details.Where(x => x.StockId == stockInfo.Id).FirstOrDefault(); + if (stockInfoDetail == null) throw new Exception($"鏈壘鍒版墭鐩榌{task.PalletCode}]鐨勭粍鐩樿鎯�"); + if (stockInfo.StockStatus != StockStatusEmun.鍏ュ簱纭.ObjToInt() || !string.IsNullOrEmpty(stockInfo.LocationCode)) + throw new Exception($"鎵樼洏[{task.PalletCode}],璇ョ粍鐩樼姸鎬佷笉鍙叆搴�"); + Dt_StockInfo? instockInfo = null; + Dt_LocationInfo? locationInfo = null; + string CarChargingStation = AppSettings.Configuration[nameof(CarChargingStation)];//鑾峰彇绌挎杞﹀厖鐢典綅缃� + var ChargingStations = CarChargingStation.Split(","); + Dt_StockInfoDetail? instockInfoDetail = null; + var instockInfoDetails = _stockService.StockInfoDetailService.Repository.QueryData(x => x.MaterielCode == stockInfoDetail.MaterielCode && x.Status == StockStatusEmun.鍏ュ簱涓�.ObjToInt()); + if (instockInfoDetails.Count > 0) + instockInfoDetail = instockInfoDetails.OrderByDescending(x => x.CreateDate).First(); + if (instockInfoDetails.Count < 1) { - return (false, "鏈壘鍒扮粍鐩樹俊鎭�"); + instockInfoDetails = _stockService.StockInfoDetailService.Repository.QueryData(x => x.MaterielCode == stockInfoDetail.MaterielCode && x.Status == StockStatusEmun.宸插叆搴�.ObjToInt()); + if (instockInfoDetails.Count > 0) + instockInfoDetail = instockInfoDetails.OrderByDescending(x => x.CreateDate).First(); } - if (stockInfo.StockStatus != StockStatusEmun.缁勭洏鏆傚瓨.ObjToInt()) + if (instockInfoDetail != null) instockInfo = _stockService.StockInfoService.Repository.GetStockInfo(instockInfoDetail.StockId); + if (instockInfo != null)//鏃犲簱瀛� { - return (false, "璇ョ粍鐩樼姸鎬佷笉鍙叆搴�"); + locationInfo = _basicRepository.LocationInfoRepository.QueryFirst(x => x.LocationCode == instockInfo.LocationCode); + //if (BaseDal.QueryFirst(x => x.SourceAddress == locationInfo.LocationCode && x.TaskState < OutTaskStatusEnum.SC_OutFinish.ObjToInt()) != null) locationInfo = null; + if (locationInfo != null && ChargingStations.Contains(locationInfo.LocationCode)) + { + if (locationInfo.MaxQty - locationInfo.CurrentQty <= 1) locationInfo = null; + } + else if (locationInfo != null && locationInfo.MaxQty - locationInfo.CurrentQty < 1) + { + locationInfo = null; + } + if (locationInfo == null) + { + var locationInfos = _basicService.LocationInfoService.GetLocationPallet(); + foreach (var item in locationInfos) + { + if (BaseDal.QueryFirst(x => x.SourceAddress == item.LocationCode) == null) + { + locationInfo = item; + break; + } + } + } } - if (!string.IsNullOrEmpty(stockInfo.LocationCode)) + //else + //{ + // locationInfo = _basicService.LocationInfoService.AssignLocation(ChargingStations);//鏌ユ壘绌挎杞﹀厖鐢佃揣浣� + //} + if (locationInfo == null) locationInfo = _basicService.LocationInfoService.AssignLocation(2);//閲嶆柊鍒嗛厤璐т綅 + if (locationInfo == null) throw new Exception($"鏃犲彲鍏ヨ揣浣�"); + Dt_LocationInfo? locationInfo1 = null; + if (locationInfo.Row == 1) { - return (false, "璇ユ墭鐩樺凡缁戝畾璐т綅"); + locationInfo1 = _basicService.LocationInfoService.Repository.QueryFirst(x => x.Row == 2 && x.Layer == locationInfo.Layer && x.Column == locationInfo.Column); + locationInfo1.LocationStatus = LocationStatusEnum.Pallet.ObjToInt(); } - if (stockInfo.Details == null || stockInfo.Details.Count == 0) - { - return (false, "娌℃湁搴撳瓨鏄庣粏淇℃伅"); - } - } - else - { - if (_stockService.StockInfoService.Repository.QueryFirst(x => x.PalletCode == palletCode) != null) - { - return (false, "璇ユ墭鐩樺凡瀛樺湪搴撳唴"); - } - } - return (true, "鎴愬姛"); + task.TaskState = (int)InTaskStatusEnum.SC_InExecuting; + task.CurrentAddress = task.NextAddress; + task.NextAddress = locationInfo.LocationCode; + task.TargetAddress = task.NextAddress; + task.TargetIsPickPlace = locationInfo.Row > 1 ? locationInfo.MaxQty - locationInfo.CurrentQty == 1 : false; + task.SourceIsPickPlace = false; + stockInfo.LocationCode = locationInfo.LocationCode; + stockInfo.StockStatus = StockStatusEmun.鍏ュ簱涓�.ObjToInt(); + stockInfoDetail.Status = StockStatusEmun.鍏ュ簱涓�.ObjToInt(); + locationInfo.CurrentQty++; + if (locationInfo.MaxQty < locationInfo.CurrentQty) throw new Exception(); + locationInfo.EnableStatus = EnableStatusEnum.OnlyOut.ObjToInt(); + locationInfo.LocationStatus = LocationStatusEnum.Inbounding.ObjToInt(); + + Db.Ado.BeginTran(); + UpdateData(task); + _stockService.StockInfoService.Repository.UpdateData(stockInfo); + _stockService.StockInfoDetailService.Repository.UpdateData(stockInfoDetail); + _basicService.LocationInfoService.Repository.UpdateData(locationInfo); + if (locationInfo1 != null) _basicService.LocationInfoService.Repository.UpdateData(locationInfo1); + Db.Ado.CommitTran(); + + return WebResponseContent.Instance.OK(data: new ReceiveWMSInfo() + { + TargetAddress = task.TargetAddress, + SourceIsPickPlace = task.SourceIsPickPlace, + TargetIsPickPlace = task.TargetIsPickPlace, + }); + } + catch (Exception ex) + { + Db.Ado.RollbackTran(); + return WebResponseContent.Instance.Error(ex.Message); + } } - - } } -- Gitblit v1.9.3