wangxinhui
2025-03-19 d8db1698c125618c1b5f62b009204ddc5d4eed5a
´úÂë¹ÜÀí/WMS/WIDESEA_WMSServer/WIDESEA_TaskInfoService/TaskService_Inbound.cs
@@ -7,6 +7,7 @@
using System.Threading.Tasks;
using WIDESEA_Common.CommonEnum;
using WIDESEA_Common.LocationEnum;
using WIDESEA_Common.OrderEnum;
using WIDESEA_Common.StockEnum;
using WIDESEA_Common.TaskEnum;
using WIDESEA_Common.WareHouseEnum;
@@ -48,7 +49,7 @@
                    return WebResponseContent.Instance.Error($"该站点已有未执行的任务");
                }
                Dt_StockInfo stockInfo = _stockRepository.StockInfoRepository.QueryFirst(x => x.PalletCode == palletCode);
                Dt_StockInfo stockInfo = _stockRepository.StockInfoRepository.Db.Queryable<Dt_StockInfo>().Where(x=>x.PalletCode== palletCode).Includes(x=>x.Details).First();
                if (stockInfo == null)
                {
                    return WebResponseContent.Instance.Error($"未找到组盘信息");
@@ -82,21 +83,49 @@
                        Roadway = "",
                        SourceAddress = stationCode,
                        TargetAddress = "",
                        TaskType = stockInfo.StockStatus == StockStatusEmun.拣选完成.ObjToInt() ? TaskTypeEnum.InPick.ObjToInt() : TaskTypeEnum.Inbound.ObjToInt(),
                        TaskType = TaskTypeEnum.Inbound.ObjToInt(),
                        TaskStatus = TaskStatusEnum.New.ObjToInt(),
                        WarehouseId = stockInfo.WarehouseId,
                        PalletType = stockInfo.PalletType
                    };
                    //获取是否存在入库单
                    Dt_InboundOrder? inboundOrder =  null;
                    if (stockInfo!=null && stockInfo.Details.Count>0)
                    {
                        string? orderNo = stockInfo.Details.FirstOrDefault()?.OrderNo ?? "";
                        inboundOrder =_inboundOrderService.Repository.QueryFirst(x => x.InboundOrderNo == orderNo && x.OrderStatus < InOrderStatusEnum.入库完成.ObjToInt());
                        if (inboundOrder!=null)
                        {
                            newTask.OrderNo = inboundOrder.InboundOrderNo;
                        }
                    }
                    if (inboundOrder != null)
                    {
                        if (inboundOrder.OrderType == InOrderTypeEnum.Allocat.ObjToInt())
                        {
                            newTask.TaskType = TaskTypeEnum.InAllocate.ObjToInt();
                            newTask.OrderNo = inboundOrder.InboundOrderNo;
                        }
                        else if (inboundOrder.OrderType == InOrderTypeEnum.Return.ObjToInt())
                        {
                            newTask.TaskType = TaskTypeEnum.ProductionReturn.ObjToInt();
                            newTask.OrderNo = inboundOrder.InboundOrderNo;
                        }
                    }
                    if (stockInfo.StockStatus == StockStatusEmun.手动组盘暂存.ObjToInt())
                    {
                        stockInfo.StockStatus = StockStatusEmun.手动组盘入库确认.ObjToInt();
                    }
                    else if (stockInfo.StockStatus == StockStatusEmun.拣选完成.ObjToInt())
                    {
                        stockInfo.StockStatus = StockStatusEmun.入库确认.ObjToInt();
                        newTask.TaskType = TaskTypeEnum.InPick.ObjToInt();
                    }
                    else
                    {
                        stockInfo.StockStatus = StockStatusEmun.入库确认.ObjToInt();
                    }
                    _unitOfWorkManage.BeginTran();
                    int taskId = BaseDal.AddData(newTask);
                    newTask.TaskId = taskId;
@@ -254,7 +283,7 @@
                    return WebResponseContent.Instance.Error($"该站点已有未执行的任务");
                }
                Dt_StockInfo stockInfo = _stockRepository.StockInfoRepository.QueryFirst(x => x.PalletCode == palletCode);
                Dt_StockInfo stockInfo = _stockRepository.StockInfoRepository.Db.Queryable<Dt_StockInfo>().Where(x => x.PalletCode == palletCode).Includes(x => x.Details).First();
                if (stockInfo == null)
                {
                    return WebResponseContent.Instance.Error($"未找到组盘信息");
@@ -289,7 +318,25 @@
                    PalletType = stockInfo.PalletType
                };
                //获取是否存在入库单
                Dt_InboundOrder? inboundOrder = null;
                if (stockInfo != null && stockInfo.Details.Count > 0)
                {
                    string? orderNo = stockInfo.Details.FirstOrDefault()?.OrderNo ?? "";
                    inboundOrder = _inboundOrderService.Repository.QueryFirst(x => x.InboundOrderNo == orderNo && x.OrderStatus < InOrderStatusEnum.入库完成.ObjToInt());
                }
                if (inboundOrder != null)
                {
                    if (inboundOrder.OrderType == InOrderTypeEnum.Allocat.ObjToInt())
                    {
                        newTask.TaskType = TaskTypeEnum.InAllocate.ObjToInt();
                    }
                    else if (inboundOrder.OrderType == InOrderTypeEnum.Return.ObjToInt())
                    {
                        newTask.TaskType = TaskTypeEnum.ProductionReturn.ObjToInt();
                    }
                }
                if (stockInfo.StockStatus == StockStatusEmun.手动组盘暂存.ObjToInt())
                {
                    stockInfo.StockStatus = StockStatusEmun.手动组盘入库确认.ObjToInt();
@@ -300,13 +347,13 @@
                }
                else if (stockInfo.StockStatus == StockStatusEmun.拣选完成.ObjToInt())
                {
                    stockInfo.StockStatus = StockStatusEmun.拣选完成.ObjToInt();
                    newTask.TaskType = TaskTypeEnum.InPick.ObjToInt();
                }
                else
                {
                    stockInfo.StockStatus = StockStatusEmun.入库确认.ObjToInt();
                }
                LocationStatusEnum lastStatus = (LocationStatusEnum)locationInfo.LocationStatus;
                _unitOfWorkManage.BeginTran();
                _recordService.LocationStatusChangeRecordSetvice.AddLocationStatusChangeRecord(locationInfo, lastStatus, LocationStatusEnum.Lock, LocationChangeType.InboundAssignLocation);
@@ -334,7 +381,7 @@
        /// <param name="stationCode"></param>
        /// <param name="palletCode"></param>
        /// <returns></returns>
        public WebResponseContent DeviceRequestInboundTask(string stationCode, string palletCode)
        public WebResponseContent DeviceRequestInboundTaskSimple(string stationCode, string palletCode)
        {
            try
            {
@@ -355,7 +402,7 @@
                {
                    return WebResponseContent.Instance.Error($"未找到组盘信息");
                }
                if (stockInfo.StockStatus != StockStatusEmun.组盘暂存.ObjToInt() && stockInfo.StockStatus != StockStatusEmun.手动组盘暂存.ObjToInt() && stockInfo.StockStatus != StockStatusEmun.出库完成.ObjToInt() && stockInfo.StockStatus != StockStatusEmun.拣选完成.ObjToInt() && stockInfo.StockStatus != StockStatusEmun.退库.ObjToInt() && stockInfo.StockStatus != StockStatusEmun.MES退库.ObjToInt())
                if (stockInfo.StockStatus != StockStatusEmun.组盘暂存.ObjToInt() && stockInfo.StockStatus != StockStatusEmun.手动组盘暂存.ObjToInt() && stockInfo.StockStatus != StockStatusEmun.出库完成.ObjToInt() && stockInfo.StockStatus != StockStatusEmun.拣选完成.ObjToInt() && stockInfo.StockStatus != StockStatusEmun.退库.ObjToInt() && stockInfo.StockStatus != StockStatusEmun.MES退库.ObjToInt() && stockInfo.StockStatus != StockStatusEmun.MES空托退库.ObjToInt())
                {
                    return WebResponseContent.Instance.Error($"该托盘状态不正确,不可申请入库");
                }
@@ -388,6 +435,12 @@
                {
                    newTask.TaskType = TaskTypeEnum.MesMatReturn.ObjToInt();
                }
                else if (stockInfo.StockStatus == StockStatusEmun.MES空托退库.ObjToInt())
                {
                    //todo æš‚时未启用
                    return WebResponseContent.Instance.Error($"空托未启用");
                    //newTask.TaskType = TaskTypeEnum.MesPalletReturn.ObjToInt();
                }
                else
                {
                    stockInfo.StockStatus = StockStatusEmun.入库确认.ObjToInt();
@@ -412,6 +465,92 @@
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="stationCode"></param>
        /// <param name="palletCode"></param>
        /// <param name="staions"></param>
        /// <param name="heightType"></param>
        /// <returns></returns>
        public WebResponseContent DeviceRequestInboundTaskByRoadways(string stationCode, string palletCode, List<string> staions, int heightType)
        {
            try
            {
                Dt_Task task = Repository.QueryFirst(x => x.PalletCode == palletCode);
                if (task != null)
                {
                    PushTasksToWCS(new List<Dt_Task> { task });
                    return WebResponseContent.Instance.OK($"该托盘已生成任务", _mapper.Map<WMSTaskDTO>(task));
                }
                if (Repository.QueryFirst(x => x.SourceAddress == stationCode && x.TaskStatus == TaskStatusEnum.New.ObjToInt()) != null)
                {
                    return WebResponseContent.Instance.Error($"该站点已有未执行的任务");
                }
                string roadwayNo = AssignRoadwayNo(staions, palletCode, heightType);
                Dt_StockInfo stockInfo = _stockRepository.StockInfoRepository.QueryFirst(x => x.PalletCode == palletCode);
                if (stockInfo == null)
                {
                    return WebResponseContent.Instance.Error($"未找到组盘信息");
                }
                if (stockInfo.StockStatus != StockStatusEmun.组盘暂存.ObjToInt() && stockInfo.StockStatus != StockStatusEmun.手动组盘暂存.ObjToInt() && stockInfo.StockStatus != StockStatusEmun.出库完成.ObjToInt() && stockInfo.StockStatus != StockStatusEmun.拣选完成.ObjToInt() && stockInfo.StockStatus != StockStatusEmun.退库.ObjToInt() && stockInfo.StockStatus != StockStatusEmun.MES退库.ObjToInt())
                {
                    return WebResponseContent.Instance.Error($"该托盘状态不正确,不可申请入库");
                }
                if (!string.IsNullOrEmpty(stockInfo.LocationCode))
                {
                    return WebResponseContent.Instance.Error($"该托盘已绑定货位");
                }
                Dt_Task newTask = new Dt_Task()
                {
                    CurrentAddress = stationCode,
                    Grade = 0,
                    NextAddress = "",
                    PalletCode = palletCode,
                    Roadway = roadwayNo,
                    SourceAddress = stationCode,
                    TargetAddress = roadwayNo,
                    TaskType = TaskTypeEnum.Inbound.ObjToInt(),
                    TaskStatus = TaskStatusEnum.New.ObjToInt(),
                    WarehouseId = stockInfo.WarehouseId,
                    PalletType = stockInfo.PalletType
                };
                if (stockInfo.StockStatus == StockStatusEmun.手动组盘暂存.ObjToInt())
                {
                    stockInfo.StockStatus = StockStatusEmun.手动组盘入库确认.ObjToInt();
                }
                else if (stockInfo.StockStatus == StockStatusEmun.MES退库.ObjToInt())
                {
                    newTask.TaskType = TaskTypeEnum.MesMatReturn.ObjToInt();
                }
                else
                {
                    stockInfo.StockStatus = StockStatusEmun.入库确认.ObjToInt();
                }
                _unitOfWorkManage.BeginTran();
                int taskId = BaseDal.AddData(newTask);
                newTask.TaskId = taskId;
                _stockRepository.StockInfoRepository.UpdateData(stockInfo);
                _unitOfWorkManage.CommitTran();
                WMSTaskDTO wMSTaskDTO = _mapper.Map<WMSTaskDTO>(newTask);
                PushTasksToWCS(new List<Dt_Task> { newTask });
                //if (newTask.WarehouseId == 5) PutFinish(stationCode);
                return WebResponseContent.Instance.OK(data: wMSTaskDTO);
            }
            catch (Exception ex)
            {
                _unitOfWorkManage.RollbackTran();
                return WebResponseContent.Instance.Error(ex.Message);
            }
        }
        /// <summary>
        /// å…¥åº“任务申请分配货位
        /// </summary>
        /// <param name="taskNum">任务号</param>