add campaign black list

This commit is contained in:
Shaun Chyxion 2021-10-29 00:27:01 +08:00
parent 0d93a4843a
commit 53d355829b

View File

@ -1,6 +1,5 @@
package com.pudonghot.yo.campaign.service.impl; package com.pudonghot.yo.campaign.service.impl;
import com.pudonghot.yo.config.ConfigService;
import lombok.val; import lombok.val;
import lombok.Setter; import lombok.Setter;
import java.util.*; import java.util.*;
@ -10,6 +9,7 @@ import com.pudonghot.yo.util.LogMDC;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import me.chyxion.tigon.mybatis.Search; import me.chyxion.tigon.mybatis.Search;
import com.pudonghot.yo.util.TimeUtils; import com.pudonghot.yo.util.TimeUtils;
import com.pudonghot.yo.config.ConfigService;
import com.pudonghot.yo.mapper.CampaignMapper; import com.pudonghot.yo.mapper.CampaignMapper;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import com.pudonghot.yo.model.domain.Campaign; import com.pudonghot.yo.model.domain.Campaign;
@ -17,6 +17,8 @@ import com.pudonghot.yo.model.domain.BaseDomain;
import com.pudonghot.yo.mapper.AgentStatusMapper; import com.pudonghot.yo.mapper.AgentStatusMapper;
import com.pudonghot.yo.model.domain.CallingList; import com.pudonghot.yo.model.domain.CallingList;
import org.springframework.context.annotation.Lazy; import org.springframework.context.annotation.Lazy;
import com.pudonghot.yo.mapper.PhoneBlacklistMapper;
import com.pudonghot.yo.model.domain.PhoneBlacklist;
import com.pudonghot.yo.service.CommonCallDataService; import com.pudonghot.yo.service.CommonCallDataService;
import com.pudonghot.yo.service.LeaderElectionService; import com.pudonghot.yo.service.LeaderElectionService;
import com.pudonghot.yo.fsagent.api.CampaignDialService; import com.pudonghot.yo.fsagent.api.CampaignDialService;
@ -61,6 +63,8 @@ public class CampaignServiceImpl
private FeignCiticBlackListService blackListService; private FeignCiticBlackListService blackListService;
@Autowired @Autowired
private ConfigService configService; private ConfigService configService;
@Autowired
private PhoneBlacklistMapper phoneBlacklistMapper;
@Scheduled(fixedRateString = "${yo.campaign.task-scheduler.fixed-rate:6000}", @Scheduled(fixedRateString = "${yo.campaign.task-scheduler.fixed-rate:6000}",
initialDelayString = "${yo.campaign.task-scheduler.init-delay:32000}") initialDelayString = "${yo.campaign.task-scheduler.init-delay:32000}")
@ -142,9 +146,24 @@ public class CampaignServiceImpl
} }
if (configService.isCiticBlackListBatch()) { if (configService.isCiticBlackListBatch()) {
val phonesBlacklist = new HashSet<String>(
phoneBlacklistMapper.listCol(PhoneBlacklist.PHONE,
new Search(PhoneBlacklist.TENANT_ID, campaign.getTenantId())
.in(PhoneBlacklist.PHONE, callingLists.stream()
.map(CallingList::getPhone)
.collect(Collectors.toSet()))
.isTrue(PhoneBlacklist.ACTIVE)));
removeBlacklist(callingLists, phonesBlacklist);
if (callingLists.isEmpty()) {
log.info("Campaign dial calling list all blocked, ignore.");
return;
}
val blackListVerifyRespData = blackListService.batchVerify( val blackListVerifyRespData = blackListService.batchVerify(
callingLists.stream().map(CallingList::getPhone) callingLists.stream()
.collect(Collectors.toSet())).getData(); .map(CallingList::getPhone)
.collect(Collectors.toSet())).getData();
if (blackListVerifyRespData != null if (blackListVerifyRespData != null
&& blackListVerifyRespData.length > 0) { && blackListVerifyRespData.length > 0) {
@ -153,25 +172,7 @@ public class CampaignServiceImpl
.map(BlackListFeignResp::getPhone) .map(BlackListFeignResp::getPhone)
.collect(Collectors.toSet()); .collect(Collectors.toSet());
if (!blackList.isEmpty()) { removeBlacklist(callingLists, blackList);
log.info("Remove black list [{}].", blackList);
val callingListIt = callingLists.iterator();
while (callingListIt.hasNext()) {
val it = callingListIt.next();
if (blackList.contains(it.getPhone())) {
log.info("Calling list [{}] is in black list, update status to BLOCKED.", it);
it.setStatus(CallingList.Status.BLOCKED);
it.setUpdatedTime(new Date());
it.setUpdatedBy(BaseDomain.SYSTEM);
callingListService.update(it);
// remove from list
callingListIt.remove();
}
}
}
if (callingLists.isEmpty()) { if (callingLists.isEmpty()) {
log.info("Campaign dial calling list all blocked, ignore."); log.info("Campaign dial calling list all blocked, ignore.");
@ -189,4 +190,28 @@ public class CampaignServiceImpl
log.info("Campaign [{}] dial [{}].", campaignId, dataList); log.info("Campaign [{}] dial [{}].", campaignId, dataList);
dialService.queueDial(req); dialService.queueDial(req);
} }
void removeBlacklist(final List<CallingList> callingLists,
final Set<String> blacklist) {
if (!blacklist.isEmpty()) {
log.info("Remove black list [{}].", blacklist);
val callingListIt = callingLists.iterator();
while (callingListIt.hasNext()) {
val it = callingListIt.next();
if (blacklist.contains(it.getPhone())) {
log.info("Calling list [{}] is in black list, update status to BLOCKED.", it);
it.setStatus(CallingList.Status.BLOCKED);
it.setUpdatedTime(new Date());
it.setUpdatedBy(BaseDomain.SYSTEM);
callingListService.update(it);
// remove from list
callingListIt.remove();
}
}
}
}
} }