mirror of https://github.com/ZhongFuCheng3y/austin
parent
5cf63b7661
commit
246e325e65
@ -1,51 +0,0 @@
|
||||
package com.java3y.austin.handler.receipt;
|
||||
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.dingtalk.api.DefaultDingTalkClient;
|
||||
import com.dingtalk.api.DingTalkClient;
|
||||
import com.dingtalk.api.request.OapiMessageCorpconversationGetsendresultRequest;
|
||||
import com.dingtalk.api.response.OapiMessageCorpconversationGetsendresultResponse;
|
||||
import com.java3y.austin.common.constant.SendAccountConstant;
|
||||
import com.java3y.austin.common.dto.account.DingDingWorkNoticeAccount;
|
||||
import com.java3y.austin.support.utils.AccountUtils;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.redis.core.StringRedisTemplate;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* 拉取钉钉工作消息回执信息
|
||||
*
|
||||
* @author 3y
|
||||
*/
|
||||
@Component
|
||||
@Slf4j
|
||||
public class DingDingWorkReceipt {
|
||||
|
||||
private static final String URL = "https://oapi.dingtalk.com/topapi/message/corpconversation/getsendresult";
|
||||
@Autowired
|
||||
private StringRedisTemplate redisTemplate;
|
||||
|
||||
@Autowired
|
||||
private AccountUtils accountUtils;
|
||||
public void pull() {
|
||||
// try {
|
||||
// for (int index = SendAccountConstant.START; true; index = index + SendAccountConstant.STEP) {
|
||||
// DingDingWorkNoticeAccount account = accountUtils.getAccountById(index, SendAccountConstant.DING_DING_WORK_NOTICE_ACCOUNT_KEY, SendAccountConstant.DING_DING_WORK_NOTICE_PREFIX, DingDingWorkNoticeAccount.class);
|
||||
// if (account == null) {
|
||||
// break;
|
||||
// }
|
||||
// String accessToken = redisTemplate.opsForValue().get(SendAccountConstant.DING_DING_ACCESS_TOKEN_PREFIX + index);
|
||||
// DingTalkClient client = new DefaultDingTalkClient(URL);
|
||||
// OapiMessageCorpconversationGetsendresultRequest req = new OapiMessageCorpconversationGetsendresultRequest();
|
||||
// req.setAgentId(Long.valueOf(account.getAgentId()));
|
||||
// req.setTaskId(456L);
|
||||
// OapiMessageCorpconversationGetsendresultResponse rsp = client.execute(req, accessToken);
|
||||
// System.out.println(rsp.getBody());
|
||||
// }
|
||||
// } catch (Exception e) {
|
||||
// log.error("DingDingWorkReceipt#pull");
|
||||
// }
|
||||
}
|
||||
}
|
@ -0,0 +1,14 @@
|
||||
package com.java3y.austin.handler.receipt.stater;
|
||||
|
||||
/**
|
||||
* 拉取回执信息 启动器
|
||||
*
|
||||
* @author 3y
|
||||
*/
|
||||
public interface ReceiptMessageStater {
|
||||
|
||||
/**
|
||||
* 启动拉取回执
|
||||
*/
|
||||
void start();
|
||||
}
|
@ -0,0 +1,33 @@
|
||||
package com.java3y.austin.handler.receipt.stater.impl;
|
||||
|
||||
import com.java3y.austin.common.constant.CommonConstant;
|
||||
import com.java3y.austin.common.enums.ChannelType;
|
||||
import com.java3y.austin.handler.handler.impl.DingDingWorkNoticeHandler;
|
||||
import com.java3y.austin.handler.receipt.stater.ReceiptMessageStater;
|
||||
import com.java3y.austin.support.dao.ChannelAccountDao;
|
||||
import com.java3y.austin.support.domain.ChannelAccount;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 拉取 钉钉工作消息的回执 内容 【未完成】
|
||||
*
|
||||
* @author 3y
|
||||
*/
|
||||
public class DingDingWorkReceiptStaterImpl implements ReceiptMessageStater {
|
||||
|
||||
@Autowired
|
||||
private DingDingWorkNoticeHandler workNoticeHandler;
|
||||
|
||||
@Autowired
|
||||
private ChannelAccountDao channelAccountDao;
|
||||
|
||||
@Override
|
||||
public void start() {
|
||||
List<ChannelAccount> accountList = channelAccountDao.findAllByIsDeletedEqualsAndSendChannelEquals(CommonConstant.FALSE, ChannelType.DING_DING_WORK_NOTICE.getCode());
|
||||
for (ChannelAccount channelAccount : accountList) {
|
||||
workNoticeHandler.pull(channelAccount.getId());
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,60 @@
|
||||
package com.java3y.austin.handler.receipt.stater.impl;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.google.common.base.Throwables;
|
||||
import com.java3y.austin.common.constant.CommonConstant;
|
||||
import com.java3y.austin.common.dto.account.sms.SmsAccount;
|
||||
import com.java3y.austin.common.enums.ChannelType;
|
||||
import com.java3y.austin.handler.receipt.stater.ReceiptMessageStater;
|
||||
import com.java3y.austin.handler.script.SmsScript;
|
||||
import com.java3y.austin.support.dao.ChannelAccountDao;
|
||||
import com.java3y.austin.support.dao.SmsRecordDao;
|
||||
import com.java3y.austin.support.domain.ChannelAccount;
|
||||
import com.java3y.austin.support.domain.SmsRecord;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
/**
|
||||
* 拉取短信回执信息
|
||||
*
|
||||
* @author 3y
|
||||
*/
|
||||
@Component
|
||||
@Slf4j
|
||||
public class SmsPullReceiptStarterImpl implements ReceiptMessageStater {
|
||||
|
||||
@Autowired
|
||||
private ChannelAccountDao channelAccountDao;
|
||||
|
||||
@Autowired
|
||||
private Map<String, SmsScript> scriptMap;
|
||||
|
||||
@Autowired
|
||||
private SmsRecordDao smsRecordDao;
|
||||
|
||||
/**
|
||||
* 拉取消息并入库
|
||||
*/
|
||||
public void start() {
|
||||
try {
|
||||
List<ChannelAccount> channelAccountList = channelAccountDao.findAllByIsDeletedEqualsAndSendChannelEquals(CommonConstant.FALSE, ChannelType.SMS.getCode());
|
||||
for (ChannelAccount channelAccount : channelAccountList) {
|
||||
SmsAccount smsAccount = JSON.parseObject(channelAccount.getAccountConfig(), SmsAccount.class);
|
||||
List<SmsRecord> smsRecordList = scriptMap.get(smsAccount.getScriptName()).pull(smsAccount.getScriptName());
|
||||
if (CollUtil.isNotEmpty(smsRecordList)) {
|
||||
smsRecordDao.saveAll(smsRecordList);
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("SmsPullReceiptStarter#start fail:{}", Throwables.getStackTraceAsString(e));
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -1,42 +0,0 @@
|
||||
package com.java3y.austin.handler.script;
|
||||
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.ArrayUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import java.lang.annotation.Annotation;
|
||||
|
||||
/**
|
||||
* sms发送脚本的抽象类
|
||||
*
|
||||
* @author 3y
|
||||
*/
|
||||
@Slf4j
|
||||
public abstract class BaseSmsScript implements SmsScript {
|
||||
|
||||
@Autowired
|
||||
private SmsScriptHolder smsScriptHolder;
|
||||
|
||||
@PostConstruct
|
||||
public void registerProcessScript() {
|
||||
if (ArrayUtils.isEmpty(this.getClass().getAnnotations())) {
|
||||
log.error("BaseSmsScript can not find annotation!");
|
||||
return;
|
||||
}
|
||||
Annotation handlerAnnotations = null;
|
||||
for (Annotation annotation : this.getClass().getAnnotations()) {
|
||||
if (annotation instanceof SmsScriptHandler) {
|
||||
handlerAnnotations = annotation;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (handlerAnnotations == null) {
|
||||
log.error("handler annotations not declared");
|
||||
return;
|
||||
}
|
||||
//注册handler
|
||||
smsScriptHolder.putHandler(((SmsScriptHandler) handlerAnnotations).value(), this);
|
||||
}
|
||||
}
|
@ -1,27 +0,0 @@
|
||||
package com.java3y.austin.handler.script;
|
||||
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
|
||||
/**
|
||||
* 标识 短信渠道
|
||||
*
|
||||
* @author 3y
|
||||
*/
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target({ElementType.TYPE})
|
||||
@Component
|
||||
public @interface SmsScriptHandler {
|
||||
|
||||
/**
|
||||
* 这里输入脚本名
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
String value();
|
||||
}
|
@ -1,25 +0,0 @@
|
||||
package com.java3y.austin.handler.script;
|
||||
|
||||
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* sendAccount->SmsScript的映射关系
|
||||
*
|
||||
* @author 3y
|
||||
*/
|
||||
@Component
|
||||
public class SmsScriptHolder {
|
||||
|
||||
private Map<String, SmsScript> handlers = new HashMap<>(8);
|
||||
|
||||
public void putHandler(String scriptName, SmsScript handler) {
|
||||
handlers.put(scriptName, handler);
|
||||
}
|
||||
public SmsScript route(String scriptName) {
|
||||
return handlers.get(scriptName);
|
||||
}
|
||||
}
|
Loading…
Reference in new issue