fix(system): 修复重构导致用户认证失败问题

This commit is contained in:
2025-12-30 10:29:12 +08:00
parent 866e689ad3
commit 79b847f9a4
6 changed files with 106 additions and 81 deletions
@@ -15,7 +15,6 @@
*/
package cn.odboy.system.dal.model;
import cn.odboy.system.dal.dataobject.SystemUserTb;
import com.alibaba.fastjson2.annotation.JSONField;
import io.swagger.annotations.ApiModelProperty;
import java.util.List;
@@ -29,9 +28,12 @@ import org.springframework.security.core.userdetails.UserDetails;
@AllArgsConstructor
public class SystemUserJwtVo implements UserDetails {
@ApiModelProperty(value = "用户") private final SystemUserTb user;
@ApiModelProperty(value = "数据权限") private final List<Long> dataScopes;
@ApiModelProperty(value = "角色") private final List<SystemRoleCodeVo> authorities;
@ApiModelProperty(value = "用户")
private final SystemUserVo user;
@ApiModelProperty(value = "数据权限")
private final List<Long> dataScopes;
@ApiModelProperty(value = "角色")
private final List<SystemRoleCodeVo> authorities;
public Set<String> getRoles() {
return authorities.stream().map(SystemRoleCodeVo::getAuthority).collect(Collectors.toSet());
@@ -13,13 +13,12 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package cn.odboy.system.framework.permission.core.handler;
import cn.odboy.framework.exception.BadRequestException;
import cn.odboy.system.dal.dataobject.SystemUserTb;
import cn.odboy.system.dal.model.SystemRoleCodeVo;
import cn.odboy.system.dal.model.SystemUserJwtVo;
import cn.odboy.system.dal.model.SystemUserVo;
import cn.odboy.system.dal.redis.SystemUserInfoDAO;
import cn.odboy.system.service.SystemDataService;
import cn.odboy.system.service.SystemRoleService;
@@ -36,16 +35,21 @@ import org.springframework.stereotype.Service;
@Slf4j
@Service("userDetailsService")
public class UserDetailsHandler implements UserDetailsService {
@Autowired private SystemRoleService systemRoleService;
@Autowired private SystemUserService systemUserService;
@Autowired private SystemDataService systemDataService;
@Autowired private SystemUserInfoDAO systemUserInfoDAO;
@Autowired
private SystemRoleService systemRoleService;
@Autowired
private SystemUserService systemUserService;
@Autowired
private SystemDataService systemDataService;
@Autowired
private SystemUserInfoDAO systemUserInfoDAO;
@Override
public SystemUserJwtVo loadUserByUsername(String username) {
SystemUserJwtVo userJwtVo = systemUserInfoDAO.getUserLoginInfoByUserName(username);
if (userJwtVo == null) {
SystemUserTb user = systemUserService.getUserByUsername(username);
SystemUserVo user = systemUserService.getUserVoByUsername(username);
if (user == null) {
throw new BadRequestException("用户不存在");
} else {
@@ -66,17 +66,28 @@ import org.springframework.web.multipart.MultipartFile;
@Service
public class SystemUserService {
@Autowired private SystemUserMapper systemUserMapper;
@Autowired private SystemUserJobService systemUserJobService;
@Autowired private SystemUserRoleService systemUserRoleService;
@Autowired private SystemUserInfoDAO systemUserInfoDAO;
@Autowired private SystemUserOnlineInfoDAO systemUserOnlineInfoDAO;
@Autowired private KitFileLocalUploadHelper fileUploadPathHelper;
@Autowired private SystemUserJobMapper systemUserJobMapper;
@Autowired private SystemUserRoleMapper systemUserRoleMapper;
@Autowired private SystemJobMapper systemJobMapper;
@Autowired private SystemRoleMapper systemRoleMapper;
@Autowired private SystemDeptMapper systemDeptMapper;
@Autowired
private SystemUserMapper systemUserMapper;
@Autowired
private SystemUserJobService systemUserJobService;
@Autowired
private SystemUserRoleService systemUserRoleService;
@Autowired
private SystemUserInfoDAO systemUserInfoDAO;
@Autowired
private SystemUserOnlineInfoDAO systemUserOnlineInfoDAO;
@Autowired
private KitFileLocalUploadHelper fileUploadPathHelper;
@Autowired
private SystemUserJobMapper systemUserJobMapper;
@Autowired
private SystemUserRoleMapper systemUserRoleMapper;
@Autowired
private SystemJobMapper systemJobMapper;
@Autowired
private SystemRoleMapper systemRoleMapper;
@Autowired
private SystemDeptMapper systemDeptMapper;
/**
* 新增用户
@@ -401,12 +412,13 @@ public class SystemUserService {
wrapper.in(SystemUserTb::getDeptId, args.getDeptIds());
}
if (StrUtil.isNotBlank(args.getBlurry())) {
wrapper.and(w -> w.like(SystemUserTb::getUsername, args.getBlurry()).or()
.like(SystemUserTb::getNickName, args.getBlurry()).or()
.like(SystemUserTb::getEmail, args.getBlurry()));
wrapper.and(w -> w.like(SystemUserTb::getUsername, args.getBlurry())
.or().like(SystemUserTb::getNickName, args.getBlurry())
.or().like(SystemUserTb::getEmail, args.getBlurry()));
}
if (CollUtil.isNotEmpty(args.getCreateTime()) && args.getCreateTime().size() >= 2) {
wrapper.between(SystemUserTb::getCreateTime, args.getCreateTime().get(0), args.getCreateTime().get(1));
wrapper.between(SystemUserTb::getCreateTime, args.getCreateTime().get(0),
args.getCreateTime().get(1));
}
}
wrapper.orderByDesc(SystemUserTb::getCreateTime);
@@ -461,6 +473,10 @@ public class SystemUserService {
return systemUserMapper.selectOne(wrapper);
}
public SystemUserVo getUserVoByUsername(String username) {
return this.convertToUserVo(this.getUserByUsername(username));
}
public long countUserByDeptIds(Set<Long> deptIds) {
LambdaQueryWrapper<SystemUserTb> wrapper = new LambdaQueryWrapper<>();
wrapper.in(SystemUserTb::getDeptId, deptIds);
@@ -15,7 +15,6 @@
*/
package cn.odboy.system.dal.model;
import cn.odboy.system.dal.dataobject.SystemUserTb;
import com.alibaba.fastjson2.annotation.JSONField;
import io.swagger.annotations.ApiModelProperty;
import java.util.List;
@@ -30,7 +29,7 @@ import org.springframework.security.core.userdetails.UserDetails;
public class SystemUserJwtVo implements UserDetails {
@ApiModelProperty(value = "用户")
private final SystemUserTb user;
private final SystemUserVo user;
@ApiModelProperty(value = "数据权限")
private final List<Long> dataScopes;
@ApiModelProperty(value = "角色")
@@ -16,9 +16,9 @@
package cn.odboy.system.framework.permission.core.handler;
import cn.odboy.framework.exception.BadRequestException;
import cn.odboy.system.dal.dataobject.SystemUserTb;
import cn.odboy.system.dal.model.SystemRoleCodeVo;
import cn.odboy.system.dal.model.SystemUserJwtVo;
import cn.odboy.system.dal.model.SystemUserVo;
import cn.odboy.system.dal.redis.SystemUserInfoDAO;
import cn.odboy.system.service.SystemDataService;
import cn.odboy.system.service.SystemRoleService;
@@ -49,7 +49,7 @@ public class UserDetailsHandler implements UserDetailsService {
public SystemUserJwtVo loadUserByUsername(String username) {
SystemUserJwtVo userJwtVo = systemUserInfoDAO.getUserLoginInfoByUserName(username);
if (userJwtVo == null) {
SystemUserTb user = systemUserService.getUserByUsername(username);
SystemUserVo user = systemUserService.getUserVoByUsername(username);
if (user == null) {
throw new BadRequestException("用户不存在");
} else {
@@ -473,6 +473,10 @@ public class SystemUserService {
return systemUserMapper.selectOne(wrapper);
}
public SystemUserVo getUserVoByUsername(String username) {
return this.convertToUserVo(this.getUserByUsername(username));
}
public long countUserByDeptIds(Set<Long> deptIds) {
LambdaQueryWrapper<SystemUserTb> wrapper = new LambdaQueryWrapper<>();
wrapper.in(SystemUserTb::getDeptId, deptIds);