更新关联问题
This commit is contained in:
parent
3c5d5d260e
commit
3e31d6fc26
@ -15,5 +15,5 @@ import java.lang.annotation.Target;
|
|||||||
public @interface ColumnMap {
|
public @interface ColumnMap {
|
||||||
String name(); // 对应数据库字段
|
String name(); // 对应数据库字段
|
||||||
String target(); // 映射表来源
|
String target(); // 映射表来源
|
||||||
String targetColumn(); // 映射表字段
|
String on(); // 映射关联字段
|
||||||
}
|
}
|
||||||
|
@ -16,4 +16,6 @@ public @interface EnableTableMap {
|
|||||||
String name() default "t";
|
String name() default "t";
|
||||||
String dept() default "";
|
String dept() default "";
|
||||||
String user() default "";
|
String user() default "";
|
||||||
|
String userOn() default "user_id";
|
||||||
|
String deptOn() default "dept_id";
|
||||||
}
|
}
|
||||||
|
@ -55,21 +55,21 @@ public class TableInfo {
|
|||||||
this.getMapColumns().stream()
|
this.getMapColumns().stream()
|
||||||
.map(MapColumnInfo::getJoin)
|
.map(MapColumnInfo::getJoin)
|
||||||
.map(join -> join.target() + " on "
|
.map(join -> join.target() + " on "
|
||||||
+ join.target() + "." + join.targetColumn() + " = "
|
+ join.target() + "." + join.on() + " = "
|
||||||
+ this.getTableNameT() + "." + join.targetColumn())
|
+ this.getTableNameT() + "." + join.on())
|
||||||
.forEach(joinSql::add);
|
.forEach(joinSql::add);
|
||||||
if (this.enableTableMap != null) {
|
if (this.enableTableMap != null) {
|
||||||
if (StringUtils.isNotEmpty(this.enableTableMap.user())) {
|
if (StringUtils.isNotEmpty(this.enableTableMap.user())) {
|
||||||
this.joinSql.add("sys_user " + this.enableTableMap.user() + " on "
|
this.joinSql.add("sys_user " + this.enableTableMap.user() + " on "
|
||||||
+ this.enableTableMap.user() + ".user_id = "
|
+ this.enableTableMap.user() + "." + this.enableTableMap.userOn() + " = "
|
||||||
+ this.getTableNameT() + "." + ".user_id");
|
+ this.getTableNameT() + "." + this.enableTableMap.userOn());
|
||||||
this.hasDataScopeValue = true;
|
this.hasDataScopeValue = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (StringUtils.isNotEmpty(this.enableTableMap.dept())) {
|
if (StringUtils.isNotEmpty(this.enableTableMap.dept())) {
|
||||||
this.joinSql.add("sys_dept " + this.enableTableMap.dept() + " on "
|
this.joinSql.add("sys_dept " + this.enableTableMap.dept() + " on "
|
||||||
+ this.enableTableMap.dept() + ".dept_id = "
|
+ this.enableTableMap.dept() + "." + this.enableTableMap.deptOn() + " = "
|
||||||
+ this.getTableNameT() + ".dept_id");
|
+ this.getTableNameT() + "." + this.enableTableMap.deptOn());
|
||||||
this.hasDataScopeValue = true;
|
this.hasDataScopeValue = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -9,6 +9,7 @@ import java.util.Map;
|
|||||||
import org.apache.ibatis.jdbc.SQL;
|
import org.apache.ibatis.jdbc.SQL;
|
||||||
|
|
||||||
import com.ruoyi.common.core.domain.BaseEntity;
|
import com.ruoyi.common.core.domain.BaseEntity;
|
||||||
|
import com.ruoyi.common.utils.StringUtils;
|
||||||
import com.ruoyi.mybatis.domain.ColumnInfo;
|
import com.ruoyi.mybatis.domain.ColumnInfo;
|
||||||
import com.ruoyi.mybatis.domain.MapColumnInfo;
|
import com.ruoyi.mybatis.domain.MapColumnInfo;
|
||||||
import com.ruoyi.mybatis.domain.TableInfo;
|
import com.ruoyi.mybatis.domain.TableInfo;
|
||||||
@ -38,12 +39,15 @@ public class SQLUtil {
|
|||||||
|
|
||||||
if (tableInfo.isEnbleMap()) {
|
if (tableInfo.isEnbleMap()) {
|
||||||
tableInfo.getJoinSql().stream()
|
tableInfo.getJoinSql().stream()
|
||||||
|
.filter(StringUtils::isNotEmpty)
|
||||||
.forEach(sql::LEFT_OUTER_JOIN);
|
.forEach(sql::LEFT_OUTER_JOIN);
|
||||||
tableInfo.getNotNullMapColumns(entity).stream()
|
tableInfo.getNotNullMapColumns(entity).stream()
|
||||||
.map(MapColumnInfo::getQuerySql)
|
.map(MapColumnInfo::getQuerySql)
|
||||||
|
.filter(StringUtils::isNotEmpty)
|
||||||
.forEach(sql::WHERE);
|
.forEach(sql::WHERE);
|
||||||
tableInfo.getNotNullColumnsForQuery(entity).stream()
|
tableInfo.getNotNullColumnsForQuery(entity).stream()
|
||||||
.map(ColumnInfo::getQuerySql)
|
.map(ColumnInfo::getQuerySql)
|
||||||
|
.filter(StringUtils::isNotEmpty)
|
||||||
.map(query -> tableInfo.getTableNameT() + "." + query)
|
.map(query -> tableInfo.getTableNameT() + "." + query)
|
||||||
.forEach(sql::WHERE);
|
.forEach(sql::WHERE);
|
||||||
if (tableInfo.hasDataScope()) {
|
if (tableInfo.hasDataScope()) {
|
||||||
@ -51,13 +55,16 @@ public class SQLUtil {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Arrays.stream(tableInfo.getOrderBy())
|
Arrays.stream(tableInfo.getOrderBy())
|
||||||
|
.filter(StringUtils::isNotEmpty)
|
||||||
.map(order -> tableInfo.getTableNameT() + "." + order)
|
.map(order -> tableInfo.getTableNameT() + "." + order)
|
||||||
.forEach(sql::ORDER_BY);
|
.forEach(sql::ORDER_BY);
|
||||||
} else {
|
} else {
|
||||||
tableInfo.getNotNullColumnsForQuery(entity).stream()
|
tableInfo.getNotNullColumnsForQuery(entity).stream()
|
||||||
.map(ColumnInfo::getQuerySql)
|
.map(ColumnInfo::getQuerySql)
|
||||||
|
.filter(StringUtils::isNotEmpty)
|
||||||
.forEach(sql::WHERE);
|
.forEach(sql::WHERE);
|
||||||
Arrays.stream(tableInfo.getOrderBy())
|
Arrays.stream(tableInfo.getOrderBy())
|
||||||
|
.filter(StringUtils::isNotEmpty)
|
||||||
.forEach(sql::ORDER_BY);
|
.forEach(sql::ORDER_BY);
|
||||||
}
|
}
|
||||||
return sql.toString();
|
return sql.toString();
|
||||||
|
Loading…
Reference in New Issue
Block a user