use of com.java3y.austin.common.domain.SimpleAnchorInfo in project austin by ZhongFuCheng3y.
the class DataServiceImpl method getTraceUserInfo.
@Override
public UserTimeLineVo getTraceUserInfo(String receiver) {
List<String> userInfoList = redisUtils.lRange(receiver, 0, -1);
if (CollUtil.isEmpty(userInfoList)) {
return UserTimeLineVo.builder().items(new ArrayList<>()).build();
}
// 0. 按时间排序
List<SimpleAnchorInfo> sortAnchorList = userInfoList.stream().map(s -> JSON.parseObject(s, SimpleAnchorInfo.class)).sorted((o1, o2) -> Math.toIntExact(o1.getTimestamp() - o2.getTimestamp())).collect(Collectors.toList());
// 1. 对相同的businessId进行分类 {"businessId":[{businessId,state,timeStamp},{businessId,state,timeStamp}]}
Map<String, List<SimpleAnchorInfo>> map = MapUtil.newHashMap();
for (SimpleAnchorInfo simpleAnchorInfo : sortAnchorList) {
List<SimpleAnchorInfo> simpleAnchorInfos = map.get(String.valueOf(simpleAnchorInfo.getBusinessId()));
if (CollUtil.isEmpty(simpleAnchorInfos)) {
simpleAnchorInfos = new ArrayList<>();
}
simpleAnchorInfos.add(simpleAnchorInfo);
map.put(String.valueOf(simpleAnchorInfo.getBusinessId()), simpleAnchorInfos);
}
// 2. 封装vo 给到前端渲染展示
List<UserTimeLineVo.ItemsVO> items = new ArrayList<>();
for (Map.Entry<String, List<SimpleAnchorInfo>> entry : map.entrySet()) {
Long messageTemplateId = TaskInfoUtils.getMessageTemplateIdFromBusinessId(Long.valueOf(entry.getKey()));
MessageTemplate messageTemplate = messageTemplateDao.findById(messageTemplateId).get();
StringBuilder sb = new StringBuilder();
for (SimpleAnchorInfo simpleAnchorInfo : entry.getValue()) {
if (AnchorState.RECEIVE.getCode().equals(simpleAnchorInfo.getState())) {
sb.append(StrPool.CRLF);
}
String startTime = DateUtil.format(new Date(simpleAnchorInfo.getTimestamp()), DatePattern.NORM_DATETIME_PATTERN);
String stateDescription = AnchorState.getDescriptionByCode(simpleAnchorInfo.getState());
sb.append(startTime).append(StrPool.C_COLON).append(stateDescription).append("==>");
}
for (String detail : sb.toString().split(StrPool.CRLF)) {
if (StrUtil.isNotBlank(detail)) {
UserTimeLineVo.ItemsVO itemsVO = UserTimeLineVo.ItemsVO.builder().businessId(entry.getKey()).sendType(ChannelType.getEnumByCode(messageTemplate.getSendChannel()).getDescription()).creator(messageTemplate.getCreator()).title(messageTemplate.getName()).detail(detail).build();
items.add(itemsVO);
}
}
}
return UserTimeLineVo.builder().items(items).build();
}
use of com.java3y.austin.common.domain.SimpleAnchorInfo in project austin by ZhongFuCheng3y.
the class AustinSink method realTimeData.
/**
* 实时数据存入Redis
* 1.用户维度(查看用户当天收到消息的链路详情),数量级大,只保留当天
* 2.消息模板维度(查看消息模板整体下发情况),数量级小,保留30天
*
* @param info
*/
private void realTimeData(AnchorInfo info) {
try {
LettuceRedisUtils.pipeline(redisAsyncCommands -> {
List<RedisFuture<?>> redisFutures = new ArrayList<>();
/**
* 1.构建userId维度的链路信息 数据结构list:{key,list}
* key:userId,listValue:[{timestamp,state,businessId},{timestamp,state,businessId}]
*/
SimpleAnchorInfo simpleAnchorInfo = SimpleAnchorInfo.builder().businessId(info.getBusinessId()).state(info.getState()).timestamp(info.getTimestamp()).build();
for (String id : info.getIds()) {
redisFutures.add(redisAsyncCommands.lpush(id.getBytes(), JSON.toJSONString(simpleAnchorInfo).getBytes()));
redisFutures.add(redisAsyncCommands.expire(id.getBytes(), (DateUtil.endOfDay(new Date()).getTime() - DateUtil.current()) / 1000));
}
/**
* 2.构建消息模板维度的链路信息 数据结构hash:{key,hash}
* key:businessId,hashValue:{state,stateCount}
*/
redisFutures.add(redisAsyncCommands.hincrby(String.valueOf(info.getBusinessId()).getBytes(), String.valueOf(info.getState()).getBytes(), info.getIds().size()));
redisFutures.add(redisAsyncCommands.expire(String.valueOf(info.getBusinessId()).getBytes(), (DateUtil.offsetDay(new Date(), 30).getTime()) / 1000));
return redisFutures;
});
} catch (Exception e) {
log.error("AustinSink#invoke error: {}", Throwables.getStackTraceAsString(e));
}
}
Aggregations