Search in sources :

Example 16 with JeecgBootException

use of org.jeecg.common.exception.JeecgBootException in project kms by mahonelau.

the class SysPermissionServiceImpl method deletePermission.

/**
 * 真实删除
 */
@Override
@Transactional
@CacheEvict(value = CacheConstant.SYS_DATA_PERMISSIONS_CACHE, allEntries = true)
public void deletePermission(String id) throws JeecgBootException {
    SysPermission sysPermission = this.getById(id);
    if (sysPermission == null) {
        throw new JeecgBootException("未找到菜单信息");
    }
    String pid = sysPermission.getParentId();
    if (oConvertUtils.isNotEmpty(pid)) {
        int count = this.count(new QueryWrapper<SysPermission>().lambda().eq(SysPermission::getParentId, pid));
        if (count == 1) {
            // 若父节点无其他子节点,则该父节点是叶子节点
            this.sysPermissionMapper.setMenuLeaf(pid, 1);
        }
    }
    sysPermissionMapper.deleteById(id);
    // 该节点可能是子节点但也可能是其它节点的父节点,所以需要级联删除
    this.removeChildrenBy(sysPermission.getId());
    // 关联删除
    Map map = new HashMap<>();
    map.put("permission_id", id);
    // 删除数据规则
    this.deletePermRuleByPermId(id);
    // 删除角色授权表
    sysRolePermissionMapper.deleteByMap(map);
    // 删除部门权限表
    sysDepartPermissionMapper.deleteByMap(map);
    // 删除部门角色授权
    sysDepartRolePermissionMapper.deleteByMap(map);
}
Also used : HashMap(java.util.HashMap) SysPermission(org.jeecg.modules.system.entity.SysPermission) JeecgBootException(org.jeecg.common.exception.JeecgBootException) HashMap(java.util.HashMap) Map(java.util.Map) CacheEvict(org.springframework.cache.annotation.CacheEvict) Transactional(org.springframework.transaction.annotation.Transactional)

Example 17 with JeecgBootException

use of org.jeecg.common.exception.JeecgBootException in project kms by mahonelau.

the class SysPermissionServiceImpl method deletePermissionLogical.

/**
 * 逻辑删除
 */
@Override
@CacheEvict(value = CacheConstant.SYS_DATA_PERMISSIONS_CACHE, allEntries = true)
public // @CacheEvict(value = CacheConstant.SYS_DATA_PERMISSIONS_CACHE,allEntries=true,condition="#sysPermission.menuType==2")
void deletePermissionLogical(String id) throws JeecgBootException {
    SysPermission sysPermission = this.getById(id);
    if (sysPermission == null) {
        throw new JeecgBootException("未找到菜单信息");
    }
    String pid = sysPermission.getParentId();
    int count = this.count(new QueryWrapper<SysPermission>().lambda().eq(SysPermission::getParentId, pid));
    if (count == 1) {
        // 若父节点无其他子节点,则该父节点是叶子节点
        this.sysPermissionMapper.setMenuLeaf(pid, 1);
    }
    sysPermission.setDelFlag(1);
    this.updateById(sysPermission);
}
Also used : SysPermission(org.jeecg.modules.system.entity.SysPermission) JeecgBootException(org.jeecg.common.exception.JeecgBootException) CacheEvict(org.springframework.cache.annotation.CacheEvict)

Example 18 with JeecgBootException

use of org.jeecg.common.exception.JeecgBootException in project kms by mahonelau.

the class SysPermissionServiceImpl method editPermission.

@Override
@CacheEvict(value = CacheConstant.SYS_DATA_PERMISSIONS_CACHE, allEntries = true)
public void editPermission(SysPermission sysPermission) throws JeecgBootException {
    SysPermission p = this.getById(sysPermission.getId());
    // TODO 该节点判断是否还有子节点
    if (p == null) {
        throw new JeecgBootException("未找到菜单信息");
    } else {
        sysPermission.setUpdateTime(new Date());
        // Step1.判断是否是一级菜单,是的话清空父菜单ID
        if (CommonConstant.MENU_TYPE_0.equals(sysPermission.getMenuType())) {
            sysPermission.setParentId("");
        }
        // Step2.判断菜单下级是否有菜单,无则设置为叶子节点
        int count = this.count(new QueryWrapper<SysPermission>().lambda().eq(SysPermission::getParentId, sysPermission.getId()));
        if (count == 0) {
            sysPermission.setLeaf(true);
        }
        // ----------------------------------------------------------------------
        this.updateById(sysPermission);
        // 如果当前菜单的父菜单变了,则需要修改新父菜单和老父菜单的,叶子节点状态
        String pid = sysPermission.getParentId();
        if ((oConvertUtils.isNotEmpty(pid) && !pid.equals(p.getParentId())) || oConvertUtils.isEmpty(pid) && oConvertUtils.isNotEmpty(p.getParentId())) {
            // a.设置新的父菜单不为叶子节点
            this.sysPermissionMapper.setMenuLeaf(pid, 0);
            // b.判断老的菜单下是否还有其他子菜单,没有的话则设置为叶子节点
            int cc = this.count(new QueryWrapper<SysPermission>().lambda().eq(SysPermission::getParentId, p.getParentId()));
            if (cc == 0) {
                if (oConvertUtils.isNotEmpty(p.getParentId())) {
                    this.sysPermissionMapper.setMenuLeaf(p.getParentId(), 1);
                }
            }
        }
    }
}
Also used : SysPermission(org.jeecg.modules.system.entity.SysPermission) JeecgBootException(org.jeecg.common.exception.JeecgBootException) Date(java.util.Date) CacheEvict(org.springframework.cache.annotation.CacheEvict)

Example 19 with JeecgBootException

use of org.jeecg.common.exception.JeecgBootException in project kms by mahonelau.

the class SysBaseApiImpl method parseTemplateByCode.

@Override
public String parseTemplateByCode(TemplateDTO templateDTO) {
    String templateCode = templateDTO.getTemplateCode();
    Map<String, String> map = templateDTO.getTemplateParam();
    List<SysMessageTemplate> sysSmsTemplates = sysMessageTemplateService.selectByCode(templateCode);
    if (sysSmsTemplates == null || sysSmsTemplates.size() == 0) {
        throw new JeecgBootException("消息模板不存在,模板编码:" + templateCode);
    }
    SysMessageTemplate sysSmsTemplate = sysSmsTemplates.get(0);
    // 模板内容
    String content = sysSmsTemplate.getTemplateContent();
    if (map != null) {
        for (Map.Entry<String, String> entry : map.entrySet()) {
            String str = "${" + entry.getKey() + "}";
            content = content.replace(str, entry.getValue());
        }
    }
    return content;
}
Also used : SysMessageTemplate(org.jeecg.modules.message.entity.SysMessageTemplate) JeecgBootException(org.jeecg.common.exception.JeecgBootException)

Example 20 with JeecgBootException

use of org.jeecg.common.exception.JeecgBootException in project jeecg-boot by jeecgboot.

the class DynamicDBUtil method getDbSourceByDbKey.

/**
 * 通过 dbKey ,获取数据源
 *
 * @param dbKey
 * @return
 */
public static DruidDataSource getDbSourceByDbKey(final String dbKey) {
    // 获取多数据源配置
    DynamicDataSourceModel dbSource = DataSourceCachePool.getCacheDynamicDataSourceModel(dbKey);
    // 先判断缓存中是否存在数据库链接
    DruidDataSource cacheDbSource = DataSourceCachePool.getCacheBasicDataSource(dbKey);
    if (cacheDbSource != null && !cacheDbSource.isClosed()) {
        log.debug("--------getDbSourceBydbKey------------------从缓存中获取DB连接-------------------");
        return cacheDbSource;
    } else {
        DruidDataSource dataSource = getJdbcDataSource(dbSource);
        if (dataSource != null && dataSource.isEnable()) {
            DataSourceCachePool.putCacheBasicDataSource(dbKey, dataSource);
        } else {
            throw new JeecgBootException("动态数据源连接失败,dbKey:" + dbKey);
        }
        log.info("--------getDbSourceBydbKey------------------创建DB数据库连接-------------------");
        return dataSource;
    }
}
Also used : JeecgBootException(org.jeecg.common.exception.JeecgBootException) DruidDataSource(com.alibaba.druid.pool.DruidDataSource) DynamicDataSourceModel(org.jeecg.common.system.vo.DynamicDataSourceModel)

Aggregations

JeecgBootException (org.jeecg.common.exception.JeecgBootException)35 SQLException (java.sql.SQLException)11 SysMessageTemplate (org.jeecg.modules.message.entity.SysMessageTemplate)9 SysPermission (org.jeecg.modules.system.entity.SysPermission)9 CacheEvict (org.springframework.cache.annotation.CacheEvict)9 JSONObject (com.alibaba.fastjson.JSONObject)6 Connection (java.sql.Connection)5 DatabaseMetaData (java.sql.DatabaseMetaData)5 DruidDataSource (com.alibaba.druid.pool.DruidDataSource)3 Date (java.util.Date)3 HashMap (java.util.HashMap)3 Map (java.util.Map)3 DynamicDataSourceModel (org.jeecg.common.system.vo.DynamicDataSourceModel)3 Transactional (org.springframework.transaction.annotation.Transactional)3 IOException (java.io.IOException)2 Result (org.jeecg.common.api.vo.Result)2 MultipartFile (org.springframework.web.multipart.MultipartFile)2 MultipartHttpServletRequest (org.springframework.web.multipart.MultipartHttpServletRequest)2 JeeccgBaseConfig (org.jeecg.config.JeeccgBaseConfig)1 OSSFile (org.jeecg.modules.oss.entity.OSSFile)1