public async Task <ResponseResult> Handle(
                Command request,
                CancellationToken cancellationToken)
            {
                IEnumerable <MaterialExport> queryResult;

                using (var scope = _databaseScopeFactory.CreateReadOnly())
                {
                    queryResult = await _repository.FindMaterialsWithAllPropertiesByTypeAsync <MaterialExport>(request.TypeId);
                }

                if (queryResult?.Any() ?? false)
                {
                    var list = queryResult.ToList();

                    var createResult = await CreateFolder();

                    var      path     = createResult.Item1;
                    var      fileName = $"{request.TypeName}{request.UserName}-{createResult.Item2}.xlsx";
                    FileInfo file     = new FileInfo($@"{path}\{fileName}");
                    if (file?.Exists ?? false)
                    {
                        file.Delete();
                    }

                    using (ExcelPackage package = new ExcelPackage(file))
                    {
                        ExcelWorksheet worksheet = package.Workbook.Worksheets.Add("物料");

                        worksheet.Cells[1, 1].Value = "物料编号";
                        worksheet.Cells[1, 2].Value = "物料名称";
                        worksheet.Cells[1, 3].Value = "物料类型";
                        worksheet.Cells[1, 4].Value = "物料规格";
                        worksheet.Cells[1, 5].Value = "物料单位";
                        worksheet.Cells[1, 6].Value = "是否为生产物料";
                        worksheet.Cells[1, 7].Value = "是否有独立编号";
                        worksheet.Cells[1, 8].Value = "采购主体";

                        worksheet.Cells[1, 9].Value = "建议采购价";
                        worksheet.Cells[1, 9].Style.HorizontalAlignment = ExcelHorizontalAlignment.Right;

                        worksheet.Cells[1, 10].Value = "是否已发布";
                        worksheet.Cells[1, 11].Value = "发布时间";
                        worksheet.Cells[1, 12].Value = "是否启用";

                        // 自定义属性名称
                        var properties = list.First().Properties;
                        if (properties?.Any() ?? false)
                        {
                            var col = 13;
                            foreach (var property in properties)
                            {
                                worksheet.Cells[1, col].Value = property.DisplayName;
                                col++;
                            }
                        }

                        int row = 2;
                        foreach (var item in list)
                        {
                            worksheet.Cells[row, 1].Value = item.MateCode;
                            worksheet.Cells[row, 2].Value = item.MateName;
                            worksheet.Cells[row, 3].Value = item.TypeName;
                            worksheet.Cells[row, 4].Value = item.MaterialSpec;
                            worksheet.Cells[row, 5].Value = item.MaterialUnits;
                            worksheet.Cells[row, 6].Value = item.IsSelfBuild ? "是" : "否";
                            worksheet.Cells[row, 7].Value = item.IdCodeSingle ? "是" : "否";
                            worksheet.Cells[row, 8].Value = item.TradeName;

                            worksheet.Cells[row, 9].Value = string.Format("{0:#,##0.00}", item.MaterialPrice);
                            worksheet.Cells[row, 9].Style.HorizontalAlignment = ExcelHorizontalAlignment.Right;

                            worksheet.Cells[row, 10].Value = (item.AuditState == 1) ? "是" : "否";
                            worksheet.Cells[row, 11].Value = (item.AuditState == 1) ? string.Format("{0:yyyy-MM-dd HH:mm:ss}", item.AuditTime) : string.Empty;
                            worksheet.Cells[row, 12].Value = item.IsDisable ? "禁用" : "启用";

                            // 自定义属性
                            var options = item.Properties;
                            if (options?.Any() ?? false)
                            {
                                var col = 13;
                                foreach (var option in options)
                                {
                                    worksheet.Cells[row, col].Value = option.OptionName;
                                    col++;
                                }
                            }

                            row++;
                        }

                        worksheet.View.FreezePanes(2, 1);
                        worksheet.Cells.AutoFitColumns();

                        package.Save();
                    }

                    string ossEndpoint        = "http://oss-cn-hangzhou.aliyuncs.com";
                    string ossAccessKeyId     = "LTAIFAiipRXidbYT";
                    string ossAccessKeySecret = "62zh9kaAd60NAqMxNPCqVcvxhNxH0H";
                    string ossBucketName      = "basichz";
                    string ossRootFolder      = "productcenter";
                    string ossAccessUrl       = "//oss.lunz.cn/";
                    var    fileManager        = new OssFileManager(ossEndpoint, ossAccessKeyId, ossAccessKeySecret, ossBucketName, ossRootFolder, ossAccessUrl);

                    // 上传至阿里云
                    var uploadResult = fileManager.Upload(file.Name.Trim(), $@"{path}\{file.Name.Trim()}");

                    // 返回阿里云Url地址
                    var url = $@"http://basichz.lunz.cn/{uploadResult.Key}";

                    file.Refresh();
                    var resource = new ResourceItem
                    {
                        FileName   = fileName,
                        FileType   = file.Extension, // .xlsx
                        FileLength = Convert.ToInt32(Math.Ceiling(file.Length / 1024.0)),
                        FileURL    = url,
                    };

                    using (var scope = _databaseScopeFactory.CreateWithTransaction())
                    {
                        await _repository.AddResourceAsync(resource, request.UserId);

                        scope.SaveChanges();
                    }

                    // 删除文件夹
                    DirectoryInfo directory = new DirectoryInfo(path);
                    if (directory.Exists)
                    {
                        directory.Delete(true);
                    }
                }

                return(ResponseResult.Ok());
            }