| | |
| | | using WIDESEA_Core.Helper; |
| | | using WIDESEAWCS_DTO.WCSInfo; |
| | | using System.Transactions; |
| | | using OfficeOpenXml.FormulaParsing.Excel.Functions.RefAndLookup; |
| | | |
| | | namespace WIDESEA_TaskInfoService |
| | | { |
| | |
| | | locationInfo.LocationStatus = LocationStatusEnum.PalletLock.ObjToInt(); |
| | | if (isUpdateStock) |
| | | { |
| | | locationInfo.LocationStatus = LocationStatusEnum.Lock.ObjToInt(); |
| | | locationInfo.LocationStatus = LocationStatusEnum.OutLock.ObjToInt(); |
| | | if (stockInfo != null && stockInfo.Details != null && stockInfo.Details.Count > 0) |
| | | { |
| | | orderNo = stockInfo.Details.FirstOrDefault()?.OrderNo ?? ""; |
| | |
| | | WebResponseContent content = new WebResponseContent(); |
| | | try |
| | | { |
| | | Dt_RoadwayInfo roadwayInfo = _basicRepository.RoadwayInfoRepository.QueryFirst(x => x.InStationCode == lineDTO.stationCode) ?? throw new Exception("æªæ¾å°è¯¥ç«å°å¯¹åºçå··éï¼è¯·æ£æ¥åºç¡é
置信æ¯"); |
| | | if (roadwayInfo.EnableStatus != EnableStatusEnum.Normal.ObjToInt() && roadwayInfo.EnableStatus != EnableStatusEnum.OnlyIn.ObjToInt()) |
| | | { |
| | | throw new Exception("该巷éä¸å¯å
¥åºï¼è¯·æ£æ¥å··éç¦ç¨ä¿¡æ¯"); |
| | | } |
| | | if (roadwayInfo.AreaId > 0) |
| | | { |
| | | Dt_AreaInfo areaInfo = _basicRepository.AreaInfoRepository.QueryFirst(x => x.Id == roadwayInfo.AreaId); |
| | | if (areaInfo != null && areaInfo.AreaStatus == EnableEnum.Disable.ObjToInt()) |
| | | { |
| | | throw new Exception("åºå被ç¦ç¨ï¼ä¸å¯å
¥åº"); |
| | | } |
| | | } |
| | | var task = BaseDal.QueryFirst(x => x.PalletCode == lineDTO.Barcode); |
| | | if (task == null) throw new Exception($"æªæ¾å°æçå·[{lineDTO.Barcode}]çå
¥åºä»»å¡"); |
| | | if (task.TaskState >= (int)InTaskStatusEnum.Line_InFinish) throw new Exception($"æçå·[{lineDTO.Barcode}]çå
¥åºä»»å¡ç¶æä¸å¹é
"); |
| | | if (task.TaskState >= (int)InTaskStatusEnum.SC_InExecuting) throw new Exception($"æçå·[{lineDTO.Barcode}]çå
¥åºä»»å¡ç¶æä¸å¹é
"); |
| | | |
| | | #region 夿æ¯å¦ä¸ºç©ºæå
¥åº |
| | | if (task.TaskType == TaskTypeEnum.PalletInbound.ObjToInt()) |
| | | return GetEmptyLocation(task); |
| | | #endregion |
| | | |
| | | Dt_StockInfo stockInfo = _stockService.StockInfoService.Repository.GetStockInfo(lineDTO.Barcode); |
| | | if (stockInfo == null) throw new Exception($"æªæ¾å°æç[{lineDTO.Barcode}]çç»çä¿¡æ¯"); |
| | | Dt_StockInfoDetail? stockInfoDetail = stockInfo.Details.Where(x => x.StockId == stockInfo.Id).FirstOrDefault(); |
| | | if (stockInfoDetail == null) throw new Exception($"æªæ¾å°æç[{lineDTO.Barcode}]çç»ç详æ
"); |
| | | if (stockInfo.StockStatus != StockStatusEmun.å
¥åºç¡®è®¤.ObjToInt()) throw new Exception($"æç[{lineDTO.Barcode}],该ç»çç¶æä¸å¯å
¥åº"); |
| | | if (stockInfo.StockStatus != StockStatusEmun.å
¥åºç¡®è®¤.ObjToInt() || !string.IsNullOrEmpty(stockInfo.LocationCode)) |
| | | throw new Exception($"æç[{lineDTO.Barcode}],该ç»çç¶æä¸å¯å
¥åº"); |
| | | |
| | | Dt_InboundOrder inboundOrder = _inboundService.InbounOrderService.GetInboundOrder(stockInfoDetail.OrderNo); |
| | | if (inboundOrder == null || inboundOrder.Details == null) throw new Exception($"æªæ¾å°æç[{lineDTO.Barcode}]çå
¥åºåæç»ä¿¡æ¯"); |
| | | Dt_StockInfo instockInfo = null; |
| | | Dt_LocationInfo locationInfo = null; |
| | | #region 夿å½åå
¥åºæçæ¹æ¬¡å·æ¯å¦åå¨å·²åé
å
¥åº |
| | | Dt_StockInfoDetail instockInfoDetail = _stockService.StockInfoDetailService.Get_StockInfoDetail(stockInfoDetail.OrderNo, stockInfoDetail.BatchNo); |
| | | if (instockInfoDetail != null) instockInfo = _stockService.StockInfoService.Repository.GetStockInfo(instockInfoDetail.StockId); |
| | | if (instockInfo != null) |
| | | if (inboundOrder == null) throw new Exception($"æªæ¾å°æç[{lineDTO.Barcode}]çå
¥åºåä¿¡æ¯"); |
| | | |
| | | #region 夿æ¯å¦æå®è´§ä½ |
| | | Dt_InboundOrderDetail? orderDetail = inboundOrder.Details.FirstOrDefault(x => x.BatchNo == stockInfoDetail.BatchNo); |
| | | if (orderDetail == null) throw new Exception($"æªæ¾å°æç[{lineDTO.Barcode}]çå
¥åºåæç»ä¿¡æ¯"); |
| | | Dt_LocationInfo? locationInfo = null; |
| | | if (!string.IsNullOrEmpty(orderDetail.LocationCode)) |
| | | { |
| | | locationInfo = _basicService.LocationInfoService.GetLocation(instockInfo.LocationCode); |
| | | locationInfo = _basicService.LocationInfoService.GetLocation(orderDetail.LocationCode); |
| | | } |
| | | #endregion |
| | | |
| | | #region 夿å½åå
¥åºæçæ¹æ¬¡å·æ¯å¦åå¨å·²åé
å
¥åº |
| | | else |
| | | { |
| | | instockInfoDetail = _stockService.StockInfoDetailService.Get_StockInfoDetail(stockInfoDetail.OrderNo);//å
¥åºååå¨åºåï¼å¤æè´§ä½ |
| | | Dt_StockInfo? instockInfo = null; |
| | | Dt_StockInfoDetail instockInfoDetail = _stockService.StockInfoDetailService.Get_StockInfoDetail(stockInfoDetail.OrderNo, stockInfoDetail.BatchNo); |
| | | if (instockInfoDetail != null) instockInfo = _stockService.StockInfoService.Repository.GetStockInfo(instockInfoDetail.StockId); |
| | | if (instockInfo != null) |
| | | { |
| | | locationInfo = _basicService.LocationInfoService.GetLocation(instockInfo.LocationCode); |
| | | //if (locationInfo.MaxQty == 12) |
| | | //{ |
| | | // locationInfo.EnableStatus = EnableStatusEnum.OnlyOut.ObjToInt(); |
| | | // _basicService.LocationInfoService.Repository.UpdateData(locationInfo); |
| | | // locationInfo = null; |
| | | //} |
| | | if (locationInfo.EnableStatus == EnableStatusEnum.OnlyOut.ObjToInt()) locationInfo = null; |
| | | else |
| | | if (locationInfo.MaxQty <= locationInfo.CurrentQty) locationInfo = null; |
| | | } |
| | | #endregion |
| | | else |
| | | { |
| | | instockInfoDetail = _stockService.StockInfoDetailService.Get_StockInfoDetail(stockInfoDetail.OrderNo);//å
¥åºååå¨åºåï¼å¤æè´§ä½ |
| | | if (instockInfoDetail != null) instockInfo = _stockService.StockInfoService.Repository.GetStockInfo(instockInfoDetail.StockId); |
| | | if (instockInfo != null) |
| | | { |
| | | List<Dt_StockInfoDetail> stockInfoDetails = _stockService.StockInfoDetailService.Get_StockInfoDetails(stockInfoDetail.OrderNo);//è·å工忿已å
¥åºæå
¥åºä¸åºå |
| | | if (stockInfoDetails.GroupBy(x => x.BatchNo).Count() < 2) locationInfo.EnableStatus = EnableStatusEnum.OnlyOut.ObjToInt(); |
| | | else locationInfo = null; |
| | | Dt_LocationInfo? location = _basicService.LocationInfoService.GetLocation(instockInfo.LocationCode);//æ¥è¯¢å·²åå¨åºåè´§ä½ç¶æ |
| | | if (location?.Row == 1) |
| | | { |
| | | var newLocation = Db.Queryable<Dt_LocationInfo>().Where(x => x.Row == 2 && x.Layer == location.Layer && x.Column == location.Column).First(); |
| | | if (newLocation != null && newLocation.LocationStatus == LocationStatusEnum.Free.ObjToInt() && newLocation.CurrentQty == 0 && (newLocation.EnableStatus == EnableStatusEnum.OnlyIn.ObjToInt() || newLocation.EnableStatus == EnableStatusEnum.Normal.ObjToInt())) |
| | | { |
| | | locationInfo = newLocation; |
| | | } |
| | | } |
| | | } |
| | | } |
| | | if (locationInfo == null) |
| | | |
| | | if (locationInfo == null)//åé
æ°è´§ä½ |
| | | { |
| | | int inboundOrderCount = inboundOrder.Details.Count; |
| | | List<Dt_StockInfoDetail> stockInfoDetails = _stockService.StockInfoDetailService.Get_StockInfoDetails(stockInfoDetail.OrderNo);//è·å工忿已å
¥åºæå
¥åºä¸åºå |
| | |
| | | locationInfo = _basicService.LocationInfoService.AssignLocation(inboundOrderCount);//éæ°åé
è´§ä½ |
| | | } |
| | | } |
| | | |
| | | |
| | | if (locationInfo == null) throw new Exception($"æ å¯å
¥è´§ä½"); |
| | | |
| | | #region ä¿®æ¹åºååè´§ä½ä¿¡æ¯ |
| | |
| | | task.CurrentAddress = task.NextAddress; |
| | | task.NextAddress = locationInfo.LocationCode; |
| | | task.TargetAddress = task.NextAddress; |
| | | task.IsPickPlace = locationInfo.MaxQty - locationInfo.CurrentQty == 1; |
| | | string[] targetCodes = task.NextAddress.Split("-"); |
| | | var Row = Convert.ToInt16(targetCodes[0]); |
| | | task.TargetIsPickPlace = Row > 1 ? locationInfo.MaxQty - locationInfo.CurrentQty == 1 : false; |
| | | task.SourceIsPickPlace = false; |
| | | stockInfo.LocationCode = locationInfo.LocationCode; |
| | | stockInfo.StockStatus = StockStatusEmun.å
¥åºä¸.ObjToInt(); |
| | | stockInfoDetail.Status = StockStatusEmun.å
¥åºä¸.ObjToInt(); |
| | | locationInfo.CurrentQty++; |
| | | if (locationInfo.MaxQty == 12) locationInfo.EnableStatus = EnableStatusEnum.OnlyOut.ObjToInt(); |
| | | if (locationInfo.MaxQty < locationInfo.CurrentQty) throw new Exception(); |
| | | /*if (locationInfo.MaxQty == 12)*/ |
| | | locationInfo.EnableStatus = EnableStatusEnum.OnlyOut.ObjToInt(); |
| | | locationInfo.LocationStatus = LocationStatusEnum.Inbounding.ObjToInt(); |
| | | |
| | | Db.Ado.BeginTran(); |
| | |
| | | content.OK(data: new ReceiveWMSInfo() |
| | | { |
| | | TargetAddress = task.TargetAddress, |
| | | IsPickPlace = task.IsPickPlace, |
| | | SourceIsPickPlace = task.SourceIsPickPlace, |
| | | TargetIsPickPlace = task.TargetIsPickPlace, |
| | | }); |
| | | } |
| | | catch (Exception ex) |
| | |
| | | return content; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// è·å空æçå
¥åºè´§ä½ |
| | | /// </summary> |
| | | /// <param name="task"></param> |
| | | /// <returns></returns> |
| | | public WebResponseContent GetEmptyLocation(Dt_Task task) |
| | | { |
| | | try |
| | | { |
| | | Dt_StockInfo stockInfo = _stockService.StockInfoService.Repository.GetStockInfo(task.PalletCode); |
| | | if (stockInfo == null) throw new Exception($"æªæ¾å°æç[{task.PalletCode}]çç»çä¿¡æ¯"); |
| | | Dt_StockInfoDetail? stockInfoDetail = stockInfo.Details.Where(x => x.StockId == stockInfo.Id).FirstOrDefault(); |
| | | if (stockInfoDetail == null) throw new Exception($"æªæ¾å°æç[{task.PalletCode}]çç»ç详æ
"); |
| | | if (stockInfo.StockStatus != StockStatusEmun.å
¥åºç¡®è®¤.ObjToInt() || !string.IsNullOrEmpty(stockInfo.LocationCode)) |
| | | throw new Exception($"æç[{task.PalletCode}],该ç»çç¶æä¸å¯å
¥åº"); |
| | | Dt_StockInfo? instockInfo = null; |
| | | Dt_LocationInfo? locationInfo = null; |
| | | string CarChargingStation = AppSettings.Configuration[nameof(CarChargingStation)];//è·åç©¿æ¢è½¦å
çµä½ç½® |
| | | var ChargingStations = CarChargingStation.Split(","); |
| | | Dt_StockInfoDetail? instockInfoDetail = null; |
| | | var instockInfoDetails = _stockService.StockInfoDetailService.Repository.QueryData(x => x.MaterielCode == stockInfoDetail.MaterielCode && x.Status == StockStatusEmun.å
¥åºä¸.ObjToInt()); |
| | | if (instockInfoDetails.Count > 0) |
| | | instockInfoDetail = instockInfoDetails.OrderByDescending(x => x.CreateDate).First(); |
| | | if (instockInfoDetails.Count < 1) |
| | | { |
| | | instockInfoDetails = _stockService.StockInfoDetailService.Repository.QueryData(x => x.MaterielCode == stockInfoDetail.MaterielCode && x.Status == StockStatusEmun.å·²å
¥åº.ObjToInt()); |
| | | if (instockInfoDetails != null && instockInfoDetails.Count > 0) |
| | | instockInfoDetail = instockInfoDetails.OrderByDescending(x => x.CreateDate).First(); |
| | | } |
| | | if (instockInfoDetail != null) instockInfo = _stockService.StockInfoService.Repository.GetStockInfo(instockInfoDetail.StockId); |
| | | if (instockInfo != null)//æ åºå |
| | | { |
| | | locationInfo = _basicRepository.LocationInfoRepository.QueryFirst(x => x.LocationCode == instockInfo.LocationCode); |
| | | if (ChargingStations.Contains(locationInfo.LocationCode)) |
| | | { |
| | | if (locationInfo.MaxQty - locationInfo.CurrentQty <= 1) locationInfo = null; |
| | | } |
| | | else if (locationInfo.MaxQty - locationInfo.CurrentQty < 1) |
| | | { |
| | | locationInfo = null; |
| | | } |
| | | if (locationInfo == null) |
| | | { |
| | | locationInfo = _basicService.LocationInfoService.GetLocationPallet(); |
| | | } |
| | | } |
| | | else |
| | | { |
| | | locationInfo = _basicService.LocationInfoService.AssignLocation(ChargingStations);//æ¥æ¾ç©¿æ¢è½¦å
çµè´§ä½ |
| | | } |
| | | if (locationInfo == null) locationInfo = _basicService.LocationInfoService.AssignLocation(2);//éæ°åé
è´§ä½ |
| | | if (locationInfo == null) throw new Exception($"æ å¯å
¥è´§ä½"); |
| | | Dt_LocationInfo? locationInfo1 = null; |
| | | if (locationInfo.Row == 1) |
| | | { |
| | | locationInfo1 = _basicService.LocationInfoService.Repository.QueryFirst(x => x.Row == 2 && x.Layer == locationInfo.Layer && x.Column == locationInfo.Column); |
| | | locationInfo1.LocationStatus = LocationStatusEnum.Pallet.ObjToInt(); |
| | | } |
| | | |
| | | task.TaskState = (int)InTaskStatusEnum.SC_InExecuting; |
| | | task.CurrentAddress = task.NextAddress; |
| | | task.NextAddress = locationInfo.LocationCode; |
| | | task.TargetAddress = task.NextAddress; |
| | | task.TargetIsPickPlace = locationInfo.Row > 1 ? locationInfo.MaxQty - locationInfo.CurrentQty == 1 : false; |
| | | task.SourceIsPickPlace = false; |
| | | stockInfo.LocationCode = locationInfo.LocationCode; |
| | | stockInfo.StockStatus = StockStatusEmun.å
¥åºä¸.ObjToInt(); |
| | | stockInfoDetail.Status = StockStatusEmun.å
¥åºä¸.ObjToInt(); |
| | | locationInfo.CurrentQty++; |
| | | if (locationInfo.MaxQty < locationInfo.CurrentQty) throw new Exception(); |
| | | locationInfo.EnableStatus = EnableStatusEnum.OnlyOut.ObjToInt(); |
| | | locationInfo.LocationStatus = LocationStatusEnum.Inbounding.ObjToInt(); |
| | | |
| | | Db.Ado.BeginTran(); |
| | | UpdateData(task); |
| | | _stockService.StockInfoService.Repository.UpdateData(stockInfo); |
| | | _stockService.StockInfoDetailService.Repository.UpdateData(stockInfoDetail); |
| | | _basicService.LocationInfoService.Repository.UpdateData(locationInfo); |
| | | if (locationInfo1 != null) _basicService.LocationInfoService.Repository.UpdateData(locationInfo1); |
| | | Db.Ado.CommitTran(); |
| | | |
| | | return WebResponseContent.Instance.OK(data: new ReceiveWMSInfo() |
| | | { |
| | | TargetAddress = task.TargetAddress, |
| | | SourceIsPickPlace = task.SourceIsPickPlace, |
| | | TargetIsPickPlace = task.TargetIsPickPlace, |
| | | }); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | Db.Ado.RollbackTran(); |
| | | return WebResponseContent.Instance.Error(ex.Message); |
| | | } |
| | | } |
| | | } |
| | | } |