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("操作成功");
}
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());
}
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/>";
}
}
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();
}
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;
}
Aggregations