Search in sources :

Example 6 with Role

use of com.moxi.mogublog.commons.entity.Role in project mogu_blog_v2 by moxi624.

the class RoleServiceImpl method deleteRole.

@Override
public String deleteRole(RoleVO roleVO) {
    // 判断该角色下是否绑定了管理员
    QueryWrapper<Admin> blogQueryWrapper = new QueryWrapper<>();
    blogQueryWrapper.eq(SQLConf.STATUS, EStatus.ENABLE);
    blogQueryWrapper.in(SQLConf.ROLEUID, roleVO.getUid());
    Integer adminCount = adminService.count(blogQueryWrapper);
    if (adminCount > 0) {
        return ResultUtil.errorWithMessage(MessageConf.ADMIN_UNDER_THIS_ROLE);
    }
    Role role = roleService.getById(roleVO.getUid());
    role.setStatus(EStatus.DISABLED);
    role.setUpdateTime(new Date());
    role.updateById();
    deleteAdminVisitUrl();
    return ResultUtil.successWithMessage(MessageConf.DELETE_SUCCESS);
}
Also used : Role(com.moxi.mogublog.commons.entity.Role) QueryWrapper(com.baomidou.mybatisplus.core.conditions.query.QueryWrapper) Admin(com.moxi.mogublog.commons.entity.Admin) Date(java.util.Date)

Example 7 with Role

use of com.moxi.mogublog.commons.entity.Role in project mogu_blog_v2 by moxi624.

the class AdminServiceImpl method getList.

@Override
public String getList(AdminVO adminVO) {
    QueryWrapper<Admin> queryWrapper = new QueryWrapper<>();
    String pictureResult = null;
    if (StringUtils.isNotEmpty(adminVO.getKeyword())) {
        queryWrapper.like(SQLConf.USER_NAME, adminVO.getKeyword()).or().like(SQLConf.NICK_NAME, adminVO.getKeyword().trim());
    }
    Page<Admin> page = new Page<>();
    page.setCurrent(adminVO.getCurrentPage());
    page.setSize(adminVO.getPageSize());
    // 去除密码
    queryWrapper.select(Admin.class, i -> !i.getProperty().equals(SQLConf.PASS_WORD));
    queryWrapper.eq(SQLConf.STATUS, EStatus.ENABLE);
    IPage<Admin> pageList = adminService.page(page, queryWrapper);
    List<Admin> list = pageList.getRecords();
    final StringBuffer fileUids = new StringBuffer();
    List<String> adminUidList = new ArrayList<>();
    list.forEach(item -> {
        if (StringUtils.isNotEmpty(item.getAvatar())) {
            fileUids.append(item.getAvatar() + SysConf.FILE_SEGMENTATION);
        }
        adminUidList.add(item.getUid());
    });
    Map<String, String> pictureMap = new HashMap<>(Constants.NUM_TEN);
    if (fileUids != null) {
        pictureResult = this.pictureFeignClient.getPicture(fileUids.toString(), SysConf.FILE_SEGMENTATION);
    }
    List<Map<String, Object>> picList = webUtil.getPictureMap(pictureResult);
    picList.forEach(item -> {
        pictureMap.put(item.get(SQLConf.UID).toString(), item.get(SQLConf.URL).toString());
    });
    // 获取用户的网盘存储空间
    String storageListJson = pictureFeignClient.getStorageByAdminUid(adminUidList);
    List<Storage> storageList = webUtil.getList(storageListJson, Storage.class);
    Map<String, Storage> storageMap = new HashMap<>();
    storageList.forEach(item -> {
        storageMap.put(item.getAdminUid(), item);
    });
    for (Admin item : list) {
        Role role = roleService.getById(item.getRoleUid());
        item.setRole(role);
        // 获取图片
        if (StringUtils.isNotEmpty(item.getAvatar())) {
            List<String> pictureUidsTemp = StringUtils.changeStringToString(item.getAvatar(), SysConf.FILE_SEGMENTATION);
            List<String> pictureListTemp = new ArrayList<>();
            pictureUidsTemp.forEach(picture -> {
                if (pictureMap.get(picture) != null && pictureMap.get(picture) != "") {
                    pictureListTemp.add(pictureMap.get(picture));
                }
            });
            item.setPhotoList(pictureListTemp);
        }
        // 设置已用容量大小和最大容量
        Storage storage = storageMap.get(item.getUid());
        if (storage != null) {
            item.setStorageSize(storage.getStorageSize());
            item.setMaxStorageSize(storage.getMaxStorageSize());
        } else {
            // 如果没有,默认为0
            item.setStorageSize(0L);
            item.setMaxStorageSize(0L);
        }
    }
    return ResultUtil.successWithData(pageList);
}
Also used : QueryWrapper(com.baomidou.mybatisplus.core.conditions.query.QueryWrapper) Page(com.baomidou.mybatisplus.extension.plugins.pagination.Page) IPage(com.baomidou.mybatisplus.core.metadata.IPage) OnlineAdmin(com.moxi.mogublog.commons.entity.OnlineAdmin) Admin(com.moxi.mogublog.commons.entity.Admin) Role(com.moxi.mogublog.commons.entity.Role) Storage(com.moxi.mogublog.commons.entity.Storage)

Example 8 with Role

use of com.moxi.mogublog.commons.entity.Role in project mogu_blog_v2 by moxi624.

the class RoleServiceImpl method addRole.

@Override
public String addRole(RoleVO roleVO) {
    String roleName = roleVO.getRoleName();
    QueryWrapper<Role> queryWrapper = new QueryWrapper<>();
    queryWrapper.eq(SQLConf.ROLENAEM, roleName);
    Role getRole = roleService.getOne(queryWrapper);
    if (getRole == null) {
        Role role = new Role();
        role.setRoleName(roleVO.getRoleName());
        role.setCategoryMenuUids(roleVO.getCategoryMenuUids());
        role.setSummary(roleVO.getSummary());
        role.insert();
        return ResultUtil.result(SysConf.SUCCESS, MessageConf.INSERT_SUCCESS);
    }
    return ResultUtil.errorWithMessage(MessageConf.ENTITY_EXIST);
}
Also used : Role(com.moxi.mogublog.commons.entity.Role) QueryWrapper(com.baomidou.mybatisplus.core.conditions.query.QueryWrapper)

Example 9 with Role

use of com.moxi.mogublog.commons.entity.Role in project mogu_blog_v2 by moxi624.

the class RoleServiceImpl method editRole.

@Override
public String editRole(RoleVO roleVO) {
    String uid = roleVO.getUid();
    Role getRole = roleService.getById(uid);
    if (getRole == null) {
        return ResultUtil.errorWithMessage(MessageConf.PARAM_INCORRECT);
    }
    getRole.setRoleName(roleVO.getRoleName());
    getRole.setCategoryMenuUids(roleVO.getCategoryMenuUids());
    getRole.setSummary(roleVO.getSummary());
    getRole.setUpdateTime(new Date());
    getRole.updateById();
    // 修改成功后,需要删除redis中所有的admin访问路径
    deleteAdminVisitUrl();
    return ResultUtil.successWithMessage(MessageConf.UPDATE_SUCCESS);
}
Also used : Role(com.moxi.mogublog.commons.entity.Role) Date(java.util.Date)

Aggregations

Role (com.moxi.mogublog.commons.entity.Role)9 Admin (com.moxi.mogublog.commons.entity.Admin)7 QueryWrapper (com.baomidou.mybatisplus.core.conditions.query.QueryWrapper)6 OnlineAdmin (com.moxi.mogublog.commons.entity.OnlineAdmin)4 ApiOperation (io.swagger.annotations.ApiOperation)3 CategoryMenu (com.moxi.mogublog.commons.entity.CategoryMenu)2 ArrayList (java.util.ArrayList)2 Date (java.util.Date)2 IPage (com.baomidou.mybatisplus.core.metadata.IPage)1 Page (com.baomidou.mybatisplus.extension.plugins.pagination.Page)1 LinkedTreeMap (com.google.gson.internal.LinkedTreeMap)1 Storage (com.moxi.mogublog.commons.entity.Storage)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 Around (org.aspectj.lang.annotation.Around)1 UsernameNotFoundException (org.springframework.security.core.userdetails.UsernameNotFoundException)1 BCryptPasswordEncoder (org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder)1 PasswordEncoder (org.springframework.security.crypto.password.PasswordEncoder)1 ServletRequestAttributes (org.springframework.web.context.request.ServletRequestAttributes)1