|
|
|
@ -1,19 +1,28 @@
|
|
|
|
|
package com.java3y.austin.web.service.impl;
|
|
|
|
|
|
|
|
|
|
import cn.hutool.core.collection.CollUtil;
|
|
|
|
|
import cn.hutool.core.date.DatePattern;
|
|
|
|
|
import cn.hutool.core.date.DateUtil;
|
|
|
|
|
import cn.hutool.core.map.MapUtil;
|
|
|
|
|
import cn.hutool.core.text.StrPool;
|
|
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
|
|
import com.java3y.austin.common.constant.AustinConstant;
|
|
|
|
|
import com.java3y.austin.common.domain.SimpleAnchorInfo;
|
|
|
|
|
import com.java3y.austin.common.enums.AnchorState;
|
|
|
|
|
import com.java3y.austin.common.enums.ChannelType;
|
|
|
|
|
import com.java3y.austin.support.dao.MessageTemplateDao;
|
|
|
|
|
import com.java3y.austin.support.domain.MessageTemplate;
|
|
|
|
|
import com.java3y.austin.support.utils.RedisUtils;
|
|
|
|
|
import com.java3y.austin.support.utils.TaskInfoUtils;
|
|
|
|
|
import com.java3y.austin.web.constants.AmisVoConstant;
|
|
|
|
|
import com.java3y.austin.web.service.DataService;
|
|
|
|
|
import com.java3y.austin.web.vo.amis.EchartsVo;
|
|
|
|
|
import com.java3y.austin.web.vo.amis.TimeLineItemVo;
|
|
|
|
|
import com.java3y.austin.web.vo.amis.UserTimeLineVo;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
import java.util.*;
|
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
@ -31,23 +40,98 @@ public class DataServiceImpl implements DataService {
|
|
|
|
|
private MessageTemplateDao messageTemplateDao;
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public TimeLineItemVo getTraceUserInfo(String receiver) {
|
|
|
|
|
return null;
|
|
|
|
|
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 = new HashMap<>();
|
|
|
|
|
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();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public EchartsVo getTraceMessageTemplateInfo(String businessId) {
|
|
|
|
|
|
|
|
|
|
// 1. 获取businessId并获取模板信息
|
|
|
|
|
businessId = getRealBusinessId(businessId);
|
|
|
|
|
Optional<MessageTemplate> optional = messageTemplateDao.findById(TaskInfoUtils.getMessageTemplateIdFromBusinessId(Long.valueOf(businessId)));
|
|
|
|
|
if (!optional.isPresent()) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
MessageTemplate messageTemplate = optional.get();
|
|
|
|
|
|
|
|
|
|
List<String> xAxisList = new ArrayList<>();
|
|
|
|
|
List<Integer> actualData = new ArrayList<>();
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* key:state
|
|
|
|
|
* value:stateCount
|
|
|
|
|
*/
|
|
|
|
|
Map<Object, Object> anchorResult = redisUtils.hGetAll(getRealBusinessId(businessId));
|
|
|
|
|
List<Integer> stateList = anchorResult.entrySet().stream().map(objectObjectEntry -> Integer.valueOf(String.valueOf(objectObjectEntry.getKey()))).collect(Collectors.toList());
|
|
|
|
|
for (AnchorState value : AnchorState.values()) {
|
|
|
|
|
|
|
|
|
|
if (CollUtil.isNotEmpty(anchorResult)) {
|
|
|
|
|
anchorResult = MapUtil.sort(anchorResult);
|
|
|
|
|
for (Map.Entry<Object, Object> entry : anchorResult.entrySet()) {
|
|
|
|
|
String description = AnchorState.getDescriptionByCode(Integer.valueOf(String.valueOf(entry.getKey())));
|
|
|
|
|
xAxisList.add(description);
|
|
|
|
|
actualData.add(Integer.valueOf(String.valueOf(entry.getValue())));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
|
|
|
|
|
String title = "【" + messageTemplate.getName() + "】在" + TaskInfoUtils.getDateFromBusinessId(Long.valueOf(businessId)) + "的下发情况:";
|
|
|
|
|
|
|
|
|
|
return EchartsVo.builder()
|
|
|
|
|
.title(EchartsVo.TitleVO.builder().text(title).build())
|
|
|
|
|
.legend(EchartsVo.LegendVO.builder().data(Arrays.asList(AmisVoConstant.LEGEND_TITLE)).build())
|
|
|
|
|
.xAxis(EchartsVo.XAxisVO.builder().data(xAxisList).build())
|
|
|
|
|
.series(Arrays.asList(EchartsVo.SeriesVO.builder().name(AmisVoConstant.LEGEND_TITLE).type(AmisVoConstant.TYPE).data(actualData).build()))
|
|
|
|
|
.yAxis(EchartsVo.YAxisVO.builder().build())
|
|
|
|
|
.tooltip(EchartsVo.TooltipVO.builder().build())
|
|
|
|
|
.build();
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
@ -65,5 +149,4 @@ public class DataServiceImpl implements DataService {
|
|
|
|
|
}
|
|
|
|
|
return businessId;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|