Search in sources :

Example 6 with TableDto

use of com.albedo.java.modules.gen.domain.dto.TableDto in project albedo by somowhere.

the class TableServiceImpl method getTableFormDb.

@Override
public TableDto getTableFormDb(TableDto tableDto) {
    // 如果有表名,则获取物理表
    if (StringUtil.isNotBlank(tableDto.getName())) {
        List<TableDto> list = findTableListFormDb(tableDto);
        if (list.size() > 0 && CollUtil.isEmpty(tableDto.getColumnList())) {
            // 如果是新增,初始化表属性
            if (ObjectUtil.isEmpty(tableDto.getId())) {
                list.get(0).setDsName(tableDto.getDsName());
                tableDto = list.get(0);
                // 设置字段说明
                if (StringUtil.isBlank(tableDto.getComments())) {
                    tableDto.setComments(tableDto.getName());
                }
                tableDto.setClassName(StringUtil.toCapitalizeCamelCase(tableDto.getName()));
            }
            // 添加新列
            List<TableColumnDto> columnList = findTableColumnList(tableDto);
            for (TableColumnDto column : columnList) {
                boolean b = false;
                for (TableColumnDto e : tableDto.getColumnList()) {
                    if (e.getName().equals(column.getName())) {
                        b = true;
                        break;
                    }
                }
                if (!b) {
                    tableDto.getColumnList().add(column);
                }
            }
            // 删除已删除的列
            for (TableColumnDto e : tableDto.getColumnList()) {
                boolean b = false;
                for (TableColumnDto column : columnList) {
                    if (column.getName().equals(e.getName())) {
                        b = true;
                    }
                }
                if (!b) {
                    e.setDelFlag(TableColumnDto.FLAG_DELETE);
                }
            }
            // 获取主键
            tableDto.setPkList(findTablePk(tableDto));
            // 初始化列属性字段
            GenUtil.initColumnField(tableDto);
        }
    }
    return tableDto;
}
Also used : TableColumnDto(com.albedo.java.modules.gen.domain.dto.TableColumnDto) TableDto(com.albedo.java.modules.gen.domain.dto.TableDto)

Example 7 with TableDto

use of com.albedo.java.modules.gen.domain.dto.TableDto in project albedo by somowhere.

the class TableServiceImpl method findFormData.

@Override
public TableFormDataVo findFormData(TableFromDto tableFromDto) {
    // 验证参数缺失
    ArgumentAssert.isTrue(tableFromDto == null || StringUtil.isNotEmpty(tableFromDto.getId()) || StringUtil.isNotEmpty(tableFromDto.getTableName()) || StringUtil.isNotEmpty(tableFromDto.getDsName()), "参数缺失!");
    TableFormDataVo tableFormDataVo = new TableFormDataVo();
    TableDto tableDto = new TableDto(tableFromDto);
    tableFormDataVo.setTableList(CollUtil.convertSelectVoList(findTableListFormDb(tableDto), TableDo.F_NAME, TableDo.F_NAMESANDTITLE));
    // 验证表是否存在
    ArgumentAssert.isTrue(StringUtil.isNotEmpty(tableFromDto.getId()) || checkTableName(tableFromDto.getTableName()), StringUtil.toAppendStr("下一步失败!", tableFromDto.getTableName(), " 表已经添加!"));
    if (ObjectUtil.isNotEmpty(tableFromDto.getId())) {
        tableDto = getOneDto(tableFromDto.getId());
        tableDto.setColumnList(tableColumnService.list(Wrappers.<TableColumnDo>query().eq(TableColumnDo.F_SQL_GENTABLEID, tableFromDto.getId())).stream().map(item -> tableColumnService.copyBeanToDto(item)).collect(Collectors.toList()));
    }
    // 获取物理表字段
    tableDto = getTableFormDb(tableDto);
    tableFormDataVo.setColumnList(CollUtil.convertSelectVoList(tableDto.getColumnList(), TableDo.F_NAME, TableDo.F_NAMESANDTITLE));
    tableFormDataVo.setTableVo(tableDto);
    GenConfig config = GenUtil.getConfig();
    tableFormDataVo.setConfig(config);
    tableFormDataVo.setDsNameList(CollUtil.convertSelectVoList(datasourceConfService.list(), DatasourceConfDo.F_NAME, DatasourceConfDo.F_NAME));
    tableFormDataVo.setQueryTypeList(CollUtil.convertSelectVoList(config.getQueryTypeList(), DictDo.F_VAL, DictDo.F_NAME));
    tableFormDataVo.setQueryTypeList(CollUtil.convertSelectVoList(config.getQueryTypeList(), DictDo.F_VAL, DictDo.F_NAME));
    tableFormDataVo.setShowTypeList(CollUtil.convertSelectVoList(config.getShowTypeList(), DictDo.F_VAL, DictDo.F_NAME));
    tableFormDataVo.setJavaTypeList(CollUtil.convertSelectVoList(config.getJavaTypeList(), DictDo.F_VAL, DictDo.F_NAME));
    if (ObjectUtil.isNotEmpty(tableDto.getId())) {
        Collections.sort(tableDto.getColumnList());
    }
    return tableFormDataVo;
}
Also used : GenConfig(com.albedo.java.modules.gen.domain.xml.GenConfig) TableFormDataVo(com.albedo.java.modules.gen.domain.vo.TableFormDataVo) TableColumnDo(com.albedo.java.modules.gen.domain.TableColumnDo) TableDto(com.albedo.java.modules.gen.domain.dto.TableDto)

Example 8 with TableDto

use of com.albedo.java.modules.gen.domain.dto.TableDto in project albedo by somowhere.

the class TableResource method tableList.

@GetMapping(value = "/ds-table-list/{dsName:^[a-zA-Z0-9]+$}")
@PreAuthorize("@pms.hasPermission('gen_table_view')")
public Result<SelectVo> tableList(@PathVariable String dsName) {
    TableDto tableDto = new TableDto();
    tableDto.setDsName(dsName);
    return Result.buildOkData(CollUtil.convertSelectVoList(tableService.findTableListFormDb(tableDto), TableDo.F_NAME, TableDo.F_NAMESANDTITLE));
}
Also used : TableDto(com.albedo.java.modules.gen.domain.dto.TableDto) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Aggregations

TableDto (com.albedo.java.modules.gen.domain.dto.TableDto)8 TableColumnDo (com.albedo.java.modules.gen.domain.TableColumnDo)4 GenConfig (com.albedo.java.modules.gen.domain.xml.GenConfig)4 TableDo (com.albedo.java.modules.gen.domain.TableDo)3 TableColumnDto (com.albedo.java.modules.gen.domain.dto.TableColumnDto)2 TableFormDataVo (com.albedo.java.modules.gen.domain.vo.TableFormDataVo)2 TemplateVo (com.albedo.java.modules.gen.domain.vo.TemplateVo)2 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)2 CacheKeyBuilder (com.albedo.java.common.core.cache.model.CacheKeyBuilder)1 BizException (com.albedo.java.common.core.exception.BizException)1 ArgumentAssert (com.albedo.java.common.core.util.ArgumentAssert)1 CollUtil (com.albedo.java.common.core.util.CollUtil)1 ObjectUtil (com.albedo.java.common.core.util.ObjectUtil)1 StringUtil (com.albedo.java.common.core.util.StringUtil)1 TableCacheKeyBuilder (com.albedo.java.modules.gen.cache.TableCacheKeyBuilder)1 DatasourceConfDo (com.albedo.java.modules.gen.domain.DatasourceConfDo)1 SchemeDto (com.albedo.java.modules.gen.domain.dto.SchemeDto)1 TableFromDto (com.albedo.java.modules.gen.domain.dto.TableFromDto)1 TableQuery (com.albedo.java.modules.gen.domain.vo.TableQuery)1 TableRepository (com.albedo.java.modules.gen.repository.TableRepository)1