Search in sources :

Example 6 with GenTableColumn

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

the class GenTableServiceImpl method updateGenTable.

/**
 * 修改业务
 *
 * @param genTable 业务信息
 * @return 结果
 */
@Override
@Transactional(rollbackFor = Exception.class)
public void updateGenTable(GenTable genTable) {
    String options = JsonUtils.toJsonString(genTable.getParams());
    genTable.setOptions(options);
    int row = baseMapper.updateById(genTable);
    if (row > 0) {
        for (GenTableColumn cenTableColumn : genTable.getColumns()) {
            genTableColumnMapper.updateById(cenTableColumn);
        }
    }
}
Also used : GenTableColumn(com.ruoyi.generator.domain.GenTableColumn) Transactional(org.springframework.transaction.annotation.Transactional)

Example 7 with GenTableColumn

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

the class GenTableServiceImpl method synchDb.

/**
 * 同步数据库
 *
 * @param tableName 表名称
 */
@Override
@Transactional(rollbackFor = Exception.class)
public void synchDb(String tableName) {
    GenTable table = baseMapper.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 (CollUtil.isEmpty(dbTableColumns)) {
        throw new ServiceException("同步数据失败,原表结构不存在");
    }
    List<String> dbTableColumnNames = dbTableColumns.stream().map(GenTableColumn::getColumnName).collect(Collectors.toList());
    List<GenTableColumn> saveColumns = new ArrayList<>();
    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.updateById(column);
        } else {
            genTableColumnMapper.insert(column);
        }
    });
    if (CollUtil.isNotEmpty(saveColumns)) {
        genTableColumnMapper.insertBatch(saveColumns);
    }
    List<GenTableColumn> delColumns = tableColumns.stream().filter(column -> !dbTableColumnNames.contains(column.getColumnName())).collect(Collectors.toList());
    if (CollUtil.isNotEmpty(delColumns)) {
        List<Long> ids = delColumns.stream().map(GenTableColumn::getColumnId).collect(Collectors.toList());
        genTableColumnMapper.deleteBatchIds(ids);
    }
}
Also used : ZipOutputStream(java.util.zip.ZipOutputStream) JsonUtils(com.ruoyi.common.utils.JsonUtils) java.util(java.util) TableDataInfo(com.ruoyi.common.core.page.TableDataInfo) GenTableColumn(com.ruoyi.generator.domain.GenTableColumn) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ObjectUtil(cn.hutool.core.util.ObjectUtil) VelocityUtils(com.ruoyi.generator.util.VelocityUtils) ServiceException(com.ruoyi.common.exception.ServiceException) RequiredArgsConstructor(lombok.RequiredArgsConstructor) LambdaQueryWrapper(com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper) Function(java.util.function.Function) PageQuery(com.ruoyi.common.core.domain.PageQuery) Template(org.apache.velocity.Template) StringUtils(com.ruoyi.common.utils.StringUtils) Service(org.springframework.stereotype.Service) ZipEntry(java.util.zip.ZipEntry) FileUtils(com.ruoyi.common.utils.file.FileUtils) IoUtil(cn.hutool.core.io.IoUtil) GenConstants(com.ruoyi.common.constant.GenConstants) StringWriter(java.io.StringWriter) Dict(cn.hutool.core.lang.Dict) IOException(java.io.IOException) GenUtils(com.ruoyi.generator.util.GenUtils) LoginHelper(com.ruoyi.common.helper.LoginHelper) GenTableMapper(com.ruoyi.generator.mapper.GenTableMapper) VelocityContext(org.apache.velocity.VelocityContext) Collectors(java.util.stream.Collectors) File(java.io.File) StandardCharsets(java.nio.charset.StandardCharsets) VelocityInitializer(com.ruoyi.generator.util.VelocityInitializer) Page(com.baomidou.mybatisplus.extension.plugins.pagination.Page) CollUtil(cn.hutool.core.collection.CollUtil) Slf4j(lombok.extern.slf4j.Slf4j) GenTable(com.ruoyi.generator.domain.GenTable) GenTableColumnMapper(com.ruoyi.generator.mapper.GenTableColumnMapper) Velocity(org.apache.velocity.app.Velocity) Constants(com.ruoyi.common.constant.Constants) Transactional(org.springframework.transaction.annotation.Transactional) ServiceException(com.ruoyi.common.exception.ServiceException) GenTable(com.ruoyi.generator.domain.GenTable) GenTableColumn(com.ruoyi.generator.domain.GenTableColumn) Transactional(org.springframework.transaction.annotation.Transactional)

Example 8 with GenTableColumn

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

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)

Example 9 with GenTableColumn

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

the class VelocityUtils method getExpandColumn.

/**
 * 获取需要在哪一列上面显示展开按钮
 *
 * @param genTable 业务表对象
 * @return 展开按钮列序号
 */
public static int getExpandColumn(GenTable genTable) {
    String options = genTable.getOptions();
    Dict paramsObj = JsonUtils.parseMap(options);
    String treeName = paramsObj.getStr(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 : Dict(cn.hutool.core.lang.Dict) GenTableColumn(com.ruoyi.generator.domain.GenTableColumn)

Example 10 with GenTableColumn

use of com.ruoyi.generator.domain.GenTableColumn in project wumei-smart by kerwincui.

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)

Aggregations

GenTableColumn (com.ruoyi.generator.domain.GenTableColumn)34 GenTable (com.ruoyi.generator.domain.GenTable)20 Transactional (org.springframework.transaction.annotation.Transactional)12 IOException (java.io.IOException)10 ServiceException (com.ruoyi.common.exception.ServiceException)8 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)6 GetMapping (org.springframework.web.bind.annotation.GetMapping)6 Constants (com.ruoyi.common.constant.Constants)5 GenConstants (com.ruoyi.common.constant.GenConstants)5 TableDataInfo (com.ruoyi.common.core.page.TableDataInfo)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 File (java.io.File)5 StringWriter (java.io.StringWriter)5 HashMap (java.util.HashMap)5