记得上下班打卡 | git大法好,push需谨慎

Commit e88f59e0 authored by anjiabin's avatar anjiabin

提交chime社交相关

parent 7462e846
...@@ -18,4 +18,12 @@ public class ChimeJoinUserCountDto{ ...@@ -18,4 +18,12 @@ public class ChimeJoinUserCountDto{
private String performancesId; private String performancesId;
private Integer count; private Integer count;
private List<String> avatarImgList; private List<String> avatarImgList;
private static final ChimeJoinUserCountDto obj = new ChimeJoinUserCountDto();
public static ChimeJoinUserCountDto getNew() {
try {
return (ChimeJoinUserCountDto) obj.clone();
} catch (CloneNotSupportedException e) {
return new ChimeJoinUserCountDto();
}
}
} }
package com.liquidnet.service.chime.utils; package com.liquidnet.service.chime.utils;
import com.alibaba.fastjson.JSONObject;
import com.liquidnet.common.cache.redis.util.RedisUtil; import com.liquidnet.common.cache.redis.util.RedisUtil;
import com.liquidnet.commons.lang.util.BeanUtil; import com.liquidnet.commons.lang.util.BeanUtil;
import com.liquidnet.commons.lang.util.JsonUtils; import com.liquidnet.commons.lang.util.JsonUtils;
import com.liquidnet.commons.lang.util.StringUtil;
import com.liquidnet.service.chime.constant.ChimeConstant; import com.liquidnet.service.chime.constant.ChimeConstant;
import com.liquidnet.service.chime.dto.ChimeJoinUserCountDto; import com.liquidnet.service.chime.dto.ChimeJoinUserCountDto;
import com.liquidnet.service.chime.dto.ChimeUserInfoDto; import com.liquidnet.service.chime.dto.ChimeUserInfoDto;
...@@ -14,11 +16,15 @@ import lombok.extern.slf4j.Slf4j; ...@@ -14,11 +16,15 @@ import lombok.extern.slf4j.Slf4j;
import org.bson.Document; import org.bson.Document;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate; import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.aggregation.Aggregation;
import org.springframework.data.mongodb.core.aggregation.AggregationResults;
import org.springframework.data.mongodb.core.query.Criteria; import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query; import org.springframework.data.mongodb.core.query.Query;
import org.springframework.data.mongodb.core.query.Update; import org.springframework.data.mongodb.core.query.Update;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection; import java.util.Collection;
import java.util.List; import java.util.List;
...@@ -97,7 +103,41 @@ public class DataUtils { ...@@ -97,7 +103,41 @@ public class DataUtils {
return mongoTemplate.find(query, ChimeUserTagDto.class,ChimeUserTagsMappingVo.class.getSimpleName()); return mongoTemplate.find(query, ChimeUserTagDto.class,ChimeUserTagsMappingVo.class.getSimpleName());
} }
/**
* 根据演出idList获取在场人数和默认头像图片(最多获取5个url)
* @param performanceIdList
* @return
*/
public List<ChimeJoinUserCountDto> getJoinUserCountList(List<String> performanceIdList){ public List<ChimeJoinUserCountDto> getJoinUserCountList(List<String> performanceIdList){
return null; Aggregation agg = Aggregation.newAggregation(
// 挑选所需的字段,类似select *,*所代表的字段内容
Aggregation.project("joinPerformanceId","avatar"),
// sql where 语句筛选符合条件的记录
Aggregation.match(Criteria.where("joinPerformanceId").in(performanceIdList)),
// 分组条件,设置分组字段
Aggregation.group("joinPerformanceId")
.addToSet("avatar").as("avatarArray")
.count().as("totalCount"),
// 排序(根据某字段排序 倒序)
// Aggregation.sort(Sort.Direction.DESC,"startDate"),
// 重新挑选字段
Aggregation.project("joinPerformanceId","totalCount","avatarArray")
);
AggregationResults<JSONObject> results = mongoTemplate.aggregate(agg, ChimeUserInfoVo.class.getSimpleName(), JSONObject.class);
List<JSONObject> mappedResultsList= results.getMappedResults();
//拼装返回结果
List<ChimeJoinUserCountDto> joinUserCountDtoList = new ArrayList<>();
mappedResultsList.stream().forEach(jsonObject -> {
ChimeJoinUserCountDto dto = ChimeJoinUserCountDto.getNew();
dto.setPerformancesId((String)jsonObject.get("joinPerformanceId"));
dto.setCount((Integer)jsonObject.get("totalCount"));
if(StringUtil.isNotNull(jsonObject.get("avatarArray"))){
dto.setAvatarImgList(Arrays.asList(jsonObject.get("avatarArray").toString().split(",")));
}
joinUserCountDtoList.add(dto);
});
log.debug("排序后的code列表2:[{}]",results);
return joinUserCountDtoList;
} }
} }
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