Commit b0bfce0e authored by renjie's avatar renjie

Merge branch 'dev-zrj' into 'staging'

返回店铺接口修改

See merge request !42
parents 0d3fd1a6 76d2b89a
......@@ -50,7 +50,8 @@ public class IpResourceDto {
this.password = ipResource.getPassword();
this.protocol = ipResource.getProtocol();
this.specialLine = ipResource.isSpecialLine();
this.bindShop = shopDto;
if (shopDto != null)
this.bindShop = shopDto;
if (useHistory)
this.bindHistories = ipResource.getBindHistory();
else
......
......@@ -32,11 +32,11 @@ public class ShopResultDto {
private String shopCookie;
private IpResource bindIp;
private IpResourceDto bindIp;
private long createTime;
public static ShopResultDto of(Shop shop, String group, IpResource ipResources) {
public static ShopResultDto of(Shop shop, String group, IpResourceDto ipResources) {
ShopResultDto shopResultDto = new ShopResultDto();
shopResultDto.setShopId(shop.getShopId());
if (shop.getShopName() != null)
......@@ -135,11 +135,11 @@ public class ShopResultDto {
this.shopUrl = shopUrl;
}
public IpResource getBindIp() {
public IpResourceDto getBindIp() {
return bindIp;
}
public void setBindIp(IpResource bindIp) {
public void setBindIp(IpResourceDto bindIp) {
this.bindIp = bindIp;
}
......
......@@ -28,6 +28,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> findByOwnerInAndSpecialLine(List<String> owners, boolean specialLine);
List<IpResource> findByStatusAndLockedAndLockTimestampLessThan(int status, boolean locked, long timestamp);
List<IpResource> findByValidTimeBetweenAndIsDeleted(long beginTime, long endTime, boolean isDeleted);
......
......@@ -7,10 +7,7 @@ import com.edgec.browserbackend.account.repository.AccountRepository;
import com.edgec.browserbackend.browser.ErrorCode.BrowserErrorCode;
import com.edgec.browserbackend.browser.domain.*;
import com.edgec.browserbackend.browser.dto.*;
import com.edgec.browserbackend.browser.repository.GroupRepository;
import com.edgec.browserbackend.browser.repository.IpResourceRepository;
import com.edgec.browserbackend.browser.repository.ShopRepository;
import com.edgec.browserbackend.browser.repository.UserShopRepository;
import com.edgec.browserbackend.browser.repository.*;
import com.edgec.browserbackend.browser.service.IpAndShopService;
import com.edgec.browserbackend.browser.service.ShopService;
import com.edgec.browserbackend.common.commons.error.ClientRequestException;
......@@ -25,6 +22,7 @@ import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.security.core.parameters.P;
import org.springframework.security.task.DelegatingSecurityContextAsyncTaskExecutor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;
......@@ -63,6 +61,9 @@ public class ShopServiceImpl implements ShopService {
@Autowired
IpAndShopService ipAndShopService;
@Autowired
SpecialLineRepository specialLineRepository;
@Override
public String addShop(String username, ShopResultDto shopResultDto) {
Account account = accountRepository.findByName(username);
......@@ -319,7 +320,13 @@ public class ShopServiceImpl implements ShopService {
if (ipResource == null)
throw new ClientRequestException(BrowserErrorCode.IPNOTEXIST);
String group = userShopRepository.findByUsernameAndShopId(username, shop.getShopId()).getGroupId();
ShopResultDto shopResultDto = ShopResultDto.of(shop, group, ipResource);
ShopResultDto shopResultDto = null;
if (ipResource.isSpecialLine()) {
SpecialLine specialLine = specialLineRepository.findAll().get(0);
shopResultDto = ShopResultDto.of(shop, group, new IpResourceDto(ipResource, null, false, specialLine));
}
else
shopResultDto = ShopResultDto.of(shop, group, new IpResourceDto(ipResource, null, false));
return shopResultDto;
}
......@@ -400,7 +407,14 @@ public class ShopServiceImpl implements ShopService {
if (ipResource == null)
ipResource = new IpResource();
String group1 = userShopRepository.findByUsernameAndShopId(username, x.getShopId()).getGroupId();
shopResultDtos.add(ShopResultDto.of(x, group1, ipResource));
ShopResultDto shopResultDto = null;
if (ipResource.isSpecialLine()) {
SpecialLine specialLine = specialLineRepository.findAll().get(0);
shopResultDto = ShopResultDto.of(x, group1, new IpResourceDto(ipResource, null, false, specialLine));
}
else
shopResultDto = ShopResultDto.of(x, group1, new IpResourceDto(ipResource, null, false));
shopResultDtos.add(shopResultDto);
});
Page<ShopResultDto> shopDtoPage = new PageImpl<>(shopResultDtos, pageable, shopIds.size());
ShopPageResultDto shopPageResultDto = new ShopPageResultDto();
......
......@@ -3,13 +3,19 @@ package com.edgec.browserbackend.browser.task;
import com.edgec.browserbackend.account.repository.AccountRepository;
import com.edgec.browserbackend.auth.domain.mongo.MongoOAuth2AccessToken;
import com.edgec.browserbackend.auth.repository.mongo.MongoOAuth2AccessTokenRepository;
import com.edgec.browserbackend.browser.domain.IpResource;
import com.edgec.browserbackend.browser.domain.SpecialLine;
import com.edgec.browserbackend.browser.repository.IpResourceRepository;
import com.edgec.browserbackend.browser.repository.SpecialLineRepository;
import com.edgec.browserbackend.browser.service.Impl.IpResourceServiceImpl;
import com.edgec.browserbackend.common.commons.utils.RemoteShellExecutor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import java.io.FileInputStream;
import java.io.*;
import java.time.Instant;
import java.util.List;
import java.util.stream.Collectors;
......@@ -25,12 +31,51 @@ public class Set3proxyTask {
@Autowired
private MongoOAuth2AccessTokenRepository mongoOAuth2AccessTokenRepository;
@Autowired
private IpResourceRepository ipResourceRepository;
@Autowired
private SpecialLineRepository specialLineRepository;
// @Scheduled(cron = "0 0/1 * * * ?")
// public void set3proxy() {
// long validTime = Instant.now().minusSeconds(43200).toEpochMilli();
// List<String> tokenUsernames = mongoOAuth2AccessTokenRepository.findByCreatedAtGreaterThan(validTime).stream().map(MongoOAuth2AccessToken::getUsername).collect(Collectors.toList());
// List<String> accountParentDtos = accountRepository.findByNameIn(tokenUsernames).stream().map(x -> x.getParent() == null ? x.getName() : x.getParent()).distinct().collect(Collectors.toList());
//// FileInputStream fileInputStream = new FileInputStream();
// }
public void set3proxy() {
long validTime = Instant.now().minusSeconds(43200).toEpochMilli();
List<String> tokenUsernames = mongoOAuth2AccessTokenRepository.findByCreatedAtGreaterThan(validTime).stream().map(MongoOAuth2AccessToken::getUsername).collect(Collectors.toList());
List<String> accountParents = accountRepository.findByNameIn(tokenUsernames).stream().map(x -> x.getParent() == null ? x.getName() : x.getParent()).distinct().collect(Collectors.toList());
log.error(accountParents.size() +"");
List<IpResource> ipResources = ipResourceRepository.findByOwnerInAndSpecialLine(accountParents, true);
log.error(ipResources.size() + "");
File file = new File("3proxy.cfg");
SpecialLine specialLine = specialLineRepository.findAll().get(0);
StringBuilder stringBuilder = new StringBuilder();
try {
file.delete();
file.createNewFile();
FileWriter fileWriter =new FileWriter(file, true);
BufferedWriter bw = new BufferedWriter(fileWriter);
stringBuilder.append("daemon\nlog /var/log/3proxy.log D\nrotate 30\n");
for (IpResource ipResource : ipResources) {
stringBuilder.append("users \"" + ipResource.getProxyUsername() + ":CL:" + ipResource.getProxyPassword() + "\"\n");
}
stringBuilder.append("\nauth strong\n");
for (IpResource ipResource : ipResources) {
stringBuilder.append("allow " + ipResource.getProxyUsername() + "\n");
stringBuilder.append("parent 1000 " + specialLine.getProxyProtocol().get(0) + " " + ipResource.getAddr() + " " + ipResource.getPort().get(1) + " fangguanlianbrowser " + ipResource.getPassword() + "\n");
}
stringBuilder.append("\nallow none\nproxy -p20004\nsocks-p20005");
bw.write(stringBuilder.toString());
bw.flush();
bw.close();
log.info("成功写入文件");
} catch (Exception e) {
log.error("出错了");
log.error(e.getMessage());
}
}
}
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