修改遍历类型字段只限制一级,避免list对泛型对象的影响
This commit is contained in:
@@ -10,7 +10,7 @@ import java.lang.reflect.Field
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取查询条件
|
* 获取查询字段列表
|
||||||
*
|
*
|
||||||
* @param fields 字段列表
|
* @param fields 字段列表
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
package com.synebula.gaea.mongo.query
|
package com.synebula.gaea.mongo.query
|
||||||
|
|
||||||
import com.synebula.gaea.extension.fields
|
import com.synebula.gaea.extension.fieldNames
|
||||||
import com.synebula.gaea.extension.firstCharLowerCase
|
import com.synebula.gaea.extension.firstCharLowerCase
|
||||||
import com.synebula.gaea.log.ILogger
|
import com.synebula.gaea.log.ILogger
|
||||||
import com.synebula.gaea.mongo.order
|
import com.synebula.gaea.mongo.order
|
||||||
@@ -80,7 +80,7 @@ open class MongoGenericQuery<TView>(var template: MongoTemplate, var logger: ILo
|
|||||||
override fun list(params: Map<String, Any>?): List<TView> {
|
override fun list(params: Map<String, Any>?): List<TView> {
|
||||||
this.check()
|
this.check()
|
||||||
return if (this.clazz != null) {
|
return if (this.clazz != null) {
|
||||||
val fields = this.clazz!!.fields()
|
val fields = this.clazz!!.fieldNames()
|
||||||
val query = Query()
|
val query = Query()
|
||||||
query.select(fields.toTypedArray())
|
query.select(fields.toTypedArray())
|
||||||
query.where(params, this.clazz!!)
|
query.where(params, this.clazz!!)
|
||||||
@@ -100,11 +100,11 @@ open class MongoGenericQuery<TView>(var template: MongoTemplate, var logger: ILo
|
|||||||
this.check()
|
this.check()
|
||||||
return if (this.clazz != null) {
|
return if (this.clazz != null) {
|
||||||
val query = Query()
|
val query = Query()
|
||||||
val fields = this.clazz!!.fields()
|
val fields = this.clazz!!.fieldNames()
|
||||||
val result = PagingData<TView>(param.page, param.size)
|
val result = PagingData<TView>(param.page, param.size)
|
||||||
result.total = this.count(param.parameters)
|
result.total = this.count(param.parameters)
|
||||||
query.where(param.parameters, this.clazz!!)
|
|
||||||
query.select(fields.toTypedArray())
|
query.select(fields.toTypedArray())
|
||||||
|
query.where(param.parameters, this.clazz!!)
|
||||||
query.with(order(param.orderBy))
|
query.with(order(param.orderBy))
|
||||||
query.skip(param.index).limit(param.size)
|
query.skip(param.index).limit(param.size)
|
||||||
result.data = this.template.find(query, this.clazz!!, this.collection)
|
result.data = this.template.find(query, this.clazz!!, this.collection)
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
package com.synebula.gaea.mongo.query
|
package com.synebula.gaea.mongo.query
|
||||||
|
|
||||||
import com.synebula.gaea.extension.fields
|
import com.synebula.gaea.extension.fieldNames
|
||||||
import com.synebula.gaea.extension.firstCharLowerCase
|
import com.synebula.gaea.extension.firstCharLowerCase
|
||||||
import com.synebula.gaea.log.ILogger
|
import com.synebula.gaea.log.ILogger
|
||||||
import com.synebula.gaea.mongo.order
|
import com.synebula.gaea.mongo.order
|
||||||
@@ -35,7 +35,7 @@ open class MongoQuery(var repo: MongoTemplate, var logger: ILogger? = null) : IQ
|
|||||||
var validViewCollection = false
|
var validViewCollection = false
|
||||||
|
|
||||||
override fun <TView> list(params: Map<String, Any>?, clazz: Class<TView>): List<TView> {
|
override fun <TView> list(params: Map<String, Any>?, clazz: Class<TView>): List<TView> {
|
||||||
val fields = clazz.fields()
|
val fields = clazz.fieldNames()
|
||||||
val query = Query()
|
val query = Query()
|
||||||
query.where(params, clazz)
|
query.where(params, clazz)
|
||||||
query.select(fields.toTypedArray())
|
query.select(fields.toTypedArray())
|
||||||
@@ -48,7 +48,7 @@ open class MongoQuery(var repo: MongoTemplate, var logger: ILogger? = null) : IQ
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun <TView> paging(param: PagingParam, clazz: Class<TView>): PagingData<TView> {
|
override fun <TView> paging(param: PagingParam, clazz: Class<TView>): PagingData<TView> {
|
||||||
val fields = clazz.fields()
|
val fields = clazz.fieldNames()
|
||||||
val result = PagingData<TView>(param.page, param.size)
|
val result = PagingData<TView>(param.page, param.size)
|
||||||
result.total = this.count(param.parameters, clazz)
|
result.total = this.count(param.parameters, clazz)
|
||||||
val query = Query()
|
val query = Query()
|
||||||
|
|||||||
@@ -1,32 +1,12 @@
|
|||||||
package com.synebula.gaea.extension
|
package com.synebula.gaea.extension
|
||||||
|
|
||||||
import java.lang.reflect.Field
|
|
||||||
import java.util.*
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 系统类型
|
* 获取对象字段信息字符串列表。
|
||||||
*/
|
*/
|
||||||
val SystemClasses = arrayOf(
|
fun Class<*>.fieldNames(): List<String> {
|
||||||
"String",
|
|
||||||
"Date",
|
|
||||||
"Int",
|
|
||||||
"Double",
|
|
||||||
"Float",
|
|
||||||
"BigDecimal",
|
|
||||||
"Decimal")
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 深度获取所有字段信息字符串列表。
|
|
||||||
* @param prefix 前缀字符串
|
|
||||||
*/
|
|
||||||
fun Class<*>.fields(prefix: String = ""): List<String> {
|
|
||||||
val names = mutableListOf<String>()
|
val names = mutableListOf<String>()
|
||||||
this.declaredFields.forEach { field ->
|
this.declaredFields.forEach { field ->
|
||||||
val fullName = if (prefix.isNotEmpty()) "$prefix.${field.name}" else field.name
|
names.add(field.name)
|
||||||
names.add(fullName)
|
|
||||||
if (!field.type.isPrimitive && !field.type.isArray && !SystemClasses.contains(field.type.simpleName)) {
|
|
||||||
names.addAll(field.type.fields(fullName))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return names
|
return names
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user