Search in sources :

Example 1 with SysDepartPermission

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

the class SysDepartPermissionController method loadDatarule.

/**
 * 部门管理授权查询数据规则数据
 */
@GetMapping(value = "/datarule/{permissionId}/{departId}")
public Result<?> loadDatarule(@PathVariable("permissionId") String permissionId, @PathVariable("departId") String departId) {
    List<SysPermissionDataRule> list = sysPermissionDataRuleService.getPermRuleListByPermId(permissionId);
    if (list == null || list.size() == 0) {
        return Result.error("未找到权限配置信息");
    } else {
        Map<String, Object> map = new HashMap<>();
        map.put("datarule", list);
        LambdaQueryWrapper<SysDepartPermission> query = new LambdaQueryWrapper<SysDepartPermission>().eq(SysDepartPermission::getPermissionId, permissionId).eq(SysDepartPermission::getDepartId, departId);
        SysDepartPermission sysDepartPermission = sysDepartPermissionService.getOne(query);
        if (sysDepartPermission == null) {
        // return Result.error("未找到角色菜单配置信息");
        } else {
            String drChecked = sysDepartPermission.getDataRuleIds();
            if (oConvertUtils.isNotEmpty(drChecked)) {
                map.put("drChecked", drChecked.endsWith(",") ? drChecked.substring(0, drChecked.length() - 1) : drChecked);
            }
        }
        return Result.ok(map);
    // TODO 以后按钮权限的查询也走这个请求 无非在map中多加两个key
    }
}
Also used : SysDepartPermission(org.jeecg.modules.system.entity.SysDepartPermission) SysPermissionDataRule(org.jeecg.modules.system.entity.SysPermissionDataRule) JSONObject(com.alibaba.fastjson.JSONObject) LambdaQueryWrapper(com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper)

Example 2 with SysDepartPermission

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

the class SysDepartPermissionController method saveDatarule.

/**
 * 保存数据规则至部门菜单关联表
 */
@PostMapping(value = "/datarule")
public Result<?> saveDatarule(@RequestBody JSONObject jsonObject) {
    try {
        String permissionId = jsonObject.getString("permissionId");
        String departId = jsonObject.getString("departId");
        String dataRuleIds = jsonObject.getString("dataRuleIds");
        log.info("保存数据规则>>" + "菜单ID:" + permissionId + "部门ID:" + departId + "数据权限ID:" + dataRuleIds);
        LambdaQueryWrapper<SysDepartPermission> query = new LambdaQueryWrapper<SysDepartPermission>().eq(SysDepartPermission::getPermissionId, permissionId).eq(SysDepartPermission::getDepartId, departId);
        SysDepartPermission sysDepartPermission = sysDepartPermissionService.getOne(query);
        if (sysDepartPermission == null) {
            return Result.error("请先保存部门菜单权限!");
        } else {
            sysDepartPermission.setDataRuleIds(dataRuleIds);
            this.sysDepartPermissionService.updateById(sysDepartPermission);
        }
    } catch (Exception e) {
        log.error("SysDepartPermissionController.saveDatarule()发生异常:" + e.getMessage(), e);
        return Result.error("保存失败");
    }
    return Result.ok("保存成功!");
}
Also used : SysDepartPermission(org.jeecg.modules.system.entity.SysDepartPermission) LambdaQueryWrapper(com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper)

Example 3 with SysDepartPermission

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

the class SysDepartPermissionServiceImpl method getPermRuleListByDeptIdAndPermId.

@Override
public List<SysPermissionDataRule> getPermRuleListByDeptIdAndPermId(String departId, String permissionId) {
    SysDepartPermission departPermission = this.getOne(new QueryWrapper<SysDepartPermission>().lambda().eq(SysDepartPermission::getDepartId, departId).eq(SysDepartPermission::getPermissionId, permissionId));
    if (departPermission != null && oConvertUtils.isNotEmpty(departPermission.getDataRuleIds())) {
        LambdaQueryWrapper<SysPermissionDataRule> query = new LambdaQueryWrapper<SysPermissionDataRule>();
        query.in(SysPermissionDataRule::getId, Arrays.asList(departPermission.getDataRuleIds().split(",")));
        query.orderByDesc(SysPermissionDataRule::getCreateTime);
        List<SysPermissionDataRule> permRuleList = this.ruleMapper.selectList(query);
        return permRuleList;
    } else {
        return null;
    }
}
Also used : SysDepartPermission(org.jeecg.modules.system.entity.SysDepartPermission) SysPermissionDataRule(org.jeecg.modules.system.entity.SysPermissionDataRule) QueryWrapper(com.baomidou.mybatisplus.core.conditions.query.QueryWrapper) LambdaQueryWrapper(com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper) LambdaQueryWrapper(com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper)

Example 4 with SysDepartPermission

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

the class SysDepartPermissionServiceImpl method saveDepartPermission.

@Override
@Transactional(rollbackFor = Exception.class)
public void saveDepartPermission(String departId, String permissionIds, String lastPermissionIds) {
    List<String> add = getDiff(lastPermissionIds, permissionIds);
    if (add != null && add.size() > 0) {
        List<SysDepartPermission> list = new ArrayList<SysDepartPermission>();
        for (String p : add) {
            if (oConvertUtils.isNotEmpty(p)) {
                SysDepartPermission rolepms = new SysDepartPermission(departId, p);
                list.add(rolepms);
            }
        }
        this.saveBatch(list);
    }
    List<String> delete = getDiff(permissionIds, lastPermissionIds);
    if (delete != null && delete.size() > 0) {
        for (String permissionId : delete) {
            this.remove(new QueryWrapper<SysDepartPermission>().lambda().eq(SysDepartPermission::getDepartId, departId).eq(SysDepartPermission::getPermissionId, permissionId));
            // 删除部门权限时,删除部门角色中已授权的权限
            List<SysDepartRole> sysDepartRoleList = sysDepartRoleMapper.selectList(new LambdaQueryWrapper<SysDepartRole>().eq(SysDepartRole::getDepartId, departId));
            List<String> roleIds = sysDepartRoleList.stream().map(SysDepartRole::getId).collect(Collectors.toList());
            if (roleIds != null && roleIds.size() > 0) {
                departRolePermissionMapper.delete(new LambdaQueryWrapper<SysDepartRolePermission>().eq(SysDepartRolePermission::getPermissionId, permissionId));
            }
        }
    }
}
Also used : SysDepartPermission(org.jeecg.modules.system.entity.SysDepartPermission) QueryWrapper(com.baomidou.mybatisplus.core.conditions.query.QueryWrapper) LambdaQueryWrapper(com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper) SysDepartRole(org.jeecg.modules.system.entity.SysDepartRole) LambdaQueryWrapper(com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper) Transactional(org.springframework.transaction.annotation.Transactional)

Example 5 with SysDepartPermission

use of org.jeecg.modules.system.entity.SysDepartPermission in project kms by mahonelau.

the class SysDepartPermissionServiceImpl method saveDepartPermission.

@Override
@Transactional(rollbackFor = Exception.class)
public void saveDepartPermission(String departId, String permissionIds, String lastPermissionIds) {
    List<String> add = getDiff(lastPermissionIds, permissionIds);
    if (add != null && add.size() > 0) {
        List<SysDepartPermission> list = new ArrayList<SysDepartPermission>();
        for (String p : add) {
            if (oConvertUtils.isNotEmpty(p)) {
                SysDepartPermission rolepms = new SysDepartPermission(departId, p);
                list.add(rolepms);
            }
        }
        this.saveBatch(list);
    }
    List<String> delete = getDiff(permissionIds, lastPermissionIds);
    if (delete != null && delete.size() > 0) {
        for (String permissionId : delete) {
            this.remove(new QueryWrapper<SysDepartPermission>().lambda().eq(SysDepartPermission::getDepartId, departId).eq(SysDepartPermission::getPermissionId, permissionId));
            // 删除部门权限时,删除部门角色中已授权的权限
            List<SysDepartRole> sysDepartRoleList = sysDepartRoleMapper.selectList(new LambdaQueryWrapper<SysDepartRole>().eq(SysDepartRole::getDepartId, departId));
            List<String> roleIds = sysDepartRoleList.stream().map(SysDepartRole::getId).collect(Collectors.toList());
            if (roleIds != null && roleIds.size() > 0) {
                departRolePermissionMapper.delete(new LambdaQueryWrapper<SysDepartRolePermission>().eq(SysDepartRolePermission::getPermissionId, permissionId));
            }
        }
    }
}
Also used : SysDepartPermission(org.jeecg.modules.system.entity.SysDepartPermission) QueryWrapper(com.baomidou.mybatisplus.core.conditions.query.QueryWrapper) LambdaQueryWrapper(com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper) SysDepartRole(org.jeecg.modules.system.entity.SysDepartRole) LambdaQueryWrapper(com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

LambdaQueryWrapper (com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper)12 SysDepartPermission (org.jeecg.modules.system.entity.SysDepartPermission)12 QueryWrapper (com.baomidou.mybatisplus.core.conditions.query.QueryWrapper)6 SysPermissionDataRule (org.jeecg.modules.system.entity.SysPermissionDataRule)6 JSONObject (com.alibaba.fastjson.JSONObject)3 SysDepartRole (org.jeecg.modules.system.entity.SysDepartRole)3 Transactional (org.springframework.transaction.annotation.Transactional)3