|
@@ -3,6 +3,7 @@ package com.idiot.operationbackend.service.impl;
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
|
|
|
import com.google.common.cache.*;
|
|
|
import com.idiot.operationbackend.config.PlatformProperties;
|
|
|
import com.idiot.operationbackend.entity.Account;
|
|
@@ -11,6 +12,7 @@ import com.idiot.operationbackend.entity.AccountTag;
|
|
|
import com.idiot.operationbackend.handler.SyncUserTask;
|
|
|
import com.idiot.operationbackend.service.facade.AccountFansService;
|
|
|
import com.idiot.operationbackend.service.facade.AccountService;
|
|
|
+import com.idiot.operationbackend.service.facade.AccountTagService;
|
|
|
import com.idiot.operationbackend.service.facade.WeChatService;
|
|
|
import com.idiot.operationbackend.support.Constants;
|
|
|
import com.idiot.operationbackend.support.CustomException;
|
|
@@ -71,6 +73,9 @@ public class WeChatServiceImpl implements WeChatService, InitializingBean {
|
|
|
@Autowired
|
|
|
private AccountFansService fansService;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private AccountTagService tagService;
|
|
|
+
|
|
|
|
|
|
@Override
|
|
|
public String notice(Map<String, String> param) {
|
|
@@ -308,7 +313,12 @@ public class WeChatServiceImpl implements WeChatService, InitializingBean {
|
|
|
@Async("asyncExecutor")
|
|
|
public void syncUserTask(String accountId, List<String> openIds) {
|
|
|
|
|
|
- List<AccountFans> accountFans = new ArrayList<>(openIds.size());
|
|
|
+ if (CollectionUtils.isEmpty(openIds)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ int size = openIds.size();
|
|
|
+ logger.info("公众号:{}同步粉丝请求粉丝信息,openId 大小:{}---- start,时间:{}",accountId,size,LocalDateTime.now().toString());
|
|
|
+ List<AccountFans> accountFans = new ArrayList<>(size);
|
|
|
|
|
|
for (String openId : openIds) {
|
|
|
AccountFans fans = fansService.queryByAccountIdAndOpenId(accountId,openId);
|
|
@@ -332,6 +342,7 @@ public class WeChatServiceImpl implements WeChatService, InitializingBean {
|
|
|
fans.setTagIdList(JSONObject.toJSONString(fansObject.getJSONObject("tagid_list")));
|
|
|
accountFans.add(fans);
|
|
|
}
|
|
|
+ logger.info("公众号:{}同步粉丝请求粉丝信息,openId 大小:{}---- end,时间:{}",accountId,size,LocalDateTime.now().toString());
|
|
|
// 保存用户
|
|
|
fansService.saveOrUpdateBatch(accountFans,1000);
|
|
|
}
|
|
@@ -340,12 +351,14 @@ public class WeChatServiceImpl implements WeChatService, InitializingBean {
|
|
|
@Override
|
|
|
@Async("asyncExecutor")
|
|
|
public void syncTag(String accountId) {
|
|
|
+
|
|
|
String lockKey = String.format(Constants.LOCK_SYNC_TAG,accountId);
|
|
|
String cacheValue = cache.getIfPresent(lockKey);
|
|
|
if (!StringUtils.isEmpty(cacheValue)) {
|
|
|
throw new CustomException(500,"");
|
|
|
}
|
|
|
cache.put(lockKey,lockKey);
|
|
|
+ logger.info("公众号:{}同步标签 ---- start,时间:{}",accountId,LocalDateTime.now().toString());
|
|
|
String requestUrl = "https://api.weixin.qq.com/cgi-bin/tags/get?access_token=%s";
|
|
|
String accessToken = getAuthorizerAccessToken(accountId);
|
|
|
HttpHeaders headers = new HttpHeaders();
|
|
@@ -369,13 +382,16 @@ public class WeChatServiceImpl implements WeChatService, InitializingBean {
|
|
|
tempTag.setCreateTime(createTime);
|
|
|
accountTags.add(tempTag);
|
|
|
}
|
|
|
+ logger.info("公众号:{}同步标签 ---- end,时间:{}",accountId,LocalDateTime.now().toString());
|
|
|
+ // 新增 多余的 删掉缺少的 俗称覆盖
|
|
|
+ boolean ifOverlay = tagService.overlayAccountTag(accountId,accountTags);
|
|
|
cache.invalidate(lockKey);
|
|
|
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public String getFansInfo(String accountId, String openId) {
|
|
|
- logger.info("查询粉丝信息,opendId:{}----start,时间:{}",accountId, LocalDateTime.now().toString());
|
|
|
+ logger.info("查询粉丝信息,openId:{}----start,时间:{}",accountId, LocalDateTime.now().toString());
|
|
|
String requestUrl = "https://api.weixin.qq.com/cgi-bin/user/info?access_token=%s&openid=OPENID&lang=zh_CN";
|
|
|
String accessToken = getAuthorizerAccessToken(accountId);
|
|
|
requestUrl = String.format(requestUrl,accessToken);
|