|
@@ -8,6 +8,11 @@ import java.util.Map;
|
|
|
import java.util.stream.Collectors;
|
|
|
import java.util.stream.Stream;
|
|
|
|
|
|
+import javax.persistence.criteria.Join;
|
|
|
+import javax.persistence.criteria.JoinType;
|
|
|
+import javax.persistence.criteria.Predicate;
|
|
|
+import javax.persistence.criteria.Root;
|
|
|
+import javax.persistence.criteria.Subquery;
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
|
|
|
import org.apache.commons.lang.StringEscapeUtils;
|
|
@@ -18,6 +23,7 @@ import org.springframework.data.domain.PageImpl;
|
|
|
import org.springframework.data.domain.PageRequest;
|
|
|
import org.springframework.data.domain.Pageable;
|
|
|
import org.springframework.data.domain.Sort;
|
|
|
+import org.springframework.data.jpa.domain.Specification;
|
|
|
import org.springframework.http.HttpStatus;
|
|
|
import org.springframework.http.ResponseEntity;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
@@ -39,6 +45,7 @@ import cn.com.qmth.examcloud.commons.base.exception.StatusException;
|
|
|
import cn.com.qmth.examcloud.commons.base.util.ErrorMsg;
|
|
|
import cn.com.qmth.examcloud.commons.web.helpers.page.PageInfo;
|
|
|
import cn.com.qmth.examcloud.commons.web.security.annotation.Uac;
|
|
|
+import cn.com.qmth.examcloud.commons.web.security.bean.User;
|
|
|
import cn.com.qmth.examcloud.commons.web.security.entity.AccessUser;
|
|
|
import cn.com.qmth.examcloud.commons.web.security.enums.RoleMeta;
|
|
|
import cn.com.qmth.examcloud.commons.web.security.enums.UacPolicy;
|
|
@@ -99,10 +106,11 @@ public class UserController extends ControllerSupport {
|
|
|
@GetMapping("/all/{curPage}/{pageSize}")
|
|
|
public PageInfo<FullUserInfo> getAllUser(@PathVariable Integer curPage,
|
|
|
@PathVariable Integer pageSize, @RequestParam Long rootOrgId,
|
|
|
- @RequestParam String loginName, @RequestParam String name, @RequestParam String enable,
|
|
|
- @RequestParam(required = false) Long roleId, @RequestParam String type) {
|
|
|
+ @RequestParam String loginName, @RequestParam String name,
|
|
|
+ @RequestParam(required = false) Boolean enable,
|
|
|
+ @RequestParam(required = false) Long roleId) {
|
|
|
|
|
|
- cn.com.qmth.examcloud.commons.web.security.bean.User accessUser = getAccessUser();
|
|
|
+ User accessUser = getAccessUser();
|
|
|
if ((!isSuperAdmin()) && (!rootOrgId.equals(accessUser.getRootOrgId()))) {
|
|
|
throw new StatusException("B-150001", "非法请求");
|
|
|
}
|
|
@@ -115,27 +123,39 @@ public class UserController extends ControllerSupport {
|
|
|
throw new StatusException("B-150004", "机构错误");
|
|
|
}
|
|
|
|
|
|
- String roleCode = null;
|
|
|
if (null != roleId) {
|
|
|
RoleEntity roleEntity = roleRepo.findOne(roleId);
|
|
|
if (null == roleEntity) {
|
|
|
throw new StatusException("B-150002", "角色不存在");
|
|
|
}
|
|
|
- roleCode = roleEntity.getCode();
|
|
|
}
|
|
|
|
|
|
- Pageable pageable = new PageRequest(curPage - 1, pageSize, Sort.Direction.DESC,
|
|
|
- "update_time");
|
|
|
+ Specification<UserEntity> specification = (root, query, cb) -> {
|
|
|
+ List<Predicate> predicates = new ArrayList<>();
|
|
|
+ predicates.add(cb.equal(root.get("rootOrgId"), rootOrgId));
|
|
|
|
|
|
- loginName = toSqlSearchPattern(loginName);
|
|
|
- name = toSqlSearchPattern(name);
|
|
|
+ if (StringUtils.isNotBlank(loginName)) {
|
|
|
+ predicates.add(cb.like(root.get("loginName"), toSqlSearchPattern(loginName)));
|
|
|
+ }
|
|
|
+ if (StringUtils.isNotBlank(name)) {
|
|
|
+ predicates.add(cb.like(root.get("name"), toSqlSearchPattern(name)));
|
|
|
+ }
|
|
|
+ if (null != roleId) {
|
|
|
+ Subquery<UserRoleRelationEntity> subquery = query
|
|
|
+ .subquery(UserRoleRelationEntity.class);
|
|
|
+ Root<UserRoleRelationEntity> subRoot = subquery.from(UserRoleRelationEntity.class);
|
|
|
+ subquery.select(subRoot);
|
|
|
+ Predicate p1 = cb.equal(subRoot.get("roleId"), roleId);
|
|
|
+ Predicate p2 = cb.equal(subRoot.get("userId"), root.get("id"));
|
|
|
+ subquery.where(cb.and(p1, p2));
|
|
|
+ predicates.add(cb.exists(subquery));
|
|
|
+ }
|
|
|
+ return cb.and(predicates.toArray(new Predicate[predicates.size()]));
|
|
|
+ };
|
|
|
+ Pageable pageable = new PageRequest(curPage - 1, pageSize, Sort.Direction.DESC,
|
|
|
+ "updateTime");
|
|
|
|
|
|
- Page<UserEntity> userList = null;
|
|
|
- if (null == roleCode) {
|
|
|
- userList = userRepo.findAll(rootOrgId, name, loginName, type, pageable);
|
|
|
- } else {
|
|
|
- userList = userRepo.findAll(rootOrgId, name, loginName, type, roleCode, pageable);
|
|
|
- }
|
|
|
+ Page<UserEntity> userList = userRepo.findAll(specification, pageable);
|
|
|
|
|
|
Iterator<UserEntity> iterator = userList.iterator();
|
|
|
|