1
dengjunjie
2025-03-11 c455612b03e6ecac994884dde5b5f4bc4909c181
ÏîÄ¿´úÂë/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
{
@@ -176,6 +177,11 @@
                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_StockInfo stockInfo = _stockService.StockInfoService.Repository.GetStockInfo(lineDTO.Barcode);
                if (stockInfo == null) throw new Exception($"未找到托盘[{lineDTO.Barcode}]的组盘信息");
                Dt_StockInfoDetail? stockInfoDetail = stockInfo.Details.Where(x => x.StockId == stockInfo.Id).FirstOrDefault();
@@ -241,7 +247,7 @@
                #region ä¿®æ”¹åº“存及货位信息
                task.TaskState = (int)InTaskStatusEnum.SC_InExecuting;
                task.CurrentAddress = task.NextAddress;
                task.NextAddress = locationInfo.LocationCode;//使用货位备注字段,对应堆垛机排列层
                task.NextAddress = locationInfo.LocationCode;
                task.TargetAddress = task.NextAddress;
                string[] targetCodes = task.NextAddress.Split("-");
                var Row = Convert.ToInt16(targetCodes[0]);
@@ -278,6 +284,79 @@
            return content;
        }
        /// <summary>
        /// èŽ·å–ç©ºæ‰˜ç›˜å…¥åº“è´§ä½
        /// </summary>
        /// <param name="task"></param>
        /// <returns></returns>
        public WebResponseContent GetEmptyLocation(Dt_Task task)
        {
            try
            {
                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 = _stockService.StockInfoDetailService.Repository.QueryData(x => x.MaterielCode == stockInfoDetail.MaterielCode).OrderByDescending(x => x.CreateDate).First();
                if (instockInfoDetail != null) instockInfo = _stockService.StockInfoService.Repository.GetStockInfo(instockInfoDetail.StockId);
                if (instockInfo != null)//无库存
                {
                    locationInfo = _basicRepository.LocationInfoRepository.QueryFirst(x => x.LocationCode == instockInfo.LocationCode);
                    if (ChargingStations.Contains(locationInfo.LocationCode))
                    {
                        if (locationInfo.MaxQty - locationInfo.CurrentQty <= 1) locationInfo = null;
                    }
                    else if (locationInfo.MaxQty - locationInfo.CurrentQty < 1)
                    {
                        locationInfo = null;
                    }
                }
                else
                {
                    locationInfo = _basicService.LocationInfoService.AssignLocation(ChargingStations);//查找穿梭车充电货位
                }
                if (locationInfo == null) locationInfo = _basicService.LocationInfoService.AssignLocation(2);//重新分配货位
                if (locationInfo == null) throw new Exception($"无可入货位");
                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);
                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);
            }
        }
    }
}