|
|
@@ -1,11 +1,17 @@
|
|
|
package com.fs.company.service.impl;
|
|
|
|
|
|
+import com.fs.common.enums.DataSourceType;
|
|
|
import com.fs.common.utils.DateUtils;
|
|
|
import com.fs.company.domain.CompanyVoiceRoboticCallBlacklist;
|
|
|
+import com.fs.company.enums.VoiceRoboticCallBlacklistBusinessTypeEnum;
|
|
|
import com.fs.company.mapper.CompanyVoiceRoboticCallBlacklistMapper;
|
|
|
import com.fs.company.param.CompanyVoiceRoboticCallBlacklistCheckParam;
|
|
|
+import com.fs.company.service.ICompanyVoiceRoboticCallBlacklistInterceptLogService;
|
|
|
import com.fs.company.service.ICompanyVoiceRoboticCallBlacklistService;
|
|
|
import com.fs.company.vo.CompanyVoiceRoboticCallBlacklistCheckVO;
|
|
|
+import com.fs.framework.datasource.DynamicDataSourceContextHolder;
|
|
|
+import com.fs.framework.datasource.TenantDataSourceManager;
|
|
|
+import com.fs.his.utils.PhoneUtil;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
@@ -15,7 +21,7 @@ import java.util.List;
|
|
|
|
|
|
/**
|
|
|
* 黑名单Service业务层处理
|
|
|
- *
|
|
|
+ *
|
|
|
* @author fs
|
|
|
* @date 2023-02-23
|
|
|
*/
|
|
|
@@ -25,9 +31,15 @@ public class CompanyVoiceRoboticCallBlacklistServiceImpl implements ICompanyVoic
|
|
|
@Autowired
|
|
|
private CompanyVoiceRoboticCallBlacklistMapper companyVoiceRoboticCallBlacklistMapper;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private ICompanyVoiceRoboticCallBlacklistInterceptLogService interceptLogService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private TenantDataSourceManager tenantDataSourceManager;
|
|
|
+
|
|
|
/**
|
|
|
* 查询黑名单
|
|
|
- *
|
|
|
+ *
|
|
|
* @param blacklistId 黑名单ID
|
|
|
* @return 黑名单
|
|
|
*/
|
|
|
@@ -39,45 +51,109 @@ public class CompanyVoiceRoboticCallBlacklistServiceImpl implements ICompanyVoic
|
|
|
|
|
|
/**
|
|
|
* 查询黑名单列表
|
|
|
- *
|
|
|
+ *
|
|
|
* @param companyCallBlacklist 黑名单
|
|
|
* @return 黑名单
|
|
|
*/
|
|
|
@Override
|
|
|
public List<CompanyVoiceRoboticCallBlacklist> selectCompanyVoiceRoboticCallBlacklistList(CompanyVoiceRoboticCallBlacklist companyCallBlacklist)
|
|
|
{
|
|
|
+ prepareQueryTargetValue(companyCallBlacklist);
|
|
|
return companyVoiceRoboticCallBlacklistMapper.selectCompanyVoiceBlacklistList(companyCallBlacklist);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 新增黑名单
|
|
|
- *
|
|
|
+ *
|
|
|
* @param companyCallBlacklist 黑名单
|
|
|
* @return 结果
|
|
|
*/
|
|
|
@Override
|
|
|
public int insertCompanyVoiceRoboticCallBlacklist(CompanyVoiceRoboticCallBlacklist companyCallBlacklist)
|
|
|
{
|
|
|
+ prepareTargetValue(companyCallBlacklist);
|
|
|
+ companyCallBlacklist.setCreateTime(DateUtils.getNowDate());
|
|
|
+ return companyVoiceRoboticCallBlacklistMapper.insertCompanyVoiceBlacklist(companyCallBlacklist);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public int insertPlatformBlacklist(CompanyVoiceRoboticCallBlacklist companyCallBlacklist) {
|
|
|
+ companyCallBlacklist.setBusinessType(VoiceRoboticCallBlacklistBusinessTypeEnum.PLATFORM.getCode());
|
|
|
+ companyCallBlacklist.setCompanyId(null);
|
|
|
+ if (companyCallBlacklist.getTargetType() == null) {
|
|
|
+ companyCallBlacklist.setTargetType(1);
|
|
|
+ }
|
|
|
+ if (companyCallBlacklist.getSource() == null) {
|
|
|
+ companyCallBlacklist.setSource(1);
|
|
|
+ }
|
|
|
+ if (companyCallBlacklist.getStatus() == null) {
|
|
|
+ companyCallBlacklist.setStatus(1);
|
|
|
+ }
|
|
|
+ if (!StringUtils.hasText(companyCallBlacklist.getTargetValue())) {
|
|
|
+ throw new RuntimeException("手机号不能为空");
|
|
|
+ }
|
|
|
+ prepareTargetValue(companyCallBlacklist);
|
|
|
+ companyCallBlacklist.setCreateTime(DateUtils.getNowDate());
|
|
|
+ return companyVoiceRoboticCallBlacklistMapper.insertCompanyVoiceBlacklist(companyCallBlacklist);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public int insertTenantBlacklist(CompanyVoiceRoboticCallBlacklist companyCallBlacklist) {
|
|
|
+ companyCallBlacklist.setBusinessType(VoiceRoboticCallBlacklistBusinessTypeEnum.TENANT.getCode());
|
|
|
+ if (companyCallBlacklist.getTargetType() == null) {
|
|
|
+ companyCallBlacklist.setTargetType(1);
|
|
|
+ }
|
|
|
+ if (companyCallBlacklist.getSource() == null) {
|
|
|
+ companyCallBlacklist.setSource(1);
|
|
|
+ }
|
|
|
+ if (companyCallBlacklist.getStatus() == null) {
|
|
|
+ companyCallBlacklist.setStatus(1);
|
|
|
+ }
|
|
|
+ if (!StringUtils.hasText(companyCallBlacklist.getTargetValue())) {
|
|
|
+ throw new RuntimeException("对象值不能为空");
|
|
|
+ }
|
|
|
+ prepareTargetValue(companyCallBlacklist);
|
|
|
+ companyCallBlacklist.setCreateTime(DateUtils.getNowDate());
|
|
|
+ return companyVoiceRoboticCallBlacklistMapper.insertCompanyVoiceBlacklist(companyCallBlacklist);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public int insertLineBlacklist(CompanyVoiceRoboticCallBlacklist companyCallBlacklist) {
|
|
|
+ companyCallBlacklist.setBusinessType(VoiceRoboticCallBlacklistBusinessTypeEnum.LINE.getCode());
|
|
|
+ if (companyCallBlacklist.getTargetType() == null) {
|
|
|
+ companyCallBlacklist.setTargetType(1);
|
|
|
+ }
|
|
|
+ if (companyCallBlacklist.getSource() == null) {
|
|
|
+ companyCallBlacklist.setSource(1);
|
|
|
+ }
|
|
|
+ if (companyCallBlacklist.getStatus() == null) {
|
|
|
+ companyCallBlacklist.setStatus(1);
|
|
|
+ }
|
|
|
+ if (!StringUtils.hasText(companyCallBlacklist.getTargetValue())) {
|
|
|
+ throw new RuntimeException("对象值不能为空");
|
|
|
+ }
|
|
|
+ prepareTargetValue(companyCallBlacklist);
|
|
|
companyCallBlacklist.setCreateTime(DateUtils.getNowDate());
|
|
|
return companyVoiceRoboticCallBlacklistMapper.insertCompanyVoiceBlacklist(companyCallBlacklist);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 修改黑名单
|
|
|
- *
|
|
|
+ *
|
|
|
* @param companyCallBlacklist 黑名单
|
|
|
* @return 结果
|
|
|
*/
|
|
|
@Override
|
|
|
public int updateCompanyVoiceRoboticCallBlacklist(CompanyVoiceRoboticCallBlacklist companyCallBlacklist)
|
|
|
{
|
|
|
+ prepareTargetValue(companyCallBlacklist);
|
|
|
companyCallBlacklist.setUpdateTime(DateUtils.getNowDate());
|
|
|
return companyVoiceRoboticCallBlacklistMapper.updateCompanyVoiceBlacklist(companyCallBlacklist);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 批量删除黑名单
|
|
|
- *
|
|
|
+ *
|
|
|
* @param blacklistIds 需要删除的黑名单ID
|
|
|
* @return 结果
|
|
|
*/
|
|
|
@@ -89,7 +165,7 @@ public class CompanyVoiceRoboticCallBlacklistServiceImpl implements ICompanyVoic
|
|
|
|
|
|
/**
|
|
|
* 删除黑名单信息
|
|
|
- *
|
|
|
+ *
|
|
|
* @param blacklistId 黑名单ID
|
|
|
* @return 结果
|
|
|
*/
|
|
|
@@ -115,6 +191,7 @@ public class CompanyVoiceRoboticCallBlacklistServiceImpl implements ICompanyVoic
|
|
|
CompanyVoiceRoboticCallBlacklist entity = new CompanyVoiceRoboticCallBlacklist();
|
|
|
entity.setId(companyVoiceRoboticCallBlacklist.getId());
|
|
|
entity.setStatus(companyVoiceRoboticCallBlacklist.getStatus());
|
|
|
+ entity.setUpdateBy(companyVoiceRoboticCallBlacklist.getUpdateBy());
|
|
|
return companyVoiceRoboticCallBlacklistMapper.updateStatusById(entity);
|
|
|
}
|
|
|
|
|
|
@@ -123,65 +200,182 @@ public class CompanyVoiceRoboticCallBlacklistServiceImpl implements ICompanyVoic
|
|
|
*/
|
|
|
@Override
|
|
|
public CompanyVoiceRoboticCallBlacklistCheckVO checkBlacklist(CompanyVoiceRoboticCallBlacklistCheckParam param) {
|
|
|
- if (param == null || param.getCompanyId() == null
|
|
|
- || !StringUtils.hasText(param.getBusinessType())
|
|
|
- || !StringUtils.hasText(param.getTargetValue())) {
|
|
|
+ if (param == null || !StringUtils.hasText(param.getTargetValue())) {
|
|
|
return CompanyVoiceRoboticCallBlacklistCheckVO.paramNull("校验参数不能为空");
|
|
|
}
|
|
|
|
|
|
String targetValue = normalizeTargetValue(param.getTargetType(), param.getTargetValue());
|
|
|
+ targetValue = encryptPhoneIfNeeded(param.getTargetType(), targetValue);
|
|
|
|
|
|
- // 1. 有 companyId,先查公司级黑名单
|
|
|
+ // 1. 有 companyId,先查租户级黑名单(businessType=12)
|
|
|
if (param.getCompanyId() != null) {
|
|
|
CompanyVoiceRoboticCallBlacklist companyHit =
|
|
|
companyVoiceRoboticCallBlacklistMapper.selectActiveByTarget(
|
|
|
param.getCompanyId(),
|
|
|
- param.getBusinessType(),
|
|
|
+ VoiceRoboticCallBlacklistBusinessTypeEnum.TENANT.getCode(),
|
|
|
targetValue
|
|
|
);
|
|
|
|
|
|
if (companyHit != null) {
|
|
|
- return CompanyVoiceRoboticCallBlacklistCheckVO.reject(
|
|
|
+ CompanyVoiceRoboticCallBlacklistCheckVO rejectVo = CompanyVoiceRoboticCallBlacklistCheckVO.reject(
|
|
|
companyHit.getId(),
|
|
|
companyHit.getBusinessType(),
|
|
|
companyHit.getTargetType(),
|
|
|
companyHit.getTargetValue(),
|
|
|
- buildReason(companyHit, "公司级黑名单")
|
|
|
+ buildReason(companyHit, "租户级黑名单")
|
|
|
);
|
|
|
+ interceptLogService.saveOnBlacklistReject(param, rejectVo);
|
|
|
+ return rejectVo;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-// CompanyVoiceRoboticCallBlacklist hit = companyVoiceRoboticCallBlacklistMapper.selectActiveByTarget(
|
|
|
-// param.getCompanyId(),
|
|
|
-// param.getBusinessType(),
|
|
|
-// targetValue
|
|
|
-// );
|
|
|
-
|
|
|
-// if (hit == null) {
|
|
|
-// return CompanyVoiceRoboticCallBlacklistCheckVO.pass(param.getBusinessType());
|
|
|
-// }
|
|
|
-//
|
|
|
-// return CompanyVoiceRoboticCallBlacklistCheckVO.reject(
|
|
|
-// hit.getId(),
|
|
|
-// hit.getBusinessType(),
|
|
|
-// hit.getTargetType(),
|
|
|
-// hit.getTargetValue(),
|
|
|
-// buildReason(hit)
|
|
|
-// );
|
|
|
- // 2. 查全局黑名单
|
|
|
- CompanyVoiceRoboticCallBlacklist globalHit = companyVoiceRoboticCallBlacklistMapper.selectGlobalActiveByTarget(param.getBusinessType(),targetValue);
|
|
|
+ // 2. 查平台级黑名单(businessType=11,company_id 为空)
|
|
|
+ CompanyVoiceRoboticCallBlacklist globalHit = companyVoiceRoboticCallBlacklistMapper.selectGlobalActiveByTarget(
|
|
|
+ VoiceRoboticCallBlacklistBusinessTypeEnum.PLATFORM.getCode(),
|
|
|
+ targetValue
|
|
|
+ );
|
|
|
|
|
|
if (globalHit != null) {
|
|
|
- return CompanyVoiceRoboticCallBlacklistCheckVO.reject(
|
|
|
+ CompanyVoiceRoboticCallBlacklistCheckVO rejectVo = CompanyVoiceRoboticCallBlacklistCheckVO.reject(
|
|
|
globalHit.getId(),
|
|
|
globalHit.getBusinessType(),
|
|
|
globalHit.getTargetType(),
|
|
|
globalHit.getTargetValue(),
|
|
|
- buildReason(globalHit, "全局黑名单")
|
|
|
+ buildReason(globalHit, "平台级黑名单")
|
|
|
+ );
|
|
|
+ interceptLogService.saveOnBlacklistReject(param, rejectVo);
|
|
|
+ return rejectVo;
|
|
|
+ }
|
|
|
+ return CompanyVoiceRoboticCallBlacklistCheckVO.pass(
|
|
|
+ VoiceRoboticCallBlacklistBusinessTypeEnum.PLATFORM.getCode()
|
|
|
+ );
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 按数据源校验黑名单:租户库先查 12/13,未命中再查主库 11;未传租户仅查主库 11。
|
|
|
+ * 命中时在当前数据源写入拦截明细(平台命中写主库,租户/线路命中写租户库)。
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public CompanyVoiceRoboticCallBlacklistCheckVO checkBlacklistWithDataSource(CompanyVoiceRoboticCallBlacklistCheckParam param) {
|
|
|
+ if (param == null || !StringUtils.hasText(param.getTargetValue())) {
|
|
|
+ return CompanyVoiceRoboticCallBlacklistCheckVO.paramNull("校验参数不能为空");
|
|
|
+ }
|
|
|
+
|
|
|
+ String previousDs = DynamicDataSourceContextHolder.getDataSourceType();
|
|
|
+ try {
|
|
|
+ Integer targetType = param.getTargetType() != null ? param.getTargetType() : 1;
|
|
|
+ String targetValue = normalizeTargetValue(targetType, param.getTargetValue());
|
|
|
+ targetValue = encryptPhoneIfNeeded(targetType, targetValue);
|
|
|
+
|
|
|
+ Long tenantId = param.getTenantId();
|
|
|
+ if (tenantId != null) {
|
|
|
+ tenantDataSourceManager.ensureSwitchByTenantId(tenantId);
|
|
|
+
|
|
|
+ if (param.getCompanyId() != null) {
|
|
|
+ CompanyVoiceRoboticCallBlacklist tenantHit = companyVoiceRoboticCallBlacklistMapper.selectActiveByTarget(
|
|
|
+ param.getCompanyId(),
|
|
|
+ VoiceRoboticCallBlacklistBusinessTypeEnum.TENANT.getCode(),
|
|
|
+ targetValue
|
|
|
+ );
|
|
|
+ if (tenantHit != null) {
|
|
|
+ return rejectAndSaveInterceptLog(param, tenantHit, "租户级黑名单");
|
|
|
+ }
|
|
|
+
|
|
|
+ CompanyVoiceRoboticCallBlacklist lineHit = companyVoiceRoboticCallBlacklistMapper.selectActiveByTarget(
|
|
|
+ param.getCompanyId(),
|
|
|
+ VoiceRoboticCallBlacklistBusinessTypeEnum.LINE.getCode(),
|
|
|
+ targetValue
|
|
|
+ );
|
|
|
+ if (lineHit != null) {
|
|
|
+ return rejectAndSaveInterceptLog(param, lineHit, "线路级黑名单");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ DynamicDataSourceContextHolder.setDataSourceType(DataSourceType.MASTER.name());
|
|
|
+ } else {
|
|
|
+ DynamicDataSourceContextHolder.setDataSourceType(DataSourceType.MASTER.name());
|
|
|
+ }
|
|
|
+
|
|
|
+ CompanyVoiceRoboticCallBlacklist platformHit = companyVoiceRoboticCallBlacklistMapper.selectGlobalActiveByTarget(
|
|
|
+ VoiceRoboticCallBlacklistBusinessTypeEnum.PLATFORM.getCode(),
|
|
|
+ targetValue
|
|
|
);
|
|
|
+ if (platformHit != null) {
|
|
|
+ return rejectAndSaveInterceptLog(param, platformHit, "平台级黑名单");
|
|
|
+ }
|
|
|
+
|
|
|
+ return CompanyVoiceRoboticCallBlacklistCheckVO.pass(
|
|
|
+ VoiceRoboticCallBlacklistBusinessTypeEnum.PLATFORM.getCode()
|
|
|
+ );
|
|
|
+ } finally {
|
|
|
+ restoreDataSource(previousDs);
|
|
|
}
|
|
|
- return CompanyVoiceRoboticCallBlacklistCheckVO.pass(param.getBusinessType());
|
|
|
+ }
|
|
|
|
|
|
+ private CompanyVoiceRoboticCallBlacklistCheckVO rejectAndSaveInterceptLog(
|
|
|
+ CompanyVoiceRoboticCallBlacklistCheckParam param,
|
|
|
+ CompanyVoiceRoboticCallBlacklist hit,
|
|
|
+ String scopeDesc) {
|
|
|
+ CompanyVoiceRoboticCallBlacklistCheckVO rejectVo = CompanyVoiceRoboticCallBlacklistCheckVO.reject(
|
|
|
+ hit.getId(),
|
|
|
+ hit.getBusinessType(),
|
|
|
+ hit.getTargetType(),
|
|
|
+ hit.getTargetValue(),
|
|
|
+ buildReason(hit, scopeDesc)
|
|
|
+ );
|
|
|
+ interceptLogService.saveOnBlacklistReject(param, rejectVo);
|
|
|
+ return rejectVo;
|
|
|
+ }
|
|
|
+
|
|
|
+ private void restoreDataSource(String previousDs) {
|
|
|
+ if (StringUtils.hasText(previousDs)) {
|
|
|
+ DynamicDataSourceContextHolder.setDataSourceType(previousDs);
|
|
|
+ } else {
|
|
|
+ DynamicDataSourceContextHolder.clearDataSourceType();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public String getDecryptPhoneById(Long blacklistId) {
|
|
|
+ CompanyVoiceRoboticCallBlacklist db = companyVoiceRoboticCallBlacklistMapper.selectCompanyVoiceBlacklistById(blacklistId);
|
|
|
+ if (db == null || !StringUtils.hasText(db.getTargetValue())) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ if (Integer.valueOf(1).equals(db.getTargetType())) {
|
|
|
+ return PhoneUtil.decryptAutoPhone(db.getTargetValue());
|
|
|
+ }
|
|
|
+ return db.getTargetValue();
|
|
|
+ }
|
|
|
+
|
|
|
+ private void prepareTargetValue(CompanyVoiceRoboticCallBlacklist entity) {
|
|
|
+ if (entity == null || !StringUtils.hasText(entity.getTargetValue())) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ String value = normalizeTargetValue(entity.getTargetType(), entity.getTargetValue());
|
|
|
+ value = encryptPhoneIfNeeded(entity.getTargetType(), value);
|
|
|
+ entity.setTargetValue(value);
|
|
|
+ }
|
|
|
+
|
|
|
+ private void prepareQueryTargetValue(CompanyVoiceRoboticCallBlacklist entity) {
|
|
|
+ if (entity == null || !StringUtils.hasText(entity.getTargetValue())) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ Integer targetType = entity.getTargetType() != null ? entity.getTargetType() : 1;
|
|
|
+ String value = normalizeTargetValue(targetType, entity.getTargetValue());
|
|
|
+ value = encryptPhoneIfNeeded(targetType, value);
|
|
|
+ entity.setTargetValue(value);
|
|
|
+ }
|
|
|
+
|
|
|
+ private String encryptPhoneIfNeeded(Integer targetType, String value) {
|
|
|
+ if (!StringUtils.hasText(value)) {
|
|
|
+ return value;
|
|
|
+ }
|
|
|
+ Integer phoneType = targetType != null ? targetType : 1;
|
|
|
+ if (Integer.valueOf(1).equals(phoneType) && value.length() <= 11) {
|
|
|
+ return PhoneUtil.encryptPhone(value);
|
|
|
+ }
|
|
|
+ return value;
|
|
|
}
|
|
|
|
|
|
/**
|