Browse Source

请求日志增加系统分类字段

weijianghai 1 week ago
parent
commit
378ac3b48e

+ 27 - 0
scripts/restore-financialdb.ps1

@@ -0,0 +1,27 @@
+param (
+    [string]$backup_dir = $(throw "请提供备份目录作为第一个参数")
+)
+
+# 设置环境变量
+$env:PGPASSWORD = 'postgres'
+
+$host_ = '127.0.0.1'
+$port = '5432'
+$username = 'postgres'
+$dbname = 'financialdb'
+$jobs = '16'
+
+# 检查数据库是否存在
+$checkDbExists = psql -U $username -tA -c "SELECT 1 FROM pg_database WHERE datname='$dbname'" | Out-String
+
+if ($checkDbExists.Trim() -ne "1") {
+    Write-Output "数据库 $dbname 不存在,正在创建..."
+    createdb -U $username $dbname
+} else {
+    Write-Output "数据库 $dbname 已存在。"
+}
+
+# 执行 pg_restore
+Write-Output "开始从 $backup_dir 恢复数据库 $dbname..."
+
+pg_restore -O -c -v -h $host_ -p $port -U $username -d $dbname -Fd -j $jobs $backup_dir

+ 3 - 0
scripts/restore-financialdb.sh

@@ -7,4 +7,7 @@ port='5432'
 username='finance'
 dbname='financialdb'
 jobs='16'
+if [ "$(psql -U ${username} -tAc "SELECT 1 FROM pg_database WHERE datname='${dbname}'")" != "1" ]; then
+    createdb -U ${username} ${dbname}
+fi
 pg_restore -O -c -v -h "${host}" -p "${port}" -U "${username}" -d "${dbname}" -Fd -j "${jobs}" "${backup_dir}"

+ 4 - 0
src/main/java/com/nokia/finance/tasks/pojo/po/common/NginxLogPo.java

@@ -135,4 +135,8 @@ public class NginxLogPo {
      * 客户端IP地址
      */
     private String remoteAddr;
+    /**
+     * 系统类型
+     */
+    private String systemType;
 }

+ 0 - 65
src/main/java/com/nokia/finance/tasks/pojo/po/common/RequestLogPo.java

@@ -1,65 +0,0 @@
-package com.nokia.finance.tasks.pojo.po.common;
-
-import com.baomidou.mybatisplus.annotation.TableName;
-import lombok.Data;
-import lombok.NoArgsConstructor;
-
-import java.time.LocalDateTime;
-
-@NoArgsConstructor
-@Data
-@TableName("common.request_log")
-public class RequestLogPo {
-    /**
-     * 请求时间
-     */
-    private LocalDateTime requestTime;
-
-    /**
-     * 账号,从token解密
-     */
-    private String loginId;
-
-    /**
-     * 页面url,从token解密
-     */
-    private String pageUrl;
-
-    /**
-     * 接口url
-     */
-    private String api;
-
-    /**
-     * 请求参数
-     */
-    private String requestParameters;
-
-    /**
-     * 请求头
-     */
-    private String headers;
-
-    /**
-     * 应用id,从token解密
-     */
-    private String appId;
-
-    /**
-     * 时间戳,从token解密
-     */
-    private LocalDateTime timeStamp;
-
-    /**
-     * 访问令牌
-     */
-    private String token;
-    /**
-     * 过期秒数,从token解密
-     */
-    private Integer expireTime;
-    /**
-     * 过期时间
-     */
-    private LocalDateTime expireTimeStamp;
-}

+ 11 - 0
src/main/java/com/nokia/finance/tasks/service/common/NginxLogService.java

@@ -127,6 +127,17 @@ public class NginxLogService implements SmartLifecycle {
                                     po.setTimeStamp(timeStamp);
                                     po.setExpireTime(expireTime);
                                     po.setExpireTimeStamp(expireTimeStamp);
+                                    String systemType = "";
+                                    if (po.getUri().contains("house-car/house")) {
+                                        systemType = "house";
+                                    } else if (po.getUri().contains("house-car/car")) {
+                                        systemType = "car";
+                                    } else if (po.getPageUrl().contains("house-car/house")) {
+                                        systemType = "house";
+                                    } else if (po.getPageUrl().contains("house-car/car")) {
+                                        systemType = "car";
+                                    }
+                                    po.setSystemType(systemType);
                                     // 将日志对象插入数据库
                                     nginxLogDao.insert(po);
                                 }