pan
2025-12-03 1b80ac5c10cd02ac0fac487b4ab9a2c6b935f8ad
ÏîÄ¿´úÂë/WMSÎÞ²Ö´¢°æ/WIDESEA_WMSServer/WIDESEA_TaskInfoService/TaskService_Outbound.cs
@@ -31,95 +31,93 @@
        /// </summary>
        /// <param name="inTask"></param>
        /// <returns></returns>
        public async Task<WebResponseContent> PalletOutboundTask(string endStation, string palletCode = "")
        public async Task<WebResponseContent> PalletOutboundTask(int num)
        {
            WebResponseContent content = new WebResponseContent();
            try
            {
                Dt_StockInfo stockInfo;
                if (string.IsNullOrEmpty(palletCode))
                {
                    stockInfo = _stockRepository.Db.Queryable<Dt_StockInfo>().Where(x => x.PalletType == PalletTypeEnum.Empty.ObjToInt() && x.StockStatus == StockStatusEmun.入库完成.ObjToInt() && !string.IsNullOrWhiteSpace(x.LocationCode)).First();
                }
                else
                {
                    stockInfo = _stockRepository.Db.Queryable<Dt_StockInfo>().Where(x => x.PalletType == PalletTypeEnum.Empty.ObjToInt() && x.PalletCode == palletCode && x.StockStatus == StockStatusEmun.入库完成.ObjToInt()).First();
                }
                var stockInfos = _stockRepository.Db.Queryable<Dt_StockInfo>().Where(x => x.PalletType == PalletTypeEnum.Empty.ObjToInt() && x.StockStatus == StockStatusEmun.入库完成.ObjToInt()).ToList();
                if (stockInfo == null)
                if (stockInfos.Count() == 0)
                {
                    return WebResponseContent.Instance.Error("未找到空托盘库存");
                }
                Dt_LocationInfo locationInfo = _locationInfoService.Repository.QueryFirst(x => x.LocationCode == stockInfo.LocationCode);
                if (locationInfo == null)
                for (int i = 0; i < num; i++)
                {
                    return WebResponseContent.Instance.Error("未找到空托盘库存对应的货位信息");
                }
                Dt_Task task = new Dt_Task()
                {
                    CurrentAddress = stockInfo.LocationCode,
                    Grade = 0,
                    NextAddress = endStation,
                    PalletCode = stockInfo.PalletCode,
                    Roadway = locationInfo.RoadwayNo,
                    SourceAddress = stockInfo.LocationCode,
                    TargetAddress = endStation,
                    TaskStatus = TaskStatusEnum.New.ObjToInt(),
                    TaskType = TaskTypeEnum.OutEmpty.ObjToInt(),
                    WarehouseId = stockInfo.WarehouseId,
                    PalletType = stockInfo.PalletType
                };
                int beforeStatus = locationInfo.LocationStatus;
                _unitOfWorkManage.BeginTran();
                stockInfo.StockStatus = StockStatusEmun.出库锁定.ObjToInt();
                locationInfo.LocationStatus = LocationStatusEnum.Lock.ObjToInt();
                int taskId = BaseDal.AddData(task);
                task.TaskId = taskId;
                _stockService.StockInfoService.UpdateData(stockInfo);
                _locationInfoService.UpdateData(locationInfo);
                _recordService.LocationStatusChangeRecordSetvice.AddLocationStatusChangeRecord(locationInfo, beforeStatus, StockChangeType.Outbound.ObjToInt(), "", task.TaskNum);
                _unitOfWorkManage.CommitTran();
                TaskModel esstask = new TaskModel()
                {
                    taskType = "carry",
                    taskGroupCode = "",
                    groupPriority = 0,
                    tasks = new List<TasksType>
                    var stockInfo = stockInfos.Where(x=>x.StockStatus != StockStatusEmun.出库锁定.ObjToInt()).FirstOrDefault();
                    Dt_LocationInfo locationInfo = _locationInfoService.Repository.QueryFirst(x => x.LocationCode == stockInfo.LocationCode);
                    if (locationInfo == null)
                    {
                            new()
                            {
                                taskCode=task.TaskNum.ToString(),
                                taskPriority=0,
                                taskDescribe=new TaskDescribeType{
                                containerCode=stockInfo.PalletCode,
                                containerType= "CT_KUBOT_STANDARD",
                                fromLocationCode=stockInfo.LocationCode??"",
                                toStationCode="",
                                toLocationCode=endStation,
                                deadline=0,storageTag=""
                                }
                            }
                        return WebResponseContent.Instance.Error("未找到空托盘库存对应的货位信息");
                    }
                };
                var result = await _eSSApiService.CreateTaskAsync(esstask);
                _logger.LogInformation("创建任务PalletOutboundTask è¿”回:  " + result);
                if (result)
                {
                    return WebResponseContent.Instance.OK(200);
                }
                else
                {
                    return WebResponseContent.Instance.Error("下发机器人任务失败!");
                    Dt_Task task = new Dt_Task()
                    {
                        CurrentAddress = stockInfo.LocationCode,
                        Grade = 0,
                        NextAddress = "1-2",
                        PalletCode = stockInfo.PalletCode,
                        Roadway = locationInfo.RoadwayNo,
                        SourceAddress = stockInfo.LocationCode,
                        TargetAddress = "1-2",
                        TaskStatus = TaskStatusEnum.New.ObjToInt(),
                        TaskType = TaskTypeEnum.OutEmpty.ObjToInt(),
                        WarehouseId = stockInfo.WarehouseId,
                        PalletType = stockInfo.PalletType
                    };
                    int beforeStatus = locationInfo.LocationStatus;
                    _unitOfWorkManage.BeginTran();
                    stockInfo.StockStatus = StockStatusEmun.出库锁定.ObjToInt();
                    locationInfo.LocationStatus = LocationStatusEnum.Lock.ObjToInt();
                    int taskId = BaseDal.AddData(task);
                    task.TaskId = taskId;
                    _stockService.StockInfoService.UpdateData(stockInfo);
                    _locationInfoService.UpdateData(locationInfo);
                    _recordService.LocationStatusChangeRecordSetvice.AddLocationStatusChangeRecord(locationInfo, beforeStatus, StockChangeType.Outbound.ObjToInt(), "", task.TaskNum);
                    _unitOfWorkManage.CommitTran();
                    TaskModel esstask = new TaskModel()
                    {
                        taskType = "carry",
                        taskGroupCode = "",
                        groupPriority = 0,
                        tasks = new List<TasksType>
                        {
                                new()
                                {
                                    taskCode=task.TaskNum.ToString(),
                                    taskPriority=0,
                                    taskDescribe=new TaskDescribeType{
                                    containerCode=stockInfo.PalletCode,
                                    containerType= "CT_KUBOT_STANDARD",
                                    fromLocationCode=stockInfo.LocationCode??"",
                                    toStationCode="",
                                    toLocationCode="1-2",
                                    deadline=0,storageTag=""
                                    }
                                }
                        }
                    };
                    var result = await _eSSApiService.CreateTaskAsync(esstask);
                    _logger.LogInformation("创建任务PalletOutboundTask è¿”回:  " + result);
                    if (result)
                    {
                        return WebResponseContent.Instance.OK(200);
                    }
                    else
                    {
                        return WebResponseContent.Instance.Error("下发机器人任务失败!");
                    }
                }
                return content.OK("空托出库成功!");
            }
            catch (Exception ex)
            {
@@ -477,7 +475,14 @@
            }
        }
        public async Task<WebResponseContent> GenerateAllocatOutboundTask(int orderDetailId, List<StockSelectViewDTO> stockSelectViews)
        /// <summary>
        /// æ™ºä»“调智仓
        /// </summary>
        /// <param name="orderDetailId"></param>
        /// <param name="stockSelectViews"></param>
        /// <param name="station"></param>
        /// <returns></returns>
        public async Task<WebResponseContent> GenerateAllocatOutboundTask(int orderDetailId, List<StockSelectViewDTO> stockSelectViews, string station = null)
        {
            try
            {
@@ -504,7 +509,7 @@
                    return WebResponseContent.Instance.Error("找不到出库明细单据");
                }
                (List<Dt_Task>, List<Dt_StockInfo>?, List<Dt_OutboundOrderDetail>?, List<Dt_OutStockLockInfo>?, List<Dt_LocationInfo>?) result = OutboundTaskDataHandle(outboundOrder.Details.First().Id, stockSelectViews);
                (List<Dt_Task>, List<Dt_StockInfo>?, List<Dt_OutboundOrderDetail>?, List<Dt_OutStockLockInfo>?, List<Dt_LocationInfo>?) result = OutboundTaskDataHandle(outboundOrder.Details.First().Id, stockSelectViews,station);
                WebResponseContent content =await GenerateOutboundTaskDataUpdate(result.Item1, result.Item2, result.Item3, result.Item4, result.Item5);
@@ -521,7 +526,7 @@
        /// <param name="orderDetailId"></param>
        /// <param name="stockSelectViews"></param>
        /// <returns></returns>
        public async Task<WebResponseContent> GenerateOutboundTask(int orderDetailId, List<StockSelectViewDTO> stockSelectViews)
        public async Task<WebResponseContent> GenerateOutboundTask(int orderDetailId, List<StockSelectViewDTO> stockSelectViews,string station=null)
        {
            try
            {
@@ -531,7 +536,7 @@
                {
                    return WebResponseContent.Instance.Error("找不到单据");
                }
                (List<Dt_Task>, List<Dt_StockInfo>?, List<Dt_OutboundOrderDetail>?, List<Dt_OutStockLockInfo>?, List<Dt_LocationInfo>?) result = OutboundTaskDataHandle(outboundOrder.Details.First().Id, stockSelectViews);
                (List<Dt_Task>, List<Dt_StockInfo>?, List<Dt_OutboundOrderDetail>?, List<Dt_OutStockLockInfo>?, List<Dt_LocationInfo>?) result = OutboundTaskDataHandle(outboundOrder.Details.First().Id, stockSelectViews,station);
                WebResponseContent content =await GenerateOutboundTaskDataUpdate(result.Item1, result.Item2, result.Item3, result.Item4, result.Item5);
@@ -550,7 +555,7 @@
        /// <param name="stockSelectViews"></param>
        /// <returns></returns>
        /// <exception cref="Exception"></exception>
        public (List<Dt_Task>, List<Dt_StockInfo>?, List<Dt_OutboundOrderDetail>?, List<Dt_OutStockLockInfo>?, List<Dt_LocationInfo>?) OutboundTaskDataHandle(int orderDetailId, List<StockSelectViewDTO> stockSelectViews)
        public (List<Dt_Task>, List<Dt_StockInfo>?, List<Dt_OutboundOrderDetail>?, List<Dt_OutStockLockInfo>?, List<Dt_LocationInfo>?) OutboundTaskDataHandle(int orderDetailId, List<StockSelectViewDTO> stockSelectViews,string station=null)
        {
            List<Dt_Task> tasks = new List<Dt_Task>();
            Dt_OutboundOrderDetail outboundOrderDetail = _outboundOrderDetailService.Repository.QueryFirst(x => x.Id == orderDetailId);
@@ -573,15 +578,15 @@
                (List<Dt_StockInfo>, Dt_OutboundOrderDetail, List<Dt_OutStockLockInfo>, List<Dt_LocationInfo>) result = _outboundOrderDetailService.AssignStockOutbound(outboundOrderDetail, stockSelectViews);
                if (result.Item1 != null && result.Item1.Count > 0)
                {
                    Dt_OutboundOrder outboundOrder = _outboundOrderService.Repository.QueryFirst(x => x.Id == outboundOrderDetail.OrderId);
                    Dt_OutboundOrder outboundOrder = _outboundOrderService.Repository.QueryFirst(x => x.Id == outboundOrderDetail.OrderId);
                    TaskTypeEnum typeEnum = outboundOrder.OrderType switch
                    {
                        (int)OutOrderTypeEnum.Issue => TaskTypeEnum.Outbound,
                        (int)OutOrderTypeEnum.Allocate => TaskTypeEnum.OutAllocate,
                        (int)OutOrderTypeEnum.Quality => TaskTypeEnum.OutQuality,
                        _ => new TaskTypeEnum()
                        _ => TaskTypeEnum.Outbound
                    };
                    tasks = GetTasks(result.Item1, typeEnum);
                    tasks = GetTasks(result.Item1, typeEnum,station);
                    result.Item2.OrderDetailStatus = OrderDetailStatusEnum.Outbound.ObjToInt();
                    result.Item3.ForEach(x =>
                    {