| using OfficeOpenXml.FormulaParsing.Excel.Functions.RefAndLookup; | 
| using System; | 
| using System.Collections; | 
| using System.Collections.Generic; | 
| using System.Linq; | 
| using System.Text; | 
| using System.Threading.Tasks; | 
| using WIDESEA_Common.CommonEnum; | 
| using WIDESEA_Common.LocationEnum; | 
| using WIDESEA_Common.StockEnum; | 
| using WIDESEA_Common.TaskEnum; | 
| using WIDESEA_Common.WareHouseEnum; | 
| using WIDESEA_Core; | 
| using WIDESEA_Core.Helper; | 
| using WIDESEA_DTO.Task; | 
| using WIDESEA_Model.Models; | 
|   | 
| namespace WIDESEA_TaskInfoService | 
| { | 
|     public partial class TaskService | 
|     { | 
|         /// <summary> | 
|         /// 申请入库任务(PDA使用,仅托盘绑定入库站台,不分配货位) | 
|         /// </summary> | 
|         /// <param name="saveModel"></param> | 
|         /// <returns></returns> | 
|         public WebResponseContent RequestInboundTask(SaveModel saveModel) | 
|         { | 
|             try | 
|             { | 
|                 var palletCode = saveModel.MainData["barcode"].ToString(); | 
|                 var warehouseId = saveModel.MainData["warehouseId"].ObjToInt(); | 
|                 var stationCode = saveModel.MainData["startPoint"].ToString(); | 
|                 Dt_Warehouse warehouse = _basicRepository.WarehouseRepository.QueryFirst(x => x.WarehouseId == warehouseId); | 
|                 if (warehouse == null) | 
|                 { | 
|                     return WebResponseContent.Instance.Error($"未找到库区"); | 
|                 } | 
|                 Dt_Task task = Repository.QueryFirst(x => x.PalletCode == palletCode && x.WarehouseId == warehouseId); | 
|                 if (task != null) | 
|                 { | 
|                     return WebResponseContent.Instance.Error($"该托盘已生成任务"); | 
|                 } | 
|   | 
|                 if (Repository.QueryFirst(x => x.SourceAddress == stationCode && x.TaskStatus == TaskStatusEnum.New.ObjToInt()) != null) | 
|                 { | 
|                     return WebResponseContent.Instance.Error($"该站点已有未执行的任务"); | 
|                 } | 
|   | 
|                 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()) | 
|                 { | 
|                     return WebResponseContent.Instance.Error($"该托盘状态不正确,不可申请入库"); | 
|                 } | 
|                 if (!string.IsNullOrEmpty(stockInfo.LocationCode)) | 
|                 { | 
|                     return WebResponseContent.Instance.Error($"该托盘已绑定货位"); | 
|                 } | 
|                 if (warehouseId != stockInfo.WarehouseId) | 
|                 { | 
|                     return WebResponseContent.Instance.Error($"仓库不正确"); | 
|                 } | 
|                 if (warehouse.WarehouseCode == WarehouseEnum.HA60.ToString()) | 
|                 { | 
|                     Dt_LocationInfo locationInfo = _basicRepository.LocationInfoRepository.QueryFirst(x => x.WarehouseId == warehouseId); | 
|                     if (locationInfo == null) return WebResponseContent.Instance.Error($"未找到当前库区货位信息"); | 
|                     return DeviceRequestInboundTask(stationCode, locationInfo.RoadwayNo, palletCode); | 
|                 } | 
|                 else | 
|                 { | 
|                     Dt_Task newTask = new Dt_Task() | 
|                     { | 
|                         CurrentAddress = stationCode, | 
|                         Grade = 0, | 
|                         NextAddress = "", | 
|                         PalletCode = palletCode, | 
|                         Roadway = "", | 
|                         SourceAddress = stationCode, | 
|                         TargetAddress = "", | 
|                         TaskType = stockInfo.StockStatus == StockStatusEmun.拣选完成.ObjToInt() ? TaskTypeEnum.InPick.ObjToInt() : TaskTypeEnum.Inbound.ObjToInt(), | 
|                         TaskStatus = TaskStatusEnum.New.ObjToInt(), | 
|                         WarehouseId = stockInfo.WarehouseId, | 
|                         PalletType = stockInfo.PalletType | 
|                     }; | 
|   | 
|                     if (stockInfo.StockStatus == StockStatusEmun.手动组盘暂存.ObjToInt()) | 
|                     { | 
|                         stockInfo.StockStatus = StockStatusEmun.手动组盘入库确认.ObjToInt(); | 
|                     } | 
|                     else | 
|                     { | 
|                         stockInfo.StockStatus = StockStatusEmun.入库确认.ObjToInt(); | 
|                     } | 
|                     _unitOfWorkManage.BeginTran(); | 
|                     int taskId = BaseDal.AddData(newTask); | 
|                     newTask.TaskId = taskId; | 
|                     _stockRepository.StockInfoRepository.UpdateData(stockInfo); | 
|                     _unitOfWorkManage.CommitTran(); | 
|                     PushTasksToWCS(new List<Dt_Task> { newTask }); | 
|                     return WebResponseContent.Instance.OK(data: newTask); | 
|                 } | 
|             } | 
|             catch (Exception ex) | 
|             { | 
|                 _unitOfWorkManage.RollbackTran(); | 
|                 return WebResponseContent.Instance.Error(ex.Message); | 
|             } | 
|         } | 
|   | 
|         /// <summary> | 
|         /// 入空箱 | 
|         /// </summary> | 
|         /// <param name="barcode"></param> | 
|         /// <param name="address"></param> | 
|         /// <param name="WarehouseId"></param> | 
|         /// <returns></returns> | 
|         public WebResponseContent InEmpty(string barcode, string address, int WarehouseId) | 
|         { | 
|             try | 
|             { | 
|                 Dt_Warehouse warehouse = _basicRepository.WarehouseRepository.QueryFirst(x => x.WarehouseId == WarehouseId); | 
|                 if (warehouse == null) | 
|                 { | 
|                     return WebResponseContent.Instance.Error($"未找到库区"); | 
|                 } | 
|                 Dt_StockInfo stockInfo = _stockRepository.StockInfoRepository.QueryFirst(x => x.PalletCode == barcode && x.StockStatus != StockStatusEmun.出库完成.ObjToInt()); | 
|                 if (stockInfo != null) throw new Exception($"托盘号已存在"); | 
|                 stockInfo = new Dt_StockInfo() | 
|                 { | 
|                     PalletCode = barcode, | 
|                     StockStatus = StockStatusEmun.入库确认.ObjToInt(), | 
|                     WarehouseId = WarehouseId, | 
|                     PalletType = PalletTypeEnum.Empty.ObjToInt(), | 
|                     Details = new List<Dt_StockInfoDetail>() | 
|                 }; | 
|                 Dt_LocationInfo locationInfo = _basicRepository.LocationInfoRepository.QueryFirst(x => x.WarehouseId == WarehouseId); | 
|                 if (locationInfo == null) return WebResponseContent.Instance.Error($"未找到当前库区货位信息"); | 
|                 locationInfo = _basicService.LocationInfoService.AssignLocation(locationInfo.RoadwayNo, ((PalletTypeEnum)stockInfo.PalletType).ObjToInt(), stockInfo.WarehouseId); | 
|                 if (locationInfo == null) | 
|                 { | 
|                     return WebResponseContent.Instance.Error($"货位分配失败,未找到可分配货位"); | 
|                 } | 
|   | 
|                 Dt_Task newTask = new Dt_Task() | 
|                 { | 
|                     CurrentAddress = address, | 
|                     Grade = 0, | 
|                     NextAddress = locationInfo.LocationCode, | 
|                     PalletCode = barcode, | 
|                     Roadway = locationInfo.RoadwayNo, | 
|                     SourceAddress = address, | 
|                     TargetAddress = locationInfo.LocationCode, | 
|                     TaskType = TaskTypeEnum.InEmpty.ObjToInt(), | 
|                     TaskStatus = TaskStatusEnum.New.ObjToInt(), | 
|                     WarehouseId = stockInfo.WarehouseId, | 
|                     PalletType = stockInfo.PalletType | 
|                 }; | 
|                 locationInfo.LocationStatus = LocationStatusEnum.Lock.ObjToInt(); | 
|                 _unitOfWorkManage.BeginTran(); | 
|                 int taskId = BaseDal.AddData(newTask); | 
|                 newTask.TaskId = taskId; | 
|                 _basicRepository.LocationInfoRepository.UpdateData(locationInfo); | 
|                 _stockRepository.StockInfoRepository.AddData(stockInfo); | 
|                 _unitOfWorkManage.CommitTran(); | 
|                 PushTasksToWCS(new List<Dt_Task> { newTask }); | 
|                 PutFinish(address); | 
|                 return WebResponseContent.Instance.OK(); | 
|             } | 
|             catch (Exception ex) | 
|             { | 
|                 _unitOfWorkManage.RollbackTran(); | 
|                 return WebResponseContent.Instance.Error(ex.Message); | 
|             } | 
|         } | 
|   | 
|         /// <summary> | 
|         ///  | 
|         /// </summary> | 
|         /// <param name="qty"></param> | 
|         /// <param name="address"></param> | 
|         /// <param name="WarehouseId"></param> | 
|         /// <param name="barcode"></param> | 
|         /// <returns></returns> | 
|         public WebResponseContent OutEmpty(int qty, string address, int WarehouseId, string barcode) | 
|         { | 
|             try | 
|             { | 
|                 Dt_Warehouse warehouse = _basicRepository.WarehouseRepository.QueryFirst(x => x.WarehouseId == WarehouseId); | 
|                 if (warehouse == null) | 
|                 { | 
|                     return WebResponseContent.Instance.Error($"未找到库区"); | 
|                 } | 
|                 List<Dt_StockInfo> stockInfos = null; | 
|                 if (string.IsNullOrEmpty(barcode)) | 
|                 { | 
|                     stockInfos = _stockRepository.StockInfoRepository.QueryData(x => x.WarehouseId == WarehouseId && x.PalletType == PalletTypeEnum.Empty.ObjToInt() && x.StockStatus == StockStatusEmun.入库完成.ObjToInt(), qty, nameof(Dt_StockInfo.CreateDate)); | 
|                 } | 
|                 else | 
|                 { | 
|                     stockInfos = _stockRepository.StockInfoRepository.QueryData(x => x.WarehouseId == WarehouseId && x.PalletType == PalletTypeEnum.Empty.ObjToInt() && x.StockStatus == StockStatusEmun.入库完成.ObjToInt() && x.PalletCode == barcode); | 
|                     if (stockInfos.Count == 0) return WebResponseContent.Instance.Error($"{warehouse.WarehouseName}未找到空箱【{barcode}】"); | 
|                 } | 
|   | 
|                 if (stockInfos.Count < qty) return WebResponseContent.Instance.Error($"{warehouse.WarehouseName}空箱库存不足,库存数【{stockInfos.Count}】"); | 
|                 List<Dt_Task> tasks = GetTasks(stockInfos, TaskTypeEnum.OutEmpty); | 
|                 stockInfos.ForEach(x => | 
|                 { | 
|                     x.StockStatus = StockStatusEmun.出库锁定.ObjToInt(); | 
|                 }); | 
|                 tasks.ForEach(x => | 
|                 { | 
|                     x.TargetAddress = address; | 
|                     x.NextAddress = address; | 
|                 }); | 
|                 _unitOfWorkManage.BeginTran(); | 
|                 BaseDal.AddData(tasks); | 
|                 _stockRepository.StockInfoRepository.UpdateData(stockInfos); | 
|                 _unitOfWorkManage.CommitTran(); | 
|                 PushTasksToWCS(tasks); | 
|                 return WebResponseContent.Instance.OK(); | 
|             } | 
|             catch (Exception ex) | 
|             { | 
|                 return WebResponseContent.Instance.Error(ex.Message); | 
|             } | 
|         } | 
|   | 
|         /// <summary> | 
|         ///  | 
|         /// </summary> | 
|         /// <param name="stationCode"></param> | 
|         /// <param name="roadwayNo"></param> | 
|         /// <param name="palletCode"></param> | 
|         /// <returns></returns> | 
|         public WebResponseContent DeviceRequestInboundTask(string stationCode, string roadwayNo, string palletCode) | 
|         { | 
|             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($"该站点已有未执行的任务"); | 
|                 } | 
|   | 
|                 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_LocationInfo? locationInfo = _basicService.LocationInfoService.AssignLocation(roadwayNo, stockInfo.PalletType, stockInfo.WarehouseId); | 
|                 if (locationInfo == null) | 
|                 { | 
|                     return WebResponseContent.Instance.Error($"货位分配失败,未找到可分配货位"); | 
|                 } | 
|   | 
|                 Dt_Task newTask = new Dt_Task() | 
|                 { | 
|                     CurrentAddress = stationCode, | 
|                     Grade = 0, | 
|                     NextAddress = locationInfo.LocationCode, | 
|                     PalletCode = palletCode, | 
|                     Roadway = roadwayNo, | 
|                     SourceAddress = stationCode, | 
|                     TargetAddress = locationInfo.LocationCode, | 
|                     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 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); | 
|                 _basicService.LocationInfoService.UpdateLocationStatus(locationInfo, newTask.PalletType, LocationStatusEnum.Lock, newTask.WarehouseId); | 
|                 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> | 
|         /// 仅申请任务,让WCS根据路由确定下一地址 | 
|         /// </summary> | 
|         /// <param name="stationCode"></param> | 
|         /// <param name="palletCode"></param> | 
|         /// <returns></returns> | 
|         public WebResponseContent DeviceRequestInboundTask(string stationCode, string palletCode) | 
|         { | 
|             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($"该站点已有未执行的任务"); | 
|                 } | 
|   | 
|                 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 = "", | 
|                     SourceAddress = stationCode, | 
|                     TargetAddress = "", | 
|                     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> | 
|         /// <param name="roadwayNo">巷道号</param> | 
|         /// <returns></returns> | 
|         public WebResponseContent AssignInboundTaskLocation(int taskNum, string roadwayNo) | 
|         { | 
|             try | 
|             { | 
|                 Dt_Task task = BaseDal.QueryFirst(x => x.TaskNum == taskNum); | 
|                 if (task == null) | 
|                 { | 
|                     return WebResponseContent.Instance.Error($"未找到该入库任务"); | 
|                 } | 
|   | 
|                 if (_basicRepository.LocationInfoRepository.QueryFirst(x => x.LocationCode == task.TargetAddress) != null) | 
|                 { | 
|                     return WebResponseContent.Instance.OK(data: task.TargetAddress); | 
|                 } | 
|   | 
|                 Dt_LocationInfo? locationInfo = _basicService.LocationInfoService.AssignLocation(roadwayNo, task.PalletType, task.WarehouseId); | 
|                 if (locationInfo == null) | 
|                 { | 
|                     return WebResponseContent.Instance.Error($"货位分配失败,未找到可分配货位"); | 
|                 } | 
|   | 
|                 task.Roadway = roadwayNo; | 
|                 task.TargetAddress = locationInfo.LocationCode; | 
|                 task.TaskStatus = TaskStatusEnum.SC_Execute.ObjToInt(); | 
|   | 
|                 LocationStatusEnum lastStatus = (LocationStatusEnum)locationInfo.LocationStatus; | 
|   | 
|                 _unitOfWorkManage.BeginTran(); | 
|                 _recordService.LocationStatusChangeRecordSetvice.AddLocationStatusChangeRecord(locationInfo, lastStatus, LocationStatusEnum.Lock, LocationChangeType.InboundAssignLocation); | 
|                 _basicService.LocationInfoService.UpdateLocationStatus(locationInfo, task.PalletType, LocationStatusEnum.Lock, task.WarehouseId); | 
|                 BaseDal.UpdateData(task); | 
|                 _unitOfWorkManage.CommitTran(); | 
|                 return WebResponseContent.Instance.OK(data: locationInfo.LocationCode); | 
|             } | 
|             catch (Exception ex) | 
|             { | 
|                 _unitOfWorkManage.RollbackTran(); | 
|                 return WebResponseContent.Instance.Error(ex.Message); | 
|             } | 
|         } | 
|   | 
|         /// <summary> | 
|         ///  | 
|         /// </summary> | 
|         /// <param name="taskNum"></param> | 
|         /// <param name="roadwayNo"></param> | 
|         /// <param name="heightType"></param> | 
|         /// <returns></returns> | 
|         public WebResponseContent AssignInboundTaskLocationByHeight(int taskNum, string roadwayNo, int heightType) | 
|         { | 
|             try | 
|             { | 
|                 Dt_Task task = BaseDal.QueryFirst(x => x.TaskNum == taskNum); | 
|                 if (task == null) | 
|                 { | 
|                     return WebResponseContent.Instance.Error($"未找到该入库任务"); | 
|                 } | 
|   | 
|                 if (_basicRepository.LocationInfoRepository.QueryFirst(x => x.LocationCode == task.TargetAddress) != null) | 
|                 { | 
|                     return WebResponseContent.Instance.OK(data: task.TargetAddress); | 
|                 } | 
|   | 
|                 Dt_LocationInfo? locationInfo = _basicService.LocationInfoService.AssignLocation(roadwayNo, task.PalletType, task.WarehouseId, heightType: heightType); | 
|                 if (locationInfo == null) | 
|                 { | 
|                     return WebResponseContent.Instance.Error($"货位分配失败,未找到可分配货位"); | 
|                 } | 
|   | 
|                 task.Roadway = roadwayNo; | 
|                 task.TargetAddress = locationInfo.LocationCode; | 
|                 task.TaskStatus = TaskStatusEnum.SC_Execute.ObjToInt(); | 
|   | 
|                 LocationStatusEnum lastStatus = (LocationStatusEnum)locationInfo.LocationStatus; | 
|   | 
|                 _unitOfWorkManage.BeginTran(); | 
|                 _recordService.LocationStatusChangeRecordSetvice.AddLocationStatusChangeRecord(locationInfo, lastStatus, LocationStatusEnum.Lock, LocationChangeType.InboundAssignLocation); | 
|                 _basicService.LocationInfoService.UpdateLocationStatus(locationInfo, task.PalletType, LocationStatusEnum.Lock, task.WarehouseId); | 
|                 BaseDal.UpdateData(task); | 
|                 _unitOfWorkManage.CommitTran(); | 
|                 return WebResponseContent.Instance.OK(data: locationInfo.LocationCode); | 
|             } | 
|             catch (Exception ex) | 
|             { | 
|                 _unitOfWorkManage.RollbackTran(); | 
|                 return WebResponseContent.Instance.Error(ex.Message); | 
|             } | 
|         } | 
|     } | 
| } |