feat: 查询个人信息 后端.

This commit is contained in:
lijiahang
2023-11-02 17:19:27 +08:00
parent eafe69ebca
commit 0322729797
17 changed files with 211 additions and 57 deletions

View File

@@ -52,6 +52,8 @@ public enum ErrorCode implements CodeInfo {
OTHER_DEVICE_LOGIN(702, "该账号于 {} 已在其他设备登录 {}({})"),
SESSION_OFFLINE(703, "该账号于 {} 已被强制下线 {}({})"),
// -------------------- 自定义 - 通用 --------------------
NETWORK_FLUCTUATION(900, "当前环境网路波动"),

View File

@@ -0,0 +1,35 @@
package com.orion.ops.framework.common.entity;
import java.io.Serializable;
/**
* 请求身份
*
* @author Jiahang Li
* @version 1.0.0
* @since 2023/11/2 16:23
*/
public interface RequestIdentity extends Serializable {
/**
* 设置请求地址
*
* @param address address
*/
void setAddress(String address);
/**
* 设置请求位置
*
* @param location location
*/
void setLocation(String location);
/**
* 设置请求 userAgent
*
* @param userAgent userAgent
*/
void setUserAgent(String userAgent);
}

View File

@@ -0,0 +1,39 @@
package com.orion.ops.framework.common.utils;
import com.orion.ops.framework.common.entity.RequestIdentity;
import com.orion.web.servlet.web.Servlets;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
import java.util.Optional;
/**
* 请求工具类
*
* @author Jiahang Li
* @version 1.0.0
* @since 2023/11/2 16:26
*/
public class Requests {
private Requests() {
}
/**
* 填充请求信息
*
* @param identity identity
*/
public static void fillIdentity(RequestIdentity identity) {
Optional.ofNullable(RequestContextHolder.getRequestAttributes())
.map(s -> (ServletRequestAttributes) s)
.map(ServletRequestAttributes::getRequest)
.ifPresent(request -> {
String address = Servlets.getRemoteAddr(request);
identity.setAddress(address);
identity.setLocation(IpUtils.getLocation(address));
identity.setUserAgent(Servlets.getUserAgent(request));
});
}
}

View File

@@ -20,8 +20,7 @@ import com.orion.ops.framework.common.enums.BooleanBit;
import com.orion.ops.framework.common.meta.TraceIdHolder;
import com.orion.ops.framework.common.security.LoginUser;
import com.orion.ops.framework.common.security.SecurityHolder;
import com.orion.ops.framework.common.utils.IpUtils;
import com.orion.web.servlet.web.Servlets;
import com.orion.ops.framework.common.utils.Requests;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
@@ -31,8 +30,6 @@ import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
import org.springframework.web.multipart.MultipartFile;
import javax.annotation.Resource;
@@ -251,15 +248,11 @@ public class OperatorLogAspect {
*/
private void fillRequest(OperatorLogModel model) {
model.setTraceId(TraceIdHolder.get());
Optional.ofNullable(RequestContextHolder.getRequestAttributes())
.map(s -> (ServletRequestAttributes) s)
.map(ServletRequestAttributes::getRequest)
.ifPresent(request -> {
String address = Servlets.getRemoteAddr(request);
model.setAddress(address);
model.setLocation(IpUtils.getLocation(address));
model.setUserAgent(Strings.retain(Servlets.getUserAgent(request), operatorLogConfig.getUserAgentLength()));
});
// 填充请求信息
Requests.fillIdentity(model);
Optional.ofNullable(model.getUserAgent())
.map(s -> Strings.retain(s, operatorLogConfig.getUserAgentLength()))
.ifPresent(model::setUserAgent);
}
/**

View File

@@ -1,5 +1,6 @@
package com.orion.ops.framework.biz.operator.log.core.model;
import com.orion.ops.framework.common.entity.RequestIdentity;
import lombok.Data;
import java.util.Date;
@@ -12,7 +13,7 @@ import java.util.Date;
* @since 2023/10/9 18:44
*/
@Data
public class OperatorLogModel {
public class OperatorLogModel implements RequestIdentity {
/**
* userId