add citic black list

This commit is contained in:
Shaun Chyxion 2021-07-07 01:37:52 +08:00
parent 84820f449e
commit 5b84c23c53
13 changed files with 176 additions and 9 deletions

View File

@ -0,0 +1,54 @@
package com.pudonghot.yo.citic.feign.config;
import lombok.val;
import feign.Response;
import feign.codec.Decoder;
import java.io.IOException;
import feign.FeignException;
import java.lang.reflect.Type;
import lombok.extern.slf4j.Slf4j;
import feign.jackson.JacksonDecoder;
import lombok.RequiredArgsConstructor;
import org.springframework.util.Assert;
import org.apache.commons.lang3.StringUtils;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.type.TypeFactory;
/**
* @author Donghuang
* @date Aug 13, 2020 12:26:19
*/
@Slf4j
@RequiredArgsConstructor
public class FeignCiticDecoder implements Decoder {
private final JacksonDecoder delegate;
private final ObjectMapper objectMapper;
/**
* {@inheritDoc}
*/
@Override
public Object decode(final Response response, final Type type) throws IOException, FeignException {
val jnResp = (JsonNode) delegate.decode(response, JsonNode.class);
val codeNode = jnResp.get("retcode");
if (codeNode != null) {
log.warn("Feign client ERROR response [{}].", jnResp);
val errCode = codeNode.asText();
Assert.state("0".equals(errCode)
// Black List
|| "300".equals(errCode),
getNodeText(jnResp, "message"));
}
return objectMapper.treeToValue(jnResp, TypeFactory.rawClass(type));
}
private String getNodeText(final JsonNode node, final String name) {
val fieldNode = node.get(name);
if (fieldNode != null) {
return StringUtils.defaultIfBlank(fieldNode.asText(), null);
}
return null;
}
}

View File

@ -34,7 +34,8 @@ public class FeignClientConfiguration {
@Bean
public Decoder feignDecoder(final ObjectMapper objectMapper) {
return new ResponseEntityDecoder(new JacksonDecoder(objectMapper));
return new ResponseEntityDecoder(
new FeignCiticDecoder(new JacksonDecoder(objectMapper), objectMapper));
}
@Bean

View File

@ -6,6 +6,8 @@ import lombok.ToString;
import com.fasterxml.jackson.annotation.JsonAlias;
/**
* 多条黑名单校验
*
* @author Donghuang
* @date Jun 23, 2021 00:15:23
*/

View File

@ -6,6 +6,8 @@ import lombok.ToString;
import com.fasterxml.jackson.annotation.JsonAlias;
/**
* 单条黑名单校验
*
* @author Donghuang
* @date Jun 23, 2021 00:15:23
*/

View File

@ -1,6 +1,7 @@
package com.pudonghot.yo.citic.feign.service;
import java.util.List;
import java.util.Collection;
import javax.validation.Valid;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
@ -33,7 +34,7 @@ public interface FeignCiticBlackListService {
@PostMapping("${yo.citic.feign.path.black-list-batch-verify:/resource/black-list/batch-verify}")
CiticBlackListBatchVerifyFeignResp batchVerify(
@RequestBody
@NotEmpty List<String> phones);
@NotEmpty Collection<String> phones);
/**
* verify black list

View File

@ -52,7 +52,7 @@ public class CallingList extends BaseDomain {
private Date lockTime;
public enum Status {
NOT_READY, READY, ACHIEVED, DIALING, CALLED, CANCELED, REVERT
NOT_READY, READY, ACHIEVED, DIALING, CALLED, CANCELED, REVERT, BLOCKED
}
public enum Type {

View File

@ -23,6 +23,7 @@ public enum ErrorCode {
DIAL_EXCEED_2TIMES_TODAY("001-007", "当日拨打超过2次"),
DIAL_EXCEED_1TIMES_IN_4HOURS("001-008", "未接通4小时内拨打"),
DIAL_EXCEED_IN_T2("001-009", "T-2日未接通拨打"),
DIAL_CITIC_BLACKLIST("001-010", "卡中心黑名单号码"),
// 内部咨询
INNER_HELP_OTHER_AGENT_NOT_FOUND("002-001", "求助坐席不存在"),

View File

@ -78,10 +78,19 @@
<groupId>com.pudonghot.yo</groupId>
<artifactId>yo-http-client-apache</artifactId>
</dependency>
<dependency>
<groupId>com.pudonghot.yo</groupId>
<artifactId>yo-citic-client</artifactId>
</dependency>
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.76</version>
</dependency>
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-dependencies-zookeeper</artifactId>

View File

@ -1,8 +1,9 @@
package com.pudonghot.yo.campaign.service.impl;
import com.pudonghot.yo.config.ConfigService;
import lombok.val;
import lombok.Setter;
import java.util.Date;
import java.util.*;
import lombok.extern.slf4j.Slf4j;
import java.util.stream.Collectors;
import com.pudonghot.yo.util.LogMDC;
@ -12,7 +13,9 @@ import com.pudonghot.yo.util.TimeUtils;
import com.pudonghot.yo.mapper.CampaignMapper;
import org.springframework.stereotype.Service;
import com.pudonghot.yo.model.domain.Campaign;
import com.pudonghot.yo.model.domain.BaseDomain;
import com.pudonghot.yo.mapper.AgentStatusMapper;
import com.pudonghot.yo.model.domain.CallingList;
import org.springframework.context.annotation.Lazy;
import com.pudonghot.yo.service.CommonCallDataService;
import com.pudonghot.yo.service.LeaderElectionService;
@ -25,8 +28,10 @@ import com.pudonghot.yo.campaign.service.CallingListService;
import org.springframework.beans.factory.annotation.Autowired;
import com.wacai.tigon.service.support.BaseQueryServiceSupport;
import static com.pudonghot.yo.model.domain.Campaign.TargetType.QUEUE;
import com.pudonghot.yo.citic.feign.service.FeignCiticBlackListService;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import com.pudonghot.yo.fsagent.api.request.ReqCampaignDial.CallingRecord;
import static com.pudonghot.yo.citic.feign.response.CiticBlackListBatchVerifyFeignResp.BlackListFeignResp;
/**
* @author Donghuang
@ -52,6 +57,10 @@ public class CampaignServiceImpl
private CommonCallDataService commonCallDataService;
@Autowired
private LeaderElectionService leaderElectionService;
@Autowired
private FeignCiticBlackListService blackListService;
@Autowired
private ConfigService configService;
@Scheduled(fixedRateString = "${yo.campaign.task-scheduler.fixed-rate:6000}",
initialDelayString = "${yo.campaign.task-scheduler.init-delay:32000}")
@ -132,6 +141,45 @@ public class CampaignServiceImpl
return;
}
if (configService.isCiticBlackListBatch()) {
val blackListVerifyRespData = blackListService.batchVerify(
callingLists.stream().map(CallingList::getPhone)
.collect(Collectors.toSet())).getData();
if (blackListVerifyRespData != null
&& blackListVerifyRespData.length > 0) {
val blackList = Arrays.stream(blackListVerifyRespData)
.filter(BlackListFeignResp::getBlacklist)
.map(BlackListFeignResp::getPhone)
.collect(Collectors.toSet());
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();
}
}
}
if (callingLists.isEmpty()) {
log.info("Campaign dial calling list all blocked, ignore.");
return;
}
}
}
val req = new ReqCampaignDial();
req.setCampaignId(campaignId);
val dataList = callingLists.stream()

View File

@ -0,0 +1,14 @@
package com.pudonghot.yo.config;
/**
* @author Donghuang
* @date Jul 07, 2021 01:06:48
*/
public interface ConfigService {
void setCiticBlackList(boolean enabled);
boolean isCiticBlackList();
void setCiticBlackListBatch(boolean enabled);
boolean isCiticBlackListBatch();
}

View File

@ -0,0 +1,18 @@
package com.pudonghot.yo.config.impl;
import lombok.Getter;
import lombok.Setter;
import com.pudonghot.yo.config.ConfigService;
import org.apache.dubbo.config.annotation.Service;
/**
* @author Donghuang
* @date Jul 07, 2021 01:08:22
*/
@Setter
@Getter
@Service(version = "${yo.fsagent.dubbo.service.version}")
public class ConfigServiceImpl implements ConfigService {
private boolean citicBlackList;
private boolean citicBlackListBatch;
}

View File

@ -1,5 +1,6 @@
package com.pudonghot.yo.openapi.controller;
import com.pudonghot.yo.config.ConfigService;
import lombok.val;
import java.util.Date;
import java.util.Calendar;
@ -37,6 +38,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import static com.pudonghot.yo.model.domain.AgentStatus.State.*;
import static com.pudonghot.yo.model.domain.AgentStatus.Status.*;
import com.pudonghot.yo.citic.feign.service.FeignCiticBlackListService;
import static com.pudonghot.yo.model.agentevent.EventType.AgentEvent_Call_Release;
/**
@ -71,6 +73,10 @@ public class CallController implements SessionAbility {
private CallDetailRecordMapper callDetailRecordMapper;
@Autowired
private LockService lockService;
@Autowired
private FeignCiticBlackListService blackListService;
@Autowired
private ConfigService configService;
@Value("${yo.openapi.account-idle-lock.timeout:4000}")
private Long accountIdleLockTimeout;
@ -108,6 +114,13 @@ public class CallController implements SessionAbility {
.eq(PhoneBlacklist.ACTIVE, true)),
ErrorCode.DIAL_BLACKLIST);
// citic black list
if (configService.isCiticBlackList()) {
AssertUtils.state(
!blackListService.isBlack(calledNumber),
ErrorCode.DIAL_CITIC_BLACKLIST);
}
// 白名单
if (phoneWhitelistMapper.exists(
new Search(PhoneWhitelist.TENANT_ID, tenantId)

View File

@ -52,7 +52,7 @@ dubbo:
address: zookeeper://172.16.4.6:2181
file: ${user.home}/dubbo-cache/${spring.application.name}/dubbo.cache
scan:
base-packages: com.pudonghot.yo.fsagent.service.dubbo.impl
base-packages: com.pudonghot.yo
yo:
datasource:
@ -89,7 +89,11 @@ yo:
task-scheduler:
fixed-rate: 240000
batch-cron: 12 12 0 * * *
feign:
base-url: http://stsl.wldmz.cc/stsl-web-partner/call-data/taskdata
channel: dx-hzqw
citic:
feign:
# base-url: http://stsl.wldmz.cc/stsl-web-partner
base-url: http://e.test.bank.ecitic.com/citiccard/stsl-web-partner
path:
calling-list: /call-data/taskdata/dx-hzqw
black-list-verify: /resource/black-list/verify
black-list-batch-verify: /resource/black-list/batch-verify