|
@@ -52,6 +52,7 @@ 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.UserRoleRelationEntity;
|
|
|
import cn.com.qmth.examcloud.core.basic.service.UserService;
|
|
|
+import cn.com.qmth.examcloud.web.helpers.GlobalHelper;
|
|
|
import cn.com.qmth.examcloud.web.support.ControllerSupport;
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
|
|
@@ -94,10 +95,12 @@ public class UserController extends ControllerSupport {
|
|
|
*/
|
|
|
@ApiOperation(value = "查询所有用户", notes = "")
|
|
|
@GetMapping("all/{curPage}/{pageSize}")
|
|
|
- public PageInfo<UserDomain> getUserPage(@PathVariable Integer curPage, @PathVariable Integer pageSize,
|
|
|
- @RequestParam(required = false) Long rootOrgId, @RequestParam String loginName, @RequestParam String name,
|
|
|
- @RequestParam(required = false) Boolean enable, @RequestParam(required = false) Long roleId,
|
|
|
- @RequestParam(required = false) Long orgId, @RequestParam(required = false) String roleCode) {
|
|
|
+ public PageInfo<UserDomain> getUserPage(@PathVariable Integer curPage,
|
|
|
+ @PathVariable Integer pageSize, @RequestParam(required = false) Long rootOrgId,
|
|
|
+ @RequestParam String loginName, @RequestParam String name,
|
|
|
+ @RequestParam(required = false) Boolean enable,
|
|
|
+ @RequestParam(required = false) Long roleId, @RequestParam(required = false) Long orgId,
|
|
|
+ @RequestParam(required = false) String roleCode) {
|
|
|
|
|
|
User accessUser = getAccessUser();
|
|
|
|
|
@@ -109,7 +112,7 @@ public class UserController extends ControllerSupport {
|
|
|
|
|
|
final Long finalRootOrgId = rootOrgId;
|
|
|
|
|
|
- OrgEntity rootOrg = orgRepo.findOne(rootOrgId);
|
|
|
+ OrgEntity rootOrg = GlobalHelper.getEntity(orgRepo, rootOrgId, OrgEntity.class);
|
|
|
if (null == rootOrg) {
|
|
|
throw new StatusException("B-150003", "机构不存在");
|
|
|
}
|
|
@@ -118,14 +121,15 @@ public class UserController extends ControllerSupport {
|
|
|
}
|
|
|
|
|
|
if (null != roleId) {
|
|
|
- RoleEntity roleEntity = roleRepo.findOne(roleId);
|
|
|
+ RoleEntity roleEntity = GlobalHelper.getEntity(roleRepo, roleId, RoleEntity.class);
|
|
|
if (null == roleEntity) {
|
|
|
throw new StatusException("B-150002", "角色不存在");
|
|
|
}
|
|
|
} else if (StringUtils.isNotBlank(roleCode)) {
|
|
|
RoleEntity roleEntity = roleRepo.findByCodeAndRootOrgIdIsNull(roleCode.trim());
|
|
|
if (null == roleEntity) {
|
|
|
- roleEntity = roleRepo.findByCodeAndRootOrgId(roleCode.trim(), accessUser.getRootOrgId());
|
|
|
+ roleEntity = roleRepo.findByCodeAndRootOrgId(roleCode.trim(),
|
|
|
+ accessUser.getRootOrgId());
|
|
|
}
|
|
|
if (null == roleEntity) {
|
|
|
throw new StatusException("B-150002", "角色不存在");
|
|
@@ -152,7 +156,8 @@ public class UserController extends ControllerSupport {
|
|
|
predicates.add(cb.equal(root.get("enable"), enable));
|
|
|
}
|
|
|
if (null != finalRoleId) {
|
|
|
- Subquery<UserRoleRelationEntity> subquery = query.subquery(UserRoleRelationEntity.class);
|
|
|
+ Subquery<UserRoleRelationEntity> subquery = query
|
|
|
+ .subquery(UserRoleRelationEntity.class);
|
|
|
Root<UserRoleRelationEntity> subRoot = subquery.from(UserRoleRelationEntity.class);
|
|
|
subquery.select(subRoot.get("userId"));
|
|
|
Predicate p1 = cb.equal(subRoot.get("roleId"), finalRoleId);
|
|
@@ -162,7 +167,8 @@ public class UserController extends ControllerSupport {
|
|
|
}
|
|
|
return cb.and(predicates.toArray(new Predicate[predicates.size()]));
|
|
|
};
|
|
|
- Pageable pageable = new PageRequest(curPage - 1, pageSize, Sort.Direction.DESC, "updateTime");
|
|
|
+ Pageable pageable = PageRequest.of(curPage - 1, pageSize, Sort.Direction.DESC,
|
|
|
+ "updateTime");
|
|
|
|
|
|
Page<UserEntity> userList = userRepo.findAll(specification, pageable);
|
|
|
|
|
@@ -181,7 +187,8 @@ public class UserController extends ControllerSupport {
|
|
|
bean.setOrgId(next.getOrgId());
|
|
|
bean.setPhoneNumber(next.getPhoneNumber());
|
|
|
if (null != bean.getOrgId()) {
|
|
|
- OrgEntity org = orgRepo.findOne(Long.valueOf(bean.getOrgId()));
|
|
|
+ OrgEntity org = GlobalHelper.getEntity(orgRepo, Long.valueOf(bean.getOrgId()),
|
|
|
+ OrgEntity.class);
|
|
|
if (null != org) {
|
|
|
bean.setOrgName(org.getName());
|
|
|
bean.setOrgCode(org.getCode());
|
|
@@ -190,12 +197,14 @@ public class UserController extends ControllerSupport {
|
|
|
bean.setRootOrgName(rootOrg.getName());
|
|
|
bean.setEnable(next.getEnable());
|
|
|
|
|
|
- List<UserRoleRelationEntity> relationList = userRoleRelationRepo.findAllByUserId(next.getId());
|
|
|
+ List<UserRoleRelationEntity> relationList = userRoleRelationRepo
|
|
|
+ .findAllByUserId(next.getId());
|
|
|
List<String> roleNameList = Lists.newArrayList();
|
|
|
List<Long> roleIdList = Lists.newArrayList();
|
|
|
List<String> roleCodeList = Lists.newArrayList();
|
|
|
for (UserRoleRelationEntity cur : relationList) {
|
|
|
- RoleEntity curRoleEntity = roleRepo.findOne(cur.getRoleId());
|
|
|
+ RoleEntity curRoleEntity = GlobalHelper.getEntity(roleRepo, cur.getRoleId(),
|
|
|
+ RoleEntity.class);
|
|
|
if (null == curRoleEntity) {
|
|
|
throw new StatusException("B-150002", "角色错误");
|
|
|
}
|
|
@@ -219,15 +228,17 @@ public class UserController extends ControllerSupport {
|
|
|
@ApiOperation(value = "模糊查询用户", notes = "")
|
|
|
@GetMapping("query")
|
|
|
public List<UserDomain> query(@RequestParam(required = false) Long rootOrgId,
|
|
|
- @RequestParam(required = false) String rootOrgCode, @RequestParam(required = false) String loginName,
|
|
|
- @RequestParam(required = false) String name, @RequestParam(required = false) Boolean enable,
|
|
|
+ @RequestParam(required = false) String rootOrgCode,
|
|
|
+ @RequestParam(required = false) String loginName,
|
|
|
+ @RequestParam(required = false) String name,
|
|
|
+ @RequestParam(required = false) Boolean enable,
|
|
|
@RequestParam(required = false) Long roleId, @RequestParam(required = false) Long orgId,
|
|
|
@RequestParam(required = false) String roleCode) {
|
|
|
|
|
|
OrgEntity rootOrg = null;
|
|
|
|
|
|
if (null != rootOrgId) {
|
|
|
- rootOrg = orgRepo.findOne(rootOrgId);
|
|
|
+ rootOrg = GlobalHelper.getEntity(orgRepo, rootOrgId, OrgEntity.class);
|
|
|
if (null == rootOrg) {
|
|
|
throw new StatusException("B-150003", "机构不存在");
|
|
|
}
|
|
@@ -248,7 +259,7 @@ public class UserController extends ControllerSupport {
|
|
|
final Long finalRootOrgId = rootOrgId;
|
|
|
|
|
|
if (null != roleId) {
|
|
|
- RoleEntity roleEntity = roleRepo.findOne(roleId);
|
|
|
+ RoleEntity roleEntity = GlobalHelper.getEntity(roleRepo, roleId, RoleEntity.class);
|
|
|
if (null == roleEntity) {
|
|
|
throw new StatusException("B-150002", "角色不存在");
|
|
|
}
|
|
@@ -285,7 +296,8 @@ public class UserController extends ControllerSupport {
|
|
|
predicates.add(cb.equal(root.get("enable"), enable));
|
|
|
}
|
|
|
if (null != finalRoleId) {
|
|
|
- Subquery<UserRoleRelationEntity> subquery = query.subquery(UserRoleRelationEntity.class);
|
|
|
+ Subquery<UserRoleRelationEntity> subquery = query
|
|
|
+ .subquery(UserRoleRelationEntity.class);
|
|
|
Root<UserRoleRelationEntity> subRoot = subquery.from(UserRoleRelationEntity.class);
|
|
|
subquery.select(subRoot.get("userId"));
|
|
|
Predicate p1 = cb.equal(subRoot.get("roleId"), finalRoleId);
|
|
@@ -296,7 +308,7 @@ public class UserController extends ControllerSupport {
|
|
|
return cb.and(predicates.toArray(new Predicate[predicates.size()]));
|
|
|
};
|
|
|
|
|
|
- PageRequest pageRequest = new PageRequest(0, 50, new Sort(Direction.DESC, "updateTime"));
|
|
|
+ PageRequest pageRequest = PageRequest.of(0, 50, new Sort(Direction.DESC, "updateTime"));
|
|
|
|
|
|
Page<UserEntity> userList = userRepo.findAll(specification, pageRequest);
|
|
|
|
|
@@ -314,7 +326,8 @@ public class UserController extends ControllerSupport {
|
|
|
bean.setCreationTime(next.getCreationTime());
|
|
|
bean.setOrgId(next.getOrgId());
|
|
|
if (null != bean.getOrgId()) {
|
|
|
- OrgEntity org = orgRepo.findOne(Long.valueOf(bean.getOrgId()));
|
|
|
+ OrgEntity org = GlobalHelper.getEntity(orgRepo, Long.valueOf(bean.getOrgId()),
|
|
|
+ OrgEntity.class);
|
|
|
if (null != org) {
|
|
|
bean.setOrgName(org.getName());
|
|
|
bean.setOrgCode(org.getCode());
|
|
@@ -323,12 +336,14 @@ public class UserController extends ControllerSupport {
|
|
|
bean.setRootOrgName(rootOrg.getName());
|
|
|
bean.setEnable(next.getEnable());
|
|
|
|
|
|
- List<UserRoleRelationEntity> relationList = userRoleRelationRepo.findAllByUserId(next.getId());
|
|
|
+ List<UserRoleRelationEntity> relationList = userRoleRelationRepo
|
|
|
+ .findAllByUserId(next.getId());
|
|
|
List<String> roleNameList = Lists.newArrayList();
|
|
|
List<Long> roleIdList = Lists.newArrayList();
|
|
|
List<String> roleCodeList = Lists.newArrayList();
|
|
|
for (UserRoleRelationEntity cur : relationList) {
|
|
|
- RoleEntity curRoleEntity = roleRepo.findOne(cur.getRoleId());
|
|
|
+ RoleEntity curRoleEntity = GlobalHelper.getEntity(roleRepo, cur.getRoleId(),
|
|
|
+ RoleEntity.class);
|
|
|
if (null == curRoleEntity) {
|
|
|
throw new StatusException("B-150002", "角色错误");
|
|
|
}
|
|
@@ -357,7 +372,8 @@ public class UserController extends ControllerSupport {
|
|
|
@GetMapping("getUserBySession")
|
|
|
public UserDomain getUserBySession() {
|
|
|
User accessUser = getAccessUser();
|
|
|
- UserEntity userEntity = userRepo.findOne(accessUser.getUserId());
|
|
|
+ UserEntity userEntity = GlobalHelper.getEntity(userRepo, accessUser.getUserId(),
|
|
|
+ UserEntity.class);
|
|
|
|
|
|
UserDomain bean = new UserDomain();
|
|
|
bean.setId(userEntity.getId());
|
|
@@ -368,7 +384,8 @@ public class UserController extends ControllerSupport {
|
|
|
bean.setCreationTime(userEntity.getCreationTime());
|
|
|
bean.setOrgId(userEntity.getOrgId());
|
|
|
if (null != bean.getOrgId()) {
|
|
|
- OrgEntity org = orgRepo.findOne(Long.valueOf(bean.getOrgId()));
|
|
|
+ OrgEntity org = GlobalHelper.getEntity(orgRepo, Long.valueOf(bean.getOrgId()),
|
|
|
+ OrgEntity.class);
|
|
|
if (null != org) {
|
|
|
bean.setOrgName(org.getName());
|
|
|
bean.setOrgCode(org.getCode());
|
|
@@ -388,7 +405,7 @@ public class UserController extends ControllerSupport {
|
|
|
@ApiOperation(value = "按id查询用户", notes = "id查询")
|
|
|
@GetMapping("/{id}")
|
|
|
public UserDomain getUserById(@PathVariable long id) {
|
|
|
- UserEntity userEntity = userRepo.findOne(id);
|
|
|
+ UserEntity userEntity = GlobalHelper.getEntity(userRepo, id, UserEntity.class);
|
|
|
|
|
|
UserDomain bean = new UserDomain();
|
|
|
bean.setId(userEntity.getId());
|
|
@@ -399,7 +416,8 @@ public class UserController extends ControllerSupport {
|
|
|
bean.setCreationTime(userEntity.getCreationTime());
|
|
|
bean.setOrgId(userEntity.getOrgId());
|
|
|
if (null != bean.getOrgId()) {
|
|
|
- OrgEntity org = orgRepo.findOne(Long.valueOf(bean.getOrgId()));
|
|
|
+ OrgEntity org = GlobalHelper.getEntity(orgRepo, Long.valueOf(bean.getOrgId()),
|
|
|
+ OrgEntity.class);
|
|
|
if (null != org) {
|
|
|
bean.setOrgName(org.getName());
|
|
|
bean.setOrgCode(org.getCode());
|
|
@@ -467,7 +485,8 @@ public class UserController extends ControllerSupport {
|
|
|
throw new StatusException("B-150009", "user ID is null");
|
|
|
}
|
|
|
|
|
|
- UserEntity userEntity = userRepo.findOne(userForm.getId());
|
|
|
+ UserEntity userEntity = GlobalHelper.getEntity(userRepo, userForm.getId(),
|
|
|
+ UserEntity.class);
|
|
|
if (null == userEntity) {
|
|
|
throw new StatusException("B-150010", "用户不存在");
|
|
|
}
|
|
@@ -506,7 +525,7 @@ public class UserController extends ControllerSupport {
|
|
|
if (null == rootOrgId) {
|
|
|
throw new StatusException("B-150002", "rootOrgId is null");
|
|
|
}
|
|
|
- OrgEntity rootOrg = orgRepo.findOne(rootOrgId);
|
|
|
+ OrgEntity rootOrg = GlobalHelper.getEntity(orgRepo, rootOrgId, OrgEntity.class);
|
|
|
if (null == rootOrg) {
|
|
|
throw new StatusException("B-150003", "机构不存在");
|
|
|
}
|
|
@@ -517,7 +536,7 @@ public class UserController extends ControllerSupport {
|
|
|
validateRootOrgIsolation(rootOrgId);
|
|
|
|
|
|
if (null != orgId) {
|
|
|
- OrgEntity org = orgRepo.findOne(orgId);
|
|
|
+ OrgEntity org = GlobalHelper.getEntity(orgRepo, orgId, OrgEntity.class);
|
|
|
if (null == org) {
|
|
|
throw new StatusException("B-150101", "子机构不存在");
|
|
|
}
|
|
@@ -545,7 +564,7 @@ public class UserController extends ControllerSupport {
|
|
|
List<UserRoleRelationEntity> userRoles = Lists.newArrayList();
|
|
|
List<Long> roleIds = userForm.getRoleIds();
|
|
|
for (Long cur : roleIds) {
|
|
|
- RoleEntity curRoleEntity = roleRepo.findOne(cur);
|
|
|
+ RoleEntity curRoleEntity = GlobalHelper.getEntity(roleRepo, cur, RoleEntity.class);
|
|
|
if (null == curRoleEntity) {
|
|
|
throw new StatusException("B-150005", "角色错误");
|
|
|
}
|
|
@@ -565,12 +584,13 @@ public class UserController extends ControllerSupport {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- UserRoleRelationEntity relation = new UserRoleRelationEntity(saved.getId(), curRoleEntity.getId());
|
|
|
+ UserRoleRelationEntity relation = new UserRoleRelationEntity(saved.getId(),
|
|
|
+ curRoleEntity.getId());
|
|
|
userRoles.add(relation);
|
|
|
}
|
|
|
|
|
|
userRoleRelationRepo.deleteByUserId(saved.getId());
|
|
|
- List<UserRoleRelationEntity> savedRelationList = userRoleRelationRepo.save(userRoles);
|
|
|
+ List<UserRoleRelationEntity> savedRelationList = userRoleRelationRepo.saveAll(userRoles);
|
|
|
|
|
|
Map<String, Object> ret = Maps.newHashMap();
|
|
|
ret.put("userId", saved.getId());
|
|
@@ -591,7 +611,7 @@ public class UserController extends ControllerSupport {
|
|
|
if (CollectionUtils.isNotEmpty(relationList)) {
|
|
|
for (UserRoleRelationEntity cur : relationList) {
|
|
|
Long roleId = cur.getRoleId();
|
|
|
- RoleEntity roleEntity = roleRepo.findOne(roleId);
|
|
|
+ RoleEntity roleEntity = GlobalHelper.getEntity(roleRepo, roleId, RoleEntity.class);
|
|
|
if (roleEntity.getCode().equals(RoleMeta.SUPER_ADMIN.name())) {
|
|
|
return true;
|
|
|
}
|
|
@@ -604,13 +624,14 @@ public class UserController extends ControllerSupport {
|
|
|
@ApiOperation(value = "重置用户密码", notes = "重置密码")
|
|
|
@PutMapping("/resetPass/{id}")
|
|
|
public void resetPass(@PathVariable String id) {
|
|
|
- List<Long> ids = Stream.of(id.split(",")).map(s -> Long.parseLong(s.trim())).collect(Collectors.toList());
|
|
|
+ List<Long> ids = Stream.of(id.split(",")).map(s -> Long.parseLong(s.trim()))
|
|
|
+ .collect(Collectors.toList());
|
|
|
|
|
|
for (Long userId : ids) {
|
|
|
if (isSuperAdmin(userId)) {
|
|
|
throw new StatusException("B-150410", "超级管理员账号不允许修改");
|
|
|
}
|
|
|
- UserEntity user = userRepo.findOne(userId);
|
|
|
+ UserEntity user = GlobalHelper.getEntity(userRepo, userId, UserEntity.class);
|
|
|
user.setPassword(BasicConsts.DEFAULT_PASSWORD);
|
|
|
userRepo.save(user);
|
|
|
}
|
|
@@ -619,13 +640,14 @@ public class UserController extends ControllerSupport {
|
|
|
@ApiOperation(value = "启用用户", notes = "启用用户")
|
|
|
@PutMapping("/enable/{ids}")
|
|
|
public List<String> enableUser(@PathVariable String ids) {
|
|
|
- List<Long> userIds = Stream.of(ids.split(",")).map(s -> Long.parseLong(s.trim())).collect(Collectors.toList());
|
|
|
+ List<Long> userIds = Stream.of(ids.split(",")).map(s -> Long.parseLong(s.trim()))
|
|
|
+ .collect(Collectors.toList());
|
|
|
List<String> ret = Lists.newArrayList();
|
|
|
for (Long userId : userIds) {
|
|
|
if (isSuperAdmin(userId)) {
|
|
|
throw new StatusException("B-150410", "超级管理员账号不允许修改");
|
|
|
}
|
|
|
- UserEntity user = userRepo.findOne(userId);
|
|
|
+ UserEntity user = GlobalHelper.getEntity(userRepo, userId, UserEntity.class);
|
|
|
user.setEnable(true);
|
|
|
userRepo.save(user);
|
|
|
ret.add(user.getId() + ":" + user.getName());
|
|
@@ -636,13 +658,14 @@ public class UserController extends ControllerSupport {
|
|
|
@ApiOperation(value = "禁用用户", notes = "禁用用户")
|
|
|
@PutMapping("/disable/{ids}")
|
|
|
public List<String> disableUser(@PathVariable String ids) {
|
|
|
- List<Long> userIds = Stream.of(ids.split(",")).map(s -> Long.parseLong(s.trim())).collect(Collectors.toList());
|
|
|
+ List<Long> userIds = Stream.of(ids.split(",")).map(s -> Long.parseLong(s.trim()))
|
|
|
+ .collect(Collectors.toList());
|
|
|
List<String> ret = Lists.newArrayList();
|
|
|
for (Long userId : userIds) {
|
|
|
if (isSuperAdmin(userId)) {
|
|
|
throw new StatusException("B-150410", "超级管理员账号不允许修改");
|
|
|
}
|
|
|
- UserEntity user = userRepo.findOne(userId);
|
|
|
+ UserEntity user = GlobalHelper.getEntity(userRepo, userId, UserEntity.class);
|
|
|
user.setEnable(false);
|
|
|
userRepo.save(user);
|
|
|
ret.add(user.getId() + ":" + user.getName());
|
|
@@ -673,9 +696,10 @@ public class UserController extends ControllerSupport {
|
|
|
@ApiOperation(value = "按id删除用户", notes = "删除")
|
|
|
@DeleteMapping("/{ids}")
|
|
|
public void deleteUser(@PathVariable String ids) {
|
|
|
- List<Long> userIds = Stream.of(ids.split(",")).map(s -> Long.parseLong(s.trim())).collect(Collectors.toList());
|
|
|
+ List<Long> userIds = Stream.of(ids.split(",")).map(s -> Long.parseLong(s.trim()))
|
|
|
+ .collect(Collectors.toList());
|
|
|
for (Long userId : userIds) {
|
|
|
- userRepo.delete(userId);
|
|
|
+ userRepo.deleteById(userId);
|
|
|
}
|
|
|
}
|
|
|
|