|
@@ -2,7 +2,11 @@ package org.example.join.sql;
|
|
|
|
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
|
import org.example.join.domain.IQueryColumn;
|
|
|
+import org.example.join.domain.QueryColumn;
|
|
|
+import org.example.join.domain.QueryCondition;
|
|
|
import org.example.join.domain.Table;
|
|
|
+import org.example.join.util.SqlConstant;
|
|
|
+import org.example.join.util.SqlUtil;
|
|
|
|
|
|
import java.util.Arrays;
|
|
|
import java.util.List;
|
|
@@ -16,11 +20,22 @@ public class Select<R> {
|
|
|
this.sql = sql;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 去重
|
|
|
+ */
|
|
|
public Select<R> distinct() {
|
|
|
sql.distinct = true;
|
|
|
return this;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 忽略查询逻辑删除
|
|
|
+ */
|
|
|
+ public Select<R> logicIgnore() {
|
|
|
+ sql.logic = false;
|
|
|
+ return this;
|
|
|
+ }
|
|
|
+
|
|
|
public Select<R> select(IQueryColumn... columns) {
|
|
|
|
|
|
if (ObjectUtil.isEmpty(columns)) {
|
|
@@ -38,6 +53,18 @@ public class Select<R> {
|
|
|
|
|
|
public From<R> from(Table... tables) {
|
|
|
sql.queryTableList.addAll(Arrays.stream(tables).peek(sql::putTableAliasMap).toList());
|
|
|
+
|
|
|
+ // 拼接逻辑删除
|
|
|
+ if (sql.logic) {
|
|
|
+ for (Table table : tables) {
|
|
|
+ String tableDelFlag = SqlUtil.getTableDelFlag(table);
|
|
|
+ if (ObjectUtil.isNotEmpty(tableDelFlag)) {
|
|
|
+ QueryColumn queryColumn = new QueryColumn(table, tableDelFlag);
|
|
|
+ sql.queryConditionList.add(new QueryCondition(queryColumn, SqlConstant.EQ, 0));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
return new From<>(sql);
|
|
|
}
|
|
|
|