|
@@ -41,6 +41,7 @@ import cn.com.qmth.examcloud.commons.web.security.enums.RoleMeta;
|
|
import cn.com.qmth.examcloud.commons.web.security.enums.UacPolicy;
|
|
import cn.com.qmth.examcloud.commons.web.security.enums.UacPolicy;
|
|
import cn.com.qmth.examcloud.commons.web.support.ControllerSupport;
|
|
import cn.com.qmth.examcloud.commons.web.support.ControllerSupport;
|
|
import cn.com.qmth.examcloud.core.basic.api.controller.bean.FullUserInfo;
|
|
import cn.com.qmth.examcloud.core.basic.api.controller.bean.FullUserInfo;
|
|
|
|
+import cn.com.qmth.examcloud.core.basic.api.controller.bean.UserForm;
|
|
import cn.com.qmth.examcloud.core.basic.dao.OrgRepo;
|
|
import cn.com.qmth.examcloud.core.basic.dao.OrgRepo;
|
|
import cn.com.qmth.examcloud.core.basic.dao.RoleRepo;
|
|
import cn.com.qmth.examcloud.core.basic.dao.RoleRepo;
|
|
import cn.com.qmth.examcloud.core.basic.dao.UserRepo;
|
|
import cn.com.qmth.examcloud.core.basic.dao.UserRepo;
|
|
@@ -48,6 +49,7 @@ import cn.com.qmth.examcloud.core.basic.dao.entity.Org;
|
|
import cn.com.qmth.examcloud.core.basic.dao.entity.RoleEntity;
|
|
import cn.com.qmth.examcloud.core.basic.dao.entity.RoleEntity;
|
|
import cn.com.qmth.examcloud.core.basic.dao.entity.UserEntity;
|
|
import cn.com.qmth.examcloud.core.basic.dao.entity.UserEntity;
|
|
import cn.com.qmth.examcloud.core.basic.dao.entity.UserRole;
|
|
import cn.com.qmth.examcloud.core.basic.dao.entity.UserRole;
|
|
|
|
+import cn.com.qmth.examcloud.core.basic.dao.enums.UserScope;
|
|
import cn.com.qmth.examcloud.core.basic.dao.enums.UserType;
|
|
import cn.com.qmth.examcloud.core.basic.dao.enums.UserType;
|
|
import cn.com.qmth.examcloud.core.basic.service.bean.UserInfo;
|
|
import cn.com.qmth.examcloud.core.basic.service.bean.UserInfo;
|
|
import cn.com.qmth.examcloud.core.basic.service.impl.UserServiceImpl;
|
|
import cn.com.qmth.examcloud.core.basic.service.impl.UserServiceImpl;
|
|
@@ -75,12 +77,12 @@ public class UserController extends ControllerSupport {
|
|
@ApiOperation(value = "查询所有用户", notes = "")
|
|
@ApiOperation(value = "查询所有用户", notes = "")
|
|
@GetMapping("/all/{curPage}/{pageSize}")
|
|
@GetMapping("/all/{curPage}/{pageSize}")
|
|
public PageInfo<FullUserInfo> getAllUser(@PathVariable Integer curPage,
|
|
public PageInfo<FullUserInfo> getAllUser(@PathVariable Integer curPage,
|
|
- @PathVariable Integer pageSize, @RequestParam Long orgId,
|
|
|
|
|
|
+ @PathVariable Integer pageSize, @RequestParam Long rootOrgId,
|
|
@RequestParam String loginName, @RequestParam String name, @RequestParam String enable,
|
|
@RequestParam String loginName, @RequestParam String name, @RequestParam String enable,
|
|
@RequestParam Long roleId, @RequestParam String type) {
|
|
@RequestParam Long roleId, @RequestParam String type) {
|
|
|
|
|
|
cn.com.qmth.examcloud.commons.web.security.bean.User accessUser = getAccessUser();
|
|
cn.com.qmth.examcloud.commons.web.security.bean.User accessUser = getAccessUser();
|
|
- if ((!isSuperAdmin()) && (!orgId.equals(accessUser.getRootOrgId()))) {
|
|
|
|
|
|
+ if ((!isSuperAdmin()) && (!rootOrgId.equals(accessUser.getRootOrgId()))) {
|
|
throw new StatusException("B-150001", "非法请求");
|
|
throw new StatusException("B-150001", "非法请求");
|
|
}
|
|
}
|
|
|
|
|
|
@@ -97,7 +99,7 @@ public class UserController extends ControllerSupport {
|
|
loginName = "%" + loginName.trim() + "%";
|
|
loginName = "%" + loginName.trim() + "%";
|
|
name = "%" + name.trim() + "%";
|
|
name = "%" + name.trim() + "%";
|
|
|
|
|
|
- Page<UserEntity> userList = userRepo.findAll(orgId, name, loginName, type, roleCode,
|
|
|
|
|
|
+ Page<UserEntity> userList = userRepo.findAll(rootOrgId, name, loginName, type, roleCode,
|
|
pageable);
|
|
pageable);
|
|
Iterator<UserEntity> iterator = userList.iterator();
|
|
Iterator<UserEntity> iterator = userList.iterator();
|
|
|
|
|
|
@@ -150,27 +152,70 @@ public class UserController extends ControllerSupport {
|
|
return new ResponseEntity(userList, HttpStatus.OK);
|
|
return new ResponseEntity(userList, HttpStatus.OK);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * 重构 2018年6月26日
|
|
|
|
+ *
|
|
|
|
+ * @author WANGWEI
|
|
|
|
+ * @param userForm
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
@ApiOperation(value = "新增用户", notes = "新增")
|
|
@ApiOperation(value = "新增用户", notes = "新增")
|
|
@PostMapping
|
|
@PostMapping
|
|
- public ResponseEntity addUser(@RequestBody UserEntity user, HttpServletRequest request) {
|
|
|
|
|
|
+ public Long addUser(@RequestBody UserForm userForm) {
|
|
cn.com.qmth.examcloud.commons.web.security.bean.User accessUser = getAccessUser();
|
|
cn.com.qmth.examcloud.commons.web.security.bean.User accessUser = getAccessUser();
|
|
- if (accessUser != null) {
|
|
|
|
- if (accessUser.getRootOrgId() != 0) {
|
|
|
|
- user.setRootOrgId(accessUser.getRootOrgId());
|
|
|
|
- } else {
|
|
|
|
- user.setRootOrgId(user.getOrgId());
|
|
|
|
- }
|
|
|
|
- } else {
|
|
|
|
- return new ResponseEntity(HttpStatus.NOT_FOUND);
|
|
|
|
|
|
+ Long rootOrgId = userForm.getRootOrgId();
|
|
|
|
+ Org org = orgRepo.findOne(rootOrgId);
|
|
|
|
+ if (null == org) {
|
|
|
|
+ throw new StatusException("B-150003", "机构不存在");
|
|
}
|
|
}
|
|
- try {
|
|
|
|
- return new ResponseEntity(userService.save(user), HttpStatus.CREATED);
|
|
|
|
- } catch (Exception e) {
|
|
|
|
- return new ResponseEntity(new ErrorMsg(e.getMessage()),
|
|
|
|
- HttpStatus.INTERNAL_SERVER_ERROR);
|
|
|
|
|
|
+ if (0 != org.getParentId()) {
|
|
|
|
+ throw new StatusException("B-150004", "机构错误");
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ if ((!isSuperAdmin()) && (!rootOrgId.equals(accessUser.getRootOrgId()))) {
|
|
|
|
+ throw new StatusException("B-150005", "无权操作");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ UserEntity userEntity = new UserEntity();
|
|
|
|
+ userEntity.setEnable(userForm.getEnable());
|
|
|
|
+ userEntity.setLoginName(userForm.getLoginName());
|
|
|
|
+ userEntity.setMobile(userForm.getMobile());
|
|
|
|
+ userEntity.setName(userForm.getName());
|
|
|
|
+ userEntity.setOrgId(rootOrgId);
|
|
|
|
+ userEntity.setRootOrgId(rootOrgId);
|
|
|
|
+ userEntity.setPassword(userForm.getPassword());
|
|
|
|
+ userEntity.setScope(UserScope.ORG);
|
|
|
|
+ userEntity.setType(UserType.NOT_STUDENT);
|
|
|
|
+
|
|
|
|
+ List<UserRole> userRoles = Lists.newArrayList();
|
|
|
|
+
|
|
|
|
+ List<Long> roleIds = userForm.getRoleIds();
|
|
|
|
+ for (Long cur : roleIds) {
|
|
|
|
+ RoleEntity curRoleEntity = roleRepo.findOne(cur);
|
|
|
|
+ if (null == curRoleEntity) {
|
|
|
|
+ throw new StatusException("B-150006", "角色错误");
|
|
|
|
+ }
|
|
|
|
+ if (curRoleEntity.getCode().equals(RoleMeta.SUPER_ADMIN.getCode())) {
|
|
|
|
+ throw new StatusException("B-150007", "不允许添加超级管理员");
|
|
|
|
+ }
|
|
|
|
+ UserRole userRole = new UserRole(curRoleEntity.getCode());
|
|
|
|
+ userRoles.add(userRole);
|
|
|
|
+ }
|
|
|
|
+ userEntity.setUserRoles(userRoles);
|
|
|
|
+
|
|
|
|
+ UserEntity saved = userService.save(userEntity);
|
|
|
|
+
|
|
|
|
+ return saved.getId();
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * 重构 2018年6月26日
|
|
|
|
+ *
|
|
|
|
+ * @author WANGWEI
|
|
|
|
+ * @param user
|
|
|
|
+ * @param request
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
@ApiOperation(value = "更新用户", notes = "更新")
|
|
@ApiOperation(value = "更新用户", notes = "更新")
|
|
@PutMapping
|
|
@PutMapping
|
|
public UserEntity updateUser(@RequestBody UserEntity user, HttpServletRequest request) {
|
|
public UserEntity updateUser(@RequestBody UserEntity user, HttpServletRequest request) {
|