Search in sources :

Example 1 with GenTable

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

the class GenController method getInfo.

/**
 * 修改代码生成业务
 */
@PreAuthorize("@ss.hasPermi('tool:gen:query')")
@GetMapping(value = "/{talbleId}")
public AjaxResult getInfo(@PathVariable Long talbleId) {
    GenTable table = genTableService.selectGenTableById(talbleId);
    List<GenTable> tables = genTableService.selectGenTableAll();
    List<GenTableColumn> list = genTableColumnService.selectGenTableColumnListByTableId(talbleId);
    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.project.tool.gen.domain.GenTable) HashMap(java.util.HashMap) GenTableColumn(com.ruoyi.project.tool.gen.domain.GenTableColumn) GetMapping(org.springframework.web.bind.annotation.GetMapping) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 2 with GenTable

use of com.ruoyi.project.tool.gen.domain.GenTable 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 3 with GenTable

use of com.ruoyi.project.tool.gen.domain.GenTable in project RuoYi-Vue-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.project.tool.gen.domain.GenTable)

Example 4 with GenTable

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

the class GenTableServiceImpl method previewCode.

/**
 * 预览代码
 *
 * @param tableId 表编号
 * @return 预览数据列表
 */
@Override
public Map<String, String> previewCode(Long tableId) {
    Map<String, String> dataMap = new LinkedHashMap<>();
    // 查询表信息
    GenTable table = genTableMapper.selectGenTableById(tableId);
    // 设置主子表信息
    setSubTable(table);
    // 设置主键列信息
    setPkColumn(table);
    VelocityInitializer.initVelocity();
    VelocityContext context = VelocityUtils.prepareContext(table);
    // 获取模板列表
    List<String> templates = VelocityUtils.getTemplateList(table.getTplCategory());
    for (String template : templates) {
        // 渲染模板
        StringWriter sw = new StringWriter();
        Template tpl = Velocity.getTemplate(template, Constants.UTF8);
        tpl.merge(context, sw);
        dataMap.put(template, sw.toString());
    }
    return dataMap;
}
Also used : StringWriter(java.io.StringWriter) GenTable(com.ruoyi.project.tool.gen.domain.GenTable) VelocityContext(org.apache.velocity.VelocityContext) LinkedHashMap(java.util.LinkedHashMap) Template(org.apache.velocity.Template)

Example 5 with GenTable

use of com.ruoyi.project.tool.gen.domain.GenTable in project RuoYi-Vue-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.project.tool.gen.domain.GenTable)

Aggregations

GenTable (com.ruoyi.project.tool.gen.domain.GenTable)18 GenTableColumn (com.ruoyi.project.tool.gen.domain.GenTableColumn)8 IOException (java.io.IOException)8 StringWriter (java.io.StringWriter)8 Template (org.apache.velocity.Template)8 VelocityContext (org.apache.velocity.VelocityContext)8 ServiceException (com.ruoyi.common.exception.ServiceException)6 File (java.io.File)4 LinkedHashMap (java.util.LinkedHashMap)4 ZipEntry (java.util.zip.ZipEntry)4 Transactional (org.springframework.transaction.annotation.Transactional)4 JSON (com.alibaba.fastjson.JSON)2 JSONObject (com.alibaba.fastjson.JSONObject)2 Constants (com.ruoyi.common.constant.Constants)2 GenConstants (com.ruoyi.common.constant.GenConstants)2 CharsetKit (com.ruoyi.common.core.text.CharsetKit)2 SecurityUtils (com.ruoyi.common.utils.SecurityUtils)2 StringUtils (com.ruoyi.common.utils.StringUtils)2 GenTableColumnMapper (com.ruoyi.project.tool.gen.mapper.GenTableColumnMapper)2 GenTableMapper (com.ruoyi.project.tool.gen.mapper.GenTableMapper)2