|
@@ -5,12 +5,14 @@ import com.caimei365.manager.entity.*;
|
|
import com.caimei365.manager.service.RedisService;
|
|
import com.caimei365.manager.service.RedisService;
|
|
import com.caimei365.manager.service.SysUserService;
|
|
import com.caimei365.manager.service.SysUserService;
|
|
import com.github.pagehelper.PageHelper;
|
|
import com.github.pagehelper.PageHelper;
|
|
|
|
+import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
|
|
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
|
|
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.util.CollectionUtils;
|
|
import org.springframework.util.CollectionUtils;
|
|
import org.springframework.util.StringUtils;
|
|
import org.springframework.util.StringUtils;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
import javax.annotation.Resource;
|
|
|
|
+import java.util.ArrayList;
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -38,18 +40,30 @@ public class SysUserServiceImpl implements SysUserService {
|
|
public ResponseJson<SysUser> getInfoByUsername(String username) {
|
|
public ResponseJson<SysUser> getInfoByUsername(String username) {
|
|
if (StringUtils.hasLength(username)) {
|
|
if (StringUtils.hasLength(username)) {
|
|
SysUser sysUser = sysUserDao.findByUsername(username);
|
|
SysUser sysUser = sysUserDao.findByUsername(username);
|
|
- // 获取用户角色列表
|
|
|
|
- List<String> roleList = sysUserDao.getRoleListByUserId(sysUser.getId());
|
|
|
|
- sysUser.setRoles(roleList);
|
|
|
|
-
|
|
|
|
- // 获取用户角色Id
|
|
|
|
- List<Integer> roleIds = sysUserDao.getRoleIdsByUsername(username);
|
|
|
|
- List<SysMenu> menus = null;
|
|
|
|
- if (!CollectionUtils.isEmpty(roleIds)) {
|
|
|
|
- // 根据角色Id获取菜单列表
|
|
|
|
- menus = sysUserDao.getMenusByRoleIds(roleIds);
|
|
|
|
|
|
+ if (null != sysUser) {
|
|
|
|
+ List<String> roleNames = new ArrayList<>();
|
|
|
|
+ List<Integer> roleIds = new ArrayList<>();
|
|
|
|
+ StringBuilder roleDesc = new StringBuilder();
|
|
|
|
+ // 根据用户Id获取用户角色列表
|
|
|
|
+ List<SysRole> roleList = sysUserDao.getRoleListByUserId(sysUser.getId());
|
|
|
|
+ if (!CollectionUtils.isEmpty(roleList)) {
|
|
|
|
+ for (SysRole role : roleList) {
|
|
|
|
+ if (null != role) {
|
|
|
|
+ roleNames.add(role.getRoleName());
|
|
|
|
+ roleIds.add(role.getId());
|
|
|
|
+ roleDesc.append(role.getRoleDesc()).append(" ");
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ sysUser.setRoles(roleNames);
|
|
|
|
+ sysUser.setRoleDesc(roleDesc.toString());
|
|
|
|
+ List<SysMenu> menus = null;
|
|
|
|
+ if (!CollectionUtils.isEmpty(roleIds)) {
|
|
|
|
+ // 根据角色Id获取菜单列表
|
|
|
|
+ menus = sysUserDao.getMenusByRoleIds(roleIds);
|
|
|
|
+ }
|
|
|
|
+ sysUser.setMenus(menus);
|
|
}
|
|
}
|
|
- sysUser.setMenus(menus);
|
|
|
|
|
|
|
|
return ResponseJson.success(sysUser);
|
|
return ResponseJson.success(sysUser);
|
|
}
|
|
}
|
|
@@ -58,8 +72,6 @@ public class SysUserServiceImpl implements SysUserService {
|
|
|
|
|
|
/**
|
|
/**
|
|
* 退出登录
|
|
* 退出登录
|
|
- *
|
|
|
|
- * @param token
|
|
|
|
*/
|
|
*/
|
|
@Override
|
|
@Override
|
|
public ResponseJson<Void> logout(String token) {
|
|
public ResponseJson<Void> logout(String token) {
|
|
@@ -445,4 +457,54 @@ public class SysUserServiceImpl implements SysUserService {
|
|
sysUserDao.deleteMenu(id);
|
|
sysUserDao.deleteMenu(id);
|
|
return ResponseJson.success();
|
|
return ResponseJson.success();
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 用户修改资料
|
|
|
|
+ */
|
|
|
|
+ @Override
|
|
|
|
+ public ResponseJson<Void> updateUserProfile(UserProfile profile) {
|
|
|
|
+ SysUser sysUser = sysUserDao.getUser(profile.getUserId());
|
|
|
|
+ if (null == sysUser) {
|
|
|
|
+ return ResponseJson.error("用户异常!", null);
|
|
|
|
+ }
|
|
|
|
+ if (StringUtils.hasLength(profile.getUsername())){
|
|
|
|
+ sysUser.setUsername(profile.getUsername());
|
|
|
|
+ }
|
|
|
|
+ if (StringUtils.hasLength(profile.getFullName())){
|
|
|
|
+ sysUser.setFullName(profile.getFullName());
|
|
|
|
+ }
|
|
|
|
+ if (StringUtils.hasLength(profile.getPhone())){
|
|
|
|
+ sysUser.setPhone(profile.getPhone());
|
|
|
|
+ }
|
|
|
|
+ if (StringUtils.hasLength(profile.getAvatar())){
|
|
|
|
+ sysUser.setAvatar(profile.getAvatar());
|
|
|
|
+ }
|
|
|
|
+ sysUserDao.updateSysUser(sysUser);
|
|
|
|
+ return ResponseJson.success();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 用户修改密码
|
|
|
|
+ */
|
|
|
|
+ @Override
|
|
|
|
+ public ResponseJson<Void> updateUserPassword(UserProfile profile) {
|
|
|
|
+ SysUser sysUser = sysUserDao.getUser(profile.getUserId());
|
|
|
|
+ if (null == sysUser) {
|
|
|
|
+ return ResponseJson.error("用户异常!", null);
|
|
|
|
+ }
|
|
|
|
+ if (!StringUtils.hasLength(profile.getPassword())){
|
|
|
|
+ return ResponseJson.error("新密码不能为空!", null);
|
|
|
|
+ }
|
|
|
|
+ if (!profile.getPassword().equals(profile.getConfirmPassword())){
|
|
|
|
+ return ResponseJson.error("两次密码输入不一致!", null);
|
|
|
|
+ }
|
|
|
|
+ if (!passwordEncoder.matches(profile.getOldPassword(), sysUser.getPassword())) {
|
|
|
|
+ return ResponseJson.error("旧密码输入错误!", null);
|
|
|
|
+ }
|
|
|
|
+ // 密码加密
|
|
|
|
+ String encodePassword = passwordEncoder.encode(profile.getPassword());
|
|
|
|
+ sysUser.setPassword(encodePassword);
|
|
|
|
+ sysUserDao.updateSysUser(sysUser);
|
|
|
|
+ return ResponseJson.success();
|
|
|
|
+ }
|
|
}
|
|
}
|