<?php

namespace App\Console\Commands;

use App\Servers\SignedDrugReportService;
use Carbon\Carbon;
use Illuminate\Console\Command;
use App\Facades\Servers\Logs\Log;

class SignedSyncDrugReportCommand extends Command
{
    protected $signature = 'drug-report-signed';

    protected $description = '查询一段时间内已经签收的单据 同步更新药检报告数据';

    public function handle(SignedDrugReportService $service): int
    {
        Log::info('drug-report-signed','已经签收同步开始');
        $startTime      = cache('drug:report:signed:time');
        if (empty($startTime)){
            $startTime = Carbon::now()->startOfDay();
        }
        $endTime = date('Y-m-d H:i:s', time());
        $page = 1;
        $pageSize = 20;
        Log::info('drug-report-signed','已经签收同步开始', ['startTime'=>$startTime, 'endTime'=>$endTime]);
        $count = $service->syncDrugReport( $startTime, $endTime, $page, $pageSize);
        cache(['drug:report:signed:time'=>$endTime]);
        Log::info('drug-report-signed','已经签收同步结束:'.$count, ['startTime'=>$startTime, 'endTime'=>$endTime]);

        return 0;
    }

}
