mirror of
https://github.com/lkddi/nexusphp.git
synced 2026-04-24 03:57:22 +08:00
attendance card
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use App\Models\Attendance;
|
||||
use App\Repositories\AttendanceRepository;
|
||||
use Illuminate\Console\Command;
|
||||
|
||||
class AttendanceCleanup extends Command
|
||||
@@ -33,39 +34,16 @@ class AttendanceCleanup extends Command
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$query = Attendance::query()->groupBy('uid')->selectRaw('uid, max(id) as max_id');
|
||||
$page = 1;
|
||||
$size = 10000;
|
||||
while (true) {
|
||||
$rows = $query->forPage($page, $size)->get();
|
||||
$log = "sql: " . last_query() . ", count: " . $rows->count();
|
||||
do_log($log);
|
||||
$this->info($log);
|
||||
if ($rows->isEmpty()) {
|
||||
$log = "no more data....";
|
||||
do_log($log);
|
||||
$this->info($log);
|
||||
break;
|
||||
}
|
||||
foreach ($rows as $row) {
|
||||
do {
|
||||
$deleted = Attendance::query()
|
||||
->where('uid', $row->uid)
|
||||
->where('id', '<', $row->max_id)
|
||||
->limit(10000)
|
||||
->delete();
|
||||
$log = "delete: $deleted by sql: " . last_query();
|
||||
do_log($log);
|
||||
$this->info($log);
|
||||
} while ($deleted > 0);
|
||||
}
|
||||
$page++;
|
||||
}
|
||||
return 0;
|
||||
$rep = new AttendanceRepository();
|
||||
$result = $rep->cleanup();
|
||||
$log = sprintf(
|
||||
'[%s], %s, result: %s',
|
||||
nexus()->getRequestId(), __METHOD__, var_export($result, true)
|
||||
);
|
||||
$this->info($log);
|
||||
do_log($log);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user