Schedule.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | Niucloud-admin 企业快速开发的saas管理平台
  4. // +----------------------------------------------------------------------
  5. // | 官方网址:https://www.niucloud.com
  6. // +----------------------------------------------------------------------
  7. // | niucloud团队 版权所有 开源版本可自由商用
  8. // +----------------------------------------------------------------------
  9. // | Author: Niucloud Team
  10. // +----------------------------------------------------------------------
  11. namespace app\adminapi\controller\sys;
  12. use app\dict\schedule\ScheduleDict;
  13. use app\service\admin\schedule\ScheduleService;
  14. use core\base\BaseAdminController;
  15. use think\Response;
  16. /**
  17. * 自动任务
  18. */
  19. class Schedule extends BaseAdminController
  20. {
  21. /**
  22. * 任务列表
  23. * @return Response
  24. */
  25. public function lists()
  26. {
  27. $data = $this->request->params([
  28. ['key', ''],
  29. ['status', 'all'],
  30. ]);
  31. return success(data: (new ScheduleService())->getPage($data));
  32. }
  33. /**
  34. * 计划任务模板
  35. * @return Response
  36. */
  37. public function template()
  38. {
  39. return success(data: (new ScheduleService())->getTemplateList());
  40. }
  41. /**
  42. * 获取任务模式
  43. * @return Response
  44. */
  45. public function getType()
  46. {
  47. return success(data: ScheduleDict::getType());
  48. }
  49. /**
  50. * 详情
  51. * @param int $id
  52. * @return Response
  53. */
  54. public function info(int $id)
  55. {
  56. return success((new ScheduleService())->getInfo($id));
  57. }
  58. /**
  59. * 添加
  60. * @return Response
  61. */
  62. public function add()
  63. {
  64. $data = $this->request->params([
  65. ['key', '', false],
  66. ['time', []],
  67. ['status', ScheduleDict::OFF],
  68. ]);
  69. $this->validate($data, 'app\validate\sys\Schedule.add');
  70. (new ScheduleService())->add($data);
  71. return success('ADD_SUCCESS');
  72. }
  73. /**
  74. * 编辑
  75. * @param int $id
  76. * @return Response
  77. */
  78. public function edit(int $id)
  79. {
  80. $data = $this->request->params([
  81. // [ 'key', '' ],
  82. ['time', []],
  83. ['status', ScheduleDict::OFF],
  84. ]);
  85. (new ScheduleService())->edit($id, $data);
  86. return success('EDIT_SUCCESS');
  87. }
  88. /**
  89. * 启用或关闭
  90. * @param int $id
  91. * @return Response
  92. */
  93. public function modifyStatus(int $id)
  94. {
  95. $data = $this->request->params([
  96. ['status', ScheduleDict::OFF],
  97. ]);
  98. (new ScheduleService())->modifyStatus($id, $data['status']);
  99. return success('EDIT_SUCCESS');
  100. }
  101. /**
  102. * 删除
  103. * @param int $id
  104. * @return Response
  105. */
  106. public function del(int $id)
  107. {
  108. (new ScheduleService())->del($id);
  109. return success('DELETE_SUCCESS');
  110. }
  111. /**
  112. * 时间间隔类型
  113. * @return Response
  114. */
  115. public function getDateType()
  116. {
  117. return success(data: ScheduleDict::getDateType());
  118. }
  119. /**
  120. * 执行一次任务
  121. * @param int $id
  122. * @return Response
  123. */
  124. public function doSchedule(int $id)
  125. {
  126. $res = (new ScheduleService())->doSchedule($id);
  127. if ($res) {
  128. return success('SUCCESS');
  129. } else {
  130. return fail('FAIL');
  131. }
  132. }
  133. }