| | |
| | | using AutoMapper; |
| | | using System.Reflection.Emit; |
| | | using AutoMapper; |
| | | using Dm.filter; |
| | | using MailKit.Search; |
| | | using Mapster; |
| | |
| | | using Org.BouncyCastle.Asn1.Ocsp; |
| | | using Org.BouncyCastle.Crypto; |
| | | using SqlSugar; |
| | | using System.Reflection.Emit; |
| | | using WIDESEA_BasicService; |
| | | using WIDESEA_Common.CommonEnum; |
| | | using WIDESEA_Common.LocationEnum; |
| | |
| | | using WIDESEA_IRecordService; |
| | | using WIDESEA_IStockService; |
| | | using WIDESEA_Model.Models; |
| | | using static HslCommunication.Profinet.Knx.KnxCode; |
| | | |
| | | namespace WIDESEA_OutboundService |
| | | { |
| | |
| | | private readonly IRepository<Dt_Task> _taskRepository; |
| | | private readonly ILocationInfoService _locationInfoService; |
| | | private readonly IESSApiService _eSSApiService; |
| | | private readonly IRepository<Dt_AllocateOrder> _allocateOrderRepository; |
| | | private readonly IRepository<Dt_AllocateMaterialInfo> _allocateMaterialInfoRepository; |
| | | |
| | | private Dictionary<string, string> stations = new Dictionary<string, string> |
| | | { |
| | |
| | | {"3-1","3-5" }, |
| | | }; |
| | | |
| | | public OutboundService(IMapper mapper, IUnitOfWorkManage unitOfWorkManage, IRepository<Dt_OutboundOrderDetail> detailRepository, IRepository<Dt_OutboundOrder> outboundRepository, IRepository<Dt_OutStockLockInfo> outboundLockInfoRepository, IRepository<Dt_StockInfo> stockInfoRepository, IRepository<Dt_StockInfoDetail> stockDetailRepository, IRepository<Dt_StockQuantityChangeRecord> stockChangeRepository, IRepository<Dt_StockInfoDetail_Hty> stockDetailHistoryRepository, IBasicService basicService, IOutboundOrderDetailService outboundOrderDetailService, IOutboundOrderService outboundOrderService, IOutStockLockInfoService outboundStockLockInfoService, IFeedbackMesService feedbackMesService, IRepository<Dt_Task> taskRepository, ILocationInfoService locationInfoService, IESSApiService eSSApiService) |
| | | public OutboundService(IMapper mapper, IUnitOfWorkManage unitOfWorkManage, IRepository<Dt_OutboundOrderDetail> detailRepository, IRepository<Dt_OutboundOrder> outboundRepository, IRepository<Dt_OutStockLockInfo> outboundLockInfoRepository, IRepository<Dt_StockInfo> stockInfoRepository, IRepository<Dt_StockInfoDetail> stockDetailRepository, IRepository<Dt_StockQuantityChangeRecord> stockChangeRepository, IRepository<Dt_StockInfoDetail_Hty> stockDetailHistoryRepository, IBasicService basicService, IOutboundOrderDetailService outboundOrderDetailService, IOutboundOrderService outboundOrderService, IOutStockLockInfoService outboundStockLockInfoService, IFeedbackMesService feedbackMesService, IRepository<Dt_Task> taskRepository, ILocationInfoService locationInfoService, IESSApiService eSSApiService, IRepository<Dt_AllocateOrder> allocateOrderRepository, IRepository<Dt_AllocateMaterialInfo> allocateMaterialInfoRepository) |
| | | { |
| | | _mapper = mapper; |
| | | _unitOfWorkManage = unitOfWorkManage; |
| | |
| | | _taskRepository = taskRepository; |
| | | _locationInfoService = locationInfoService; |
| | | _eSSApiService = eSSApiService; |
| | | _allocateOrderRepository = allocateOrderRepository; |
| | | _allocateMaterialInfoRepository = allocateMaterialInfoRepository; |
| | | } |
| | | |
| | | #region åºåºåé
|
| | |
| | | |
| | | if (outboundOrder.IsBatch == 1) |
| | | { |
| | | selectedDetails = _detailRepository.QueryData(x => x.WarehouseCode == selectedDetails.First().WarehouseCode && x.MaterielCode == selectedDetails.First().MaterielCode && x.BatchNo == selectedDetails.First().BatchNo && x.SupplyCode == selectedDetails.First().SupplyCode); |
| | | selectedDetails = _detailRepository.QueryData(x => x.OrderId == selectedDetails.First().OrderId && x.WarehouseCode == selectedDetails.First().WarehouseCode && x.MaterielCode == selectedDetails.First().MaterielCode && x.BatchNo == selectedDetails.First().BatchNo && x.SupplyCode == selectedDetails.First().SupplyCode); |
| | | } |
| | | |
| | | |
| | |
| | | } |
| | | #endregion |
| | | |
| | | |
| | | |
| | | #region æ´ç®±åºåº |
| | | public WebResponseContent CompleteOutboundWithPallet(OutboundCompletePalletRequestDTO request) |
| | | { |
| | | WebResponseContent content = WebResponseContent.Instance; |
| | |
| | | // æ´ç®±åºåºæ éæå
|
| | | PerformFullOutboundOperation(stockInfo, request, lockInfo.TaskNum.GetValueOrDefault()); |
| | | |
| | | if (outboundOrder.OrderType != 0) |
| | | { |
| | | |
| | | Dt_AllocateOrder allocateOrder = _allocateOrderRepository.QueryFirst(x => x.OrderNo == outboundOrder.OrderNo); |
| | | if (allocateOrder != null) |
| | | { |
| | | List<Dt_AllocateMaterialInfo> allocateMaterialInfos = new List<Dt_AllocateMaterialInfo>(); |
| | | foreach (var item in stockInfo.Details) |
| | | { |
| | | Dt_AllocateMaterialInfo allocateMaterialInfo = new Dt_AllocateMaterialInfo() |
| | | { |
| | | Barcode = item.Barcode, |
| | | BatchNo = item.BatchNo, |
| | | FactoryArea = item.FactoryArea, |
| | | MaterialCode = item.MaterielCode, |
| | | MaterialName = item.MaterielName, |
| | | OrderId = outboundOrder.Id, |
| | | OrderNo = outboundOrder.OrderNo, |
| | | Quantity = item.StockQuantity, |
| | | SupplyCode = item.SupplyCode, |
| | | Unit = item.Unit, |
| | | WarehouseCode = allocateOrder.ToWarehouse |
| | | }; |
| | | allocateMaterialInfos.Add(allocateMaterialInfo); |
| | | } |
| | | _allocateMaterialInfoRepository.AddData(allocateMaterialInfos); |
| | | } |
| | | } |
| | | |
| | | decimal allocatedQuantity = actualOutboundQuantity; |
| | | List<Dt_OutboundOrderDetail> updateDetails = new(); |
| | |
| | | _stockDetailRepository.DeleteData(stockInfo.Details); |
| | | _stockChangeRepository.AddData(changeRecords); |
| | | } |
| | | #endregion |
| | | |
| | | #region æ£é |
| | | /// <summary> |
| | |
| | | // 8. 夿æ¯å¦éè¦æå
ï¼å½åºåºæ°éå°äºåºåæ°éæ¶éè¦æå
ï¼ |
| | | bool isUnpacked = actualOutboundQuantity < stockDetail.StockQuantity; |
| | | List<MaterialCodeReturnDTO> returnDTOs = new List<MaterialCodeReturnDTO>(); |
| | | |
| | | string newBarcode = string.Empty; |
| | | // 9. å¼å¯äºå¡ |
| | | _unitOfWorkManage.BeginTran(); |
| | | try |
| | | { |
| | | decimal beforeQuantity = stockDetail.StockQuantity; // åå§åºåé |
| | | |
| | | Dt_AllocateMaterialInfo allocateMaterialInfo = new Dt_AllocateMaterialInfo(); |
| | | |
| | | // æ ¹æ®æ¯å¦æå
æ§è¡ä¸åçæä½ |
| | | if (isUnpacked) |
| | | { |
| | | returnDTOs = PerformUnpackOperation(stockDetail, stockInfo, actualOutboundQuantity, request, beforeQuantity, lockInfo.TaskNum.GetValueOrDefault()); |
| | | (string NewBarcode, List<MaterialCodeReturnDTO> MaterialCodeReturnDTOs) result = PerformUnpackOperation(stockDetail, stockInfo, actualOutboundQuantity, request, beforeQuantity, lockInfo.TaskNum.GetValueOrDefault(), outboundOrder.Id, outboundOrder.OrderNo); |
| | | |
| | | returnDTOs = result.MaterialCodeReturnDTOs; |
| | | newBarcode = result.NewBarcode; |
| | | |
| | | MaterialCodeReturnDTO returnDTO = returnDTOs.First(x => x.Barcode == newBarcode); |
| | | |
| | | if (outboundOrder.OrderType != 0) |
| | | { |
| | | allocateMaterialInfo = new Dt_AllocateMaterialInfo() |
| | | { |
| | | Barcode = returnDTO.Barcode, |
| | | BatchNo = returnDTO.BatchNo, |
| | | FactoryArea = returnDTO.FactoryArea, |
| | | MaterialCode = returnDTO.MaterialCode, |
| | | MaterialName = returnDTO.MaterialName, |
| | | OrderId = outboundOrder.Id, |
| | | OrderNo = outboundOrder.OrderNo, |
| | | Quantity = returnDTO.Quantity, |
| | | SupplyCode = returnDTO.SuplierCode, |
| | | Unit = stockDetail.Unit |
| | | }; |
| | | } |
| | | |
| | | } |
| | | else |
| | | { |
| | | PerformFullOutboundOperation(stockDetail, stockInfo, actualOutboundQuantity, request, beforeQuantity, lockInfo.TaskNum.GetValueOrDefault()); |
| | | |
| | | if (outboundOrder.OrderType != 0) |
| | | { |
| | | allocateMaterialInfo = new Dt_AllocateMaterialInfo() |
| | | { |
| | | Barcode = stockDetail.Barcode, |
| | | BatchNo = stockDetail.BatchNo, |
| | | FactoryArea = stockDetail.FactoryArea, |
| | | MaterialCode = stockDetail.MaterielCode, |
| | | MaterialName = stockDetail.MaterielName, |
| | | OrderId = outboundOrder.Id, |
| | | OrderNo = outboundOrder.OrderNo, |
| | | Quantity = stockDetail.StockQuantity, |
| | | SupplyCode = stockDetail.SupplyCode, |
| | | Unit = stockDetail.Unit |
| | | }; |
| | | } |
| | | |
| | | } |
| | | |
| | | // 夿æ¯å¦æ¯è°æ¨å |
| | | if (outboundOrder.OrderType != 0) |
| | | { |
| | | Dt_AllocateOrder allocateOrder = _allocateOrderRepository.QueryFirst(x => x.OrderNo == outboundOrder.OrderNo); |
| | | if (allocateOrder != null) |
| | | { |
| | | allocateMaterialInfo.WarehouseCode = allocateOrder.ToWarehouse; |
| | | |
| | | _allocateMaterialInfoRepository.AddData(allocateMaterialInfo); |
| | | } |
| | | } |
| | | |
| | | decimal allocatedQuantity = actualOutboundQuantity; |
| | |
| | | response.ScannedDetail = scannedDetail; |
| | | response.UpdatedDetails = updateDetails; |
| | | |
| | | if (!string.IsNullOrEmpty(newBarcode)) |
| | | { |
| | | // ç©ææ°æ¡ç åä¼ |
| | | _feedbackMesService.BarcodeFeedback(newBarcode); |
| | | } |
| | | |
| | | // æ£æ¥åºåºåæ¯å¦å®æ |
| | | if (CheckOutboundOrderCompleted(request.OrderNo)) |
| | | { |
| | |
| | | /// <param name="beforeQuantity"></param> |
| | | /// <param name="taskNum"></param> |
| | | /// <returns></returns> |
| | | private List<MaterialCodeReturnDTO> PerformUnpackOperation(Dt_StockInfoDetail stockDetail, Dt_StockInfo stockInfo, |
| | | decimal actualOutboundQuantity, OutboundCompleteRequestDTO request, decimal beforeQuantity, int taskNum) |
| | | private (string NewBarcode, List<MaterialCodeReturnDTO> MaterialCodeReturnDTOs) PerformUnpackOperation(Dt_StockInfoDetail stockDetail, Dt_StockInfo stockInfo, |
| | | decimal actualOutboundQuantity, OutboundCompleteRequestDTO request, decimal beforeQuantity, int taskNum, int orderId, string orderNo) |
| | | { |
| | | string newBarcode = GenerateNewBarcode(); |
| | | |
| | | string remark = $"æå
è®°å½ï¼åæ¡ç ï¼{request.Barcode}ï¼åæ°éï¼{stockDetail.StockQuantity}ï¼åºåºæ¡ç ï¼{newBarcode}ï¼ åºåºæ°éï¼{actualOutboundQuantity}ï¼ååºæ¡ç ï¼{request.Barcode}ï¼ååºæ°éï¼{stockDetail.StockQuantity - actualOutboundQuantity},æä½è
ï¼{request.Operator}"; |
| | | |
| | | List<Dt_MaterialCodeInfo> materialCodeInfos = CreateMaterialCodeInfos(stockDetail, newBarcode, actualOutboundQuantity, remark); |
| | | List<Dt_MaterialCodeInfo> materialCodeInfos = CreateMaterialCodeInfos(stockDetail, newBarcode, actualOutboundQuantity, remark, taskNum, orderId, orderNo); |
| | | |
| | | List<MaterialCodeReturnDTO> returnDTOs = _mapper.Map<List<MaterialCodeReturnDTO>>(materialCodeInfos); |
| | | |
| | |
| | | Unit = stockDetail.Unit, |
| | | InboundOrderRowNo = stockDetail.InboundOrderRowNo, |
| | | SupplyCode = stockDetail.SupplyCode, |
| | | Creater = stockDetail.Creater, |
| | | CreateDate = stockDetail.CreateDate, |
| | | FactoryArea = stockDetail.FactoryArea, |
| | | WarehouseCode = stockDetail.WarehouseCode, |
| | | Remark = $"æå
ååå§è®°å½ï¼åæ¡ç ï¼{request.Barcode}ï¼åæ°éï¼{stockDetail.StockQuantity}ï¼åºåºæ°éï¼{actualOutboundQuantity}ï¼æä½è
ï¼{request.Operator}" |
| | | Remark = $"æå
ååå§è®°å½ï¼åºåºåå·ï¼{orderNo}ï¼åºåºå主é®ï¼{orderId}ï¼åæ¡ç ï¼{request.Barcode}ï¼åæ°éï¼{stockDetail.StockQuantity}ï¼åºåºæ°éï¼{actualOutboundQuantity}ï¼æä½è
ï¼{request.Operator}" |
| | | }; |
| | | _stockDetailHistoryRepository.AddData(originalHistoryRecord); |
| | | |
| | |
| | | // æ´æ°ååºåæç» |
| | | stockDetail.StockQuantity = remainingQuantity; |
| | | //stockDetail.Barcode = newBarcode; |
| | | stockDetail.Remark = $"æå
åæ´æ°ï¼åæ¡ç ï¼{request.Barcode}ï¼æ°æ°éï¼{remainingQuantity}ï¼æä½è
ï¼{request.Operator}"; |
| | | stockDetail.Remark = $"æå
åæ´æ°ï¼åºåºåå·ï¼{orderNo}ï¼åºåºå主é®ï¼{orderId}ï¼åæ¡ç ï¼{request.Barcode}ï¼æ°æ°éï¼{remainingQuantity}ï¼æä½è
ï¼{request.Operator}"; |
| | | _stockDetailRepository.UpdateData(stockDetail); |
| | | } |
| | | |
| | |
| | | AfterQuantity = beforeQuantity - actualOutboundQuantity, |
| | | SupplyCode = stockDetail.SupplyCode, |
| | | WarehouseCode = stockDetail.WarehouseCode, |
| | | Remark = $"æå
åºåºï¼åæ¡ç ï¼{request.Barcode}ï¼æ°æ¡ç ï¼{newBarcode}ï¼åºåºæ°éï¼{actualOutboundQuantity}ï¼å©ä½ï¼{remainingQuantity}ï¼æä½è
ï¼{request.Operator}" |
| | | Remark = $"æå
åºåºï¼åºåºåå·ï¼{orderNo}ï¼åºåºå主é®ï¼{orderId}ï¼åæ¡ç ï¼{request.Barcode}ï¼æ°æ¡ç ï¼{newBarcode}ï¼åºåºæ°éï¼{actualOutboundQuantity}ï¼å©ä½ï¼{remainingQuantity}ï¼æä½è
ï¼{request.Operator}" |
| | | }; |
| | | _stockChangeRepository.AddData(unpackChangeRecord); |
| | | |
| | | return returnDTOs; |
| | | return (newBarcode, returnDTOs); |
| | | } |
| | | |
| | | /// <summary> |
| | |
| | | InboundOrderRowNo = stockDetail.InboundOrderRowNo, |
| | | SupplyCode = stockDetail.SupplyCode, |
| | | FactoryArea = stockDetail.FactoryArea, |
| | | Creater = stockDetail.Creater, |
| | | CreateDate = stockDetail.CreateDate, |
| | | WarehouseCode = stockDetail.WarehouseCode, |
| | | Remark = $"åºåºå®æå é¤ï¼æ¡ç ï¼{request.Barcode}ï¼åæ°éï¼{stockDetail.StockQuantity}ï¼åºåºæ°éï¼{actualOutboundQuantity}ï¼æä½è
ï¼{request.Operator}" |
| | | }; |
| | |
| | | /// <param name="afterQuantity"></param> |
| | | /// <param name="remark"></param> |
| | | /// <returns></returns> |
| | | private List<Dt_MaterialCodeInfo> CreateMaterialCodeInfos(Dt_StockInfoDetail stockDetail, string newBarcode, decimal splitQuantity, string remark) |
| | | private List<Dt_MaterialCodeInfo> CreateMaterialCodeInfos(Dt_StockInfoDetail stockDetail, string newBarcode, decimal splitQuantity, string remark, int taskNum, int orderId, string orderNo) |
| | | { |
| | | List<Dt_MaterialCodeInfo> materialCodeInfos = new List<Dt_MaterialCodeInfo>(); |
| | | |
| | |
| | | SuplierCode = stockDetail.SupplyCode, |
| | | Unit = stockDetail.Unit, |
| | | Date = DateTime.Now.ToString("yyyy-MM-dd"), |
| | | Remark = remark |
| | | Remark = remark, |
| | | WarehouseCode = stockDetail.WarehouseCode, |
| | | OrderNo = orderNo, |
| | | OrderId = orderId, |
| | | ReturnStatus = 0 |
| | | }; |
| | | materialCodeInfos.Add(outMaterialCodeInfo); |
| | | |
| | |
| | | SuplierCode = stockDetail.SupplyCode, |
| | | Unit = stockDetail.Unit, |
| | | Date = DateTime.Now.ToString("yyyy-MM-dd"), |
| | | Remark = remark |
| | | Remark = remark, |
| | | WarehouseCode = stockDetail.WarehouseCode, |
| | | OrderNo = orderNo, |
| | | OrderId = orderId, |
| | | ReturnStatus = 0 |
| | | }; |
| | | |
| | | materialCodeInfos.Add(returnMaterialCodeInfo); |
| | |
| | | WebResponseContent content = new WebResponseContent(); |
| | | try |
| | | { |
| | | var stock = await _stockInfoRepository.Db.Queryable<Dt_StockInfo>().Includes(x=>x.Details).Where(x => x.PalletCode == palletCode).FirstAsync(); |
| | | var stock = await _stockInfoRepository.Db.Queryable<Dt_StockInfo>().Includes(x => x.Details).Where(x => x.PalletCode == palletCode).FirstAsync(); |
| | | |
| | | if (stock == null) |
| | | { |
| | |
| | | stockInfo_Hty.SourceId = stock.Id; |
| | | stockInfo_Hty.OperateType = "å空箱"; |
| | | stockInfo_Hty.InsertTime = DateTime.Now; |
| | | |
| | | |
| | | _unitOfWorkManage.BeginTran(); |
| | | await _outboundRepository.Db.InsertNav(stockInfo_Hty).IncludesAllFirstLayer().ExecuteCommandAsync(); |
| | | await _stockInfoRepository.DeleteDataByIdAsync(stock.Id); |
| | |
| | | |
| | | #endregion |
| | | |
| | | #region |
| | | #region ååº |
| | | public async Task<WebResponseContent> ReturnToWarehouse(string palletCode, string OrderNo, string station) |
| | | { |
| | | WebResponseContent content = new WebResponseContent(); |
| | |
| | | { |
| | | stock.PalletType = (int)PalletTypeEnum.Empty; |
| | | stock.StockStatus = (int)StockStatusEmun.ç»çæå; |
| | | stock.LocationCode = ""; |
| | | } |
| | | else if (stock.Details.Count > 0) |
| | | { |
| | |
| | | { |
| | | return content.Error($"æç{palletCode}åºåæªæ£éå®ä¸å
许ååº"); |
| | | } |
| | | stock.StockStatus = (int)StockStatusEmun.ç»çæå; |
| | | stock.LocationCode = ""; |
| | | } |
| | | |
| | | var task = await _taskRepository.Db.Queryable<Dt_Task>() |
| | |
| | | SourceAddress = stations[station], |
| | | TargetAddress = newLocation.LocationCode, |
| | | TaskStatus = (int)TaskStatusEnum.New, |
| | | TaskType = stock.Details.Count > 0 ? (int)TaskTypeEnum.InPick : (int)TaskTypeEnum.OutEmpty, |
| | | TaskType = stock.Details.Count > 0 ? (int)TaskTypeEnum.InPick : (int)TaskTypeEnum.InEmpty, |
| | | PalletType = stock.PalletType, |
| | | WarehouseId = stock.WarehouseId |
| | | }; |
| | | |
| | | _stockInfoRepository.UpdateData(stock); |
| | | _taskRepository.AddData(newTask); |
| | | |
| | | var moveResult = await _eSSApiService.MoveContainerAsync(new MoveContainerRequest |
| | | { |
| | | slotCode = movestations[station], |
| | | containerCode = palletCode |
| | | }); |
| | | //var moveResult = await _eSSApiService.MoveContainerAsync(new MoveContainerRequest |
| | | //{ |
| | | // slotCode = movestations[station], |
| | | // containerCode = palletCode |
| | | //}); |
| | | return content.OK(); |
| | | |
| | | } |