1. 微信服务号和微信小程序handler 单发 适配埋点结构

2. web后端增加埋点微信渠道的描述
3. idea reformat code
master
3y 2 years ago
parent 038a16dbdc
commit d63f4b3959

@ -6,6 +6,7 @@ import lombok.Builder;
import lombok.Data; import lombok.Data;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
import java.io.Serializable;
import java.util.Set; import java.util.Set;
/** /**
@ -17,7 +18,7 @@ import java.util.Set;
@Builder @Builder
@AllArgsConstructor @AllArgsConstructor
@NoArgsConstructor @NoArgsConstructor
public class TaskInfo { public class TaskInfo implements Serializable {
/** /**
* Id, , , 使 messageId * Id, , , 使 messageId

@ -27,16 +27,14 @@ public abstract class AbstractDeduplicationService implements DeduplicationServi
@Autowired @Autowired
private DeduplicationHolder deduplicationHolder; private DeduplicationHolder deduplicationHolder;
@Autowired
private LogUtils logUtils;
@PostConstruct @PostConstruct
private void init() { private void init() {
deduplicationHolder.putService(deduplicationType, this); deduplicationHolder.putService(deduplicationType, this);
} }
@Autowired
private LogUtils logUtils;
@Override @Override
public void deduplication(DeduplicationParam param) { public void deduplication(DeduplicationParam param) {
TaskInfo taskInfo = param.getTaskInfo(); TaskInfo taskInfo = param.getTaskInfo();

@ -18,6 +18,8 @@ import org.springframework.stereotype.Service;
public class FrequencyDeduplicationService extends AbstractDeduplicationService { public class FrequencyDeduplicationService extends AbstractDeduplicationService {
private static final String PREFIX = "FRE";
@Autowired @Autowired
public FrequencyDeduplicationService(@Qualifier("SimpleLimitService") LimitService limitService) { public FrequencyDeduplicationService(@Qualifier("SimpleLimitService") LimitService limitService) {
@ -26,8 +28,6 @@ public class FrequencyDeduplicationService extends AbstractDeduplicationService
} }
private static final String PREFIX = "FRE";
/** /**
* key * key
* <p> * <p>

@ -16,24 +16,22 @@ import java.util.Objects;
* handler * handler
*/ */
public abstract class BaseHandler implements Handler { public abstract class BaseHandler implements Handler {
@Autowired
private HandlerHolder handlerHolder;
@Autowired
private LogUtils logUtils;
@Autowired
private FlowControlFactory flowControlFactory;
/** /**
* Code * Code
* *
*/ */
protected Integer channelCode; protected Integer channelCode;
/** /**
* *
* *
*/ */
protected FlowControlParam flowControlParam; protected FlowControlParam flowControlParam;
@Autowired
private HandlerHolder handlerHolder;
@Autowired
private LogUtils logUtils;
@Autowired
private FlowControlFactory flowControlFactory;
/** /**
* Handler * Handler
@ -43,21 +41,13 @@ public abstract class BaseHandler implements Handler {
handlerHolder.putHandler(channelCode, this); handlerHolder.putHandler(channelCode, this);
} }
/**
* @Override
* public void doHandler(TaskInfo taskInfo) {
* @param taskInfo
*/
public void flowControl(TaskInfo taskInfo) {
// 只有子类指定了限流参数,才需要限流 // 只有子类指定了限流参数,才需要限流
if (Objects.nonNull(flowControlParam)) { if (Objects.nonNull(flowControlParam)) {
flowControlFactory.flowControl(taskInfo, flowControlParam); flowControlFactory.flowControl(taskInfo, flowControlParam);
} }
}
@Override
public void doHandler(TaskInfo taskInfo) {
flowControl(taskInfo);
if (handler(taskInfo)) { if (handler(taskInfo)) {
logUtils.print(AnchorInfo.builder().state(AnchorState.SEND_SUCCESS.getCode()).bizId(taskInfo.getBizId()).messageId(taskInfo.getMessageId()).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; return;

@ -50,6 +50,8 @@ import java.util.concurrent.TimeUnit;
public class DingDingWorkNoticeHandler extends BaseHandler implements Handler { public class DingDingWorkNoticeHandler extends BaseHandler implements Handler {
private static final String DING_DING_RECALL_KEY_PREFIX = "RECALL_";
private static final String RECALL_BIZ_TYPE = "DingDingWorkNoticeHandler#recall";
@Autowired @Autowired
private AccountUtils accountUtils; private AccountUtils accountUtils;
@Autowired @Autowired
@ -63,9 +65,6 @@ public class DingDingWorkNoticeHandler extends BaseHandler implements Handler {
channelCode = ChannelType.DING_DING_WORK_NOTICE.getCode(); channelCode = ChannelType.DING_DING_WORK_NOTICE.getCode();
} }
private static final String DING_DING_RECALL_KEY_PREFIX = "RECALL_";
private static final String RECALL_BIZ_TYPE = "DingDingWorkNoticeHandler#recall";
@Override @Override
public boolean handler(TaskInfo taskInfo) { public boolean handler(TaskInfo taskInfo) {
try { try {

@ -16,7 +16,7 @@ import com.java3y.austin.handler.handler.Handler;
import com.java3y.austin.support.utils.AccountUtils; import com.java3y.austin.support.utils.AccountUtils;
import com.java3y.austin.support.utils.LogUtils; import com.java3y.austin.support.utils.LogUtils;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import me.chanjar.weixin.common.error.WxMpErrorMsgEnum; import me.chanjar.weixin.common.error.WxCpErrorMsgEnum;
import me.chanjar.weixin.cp.api.WxCpService; import me.chanjar.weixin.cp.api.WxCpService;
import me.chanjar.weixin.cp.api.impl.WxCpMessageServiceImpl; import me.chanjar.weixin.cp.api.impl.WxCpMessageServiceImpl;
import me.chanjar.weixin.cp.api.impl.WxCpServiceImpl; import me.chanjar.weixin.cp.api.impl.WxCpServiceImpl;
@ -55,7 +55,7 @@ public class EnterpriseWeChatHandler extends BaseHandler implements Handler {
WxCpDefaultConfigImpl accountConfig = accountUtils.getAccountById(taskInfo.getSendAccount(), WxCpDefaultConfigImpl.class); WxCpDefaultConfigImpl accountConfig = accountUtils.getAccountById(taskInfo.getSendAccount(), WxCpDefaultConfigImpl.class);
WxCpMessageServiceImpl messageService = new WxCpMessageServiceImpl(initService(accountConfig)); WxCpMessageServiceImpl messageService = new WxCpMessageServiceImpl(initService(accountConfig));
WxCpMessageSendResult result = messageService.send(buildWxCpMessage(taskInfo, accountConfig.getAgentId())); WxCpMessageSendResult result = messageService.send(buildWxCpMessage(taskInfo, accountConfig.getAgentId()));
if (Integer.valueOf(WxMpErrorMsgEnum.CODE_0.getCode()).equals(result.getErrCode())) { if (Integer.valueOf(WxCpErrorMsgEnum.CODE_0.getCode()).equals(result.getErrCode())) {
return true; return true;
} }
logUtils.print(AnchorInfo.builder().bizId(taskInfo.getBizId()).messageId(taskInfo.getMessageId()).businessId(taskInfo.getBusinessId()) logUtils.print(AnchorInfo.builder().bizId(taskInfo.getBizId()).messageId(taskInfo.getMessageId()).businessId(taskInfo.getBusinessId())

@ -19,6 +19,7 @@ import com.java3y.austin.handler.handler.Handler;
import com.java3y.austin.support.utils.AccountUtils; import com.java3y.austin.support.utils.AccountUtils;
import com.java3y.austin.support.utils.LogUtils; import com.java3y.austin.support.utils.LogUtils;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import me.chanjar.weixin.common.error.WxCpErrorMsgEnum;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@ -52,7 +53,7 @@ public class EnterpriseWeChatRobotHandler extends BaseHandler implements Handler
.timeout(2000) .timeout(2000)
.execute().body(); .execute().body();
EnterpriseWeChatRootResult weChatRootResult = JSON.parseObject(result, EnterpriseWeChatRootResult.class); EnterpriseWeChatRootResult weChatRootResult = JSON.parseObject(result, EnterpriseWeChatRootResult.class);
if (weChatRootResult.getErrcode() == 0) { if (Integer.valueOf(WxCpErrorMsgEnum.CODE_0.getCode()).equals(weChatRootResult.getErrcode())) {
return true; return true;
} }
logUtils.print(AnchorInfo.builder().bizId(taskInfo.getBizId()).messageId(taskInfo.getMessageId()).businessId(taskInfo.getBusinessId()) logUtils.print(AnchorInfo.builder().bizId(taskInfo.getBizId()).messageId(taskInfo.getMessageId()).businessId(taskInfo.getBusinessId())

@ -2,9 +2,9 @@ package com.java3y.austin.handler.handler.impl;
import cn.binarywang.wx.miniapp.api.WxMaService; import cn.binarywang.wx.miniapp.api.WxMaService;
import cn.binarywang.wx.miniapp.bean.WxMaSubscribeMessage; import cn.binarywang.wx.miniapp.bean.WxMaSubscribeMessage;
import cn.hutool.core.collection.CollUtil;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.google.common.base.Throwables; import com.google.common.base.Throwables;
import com.google.common.collect.Sets;
import com.java3y.austin.common.domain.AnchorInfo; import com.java3y.austin.common.domain.AnchorInfo;
import com.java3y.austin.common.domain.RecallTaskInfo; import com.java3y.austin.common.domain.RecallTaskInfo;
import com.java3y.austin.common.domain.TaskInfo; import com.java3y.austin.common.domain.TaskInfo;
@ -45,16 +45,13 @@ public class MiniProgramAccountHandler extends BaseHandler implements Handler {
try { try {
MiniProgramContentModel contentModel = (MiniProgramContentModel) taskInfo.getContentModel(); MiniProgramContentModel contentModel = (MiniProgramContentModel) taskInfo.getContentModel();
WxMaService wxMaService = accountUtils.getAccountById(taskInfo.getSendAccount(), WxMaService.class); WxMaService wxMaService = accountUtils.getAccountById(taskInfo.getSendAccount(), WxMaService.class);
List<WxMaSubscribeMessage> wxMaSubscribeMessages = assembleReq(taskInfo.getReceiver(), contentModel);
for (WxMaSubscribeMessage message : wxMaSubscribeMessages) { WxMaSubscribeMessage message = assembleReq(taskInfo.getReceiver(), contentModel);
try { wxMaService.getSubscribeService().sendSubscribeMsg(message);
wxMaService.getSubscribeService().sendSubscribeMsg(message);
} catch (WxErrorException e) {
logUtils.print(AnchorInfo.builder().bizId(taskInfo.getBizId()).messageId(taskInfo.getMessageId()).businessId(taskInfo.getBusinessId())
.ids(Sets.newHashSet(message.getToUser())).state(e.getError().getErrorCode()).build());
}
}
return true; return true;
} catch (WxErrorException e) {
logUtils.print(AnchorInfo.builder().bizId(taskInfo.getBizId()).messageId(taskInfo.getMessageId()).businessId(taskInfo.getBusinessId())
.ids(taskInfo.getReceiver()).state(e.getError().getErrorCode()).build());
} catch (Exception e) { } catch (Exception e) {
log.error("MiniProgramAccountHandler#handler fail:{},params:{}", Throwables.getStackTraceAsString(e), JSON.toJSONString(taskInfo)); log.error("MiniProgramAccountHandler#handler fail:{},params:{}", Throwables.getStackTraceAsString(e), JSON.toJSONString(taskInfo));
} }
@ -65,18 +62,13 @@ public class MiniProgramAccountHandler extends BaseHandler implements Handler {
/** /**
* *
*/ */
private List<WxMaSubscribeMessage> assembleReq(Set<String> receiver, MiniProgramContentModel contentModel) { private WxMaSubscribeMessage assembleReq(Set<String> receiver, MiniProgramContentModel contentModel) {
List<WxMaSubscribeMessage> messageList = new ArrayList<>(receiver.size()); return WxMaSubscribeMessage.builder()
for (String openId : receiver) { .toUser(CollUtil.getFirst(receiver.iterator()))
WxMaSubscribeMessage subscribeMessage = WxMaSubscribeMessage.builder() .data(getWxMaTemplateData(contentModel.getMiniProgramParam()))
.toUser(openId) .templateId(contentModel.getTemplateId())
.data(getWxMaTemplateData(contentModel.getMiniProgramParam())) .page(contentModel.getPage())
.templateId(contentModel.getTemplateId()) .build();
.page(contentModel.getPage())
.build();
messageList.add(subscribeMessage);
}
return messageList;
} }
/** /**

@ -1,8 +1,8 @@
package com.java3y.austin.handler.handler.impl; package com.java3y.austin.handler.handler.impl;
import cn.hutool.core.collection.CollUtil;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.google.common.base.Throwables; import com.google.common.base.Throwables;
import com.google.common.collect.Sets;
import com.java3y.austin.common.domain.AnchorInfo; import com.java3y.austin.common.domain.AnchorInfo;
import com.java3y.austin.common.domain.RecallTaskInfo; import com.java3y.austin.common.domain.RecallTaskInfo;
import com.java3y.austin.common.domain.TaskInfo; import com.java3y.austin.common.domain.TaskInfo;
@ -47,39 +47,31 @@ public class OfficialAccountHandler extends BaseHandler implements Handler {
try { try {
OfficialAccountsContentModel contentModel = (OfficialAccountsContentModel) taskInfo.getContentModel(); OfficialAccountsContentModel contentModel = (OfficialAccountsContentModel) taskInfo.getContentModel();
WxMpService wxMpService = accountUtils.getAccountById(taskInfo.getSendAccount(), WxMpService.class); WxMpService wxMpService = accountUtils.getAccountById(taskInfo.getSendAccount(), WxMpService.class);
List<WxMpTemplateMessage> messages = assembleReq(taskInfo.getReceiver(), contentModel);
for (WxMpTemplateMessage message : messages) { WxMpTemplateMessage message = assembleReq(taskInfo.getReceiver(), contentModel);
try { wxMpService.getTemplateMsgService().sendTemplateMsg(message);
wxMpService.getTemplateMsgService().sendTemplateMsg(message);
} catch (WxErrorException e) {
logUtils.print(AnchorInfo.builder().bizId(taskInfo.getBizId()).messageId(taskInfo.getMessageId()).businessId(taskInfo.getBusinessId())
.ids(Sets.newHashSet(message.getToUser())).state(e.getError().getErrorCode()).build());
}
}
return true; return true;
} catch (WxErrorException e) {
logUtils.print(AnchorInfo.builder().bizId(taskInfo.getBizId()).messageId(taskInfo.getMessageId()).businessId(taskInfo.getBusinessId())
.ids(taskInfo.getReceiver()).state(e.getError().getErrorCode()).build());
} catch (Exception e) { } catch (Exception e) {
log.error("OfficialAccountHandler#handler fail:{},params:{}", Throwables.getStackTraceAsString(e), JSON.toJSONString(taskInfo)); log.error("OfficialAccountHandler#handler fail:{},params:{}", Throwables.getStackTraceAsString(e), JSON.toJSONString(taskInfo));
} }
return false; return false;
} }
/** /**
* *
*/ */
private List<WxMpTemplateMessage> assembleReq(Set<String> receiver, OfficialAccountsContentModel contentModel) { private WxMpTemplateMessage assembleReq(Set<String> receiver, OfficialAccountsContentModel contentModel) {
List<WxMpTemplateMessage> wxMpTemplateMessages = new ArrayList<>(receiver.size()); return WxMpTemplateMessage.builder()
for (String openId : receiver) { .toUser(CollUtil.getFirst(receiver.iterator()))
WxMpTemplateMessage templateMessage = WxMpTemplateMessage.builder() .templateId(contentModel.getTemplateId())
.toUser(openId) .url(contentModel.getUrl())
.templateId(contentModel.getTemplateId()) .data(getWxMpTemplateData(contentModel.getOfficialAccountParam()))
.url(contentModel.getUrl()) .miniProgram(new WxMpTemplateMessage.MiniProgram(contentModel.getMiniProgramId(), contentModel.getPath(), false))
.data(getWxMpTemplateData(contentModel.getOfficialAccountParam())) .build();
.miniProgram(new WxMpTemplateMessage.MiniProgram(contentModel.getMiniProgramId(), contentModel.getPath(), false))
.build();
wxMpTemplateMessages.add(templateMessage);
}
return wxMpTemplateMessages;
} }
/** /**

@ -38,15 +38,14 @@ import java.util.Set;
@Slf4j @Slf4j
public class PushHandler extends BaseHandler implements Handler { public class PushHandler extends BaseHandler implements Handler {
public PushHandler() {
channelCode = ChannelType.PUSH.getCode();
}
@Autowired @Autowired
private AccountUtils accountUtils; private AccountUtils accountUtils;
@Autowired @Autowired
private AccessTokenUtils accessTokenUtils; private AccessTokenUtils accessTokenUtils;
public PushHandler() {
channelCode = ChannelType.PUSH.getCode();
}
@Override @Override
public boolean handler(TaskInfo taskInfo) { public boolean handler(TaskInfo taskInfo) {

@ -39,29 +39,24 @@ import java.util.Random;
@Slf4j @Slf4j
public class SmsHandler extends BaseHandler implements Handler { public class SmsHandler extends BaseHandler implements Handler {
public SmsHandler() { /**
channelCode = ChannelType.SMS.getCode(); *
} */
private static final Integer AUTO_FLOW_RULE = 0;
private static final String FLOW_KEY = "msgTypeSmsConfig";
private static final String FLOW_KEY_PREFIX = "message_type_";
@Autowired @Autowired
private SmsRecordDao smsRecordDao; private SmsRecordDao smsRecordDao;
@Autowired @Autowired
private ConfigService config; private ConfigService config;
@Autowired @Autowired
private ApplicationContext applicationContext; private ApplicationContext applicationContext;
@Autowired @Autowired
private AccountUtils accountUtils; private AccountUtils accountUtils;
/** public SmsHandler() {
* channelCode = ChannelType.SMS.getCode();
*/ }
private static final Integer AUTO_FLOW_RULE = 0;
private static final String FLOW_KEY = "msgTypeSmsConfig";
private static final String FLOW_KEY_PREFIX = "message_type_";
@Override @Override
public boolean handler(TaskInfo taskInfo) { public boolean handler(TaskInfo taskInfo) {

@ -2,7 +2,10 @@ package com.java3y.austin.handler.pending;
import cn.hutool.core.collection.CollUtil; import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.ObjectUtil;
import com.google.common.collect.Sets;
import com.java3y.austin.common.domain.TaskInfo; import com.java3y.austin.common.domain.TaskInfo;
import com.java3y.austin.common.enums.ChannelType;
import com.java3y.austin.handler.deduplication.DeduplicationRuleService; import com.java3y.austin.handler.deduplication.DeduplicationRuleService;
import com.java3y.austin.handler.discard.DiscardMessageService; import com.java3y.austin.handler.discard.DiscardMessageService;
import com.java3y.austin.handler.handler.HandlerHolder; import com.java3y.austin.handler.handler.HandlerHolder;
@ -63,6 +66,17 @@ public class Task implements Runnable {
// 3. 真正发送消息 // 3. 真正发送消息
if (CollUtil.isNotEmpty(taskInfo.getReceiver())) { if (CollUtil.isNotEmpty(taskInfo.getReceiver())) {
// 3.1 微信小程序&服务号只支持单人推送,为了后续逻辑统一处理,于是在这做了打散
if (ChannelType.MINI_PROGRAM.getCode().equals(taskInfo.getSendChannel())
|| ChannelType.OFFICIAL_ACCOUNT.getCode().equals(taskInfo.getSendChannel())) {
for (String receiver : taskInfo.getReceiver()) {
TaskInfo taskClone = ObjectUtil.cloneByStream(this.taskInfo);
taskClone.setReceiver(Sets.newHashSet(receiver));
handlerHolder.route(taskInfo.getSendChannel()).doHandler(taskClone);
}
return;
}
handlerHolder.route(taskInfo.getSendChannel()).doHandler(taskInfo); handlerHolder.route(taskInfo.getSendChannel()).doHandler(taskInfo);
} }

@ -21,15 +21,13 @@ import java.util.concurrent.ExecutorService;
*/ */
@Component @Component
public class TaskPendingHolder { public class TaskPendingHolder {
@Autowired
private ThreadPoolUtils threadPoolUtils;
private Map<String, ExecutorService> taskPendingHolder = new HashMap<>(32);
/** /**
* groupId * groupId
*/ */
private static List<String> groupIds = GroupIdMappingUtils.getAllGroupIds(); private static List<String> groupIds = GroupIdMappingUtils.getAllGroupIds();
@Autowired
private ThreadPoolUtils threadPoolUtils;
private Map<String, ExecutorService> taskPendingHolder = new HashMap<>(32);
/** /**
* 线 * 线

@ -32,35 +32,22 @@ import java.util.Optional;
@Slf4j @Slf4j
public class ReceiverStart { public class ReceiverStart {
@Autowired
private ApplicationContext context;
@Autowired
private ConsumerFactory consumerFactory;
/** /**
* receiver * receiver
*/ */
private static final String RECEIVER_METHOD_NAME = "Receiver.consumer"; private static final String RECEIVER_METHOD_NAME = "Receiver.consumer";
/** /**
* groupId * groupId
*/ */
private static List<String> groupIds = GroupIdMappingUtils.getAllGroupIds(); private static List<String> groupIds = GroupIdMappingUtils.getAllGroupIds();
/** /**
* (groupIds) * (groupIds)
*/ */
private static Integer index = 0; private static Integer index = 0;
@Autowired
/** private ApplicationContext context;
* Receiver @Autowired
*/ private ConsumerFactory consumerFactory;
@PostConstruct
public void init() {
for (int i = 0; i < groupIds.size(); i++) {
context.getBean(Receiver.class);
}
}
/** /**
* Receiverconsumer @KafkaListenergroupId * Receiverconsumer @KafkaListenergroupId
@ -78,6 +65,16 @@ public class ReceiverStart {
}; };
} }
/**
* Receiver
*/
@PostConstruct
public void init() {
for (int i = 0; i < groupIds.size(); i++) {
context.getBean(Receiver.class);
}
}
/** /**
* tag * tag
* producer tagheader * producer tagheader

@ -34,15 +34,12 @@ import java.util.stream.Collectors;
@Component("YunPianSmsScript") @Component("YunPianSmsScript")
public class YunPianSmsScript implements SmsScript { public class YunPianSmsScript implements SmsScript {
private static final String PARAMS_SPLIT_KEY = "{|}";
private static final String PARAMS_KV_SPLIT_KEY = "{:}";
private static Logger log = LoggerFactory.getLogger(YunPianSmsScript.class); private static Logger log = LoggerFactory.getLogger(YunPianSmsScript.class);
@Autowired @Autowired
private AccountUtils accountUtils; private AccountUtils accountUtils;
private static final String PARAMS_SPLIT_KEY = "{|}";
private static final String PARAMS_KV_SPLIT_KEY = "{:}";
@Override @Override
public List<SmsRecord> send(SmsParam smsParam) { public List<SmsRecord> send(SmsParam smsParam) {

@ -41,6 +41,42 @@ public class SendAssembleAction implements BusinessProcess<SendTaskModel> {
@Autowired @Autowired
private MessageTemplateDao messageTemplateDao; private MessageTemplateDao messageTemplateDao;
/**
* contentModelmsgContent
*/
private static ContentModel getContentModelValue(MessageTemplate messageTemplate, MessageParam messageParam) {
// 得到真正的ContentModel 类型
Integer sendChannel = messageTemplate.getSendChannel();
Class<? extends ContentModel> contentModelClass = ChannelType.getChanelModelClassByCode(sendChannel);
// 得到模板的 msgContent 和 入参
Map<String, String> variables = messageParam.getVariables();
JSONObject jsonObject = JSON.parseObject(messageTemplate.getMsgContent());
// 通过反射 组装出 contentModel
Field[] fields = ReflectUtil.getFields(contentModelClass);
ContentModel contentModel = ReflectUtil.newInstance(contentModelClass);
for (Field field : fields) {
String originValue = jsonObject.getString(field.getName());
if (StrUtil.isNotBlank(originValue)) {
String resultValue = ContentHolderUtil.replacePlaceHolder(originValue, variables);
Object resultObj = JSONUtil.isJsonObj(resultValue) ? JSONUtil.toBean(resultValue, field.getType()) : resultValue;
ReflectUtil.setFieldValue(contentModel, field, resultObj);
}
}
// 如果 url 字段存在则在url拼接对应的埋点参数
String url = (String) ReflectUtil.getFieldValue(contentModel, LINK_NAME);
if (StrUtil.isNotBlank(url)) {
String resultUrl = TaskInfoUtils.generateUrl(url, messageTemplate.getId(), messageTemplate.getTemplateType());
ReflectUtil.setFieldValue(contentModel, LINK_NAME, resultUrl);
}
return contentModel;
}
@Override @Override
public void process(ProcessContext<SendTaskModel> context) { public void process(ProcessContext<SendTaskModel> context) {
SendTaskModel sendTaskModel = context.getProcessModel(); SendTaskModel sendTaskModel = context.getProcessModel();
@ -97,41 +133,4 @@ public class SendAssembleAction implements BusinessProcess<SendTaskModel> {
return taskInfoList; return taskInfoList;
} }
/**
* contentModelmsgContent
*/
private static ContentModel getContentModelValue(MessageTemplate messageTemplate, MessageParam messageParam) {
// 得到真正的ContentModel 类型
Integer sendChannel = messageTemplate.getSendChannel();
Class<? extends ContentModel> contentModelClass = ChannelType.getChanelModelClassByCode(sendChannel);
// 得到模板的 msgContent 和 入参
Map<String, String> variables = messageParam.getVariables();
JSONObject jsonObject = JSON.parseObject(messageTemplate.getMsgContent());
// 通过反射 组装出 contentModel
Field[] fields = ReflectUtil.getFields(contentModelClass);
ContentModel contentModel = ReflectUtil.newInstance(contentModelClass);
for (Field field : fields) {
String originValue = jsonObject.getString(field.getName());
if (StrUtil.isNotBlank(originValue)) {
String resultValue = ContentHolderUtil.replacePlaceHolder(originValue, variables);
Object resultObj = JSONUtil.isJsonObj(resultValue) ? JSONUtil.toBean(resultValue, field.getType()) : resultValue;
ReflectUtil.setFieldValue(contentModel, field, resultObj);
}
}
// 如果 url 字段存在则在url拼接对应的埋点参数
String url = (String) ReflectUtil.getFieldValue(contentModel, LINK_NAME);
if (StrUtil.isNotBlank(url)) {
String resultUrl = TaskInfoUtils.generateUrl(url, messageTemplate.getId(), messageTemplate.getTemplateType());
ReflectUtil.setFieldValue(contentModel, LINK_NAME, resultUrl);
}
return contentModel;
}
} }

@ -22,24 +22,21 @@ import java.util.concurrent.ExecutorService;
@Accessors(chain = true) @Accessors(chain = true)
public class PendingParam<T> { public class PendingParam<T> {
/**
* 线
*/
protected ExecutorService executorService;
/** /**
* *
*/ */
private BlockingQueue<T> queue; private BlockingQueue<T> queue;
/** /**
* batch * batch
*/ */
private Integer numThreshold; private Integer numThreshold;
/** /**
* batch * batch
*/ */
private Long timeThreshold; private Long timeThreshold;
/**
* 线
*/
protected ExecutorService executorService;
} }

@ -18,25 +18,21 @@ import lombok.experimental.Accessors;
@Builder @Builder
@Accessors(chain = true) @Accessors(chain = true)
public class ProcessContext<T extends ProcessModel> { public class ProcessContext<T extends ProcessModel> {
/** /**
* code * code
*/ */
private String code; private String code;
/** /**
* *
*/ */
private T processModel; private T processModel;
/** /**
* *
*/ */
private Boolean needBreak; private Boolean needBreak;
/** /**
* *
*/ */
BasicResultVO response; private BasicResultVO response;
} }

@ -22,16 +22,14 @@ import java.util.Properties;
@Slf4j @Slf4j
@Component @Component
public class NacosUtils { public class NacosUtils {
private final Properties properties = new Properties();
@NacosInjected @NacosInjected
private ConfigService configService; private ConfigService configService;
@Value("${nacos.group}") @Value("${nacos.group}")
private String nacosGroup; private String nacosGroup;
@Value("${nacos.data-id}") @Value("${nacos.data-id}")
private String nacosDataId; private String nacosDataId;
private final Properties properties = new Properties();
public String getProperty(String key, String defaultValue) { public String getProperty(String key, String defaultValue) {
try { try {
String property = this.getContext(); String property = this.getContext();

@ -14,12 +14,10 @@ import org.springframework.stereotype.Component;
@Component @Component
public class ThreadPoolUtils { public class ThreadPoolUtils {
private static final String SOURCE_NAME = "austin";
@Autowired @Autowired
private ThreadPoolExecutorShutdownDefinition shutdownDefinition; private ThreadPoolExecutorShutdownDefinition shutdownDefinition;
private static final String SOURCE_NAME = "austin";
/** /**
* 1. 线 线 * 1. 线 线
* 2. 线 Spring * 2. 线 Spring

@ -33,13 +33,12 @@ import java.util.List;
@Component @Component
public class AustinAspect { public class AustinAspect {
@Autowired
private HttpServletRequest request;
/** /**
* KEY * KEY
*/ */
private final String REQUEST_ID_KEY = "request_unique_id"; private final String REQUEST_ID_KEY = "request_unique_id";
@Autowired
private HttpServletRequest request;
/** /**
* AustinAspect * AustinAspect

@ -21,6 +21,7 @@ import com.java3y.austin.support.domain.SmsRecord;
import com.java3y.austin.support.utils.RedisUtils; import com.java3y.austin.support.utils.RedisUtils;
import com.java3y.austin.support.utils.TaskInfoUtils; import com.java3y.austin.support.utils.TaskInfoUtils;
import com.java3y.austin.web.service.DataService; import com.java3y.austin.web.service.DataService;
import com.java3y.austin.web.utils.AnchorStateUtils;
import com.java3y.austin.web.utils.Convert4Amis; import com.java3y.austin.web.utils.Convert4Amis;
import com.java3y.austin.web.vo.DataParam; import com.java3y.austin.web.vo.DataParam;
import com.java3y.austin.web.vo.amis.EchartsVo; import com.java3y.austin.web.vo.amis.EchartsVo;
@ -91,7 +92,7 @@ public class DataServiceImpl implements DataService {
*/ */
Map<Object, Object> anchorResult = redisUtils.hGetAll(getRealBusinessId(businessId)); Map<Object, Object> anchorResult = redisUtils.hGetAll(getRealBusinessId(businessId));
return Convert4Amis.getEchartsVo(anchorResult, optional.get().getName(), businessId); return Convert4Amis.getEchartsVo(anchorResult, optional.get(), businessId);
} }
@Override @Override
@ -151,7 +152,8 @@ public class DataServiceImpl implements DataService {
sb.append(StrPool.CRLF); sb.append(StrPool.CRLF);
} }
String startTime = DateUtil.format(new Date(simpleAnchorInfo.getTimestamp()), DatePattern.NORM_DATETIME_PATTERN); String startTime = DateUtil.format(new Date(simpleAnchorInfo.getTimestamp()), DatePattern.NORM_DATETIME_PATTERN);
String stateDescription = EnumUtil.getDescriptionByCode(simpleAnchorInfo.getState(), AnchorState.class); String stateDescription = AnchorStateUtils.getDescriptionByState(messageTemplate.getSendChannel(), simpleAnchorInfo.getState());
sb.append(startTime).append(StrPool.C_COLON).append(stateDescription).append("==>"); sb.append(startTime).append(StrPool.C_COLON).append(stateDescription).append("==>");
} }

@ -30,7 +30,6 @@ import me.chanjar.weixin.common.bean.result.WxMediaUploadResult;
import me.chanjar.weixin.cp.api.impl.WxCpServiceImpl; import me.chanjar.weixin.cp.api.impl.WxCpServiceImpl;
import me.chanjar.weixin.cp.config.impl.WxCpDefaultConfigImpl; import me.chanjar.weixin.cp.config.impl.WxCpDefaultConfigImpl;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartFile;

@ -0,0 +1,41 @@
package com.java3y.austin.web.utils;
import cn.hutool.core.util.StrUtil;
import com.java3y.austin.common.enums.AnchorState;
import com.java3y.austin.common.enums.ChannelType;
import com.java3y.austin.common.enums.EnumUtil;
import me.chanjar.weixin.common.error.WxCpErrorMsgEnum;
import me.chanjar.weixin.common.error.WxMaErrorMsgEnum;
import me.chanjar.weixin.common.error.WxMpErrorMsgEnum;
/**
* @author 3y
* AnchorStateUtils
*/
public class AnchorStateUtils {
/**
*
*
* @param channel
* @param state
* @return
*/
public static String getDescriptionByState(Integer channel, Integer state) {
String stateDescription = EnumUtil.getDescriptionByCode(state, AnchorState.class);
// 如果 AnchorState 找不到对应的点位描述,那就是在对应渠道的点位信息
if (StrUtil.isBlank(stateDescription)) {
if (ChannelType.MINI_PROGRAM.getCode().equals(channel)) {
stateDescription = WxMaErrorMsgEnum.findMsgByCode(state);
} else if (ChannelType.OFFICIAL_ACCOUNT.getCode().equals(channel)) {
stateDescription = WxMpErrorMsgEnum.findMsgByCode(state);
} else if (ChannelType.ENTERPRISE_WE_CHAT.getCode().equals(channel)) {
stateDescription = WxCpErrorMsgEnum.findMsgByCode(state);
}
}
return stateDescription;
}
}

@ -8,11 +8,11 @@ import cn.hutool.core.util.ReflectUtil;
import cn.hutool.core.util.StrUtil; import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.java3y.austin.common.enums.AnchorState;
import com.java3y.austin.common.enums.ChannelType; import com.java3y.austin.common.enums.ChannelType;
import com.java3y.austin.common.enums.EnumUtil; import com.java3y.austin.common.enums.EnumUtil;
import com.java3y.austin.common.enums.SmsStatus; import com.java3y.austin.common.enums.SmsStatus;
import com.java3y.austin.support.domain.ChannelAccount; import com.java3y.austin.support.domain.ChannelAccount;
import com.java3y.austin.support.domain.MessageTemplate;
import com.java3y.austin.support.domain.SmsRecord; import com.java3y.austin.support.domain.SmsRecord;
import com.java3y.austin.support.utils.TaskInfoUtils; import com.java3y.austin.support.utils.TaskInfoUtils;
import com.java3y.austin.web.vo.amis.CommonAmisVo; import com.java3y.austin.web.vo.amis.CommonAmisVo;
@ -386,19 +386,19 @@ public class Convert4Amis {
* @param businessId * @param businessId
* @return * @return
*/ */
public static EchartsVo getEchartsVo(Map<Object, Object> anchorResult, String templateName, String businessId) { public static EchartsVo getEchartsVo(Map<Object, Object> anchorResult, MessageTemplate messageTemplate, String businessId) {
List<String> xAxisList = new ArrayList<>(); List<String> xAxisList = new ArrayList<>();
List<Integer> actualData = new ArrayList<>(); List<Integer> actualData = new ArrayList<>();
if (CollUtil.isNotEmpty(anchorResult)) { if (CollUtil.isNotEmpty(anchorResult)) {
anchorResult = MapUtil.sort(anchorResult); anchorResult = MapUtil.sort(anchorResult);
for (Map.Entry<Object, Object> entry : anchorResult.entrySet()) { for (Map.Entry<Object, Object> entry : anchorResult.entrySet()) {
String description = EnumUtil.getDescriptionByCode(Integer.valueOf(String.valueOf(entry.getKey())), AnchorState.class); String description = AnchorStateUtils.getDescriptionByState(messageTemplate.getSendChannel(), Integer.valueOf(String.valueOf(entry.getKey())));
xAxisList.add(description); xAxisList.add(description);
actualData.add(Integer.valueOf(String.valueOf(entry.getValue()))); actualData.add(Integer.valueOf(String.valueOf(entry.getValue())));
} }
} }
String title = "【" + templateName + "】在" + DateUtil.format(DateUtil.parse(String.valueOf(TaskInfoUtils.getDateFromBusinessId(Long.valueOf(businessId)))), DatePattern.CHINESE_DATE_FORMATTER) + "的下发情况:"; String title = "【" + messageTemplate.getName() + "】在" + DateUtil.format(DateUtil.parse(String.valueOf(TaskInfoUtils.getDateFromBusinessId(Long.valueOf(businessId)))), DatePattern.CHINESE_DATE_FORMATTER) + "的下发情况:";
return EchartsVo.builder() return EchartsVo.builder()
.title(EchartsVo.TitleVO.builder().text(title).build()) .title(EchartsVo.TitleVO.builder().text(title).build())

Loading…
Cancel
Save