use of com.albedo.java.modules.gen.domain.TableColumnDo 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.TableColumnDo 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.TableColumnDo 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.TableColumnDo 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;
}
use of com.albedo.java.modules.gen.domain.TableColumnDo in project albedo by somowhere.
the class TableServiceImpl method saveOrUpdate.
@Override
public void saveOrUpdate(TableDto tableDto) {
TableDo tableDo = new TableDo();
copyDtoToBean(tableDto, tableDo);
super.saveOrUpdate(tableDo);
logger.debug("Save Information for Table: {}", tableDo);
for (TableColumnDo item : tableDo.getColumnFormList()) {
item.setTableId(tableDo.getId());
}
List<TableColumnDo> tableColumnDoEntities = tableColumnService.list(Wrappers.<TableColumnDo>query().eq(TableColumnDo.F_SQL_GENTABLEID, tableDo.getId()));
for (TableColumnDo item : tableDo.getColumnFormList()) {
for (TableColumnDo tableColumnDo : tableColumnDoEntities) {
if (tableColumnDo.getId().equals(item.getId())) {
item.setVersion(tableColumnDo.getVersion());
break;
}
}
}
tableColumnService.saveOrUpdateBatch(tableDo.getColumnFormList());
}
Aggregations