Search in sources :

Example 16 with ServiceException

use of com.ruoyi.common.exception.ServiceException in project RuoYi-Vue-Oracle by yangzongzhuan.

the class GenTableServiceImpl method synchDb.

/**
 * 同步数据库
 *
 * @param tableName 表名称
 */
@Override
@Transactional
public void synchDb(String tableName) {
    GenTable table = genTableMapper.selectGenTableByName(tableName);
    List<GenTableColumn> tableColumns = table.getColumns();
    Map<String, GenTableColumn> tableColumnMap = tableColumns.stream().collect(Collectors.toMap(GenTableColumn::getColumnName, Function.identity()));
    List<GenTableColumn> dbTableColumns = genTableColumnMapper.selectDbTableColumnsByName(tableName);
    if (StringUtils.isEmpty(dbTableColumns)) {
        throw new ServiceException("同步数据失败,原表结构不存在");
    }
    List<String> dbTableColumnNames = dbTableColumns.stream().map(GenTableColumn::getColumnName).collect(Collectors.toList());
    dbTableColumns.forEach(column -> {
        GenUtils.initColumnField(column, table);
        if (tableColumnMap.containsKey(column.getColumnName())) {
            GenTableColumn prevColumn = tableColumnMap.get(column.getColumnName());
            column.setColumnId(prevColumn.getColumnId());
            if (column.isList()) {
                // 如果是列表,继续保留查询方式/字典类型选项
                column.setDictType(prevColumn.getDictType());
                column.setQueryType(prevColumn.getQueryType());
            }
            if (StringUtils.isNotEmpty(prevColumn.getIsRequired()) && !column.isPk() && (column.isInsert() || column.isEdit()) && ((column.isUsableColumn()) || (!column.isSuperColumn()))) {
                // 如果是(新增/修改&非主键/非忽略及父属性),继续保留必填/显示类型选项
                column.setIsRequired(prevColumn.getIsRequired());
                column.setHtmlType(prevColumn.getHtmlType());
            }
            genTableColumnMapper.updateGenTableColumn(column);
        } else {
            genTableColumnMapper.insertGenTableColumn(column);
        }
    });
    List<GenTableColumn> delColumns = tableColumns.stream().filter(column -> !dbTableColumnNames.contains(column.getColumnName())).collect(Collectors.toList());
    if (StringUtils.isNotEmpty(delColumns)) {
        genTableColumnMapper.deleteGenTableColumns(delColumns);
    }
}
Also used : ZipOutputStream(java.util.zip.ZipOutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) CharsetKit(com.ruoyi.common.core.text.CharsetKit) ServiceException(com.ruoyi.common.exception.ServiceException) LoggerFactory(org.slf4j.LoggerFactory) VelocityUtils(com.ruoyi.project.tool.gen.util.VelocityUtils) Autowired(org.springframework.beans.factory.annotation.Autowired) GenTableMapper(com.ruoyi.project.tool.gen.mapper.GenTableMapper) Function(java.util.function.Function) GenTableColumnMapper(com.ruoyi.project.tool.gen.mapper.GenTableColumnMapper) Template(org.apache.velocity.Template) LinkedHashMap(java.util.LinkedHashMap) StringUtils(com.ruoyi.common.utils.StringUtils) Service(org.springframework.stereotype.Service) Map(java.util.Map) SecurityUtils(com.ruoyi.common.utils.SecurityUtils) ZipEntry(java.util.zip.ZipEntry) Logger(org.slf4j.Logger) StringWriter(java.io.StringWriter) GenConstants(com.ruoyi.common.constant.GenConstants) GenTable(com.ruoyi.project.tool.gen.domain.GenTable) IOException(java.io.IOException) FileUtils(org.apache.commons.io.FileUtils) Collectors(java.util.stream.Collectors) VelocityContext(org.apache.velocity.VelocityContext) File(java.io.File) IOUtils(org.apache.commons.io.IOUtils) List(java.util.List) JSON(com.alibaba.fastjson.JSON) GenTableColumn(com.ruoyi.project.tool.gen.domain.GenTableColumn) JSONObject(com.alibaba.fastjson.JSONObject) Velocity(org.apache.velocity.app.Velocity) GenUtils(com.ruoyi.project.tool.gen.util.GenUtils) Transactional(org.springframework.transaction.annotation.Transactional) Constants(com.ruoyi.common.constant.Constants) VelocityInitializer(com.ruoyi.project.tool.gen.util.VelocityInitializer) ServiceException(com.ruoyi.common.exception.ServiceException) GenTable(com.ruoyi.project.tool.gen.domain.GenTable) GenTableColumn(com.ruoyi.project.tool.gen.domain.GenTableColumn) Transactional(org.springframework.transaction.annotation.Transactional)

Example 17 with ServiceException

use of com.ruoyi.common.exception.ServiceException in project RuoYi-Vue-fast by yangzongzhuan.

the class GenTableServiceImpl method synchDb.

/**
 * 同步数据库
 *
 * @param tableName 表名称
 */
@Override
@Transactional
public void synchDb(String tableName) {
    GenTable table = genTableMapper.selectGenTableByName(tableName);
    List<GenTableColumn> tableColumns = table.getColumns();
    Map<String, GenTableColumn> tableColumnMap = tableColumns.stream().collect(Collectors.toMap(GenTableColumn::getColumnName, Function.identity()));
    List<GenTableColumn> dbTableColumns = genTableColumnMapper.selectDbTableColumnsByName(tableName);
    if (StringUtils.isEmpty(dbTableColumns)) {
        throw new ServiceException("同步数据失败,原表结构不存在");
    }
    List<String> dbTableColumnNames = dbTableColumns.stream().map(GenTableColumn::getColumnName).collect(Collectors.toList());
    dbTableColumns.forEach(column -> {
        GenUtils.initColumnField(column, table);
        if (tableColumnMap.containsKey(column.getColumnName())) {
            GenTableColumn prevColumn = tableColumnMap.get(column.getColumnName());
            column.setColumnId(prevColumn.getColumnId());
            if (column.isList()) {
                // 如果是列表,继续保留查询方式/字典类型选项
                column.setDictType(prevColumn.getDictType());
                column.setQueryType(prevColumn.getQueryType());
            }
            if (StringUtils.isNotEmpty(prevColumn.getIsRequired()) && !column.isPk() && (column.isInsert() || column.isEdit()) && ((column.isUsableColumn()) || (!column.isSuperColumn()))) {
                // 如果是(新增/修改&非主键/非忽略及父属性),继续保留必填/显示类型选项
                column.setIsRequired(prevColumn.getIsRequired());
                column.setHtmlType(prevColumn.getHtmlType());
            }
            genTableColumnMapper.updateGenTableColumn(column);
        } else {
            genTableColumnMapper.insertGenTableColumn(column);
        }
    });
    List<GenTableColumn> delColumns = tableColumns.stream().filter(column -> !dbTableColumnNames.contains(column.getColumnName())).collect(Collectors.toList());
    if (StringUtils.isNotEmpty(delColumns)) {
        genTableColumnMapper.deleteGenTableColumns(delColumns);
    }
}
Also used : ZipOutputStream(java.util.zip.ZipOutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) CharsetKit(com.ruoyi.common.core.text.CharsetKit) ServiceException(com.ruoyi.common.exception.ServiceException) LoggerFactory(org.slf4j.LoggerFactory) VelocityUtils(com.ruoyi.project.tool.gen.util.VelocityUtils) Autowired(org.springframework.beans.factory.annotation.Autowired) GenTableMapper(com.ruoyi.project.tool.gen.mapper.GenTableMapper) Function(java.util.function.Function) GenTableColumnMapper(com.ruoyi.project.tool.gen.mapper.GenTableColumnMapper) Template(org.apache.velocity.Template) LinkedHashMap(java.util.LinkedHashMap) StringUtils(com.ruoyi.common.utils.StringUtils) Service(org.springframework.stereotype.Service) Map(java.util.Map) SecurityUtils(com.ruoyi.common.utils.SecurityUtils) ZipEntry(java.util.zip.ZipEntry) Logger(org.slf4j.Logger) StringWriter(java.io.StringWriter) GenConstants(com.ruoyi.common.constant.GenConstants) GenTable(com.ruoyi.project.tool.gen.domain.GenTable) IOException(java.io.IOException) FileUtils(org.apache.commons.io.FileUtils) Collectors(java.util.stream.Collectors) VelocityContext(org.apache.velocity.VelocityContext) File(java.io.File) IOUtils(org.apache.commons.io.IOUtils) List(java.util.List) JSON(com.alibaba.fastjson.JSON) GenTableColumn(com.ruoyi.project.tool.gen.domain.GenTableColumn) JSONObject(com.alibaba.fastjson.JSONObject) Velocity(org.apache.velocity.app.Velocity) GenUtils(com.ruoyi.project.tool.gen.util.GenUtils) Transactional(org.springframework.transaction.annotation.Transactional) Constants(com.ruoyi.common.constant.Constants) VelocityInitializer(com.ruoyi.project.tool.gen.util.VelocityInitializer) ServiceException(com.ruoyi.common.exception.ServiceException) GenTable(com.ruoyi.project.tool.gen.domain.GenTable) GenTableColumn(com.ruoyi.project.tool.gen.domain.GenTableColumn) Transactional(org.springframework.transaction.annotation.Transactional)

Example 18 with ServiceException

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

the class SysConfigServiceImpl method deleteConfigByIds.

/**
 * 批量删除参数信息
 *
 * @param configIds 需要删除的参数ID
 */
@Override
public void deleteConfigByIds(Long[] configIds) {
    for (Long configId : configIds) {
        SysConfig config = selectConfigById(configId);
        if (StringUtils.equals(UserConstants.YES, config.getConfigType())) {
            throw new ServiceException(String.format("内置参数【%1$s】不能删除 ", config.getConfigKey()));
        }
        RedisUtils.deleteObject(getCacheKey(config.getConfigKey()));
    }
    baseMapper.deleteBatchIds(Arrays.asList(configIds));
}
Also used : SysConfig(com.ruoyi.system.domain.SysConfig) ServiceException(com.ruoyi.common.exception.ServiceException)

Example 19 with ServiceException

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

the class SysDeptServiceImpl method checkDeptDataScope.

/**
 * 校验部门是否有数据权限
 *
 * @param deptId 部门id
 */
@Override
public void checkDeptDataScope(Long deptId) {
    if (!LoginHelper.isAdmin()) {
        SysDept dept = new SysDept();
        dept.setDeptId(deptId);
        List<SysDept> depts = this.selectDeptList(dept);
        if (CollUtil.isEmpty(depts)) {
            throw new ServiceException("没有权限访问部门数据!");
        }
    }
}
Also used : ServiceException(com.ruoyi.common.exception.ServiceException) SysDept(com.ruoyi.common.core.domain.entity.SysDept)

Example 20 with ServiceException

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

the class SysDeptServiceImpl method insertDept.

/**
 * 新增保存部门信息
 *
 * @param dept 部门信息
 * @return 结果
 */
@Override
public int insertDept(SysDept dept) {
    SysDept info = baseMapper.selectById(dept.getParentId());
    // 如果父节点不为正常状态,则不允许新增子节点
    if (!UserConstants.DEPT_NORMAL.equals(info.getStatus())) {
        throw new ServiceException("部门停用,不允许新增");
    }
    dept.setAncestors(info.getAncestors() + "," + dept.getParentId());
    return baseMapper.insert(dept);
}
Also used : ServiceException(com.ruoyi.common.exception.ServiceException) SysDept(com.ruoyi.common.core.domain.entity.SysDept)

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