| | |
| | | import com.xcong.farmer.cms.modules.system.mapper.*; |
| | | import com.xcong.farmer.cms.modules.system.service.IUserService; |
| | | import com.xcong.farmer.cms.modules.system.util.LoginUserUtil; |
| | | import com.xcong.farmer.cms.modules.system.vo.AdminRoleVo; |
| | | import com.xcong.farmer.cms.modules.system.vo.AdminSeeUserInfoVo; |
| | | import com.xcong.farmer.cms.modules.system.vo.AdminUserMenuVo; |
| | | import com.xcong.farmer.cms.modules.system.vo.AdminUserVo; |
| | | import com.xcong.farmer.cms.modules.system.vo.*; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.stereotype.Service; |
| | | import cn.hutool.core.util.StrUtil; |
| | |
| | | @Resource |
| | | private RoleMenuMapper roleMenuMapper; |
| | | @Resource |
| | | private ColumnMapper columnMapper; |
| | | @Resource |
| | | private ArticleMapper articleMapper; |
| | | @Resource |
| | | private MessageBoardMapper messageBoardMapper; |
| | | @Resource |
| | | private MenuMapper menuMapper; |
| | | |
| | | @Override |
| | |
| | | UserEntity userlogin = LoginUserUtil.getLoginUser(); |
| | | Page<AdminUserVo> page = new Page<>(adminUserDto.getPageNum(), adminUserDto.getPageSize()); |
| | | UserEntity userEntity = new UserEntity(); |
| | | long belongId = userlogin.getBelongId() == null ? 0L : userlogin.getBelongId(); |
| | | if(belongId > 0L){ |
| | | userEntity.setBelongId(belongId); |
| | | long companyId = userlogin.getCompanyId() == null ? UserEntity.USER_BELONG_TOP : userlogin.getCompanyId(); |
| | | if(companyId > UserEntity.USER_BELONG_TOP){ |
| | | userEntity.setCompanyId(companyId); |
| | | userEntity.setRoleName(RoleEntity.ROLE_ADMIN_NAME); |
| | | }else if(companyId == UserEntity.USER_BELONG_TOP){ |
| | | userEntity.setRoleName(RoleEntity.ROLE_SUPER_NAME); |
| | | } |
| | | if(StrUtil.isNotEmpty(adminUserDto.getUsername())){ |
| | | userEntity.setUsername(adminUserDto.getUsername()); |
| | |
| | | public Result addUser(AdminAddUserDto adminAddUserDto) { |
| | | UserEntity userlogin = LoginUserUtil.getLoginUser(); |
| | | String username = adminAddUserDto.getUsername(); |
| | | if(StrUtil.isEmpty(username)){ |
| | | return Result.fail("请输入用户名"); |
| | | QueryWrapper<UserEntity> objectQueryWrapper = new QueryWrapper<>(); |
| | | objectQueryWrapper.eq("username",username); |
| | | List<UserEntity> userEntities = this.baseMapper.selectList(objectQueryWrapper); |
| | | if(CollUtil.isNotEmpty(userEntities)){ |
| | | return Result.fail("用户名重复"); |
| | | } |
| | | String roleIds = adminAddUserDto.getRoleIds(); |
| | | if(StrUtil.isEmpty(roleIds)){ |
| | | return Result.fail("请选择用户角色"); |
| | | } |
| | | String phone = adminAddUserDto.getPhone(); |
| | | if(StrUtil.isEmpty(phone)){ |
| | | return Result.fail("请输入联系电话"); |
| | | } |
| | | Long belongId = adminAddUserDto.getBelongId() == null ? 0L:adminAddUserDto.getBelongId(); |
| | | if(belongId == 0L){ |
| | | Long belongId = adminAddUserDto.getBelongId() == null ? UserEntity.USER_BELONG_TOP:adminAddUserDto.getBelongId(); |
| | | if(belongId == UserEntity.USER_BELONG_TOP){ |
| | | return Result.fail("请选择所属公司"); |
| | | } |
| | | UserEntity userEntity = new UserEntity(); |
| | |
| | | } |
| | | userEntity.setPassword(SecureUtil.md5(UserEntity.PASSWORD_DEFAULT)); |
| | | userEntity.setStatus(UserEntity.STATUS_ENABLE); |
| | | userEntity.setBelongId(belongId); |
| | | userEntity.setCompanyId(belongId); |
| | | int insert = this.baseMapper.insert(userEntity); |
| | | if(insert > 0){ |
| | | saveUserRole(roleIds,userEntity.getId()); |
| | |
| | | adminSeeUserInfoVo.setNickname(userEntity.getNickname()); |
| | | adminSeeUserInfoVo.setPhone(userEntity.getPhone()); |
| | | adminSeeUserInfoVo.setEmail(userEntity.getEmail()); |
| | | adminSeeUserInfoVo.setBelongId(userEntity.getCompanyId()); |
| | | |
| | | List<AdminRoleVo> adminRoleVos = new ArrayList<>(); |
| | | QueryWrapper<UserRoleEntity> objectQueryWrapper = new QueryWrapper<>(); |
| | |
| | | if(StrUtil.isEmpty(phone)){ |
| | | return Result.fail("请输入联系电话"); |
| | | } |
| | | Long belongId = adminUpdateUserDto.getBelongId() == null ? UserEntity.USER_BELONG_TOP : adminUpdateUserDto.getBelongId(); |
| | | if(UserEntity.USER_BELONG_TOP == belongId){ |
| | | return Result.fail("请输入所属公司"); |
| | | } |
| | | UserEntity userEntity = this.baseMapper.selectById(adminUpdateUserDto.getId()); |
| | | if(ObjectUtil.isEmpty(userEntity)){ |
| | | return Result.fail("用户不存在"); |
| | | } |
| | | userEntity.setCompanyId(belongId); |
| | | userEntity.setUsername(username); |
| | | userEntity.setPhone(phone); |
| | | if(StrUtil.isNotEmpty(adminUpdateUserDto.getNickname())){ |
| | |
| | | List<UserRoleEntity> userRoleEntities = userRoleMapper.selectList(userRoleQueryWrapper); |
| | | if(CollUtil.isNotEmpty(userRoleEntities)){ |
| | | List menuIds = new ArrayList<Long>(); |
| | | for(UserRoleEntity userRoleEntity : userRoleEntities){ |
| | | List<RoleMenuEntity> roleMenuEntities = roleMenuMapper.selectListByRoleId(userRoleEntity.getRoleId()); |
| | | if(CollUtil.isNotEmpty(roleMenuEntities)){ |
| | | for(RoleMenuEntity roleMenuEntity : roleMenuEntities){ |
| | | menuIds.add(roleMenuEntity.getMenuId()); |
| | | if(UserEntity.USERNAME_DEFAULT.equals(loginUser.getUsername())){ |
| | | List<MenuEntity> menuEntities = menuMapper.selectList(new QueryWrapper<>()); |
| | | if(CollUtil.isNotEmpty(menuEntities)){ |
| | | for(MenuEntity menuEntity : menuEntities){ |
| | | menuIds.add(menuEntity.getId()); |
| | | } |
| | | } |
| | | }else{ |
| | | for(UserRoleEntity userRoleEntity : userRoleEntities){ |
| | | List<RoleMenuEntity> roleMenuEntities = roleMenuMapper.selectListByRoleId(userRoleEntity.getRoleId()); |
| | | if(CollUtil.isNotEmpty(roleMenuEntities)){ |
| | | for(RoleMenuEntity roleMenuEntity : roleMenuEntities){ |
| | | menuIds.add(roleMenuEntity.getMenuId()); |
| | | } |
| | | } |
| | | } |
| | | } |
| | |
| | | adminUserMenuVos.add(iterator.next().getValue()); |
| | | } |
| | | |
| | | } |
| | | } |
| | | if(CollUtil.isNotEmpty(adminUserMenuVos)){ |
| | | for(AdminUserMenuVo adminUserMenuVo : adminUserMenuVos){ |
| | | List<AdminUserMenuVo> child = adminUserMenuVo.getChild(); |
| | | if(CollUtil.isNotEmpty(child)){ |
| | | List<Long> menuIdChilds = new ArrayList<>(); |
| | | for(AdminUserMenuVo adminUserMenuVoChild : child){ |
| | | Long id = adminUserMenuVoChild.getId(); |
| | | menuIdChilds.add(id); |
| | | } |
| | | List<AdminUserMenuVo> adminUserMenuVoByOrderNum = menuMapper.selectAdminUserMenuVoOrderByOrderNum(menuIdChilds); |
| | | adminUserMenuVo.setChild(adminUserMenuVoByOrderNum); |
| | | } |
| | | } |
| | | } |
| | | return Result.ok(adminUserMenuVos); |
| | |
| | | return Result.ok("修改成功"); |
| | | } |
| | | |
| | | @Override |
| | | public Result userInfo() { |
| | | UserEntity loginUser = LoginUserUtil.getLoginUser(); |
| | | Long id = loginUser.getId(); |
| | | UserEntity userEntity = this.baseMapper.selectById(id); |
| | | if(ObjectUtil.isEmpty(userEntity)){ |
| | | return Result.fail("用户不存在"); |
| | | } |
| | | AdminUserInfoVo adminUserInfoVo = new AdminUserInfoVo(); |
| | | adminUserInfoVo.setId(userEntity.getId()); |
| | | adminUserInfoVo.setUsername(userEntity.getUsername()); |
| | | adminUserInfoVo.setNickname(userEntity.getNickname()); |
| | | adminUserInfoVo.setPhone(userEntity.getPhone()); |
| | | adminUserInfoVo.setEmail(userEntity.getEmail()); |
| | | return Result.ok(adminUserInfoVo); |
| | | } |
| | | |
| | | @Override |
| | | public Result viewHomePage() { |
| | | UserEntity loginUser = LoginUserUtil.getLoginUser(); |
| | | Long companyId = LoginUserUtil.getCompanyId(); |
| | | |
| | | AdminHomePageInfoVo adminHomePageInfoVo = new AdminHomePageInfoVo(); |
| | | |
| | | QueryWrapper<UserRoleEntity> userRoleQueryWrapper = new QueryWrapper<>(); |
| | | userRoleQueryWrapper.eq("user_id",loginUser.getId()); |
| | | List<UserRoleEntity> userRoleEntities = userRoleMapper.selectList(userRoleQueryWrapper); |
| | | if(CollUtil.isNotEmpty(userRoleEntities)){ |
| | | List<String> roleNames = new ArrayList<>(); |
| | | for(UserRoleEntity userRoleEntity : userRoleEntities){ |
| | | RoleEntity roleEntity = roleMapper.selectById(userRoleEntity.getRoleId()); |
| | | roleNames.add(roleEntity.getRoleName()); |
| | | } |
| | | adminHomePageInfoVo.setRoleNames(roleNames); |
| | | } |
| | | |
| | | QueryWrapper<ColumnEntity> columnQueryWrapper = new QueryWrapper<>(); |
| | | columnQueryWrapper.eq("company_id",companyId); |
| | | adminHomePageInfoVo.setColumnNum(columnMapper.selectCount(columnQueryWrapper)); |
| | | |
| | | QueryWrapper<ArticleEntity> articleQueryWrapper = new QueryWrapper<>(); |
| | | articleQueryWrapper.eq("company_id",companyId); |
| | | articleQueryWrapper.eq("del_status",ArticleEntity.DELETE_STATUS_NO); |
| | | adminHomePageInfoVo.setArticleNum(articleMapper.selectCount(articleQueryWrapper)); |
| | | |
| | | QueryWrapper<MessageBoardEntity> messageQueryWrapper = new QueryWrapper<>(); |
| | | messageQueryWrapper.eq("company_id",companyId); |
| | | adminHomePageInfoVo.setMessageNum(messageBoardMapper.selectCount(messageQueryWrapper)); |
| | | return Result.ok(adminHomePageInfoVo); |
| | | } |
| | | |
| | | private void saveUserRole(String roleIds,Long userId) { |
| | | if (StrUtil.isNotEmpty(roleIds)) { |
| | | String[] roleIdList = roleIds.split(StringPool.COMMA); |