ConversationArchiveTask.java
2.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package com.linkwechat.quartz.task;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.linkwechat.common.constant.WeConstans;
import com.linkwechat.common.core.domain.entity.WeCorpAccount;
import com.linkwechat.common.core.redis.RedisCache;
import com.linkwechat.common.utils.StringUtils;
import com.linkwechat.wecom.domain.WeChatContactMsg;
import com.linkwechat.wecom.service.IWeChatContactMsgService;
import com.linkwechat.wecom.service.IWeCorpAccountService;
import com.tencent.wework.FinanceService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
/**
* @author danmo
* @description 会话存档定时任务
* @date 2021/7/26 15:50
**/
@Slf4j
@Component("conversationArchiveTask")
public class ConversationArchiveTask {
@Autowired
private RedisCache redisCache;
@Autowired
private IWeCorpAccountService weCorpAccountService;
@Autowired
private IWeChatContactMsgService weChatContactMsgService;
public void FinanceTask(String corpId, String secret, String privateKey){
log.info("执行有参方法: params:{},{}", corpId, secret);
Long seqLong = 0L;
log.info(">>>>>>>seq:{}", seqLong);
if(StringUtils.isEmpty(privateKey)){
WeCorpAccount validWeCorpAccount = weCorpAccountService.findValidWeCorpAccount();
privateKey = validWeCorpAccount.getFinancePrivateKey();
}
LambdaQueryWrapper<WeChatContactMsg> wrapper = new LambdaQueryWrapper<WeChatContactMsg>().orderByDesc(WeChatContactMsg::getSeq).last("limit 1");
WeChatContactMsg weChatContactMsg = weChatContactMsgService.getOne(wrapper);
if(weChatContactMsg != null){
seqLong = weChatContactMsg.getSeq();
}
FinanceService financeService = new FinanceService(corpId,secret,privateKey);
financeService.getChatData(seqLong,(data) -> redisCache.convertAndSend(WeConstans.CONVERSATION_MSG_CHANNEL,data));
}
}