Search in sources :

Example 16 with GenTableColumn

use of com.ruoyi.gen.domain.GenTableColumn in project RuoYi-Cloud-Oracle by yangzongzhuan.

the class GenTableServiceImpl method importGenTable.

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

Example 17 with GenTableColumn

use of com.ruoyi.gen.domain.GenTableColumn in project RuoYi-Cloud-Plus by JavaLionLi.

the class GenController method getInfo.

/**
 * 修改代码生成业务
 */
@ApiOperation("修改代码生成业务")
@SaCheckPermission("tool:gen:query")
@GetMapping(value = "/{tableId}")
public R<Map<String, Object>> getInfo(@PathVariable Long tableId) {
    GenTable table = genTableService.selectGenTableById(tableId);
    List<GenTable> tables = genTableService.selectGenTableAll();
    List<GenTableColumn> list = genTableService.selectGenTableColumnListByTableId(tableId);
    Map<String, Object> map = new HashMap<String, Object>();
    map.put("info", table);
    map.put("rows", list);
    map.put("tables", tables);
    return R.ok(map);
}
Also used : GenTable(com.ruoyi.gen.domain.GenTable) HashMap(java.util.HashMap) GenTableColumn(com.ruoyi.gen.domain.GenTableColumn) ApiOperation(io.swagger.annotations.ApiOperation) SaCheckPermission(cn.dev33.satoken.annotation.SaCheckPermission)

Example 18 with GenTableColumn

use of com.ruoyi.gen.domain.GenTableColumn in project RuoYi-Cloud-Plus by JavaLionLi.

the class VelocityUtils method getExpandColumn.

/**
 * 获取需要在哪一列上面显示展开按钮
 *
 * @param genTable 业务表对象
 * @return 展开按钮列序号
 */
public static int getExpandColumn(GenTable genTable) {
    String options = genTable.getOptions();
    Dict paramsObj = JsonUtils.parseMap(options);
    String treeName = paramsObj.getStr(GenConstants.TREE_NAME);
    int num = 0;
    for (GenTableColumn column : genTable.getColumns()) {
        if (column.isList()) {
            num++;
            String columnName = column.getColumnName();
            if (columnName.equals(treeName)) {
                break;
            }
        }
    }
    return num;
}
Also used : Dict(cn.hutool.core.lang.Dict) GenTableColumn(com.ruoyi.gen.domain.GenTableColumn)

Example 19 with GenTableColumn

use of com.ruoyi.gen.domain.GenTableColumn in project RuoYi-Cloud-Plus by JavaLionLi.

the class VelocityUtils method getImportList.

/**
 * 根据列类型获取导入包
 *
 * @param genTable 业务表对象
 * @return 返回需要导入的包列表
 */
public static HashSet<String> getImportList(GenTable genTable) {
    List<GenTableColumn> columns = genTable.getColumns();
    GenTable subGenTable = genTable.getSubTable();
    HashSet<String> importList = new HashSet<String>();
    if (ObjectUtil.isNotNull(subGenTable)) {
        importList.add("java.util.List");
    }
    for (GenTableColumn column : columns) {
        if (!column.isSuperColumn() && GenConstants.TYPE_DATE.equals(column.getJavaType())) {
            importList.add("java.util.Date");
        } else if (!column.isSuperColumn() && GenConstants.TYPE_BIGDECIMAL.equals(column.getJavaType())) {
            importList.add("java.math.BigDecimal");
        }
    }
    return importList;
}
Also used : GenTable(com.ruoyi.gen.domain.GenTable) GenTableColumn(com.ruoyi.gen.domain.GenTableColumn)

Example 20 with GenTableColumn

use of com.ruoyi.gen.domain.GenTableColumn in project RuoYi-Cloud-Plus by JavaLionLi.

the class GenTableServiceImpl method synchDb.

/**
 * 同步数据库
 *
 * @param tableName 表名称
 */
@Override
public void synchDb(String tableName) {
    GenTable table = baseMapper.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 (CollUtil.isEmpty(dbTableColumns)) {
        throw new ServiceException("同步数据失败,原表结构不存在");
    }
    List<String> dbTableColumnNames = dbTableColumns.stream().map(GenTableColumn::getColumnName).collect(Collectors.toList());
    List<GenTableColumn> saveColumns = new ArrayList<>();
    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.updateById(column);
        } else {
            genTableColumnMapper.insert(column);
        }
    });
    if (CollUtil.isNotEmpty(saveColumns)) {
        genTableColumnMapper.insertBatch(saveColumns);
    }
    List<GenTableColumn> delColumns = tableColumns.stream().filter(column -> !dbTableColumnNames.contains(column.getColumnName())).collect(Collectors.toList());
    if (CollUtil.isNotEmpty(delColumns)) {
        List<Long> ids = delColumns.stream().map(GenTableColumn::getColumnId).collect(Collectors.toList());
        genTableColumnMapper.deleteBatchIds(ids);
    }
}
Also used : ZipOutputStream(java.util.zip.ZipOutputStream) java.util(java.util) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ObjectUtil(cn.hutool.core.util.ObjectUtil) RequiredArgsConstructor(lombok.RequiredArgsConstructor) IdUtil(cn.hutool.core.util.IdUtil) LambdaQueryWrapper(com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper) Constants(com.ruoyi.common.core.constant.Constants) TableDataInfo(com.ruoyi.common.mybatis.core.page.TableDataInfo) LoginHelper(com.ruoyi.common.satoken.utils.LoginHelper) Function(java.util.function.Function) ServiceException(com.ruoyi.common.core.exception.ServiceException) Template(org.apache.velocity.Template) Wrapper(com.baomidou.mybatisplus.core.conditions.Wrapper) Service(org.springframework.stereotype.Service) JsonUtils(com.ruoyi.common.core.utils.JsonUtils) GenUtils(com.ruoyi.gen.util.GenUtils) GenTableColumnMapper(com.ruoyi.gen.mapper.GenTableColumnMapper) ZipEntry(java.util.zip.ZipEntry) GenTable(com.ruoyi.gen.domain.GenTable) VelocityUtils(com.ruoyi.gen.util.VelocityUtils) QueryWrapper(com.baomidou.mybatisplus.core.conditions.query.QueryWrapper) Wrappers(com.baomidou.mybatisplus.core.toolkit.Wrappers) IoUtil(cn.hutool.core.io.IoUtil) Snowflake(cn.hutool.core.lang.Snowflake) GenTableMapper(com.ruoyi.gen.mapper.GenTableMapper) VelocityInitializer(com.ruoyi.gen.util.VelocityInitializer) StringWriter(java.io.StringWriter) Dict(cn.hutool.core.lang.Dict) GenConstants(com.ruoyi.common.core.constant.GenConstants) IOException(java.io.IOException) GenTableColumn(com.ruoyi.gen.domain.GenTableColumn) StringUtils(com.ruoyi.common.core.utils.StringUtils) VelocityContext(org.apache.velocity.VelocityContext) Collectors(java.util.stream.Collectors) FileUtils(com.ruoyi.common.core.utils.file.FileUtils) File(java.io.File) StandardCharsets(java.nio.charset.StandardCharsets) Page(com.baomidou.mybatisplus.extension.plugins.pagination.Page) CollUtil(cn.hutool.core.collection.CollUtil) Slf4j(lombok.extern.slf4j.Slf4j) Velocity(org.apache.velocity.app.Velocity) PageQuery(com.ruoyi.common.mybatis.core.page.PageQuery) ServiceException(com.ruoyi.common.core.exception.ServiceException) GenTable(com.ruoyi.gen.domain.GenTable) GenTableColumn(com.ruoyi.gen.domain.GenTableColumn)

Aggregations

GenTableColumn (com.ruoyi.gen.domain.GenTableColumn)20 GenTable (com.ruoyi.gen.domain.GenTable)12 ServiceException (com.ruoyi.common.core.exception.ServiceException)6 IOException (java.io.IOException)6 Transactional (org.springframework.transaction.annotation.Transactional)6 JSONObject (com.alibaba.fastjson.JSONObject)4 GetMapping (org.springframework.web.bind.annotation.GetMapping)4 Constants (com.ruoyi.common.core.constant.Constants)3 GenConstants (com.ruoyi.common.core.constant.GenConstants)3 StringUtils (com.ruoyi.common.core.utils.StringUtils)3 GenTableColumnMapper (com.ruoyi.gen.mapper.GenTableColumnMapper)3 GenTableMapper (com.ruoyi.gen.mapper.GenTableMapper)3 GenUtils (com.ruoyi.gen.util.GenUtils)3 VelocityInitializer (com.ruoyi.gen.util.VelocityInitializer)3 VelocityUtils (com.ruoyi.gen.util.VelocityUtils)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 File (java.io.File)3 StringWriter (java.io.StringWriter)3 HashMap (java.util.HashMap)3 Function (java.util.function.Function)3