| | |
| | | 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;
|
| | |
| | |
|
| | | @Autowired
|
| | | private ISysConfigService configService;
|
| | |
|
| | | @Autowired
|
| | | protected Validator validator;
|
| | |
|
| | | /**
|
| | | * 根据条件分页查询用户列表
|
| | |
| | | */
|
| | | 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);
|
| | |
| | | SysUser u = userMapper.selectUserByUserName(user.getUserName());
|
| | | if (StringUtils.isNull(u))
|
| | | {
|
| | | BeanValidators.validateWithException(validator, user);
|
| | | user.setPassword(SecurityUtils.encryptPassword(password));
|
| | | user.setCreateBy(operName);
|
| | | this.insertUser(user);
|
| | |
| | | }
|
| | | else if (isUpdateSupport)
|
| | | {
|
| | | BeanValidators.validateWithException(validator, user);
|
| | | user.setUpdateBy(operName);
|
| | | this.updateUser(user);
|
| | | successNum++;
|