Commit c701e9b9 authored by zhangdongying's avatar zhangdongying
Browse files

feat: 全局日志组件编写

parent ac71db42
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -87,6 +87,7 @@ class AppOperateLogService
    )
    {
        return $this->operateLogService->addOperateLog(
            make(RequestInterface::class)->header('hwq-request-id', ''),
            $this->config->get('app_name'),
            Auth::id() ?? 0,
            Auth::user()['name'] ?? '',
@@ -105,6 +106,7 @@ class AppOperateLogService
    /**
     * 添加系统操作日志
     *
     * @param string $requestId 请求ID
     * @param string $action 方法全路径
     * @param string $tableName 表名
     * @param string $recordId 记录ID
@@ -128,6 +130,7 @@ class AppOperateLogService
    )
    {
        return $this->operateLogService->addOperateLog(
            '',
            $this->config->get('app_name'),
            0,
            'system',
+8 −5
Original line number Diff line number Diff line
@@ -49,19 +49,19 @@ class OperateLogService
    }

    /**
     * 将数组转换成JSON
     * 生成唯一ID
     *
     * @param array $array 数组
     * @return string
     */
    public static function encodeArrayToJson(array $array): string
    public static function generateUniqueId(): string
    {
        return json_encode($array, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
        return sha1(uniqid('', true) . mt_rand(10000, 99999));
    }

    /**
     * 添加操作日志
     *
     * @param string $requestId 请求ID
     * @param string $appName 项目名称
     * @param int $operatorId 操作人ID
     * @param string $operatorName 操作人名称
@@ -78,6 +78,7 @@ class OperateLogService
     * @throws \Exception
     */
    public function addOperateLog(
        string $requestId,
        string $appName,
        int $operatorId,
        string $operatorName,
@@ -93,6 +94,8 @@ class OperateLogService
    ): bool
    {
        $data = [
            'log_sn'        => self::generateUniqueId(),
            'request_id'    => $requestId,
            'app_name'      => $appName,
            'operator_id'   => $operatorId,
            'operator_name' => $operatorName,
@@ -108,6 +111,6 @@ class OperateLogService
            'created_at'    => date('Y-m-d H:i:s'),
        ];

        return (bool)$this->queueService->push($this->queue, self::encodeArrayToJson($data));
        return (bool)$this->queueService->push($this->queue, json_encode($data));
    }
}
 No newline at end of file
+0 −12
Original line number Diff line number Diff line
@@ -42,16 +42,4 @@ class RedisQueueService
    {
        return $this->redis->lPush($queue, $data);
    }

    /**
     * 从队列阻塞拉取
     *
     * @param string $queue 队列名称
     * @return int $timeout 超时秒数
     * @throws \Exception
     */
    public function blockPop(string $queue, int $timeout)
    {
        return $this->redis->brPop($queue, $timeout);
    }
}
 No newline at end of file