<?php

namespace App\Console\Commands;

use App\Imports\chatOrder;
use App\Imports\Docter\DocterInfo;
use App\Imports\Docter\DocterOrganizationInfo;
use App\Imports\Docter\OrganizationInfo;
use App\Imports\User\PatientsInfo;
use App\Imports\User\UserInfo;
use App\Models\Organization;
use Illuminate\Console\Command;
use Maatwebsite\Excel\Facades\Excel;
class ImportUser extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'import:importUser {type} {filepath}';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = '用户数据导入';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return mixed
     */
    public function handle()
    {
        $type = $this->argument('type');
        $file_path = $this->argument('filepath');
        //路径相对于项目根目录即 /public
        if(empty($type) || empty($file_path)){
            dd('请输入完整参数');
        }
        //用户信息导入
        if($type == 'user'){
            $this->makeUser($file_path);
        }
        if($type == 'patients'){
            $this->makePatients($file_path);
        }
    }
    //导入用户
    public function makeUser($file_path)
    {
        $this->importsUser($file_path);
    }
    public function importsUser($filePath)
    {
        $filePath = './public/import/' . $filePath . '.xlsx';
        Excel::import(new UserInfo(), $filePath);
    }
    //导入患者
    public function makePatients($file_path)
    {
        $this->importsPatients($file_path);
    }
    public function importsPatients($filePath)
    {
        $filePath = './public/import/' . $filePath . '.xlsx';
        Excel::import(new PatientsInfo(), $filePath);
    }
}
