承接 dandysi/laravel-batch-upload 相关项目开发

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

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

dandysi/laravel-batch-upload

Composer 安装命令:

composer require dandysi/laravel-batch-upload

包简介

A framework to help manage/automate/process data uploads (such as CSV), using your business logic

README 文档

README

A framework to help manage/automate/process data uploads (such as CSV), using your business logic. It has potential to be much more than just a databse update tool.

  • Scheduling - Define when you would like uploads to be processed
  • Validation - Add rules to ensure that data is valid before being processed and provide feedback on any failures
  • Configurable - Global or granular per processor
  • Headless - Create the frontend and approval process to suite your exact needs

Install

composer require dandysi/laravel-batch-upload

Config

php artisan vendor:publish --provider="Dandysi\Laravel\BatchUpload\BatchUploadServiceProvider"

Configure this package by changing the values in config/batch-upload.php.

Getting Started

The first step is to create a processor (an engine for processing row data). It is a simple PHP class and can be created with the following maker command:

php artisan make:batch-upload-processor CreateCategoriesProcessor create_categories

Add the processor to the config/batch-upload.php config file.

/**
 * Register processors here
 */
'processors' => [
    App\BatchUploads\CreateCategoriesProcessor::class
],

Define the columns/validation rules and implement code to handle the uploaded row data.

class CreateCategoriesProcessor implements ProcessorInterface
{
    public function config(): ProcessorConfig 
    {
        return ProcessorConfig::create()
            ->column('code', 'Code', 'required')
            ->column('name', 'Name', 'required')
        ;
    }

    public function __invoke(array $row): void
    {
        $category = Cagegory::create([
            'code' => $row['code'],
            'name' => $row['name]
        ]);

        //more than just a simple data upload as you can add any other business logic here
    }

Creating Batches

Ordinarily this would not be in one step, however the below outlines all the required stages.

use Dandysi\Laravel\BatchUpload\Services\BatchService;

//Step 1 - Create
$service = app(BatchService::class);
$options = $service->options('create_categories', '/data/categories.csv');

$batch = $service->create($options);

//Step 2 - Approve
$batch->status = Batch::STATUS_APPROVE;
$batch->save();

//Step 3 - Dispatch (each row will be a seperate queued job)
$service->dispatch($batch);

If validation errors occur, they will be recorded against each row and the status of the batch/row will reflect this.

Scheduled Batches

Schedule batches with an additional option and not performing step 3 above.

$options = $service
    ->options('create_categories', '/data/categories.csv')
    ->schedule(now()->tommorow())
;

To ensure scheduled batches are dispatched you will need to add a schedule command in the console kernel:

class Kernel extends ConsoleKernel
{
    /**
     * Define the application's command schedule.
     */
    protected function schedule(Schedule $schedule): void
    {
        $schedule->command('batch-upload:dispatch')->everyTenMinutes();
    }

or create your own cron entry to execute the following:

php artisan batch-upload:dispatch

User Batches

If your batches need to be identifiable by users, another option can be added during the creation step:

$options = $service
    ->options('create_categories', '/data/categories.csv')
    ->user('user123')
;

Console Commands

Create and dispatch a batch straight away:

php artisan batch-upload:create create_categories /data/categories.csv --force-dispatch

delay by minutes --delay=60 or indentify with a user --user=user123. Delays will require the schedule command/cron step outlined above to be in place.

License

Open-sourced software licensed under the MIT license.

dandysi/laravel-batch-upload 适用场景与选型建议

dandysi/laravel-batch-upload 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 6 次下载、GitHub Stars 达 0, 最近一次更新时间为 2024 年 02 月 05 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「php」 「upload」 「laravel」 「batch」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

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

围绕 dandysi/laravel-batch-upload 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-02-05