Search in sources :

Example 21 with ServiceException

use of com.ruoyi.common.exception.ServiceException in project RuoYi-Vue-Plus by JavaLionLi.

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 22 with ServiceException

use of com.ruoyi.common.exception.ServiceException in project RuoYi-Vue-Plus by JavaLionLi.

the class SysOssConfigServiceImpl method deleteWithValidByIds.

@Override
public Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid) {
    if (isValid) {
        if (CollUtil.containsAny(ids, OssConstant.SYSTEM_DATA_IDS)) {
            throw new ServiceException("系统内置, 不可删除!");
        }
    }
    List<SysOssConfig> list = Lists.newArrayList();
    for (Long configId : ids) {
        SysOssConfig config = baseMapper.selectById(configId);
        list.add(config);
    }
    boolean flag = baseMapper.deleteBatchIds(ids) > 0;
    if (flag) {
        list.stream().forEach(sysOssConfig -> {
            RedisUtils.deleteObject(getCacheKey(sysOssConfig.getConfigKey()));
        });
    }
    return flag;
}
Also used : SysOssConfig(com.ruoyi.system.domain.SysOssConfig) ServiceException(com.ruoyi.common.exception.ServiceException)

Example 23 with ServiceException

use of com.ruoyi.common.exception.ServiceException in project RuoYi-Vue-Plus by JavaLionLi.

the class SysUserServiceImpl method checkUserDataScope.

/**
 * 校验用户是否有数据权限
 *
 * @param userId 用户id
 */
@Override
public void checkUserDataScope(Long userId) {
    if (!LoginHelper.isAdmin()) {
        SysUser user = new SysUser();
        user.setUserId(userId);
        List<SysUser> users = this.selectUserList(user);
        if (CollUtil.isEmpty(users)) {
            throw new ServiceException("没有权限访问用户数据!");
        }
    }
}
Also used : SysUser(com.ruoyi.common.core.domain.entity.SysUser) ServiceException(com.ruoyi.common.exception.ServiceException)

Example 24 with ServiceException

use of com.ruoyi.common.exception.ServiceException in project RuoYi-Vue-Plus by JavaLionLi.

the class GenTableServiceImpl method importGenTable.

/**
 * 导入表结构
 *
 * @param tableList 导入表列表
 */
@Override
@Transactional(rollbackFor = Exception.class)
public void importGenTable(List<GenTable> tableList) {
    String operName = LoginHelper.getUsername();
    try {
        for (GenTable table : tableList) {
            String tableName = table.getTableName();
            GenUtils.initTable(table, operName);
            int row = baseMapper.insert(table);
            if (row > 0) {
                // 保存列信息
                List<GenTableColumn> genTableColumns = genTableColumnMapper.selectDbTableColumnsByName(tableName);
                List<GenTableColumn> saveColumns = new ArrayList<>();
                for (GenTableColumn column : genTableColumns) {
                    GenUtils.initColumnField(column, table);
                    saveColumns.add(column);
                }
                if (CollUtil.isNotEmpty(saveColumns)) {
                    genTableColumnMapper.insertBatch(saveColumns);
                }
            }
        }
    } catch (Exception e) {
        throw new ServiceException("导入失败:" + e.getMessage());
    }
}
Also used : ServiceException(com.ruoyi.common.exception.ServiceException) GenTable(com.ruoyi.generator.domain.GenTable) GenTableColumn(com.ruoyi.generator.domain.GenTableColumn) ServiceException(com.ruoyi.common.exception.ServiceException) IOException(java.io.IOException) Transactional(org.springframework.transaction.annotation.Transactional)

Example 25 with ServiceException

use of com.ruoyi.common.exception.ServiceException in project RuoYi-Vue-Plus by JavaLionLi.

the class GenTableServiceImpl method validateEdit.

/**
 * 修改保存参数校验
 *
 * @param genTable 业务信息
 */
@Override
public void validateEdit(GenTable genTable) {
    if (GenConstants.TPL_TREE.equals(genTable.getTplCategory())) {
        String options = JsonUtils.toJsonString(genTable.getParams());
        Dict paramsObj = JsonUtils.parseMap(options);
        if (StringUtils.isEmpty(paramsObj.getStr(GenConstants.TREE_CODE))) {
            throw new ServiceException("树编码字段不能为空");
        } else if (StringUtils.isEmpty(paramsObj.getStr(GenConstants.TREE_PARENT_CODE))) {
            throw new ServiceException("树父编码字段不能为空");
        } else if (StringUtils.isEmpty(paramsObj.getStr(GenConstants.TREE_NAME))) {
            throw new ServiceException("树名称字段不能为空");
        } else if (GenConstants.TPL_SUB.equals(genTable.getTplCategory())) {
            if (StringUtils.isEmpty(genTable.getSubTableName())) {
                throw new ServiceException("关联子表的表名不能为空");
            } else if (StringUtils.isEmpty(genTable.getSubTableFkName())) {
                throw new ServiceException("子表关联的外键名不能为空");
            }
        }
    }
}
Also used : ServiceException(com.ruoyi.common.exception.ServiceException) Dict(cn.hutool.core.lang.Dict)

Aggregations

ServiceException (com.ruoyi.common.exception.ServiceException)109 IOException (java.io.IOException)21 Transactional (org.springframework.transaction.annotation.Transactional)21 GenTable (com.ruoyi.generator.domain.GenTable)12 StringWriter (java.io.StringWriter)12 Template (org.apache.velocity.Template)12 VelocityContext (org.apache.velocity.VelocityContext)12 SysRole (com.ruoyi.common.core.domain.entity.SysRole)10 File (java.io.File)10 SysUser (com.ruoyi.common.core.domain.entity.SysUser)9 GenTableColumn (com.ruoyi.generator.domain.GenTableColumn)8 Before (org.aspectj.lang.annotation.Before)8 JSONObject (com.alibaba.fastjson.JSONObject)6 LambdaQueryWrapper (com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper)6 SysDept (com.ruoyi.common.core.domain.entity.SysDept)6 LoginUser (com.ruoyi.common.core.domain.model.LoginUser)6 Constants (com.ruoyi.common.constant.Constants)5 GenConstants (com.ruoyi.common.constant.GenConstants)5 StringUtils (com.ruoyi.common.utils.StringUtils)5 SysOss (com.ruoyi.system.domain.SysOss)5