Search in sources :

Example 6 with GenTable

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

the class GenController method getInfo.

/**
 * 修改代码生成业务
 */
@RequiresPermissions("tool:gen:query")
@GetMapping(value = "/{tableId}")
public AjaxResult getInfo(@PathVariable Long tableId) {
    GenTable table = genTableService.selectGenTableById(tableId);
    List<GenTable> tables = genTableService.selectGenTableAll();
    List<GenTableColumn> list = genTableColumnService.selectGenTableColumnListByTableId(tableId);
    Map<String, Object> map = new HashMap<String, Object>();
    map.put("info", table);
    map.put("rows", list);
    map.put("tables", tables);
    return AjaxResult.success(map);
}
Also used : GenTable(com.ruoyi.gen.domain.GenTable) HashMap(java.util.HashMap) GenTableColumn(com.ruoyi.gen.domain.GenTableColumn) RequiresPermissions(com.ruoyi.common.security.annotation.RequiresPermissions) GetMapping(org.springframework.web.bind.annotation.GetMapping)

Example 7 with GenTable

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

the class GenTableServiceImpl method selectGenTableById.

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

Example 8 with GenTable

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

the class GenTableServiceImpl method synchDb.

/**
 * 同步数据库
 *
 * @param tableName 表名称
 */
@Override
@Transactional(rollbackFor = Exception.class)
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) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) Constants(com.ruoyi.common.core.constant.Constants) Function(java.util.function.Function) ServiceException(com.ruoyi.common.core.exception.ServiceException) Template(org.apache.velocity.Template) LinkedHashMap(java.util.LinkedHashMap) Service(org.springframework.stereotype.Service) Map(java.util.Map) 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) Logger(org.slf4j.Logger) GenTableMapper(com.ruoyi.gen.mapper.GenTableMapper) VelocityInitializer(com.ruoyi.gen.util.VelocityInitializer) StringWriter(java.io.StringWriter) IOException(java.io.IOException) FileUtils(org.apache.commons.io.FileUtils) GenConstants(com.ruoyi.common.core.constant.GenConstants) GenTableColumn(com.ruoyi.gen.domain.GenTableColumn) StringUtils(com.ruoyi.common.core.utils.StringUtils) 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) JSONObject(com.alibaba.fastjson.JSONObject) Velocity(org.apache.velocity.app.Velocity) SecurityUtils(com.ruoyi.common.security.utils.SecurityUtils) Transactional(org.springframework.transaction.annotation.Transactional) ServiceException(com.ruoyi.common.core.exception.ServiceException) GenTable(com.ruoyi.gen.domain.GenTable) GenTableColumn(com.ruoyi.gen.domain.GenTableColumn) Transactional(org.springframework.transaction.annotation.Transactional)

Example 9 with GenTable

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

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.gen.domain.GenTable)

Example 10 with GenTable

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

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 (StringUtils.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.gen.domain.GenTable) GenTableColumn(com.ruoyi.gen.domain.GenTableColumn) HashSet(java.util.HashSet)

Aggregations

GenTable (com.ruoyi.gen.domain.GenTable)27 GenTableColumn (com.ruoyi.gen.domain.GenTableColumn)12 IOException (java.io.IOException)12 StringWriter (java.io.StringWriter)12 Template (org.apache.velocity.Template)12 VelocityContext (org.apache.velocity.VelocityContext)12 ServiceException (com.ruoyi.common.core.exception.ServiceException)9 ZipEntry (java.util.zip.ZipEntry)6 File (java.io.File)5 Snowflake (cn.hutool.core.lang.Snowflake)4 LinkedHashMap (java.util.LinkedHashMap)4 Transactional (org.springframework.transaction.annotation.Transactional)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