Commit b360da96 authored by renjie's avatar renjie

Merge branch 'dev-zrj' into 'staging'

自有专线

See merge request !62
parents ec6afd2f 87168aac
......@@ -396,6 +396,24 @@ public class AdministratorController {
return resultDto;
}
//添加白名单
@PreAuthorize(Securitys.ADMIN_EL)
@RequestMapping(path = "/0xadministrator/userwhitelist/add", method = RequestMethod.PUT)
public ResultDto addWhiteList(Principal principal, @RequestParam("username") String username, @RequestParam("website") String website) {
ResultDto resultDto = new ResultDto();
try {
administratorService.addUserWhiteList(username, website);
resultDto.setStatus(0);
}catch (ClientRequestException e) {
resultDto.setStatus(-1);
Map<String, Object> statusInfo = new HashMap<>();
statusInfo.put("code", e.getErrorCode());
statusInfo.put("message", e.getMessage());
resultDto.setStatusInfo(statusInfo);
}
return resultDto;
}
//统计ip数量
@PreAuthorize(Securitys.ADMIN_EL)
@RequestMapping(path = "/0xadministrator/ip/count", method = RequestMethod.GET)
......
......@@ -62,5 +62,7 @@ public interface AdministratorService {
void addWhiteList(String website);
void addUserWhiteList(String username, String website);
File getProxyConfig();
}
......@@ -465,6 +465,15 @@ public class AdministratorServiceImpl implements AdministratorService {
whiteSiteRepository.save(whiteSite);
}
@Override
public void addUserWhiteList(String username, String website) {
Account account = accountRepository.findByName(username);
if (account == null)
throw new ClientRequestException(AccountErrorCode.NAMENOTEXIST);
account.getWhiteList().add(website);
accountRepository.save(account);
}
@Override
public File getProxyConfig() {
ProxyConfig proxyConfig = null;
......
......@@ -29,6 +29,7 @@ public class IpResourceRequestDto {
private int ipkeptperiod = 7;
private String startscript = "";
private boolean specialLine;
//自有IP需要传proxy的账号
private String username;
private String password;
......@@ -206,4 +207,12 @@ public class IpResourceRequestDto {
public void setUsername(String username) {
this.username = username;
}
public boolean isSpecialLine() {
return specialLine;
}
public void setSpecialLine(boolean specialLine) {
this.specialLine = specialLine;
}
}
......@@ -218,6 +218,8 @@ public class IpResourceServiceImpl implements IpResourceService {
.filter(x -> Vendor.valueOf(ipResourceRequestDto.getVendor()).getValue().equals(x.substring(0, x.indexOf("-"))))
.map(x -> x.substring(x.lastIndexOf("-") + 1)).collect(Collectors.joining());
newprice = ipResourceRequestDto.getUnit().equals("week") ? (Integer.valueOf(price)/3) : Integer.valueOf(price);
if (ipResourceRequestDto.isSpecialLine())
newprice *= 3;
}
IpChargeResultDto ipChargeResultDto = accountService.preChargeByMoney(username, newprice * ipResourceRequestDto.getAmount() * ipResourceRequestDto.getPeriod());
......@@ -253,6 +255,7 @@ public class IpResourceServiceImpl implements IpResourceService {
throw new ClientRequestException(BrowserErrorCode.INFORMATIONNOTCOMPELETE);
if (StringUtils.isBlank(ipResourceRequestDto.getAddr().get(0)))
throw new ClientRequestException(BrowserErrorCode.INFORMATIONNOTCOMPELETE);
ipResource.setSpecialLine(ipResourceRequestDto.isSpecialLine());
ipResource.setAddr(ipResourceRequestDto.getAddr().get(0));
ipResource.setIpType(IpType.OWN);
ipResource.setVendor(Vendor.valueOf(ipResourceRequestDto.getVendor()));
......@@ -611,11 +614,16 @@ public class IpResourceServiceImpl implements IpResourceService {
}
}
}
if (x.getStatus() == 6 || (x.isSpecialLine() && x.getPurchasedTime() > (Instant.now().toEpochMilli() - 12*60*1000)))
if (x.getStatus() == 6)
x.setStatus(3);
if (x.getStatus() == 3) {
x.setAddr("");
}
if (x.isSpecialLine() && x.getPurchasedTime() > (Instant.now().toEpochMilli() - 12*60*1000)) {
x.setStatus(3);
ipResourceRepository.save(x);
x.setAddr("");
}
SpecialLine specialLine = specialLineRepository.findAll().get(0);
if (x.isSpecialLine())
ipResourceDtos.add(new IpResourceDto(x, shopDto, false, specialLine));
......
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