绑定号码去重

master
yqy 1 year ago
parent 2ea11676c4
commit 7294fa5c6b

@ -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<ProxyAccountEntity>().in(ProxyAccountEntity::getNid, phoneList));
}
/**
*
*
* @param phones
* @return
*/
public List<String> checkSamePhone(List<String> phones) {
List<String> repeatList = proxyAccountMapper.selectList(new LambdaQueryWrapper<ProxyAccountEntity>().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<ProxyAccountEntity> list = new ArrayList<>();
String[] split = phone.split(",");
List<String> originList = Arrays.asList(phone.split(","));
List<String> 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<ProxyAccountEntity>().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<ProxyEntity> proxyEntityList) {
proxyMapper.insertAll(proxyEntityList);
List<ProxyAccountEntity> list = new ArrayList<>();
for (ProxyEntity proxyEntity : proxyEntityList) {
List<String> phoneList = proxyEntity.getPhoneList();
for (String phone : phoneList) {
//去重
List<String> 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;
}

Loading…
Cancel
Save