|
|
@@ -2,30 +2,47 @@ package com.fs.qw.service.impl;
|
|
|
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.fs.common.core.domain.R;
|
|
|
import com.fs.common.core.redis.RedisCache;
|
|
|
import com.fs.common.exception.CustomException;
|
|
|
+import com.fs.common.service.ISmsService;
|
|
|
import com.fs.common.utils.DateUtils;
|
|
|
import com.fs.common.utils.StringUtils;
|
|
|
+import com.fs.company.domain.CompanySms;
|
|
|
+import com.fs.company.domain.CompanySmsTemp;
|
|
|
+import com.fs.company.service.ICompanySmsService;
|
|
|
+import com.fs.company.service.ICompanySmsTempService;
|
|
|
import com.fs.fastgptApi.util.HttpUtil;
|
|
|
+import com.fs.his.dto.SendResultDetailDTO;
|
|
|
+import com.fs.qw.bo.SendMsgLogBo;
|
|
|
import com.fs.qw.domain.QwAcquisitionAssistant;
|
|
|
import com.fs.qw.domain.QwCompany;
|
|
|
+import com.fs.qw.domain.QwContactAcquisitionUser;
|
|
|
import com.fs.qw.dto.acquisition.*;
|
|
|
+import com.fs.qw.enums.SmsLogType;
|
|
|
import com.fs.qw.mapper.QwAcquisitionAssistantMapper;
|
|
|
import com.fs.qw.service.IQwAcquisitionAssistantService;
|
|
|
import com.fs.qw.service.IQwCompanyService;
|
|
|
+import com.fs.qw.service.IQwContactAcquisitionUserService;
|
|
|
import com.fs.qw.utils.UniqueStringUtil;
|
|
|
import com.fs.qw.vo.AcquisitionAssistantDetailVO;
|
|
|
import com.fs.qwApi.config.QwApiConfig;
|
|
|
+import com.fs.qwApi.domain.QwResult;
|
|
|
+import com.fs.qwApi.param.QwLinkCreateParam;
|
|
|
+import com.fs.qwApi.service.QwApiService;
|
|
|
import com.fs.wx.kf.service.IWeixinKfService;
|
|
|
import com.fs.wx.kf.vo.WeixinKfTokenVO;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.data.redis.core.RedisTemplate;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
import org.springframework.util.CollectionUtils;
|
|
|
|
|
|
import java.util.*;
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
* 企微-获客链接管理Service业务层处理
|
|
|
@@ -37,6 +54,9 @@ public class QwAcquisitionAssistantServiceImpl implements IQwAcquisitionAssistan
|
|
|
@Autowired
|
|
|
private QwAcquisitionAssistantMapper qwAcquisitionAssistantMapper;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private QwAcquisitionAssistantMapper acquisitionAssistantMapper;
|
|
|
+
|
|
|
@Autowired
|
|
|
private IWeixinKfService weixinKfService;
|
|
|
|
|
|
@@ -46,6 +66,25 @@ public class QwAcquisitionAssistantServiceImpl implements IQwAcquisitionAssistan
|
|
|
@Autowired
|
|
|
private IQwCompanyService qwCompanyService;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private ICompanySmsTempService smsTempService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private ICompanySmsService companySmsService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private ISmsService smsService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private IQwContactAcquisitionUserService insertQwContactWayUser;
|
|
|
+
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private RedisTemplate redisTemplate;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private QwApiService qwApiService;
|
|
|
+
|
|
|
|
|
|
// 获客链接管理-企微的ACCESS_TOKEN的key
|
|
|
private static final String QW_ACQUISITION_KEY_PREFIX = "qw:acquisition:key:";
|
|
|
@@ -54,6 +93,13 @@ public class QwAcquisitionAssistantServiceImpl implements IQwAcquisitionAssistan
|
|
|
// 获客链接-页面参数-url的key
|
|
|
private static final String QW_ACQUISITION_URL_KEY_PREFIX = "qw:acquisition:url:key:";
|
|
|
|
|
|
+ //获客链接短信模板code
|
|
|
+ private static final String SMS_LINK_TEMPLATE_CODE = "获客链接短信模板";
|
|
|
+
|
|
|
+
|
|
|
+ //访问链接域名(待优化)
|
|
|
+ private static final String LINK_DOMAIN = "";
|
|
|
+
|
|
|
/**
|
|
|
* 获取access_token并返回完整URL
|
|
|
*/
|
|
|
@@ -241,6 +287,147 @@ public class QwAcquisitionAssistantServiceImpl implements IQwAcquisitionAssistan
|
|
|
return list;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public SendResultDetailDTO sendMessageAcquisition(String phone, Long qwAcquisitionId, SendMsgLogBo sendMsgLogBo) {
|
|
|
+ log.info("发送获客链接短信,号码:{}", phone);
|
|
|
+
|
|
|
+ // 1. 获取短信模板
|
|
|
+ CompanySmsTemp temp = smsTempService.selectCompanySmsTempByCode(SMS_LINK_TEMPLATE_CODE);
|
|
|
+ if (temp == null) {
|
|
|
+ log.info("获客链接-未找到短信模板:{}", SMS_LINK_TEMPLATE_CODE);
|
|
|
+ throw new CustomException("获客链接-未找到短信模板");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 2. 获取获客链接信息
|
|
|
+ String originalContent = temp.getContent();
|
|
|
+ QwAcquisitionAssistant acquisitionAssistant = qwAcquisitionAssistantMapper.selectQwAcquisitionAssistantById(qwAcquisitionId);
|
|
|
+ if (acquisitionAssistant == null) {
|
|
|
+ log.info("获客链接-未找到获客链接id:{}", qwAcquisitionId);
|
|
|
+ throw new CustomException("获客链接-未找到获客链接信息");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 3. 构建短信内容
|
|
|
+ String replaceText = LINK_DOMAIN + acquisitionAssistant.getPageParam();
|
|
|
+ String content = originalContent.replace("${sms.friendLink}", replaceText);
|
|
|
+
|
|
|
+ // 4. 计算需要的短信条数
|
|
|
+ Integer needCount = calculateSmsCount(content);
|
|
|
+
|
|
|
+ // 5. 【乐观锁扣减,支持重试】
|
|
|
+ int maxRetries = 3;
|
|
|
+
|
|
|
+ for (int retryCount = 0; retryCount < maxRetries; retryCount++) {
|
|
|
+ // 先查缓存快速检查余额
|
|
|
+ Long balance = companySmsService.getBalance(2L);
|
|
|
+ if (balance == null || balance < needCount) {
|
|
|
+ log.warn("短信余额不足, companyId=2, balance={}, needCount={}", balance, needCount);
|
|
|
+ return new SendResultDetailDTO(false, "短信余额不足", null);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 获取最新数据(含version)
|
|
|
+ CompanySms latestSms = companySmsService.selectCompanySms(2L);
|
|
|
+ if (latestSms == null) {
|
|
|
+ throw new CustomException("公司短信配置不存在");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 再次确认余额(DB为准)
|
|
|
+ if (latestSms.getRemainSmsCount() < needCount) {
|
|
|
+ log.warn("短信余额不足, companyId=2, remainCount={}, needCount={}",
|
|
|
+ latestSms.getRemainSmsCount(), needCount);
|
|
|
+ return new SendResultDetailDTO(false, "短信余额不足", null);
|
|
|
+ }
|
|
|
+
|
|
|
+ Long version = latestSms.getVersion() != null ? latestSms.getVersion() : 0L;
|
|
|
+ int updateCount = companySmsService.decrementRemainSmsCountWithVersion(2L, needCount, version);
|
|
|
+
|
|
|
+ if (updateCount > 0) {
|
|
|
+ log.info("乐观锁扣减成功, needCount={}, version={}", needCount, version);
|
|
|
+ // 扣减成功,跳出循环
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
+ log.warn("乐观锁扣减失败,第{}次重试", retryCount + 1);
|
|
|
+
|
|
|
+ // 最后一次重试失败,返回错误
|
|
|
+ if (retryCount == maxRetries - 1) {
|
|
|
+ return new SendResultDetailDTO(false, "系统繁忙,请稍后重试", null);
|
|
|
+ }
|
|
|
+
|
|
|
+ try {
|
|
|
+ Thread.sleep(50L * (retryCount + 1));
|
|
|
+ } catch (InterruptedException e) {
|
|
|
+ Thread.currentThread().interrupt();
|
|
|
+ return new SendResultDetailDTO(false, "操作被中断", null);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 6. 更新缓存
|
|
|
+ companySmsService.updateCacheBalance(2L, -needCount);
|
|
|
+
|
|
|
+ try {
|
|
|
+ sendMsgLogBo.setQwAcquisitionId(acquisitionAssistant.getId());
|
|
|
+
|
|
|
+ // 7. 发送短信
|
|
|
+ R r = smsService.simpleSmsSend(phone, content, temp, SmsLogType.ACQUISITION_LINK, sendMsgLogBo);
|
|
|
+
|
|
|
+ if (r != null && "200".equals(String.valueOf(r.get("code")))) {
|
|
|
+ log.info("短信发送成功, phone={}, needCount={}", phone, needCount);
|
|
|
+ return new SendResultDetailDTO(true, null, null);
|
|
|
+ } else {
|
|
|
+ // 8. 发送失败,退还余额
|
|
|
+ String msg = r != null && r.get("msg") != null ? r.get("msg").toString() : "未知错误";
|
|
|
+ log.warn("短信发送失败,退还余额, phone={}, needCount={}", phone, needCount);
|
|
|
+ rollbackBalance(needCount, maxRetries);
|
|
|
+ return new SendResultDetailDTO(false, msg, null);
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("发送异常,退还余额, phone=" + phone, e);
|
|
|
+ rollbackBalance(needCount, maxRetries);
|
|
|
+ return new SendResultDetailDTO(false, e.getMessage(), null);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //根据短信文字内容计算短信条数
|
|
|
+ private int calculateSmsCount(String content) {
|
|
|
+ if (content == null) return 1;
|
|
|
+ int counts = content.length() / 67;
|
|
|
+ if (content.length() % 67 > 0) {
|
|
|
+ counts = counts + 1;
|
|
|
+ }
|
|
|
+ if (counts == 0) {
|
|
|
+ counts = 1;
|
|
|
+ }
|
|
|
+ return counts;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 退还余额(带重试)
|
|
|
+ */
|
|
|
+ private void rollbackBalance(int needCount, int maxRetries) {
|
|
|
+ for (int i = 0; i < maxRetries; i++) {
|
|
|
+ try {
|
|
|
+ CompanySms current = companySmsService.selectCompanySms(2L);
|
|
|
+ if (current == null) {
|
|
|
+ log.error("退还短信余额失败,公司短信配置不存在");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ Long currentVersion = current.getVersion() != null ? current.getVersion() : 0L;
|
|
|
+ int rollbackCount = companySmsService.incrementRemainSmsCountWithVersion(2L, needCount, currentVersion);
|
|
|
+ if (rollbackCount > 0) {
|
|
|
+ companySmsService.updateCacheBalance(2L, needCount);
|
|
|
+ log.info("退还余额成功, needCount={}", needCount);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ Thread.sleep(50L);
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("退还短信余额异常,第{}次重试", i + 1, e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ log.error("退还短信余额失败,需要人工处理, companyId=2, needCount={}", needCount);
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
public String syncListFromQw(String corpid, String corpsecret) {
|
|
|
@@ -387,6 +574,8 @@ public class QwAcquisitionAssistantServiceImpl implements IQwAcquisitionAssistan
|
|
|
vo.setRemark(localData.getRemark());
|
|
|
vo.setCorpId(localData.getCorpId());
|
|
|
vo.setScheme(localData.getScheme());
|
|
|
+ vo.setUserLimitJson(localData.getUserLimitJson());
|
|
|
+ vo.setSpareUserIds(localData.getSpareUserIds());
|
|
|
} else {
|
|
|
// 纯企微数据,设置默认值
|
|
|
vo.setStatus(1);
|
|
|
@@ -518,7 +707,7 @@ public class QwAcquisitionAssistantServiceImpl implements IQwAcquisitionAssistan
|
|
|
|
|
|
@Override
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
- public QwAcquisitionAssistant createWithQw(String corpid, String corpsecret, QwAcquisitionAssistant assistant) {
|
|
|
+ public QwAcquisitionAssistant createWithQw(String corpid, String corpsecret, QwAcquisitionAssistant assistant,Long companyId) {
|
|
|
// 参数校验
|
|
|
if (StringUtils.isEmpty(assistant.getLinkName())) {
|
|
|
throw new CustomException("链接名称不能为空");
|
|
|
@@ -580,8 +769,9 @@ public class QwAcquisitionAssistantServiceImpl implements IQwAcquisitionAssistan
|
|
|
if (response.getLink().getCreateTime() != null) {
|
|
|
assistant.setQwCreateTime(new Date(response.getLink().getCreateTime() * 1000));
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
+// assistant.setQwCreateTime(new Date());
|
|
|
+// assistant.setUrl("6666666666");
|
|
|
+// assistant.setLinkId("123121");
|
|
|
//如果这个随机参数已存在,则重新生成
|
|
|
String randomParam =generateUniquePageParam();
|
|
|
|
|
|
@@ -592,12 +782,23 @@ public class QwAcquisitionAssistantServiceImpl implements IQwAcquisitionAssistan
|
|
|
|
|
|
// 设置本地字段并保存
|
|
|
setLocalFields(assistant, true);
|
|
|
- qwAcquisitionAssistantMapper.insertQwAcquisitionAssistant(assistant);
|
|
|
+ acquisitionAssistantMapper.insertQwAcquisitionAssistant(assistant);
|
|
|
+
|
|
|
+ String userLimitJson = assistant.getUserLimitJson();
|
|
|
+ List<QwContactAcquisitionUser> acquisitionUserList = JSON.parseArray(userLimitJson, QwContactAcquisitionUser.class);
|
|
|
+ for (QwContactAcquisitionUser acquisitionUser : acquisitionUserList) {
|
|
|
+ acquisitionUser.setDayCount(acquisitionUser.getLimitCount());
|
|
|
+ acquisitionUser.setLinkId(assistant.getLinkId());
|
|
|
+ acquisitionUser.setCompanyId(companyId);
|
|
|
+ acquisitionUser.setCorpId(corpid);
|
|
|
+ insertQwContactWayUser.insertQwContactAcquisitionUser(acquisitionUser);
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
// ========== 缓存URL,便于后续通过pageParam访问 ==========
|
|
|
try {
|
|
|
String cacheKey = QW_ACQUISITION_URL_KEY_PREFIX + randomParam;
|
|
|
- Integer cacheExpire = 10; // 默认缓存10天
|
|
|
+ Integer cacheExpire = 2; // 默认缓存2天
|
|
|
redisCache.setCacheObject(cacheKey, friendUrl, cacheExpire, TimeUnit.DAYS);
|
|
|
log.info("获客链接URL缓存成功, pageParam: {}, url: {}", randomParam, friendUrl);
|
|
|
} catch (Exception e) {
|
|
|
@@ -605,13 +806,14 @@ public class QwAcquisitionAssistantServiceImpl implements IQwAcquisitionAssistan
|
|
|
log.error("获客链接URL缓存失败, pageParam: {}", randomParam, e);
|
|
|
}
|
|
|
return assistant;
|
|
|
+
|
|
|
}
|
|
|
|
|
|
// ==================== 编辑方法 ====================
|
|
|
|
|
|
@Override
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
- public QwAcquisitionAssistant updateWithQw(String corpid, String corpsecret, QwAcquisitionAssistant assistant) {
|
|
|
+ public QwAcquisitionAssistant updateWithQw(String corpid, String corpsecret, QwAcquisitionAssistant assistant,Long companyId) {
|
|
|
// 参数校验
|
|
|
if (assistant.getId() == null) {
|
|
|
throw new CustomException("ID不能为空");
|
|
|
@@ -621,7 +823,7 @@ public class QwAcquisitionAssistantServiceImpl implements IQwAcquisitionAssistan
|
|
|
}
|
|
|
|
|
|
// 查询本地是否存在
|
|
|
- QwAcquisitionAssistant existAssistant = qwAcquisitionAssistantMapper.selectQwAcquisitionAssistantById(assistant.getId());
|
|
|
+ QwAcquisitionAssistant existAssistant = acquisitionAssistantMapper.selectQwAcquisitionAssistantById(assistant.getId());
|
|
|
if (existAssistant == null) {
|
|
|
throw new CustomException("获客链接不存在");
|
|
|
}
|
|
|
@@ -634,30 +836,60 @@ public class QwAcquisitionAssistantServiceImpl implements IQwAcquisitionAssistan
|
|
|
}
|
|
|
request.setSkipVerify(Boolean.parseBoolean(assistant.getSkipVerify()));
|
|
|
|
|
|
+ AcquisitionRange range=new AcquisitionRange();
|
|
|
+ range.setUserList(assistant.getUserListParam());
|
|
|
+ request.setRange(range);
|
|
|
//request.setMarkSource(assistant.getMarkSource());
|
|
|
|
|
|
- // 调用企微API
|
|
|
+// 调用企微API
|
|
|
String qwApiUrl = buildApiUrl(corpid, corpsecret, QwApiConfig.updateAcquisition);
|
|
|
AcquisitionUpdateResponse response = callQwApi(qwApiUrl, request, AcquisitionUpdateResponse.class, "更新获客链接");
|
|
|
|
|
|
// 更新本地字段
|
|
|
setLocalFields(assistant, false);
|
|
|
- //TODO重新生成页面参数,需要修改对应redis缓存
|
|
|
+ //重新生成页面参数,需要修改对应redis缓存
|
|
|
String oldPageParam = existAssistant.getPageParam();
|
|
|
String oldKey = QW_ACQUISITION_URL_KEY_PREFIX + oldPageParam;
|
|
|
redisCache.deleteObject(oldKey);
|
|
|
String newPageParam =generateUniquePageParam();
|
|
|
String newKey = QW_ACQUISITION_URL_KEY_PREFIX + newPageParam;
|
|
|
- Integer cacheExpire = 10;//默认缓存10天
|
|
|
+ Integer cacheExpire = 2;//默认缓存2天
|
|
|
redisCache.setCacheObject(newKey, existAssistant.getUrl(), cacheExpire, TimeUnit.DAYS);
|
|
|
|
|
|
assistant.setPageParam(newPageParam);
|
|
|
|
|
|
- int rows = qwAcquisitionAssistantMapper.updateQwAcquisitionAssistant(assistant);
|
|
|
+ int rows = acquisitionAssistantMapper.updateQwAcquisitionAssistant(assistant);
|
|
|
if (rows <= 0) {
|
|
|
throw new CustomException("本地数据更新失败");
|
|
|
}
|
|
|
|
|
|
+ //先根据linkId查询出所有ID,再删除
|
|
|
+ List<QwContactAcquisitionUser> userList = insertQwContactWayUser.list(
|
|
|
+ new LambdaQueryWrapper<QwContactAcquisitionUser>()
|
|
|
+ .eq(QwContactAcquisitionUser::getLinkId, existAssistant.getLinkId()));
|
|
|
+
|
|
|
+ if (!CollectionUtils.isEmpty(userList)) {
|
|
|
+ List<Long> ids = userList.stream()
|
|
|
+ .map(QwContactAcquisitionUser::getId)
|
|
|
+ .filter(Objects::nonNull)
|
|
|
+ .collect(Collectors.toList());
|
|
|
+
|
|
|
+ if (!ids.isEmpty()) {
|
|
|
+ insertQwContactWayUser.removeByIds(ids);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ String userLimitJson = assistant.getUserLimitJson();
|
|
|
+ List<QwContactAcquisitionUser> acquisitionUserList = JSON.parseArray(userLimitJson, QwContactAcquisitionUser.class);
|
|
|
+ for (QwContactAcquisitionUser acquisitionUser : acquisitionUserList) {
|
|
|
+ acquisitionUser.setDayCount(acquisitionUser.getLimitCount());
|
|
|
+ acquisitionUser.setLinkId(existAssistant.getLinkId());
|
|
|
+ acquisitionUser.setCompanyId(companyId);
|
|
|
+ acquisitionUser.setCorpId(corpid);
|
|
|
+ insertQwContactWayUser.insertQwContactAcquisitionUser(acquisitionUser);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
return assistant;
|
|
|
}
|
|
|
|
|
|
@@ -764,4 +996,81 @@ public class QwAcquisitionAssistantServiceImpl implements IQwAcquisitionAssistan
|
|
|
|
|
|
return friendUrl;
|
|
|
}
|
|
|
-}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void resetAcquisitionLinkUserLimit() {
|
|
|
+ long startTimeMillis = System.currentTimeMillis();
|
|
|
+ log.info("====== 开始重置获客链接用户每日添加额度 ======");
|
|
|
+
|
|
|
+ try {
|
|
|
+ QwAcquisitionAssistant queryParam = new QwAcquisitionAssistant();
|
|
|
+ queryParam.setDelFlag("0");
|
|
|
+ List<QwAcquisitionAssistant> assistants = acquisitionAssistantMapper.selectQwAcquisitionAssistantList(queryParam);
|
|
|
+
|
|
|
+ if (assistants == null || assistants.isEmpty()) {
|
|
|
+ log.info("没有需要处理的获客链接");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ int processedCount = 0;
|
|
|
+ int restoredUserCount = 0;
|
|
|
+
|
|
|
+ for (QwAcquisitionAssistant assistant : assistants) {
|
|
|
+ try {
|
|
|
+ if (assistant.getUserLimitJson() != null && !assistant.getUserLimitJson().isEmpty()) {
|
|
|
+ com.alibaba.fastjson.JSONArray userLimitArray = com.alibaba.fastjson.JSON.parseArray(assistant.getUserLimitJson());
|
|
|
+
|
|
|
+ List<String> restoredUserList = new java.util.ArrayList<>();
|
|
|
+ List<Long> restoredQwUserTableIdList = new java.util.ArrayList<>();
|
|
|
+
|
|
|
+ for (int i = 0; i < userLimitArray.size(); i++) {
|
|
|
+ com.alibaba.fastjson.JSONObject userLimit = userLimitArray.getJSONObject(i);
|
|
|
+ String userId = userLimit.getString("userId");
|
|
|
+ Long qwUserId = userLimit.getLong("qwUserId");
|
|
|
+
|
|
|
+ restoredUserList.add(userId);
|
|
|
+ if (qwUserId != null) {
|
|
|
+ restoredQwUserTableIdList.add(qwUserId);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ assistant.setUserList(com.alibaba.fastjson.JSON.toJSONString(restoredUserList));
|
|
|
+ assistant.setQwUserTableIdList(com.alibaba.fastjson.JSON.toJSONString(restoredQwUserTableIdList));
|
|
|
+
|
|
|
+
|
|
|
+ // 构建请求
|
|
|
+ QwLinkCreateParam linkCreateParam=new QwLinkCreateParam();
|
|
|
+ linkCreateParam.setLink_id(assistant.getLinkId());
|
|
|
+
|
|
|
+ QwLinkCreateParam.Range range=new QwLinkCreateParam.Range();
|
|
|
+ range.setUser_list(JSON.parseArray(assistant.getUserList(), String.class));
|
|
|
+ linkCreateParam.setRange(range);
|
|
|
+
|
|
|
+ //调用企微API
|
|
|
+ QwResult qwResult = qwApiService.linkUpdate(linkCreateParam, assistant.getCorpId());
|
|
|
+ if (qwResult.getErrcode() == 0) {
|
|
|
+ acquisitionAssistantMapper.updateQwAcquisitionAssistant(assistant);
|
|
|
+ restoredUserCount += restoredUserList.size();
|
|
|
+ processedCount++;
|
|
|
+
|
|
|
+ }else {
|
|
|
+ log.error("修改渠道活码 失败!"+linkCreateParam+":"+qwResult.getErrmsg());
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ log.info("获客链接{}已恢复{}个用户的添加额度", assistant.getLinkId(), restoredUserList.size());
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("处理获客链接{}时出错", assistant.getId(), e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ long endTimeMillis = System.currentTimeMillis();
|
|
|
+ log.info("====== 获客链接用户额度重置完成,处理{}个链接,恢复{}个用户,耗时 {} 毫秒 ======",
|
|
|
+ processedCount, restoredUserCount, (endTimeMillis - startTimeMillis));
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("重置获客链接用户额度任务执行失败", e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|