From 7294fa5c6b76484fe509eeaaf675ff122eabb695 Mon Sep 17 00:00:00 2001 From: yqy Date: Fri, 28 Apr 2023 14:03:52 +0800 Subject: [PATCH] =?UTF-8?q?=E7=BB=91=E5=AE=9A=E5=8F=B7=E7=A0=81=E5=8E=BB?= =?UTF-8?q?=E9=87=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../baiye/service/impl/ProxyServiceImpl.java | 31 +++++++++++++++---- 1 file changed, 25 insertions(+), 6 deletions(-) diff --git a/cdp-tools/cdp-tool-xhs/cdp-tool-xhs-service/src/main/java/com/baiye/service/impl/ProxyServiceImpl.java b/cdp-tools/cdp-tool-xhs/cdp-tool-xhs-service/src/main/java/com/baiye/service/impl/ProxyServiceImpl.java index 24d2e91..0ed5fab 100644 --- a/cdp-tools/cdp-tool-xhs/cdp-tool-xhs-service/src/main/java/com/baiye/service/impl/ProxyServiceImpl.java +++ b/cdp-tools/cdp-tool-xhs/cdp-tool-xhs-service/src/main/java/com/baiye/service/impl/ProxyServiceImpl.java @@ -1,6 +1,7 @@ package com.baiye.service.impl; import cn.hutool.core.collection.CollUtil; +import cn.hutool.core.collection.CollectionUtil; import cn.hutool.core.io.FileUtil; import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.RandomUtil; @@ -223,14 +224,30 @@ public class ProxyServiceImpl implements ProxyService { proxyAccountMapper.delete(new LambdaQueryWrapper().in(ProxyAccountEntity::getNid, phoneList)); } + /** + * 号码查重 + * + * @param phones 需要检测的号码集合 + * @return 去掉重复后的号码集合 + */ + public List checkSamePhone(List phones) { + List repeatList = proxyAccountMapper.selectList(new LambdaQueryWrapper().in(ProxyAccountEntity::getNid, phones)).stream().map(ProxyAccountEntity::getNid).collect(Collectors.toList()); + return CollectionUtil.subtractToList(phones, repeatList); + } + @Override public void addAccountIp(Long proxyId, String phone) { List list = new ArrayList<>(); - String[] split = phone.split(","); + List originList = Arrays.asList(phone.split(",")); + List phoneList = checkSamePhone(originList); - for (String p : split) { - log.info("号码 =" + p.trim()); + for (String p : phoneList) { ProxyAccountEntity proxyAccountEntity = new ProxyAccountEntity(p.trim(), proxyId); +// ProxyAccountEntity checkEntity = proxyAccountMapper.selectOne(new LambdaQueryWrapper().eq(ProxyAccountEntity::getNid, p.trim())); +// if (checkEntity != null && checkEntity.getProxyId() != null) { +// log.warn("号码重复 ,phone:{}", p); +// continue; +// } list.add(proxyAccountEntity); } if (CollUtil.isNotEmpty(list)) { @@ -246,11 +263,13 @@ public class ProxyServiceImpl implements ProxyService { @Transactional(rollbackFor = Exception.class) public void insertAll(List proxyEntityList) { proxyMapper.insertAll(proxyEntityList); - List list = new ArrayList<>(); + for (ProxyEntity proxyEntity : proxyEntityList) { List phoneList = proxyEntity.getPhoneList(); - for (String phone : phoneList) { + //去重 + List phones = checkSamePhone(phoneList); + for (String phone : phones) { ProxyAccountEntity proxyAccountEntity = new ProxyAccountEntity(phone, proxyEntity.getId()); list.add(proxyAccountEntity); } @@ -312,7 +331,7 @@ public class ProxyServiceImpl implements ProxyService { } } catch (Exception e) { log.error("无效的代理地址: {},号码:{}, 错误信息:{}", proxyEntity.getIp(), phone, e.getMessage()); - throw new BadRequestException("代理Ip不可用,请重新绑定,号码:" + phone); + throw new BadRequestException("代理Ip不可用或代理网络不稳定 ,请更换代理或重试,号码:" + phone); } return proxyEntity; }