Search in sources :

Example 26 with GenTable

use of com.ruoyi.generator.domain.GenTable in project RuoYi-Vue-Plus by JavaLionLi.

the class VelocityUtils method setSubVelocityContext.

public static void setSubVelocityContext(VelocityContext context, GenTable genTable) {
    GenTable subTable = genTable.getSubTable();
    String subTableName = genTable.getSubTableName();
    String subTableFkName = genTable.getSubTableFkName();
    String subClassName = genTable.getSubTable().getClassName();
    String subTableFkClassName = StringUtils.convertToCamelCase(subTableFkName);
    context.put("subTable", subTable);
    context.put("subTableName", subTableName);
    context.put("subTableFkName", subTableFkName);
    context.put("subTableFkClassName", subTableFkClassName);
    context.put("subTableFkclassName", StringUtils.uncapitalize(subTableFkClassName));
    context.put("subClassName", subClassName);
    context.put("subclassName", StringUtils.uncapitalize(subClassName));
    context.put("subImportList", getImportList(genTable.getSubTable()));
}
Also used : GenTable(com.ruoyi.generator.domain.GenTable)

Example 27 with GenTable

use of com.ruoyi.generator.domain.GenTable in project RuoYi-Flowable-Plus by KonBAI-Q.

the class GenTableServiceImpl method importGenTable.

/**
 * 导入表结构
 *
 * @param tableList 导入表列表
 */
@Override
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)

Example 28 with GenTable

use of com.ruoyi.generator.domain.GenTable in project RuoYi-Flowable-Plus by KonBAI-Q.

the class GenTableServiceImpl method selectGenTableById.

/**
 * 查询业务信息
 *
 * @param id 业务ID
 * @return 业务信息
 */
@Override
public GenTable selectGenTableById(Long id) {
    GenTable genTable = baseMapper.selectGenTableById(id);
    setTableFromOptions(genTable);
    return genTable;
}
Also used : GenTable(com.ruoyi.generator.domain.GenTable)

Example 29 with GenTable

use of com.ruoyi.generator.domain.GenTable in project RuoYi-Flowable-Plus by KonBAI-Q.

the class VelocityUtils method setSubVelocityContext.

public static void setSubVelocityContext(VelocityContext context, GenTable genTable) {
    GenTable subTable = genTable.getSubTable();
    String subTableName = genTable.getSubTableName();
    String subTableFkName = genTable.getSubTableFkName();
    String subClassName = genTable.getSubTable().getClassName();
    String subTableFkClassName = StringUtils.convertToCamelCase(subTableFkName);
    context.put("subTable", subTable);
    context.put("subTableName", subTableName);
    context.put("subTableFkName", subTableFkName);
    context.put("subTableFkClassName", subTableFkClassName);
    context.put("subTableFkclassName", StringUtils.uncapitalize(subTableFkClassName));
    context.put("subClassName", subClassName);
    context.put("subclassName", StringUtils.uncapitalize(subClassName));
    context.put("subImportList", getImportList(genTable.getSubTable()));
}
Also used : GenTable(com.ruoyi.generator.domain.GenTable)

Example 30 with GenTable

use of com.ruoyi.generator.domain.GenTable in project RuoYi-Flowable-Plus by KonBAI-Q.

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");
            importList.add("com.fasterxml.jackson.annotation.JsonFormat");
        } else if (!column.isSuperColumn() && GenConstants.TYPE_BIGDECIMAL.equals(column.getJavaType())) {
            importList.add("java.math.BigDecimal");
        }
    }
    return importList;
}
Also used : GenTable(com.ruoyi.generator.domain.GenTable) GenTableColumn(com.ruoyi.generator.domain.GenTableColumn)

Aggregations

GenTable (com.ruoyi.generator.domain.GenTable)45 GenTableColumn (com.ruoyi.generator.domain.GenTableColumn)20 IOException (java.io.IOException)20 StringWriter (java.io.StringWriter)20 Template (org.apache.velocity.Template)20 VelocityContext (org.apache.velocity.VelocityContext)20 ServiceException (com.ruoyi.common.exception.ServiceException)12 ZipEntry (java.util.zip.ZipEntry)10 File (java.io.File)8 Transactional (org.springframework.transaction.annotation.Transactional)8 LinkedHashMap (java.util.LinkedHashMap)6 Constants (com.ruoyi.common.constant.Constants)5 GenConstants (com.ruoyi.common.constant.GenConstants)5 StringUtils (com.ruoyi.common.utils.StringUtils)5 GenTableColumnMapper (com.ruoyi.generator.mapper.GenTableColumnMapper)5 GenTableMapper (com.ruoyi.generator.mapper.GenTableMapper)5 GenUtils (com.ruoyi.generator.util.GenUtils)5 VelocityInitializer (com.ruoyi.generator.util.VelocityInitializer)5 VelocityUtils (com.ruoyi.generator.util.VelocityUtils)5 ByteArrayOutputStream (java.io.ByteArrayOutputStream)5