Search in sources :

Example 81 with QueryWrapper

use of com.baomidou.mybatisplus.core.conditions.query.QueryWrapper in project EVA-API by PKAQ-LAB.

the class RoleService method saveModule.

/**
 * 保存角色关系表
 */
public void saveModule(RoleEntity role) {
    QueryWrapper<RoleModuleEntity> wrapper = new QueryWrapper<>();
    wrapper.eq("role_id", role.getId());
    // 删除角色原有的模块
    this.roleModuleMapper.delete(wrapper);
    // 插入新的权限信息
    if (CollectionUtil.isNotEmpty(role.getModules())) {
        List<RoleModuleEntity> modules = role.getModules();
        Map<String, String[]> resourceMap = role.getResources();
        for (RoleModuleEntity module : modules) {
            module.setRoleId(role.getId());
            // 设置角色拥有的资源
            String[] resources = null != resourceMap ? resourceMap.get(module.getModuleId() + "") : null;
            if (null == resources || resources.length < 1) {
                this.roleModuleMapper.insert(module);
            } else {
                for (String s : resources) {
                    module.setId(IdWorker.getIdStr());
                    module.setResourceId(s);
                    this.roleModuleMapper.insert(module);
                }
            }
        }
    }
}
Also used : RoleModuleEntity(io.nerv.web.sys.role.entity.RoleModuleEntity) QueryWrapper(com.baomidou.mybatisplus.core.conditions.query.QueryWrapper)

Example 82 with QueryWrapper

use of com.baomidou.mybatisplus.core.conditions.query.QueryWrapper in project EVA-API by PKAQ-LAB.

the class RoleService method listUser.

/**
 * 获取该角色绑定的所有用户
 * @param roleId 权限条件
 * @return
 */
public Map<String, Object> listUser(String roleId, String deptId) {
    // 获取所有用户
    UserEntity userEntity = new UserEntity();
    if (StrUtil.isNotBlank(deptId)) {
        userEntity.setDeptId(deptId);
    }
    userEntity.setLocked(LockEnumm.UNLOCK.getIndex());
    List<UserEntity> users = this.userService.listUser(userEntity);
    // 获取已选的模块
    RoleUserEntity roleUserEntity = new RoleUserEntity();
    roleUserEntity.setRoleId(roleId);
    QueryWrapper<RoleUserEntity> wrapper = new QueryWrapper<>();
    wrapper.setEntity(roleUserEntity);
    // 只返回moduleId
    List<RoleUserEntity> roleUserList = this.roleUserMapper.selectList(wrapper);
    List<String> checked = null;
    if (CollectionUtils.isNotEmpty(roleUserList)) {
        checked = new ArrayList<>(roleUserList.size());
        for (RoleUserEntity rue : roleUserList) {
            checked.add(rue.getUserId());
        }
    }
    Map<String, Object> map = new HashMap<>(2);
    map.put("users", users);
    map.put("checked", checked);
    return map;
}
Also used : RoleUserEntity(io.nerv.web.sys.role.entity.RoleUserEntity) QueryWrapper(com.baomidou.mybatisplus.core.conditions.query.QueryWrapper) RoleUserEntity(io.nerv.web.sys.role.entity.RoleUserEntity) UserEntity(io.nerv.web.sys.user.entity.UserEntity)

Example 83 with QueryWrapper

use of com.baomidou.mybatisplus.core.conditions.query.QueryWrapper in project EVA-API by PKAQ-LAB.

the class DictService method delDict.

/**
 * 删除一条字典 逻辑删除
 * @param id 字典ID
 */
public void delDict(String id) {
    // 先删除子表 再删除主表
    QueryWrapper<DictItemEntity> deleteWrapper = new QueryWrapper();
    deleteWrapper.eq("main_id", id);
    this.dictItemMapper.delete(deleteWrapper);
    this.mapper.deleteById(id);
    // 删掉字典之后,移除字典缓存中的相关字典
    DictEntity dictEntity = this.mapper.getDict(id);
    if (dictEntity != null) {
        dictCacheHelper.remove(dictEntity.getCode());
    }
}
Also used : DictItemEntity(io.nerv.web.sys.dict.entity.DictItemEntity) DictEntity(io.nerv.web.sys.dict.entity.DictEntity) QueryWrapper(com.baomidou.mybatisplus.core.conditions.query.QueryWrapper)

Example 84 with QueryWrapper

use of com.baomidou.mybatisplus.core.conditions.query.QueryWrapper in project EVA-API by PKAQ-LAB.

the class ModuleService method editModule.

/**
 * 新增/编辑一条模块信息
 * @param module 要 新增/编辑 得模块对象
 * @return 重新查询模块列表
 */
public void editModule(ModuleEntity module) {
    String moduleId = module.getId();
    ModuleEntity originModule = this.getById(moduleId);
    // 获取上级节点
    String pid = module.getParentId();
    if (StrUtil.isNotBlank(moduleId)) {
        // 是否启用的逻辑
        if (StrUtil.isNotBlank(module.getStatus()) && LockEnumm.UNLOCK.getIndex().equals(module.getStatus())) {
            if (!isDisable(module)) {
                // 如果父节点状态为禁用,则子节点状态也只能为禁用
                throw new BizException(BizCodeEnum.PARENT_NOT_AVAILABLE);
            }
        }
        // 是否禁用的逻辑
        disableChild(module);
    } else {
        // 新增设置orders为同级模块中最大的orders+1
        module.setIsleaf(true);
        module.setOrders(this.mapper.listOrder(pid) + 1);
    }
    String root = "0";
    // 当前编辑节点为子节点
    if (!root.equals(pid) && StrUtil.isNotBlank(pid)) {
        // 查询新父节点信息
        ModuleEntity parentModule = this.getModule(pid);
        // 设置当前节点信息
        module.setPathId(StrUtil.isNotBlank(parentModule.getPathId()) ? parentModule.getPathId() + "," + parentModule.getId() : parentModule.getId());
        // pathName
        String pathName = StrUtil.format("{}/{}", parentModule.getName(), module.getName());
        String oldFatherPath = null;
        if (moduleId != null && originModule != null && StrUtil.isNotBlank(originModule.getParentId())) {
            // 得到原来父节点的path路径
            ModuleEntity oldParent = this.mapper.selectById(originModule.getParentId());
            oldFatherPath = oldParent != null ? oldParent.getPath() : null;
        }
        module.setPath(TreeHelper.assemblePath(parentModule.getPath(), module.getPath(), oldFatherPath));
        module.setPathName(pathName);
        module.setParentName(parentModule.getName());
    }
    // 如果更换了父节点 重新确定原父节点的 leaf属性,以及所修改节点的orders属性
    if (null != originModule && this.parentChanged(originModule.getParentId(), pid)) {
        // 更新原节点
        // 检查原父节点是否还存在子节点 来重新确定原始父节点得isleaf属性
        // 由于数据还未提交 节点仍然挂载在原始节点上 所以这里要 -1
        int originParentChilds = this.mapper.countPrantLeaf(originModule.getParentId()) - 1;
        if (originParentChilds < 1) {
            ModuleEntity originParentModule = new ModuleEntity();
            originParentModule.setIsleaf(true);
            originParentModule.setId(originModule.getParentId());
            this.mapper.updateById(originParentModule);
        }
        // 更新新节点 isleaf属性
        int newParentChilds = this.mapper.countPrantLeaf(pid);
        ModuleEntity newParentModule = new ModuleEntity();
        newParentModule.setIsleaf(false);
        newParentModule.setId(pid);
        this.mapper.updateById(newParentModule);
        // 重新设置节点顺序
        module.setOrders(newParentChilds + 1);
    }
    // 持久化
    if (StrUtil.isBlank(moduleId)) {
        moduleId = IdWorker.getIdStr();
        module.setId(moduleId);
        this.mapper.insert(module);
    } else {
        this.mapper.updateById(module);
    }
    /**
     *         写入资源信息, 先删除
     *         有id 更新
     *         无id 新增
     */
    List<ModuleResources> resources = module.getResources();
    if (CollUtil.isNotEmpty(resources)) {
        List<String> ids = new ArrayList<>(resources.size());
        for (ModuleResources item : resources) {
            if (StrUtil.isNotBlank(item.getId())) {
                this.moduleResourceMapper.updateById(item);
            } else {
                item.setId(IdWorker.getIdStr());
                item.setModuleId(moduleId);
                this.moduleResourceMapper.insert(item);
            }
            ids.add(item.getId());
        }
        // 移除被删除的
        if (StrUtil.isNotBlank(moduleId)) {
            QueryWrapper<ModuleResources> deleteWrapper = new QueryWrapper();
            deleteWrapper.notIn("id", ids);
            deleteWrapper.eq("module_id", moduleId);
            try {
                this.moduleResourceMapper.delete(deleteWrapper);
            } catch (Exception e) {
                throw new BizException(BizCodeEnum.RESOURCE_USED);
            }
        }
    }
    // 刷新所有子节点的 path parent_name path_name 当修改状态的时候不用刷新子节点信息
    if (StrUtil.isNotBlank(module.getId()) && null != originModule) {
        this.refreshChild(module, originModule);
    }
}
Also used : ModuleResources(io.nerv.web.sys.module.entity.ModuleResources) QueryWrapper(com.baomidou.mybatisplus.core.conditions.query.QueryWrapper) BizException(io.nerv.core.exception.BizException) ArrayList(java.util.ArrayList) ModuleEntity(io.nerv.web.sys.module.entity.ModuleEntity) BizException(io.nerv.core.exception.BizException)

Example 85 with QueryWrapper

use of com.baomidou.mybatisplus.core.conditions.query.QueryWrapper in project EVA-API by PKAQ-LAB.

the class ModuleService method getModule.

/**
 * 根据ID获取一条模块信息
 * @param id 模块ID
 * @return 模块信息
 */
public ModuleEntity getModule(String id) {
    ModuleEntity module = this.getById(id);
    // 获取资源信息
    QueryWrapper queryWrapper = new QueryWrapper();
    queryWrapper.eq("module_id", id);
    List<ModuleResources> resourceList = this.moduleResourceMapper.selectList(queryWrapper);
    module.setResources(resourceList);
    return module;
}
Also used : QueryWrapper(com.baomidou.mybatisplus.core.conditions.query.QueryWrapper) ModuleResources(io.nerv.web.sys.module.entity.ModuleResources) ModuleEntity(io.nerv.web.sys.module.entity.ModuleEntity)

Aggregations

QueryWrapper (com.baomidou.mybatisplus.core.conditions.query.QueryWrapper)723 Transactional (org.springframework.transaction.annotation.Transactional)98 IPage (com.baomidou.mybatisplus.core.metadata.IPage)82 UserRolesVo (top.hcode.hoj.pojo.vo.UserRolesVo)74 LambdaQueryWrapper (com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper)72 Page (com.baomidou.mybatisplus.extension.plugins.pagination.Page)65 ArrayList (java.util.ArrayList)61 Session (org.apache.shiro.session.Session)61 StatusFailException (top.hcode.hoj.common.exception.StatusFailException)60 StatusForbiddenException (top.hcode.hoj.common.exception.StatusForbiddenException)55 Problem (top.hcode.hoj.pojo.entity.problem.Problem)50 UpdateWrapper (com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper)45 Date (java.util.Date)44 HttpServletRequest (javax.servlet.http.HttpServletRequest)35 HashMap (java.util.HashMap)34 RequiresAuthentication (org.apache.shiro.authz.annotation.RequiresAuthentication)34 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)34 ApiOperation (io.swagger.annotations.ApiOperation)32 HttpSession (javax.servlet.http.HttpSession)31 Judge (top.hcode.hoj.pojo.entity.judge.Judge)30