| | |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.xcong.farmer.cms.common.response.Result; |
| | | import com.xcong.farmer.cms.modules.system.dto.AdminAddUserDto; |
| | | import com.xcong.farmer.cms.modules.system.dto.AdminUpdateUserDto; |
| | | import com.xcong.farmer.cms.modules.system.dto.AdminUserDto; |
| | | import com.xcong.farmer.cms.modules.system.dto.*; |
| | | import com.xcong.farmer.cms.modules.system.entity.*; |
| | | 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; |
| | |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.io.Serializable; |
| | | import java.util.*; |
| | | |
| | | @Service |
| | |
| | | |
| | | @Override |
| | | public Result getUserInPage(AdminUserDto adminUserDto) { |
| | | UserEntity userlogin = LoginUserUtil.getLoginUser(); |
| | | Page<AdminUserVo> page = new Page<>(adminUserDto.getPageNum(), adminUserDto.getPageSize()); |
| | | UserEntity userEntity = new UserEntity(); |
| | | long belongId = userlogin.getBelongId() == null ? UserEntity.USER_BELONG_TOP : userlogin.getBelongId(); |
| | | if(belongId > UserEntity.USER_BELONG_TOP){ |
| | | userEntity.setBelongId(belongId); |
| | | userEntity.setRoleName(RoleEntity.ROLE_ADMIN_NAME); |
| | | }else if(belongId == UserEntity.USER_BELONG_TOP){ |
| | | userEntity.setRoleName(RoleEntity.ROLE_SUPER_NAME); |
| | | } |
| | | if(StrUtil.isNotEmpty(adminUserDto.getUsername())){ |
| | | userEntity.setUsername(adminUserDto.getUsername()); |
| | | } |
| | |
| | | @Override |
| | | @Transactional |
| | | 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); |
| | | // objectQueryWrapper.eq("belong_id",userlogin.getBelongId()); |
| | | List<UserEntity> userEntities = this.baseMapper.selectList(objectQueryWrapper); |
| | | if(CollUtil.isNotEmpty(userEntities)){ |
| | | return Result.fail("用户名重复"); |
| | | } |
| | | String roleIds = adminAddUserDto.getRoleIds(); |
| | | if(StrUtil.isEmpty(roleIds)){ |
| | |
| | | String phone = adminAddUserDto.getPhone(); |
| | | if(StrUtil.isEmpty(phone)){ |
| | | return Result.fail("请输入联系电话"); |
| | | } |
| | | 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.setUsername(username); |
| | |
| | | } |
| | | userEntity.setPassword(SecureUtil.md5(UserEntity.PASSWORD_DEFAULT)); |
| | | userEntity.setStatus(UserEntity.STATUS_ENABLE); |
| | | userEntity.setBelongId(belongId); |
| | | int insert = this.baseMapper.insert(userEntity); |
| | | if(insert > 0){ |
| | | saveUserRole(roleIds,userEntity.getId()); |
| | |
| | | |
| | | @Override |
| | | public Result userMenu() { |
| | | Long userId = LoginUserUtil.getLoginUser().getId(); |
| | | UserEntity loginUser = LoginUserUtil.getLoginUser(); |
| | | Long userId = loginUser.getId(); |
| | | List<AdminUserMenuVo> adminUserMenuVos = new ArrayList<>(); |
| | | |
| | | QueryWrapper<UserRoleEntity> userRoleQueryWrapper = new QueryWrapper<>(); |
| | |
| | | AdminUserMenuVo adminUserMenuVo = menuMapper.selectAdminRoleMenuVoById(childId); |
| | | Long parentId = adminUserMenuVo.getParentId(); |
| | | AdminUserMenuVo adminUserMenuVoParent = menuMap.get(parentId); |
| | | List<AdminUserMenuVo> child = adminUserMenuVoParent.getChild(); |
| | | if(CollUtil.isEmpty(child)){ |
| | | List<AdminUserMenuVo> list = new ArrayList<>(); |
| | | list.add(adminUserMenuVo); |
| | | adminUserMenuVoParent.setChild(list); |
| | | }else{ |
| | | child.add(adminUserMenuVo); |
| | | if(ObjectUtil.isNotEmpty(adminUserMenuVoParent)){ |
| | | List<AdminUserMenuVo> child = adminUserMenuVoParent.getChild(); |
| | | if(CollUtil.isEmpty(child)){ |
| | | List<AdminUserMenuVo> list = new ArrayList<>(); |
| | | list.add(adminUserMenuVo); |
| | | adminUserMenuVoParent.setChild(list); |
| | | }else{ |
| | | child.add(adminUserMenuVo); |
| | | } |
| | | } |
| | | } |
| | | } |
| | |
| | | |
| | | } |
| | | } |
| | | 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); |
| | | } |
| | | |
| | | @Override |
| | | @Transactional |
| | | public Result delObjs(AdminDeleteDto adminDeleteDto) { |
| | | String ids = adminDeleteDto.getIds(); |
| | | if(StrUtil.isNotEmpty(ids)){ |
| | | String[] userIds = ids.split(StringPool.COMMA); |
| | | for(String userIdStr : userIds){ |
| | | Long userId = Long.valueOf(userIdStr); |
| | | |
| | | QueryWrapper<UserRoleEntity> objectQueryWrapper = new QueryWrapper<>(); |
| | | objectQueryWrapper.eq("user_id",userId); |
| | | userRoleMapper.delete(objectQueryWrapper); |
| | | |
| | | this.baseMapper.deleteById(userId); |
| | | } |
| | | |
| | | } |
| | | return Result.ok("删除成功"); |
| | | } |
| | | |
| | | @Override |
| | | @Transactional |
| | | public Result updatePassword(AdminUpdatePasswordDto adminUpdatePasswordDto) { |
| | | UserEntity loginUser = LoginUserUtil.getLoginUser(); |
| | | Long userId = loginUser.getId(); |
| | | UserEntity userEntity = this.baseMapper.selectById(userId); |
| | | if(ObjectUtil.isEmpty(userEntity)){ |
| | | return Result.fail("用户不存在"); |
| | | } |
| | | String oldPassword = adminUpdatePasswordDto.getOldPassword(); |
| | | if(StrUtil.isEmpty(oldPassword)){ |
| | | return Result.fail("请输入原密码"); |
| | | } |
| | | String newPassword = adminUpdatePasswordDto.getNewPassword(); |
| | | if(StrUtil.isEmpty(newPassword)){ |
| | | return Result.fail("请输入新密码"); |
| | | } |
| | | String s = SecureUtil.md5(oldPassword); |
| | | if(!userEntity.getPassword().equals(s)){ |
| | | return Result.fail("原密码不正确,请联系管理员重置密码"); |
| | | } |
| | | userEntity.setPassword(SecureUtil.md5(newPassword)); |
| | | this.baseMapper.updateById(userEntity); |
| | | 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); |
| | | } |
| | | |
| | | private void saveUserRole(String roleIds,Long userId) { |
| | | if (StrUtil.isNotEmpty(roleIds)) { |
| | | String[] roleIdList = roleIds.split(StringPool.COMMA); |