Search in sources :

Example 1 with TableDo

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

the class TableServiceImpl method findTableListFormDb.

@Override
public List<TableDto> findTableListFormDb(TableDto tableDto) {
    ArgumentAssert.notNull(tableDto, "无效参数");
    List<TableDo> tableDoEntities = list();
    TableQuery tableQuery = new TableQuery();
    if (StringUtil.isNotEmpty(tableDto.getName())) {
        tableQuery.setName(tableDto.getName());
    } else {
        List<String> tempNames = Lists.newArrayList("gen_");
        tableQuery.setNotLikeNames(tempNames);
        if (ObjectUtil.isNotEmpty(tableDoEntities)) {
            tableQuery.setNotNames(CollUtil.extractToList(tableDoEntities, TableDo.F_NAME));
        }
    }
    List<TableDo> list = repository.findTableList(tableQuery, tableDto.getDsName());
    return list.stream().map(item -> copyBeanToDto(item)).collect(Collectors.toList());
}
Also used : TableDo(com.albedo.java.modules.gen.domain.TableDo) ObjectUtil(com.albedo.java.common.core.util.ObjectUtil) DictDo(com.albedo.java.modules.sys.domain.DictDo) ArgumentAssert(com.albedo.java.common.core.util.ArgumentAssert) CollUtil(com.albedo.java.common.core.util.CollUtil) TableService(com.albedo.java.modules.gen.service.TableService) DatasourceConfService(com.albedo.java.modules.gen.service.DatasourceConfService) TableColumnDto(com.albedo.java.modules.gen.domain.dto.TableColumnDto) GenUtil(com.albedo.java.modules.gen.util.GenUtil) TableColumnService(com.albedo.java.modules.gen.service.TableColumnService) Lists(com.google.common.collect.Lists) TableFormDataVo(com.albedo.java.modules.gen.domain.vo.TableFormDataVo) Service(org.springframework.stereotype.Service) GenConfig(com.albedo.java.modules.gen.domain.xml.GenConfig) TableColumnDo(com.albedo.java.modules.gen.domain.TableColumnDo) TableDo(com.albedo.java.modules.gen.domain.TableDo) TableRepository(com.albedo.java.modules.gen.repository.TableRepository) TableDto(com.albedo.java.modules.gen.domain.dto.TableDto) Wrappers(com.baomidou.mybatisplus.core.toolkit.Wrappers) DatasourceConfDo(com.albedo.java.modules.gen.domain.DatasourceConfDo) Resource(javax.annotation.Resource) Set(java.util.Set) TableCacheKeyBuilder(com.albedo.java.modules.gen.cache.TableCacheKeyBuilder) CacheKeyBuilder(com.albedo.java.common.core.cache.model.CacheKeyBuilder) StringUtil(com.albedo.java.common.core.util.StringUtil) Collectors(java.util.stream.Collectors) TableFromDto(com.albedo.java.modules.gen.domain.dto.TableFromDto) List(java.util.List) AbstractDataCacheServiceImpl(com.albedo.java.plugins.database.mybatis.service.impl.AbstractDataCacheServiceImpl) TableQuery(com.albedo.java.modules.gen.domain.vo.TableQuery) Collections(java.util.Collections) Transactional(org.springframework.transaction.annotation.Transactional) Assert(org.springframework.util.Assert) TableQuery(com.albedo.java.modules.gen.domain.vo.TableQuery)

Example 2 with TableDo

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

the class SchemeServiceImpl method generateCode.

@Override
public String generateCode(SchemeDto schemeDto) {
    StringBuilder result = new StringBuilder();
    // 查询主表及字段列
    TableDto tableDto = tableService.getOneDto(schemeDto.getTableId());
    tableDto.setColumnList(tableColumnService.list(Wrappers.<TableColumnDo>query().eq(TableColumnDo.F_SQL_GENTABLEID, tableDto.getId())).stream().map(item -> tableColumnService.copyBeanToDto(item)).collect(Collectors.toList()));
    Collections.sort(tableDto.getColumnList());
    // 获取所有代码模板
    GenConfig config = GenUtil.getConfig();
    // 获取模板列表
    List<TemplateVo> templateList = GenUtil.getTemplateList(config, schemeDto.getCategory(), false);
    List<TemplateVo> childTableTemplateList = GenUtil.getTemplateList(config, schemeDto.getCategory(), true);
    // 如果有子表模板,则需要获取子表列表
    if (childTableTemplateList.size() > 0) {
        tableDto.setChildList(tableRepository.selectList(Wrappers.<TableDo>lambdaQuery().eq(TableDo::getParentTable, tableDto.getId())).stream().map(item -> tableService.copyBeanToDto(item)).collect(Collectors.toList()));
    }
    // 生成子表模板代码
    if (tableDto.getChildList() == null) {
        tableDto.setChildList(Lists.newArrayList());
    }
    for (TableDto childTable : tableDto.getChildList()) {
        Collections.sort(childTable.getColumnList());
        childTable.setCategory(schemeDto.getCategory());
        schemeDto.setTableDto(childTable);
        Map<String, Object> childTableModel = GenUtil.getDataModel(schemeDto);
        for (TemplateVo tpl : childTableTemplateList) {
            result.append(GenUtil.generateToFile(tpl, childTableModel, schemeDto.getReplaceFile()));
        }
    }
    tableDto.setCategory(schemeDto.getCategory());
    // 生成主表模板代码
    schemeDto.setTableDto(tableDto);
    Map<String, Object> model = GenUtil.getDataModel(schemeDto);
    for (TemplateVo tpl : templateList) {
        result.append(GenUtil.generateToFile(tpl, model, schemeDto.getReplaceFile()));
    }
    return result.toString();
}
Also used : TableDo(com.albedo.java.modules.gen.domain.TableDo) GenConfig(com.albedo.java.modules.gen.domain.xml.GenConfig) TableColumnDo(com.albedo.java.modules.gen.domain.TableColumnDo) TemplateVo(com.albedo.java.modules.gen.domain.vo.TemplateVo) TableDto(com.albedo.java.modules.gen.domain.dto.TableDto)

Example 3 with TableDo

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

the class SchemeServiceImpl method previewCode.

@Override
public Map<String, Object> previewCode(String id, String username) {
    Map<String, Object> result = Maps.newHashMap();
    SchemeDto schemeDto = super.getOneDto(id);
    // 查询主表及字段列
    TableDto tableDto = tableService.getOneDto(schemeDto.getTableId());
    ArgumentAssert.notNull(tableDto, "无法找到业务表ID为" + id + "的数据");
    tableDto.setColumnList(Optional.ofNullable(tableColumnService.list(Wrappers.<TableColumnDo>query().eq(TableColumnDo.F_SQL_GENTABLEID, tableDto.getId()))).orElseThrow(() -> new BizException("业务列信息不存在")).stream().map(item -> tableColumnService.copyBeanToDto(item)).collect(Collectors.toList()));
    Collections.sort(tableDto.getColumnList());
    // 获取所有代码模板
    GenConfig config = GenUtil.getConfig();
    // 获取模板列表
    List<TemplateVo> templateList = GenUtil.getTemplateList(config, schemeDto.getCategory(), false);
    List<TemplateVo> childTableTemplateList = GenUtil.getTemplateList(config, schemeDto.getCategory(), true);
    // 如果有子表模板,则需要获取子表列表
    if (childTableTemplateList.size() > 0) {
        tableDto.setChildList(Optional.ofNullable(tableRepository.selectList(Wrappers.<TableDo>lambdaQuery().eq(TableDo::getParentTable, tableDto.getId()))).orElseThrow(() -> new BizException("业务表不存在")).stream().map(item -> tableService.copyBeanToDto(item)).collect(Collectors.toList()));
    }
    // 生成子表模板代码
    if (tableDto.getChildList() == null) {
        tableDto.setChildList(Lists.newArrayList());
    }
    for (TableDto childTable : tableDto.getChildList()) {
        Collections.sort(childTable.getColumnList());
        childTable.setCategory(schemeDto.getCategory());
        schemeDto.setTableDto(childTable);
        Map<String, Object> childTableModel = GenUtil.getDataModel(schemeDto);
        for (TemplateVo tpl : childTableTemplateList) {
            String content = FreeMarkers.renderString(StringUtil.trimToEmpty(tpl.getContent()), childTableModel);
            result.put(FreeMarkers.renderString(tpl.getFileName(), childTableModel), content);
        }
    }
    tableDto.setCategory(schemeDto.getCategory());
    // 生成主表模板代码
    schemeDto.setTableDto(tableDto);
    Map<String, Object> model = GenUtil.getDataModel(schemeDto);
    for (TemplateVo tpl : templateList) {
        String content = FreeMarkers.renderString(StringUtil.trimToEmpty(tpl.getContent()), model);
        result.put(FreeMarkers.renderString(tpl.getFileName(), model), content);
    }
    return result;
}
Also used : TableDo(com.albedo.java.modules.gen.domain.TableDo) GenConfig(com.albedo.java.modules.gen.domain.xml.GenConfig) BizException(com.albedo.java.common.core.exception.BizException) TableColumnDo(com.albedo.java.modules.gen.domain.TableColumnDo) TemplateVo(com.albedo.java.modules.gen.domain.vo.TemplateVo) TableDto(com.albedo.java.modules.gen.domain.dto.TableDto) SchemeDto(com.albedo.java.modules.gen.domain.dto.SchemeDto)

Example 4 with TableDo

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

the class TableServiceImpl method refreshColumn.

@Override
public void refreshColumn(TableDto tableDto) {
    Assert.isTrue(tableDto != null, "tableDto为空,操作失败");
    Assert.isTrue(CollUtil.isNotEmpty(tableDto.getColumnList()), "对象 " + tableDto.getName() + " 列信息为空,操作失败");
    tableColumnService.deleteByTableId(tableDto.getId());
    TableDo tableDo = new TableDo();
    copyDtoToBean(tableDto, tableDo);
    for (TableColumnDo item : tableDo.getColumnList()) {
        item.setTableId(tableDo.getId());
    }
    tableColumnService.saveOrUpdateBatch(tableDo.getColumnList());
}
Also used : TableDo(com.albedo.java.modules.gen.domain.TableDo) TableColumnDo(com.albedo.java.modules.gen.domain.TableColumnDo)

Example 5 with TableDo

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

the class TableServiceImpl method delete.

@Override
public void delete(Set<String> ids) {
    ids.forEach(id -> {
        TableDo entity = repository.selectById(id);
        Assert.notNull(entity, "对象 " + id + " 信息为空,删除失败");
        removeById(id);
        tableColumnService.deleteByTableId(id);
        logger.debug("Deleted TableDto: {}", entity);
    });
}
Also used : TableDo(com.albedo.java.modules.gen.domain.TableDo)

Aggregations

TableDo (com.albedo.java.modules.gen.domain.TableDo)7 TableColumnDo (com.albedo.java.modules.gen.domain.TableColumnDo)5 GenConfig (com.albedo.java.modules.gen.domain.xml.GenConfig)4 TableDto (com.albedo.java.modules.gen.domain.dto.TableDto)3 TemplateVo (com.albedo.java.modules.gen.domain.vo.TemplateVo)2 Transactional (org.springframework.transaction.annotation.Transactional)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 SchemeDo (com.albedo.java.modules.gen.domain.SchemeDo)1 SchemeDto (com.albedo.java.modules.gen.domain.dto.SchemeDto)1 TableColumnDto (com.albedo.java.modules.gen.domain.dto.TableColumnDto)1 TableFromDto (com.albedo.java.modules.gen.domain.dto.TableFromDto)1 SchemeFormDataVo (com.albedo.java.modules.gen.domain.vo.SchemeFormDataVo)1 TableFormDataVo (com.albedo.java.modules.gen.domain.vo.TableFormDataVo)1