| | |
| | | import java.util.ArrayList;
|
| | | import java.util.List;
|
| | | import java.util.stream.Collectors;
|
| | | import javax.validation.Validator;
|
| | | import org.slf4j.Logger;
|
| | | import org.slf4j.LoggerFactory;
|
| | | import org.springframework.beans.factory.annotation.Autowired;
|
| | |
| | | import com.ruoyi.common.exception.ServiceException;
|
| | | import com.ruoyi.common.utils.SecurityUtils;
|
| | | import com.ruoyi.common.utils.StringUtils;
|
| | | import com.ruoyi.common.utils.bean.BeanValidators;
|
| | | import com.ruoyi.common.utils.spring.SpringUtils;
|
| | | import com.ruoyi.framework.aspectj.lang.annotation.DataScope;
|
| | | import com.ruoyi.project.system.domain.SysPost;
|
| | |
| | | import com.ruoyi.project.system.mapper.SysUserPostMapper;
|
| | | import com.ruoyi.project.system.mapper.SysUserRoleMapper;
|
| | | import com.ruoyi.project.system.service.ISysConfigService;
|
| | | import com.ruoyi.project.system.service.ISysDeptService;
|
| | | import com.ruoyi.project.system.service.ISysUserService;
|
| | |
|
| | | /**
|
| | |
| | |
|
| | | @Autowired
|
| | | private ISysConfigService configService;
|
| | |
|
| | | @Autowired
|
| | | private ISysDeptService deptService;
|
| | |
|
| | | @Autowired
|
| | | protected Validator validator;
|
| | |
|
| | | /**
|
| | | * 根据条件分页查询用户列表
|
| | |
| | | /**
|
| | | * 校验用户名称是否唯一
|
| | | *
|
| | | * @param userName 用户名称
|
| | | * @param user 用户信息
|
| | | * @return 结果
|
| | | */
|
| | | @Override
|
| | | public String checkUserNameUnique(String userName)
|
| | | public boolean checkUserNameUnique(SysUser user)
|
| | | {
|
| | | int count = userMapper.checkUserNameUnique(userName);
|
| | | if (count > 0)
|
| | | Long userId = StringUtils.isNull(user.getUserId()) ? -1L : user.getUserId();
|
| | | SysUser info = userMapper.checkUserNameUnique(user.getUserName());
|
| | | if (StringUtils.isNotNull(info) && info.getUserId().longValue() != userId.longValue())
|
| | | {
|
| | | return UserConstants.NOT_UNIQUE;
|
| | | }
|
| | |
| | | * @return
|
| | | */
|
| | | @Override
|
| | | public String checkPhoneUnique(SysUser user)
|
| | | public boolean checkPhoneUnique(SysUser user)
|
| | | {
|
| | | Long userId = StringUtils.isNull(user.getUserId()) ? -1L : user.getUserId();
|
| | | SysUser info = userMapper.checkPhoneUnique(user.getPhonenumber());
|
| | |
| | | * @return
|
| | | */
|
| | | @Override
|
| | | public String checkEmailUnique(SysUser user)
|
| | | public boolean checkEmailUnique(SysUser user)
|
| | | {
|
| | | Long userId = StringUtils.isNull(user.getUserId()) ? -1L : user.getUserId();
|
| | | SysUser info = userMapper.checkEmailUnique(user.getEmail());
|
| | |
| | | */
|
| | | public void insertUserRole(SysUser user)
|
| | | {
|
| | | Long[] roles = user.getRoleIds();
|
| | | if (StringUtils.isNotNull(roles))
|
| | | {
|
| | | // 新增用户与角色管理
|
| | | List<SysUserRole> list = new ArrayList<SysUserRole>();
|
| | | for (Long roleId : roles)
|
| | | {
|
| | | SysUserRole ur = new SysUserRole();
|
| | | ur.setUserId(user.getUserId());
|
| | | ur.setRoleId(roleId);
|
| | | list.add(ur);
|
| | | }
|
| | | if (list.size() > 0)
|
| | | {
|
| | | userRoleMapper.batchUserRole(list);
|
| | | }
|
| | | }
|
| | | this.insertUserRole(user.getUserId(), user.getRoleIds());
|
| | | }
|
| | |
|
| | | /**
|
| | |
| | | public void insertUserPost(SysUser user)
|
| | | {
|
| | | Long[] posts = user.getPostIds();
|
| | | if (StringUtils.isNotNull(posts))
|
| | | if (StringUtils.isNotEmpty(posts))
|
| | | {
|
| | | // 新增用户与岗位管理
|
| | | List<SysUserPost> list = new ArrayList<SysUserPost>();
|
| | | List<SysUserPost> list = new ArrayList<SysUserPost>(posts.length);
|
| | | for (Long postId : posts)
|
| | | {
|
| | | SysUserPost up = new SysUserPost();
|
| | |
| | | up.setPostId(postId);
|
| | | list.add(up);
|
| | | }
|
| | | if (list.size() > 0)
|
| | | {
|
| | | userPostMapper.batchUserPost(list);
|
| | | }
|
| | | userPostMapper.batchUserPost(list);
|
| | | }
|
| | | }
|
| | |
|
| | |
| | | */
|
| | | public void insertUserRole(Long userId, Long[] roleIds)
|
| | | {
|
| | | if (StringUtils.isNotNull(roleIds))
|
| | | if (StringUtils.isNotEmpty(roleIds))
|
| | | {
|
| | | // 新增用户与角色管理
|
| | | List<SysUserRole> list = new ArrayList<SysUserRole>();
|
| | | List<SysUserRole> list = new ArrayList<SysUserRole>(roleIds.length);
|
| | | for (Long roleId : roleIds)
|
| | | {
|
| | | SysUserRole ur = new SysUserRole();
|
| | |
| | | ur.setRoleId(roleId);
|
| | | list.add(ur);
|
| | | }
|
| | | if (list.size() > 0)
|
| | | {
|
| | | userRoleMapper.batchUserRole(list);
|
| | | }
|
| | | userRoleMapper.batchUserRole(list);
|
| | | }
|
| | | }
|
| | |
|
| | |
| | | for (Long userId : userIds)
|
| | | {
|
| | | checkUserAllowed(new SysUser(userId));
|
| | | checkUserDataScope(userId);
|
| | | }
|
| | | // 删除用户与角色关联
|
| | | userRoleMapper.deleteUserRole(userIds);
|
| | |
| | | int failureNum = 0;
|
| | | StringBuilder successMsg = new StringBuilder();
|
| | | StringBuilder failureMsg = new StringBuilder();
|
| | | String password = configService.selectConfigByKey("sys.user.initPassword");
|
| | | for (SysUser user : userList)
|
| | | {
|
| | | try
|
| | |
| | | SysUser u = userMapper.selectUserByUserName(user.getUserName());
|
| | | if (StringUtils.isNull(u))
|
| | | {
|
| | | BeanValidators.validateWithException(validator, user);
|
| | | deptService.checkDeptDataScope(user.getDeptId());
|
| | | String password = configService.selectConfigByKey("sys.user.initPassword");
|
| | | user.setPassword(SecurityUtils.encryptPassword(password));
|
| | | user.setCreateBy(operName);
|
| | | this.insertUser(user);
|
| | | userMapper.insertUser(user);
|
| | | successNum++;
|
| | | successMsg.append("<br/>" + successNum + "、账号 " + user.getUserName() + " 导入成功");
|
| | | }
|
| | | else if (isUpdateSupport)
|
| | | {
|
| | | BeanValidators.validateWithException(validator, user);
|
| | | checkUserAllowed(u);
|
| | | checkUserDataScope(u.getUserId());
|
| | | deptService.checkDeptDataScope(user.getDeptId());
|
| | | user.setUserId(u.getUserId());
|
| | | user.setUpdateBy(operName);
|
| | | this.updateUser(user);
|
| | | userMapper.updateUser(user);
|
| | | successNum++;
|
| | | successMsg.append("<br/>" + successNum + "、账号 " + user.getUserName() + " 更新成功");
|
| | | }
|