提供 业务 bizId 和 messageId 注入, 支持基于 messageId 查询结果

pull/46/head
sky.huang 1 year ago
parent 5f12b96c19
commit 6083116471

@ -27,6 +27,10 @@ public class AustinConstant {
*/
public static final String SEND_ALL = "@all";
public static final String CACHE_KEY_PREFIX = "Austin";
public static final String MESSAGE_ID = "MessageId";
/**
* /

@ -17,7 +17,17 @@ import java.util.Set;
@AllArgsConstructor
@NoArgsConstructor
public class AnchorInfo {
/**
* Id(使)
* TaskInfoUtils
*/
private String bizId;
/**
* Id(使)
* TaskInfoUtils
*/
private String messageId;
/**
*
*/

@ -0,0 +1,36 @@
package com.java3y.austin.common.domain;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
* @Author: sky
* @Date: 2023/7/13 10:43
* @Description: SimpleTaskInfo
* @Version 1.0.0
*/
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class SimpleTaskInfo {
/**
* Id, , , 使 messageId
*/
private String bizId;
/**
* Id(使)
* TaskInfoUtils
*/
private String messageId;
/**
* Id(使)
* TaskInfoUtils
*/
private Long businessId;
}

@ -19,6 +19,17 @@ import java.util.Set;
@NoArgsConstructor
public class TaskInfo {
/**
* Id, , , 使 messageId
*/
private String bizId;
/**
* Id(使)
* TaskInfoUtils
*/
private String messageId;
/**
* Id
*/

@ -46,7 +46,7 @@ public abstract class AbstractDeduplicationService implements DeduplicationServi
// 剔除符合去重条件的用户
if (CollUtil.isNotEmpty(filterReceiver)) {
taskInfo.getReceiver().removeAll(filterReceiver);
logUtils.print(AnchorInfo.builder().businessId(taskInfo.getBusinessId()).ids(filterReceiver).state(param.getAnchorState().getCode()).build());
logUtils.print(AnchorInfo.builder().bizId(taskInfo.getBizId()).messageId(taskInfo.getMessageId()).businessId(taskInfo.getBusinessId()).ids(filterReceiver).state(param.getAnchorState().getCode()).build());
}
}

@ -38,7 +38,7 @@ public class DiscardMessageService {
JSONArray array = JSON.parseArray(config.getProperty(DISCARD_MESSAGE_KEY, CommonConstant.EMPTY_VALUE_JSON_ARRAY));
if (array.contains(String.valueOf(taskInfo.getMessageTemplateId()))) {
logUtils.print(AnchorInfo.builder().businessId(taskInfo.getBusinessId()).ids(taskInfo.getReceiver()).state(AnchorState.DISCARD.getCode()).build());
logUtils.print(AnchorInfo.builder().bizId(taskInfo.getBizId()).messageId(taskInfo.getMessageId()).businessId(taskInfo.getBusinessId()).ids(taskInfo.getReceiver()).state(AnchorState.DISCARD.getCode()).build());
return true;
}
return false;

@ -59,10 +59,10 @@ public abstract class BaseHandler implements Handler {
public void doHandler(TaskInfo taskInfo) {
flowControl(taskInfo);
if (handler(taskInfo)) {
logUtils.print(AnchorInfo.builder().state(AnchorState.SEND_SUCCESS.getCode()).businessId(taskInfo.getBusinessId()).ids(taskInfo.getReceiver()).build());
logUtils.print(AnchorInfo.builder().state(AnchorState.SEND_SUCCESS.getCode()).bizId(taskInfo.getBizId()).messageId(taskInfo.getMessageId()).businessId(taskInfo.getBusinessId()).ids(taskInfo.getReceiver()).build());
return;
}
logUtils.print(AnchorInfo.builder().state(AnchorState.SEND_FAIL.getCode()).businessId(taskInfo.getBusinessId()).ids(taskInfo.getReceiver()).build());
logUtils.print(AnchorInfo.builder().state(AnchorState.SEND_FAIL.getCode()).bizId(taskInfo.getBizId()).messageId(taskInfo.getMessageId()).businessId(taskInfo.getBusinessId()).ids(taskInfo.getReceiver()).build());
}

@ -41,7 +41,7 @@ public class ConsumeServiceImpl implements ConsumeService {
public void consume2Send(List<TaskInfo> taskInfoLists) {
String topicGroupId = GroupIdMappingUtils.getGroupIdByTaskInfo(CollUtil.getFirst(taskInfoLists.iterator()));
for (TaskInfo taskInfo : taskInfoLists) {
logUtils.print(LogParam.builder().bizType(LOG_BIZ_TYPE).object(taskInfo).build(), AnchorInfo.builder().ids(taskInfo.getReceiver()).businessId(taskInfo.getBusinessId()).state(AnchorState.RECEIVE.getCode()).build());
logUtils.print(LogParam.builder().bizType(LOG_BIZ_TYPE).object(taskInfo).build(), AnchorInfo.builder().bizId(taskInfo.getBizId()).messageId(taskInfo.getMessageId()).ids(taskInfo.getReceiver()).businessId(taskInfo.getBusinessId()).state(AnchorState.RECEIVE.getCode()).build());
Task task = context.getBean(Task.class).setTaskInfo(taskInfo);
taskPendingHolder.route(topicGroupId).execute(task);
}

@ -47,13 +47,13 @@ public class ShieldServiceImpl implements ShieldService {
if (isNight()) {
if (ShieldType.NIGHT_SHIELD.getCode().equals(taskInfo.getShieldType())) {
logUtils.print(AnchorInfo.builder().state(AnchorState.NIGHT_SHIELD.getCode())
.businessId(taskInfo.getBusinessId()).ids(taskInfo.getReceiver()).build());
.bizId(taskInfo.getBizId()).messageId(taskInfo.getMessageId()).businessId(taskInfo.getBusinessId()).ids(taskInfo.getReceiver()).build());
}
if (ShieldType.NIGHT_SHIELD_BUT_NEXT_DAY_SEND.getCode().equals(taskInfo.getShieldType())) {
redisUtils.lPush(NIGHT_SHIELD_BUT_NEXT_DAY_SEND_KEY, JSON.toJSONString(taskInfo,
SerializerFeature.WriteClassName),
SECONDS_OF_A_DAY);
logUtils.print(AnchorInfo.builder().state(AnchorState.NIGHT_SHIELD_NEXT_SEND.getCode()).businessId(taskInfo.getBusinessId()).ids(taskInfo.getReceiver()).build());
logUtils.print(AnchorInfo.builder().state(AnchorState.NIGHT_SHIELD_NEXT_SEND.getCode()).bizId(taskInfo.getBizId()).messageId(taskInfo.getMessageId()).businessId(taskInfo.getBusinessId()).ids(taskInfo.getReceiver()).build());
}
taskInfo.setReceiver(new HashSet<>());
}

@ -4,6 +4,7 @@ package com.java3y.austin.service.api.impl.action;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.ReUtil;
import com.alibaba.fastjson.JSON;
import com.java3y.austin.common.domain.SimpleTaskInfo;
import com.java3y.austin.common.domain.TaskInfo;
import com.java3y.austin.common.enums.IdType;
import com.java3y.austin.common.enums.RespStatusEnum;
@ -49,8 +50,11 @@ public class AfterParamCheckAction implements BusinessProcess<SendTaskModel> {
filterIllegalReceiver(taskInfo);
if (CollUtil.isEmpty(taskInfo)) {
context.setNeedBreak(true).setResponse(BasicResultVO.fail(RespStatusEnum.CLIENT_BAD_PARAMETERS));
context.setNeedBreak(true).setResponse(BasicResultVO.fail(RespStatusEnum.CLIENT_BAD_PARAMETERS, "手机号或邮箱不合法, 无有效的发送任务"));
}
// 数据组装
context.setResponse(BasicResultVO.success(taskInfo.stream().map(v -> SimpleTaskInfo.builder().businessId(v.getBusinessId()).messageId(v.getMessageId()).bizId(v.getBizId()).build()).collect(Collectors.toList())));
}
/**

@ -79,6 +79,8 @@ public class AssembleAction implements BusinessProcess<SendTaskModel> {
for (MessageParam messageParam : messageParamList) {
TaskInfo taskInfo = TaskInfo.builder()
.messageId(TaskInfoUtils.generateMessageId())
.bizId(messageParam.getBizId())
.messageTemplateId(messageTemplate.getId())
.businessId(TaskInfoUtils.generateBusinessId(messageTemplate.getId(), messageTemplate.getTemplateType()))
.receiver(new HashSet<>(Arrays.asList(messageParam.getReceiver().split(String.valueOf(StrUtil.C_COMMA)))))
@ -90,6 +92,10 @@ public class AssembleAction implements BusinessProcess<SendTaskModel> {
.sendAccount(messageTemplate.getSendAccount())
.contentModel(getContentModelValue(messageTemplate, messageParam)).build();
if (StrUtil.isBlank(taskInfo.getBizId())) {
taskInfo.setBizId(taskInfo.getMessageId());
}
taskInfoList.add(taskInfo);
}

@ -34,7 +34,7 @@ public class PreParamCheckAction implements BusinessProcess<SendTaskModel> {
// 1.没有传入 消息模板Id 或者 messageParam
if (Objects.isNull(messageTemplateId) || CollUtil.isEmpty(messageParamList)) {
context.setNeedBreak(true).setResponse(BasicResultVO.fail(RespStatusEnum.CLIENT_BAD_PARAMETERS));
context.setNeedBreak(true).setResponse(BasicResultVO.fail(RespStatusEnum.CLIENT_BAD_PARAMETERS, "模板ID或参数列表为空"));
return;
}
@ -43,7 +43,7 @@ public class PreParamCheckAction implements BusinessProcess<SendTaskModel> {
.filter(messageParam -> !StrUtil.isBlank(messageParam.getReceiver()))
.collect(Collectors.toList());
if (CollUtil.isEmpty(resultMessageParamList)) {
context.setNeedBreak(true).setResponse(BasicResultVO.fail(RespStatusEnum.CLIENT_BAD_PARAMETERS));
context.setNeedBreak(true).setResponse(BasicResultVO.fail(RespStatusEnum.CLIENT_BAD_PARAMETERS, "含接受者的参数列表为空"));
return;
}

@ -27,7 +27,7 @@ public class RecallServiceImpl implements RecallService {
@Override
public SendResponse recall(SendRequest sendRequest) {
if(ObjectUtils.isEmpty(sendRequest)){
return new SendResponse(RespStatusEnum.CLIENT_BAD_PARAMETERS.getCode(), RespStatusEnum.CLIENT_BAD_PARAMETERS.getMsg());
return new SendResponse(RespStatusEnum.CLIENT_BAD_PARAMETERS.getCode(), RespStatusEnum.CLIENT_BAD_PARAMETERS.getMsg(), null);
}
SendTaskModel sendTaskModel = SendTaskModel.builder()
.messageTemplateId(sendRequest.getMessageTemplateId())
@ -38,6 +38,6 @@ public class RecallServiceImpl implements RecallService {
.needBreak(false)
.response(BasicResultVO.success()).build();
ProcessContext process = processController.process(context);
return new SendResponse(process.getResponse().getStatus(), process.getResponse().getMsg());
return new SendResponse(process.getResponse().getStatus(), process.getResponse().getMsg(), null);
}
}

@ -1,6 +1,7 @@
package com.java3y.austin.service.api.impl.service;
import cn.monitor4all.logRecord.annotation.OperationLog;
import com.java3y.austin.common.domain.SimpleTaskInfo;
import com.java3y.austin.common.enums.RespStatusEnum;
import com.java3y.austin.common.vo.BasicResultVO;
import com.java3y.austin.service.api.domain.BatchSendRequest;
@ -15,6 +16,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Collections;
import java.util.List;
/**
*
@ -31,7 +33,7 @@ public class SendServiceImpl implements SendService {
@OperationLog(bizType = "SendService#send", bizId = "#sendRequest.messageTemplateId", msg = "#sendRequest")
public SendResponse send(SendRequest sendRequest) {
if(ObjectUtils.isEmpty(sendRequest)){
return new SendResponse(RespStatusEnum.CLIENT_BAD_PARAMETERS.getCode(), RespStatusEnum.CLIENT_BAD_PARAMETERS.getMsg());
return new SendResponse(RespStatusEnum.CLIENT_BAD_PARAMETERS.getCode(), RespStatusEnum.CLIENT_BAD_PARAMETERS.getMsg(), null);
}
SendTaskModel sendTaskModel = SendTaskModel.builder()
@ -47,7 +49,7 @@ public class SendServiceImpl implements SendService {
ProcessContext process = processController.process(context);
return new SendResponse(process.getResponse().getStatus(), process.getResponse().getMsg());
return new SendResponse(process.getResponse().getStatus(), process.getResponse().getMsg(), (List<SimpleTaskInfo>) process.getResponse().getData());
}
@Override
@ -66,7 +68,7 @@ public class SendServiceImpl implements SendService {
ProcessContext process = processController.process(context);
return new SendResponse(process.getResponse().getStatus(), process.getResponse().getMsg());
return new SendResponse(process.getResponse().getStatus(), process.getResponse().getMsg(), null);
}

@ -0,0 +1,49 @@
package com.java3y.austin.service.api.impl.service;
import cn.hutool.core.collection.CollUtil;
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.RespStatusEnum;
import com.java3y.austin.service.api.domain.SendResponse;
import com.java3y.austin.service.api.domain.TraceResponse;
import com.java3y.austin.service.api.service.TraceService;
import com.java3y.austin.support.utils.RedisUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Primary;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.stream.Collectors;
/**
* @Author: sky
* @Date: 2023/7/13 13:45
* @Description: TraceServiceImpl
* @Version 1.0.0
*/
@Service
@Primary
public class TraceServiceImpl implements TraceService {
@Autowired
private RedisUtils redisUtils;
@Override
public TraceResponse traceByMessageId(String messageId) {
if (StrUtil.isBlank(messageId)) {
return new TraceResponse(RespStatusEnum.CLIENT_BAD_PARAMETERS.getCode(), RespStatusEnum.CLIENT_BAD_PARAMETERS.getMsg(), null);
}
String redisMessageKey = StrUtil.join(StrUtil.COLON, AustinConstant.CACHE_KEY_PREFIX, AustinConstant.MESSAGE_ID, messageId);
List<String> messageList = redisUtils.lRange(redisMessageKey, 0, -1);
if (CollUtil.isEmpty(messageList)) {
return new TraceResponse(RespStatusEnum.FAIL.getCode(), RespStatusEnum.FAIL.getMsg(), null);
}
// 0. 按时间排序
List<SimpleAnchorInfo> sortAnchorList = messageList.stream().map(s -> JSON.parseObject(s, SimpleAnchorInfo.class)).sorted((o1, o2) -> Math.toIntExact(o1.getTimestamp() - o2.getTimestamp())).collect(Collectors.toList());
return new TraceResponse(RespStatusEnum.SUCCESS.getCode(), RespStatusEnum.SUCCESS.getMsg(), sortAnchorList);
}
}

@ -21,6 +21,11 @@ import java.util.Map;
@Builder
public class MessageParam {
/**
* Id, , , austin Id
*/
private String bizId;
/**
* @Description:
* ,

@ -1,10 +1,13 @@
package com.java3y.austin.service.api.domain;
import com.java3y.austin.common.domain.SimpleTaskInfo;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;
import java.util.List;
/**
*
@ -20,10 +23,14 @@ public class SendResponse {
*
*/
private String code;
/**
*
*/
private String msg;
/**
*
*/
private List<SimpleTaskInfo> data;
}

@ -0,0 +1,35 @@
package com.java3y.austin.service.api.domain;
import com.java3y.austin.common.domain.SimpleAnchorInfo;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;
import java.util.List;
/**
* @Author: sky
* @Date: 2023/7/13 13:38
* @Description: TraceResponse
* @Version 1.0.0
*/
@Data
@Accessors(chain = true)
@AllArgsConstructor
@NoArgsConstructor
public class TraceResponse {
/**
*
*/
private String code;
/**
*
*/
private String msg;
/**
*
*/
private List<SimpleAnchorInfo> data;
}

@ -0,0 +1,20 @@
package com.java3y.austin.service.api.service;
import com.java3y.austin.service.api.domain.TraceResponse;
/**
*
* @Author: sky
* @Date: 2023/7/13 13:35
* @Description: TraceService
* @Version 1.0.0
*/
public interface TraceService {
/**
* ID
* @param messageId
* @return
*/
TraceResponse traceByMessageId(String messageId);
}

@ -1,8 +1,10 @@
package com.java3y.austin.stream.sink;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSON;
import com.google.common.base.Throwables;
import com.java3y.austin.common.constant.AustinConstant;
import com.java3y.austin.common.domain.AnchorInfo;
import com.java3y.austin.common.domain.SimpleAnchorInfo;
import com.java3y.austin.stream.utils.LettuceRedisUtils;
@ -10,6 +12,7 @@ import io.lettuce.core.RedisFuture;
import lombok.extern.slf4j.Slf4j;
import org.apache.flink.streaming.api.functions.sink.SinkFunction;
import java.time.Duration;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
@ -40,13 +43,21 @@ public class AustinSink implements SinkFunction<AnchorInfo> {
try {
LettuceRedisUtils.pipeline(redisAsyncCommands -> {
List<RedisFuture<?>> redisFutures = new ArrayList<>();
/**
* 1.messageId list:{key,list}
* key:Austin:MessageId:{messageId},listValue:[{timestamp,state,businessId},{timestamp,state,businessId}]
*/
String redisMessageKey = StrUtil.join(StrUtil.COLON, AustinConstant.CACHE_KEY_PREFIX, AustinConstant.MESSAGE_ID, info.getMessageId());
SimpleAnchorInfo messageAnchorInfo = SimpleAnchorInfo.builder().businessId(info.getBusinessId()).state(info.getState()).timestamp(info.getLogTimestamp()).build();
redisFutures.add(redisAsyncCommands.lpush(redisMessageKey.getBytes(), JSON.toJSONString(messageAnchorInfo).getBytes()));
redisFutures.add(redisAsyncCommands.expire(redisMessageKey.getBytes(), Duration.ofDays(3).toMillis() / 1000));
/**
* 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.getLogTimestamp()).build();
SimpleAnchorInfo userAnchorInfo = SimpleAnchorInfo.builder().businessId(info.getBusinessId()).state(info.getState()).timestamp(info.getLogTimestamp()).build();
for (String id : info.getIds()) {
redisFutures.add(redisAsyncCommands.lpush(id.getBytes(), JSON.toJSONString(simpleAnchorInfo).getBytes()));
redisFutures.add(redisAsyncCommands.lpush(id.getBytes(), JSON.toJSONString(userAnchorInfo).getBytes()));
redisFutures.add(redisAsyncCommands.expire(id.getBytes(), (DateUtil.endOfDay(new Date()).getTime() - DateUtil.current()) / 1000));
}

@ -2,6 +2,7 @@ package com.java3y.austin.support.utils;
import cn.hutool.core.date.DatePattern;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.IdUtil;
import com.java3y.austin.common.constant.CommonConstant;
import java.util.Date;
@ -16,6 +17,13 @@ public class TaskInfoUtils {
private static final int TYPE_FLAG = 1000000;
private static final String CODE = "track_code_bid";
/**
* Id
* @return
*/
public static String generateMessageId() {
return IdUtil.nanoId();
}
/**
* BusinessId
* +ID+

@ -36,6 +36,15 @@ public class DataController {
@Autowired
private DataService dataService;
@PostMapping("/message")
@ApiOperation("/获取【72小时】发送消息的全链路数据")
public UserTimeLineVo getMessageData(@RequestBody DataParam dataParam) {
if (Objects.isNull(dataParam) || StrUtil.isBlank(dataParam.getMessageId())) {
return UserTimeLineVo.builder().items(new ArrayList<>()).build();
}
return dataService.getTraceMessageInfo(dataParam.getMessageId());
}
@PostMapping("/user")
@ApiOperation("/获取【当天】用户接收消息的全链路数据")
public UserTimeLineVo getUserData(@RequestBody DataParam dataParam) {

@ -12,6 +12,14 @@ import com.java3y.austin.web.vo.amis.UserTimeLineVo;
*/
public interface DataService {
/**
*
*
* @param messageId
* @return
*/
UserTimeLineVo getTraceMessageInfo(String messageId);
/**
*
*

@ -12,6 +12,8 @@ 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.common.enums.EnumUtil;
import com.java3y.austin.service.api.domain.TraceResponse;
import com.java3y.austin.service.api.service.TraceService;
import com.java3y.austin.support.dao.MessageTemplateDao;
import com.java3y.austin.support.dao.SmsRecordDao;
import com.java3y.austin.support.domain.MessageTemplate;
@ -47,6 +49,18 @@ public class DataServiceImpl implements DataService {
@Autowired
private SmsRecordDao smsRecordDao;
@Autowired
private TraceService traceService;
@Override
public UserTimeLineVo getTraceMessageInfo(String messageId) {
TraceResponse traceResponse = traceService.traceByMessageId(messageId);
if (CollUtil.isEmpty(traceResponse.getData())) {
return UserTimeLineVo.builder().items(new ArrayList<>()).build();
}
return buildUserTimeLineVo(traceResponse.getData());
}
@Override
public UserTimeLineVo getTraceUserInfo(String receiver) {
@ -57,51 +71,7 @@ public class DataServiceImpl implements DataService {
// 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).orElse(null);
if (Objects.isNull(messageTemplate)) {
continue;
}
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 = EnumUtil.getDescriptionByCode(simpleAnchorInfo.getState(), AnchorState.class);
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(EnumUtil.getEnumByCode(messageTemplate.getSendChannel(), ChannelType.class).getDescription())
.creator(messageTemplate.getCreator())
.title(messageTemplate.getName())
.detail(detail)
.build();
items.add(itemsVO);
}
}
}
return UserTimeLineVo.builder().items(items).build();
return buildUserTimeLineVo(sortAnchorList);
}
@Override
@ -153,4 +123,51 @@ public class DataServiceImpl implements DataService {
}
return businessId;
}
private UserTimeLineVo buildUserTimeLineVo(List<SimpleAnchorInfo> sortAnchorList){
// 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).orElse(null);
if (Objects.isNull(messageTemplate)) {
continue;
}
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 = EnumUtil.getDescriptionByCode(simpleAnchorInfo.getState(), AnchorState.class);
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(EnumUtil.getEnumByCode(messageTemplate.getSendChannel(), ChannelType.class).getDescription())
.creator(messageTemplate.getCreator())
.title(messageTemplate.getName())
.detail(detail)
.build();
items.add(itemsVO);
}
}
}
return UserTimeLineVo.builder().items(items).build();
}
}

@ -17,6 +17,12 @@ import lombok.NoArgsConstructor;
@NoArgsConstructor
public class DataParam {
/**
* Id
*/
private String messageId;
/**
*
*/

Loading…
Cancel
Save