Commit 21b06852 authored by Administrator's avatar Administrator

Merge branch 'staging' into 'master'

Staging

See merge request !115
parents f95ec053 ebfc8950
......@@ -167,4 +167,20 @@ public class IpControlloer {
}
return resultDto;
}
@RequestMapping(value = "/releasedeleted", method = RequestMethod.PUT)
public ResultDto deleteUseless(Principal principal) {
ResultDto resultDto = new ResultDto();
try {
ipResourceService.releaseDeletedIp();
resultDto.setStatus(0);
} catch (Exception e) {
resultDto.setStatus(-1);
Map<String, Object> statusInfo = new HashMap<>();
statusInfo.put("code", 80001);
statusInfo.put("message", e.getMessage());
resultDto.setStatusInfo(statusInfo);
}
return resultDto;
}
}
package com.edgec.browserbackend.browser.repository;
import com.edgec.browserbackend.browser.domain.IpResource;
import com.edgec.browserbackend.browser.domain.IpType;
import com.edgec.browserbackend.browser.domain.Shop;
import com.google.gson.internal.$Gson$Preconditions;
import org.springframework.data.domain.Page;
......@@ -28,6 +29,8 @@ public interface IpResourceRepository extends MongoRepository<IpResource, String
Page<IpResource> findByIsDeletedAndIdInAndRegionCnLikeOrderByPurchasedTimeDesc(boolean isDeleted, List<String> ipIds, String region, Pageable pageable);
List<IpResource> findByIsDeletedAndShopIdInAndRegionCnLike(boolean isDeleted, List<String> shopIds, String regionCn);
List<IpResource> findByIsDeleted(boolean isDeleted);
List<IpResource> findByOwnerInAndSpecialLine(List<String> owners, boolean specialLine);
List<IpResource> findBySpecialLineAndIsDeleted(boolean specialLine, boolean isDeleted);
......
......@@ -112,8 +112,8 @@ public class IpResourceRepositoryCustomImpl implements IpResourceRepositoryCusto
@Override
public List<IpResource> sampleTasks(List<Integer> status) {
Criteria matchCriteria = new Criteria();
matchCriteria.orOperator(where("status").in(status).and("isLocked").is(false).and("isDeleted").is(false).and("healthLockTimestamp").lte(Instant.now().minusSeconds(60*30).toEpochMilli()),
where("status").in(status).and("isLocked").is(true).and("healthLockTimestamp").lte(Instant.now().minusSeconds(300).toEpochMilli()).and("isDeleted").is(false));
matchCriteria.orOperator(where("status").in(status).and("isLocked").is(false).and("validTime").gt(Instant.now().toEpochMilli()).and("isDeleted").is(false).and("healthLockTimestamp").lte(Instant.now().minusSeconds(60*30).toEpochMilli()),
where("status").in(status).and("isLocked").is(true).and("healthLockTimestamp").lte(Instant.now().minusSeconds(600).toEpochMilli()).and("isDeleted").is(false));
MatchOperation match = Aggregation.match(matchCriteria);
......
......@@ -801,4 +801,18 @@ public class IpResourceServiceImpl implements IpResourceService {
ipResourceRepository.save(ipResource);
}
}
@Override
public void releaseDeletedIp() {
String URL = (profiles.equals("dev") || profiles.equals("staging"))? TESTURL : CLOUDAMURL;
RestTemplate restTemplate = new RestTemplate();
HttpHeaders headers = buildGetHeader();
Map<String, String> params = new HashMap<String, String>();
HttpEntity<Map<String, String>> httpEntity = new HttpEntity<>(params, headers);
List<IpResource> ipResources = ipResourceRepository.findByIsDeleted(true);
for (IpResource ipResource : ipResources) {
ResponseEntity<String> result = restTemplate.exchange(URL + "/intelligroup/ipresources?accountId=browser&ip={ip}", HttpMethod.DELETE, httpEntity, String.class, ipResource.getAddr());
DeleteIpResultDto deleteIpResultDto = JSON.parseObject(result.getBody(), DeleteIpResultDto.class);
}
}
}
......@@ -30,4 +30,6 @@ public interface IpResourceService {
IpResourceDto queryIp(String username, IpResourceRequestDto ipResourceRequestDto);
void setSpecialLine();
void releaseDeletedIp();
}
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