Search in sources :

Example 21 with GenTable

use of com.ruoyi.generator.domain.GenTable in project hocassian-media-matrix by hokaso.

the class GenTableServiceImpl method generatorCode.

/**
 * 生成代码(自定义路径)
 *
 * @param tableName 表名称
 */
@Override
public void generatorCode(String tableName) {
    // 查询表信息
    GenTable table = genTableMapper.selectGenTableByName(tableName);
    // 设置主子表信息
    setSubTable(table);
    // 设置主键列信息
    setPkColumn(table);
    VelocityInitializer.initVelocity();
    VelocityContext context = VelocityUtils.prepareContext(table);
    // 获取模板列表
    List<String> templates = VelocityUtils.getTemplateList(table.getTplCategory());
    for (String template : templates) {
        if (!StringUtils.containsAny(template, "sql.vm", "api.js.vm", "index.vue.vm", "index-tree.vue.vm")) {
            // 渲染模板
            StringWriter sw = new StringWriter();
            Template tpl = Velocity.getTemplate(template, Constants.UTF8);
            tpl.merge(context, sw);
            try {
                String path = getGenPath(table, template);
                FileUtils.writeStringToFile(new File(path), sw.toString(), CharsetKit.UTF_8);
            } catch (IOException e) {
                throw new CustomException("渲染模板失败,表名:" + table.getTableName());
            }
        }
    }
}
Also used : StringWriter(java.io.StringWriter) GenTable(com.ruoyi.generator.domain.GenTable) VelocityContext(org.apache.velocity.VelocityContext) IOException(java.io.IOException) CustomException(com.ruoyi.common.exception.CustomException) File(java.io.File) Template(org.apache.velocity.Template)

Example 22 with GenTable

use of com.ruoyi.generator.domain.GenTable in project hocassian-media-matrix by hokaso.

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.generator.domain.GenTable) VelocityContext(org.apache.velocity.VelocityContext) LinkedHashMap(java.util.LinkedHashMap) Template(org.apache.velocity.Template)

Example 23 with GenTable

use of com.ruoyi.generator.domain.GenTable in project hocassian-media-matrix by hokaso.

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.generator.domain.GenTable) HashMap(java.util.HashMap) GenTableColumn(com.ruoyi.generator.domain.GenTableColumn) GetMapping(org.springframework.web.bind.annotation.GetMapping) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 24 with GenTable

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

the class GenController method getInfo.

/**
 * 修改代码生成业务
 */
@ApiOperation("修改代码生成业务")
@SaCheckPermission("tool:gen:query")
@GetMapping(value = "/{talbleId}")
public R<Map<String, Object>> 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 R.ok(map);
}
Also used : GenTable(com.ruoyi.generator.domain.GenTable) HashMap(java.util.HashMap) GenTableColumn(com.ruoyi.generator.domain.GenTableColumn) ApiOperation(io.swagger.annotations.ApiOperation) SaCheckPermission(cn.dev33.satoken.annotation.SaCheckPermission)

Example 25 with GenTable

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

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)

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