Esempio n. 1
0
        public ResponseOutput GetProductsByBatchId(int batchId)
        {
            List <ProductDto>         productDtos = new List <ProductDto>();
            List <ProductInformation> products    = _productService.GetProductsByBatchId(batchId);

            try
            {
                _logger.LogInformation("进入GetProductsByBatchId方法");
                foreach (var product in products)
                {
                    //过滤商品状态
                    //if (product.ProductStatus == ProductStatusTypeEnum.Down || product.ProductStatus == ProductStatusTypeEnum.Unknown
                    //    || product.StockType == StockStatusTypeEnum.No || product.StockType == StockStatusTypeEnum.Unknown)
                    //{
                    //    continue;
                    //}
                    //过滤库存状态
                    if (product.ProductStatus == ProductStatusTypeEnum.Down || product.ProductStatus == ProductStatusTypeEnum.Unknown)
                    {
                        continue;
                    }
                    //图片详情
                    var productDetails = _productDetailService.GetDetailsByProductId(product.Id);
                    List <ProductDetailOutputDto> detailDtos = new List <ProductDetailOutputDto>();
                    if (productDetails != null)
                    {
                        foreach (var productDetail in productDetails)
                        {
                            detailDtos.Add(new ProductDetailOutputDto()
                            {
                                PhotoPath = productDetail.PhotoPath.Replace('\\', '/')
                            });
                        }
                    }

                    var productDto = new ProductDto();
                    productDto.Id   = product.Id;
                    productDto.Code = product.ProductCode;
                    productDto.Name = product.ProductName;
                    if (!string.IsNullOrEmpty(product.Description))
                    {
                        //修改富文本的图片为绝对路径
                        string processDescription = TextParse.ProcessHtmlImageUrlList(product.Description);
                        productDto.Description = processDescription;
                    }
                    productDto.StockStatus   = (int)product.StockType;
                    productDto.ClassType     = (int)product.Type;
                    productDto.ProductStatus = (int)product.ProductStatus;
                    productDto.Photos        = detailDtos.Select(item => Path.Combine("http://www.bangbangfuli.cn:5001/", item.PhotoPath.Replace('\\', '/'))).ToList();
                    productDtos.Add(productDto);
                }
                return(new ResponseOutput(productDtos, "0", string.Empty, HttpContext.TraceIdentifier));
            }
            catch (Exception ex)
            {
                _logger.LogError($"异常为{ex.ToString()}");
                return(new ResponseOutput(null, "-1", ex.Message, HttpContext.TraceIdentifier));
            }
        }
        public ResponseOutput GetProductsByBatchId(int batchId)
        {
            List <ProductDto>         productDtos = new List <ProductDto>();
            List <ProductInformation> products    = _productService.GetProductsByBatchId(batchId);

            try
            {
                _logger.LogInformation("进入GetProductsByBatchId方法");
                foreach (var product in products)
                {
                    //过滤商品状态
                    if (product.ProductStatus == ProductStatusTypeEnum.Down || product.ProductStatus == ProductStatusTypeEnum.Unknown ||
                        product.StockType == StockStatusTypeEnum.No || product.StockType == StockStatusTypeEnum.Unknown)
                    {
                        continue;
                    }
                    //图片详情
                    var productDetails = _productDetailService.GetDetailsByProductId(product.Id);
                    List <ProductDetailOutputDto> detailDtos = new List <ProductDetailOutputDto>();
                    if (productDetails != null)
                    {
                        foreach (var productDetail in productDetails)
                        {
                            detailDtos.Add(new ProductDetailOutputDto()
                            {
                                PhotoPath = productDetail.PhotoPath
                            });
                        }
                    }

                    productDtos.Add(new ProductDto
                    {
                        Id            = product.Id,
                        Code          = product.ProductCode,
                        Name          = product.ProductName,
                        Description   = product.Description,
                        StockStatus   = (int)product.StockType,
                        ClassType     = (int)product.Type,
                        ProductStatus = (int)product.ProductStatus,
                        Photos        = detailDtos.Select(item => item.PhotoPath).ToList()
                    });
                }
                return(new ResponseOutput(productDtos, "0", string.Empty, HttpContext.TraceIdentifier));
            }
            catch (Exception ex)
            {
                _logger.LogError($"异常为{ex.ToString()}");
                return(new ResponseOutput(null, "-1", ex.Message, HttpContext.TraceIdentifier));
            }
        }