TaskResetLogRepository.php 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. <?php
  2. namespace App\Module\Task\Repositorys;
  3. use App\Module\Task\Models\TaskResetLog;
  4. use Dcat\Admin\Repositories\EloquentRepository;
  5. /**
  6. * 任务重置日志数据仓库类
  7. *
  8. * 提供任务重置日志数据的访问和操作功能。
  9. * 该类是任务重置日志模块与后台管理系统的桥梁,用于处理任务重置日志数据的CRUD操作。
  10. */
  11. class TaskResetLogRepository extends EloquentRepository
  12. {
  13. /**
  14. * 关联的Eloquent模型类
  15. *
  16. * @var string
  17. */
  18. protected $eloquentClass = TaskResetLog::class;
  19. /**
  20. * 获取最近的任务重置日志
  21. *
  22. * @param string|null $resetType 重置类型
  23. * @param int $limit 限制数量
  24. * @return array 任务重置日志列表
  25. */
  26. public function getRecentResetLogs(?string $resetType = null, int $limit = 100): array
  27. {
  28. $query = $this->eloquentClass::query();
  29. if ($resetType) {
  30. $query->where('reset_type', $resetType);
  31. }
  32. return $query->orderBy('reset_time', 'desc')
  33. ->limit($limit)
  34. ->get()
  35. ->toArray();
  36. }
  37. /**
  38. * 获取特定时间段内的任务重置日志
  39. *
  40. * @param string $startDate 开始日期
  41. * @param string $endDate 结束日期
  42. * @return array 任务重置日志列表
  43. */
  44. public function getResetLogsByDateRange(string $startDate, string $endDate): array
  45. {
  46. return $this->eloquentClass::whereBetween('reset_time', [$startDate, $endDate])
  47. ->orderBy('reset_time', 'desc')
  48. ->get()
  49. ->toArray();
  50. }
  51. /**
  52. * 获取最后一次特定类型的任务重置日志
  53. *
  54. * @param string $resetType 重置类型
  55. * @return TaskResetLog|null 任务重置日志对象
  56. */
  57. public function getLastResetLog(string $resetType): ?TaskResetLog
  58. {
  59. return $this->eloquentClass::where('reset_type', $resetType)
  60. ->orderBy('reset_time', 'desc')
  61. ->first();
  62. }
  63. }