Exemplo n.º 1
0
        /// <summary>
        /// 锁定库存
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public async Task BlockQtyAsync(WarehouseBlockQtyDto input)
        {
            var blockQtyProductsInfo = input.Products.ToDictionary(x => x.ProductId, x => x.Qty);
            var warehouses           = await _warehouseRepo.Where(x => blockQtyProductsInfo.Keys.Contains(x.ProductId.Value), noTracking : false).ToListAsync();

            var products = await _productRepo.Where(x => blockQtyProductsInfo.Keys.Contains(x.Id)).ToListAsync();

            var result = await _warehouseManager.BlockQtyAsync(input.OrderId, blockQtyProductsInfo, warehouses, products);

            //库存都符合锁定条件才能批量更新数据库
            if (result)
            {
                await _warehouseRepo.UpdateRangeAsync(warehouses);
            }
        }
Exemplo n.º 2
0
    /// <summary>
    /// 锁定库存
    /// </summary>
    /// <param name="input"></param>
    /// <returns></returns>
    public async Task BlockQtyAsync(OrderCreatedEvent eventDto, IMessageTracker tracker)
    {
        var blockQtyProductsInfo = eventDto.Data.Products.ToDictionary(x => x.ProductId, x => x.Qty);
        var warehouses           = await _warehouseRepo.Where(x => blockQtyProductsInfo.Keys.Contains(x.ProductId.Value), noTracking : false).ToListAsync();

        var products = await _productRepo.Where(x => blockQtyProductsInfo.Keys.Contains(x.Id)).ToListAsync();

        var result = await _warehouseManager.BlockQtyAsync(eventDto.Data.OrderId, blockQtyProductsInfo, warehouses, products);

        //库存都符合锁定条件才能批量更新数据库
        if (result)
        {
            await _warehouseRepo.UpdateRangeAsync(warehouses);

            await tracker?.MarkAsProcessedAsync(eventDto);
        }
    }