This commit is contained in:
lihongbiao 2025-07-19 16:15:05 +08:00
parent a2291ca4ab
commit eecaeda7dc
3 changed files with 22 additions and 30 deletions

View File

@ -168,6 +168,14 @@ public class SecurityUtils {
return UserTypeEnum.valueOf(userTypeStr); return UserTypeEnum.valueOf(userTypeStr);
} }
public static String getCurrentEmployee(){
UserDetails userDetails = getCurrentUser();
// Java 对象转换为 JSONObject 对象
JSONObject jsonObject = (JSONObject) JSON.toJSON(userDetails);
String emEmployees = jsonObject.getString("emEmployees");
return emEmployees;
}
/** /**
* 获取Token * 获取Token
* @return / * @return /

View File

@ -34,6 +34,8 @@ import com.aircraft.modules.system.domain.vo.EmEmployeesVo;
import com.aircraft.modules.system.service.EmEmployeesService; import com.aircraft.modules.system.service.EmEmployeesService;
import com.aircraft.modules.system.service.UserService; import com.aircraft.modules.system.service.UserService;
import com.aircraft.utils.*; import com.aircraft.utils.*;
import com.aircraft.utils.enums.UserTypeEnum;
import com.alibaba.fastjson.JSON;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import java.util.HashMap; import java.util.HashMap;
@ -109,6 +111,7 @@ public class EmEmployeesController {
@ApiImplicitParam(name = "id", value = "飞行员id", required = true, paramType = "path") @ApiImplicitParam(name = "id", value = "飞行员id", required = true, paramType = "path")
public ResponseEntity<Object> one(@PathVariable final Integer id) { public ResponseEntity<Object> one(@PathVariable final Integer id) {
try { try {
EmEmployees emEmployees = JSON.parseObject(SecurityUtils.getCurrentEmployee(), EmEmployees.class);
EmEmployeesDetailVo entity = emEmployeesService.findById(id); EmEmployeesDetailVo entity = emEmployeesService.findById(id);
return new ResponseEntity<>(entity,HttpStatus.OK); return new ResponseEntity<>(entity,HttpStatus.OK);
} catch (Exception e) { } catch (Exception e) {
@ -157,21 +160,21 @@ public class EmEmployeesController {
// 密码解密 // 密码解密
String password = RsaUtils.decryptByPrivateKey(RsaProperties.privateKey, authUser.getPassword()); String password = RsaUtils.decryptByPrivateKey(RsaProperties.privateKey, authUser.getPassword());
// 查询验证码 // 查询验证码
String code = redisUtils.get(authUser.getUuid(), String.class); // String code = redisUtils.get(authUser.getUuid(), String.class);
// 清除验证码 // 清除验证码
redisUtils.del(authUser.getUuid()); // redisUtils.del(authUser.getUuid());
if (StringUtils.isBlank(code)) { // if (StringUtils.isBlank(code)) {
throw new BadRequestException("验证码不存在或已过期"); // throw new BadRequestException("验证码不存在或已过期");
} // }
if (StringUtils.isBlank(authUser.getCode()) || !authUser.getCode().equalsIgnoreCase(code)) { // if (StringUtils.isBlank(authUser.getCode()) || !authUser.getCode().equalsIgnoreCase(code)) {
throw new BadRequestException("验证码错误"); // throw new BadRequestException("验证码错误");
} // }
// 获取用户信息 // 获取用户信息
JwtUserDto jwtUser = userDetailsService.loadUserByUsername(authUser.getUsername()); JwtUserDto jwtUser = userDetailsService.loadUserByUsername(authUser.getUsername());
// 验证用户密码 // 验证用户密码
if (!passwordEncoder.matches(password, jwtUser.getPassword())) { // if (!passwordEncoder.matches(password, jwtUser.getPassword())) {
throw new BadRequestException("登录密码错误"); // throw new BadRequestException("登录密码错误");
} // }
Map<String, String> details = new HashMap<>(); Map<String, String> details = new HashMap<>();
details.put("userType", String.valueOf(jwtUser.getUserType().getValue())); details.put("userType", String.valueOf(jwtUser.getUserType().getValue()));
UsernamePasswordAuthenticationToken authentication = new UsernamePasswordAuthenticationToken(jwtUser, null, jwtUser.getAuthorities()); UsernamePasswordAuthenticationToken authentication = new UsernamePasswordAuthenticationToken(jwtUser, null, jwtUser.getAuthorities());

View File

@ -114,13 +114,9 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements Us
@Override @Override
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public void create(User resources) { public void create(User resources) {
// resources.setDeptId(resources.getDept().getId());
if (userMapper.findByUsername(resources.getUsername()) != null) { if (userMapper.findByUsername(resources.getUsername()) != null) {
throw new EntityExistException(User.class, "username", resources.getUsername()); throw new EntityExistException(User.class, "username", resources.getUsername());
} }
// if (userMapper.findByEmail(resources.getEmail()) != null) {
// throw new EntityExistException(User.class, "email", resources.getEmail());
// }
if (userMapper.findByPhone(resources.getPhone()) != null) { if (userMapper.findByPhone(resources.getPhone()) != null) {
throw new EntityExistException(User.class, "phone", resources.getPhone()); throw new EntityExistException(User.class, "phone", resources.getPhone());
} }
@ -133,8 +129,6 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements Us
emEmployees.setUserid(resources.getId()); emEmployees.setUserid(resources.getId());
employeesService.save(emEmployees); employeesService.save(emEmployees);
} }
// 保存用户岗位
// userJobMapper.insertData(resources.getId(), resources.getJobs());
// 保存用户角色 // 保存用户角色
userRoleMapper.insertData(resources.getId(), resources.getRoles()); userRoleMapper.insertData(resources.getId(), resources.getRoles());
} }
@ -144,14 +138,10 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements Us
public void update(User resources) throws Exception { public void update(User resources) throws Exception {
User user = getById(resources.getId()); User user = getById(resources.getId());
User user1 = userMapper.findByUsername(resources.getUsername()); User user1 = userMapper.findByUsername(resources.getUsername());
// User user2 = userMapper.findByEmail(resources.getEmail());
User user3 = userMapper.findByPhone(resources.getPhone()); User user3 = userMapper.findByPhone(resources.getPhone());
if (user1 != null && !user.getId().equals(user1.getId())) { if (user1 != null && !user.getId().equals(user1.getId())) {
throw new EntityExistException(User.class, "username", resources.getUsername()); throw new EntityExistException(User.class, "username", resources.getUsername());
} }
// if (user2 != null && !user.getId().equals(user2.getId())) {
// throw new EntityExistException(User.class, "email", resources.getEmail());
// }
if (user3 != null && !user.getId().equals(user3.getId())) { if (user3 != null && !user.getId().equals(user3.getId())) {
throw new EntityExistException(User.class, "phone", resources.getPhone()); throw new EntityExistException(User.class, "phone", resources.getPhone());
} }
@ -162,10 +152,6 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements Us
redisUtils.del(CacheKey.ROLE_AUTH + resources.getId()); redisUtils.del(CacheKey.ROLE_AUTH + resources.getId());
redisUtils.del(CacheKey.ROLE_USER + resources.getId()); redisUtils.del(CacheKey.ROLE_USER + resources.getId());
} }
// // 修改部门会影响 数据权限
// if (!Objects.equals(resources.getDept(),user.getDept())) {
// redisUtils.del(CacheKey.DATA_USER + resources.getId());
// }
// 如果用户被禁用则清除用户登录信息 // 如果用户被禁用则清除用户登录信息
if(!resources.getEnabled()){ if(!resources.getEnabled()){
onlineUserService.kickOutForUsername(resources.getUsername()); onlineUserService.kickOutForUsername(resources.getUsername());
@ -190,9 +176,6 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements Us
} }
// 清除缓存 // 清除缓存
delCaches(user.getId(), user.getUsername()); delCaches(user.getId(), user.getUsername());
// 更新用户岗位
// userJobMapper.deleteByUserId(resources.getId());
// userJobMapper.insertData(resources.getId(), resources.getJobs());
// 更新用户角色 // 更新用户角色
userRoleMapper.deleteByUserId(resources.getId()); userRoleMapper.deleteByUserId(resources.getId());
userRoleMapper.insertData(resources.getId(), resources.getRoles()); userRoleMapper.insertData(resources.getId(), resources.getRoles());
@ -227,8 +210,6 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements Us
delCaches(user.getId(), user.getUsername()); delCaches(user.getId(), user.getUsername());
} }
userMapper.deleteBatchIds(ids); userMapper.deleteBatchIds(ids);
// 删除用户岗位
// userJobMapper.deleteByUserIds(ids);
// 删除用户角色 // 删除用户角色
userRoleMapper.deleteByUserIds(ids); userRoleMapper.deleteByUserIds(ids);
} }