Compare commits

...

6 Commits

Author SHA1 Message Date
caozehui
0f5b7603b4 微调 2025-08-19 18:12:35 +08:00
1f41ef2d01 增加从requestUtil中获取登录名的方法,by accessToken 2025-08-05 20:46:54 +08:00
75cb5163f1 jwt增加用户登录名 2025-08-05 20:41:12 +08:00
c401f04bbe jwt增加用户登录名 2025-08-05 20:37:58 +08:00
f069a16e43 jwt增加用户登录名 2025-08-05 20:33:32 +08:00
caozehui
2454d84919 微调 2025-07-15 13:48:32 +08:00
5 changed files with 65 additions and 24 deletions

View File

@@ -43,6 +43,7 @@ public interface SecurityConstants {
* 认证成功后,返回信息包含的内容-
*/
String USER_ID = "userId";
String LOGIN_NAME = "loginName";
String USER_TYPE = "userType";
String USER_NAME_KEY = "name";
String USER_HEAD_KEY = "headSculpture";

View File

@@ -34,14 +34,15 @@ public class JwtUtil {
*/
private final static String JWT_ISS = "NJCN";
public static String getAccessToken(String userId) {
public static String getAccessToken(String userId,String loginName) {
Map<String, Object> headers = new HashMap<>();
headers.put("typ", "JWT");
headers.put("alg", "HS256");
Map<String, Object> payload = new HashMap<>();
payload.put(SecurityConstants.USER_ID, userId);
payload.put(SecurityConstants.LOGIN_NAME, loginName);
// 永不过期
payload.put("exp", Instant.now().plusSeconds(DAY_SECOND * Integer.MAX_VALUE).getEpochSecond());
payload.put("exp", 4910070710L);
payload.put("sub", SUBJECT);
payload.put("iss", JWT_ISS);
payload.put("iat", Instant.now().getEpochSecond());

View File

@@ -17,8 +17,10 @@ import org.springframework.web.multipart.MultipartFile;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.URLEncoder;
import java.util.Collection;
import java.util.List;
@@ -115,6 +117,26 @@ public class ExcelUtil {
}
}
/**
* 指定名称、sheet名多个sheet、数据多组数据导出数据到本地
*
* @param path 文件路径
* @param fileName 文件名
* @param sheetsList
*/
public static void saveExcel(String path, String fileName, List<Map<String, Object>> sheetsList) {
String filePath = path + "\\" + fileName;
try {
OutputStream outputStream = new FileOutputStream(filePath);
Workbook workbook = ExcelExportUtil.exportExcel(sheetsList, ExcelType.XSSF);
workbook.write(outputStream);
outputStream.flush();
outputStream.close();
} catch (IOException e) {
log.error(">>> 导出数据异常:{}", e.getMessage());
}
}
/**
* 指定名称、数据下载报表(带指定标题将*显示比必填信息),带有下拉信息
@@ -158,13 +180,11 @@ public class ExcelUtil {
//没有表格标题,只有表格头
for (int i = 0; i < headerRowNumber; i++) {
//获取列数
int physicalNumberOfCells = sheetAt.getRow(i).getPhysicalNumberOfCells();
//获取行
Row row = sheetAt.getRow(i);
if (Objects.isNull(row)) {
continue;
}
for (int j = 0; j < physicalNumberOfCells; j++) {
for (int j = row.getFirstCellNum(); j < row.getLastCellNum(); j++) {
//获取单元格对象
Cell cell = row.getCell(j);
//获取单元格样式对象

View File

@@ -39,7 +39,8 @@ public class HttpResultUtil {
* 业务异常组装结果集
*/
public static <T> HttpResult<T> assembleBusinessExceptionResult(BusinessException businessException, T result, String methodDescribe) {
return assembleResult(businessException.getCode(), result, StrFormatter.format("{}{}{}", methodDescribe, StrUtil.C_COMMA, businessException.getMessage()));
// return assembleResult(businessException.getCode(), result, StrFormatter.format("{}{}{}", methodDescribe, StrUtil.C_COMMA, businessException.getMessage()));
return assembleResult(businessException.getCode(), result, businessException.getMessage());
}
}

View File

@@ -65,15 +65,15 @@ public class RequestUtil {
*
* @return 若成功返回当前登录用户的ID若失败返回null
*/
public static String getUserId(ServerHttpRequest serverHttpRequest) {
String accessToken = getAccessToken(serverHttpRequest);
String userId = null;
if (StrUtil.isNotBlank(accessToken)) {
Map<String, Object> map = JwtUtil.parseToken(accessToken);
userId = (String) map.get(SecurityConstants.USER_ID);
}
return userId;
}
// public static String getUserId(ServerHttpRequest serverHttpRequest) {
// String accessToken = getAccessToken(serverHttpRequest);
// String userId = null;
// if (StrUtil.isNotBlank(accessToken)) {
// Map<String, Object> map = JwtUtil.parseToken(accessToken);
// userId = (String) map.get(SecurityConstants.USER_ID);
// }
// return userId;
// }
/**
* 获取当前登录用户的ID
@@ -90,6 +90,33 @@ public class RequestUtil {
return userId;
}
/**
* 获取当前登录用户的ID
*
* @return 若成功返回当前登录用户的ID若失败返回null
*/
public static String getLoginNameByToken() {
String accessToken = getAccessToken();
String loginName = null;
if (StrUtil.isNotBlank(accessToken)) {
Map<String, Object> map = JwtUtil.parseToken(accessToken);
loginName = (String) map.get(SecurityConstants.LOGIN_NAME);
}
return StrUtil.isBlank(loginName) ? LogInfo.UNKNOWN_USER : loginName;
}
/**
* 获取用户登录名称
* 该方法通常用于未登录阶段无token信息
*/
public static String getLoginName() {
HttpServletRequest request = HttpServletUtil.getRequest();;
String loginName = (String) request.getAttribute(SecurityConstants.AUTHENTICATE_USERNAME);
return StrUtil.isBlank(loginName) ? LogInfo.UNKNOWN_USER : loginName;
}
/**
* 获取当前登录用户的用户名
*
@@ -106,15 +133,6 @@ public class RequestUtil {
}
/**
* 获取用户登录名称
* 该方法通常用于未登录阶段无token信息
*/
public static String getLoginName() {
HttpServletRequest request = HttpServletUtil.getRequest();;
String loginName = (String) request.getAttribute(SecurityConstants.AUTHENTICATE_USERNAME);
return StrUtil.isBlank(loginName) ? LogInfo.UNKNOWN_USER : loginName;
}
/**
* 获取请求体