|
|
@@ -270,26 +270,47 @@ public class QwAcquisitionLinkInfoServiceImpl implements IQwAcquisitionLinkInfoS
|
|
|
|
|
|
@Override
|
|
|
public int batchCreateMessageLink(BatchAddAcquisitionLinkDTO batchAddAcquisitionLinkDTO) {
|
|
|
- Long qwAcquisitionAssistantId = batchAddAcquisitionLinkDTO.getQwAcquisitionAssistantId();
|
|
|
- String qwAcquisitionAssistantUrl = batchAddAcquisitionLinkDTO.getQwAcquisitionAssistantUrl();
|
|
|
+ Long qwAcquisitionId = batchAddAcquisitionLinkDTO.getQwAcquisitionAssistantId();
|
|
|
List<String> phoneList = batchAddAcquisitionLinkDTO.getPhoneList();
|
|
|
int result = 0;
|
|
|
+
|
|
|
+ CompanySmsTemp temp = smsTempService.selectCompanySmsTempByCode(SMS_LINK_TEMPLATE_CODE);
|
|
|
+ if (temp == null) {
|
|
|
+ log.info("获客链接-未找到短信模板:{}", SMS_LINK_TEMPLATE_CODE);
|
|
|
+ throw new CustomException("获客链接-未找到短信模板");
|
|
|
+ }
|
|
|
+ String originalContent = temp.getContent();
|
|
|
+ //获取获客链接管理信息
|
|
|
+ QwAcquisitionAssistant acquisitionAssistant = acquisitionAssistantMapper.selectQwAcquisitionAssistantById(qwAcquisitionId);
|
|
|
+ if (acquisitionAssistant == null) {
|
|
|
+ log.info("获客链接-未找到获客链接id:{}", qwAcquisitionId);
|
|
|
+ throw new CustomException("获客链接-未找到获客链接信息");
|
|
|
+ }
|
|
|
+ SendMsgLogBo sendMsgLogBo = new SendMsgLogBo();
|
|
|
+ sendMsgLogBo.setCompanyUserId(batchAddAcquisitionLinkDTO.getCreateBy());
|
|
|
+ sendMsgLogBo.setQwAcquisitionId(acquisitionAssistant.getId());
|
|
|
for (String phone : phoneList) {
|
|
|
try {
|
|
|
//新增号码-链接生成记录
|
|
|
String randomStr = generateUniqueRandomStr();
|
|
|
- int addResult = addAcquisitionLinkInfo(qwAcquisitionAssistantId, phone, qwAcquisitionAssistantUrl, randomStr,batchAddAcquisitionLinkDTO.getCreateBy());
|
|
|
- result += addResult;
|
|
|
- // 可以在这里根据 addResult 判断单次是否成功,并记录日志
|
|
|
- if (addResult > 0) {
|
|
|
- log.debug("成功为手机号 {} 创建获客链接", phone);
|
|
|
+ String replaceText = LINK_DOMAIN + randomStr;
|
|
|
+ String content = originalContent.replace("${sms.friendLink}", replaceText);
|
|
|
+
|
|
|
+
|
|
|
+ R r = smsService.simpleSmsSend(phone, content, temp, SmsLogType.ACQUISITION_LINK, sendMsgLogBo);
|
|
|
+
|
|
|
+ if (r != null && "200".equals(String.valueOf(r.get("code")))) {
|
|
|
+
|
|
|
+ //新增号码-链接生成记录
|
|
|
+ int addResult =addAcquisitionLinkInfo(acquisitionAssistant.getId(), phone, acquisitionAssistant.getUrl(), randomStr, sendMsgLogBo.getCompanyUserId());
|
|
|
+ result += addResult;
|
|
|
} else {
|
|
|
- log.warn("为手机号 {} 创建获客链接失败", phone);
|
|
|
+ String msg = r != null && r.get("msg") != null ? r.get("msg").toString() : "未知错误";
|
|
|
+ log.warn("短信发送失败 获客链接id={}, phone={}, msg={}", qwAcquisitionId, phone, msg);
|
|
|
}
|
|
|
} catch (Exception e) {
|
|
|
// 捕获异常,记录错误,但不中断整个循环
|
|
|
log.error("为手机号 {} 创建获客链接时发生异常", phone, e);
|
|
|
- // 可以选择在此处继续下一次循环,或者根据业务要求决定是否中断
|
|
|
}
|
|
|
}
|
|
|
log.info("批量创建获客链接完成,总计尝试 {}, 成功 {}", phoneList.size(), result);
|