1.2.5版本临时分支

This commit is contained in:
yulichang 2022-11-07 19:36:12 +08:00
parent 8aeeea9265
commit 492c7f59d4
3 changed files with 24 additions and 13 deletions

View File

@ -158,6 +158,8 @@ public class MPJInterceptor implements Interceptor {
MPJLambdaWrapper wrapper = (MPJLambdaWrapper) obj; MPJLambdaWrapper wrapper = (MPJLambdaWrapper) obj;
Map<String, Field> fieldMap = ReflectionKit.getFieldMap(resultType); Map<String, Field> fieldMap = ReflectionKit.getFieldMap(resultType);
List<SelectColumn> columnList = wrapper.getSelectColumns(); List<SelectColumn> columnList = wrapper.getSelectColumns();
//移除对多查询列为了可重复使用wrapper
columnList.removeIf(SelectColumn::isLabel);
List<ResultMapping> resultMappings = new ArrayList<>(columnList.size()); List<ResultMapping> resultMappings = new ArrayList<>(columnList.size());
columnList.forEach(i -> { columnList.forEach(i -> {
TableFieldInfo info = i.getTableFieldInfo(); TableFieldInfo info = i.getTableFieldInfo();
@ -211,7 +213,7 @@ public class MPJInterceptor implements Interceptor {
//列名去重 //列名去重
columnName = getColumn(columnSet, columnName); columnName = getColumn(columnSet, columnName);
columnList.add(SelectColumn.of(mpjColl.getEntityClass(), r.getColumn(), null, columnList.add(SelectColumn.of(mpjColl.getEntityClass(), r.getColumn(), null,
Objects.equals(columnName, r.getColumn()) ? null : columnName, null, null, null)); Objects.equals(columnName, r.getColumn()) ? null : columnName, null, null, true, null));
ResultMapping.Builder builder = new ResultMapping.Builder(ms.getConfiguration(), r.getProperty(), columnName, r.getJavaType()); ResultMapping.Builder builder = new ResultMapping.Builder(ms.getConfiguration(), r.getProperty(), columnName, r.getJavaType());
if (r.isId()) {//主键标记为id标签 if (r.isId()) {//主键标记为id标签
builder.flags(Collections.singletonList(ResultFlag.ID)); builder.flags(Collections.singletonList(ResultFlag.ID));

View File

@ -48,26 +48,34 @@ public class SelectColumn implements UniqueObject {
*/ */
private final Class<?> keyType; private final Class<?> keyType;
/**
* 是否是对多的列
*/
private final boolean label;
/** /**
* 字段函数 * 字段函数
*/ */
private final BaseFuncEnum funcEnum; private final BaseFuncEnum funcEnum;
private SelectColumn(Class<?> clazz, String columnName, TableFieldInfo tableFieldInfo, String alias, String tagProperty, Class<?> keyType, BaseFuncEnum funcEnum) { private SelectColumn(Class<?> clazz, String columnName, TableFieldInfo tableFieldInfo, String alias,
String tagProperty, Class<?> keyType, boolean label, BaseFuncEnum funcEnum) {
this.clazz = clazz; this.clazz = clazz;
this.columnName = columnName; this.columnName = columnName;
this.tableFieldInfo = tableFieldInfo; this.tableFieldInfo = tableFieldInfo;
this.alias = alias; this.alias = alias;
this.tagProperty = tagProperty; this.tagProperty = tagProperty;
this.keyType = keyType; this.keyType = keyType;
this.label = label;
this.funcEnum = funcEnum; this.funcEnum = funcEnum;
} }
public static SelectColumn of(Class<?> clazz, String columnName, TableFieldInfo tableFieldInfo, String alias, String tagProperty, Class<?> keyType, BaseFuncEnum funcEnum) { public static SelectColumn of(Class<?> clazz, String columnName, TableFieldInfo tableFieldInfo, String alias,
String tagProperty, Class<?> keyType, boolean label, BaseFuncEnum funcEnum) {
if (tagProperty != null) if (tagProperty != null)
tagProperty = StringUtils.getTargetColumn(tagProperty); tagProperty = StringUtils.getTargetColumn(tagProperty);
return new SelectColumn(clazz, columnName, tableFieldInfo, alias, tagProperty, keyType, funcEnum); return new SelectColumn(clazz, columnName, tableFieldInfo, alias, tagProperty, keyType, label, funcEnum);
} }
/** /**

View File

@ -142,7 +142,8 @@ public class MPJLambdaWrapper<T> extends MPJAbstractLambdaWrapper<T, MPJLambdaWr
for (SFunction<S, ?> s : columns) { for (SFunction<S, ?> s : columns) {
ColumnCache cache = getCache(s); ColumnCache cache = getCache(s);
selectColumns.add(SelectColumn.of(LambdaUtils.getEntityClass(s), cache.getColumn(), cache.getTableFieldInfo(), selectColumns.add(SelectColumn.of(LambdaUtils.getEntityClass(s), cache.getColumn(), cache.getTableFieldInfo(),
null, cache.getTableFieldInfo() == null ? cache.getKeyProperty() : cache.getTableFieldInfo().getProperty(), cache.getKeyType(), null)); null, cache.getTableFieldInfo() == null ? cache.getKeyProperty() : cache.getTableFieldInfo().getProperty(),
cache.getKeyType(), false, null));
} }
} }
return typedThis; return typedThis;
@ -282,7 +283,7 @@ public class MPJLambdaWrapper<T> extends MPJAbstractLambdaWrapper<T, MPJLambdaWr
TableInfo info = TableInfoHelper.getTableInfo(entityClass); TableInfo info = TableInfoHelper.getTableInfo(entityClass);
Assert.notNull(info, "table not find by class <%s>", entityClass.getName()); Assert.notNull(info, "table not find by class <%s>", entityClass.getName());
info.getFieldList().stream().filter(predicate).collect(Collectors.toList()).forEach( info.getFieldList().stream().filter(predicate).collect(Collectors.toList()).forEach(
i -> selectColumns.add(SelectColumn.of(entityClass, i.getColumn(), i, null, i.getProperty(), null, null))); i -> selectColumns.add(SelectColumn.of(entityClass, i.getColumn(), i, null, i.getProperty(), null, false, null)));
return typedThis; return typedThis;
} }
@ -293,12 +294,12 @@ public class MPJLambdaWrapper<T> extends MPJAbstractLambdaWrapper<T, MPJLambdaWr
List<Field> tagFields = ReflectionKit.getFieldList(tag); List<Field> tagFields = ReflectionKit.getFieldList(tag);
tableInfo.getFieldList().forEach(i -> { tableInfo.getFieldList().forEach(i -> {
if (tagFields.stream().anyMatch(f -> f.getName().equals(i.getProperty()))) { if (tagFields.stream().anyMatch(f -> f.getName().equals(i.getProperty()))) {
selectColumns.add(SelectColumn.of(source, i.getColumn(), i, null, i.getProperty(), null, null)); selectColumns.add(SelectColumn.of(source, i.getColumn(), i, null, i.getProperty(), null, false, null));
} }
}); });
if (tableInfo.havePK() && tagFields.stream().anyMatch(i -> i.getName().equals(tableInfo.getKeyProperty()))) { if (tableInfo.havePK() && tagFields.stream().anyMatch(i -> i.getName().equals(tableInfo.getKeyProperty()))) {
selectColumns.add(SelectColumn.of(source, tableInfo.getKeyColumn(), null, null, selectColumns.add(SelectColumn.of(source, tableInfo.getKeyColumn(), null, null,
tableInfo.getKeyProperty(), tableInfo.getKeyType(), null)); tableInfo.getKeyProperty(), tableInfo.getKeyType(), false, null));
} }
return typedThis; return typedThis;
} }
@ -307,7 +308,7 @@ public class MPJLambdaWrapper<T> extends MPJAbstractLambdaWrapper<T, MPJLambdaWr
public <S> MPJLambdaWrapper<T> selectAs(SFunction<S, ?> column, String alias) { public <S> MPJLambdaWrapper<T> selectAs(SFunction<S, ?> column, String alias) {
ColumnCache cache = getCache(column); ColumnCache cache = getCache(column);
selectColumns.add(SelectColumn.of(LambdaUtils.getEntityClass(column), cache.getColumn(), cache.getTableFieldInfo(), selectColumns.add(SelectColumn.of(LambdaUtils.getEntityClass(column), cache.getColumn(), cache.getTableFieldInfo(),
alias, null, cache.getKeyType(), null)); alias, null, cache.getKeyType(), false, null));
return typedThis; return typedThis;
} }
@ -315,7 +316,7 @@ public class MPJLambdaWrapper<T> extends MPJAbstractLambdaWrapper<T, MPJLambdaWr
if (condition) { if (condition) {
ColumnCache cache = getCache(column); ColumnCache cache = getCache(column);
selectColumns.add(SelectColumn.of(LambdaUtils.getEntityClass(column), cache.getColumn(), selectColumns.add(SelectColumn.of(LambdaUtils.getEntityClass(column), cache.getColumn(),
cache.getTableFieldInfo(), alias, alias, cache.getKeyType(), funcEnum)); cache.getTableFieldInfo(), alias, alias, cache.getKeyType(), false, funcEnum));
} }
return typedThis; return typedThis;
} }
@ -323,7 +324,7 @@ public class MPJLambdaWrapper<T> extends MPJAbstractLambdaWrapper<T, MPJLambdaWr
@Override @Override
public MPJLambdaWrapper<T> selectFunc(boolean condition, BaseFuncEnum funcEnum, Object column, String alias) { public MPJLambdaWrapper<T> selectFunc(boolean condition, BaseFuncEnum funcEnum, Object column, String alias) {
if (condition) { if (condition) {
selectColumns.add(SelectColumn.of(null, column.toString(), null, alias, alias, null, funcEnum)); selectColumns.add(SelectColumn.of(null, column.toString(), null, alias, alias, null, false, funcEnum));
} }
return typedThis; return typedThis;
} }
@ -333,10 +334,10 @@ public class MPJLambdaWrapper<T> extends MPJAbstractLambdaWrapper<T, MPJLambdaWr
Assert.notNull(info, "table can not be find -> %s", clazz); Assert.notNull(info, "table can not be find -> %s", clazz);
if (info.havePK()) { if (info.havePK()) {
selectColumns.add(SelectColumn.of(clazz, info.getKeyColumn(), null, null, selectColumns.add(SelectColumn.of(clazz, info.getKeyColumn(), null, null,
info.getKeyProperty(), info.getKeyType(), null)); info.getKeyProperty(), info.getKeyType(), false, null));
} }
info.getFieldList().forEach(c -> info.getFieldList().forEach(c ->
selectColumns.add(SelectColumn.of(clazz, c.getColumn(), c, null, c.getProperty(), null, null))); selectColumns.add(SelectColumn.of(clazz, c.getColumn(), c, null, c.getProperty(), null, false, null)));
return typedThis; return typedThis;
} }