| | |
| | | using Microsoft.Extensions.Logging; |
| | | using SqlSugar; |
| | | 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; |
| | | using WIDESEA_Core.CodeConfigEnum; |
| | | using WIDESEA_Core.DB; |
| | | using WIDESEA_Core.Enums; |
| | | using WIDESEA_Core.Helper; |
| | | using WIDESEA_Core.Seed; |
| | | using WIDESEA_IAllocateService; |
| | | using WIDESEA_IBasicService; |
| | | using WIDESEA_IInboundService; |
| | | using WIDESEA_IOutboundService; |
| | | using WIDESEA_Model.Models; |
| | |
| | | public readonly IOutboundService _outboundService; |
| | | public readonly IRepository<Dt_AllocateOrder> _allocateOrderRepository; |
| | | public readonly IRepository<Dt_AllocateOrderDetail> _allocateOrderDetailRepository; |
| | | private readonly IMaterielInfoService _materielInfoService; |
| | | public readonly IRepository<Dt_InboundOrderDetail> _inboundOrderDetailRepository; |
| | | |
| | | private readonly ILogger<AllocateService> _logger; |
| | | public AllocateService(IRepository<Dt_AllocateOrder> BaseDal, |
| | |
| | | IOutboundService outboundService, |
| | | IRepository<Dt_AllocateOrder> allocateOrderRepository, |
| | | IRepository<Dt_AllocateOrderDetail> allocateOrderDetailRepository, |
| | | ILogger<AllocateService> logger) : base(BaseDal) |
| | | IRepository<Dt_InboundOrderDetail> inboundOrderDetailRepository, |
| | | ILogger<AllocateService> logger, |
| | | IMaterielInfoService materielInfoService) : base(BaseDal) |
| | | { |
| | | _unitOfWorkManage = unitOfWorkManage; |
| | | _inboundService = inboundService; |
| | |
| | | _allocateOrderRepository = allocateOrderRepository; |
| | | _allocateOrderDetailRepository = allocateOrderDetailRepository; |
| | | _logger = logger; |
| | | _inboundOrderDetailRepository = inboundOrderDetailRepository; |
| | | _materielInfoService = materielInfoService; |
| | | } |
| | | |
| | | 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 => AddAllocateOrder(allocateOrder), |
| | | 2 => UpdateAllocateOrder(allocateOrder), |
| | | 3 => DeleteAllocateOrder(allocateOrder), |
| | | 1 => await AddAllocateOrder(allocateOrder), |
| | | 2 => await UpdateAllocateOrder(allocateOrder), |
| | | 3 => await DeleteAllocateOrder(allocateOrder), |
| | | |
| | | _ => WebResponseContent.Instance.OK(), |
| | | }; |
| | |
| | | } |
| | | } |
| | | |
| | | public WebResponseContent AddAllocateOrder(Dt_AllocateOrder allocateOrder) |
| | | public async Task<WebResponseContent> AddAllocateOrder(Dt_AllocateOrder allocateOrder) |
| | | { |
| | | try |
| | | { |
| | | if (BaseDal.QueryFirst(x => x.UpperOrderNo == allocateOrder.UpperOrderNo) != null) |
| | | { |
| | | return WebResponseContent.Instance.Error($"è°æ¨åå·éå¤"); |
| | | return WebResponseContent.Instance.Error($"{allocateOrder.UpperOrderNo}è°æ¨åå·éå¤"); |
| | | } |
| | | allocateOrder.OrderNo = CreateCodeByRule(nameof(RuleCodeEnum.AllocateOrderCodeRule)); |
| | | Db.InsertNav(allocateOrder).Include(x => x.Details).ExecuteCommand(); |
| | | if (Enum.TryParse<BusinessTypeEnum>(allocateOrder.BusinessType, out var businessType)) |
| | | var materielCodes = allocateOrder.Details.Select(x => x.MaterielCode).Distinct().ToList(); |
| | | var materielInfos = _materielInfoService.Db.Queryable<Dt_MaterielInfo>().Where(x => materielCodes.Contains(x.MaterielCode)).ToList(); |
| | | foreach (var item in allocateOrder.Details) |
| | | { |
| | | if (businessType == BusinessTypeEnum.å¤é¨ä»åºè°æºä») |
| | | if (materielInfos.Any()) |
| | | { |
| | | var inboundOrders = ConvertToInboundOrders(allocateOrder); |
| | | _inboundService.InbounOrderService.ReceiveInboundOrder(inboundOrders, 1); |
| | | } |
| | | else if (businessType == BusinessTypeEnum.æºä»è°å¤é¨ä»åº) |
| | | { |
| | | var outboundOrders = ConvertToOutboundOrders(allocateOrder); |
| | | _outboundService.OutboundOrderService.ReceiveOutboundOrder(outboundOrders, 1); |
| | | } |
| | | else |
| | | { |
| | | // å¤çæªå®ä¹çæä¸¾å¼ï¼å¦æªæ¥æ°å¢ä½æªå®ç°çç±»åï¼ |
| | | throw new NotSupportedException($"䏿¯æçä¸å¡ç±»åæä¸¾å¼: {businessType}"); |
| | | item.MaterielName = materielInfos.FirstOrDefault(x => x.MaterielCode == item.MaterielCode)?.MaterielName ?? ""; |
| | | } |
| | | } |
| | | Db.InsertNav(allocateOrder).Include(x => x.Details).ExecuteCommand(); |
| | | await AddInOutData(allocateOrder); |
| | | return WebResponseContent.Instance.OK(); |
| | | } |
| | | catch (Exception ex) |
| | |
| | | return WebResponseContent.Instance.Error(ex.Message); |
| | | } |
| | | } |
| | | public WebResponseContent UpdateAllocateOrder(Dt_AllocateOrder model) |
| | | |
| | | private async Task AddInOutData(Dt_AllocateOrder allocateOrder) |
| | | { |
| | | if (Enum.TryParse<BusinessTypeEnum>(allocateOrder.BusinessType, out var businessType)) |
| | | { |
| | | if (businessType == BusinessTypeEnum.å¤é¨ä»åºè°æºä») |
| | | { |
| | | allocateOrder.OrderType = (int)InOrderTypeEnum.AllocatInbound; |
| | | var inboundOrders = ConvertToInboundOrders(allocateOrder); |
| | | await _inboundService.InbounOrderService.ReceiveInboundOrder(inboundOrders, 1); |
| | | } |
| | | else if (businessType == BusinessTypeEnum.æºä»è°å¤é¨ä»åº || businessType == BusinessTypeEnum.æºä»è°æºä») |
| | | { |
| | | if (businessType == BusinessTypeEnum.æºä»è°å¤é¨ä»åº) |
| | | { |
| | | allocateOrder.OrderType = (int)InOrderTypeEnum.AllocatOutbound; |
| | | } |
| | | else if (businessType == BusinessTypeEnum.æºä»è°æºä») |
| | | { |
| | | allocateOrder.OrderType = (int)InOrderTypeEnum.InternalAllocat; |
| | | } |
| | | |
| | | var outboundOrders = ConvertToOutboundOrders(allocateOrder); |
| | | await _outboundService.OutboundOrderService.ReceiveOutboundOrder(outboundOrders, 1); |
| | | } |
| | | else |
| | | { |
| | | // å¤çæªå®ä¹çæä¸¾å¼ï¼å¦æªæ¥æ°å¢ä½æªå®ç°çç±»åï¼ |
| | | throw new NotSupportedException($"䏿¯æçä¸å¡ç±»åæä¸¾å¼: {businessType}"); |
| | | } |
| | | } |
| | | } |
| | | |
| | | public async Task<WebResponseContent> UpdateAllocateOrder(Dt_AllocateOrder model) |
| | | { |
| | | try |
| | | { |
| | |
| | | List<Dt_AllocateOrderDetail> allocateOrderDetails = new List<Dt_AllocateOrderDetail>(); |
| | | List<Dt_AllocateOrderDetail> updateAllocateOrderDetails = new List<Dt_AllocateOrderDetail>(); |
| | | List<int> detailIds = new List<int>(); |
| | | |
| | | var materielCodes = allocateOrder.Details.Select(x => x.MaterielCode).Distinct().ToList(); |
| | | var materielInfos = _materielInfoService.Db.Queryable<Dt_MaterielInfo>().Where(x => materielCodes.Contains(x.MaterielCode)).ToList(); |
| | | |
| | | foreach (var item in model.Details) |
| | | { |
| | | if (string.IsNullOrEmpty(item.Barcode)) |
| | | { |
| | | |
| | | } |
| | | else |
| | | if (!string.IsNullOrEmpty(item.Barcode)) |
| | | { |
| | | Dt_AllocateOrderDetail? allocateOrderDetail = allocateOrder.Details.FirstOrDefault(x => x.Barcode == item.Barcode); |
| | | if (allocateOrderDetail == null) |
| | |
| | | BarcodeQty = (decimal)item.BarcodeQty, |
| | | OrderQuantity = item.OrderQuantity |
| | | }; |
| | | if (materielInfos.Any()) |
| | | { |
| | | allocateOrderDetail.MaterielName = materielInfos.FirstOrDefault(x => x.MaterielCode == item.MaterielCode)?.MaterielName ?? ""; |
| | | } |
| | | allocateOrderDetails.Add(allocateOrderDetail); |
| | | } |
| | | else |
| | |
| | | allocateOrderDetail.BarcodeUnit = item.BarcodeUnit; |
| | | allocateOrderDetail.BarcodeQty = item.BarcodeQty; |
| | | allocateOrderDetail.OrderQuantity = item.OrderQuantity; |
| | | |
| | | if (materielInfos.Any()) |
| | | { |
| | | allocateOrderDetail.MaterielName = materielInfos.FirstOrDefault(x => x.MaterielCode == item.MaterielCode)?.MaterielName ?? ""; |
| | | } |
| | | |
| | | updateAllocateOrderDetails.Add(allocateOrderDetail); |
| | | detailIds.Add(allocateOrderDetail.Id); |
| | |
| | | _unitOfWorkManage.BeginTran(); |
| | | foreach (var item in deletePurchaseOrderDetails) |
| | | { |
| | | _allocateOrderDetailRepository.DeleteAndMoveIntoHty(item, OperateTypeEnum.èªå¨å é¤); |
| | | // _allocateOrderDetailRepository.DeleteAndMoveIntoHty(item, OperateTypeEnum.èªå¨å é¤); |
| | | _allocateOrderDetailRepository.DeleteData(item); |
| | | } |
| | | |
| | | _allocateOrderDetailRepository.UpdateData(updateAllocateOrderDetails); |
| | | _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=allocateOrder.OrderType, |
| | | 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, |
| | | SupplyCode="", |
| | | lineNo=detail.LineNo, |
| | | SupplyCode=detail.SupplyCode, |
| | | WarehouseCode=detail.WarehouseCode, |
| | | Barcode=detail.Barcode, |
| | | OutBoxbarcodes="", |
| | |
| | | |
| | | 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, |
| | |
| | | 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 = item.Detail.BarcodeQty??0, |
| | | 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 = "", |
| | | WarehouseCode = detail.WarehouseCode, |
| | | SupplyCode = item.Detail.SupplyCode, |
| | | WarehouseCode = item.Detail.WarehouseCode, |
| | | |
| | | }).ToList() |
| | | }; |
| | |
| | | return code; |
| | | } |
| | | } |
| | | |
| | | public override PageGridData<Dt_AllocateOrder> GetPageData(PageDataOptions options) |
| | | { |
| | | string wheres = ValidatePageOptions(options); |
| | | //è·åæåºå段 |
| | | Dictionary<string, SqlSugar.OrderByType> orderbyDic = GetPageDataSort(options, TProperties); |
| | | List<OrderByModel> orderByModels = new List<OrderByModel>(); |
| | | foreach (var item in orderbyDic) |
| | | { |
| | | OrderByModel orderByModel = new() |
| | | { |
| | | FieldName = item.Key, |
| | | OrderByType = item.Value |
| | | }; |
| | | orderByModels.Add(orderByModel); |
| | | } |
| | | |
| | | |
| | | int totalCount = 0; |
| | | List<SearchParameters> searchParametersList = new List<SearchParameters>(); |
| | | if (!string.IsNullOrEmpty(options.Wheres)) |
| | | { |
| | | try |
| | | { |
| | | searchParametersList = options.Wheres.DeserializeObject<List<SearchParameters>>(); |
| | | options.Filter = searchParametersList; |
| | | } |
| | | catch { } |
| | | } |
| | | var data = BaseDal.Db.Queryable<Dt_AllocateOrder>() |
| | | .WhereIF(!wheres.IsNullOrEmpty(), wheres) |
| | | .OrderBy(orderByModels) |
| | | .ToPageList(options.Page, options.Rows, ref totalCount); |
| | | |
| | | foreach (var item in data) |
| | | { |
| | | Dt_InboundOrder _InboundOrder = SqlSugarHelper.DbWMS.Queryable<Dt_InboundOrder>().Where(x => x.UpperOrderNo == item.UpperOrderNo).First(); |
| | | Dt_OutboundOrder OutboundOrder = SqlSugarHelper.DbWMS.Queryable<Dt_OutboundOrder>().Where(x => x.UpperOrderNo == item.UpperOrderNo).First(); |
| | | if (_InboundOrder != null) |
| | | { |
| | | item.OrderStatus = _InboundOrder.OrderStatus; |
| | | item.OrderType = _InboundOrder.OrderType; |
| | | }else if (OutboundOrder!=null) |
| | | { |
| | | item.OrderStatus = OutboundOrder.OrderStatus; |
| | | item.OrderType = OutboundOrder.OrderType; |
| | | } |
| | | } |
| | | return new PageGridData<Dt_AllocateOrder>(totalCount, data); |
| | | } |
| | | |
| | | public override PageGridData<Dt_InboundOrderDetail> GetDetailPage(PageDataOptions options) |
| | | { |
| | | string wheres = ValidatePageOptions(options); |
| | | //è·åæåºå段 |
| | | Dictionary<string, SqlSugar.OrderByType> orderbyDic = GetPageDataSort(options, TProperties); |
| | | List<OrderByModel> orderByModels = new List<OrderByModel>(); |
| | | foreach (var item in orderbyDic) |
| | | { |
| | | OrderByModel orderByModel = new() |
| | | { |
| | | FieldName = item.Key, |
| | | OrderByType = item.Value |
| | | }; |
| | | orderByModels.Add(orderByModel); |
| | | } |
| | | |
| | | |
| | | int totalCount = 0; |
| | | List<SearchParameters> searchParametersList = new List<SearchParameters>(); |
| | | if (!string.IsNullOrEmpty(options.Wheres)) |
| | | { |
| | | try |
| | | { |
| | | searchParametersList = options.Wheres.DeserializeObject<List<SearchParameters>>(); |
| | | options.Filter = searchParametersList; |
| | | } |
| | | catch { } |
| | | } |
| | | //var data = BaseDal.Db.Queryable<Dt_AllocateOrderDetail>() |
| | | // .WhereIF(!wheres.IsNullOrEmpty(), wheres) |
| | | // .OrderBy(orderByModels) |
| | | // .ToPageList(options.Page, options.Rows, ref totalCount); |
| | | //Dt_AllocateOrder allocateOrder = _allocateOrderRepository.QueryFirst(x => x.Id == (int)options.Value); |
| | | //Dt_InboundOrder _InboundOrder = SqlSugarHelper.DbWMS.Queryable<Dt_InboundOrder>().Where(x => x.UpperOrderNo == allocateOrder.UpperOrderNo).First(); |
| | | //var details = _inboundOrderDetailRepository.QueryData(x => x.OrderId == _InboundOrder.Id ); |
| | | //foreach (var item in data) |
| | | //{ |
| | | // var detail = details.Where(x => x.MaterielCode == item.MaterielCode).FirstOrDefault(); |
| | | // if (detail != null) |
| | | // { |
| | | // item.OrderQuantity = detail.OrderQuantity; |
| | | // item.ReceiptQuantity = detail.ReceiptQuantity; |
| | | // item.OverInQuantity = detail.OverInQuantity; |
| | | // item.OrderDetailStatus = detail.OrderDetailStatus; |
| | | // } |
| | | //} |
| | | //return new PageGridData<Dt_AllocateOrderDetail>(totalCount, data); |
| | | |
| | | Dt_AllocateOrder allocateOrder = _allocateOrderRepository.QueryFirst(x => x.Id == (int)options.Value); |
| | | Dt_InboundOrder _InboundOrder = SqlSugarHelper.DbWMS.Queryable<Dt_InboundOrder>().Where(x => x.UpperOrderNo == allocateOrder.UpperOrderNo).First(); |
| | | var Id = _InboundOrder == null ? 0 : _InboundOrder.Id; |
| | | var data = BaseDal.Db.Queryable<Dt_InboundOrderDetail>() |
| | | .WhereIF(!wheres.IsNullOrEmpty(), wheres) |
| | | .Where( x => x.OrderId == Id) |
| | | .OrderBy(orderByModels) |
| | | .ToPageList(options.Page, options.Rows, ref totalCount); |
| | | |
| | | |
| | | return new PageGridData<Dt_InboundOrderDetail>(totalCount, data); |
| | | } |
| | | } |
| | | } |