| | |
| | | using Microsoft.Extensions.Logging; |
| | | using Autofac.Core; |
| | | using MailKit.Search; |
| | | using Microsoft.Extensions.Logging; |
| | | using SqlSugar; |
| | | using SqlSugar.Extensions; |
| | | using System; |
| | |
| | | { |
| | | 1 => await AddAllocateOrder(allocateOrder), |
| | | 2 => await UpdateAllocateOrder(allocateOrder), |
| | | 3 => DeleteAllocateOrder(allocateOrder), |
| | | 3 => await DeleteAllocateOrder(allocateOrder), |
| | | |
| | | _ => WebResponseContent.Instance.OK(), |
| | | }; |
| | |
| | | } |
| | | allocateOrder.OrderNo = CreateCodeByRule(nameof(RuleCodeEnum.AllocateOrderCodeRule)); |
| | | Db.InsertNav(allocateOrder).Include(x => x.Details).ExecuteCommand(); |
| | | if (Enum.TryParse<BusinessTypeEnum>(allocateOrder.BusinessType, out var businessType)) |
| | | { |
| | | if (businessType == BusinessTypeEnum.æºä»è°å¤é¨ä»åº) |
| | | { |
| | | var inboundOrders = ConvertToInboundOrders(allocateOrder); |
| | | await _inboundService.InbounOrderService.ReceiveInboundOrder(inboundOrders, 1); |
| | | } |
| | | else if (businessType == BusinessTypeEnum.å¤é¨ä»åºè°æºä») |
| | | { |
| | | var outboundOrders = ConvertToOutboundOrders(allocateOrder); |
| | | await _outboundService.OutboundOrderService.ReceiveOutboundOrder(outboundOrders, 1); |
| | | } |
| | | else |
| | | { |
| | | // å¤çæªå®ä¹çæä¸¾å¼ï¼å¦æªæ¥æ°å¢ä½æªå®ç°çç±»åï¼ |
| | | throw new NotSupportedException($"䏿¯æçä¸å¡ç±»åæä¸¾å¼: {businessType}"); |
| | | } |
| | | } |
| | | await AddInOutData(allocateOrder); |
| | | return WebResponseContent.Instance.OK(); |
| | | } |
| | | catch (Exception ex) |
| | |
| | | return WebResponseContent.Instance.Error(ex.Message); |
| | | } |
| | | } |
| | | |
| | | private async Task AddInOutData(Dt_AllocateOrder allocateOrder) |
| | | { |
| | | if (Enum.TryParse<BusinessTypeEnum>(allocateOrder.BusinessType, out var businessType)) |
| | | { |
| | | if (businessType == BusinessTypeEnum.å¤é¨ä»åºè°æºä») |
| | | { |
| | | allocateOrder.OrderType = InOrderTypeEnum.AllocatInbound.ObjToInt(); |
| | | var inboundOrders = ConvertToInboundOrders(allocateOrder); |
| | | await _inboundService.InbounOrderService.ReceiveInboundOrder(inboundOrders, 1); |
| | | } |
| | | else if (businessType == BusinessTypeEnum.æºä»è°å¤é¨ä»åº || businessType == BusinessTypeEnum.æºä»è°æºä») |
| | | { |
| | | if (businessType == BusinessTypeEnum.æºä»è°å¤é¨ä»åº) |
| | | { |
| | | allocateOrder.OrderType = InOrderTypeEnum.AllocatOutbound.ObjToInt(); |
| | | } |
| | | else if (businessType == BusinessTypeEnum.æºä»è°æºä») |
| | | { |
| | | allocateOrder.OrderType = InOrderTypeEnum.InternalAllocat.ObjToInt(); |
| | | } |
| | | |
| | | var outboundOrders = ConvertToOutboundOrders(allocateOrder); |
| | | await _outboundService.OutboundOrderService.ReceiveOutboundOrder(outboundOrders, 1); |
| | | } |
| | | else |
| | | { |
| | | // å¤çæªå®ä¹çæä¸¾å¼ï¼å¦æªæ¥æ°å¢ä½æªå®ç°çç±»åï¼ |
| | | throw new NotSupportedException($"䏿¯æçä¸å¡ç±»åæä¸¾å¼: {businessType}"); |
| | | } |
| | | } |
| | | } |
| | | |
| | | public async Task<WebResponseContent> UpdateAllocateOrder(Dt_AllocateOrder model) |
| | | { |
| | | try |
| | |
| | | _unitOfWorkManage.BeginTran(); |
| | | foreach (var item in deletePurchaseOrderDetails) |
| | | { |
| | | // _allocateOrderDetailRepository.DeleteAndMoveIntoHty(item, OperateTypeEnum.èªå¨å é¤); |
| | | // _allocateOrderDetailRepository.DeleteAndMoveIntoHty(item, OperateTypeEnum.èªå¨å é¤); |
| | | _allocateOrderDetailRepository.DeleteData(item); |
| | | } |
| | | |
| | |
| | | _allocateOrderDetailRepository.AddData(allocateOrderDetails); |
| | | |
| | | BaseDal.UpdateData(allocateOrder); |
| | | |
| | | DeleteInOutData(model.UpperOrderNo, allocateOrder); |
| | | await AddInOutData(allocateOrder); |
| | | |
| | | _unitOfWorkManage.CommitTran(); |
| | | |
| | | |
| | |
| | | } |
| | | } |
| | | |
| | | public WebResponseContent DeleteAllocateOrder(Dt_AllocateOrder model) |
| | | public async Task<WebResponseContent> DeleteAllocateOrder(Dt_AllocateOrder model) |
| | | { |
| | | try |
| | | { |
| | |
| | | _allocateOrderDetailRepository.DeleteData(item); |
| | | } |
| | | BaseDal.DeleteData(allocateOrder); |
| | | |
| | | DeleteInOutData(model.UpperOrderNo, allocateOrder); |
| | | |
| | | _unitOfWorkManage.CommitTran(); |
| | | return WebResponseContent.Instance.OK(); |
| | | } |
| | |
| | | } |
| | | } |
| | | |
| | | private void DeleteInOutData(string upperOrderNo, Dt_AllocateOrder allocateOrder) |
| | | { |
| | | if (Enum.TryParse<BusinessTypeEnum>(allocateOrder.BusinessType, out var businessType)) |
| | | { |
| | | if (businessType == BusinessTypeEnum.å¤é¨ä»åºè°æºä») |
| | | { |
| | | _inboundService.InbounOrderService.Db.Deleteable<Dt_InboundOrder>().Where(x => x.UpperOrderNo == upperOrderNo).ExecuteCommand(); |
| | | |
| | | _inboundService.InboundOrderDetailService.Db.Deleteable<Dt_InboundOrderDetail>() |
| | | .Where(p => SqlFunc.Subqueryable<Dt_InboundOrder>().Where(s => s.Id == p.OrderId && s.UpperOrderNo == upperOrderNo).Any()).ExecuteCommand(); |
| | | } |
| | | else if (businessType == BusinessTypeEnum.æºä»è°å¤é¨ä»åº || businessType == BusinessTypeEnum.æºä»è°æºä») |
| | | { |
| | | _outboundService.OutboundOrderService.Db.Deleteable<Dt_OutboundOrder>().Where(x => x.UpperOrderNo == upperOrderNo).ExecuteCommand(); |
| | | _outboundService.OutboundOrderDetailService.Db.Deleteable<Dt_OutboundOrderDetail>() |
| | | .Where(p => SqlFunc.Subqueryable<Dt_OutboundOrder>().Where(s => s.Id == p.OrderId && s.UpperOrderNo == upperOrderNo).Any()).ExecuteCommand(); |
| | | } |
| | | } |
| | | } |
| | | |
| | | public List<Dt_InboundOrder> ConvertToInboundOrders(Dt_AllocateOrder allocateOrder) |
| | | { |
| | | var distinctDetails = allocateOrder.Details |
| | | .GroupBy(d => d.Barcode) |
| | | .Select(g => g.First()) |
| | | .ToList(); |
| | | |
| | | return new List<Dt_InboundOrder>() |
| | | { |
| | | new Dt_InboundOrder(){ |
| | |
| | | InboundOrderNo=allocateOrder.OrderNo, |
| | | UpperOrderNo=allocateOrder.UpperOrderNo, |
| | | SupplierId=allocateOrder.SupplierId, |
| | | OrderType=InOrderTypeEnum.Allocat.ObjToInt(), |
| | | OrderType= allocateOrder.OrderType , |
| | | OrderStatus=allocateOrder.OrderStatus, |
| | | CreateType=allocateOrder.CreateType, |
| | | BusinessType=allocateOrder.BusinessType, |
| | | IsBatch=allocateOrder.IsBatch, |
| | | FactoryArea=allocateOrder.FactoryArea, |
| | | Remark=allocateOrder.Remark, |
| | | Details=allocateOrder.Details.Select(detail=>new Dt_InboundOrderDetail |
| | | Details=distinctDetails.Select(detail=>new Dt_InboundOrderDetail |
| | | { |
| | | OrderId= detail.OrderId, |
| | | OrderId= 0, |
| | | MaterielCode=detail.MaterielCode, |
| | | MaterielName="", |
| | | BatchNo=detail.BatchNo, |
| | |
| | | OrderDetailStatus=detail.OrderDetailStatus, |
| | | Unit=detail.Unit, |
| | | RowNo=0, |
| | | lineNo=detail.LineNo, |
| | | SupplyCode=detail.SupplyCode, |
| | | WarehouseCode=detail.WarehouseCode, |
| | | Barcode=detail.Barcode, |
| | |
| | | |
| | | public Dt_OutboundOrder ConvertToOutboundOrders(Dt_AllocateOrder allocateOrder) |
| | | { |
| | | |
| | | var distinctDetails = allocateOrder.Details |
| | | .GroupBy(d => string.IsNullOrEmpty(d.Barcode) |
| | | ? $"{d.MaterielCode}_{d.BatchNo}_{d.SupplyCode}_{d.WarehouseCode}" |
| | | : d.Barcode) |
| | | .Select(g => new |
| | | { |
| | | Detail = g.First(), |
| | | //æ±æ»åç»å
çæ°é |
| | | Qty = g.Sum(x => x.BarcodeQty ?? x.OrderQuantity) |
| | | }).ToList(); |
| | | |
| | | return new Dt_OutboundOrder() |
| | | { |
| | | WarehouseId = allocateOrder.WarehouseId, |
| | | OrderNo = allocateOrder.OrderNo, |
| | | UpperOrderNo = allocateOrder.UpperOrderNo, |
| | | OrderType = OutOrderTypeEnum.Allocate.ObjToInt(), |
| | | OrderType = allocateOrder.OrderType, |
| | | OrderStatus = allocateOrder.OrderStatus, |
| | | CreateType = allocateOrder.CreateType, |
| | | BusinessType = allocateOrder.BusinessType, |
| | |
| | | Remark = allocateOrder.Remark, |
| | | DepartmentCode = "", |
| | | DepartmentName = "", |
| | | Details = allocateOrder.Details.Select(detail => new Dt_OutboundOrderDetail |
| | | Details = distinctDetails.Select(item => new Dt_OutboundOrderDetail |
| | | { |
| | | OrderId = detail.OrderId, |
| | | MaterielCode = detail.MaterielCode, |
| | | OrderId = 0, |
| | | MaterielCode = item.Detail.MaterielCode, |
| | | MaterielName = "", |
| | | BatchNo = detail.BatchNo, |
| | | OrderQuantity = detail.OrderQuantity, |
| | | BatchNo = item.Detail.BatchNo, |
| | | OrderQuantity = item.Detail.OrderQuantity, |
| | | BarcodeQty = (decimal)item.Detail.BarcodeQty, |
| | | BarcodeUnit = item.Detail.BarcodeUnit, |
| | | LockQuantity = 0, |
| | | lineNo = item.Detail.LineNo, |
| | | OverOutQuantity = 0, |
| | | OrderDetailStatus = detail.OrderDetailStatus, |
| | | Unit = detail.Unit, |
| | | OrderDetailStatus = item.Detail.OrderDetailStatus, |
| | | Unit = item.Detail.Unit, |
| | | RowNo = 0, |
| | | SupplyCode = detail.SupplyCode, |
| | | WarehouseCode = detail.WarehouseCode, |
| | | SupplyCode = item.Detail.SupplyCode, |
| | | WarehouseCode = item.Detail.WarehouseCode, |
| | | |
| | | }).ToList() |
| | | }; |