From d862bef4262f290aa9f5fd646837f7deea9c7006 Mon Sep 17 00:00:00 2001
From: 云 <2163098428@qq.com>
Date: 星期一, 13 四月 2026 16:29:08 +0800
Subject: [PATCH] fix(order): 修复订单编号生成中的字段名不一致问题
---
src/main/java/com/ruoyi/framework/security/service/TokenService.java | 88 ++++++++++++++++++++++++++++++++++++++-----
1 files changed, 77 insertions(+), 11 deletions(-)
diff --git a/src/main/java/com/ruoyi/framework/security/service/TokenService.java b/src/main/java/com/ruoyi/framework/security/service/TokenService.java
index 5b7cf11..5799a03 100644
--- a/src/main/java/com/ruoyi/framework/security/service/TokenService.java
+++ b/src/main/java/com/ruoyi/framework/security/service/TokenService.java
@@ -21,10 +21,11 @@
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.utils.ip.AddressUtils;
import com.ruoyi.common.utils.ip.IpUtils;
-import com.ruoyi.common.utils.uuid.IdUtils;
-import com.ruoyi.framework.redis.RedisCache;
-import com.ruoyi.framework.security.LoginUser;
-import eu.bitwalker.useragentutils.UserAgent;
+import com.ruoyi.common.utils.uuid.IdUtils;
+import com.ruoyi.framework.redis.RedisCache;
+import com.ruoyi.framework.security.LoginUser;
+import com.ruoyi.project.system.domain.SysRole;
+import eu.bitwalker.useragentutils.UserAgent;
import io.jsonwebtoken.Claims;
import io.jsonwebtoken.Jwts;
import io.jsonwebtoken.SignatureAlgorithm;
@@ -159,18 +160,83 @@
{
loginUser.setLoginTime(System.currentTimeMillis());
loginUser.setExpireTime(loginUser.getLoginTime() + expireTime * MILLIS_MINUTE);
- LambdaQueryWrapper<SysUserDept> sysUserDeptLambdaQueryWrapper = new LambdaQueryWrapper<>();
- sysUserDeptLambdaQueryWrapper.eq(SysUserDept::getUserId, loginUser.getUserId());
- List<SysUserDept> sysUserDept = sysUserDeptMapper.selectList(sysUserDeptLambdaQueryWrapper);
- if(!CollectionUtils.isEmpty(sysUserDept)){
- List<Long> collect = sysUserDept.stream().map(SysUserDept::getDeptId).collect(Collectors.toList());
- loginUser.setDeptId(collect.toArray(new Long[0]));
- }
+ loginUser.setDeptIds(getDeptIdsByUserId(loginUser.getUserId()));
+ if (loginUser.getDeptIds() != null && loginUser.getDeptIds().length > 0)
+ {
+ loginUser.setCurrentDeptId(loginUser.getDeptIds()[0]);
+ }
+ loginUser.setDataScope(resolveDataScope(loginUser));
// 鏍规嵁uuid灏唋oginUser缂撳瓨
String userKey = getTokenKey(loginUser.getToken());
redisCache.setCacheObject(userKey, loginUser, expireTime, TimeUnit.MINUTES);
}
+ public String resolveDataScope(LoginUser loginUser)
+ {
+ if (loginUser == null || loginUser.getUser() == null || CollectionUtils.isEmpty(loginUser.getUser().getRoles()))
+ {
+ return null;
+ }
+ boolean hasCustom = false;
+ boolean hasDeptAndChild = false;
+ boolean hasDept = false;
+ boolean hasSelf = false;
+ for (SysRole role : loginUser.getUser().getRoles())
+ {
+ if (role == null || !"0".equals(role.getStatus()))
+ {
+ continue;
+ }
+ if ("1".equals(role.getDataScope()))
+ {
+ return "1";
+ }
+ if ("2".equals(role.getDataScope()))
+ {
+ hasCustom = true;
+ }
+ else if ("4".equals(role.getDataScope()))
+ {
+ hasDeptAndChild = true;
+ }
+ else if ("3".equals(role.getDataScope()))
+ {
+ hasDept = true;
+ }
+ else if ("5".equals(role.getDataScope()))
+ {
+ hasSelf = true;
+ }
+ }
+ if (hasCustom)
+ {
+ return "2";
+ }
+ if (hasDeptAndChild)
+ {
+ return "4";
+ }
+ if (hasDept)
+ {
+ return "3";
+ }
+ if (hasSelf)
+ {
+ return "5";
+ }
+ return null;
+ }
+
+ public Long[] getDeptIdsByUserId(Long userId){
+ LambdaQueryWrapper<SysUserDept> sysUserDeptLambdaQueryWrapper = new LambdaQueryWrapper<>();
+ sysUserDeptLambdaQueryWrapper.eq(SysUserDept::getUserId, userId);
+ List<SysUserDept> sysUserDept = sysUserDeptMapper.selectList(sysUserDeptLambdaQueryWrapper);
+ if(CollectionUtils.isEmpty(sysUserDept)){
+ return null;
+ }
+ return sysUserDept.stream().map(SysUserDept::getDeptId).toArray(Long[]::new);
+ }
+
/**
* 璁剧疆鐢ㄦ埛浠g悊淇℃伅
*
--
Gitblit v1.9.3