diff --git a/app/command/Crontab.php b/app/command/Crontab.php new file mode 100644 index 0000000..c65fa33 --- /dev/null +++ b/app/command/Crontab.php @@ -0,0 +1,87 @@ +setName('crontab') + ->setDescription('定时任务'); + } + + protected function execute(Input $input, Output $output) + { + $lists = CrontabModel::where('status', CrontabEnum::START)->select()->toArray(); + if (empty($lists)) { + return false; + } + $time = time(); + foreach ($lists as $item) { + if (empty($item['last_time'])) { + $lastTime = (new CronExpression($item['expression'])) + ->getNextRunDate() + ->getTimestamp(); + CrontabModel::where('id', $item['id'])->update([ + 'last_time' => $lastTime, + ]); + continue; + } + + $nextTime = (new CronExpression($item['expression'])) + ->getNextRunDate($item['last_time']) + ->getTimestamp(); + if ($nextTime > $time) { + // 未到时间,不执行 + continue; + } + // 开始执行 + self::start($item); + } + } + + public static function start($item) + { + // 开始执行 + $startTime = microtime(true); + try { + $params = explode(' ', $item['params']); + if (is_array($params) && !empty($item['params'])) { + Console::call($item['command'], $params); + } else { + Console::call($item['command']); + } + // 清除错误信息 + CrontabModel::where('id', $item['id'])->update(['error' => '']); + } catch (\Exception $e) { + // 记录错误信息 + CrontabModel::where('id', $item['id'])->update([ + 'error' => $e->getMessage(), + 'status' => CrontabEnum::ERROR + ]); + } finally { + $endTime = microtime(true); + // 本次执行时间 + $useTime = round(($endTime - $startTime), 2); + // 最大执行时间 + $maxTime = max($useTime, $item['max_time']); + // 更新最后执行时间 + CrontabModel::where('id', $item['id'])->update([ + 'last_time' => time(), + 'time' => $useTime, + 'max_time' => $maxTime + ]); + } + } +} \ No newline at end of file diff --git a/app/controller/admin/system/CacheController.php b/app/controller/admin/system/CacheController.php new file mode 100644 index 0000000..6199b2c --- /dev/null +++ b/app/controller/admin/system/CacheController.php @@ -0,0 +1,23 @@ +withSearch([], [ + + ]); + + $paginate = CurdService::getPaginate($this->request, $model); + + return $this->writeSuccess('success', $paginate); + } +} \ No newline at end of file diff --git a/app/controller/admin/system/CacheDataController.php b/app/controller/admin/system/CacheDataController.php new file mode 100644 index 0000000..2bca63d --- /dev/null +++ b/app/controller/admin/system/CacheDataController.php @@ -0,0 +1,23 @@ +withSearch([], [ + + ]); + + $paginate = CurdService::getPaginate($this->request, $model); + + return $this->writeSuccess('success', $paginate); + } +} \ No newline at end of file diff --git a/app/controller/admin/system/ConfigController.php b/app/controller/admin/system/ConfigController.php new file mode 100644 index 0000000..a703458 --- /dev/null +++ b/app/controller/admin/system/ConfigController.php @@ -0,0 +1,23 @@ +withSearch([], [ + + ]); + + $paginate = CurdService::getPaginate($this->request, $model); + + return $this->writeSuccess('success', $paginate); + } +} \ No newline at end of file diff --git a/app/controller/admin/system/DictionaryController.php b/app/controller/admin/system/DictionaryController.php index 347f220..867f3ed 100644 --- a/app/controller/admin/system/DictionaryController.php +++ b/app/controller/admin/system/DictionaryController.php @@ -4,9 +4,7 @@ namespace app\controller\admin\system; use app\BaseController; use app\entity\SysDictionary; -use app\entity\SysDictionaryData; use app\service\CurdService; -use think\db\exception\DbException; use think\response\Json; class DictionaryController extends BaseController diff --git a/app/entity/SysConfig.php b/app/entity/SysConfig.php new file mode 100644 index 0000000..9047fe4 --- /dev/null +++ b/app/entity/SysConfig.php @@ -0,0 +1,14 @@ +name("admin.LoginCaptcha"); Route::post("login", [auth\LoginController::class, "index"])->name("admin.SysUserLogin")->middleware([ClientMiddleware::class]); + + Route::group(function () { @@ -34,18 +40,39 @@ Route::group("adminapi", function () { Route::get("user", [auth\AuthController::class, "user"])->name("admin.SysUserInfo"); }); - /* - * 系统文件管理 - */ - Route::get('file/page', [FileController::class, "page"])->name("system.pageFiles"); - Route::delete('file/remove/batch', [FileController::class, "batchRemove"])->name("system.batchRemoveFile"); + + Route::group("file", function () { + /* + * 文件管理 + */ + Route::get('page', [FileController::class, "page"])->name("system.pageFiles"); + Route::delete('remove/batch', [FileController::class, "batchRemove"])->name("system.batchRemoveFile"); + })->name('文件接口'); Route::group("system", function () { Route::get('login-record/page', [LoginRecordController::class, "page"])->name("system.pageLoginRecords"); Route::get('operate-record/page', [OperateRecordController::class, "page"])->name("system.pageOperateRecords"); Route::get('request-record/page', [RequestRecordController::class, "page"])->name("system.pageRequestRecords"); - + /* + * 缓存管理 + */ + Route::get('cache', [CacheController::class, "list"])->name("system.listCache"); + Route::put('cache', [CacheController::class, "update"])->name("system.updateCache"); + /* + * 缓存数据管理 + */ + Route::get('cache-data', [CacheDataController::class, "list"])->name("system.listCacheData"); + Route::delete('cache-data/batch', [CacheDataController::class, "batchDelete"])->name("system.batchRemoveCacheData"); + Route::put('cache-data', [CacheDataController::class, "update"])->name("system.updateCacheData"); + /* + * 配置管理 + */ + Route::get('config', [ConfigController::class, "list"])->name("system.listConfig"); + Route::post("config", [UserController::class, "add"])->name("system.addConfig"); + Route::put("config$", [UserController::class, "update"])->name("system.updateConfig"); + Route::delete("config", [UserController::class, "delete"])->name("system.deleteConfig"); + Route::put("config/cache", [UserController::class, "cache"])->name("system.cacheConfig"); /* * 用户管理 */