|
@@ -15,6 +15,7 @@ import java.util.*;
|
|
|
import java.util.regex.Matcher;
|
|
|
import java.util.regex.Pattern;
|
|
|
import java.util.stream.Collectors;
|
|
|
+import java.util.stream.Stream;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.commons.collections4.CollectionUtils;
|
|
|
import org.apache.commons.lang.StringUtils;
|
|
@@ -151,6 +152,16 @@ public class AdwebEnquiryServiceImpl extends ServiceImpl<AdwebEnquiryMapper, Adw
|
|
|
private static final String SiteBlackIpKey = "SITE_BLACK_IP_LIST";
|
|
|
private static final String SiteWhiteIpListKey = "SITE_WHITE_IP_LIST";
|
|
|
|
|
|
+ // 垃圾询盘原因
|
|
|
+ private static final String EMPTY_MESSAGE_REASON = "系统操作-通过询盘内容为空检测到垃圾询盘";
|
|
|
+ private static final String EMAIL_BLACKLIST_REASON = "系统操作-通过公共和站点的询盘邮箱黑名单检测到垃圾询盘-%s";
|
|
|
+ private static final String EMAIL_PUBLIC_BLACKLIST_REASON = "系统操作-通过公共的询盘邮箱黑名单检测到垃圾询盘-%s";
|
|
|
+ private static final String EMAIL_SITE_BLACKLIST_REASON = "系统操作-通过站点的询盘邮箱黑名单检测到垃圾询盘-%s";
|
|
|
+ private static final String IP_BLACKLIST_REASON = "系统操作-通过询盘公共和站点ip黑名单检测到垃圾询盘-%s";
|
|
|
+ private static final String URL_BLACKLIST_REASON = "系统操作-通过站点url检测到垃圾询盘-%s";
|
|
|
+ private static final String KEYWORD_BLACKLIST_REASON = "系统操作-通过公共和站点关键词黑名单检测到垃圾询盘-%s";
|
|
|
+ private static final String LONG_WORD_REASON = "系统操作-通过单词长度超过50个字符检测到垃圾询盘";
|
|
|
+
|
|
|
@Value("${judge_waste_enquiry.email.tenMinNum}")
|
|
|
private Integer emailTenMinNum;
|
|
|
|
|
@@ -973,227 +984,84 @@ public class AdwebEnquiryServiceImpl extends ServiceImpl<AdwebEnquiryMapper, Adw
|
|
|
private void judgeWasteEnquiryBySiteId(
|
|
|
List<AdwebEnquiry> adwebEnquiryList, AdwebSite adwebSite, List<String> blackWordList) {
|
|
|
|
|
|
- // 邮箱 黑名单
|
|
|
- // 先获取对应站点的邮箱黑名单
|
|
|
- List<String> siteBlackEmailList =
|
|
|
- (List<String>) adwebRedisUtil.get(SiteBlackEmailKey + "::" + adwebSite.getId());
|
|
|
- if (CollectionUtils.isEmpty(siteBlackEmailList)) {
|
|
|
- enquirySiteBlackEmailService.saveRedisSiteBlackEmailBySiteId(adwebSite.getId(), 0);
|
|
|
- siteBlackEmailList =
|
|
|
- (List<String>) adwebRedisUtil.get(SiteBlackEmailKey + "::" + adwebSite.getId());
|
|
|
- if (CollectionUtils.isEmpty(siteBlackEmailList)) {
|
|
|
- siteBlackEmailList = new ArrayList<>();
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- // 邮箱 公共黑名单
|
|
|
- List<String> publicBlackEmailList = (List<String>) adwebRedisUtil.get(BlackEmailKey);
|
|
|
- if (CollectionUtils.isEmpty(publicBlackEmailList)) {
|
|
|
- List<AdwebPublicBlackEmail> enquiryPublicBlackEmailList =
|
|
|
- adwebPublicBlackEmailService.list(
|
|
|
- new LambdaQueryWrapper<AdwebPublicBlackEmail>()
|
|
|
- .ne(AdwebPublicBlackEmail::getStatus, 0)
|
|
|
- .eq(AdwebPublicBlackEmail::getBlackOrWhite, 0)
|
|
|
- .isNotNull(AdwebPublicBlackEmail::getEmail)
|
|
|
- .select(AdwebPublicBlackEmail::getEmail));
|
|
|
-
|
|
|
- if (CollectionUtils.isNotEmpty(enquiryPublicBlackEmailList)) {
|
|
|
- publicBlackEmailList =
|
|
|
- enquiryPublicBlackEmailList.stream()
|
|
|
- .map(AdwebPublicBlackEmail::getEmail)
|
|
|
- .filter(StringUtil::isNotEmpty)
|
|
|
- .collect(Collectors.toList());
|
|
|
- adwebRedisUtil.set(BlackEmailKey, publicBlackEmailList, 60 * 60 * 24);
|
|
|
- } else {
|
|
|
- publicBlackEmailList = new ArrayList<>();
|
|
|
- }
|
|
|
- } else {
|
|
|
- publicBlackEmailList =
|
|
|
- publicBlackEmailList.stream().filter(s -> !s.isEmpty()).collect(Collectors.toList());
|
|
|
- }
|
|
|
- List<String> allBlackEmailList = new ArrayList<>();
|
|
|
- if (CollectionUtils.isNotEmpty(siteBlackEmailList)) {
|
|
|
- allBlackEmailList = new ArrayList<>(siteBlackEmailList);
|
|
|
- }
|
|
|
- allBlackEmailList.addAll(publicBlackEmailList);
|
|
|
- List<String> blackEmailList = new ArrayList<>();
|
|
|
- if (CollectionUtils.isNotEmpty(allBlackEmailList)) {
|
|
|
- HashSet<String> blackEmailHashSet = new HashSet<String>(allBlackEmailList);
|
|
|
- blackEmailList = new ArrayList<>(blackEmailHashSet);
|
|
|
- }
|
|
|
-
|
|
|
- log.info("公共邮箱黑名单:{}", publicBlackEmailList.size());
|
|
|
- log.info("站点邮箱黑名单:{}", siteBlackEmailList.size());
|
|
|
-
|
|
|
- // 邮箱 白名单
|
|
|
- // 先获取对应站点的邮箱白名单
|
|
|
- List<String> siteWhiteEmailList =
|
|
|
- (List<String>) adwebRedisUtil.get(SiteWhiteEmailListKey + "::" + adwebSite.getId());
|
|
|
- if (CollectionUtils.isEmpty(siteWhiteEmailList)) {
|
|
|
- enquirySiteBlackEmailService.saveRedisSiteBlackEmailBySiteId(adwebSite.getId(), 1);
|
|
|
- siteWhiteEmailList =
|
|
|
- (List<String>) adwebRedisUtil.get(SiteWhiteEmailListKey + "::" + adwebSite.getId());
|
|
|
- }
|
|
|
- // 公共邮箱白名单数据
|
|
|
- List<String> publicWhiteEmailList = (List<String>) adwebRedisUtil.get(WhiteEmailListKey);
|
|
|
- if (CollectionUtils.isEmpty(publicWhiteEmailList)) {
|
|
|
- List<AdwebPublicBlackEmail> enquiryPublicWhiteEmailList =
|
|
|
- adwebPublicBlackEmailService.list(
|
|
|
- new LambdaQueryWrapper<AdwebPublicBlackEmail>()
|
|
|
- .ne(AdwebPublicBlackEmail::getStatus, 0)
|
|
|
- .eq(AdwebPublicBlackEmail::getBlackOrWhite, 1)
|
|
|
- .isNotNull(AdwebPublicBlackEmail::getEmail)
|
|
|
- .select(AdwebPublicBlackEmail::getEmail));
|
|
|
-
|
|
|
- if (CollectionUtils.isNotEmpty(enquiryPublicWhiteEmailList)) {
|
|
|
- publicWhiteEmailList =
|
|
|
- enquiryPublicWhiteEmailList.stream()
|
|
|
- .map(AdwebPublicBlackEmail::getEmail)
|
|
|
- .filter(StringUtil::isNotEmpty)
|
|
|
- .collect(Collectors.toList());
|
|
|
- adwebRedisUtil.set(WhiteEmailListKey, publicWhiteEmailList, 60 * 60 * 24);
|
|
|
- } else {
|
|
|
- publicWhiteEmailList = new ArrayList<>();
|
|
|
- }
|
|
|
- } else {
|
|
|
- publicWhiteEmailList =
|
|
|
- publicWhiteEmailList.stream().filter(s -> !s.isEmpty()).collect(Collectors.toList());
|
|
|
- }
|
|
|
- List<String> allWhiteEmailList = new ArrayList<>();
|
|
|
- if (CollectionUtils.isNotEmpty(siteWhiteEmailList)) {
|
|
|
- allWhiteEmailList = new ArrayList<>(siteWhiteEmailList);
|
|
|
- }
|
|
|
- allWhiteEmailList.addAll(publicWhiteEmailList);
|
|
|
- List<String> whiteEmailList = new ArrayList<>();
|
|
|
- if (CollectionUtils.isNotEmpty(allWhiteEmailList)) {
|
|
|
- HashSet<String> whiteEmailHashSet = new HashSet<String>(allWhiteEmailList);
|
|
|
- whiteEmailList = new ArrayList<>(whiteEmailHashSet);
|
|
|
- }
|
|
|
-
|
|
|
- log.info("公共邮箱白名单:" + FastJsonUtil.toJSONString(publicWhiteEmailList));
|
|
|
- log.info("站点邮箱白名单:" + FastJsonUtil.toJSONString(siteWhiteEmailList));
|
|
|
+ // 站点邮箱黑名单
|
|
|
+ List<String> siteBlackEmailList = getSiteBlackEmailList(adwebSite);
|
|
|
+ // 公共邮箱黑名单
|
|
|
+ List<String> publicBlackEmailList = getPublicBlackEmailList();
|
|
|
+
|
|
|
+ // 处理可能的 null 返回值
|
|
|
+ siteBlackEmailList = siteBlackEmailList == null ? Collections.emptyList() : siteBlackEmailList;
|
|
|
+ publicBlackEmailList =
|
|
|
+ publicBlackEmailList == null ? Collections.emptyList() : publicBlackEmailList;
|
|
|
+
|
|
|
+ // 合并两个列表并去重
|
|
|
+ List<String> blackEmailList =
|
|
|
+ Stream.concat(siteBlackEmailList.stream(), publicBlackEmailList.stream())
|
|
|
+ .distinct()
|
|
|
+ .collect(Collectors.toList());
|
|
|
+
|
|
|
+ log.info("公共邮箱黑名单长度:{}", publicBlackEmailList.size());
|
|
|
+ log.info("站点邮箱黑名单长度:{}", siteBlackEmailList.size());
|
|
|
+ log.info("全部邮箱黑名单长度:{}", blackEmailList.size());
|
|
|
+
|
|
|
+ // 站点邮箱白名单
|
|
|
+ List<String> siteWhiteEmailList = getSiteWhiteEmailList(adwebSite);
|
|
|
+ // 公共邮箱白名单
|
|
|
+ List<String> publicWhiteEmailList = getPublicWhiteEmailList();
|
|
|
+
|
|
|
+ // 处理可能的 null 返回值
|
|
|
+ siteWhiteEmailList = siteWhiteEmailList == null ? Collections.emptyList() : siteWhiteEmailList;
|
|
|
+ publicWhiteEmailList =
|
|
|
+ publicWhiteEmailList == null ? Collections.emptyList() : publicWhiteEmailList;
|
|
|
+
|
|
|
+ // 合并两个列表并去重
|
|
|
+ List<String> whiteEmailList =
|
|
|
+ Stream.concat(siteWhiteEmailList.stream(), publicWhiteEmailList.stream())
|
|
|
+ .distinct()
|
|
|
+ .collect(Collectors.toList());
|
|
|
+
|
|
|
+ log.info("公共邮箱白名单长度:{}", siteWhiteEmailList.size());
|
|
|
+ log.info("站点邮箱白名单长度:{}", publicWhiteEmailList.size());
|
|
|
+ log.info("全部邮箱白名单长度:{}", whiteEmailList.size());
|
|
|
|
|
|
- // Ip黑名单
|
|
|
// 公共ip黑名单
|
|
|
- List<String> publicBlackIpList = (List<String>) adwebRedisUtil.get(BlackIpKey);
|
|
|
- if (CollectionUtils.isEmpty(publicBlackIpList)) {
|
|
|
- List<AdwebPublicBlackIp> enquiryPublicBlackIpList =
|
|
|
- adwebPublicBlackIpService.list(
|
|
|
- new LambdaQueryWrapper<AdwebPublicBlackIp>()
|
|
|
- .ne(AdwebPublicBlackIp::getStatus, 0)
|
|
|
- .eq(AdwebPublicBlackIp::getBlackOrWhite, 0)
|
|
|
- .select(AdwebPublicBlackIp::getIp));
|
|
|
- if (CollectionUtils.isNotEmpty(enquiryPublicBlackIpList)) {
|
|
|
- publicBlackIpList =
|
|
|
- enquiryPublicBlackIpList.stream()
|
|
|
- .map(AdwebPublicBlackIp::getIp)
|
|
|
- .collect(Collectors.toList());
|
|
|
- adwebRedisUtil.set(BlackIpKey, publicBlackIpList, 60 * 60 * 24);
|
|
|
- } else {
|
|
|
- publicBlackIpList = new ArrayList<>();
|
|
|
- }
|
|
|
- }
|
|
|
+ List<String> publicBlackIpList = getPublicBlackIpList();
|
|
|
// 站点ip黑名单
|
|
|
- List<String> siteBlackIpList =
|
|
|
- (List<String>) adwebRedisUtil.get(SiteBlackIpKey + "::" + adwebSite.getId());
|
|
|
- if (CollectionUtils.isEmpty(siteBlackIpList)) {
|
|
|
- List<AdwebSiteBlackIp> enquirySiteBlackIpList =
|
|
|
- adwebSiteBlackIpService.list(
|
|
|
- new LambdaQueryWrapper<AdwebSiteBlackIp>()
|
|
|
- .ne(AdwebSiteBlackIp::getStatus, 0)
|
|
|
- .eq(AdwebSiteBlackIp::getBlackOrWhite, 0)
|
|
|
- .eq(AdwebSiteBlackIp::getSiteId, adwebSite.getId())
|
|
|
- .select(AdwebSiteBlackIp::getIp));
|
|
|
- if (CollectionUtils.isNotEmpty(enquirySiteBlackIpList)) {
|
|
|
- siteBlackIpList =
|
|
|
- enquirySiteBlackIpList.stream()
|
|
|
- .map(AdwebSiteBlackIp::getIp)
|
|
|
- .collect(Collectors.toList());
|
|
|
- adwebRedisUtil.set(
|
|
|
- SiteBlackIpKey + "::" + adwebSite.getId(), siteBlackIpList, 60 * 60 * 24);
|
|
|
- } else {
|
|
|
- siteBlackIpList = new ArrayList<>();
|
|
|
- }
|
|
|
- }
|
|
|
- List<String> allBlackIpList = new ArrayList<>();
|
|
|
- if (CollectionUtils.isNotEmpty(siteBlackIpList)) {
|
|
|
- allBlackIpList = new ArrayList<>(siteBlackIpList);
|
|
|
- }
|
|
|
- allBlackIpList.addAll(publicBlackIpList);
|
|
|
- List<String> blackIpList = new ArrayList<>();
|
|
|
- if (CollectionUtils.isNotEmpty(allBlackIpList)) {
|
|
|
- HashSet<String> blackIpHashSet = new HashSet<String>(allBlackIpList);
|
|
|
- blackIpList = new ArrayList<>(blackIpHashSet);
|
|
|
- }
|
|
|
+ List<String> siteBlackIpList = getSiteBlackIpList(adwebSite);
|
|
|
+
|
|
|
+ // 处理可能的 null 返回值
|
|
|
+ siteBlackIpList = siteBlackIpList == null ? Collections.emptyList() : siteBlackIpList;
|
|
|
+ publicBlackIpList = publicBlackIpList == null ? Collections.emptyList() : publicBlackIpList;
|
|
|
+ List<String> blackIpList =
|
|
|
+ Stream.concat(siteBlackIpList.stream(), publicBlackIpList.stream())
|
|
|
+ .distinct()
|
|
|
+ .collect(Collectors.toList());
|
|
|
|
|
|
- log.info("公共ip黑名单:{} 个", publicBlackIpList.size());
|
|
|
- log.info("站点ip黑名单:{} 个", siteBlackIpList.size());
|
|
|
+ log.info("公共ip黑名单长度:{} 个", publicBlackIpList.size());
|
|
|
+ log.info("站点ip黑名单长度:{} 个", siteBlackIpList.size());
|
|
|
+ log.info("全部ip黑名单长度:{}", blackIpList.size());
|
|
|
|
|
|
- // Ip白名单
|
|
|
// 公共Ip白名单
|
|
|
- List<String> publicWhiteIpList = (List<String>) adwebRedisUtil.get(WhiteIpListKey);
|
|
|
- if (publicWhiteIpList == null) {
|
|
|
- List<AdwebPublicBlackIp> enquiryPublicWhiteIpList =
|
|
|
- adwebPublicBlackIpService.list(
|
|
|
- new LambdaQueryWrapper<AdwebPublicBlackIp>()
|
|
|
- .ne(AdwebPublicBlackIp::getStatus, 0)
|
|
|
- .eq(AdwebPublicBlackIp::getBlackOrWhite, 1)
|
|
|
- .select(AdwebPublicBlackIp::getIp));
|
|
|
- if (CollectionUtils.isNotEmpty(enquiryPublicWhiteIpList)) {
|
|
|
- publicWhiteIpList =
|
|
|
- enquiryPublicWhiteIpList.stream()
|
|
|
- .map(AdwebPublicBlackIp::getIp)
|
|
|
- .collect(Collectors.toList());
|
|
|
- adwebRedisUtil.set(WhiteIpListKey, publicWhiteIpList, 60 * 60 * 24);
|
|
|
- } else {
|
|
|
- publicWhiteIpList = new ArrayList<>();
|
|
|
- }
|
|
|
- }
|
|
|
- // 站点Ip白名单, 基于站点查询
|
|
|
- List<String> siteWhiteIpList =
|
|
|
- (List<String>) adwebRedisUtil.get(SiteWhiteIpListKey + "::" + adwebSite.getId());
|
|
|
- if (CollectionUtils.isEmpty(siteWhiteIpList)) {
|
|
|
- List<AdwebSiteBlackIp> enquirySiteWhiteIpList =
|
|
|
- adwebSiteBlackIpService.list(
|
|
|
- new LambdaQueryWrapper<AdwebSiteBlackIp>()
|
|
|
- .ne(AdwebSiteBlackIp::getStatus, 0)
|
|
|
- .eq(AdwebSiteBlackIp::getBlackOrWhite, 1)
|
|
|
- .eq(AdwebSiteBlackIp::getSiteId, adwebSite.getId())
|
|
|
- .select(AdwebSiteBlackIp::getIp));
|
|
|
- if (CollectionUtils.isNotEmpty(enquirySiteWhiteIpList)) {
|
|
|
- siteWhiteIpList =
|
|
|
- enquirySiteWhiteIpList.stream()
|
|
|
- .map(AdwebSiteBlackIp::getIp)
|
|
|
- .collect(Collectors.toList());
|
|
|
- adwebRedisUtil.set(
|
|
|
- SiteWhiteIpListKey + "::" + adwebSite.getId(), siteWhiteIpList, 60 * 60 * 24);
|
|
|
- } else {
|
|
|
- siteWhiteIpList = new ArrayList<>();
|
|
|
- }
|
|
|
- }
|
|
|
- List<String> allWhiteIpList = new ArrayList<>();
|
|
|
- if (CollectionUtils.isNotEmpty(siteWhiteIpList)) {
|
|
|
- allWhiteIpList = new ArrayList<>(siteWhiteIpList);
|
|
|
- }
|
|
|
- allWhiteIpList.addAll(publicWhiteIpList);
|
|
|
- List<String> whiteIpList = new ArrayList<>();
|
|
|
- if (CollectionUtils.isNotEmpty(allWhiteIpList)) {
|
|
|
- HashSet<String> whiteIpHashSet = new HashSet<String>(allWhiteIpList);
|
|
|
- whiteIpList = new ArrayList<>(whiteIpHashSet);
|
|
|
- }
|
|
|
+ List<String> publicWhiteIpList = getPublicWhiteIpList();
|
|
|
+ // 站点Ip白名单
|
|
|
+ List<String> siteWhiteIpList = getSiteWhiteIpList(adwebSite);
|
|
|
+
|
|
|
+ // 处理可能的 null 返回值
|
|
|
+ siteWhiteIpList = siteWhiteIpList == null ? Collections.emptyList() : siteWhiteIpList;
|
|
|
+ publicWhiteIpList = publicWhiteIpList == null ? Collections.emptyList() : publicWhiteIpList;
|
|
|
+
|
|
|
+ List<String> whiteIpList =
|
|
|
+ Stream.concat(siteWhiteIpList.stream(), publicWhiteIpList.stream())
|
|
|
+ .distinct()
|
|
|
+ .collect(Collectors.toList());
|
|
|
|
|
|
- log.info("公共ip白名单:" + FastJsonUtil.toJSONString(publicWhiteIpList));
|
|
|
- log.info("站点ip白名单:" + FastJsonUtil.toJSONString(siteWhiteIpList));
|
|
|
+ log.info("公共ip白名单长度:{}", publicWhiteIpList.size());
|
|
|
+ log.info("站点ip白名单长度:{}", siteWhiteIpList.size());
|
|
|
+ log.info("全部ip白名单长度:{}", whiteIpList.size());
|
|
|
|
|
|
// 站点询盘规则黑名单
|
|
|
- LambdaQueryWrapper<AdwebSiteEnquiryRule> adwebEnquirySiteRuleQueryWrapper =
|
|
|
- new LambdaQueryWrapper<>();
|
|
|
- adwebEnquirySiteRuleQueryWrapper.eq(AdwebSiteEnquiryRule::getSiteId, adwebSite.getId());
|
|
|
- adwebEnquirySiteRuleQueryWrapper.eq(AdwebSiteEnquiryRule::getStatus, 1);
|
|
|
- adwebEnquirySiteRuleQueryWrapper.eq(AdwebSiteEnquiryRule::getBlackOrWhite, 0);
|
|
|
- List<AdwebSiteEnquiryRule> siteBlackRuleList =
|
|
|
- adwebSiteEnquiryRuleService.list(adwebEnquirySiteRuleQueryWrapper);
|
|
|
- log.info("站点关键词黑名单:" + FastJsonUtil.toJSONString(siteBlackRuleList));
|
|
|
+ List<AdwebSiteEnquiryRule> siteBlackRuleList = geSiteBlackRuleList(adwebSite);
|
|
|
+ log.info("站点关键词黑名单长度:{}", siteBlackRuleList.size());
|
|
|
|
|
|
// 判断上一封询盘是否是垃圾询盘
|
|
|
AdwebEnquiry isJudgeWasteEnquiry = new AdwebEnquiry();
|
|
@@ -1203,12 +1071,8 @@ public class AdwebEnquiryServiceImpl extends ServiceImpl<AdwebEnquiryMapper, Adw
|
|
|
for (AdwebEnquiry adwebEnquiry : adwebEnquiryList) {
|
|
|
// 没有message的无法判断,认为是普通询盘
|
|
|
if (StringUtil.isEmpty(adwebEnquiry.getMessage())) {
|
|
|
- adwebEnquiry.setWasteEnquiry(1);
|
|
|
- adwebEnquiry.setUserEffective(0);
|
|
|
- log.info(
|
|
|
- "询盘id是:{}, 站点code是:{}, 通过——询盘内容为空——检测到垃圾询盘",
|
|
|
- adwebEnquiry.getId(),
|
|
|
- adwebEnquiry.getSiteCode());
|
|
|
+ markAsWasteEnquiry(adwebEnquiry, EMPTY_MESSAGE_REASON, "");
|
|
|
+ logInfo(adwebEnquiry, "通过——询盘内容为空——检测到垃圾询盘");
|
|
|
continue;
|
|
|
}
|
|
|
|
|
@@ -1217,164 +1081,20 @@ public class AdwebEnquiryServiceImpl extends ServiceImpl<AdwebEnquiryMapper, Adw
|
|
|
siteBlackEmailList, siteBlackIpList, isJudgeWasteEnquiry, adwebSite);
|
|
|
isJudgeWasteEnquiry = adwebEnquiry;
|
|
|
|
|
|
- // 判断 询盘邮箱黑名单
|
|
|
- if (CollectionUtils.isNotEmpty(blackEmailList)
|
|
|
- || StringUtils.isNotBlank(adwebEnquiry.getEmail())) {
|
|
|
-
|
|
|
- String email = adwebEnquiry.getEmail().toLowerCase();
|
|
|
-
|
|
|
- String message =
|
|
|
- adwebEnquiry
|
|
|
- .getMessage()
|
|
|
- .replaceAll("[\\n\\t]", " ")
|
|
|
- .replaceAll(" {2,}", " ")
|
|
|
- .toLowerCase();
|
|
|
-
|
|
|
- // 公共黑白名单
|
|
|
- // boolean isContainPublicWhite = false;
|
|
|
- // String containPublicWhiteStr = "";
|
|
|
- // 白名单
|
|
|
- // for(String publicWhiteEmail : publicWhiteEmailList){
|
|
|
- // log.info("judgeWasteEnquiry --
|
|
|
- // 当前询盘Id:{},!whiteEmailList.contains(email):{}",adwebEnquiry.getId(),!whiteEmailList.contains(email));
|
|
|
- // if(email.equals(publicWhiteEmail) ||
|
|
|
- // message.equals(publicWhiteEmail)){
|
|
|
- // containPublicWhiteStr = publicWhiteEmail;
|
|
|
- // isContainPublicWhite = true;
|
|
|
- // break;
|
|
|
- // }
|
|
|
- // }
|
|
|
-
|
|
|
- // 黑名单
|
|
|
- String containPublicBlackStr = "";
|
|
|
- boolean isContainPublicBlack = false;
|
|
|
- if (CollectionUtils.isNotEmpty(publicBlackEmailList)) {
|
|
|
- for (String blackEmail : publicBlackEmailList) {
|
|
|
- String allBlackEmail = blackEmail;
|
|
|
- if (allBlackEmail.contains("*")) {
|
|
|
- allBlackEmail = allBlackEmail.substring(1, allBlackEmail.length() - 1);
|
|
|
- if (email.contains(allBlackEmail) || message.contains(allBlackEmail)) {
|
|
|
- containPublicBlackStr = blackEmail;
|
|
|
- isContainPublicBlack = true;
|
|
|
- break;
|
|
|
- }
|
|
|
- } else {
|
|
|
- if (email.equals(allBlackEmail) || message.equals(allBlackEmail)) {
|
|
|
- containPublicBlackStr = blackEmail;
|
|
|
- isContainPublicBlack = true;
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- log.info("是否是公共黑名单:" + isContainPublicBlack);
|
|
|
- log.info("匹配的公共黑名单:" + containPublicBlackStr);
|
|
|
- // 站点黑白名单
|
|
|
- boolean isContainSiteWhite = false;
|
|
|
- boolean isSiteAllContain = true;
|
|
|
- String containSiteWhiteStr = "";
|
|
|
- // 白名单
|
|
|
- if (CollectionUtils.isNotEmpty(siteWhiteEmailList)) {
|
|
|
- for (String whiteEmail : siteWhiteEmailList) {
|
|
|
- String compareWhiteEmail = whiteEmail;
|
|
|
- if (compareWhiteEmail.contains("*")) {
|
|
|
- compareWhiteEmail = whiteEmail.substring(1, whiteEmail.length() - 1);
|
|
|
- if (email.contains(compareWhiteEmail) || message.contains(compareWhiteEmail)) {
|
|
|
- containSiteWhiteStr = compareWhiteEmail;
|
|
|
- isContainSiteWhite = true;
|
|
|
- isSiteAllContain = false;
|
|
|
- break;
|
|
|
- }
|
|
|
- } else {
|
|
|
- if (email.equals(compareWhiteEmail) || message.equals(compareWhiteEmail)) {
|
|
|
- containSiteWhiteStr = compareWhiteEmail;
|
|
|
- isContainSiteWhite = true;
|
|
|
- isSiteAllContain = false;
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- log.info("是否是站点白名单:" + isContainSiteWhite);
|
|
|
- log.info("匹配的站点白名单:" + containSiteWhiteStr);
|
|
|
- // 黑名单
|
|
|
- boolean isContainSiteBlack = false;
|
|
|
- String containSiteBlackStr = "";
|
|
|
- if (CollectionUtils.isNotEmpty(siteBlackEmailList)) {
|
|
|
- for (String blackEmail : siteBlackEmailList) {
|
|
|
- String allBlackEmail = blackEmail;
|
|
|
- if (allBlackEmail.contains("*")) {
|
|
|
- allBlackEmail = allBlackEmail.substring(1, allBlackEmail.length() - 1);
|
|
|
- if (email.contains(allBlackEmail) || message.contains(allBlackEmail)) {
|
|
|
- containSiteBlackStr = allBlackEmail;
|
|
|
- isContainSiteBlack = true;
|
|
|
- isSiteAllContain = false;
|
|
|
- break;
|
|
|
- }
|
|
|
- } else {
|
|
|
- if (email.equals(allBlackEmail) || message.equals(allBlackEmail)) {
|
|
|
- containSiteBlackStr = allBlackEmail;
|
|
|
- isContainSiteBlack = true;
|
|
|
- isSiteAllContain = false;
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- log.info("是否是站点黑名单:" + isContainSiteBlack);
|
|
|
- log.info("匹配的站点黑名单:" + containSiteBlackStr);
|
|
|
- // 判断邮箱或者内容即在黑名单里又在白名单里,特殊处理
|
|
|
- if (isContainSiteBlack && isContainSiteWhite) {
|
|
|
- if (containSiteBlackStr.length() <= containSiteWhiteStr.length()) {
|
|
|
- isContainSiteBlack = false;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- log.info("第二次处理是否是站点黑名单:" + isContainSiteBlack);
|
|
|
- if (isContainPublicBlack || !isSiteAllContain) {
|
|
|
- if (isContainPublicBlack && isContainSiteBlack) {
|
|
|
- adwebEnquiry.setWasteEnquiry(1);
|
|
|
- adwebEnquiry.setUserEffective(0);
|
|
|
- adwebEnquiry.setWasteEnquiryType("email");
|
|
|
- adwebEnquiry.setEffectiveReason("系统操作-通过公共和站点的询盘邮箱黑名单检测到垃圾询盘-" + containSiteBlackStr);
|
|
|
- log.info(
|
|
|
- "询盘id是:{}, 站点code是:{}, 通过——询盘邮箱黑名单——检测到垃圾询盘, 黑名单邮箱是:{}",
|
|
|
- adwebEnquiry.getId(),
|
|
|
- adwebEnquiry.getSiteCode(),
|
|
|
- containSiteBlackStr);
|
|
|
- continue outerloop;
|
|
|
- }
|
|
|
- if (isContainPublicBlack && isSiteAllContain) {
|
|
|
- adwebEnquiry.setWasteEnquiry(1);
|
|
|
- adwebEnquiry.setUserEffective(0);
|
|
|
- adwebEnquiry.setWasteEnquiryType("email");
|
|
|
- adwebEnquiry.setEffectiveReason("系统操作-通过公共的询盘邮箱黑名单检测到垃圾询盘-" + containPublicBlackStr);
|
|
|
- log.info(
|
|
|
- "询盘id是:{}, 站点code是:{}, 通过——询盘邮箱黑名单——检测到垃圾询盘, 黑名单邮箱是:{}",
|
|
|
- adwebEnquiry.getId(),
|
|
|
- adwebEnquiry.getSiteCode(),
|
|
|
- containPublicBlackStr);
|
|
|
- continue outerloop;
|
|
|
- }
|
|
|
- if (!isContainPublicBlack && isContainSiteBlack) {
|
|
|
- adwebEnquiry.setWasteEnquiry(1);
|
|
|
- adwebEnquiry.setUserEffective(0);
|
|
|
- adwebEnquiry.setWasteEnquiryType("email");
|
|
|
- adwebEnquiry.setEffectiveReason("系统操作-通过站点的询盘邮箱黑名单检测到垃圾询盘-" + containSiteBlackStr);
|
|
|
- log.info(
|
|
|
- "询盘id是:{}, 站点code是:{}, 通过——询盘邮箱黑名单——检测到垃圾询盘, 黑名单邮箱是:{}",
|
|
|
- adwebEnquiry.getId(),
|
|
|
- adwebEnquiry.getSiteCode(),
|
|
|
- containSiteBlackStr);
|
|
|
- continue outerloop;
|
|
|
- }
|
|
|
- }
|
|
|
+ // 判断询盘邮箱黑名单
|
|
|
+ boolean shotTarget =
|
|
|
+ dealEmailBlackList(
|
|
|
+ adwebEnquiry,
|
|
|
+ blackEmailList,
|
|
|
+ publicBlackEmailList,
|
|
|
+ siteWhiteEmailList,
|
|
|
+ siteBlackEmailList);
|
|
|
+
|
|
|
+ // 命中后跳出循环
|
|
|
+ if (shotTarget) {
|
|
|
+ continue outerloop;
|
|
|
}
|
|
|
|
|
|
- // @see http://52.83.154.198:8082/browse/ADWEBV2-12
|
|
|
- // 垃圾询盘过滤时IP按照客户IP去使用黑名单过滤而不再使用来源IP
|
|
|
// 判断是否为ip黑名单
|
|
|
if (CollectionUtils.isNotEmpty(blackIpList)
|
|
|
|| StringUtils.isNotBlank(adwebEnquiry.getCustomerIp())) {
|
|
@@ -1390,18 +1110,10 @@ public class AdwebEnquiryServiceImpl extends ServiceImpl<AdwebEnquiryMapper, Adw
|
|
|
if (siteBlackIpList.contains(ip) && !siteWhiteIpList.contains(ip)) {
|
|
|
isSiteIp = true;
|
|
|
}
|
|
|
- if (isPublicIp || isSiteIp) {
|
|
|
- adwebEnquiry.setWasteEnquiry(1);
|
|
|
- adwebEnquiry.setUserEffective(0);
|
|
|
- adwebEnquiry.setWasteEnquiryType("ip");
|
|
|
- }
|
|
|
if (isPublicIp && isSiteIp) {
|
|
|
- adwebEnquiry.setEffectiveReason("系统操作-通过询盘公共和站点ip黑名单检测到垃圾询盘-" + ip);
|
|
|
- log.info(
|
|
|
- "询盘id是:{}, 站点code是:{}, 通过——询盘公共和站点ip黑名单——检测到垃圾询盘, ip是:{}",
|
|
|
- adwebEnquiry.getId(),
|
|
|
- adwebEnquiry.getSiteCode(),
|
|
|
- ip);
|
|
|
+ String reason = String.format(IP_BLACKLIST_REASON, ip);
|
|
|
+ markAsWasteEnquiry(adwebEnquiry, reason, "ip");
|
|
|
+ logInfo(adwebEnquiry, reason);
|
|
|
continue;
|
|
|
}
|
|
|
if (isPublicIp) {
|
|
@@ -1556,7 +1268,6 @@ public class AdwebEnquiryServiceImpl extends ServiceImpl<AdwebEnquiryMapper, Adw
|
|
|
isPreviousOneWasteEnquiry(blackEmailList, blackIpList, isJudgeWasteEnquiry);
|
|
|
|
|
|
// 更新redis
|
|
|
- // 站点
|
|
|
if (CollectionUtils.isNotEmpty(siteBlackEmailList)) {
|
|
|
adwebRedisUtil.set(SiteBlackEmailKey + "::" + adwebSite.getId(), siteBlackEmailList, 86400);
|
|
|
}
|
|
@@ -1585,6 +1296,384 @@ public class AdwebEnquiryServiceImpl extends ServiceImpl<AdwebEnquiryMapper, Adw
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ /** 询盘处理邮箱黑名单 */
|
|
|
+ private boolean dealEmailBlackList(
|
|
|
+ AdwebEnquiry adwebEnquiry,
|
|
|
+ List<String> blackEmailList,
|
|
|
+ List<String> publicBlackEmailList,
|
|
|
+ List<String> siteWhiteEmailList,
|
|
|
+ List<String> siteBlackEmailList) {
|
|
|
+ if (CollectionUtils.isNotEmpty(blackEmailList)
|
|
|
+ || StringUtils.isNotBlank(adwebEnquiry.getEmail())) {
|
|
|
+ log.info(" --- 开始判断询盘邮箱黑名单 --- 当前询盘Id:{}", adwebEnquiry.getId());
|
|
|
+ String email = adwebEnquiry.getEmail().toLowerCase();
|
|
|
+ String message =
|
|
|
+ adwebEnquiry
|
|
|
+ .getMessage()
|
|
|
+ .replaceAll("[\\n\\t]", " ")
|
|
|
+ .replaceAll(" {2,}", " ")
|
|
|
+ .toLowerCase();
|
|
|
+
|
|
|
+ // 公共邮箱黑名单
|
|
|
+ String containPublicBlackStr = "";
|
|
|
+ boolean isContainPublicBlack = false;
|
|
|
+ if (CollectionUtils.isNotEmpty(publicBlackEmailList)) {
|
|
|
+ for (String blackEmail : publicBlackEmailList) {
|
|
|
+ String allBlackEmail = blackEmail;
|
|
|
+ if (allBlackEmail.contains("*")) {
|
|
|
+ allBlackEmail = allBlackEmail.substring(1, allBlackEmail.length() - 1);
|
|
|
+ if (email.contains(allBlackEmail) || message.contains(allBlackEmail)) {
|
|
|
+ containPublicBlackStr = blackEmail;
|
|
|
+ isContainPublicBlack = true;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ if (email.equals(allBlackEmail) || message.equals(allBlackEmail)) {
|
|
|
+ containPublicBlackStr = blackEmail;
|
|
|
+ isContainPublicBlack = true;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ log.info("是否是公共黑名单:{}", isContainPublicBlack);
|
|
|
+ log.info("匹配的公共黑名单:{}", containPublicBlackStr);
|
|
|
+
|
|
|
+ // 站点白名单
|
|
|
+ boolean isContainSiteWhite = false;
|
|
|
+ boolean isSiteAllContain = true;
|
|
|
+ String containSiteWhiteStr = "";
|
|
|
+ if (CollectionUtils.isNotEmpty(siteWhiteEmailList)) {
|
|
|
+ for (String whiteEmail : siteWhiteEmailList) {
|
|
|
+ String compareWhiteEmail = whiteEmail;
|
|
|
+ if (compareWhiteEmail.contains("*")) {
|
|
|
+ compareWhiteEmail = whiteEmail.substring(1, whiteEmail.length() - 1);
|
|
|
+ if (email.contains(compareWhiteEmail) || message.contains(compareWhiteEmail)) {
|
|
|
+ containSiteWhiteStr = compareWhiteEmail;
|
|
|
+ isContainSiteWhite = true;
|
|
|
+ isSiteAllContain = false;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ if (email.equals(compareWhiteEmail) || message.equals(compareWhiteEmail)) {
|
|
|
+ containSiteWhiteStr = compareWhiteEmail;
|
|
|
+ isContainSiteWhite = true;
|
|
|
+ isSiteAllContain = false;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ log.info("是否是站点白名单:{}", isContainSiteWhite);
|
|
|
+ log.info("匹配的站点白名单:{}", containSiteWhiteStr);
|
|
|
+ // 站点黑名单
|
|
|
+ boolean isContainSiteBlack = false;
|
|
|
+ String containSiteBlackStr = "";
|
|
|
+ if (CollectionUtils.isNotEmpty(siteBlackEmailList)) {
|
|
|
+ for (String blackEmail : siteBlackEmailList) {
|
|
|
+ String allBlackEmail = blackEmail;
|
|
|
+ if (allBlackEmail.contains("*")) {
|
|
|
+ allBlackEmail = allBlackEmail.substring(1, allBlackEmail.length() - 1);
|
|
|
+ if (email.contains(allBlackEmail) || message.contains(allBlackEmail)) {
|
|
|
+ containSiteBlackStr = allBlackEmail;
|
|
|
+ isContainSiteBlack = true;
|
|
|
+ isSiteAllContain = false;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ if (email.equals(allBlackEmail) || message.equals(allBlackEmail)) {
|
|
|
+ containSiteBlackStr = allBlackEmail;
|
|
|
+ isContainSiteBlack = true;
|
|
|
+ isSiteAllContain = false;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ log.info("是否是站点黑名单:{}", isContainSiteBlack);
|
|
|
+ log.info("匹配的站点黑名单:{}", containSiteBlackStr);
|
|
|
+
|
|
|
+ // 判断邮箱或者内容即在黑名单里又在白名单里,特殊处理
|
|
|
+ if (isContainSiteBlack && isContainSiteWhite) {
|
|
|
+ if (containSiteBlackStr.length() <= containSiteWhiteStr.length()) {
|
|
|
+ isContainSiteBlack = false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ log.info("第二次处理是否是站点黑名单:{}", isContainSiteBlack);
|
|
|
+ if (isContainPublicBlack || !isSiteAllContain) {
|
|
|
+
|
|
|
+ // 公共邮箱黑名单和站点邮箱黑名单全部命中
|
|
|
+ if (isContainPublicBlack && isContainSiteBlack) {
|
|
|
+ String reason = String.format(EMAIL_BLACKLIST_REASON, containSiteBlackStr);
|
|
|
+ markAsWasteEnquiry(adwebEnquiry, reason, "email");
|
|
|
+ logInfo(adwebEnquiry, reason);
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 公共邮箱黑名单命中
|
|
|
+ if (isContainPublicBlack && isSiteAllContain) {
|
|
|
+ String reason = String.format(EMAIL_PUBLIC_BLACKLIST_REASON, containPublicBlackStr);
|
|
|
+ markAsWasteEnquiry(adwebEnquiry, reason, "email");
|
|
|
+ logInfo(adwebEnquiry, reason);
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 站点邮箱黑名单命中
|
|
|
+ if (!isContainPublicBlack && isContainSiteBlack) {
|
|
|
+ String reason = String.format(EMAIL_SITE_BLACKLIST_REASON, containSiteBlackStr);
|
|
|
+ markAsWasteEnquiry(adwebEnquiry, reason, "email");
|
|
|
+ logInfo(adwebEnquiry, reason);
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /** 标记为垃圾询盘 */
|
|
|
+ private void markAsWasteEnquiry(AdwebEnquiry adwebEnquiry, String reason, String enquiryType) {
|
|
|
+ adwebEnquiry.setWasteEnquiry(1);
|
|
|
+ adwebEnquiry.setUserEffective(0);
|
|
|
+ adwebEnquiry.setWasteEnquiryType(enquiryType);
|
|
|
+ adwebEnquiry.setEffectiveReason(reason);
|
|
|
+ }
|
|
|
+
|
|
|
+ /** 询盘记录日志 */
|
|
|
+ private void logInfo(AdwebEnquiry adwebEnquiry, String message) {
|
|
|
+ log.info("询盘id是:{}, 站点code是:{}, {}", adwebEnquiry.getId(), adwebEnquiry.getSiteCode(), message);
|
|
|
+ }
|
|
|
+
|
|
|
+ /** 获取站点关键词黑名单 */
|
|
|
+ private List<AdwebSiteEnquiryRule> geSiteBlackRuleList(AdwebSite adwebSite) {
|
|
|
+ LambdaQueryWrapper<AdwebSiteEnquiryRule> adwebEnquirySiteRuleQueryWrapper =
|
|
|
+ new LambdaQueryWrapper<>();
|
|
|
+ adwebEnquirySiteRuleQueryWrapper.eq(AdwebSiteEnquiryRule::getSiteId, adwebSite.getId());
|
|
|
+ adwebEnquirySiteRuleQueryWrapper.eq(AdwebSiteEnquiryRule::getStatus, 1);
|
|
|
+ adwebEnquirySiteRuleQueryWrapper.eq(AdwebSiteEnquiryRule::getBlackOrWhite, 0);
|
|
|
+
|
|
|
+ return adwebSiteEnquiryRuleService.list(adwebEnquirySiteRuleQueryWrapper);
|
|
|
+ }
|
|
|
+
|
|
|
+ /** 站点IP白名单 */
|
|
|
+ private List<String> getSiteWhiteIpList(AdwebSite adwebSite) {
|
|
|
+ String siteWhiteIpRedisKey = SiteWhiteIpListKey + "::" + adwebSite.getId();
|
|
|
+
|
|
|
+ List<String> siteWhiteIpList = getListFromRedis(siteWhiteIpRedisKey);
|
|
|
+
|
|
|
+ if (CollectionUtils.isEmpty(siteWhiteIpList)) {
|
|
|
+ List<AdwebSiteBlackIp> enquirySiteWhiteIpList =
|
|
|
+ adwebSiteBlackIpService.list(
|
|
|
+ new LambdaQueryWrapper<AdwebSiteBlackIp>()
|
|
|
+ .ne(AdwebSiteBlackIp::getStatus, 0)
|
|
|
+ .eq(AdwebSiteBlackIp::getBlackOrWhite, 1)
|
|
|
+ .eq(AdwebSiteBlackIp::getSiteId, adwebSite.getId())
|
|
|
+ .select(AdwebSiteBlackIp::getIp));
|
|
|
+ if (CollectionUtils.isNotEmpty(enquirySiteWhiteIpList)) {
|
|
|
+ siteWhiteIpList =
|
|
|
+ enquirySiteWhiteIpList.stream()
|
|
|
+ .map(AdwebSiteBlackIp::getIp)
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ adwebRedisUtil.set(siteWhiteIpRedisKey, siteWhiteIpList, 60 * 60 * 24);
|
|
|
+ } else {
|
|
|
+ siteWhiteIpList = new ArrayList<>();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return siteWhiteIpList;
|
|
|
+ }
|
|
|
+
|
|
|
+ /** 公共IP白名单列表 */
|
|
|
+ private List<String> getPublicWhiteIpList() {
|
|
|
+ List<String> publicWhiteIpList = getListFromRedis(WhiteIpListKey);
|
|
|
+ if (publicWhiteIpList == null) {
|
|
|
+ List<AdwebPublicBlackIp> enquiryPublicWhiteIpList =
|
|
|
+ adwebPublicBlackIpService.list(
|
|
|
+ new LambdaQueryWrapper<AdwebPublicBlackIp>()
|
|
|
+ .ne(AdwebPublicBlackIp::getStatus, 0)
|
|
|
+ .eq(AdwebPublicBlackIp::getBlackOrWhite, 1)
|
|
|
+ .select(AdwebPublicBlackIp::getIp));
|
|
|
+ if (CollectionUtils.isNotEmpty(enquiryPublicWhiteIpList)) {
|
|
|
+ publicWhiteIpList =
|
|
|
+ enquiryPublicWhiteIpList.stream()
|
|
|
+ .map(AdwebPublicBlackIp::getIp)
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ adwebRedisUtil.set(WhiteIpListKey, publicWhiteIpList, 60 * 60 * 24);
|
|
|
+ } else {
|
|
|
+ publicWhiteIpList = new ArrayList<>();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return publicWhiteIpList;
|
|
|
+ }
|
|
|
+
|
|
|
+ /** 获取公共黑名单IP列表 */
|
|
|
+ private List<String> getPublicBlackIpList() {
|
|
|
+ List<String> publicBlackIpList = getListFromRedis(BlackIpKey);
|
|
|
+
|
|
|
+ if (CollectionUtils.isEmpty(publicBlackIpList)) {
|
|
|
+ List<AdwebPublicBlackIp> enquiryPublicBlackIpList =
|
|
|
+ adwebPublicBlackIpService.list(
|
|
|
+ new LambdaQueryWrapper<AdwebPublicBlackIp>()
|
|
|
+ .ne(AdwebPublicBlackIp::getStatus, 0)
|
|
|
+ .eq(AdwebPublicBlackIp::getBlackOrWhite, 0)
|
|
|
+ .select(AdwebPublicBlackIp::getIp));
|
|
|
+ if (CollectionUtils.isNotEmpty(enquiryPublicBlackIpList)) {
|
|
|
+ publicBlackIpList =
|
|
|
+ enquiryPublicBlackIpList.stream()
|
|
|
+ .map(AdwebPublicBlackIp::getIp)
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ adwebRedisUtil.set(BlackIpKey, publicBlackIpList, 60 * 60 * 24);
|
|
|
+ } else {
|
|
|
+ publicBlackIpList = new ArrayList<>();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return publicBlackIpList;
|
|
|
+ }
|
|
|
+
|
|
|
+ /** 获取站点黑名单IP列表 */
|
|
|
+ private List<String> getSiteBlackIpList(AdwebSite adwebSite) {
|
|
|
+ String siteBlackIpRedisKey = SiteWhiteIpListKey + "::" + adwebSite.getId();
|
|
|
+
|
|
|
+ List<String> siteWhiteIpList = getListFromRedis(siteBlackIpRedisKey);
|
|
|
+
|
|
|
+ if (CollectionUtils.isEmpty(siteWhiteIpList)) {
|
|
|
+ List<AdwebSiteBlackIp> enquirySiteWhiteIpList =
|
|
|
+ adwebSiteBlackIpService.list(
|
|
|
+ new LambdaQueryWrapper<AdwebSiteBlackIp>()
|
|
|
+ .ne(AdwebSiteBlackIp::getStatus, 0)
|
|
|
+ .eq(AdwebSiteBlackIp::getBlackOrWhite, 1)
|
|
|
+ .eq(AdwebSiteBlackIp::getSiteId, adwebSite.getId())
|
|
|
+ .select(AdwebSiteBlackIp::getIp));
|
|
|
+ if (CollectionUtils.isNotEmpty(enquirySiteWhiteIpList)) {
|
|
|
+ siteWhiteIpList =
|
|
|
+ enquirySiteWhiteIpList.stream()
|
|
|
+ .map(AdwebSiteBlackIp::getIp)
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ adwebRedisUtil.set(siteBlackIpRedisKey, siteWhiteIpList, 60 * 60 * 24);
|
|
|
+ } else {
|
|
|
+ siteWhiteIpList = new ArrayList<>();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return siteWhiteIpList;
|
|
|
+ }
|
|
|
+
|
|
|
+ /** 获取站点黑名单邮箱列表 */
|
|
|
+ private List<String> getSiteBlackEmailList(AdwebSite adwebSite) {
|
|
|
+ String siteBlackEmailRedisKey = SiteBlackEmailKey + "::" + adwebSite.getId();
|
|
|
+ List<String> siteBlackEmailList = getListFromRedis(siteBlackEmailRedisKey);
|
|
|
+
|
|
|
+ if (CollectionUtils.isEmpty(siteBlackEmailList)) {
|
|
|
+ enquirySiteBlackEmailService.saveRedisSiteBlackEmailBySiteId(adwebSite.getId(), 0);
|
|
|
+ siteBlackEmailList = getListFromRedis(siteBlackEmailRedisKey);
|
|
|
+ if (CollectionUtils.isEmpty(siteBlackEmailList)) {
|
|
|
+ siteBlackEmailList = new ArrayList<>();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return siteBlackEmailList;
|
|
|
+ }
|
|
|
+
|
|
|
+ /** 获取站点白名单邮箱列表 */
|
|
|
+ private List<String> getSiteWhiteEmailList(AdwebSite adwebSite) {
|
|
|
+ String siteWhiteEmailRedisKey = SiteWhiteEmailListKey + "::" + adwebSite.getId();
|
|
|
+
|
|
|
+ List<String> siteWhiteEmailList = getListFromRedis(siteWhiteEmailRedisKey);
|
|
|
+
|
|
|
+ if (CollectionUtils.isEmpty(siteWhiteEmailList)) {
|
|
|
+ enquirySiteBlackEmailService.saveRedisSiteBlackEmailBySiteId(adwebSite.getId(), 0);
|
|
|
+ siteWhiteEmailList = getListFromRedis(siteWhiteEmailRedisKey);
|
|
|
+ if (CollectionUtils.isEmpty(siteWhiteEmailList)) {
|
|
|
+ siteWhiteEmailList = new ArrayList<>();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return siteWhiteEmailList;
|
|
|
+ }
|
|
|
+
|
|
|
+ /** 获取公共邮箱黑名单 */
|
|
|
+ private List<String> getPublicBlackEmailList() {
|
|
|
+ List<String> publicBlackEmailList = getListFromRedis(BlackEmailKey);
|
|
|
+
|
|
|
+ if (CollectionUtils.isEmpty(publicBlackEmailList)) {
|
|
|
+ List<AdwebPublicBlackEmail> enquiryPublicBlackEmailList =
|
|
|
+ adwebPublicBlackEmailService.list(
|
|
|
+ new LambdaQueryWrapper<AdwebPublicBlackEmail>()
|
|
|
+ .ne(AdwebPublicBlackEmail::getStatus, 0)
|
|
|
+ .eq(AdwebPublicBlackEmail::getBlackOrWhite, 0)
|
|
|
+ .isNotNull(AdwebPublicBlackEmail::getEmail)
|
|
|
+ .select(AdwebPublicBlackEmail::getEmail));
|
|
|
+
|
|
|
+ if (CollectionUtils.isNotEmpty(enquiryPublicBlackEmailList)) {
|
|
|
+ publicBlackEmailList =
|
|
|
+ enquiryPublicBlackEmailList.stream()
|
|
|
+ .map(AdwebPublicBlackEmail::getEmail)
|
|
|
+ .filter(StringUtil::isNotEmpty)
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ adwebRedisUtil.set(BlackEmailKey, publicBlackEmailList, 60 * 60 * 24);
|
|
|
+ } else {
|
|
|
+ publicBlackEmailList = new ArrayList<>();
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ publicBlackEmailList =
|
|
|
+ publicBlackEmailList.stream().filter(s -> !s.isEmpty()).collect(Collectors.toList());
|
|
|
+ }
|
|
|
+
|
|
|
+ return publicBlackEmailList;
|
|
|
+ }
|
|
|
+
|
|
|
+ /** 获取公共邮箱白名单 */
|
|
|
+ private List<String> getPublicWhiteEmailList() {
|
|
|
+ List<String> publicWhiteEmailList = getListFromRedis(WhiteEmailListKey);
|
|
|
+
|
|
|
+ if (CollectionUtils.isEmpty(publicWhiteEmailList)) {
|
|
|
+ List<AdwebPublicBlackEmail> enquiryPublicWhiteEmailList =
|
|
|
+ adwebPublicBlackEmailService.list(
|
|
|
+ new LambdaQueryWrapper<AdwebPublicBlackEmail>()
|
|
|
+ .ne(AdwebPublicBlackEmail::getStatus, 0)
|
|
|
+ .eq(AdwebPublicBlackEmail::getBlackOrWhite, 1)
|
|
|
+ .isNotNull(AdwebPublicBlackEmail::getEmail)
|
|
|
+ .select(AdwebPublicBlackEmail::getEmail));
|
|
|
+
|
|
|
+ if (CollectionUtils.isNotEmpty(enquiryPublicWhiteEmailList)) {
|
|
|
+ publicWhiteEmailList =
|
|
|
+ enquiryPublicWhiteEmailList.stream()
|
|
|
+ .map(AdwebPublicBlackEmail::getEmail)
|
|
|
+ .filter(StringUtil::isNotEmpty)
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ adwebRedisUtil.set(WhiteEmailListKey, publicWhiteEmailList, 60 * 60 * 24);
|
|
|
+ } else {
|
|
|
+ publicWhiteEmailList = new ArrayList<>();
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ publicWhiteEmailList =
|
|
|
+ publicWhiteEmailList.stream().filter(s -> !s.isEmpty()).collect(Collectors.toList());
|
|
|
+ }
|
|
|
+
|
|
|
+ return publicWhiteEmailList;
|
|
|
+ }
|
|
|
+
|
|
|
+ /** 从redis中获取List<String> */
|
|
|
+ private List<String> getListFromRedis(String redisKey) {
|
|
|
+ try {
|
|
|
+ Object result = adwebRedisUtil.get(redisKey);
|
|
|
+ if (result instanceof List<?>) {
|
|
|
+ @SuppressWarnings("unchecked")
|
|
|
+ List<String> list = (List<String>) result;
|
|
|
+ return list;
|
|
|
+ } else {
|
|
|
+ return new ArrayList<>();
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ // Log the exception and return an empty list as a fallback
|
|
|
+ log.error("Failed to retrieve data from Redis: {}", e.getMessage());
|
|
|
+ return new ArrayList<>();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
private boolean validateWordLength(String text) {
|
|
|
if (StringUtil.isEmpty(text)) {
|
|
|
return false;
|