<?php

namespace App\Console\Commands;

use App\Facades\Servers\Logs\Log;
use App\Models\DrugReportInfo;
use App\Servers\UpdateDrugReportService;
use Carbon\Carbon;
use Illuminate\Console\Command;

class UpdateDrugReportAssCommand extends Command
{
    protected $signature = 'update-drug-report-ass';

    protected $description = '同步药检报告数据';
    public function __construct()
    {
        parent::__construct();
    }
    public function handle(UpdateDrugReportService $service): int
    {
        echo "开始同步药检报告数据...", PHP_EOL;
        $endDateTime    = cache('increment:drug:ass:time');
        if (!$endDateTime){
            $endTime = time();
        }else{
            $endTime = strtotime($endDateTime);
        }
        $startTime  = ($endTime - 86400 * 30);
        $startTime  = date('Y-m-d H:i:s', $startTime);
        $endTime    = date('Y-m-d H:i:s', $endTime);
        $page       = 1;
        $pageSize   = 20;
        Log::info('update-drug-report-ass','更新同步开始', ['startTime'=>$startTime, 'endTime'=>$endTime]);
        $data       = $service->syncDrugReport($startTime, $endTime, $page, $pageSize);
        Log::info('update-drug-report-ass','更新同步结束'. "，共{$data['count']}，处理 {$data['total']} 条记录！", ['startTime'=>$startTime, 'endTime'=>$endTime]);
        echo "共{$data['count']}，处理 {$data['total']} 条记录！", PHP_EOL;

        return 0;
    }

}
