Example #1
0
        /// <summary>
        /// 分页列表
        /// </summary>
        /// <param name="search"></param>
        /// <returns></returns>
        public async Task <PageModelDto <WarehouseDto> > GetPagedAsync(WarehouseSearchDto search)
        {
            var total = await _warehouseRepo.CountAsync(x => true);

            if (total == 0)
            {
                return new PageModelDto <WarehouseDto>
                       {
                           TotalCount = 0
                           ,
                           PageIndex = search.PageIndex
                           ,
                           PageSize = search.PageSize
                       }
            }
            ;

            var products   = _productRepo.Where(x => true);
            var warehouses = _warehouseRepo.Where(x => true);

            var skipNumber = (search.PageIndex - 1) * search.PageSize;

            var data = await(from s in warehouses
                             join p in products
                             on s.ProductId equals p.Id into sp
                             from x in sp.DefaultIfEmpty()
                             select new WarehouseDto()
            {
                Id = s.Id.ToString()
                ,
                FreezedQty = s.BlockedQty
                ,
                PositionCode = s.Position.Code
                ,
                PositionDescription = s.Position.Description
                ,
                ProductId = s.ProductId.Value.ToString()
                ,
                ProductName = x.Name
                ,
                ProductSku = x.Sku
                ,
                Qty = s.Qty
            })
                       .Skip(skipNumber)
                       .Take(search.PageSize)
                       .OrderByDescending(x => x.Id)
                       .ToListAsync();

            return(new PageModelDto <WarehouseDto>()
            {
                PageIndex = search.PageIndex
                ,
                PageSize = search.PageSize
                ,
                TotalCount = total
                ,
                Data = data
            });
        }
Example #2
0
    /// <summary>
    /// 分页列表
    /// </summary>
    /// <param name="search"></param>
    /// <returns></returns>
    public async Task <PageModelDto <WarehouseDto> > GetPagedAsync(WarehouseSearchDto search)
    {
        var total = await _warehouseRepo.CountAsync(x => true);

        if (total == 0)
        {
            return(new PageModelDto <WarehouseDto>(search));
        }

        var products   = _productRepo.Where(x => true);
        var warehouses = _warehouseRepo.Where(x => true);
        var data       = await(from s in warehouses
                               join p in products
                               on s.ProductId equals p.Id into sp
                               from x in sp.DefaultIfEmpty()
                               select new WarehouseDto()
        {
            Id                  = s.Id,
            FreezedQty          = s.BlockedQty,
            PositionCode        = s.Position.Code,
            PositionDescription = s.Position.Description,
            ProductId           = s.ProductId,
            ProductName         = x.Name,
            ProductSku          = x.Sku,
            Qty                 = s.Qty
        })
                         .Skip(search.SkipRows())
                         .Take(search.PageSize)
                         .OrderByDescending(x => x.Id)
                         .ToListAsync();

        return(new PageModelDto <WarehouseDto>(search, data, total));
    }
Example #3
0
        /// <summary>
        /// 创建商品
        /// </summary>
        /// <param name="sku"></param>
        /// <param name="name"></param>
        /// <param name="unit"></param>
        /// <param name="describe"></param>
        /// <returns></returns>
        public virtual async Task <Product> CreateAsync(string sku, decimal price, string name, string unit, string describe = null)
        {
            var product = await _productRepo.Where(x => x.Sku == sku || x.Name == name).FirstOrDefaultAsync();

            if (product != null)
            {
                if (product.Sku == sku)
                {
                    throw new ArgumentException("sku exists");
                }
                if (product.Name == name)
                {
                    throw new ArgumentException("name exists");
                }
            }

            return(new Product(
                       IdGenerater.GetNextId(IdGenerater.DatacenterId, IdGenerater.WorkerId)
                       , sku
                       , price
                       , name
                       , unit
                       , describe
                       ));
        }
Example #4
0
    /// <summary>
    /// 商品分页列表
    /// </summary>
    /// <param name="search"></param>
    /// <returns></returns>
    public async Task <PageModelDto <ProductDto> > GetPagedAsync(ProductSearchPagedDto search)
    {
        var whereCondition = ExpressionCreator
                             .New <Product>()
                             .AndIf(search.Id > 0, x => x.Id == search.Id);

        var total = await _productRepo.CountAsync(whereCondition);

        if (total == 0)
        {
            return(new PageModelDto <ProductDto>(search));
        }

        var entities = await _productRepo
                       .Where(whereCondition)
                       .OrderByDescending(x => x.Id)
                       .Skip(search.SkipRows())
                       .Take(search.PageSize)
                       .ToListAsync();

        var productDtos = Mapper.Map <List <ProductDto> >(entities);

        if (productDtos.IsNotNullOrEmpty())
        {
            //调用maint微服务获取字典,组合商品状态信息
            var restRpcResult = await _maintRestClient.GetDictAsync(RpcConsts.ProdunctStatusId);

            if (restRpcResult.IsSuccessStatusCode)
            {
                var dict = restRpcResult.Content;
                if (dict is not null && dict.Children.IsNotNullOrEmpty())
                {
                    productDtos.ForEach(x =>
                    {
                        x.StatusDescription = dict.Children.FirstOrDefault(d => d.Value == x.StatusCode.ToString())?.Name;
                    });
                }
            }
        }

        return(new PageModelDto <ProductDto>(search, productDtos, total));
    }
Example #5
0
        /// <summary>
        /// 上架商品
        /// </summary>
        /// <param name="id"></param>
        /// <param name="input"></param>
        /// <returns></returns>
        public async Task <ProductDto> PutOnSaleAsync(long id, ProductPutOnSaleDto input)
        {
            var product = await _productRepo.GetAsync(id);

            var warehouseInfo = await _warehouseInfoRepo.Where(x => x.ProductId == id).FirstOrDefaultAsync();

            _productMgr.PutOnSale(product, warehouseInfo, input.Reason);

            await _productRepo.UpdateAsync(product);

            return(_mapper.Map <ProductDto>(product));
        }
Example #6
0
        /// <summary>
        /// 商品列表
        /// </summary>
        /// <param name="search"></param>
        /// <returns></returns>
        public async Task <List <ProductDto> > GetListAsync(ProductSearchListDto search)
        {
            var whereCondition = ExpressionCreator
                                 .New <Product>()
                                 .AndIf(search.Ids.IsNotNullOrEmpty(), x => (search.Ids.Select(x => x).Distinct()).Contains(x.Id))
                                 .AndIf(search.StatusCode > 0, x => (int)x.Status.Code == search.StatusCode);

            var products = await _productRepo.Where(whereCondition).ToListAsync();

            var productsDto = Mapper.Map <List <ProductDto> >(products);

            return(productsDto);
        }
Example #7
0
        /// <summary>
        /// 分配货架给商品
        /// </summary>
        /// <param name="warehouse"></param>
        /// <param name="productId"></param>
        /// <returns></returns>
        public async Task AllocateShelfToProductAsync(Warehouse warehouse, Product product)
        {
            Checker.NotNull(warehouse, nameof(warehouse));
            Checker.NotNull(product, nameof(product));

            var existWarehouse = await _warehouseRepo.Where(x => x.ProductId == product.Id).SingleOrDefaultAsync();

            //一个商品只能分配一个货架,但可以调整货架。
            if (existWarehouse != null && existWarehouse.Id != warehouse.Id)
            {
                throw new AdncArgumentException("AssignedWarehouseId", nameof(warehouse));
            }

            warehouse.SetProductId(product.Id);
        }
Example #8
0
        /// <summary>
        /// 商品列表
        /// </summary>
        /// <param name="search"></param>
        /// <returns></returns>
        public async Task <List <ProductDto> > GetListAsync(ProductSearchListDto search)
        {
            var whereCondition = ExpressionExtension.True <Product>();

            if (!search.Ids.IsNullOrEmpty())
            {
                var ids = search.Ids.Where(x => x.IsNotNullOrEmpty()).Select(x => x.ToLong().Value).Distinct();

                whereCondition = whereCondition.And(x => ids.Contains(x.Id));
            }
            if (search.StatusCode > 0)
            {
                whereCondition = whereCondition.And(x => (int)x.Status.Code == search.StatusCode);
            }

            var products = await _productRepo.Where(whereCondition).ToListAsync();

            var productsDto = _mapper.Map <List <ProductDto> >(products);

            return(productsDto);
        }