| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071 |
- <?php
- namespace App\Module\Task\Repositorys;
- use App\Module\Task\Models\TaskResetLog;
- use Dcat\Admin\Repositories\EloquentRepository;
- /**
- * 任务重置日志数据仓库类
- *
- * 提供任务重置日志数据的访问和操作功能。
- * 该类是任务重置日志模块与后台管理系统的桥梁,用于处理任务重置日志数据的CRUD操作。
- */
- class TaskResetLogRepository extends EloquentRepository
- {
- /**
- * 关联的Eloquent模型类
- *
- * @var string
- */
- protected $eloquentClass = TaskResetLog::class;
-
- /**
- * 获取最近的任务重置日志
- *
- * @param string|null $resetType 重置类型
- * @param int $limit 限制数量
- * @return array 任务重置日志列表
- */
- public function getRecentResetLogs(?string $resetType = null, int $limit = 100): array
- {
- $query = $this->eloquentClass::query();
-
- if ($resetType) {
- $query->where('reset_type', $resetType);
- }
-
- return $query->orderBy('reset_time', 'desc')
- ->limit($limit)
- ->get()
- ->toArray();
- }
-
- /**
- * 获取特定时间段内的任务重置日志
- *
- * @param string $startDate 开始日期
- * @param string $endDate 结束日期
- * @return array 任务重置日志列表
- */
- public function getResetLogsByDateRange(string $startDate, string $endDate): array
- {
- return $this->eloquentClass::whereBetween('reset_time', [$startDate, $endDate])
- ->orderBy('reset_time', 'desc')
- ->get()
- ->toArray();
- }
-
- /**
- * 获取最后一次特定类型的任务重置日志
- *
- * @param string $resetType 重置类型
- * @return TaskResetLog|null 任务重置日志对象
- */
- public function getLastResetLog(string $resetType): ?TaskResetLog
- {
- return $this->eloquentClass::where('reset_type', $resetType)
- ->orderBy('reset_time', 'desc')
- ->first();
- }
- }
|