|
@@ -105,17 +105,16 @@ public class Sql implements IFormat {
|
|
|
*/
|
|
|
private String createSql(Sql sql) {
|
|
|
|
|
|
- List<IQueryColumn> queryFieldsList = sql.queryFieldsList;
|
|
|
- List<ITable> queryTableList = sql.queryTableList;
|
|
|
- List<QueryCondition> queryConditionList = sql.queryConditionList;
|
|
|
- List<QueryColumn> groupByList = sql.groupByList;
|
|
|
- List<QueryConditionOrder> orderByList = sql.orderByList;
|
|
|
-
|
|
|
// select
|
|
|
StringBuilder sqlBuilder = new StringBuilder().append(SqlConstant.SELECT);
|
|
|
|
|
|
+ // distinct
|
|
|
+ if (sql.distinct) {
|
|
|
+ sqlBuilder.append(SqlConstant.DISTINCT);
|
|
|
+ }
|
|
|
+
|
|
|
// fields
|
|
|
- String queryFields = listFormatSql(queryFieldsList, StringPool.COMMA);
|
|
|
+ String queryFields = listFormatSql(sql.queryFieldsList, StringPool.COMMA);
|
|
|
if (StrUtil.isBlank(queryFields)) {
|
|
|
sqlBuilder.append(StringPool.ASTERISK);
|
|
|
} else {
|
|
@@ -123,22 +122,22 @@ public class Sql implements IFormat {
|
|
|
}
|
|
|
|
|
|
// from table join table on
|
|
|
- sqlBuilder.append(SqlConstant.FROM).append(getQueryTablesSql(queryTableList));
|
|
|
+ sqlBuilder.append(SqlConstant.FROM).append(getQueryTablesSql(sql.queryTableList));
|
|
|
|
|
|
// where 条件
|
|
|
- String where = listFormatSql(queryConditionList, SqlConstant.AND);
|
|
|
+ String where = listFormatSql(sql.queryConditionList, SqlConstant.AND);
|
|
|
if (StrUtil.isNotBlank(where)) {
|
|
|
sqlBuilder.append(SqlConstant.WHERE).append(where);
|
|
|
}
|
|
|
|
|
|
// groupBy 条件
|
|
|
- String groupBy = listFormatSql(groupByList, StringPool.COMMA);
|
|
|
+ String groupBy = listFormatSql(sql.groupByList, StringPool.COMMA);
|
|
|
if (StrUtil.isNotBlank(groupBy)) {
|
|
|
sqlBuilder.append(SqlConstant.GROUP_BY).append(groupBy);
|
|
|
}
|
|
|
|
|
|
// orderBy 条件
|
|
|
- String orderBy = listFormatSql(orderByList, StringPool.COMMA);
|
|
|
+ String orderBy = listFormatSql(sql.orderByList, StringPool.COMMA);
|
|
|
if (StrUtil.isNotBlank(orderBy)) {
|
|
|
sqlBuilder.append(SqlConstant.ORDER_BY).append(orderBy);
|
|
|
}
|