<?php

namespace App\Console\Commands;

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

class IncrementSyncDrugReportAssCommand extends Command
{
    protected $signature = 'increment-drug-report-ass';

    protected $description = '增量同步上游出库单数据';

    public function handle(IncrementDrugReportAssService $service): int
    {
        Log::info('increment_drug','增量同步开始');
        $startTime      = cache('increment:drug:ass:time');
        if (empty($startTime)){
            $startTime = Carbon::now()->startOfDay();
        }
        $source = 'querydrugreportass';
        $endTime = Carbon::now();
        Log::info('increment_drug','增量同步开始', ['startTime'=>$startTime, 'endTime'=>$endTime]);
        $page = 1;
        $pageSize = 20;
        $data = $service->syncDrugReport($source, $startTime, $endTime, $page, $pageSize);
        Log::info('increment_drug','增量同步结束'. "，共{$data['total_num']}，处理 {$data['total']} 条记录！", ['startTime'=>$startTime, 'endTime'=>$endTime]);
        cache(['increment:drug:ass:time'=>$endTime]);
        return 0;
    }

}
