Commit 10d8acab by 陈健智

用户管理调整

parent 431f1904
......@@ -151,7 +151,7 @@ public class UserController extends BaseController {
@ApiOperation("批量编辑项目权限")
@PostMapping("/all-user/batch-update")
@Auth(role = RoleEnum.SUPER_ADMIN)
public ResponseResult updateBatchUserRoles(@ApiParam(name = "json", value = "json:{id:用户id,roles:[{projectId:权限项目id,roleId:权限},{},...]}",
public ResponseResult updateBatchUserRoles(@ApiParam(name = "json", value = "json:{id:用户id,roles:[{projectId:权限项目id,roleId:权限,exportAmount:舆情导出数量,expiredTime:过期时间},{},...]}",
required = true)
@RequestBody JSONObject json) {
return userService.updateBatchUserRoles(json);
......
......@@ -435,13 +435,14 @@ public class UserServiceImpl implements UserService {
List<UserRole> roles = entry.getValue();
for (UserRole role : roles) {
String projectId = role.getProjectId();
Project project = GlobalPojo.PROJECT_MAP.get(projectId);
if (Objects.isNull(project)) {
project = projectDao.findOneById(projectId);
// 已终止/已删除的项目不返回
Project project = projectDao.findOneById(projectId);
if ((Objects.isNull(GlobalPojo.PROJECT_MAP.get(projectId)) && Objects.isNull(project)) || !project.isStart()){
continue;
}
JSONObject jsonObject = new JSONObject();
jsonObject.put("projectId", projectId);
jsonObject.put("projectName", Objects.isNull(project) ? "已删除的项目" : project.getProjectName());
jsonObject.put("projectName", project.getProjectName());
jsonObject.put("id", user.getId());
jsonObject.put("nickname", user.getNickname());
jsonObject.put("username", user.getUsername());
......@@ -516,11 +517,20 @@ public class UserServiceImpl implements UserService {
jsonObject.put("phoneNumber", user.getPhoneNumber());
List<JSONObject> roles = user.getRoles().stream().map(role -> {
JSONObject json = new JSONObject();
String projectId = role.getProjectId();
// 已终止/已删除的项目不返回
Project project = projectDao.findOneById(projectId);
if ((Objects.isNull(GlobalPojo.PROJECT_MAP.get(projectId)) && Objects.isNull(project)) || !project.isStart()){
return null;
}
json.put("projectName", project.getProjectName());
json.put("key", role.getKey());
json.put("projectId", role.getProjectId());
json.put("projectId", projectId);
json.put("roleId", role.getRoleId());
json.put("exportAmount", role.getExportAmount());
json.put("expiredTime", role.getExpiredTime());
return json;
}).collect(Collectors.toList());
}).filter(Objects::nonNull).collect(Collectors.toList());
jsonObject.put("roles", roles);
return ResponseResult.success(jsonObject);
}
......@@ -528,13 +538,19 @@ public class UserServiceImpl implements UserService {
@Override
public ResponseResult updateBatchUserRoles(JSONObject json) {
String id = json.getString("id");
List<UserRole> roles = json.getJSONArray("roles").toJavaList(UserRole.class);
for (UserRole role : roles) {
User user = userDao.findOneById(id);
List<UserRole> newRoles = json.getJSONArray("roles").toJavaList(UserRole.class);
List<String> keys = newRoles.stream().map(UserRole::getKey).collect(Collectors.toList());
// 无需被修改的权限列表
List<UserRole> oldRoles = user.getRoles().stream().filter(role -> !keys.contains(role.getKey())).collect(Collectors.toList());
for (UserRole role : newRoles) {
if (Objects.isNull(role.getExportAmount())) {
role.setExportAmount(1000);
}
role.setKey(Tools.concat(role.getProjectId(), role.getRoleId()));
role.setExpiredTime(null);
}
userDao.updateOneByIdWithField(id, new Update().set("roles", roles));
oldRoles.addAll(newRoles);
userDao.updateOneByIdWithField(id, new Update().set("roles", oldRoles));
return ResponseResult.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