Alarm.php 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. <?php
  2. namespace App\Module\System\AdminMetrics;
  3. use UCore\DcatAdmin\Metrics\Sys\JobRun;
  4. use App\Console\Commands\GuidanceJisuan;
  5. use App\Module\Transfer\Enums\TStatus;
  6. use App\Module\Transfer\Enums\TType;
  7. use App\Module\Transfer\Model\TransferOrder;
  8. use Carbon\Carbon;
  9. use UCore\Helper\Cache;
  10. use UCore\Helper\Bc;
  11. use Illuminate\Http\Request;
  12. /**
  13. * 系统报警
  14. * Class Alarm
  15. *
  16. */
  17. class Alarm extends \UCore\DcatAdmin\Metrics\Examples\ListDataColor
  18. {
  19. protected $title = '运行情况';
  20. /**
  21. * 初始化卡片内容
  22. */
  23. protected function init()
  24. {
  25. parent::init();
  26. $this->title('运行情况');
  27. $this->chart = null;
  28. }
  29. protected function getData()
  30. {
  31. return Cache::cacheCall([ __CLASS__, __FUNCTION__, 2 ], function () {
  32. $now = time();
  33. $data = [];
  34. // Cron分钟的任务
  35. /**
  36. * @var \App\Module\Job\Model\JobRun $last
  37. */
  38. $last = \App\Module\Job\Model\JobRun::query()->where('queue', '=', 'Console')->orderByDesc('id')->first();
  39. if ($last) {
  40. $va = [
  41. 'title' => 'Cron分钟任务',
  42. 'value' => $last->created_at->format('H:i:s'),
  43. 'type' => self::TYPE_OK
  44. ];
  45. if ($now - $last->created_at->timestamp > 300) {
  46. $va['type'] = self::TYPE_ERROR;
  47. }
  48. if ($now - $last->created_at->timestamp > 60) {
  49. $va['type'] = self::TYPE_WARNING;
  50. }
  51. $data[] = $va;
  52. }
  53. $lastGJ = \App\Module\Job\Model\JobRun::query()
  54. ->where('queue', '=', 'Console')
  55. ->where('runclass', '=', GuidanceJisuan::class)
  56. ->orderByDesc('id')->first();
  57. if ($lastGJ) {
  58. $va = [
  59. 'title' => '计算指导价格',
  60. 'value' => $lastGJ->created_at->format('m-d H:i:s'),
  61. 'type' => self::TYPE_OK
  62. ];
  63. if ($now - $lastGJ->created_at->timestamp > (3600*24)) {
  64. $va['type'] = self::TYPE_ERROR;
  65. }
  66. $data[] = $va;
  67. }
  68. return $data;
  69. }, [], 10);
  70. }
  71. }