Search in sources :

Example 1 with GenConfig

use of com.albedo.java.modules.gen.domain.xml.GenConfig 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 2 with GenConfig

use of com.albedo.java.modules.gen.domain.xml.GenConfig 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 3 with GenConfig

use of com.albedo.java.modules.gen.domain.xml.GenConfig 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 4 with GenConfig

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

the class SchemeServiceImpl method findFormData.

@Override
@Transactional(readOnly = true)
public SchemeFormDataVo findFormData(SchemeDto schemeDto, String loginId) {
    SchemeFormDataVo schemeFormDataVo = new SchemeFormDataVo();
    ArgumentAssert.notNull(schemeDto, "生成方案不能为空");
    if (StringUtil.isNotEmpty(schemeDto.getId())) {
        schemeDto = super.getOneDto(schemeDto.getId());
    }
    if (StringUtil.isBlank(schemeDto.getPackageName())) {
        schemeDto.setPackageName("com.albedo.java.modules");
    }
    if (StringUtil.isBlank(schemeDto.getFunctionAuthor())) {
        schemeDto.setFunctionAuthor(loginId);
    }
    schemeFormDataVo.setSchemeVo(schemeDto);
    GenConfig config = GenUtil.getConfig();
    schemeFormDataVo.setConfig(config);
    schemeFormDataVo.setCategoryList(CollUtil.convertSelectVoList(config.getCategoryList(), DictDo.F_VAL, DictDo.F_NAME));
    schemeFormDataVo.setViewTypeList(CollUtil.convertSelectVoList(config.getViewTypeList(), DictDo.F_VAL, DictDo.F_NAME));
    List<TableDo> tableDoList = tableService.list(), list = Lists.newArrayList();
    List<String> tableIds = Lists.newArrayList();
    if (StringUtil.isNotEmpty(schemeDto.getId())) {
        List<SchemeDo> schemeDoList = findAllListIdNot(schemeDto.getId());
        tableIds = CollUtil.extractToList(schemeDoList, "tableId");
    }
    for (TableDo tableDo : tableDoList) {
        if (!tableIds.contains(tableDo.getId())) {
            list.add(tableDo);
        }
    }
    schemeFormDataVo.setTableList(CollUtil.convertSelectVoList(list, TableDo.F_ID, TableDo.F_NAMESANDTITLE));
    return schemeFormDataVo;
}
Also used : TableDo(com.albedo.java.modules.gen.domain.TableDo) GenConfig(com.albedo.java.modules.gen.domain.xml.GenConfig) SchemeDo(com.albedo.java.modules.gen.domain.SchemeDo) SchemeFormDataVo(com.albedo.java.modules.gen.domain.vo.SchemeFormDataVo) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

GenConfig (com.albedo.java.modules.gen.domain.xml.GenConfig)4 TableColumnDo (com.albedo.java.modules.gen.domain.TableColumnDo)3 TableDo (com.albedo.java.modules.gen.domain.TableDo)3 TableDto (com.albedo.java.modules.gen.domain.dto.TableDto)3 TemplateVo (com.albedo.java.modules.gen.domain.vo.TemplateVo)2 BizException (com.albedo.java.common.core.exception.BizException)1 SchemeDo (com.albedo.java.modules.gen.domain.SchemeDo)1 SchemeDto (com.albedo.java.modules.gen.domain.dto.SchemeDto)1 SchemeFormDataVo (com.albedo.java.modules.gen.domain.vo.SchemeFormDataVo)1 TableFormDataVo (com.albedo.java.modules.gen.domain.vo.TableFormDataVo)1 Transactional (org.springframework.transaction.annotation.Transactional)1