refactor: 完善日志记录处理
This commit is contained in:
@@ -4,6 +4,8 @@ declare (strict_types = 1);
|
|||||||
namespace app\admin\middleware\v1;
|
namespace app\admin\middleware\v1;
|
||||||
|
|
||||||
use app\admin\model\v1\SysOperateLog;
|
use app\admin\model\v1\SysOperateLog;
|
||||||
|
use app\admin\model\v1\SysRestfulApiModel;
|
||||||
|
use think\facade\Cache;
|
||||||
|
|
||||||
class OperateLog
|
class OperateLog
|
||||||
{
|
{
|
||||||
@@ -18,9 +20,19 @@ class OperateLog
|
|||||||
{
|
{
|
||||||
$response = $next($request);
|
$response = $next($request);
|
||||||
|
|
||||||
|
$restful_api_name_map = Cache::get('sys_restful_api:map:name');
|
||||||
|
if (empty($restful_api_name_map)) {
|
||||||
|
$restful_api_name_map = [];
|
||||||
|
$restful_api = SysRestfulApiModel::cache('sys_restful_api')->select();
|
||||||
|
foreach ($restful_api as $item) {
|
||||||
|
$restful_api_name_map[$item['method'] . '-' . $item['layer'] . '.' . $item['controller'] . '/' . $item['action']] = $item['name'];
|
||||||
|
}
|
||||||
|
Cache::set('sys_restful_api:map:name', $restful_api_name_map);
|
||||||
|
}
|
||||||
|
|
||||||
$log = [
|
$log = [
|
||||||
'user_id' => $request->uid,
|
'user_id' => $request->uid,
|
||||||
'title' => '操作日志',
|
'title' => $restful_api_name_map[$request->method() . '-' . $request->controller() . '/' . $request->action()] ?? '',
|
||||||
'version' => $request->layer(),
|
'version' => $request->layer(),
|
||||||
'method' => $request->method(),
|
'method' => $request->method(),
|
||||||
'controller' => $request->controller(base: true),
|
'controller' => $request->controller(base: true),
|
||||||
|
|||||||
@@ -18,8 +18,11 @@ class SysRestfulApiBaseModel extends BaseModel
|
|||||||
// 字段信息
|
// 字段信息
|
||||||
protected $schema = [
|
protected $schema = [
|
||||||
'id' => 'int',
|
'id' => 'int',
|
||||||
'module' => 'string',
|
|
||||||
'name' => 'string',
|
'name' => 'string',
|
||||||
|
'module' => 'string',
|
||||||
|
'layer' => 'string',
|
||||||
|
'controller' => 'string',
|
||||||
|
'action' => 'string',
|
||||||
'rule' => 'string',
|
'rule' => 'string',
|
||||||
'method' => 'string',
|
'method' => 'string',
|
||||||
'desc' => 'string',
|
'desc' => 'string',
|
||||||
|
|||||||
@@ -29,8 +29,11 @@ class CreateSysRestfulApi extends Migrator
|
|||||||
public function change()
|
public function change()
|
||||||
{
|
{
|
||||||
$table = $this->table('sys_restful_api', ['engine' => 'MyISAM', 'collation' => 'utf8mb4_general_ci', 'comment' => '系统接口表']);
|
$table = $this->table('sys_restful_api', ['engine' => 'MyISAM', 'collation' => 'utf8mb4_general_ci', 'comment' => '系统接口表']);
|
||||||
$table->addColumn('module', 'string', ['limit' => 32, 'default' => '', 'comment' => '模块'])
|
$table->addColumn('name', 'string', ['limit' => 64, 'default' => '', 'comment' => '接口名称'])
|
||||||
->addColumn('name', 'string', ['limit' => 64, 'default' => '', 'comment' => '接口名称'])
|
->addColumn('module', 'string', ['limit' => 32, 'default' => '', 'comment' => '模块名'])
|
||||||
|
->addColumn('layer', 'string', ['limit' => 15, 'default' => '', 'comment' => '控制器分级名'])
|
||||||
|
->addColumn('controller', 'string', ['limit' => 64, 'default' => '', 'comment' => '控制器名'])
|
||||||
|
->addColumn('action', 'string', ['limit' => 64, 'default' => '', 'comment' => '方法名'])
|
||||||
->addColumn('rule', 'string', ['limit' => 128, 'default' => '', 'comment' => '接口路由'])
|
->addColumn('rule', 'string', ['limit' => 128, 'default' => '', 'comment' => '接口路由'])
|
||||||
->addColumn('method', 'string', ['limit' => 8, 'default' => '', 'comment' => '请求方式'])
|
->addColumn('method', 'string', ['limit' => 8, 'default' => '', 'comment' => '请求方式'])
|
||||||
->addColumn('desc', 'string', ['limit' => 255, 'default' => '', 'comment' => '接口描述'])
|
->addColumn('desc', 'string', ['limit' => 255, 'default' => '', 'comment' => '接口描述'])
|
||||||
|
|||||||
Reference in New Issue
Block a user