mirror of
https://gitee.com/lab1024/smart-admin.git
synced 2025-11-07 19:23:48 +08:00
v3.14.0 更新;【新增】EasyExcel重磅升级为FastExcel;【新增】使用最强Argon2算法作为密码存储;【新增】大家吐槽的数据字典改为可重复;【新增】前端布局再增加多种样式;【优化】升级SaToken到最新版本;【优化】token使用Sa-Token的Bearer类型;【优化】优化其他
This commit is contained in:
@@ -4,21 +4,15 @@ import cn.dev33.satoken.annotation.SaIgnore;
|
||||
import cn.dev33.satoken.exception.SaTokenException;
|
||||
import cn.dev33.satoken.stp.StpUtil;
|
||||
import cn.dev33.satoken.strategy.SaStrategy;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import net.lab1024.sa.admin.module.system.login.domain.RequestEmployee;
|
||||
import net.lab1024.sa.admin.module.system.login.service.LoginService;
|
||||
import net.lab1024.sa.base.common.annoation.NoNeedLogin;
|
||||
import net.lab1024.sa.base.common.code.SystemErrorCode;
|
||||
import net.lab1024.sa.base.common.code.UserErrorCode;
|
||||
import net.lab1024.sa.base.common.constant.StringConst;
|
||||
import net.lab1024.sa.base.common.domain.ResponseDTO;
|
||||
import net.lab1024.sa.base.common.domain.SystemEnvironment;
|
||||
import net.lab1024.sa.base.common.enumeration.SystemEnvironmentEnum;
|
||||
import net.lab1024.sa.base.common.enumeration.UserTypeEnum;
|
||||
import net.lab1024.sa.base.common.util.SmartRequestUtil;
|
||||
import net.lab1024.sa.base.common.util.SmartResponseUtil;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.http.HttpMethod;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.stereotype.Component;
|
||||
@@ -47,9 +41,6 @@ public class AdminInterceptor implements HandlerInterceptor {
|
||||
@Resource
|
||||
private LoginService loginService;
|
||||
|
||||
@Resource
|
||||
private SystemEnvironment systemEnvironment;
|
||||
|
||||
@Override
|
||||
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
|
||||
|
||||
@@ -68,17 +59,7 @@ public class AdminInterceptor implements HandlerInterceptor {
|
||||
// --------------- 第一步: 根据token 获取用户 ---------------
|
||||
|
||||
String tokenValue = StpUtil.getTokenValue();
|
||||
boolean debugNumberTokenFlag = isDevDebugNumberToken(tokenValue);
|
||||
|
||||
String loginId = null;
|
||||
if (debugNumberTokenFlag) {
|
||||
//开发、测试环境,且为数字的话,则表明为 调试临时用户,即需要调用 sa-token switch
|
||||
loginId = UserTypeEnum.ADMIN_EMPLOYEE.getValue() + StringConst.COLON + tokenValue;
|
||||
StpUtil.switchTo(loginId);
|
||||
} else {
|
||||
loginId = (String) StpUtil.getLoginIdByToken(tokenValue);
|
||||
}
|
||||
|
||||
String loginId = (String) StpUtil.getLoginIdByToken(tokenValue);
|
||||
RequestEmployee requestEmployee = loginService.getLoginEmployee(loginId, request);
|
||||
|
||||
// --------------- 第二步: 校验 登录 ---------------
|
||||
@@ -86,7 +67,7 @@ public class AdminInterceptor implements HandlerInterceptor {
|
||||
Method method = ((HandlerMethod) handler).getMethod();
|
||||
NoNeedLogin noNeedLogin = ((HandlerMethod) handler).getMethodAnnotation(NoNeedLogin.class);
|
||||
if (noNeedLogin != null) {
|
||||
checkActiveTimeout(requestEmployee, debugNumberTokenFlag);
|
||||
checkActiveTimeout(requestEmployee);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -96,7 +77,7 @@ public class AdminInterceptor implements HandlerInterceptor {
|
||||
}
|
||||
|
||||
// 检测token 活跃频率
|
||||
checkActiveTimeout(requestEmployee, debugNumberTokenFlag);
|
||||
checkActiveTimeout(requestEmployee);
|
||||
|
||||
|
||||
// --------------- 第三步: 校验 权限 ---------------
|
||||
@@ -143,13 +124,7 @@ public class AdminInterceptor implements HandlerInterceptor {
|
||||
/**
|
||||
* 检测:token 最低活跃频率(单位:秒),如果 token 超过此时间没有访问系统就会被冻结
|
||||
*/
|
||||
private void checkActiveTimeout(RequestEmployee requestEmployee, boolean debugNumberTokenFlag) {
|
||||
|
||||
// 对于开发环境的 数字 debug token ,不需要检测活跃有效期
|
||||
if (debugNumberTokenFlag) {
|
||||
return;
|
||||
}
|
||||
|
||||
private void checkActiveTimeout(RequestEmployee requestEmployee) {
|
||||
// 用户不在线,也不用检测
|
||||
if (requestEmployee == null) {
|
||||
return;
|
||||
@@ -160,29 +135,9 @@ public class AdminInterceptor implements HandlerInterceptor {
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 是否为开发使用的 debug token
|
||||
*
|
||||
* @param token
|
||||
* @return
|
||||
*/
|
||||
private boolean isDevDebugNumberToken(String token) {
|
||||
if (!StrUtil.isNumeric(token)) {
|
||||
return false;
|
||||
}
|
||||
return systemEnvironment.getCurrentEnvironment() == SystemEnvironmentEnum.DEV
|
||||
|| systemEnvironment.getCurrentEnvironment() == SystemEnvironmentEnum.TEST;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {
|
||||
// 清除上下文
|
||||
SmartRequestUtil.remove();
|
||||
// 开发环境,关闭 sa token 的临时切换用户
|
||||
if (systemEnvironment.getCurrentEnvironment() == SystemEnvironmentEnum.DEV) {
|
||||
StpUtil.endSwitch();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
package net.lab1024.sa.admin.module.business.goods.domain.form;
|
||||
|
||||
import com.alibaba.excel.annotation.ExcelProperty;
|
||||
import cn.idev.excel.annotation.ExcelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package net.lab1024.sa.admin.module.business.goods.domain.vo;
|
||||
|
||||
import com.alibaba.excel.annotation.ExcelProperty;
|
||||
import cn.idev.excel.annotation.ExcelProperty;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
|
||||
@@ -4,7 +4,6 @@ import com.fasterxml.jackson.databind.annotation.JsonSerialize;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
import net.lab1024.sa.admin.module.business.goods.constant.GoodsStatusEnum;
|
||||
import net.lab1024.sa.base.common.json.serializer.DictValueVoSerializer;
|
||||
import net.lab1024.sa.base.common.swagger.SchemaEnum;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
@@ -32,7 +31,6 @@ public class GoodsVO {
|
||||
private Integer goodsStatus;
|
||||
|
||||
@Schema(description = "产地")
|
||||
@JsonSerialize(using = DictValueVoSerializer.class)
|
||||
private String place;
|
||||
|
||||
@Schema(description = "商品价格")
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package net.lab1024.sa.admin.module.business.goods.service;
|
||||
|
||||
import com.alibaba.excel.EasyExcel;
|
||||
import cn.idev.excel.FastExcel;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
@@ -174,7 +174,7 @@ public class GoodsService {
|
||||
public ResponseDTO<String> importGoods(MultipartFile file) {
|
||||
List<GoodsImportForm> dataList;
|
||||
try {
|
||||
dataList = EasyExcel.read(file.getInputStream()).head(GoodsImportForm.class)
|
||||
dataList = FastExcel.read(file.getInputStream()).head(GoodsImportForm.class)
|
||||
.sheet()
|
||||
.doReadSync();
|
||||
} catch (IOException e) {
|
||||
@@ -194,12 +194,13 @@ public class GoodsService {
|
||||
*/
|
||||
public List<GoodsExcelVO> getAllGoods() {
|
||||
List<GoodsEntity> goodsEntityList = goodsDao.selectList(null);
|
||||
String keyCode="GODOS_PLACE";
|
||||
return goodsEntityList.stream()
|
||||
.map(e ->
|
||||
GoodsExcelVO.builder()
|
||||
.goodsStatus(SmartEnumUtil.getEnumDescByValue(e.getGoodsStatus(), GoodsStatusEnum.class))
|
||||
.categoryName(categoryQueryService.queryCategoryName(e.getCategoryId()))
|
||||
.place(Arrays.stream(e.getPlace().split(",")).map(code -> dictCacheService.selectValueNameByValueCode(code)).collect(Collectors.joining(",")))
|
||||
.place(Arrays.stream(e.getPlace().split(",")).map(code -> dictCacheService.selectValueNameByValueCode(keyCode,code)).collect(Collectors.joining(",")))
|
||||
.price(e.getPrice())
|
||||
.goodsName(e.getGoodsName())
|
||||
.remark(e.getRemark())
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package net.lab1024.sa.admin.module.business.oa.enterprise.domain.vo;
|
||||
|
||||
import com.alibaba.excel.annotation.ExcelProperty;
|
||||
import cn.idev.excel.annotation.ExcelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
package net.lab1024.sa.admin.module.system.employee.controller;
|
||||
|
||||
import cn.dev33.satoken.annotation.SaCheckPermission;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import net.lab1024.sa.admin.constant.AdminSwaggerTagConst;
|
||||
import net.lab1024.sa.admin.module.system.employee.domain.form.*;
|
||||
import net.lab1024.sa.admin.module.system.employee.domain.vo.EmployeeVO;
|
||||
|
||||
@@ -4,9 +4,9 @@ import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
import net.lab1024.sa.base.common.enumeration.GenderEnum;
|
||||
import net.lab1024.sa.base.common.swagger.SchemaEnum;
|
||||
import net.lab1024.sa.base.common.util.SmartVerificationUtil;
|
||||
import net.lab1024.sa.base.common.validator.enumeration.CheckEnum;
|
||||
import org.hibernate.validator.constraints.Length;
|
||||
import net.lab1024.sa.base.common.util.SmartVerificationUtil;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
import javax.validation.constraints.Pattern;
|
||||
|
||||
@@ -55,4 +55,4 @@ public class EmployeeUpdateCenterForm {
|
||||
@Schema(description = "备注")
|
||||
@Length(max = 200, message = "备注最多200字符")
|
||||
private String remark;
|
||||
}
|
||||
}
|
||||
@@ -60,8 +60,8 @@ public class LoginController {
|
||||
|
||||
@Operation(summary = "退出登陆 @author 卓大")
|
||||
@GetMapping("/login/logout")
|
||||
public ResponseDTO<String> logout(@RequestHeader(value = RequestHeaderConst.TOKEN, required = false) String token) {
|
||||
return loginService.logout(token, SmartRequestUtil.getRequestUser());
|
||||
public ResponseDTO<String> logout() {
|
||||
return loginService.logout(SmartRequestUtil.getRequestUser());
|
||||
}
|
||||
|
||||
@Operation(summary = "获取验证码 @author 卓大")
|
||||
|
||||
@@ -378,10 +378,10 @@ public class LoginService implements StpInterface {
|
||||
/**
|
||||
* 退出登录
|
||||
*/
|
||||
public ResponseDTO<String> logout(String token, RequestUser requestUser) {
|
||||
public ResponseDTO<String> logout(RequestUser requestUser) {
|
||||
|
||||
// sa token 登出
|
||||
StpUtil.logoutByTokenValue(token);
|
||||
StpUtil.logout();
|
||||
|
||||
// 清空登录信息缓存
|
||||
loginEmployeeCache.remove(requestUser.getUserId());
|
||||
|
||||
@@ -19,9 +19,8 @@
|
||||
|
||||
<select id="selectMenuListByRoleIdList"
|
||||
resultType="net.lab1024.sa.admin.module.system.menu.domain.entity.MenuEntity">
|
||||
|
||||
SELECT
|
||||
t_menu.*
|
||||
distinct t_menu.*
|
||||
from t_menu
|
||||
left join t_role_menu on t_role_menu.menu_id = t_menu.menu_id
|
||||
<where>
|
||||
@@ -35,8 +34,6 @@
|
||||
</foreach>
|
||||
</if>
|
||||
</where>
|
||||
group by t_menu.menu_id
|
||||
ORDER BY t_menu.sort ASC
|
||||
|
||||
</select>
|
||||
</mapper>
|
||||
Reference in New Issue
Block a user