|
@@ -4,6 +4,7 @@ import java.util.ArrayList;
|
|
|
import java.util.Date;
|
|
|
import java.util.Iterator;
|
|
|
import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
import java.util.stream.Collectors;
|
|
|
import java.util.stream.Stream;
|
|
|
|
|
@@ -32,6 +33,7 @@ import org.springframework.web.bind.annotation.RequestParam;
|
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
|
import com.google.common.collect.Lists;
|
|
|
+import com.google.common.collect.Maps;
|
|
|
|
|
|
import cn.com.qmth.examcloud.commons.base.exception.StatusException;
|
|
|
import cn.com.qmth.examcloud.commons.base.util.ErrorMsg;
|
|
@@ -213,7 +215,7 @@ public class UserController extends ControllerSupport {
|
|
|
*/
|
|
|
@ApiOperation(value = "新增用户", notes = "新增")
|
|
|
@PostMapping
|
|
|
- public Long addUser(@RequestBody UserForm userForm) {
|
|
|
+ public Map<String, Object> addUser(@RequestBody UserForm userForm) {
|
|
|
userForm.setId(null);
|
|
|
return insertOrUpdateUser(userForm);
|
|
|
}
|
|
@@ -227,7 +229,7 @@ public class UserController extends ControllerSupport {
|
|
|
*/
|
|
|
@ApiOperation(value = "更新用户", notes = "更新")
|
|
|
@PutMapping
|
|
|
- public Long updateUser(@RequestBody UserForm userForm) {
|
|
|
+ public Map<String, Object> updateUser(@RequestBody UserForm userForm) {
|
|
|
if (null == userForm.getId()) {
|
|
|
throw new StatusException("B-150009", "user ID is null");
|
|
|
}
|
|
@@ -253,7 +255,7 @@ public class UserController extends ControllerSupport {
|
|
|
* @param userForm
|
|
|
* @return
|
|
|
*/
|
|
|
- private Long insertOrUpdateUser(UserForm userForm) {
|
|
|
+ private Map<String, Object> insertOrUpdateUser(UserForm userForm) {
|
|
|
cn.com.qmth.examcloud.commons.web.security.bean.User accessUser = getAccessUser();
|
|
|
Long rootOrgId = userForm.getRootOrgId();
|
|
|
Org rootOrg = orgRepo.findOne(rootOrgId);
|
|
@@ -279,6 +281,8 @@ public class UserController extends ControllerSupport {
|
|
|
userEntity.setPassword(userForm.getPassword());
|
|
|
userEntity.setUpdateTime(new Date());
|
|
|
|
|
|
+ UserEntity saved = userService.save(userEntity);
|
|
|
+
|
|
|
List<UserRoleRelationEntity> userRoles = Lists.newArrayList();
|
|
|
List<Long> roleIds = userForm.getRoleIds();
|
|
|
for (Long cur : roleIds) {
|
|
@@ -289,16 +293,19 @@ public class UserController extends ControllerSupport {
|
|
|
if (curRoleEntity.getCode().equals(RoleMeta.SUPER_ADMIN.getCode())) {
|
|
|
throw new StatusException("B-150007", "不允许新增或修改超级管理员");
|
|
|
}
|
|
|
- UserRoleRelationEntity relation = new UserRoleRelationEntity(userEntity.getId(),
|
|
|
+ UserRoleRelationEntity relation = new UserRoleRelationEntity(saved.getId(),
|
|
|
curRoleEntity.getId(), curRoleEntity.getCode());
|
|
|
userRoles.add(relation);
|
|
|
}
|
|
|
|
|
|
- userRoleRelationRepo.deleteByUserId(userEntity.getId());
|
|
|
- userRoleRelationRepo.save(userRoles);
|
|
|
- UserEntity saved = userService.save(userEntity);
|
|
|
+ userRoleRelationRepo.deleteByUserId(saved.getId());
|
|
|
+ List<UserRoleRelationEntity> savedRelationList = userRoleRelationRepo.save(userRoles);
|
|
|
|
|
|
- return saved.getId();
|
|
|
+ Map<String, Object> ret = Maps.newHashMap();
|
|
|
+ ret.put("userId", saved.getId());
|
|
|
+ ret.put("loginName", saved.getLoginName());
|
|
|
+ ret.put("roleList", savedRelationList);
|
|
|
+ return ret;
|
|
|
}
|
|
|
|
|
|
@ApiOperation(value = "重置用户密码", notes = "重置密码")
|