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());
}
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();
}
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;
}
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());
}
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);
});
}
Aggregations