Compare commits
6 Commits
2025-07
...
0f5b7603b4
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0f5b7603b4 | ||
| 1f41ef2d01 | |||
| 75cb5163f1 | |||
| c401f04bbe | |||
| f069a16e43 | |||
|
|
2454d84919 |
@@ -43,6 +43,7 @@ public interface SecurityConstants {
|
|||||||
* 认证成功后,返回信息包含的内容-
|
* 认证成功后,返回信息包含的内容-
|
||||||
*/
|
*/
|
||||||
String USER_ID = "userId";
|
String USER_ID = "userId";
|
||||||
|
String LOGIN_NAME = "loginName";
|
||||||
String USER_TYPE = "userType";
|
String USER_TYPE = "userType";
|
||||||
String USER_NAME_KEY = "name";
|
String USER_NAME_KEY = "name";
|
||||||
String USER_HEAD_KEY = "headSculpture";
|
String USER_HEAD_KEY = "headSculpture";
|
||||||
|
|||||||
@@ -34,14 +34,15 @@ public class JwtUtil {
|
|||||||
*/
|
*/
|
||||||
private final static String JWT_ISS = "NJCN";
|
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<>();
|
Map<String, Object> headers = new HashMap<>();
|
||||||
headers.put("typ", "JWT");
|
headers.put("typ", "JWT");
|
||||||
headers.put("alg", "HS256");
|
headers.put("alg", "HS256");
|
||||||
Map<String, Object> payload = new HashMap<>();
|
Map<String, Object> payload = new HashMap<>();
|
||||||
payload.put(SecurityConstants.USER_ID, userId);
|
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("sub", SUBJECT);
|
||||||
payload.put("iss", JWT_ISS);
|
payload.put("iss", JWT_ISS);
|
||||||
payload.put("iat", Instant.now().getEpochSecond());
|
payload.put("iat", Instant.now().getEpochSecond());
|
||||||
|
|||||||
@@ -17,8 +17,10 @@ import org.springframework.web.multipart.MultipartFile;
|
|||||||
|
|
||||||
import javax.servlet.ServletOutputStream;
|
import javax.servlet.ServletOutputStream;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
import java.io.FileOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
import java.io.OutputStream;
|
||||||
import java.net.URLEncoder;
|
import java.net.URLEncoder;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.List;
|
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++) {
|
for (int i = 0; i < headerRowNumber; i++) {
|
||||||
//获取列数
|
//获取列数
|
||||||
int physicalNumberOfCells = sheetAt.getRow(i).getPhysicalNumberOfCells();
|
|
||||||
//获取行
|
|
||||||
Row row = sheetAt.getRow(i);
|
Row row = sheetAt.getRow(i);
|
||||||
if (Objects.isNull(row)) {
|
if (Objects.isNull(row)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
for (int j = 0; j < physicalNumberOfCells; j++) {
|
for (int j = row.getFirstCellNum(); j < row.getLastCellNum(); j++) {
|
||||||
//获取单元格对象
|
//获取单元格对象
|
||||||
Cell cell = row.getCell(j);
|
Cell cell = row.getCell(j);
|
||||||
//获取单元格样式对象
|
//获取单元格样式对象
|
||||||
|
|||||||
@@ -39,7 +39,8 @@ public class HttpResultUtil {
|
|||||||
* 业务异常组装结果集
|
* 业务异常组装结果集
|
||||||
*/
|
*/
|
||||||
public static <T> HttpResult<T> assembleBusinessExceptionResult(BusinessException businessException, T result, String methodDescribe) {
|
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());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -65,15 +65,15 @@ public class RequestUtil {
|
|||||||
*
|
*
|
||||||
* @return 若成功,返回当前登录用户的ID;若失败,返回null
|
* @return 若成功,返回当前登录用户的ID;若失败,返回null
|
||||||
*/
|
*/
|
||||||
public static String getUserId(ServerHttpRequest serverHttpRequest) {
|
// public static String getUserId(ServerHttpRequest serverHttpRequest) {
|
||||||
String accessToken = getAccessToken(serverHttpRequest);
|
// String accessToken = getAccessToken(serverHttpRequest);
|
||||||
String userId = null;
|
// String userId = null;
|
||||||
if (StrUtil.isNotBlank(accessToken)) {
|
// if (StrUtil.isNotBlank(accessToken)) {
|
||||||
Map<String, Object> map = JwtUtil.parseToken(accessToken);
|
// Map<String, Object> map = JwtUtil.parseToken(accessToken);
|
||||||
userId = (String) map.get(SecurityConstants.USER_ID);
|
// userId = (String) map.get(SecurityConstants.USER_ID);
|
||||||
}
|
// }
|
||||||
return userId;
|
// return userId;
|
||||||
}
|
// }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取当前登录用户的ID
|
* 获取当前登录用户的ID
|
||||||
@@ -90,6 +90,33 @@ public class RequestUtil {
|
|||||||
return userId;
|
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取请求体
|
* 获取请求体
|
||||||
|
|||||||
Reference in New Issue
Block a user