Search in sources :

Example 1 with AgileGeneratorTableColumn

use of com.jeeagile.generator.entity.AgileGeneratorTableColumn in project jeeagile by jeeagile.

the class AgileGeneratorTableServiceImpl method importTable.

@Override
public boolean importTable(List<String> tableNameList) {
    for (String tableName : tableNameList) {
        AgileGeneratorTable agileGeneratorTable = this.getBaseMapper().selectDbTableByTableName(tableName);
        if (agileGeneratorTable == null || AgileStringUtil.isEmpty(agileGeneratorTable.getTableName())) {
            throw new AgileValidateException("表(" + tableName + ")不存在!");
        }
        AgileGeneratorUtil.initGeneratorTable(agileGeneratorTable);
        this.save(agileGeneratorTable);
        List<AgileGeneratorTableColumn> agileGeneratorTableColumnList = this.getBaseMapper().selectDbTableColumnByTableName(tableName);
        if (agileGeneratorTableColumnList != null && !agileGeneratorTableColumnList.isEmpty()) {
            agileGeneratorTableColumnList.forEach(agileGeneratorTableColumn -> AgileGeneratorUtil.initColumnField(agileGeneratorTable, agileGeneratorTableColumn));
        }
        agileGeneratorTableColumnService.saveBatch(agileGeneratorTableColumnList);
    }
    return true;
}
Also used : AgileGeneratorTable(com.jeeagile.generator.entity.AgileGeneratorTable) AgileValidateException(com.jeeagile.core.exception.AgileValidateException) AgileGeneratorTableColumn(com.jeeagile.generator.entity.AgileGeneratorTableColumn)

Example 2 with AgileGeneratorTableColumn

use of com.jeeagile.generator.entity.AgileGeneratorTableColumn in project jeeagile by jeeagile.

the class AgileGeneratorUtil method prepareVelocityContext.

/**
 * 设置模板变量信息
 *
 * @return 模板列表
 */
public static VelocityContext prepareVelocityContext(AgileGeneratorTableInfo agileGeneratorTableInfo) {
    String moduleName = agileGeneratorTableInfo.getModuleName();
    String businessName = agileGeneratorTableInfo.getBusinessName();
    String packageName = agileGeneratorTableInfo.getPackageName();
    String tableType = agileGeneratorTableInfo.getTableType();
    String functionName = agileGeneratorTableInfo.getFunctionName();
    AgileGeneratorTableColumn tablePkColumn = getTablePkColumn(agileGeneratorTableInfo.getAgileGeneratorTableColumnList());
    VelocityContext velocityContext = new VelocityContext();
    velocityContext.put("tableType", tableType);
    velocityContext.put("tableName", agileGeneratorTableInfo.getTableName());
    velocityContext.put("functionName", StringUtils.isNotEmpty(functionName) ? functionName : "【请填写功能名称】");
    velocityContext.put("ClassName", agileGeneratorTableInfo.getClassName());
    velocityContext.put("className", StringUtils.uncapitalize(agileGeneratorTableInfo.getClassName()));
    velocityContext.put("moduleName", agileGeneratorTableInfo.getModuleName());
    velocityContext.put("BusinessName", StringUtils.capitalize(agileGeneratorTableInfo.getBusinessName()));
    velocityContext.put("businessName", agileGeneratorTableInfo.getBusinessName());
    velocityContext.put("basePackage", getPackagePrefix(packageName));
    velocityContext.put("packageName", packageName);
    velocityContext.put("author", agileGeneratorTableInfo.getFunctionAuthor());
    velocityContext.put("datetime", AgileDateUtil.getDateNow());
    velocityContext.put("pkColumn", tablePkColumn);
    velocityContext.put("importList", getJavaImportList(agileGeneratorTableInfo.getAgileGeneratorTableColumnList()));
    velocityContext.put("permissionPrefix", getPermissionPrefix(moduleName, businessName));
    velocityContext.put("columnList", agileGeneratorTableInfo.getAgileGeneratorTableColumnList());
    velocityContext.put("table", agileGeneratorTableInfo);
    velocityContext.put("StringUtil", AgileStringUtil.class);
    setMenuVelocityContext(velocityContext, agileGeneratorTableInfo);
    if (AgileGeneratorConstants.TABLE_TYPE_TREE.equals(tableType)) {
        setTreeVelocityContext(velocityContext, agileGeneratorTableInfo);
    }
    return velocityContext;
}
Also used : VelocityContext(org.apache.velocity.VelocityContext) AgileGeneratorTableColumn(com.jeeagile.generator.entity.AgileGeneratorTableColumn)

Example 3 with AgileGeneratorTableColumn

use of com.jeeagile.generator.entity.AgileGeneratorTableColumn in project jeeagile by jeeagile.

the class AgileGeneratorTableServiceImpl method syncTableById.

@Override
public boolean syncTableById(String agileGeneratorTableId) {
    AgileGeneratorTableInfo tableInfo = this.selectTableInfoById(agileGeneratorTableId);
    if (tableInfo != null) {
        List<AgileGeneratorTableColumn> tableColumnList = tableInfo.getAgileGeneratorTableColumnList();
        List<String> tableColumnNameList = tableColumnList.stream().map(AgileGeneratorTableColumn::getColumnName).collect(Collectors.toList());
        List<AgileGeneratorTableColumn> dbTableColumnList = this.getBaseMapper().selectDbTableColumnByTableName(tableInfo.getTableName());
        List<String> dbTableColumnNameList = dbTableColumnList.stream().map(AgileGeneratorTableColumn::getColumnName).collect(Collectors.toList());
        for (AgileGeneratorTableColumn agileGeneratorTableColumn : dbTableColumnList) {
            if (!tableColumnNameList.contains(agileGeneratorTableColumn.getColumnName())) {
                AgileGeneratorUtil.initColumnField(tableInfo, agileGeneratorTableColumn);
                agileGeneratorTableColumnService.save(agileGeneratorTableColumn);
            }
        }
        List<String> deleteColumnIdList = tableColumnList.stream().filter(genTableColumn -> !dbTableColumnNameList.contains(genTableColumn.getColumnName())).map(AgileGeneratorTableColumn::getId).collect(Collectors.toList());
        if (!CollectionUtils.isEmpty(deleteColumnIdList)) {
            agileGeneratorTableColumnService.removeByIds(deleteColumnIdList);
        }
    } else {
        throw new AgileValidateException("表生成信息已不存在无法同步!");
    }
    return true;
}
Also used : AgileGeneratorTableInfo(com.jeeagile.generator.vo.AgileGeneratorTableInfo) AgileValidateException(com.jeeagile.core.exception.AgileValidateException) AgileGeneratorTableColumn(com.jeeagile.generator.entity.AgileGeneratorTableColumn)

Aggregations

AgileGeneratorTableColumn (com.jeeagile.generator.entity.AgileGeneratorTableColumn)3 AgileValidateException (com.jeeagile.core.exception.AgileValidateException)2 AgileGeneratorTable (com.jeeagile.generator.entity.AgileGeneratorTable)1 AgileGeneratorTableInfo (com.jeeagile.generator.vo.AgileGeneratorTableInfo)1 VelocityContext (org.apache.velocity.VelocityContext)1