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));
});
}
}