| | |
| | | using OfficeOpenXml.FormulaParsing.Excel.Functions.RefAndLookup; |
| | | using SqlSugar; |
| | | using System; |
| | | using System.Collections; |
| | | using System.Collections.Concurrent; |
| | | using System.Collections.Generic; |
| | | using System.Linq; |
| | | using System.Text; |
| | | using System.Threading.Tasks; |
| | | using System.Transactions; |
| | | using WIDESEA_BasicService; |
| | | using WIDESEA_Common.CommonEnum; |
| | | using WIDESEA_Common.LocationEnum; |
| | |
| | | WebResponseContent content = new WebResponseContent(); |
| | | try |
| | | { |
| | | var stockInfos = _stockRepository.Db.Queryable<Dt_StockInfo>().Where(x => x.PalletType == PalletTypeEnum.Empty.ObjToInt() && x.StockStatus == StockStatusEmun.å
¥åºå®æ.ObjToInt()).WhereIF(locationType != 0, x => x.LocationType == locationType).Take(num).ToList(); |
| | | Dictionary<string, SqlSugar.OrderByType> orderByDict = new Dictionary<string, SqlSugar.OrderByType>() |
| | | { |
| | | { nameof(Dt_LocationInfo.Layer), SqlSugar.OrderByType.Asc }, |
| | | { nameof(Dt_LocationInfo.Row), SqlSugar.OrderByType.Asc }, |
| | | { nameof(Dt_LocationInfo.Column), SqlSugar.OrderByType.Asc }, |
| | | { nameof(Dt_LocationInfo.Depth), SqlSugar.OrderByType.Desc }, |
| | | }; |
| | | |
| | | if (stockInfos.Count() == 0) |
| | | var query = _stockRepository.Db.Queryable<Dt_StockInfo>() |
| | | .Where(x => x.PalletType == PalletTypeEnum.Empty.ObjToInt() |
| | | && x.StockStatus == StockStatusEmun.å
¥åºå®æ.ObjToInt()) |
| | | .WhereIF(locationType != 0, x => x.LocationType == locationType) |
| | | .LeftJoin<Dt_LocationInfo>((s, l) => s.LocationCode == l.LocationCode); |
| | | |
| | | if (query.Count() == 0) |
| | | { |
| | | return WebResponseContent.Instance.Error("æªæ¾å°ç©ºæçåºå"); |
| | | } |
| | | |
| | | bool isFirstOrder = true; |
| | | foreach (var item in orderByDict) |
| | | { |
| | | string fieldName = item.Key.Equals("Column", StringComparison.OrdinalIgnoreCase) |
| | | ? $"l.[{item.Key}]" |
| | | : $"l.{item.Key}"; |
| | | |
| | | string sortSql = $"{fieldName} {(item.Value == SqlSugar.OrderByType.Asc ? "ASC" : "DESC")}"; |
| | | |
| | | if (isFirstOrder) |
| | | { |
| | | query = query.OrderBy(sortSql); |
| | | isFirstOrder = false; |
| | | } |
| | | else |
| | | { |
| | | query = query.OrderBy(sortSql); |
| | | } |
| | | } |
| | | |
| | | var stockInfos = await query.Take(num).ToListAsync(); |
| | | |
| | | foreach (var stockInfo in stockInfos) |
| | | { |
| | | Dt_LocationInfo locationInfo = _locationInfoService.Repository.QueryFirst(x => x.LocationCode == stockInfo.LocationCode); |
| | |
| | | |
| | | _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); |
| | | } |
| | | return content.OK("空æåºåºæå!"); |
| | | } |
| | |
| | | return WebResponseContent.Instance.Error(ex.Message); |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | /// <summary> |
| | |
| | | TargetAddress = outStation, |
| | | TaskStatus = TaskStatusEnum.New.ObjToInt(), |
| | | TaskType = taskType.ObjToInt(), |
| | | // TaskNum = BaseDal.GetTaskNum(nameof(SequenceEnum.SeqTaskNum)), |
| | | //TaskNum = BaseDal.GetTaskNum(nameof(SequenceEnum.SeqTaskNum)), |
| | | PalletType = stockInfo.PalletType, |
| | | WarehouseId = stockInfo.WarehouseId, |
| | | }; |
| | |
| | | |
| | | } |
| | | |
| | | |
| | | |
| | | #region åæ¹åé
åºå |
| | | #region å
åé管çå¨ |
| | | private static readonly ConcurrentDictionary<string, SemaphoreSlim> _materialLocks = |
| | |
| | | WebResponseContent content = new WebResponseContent(); |
| | | try |
| | | { |
| | | var allFactoryAreas = stockViews.SelectMany(sv => sv.Details) |
| | | .Select(x => x.FactoryArea) |
| | | .GroupBy(x => x) |
| | | .ToList(); |
| | | if (allFactoryAreas.Count >= 2) |
| | | { |
| | | return content.Error($"è¯·éæ©åä¸ååºåºåçåºåè¿è¡çç¹ï¼å½åæ¶å{allFactoryAreas.Count}个ä¸åçååº"); |
| | | } |
| | | List<int> ids = stockViews.Select(x => x.StockId).ToList(); |
| | | //è·ååºå |
| | | List<Dt_StockInfo> stockInfos = _stockRepository.Db.Queryable<Dt_StockInfo>().Where(x => ids.Contains(x.Id)).Includes(x => x.Details).ToList(); |
| | |
| | | } |
| | | //è·åè´§ä½ |
| | | List<string> locStrs = stockInfos.Select(x => x.LocationCode).ToList(); |
| | | List<Dt_LocationInfo> locationInfos = (List<Dt_LocationInfo>)_locationInfoService.Db.Queryable<Dt_LocationInfo>().Where(x => locStrs.Contains(x.LocationCode)); |
| | | List<Dt_LocationInfo> locationInfos =_locationInfoService.Db.Queryable<Dt_LocationInfo>().Where(x => locStrs.Contains(x.LocationCode)).ToList(); |
| | | if (stockInfos.Count != locationInfos.Count) |
| | | { |
| | | string? locStr = locStrs.FirstOrDefault(x => !locationInfos.Select(x => x.LocationCode).ToList().Contains(x)); |
| | |
| | | WarehouseId = stockInfos.FirstOrDefault().WarehouseId, |
| | | TakeStockStatus = TakeStockStatusEnum.çç¹ä¸.ObjToInt(), |
| | | OrderNo = CreateCodeByRule(nameof(RuleCodeEnum.PDCodeRule)), |
| | | Details = new List<Dt_TakeStockOrderDetail>() |
| | | AllPalletCode = string.Join(",", stockInfos.Select(item => item.PalletCode).Where(palletCode => !string.IsNullOrEmpty(palletCode))), |
| | | Remark = outStation |
| | | |
| | | }; |
| | | foreach (var item in stockInfos) |
| | | { |
| | |
| | | return content.Error($"æªæ¾å°{item.PalletCode}åºåæç»æ°æ®"); |
| | | } |
| | | Dt_LocationInfo? locationInfo = locationInfos.FirstOrDefault(x => x.LocationCode == item.LocationCode); |
| | | if (locationInfo == null && (locationInfo.EnableStatus == EnableStatusEnum.Disable.ObjToInt() || locationInfo.EnableStatus != EnableStatusEnum.Normal.ObjToInt()) && locationInfo.LocationStatus != LocationStatusEnum.InStock.ObjToInt() && item.StockStatus != StockStatusEmun.å
¥åºå®æ.ObjToInt()) |
| | | if (locationInfo == null || (locationInfo.EnableStatus == EnableStatusEnum.Disable.ObjToInt() || locationInfo.EnableStatus != EnableStatusEnum.Normal.ObjToInt()) || locationInfo.LocationStatus != LocationStatusEnum.InStock.ObjToInt() || item.StockStatus != StockStatusEmun.å
¥åºå®æ.ObjToInt()) |
| | | { |
| | | content.Error($"{item.PalletCode}è´§ä½æåºåç¶æä¸æ»¡è¶³åºåºæ¡ä»¶"); |
| | | return content.Error($"{item.PalletCode}è´§ä½æåºåç¶æä¸æ»¡è¶³åºåºæ¡ä»¶"); |
| | | } |
| | | } |
| | | List<Dt_Task> tasks = GetTasks(stockInfos, TaskTypeEnum.OutInventory,outStation); |
| | |
| | | _unitOfWorkManage.BeginTran(); |
| | | //æ´æ°åºåç¶æ |
| | | _stockRepository.UpdateData(stockInfos); |
| | | BaseDal.Db.InsertNav(takeStockOrder); |
| | | _takeStockOrder.AddData(takeStockOrder); |
| | | //æ°å»ºä»»å¡ |
| | | BaseDal.AddData(tasks); |
| | | _locationInfoService.UpdateData(locationInfos); |
| | |
| | | catch (Exception ex) |
| | | { |
| | | _unitOfWorkManage.RollbackTran(); |
| | | content.Error(ex.Message); |
| | | return await Task.FromResult(WebResponseContent.Instance.Error(ex.Message)); |
| | | } |
| | | return content; |
| | | } |
| | |
| | | return code; |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// éå®åºåååºåç§»åº |
| | | /// </summary> |
| | | /// <param name="id"></param> |
| | | /// <returns></returns> |
| | | public async Task<WebResponseContent> AreaOutbound(List<StockViewDTO> stockViews) |
| | | { |
| | | WebResponseContent content = new WebResponseContent(); |
| | | try |
| | | { |
| | | List<int> ids = stockViews.Select(x => x.StockId).ToList(); |
| | | //è·ååºå |
| | | List<Dt_StockInfo> stockInfos = _stockRepository.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 = _locationInfoService.Db.Queryable<Dt_LocationInfo>().Where(x => locStrs.Contains(x.LocationCode)).ToList(); |
| | | if (stockInfos.Count != locationInfos.Count) |
| | | { |
| | | string? locStr = locStrs.FirstOrDefault(x => !locationInfos.Select(x => x.LocationCode).ToList().Contains(x)); |
| | | return content.Error($"æªæ¾å°{locStr}è´§ä½æ°æ®"); |
| | | } |
| | | |
| | | foreach (var item in stockInfos) |
| | | { |
| | | Dt_LocationInfo? locationInfo = locationInfos.FirstOrDefault(x => x.LocationCode == item.LocationCode); |
| | | if (locationInfo == null || (locationInfo.EnableStatus == EnableStatusEnum.Disable.ObjToInt() || locationInfo.EnableStatus != EnableStatusEnum.Normal.ObjToInt()) || item.StockStatus != StockStatusEmun.å
¥åºå®æ.ObjToInt()) |
| | | { |
| | | return content.Error($"{item.PalletCode}è´§ä½æåºåç¶æä¸æ»¡è¶³åºåºæ¡ä»¶"); |
| | | } |
| | | } |
| | | List<Dt_Task> tasks = AreaGetTasks(stockInfos, TaskTypeEnum.AreaRelocation); |
| | | if (tasks == null || tasks.Count <= 0) |
| | | { |
| | | return content.Error($"çæä»»å¡å¤±è´¥"); |
| | | } |
| | | stockInfos.ForEach(x => |
| | | { |
| | | x.StockStatus = StockStatusEmun.åºåºéå®.ObjToInt(); |
| | | }); |
| | | tasks.ForEach(x => |
| | | { |
| | | x.OrderNo = "æ åæ®ç§»åº"; |
| | | }); |
| | | locationInfos.ForEach(x => |
| | | { |
| | | x.LocationStatus = LocationStatusEnum.Lock.ObjToInt(); |
| | | }); |
| | | _unitOfWorkManage.BeginTran(); |
| | | //æ´æ°åºåç¶æ |
| | | _stockRepository.UpdateData(stockInfos); |
| | | //æ°å»ºä»»å¡ |
| | | BaseDal.AddData(tasks); |
| | | _locationInfoService.UpdateData(locationInfos); |
| | | _unitOfWorkManage.CommitTran(); |
| | | content.OK(); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | _unitOfWorkManage.RollbackTran(); |
| | | return await Task.FromResult(WebResponseContent.Instance.Error(ex.Message)); |
| | | } |
| | | return content; |
| | | } |
| | | |
| | | public List<Dt_Task> AreaGetTasks(List<Dt_StockInfo> stockInfos, TaskTypeEnum taskType) |
| | | { |
| | | // ä½¿ç¨ TransactionScope å
裹æ´ä¸ªæä½ï¼ç¡®ä¿æææ°æ®åºæä½å¨åä¸äºå¡ä¸ |
| | | using (var scope = new TransactionScope(TransactionScopeOption.Required, |
| | | new TransactionOptions { IsolationLevel = IsolationLevel.ReadCommitted })) |
| | | { |
| | | try |
| | | { |
| | | List<Dt_Task> tasks = new List<Dt_Task>(); |
| | | List<Dt_LocationInfo> locationInfos = _locationInfoService.Repository.QueryData( |
| | | x => stockInfos.Select(x => x.LocationCode).Contains(x.LocationCode)); |
| | | |
| | | for (int i = 0; i < stockInfos.Count; i++) |
| | | { |
| | | Dt_StockInfo stockInfo = stockInfos[i]; |
| | | |
| | | if (stockInfo != null) |
| | | { |
| | | Dt_LocationInfo? locationInfo = locationInfos.FirstOrDefault(x => x.LocationCode == stockInfo.LocationCode); |
| | | var newLocation = _locationInfoService.AssignLocation(stockInfo.LocationType); |
| | | |
| | | if (newLocation == null) |
| | | { |
| | | throw new Exception($"å¨{stockInfo.PalletCode}æ¶æ²¡æç©ºé²åºä½å¯è¿è¡ååºåç§»åºï¼è¯·æ£æ¥æåå°ç§»åºæç®±"); |
| | | } |
| | | |
| | | if (!tasks.Exists(x => x.PalletCode == stockInfo.PalletCode)) |
| | | { |
| | | Dt_Task task = new() |
| | | { |
| | | CurrentAddress = stockInfo.LocationCode, |
| | | Grade = 0, |
| | | PalletCode = stockInfo.PalletCode, |
| | | NextAddress = "", |
| | | Roadway = locationInfo.RoadwayNo, |
| | | SourceAddress = stockInfo.LocationCode, |
| | | TargetAddress = newLocation.LocationCode, |
| | | TaskStatus = TaskStatusEnum.New.ObjToInt(), |
| | | TaskType = taskType.ObjToInt(), |
| | | PalletType = stockInfo.PalletType, |
| | | WarehouseId = stockInfo.WarehouseId, |
| | | }; |
| | | tasks.Add(task); |
| | | } |
| | | |
| | | newLocation.LocationStatus = LocationStatusEnum.Lock.ObjToInt(); |
| | | _locationInfoService.UpdateData(newLocation); |
| | | } |
| | | } |
| | | |
| | | // æäº¤äºå¡ |
| | | scope.Complete(); |
| | | return tasks; |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | // TransactionScope ä¼èªå¨åæ»äºå¡ï¼æ éæå¨ Rollback |
| | | throw new Exception(ex.Message); |
| | | } |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// éå®åºåè·¨åºåç§»åº |
| | | /// </summary> |
| | | /// <param name="stockViews"></param> |
| | | /// <param name="targetLocationType">ç®æ è´§ä½ç±»å</param> |
| | | /// <returns></returns> |
| | | public async Task<WebResponseContent> CrossAreaOutbound(List<StockViewDTO> stockViews, int targetLocationType) |
| | | { |
| | | WebResponseContent content = new WebResponseContent(); |
| | | try |
| | | { |
| | | if(targetLocationType == (int)LocationTypeEnum.Electronic) |
| | | { |
| | | return content.Error("çµåä»ä¸å
许跨åºåç§»åº"); |
| | | } |
| | | List<int> ids = stockViews.Select(x => x.StockId).ToList(); |
| | | List<Dt_StockInfo> stockInfos = _stockRepository.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).Contains(x.PalletCode)); |
| | | return content.Error($"æªæ¾å°{stockViewDTO?.PalletCode}åºå"); |
| | | } |
| | | |
| | | List<string> locStrs = stockInfos.Select(x => x.LocationCode).ToList(); |
| | | List<Dt_LocationInfo> locationInfos = _locationInfoService.Db.Queryable<Dt_LocationInfo>().Where(x => locStrs.Contains(x.LocationCode)).ToList(); |
| | | |
| | | if (stockInfos.Count != locationInfos.Count) |
| | | { |
| | | string? locStr = locStrs.FirstOrDefault(x => !locationInfos.Select(x => x.LocationCode).Contains(x)); |
| | | return content.Error($"æªæ¾å°{locStr}è´§ä½æ°æ®"); |
| | | } |
| | | |
| | | foreach (var item in stockInfos) |
| | | { |
| | | if (item.PalletType != PalletTypeEnum.Empty.ObjToInt()) |
| | | { |
| | | return content.Error($"æçã{item.PalletCode}ãé空箱ï¼ä»
空箱å
许跨åºåç§»åºï¼"); |
| | | } |
| | | Dt_LocationInfo? locationInfo = locationInfos.FirstOrDefault(x => x.LocationCode == item.LocationCode); |
| | | if (locationInfo == null || locationInfo.EnableStatus != EnableStatusEnum.Normal.ObjToInt() || item.StockStatus != StockStatusEmun.å
¥åºå®æ.ObjToInt()) |
| | | { |
| | | return content.Error($"{item.PalletCode}è´§ä½æåºåç¶æä¸æ»¡è¶³åºåºæ¡ä»¶"); |
| | | } |
| | | } |
| | | |
| | | List<Dt_Task> tasks = CrossAreaGetTasks(stockInfos, targetLocationType, TaskTypeEnum.CrossAreaRelocation); |
| | | |
| | | if (tasks == null || tasks.Count <= 0) |
| | | { |
| | | return content.Error("çæè·¨åºåç§»åºä»»å¡å¤±è´¥"); |
| | | } |
| | | |
| | | stockInfos.ForEach(x => |
| | | { |
| | | x.StockStatus = StockStatusEmun.åºåºéå®.ObjToInt(); |
| | | }); |
| | | |
| | | tasks.ForEach(x => |
| | | { |
| | | x.OrderNo = "è·¨åºåç§»åº"; |
| | | }); |
| | | |
| | | locationInfos.ForEach(x => |
| | | { |
| | | x.LocationStatus = LocationStatusEnum.Lock.ObjToInt(); |
| | | }); |
| | | |
| | | _unitOfWorkManage.BeginTran(); |
| | | _stockRepository.UpdateData(stockInfos); |
| | | BaseDal.AddData(tasks); |
| | | _locationInfoService.UpdateData(locationInfos); |
| | | _unitOfWorkManage.CommitTran(); |
| | | |
| | | content.OK(); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | _unitOfWorkManage.RollbackTran(); |
| | | return await Task.FromResult(WebResponseContent.Instance.Error(ex.Message)); |
| | | } |
| | | return content; |
| | | } |
| | | |
| | | |
| | | /// <summary> |
| | | /// çæè·¨åºåç§»åºä»»å¡ |
| | | /// </summary> |
| | | /// <param name="stockInfos">åºåå表</param> |
| | | /// <param name="targetAreaCode">ç®æ åºåç¼ç </param> |
| | | /// <param name="taskType">ä»»å¡ç±»å</param> |
| | | /// <returns></returns> |
| | | public List<Dt_Task> CrossAreaGetTasks(List<Dt_StockInfo> stockInfos, int targetLocationType, TaskTypeEnum taskType) |
| | | { |
| | | using (var scope = new TransactionScope(TransactionScopeOption.Required, |
| | | new TransactionOptions { IsolationLevel = IsolationLevel.ReadCommitted })) |
| | | { |
| | | try |
| | | { |
| | | List<Dt_Task> tasks = new List<Dt_Task>(); |
| | | |
| | | foreach (var stockInfo in stockInfos) |
| | | { |
| | | Dt_LocationInfo newLocation = _locationInfoService.AssignLocation(targetLocationType); |
| | | |
| | | if (newLocation == null) |
| | | { |
| | | throw new Exception($"{stockInfo.PalletCode} 没æç©ºé²è´§ä½å¯è¿è¡è·¨åºåç§»åº"); |
| | | } |
| | | |
| | | if (!tasks.Exists(x => x.PalletCode == stockInfo.PalletCode)) |
| | | { |
| | | Dt_Task task = new() |
| | | { |
| | | CurrentAddress = stockInfo.LocationCode, |
| | | Grade = 0, |
| | | PalletCode = stockInfo.PalletCode, |
| | | NextAddress = "", |
| | | Roadway = newLocation.RoadwayNo, |
| | | SourceAddress = stockInfo.LocationCode, |
| | | TargetAddress = newLocation.LocationCode, |
| | | TaskStatus = TaskStatusEnum.New.ObjToInt(), |
| | | TaskType = taskType.ObjToInt(), |
| | | PalletType = stockInfo.PalletType, |
| | | WarehouseId = stockInfo.WarehouseId, |
| | | }; |
| | | tasks.Add(task); |
| | | } |
| | | |
| | | newLocation.LocationStatus = LocationStatusEnum.Lock.ObjToInt(); |
| | | _locationInfoService.UpdateData(newLocation); |
| | | } |
| | | |
| | | scope.Complete(); |
| | | return tasks; |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | throw new Exception(ex.Message); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | } |