承接 leyton/clevexport 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

leyton/clevexport

Composer 安装命令:

composer require leyton/clevexport

包简介

A Clever mechanism to export large data asynchronously

README 文档

README

Async Excel export for large Laravel datasets -- chunked, queued, and crash-free.

License Stars PHP Laravel

Table of Contents

Motivation

The goal of this Laravel package is to execute the exportation to EXCEL large data/records that may cause in the crash of the server or a timeout. The idea is to divide the process in sub operations managable and easy to perform.

Installation

compose require leyton/clevexport

After the installation make sure to publish the assets

php artisan vendor:publish --provider="Leyton\ClevExportServiceProvider"

You will find the config/clevexport.php file containing all the configurations needed.

return [
    // array of listeners that will be executed once the execution is done
    'listeners' => [], 
    
    // if you want to stock the user who started the export
    'with_owner' => true,
    
    // the guard    
    'guard' => 'web',
    
    // the foreign key name in the exports table
    'owner_id' => 'user_id',
    
    // The Authenticable class
    'owner_class' => \App\Models\User:class,
    
    // Number of chunks
    'chunks' => 10,
];

Then you can run your migration

php artisan migrate

Usage

The QueryFinder should be provided with an instance of an object that implements the IseExportable Interface

 $dossierExporter = QueryFinder::getInstance($this->defaultDossierService, $this->transformer);

 PreparingExportJob::dispatch($dossierExporter, $request->all())->delay(now()->addSecond());

A second Parameter is optional and if is provided it should implement the ShouldHandleResult It is where you can perform extra work on the results and provide the headers in a ExportTransformed container If the second parameter is not provided then the headers will be the column names selected from the query.

Exportable

class UserExportable implements IsExportable
{

    /**
     * @param array $params
     * @return Builder
     */
    public function query(array $params): Builder
    {
        return  User::select('id', 'name', 'email')
            ->addSelect([
                'title' => Post::selectRaw('SUBSTRING(`content`, 1, 10) as `title`')->limit(1)
            ]);
    }
}

Transformer

class UserTransformer implements ShouldHandleResult
{

    public function transform($data): ExportTransformed
    {
        $data =   $data->map(function(User $user){
            $user->most_commented = optional($user->posts()->withCount('comments')->first())->comments_count;
            $user->comments_count = $user->comments()->count();
            $user->posts_count = $user->posts()->count();
            return $user;
        });

        return  new ExportTransformed(['id', 'name', 'email', 'title', 'Most commented', 'Comments count', 'Posts count'], $data->toArray());
    }
}

License

This project is licensed under the Apache 2.0 License - see the LICENSE file for details.

Built with care by Leyton CognitX

leyton/clevexport 适用场景与选型建议

leyton/clevexport 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 14 次下载、GitHub Stars 达 49, 最近一次更新时间为 2022 年 03 月 10 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 leyton/clevexport 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 leyton/clevexport 我们能提供哪些服务?
定制开发 / 二次开发

基于 leyton/clevexport 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 14
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 52
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 49
  • Watchers: 4
  • Forks: 5
  • 开发语言: PHP

其他信息

  • 授权协议: Apache-2.0
  • 更新时间: 2022-03-10