|
@@ -14,7 +14,6 @@ import javax.persistence.criteria.Predicate;
|
|
|
import org.apache.commons.lang.StringUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.data.domain.Page;
|
|
|
-import org.springframework.data.domain.PageImpl;
|
|
|
import org.springframework.data.domain.Pageable;
|
|
|
import org.springframework.data.jpa.domain.Specification;
|
|
|
import org.springframework.data.redis.core.RedisTemplate;
|
|
@@ -37,16 +36,13 @@ import cn.com.qmth.examcloud.core.basic.dao.UserLoginRepo;
|
|
|
import cn.com.qmth.examcloud.core.basic.dao.UserOpsLogRepo;
|
|
|
import cn.com.qmth.examcloud.core.basic.dao.UserRepo;
|
|
|
import cn.com.qmth.examcloud.core.basic.dao.UserRoleRepo;
|
|
|
-import cn.com.qmth.examcloud.core.basic.dao.constants.Consts;
|
|
|
import cn.com.qmth.examcloud.core.basic.dao.entity.Org;
|
|
|
-import cn.com.qmth.examcloud.core.basic.dao.entity.Student;
|
|
|
import cn.com.qmth.examcloud.core.basic.dao.entity.ThirdPartyAccessEntity;
|
|
|
import cn.com.qmth.examcloud.core.basic.dao.entity.ThirdPartyAccessPK;
|
|
|
import cn.com.qmth.examcloud.core.basic.dao.entity.UserEntity;
|
|
|
import cn.com.qmth.examcloud.core.basic.dao.entity.UserLogin;
|
|
|
import cn.com.qmth.examcloud.core.basic.dao.entity.UserOpsLog;
|
|
|
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.service.AuthService;
|
|
|
import cn.com.qmth.examcloud.core.basic.service.UserService;
|
|
|
import cn.com.qmth.examcloud.core.basic.service.bean.LoginInfo;
|
|
@@ -95,47 +91,6 @@ public class UserServiceImpl implements UserService {
|
|
|
this.accessUserOps = new AccessUserOpsForRedis(redisTemplate);
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * 查询所有用户
|
|
|
- *
|
|
|
- * @param userCriteria
|
|
|
- * @param pageable
|
|
|
- * @return
|
|
|
- */
|
|
|
- public Page<UserEntity> findAll(UserEntity userCriteria, Pageable pageable) {
|
|
|
- Specification<UserEntity> userSpecification = (root, query, cb) -> {
|
|
|
- List<Predicate> predicates = new ArrayList<>();
|
|
|
- if (userCriteria.getType() != null) {
|
|
|
- predicates.add(cb.equal(root.get("type"), userCriteria.getType()));
|
|
|
- }
|
|
|
- predicates.add(cb.equal(root.get("rootOrgId"), userCriteria.getRootOrgId()));
|
|
|
- if (StringUtils.isNotEmpty(userCriteria.getLoginName())) {
|
|
|
- predicates.add(
|
|
|
- cb.like(root.get("loginName"), "%" + userCriteria.getLoginName() + "%"));
|
|
|
- }
|
|
|
- if (StringUtils.isNotEmpty(userCriteria.getName())) {
|
|
|
- predicates.add(cb.like(root.get("name"), "%" + userCriteria.getName() + "%"));
|
|
|
- }
|
|
|
- if (userCriteria.getOrgId() != null) {
|
|
|
- predicates.add(cb.equal(root.get("orgId"), userCriteria.getOrgId()));
|
|
|
- }
|
|
|
- if (userCriteria.getEnable() != null) {
|
|
|
- predicates.add(cb.equal(root.get("enable"), userCriteria.getEnable()));
|
|
|
- }
|
|
|
- return cb.and(predicates.toArray(new Predicate[predicates.size()]));
|
|
|
- };
|
|
|
- List<UserEntity> users = userRepo.findAll(userSpecification);
|
|
|
- int pageNumber = pageable.getPageNumber();
|
|
|
- int pageSize = pageable.getPageSize();
|
|
|
- users = users.stream().filter(user -> filterNonMarkerUser(user))
|
|
|
- .collect(Collectors.toList());
|
|
|
- long total = users.size();
|
|
|
- users = users.stream().skip(pageNumber * pageSize).limit(pageSize)
|
|
|
- .collect(Collectors.toList());
|
|
|
- Page<UserEntity> userPage = new PageImpl<UserEntity>(users, pageable, total);
|
|
|
- return userPage;
|
|
|
- }
|
|
|
-
|
|
|
/**
|
|
|
* 过滤非评卷员
|
|
|
*
|
|
@@ -177,74 +132,6 @@ public class UserServiceImpl implements UserService {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * 查询所有机构用户
|
|
|
- *
|
|
|
- * @param userCriteria
|
|
|
- * @param pageable
|
|
|
- * @return
|
|
|
- */
|
|
|
- public Page<UserEntity> findOrgUser(UserEntity userCriteria, Pageable pageable) {
|
|
|
- Specification<UserEntity> userSpecification = (root, query, cb) -> {
|
|
|
- List<Predicate> predicates = new ArrayList<>();
|
|
|
- predicates.add(cb.equal(root.get("rootOrgId"), root.get("orgId")));
|
|
|
- if (userCriteria.getType() != null) {
|
|
|
- predicates.add(cb.equal(root.get("type"), userCriteria.getType()));
|
|
|
- }
|
|
|
- if (userCriteria.getOrgId() != null) {
|
|
|
- predicates.add(cb.equal(root.get("rootOrgId"), userCriteria.getOrgId()));
|
|
|
- }
|
|
|
- if (StringUtils.isNotEmpty(userCriteria.getLoginName())) {
|
|
|
- predicates.add(
|
|
|
- cb.like(root.get("loginName"), "%" + userCriteria.getLoginName() + "%"));
|
|
|
- }
|
|
|
- if (StringUtils.isNotEmpty(userCriteria.getName())) {
|
|
|
- predicates.add(cb.like(root.get("name"), "%" + userCriteria.getName() + "%"));
|
|
|
- }
|
|
|
- if (userCriteria.getEnable() != null) {
|
|
|
- predicates.add(cb.equal(root.get("enable"), userCriteria.getEnable()));
|
|
|
- }
|
|
|
- return cb.and(predicates.toArray(new Predicate[predicates.size()]));
|
|
|
- };
|
|
|
- List<UserEntity> users = userRepo.findAll(userSpecification);
|
|
|
- int pageNumber = pageable.getPageNumber();
|
|
|
- int pageSize = pageable.getPageSize();
|
|
|
- users = users.stream().filter(user -> filterAdminUser(user)).collect(Collectors.toList());
|
|
|
- long total = users.size();
|
|
|
- users = users.stream().skip(pageNumber * pageSize).limit(pageSize)
|
|
|
- .collect(Collectors.toList());
|
|
|
- Page<UserEntity> userPage = new PageImpl<UserEntity>(users, pageable, total);
|
|
|
- return userPage;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 初始化密码
|
|
|
- *
|
|
|
- * @param userId
|
|
|
- */
|
|
|
- public void initPassword(long userId) {
|
|
|
- UserEntity user = userRepo.findOne(userId);
|
|
|
- // 根据用户类型采用不同的初始化策略
|
|
|
- if (user.getType() == UserType.COMMON) {
|
|
|
- // 初始化为默认密码
|
|
|
- user.setPassword(Consts.DEFAULT_PASSWORD);
|
|
|
-
|
|
|
- } else if (user.getType() == UserType.STUDENT) {
|
|
|
- // 截取身份证后6位为学生登录密码
|
|
|
- Student student = studentRepo.findByUserId(userId);
|
|
|
- String identityNumber = student.getIdentityNumber();
|
|
|
- if (StringUtils.isNotEmpty(identityNumber)
|
|
|
- && identityNumber.matches("[0-9a-zA-Z]{6,}")) {
|
|
|
- user.setPassword(
|
|
|
- StringUtils.substring(identityNumber, -6, identityNumber.length()));
|
|
|
- } else {
|
|
|
- user.setPassword(Consts.DEFAULT_PASSWORD);
|
|
|
- }
|
|
|
- }
|
|
|
- user.setUpdateTime(new Date());
|
|
|
- userRepo.save(user);
|
|
|
- }
|
|
|
-
|
|
|
/**
|
|
|
* 一般登录
|
|
|
*
|
|
@@ -444,7 +331,6 @@ public class UserServiceImpl implements UserService {
|
|
|
userInfo.setRootOrgName(rootOrg.getName());
|
|
|
}
|
|
|
userInfo.setToken(token);
|
|
|
- userInfo.setType(user.getType().toString());
|
|
|
userInfo.setUserRoles(user.getUserRoles());
|
|
|
userInfo.setRoleNames(getRoleNames(user.getUserRoles()));
|
|
|
return userInfo;
|
|
@@ -537,8 +423,6 @@ public class UserServiceImpl implements UserService {
|
|
|
List<UserRole> userRoles = new LinkedList<UserRole>();
|
|
|
userRoles.add(userRole);
|
|
|
user.setUserRoles(userRoles);
|
|
|
- user.setScope(UserScope.ORG);
|
|
|
- user.setType(UserType.COMMON);
|
|
|
return userRepo.save(user);
|
|
|
}
|
|
|
|