Search in sources :

Example 1 with SysPermission

use of org.jeecg.modules.system.entity.SysPermission in project jeecg-boot by jeecgboot.

the class NgAlainServiceImpl method getJeecgMenu.

@Override
public JSONArray getJeecgMenu(String id) throws Exception {
    List<SysPermission> metaList = sysPermissionService.queryByUser(id);
    JSONArray jsonArray = new JSONArray();
    getPermissionJsonArray(jsonArray, metaList, null);
    JSONArray menulist = parseNgAlain(jsonArray);
    JSONObject jeecgMenu = new JSONObject();
    jeecgMenu.put("text", "jeecg菜单");
    jeecgMenu.put("group", true);
    jeecgMenu.put("children", menulist);
    JSONArray jeecgMenuList = new JSONArray();
    jeecgMenuList.add(jeecgMenu);
    return jeecgMenuList;
}
Also used : JSONObject(com.alibaba.fastjson.JSONObject) JSONArray(com.alibaba.fastjson.JSONArray) SysPermission(org.jeecg.modules.system.entity.SysPermission)

Example 2 with SysPermission

use of org.jeecg.modules.system.entity.SysPermission in project jeecg-boot by jeecgboot.

the class SysDepartPermissionController method queryTreeListForDeptRole.

/**
 * 用户角色授权功能,查询菜单权限树
 * @param request
 * @return
 */
@RequestMapping(value = "/queryTreeListForDeptRole", method = RequestMethod.GET)
public Result<Map<String, Object>> queryTreeListForDeptRole(@RequestParam(name = "departId", required = true) String departId, HttpServletRequest request) {
    Result<Map<String, Object>> result = new Result<>();
    // 全部权限ids
    List<String> ids = new ArrayList<>();
    try {
        LambdaQueryWrapper<SysPermission> query = new LambdaQueryWrapper<SysPermission>();
        query.eq(SysPermission::getDelFlag, CommonConstant.DEL_FLAG_0);
        query.orderByAsc(SysPermission::getSortNo);
        query.inSql(SysPermission::getId, "select permission_id  from sys_depart_permission where depart_id='" + departId + "'");
        List<SysPermission> list = sysPermissionService.list(query);
        for (SysPermission sysPer : list) {
            ids.add(sysPer.getId());
        }
        List<TreeModel> treeList = new ArrayList<>();
        getTreeModelList(treeList, list, null);
        Map<String, Object> resMap = new HashMap<String, Object>();
        // 全部树节点数据
        resMap.put("treeList", treeList);
        // 全部树ids
        resMap.put("ids", ids);
        result.setResult(resMap);
        result.setSuccess(true);
    } catch (Exception e) {
        log.error(e.getMessage(), e);
    }
    return result;
}
Also used : Result(org.jeecg.common.api.vo.Result) LambdaQueryWrapper(com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper) TreeModel(org.jeecg.modules.system.model.TreeModel) SysPermission(org.jeecg.modules.system.entity.SysPermission) JSONObject(com.alibaba.fastjson.JSONObject)

Example 3 with SysPermission

use of org.jeecg.modules.system.entity.SysPermission in project jeecg-boot by jeecgboot.

the class SysDepartPermissionController method getTreeModelList.

private void getTreeModelList(List<TreeModel> treeList, List<SysPermission> metaList, TreeModel temp) {
    for (SysPermission permission : metaList) {
        String tempPid = permission.getParentId();
        TreeModel tree = new TreeModel(permission.getId(), tempPid, permission.getName(), permission.getRuleFlag(), permission.isLeaf());
        if (temp == null && oConvertUtils.isEmpty(tempPid)) {
            treeList.add(tree);
            if (!tree.getIsLeaf()) {
                getTreeModelList(treeList, metaList, tree);
            }
        } else if (temp != null && tempPid != null && tempPid.equals(temp.getKey())) {
            temp.getChildren().add(tree);
            if (!tree.getIsLeaf()) {
                getTreeModelList(treeList, metaList, tree);
            }
        }
    }
}
Also used : TreeModel(org.jeecg.modules.system.model.TreeModel) SysPermission(org.jeecg.modules.system.entity.SysPermission)

Example 4 with SysPermission

use of org.jeecg.modules.system.entity.SysPermission in project jeecg-boot by jeecgboot.

the class SysPermissionServiceImpl method hasPermission.

@Override
public boolean hasPermission(String username, String url) {
    SysPermission sysPermission = new SysPermission();
    sysPermission.setUrl(url);
    int count = baseMapper.queryCountByUsername(username, sysPermission);
    if (count > 0) {
        return true;
    } else {
        return false;
    }
}
Also used : SysPermission(org.jeecg.modules.system.entity.SysPermission)

Example 5 with SysPermission

use of org.jeecg.modules.system.entity.SysPermission in project jeecg-boot by jeecgboot.

the class SysPermissionServiceImpl method removeChildrenBy.

/**
 * 根据父id删除其关联的子节点数据
 *
 * @return
 */
public void removeChildrenBy(String parentId) {
    LambdaQueryWrapper<SysPermission> query = new LambdaQueryWrapper<>();
    // 封装查询条件parentId为主键,
    query.eq(SysPermission::getParentId, parentId);
    // 查出该主键下的所有子级
    List<SysPermission> permissionList = this.list(query);
    if (permissionList != null && permissionList.size() > 0) {
        // id
        String id = "";
        // 查出的子级数量
        int num = 0;
        // 如果查出的集合不为空, 则先删除所有
        this.remove(query);
        // 再遍历刚才查出的集合, 根据每个对象,查找其是否仍有子级
        for (int i = 0, len = permissionList.size(); i < len; i++) {
            id = permissionList.get(i).getId();
            Map map = new HashMap<>();
            map.put("permission_id", id);
            // 删除数据规则
            this.deletePermRuleByPermId(id);
            // 删除角色授权表
            sysRolePermissionMapper.deleteByMap(map);
            // 删除部门权限表
            sysDepartPermissionMapper.deleteByMap(map);
            // 删除部门角色授权
            sysDepartRolePermissionMapper.deleteByMap(map);
            num = this.count(new LambdaQueryWrapper<SysPermission>().eq(SysPermission::getParentId, id));
            // 如果有, 则递归
            if (num > 0) {
                this.removeChildrenBy(id);
            }
        }
    }
}
Also used : HashMap(java.util.HashMap) SysPermission(org.jeecg.modules.system.entity.SysPermission) HashMap(java.util.HashMap) Map(java.util.Map) LambdaQueryWrapper(com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper)

Aggregations

SysPermission (org.jeecg.modules.system.entity.SysPermission)59 JSONObject (com.alibaba.fastjson.JSONObject)22 LambdaQueryWrapper (com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper)22 TreeModel (org.jeecg.modules.system.model.TreeModel)16 Result (org.jeecg.common.api.vo.Result)14 JSONArray (com.alibaba.fastjson.JSONArray)10 HashMap (java.util.HashMap)9 Map (java.util.Map)9 JeecgBootException (org.jeecg.common.exception.JeecgBootException)9 CacheEvict (org.springframework.cache.annotation.CacheEvict)9 Transactional (org.springframework.transaction.annotation.Transactional)9 SysPermissionTree (org.jeecg.modules.system.model.SysPermissionTree)8 IOException (java.io.IOException)3 ArrayList (java.util.ArrayList)3 Date (java.util.Date)3 SysPermissionDataRule (org.jeecg.modules.system.entity.SysPermissionDataRule)3 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)3 LoginUser (org.jeecg.common.system.vo.LoginUser)2