Search in sources :

Example 1 with SimpleAnchorInfo

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();
}
Also used : DataService(com.java3y.austin.web.service.DataService) DateUtil(cn.hutool.core.date.DateUtil) AustinConstant(com.java3y.austin.common.constant.AustinConstant) RedisUtils(com.java3y.austin.support.utils.RedisUtils) java.util(java.util) AnchorState(com.java3y.austin.common.enums.AnchorState) MapUtil(cn.hutool.core.map.MapUtil) AmisVoConstant(com.java3y.austin.web.constants.AmisVoConstant) SimpleAnchorInfo(com.java3y.austin.common.domain.SimpleAnchorInfo) Autowired(org.springframework.beans.factory.annotation.Autowired) StrPool(cn.hutool.core.text.StrPool) Collectors(java.util.stream.Collectors) TaskInfoUtils(com.java3y.austin.support.utils.TaskInfoUtils) ChannelType(com.java3y.austin.common.enums.ChannelType) CollUtil(cn.hutool.core.collection.CollUtil) StrUtil(cn.hutool.core.util.StrUtil) JSON(com.alibaba.fastjson.JSON) Service(org.springframework.stereotype.Service) MessageTemplateDao(com.java3y.austin.support.dao.MessageTemplateDao) MessageTemplate(com.java3y.austin.support.domain.MessageTemplate) EchartsVo(com.java3y.austin.web.vo.amis.EchartsVo) DatePattern(cn.hutool.core.date.DatePattern) UserTimeLineVo(com.java3y.austin.web.vo.amis.UserTimeLineVo) SimpleAnchorInfo(com.java3y.austin.common.domain.SimpleAnchorInfo) MessageTemplate(com.java3y.austin.support.domain.MessageTemplate) UserTimeLineVo(com.java3y.austin.web.vo.amis.UserTimeLineVo)

Example 2 with SimpleAnchorInfo

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));
    }
}
Also used : SimpleAnchorInfo(com.java3y.austin.common.domain.SimpleAnchorInfo) RedisFuture(io.lettuce.core.RedisFuture) ArrayList(java.util.ArrayList) Date(java.util.Date)

Aggregations

SimpleAnchorInfo (com.java3y.austin.common.domain.SimpleAnchorInfo)2 CollUtil (cn.hutool.core.collection.CollUtil)1 DatePattern (cn.hutool.core.date.DatePattern)1 DateUtil (cn.hutool.core.date.DateUtil)1 MapUtil (cn.hutool.core.map.MapUtil)1 StrPool (cn.hutool.core.text.StrPool)1 StrUtil (cn.hutool.core.util.StrUtil)1 JSON (com.alibaba.fastjson.JSON)1 AustinConstant (com.java3y.austin.common.constant.AustinConstant)1 AnchorState (com.java3y.austin.common.enums.AnchorState)1 ChannelType (com.java3y.austin.common.enums.ChannelType)1 MessageTemplateDao (com.java3y.austin.support.dao.MessageTemplateDao)1 MessageTemplate (com.java3y.austin.support.domain.MessageTemplate)1 RedisUtils (com.java3y.austin.support.utils.RedisUtils)1 TaskInfoUtils (com.java3y.austin.support.utils.TaskInfoUtils)1 AmisVoConstant (com.java3y.austin.web.constants.AmisVoConstant)1 DataService (com.java3y.austin.web.service.DataService)1 EchartsVo (com.java3y.austin.web.vo.amis.EchartsVo)1 UserTimeLineVo (com.java3y.austin.web.vo.amis.UserTimeLineVo)1 RedisFuture (io.lettuce.core.RedisFuture)1