|
@@ -12,7 +12,10 @@ import com.qmth.paper.library.common.bean.dto.UserDto;
|
|
|
import com.qmth.paper.library.common.bean.dto.VerifyCodeCheckDto;
|
|
|
import com.qmth.paper.library.common.bean.params.ApproveUserResult;
|
|
|
import com.qmth.paper.library.common.bean.params.UserSaveParams;
|
|
|
-import com.qmth.paper.library.common.bean.result.*;
|
|
|
+import com.qmth.paper.library.common.bean.result.LoginResult;
|
|
|
+import com.qmth.paper.library.common.bean.result.RoleResult;
|
|
|
+import com.qmth.paper.library.common.bean.result.SysUserResult;
|
|
|
+import com.qmth.paper.library.common.bean.result.UserRoleNameResult;
|
|
|
import com.qmth.paper.library.common.config.DictionaryConfig;
|
|
|
import com.qmth.paper.library.common.contant.SpringContextHolder;
|
|
|
import com.qmth.paper.library.common.contant.SystemConstant;
|
|
@@ -69,9 +72,6 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
|
|
|
@Resource
|
|
|
SysUserMapper sysUserMapper;
|
|
|
|
|
|
- @Resource
|
|
|
- SysOrgService sysOrgService;
|
|
|
-
|
|
|
@Resource
|
|
|
SysUserService sysUserService;
|
|
|
|
|
@@ -400,100 +400,6 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
|
|
|
return resultUserId;
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * 临时保存用户不鉴权
|
|
|
- *
|
|
|
- * @param userSaveParams 用户参数
|
|
|
- * @return 结果
|
|
|
- */
|
|
|
- @Override
|
|
|
- public boolean saveUserNoAuth(UserSaveParams userSaveParams) {
|
|
|
- SysUserService sysUserService = SpringContextHolder.getBean(SysUserService.class);
|
|
|
- boolean isSuccess = true;
|
|
|
- try {
|
|
|
- Long schoolId = Objects.nonNull(ServletUtil.getRequestHeaderSchoolIdByNotVaild()) ? Long.valueOf(ServletUtil.getRequestHeaderSchoolIdByNotVaild().toString()) : null;
|
|
|
- if (schoolId == null) {
|
|
|
- schoolId = userSaveParams.getSchoolId();
|
|
|
- }
|
|
|
- List<SysUser> requestUserList = this.list(new QueryWrapper<SysUser>().lambda().eq(SysUser::getSchoolId, schoolId).like(SysUser::getLoginName, "admin"));
|
|
|
- if (requestUserList.size() == 0) {
|
|
|
- throw ExceptionResultEnum.ERROR.exception("该学校没有内置的学校管理员");
|
|
|
- }
|
|
|
- SysUser requestUser = requestUserList.get(0);
|
|
|
- Gson gson = new Gson();
|
|
|
- userSaveParams.setSchoolId(schoolId);
|
|
|
- SysUser sysUser = gson.fromJson(gson.toJson(userSaveParams), SysUser.class);
|
|
|
- if (Objects.isNull(sysUser.getId())) {//新增用户
|
|
|
- // 登录名是否唯一
|
|
|
- QueryWrapper<SysUser> queryWrapper = new QueryWrapper<>();
|
|
|
- if (Objects.isNull(schoolId)) {
|
|
|
- queryWrapper.lambda().isNull(SysUser::getSchoolId);
|
|
|
- } else {
|
|
|
- queryWrapper.lambda().eq(SysUser::getSchoolId, schoolId);
|
|
|
- }
|
|
|
- queryWrapper.lambda().eq(SysUser::getLoginName, sysUser.getLoginName());
|
|
|
- SysUser user = sysUserService.getOne(queryWrapper);
|
|
|
- if (user != null) {
|
|
|
- throw ExceptionResultEnum.ERROR.exception("用户名已存在");
|
|
|
- }
|
|
|
-
|
|
|
- sysUser.insertInfo(requestUser.getId());
|
|
|
- sysUserService.save(sysUser);
|
|
|
- for (Long roleId : userSaveParams.getRoleIds()) {
|
|
|
- commonService.addUserRolePrivilege(sysUser, roleId);
|
|
|
- }
|
|
|
- } else {//修改用户
|
|
|
- List<SysUserRole> sysUserRoleList = commonCacheService.userRolePrivilegeCache(sysUser.getId());
|
|
|
- List<Long> userRolesList = Arrays.asList(userSaveParams.getRoleIds());
|
|
|
- Set<Long> dbUserRolesList = sysUserRoleList.stream().map(SysUserRole::getRoleId).collect(Collectors.toSet());
|
|
|
- int count = (int) dbUserRolesList.stream().filter(userRolesList::contains).count();
|
|
|
- SysUser dbUser = sysUserService.getById(sysUser.getId());
|
|
|
- sysUser.updateInfo(requestUser.getId());
|
|
|
- sysUserService.updateById(sysUser);
|
|
|
- List<SysRole> list = sysUserRoleService.listRoleByUserId(sysUser.getId());
|
|
|
- boolean containsQuestionTeacher = list.stream().anyMatch(m -> RoleTypeEnum.SCHOOL_ADMIN.equals(m.getType()));
|
|
|
- if (containsQuestionTeacher || count == 0 || dbUserRolesList.size() != userRolesList.size()) {
|
|
|
- QueryWrapper<SysUserRole> sysUserRoleQueryWrapper = new QueryWrapper<>();
|
|
|
- sysUserRoleQueryWrapper.lambda().eq(SysUserRole::getUserId, sysUser.getId());
|
|
|
- sysUserRoleService.remove(sysUserRoleQueryWrapper);
|
|
|
-
|
|
|
- commonCacheService.removeUserRolePrivilegeCache(sysUser.getId());
|
|
|
- for (Long roleId : userSaveParams.getRoleIds()) {
|
|
|
- commonService.addUserRolePrivilege(sysUser, roleId);
|
|
|
- }
|
|
|
- }
|
|
|
- //如果修改了角色,需要重新登录
|
|
|
- if (count == 0 || dbUserRolesList.size() != userRolesList.size()) {
|
|
|
- commonService.removeUserInfo(sysUser.getId(), true);
|
|
|
- }
|
|
|
- //如果修改了机构或手机号,需更新用户缓存
|
|
|
- if (Objects.nonNull(dbUser.getOrgId())) {
|
|
|
- if (containsQuestionTeacher || dbUser.getOrgId().longValue() != sysUser.getOrgId().longValue()
|
|
|
- || !Objects.equals(dbUser.getMobileNumber(), sysUser.getMobileNumber())) {
|
|
|
- if (Objects.isNull(commonCacheService.updateUserCache(sysUser.getId()))) {
|
|
|
- commonCacheService.removeUserCache(sysUser.getId());
|
|
|
- }
|
|
|
- if (Objects.isNull(commonCacheService.updateUserAuthCache(sysUser.getId()))) {
|
|
|
- commonCacheService.removeUserAuthCache(sysUser.getId());
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- } catch (Exception e) {
|
|
|
- log.error(SystemConstant.LOG_ERROR, e);
|
|
|
- isSuccess = false;
|
|
|
- if (e instanceof DuplicateKeyException) {
|
|
|
- String errorColumn = e.getCause().toString();
|
|
|
- String columnStr = errorColumn.substring(errorColumn.lastIndexOf("key") + 3, errorColumn.length()).replaceAll("'", "");
|
|
|
- throw ExceptionResultEnum.SQL_ERROR.exception("[" + FieldUniqueEnum.convertToTitle(columnStr) + "]数据不允许重复插入");
|
|
|
- } else if (e instanceof ApiException) {
|
|
|
- ResultUtil.error((ApiException) e, e.getMessage());
|
|
|
- } else {
|
|
|
- ResultUtil.error(e.getMessage());
|
|
|
- }
|
|
|
- }
|
|
|
- return isSuccess;
|
|
|
- }
|
|
|
|
|
|
/**
|
|
|
* 根据id获取
|
|
@@ -506,16 +412,6 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
|
|
|
return sysUserMapper.findById(id);
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * 根据id集合获取
|
|
|
- *
|
|
|
- * @param ids
|
|
|
- * @return
|
|
|
- */
|
|
|
- @Override
|
|
|
- public ApproveUserResult findByIds(List<Long> ids) {
|
|
|
- return sysUserMapper.findByIds(ids);
|
|
|
- }
|
|
|
|
|
|
@Override
|
|
|
public void checkSmsCode(Long userId, String mobileNumber, String code) {
|
|
@@ -627,136 +523,13 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
|
|
|
return sysUserMapper.findByRoldIdAndMemberName(roleId, name, sysUser.getSchoolId());
|
|
|
}
|
|
|
|
|
|
- @Override
|
|
|
- public boolean includeSysRole(Long userId, RoleTypeEnum defaultRole) {
|
|
|
- SysRole sysRole = sysRoleService.getOne(new QueryWrapper<SysRole>().lambda().eq(SysRole::getType, defaultRole));
|
|
|
- if (Objects.nonNull(sysRole)) {
|
|
|
- SysUserRole sysUserRole = sysUserRoleService.getOne(new QueryWrapper<SysUserRole>()
|
|
|
- .lambda()
|
|
|
- .eq(SysUserRole::getUserId, userId)
|
|
|
- .eq(SysUserRole::getRoleId, sysRole.getId()));
|
|
|
- return Objects.nonNull(sysUserRole);
|
|
|
- }
|
|
|
- return false;
|
|
|
- }
|
|
|
-
|
|
|
@Transactional
|
|
|
@Override
|
|
|
- public boolean delete(Long id) {
|
|
|
- this.removeById(id);
|
|
|
- sysUserRoleService.removeByUserId(id);
|
|
|
- return true;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 批量处理用户信息帮助类
|
|
|
- *
|
|
|
- * @param userSaveParamsList 用户信息集合
|
|
|
- * @param master 创建人信息
|
|
|
- * @return 处理后的结果
|
|
|
- */
|
|
|
- @Deprecated
|
|
|
- private UserBatchDisposeResult disposeUserInfoHelp(List<UserSaveParams> userSaveParamsList, SysUser master) throws NoSuchAlgorithmException {
|
|
|
- Long schoolId = master.getSchoolId();
|
|
|
- List<SysUser> userList = new ArrayList<>();
|
|
|
- List<SysUserRole> sysUserRoleList = new ArrayList<>();
|
|
|
- // 用户角色更新 - 对用户角色权限的各种清除操作
|
|
|
- Set<Long> willRemoveUserPri = new HashSet<>();
|
|
|
- // 用户基础信息更新 - 对用户权限缓存的更新
|
|
|
- Set<Long> willUpdateUserPri = new HashSet<>();
|
|
|
- for (UserSaveParams userSaveParams : userSaveParamsList) {
|
|
|
- String mobileNumber = userSaveParams.getMobileNumber();
|
|
|
- // 手机号检验
|
|
|
- if (SystemConstant.strNotNull(mobileNumber)) {
|
|
|
- SysUser checkMobileNumber = this.getOne(new QueryWrapper<SysUser>().lambda().eq(SysUser::getSchoolId, schoolId).eq(SysUser::getEnable, true).eq(SysUser::getMobileNumber, mobileNumber));
|
|
|
- if (Objects.nonNull(checkMobileNumber)) {
|
|
|
- if (!checkMobileNumber.getId().equals(userSaveParams.getId())) {
|
|
|
- throw ExceptionResultEnum.ERROR.exception("用户手机号【" + mobileNumber + "】重复");
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- Gson gson = new Gson();
|
|
|
- userSaveParams.setSchoolId(schoolId);
|
|
|
- SysUser userCell = gson.fromJson(gson.toJson(userSaveParams), SysUser.class);
|
|
|
- if (Objects.isNull(userCell.getId())) {//新增用户
|
|
|
- userCell.insertInfo(master.getId());
|
|
|
- userList.add(userCell);
|
|
|
- List<SysUserRole> sysUserRoleCell = commonService.disposeUserPrivilege(userCell, userSaveParams.getRoleIds());
|
|
|
- sysUserRoleList.addAll(sysUserRoleCell);
|
|
|
- } else {//修改用户
|
|
|
- List<SysUserRole> oldRoleList = commonCacheService.userRolePrivilegeCache(userCell.getId());
|
|
|
- List<Long> newRoleList = Arrays.asList(userSaveParams.getRoleIds());
|
|
|
- Set<Long> dbUserRolesList = oldRoleList.stream().map(SysUserRole::getRoleId).collect(Collectors.toSet());
|
|
|
- int count = (int) dbUserRolesList.stream().filter(newRoleList::contains).count();
|
|
|
- SysUser dbUser = this.getById(userCell.getId());
|
|
|
- userCell.updateInfo(master.getId());
|
|
|
- userList.add(userCell);
|
|
|
- //如果修改了角色,需要重新登录
|
|
|
- if (count == 0 || dbUserRolesList.size() != newRoleList.size()) {
|
|
|
- List<SysUserRole> sysUserRoleCell = commonService.disposeUserPrivilege(userCell, userSaveParams.getRoleIds());
|
|
|
- sysUserRoleList.addAll(sysUserRoleCell);
|
|
|
- willRemoveUserPri.add(userCell.getId());
|
|
|
- } else if (!dbUser.getOrgId().equals(userCell.getOrgId())) {
|
|
|
- commonService.removeUserInfo(userCell.getId(), true);
|
|
|
- }
|
|
|
- //如果修改了机构或手机号,需更新用户缓存
|
|
|
- if (Objects.nonNull(dbUser.getOrgId())) {
|
|
|
- if (dbUser.getOrgId().longValue() != userCell.getOrgId().longValue()
|
|
|
- || !Objects.equals(dbUser.getMobileNumber(), userCell.getMobileNumber())) {
|
|
|
- willUpdateUserPri.add(userCell.getId());
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
+ public boolean delete(List<Long> ids) {
|
|
|
+ this.removeByIds(ids);
|
|
|
+ for (Long id : ids) {
|
|
|
+ sysUserRoleService.removeByUserId(id);
|
|
|
}
|
|
|
- UserBatchDisposeResult userBatchDisposeResult = new UserBatchDisposeResult();
|
|
|
- userBatchDisposeResult.setUserList(userList);
|
|
|
- userBatchDisposeResult.setUserRoleList(sysUserRoleList);
|
|
|
- userBatchDisposeResult.setRemoveIdSet(willRemoveUserPri);
|
|
|
- userBatchDisposeResult.setUpdateIdSet(willUpdateUserPri);
|
|
|
-
|
|
|
- return userBatchDisposeResult;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 解析机构名称
|
|
|
- *
|
|
|
- * @param schoolId 学校id
|
|
|
- * @param orgName 结构名称
|
|
|
- * @return 机构id
|
|
|
- */
|
|
|
- private Long analyzeOrgName(Long schoolId, String orgName) {
|
|
|
- SysOrg sysOrg = sysOrgService.getOne(new QueryWrapper<SysOrg>().lambda().eq(SysOrg::getEnable, true).eq(SysOrg::getSchoolId, schoolId).eq(SysOrg::getName, orgName));
|
|
|
- if (Objects.isNull(sysOrg)) {
|
|
|
- throw ExceptionResultEnum.ERROR.exception("系统中不存在excel导入的机构【" + orgName + "】");
|
|
|
- }
|
|
|
- return sysOrg.getId();
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 根据角色名称获取角色id集合
|
|
|
- *
|
|
|
- * @param schoolId 学校id
|
|
|
- * @param roleName 角色名称组
|
|
|
- * @return 角色集合
|
|
|
- */
|
|
|
- private LinkedHashSet<Long> analyzeRoleName(Long schoolId, String roleName) {
|
|
|
- LinkedHashSet<Long> roleIdList = new LinkedHashSet<>();
|
|
|
- String[] arr = roleName.split(SystemConstant.COMMA);
|
|
|
- for (String cell : arr) {
|
|
|
- QueryWrapper<SysRole> sysRoleQueryWrapper = new QueryWrapper<>();
|
|
|
- sysRoleQueryWrapper.lambda().eq(SysRole::getEnable, true)
|
|
|
- .eq(SysRole::getName, cell);
|
|
|
- if (Objects.isNull(RoleTypeEnum.convertDescToEnum(cell))) {
|
|
|
- // 自定义角色带学校id查
|
|
|
- sysRoleQueryWrapper.lambda().eq(SysRole::getSchoolId, schoolId);
|
|
|
- }
|
|
|
- SysRole sysRole = sysRoleService.getOne(sysRoleQueryWrapper);
|
|
|
- if (Objects.isNull(sysRole)) {
|
|
|
- throw ExceptionResultEnum.ERROR.exception("系统中不存在excel导入的角色【" + cell + "】");
|
|
|
- }
|
|
|
- roleIdList.add(sysRole.getId());
|
|
|
- }
|
|
|
- return roleIdList;
|
|
|
+ return true;
|
|
|
}
|
|
|
}
|