Search in sources :

Example 36 with LambdaQueryWrapper

use of com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper 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)

Example 37 with LambdaQueryWrapper

use of com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper in project RuoYi-Flowable-Plus by KonBAI-Q.

the class SysConfigServiceImpl method checkConfigKeyUnique.

/**
 * 校验参数键名是否唯一
 *
 * @param config 参数配置信息
 * @return 结果
 */
@Override
public String checkConfigKeyUnique(SysConfig config) {
    Long configId = ObjectUtil.isNull(config.getConfigId()) ? -1L : config.getConfigId();
    SysConfig info = baseMapper.selectOne(new LambdaQueryWrapper<SysConfig>().eq(SysConfig::getConfigKey, config.getConfigKey()));
    if (ObjectUtil.isNotNull(info) && info.getConfigId().longValue() != configId.longValue()) {
        return UserConstants.NOT_UNIQUE;
    }
    return UserConstants.UNIQUE;
}
Also used : SysConfig(com.ruoyi.system.domain.SysConfig) LambdaQueryWrapper(com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper)

Example 38 with LambdaQueryWrapper

use of com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper in project RuoYi-Flowable-Plus by KonBAI-Q.

the class SysDeptServiceImpl method updateDeptChildren.

/**
 * 修改子元素关系
 *
 * @param deptId       被修改的部门ID
 * @param newAncestors 新的父ID集合
 * @param oldAncestors 旧的父ID集合
 */
public void updateDeptChildren(Long deptId, String newAncestors, String oldAncestors) {
    List<SysDept> children = baseMapper.selectList(new LambdaQueryWrapper<SysDept>().apply(DataBaseHelper.findInSet(deptId, "ancestors")));
    List<SysDept> list = new ArrayList<>();
    for (SysDept child : children) {
        SysDept dept = new SysDept();
        dept.setDeptId(child.getDeptId());
        dept.setAncestors(child.getAncestors().replaceFirst(oldAncestors, newAncestors));
        list.add(dept);
    }
    if (list.size() > 0) {
        baseMapper.updateBatchById(list);
    }
}
Also used : SysDept(com.ruoyi.common.core.domain.entity.SysDept) ArrayList(java.util.ArrayList) LambdaQueryWrapper(com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper)

Example 39 with LambdaQueryWrapper

use of com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper in project RuoYi-Flowable-Plus by KonBAI-Q.

the class SysDictTypeServiceImpl method deleteDictTypeByIds.

/**
 * 批量删除字典类型信息
 *
 * @param dictIds 需要删除的字典ID
 */
@Override
public void deleteDictTypeByIds(Long[] dictIds) {
    for (Long dictId : dictIds) {
        SysDictType dictType = selectDictTypeById(dictId);
        if (dictDataMapper.exists(new LambdaQueryWrapper<SysDictData>().eq(SysDictData::getDictType, dictType.getDictType()))) {
            throw new ServiceException(String.format("%1$s已分配,不能删除", dictType.getDictName()));
        }
        RedisUtils.deleteObject(getCacheKey(dictType.getDictType()));
    }
    baseMapper.deleteBatchIds(Arrays.asList(dictIds));
}
Also used : ServiceException(com.ruoyi.common.exception.ServiceException) SysDictType(com.ruoyi.common.core.domain.entity.SysDictType) LambdaQueryWrapper(com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper)

Example 40 with LambdaQueryWrapper

use of com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper in project RuoYi-Flowable-Plus by KonBAI-Q.

the class SysUserServiceImpl method deleteUserByIds.

/**
 * 批量删除用户信息
 *
 * @param userIds 需要删除的用户ID
 * @return 结果
 */
@Override
@Transactional(rollbackFor = Exception.class)
public int deleteUserByIds(Long[] userIds) {
    for (Long userId : userIds) {
        checkUserAllowed(new SysUser(userId));
        checkUserDataScope(userId);
    }
    List<Long> ids = Arrays.asList(userIds);
    // 删除用户与角色关联
    userRoleMapper.delete(new LambdaQueryWrapper<SysUserRole>().in(SysUserRole::getUserId, ids));
    // 删除用户与岗位表
    userPostMapper.delete(new LambdaQueryWrapper<SysUserPost>().in(SysUserPost::getUserId, ids));
    return baseMapper.deleteBatchIds(ids);
}
Also used : SysUser(com.ruoyi.common.core.domain.entity.SysUser) LambdaQueryWrapper(com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

LambdaQueryWrapper (com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper)381 Transactional (org.springframework.transaction.annotation.Transactional)60 JSONObject (com.alibaba.fastjson.JSONObject)52 Result (org.jeecg.common.api.vo.Result)50 ArrayList (java.util.ArrayList)42 List (java.util.List)30 Map (java.util.Map)29 Collectors (java.util.stream.Collectors)26 Service (org.springframework.stereotype.Service)24 LoginUser (org.jeecg.common.system.vo.LoginUser)22 SysPermission (org.jeecg.modules.system.entity.SysPermission)22 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)22 QueryWrapper (com.baomidou.mybatisplus.core.conditions.query.QueryWrapper)21 IPage (com.baomidou.mybatisplus.core.metadata.IPage)20 HashMap (java.util.HashMap)20 SysUser (org.jeecg.modules.system.entity.SysUser)20 ApiOperation (io.swagger.annotations.ApiOperation)19 ServiceException (cn.lili.common.exception.ServiceException)18 ServiceImpl (com.baomidou.mybatisplus.extension.service.impl.ServiceImpl)18 Autowired (org.springframework.beans.factory.annotation.Autowired)18