Commit e376761d authored by jim's avatar jim

ip

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