Commit 250c782d authored by hubin's avatar hubin

用户管理

parent 5026ea26
...@@ -18,12 +18,12 @@ public class GatewayConfig { ...@@ -18,12 +18,12 @@ public class GatewayConfig {
public static String NACOS_ROUTE_GROUP; public static String NACOS_ROUTE_GROUP;
@Value("${spring.cloud.nacos.discovery.server-addr}") @Value("${spring.cloud.nacos.config.server-addr}")
public void setNacosServerAddr(String nacosServerAddr){ public void setNacosServerAddr(String nacosServerAddr){
NACOS_SERVER_ADDR = nacosServerAddr; NACOS_SERVER_ADDR = nacosServerAddr;
} }
@Value("${spring.cloud.nacos.discovery.namespace}") @Value("${spring.cloud.nacos.config.namespace}")
public void setNacosNamespace(String nacosNamespace){ public void setNacosNamespace(String nacosNamespace){
NACOS_NAMESPACE = nacosNamespace; NACOS_NAMESPACE = nacosNamespace;
} }
......
...@@ -20,6 +20,7 @@ import org.springframework.beans.factory.annotation.Autowired; ...@@ -20,6 +20,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import java.util.ArrayList;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
import java.util.stream.Collectors; import java.util.stream.Collectors;
...@@ -195,4 +196,81 @@ public class UserController { ...@@ -195,4 +196,81 @@ public class UserController {
/**
* 新增用户
*/ @PostMapping("/updateUser")
public Result updateUser(ReqUserInfo reqUserInfo) {
if (reqUserInfo.getId() == null || reqUserInfo.getId() == 0) {
return Result.failed("用户id无效!");
}
SystemUser systemUser = userInfoService.getOne(new LambdaQueryWrapper<SystemUser>().eq(SystemUser::getUserId, reqUserInfo.getId()));
if (systemUser == null) {
return Result.failed("用户id无效!");
}
boolean flag = false;
if (!reqUserInfo.getName().equals(systemUser.getRealName())) {
systemUser.setRealName(reqUserInfo.getName());
flag = true;
}
if (!reqUserInfo.getAccount().equals(systemUser.getAccount())) {
systemUser.setAccount(reqUserInfo.getAccount());
flag = true;
}
// if (!reqUserInfo.getAvatar().equals(systemUser.getAvatar())) {
// systemUser.setAvatar(reqUserInfo.getAvatar());
// flag = true;
// }
if (!reqUserInfo.getGender().equals(systemUser.getGender())) {
systemUser.setGender(reqUserInfo.getGender());
flag = true;
}
if (!reqUserInfo.getId().equals(systemUser.getUserId())) {
systemUser.setUserId(reqUserInfo.getId());
flag = true;
}
if (flag) {
systemUser.setUpdatedTime(new Date());
userInfoService.save(systemUser);
}
//查询该角色下所有的资源数据
List<SystemUserRole> roleResources = userRoleService.list(new LambdaQueryWrapper<SystemUserRole>().eq(SystemUserRole::getUserId, reqUserInfo.getId()));
if(reqUserInfo.getRoleIds()==null){
reqUserInfo.setRoleIds(new ArrayList<>());
}
List<SystemUserRole> newRoleResources = reqUserInfo.getRoleIds().stream()
.filter(id -> {
for (SystemUserRole r : roleResources) {
if (r.getRoleId().equals(id)) {
return false;
}
}
return true;
}).map(resourceId -> {
SystemUserRole systemRoleResource = new SystemUserRole();
systemRoleResource.setRoleId(resourceId);
systemRoleResource.setUserId(reqUserInfo.getId());
return systemRoleResource;
}).collect(Collectors.toList());
userRoleService.saveBatch(newRoleResources);
List<Long> deleteRoleResources = roleResources.stream()
.map(SystemUserRole::getRoleId).filter(id -> !reqUserInfo.getRoleIds().contains(id))
.collect(Collectors.toList());
userRoleService.removeByIds(deleteRoleResources);
return Result.success("更新成功");
}
/**
* 根据id 删除用户
*/
@PostMapping("/deleateByUserId")
public Result deleateByUserid(Long id){
this.userInfoService.removeById(id);
return Result.success("更新成功");
}
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment