| | |
| | | using Autofac.Core; |
| | | using AutoMapper; |
| | | using Microsoft.AspNetCore.Mvc; |
| | | using Microsoft.Extensions.Logging; |
| | | using SqlSugar; |
| | | 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_IBasicService; |
| | | using WIDESEA_IOutboundService; |
| | | using WIDESEA_Model.Models; |
| | | |
| | |
| | | private readonly IMapper _mapper; |
| | | private readonly IUnitOfWorkManage _unitOfWorkManage; |
| | | public IRepository<Dt_OutboundOrder> Repository => BaseDal; |
| | | |
| | | private readonly ILogger<OutboundOrderService> _logger; |
| | | private readonly IRepository<Dt_OutboundOrderDetail> _outboundOrderDetailRepository; |
| | | |
| | | public OutboundOrderService(IRepository<Dt_OutboundOrder> BaseDal, IMapper mapper, IUnitOfWorkManage unitOfWorkManage, IRepository<Dt_OutboundOrderDetail> outboundOrderDetailRepository) : base(BaseDal) |
| | | private readonly IMaterialUnitService _materialUnitService; |
| | | public OutboundOrderService(IRepository<Dt_OutboundOrder> BaseDal, IMapper mapper, IUnitOfWorkManage unitOfWorkManage, IRepository<Dt_OutboundOrderDetail> outboundOrderDetailRepository, ILogger<OutboundOrderService> logger, IMaterialUnitService materialUnitService) : base(BaseDal) |
| | | { |
| | | _mapper = mapper; |
| | | _unitOfWorkManage = unitOfWorkManage; |
| | | _outboundOrderDetailRepository = outboundOrderDetailRepository; |
| | | _logger = logger; |
| | | _materialUnitService = materialUnitService; |
| | | } |
| | | |
| | | public WebResponseContent ReceiveOutboundOrder(Dt_OutboundOrder model, int operateType) |
| | | private int[] OrderTypes = new int[] { (int)InOrderTypeEnum.AllocatOutbound, (int)InOrderTypeEnum.InternalAllocat, (int)InOrderTypeEnum.ReCheck }; |
| | | public async Task<WebResponseContent> ReceiveOutboundOrder(Dt_OutboundOrder model, int operateType) |
| | | { |
| | | try |
| | | { |
| | | return operateType switch |
| | | { |
| | | 1 => AddOutboundOrder(model), |
| | | 2 => UpdateOutboundOrder(model), |
| | | 1 => await AddOutboundOrder(model), |
| | | 2 => await UpdateOutboundOrder(model), |
| | | 3 => DeleteOutboundOrder(model), |
| | | |
| | | _ => WebResponseContent.Instance.OK(), |
| | |
| | | } |
| | | } |
| | | |
| | | public WebResponseContent AddOutboundOrder(Dt_OutboundOrder model) |
| | | public async Task<WebResponseContent> AddOutboundOrder(Dt_OutboundOrder model) |
| | | { |
| | | try |
| | | { |
| | |
| | | { |
| | | return WebResponseContent.Instance.Error($"åºåºåå·éå¤"); |
| | | } |
| | | foreach (var item in model.Details) |
| | | { |
| | | var issueoStockResult = await _materialUnitService.ConvertFromToStockAsync(item.MaterielCode, item.BarcodeUnit, item.BarcodeQty); |
| | | item.Unit = issueoStockResult.Unit; |
| | | item.OrderQuantity = issueoStockResult.Quantity; |
| | | var moveissueoStockResult = await _materialUnitService.ConvertFromToStockAsync(item.MaterielCode, item.BarcodeUnit, item.BarcodeMoveQty); |
| | | item.MoveQty = moveissueoStockResult.Quantity; |
| | | } |
| | | if (!OrderTypes.Contains(model.OrderType)) |
| | | { |
| | | model.OrderNo = CreateCodeByRule(nameof(RuleCodeEnum.OutboundOrderRule)); |
| | | } |
| | | |
| | | model.OrderNo = CreateCodeByRule(nameof(RuleCodeEnum.OutboundOrderRule)); |
| | | Db.InsertNav(model).Include(x => x.Details).ExecuteCommand(); |
| | | |
| | | return WebResponseContent.Instance.OK(); |
| | |
| | | return WebResponseContent.Instance.Error(ex.Message); |
| | | } |
| | | } |
| | | public WebResponseContent UpdateOutboundOrder(Dt_OutboundOrder model) |
| | | public async Task<WebResponseContent> UpdateOutboundOrder(Dt_OutboundOrder model) |
| | | { |
| | | try |
| | | { |
| | |
| | | { |
| | | return WebResponseContent.Instance.Error($"æªæ¾å°åºåºåæç»ä¿¡æ¯"); |
| | | } |
| | | List<Dt_OutboundOrderDetail> inboundOrderDetails = new List<Dt_OutboundOrderDetail>(); |
| | | List<Dt_OutboundOrderDetail> updateInboundOrderDetails = new List<Dt_OutboundOrderDetail>(); |
| | | if (outboundOrder.OrderStatus != (int)OutOrderStatusEnum.æªå¼å§) |
| | | { |
| | | return WebResponseContent.Instance.Error($"该订åç¶æä¸å
许修æ¹"); |
| | | } |
| | | List<Dt_OutboundOrderDetail> outboundOrderDetails = new List<Dt_OutboundOrderDetail>(); |
| | | List<Dt_OutboundOrderDetail> updateoutboundOrderDetails = new List<Dt_OutboundOrderDetail>(); |
| | | List<int> detailIds = new List<int>(); |
| | | foreach (var item in model.Details) |
| | | { |
| | |
| | | BatchNo = item.BatchNo, |
| | | Unit = item.Unit, |
| | | WarehouseCode = item.WarehouseCode, |
| | | MoveQty=item.MoveQty, |
| | | OrderQuantity = item.OrderQuantity |
| | | MoveQty = item.MoveQty, |
| | | OrderQuantity = item.OrderQuantity, |
| | | BarcodeMoveQty = item.MoveQty, |
| | | BarcodeQty = item.OrderQuantity, |
| | | BarcodeUnit = item.Unit, |
| | | }; |
| | | inboundOrderDetails.Add(outboundOrderDetail); |
| | | var issueoStockResult = await _materialUnitService.ConvertFromToStockAsync(item.MaterielCode, item.BarcodeUnit, item.BarcodeQty); |
| | | item.Unit = issueoStockResult.Unit; |
| | | item.OrderQuantity = issueoStockResult.Quantity; |
| | | var moveissueoStockResult = await _materialUnitService.ConvertFromToStockAsync(item.MaterielCode, item.BarcodeUnit, item.BarcodeMoveQty); |
| | | item.MoveQty = moveissueoStockResult.Quantity; |
| | | |
| | | outboundOrderDetails.Add(outboundOrderDetail); |
| | | } |
| | | else |
| | | { |
| | |
| | | outboundOrderDetail.WarehouseCode = item.WarehouseCode; |
| | | outboundOrderDetail.MoveQty = item.MoveQty; |
| | | outboundOrderDetail.OrderQuantity = item.OrderQuantity; |
| | | outboundOrderDetail.BarcodeMoveQty = item.MoveQty; |
| | | outboundOrderDetail.BarcodeQty = item.OrderQuantity; |
| | | outboundOrderDetail.BarcodeUnit = item.Unit; |
| | | var issueoStockResult = await _materialUnitService.ConvertFromToStockAsync(item.MaterielCode, item.BarcodeUnit, item.BarcodeQty); |
| | | outboundOrderDetail.Unit = issueoStockResult.Unit; |
| | | outboundOrderDetail.OrderQuantity = issueoStockResult.Quantity; |
| | | var moveissueoStockResult = await _materialUnitService.ConvertFromToStockAsync(item.MaterielCode, item.BarcodeUnit, item.BarcodeMoveQty); |
| | | outboundOrderDetail.MoveQty = moveissueoStockResult.Quantity; |
| | | |
| | | updateInboundOrderDetails.Add(outboundOrderDetail); |
| | | |
| | | updateoutboundOrderDetails.Add(outboundOrderDetail); |
| | | detailIds.Add(outboundOrderDetail.Id); |
| | | } |
| | | } |
| | |
| | | _unitOfWorkManage.BeginTran(); |
| | | foreach (var item in deletePurchaseOrderDetails) |
| | | { |
| | | _outboundOrderDetailRepository.DeleteAndMoveIntoHty(item, OperateTypeEnum.èªå¨å é¤); |
| | | // _outboundOrderDetailRepository.DeleteAndMoveIntoHty(item, OperateTypeEnum.èªå¨å é¤); |
| | | _outboundOrderDetailRepository.DeleteData(item); |
| | | } |
| | | |
| | | _outboundOrderDetailRepository.UpdateData(updateInboundOrderDetails); |
| | | _outboundOrderDetailRepository.AddData(inboundOrderDetails); |
| | | _outboundOrderDetailRepository.UpdateData(updateoutboundOrderDetails); |
| | | _outboundOrderDetailRepository.AddData(outboundOrderDetails); |
| | | |
| | | BaseDal.UpdateData(outboundOrder); |
| | | _unitOfWorkManage.CommitTran(); |
| | |
| | | { |
| | | try |
| | | { |
| | | var outboundOrder = Db.Queryable<Dt_OutboundOrder>().Where(x => x.UpperOrderNo == model.UpperOrderNo).Includes(x => x.Details).First(); |
| | | var outboundOrder = Db.Queryable<Dt_OutboundOrder>().Where(x => x.UpperOrderNo == model.UpperOrderNo).Includes(x => x.Details).First(); |
| | | if (outboundOrder == null) |
| | | { |
| | | return WebResponseContent.Instance.Error($"æªæ¾å°åºåºåä¿¡æ¯"); |
| | |
| | | { |
| | | return WebResponseContent.Instance.Error($"æªæ¾å°åºåºåæç»ä¿¡æ¯"); |
| | | } |
| | | //Db.DeleteNav(inboundOrder).Include(x => x.Details).ExecuteCommand(); |
| | | if (outboundOrder.OrderStatus != (int)OutOrderStatusEnum.æªå¼å§) |
| | | { |
| | | return WebResponseContent.Instance.Error($"该订åç¶æä¸å
许å é¤"); |
| | | } |
| | | _unitOfWorkManage.BeginTran(); |
| | | BaseDal.DeleteAndMoveIntoHty(outboundOrder, OperateTypeEnum.èªå¨å é¤); |
| | | //BaseDal.DeleteAndMoveIntoHty(outboundOrder, OperateTypeEnum.èªå¨å é¤); |
| | | foreach (var item in outboundOrder.Details) |
| | | { |
| | | _outboundOrderDetailRepository.DeleteAndMoveIntoHty(item, OperateTypeEnum.èªå¨å é¤); |
| | | // _outboundOrderDetailRepository.DeleteAndMoveIntoHty(item, OperateTypeEnum.èªå¨å é¤);\\ |
| | | _outboundOrderDetailRepository.DeleteData(item); |
| | | } |
| | | BaseDal.DeleteData(outboundOrder); |
| | | _unitOfWorkManage.CommitTran(); |
| | | |
| | | return WebResponseContent.Instance.OK(); |
| | |
| | | catch (Exception ex) |
| | | { |
| | | _unitOfWorkManage.RollbackTran(); |
| | | _logger.LogInformation(ex.Message); |
| | | return WebResponseContent.Instance.Error(ex.Message); |
| | | } |
| | | } |
| | |
| | | /// </summary> |
| | | public async Task<WebResponseContent> GetById(int id) |
| | | { |
| | | var order = await Db.Queryable<Dt_OutboundOrder>().FirstAsync(o=>o.Id==id); |
| | | var order = await Db.Queryable<Dt_OutboundOrder>().FirstAsync(o => o.Id == id); |
| | | if (order == null) |
| | | { |
| | | return WebResponseContent.Instance.Error("æªæ¾å°åºåºåä¿¡æ¯"); |
| | |
| | | return code; |
| | | } |
| | | } |
| | | |
| | | |
| | | public override PageGridData<Dt_OutboundOrder> 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_OutboundOrder>() |
| | | .WhereIF(!wheres.IsNullOrEmpty(), wheres) |
| | | .Where(x => x.OrderType == 0) |
| | | .OrderBy(orderByModels) |
| | | .ToPageList(options.Page, options.Rows, ref totalCount); |
| | | |
| | | return new PageGridData<Dt_OutboundOrder>(totalCount, data); |
| | | } |
| | | } |
| | | } |