duyongjia
2024-12-28 6be2bc8324ca81145830b758c110255d9dfdc00b
ÏîÄ¿´úÂë/WMS/WIDESEA_WMSServer/WIDESEA_TaskInfoService/PartialTaskService_Outbound.cs
@@ -60,6 +60,47 @@
            return tasks;
        }
        /// <summary>
        /// åº“存数据转出库任务,任务需关联任务明细ID
        /// </summary>
        /// <param name="stockInfos"></param>
        /// <returns></returns>
        public List<Dt_Task> GetTasksOutBoundDetailId(List<Dt_StockInfo> stockInfos,int detailId)
        {
            List<Dt_Task> tasks = new List<Dt_Task>();
            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 = 3,
                            PalletCode = stockInfo.PalletCode,
                            NextAddress = roadwayInfo.OutStationCode,
                            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)),
                            Remark = detailId.ToString()//用于任务关联出库单明细
                        };
                        tasks.Add(task);
                    }
                }
            }
            return tasks;
        }
        /// <summary>
        /// å‡ºåº“任务数据处理
        /// </summary>
@@ -90,7 +131,8 @@
                (List<Dt_StockInfo>, Dt_OutboundOrderDetail, List<Dt_OutStockLockInfo>, List<Dt_LocationInfo>) result = _outboundService.OutboundOrderDetailService.AssignStockOutbound(outboundOrderDetail, stockSelectViews);
                if (result.Item1 != null && result.Item1.Count > 0)
                {
                    tasks = GetTasks(result.Item1);
                    //tasks = GetTasks(result.Item1);
                    tasks = GetTasksOutBoundDetailId(result.Item1, orderDetailId);
                    result.Item2.OrderDetailStatus = OrderDetailStatusEnum.Outbound.ObjToInt();
                    result.Item3.ForEach(x =>
                    {
@@ -113,7 +155,8 @@
                if (stockLockInfos != null && stockLockInfos.Count > 0)
                {
                    List<Dt_StockInfo> stocks = _stockService.StockInfoService.Repository.GetStockInfosByPalletCodes(stockLockInfos.Select(x => x.PalletCode).Distinct().ToList());
                    tasks = GetTasks(stocks);
                    //tasks = GetTasks(stocks);
                    tasks = GetTasksOutBoundDetailId(stocks, orderDetailId);
                }
            }
@@ -353,7 +396,7 @@
                            SourceAddress = location.LocationCode,
                            TargetAddress = locationInfos.LocationCode,
                            TaskStatus = InTaskStatusEnum.RelocationNew.ObjToInt(),
                            TaskType = TaskTypeEnum.Relocation.ObjToInt(),
                            //TaskType = TaskTypeEnum.Relocation.ObjToInt(),
                            Depth= location.Depth,
                            TaskNum = BaseDal.GetTaskNum(nameof(SequenceEnum.SeqTaskNum))
                        };
@@ -435,14 +478,18 @@
        /// </summary>
        /// <param name="inTask"></param>
        /// <returns></returns>
        public WebResponseContent PalletOutboundTask(string roadwayNo, string endStation)
        public WebResponseContent PalletOutboundTask(string roadwayNo, string endStation,string strayType)
        {
            try
            {
                Dt_StockInfo stockInfo = _stockService.StockInfoService.Repository.GetPalletStockInfo(roadwayNo);
                Dt_StockInfo stockInfo = _stockService.StockInfoService.Repository.GetPalletStockInfo(roadwayNo,strayType);
                if (stockInfo == null)
                {
                    return WebResponseContent.Instance.Error("未找到空托盘库存");
                }
                if (BaseDal.QueryFirst(x => (x.TargetAddress == endStation) && x.TaskStatus == OutTaskStatusEnum.OutNew.ObjToInt()) != null)
                {
                    return WebResponseContent.Instance.Error("当前出库站台已经有一台新的出库任务!");
                }
                Dt_LocationInfo locationInfo = _basicService.LocationInfoService.Repository.QueryFirst(x => x.LocationCode == stockInfo.LocationCode && x.RoadwayNo == roadwayNo);
                if (locationInfo == null)
@@ -467,53 +514,64 @@
                    TaskStatus = OutTaskStatusEnum.OutNew.ObjToInt(),
                    TaskType = TaskTypeEnum.PalletOutbound.ObjToInt(),
                    Depth = locationInfo.Depth,
                    TaskNum = BaseDal.GetTaskNum(nameof(SequenceEnum.SeqTaskNum))
                    TaskNum = BaseDal.GetTaskNum(nameof(SequenceEnum.SeqTaskNum)),
                    Creater = "System"
                };
                int beforeStatus = locationInfo.LocationStatus;
                _unitOfWorkManage.BeginTran();
                BaseDal.AddData(task);
                stockInfo.StockStatus = StockStatusEmun.出库锁定.ObjToInt();
                locationInfo.LocationStatus = LocationStatusEnum.Lock.ObjToInt();
                tasks.Add(task);
                (List<Dt_Task>?, List<Dt_Task>?) result = RelocationTasks(tasks.OrderBy(x => x.Depth).ToList());
                if (result.Item1 != null && result.Item1.Count > 0)
                {
                    for (int i = 0; i < result.Item1.Count; i++)
                    {
                        result.Item1[i].Grade = 1;
                    }
                    AddData(result.Item1);
                    var response = HttpHelper.Post<WebResponseContent>(url + "ReceiveTask/", result.Item1, "入库任务下发");
                    if (!response.Status)
                    {
                        _unitOfWorkManage.RollbackTran();
                        return  WebResponseContent.Instance.Error($"{response.Message}");
                    }
                }
                if (result.Item2 != null && result.Item2.Count > 0)
                {
                    for (int i = 0; i < result.Item2.Count; i++)
                    {
                        Dt_LocationInfo location = _basicService.LocationInfoService.Repository.QueryFirst(x => x.LocationCode == result.Item2[i].SourceAddress && x.RoadwayNo == result.Item2[i].Roadway);
                        if (location.Depth == 2)
                        {
                            _basicService.LocationInfoService.UpdateLocationLock(location, result.Item2[i].TaskNum, StockChangeType.Outbound.ObjToInt(), false);
                        }
                        result.Item2[i].Grade = 1;
                    }
                    AddData(result.Item2);
                    var response = HttpHelper.Post<WebResponseContent>(url + "ReceiveTask/", result.Item2, "出库任务下发");
                    if (!response.Status)
                    {
                        _unitOfWorkManage.RollbackTran();
                        return  WebResponseContent.Instance.Error($"{response.Message}");
                    }
                }
                //(List<Dt_Task>?, List<Dt_Task>?) result = RelocationTasks(tasks.OrderBy(x => x.Depth).ToList());
                //if (result.Item1 != null && result.Item1.Count > 0)
                //{
                //    for (int i = 0; i < result.Item1.Count; i++)
                //    {
                //        result.Item1[i].Grade = 1;
                //    }
                //    AddData(result.Item1);
                //    var response = HttpHelper.Post<WebResponseContent>(url + "ReceiveTask/", result.Item1, "入库任务下发");
                //    if (!response.Status)
                //    {
                //        _unitOfWorkManage.RollbackTran();
                //        return  WebResponseContent.Instance.Error($"{response.Message}");
                //    }
                //}
                //if (result.Item2 != null && result.Item2.Count > 0)
                //{
                //    for (int i = 0; i < result.Item2.Count; i++)
                //    {
                //        Dt_LocationInfo location = _basicService.LocationInfoService.Repository.QueryFirst(x => x.LocationCode == result.Item2[i].SourceAddress && x.RoadwayNo == result.Item2[i].Roadway);
                //        if (location.Depth == 2)
                //        {
                //            _basicService.LocationInfoService.UpdateLocationLock(location, result.Item2[i].TaskNum, StockChangeType.Outbound.ObjToInt(), false);
                //        }
                //        result.Item2[i].Grade = 1;
                //    }
                //    AddData(result.Item2);
                //    var response = HttpHelper.Post<WebResponseContent>(url + "ReceiveTask/", result.Item2, "出库任务下发");
                //    if (!response.Status)
                //    {
                //        _unitOfWorkManage.RollbackTran();
                //        return  WebResponseContent.Instance.Error($"{response.Message}");
                //    }
                //}
                _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);
                var response = HttpHelper.Post<WebResponseContent>(url + "ReceiveTask/", tasks, "出库任务下发");
                if (!response.Status)
                {
                    _unitOfWorkManage.RollbackTran();
                    return WebResponseContent.Instance.Error($"{response.Message}");
                }
                _unitOfWorkManage.CommitTran();
                return WebResponseContent.Instance.OK();
            }