Search in sources :

Example 1 with TableDto

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

the class TableResource method refreshColumn.

/**
 * @param id
 * @return
 */
@PutMapping("refresh-column" + CommonConstants.URL_ID_REGEX)
@PreAuthorize("@pms.hasPermission('gen_table_edit')")
public Result refreshColumn(@PathVariable String id) {
    log.debug("REST request to refreshColumn Entity : {}", id);
    TableDto tableDto = tableService.getOneDto(id);
    ArgumentAssert.notNull(tableDto, "对象 " + id + " 信息为空,操作失败");
    tableService.getTableFormDb(tableDto);
    tableService.refreshColumn(tableDto);
    return Result.buildOk("操作成功");
}
Also used : TableDto(com.albedo.java.modules.gen.domain.dto.TableDto) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 2 with TableDto

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

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

the class GenUtil method generateToFile.

/**
 * 生成到文件
 *
 * @param tpl
 * @param model
 * @param isReplaceFile
 * @return
 */
public static String generateToFile(TemplateVo tpl, Map<String, Object> model, boolean isReplaceFile) {
    // 获取生成文件 "c:\\temp\\"//
    String realFileName = FreeMarkers.renderString(tpl.getFileName(), model), fileName = StringUtil.getProjectPath(realFileName, getConfig().getCodeUiPath()) + File.separator + FreeMarkers.renderString(tpl.getFilePath() + StringUtil.SLASH, model).replaceAll("//|/|\\.", "\\" + File.separator) + realFileName;
    logger.debug(" fileName === " + fileName);
    boolean entityId = "entityId".equals(tpl.getName());
    if (entityId) {
        TableDto table = (TableDto) model.get("table");
        if (table.isNotCompositeId()) {
            return "因不满足联合主键条件已忽略" + fileName + "<br/>";
        }
    }
    // 获取生成文件内容
    String content = FreeMarkers.renderString(StringUtil.trimToEmpty(tpl.getContent()), model);
    logger.debug(" content === \r\n" + content);
    // 如果选择替换文件,则删除原文件
    if (isReplaceFile) {
        FileUtil.deleteFile(fileName);
    }
    // 创建并写入文件
    if (FileUtil.createFile(fileName)) {
        FileUtil.writeString(content, fileName, CharsetUtil.UTF_8);
        logger.debug(" file create === " + fileName);
        return "生成成功:" + fileName + "<br/>";
    } else {
        logger.debug(" file extents === " + fileName);
        return "文件已存在:" + fileName + "<br/>";
    }
}
Also used : TableDto(com.albedo.java.modules.gen.domain.dto.TableDto)

Example 4 with TableDto

use of com.albedo.java.modules.gen.domain.dto.TableDto 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 5 with TableDto

use of com.albedo.java.modules.gen.domain.dto.TableDto 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)

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