Commit fa241b6f authored by huangjiamin's avatar huangjiamin

迁移ip

parent 2aab3e92
...@@ -7,9 +7,11 @@ import com.edgec.browserbackend.account.dto.ResultDto; ...@@ -7,9 +7,11 @@ import com.edgec.browserbackend.account.dto.ResultDto;
import com.edgec.browserbackend.account.dto.UserUsedDto; import com.edgec.browserbackend.account.dto.UserUsedDto;
import com.edgec.browserbackend.account.service.*; import com.edgec.browserbackend.account.service.*;
import com.edgec.browserbackend.browser.ErrorCode.BrowserErrorCode; import com.edgec.browserbackend.browser.ErrorCode.BrowserErrorCode;
import com.edgec.browserbackend.browser.dto.IpListRequestDto;
import com.edgec.browserbackend.browser.service.TempService; import com.edgec.browserbackend.browser.service.TempService;
import com.edgec.browserbackend.common.auth.Securitys; import com.edgec.browserbackend.common.auth.Securitys;
import com.edgec.browserbackend.common.commons.error.ClientRequestException; import com.edgec.browserbackend.common.commons.error.ClientRequestException;
import com.edgec.browserbackend.common.utils.ResponseUtil;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
...@@ -17,6 +19,7 @@ import org.springframework.beans.factory.annotation.Autowired; ...@@ -17,6 +19,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page; import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Pageable;
import org.springframework.data.repository.query.Param;
import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
...@@ -591,6 +594,47 @@ public class AdministratorController { ...@@ -591,6 +594,47 @@ public class AdministratorController {
} }
return resultDto; return resultDto;
} }
/**
* 获取用户IP列表
*
* @param owner owner
* @return ResultDto
*/
@GetMapping(value = "/{owner}/ip")
public ResultDto ipMigration(@PathVariable String owner) {
String logs = "【IpMigration】 ";
log.info("{}, params : {}", logs, owner);
try {
return ResponseUtil.success(administratorService.getUsernameIpList(owner));
} catch (Exception e) {
log.error("{}, Exception : {}", logs, e.getMessage(), e);
return ResponseUtil.error(e.getMessage());
}
}
/**
* 迁移ip
*
* @param owner owner
* @param newOwner newOwner
* @param ips ips
* @return ResultDto
*/
@PutMapping(value = "/{owner}/ip/{newOwner}")
public ResultDto ipMigration(@PathVariable String owner, @PathVariable String newOwner, @RequestParam String ips) {
String logs = "【IpMigration】 ";
log.info("{}, params : {}, {} ip migration {}", logs, owner, newOwner, ips);
try {
return ResponseUtil.success(administratorService.ipMigration(owner, newOwner, ips));
} catch (ClientRequestException e) {
log.warn("{}, ClientRequestException : {}", logs, e.getErrorCode().getReason());
return ResponseUtil.error(e.getErrorCode());
} catch (Exception e) {
log.error("{}, Exception : {}", logs, e.getMessage(), e);
return ResponseUtil.error(e.getMessage());
}
}
} }
......
...@@ -2,6 +2,7 @@ package com.edgec.browserbackend.account.service; ...@@ -2,6 +2,7 @@ package com.edgec.browserbackend.account.service;
import com.edgec.browserbackend.account.domain.*; import com.edgec.browserbackend.account.domain.*;
import com.edgec.browserbackend.account.dto.*; import com.edgec.browserbackend.account.dto.*;
import com.edgec.browserbackend.browser.domain.IpResource;
import org.springframework.data.domain.Page; import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Pageable;
...@@ -70,4 +71,7 @@ public interface AdministratorService { ...@@ -70,4 +71,7 @@ public interface AdministratorService {
Long convertToDistributor(String id, boolean tag); Long convertToDistributor(String id, boolean tag);
List<String> getUsernameIpList(String owner);
List<String> ipMigration(String owner, String newOwner, String ips);
} }
...@@ -8,6 +8,7 @@ import com.edgec.browserbackend.account.service.AdministratorService; ...@@ -8,6 +8,7 @@ import com.edgec.browserbackend.account.service.AdministratorService;
import com.edgec.browserbackend.auth.service.UserService; import com.edgec.browserbackend.auth.service.UserService;
import com.edgec.browserbackend.browser.ErrorCode.BrowserErrorCode; import com.edgec.browserbackend.browser.ErrorCode.BrowserErrorCode;
import com.edgec.browserbackend.browser.domain.IpCountRecord; import com.edgec.browserbackend.browser.domain.IpCountRecord;
import com.edgec.browserbackend.browser.domain.IpResource;
import com.edgec.browserbackend.browser.domain.ProxyConfig; import com.edgec.browserbackend.browser.domain.ProxyConfig;
import com.edgec.browserbackend.browser.repository.IpCountRecordRepository; import com.edgec.browserbackend.browser.repository.IpCountRecordRepository;
import com.edgec.browserbackend.browser.repository.IpResourceRepository; import com.edgec.browserbackend.browser.repository.IpResourceRepository;
...@@ -718,6 +719,18 @@ public class AdministratorServiceImpl implements AdministratorService { ...@@ -718,6 +719,18 @@ public class AdministratorServiceImpl implements AdministratorService {
return accountRepository.convertToDistributor(id, tag); return accountRepository.convertToDistributor(id, tag);
} }
@Override
public List<String> getUsernameIpList(String owner) {
return ipResourceRepository.findByOwnerAndIsDeleted(owner, false).stream().map(IpResource::getAddr).collect(Collectors.toList());
}
@Override
public List<String> ipMigration(String owner, String newOwner, String ips) {
accountRepository.findByName(newOwner).orElseThrow(() -> new ClientRequestException(AccountErrorCode.NAMENOTEXIST));
Arrays.asList(ips.split(";")).forEach(ip ->ipResourceRepository.ipMigration(owner, newOwner, ip));
return getUsernameIpList(newOwner);
}
} }
......
...@@ -82,4 +82,13 @@ public interface IpResourceRepository extends MongoRepository<IpResource, String ...@@ -82,4 +82,13 @@ public interface IpResourceRepository extends MongoRepository<IpResource, String
List<IpResource> findByStatusInAndIsDeletedAndIsLocked(List<Integer> status, boolean isDeleted, boolean isLocked); List<IpResource> findByStatusInAndIsDeletedAndIsLocked(List<Integer> status, boolean isDeleted, boolean isLocked);
List<IpResource> findByValidTimeLessThanAndIsDeleted(long toEpochMilli, boolean b); List<IpResource> findByValidTimeLessThanAndIsDeleted(long toEpochMilli, boolean b);
/**
* 查询用户未被删除的ip
*
* @param owner owner
* @param isDelete isDelete
* @return List
*/
List<IpResource> findByOwnerAndIsDeleted(String owner, boolean isDelete);
} }
...@@ -36,4 +36,13 @@ public interface IpResourceRepositoryCustom { ...@@ -36,4 +36,13 @@ public interface IpResourceRepositoryCustom {
List<IpResource> findShopIdInListAndRegionLike(List<String> shopIds, boolean isDeleted, String region); List<IpResource> findShopIdInListAndRegionLike(List<String> shopIds, boolean isDeleted, String region);
List<IpResource> specialLineCheckTask(); List<IpResource> specialLineCheckTask();
/**
* ip迁移
*
* @param owner owner
* @param newOwner newOwner
* @param ip ip
*/
void ipMigration(String owner, String newOwner, String ip);
} }
...@@ -233,4 +233,14 @@ public class IpResourceRepositoryCustomImpl implements IpResourceRepositoryCusto ...@@ -233,4 +233,14 @@ public class IpResourceRepositoryCustomImpl implements IpResourceRepositoryCusto
return list; return list;
} }
@Override
public void ipMigration(String owner, String newOwner, String ip) {
Document doc = new Document();
BasicQuery basicQuery = new BasicQuery(doc);
basicQuery.addCriteria(where("addr").is(ip).and("owner").is(owner).and("isDeleted").is(false));
Update update = new Update();
update.set("owner", newOwner);
mongoTemplate.updateFirst(basicQuery, update, IpResource.class);
}
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment