Search in sources :

Example 1 with GenTableColumn

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

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

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

the class VelocityUtils method getExpandColumn.

/**
 * 获取需要在哪一列上面显示展开按钮
 *
 * @param genTable 业务表对象
 * @return 展开按钮列序号
 */
public static int getExpandColumn(GenTable genTable) {
    String options = genTable.getOptions();
    JSONObject paramsObj = JSONObject.parseObject(options);
    String treeName = paramsObj.getString(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 : JSONObject(com.alibaba.fastjson.JSONObject) GenTableColumn(com.ruoyi.project.tool.gen.domain.GenTableColumn)

Example 4 with GenTableColumn

use of com.ruoyi.project.tool.gen.domain.GenTableColumn in project RuoYi-Vue-fast 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 5 with GenTableColumn

use of com.ruoyi.project.tool.gen.domain.GenTableColumn in project RuoYi-Vue-fast by yangzongzhuan.

the class GenTableServiceImpl method updateGenTable.

/**
 * 修改业务
 *
 * @param genTable 业务信息
 * @return 结果
 */
@Override
@Transactional
public void updateGenTable(GenTable genTable) {
    String options = JSON.toJSONString(genTable.getParams());
    genTable.setOptions(options);
    int row = genTableMapper.updateGenTable(genTable);
    if (row > 0) {
        for (GenTableColumn cenTableColumn : genTable.getColumns()) {
            genTableColumnMapper.updateGenTableColumn(cenTableColumn);
        }
    }
}
Also used : GenTableColumn(com.ruoyi.project.tool.gen.domain.GenTableColumn) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

GenTableColumn (com.ruoyi.project.tool.gen.domain.GenTableColumn)14 GenTable (com.ruoyi.project.tool.gen.domain.GenTable)8 Transactional (org.springframework.transaction.annotation.Transactional)6 JSONObject (com.alibaba.fastjson.JSONObject)4 ServiceException (com.ruoyi.common.exception.ServiceException)4 IOException (java.io.IOException)4 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)4 GetMapping (org.springframework.web.bind.annotation.GetMapping)4 JSON (com.alibaba.fastjson.JSON)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 TableDataInfo (com.ruoyi.framework.web.page.TableDataInfo)2 GenTableColumnMapper (com.ruoyi.project.tool.gen.mapper.GenTableColumnMapper)2 GenTableMapper (com.ruoyi.project.tool.gen.mapper.GenTableMapper)2 GenUtils (com.ruoyi.project.tool.gen.util.GenUtils)2 VelocityInitializer (com.ruoyi.project.tool.gen.util.VelocityInitializer)2 VelocityUtils (com.ruoyi.project.tool.gen.util.VelocityUtils)2