Commit 0c83b062 authored by 赵啸非's avatar 赵啸非

动态字段调整排序逻辑

parent 93867451
......@@ -75,40 +75,37 @@ public class AppDatasetController extends BaseCRUDJsonBodyMappingController<AppD
@Override
protected void doListBefore(AppDatasetEntity query, Map<String, Object> model, Context context) throws AppException {
if (!ObjectUtils.isEmpty(query.getOrConditionList())||!ObjectUtils.isEmpty(query.getAndConditionList())) {
if (!ObjectUtils.isEmpty(query.getOrConditionList()) || !ObjectUtils.isEmpty(query.getAndConditionList())) {
AppDatasetQuery appDatasetQuery = new AppDatasetQuery();
if (!ObjectUtils.isEmpty(query.getOrConditionList())){
appDatasetQuery.setOrConditionList(query.getOrConditionList());
}
if(!ObjectUtils.isEmpty(query.getAndConditionList())){
if (!ObjectUtils.isEmpty(query.getAndConditionList())) {
appDatasetQuery.setOrConditionList(query.getAndConditionList());
}
appDatasetQuery.setAppId(query.getAppId());
appDatasetQuery.setOrderCols(query.getOrderCols());
PageInfo pageInfo = this.buildPageInfo(query);
Result<AppInfoFieldEntity> customResult = this.service.findCustomList(appDatasetQuery, pageInfo, context);
//根据查询条件的数量去除数量不足的结果
int count = query.getOrConditionList().size();
List<Long> datasetIdList = customResult.getList().stream().map(item -> item.getDatasetId()).collect(Collectors.toList());
Map<Long, Long> collect = datasetIdList.stream().collect(Collectors.groupingBy(x -> x, Collectors.counting()));
List<Long> dataSets = collect.entrySet().stream().map(entrySet -> {
if (entrySet.getValue() == count) {
return entrySet.getKey();
if (!ObjectUtils.isEmpty(query.getOrConditionList())) {
appDatasetQuery.setOrConditionList(query.getOrConditionList());
appDatasetQuery.setAppId(query.getAppId());
appDatasetQuery.setOrderCols(query.getOrderCols());
PageInfo pageInfo = this.buildPageInfo(query);
Result<AppInfoFieldEntity> customResult = this.service.findCustomList(appDatasetQuery, pageInfo, context);
//根据查询条件的数量去除数量不足的结果
int count = query.getOrConditionList().size();
List<Long> datasetIdList = customResult.getList().stream().map(item -> item.getDatasetId()).collect(Collectors.toList());
Map<Long, Long> collect = datasetIdList.stream().collect(Collectors.groupingBy(x -> x, Collectors.counting()));
List<Long> dataSets = collect.entrySet().stream().map(entrySet -> {
if (entrySet.getValue() == count) {
return entrySet.getKey();
} else {
return null;
}
}).filter(f -> f != null).collect(Collectors.toList());
if (!ObjectUtils.isEmpty(dataSets)) {
query.setIdList(dataSets);
} else {
return null;
query.setIdList(ListUtil.toList(0L));
}
}).filter(f -> f != null).collect(Collectors.toList());
if (!ObjectUtils.isEmpty(dataSets)) {
query.setIdList(dataSets);
}else{
query.setIdList(ListUtil.toList(0L));
query.setOrConditionList(null);
}
query.setOrConditionList(null);
}
if (!ObjectUtils.isEmpty(query.getFieldCode()) || !ObjectUtils.isEmpty(query.getFieldName())) {
......
......@@ -15,18 +15,7 @@
<if test="condition.appId!=null and condition.appId!=''">
and a.appId = #{condition.appId,jdbcType=VARCHAR}
</if>
<include refid="_second_condition_"/>
<!-- <if test="condition.fieldCode!=null and condition.fieldCode!=''">
and b.fieldCode = #{condition.fieldCode,jdbcType=VARCHAR}
</if>
<if test="condition.fieldName!=null and condition.fieldName!=''">
and b.fieldName = #{condition.fieldName,jdbcType=VARCHAR}
</if>
<if test="condition.fieldValue != null and condition.fieldValue != ''">
and b.fieldValue like #{condition.fieldValue}
</if>-->
</trim>
</trim>
</select>
......@@ -45,53 +34,12 @@
and a.appId = #{condition.appId,jdbcType=VARCHAR}
</if>
<include refid="_second_condition_"/>
<!-- <if test="condition.fieldCode!=null and condition.fieldCode!=''">
and b.fieldCode = #{condition.fieldCode,jdbcType=VARCHAR}
</if>
<if test="condition.fieldName!=null and condition.fieldName!=''">
and b.fieldName = #{condition.fieldName,jdbcType=VARCHAR}
</if>
<if test="condition.fieldValue != null and condition.fieldValue != ''">
and b.fieldValue like #{condition.fieldValue}
</if>-->
</trim>
</trim>
<if test="(orderColList == null or orderColList.isEmpty()) and orderCol != null and !orderCol.isEmpty()">
order by
IF
( `fieldType` = 'top', '0', '1' ),
`fieldValue` DESC,
order by
fieldType IN('top','date') DESC ,fieldValue DESC
<trim prefix="" suffixOverrides="," suffix="">
<if test="orderCol.containsKey('id')">
a.id
<if test='orderCol.id != null and "DESC".equalsIgnoreCase(orderCol.id)'>DESC</if>
,
</if>
<if test="orderCol.containsKey('appId')">
a.appId
<if test='orderCol.appId != null and "DESC".equalsIgnoreCase(orderCol.appId)'>DESC</if>
,
</if>
<if test="orderCol.containsKey('createTime')">
a.createTime
<if test='orderCol.createTime != null and "DESC".equalsIgnoreCase(orderCol.createTime)'>DESC</if>
,
</if>
<if test="orderCol.containsKey('updateUserId')">
a.updateUserId
<if test='orderCol.updateUserId != null and "DESC".equalsIgnoreCase(orderCol.updateUserId)'>DESC</if>
,
</if>
<if test="orderCol.containsKey('updateTime')">
a.updateTime
<if test='orderCol.updateTime != null and "DESC".equalsIgnoreCase(orderCol.updateTime)'>DESC</if>
,
</if>
</trim>
</if>
</select>
<!-- 条件映射 -->
......
......@@ -46,6 +46,7 @@ Content-Type: application/json
"page": 1,
"size": 10
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment