Commit e376761d authored by jim's avatar jim

ip

parent b8163943
package com.edgec.browserbackend.browser.domain;
import com.edgec.browserbackend.browser.dto.Interval;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import org.springframework.data.annotation.Id;
import org.springframework.data.annotation.Transient;
import org.springframework.data.mongodb.core.mapping.Document;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
@Document(collection = "ipresource")
@JsonIgnoreProperties(ignoreUnknown = true)
public class IpResource implements Serializable {
@Id
private String id;
private String addr;
......@@ -311,4 +311,22 @@ public class IpResource implements Serializable {
public void setShopId(String shopId) {
this.shopId = shopId;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof IpResource)) return false;
IpResource that = (IpResource) o;
return Objects.equals(getId(), that.getId());
}
@Override
public int hashCode() {
return Objects.hash(getId());
}
}
package com.edgec.browserbackend.browser.dto;
import com.alibaba.fastjson.JSONObject;
import com.edgec.browserbackend.browser.domain.IpResource;
import com.edgec.browserbackend.browser.domain.Shop;
import com.edgec.browserbackend.browser.domain.TransferStatus;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.google.gson.JsonObject;
import org.elasticsearch.client.license.LicensesStatus;
import java.util.ArrayList;
import java.util.List;
import java.util.Stack;
@JsonIgnoreProperties(ignoreUnknown = true)
public class ShopResultDto {
......
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;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.mongodb.repository.MongoRepository;
......@@ -13,27 +9,45 @@ import java.util.List;
public interface IpResourceRepository extends MongoRepository<IpResource, String>, IpResourceRepositoryCustom {
IpResource findByAddr(String addr);
IpResource findByAddrAndIsDeletedAndIsLocked(String addr, boolean isDeleted, boolean isLocked);
IpResource findByAddrAndIsDeleted(String addr, boolean isDeleted);
IpResource findByIdAndIsDeletedAndIsLocked(String id, boolean isDeleted, boolean isLocked);
IpResource findByIdAndIsDeleted(String id, boolean isDeleted);
Page<IpResource> findByIdInAndIsDeletedOrderByPurchasedTimeDesc(List<String> ipIds, boolean isDeleted, Pageable pageable);
List<IpResource> findByOwnerAndIsDeletedAndBind(String owner, boolean isDeleted, boolean bind);
List<IpResource> findByOwnerAndStatusIsNotInAndIsDeletedAndBind(String owner, List<Integer> status, boolean isDeleted, boolean bind);
List<IpResource> findByOwnerAndStatusInAndIsDeletedAndBind(String owner, List<Integer> status, boolean isDeleted, boolean bind);
List<IpResource> findByOwnerAndStatusAndIsDeletedAndBind(String owner, int status, boolean isDeleted, boolean bind);
List<IpResource> findByOwnerInAndIsDeletedAndBind(List<String> owner, boolean isDeleted, boolean bind);
List<IpResource> findByOwnerInAndStatusIsNotInAndIsDeletedAndBind(List<String> owner, List<Integer> status, boolean isDeleted, boolean bind);
List<IpResource> findByOwnerInAndStatusInAndIsDeletedAndBind(List<String> owner, List<Integer> status, boolean isDeleted, boolean bind);
List<IpResource> findByOwnerInAndStatusAndIsDeletedAndBind(List<String> owner, int status, boolean isDeleted, boolean bind);
Page<IpResource> findByIsDeletedAndIdInAndAddrLikeOrderByPurchasedTimeDesc(boolean isDeleted, List<String> ipIds, String addr, Pageable pageable);
Page<IpResource> findByIsDeletedAndIdInAndVendorCnLikeOrderByPurchasedTimeDesc(boolean isDeleted, List<String> ipIds, String vendorCn, Pageable pageable);
Page<IpResource> findByIsDeletedAndIdInAndVendorLikeOrderByPurchasedTimeDesc(boolean isDeleted, List<String> ipIds, String vendor, Pageable pageable);
Page<IpResource> findByIsDeletedAndIdInAndRegionCnLikeOrderByPurchasedTimeDesc(boolean isDeleted, List<String> ipIds, String region, Pageable pageable);
List<IpResource> findByIsDeleted(boolean isDeleted);
List<IpResource> findByOwnerInAndSpecialLine(List<String> owners, boolean specialLine);
List<IpResource> findBySpecialLineAndIsDeleted(boolean specialLine, boolean isDeleted);
List<IpResource> findByRegionInAndIsDeleted(List<String> regions, boolean isDeleted);
......@@ -49,6 +63,8 @@ public interface IpResourceRepository extends MongoRepository<IpResource, String
long countAllByIsDeletedAndValidTimeGreaterThan(boolean isDeleted, long time);
long countAllByOwnerAndIsDeletedAndValidTimeGreaterThan(String username, boolean isDeleted, long time);
long countAllByOwnerInAndIsDeletedAndValidTimeGreaterThan(List<String> username, boolean isDeleted, long time);
long countAllByOwner(String username);
}
......@@ -19,6 +19,8 @@ public interface IpResourceRepositoryCustom {
List<IpResource> sampleTasks(List<Integer> status);
List<IpResource> findIds();
boolean addShopId(String ipId, String shopId);
boolean deleteShopId(String ipId, String shopId, BindHistory bindHistory);
......
......@@ -3,17 +3,13 @@ package com.edgec.browserbackend.browser.repository;
import com.edgec.browserbackend.browser.domain.BindHistory;
import com.edgec.browserbackend.browser.domain.IpResource;
import com.edgec.browserbackend.browser.dto.IpResourceUnwindResultDto;
import com.edgec.browserbackend.common.utils.JsonUtils;
import com.mongodb.client.result.UpdateResult;
import org.apache.commons.lang3.StringUtils;
import org.bson.Document;
import org.elasticsearch.common.recycler.Recycler;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.aggregation.*;
import org.springframework.data.mongodb.core.query.BasicQuery;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.CriteriaDefinition;
import org.springframework.data.mongodb.core.query.Update;
import java.time.Instant;
......@@ -95,7 +91,7 @@ public class IpResourceRepositoryCustomImpl implements IpResourceRepositoryCusto
@Override
public List<IpResource> sampleTasks(int status, long timestamp) {
Criteria matchCriteria = new Criteria();
Criteria matchCriteria = new Criteria();
matchCriteria.orOperator(where("status").is(status).and("isLocked").is(false).and("isDeleted").is(false),
where("status").is(status).and("isLocked").is(true).and("lockTimestamp").lte(timestamp).and("isDeleted").is(false));
......@@ -110,8 +106,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("validTime").gt(Instant.now().toEpochMilli()).and("isDeleted").is(false).and("healthLockTimestamp").lte(Instant.now().minusSeconds(60*30).toEpochMilli()),
Criteria matchCriteria = new Criteria();
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);
......@@ -194,7 +190,7 @@ public class IpResourceRepositoryCustomImpl implements IpResourceRepositoryCusto
if (ipResourceUnwindResultDtos.isEmpty()) {
return new ArrayList<>();
}
HashMap<String ,IpResource> ipResourceHashMap = new HashMap<>();
HashMap<String, IpResource> ipResourceHashMap = new HashMap<>();
ipResourceUnwindResultDtos.forEach(x -> {
if (ipResourceHashMap.containsKey(x.getId())) {
ipResourceHashMap.get(x.getId()).getShopIds().add(x.getShopId());
......@@ -203,8 +199,8 @@ public class IpResourceRepositoryCustomImpl implements IpResourceRepositoryCusto
}
});
List<IpResource> result = new ArrayList<>();
Set<Map.Entry<String,IpResource>> entry = ipResourceHashMap.entrySet();
for(Map.Entry<String,IpResource> e:entry){
Set<Map.Entry<String, IpResource>> entry = ipResourceHashMap.entrySet();
for (Map.Entry<String, IpResource> e : entry) {
result.add(e.getValue());
}
return result;
......@@ -220,7 +216,7 @@ public class IpResourceRepositoryCustomImpl implements IpResourceRepositoryCusto
if (ipResourceUnwindResultDtos.isEmpty()) {
return new ArrayList<>();
}
HashMap<String ,IpResource> ipResourceHashMap = new HashMap<>();
HashMap<String, IpResource> ipResourceHashMap = new HashMap<>();
ipResourceUnwindResultDtos.forEach(x -> {
if (ipResourceHashMap.containsKey(x.getId())) {
ipResourceHashMap.get(x.getId()).getShopIds().add(x.getShopId());
......@@ -229,8 +225,8 @@ public class IpResourceRepositoryCustomImpl implements IpResourceRepositoryCusto
}
});
List<IpResource> result = new ArrayList<>();
Set<Map.Entry<String,IpResource>> entry = ipResourceHashMap.entrySet();
for(Map.Entry<String,IpResource> e:entry){
Set<Map.Entry<String, IpResource>> entry = ipResourceHashMap.entrySet();
for (Map.Entry<String, IpResource> e : entry) {
result.add(e.getValue());
}
return result;
......@@ -246,7 +242,7 @@ public class IpResourceRepositoryCustomImpl implements IpResourceRepositoryCusto
if (ipResourceUnwindResultDtos.isEmpty()) {
return new ArrayList<>();
}
HashMap<String ,IpResource> ipResourceHashMap = new HashMap<>();
HashMap<String, IpResource> ipResourceHashMap = new HashMap<>();
ipResourceUnwindResultDtos.forEach(x -> {
if (ipResourceHashMap.containsKey(x.getId())) {
ipResourceHashMap.get(x.getId()).getShopIds().add(x.getShopId());
......@@ -255,10 +251,19 @@ public class IpResourceRepositoryCustomImpl implements IpResourceRepositoryCusto
}
});
List<IpResource> result = new ArrayList<>();
Set<Map.Entry<String,IpResource>> entry = ipResourceHashMap.entrySet();
for(Map.Entry<String,IpResource> e:entry){
Set<Map.Entry<String, IpResource>> entry = ipResourceHashMap.entrySet();
for (Map.Entry<String, IpResource> e : entry) {
result.add(e.getValue());
}
return result;
}
@Override
public List<IpResource> findIds() {
BasicQuery basicQuery = new BasicQuery(new Document());
basicQuery.fields().include("id");
return mongoTemplate.find(basicQuery, IpResource.class);
}
}
......@@ -597,17 +597,18 @@ public class IpResourceServiceImpl implements IpResourceService {
notUsed = ipResourceRepository.findByOwnerInAndStatusIsNotInAndIsDeletedAndBind(children, Arrays.asList(3, 5, 6), false, false);
break;
case 5:
// 已分配
ipResources = ipResourceRepository.findShopIdInList(shopIds, false);
if (!isParent)
notUsed = ipResourceRepository.findByOwnerAndStatusIsNotInAndIsDeletedAndBind(username, Arrays.asList(0, 2, 4, 8), false, false);
notUsed = ipResourceRepository.findByOwnerAndStatusInAndIsDeletedAndBind(username, Arrays.asList(2, 4, 8), false, false);
else
notUsed = ipResourceRepository.findByOwnerInAndStatusIsNotInAndIsDeletedAndBind(children, Arrays.asList(0, 2, 4, 8), false, false);
notUsed = ipResourceRepository.findByOwnerInAndStatusInAndIsDeletedAndBind(children, Arrays.asList(2, 4, 8), false, false);
break;
}
if (notUsed != null)
ipResources.addAll(notUsed);
List<IpResourceDto> ipResourceDtos = new ArrayList<>();
List<String> allIpIds = ipResources.stream().map(x -> x.getId()).collect(Collectors.toList());
List<String> allIpIds = ipResources.stream().distinct().map(x -> x.getId()).collect(Collectors.toList());
Page<IpResource> ipResources1 = null;
if (ipFilterDto != null && StringUtils.isNotBlank(ipFilterDto.getRegion())) {
ipResources1 = ipResourceRepository.findByIsDeletedAndIdInAndRegionCnLikeOrderByPurchasedTimeDesc(false, allIpIds, ipFilterDto.getRegion(), pageable);
......
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