| | |
| | | using SqlSugar; |
| | | using Autofac.Core; |
| | | using MailKit.Search; |
| | | using Microsoft.Extensions.Logging; |
| | | using SqlSugar; |
| | | using SqlSugar.Extensions; |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.Linq; |
| | | using System.Text; |
| | | using System.Threading.Tasks; |
| | | using WIDESEA_Common.AllocateEnum; |
| | | using WIDESEA_Common.OrderEnum; |
| | | using WIDESEA_Core; |
| | | using WIDESEA_Core.BaseRepository; |
| | | using WIDESEA_Core.BaseServices; |
| | |
| | | public readonly IOutboundService _outboundService; |
| | | public readonly IRepository<Dt_AllocateOrder> _allocateOrderRepository; |
| | | public readonly IRepository<Dt_AllocateOrderDetail> _allocateOrderDetailRepository; |
| | | public AllocateService(IRepository<Dt_AllocateOrder> BaseDal, |
| | | |
| | | private readonly ILogger<AllocateService> _logger; |
| | | public AllocateService(IRepository<Dt_AllocateOrder> BaseDal, |
| | | IUnitOfWorkManage unitOfWorkManage, |
| | | IInboundService inboundService, |
| | | IOutboundService outboundService, |
| | | IRepository<Dt_AllocateOrder> allocateOrderRepository, |
| | | IRepository<Dt_AllocateOrderDetail> allocateOrderDetailRepository) : base(BaseDal) |
| | | IRepository<Dt_AllocateOrderDetail> allocateOrderDetailRepository, |
| | | ILogger<AllocateService> logger) : base(BaseDal) |
| | | { |
| | | _unitOfWorkManage = unitOfWorkManage; |
| | | _inboundService = inboundService; |
| | | _outboundService = outboundService; |
| | | _allocateOrderRepository = allocateOrderRepository; |
| | | _allocateOrderDetailRepository = allocateOrderDetailRepository; |
| | | _logger = logger; |
| | | } |
| | | |
| | | public IRepository<Dt_AllocateOrder> Repository => BaseDal; |
| | | |
| | | |
| | | public WebResponseContent ReceiveAllocateOrder(Dt_AllocateOrder allocateOrder, int operateType) |
| | | public async Task<WebResponseContent> ReceiveAllocateOrder(Dt_AllocateOrder allocateOrder, int operateType) |
| | | { |
| | | try |
| | | { |
| | | return operateType switch |
| | | { |
| | | 1 => AddInboundOrder(allocateOrder), |
| | | 2 => UpdateInboundOrder(allocateOrder), |
| | | 3 => DeleteInboundOrder(allocateOrder), |
| | | 1 => await AddAllocateOrder(allocateOrder), |
| | | 2 => await UpdateAllocateOrder(allocateOrder), |
| | | 3 => await DeleteAllocateOrder(allocateOrder), |
| | | |
| | | _ => WebResponseContent.Instance.OK(), |
| | | }; |
| | |
| | | } |
| | | } |
| | | |
| | | public WebResponseContent AddInboundOrder(Dt_AllocateOrder allocateOrder) |
| | | public async Task<WebResponseContent> AddAllocateOrder(Dt_AllocateOrder allocateOrder) |
| | | { |
| | | try |
| | | { |
| | |
| | | } |
| | | allocateOrder.OrderNo = CreateCodeByRule(nameof(RuleCodeEnum.AllocateOrderCodeRule)); |
| | | Db.InsertNav(allocateOrder).Include(x => x.Details).ExecuteCommand(); |
| | | if (Enum.TryParse<BusinessTypeEnum>(allocateOrder.BusinessType, out var businessType)) |
| | | await AddInOutData(allocateOrder); |
| | | return WebResponseContent.Instance.OK(); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | _logger.LogInformation("AllocateService AddAllocateOrder err: " + ex.Message); |
| | | 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.å¤é¨ä»åºè°æºä») |
| | | { |
| | | if (businessType == BusinessTypeEnum.å¤é¨ä»åºè°æºä») |
| | | allocateOrder.OrderType = InOrderTypeEnum.Allocat.ObjToInt(); |
| | | var inboundOrders = ConvertToInboundOrders(allocateOrder); |
| | | await _inboundService.InbounOrderService.ReceiveInboundOrder(inboundOrders, 1); |
| | | } |
| | | else if (businessType == BusinessTypeEnum.æºä»è°å¤é¨ä»åº || businessType == BusinessTypeEnum.æºä»è°æºä») |
| | | { |
| | | if (businessType == BusinessTypeEnum.æºä»è°å¤é¨ä»åº) |
| | | { |
| | | var inboundOrders = ConvertToInboundOrders(allocateOrder); |
| | | _inboundService.InbounOrderService.ReceiveInboundOrder(inboundOrders, 1); |
| | | allocateOrder.OrderType = InOrderTypeEnum.Allocat.ObjToInt(); |
| | | } |
| | | else if (businessType == BusinessTypeEnum.æºä»è°å¤é¨ä»åº) |
| | | else if (businessType == BusinessTypeEnum.æºä»è°æºä») |
| | | { |
| | | var outboundOrders = ConvertToOutboundOrders(allocateOrder); |
| | | _outboundService.OutboundOrderService.ReceiveOutboundOrder(outboundOrders, 1); |
| | | 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 |
| | | { |
| | | var allocateOrder = Db.Queryable<Dt_AllocateOrder>().Where(x => x.UpperOrderNo == model.UpperOrderNo).Includes(x => x.Details).First(); |
| | | if (allocateOrder == null) |
| | | { |
| | | return WebResponseContent.Instance.Error($"æªæ¾å°è°æ¨åä¿¡æ¯"); |
| | | } |
| | | if (allocateOrder.Details == null || allocateOrder.Details.Count == 0) |
| | | { |
| | | return WebResponseContent.Instance.Error($"æªæ¾å°è°æ¨åæç»ä¿¡æ¯"); |
| | | } |
| | | List<Dt_AllocateOrderDetail> allocateOrderDetails = new List<Dt_AllocateOrderDetail>(); |
| | | List<Dt_AllocateOrderDetail> updateAllocateOrderDetails = new List<Dt_AllocateOrderDetail>(); |
| | | List<int> detailIds = new List<int>(); |
| | | foreach (var item in model.Details) |
| | | { |
| | | if (string.IsNullOrEmpty(item.Barcode)) |
| | | { |
| | | |
| | | } |
| | | else |
| | | { |
| | | // å¤çæªå®ä¹çæä¸¾å¼ï¼å¦æªæ¥æ°å¢ä½æªå®ç°çç±»åï¼ |
| | | throw new NotSupportedException($"䏿¯æçä¸å¡ç±»åæä¸¾å¼: {businessType}"); |
| | | } |
| | | } |
| | | return WebResponseContent.Instance.OK(); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | return WebResponseContent.Instance.Error(ex.Message); |
| | | } |
| | | } |
| | | public WebResponseContent UpdateInboundOrder(Dt_AllocateOrder model) |
| | | { |
| | | try |
| | | { |
| | | var allocateOrder = Db.Queryable<Dt_AllocateOrder>().Where(x => x.UpperOrderNo == model.UpperOrderNo).Includes(x => x.Details).First(); |
| | | if (allocateOrder == null) |
| | | { |
| | | return WebResponseContent.Instance.Error($"æªæ¾å°è°æ¨åä¿¡æ¯"); |
| | | } |
| | | if (allocateOrder.Details == null || allocateOrder.Details.Count == 0) |
| | | { |
| | | return WebResponseContent.Instance.Error($"æªæ¾å°è°æ¨åæç»ä¿¡æ¯"); |
| | | } |
| | | List<Dt_AllocateOrderDetail> allocateOrderDetails = new List<Dt_AllocateOrderDetail>(); |
| | | List<Dt_AllocateOrderDetail> updateAllocateOrderDetails = new List<Dt_AllocateOrderDetail>(); |
| | | List<int> detailIds = new List<int>(); |
| | | foreach (var item in model.Details) |
| | | { |
| | | if (string.IsNullOrEmpty(item.Barcode)) |
| | | Dt_AllocateOrderDetail? allocateOrderDetail = allocateOrder.Details.FirstOrDefault(x => x.Barcode == item.Barcode); |
| | | if (allocateOrderDetail == null) |
| | | { |
| | | |
| | | allocateOrderDetail = new Dt_AllocateOrderDetail() |
| | | { |
| | | OrderId = allocateOrder.Id, |
| | | MaterielCode = item.MaterielCode, |
| | | LineNo = item.LineNo, |
| | | BatchNo = item.BatchNo, |
| | | Unit = item.Unit, |
| | | WarehouseCode = item.WarehouseCode, |
| | | Barcode = item.Barcode, |
| | | BarcodeUnit = item.BarcodeUnit, |
| | | BarcodeQty = (decimal)item.BarcodeQty, |
| | | OrderQuantity = item.OrderQuantity |
| | | }; |
| | | allocateOrderDetails.Add(allocateOrderDetail); |
| | | } |
| | | else |
| | | { |
| | | Dt_AllocateOrderDetail? allocateOrderDetail = allocateOrder.Details.FirstOrDefault(x => x.Barcode == item.Barcode); |
| | | if (allocateOrderDetail == null) |
| | | { |
| | | allocateOrderDetail = new Dt_AllocateOrderDetail() |
| | | { |
| | | OrderId = allocateOrder.Id, |
| | | MaterielCode = item.MaterielCode, |
| | | LineNo= item.LineNo, |
| | | BatchNo = item.BatchNo, |
| | | Unit = item.Unit, |
| | | WarehouseCode = item.WarehouseCode, |
| | | Barcode = item.Barcode, |
| | | BarcodeUnit = item.BarcodeUnit, |
| | | BarcodeQty = (decimal)item.BarcodeQty, |
| | | OrderQuantity = item.OrderQuantity |
| | | }; |
| | | allocateOrderDetails.Add(allocateOrderDetail); |
| | | } |
| | | else |
| | | { |
| | | allocateOrderDetail.LineNo = item.LineNo; |
| | | allocateOrderDetail.MaterielCode = item.MaterielCode; |
| | | allocateOrderDetail.BatchNo = item.BatchNo; |
| | | allocateOrderDetail.Unit = item.Unit; |
| | | allocateOrderDetail.WarehouseCode = item.WarehouseCode; |
| | | allocateOrderDetail.Barcode = item.Barcode; |
| | | allocateOrderDetail.BarcodeUnit = item.BarcodeUnit; |
| | | allocateOrderDetail.BarcodeQty = item.BarcodeQty; |
| | | allocateOrderDetail.OrderQuantity = item.OrderQuantity; |
| | | allocateOrderDetail.LineNo = item.LineNo; |
| | | allocateOrderDetail.MaterielCode = item.MaterielCode; |
| | | allocateOrderDetail.BatchNo = item.BatchNo; |
| | | allocateOrderDetail.Unit = item.Unit; |
| | | allocateOrderDetail.WarehouseCode = item.WarehouseCode; |
| | | allocateOrderDetail.Barcode = item.Barcode; |
| | | allocateOrderDetail.BarcodeUnit = item.BarcodeUnit; |
| | | allocateOrderDetail.BarcodeQty = item.BarcodeQty; |
| | | allocateOrderDetail.OrderQuantity = item.OrderQuantity; |
| | | |
| | | |
| | | updateAllocateOrderDetails.Add(allocateOrderDetail); |
| | | detailIds.Add(allocateOrderDetail.Id); |
| | | } |
| | | updateAllocateOrderDetails.Add(allocateOrderDetail); |
| | | detailIds.Add(allocateOrderDetail.Id); |
| | | } |
| | | } |
| | | } |
| | | |
| | | allocateOrder.UpperOrderNo = model.UpperOrderNo; |
| | | allocateOrder.BusinessType = model.BusinessType; |
| | | allocateOrder.IsBatch = model.IsBatch; |
| | | allocateOrder.FactoryArea = model.FactoryArea; |
| | | allocateOrder.UpperOrderNo = model.UpperOrderNo; |
| | | allocateOrder.BusinessType = model.BusinessType; |
| | | allocateOrder.IsBatch = model.IsBatch; |
| | | allocateOrder.FactoryArea = model.FactoryArea; |
| | | |
| | | List<Dt_AllocateOrderDetail> deletePurchaseOrderDetails = allocateOrder.Details.Where(x => !detailIds.Contains(x.Id)).ToList(); |
| | | List<Dt_AllocateOrderDetail> deletePurchaseOrderDetails = allocateOrder.Details.Where(x => !detailIds.Contains(x.Id)).ToList(); |
| | | |
| | | _unitOfWorkManage.BeginTran(); |
| | | foreach (var item in deletePurchaseOrderDetails) |
| | | { |
| | | _allocateOrderDetailRepository.DeleteAndMoveIntoHty(item, OperateTypeEnum.èªå¨å é¤); |
| | | } |
| | | _unitOfWorkManage.BeginTran(); |
| | | foreach (var item in deletePurchaseOrderDetails) |
| | | { |
| | | // _allocateOrderDetailRepository.DeleteAndMoveIntoHty(item, OperateTypeEnum.èªå¨å é¤); |
| | | _allocateOrderDetailRepository.DeleteData(item); |
| | | } |
| | | |
| | | _allocateOrderDetailRepository.UpdateData(updateAllocateOrderDetails); |
| | | _allocateOrderDetailRepository.AddData(allocateOrderDetails); |
| | | _allocateOrderDetailRepository.UpdateData(updateAllocateOrderDetails); |
| | | _allocateOrderDetailRepository.AddData(allocateOrderDetails); |
| | | |
| | | BaseDal.UpdateData(allocateOrder); |
| | | _unitOfWorkManage.CommitTran(); |
| | | BaseDal.UpdateData(allocateOrder); |
| | | |
| | | DeleteInOutData(model.UpperOrderNo, allocateOrder); |
| | | await AddInOutData(allocateOrder); |
| | | |
| | | _unitOfWorkManage.CommitTran(); |
| | | |
| | | |
| | | return WebResponseContent.Instance.OK(); |
| | |
| | | catch (Exception ex) |
| | | { |
| | | _unitOfWorkManage.RollbackTran(); |
| | | _logger.LogInformation("AllocateService UpdateAllocateOrder err: " + ex.Message); |
| | | return WebResponseContent.Instance.Error(ex.Message); |
| | | } |
| | | } |
| | | |
| | | public WebResponseContent DeleteInboundOrder(Dt_AllocateOrder model) |
| | | public async Task<WebResponseContent> DeleteAllocateOrder(Dt_AllocateOrder model) |
| | | { |
| | | try |
| | | { |
| | | var allocateOrder = Db.Queryable<Dt_AllocateOrder>().Where(x => x.UpperOrderNo == model.UpperOrderNo).Includes(x => x.Details).First(); |
| | | if (allocateOrder == null) |
| | | { |
| | | return WebResponseContent.Instance.Error($"æªæ¾å°è°æ¨åä¿¡æ¯"); |
| | | } |
| | | if (allocateOrder.Details == null || allocateOrder.Details.Count == 0) |
| | | { |
| | | return WebResponseContent.Instance.Error($"æªæ¾å°è°æ¨åæç»ä¿¡æ¯"); |
| | | } |
| | | //Db.DeleteNav(inboundOrder).Include(x => x.Details).ExecuteCommand(); |
| | | _unitOfWorkManage.BeginTran(); |
| | | BaseDal.DeleteAndMoveIntoHty(allocateOrder, OperateTypeEnum.èªå¨å é¤); |
| | | foreach (var item in allocateOrder.Details) |
| | | { |
| | | _allocateOrderDetailRepository.DeleteAndMoveIntoHty(item, OperateTypeEnum.èªå¨å é¤); |
| | | } |
| | | _unitOfWorkManage.CommitTran(); |
| | | var allocateOrder = Db.Queryable<Dt_AllocateOrder>().Where(x => x.UpperOrderNo == model.UpperOrderNo).Includes(x => x.Details).First(); |
| | | if (allocateOrder == null) |
| | | { |
| | | return WebResponseContent.Instance.Error($"æªæ¾å°è°æ¨åä¿¡æ¯"); |
| | | } |
| | | if (allocateOrder.Details == null || allocateOrder.Details.Count == 0) |
| | | { |
| | | return WebResponseContent.Instance.Error($"æªæ¾å°è°æ¨åæç»ä¿¡æ¯"); |
| | | } |
| | | //Db.DeleteNav(Allocate).Include(x => x.Details).ExecuteCommand(); |
| | | _unitOfWorkManage.BeginTran(); |
| | | // BaseDal.DeleteAndMoveIntoHty(allocateOrder, OperateTypeEnum.èªå¨å é¤); |
| | | foreach (var item in allocateOrder.Details) |
| | | { |
| | | // _allocateOrderDetailRepository.DeleteAndMoveIntoHty(item, OperateTypeEnum.èªå¨å é¤); |
| | | _allocateOrderDetailRepository.DeleteData(item); |
| | | } |
| | | BaseDal.DeleteData(allocateOrder); |
| | | |
| | | DeleteInOutData(model.UpperOrderNo, allocateOrder); |
| | | |
| | | _unitOfWorkManage.CommitTran(); |
| | | return WebResponseContent.Instance.OK(); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | _unitOfWorkManage.RollbackTran(); |
| | | _logger.LogInformation("AllocateService DeleteAllocateOrder err: " + ex.Message); |
| | | return WebResponseContent.Instance.Error(ex.Message); |
| | | } |
| | | } |
| | | |
| | | 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(); |
| | | } |
| | | } |
| | | } |
| | | |
| | |
| | | InboundOrderNo=allocateOrder.OrderNo, |
| | | UpperOrderNo=allocateOrder.UpperOrderNo, |
| | | SupplierId=allocateOrder.SupplierId, |
| | | OrderType=allocateOrder.OrderType, |
| | | OrderType= allocateOrder.OrderType , |
| | | OrderStatus=allocateOrder.OrderStatus, |
| | | CreateType=allocateOrder.CreateType, |
| | | BusinessType=allocateOrder.BusinessType, |
| | |
| | | OrderDetailStatus=detail.OrderDetailStatus, |
| | | Unit=detail.Unit, |
| | | RowNo=0, |
| | | SupplyCode="", |
| | | SupplyCode=detail.SupplyCode, |
| | | WarehouseCode=detail.WarehouseCode, |
| | | Barcode=detail.Barcode, |
| | | OutBoxbarcodes="", |
| | |
| | | { |
| | | return new Dt_OutboundOrder() |
| | | { |
| | | WarehouseId= allocateOrder.WarehouseId, |
| | | OrderNo=allocateOrder.OrderNo, |
| | | UpperOrderNo=allocateOrder.UpperOrderNo, |
| | | OrderType=allocateOrder.OrderType, |
| | | OrderStatus=allocateOrder.OrderStatus, |
| | | CreateType=allocateOrder.CreateType, |
| | | BusinessType=allocateOrder.BusinessType, |
| | | IsBatch=allocateOrder.IsBatch, |
| | | FactoryArea=allocateOrder.FactoryArea, |
| | | Remark=allocateOrder.Remark, |
| | | DepartmentCode="", |
| | | DepartmentName="", |
| | | Details=allocateOrder.Details.Select(detail=>new Dt_OutboundOrderDetail |
| | | { |
| | | OrderId= detail.OrderId, |
| | | MaterielCode=detail.MaterielCode, |
| | | MaterielName="", |
| | | BatchNo=detail.BatchNo, |
| | | OrderQuantity=detail.OrderQuantity, |
| | | LockQuantity=0, |
| | | OverOutQuantity=0, |
| | | OrderDetailStatus=detail.OrderDetailStatus, |
| | | Unit=detail.Unit, |
| | | RowNo=0, |
| | | SupplyCode="", |
| | | WarehouseCode=detail.WarehouseCode, |
| | | |
| | | }).ToList() |
| | | WarehouseId = allocateOrder.WarehouseId, |
| | | OrderNo = allocateOrder.OrderNo, |
| | | UpperOrderNo = allocateOrder.UpperOrderNo, |
| | | OrderType = allocateOrder.OrderType, |
| | | OrderStatus = allocateOrder.OrderStatus, |
| | | CreateType = allocateOrder.CreateType, |
| | | BusinessType = allocateOrder.BusinessType, |
| | | IsBatch = allocateOrder.IsBatch, |
| | | FactoryArea = allocateOrder.FactoryArea, |
| | | Remark = allocateOrder.Remark, |
| | | DepartmentCode = "", |
| | | DepartmentName = "", |
| | | Details = allocateOrder.Details.Select(detail => new Dt_OutboundOrderDetail |
| | | { |
| | | OrderId = detail.OrderId, |
| | | MaterielCode = detail.MaterielCode, |
| | | MaterielName = "", |
| | | BatchNo = detail.BatchNo, |
| | | OrderQuantity = detail.OrderQuantity, |
| | | LockQuantity = 0, |
| | | OverOutQuantity = 0, |
| | | OrderDetailStatus = detail.OrderDetailStatus, |
| | | Unit = detail.Unit, |
| | | RowNo = 0, |
| | | SupplyCode = detail.SupplyCode, |
| | | WarehouseCode = detail.WarehouseCode, |
| | | |
| | | }).ToList() |
| | | }; |
| | | } |
| | | |