| | |
| | | using WIDESEA_Core.Utilities; |
| | | using System.Transactions; |
| | | using Microsoft.Data.SqlClient; |
| | | using WIDESEA_Model.Models.Outbound; |
| | | using WIDESEA_Common.OrderEnum; |
| | | using WIDESEA_Core.CodeConfigEnum; |
| | | |
| | | namespace WIDESEA_TaskInfoService |
| | | { |
| | | public partial class TaskService |
| | | { |
| | | public string ReceiveTask = WIDESEA_Core.Helper.AppSettings.Configuration["ReceiveTask"]; |
| | | /// <summary> |
| | | /// åºåæ°æ®è½¬åºåºä»»å¡ |
| | | /// </summary> |
| | | /// <param name="stockInfos"></param> |
| | | /// <returns></returns> |
| | | public List<Dt_Task> GetTasks(List<Dt_StockInfo> stockInfos, TaskTypeEnum taskType) |
| | | { |
| | | 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); |
| | | if (locationInfo == null) |
| | | { |
| | | throw new Exception("æªæ¾å°åºåºåºä½"); |
| | | } |
| | | Dt_Task dt_Task = BaseDal.QueryFirst(x => x.SourceAddress == locationInfo.LocationCode || x.TargetAddress == locationInfo.LocationCode); |
| | | if (dt_Task != null) |
| | | { |
| | | throw new Exception("该货ä½å·²åå¨èµ·ç¹ä»»å¡æç»ç¹ä»»å¡"); |
| | | } |
| | | Dt_Task dt_Task1 = BaseDal.QueryFirst(x => x.PalletCode == stockInfo.PalletCode); |
| | | if (dt_Task1 != null) |
| | | { |
| | | throw new Exception("该æçå·²åå¨ä»»å¡"); |
| | | } |
| | | Dt_RoadwayInfo roadwayInfo = _basicService.RoadwayInfoService.Repository.QueryFirst(x => x.RoadwayNo == locationInfo.RoadwayNo); |
| | | Dt_StockInfoDetail stockInfoDetail = _stockService.StockInfoDetailService.Repository.QueryFirst(x => x.StockId == stockInfo.Id); |
| | | if (roadwayInfo != null) |
| | | { |
| | | if (roadwayInfo.RoadwayNo.Contains("CP")) |
| | | { |
| | | Dt_Task task = new() |
| | | { |
| | | PalletType = stockInfo.PalletType, |
| | | OrderNo = stockInfoDetail.OrderNo, |
| | | CurrentAddress = locationInfo.LocationCode, |
| | | Grade = 0, |
| | | Creater = "WMS", |
| | | PalletCode = stockInfo.PalletCode, |
| | | NextAddress = roadwayInfo.OutSCStationCode, |
| | | Roadway = locationInfo.RoadwayNo, |
| | | SourceAddress = locationInfo.LocationCode, |
| | | TargetAddress = "", |
| | | TaskStatus = OutTaskStatusEnum.OutNew.ObjToInt(), |
| | | TaskType = taskType.ObjToInt(), |
| | | Depth = locationInfo.Depth, |
| | | WarehouseId = stockInfo.WarehouseId, |
| | | TaskNum = BaseDal.GetTaskNum(nameof(SequenceEnum.SeqTaskNum)), |
| | | MaterielCode = stockInfoDetail.MaterielCode, |
| | | Quantity = (float)stockInfoDetail.StockQuantity |
| | | }; |
| | | tasks.Add(task); |
| | | } |
| | | else |
| | | { |
| | | Dt_Task task = new() |
| | | { |
| | | PalletType = stockInfo.PalletType, |
| | | OrderNo = stockInfoDetail.OrderNo, |
| | | CurrentAddress = locationInfo.LocationCode, |
| | | Grade = 0, |
| | | Creater = "WMS", |
| | | PalletCode = stockInfo.PalletCode, |
| | | NextAddress = roadwayInfo.OutSCStationCode, |
| | | Roadway = locationInfo.RoadwayNo, |
| | | SourceAddress = locationInfo.LocationCode, |
| | | TargetAddress = "", |
| | | TaskStatus = OutTaskStatusEnum.OutNew.ObjToInt(), |
| | | TaskType = taskType.ObjToInt(), |
| | | Depth = locationInfo.Depth, |
| | | WarehouseId = stockInfo.WarehouseId, |
| | | TaskNum = BaseDal.GetTaskNum(nameof(SequenceEnum.SeqTaskNum)) |
| | | }; |
| | | if (taskType != TaskTypeEnum.OutEmpty) |
| | | { |
| | | task.MaterielCode = stockInfo.Details?.Where(x => x.StockId == stockInfo.Id).FirstOrDefault()?.MaterielCode; |
| | | task.Quantity = (float)stockInfo.Details?.Where(x => x.StockId == stockInfo.Id).Sum(x => x.StockQuantity); |
| | | } |
| | | tasks.Add(task); |
| | | } |
| | | |
| | | } |
| | | } |
| | | |
| | | } |
| | | return tasks; |
| | | } |
| | | |
| | | |
| | | |
| | | /// <summary> |
| | | /// åºåºä»»å¡æ°æ®å¤ç |
| | | /// </summary> |
| | | /// <param name="orderDetailId"></param> |
| | | /// <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[] keys) |
| | | { |
| | | List<Dt_Task> tasks = new List<Dt_Task>(); |
| | | List<Dt_OutboundOrderDetail> outboundOrderDetails = _outboundService.OutboundOrderDetailService.Repository.QueryData(x => keys.Contains(x.Id)); |
| | | |
| | | if (outboundOrderDetails == null || outboundOrderDetails.Count == 0) |
| | | { |
| | | throw new Exception("æªæ¾å°åºåºåæç»ä¿¡æ¯"); |
| | | } |
| | | if (outboundOrderDetails.FirstOrDefault(x => x.OrderDetailStatus > OrderDetailStatusEnum.New.ObjToInt() && x.OrderDetailStatus != OrderDetailStatusEnum.AssignOverPartial.ObjToInt()) != null) |
| | | { |
| | | throw new Exception("æéåºåºåæç»åå¨åºåºä¸æå·²å®æ"); |
| | | } |
| | | List<Dt_StockInfo>? stockInfos = null; |
| | | List<Dt_OutboundOrderDetail>? orderDetails = null; |
| | | List<Dt_OutStockLockInfo>? outStockLockInfos = null; |
| | | List<Dt_LocationInfo>? locationInfos = null; |
| | | //if (outboundOrderDetail.OrderDetailStatus == OrderDetailStatusEnum.New.ObjToInt()) |
| | | { |
| | | Dt_OutboundOrder dt_OutboundOrder = _outboundService.OutboundOrderService.Repository.QueryData(x => x.Id == outboundOrderDetails.First().OrderId).First(); |
| | | (List<Dt_StockInfo>, List<Dt_OutboundOrderDetail>, List<Dt_OutStockLockInfo>, List<Dt_LocationInfo>) result = new(); |
| | | result = _outboundService.OutboundOrderDetailService.AssignStockOutbound(outboundOrderDetails); |
| | | if (result.Item1 != null && result.Item1.Count > 0) |
| | | { |
| | | Dt_OutboundOrder outboundOrder = _outboundService.OutboundOrderService.Repository.QueryFirst(x => x.Id == outboundOrderDetails.FirstOrDefault().OrderId); |
| | | TaskTypeEnum typeEnum = outboundOrder.OrderType switch |
| | | { |
| | | (int)OrderTypeEnum.ç产åºåºå => TaskTypeEnum.Outbound, |
| | | (int)OrderTypeEnum.è°æ¨åºåºå => TaskTypeEnum.OutAllocate, |
| | | (int)OrderTypeEnum.忣åºåºå => TaskTypeEnum.ReverseOut, |
| | | _ => new TaskTypeEnum() |
| | | }; |
| | | tasks = GetTasks(result.Item1, typeEnum); |
| | | tasks.ForEach(x => |
| | | { |
| | | x.OrderNo = outboundOrder.OrderNo; |
| | | }); |
| | | if (dt_OutboundOrder.OutWareHouse.Contains("BC")) |
| | | { |
| | | result.Item2.ForEach(x => |
| | | { |
| | | x.OrderDetailStatus = OrderDetailStatusEnum.Outbound.ObjToInt(); |
| | | }); |
| | | } |
| | | else |
| | | { |
| | | |
| | | |
| | | result.Item2.ForEach(x => |
| | | { |
| | | if (x.LockQuantity == x.OrderQuantity) |
| | | { |
| | | x.OrderDetailStatus = OrderDetailStatusEnum.Outbound.ObjToInt(); |
| | | } |
| | | }); |
| | | } |
| | | |
| | | result.Item3.ForEach(x => |
| | | { |
| | | |
| | | x.Status = OutStockStatus.åºåºä¸.ObjToInt(); |
| | | }); |
| | | |
| | | stockInfos = result.Item1; |
| | | orderDetails = result.Item2; |
| | | outStockLockInfos = result.Item3; |
| | | locationInfos = result.Item4; |
| | | } |
| | | else |
| | | { |
| | | throw new Exception("æ åºå"); |
| | | } |
| | | } |
| | | //else |
| | | //{ |
| | | // List<Dt_OutStockLockInfo> stockLockInfos = _outboundService.OutboundStockLockInfoService.GetByOrderDetailId(outboundOrderDetail.OrderId, OutLockStockStatusEnum.å·²åé
); |
| | | // if (stockLockInfos != null && stockLockInfos.Count > 0) |
| | | // { |
| | | // List<Dt_StockInfo> stocks = _stockService.StockInfoService.Repository.GetStockInfosByPalletCodes(stockLockInfos.Select(x => x.PalletCode).Distinct().ToList()); |
| | | // tasks = GetTasks(stocks); |
| | | // } |
| | | //} |
| | | |
| | | return (tasks, stockInfos, orderDetails, outStockLockInfos, locationInfos); |
| | | } |
| | | |
| | | |
| | | /// <summary> |
| | | /// åºåºä»»å¡æ°æ®å¤ç |
| | | /// </summary> |
| | | /// <param name="orderDetailId"></param> |
| | | /// <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) |
| | | { |
| | | List<Dt_Task> tasks = new List<Dt_Task>(); |
| | | Dt_OutboundOrderDetail outboundOrderDetail = _outboundService.OutboundOrderDetailService.Repository.QueryFirst(x => x.OrderId == orderDetailId); |
| | | |
| | | if (outboundOrderDetail == null) |
| | | { |
| | | throw new Exception("æªæ¾å°åºåºåæç»ä¿¡æ¯"); |
| | | } |
| | | |
| | | if (stockSelectViews.Sum(x => x.UseableQuantity) > outboundOrderDetail.OrderQuantity - outboundOrderDetail.LockQuantity) |
| | | { |
| | | throw new Exception("éæ©æ°éè¶
åºåæ®æ°é"); |
| | | } |
| | | List<Dt_StockInfo>? stockInfos = null; |
| | | Dt_OutboundOrderDetail? orderDetail = null; |
| | | List<Dt_OutStockLockInfo>? outStockLockInfos = null; |
| | | List<Dt_LocationInfo>? locationInfos = null; |
| | | if (outboundOrderDetail.OrderDetailStatus == OrderDetailStatusEnum.New.ObjToInt()) |
| | | { |
| | | (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) |
| | | { |
| | | Dt_OutboundOrder outboundOrder = _outboundService.OutboundOrderService.Repository.QueryFirst(x => x.Id == outboundOrderDetail.OrderId); |
| | | TaskTypeEnum typeEnum = outboundOrder.OrderType switch |
| | | { |
| | | (int)OrderTypeEnum.ç产åºåºå => TaskTypeEnum.Outbound, |
| | | (int)OrderTypeEnum.è°æ¨åºåºå => TaskTypeEnum.OutAllocate, |
| | | (int)OrderTypeEnum.忣ååºå => TaskTypeEnum.ReverseIn, |
| | | _ => new TaskTypeEnum() |
| | | }; |
| | | tasks = GetTasks(result.Item1, typeEnum); |
| | | result.Item2.OrderDetailStatus = OrderDetailStatusEnum.Outbound.ObjToInt(); |
| | | result.Item3.ForEach(x => |
| | | { |
| | | x.Status = OutStockStatus.åºåºä¸.ObjToInt(); |
| | | }); |
| | | stockInfos = result.Item1; |
| | | orderDetail = result.Item2; |
| | | outStockLockInfos = result.Item3; |
| | | locationInfos = result.Item4; |
| | | } |
| | | else |
| | | { |
| | | throw new Exception("æ åºå"); |
| | | } |
| | | } |
| | | else |
| | | { |
| | | List<Dt_OutStockLockInfo> stockLockInfos = _outboundService.OutboundStockLockInfoService.GetByOrderDetailId(outboundOrderDetail.OrderId); |
| | | if (stockLockInfos != null && stockLockInfos.Count > 0) |
| | | { |
| | | List<Dt_StockInfo> stocks = _stockService.StockInfoService.Repository.GetStockInfosByPalletCodes(stockLockInfos.Select(x => x.PalletCode).Distinct().ToList()); |
| | | tasks = GetTasks(stocks, TaskTypeEnum.Outbound); |
| | | } |
| | | } |
| | | |
| | | return (tasks, stockInfos, orderDetail == null ? null : new List<Dt_OutboundOrderDetail> { orderDetail }, outStockLockInfos, locationInfos); |
| | | } |
| | | |
| | | |
| | | private (bool, string, object?) CheckOutboundOrderAddData(OutboundOrderAddDTO outboundOrderAddDTO) |
| | | { |
| | | (bool, string, object?) result1 = ModelValidate.ValidateModelData(outboundOrderAddDTO); |
| | | if (!result1.Item1) return result1; |
| | | |
| | | (bool, string, object?) result2 = ModelValidate.ValidateModelData(outboundOrderAddDTO.Details); |
| | | if (!result2.Item1) return result2; |
| | | |
| | | IEnumerable<int> inOrderTypes = Enum.GetValues<OutOrderTypeEnum>().Cast<int>(); |
| | | if (!inOrderTypes.Contains(outboundOrderAddDTO.OrderType)) |
| | | { |
| | | return (false, "æªæ¾å°è¯¥åæ®ç±»å", outboundOrderAddDTO); |
| | | } |
| | | |
| | | Dt_OutboundOrder dt_OutboundOrder = _outboundService.OutboundOrderService.Repository.QueryFirst(x => x.UpperOrderNo == outboundOrderAddDTO.UpperOrderNo && !string.IsNullOrEmpty(x.UpperOrderNo)); |
| | | if (dt_OutboundOrder != null) |
| | | { |
| | | return (false, "忮已åå¨", outboundOrderAddDTO); |
| | | } |
| | | return (true, "æå", outboundOrderAddDTO); |
| | | } |
| | | |
| | | public WebResponseContent GenerateOutboundTask(int orderDetailId, List<StockSelectViewDTO> stockSelectViews) |
| | | { |
| | | try |
| | | { |
| | | (List<Dt_Task>, List<Dt_StockInfo>?, List<Dt_OutboundOrderDetail>?, List<Dt_OutStockLockInfo>?, List<Dt_LocationInfo>?) result = OutboundTaskDataHandle(orderDetailId, stockSelectViews); |
| | | |
| | | WebResponseContent content = GenerateOutboundTaskDataUpdate(result.Item1, result.Item2, result.Item3, result.Item4, result.Item5); |
| | | |
| | | return content; |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | return WebResponseContent.Instance.Error(ex.Message); |
| | | } |
| | | } |
| | | /// <summary> |
| | | /// çæâä»»å¡ |
| | | /// </summary> |
| | | /// <param name="orderDetailId"></param> |
| | | /// <param name="stockSelectViews"></param> |
| | | /// <returns></returns> |
| | | public WebResponseContent GenerateOutboundTasks(int orderDetailId, List<StockSelectViewDTO> stockSelectViews) |
| | | { |
| | | try |
| | | { |
| | | (List<Dt_Task>, List<Dt_StockInfo>?, List<Dt_OutboundOrderDetail>?, List<Dt_OutStockLockInfo>?, List<Dt_LocationInfo>?) result = OutboundTaskDataHandle(orderDetailId, stockSelectViews); |
| | | |
| | | WebResponseContent content = GenerateOutboundTaskDataUpdate(result.Item1, result.Item2, result.Item3, result.Item4, result.Item5); |
| | | |
| | | return content; |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | throw new Exception(ex.Message); |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// çæåºåºä»»å¡åæ°æ®æ´æ°å°æ°æ®åº |
| | | /// </summary> |
| | | /// <param name="tasks"></param> |
| | | /// <param name="stockInfos"></param> |
| | | /// <param name="outboundOrderDetails"></param> |
| | | /// <param name="outStockLockInfos"></param> |
| | | /// <param name="locationInfos"></param> |
| | | /// <returns></returns> |
| | | public WebResponseContent GenerateOutboundTaskDataUpdate(List<Dt_Task> tasks, List<Dt_StockInfo>? stockInfos = null, List<Dt_OutboundOrderDetail>? outboundOrderDetails = null, List<Dt_OutStockLockInfo>? outStockLockInfos = null, List<Dt_LocationInfo>? locationInfos = null) |
| | | { |
| | | try |
| | | { |
| | | WebResponseContent content = new WebResponseContent(); |
| | | _unitOfWorkManage.BeginTran(); |
| | | |
| | | BaseDal.AddData(tasks); |
| | | //å¤æç§»åº |
| | | //content = RelocationTasks(tasks.OrderBy(x => x.Depth).ToList()); |
| | | //if (content.Status) |
| | | //{ |
| | | // _unitOfWorkManage.CommitTran(); |
| | | //} |
| | | //else |
| | | //{ |
| | | // _unitOfWorkManage.RollbackTran(); |
| | | // return content; |
| | | //} |
| | | //BaseDal.AddData(tasks); |
| | | |
| | | if (stockInfos != null && outboundOrderDetails != null && outStockLockInfos != null && locationInfos != null) |
| | | { |
| | | Dt_OutboundOrder outboundOrder = _outboundService.OutboundOrderService.Repository.QueryFirst(x => x.Id == outboundOrderDetails.FirstOrDefault().OrderId); |
| | | outboundOrder.OrderStatus = OutboundStatusEnum.åºåºä¸.ObjToInt(); |
| | | _outboundService.OutboundOrderService.Repository.UpdateData(outboundOrder); |
| | | content = _outboundService.OutboundOrderDetailService.LockOutboundStockDataUpdate(stockInfos, outboundOrderDetails, outStockLockInfos, locationInfos, tasks: tasks); |
| | | |
| | | if (!content.Status) |
| | | { |
| | | _unitOfWorkManage.RollbackTran(); |
| | | return content; |
| | | } |
| | | } |
| | | else if (outboundOrderDetails != null && outboundOrderDetails.Count > 0) |
| | | { |
| | | outboundOrderDetails.ForEach(x => |
| | | { |
| | | x.OrderDetailStatus = OrderDetailStatusEnum.Outbound.ObjToInt(); |
| | | }); |
| | | |
| | | _outboundService.OutboundOrderDetailService.Repository.UpdateData(outboundOrderDetails); |
| | | } |
| | | _unitOfWorkManage.CommitTran(); |
| | | //å°ä»»å¡æ¨éå°WCS |
| | | |
| | | if (tasks.FirstOrDefault().Roadway.Contains("SC01_BC")) |
| | | { |
| | | PushTasksToWCS(tasks); |
| | | } |
| | | else |
| | | { |
| | | PushTasksWCS(tasks); |
| | | } |
| | | return WebResponseContent.Instance.OK(); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | _unitOfWorkManage.RollbackTran(); |
| | | return WebResponseContent.Instance.Error(ex.Message); |
| | | } |
| | | |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 夿巷éå
ç§»åº |
| | | /// </summary> |
| | | /// <param name="TaskNum"></param> |
| | | /// <param name="SourceAddress"></param> |
| | | /// <returns></returns> |
| | | public WebResponseContent IsRelocations(int TaskNum, string SourceAddress) |
| | | { |
| | | try |
| | | { |
| | | WebResponseContent content = new WebResponseContent(); |
| | | List<Dt_LocationInfo> loca = new List<Dt_LocationInfo>(); |
| | | Dt_Task task = BaseDal.QueryFirst(x => x.TaskNum == TaskNum); |
| | | if (task == null) |
| | | { |
| | | return content = WebResponseContent.Instance.Error($"æªæ¾å°è¯¥ä»»å¡ä¿¡æ¯ï¼ä»»å¡å·ï¼{TaskNum}"); |
| | | } |
| | | else |
| | | { |
| | | //夿æ¯å¦éè¦ç§»åº |
| | | string[] targetCodes = SourceAddress.Split("-"); |
| | | if (targetCodes[1] == "001") |
| | | { |
| | | targetCodes[1] = "002"; |
| | | |
| | | } |
| | | else if (targetCodes[1] == "004") |
| | | { |
| | | targetCodes[1] = "003"; |
| | | } |
| | | else |
| | | { |
| | | return content = WebResponseContent.Instance.Error($"è´§ä½è§£æå¤±è´¥ï¼è´§ä½ç¼å·ï¼{SourceAddress}"); |
| | | } |
| | | targetCodes[4] = "01"; |
| | | string LocationCode = string.Join("-", targetCodes); //ç»è£
æµ
åºä½å°å |
| | | Dt_LocationInfo locationInfos = _basicService.LocationInfoService.Repository.QueryFirst(x => x.LocationCode == LocationCode && (x.LocationStatus == (int)LocationStatusEnum.Free || x.LocationStatus == (int)LocationStatusEnum.InStock)); |
| | | if (locationInfos == null) |
| | | { |
| | | return content = WebResponseContent.Instance.Error($"æªæ¾å°è¯¥è´§ä½ä¿¡æ¯,è´§ä½ç¼å·:{locationInfos}"); |
| | | } |
| | | else |
| | | { |
| | | if (locationInfos.LocationStatus == (int)LocationStatusEnum.Free) //夿æµ
è´§ä½æ¯å¦æè´§ |
| | | { |
| | | return content = WebResponseContent.Instance.OK(); |
| | | } |
| | | else |
| | | { |
| | | Dt_StockInfo dt_StockInfo = _stockService.StockInfoService.Repository.QueryFirst(x => x.LocationCode == LocationCode && x.StockStatus == (int)StockStatusEmun.å·²å
¥åº); |
| | | if (dt_StockInfo == null) |
| | | { |
| | | return content = WebResponseContent.Instance.Error($"æªæ¾å°è¯¥è´§ä½çåºåä¿¡æ¯,è´§ä½ç¼å·:{LocationCode}"); |
| | | } |
| | | else |
| | | { |
| | | Dt_LocationInfo newLocation; |
| | | //æ¥èµ°è´§ä½ï¼è¿è¡çæç§»åºä»»å¡ |
| | | int Locationtype = 9; //é»è®¤ä¸º9 |
| | | if (dt_StockInfo.MaterialType == (int)InventoryMaterialType.æå) |
| | | { |
| | | Locationtype = 11; |
| | | } |
| | | else if (dt_StockInfo.MaterialType == (int)InventoryMaterialType.åææ) |
| | | { |
| | | Locationtype = 10; |
| | | } |
| | | newLocation = _basicService.LocationInfoService.GetLocation(locationInfos.RoadwayNo, Locationtype); //æ¿å°äºç§»åºåçè´§ä½ |
| | | if (dt_StockInfo.MaterialType == (int)InventoryMaterialType.æå) |
| | | { |
| | | string[] targetCodesst = dt_StockInfo.PalletCode.Split("*"); |
| | | //Dt_InboundOrder dt_Inbound = _inboundService.InbounOrderService.Repository.QueryFirst(x => x.OrderName == targetCodesst[0]); |
| | | //if (dt_Inbound.Startingcolumn != 0 || dt_Inbound.Terminationcolumn != 0) |
| | | //{ |
| | | // newLocation = _basicService.LocationInfoService.GetLocation2(locationInfos.RoadwayNo, Locationtype, dt_Inbound.Startingcolumn, dt_Inbound.Terminationcolumn); |
| | | //} |
| | | //else |
| | | //{ |
| | | // newLocation = _basicService.LocationInfoService.GetLocation(locationInfos.RoadwayNo, Locationtype); |
| | | //} |
| | | |
| | | } |
| | | else |
| | | { |
| | | newLocation = _basicService.LocationInfoService.GetLocation(locationInfos.RoadwayNo, Locationtype); |
| | | } |
| | | |
| | | |
| | | if (newLocation != null) |
| | | { |
| | | Dt_Task dt_Task = new() |
| | | { |
| | | PalletCode = dt_StockInfo.PalletCode, |
| | | Roadway = locationInfos.RoadwayNo, |
| | | //TaskType = TaskTypeEnum.RelocationIn.ObjToInt(), |
| | | TaskStatus = OutTaskStatusEnum.OutNew.ObjToInt(), |
| | | SourceAddress = locationInfos.LocationCode, |
| | | TargetAddress = newLocation.LocationCode, |
| | | CurrentAddress = locationInfos.LocationCode, |
| | | NextAddress = newLocation.LocationCode, |
| | | Grade = 2, |
| | | Creater = "WMS", |
| | | CreateDate = DateTime.Now, |
| | | TaskNum = BaseDal.GetTaskNum(nameof(SequenceEnum.SeqTaskNum)), |
| | | MaterialType = dt_StockInfo.MaterialType |
| | | }; |
| | | _unitOfWorkManage.BeginTran(); |
| | | if (locationInfos.LocationStatus == LocationStatusEnum.InStock.ObjToInt()) |
| | | { |
| | | locationInfos.LocationStatus = LocationStatusEnum.Lock.ObjToInt(); |
| | | newLocation.LocationStatus = LocationStatusEnum.Lock.ObjToInt(); |
| | | |
| | | } |
| | | else if (locationInfos.LocationStatus == LocationStatusEnum.Pallet.ObjToInt()) |
| | | { |
| | | locationInfos.LocationStatus = LocationStatusEnum.PalletLock.ObjToInt(); |
| | | newLocation.LocationStatus = LocationStatusEnum.PalletLock.ObjToInt(); |
| | | } |
| | | loca.Add(newLocation); |
| | | loca.Add(locationInfos); |
| | | _basicService.LocationInfoService.UpdateData(loca); |
| | | _unitOfWorkManage.CommitTran(); |
| | | return content = WebResponseContent.Instance.OK(data: dt_Task); |
| | | } |
| | | else |
| | | { |
| | | return content = WebResponseContent.Instance.Error($"æªæ¾å°å··éå
å¯ç§»åºçè´§ä½"); |
| | | } |
| | | |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | _unitOfWorkManage.RollbackTran(); |
| | | throw; |
| | | } |
| | | } |
| | | |
| | | |
| | | public string ReceiveWMSTask = WIDESEA_Core.Helper.AppSettings.Configuration["ReceiveWMSTask"]; |
| | | |
| | | /// <summary> |
| | | /// çæåºåºä»»å¡ |
| | | /// </summary> |
| | | /// <param name="keys"></param> |
| | | /// <returns></returns> |
| | | public WebResponseContent WMSGenerateOutboundTask(int[] keys) |
| | | { |
| | | try |
| | | { |
| | | List<Dt_Task> tasks = new List<Dt_Task>(); |
| | | List<StockSelectViewDTO> stockSelectViews = new List<StockSelectViewDTO>(); |
| | | List<Dt_StockInfo> stockInfos = new List<Dt_StockInfo>(); |
| | | List<Dt_OutboundOrderDetail> outboundOrderDetails = new List<Dt_OutboundOrderDetail>(); |
| | | List<Dt_OutStockLockInfo> outStockLockInfos = new List<Dt_OutStockLockInfo>(); |
| | | List<Dt_LocationInfo> locationInfos = new List<Dt_LocationInfo>(); |
| | | foreach (int key in keys) |
| | | { |
| | | |
| | | (List<Dt_Task>, List<Dt_StockInfo>?, List<Dt_OutboundOrderDetail>?, List<Dt_OutStockLockInfo>?, List<Dt_LocationInfo>?) result = OutboundTaskDataHandle(keys); |
| | | if (result.Item2 != null && result.Item2.Count > 0) |
| | | { |
| | | stockInfos.AddRange(result.Item2); |
| | | } |
| | | if (result.Item3 != null && result.Item3.Count > 0) |
| | | { |
| | | outboundOrderDetails.AddRange(result.Item3); |
| | | } |
| | | if (result.Item4 != null && result.Item4.Count > 0) |
| | | { |
| | | outStockLockInfos.AddRange(result.Item4); |
| | | } |
| | | if (result.Item5 != null && result.Item5.Count > 0) |
| | | { |
| | | if (result.Item5.Any(x => x.RoadwayNo.Contains("DW")) || result.Item5.Any(x => x.RoadwayNo.Contains("YS"))) |
| | | { |
| | | locationInfos.AddRange(result.Item5.DistinctBy(x => x.LocationCode)); |
| | | |
| | | } |
| | | else |
| | | { |
| | | locationInfos.AddRange(result.Item5); |
| | | |
| | | } |
| | | |
| | | } |
| | | if (result.Item1 != null && result.Item1.Count > 0) |
| | | { |
| | | tasks.AddRange(result.Item1); |
| | | } |
| | | if (locationInfos.First().RoadwayNo.Contains("DW") || locationInfos.First().RoadwayNo.Contains("YS")) |
| | | { |
| | | break; |
| | | } |
| | | |
| | | } |
| | | |
| | | WebResponseContent content = GenerateOutboundTaskDataUpdate(tasks, stockInfos, outboundOrderDetails, outStockLockInfos, locationInfos); |
| | | return content; |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | _unitOfWorkManage.RollbackTran(); |
| | | return WebResponseContent.Instance.Error(ex.Message); |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// ä»»å¡åæ¶ |
| | | /// </summary> |
| | | /// <param name="saveModel"></param> |
| | | /// <returns></returns> |
| | | public WebResponseContent Cancelinventory(int taskNum) |
| | | { |
| | | WebResponseContent content = new WebResponseContent(); |
| | | Dt_Task task = BaseDal.QueryFirst(x => x.TaskNum == taskNum); |
| | | if (task != null) |
| | | { |
| | | if (task.TaskType == (int)TaskTypeEnum.Outbound || task.TaskType == (int)TaskTypeEnum.EmptyProductBack) |
| | | { |
| | | //å¤çåºåºçé»è¾ |
| | | Dt_LocationInfo locationinfo = _basicService.LocationInfoService.Repository.QueryFirst(x => x.LocationCode == task.SourceAddress); |
| | | if (locationinfo.LocationStatus == LocationStatusEnum.Lock.ObjToInt()) |
| | | { |
| | | locationinfo.LocationStatus = LocationStatusEnum.InStock.ObjToInt(); |
| | | } |
| | | if (locationinfo.LocationStatus == LocationStatusEnum.PalletLock.ObjToInt()) |
| | | { |
| | | locationinfo.LocationStatus = LocationStatusEnum.Pallet.ObjToInt(); |
| | | } |
| | | _basicService.LocationInfoService.Repository.UpdateData(locationinfo); |
| | | Dt_StockInfo stockInfo = _stockService.StockInfoService.Repository.QueryFirst(x => x.PalletCode == task.PalletCode); |
| | | stockInfo.StockStatus = (int)StockStatusEmun.å·²å
¥åº; |
| | | _stockService.StockInfoService.Repository.UpdateData(stockInfo); |
| | | Dt_StockInfoDetail stocktdetail = _stockService.StockInfoDetailService.Repository.QueryFirst(x => x.StockId == stockInfo.Id); |
| | | if (stocktdetail != null) |
| | | { |
| | | stocktdetail.Status = (int)StockStatusEmun.å·²å
¥åº; |
| | | _stockService.StockInfoDetailService.Repository.UpdateData(stocktdetail); |
| | | } |
| | | BaseDal.DeleteData(task); |
| | | BaseDal.DeleteAndMoveIntoHty(task, OperateType.人工å é¤); |
| | | WriteLog.GetLog("任塿¥å¿").Write($"åºåºä»»å¡åæ¶æåï¼æçæ¡ç ï¼{task.PalletCode}", $"ä»»å¡åæ¶"); |
| | | return content = WebResponseContent.Instance.Error($"åºåºä»»å¡åæ¶æå"); |
| | | |
| | | } |
| | | else if (task.TaskType == (int)TaskTypeEnum.Inbound || task.TaskType == (int)TaskTypeEnum.Inbound) |
| | | { |
| | | //å¤çåºåºçé»è¾ |
| | | Dt_LocationInfo locationinfo = _basicService.LocationInfoService.Repository.QueryFirst(x => x.LocationCode == task.TargetAddress); |
| | | if (locationinfo.LocationStatus == LocationStatusEnum.Lock.ObjToInt() || locationinfo.LocationStatus == LocationStatusEnum.PalletLock.ObjToInt()) |
| | | { |
| | | locationinfo.LocationStatus = LocationStatusEnum.Free.ObjToInt(); |
| | | } |
| | | _basicService.LocationInfoService.Repository.UpdateData(locationinfo); |
| | | Dt_StockInfo stockInfo = _stockService.StockInfoService.Repository.QueryFirst(x => x.PalletCode == task.PalletCode); |
| | | _stockService.StockInfoService.Repository.DeleteData(stockInfo); |
| | | Dt_StockInfoDetail stocktdetail = _stockService.StockInfoDetailService.Repository.QueryFirst(x => x.StockId == stockInfo.Id); |
| | | if (stocktdetail != null) |
| | | { |
| | | _stockService.StockInfoDetailService.Repository.DeleteData(stocktdetail); |
| | | } |
| | | BaseDal.DeleteData(task); |
| | | BaseDal.DeleteAndMoveIntoHty(task, OperateType.人工å é¤); |
| | | WriteLog.GetLog("任塿¥å¿").Write($"å
¥åºä»»å¡åæ¶æåï¼æçæ¡ç ï¼{task.PalletCode}", $"ä»»å¡åæ¶"); |
| | | return content = WebResponseContent.Instance.Error($"å
¥åºä»»å¡åæ¶æå"); |
| | | } |
| | | else |
| | | { |
| | | return content = WebResponseContent.Instance.Error($"该任å¡çä»»å¡ç±»åå¼å¸¸ï¼åæ¶å¤±è´¥"); |
| | | } |
| | | } |
| | | else |
| | | { |
| | | return content = WebResponseContent.Instance.Error($"æªæ¾å°ä»»å¡å·"); |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// éå®åºåçæçç¹ååºåº |
| | | /// </summary> |
| | | /// <param name="id"></param> |
| | | /// <returns></returns> |
| | | public WebResponseContent TakeOutbound(List<StockViewDTO> stockViews) |
| | | { |
| | | WebResponseContent content = new WebResponseContent(); |
| | | try |
| | | { |
| | | if (stockViews.Select(x => x.WarehouseId).Distinct().Count() >= 2) |
| | | { |
| | | return content.Error($"è¯·éæ©åä¸ä»åºåºåè¿è¡çç¹"); |
| | | } |
| | | List<int> ids = stockViews.Select(x => x.StockId).ToList(); |
| | | //è·ååºå |
| | | List<Dt_StockInfo> stockInfos = _stockRepository.StockInfoRepository.Db.Queryable<Dt_StockInfo>().Where(x => ids.Contains(x.Id)).Includes(x => x.Details).ToList(); |
| | | if (stockInfos.Count != stockViews.Count) |
| | | { |
| | | StockViewDTO? stockViewDTO = stockViews.FirstOrDefault(x => !stockInfos.Select(x => x.PalletCode).ToList().Contains(x.PalletCode)); |
| | | return content.Error($"æªæ¾å°{stockViewDTO?.PalletCode}åºå"); |
| | | } |
| | | //è·åè´§ä½ |
| | | List<string> locStrs = stockInfos.Select(x => x.LocationCode).ToList(); |
| | | List<Dt_LocationInfo> locationInfos = _basicRepository.LocationInfoRepository.QueryData(x => locStrs.Contains(x.LocationCode)); |
| | | if (stockInfos.Count != locationInfos.Count) |
| | | { |
| | | string? locStr = locStrs.FirstOrDefault(x => !locationInfos.Select(x => x.LocationCode).ToList().Contains(x)); |
| | | return content.Error($"æªæ¾å°{locStr}è´§ä½æ°æ®"); |
| | | } |
| | | Dt_TakeStockOrder takeStockOrder = new Dt_TakeStockOrder() |
| | | { |
| | | WarehouseId = stockInfos.FirstOrDefault().WarehouseId, |
| | | TakeStockStatus = TakeStockStatusEnum.çç¹ä¸.ObjToInt(), |
| | | OrderNo = _outboundService.OutboundOrderService.CreateCodeByRule(nameof(RuleCode.PDCodeRule)), |
| | | Details = new List<Dt_TakeStockOrderDetail>() |
| | | }; |
| | | foreach (var item in stockInfos) |
| | | { |
| | | if (item.Details.Count <= 0) |
| | | { |
| | | return content.Error($"æªæ¾å°{item.PalletCode}åºåæç»æ°æ®"); |
| | | } |
| | | Dt_LocationInfo? locationInfo = locationInfos.FirstOrDefault(x => x.LocationCode == item.LocationCode); |
| | | if (locationInfo != null && (locationInfo.EnableStatus == EnableStatusEnum.OnlyOut.ObjToInt() || locationInfo.EnableStatus == EnableStatusEnum.Normal.ObjToInt()) && locationInfo.LocationStatus == LocationStatusEnum.InStock.ObjToInt() && item.StockStatus == StockStatusEmun.å
¥åºå®æ.ObjToInt()) |
| | | { |
| | | //å建æç» |
| | | Dt_TakeStockOrderDetail takeStockOrderDetail = new Dt_TakeStockOrderDetail() |
| | | { |
| | | MaterielCode = item.Details.FirstOrDefault().MaterielCode, |
| | | MaterielName = item.Details.FirstOrDefault().MaterielName ?? "æ ç©æåç§°", |
| | | BatchNo = item.Details.FirstOrDefault().BatchNo, |
| | | MaterielSpec = item.Details.FirstOrDefault().MaterieSpec ?? "æ ç©æè§æ ¼", |
| | | LocationCode = item.LocationCode, |
| | | TakePalletCode = item.PalletCode, |
| | | TakeDetalStatus = TakeStockDetailStatusEnum.çç¹åºåºä¸.ObjToInt(), |
| | | SysQty = item.Details.Sum(x => x.StockQuantity), |
| | | Qty = 0 |
| | | }; |
| | | takeStockOrder.Details.Add(takeStockOrderDetail); |
| | | } |
| | | else |
| | | { |
| | | content.Error($"è´§ä½æåºåç¶æä¸æ»¡è¶³åºåºæ¡ä»¶"); |
| | | } |
| | | } |
| | | List<Dt_Task> tasks = GetTasks(stockInfos, TaskTypeEnum.OutInventory); |
| | | if (tasks == null || tasks.Count <= 0) |
| | | { |
| | | return content.Error($"çæä»»å¡å¤±è´¥"); |
| | | } |
| | | stockInfos.ForEach(x => |
| | | { |
| | | x.StockStatus = StockStatusEmun.åºåºéå®.ObjToInt(); |
| | | }); |
| | | tasks.ForEach(x => |
| | | { |
| | | x.OrderNo = takeStockOrder.OrderNo; |
| | | }); |
| | | LocationStatusEnum locationStatus = LocationStatusEnum.Lock; |
| | | _unitOfWorkManage.BeginTran(); |
| | | //æ´æ°åºåç¶æ |
| | | _stockRepository.StockInfoRepository.UpdateData(stockInfos); |
| | | BaseDal.Db.InsertNav(takeStockOrder).Include(x => x.Details).ExecuteCommand(); |
| | | //æ°å»ºä»»å¡ |
| | | BaseDal.AddData(tasks); |
| | | _basicService.LocationInfoService.Repository.UpdateLocationStatus(locationInfos, locationStatus); |
| | | _unitOfWorkManage.CommitTran(); |
| | | if (tasks.FirstOrDefault().PalletCode.Contains("BC")) |
| | | { |
| | | PushTasksToWCS(tasks); |
| | | } |
| | | else |
| | | { |
| | | PushTasksWCS(tasks); |
| | | } |
| | | |
| | | content.OK(); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | _unitOfWorkManage.RollbackTran(); |
| | | content.Error(ex.Message); |
| | | } |
| | | return content; |
| | | } |
| | | } |
| | | } |