Commit ced62e6b authored by renjie's avatar renjie

配置获取接口

parent 1b7185ff
......@@ -247,7 +247,7 @@ public class AccountServiceImpl implements AccountService {
}
//0 -- newip, 1 --renew, 2 --ipkeptfee, 3 --deleteip, 4 -- stopinstanceonly , 5 -- Startinstanceonly, 6 -- refundipkeptfee
//0 -- newip, 1 --renew, 2 --ipkeptfee, 3 --deleteip
private float getRate(String name, IpChargeRequestDto requestDto) {
int chargeType = requestDto.getChargeType();
......
......@@ -41,4 +41,20 @@ public class ConfigController {
}
return resultDto;
}
@RequestMapping(value = "/platformOptions", method = RequestMethod.POST)
public ResultDto getPlatformOptions() {
ResultDto resultDto = new ResultDto();
try {
resultDto.setData(ipResourceService.getPlatformOptions());
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;
}
}
package com.edgec.browserbackend.browser.domain;
import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.mapping.Document;
import java.util.List;
import java.util.Map;
/**
* @Desc
* @Author jason
* @CreateTime 2020/3/12 10:30 上午
**/
@Document("ipOptions")
public class IpOptions {
@Id
private String id;
private Map<String, List<String>> ipRegion;
private Map<String, List<String>> ipPlatForm;
private Map<String, Map<String, List<String>>> supportedPlatForm;
private List<String> ipDurations;
public List<String> getIpDurations() {
return ipDurations;
}
public void setIpDurations(List<String> ipDurations) {
this.ipDurations = ipDurations;
}
public Map<String, List<String>> getIpPlatForm() {
return ipPlatForm;
}
public void setIpPlatForm(Map<String, List<String>> ipPlatForm) {
this.ipPlatForm = ipPlatForm;
}
public Map<String, List<String>> getIpRegion() {
return ipRegion;
}
public void setIpRegion(Map<String, List<String>> ipRegion) {
this.ipRegion = ipRegion;
}
public Map<String, Map<String, List<String>>> getSupportedPlatForm() {
return supportedPlatForm;
}
public void setSupportedPlatForm(Map<String, Map<String, List<String>>> supportedPlatForm) {
this.supportedPlatForm = supportedPlatForm;
}
}
package com.edgec.browserbackend.browser.domain;
import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.mapping.Document;
import java.util.List;
import java.util.Map;
/**
* @Desc
* @Author jason
* @CreateTime 2020/3/12 11:44 上午
**/
@Document("platformoptions")
public class PlatformOptions {
private String platform;
private Map<String, String> subPlatform;
public Map<String, String> getSubPlatform() {
return subPlatform;
}
public void setPlatform(String platform) {
this.platform = platform;
}
public String getPlatform() {
return platform;
}
public void setSubPlatform(Map<String, String> subPlatform) {
this.subPlatform = subPlatform;
}
}
package com.edgec.browserbackend.browser.repository;
import com.edgec.browserbackend.browser.domain.IpOptions;
import org.springframework.data.mongodb.repository.MongoRepository;
/**
* @Desc
* @Author jason
* @CreateTime 2020/3/12 10:49 上午
**/
public interface IpOptionsRepository extends MongoRepository<IpOptions, String> {
}
package com.edgec.browserbackend.browser.repository;
import com.edgec.browserbackend.browser.domain.PlatformOptions;
import org.springframework.data.mongodb.repository.MongoRepository;
/**
* @Desc
* @Author jason
* @CreateTime 2020/3/12 12:02 下午
**/
public interface PlatformOptionsRepository extends MongoRepository<PlatformOptions, String> {
}
......@@ -5,12 +5,11 @@ import com.alibaba.fastjson.JSONObject;
import com.edgec.browserbackend.account.domain.Account;
import com.edgec.browserbackend.account.exception.AccountErrorCode;
import com.edgec.browserbackend.account.repository.AccountRepository;
import com.edgec.browserbackend.account.service.AccountService;
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.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.IpResourceService;
import com.edgec.browserbackend.common.commons.error.ClientRequestException;
import com.edgec.browserbackend.common.utils.FileUtil;
......@@ -27,7 +26,6 @@ import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;
import java.io.File;
import java.net.URL;
import java.time.Instant;
import java.util.*;
import java.util.stream.Collectors;
......@@ -59,6 +57,15 @@ public class IpResourceServiceImpl implements IpResourceService {
@Autowired
private ShopRepository shopRepository;
@Autowired
private AccountService accountService;
@Autowired
private IpOptionsRepository ipOptionsRepository;
@Autowired
private PlatformOptionsRepository platformOptionsRepository;
public HttpHeaders buildPostHeader() {
HttpHeaders header = new HttpHeaders();
header.setContentType(MediaType.APPLICATION_JSON);
......@@ -90,6 +97,7 @@ public class IpResourceServiceImpl implements IpResourceService {
if (account.getPermission() < 8)
throw new ClientRequestException(AccountErrorCode.NOPERMISSION);
//todo 预扣费
List<IpResourceDto> ipResourceDtos = new ArrayList<>();
RestTemplate restTemplate = new RestTemplate();
HttpHeaders header = buildPostHeader();
......@@ -366,9 +374,30 @@ public class IpResourceServiceImpl implements IpResourceService {
}
@Override
public JSONObject getIpOptions() {
JSONObject jsonObject = JSONObject.parseObject(FileUtil.read(new File("src/main/resources/ipOptions.json"), "UTF-8"));
return jsonObject;
public void setIpOptions() {
IpOptions jsonObject = JSONObject.parseObject(FileUtil.read(new File("src/main/resources/ipOptions.json"), "UTF-8"), IpOptions.class);
ipOptionsRepository.save(jsonObject);
}
@Override
public IpOptions getIpOptions() {
try {
IpOptions jsonObject = ipOptionsRepository.findAll().get(0);
return jsonObject;
} catch (Exception e) {
logger.error(e.getMessage());
throw new ClientRequestException(BrowserErrorCode.UNKNOWN);
}
}
@Override
public List<PlatformOptions> getPlatformOptions() {
try {
List<PlatformOptions> platformOptions = platformOptionsRepository.findAll();
return platformOptions;
} catch (Exception e) {
logger.error(e.getMessage());
throw new ClientRequestException(BrowserErrorCode.UNKNOWN);
}
}
}
package com.edgec.browserbackend.browser.service;
import com.alibaba.fastjson.JSONObject;
import com.edgec.browserbackend.browser.domain.IpOptions;
import com.edgec.browserbackend.browser.domain.Platform;
import com.edgec.browserbackend.browser.domain.PlatformOptions;
import com.edgec.browserbackend.browser.dto.*;
import java.util.List;
......@@ -15,5 +17,9 @@ public interface IpResourceService {
IpPageResultDto getIpList(String username, int groupType, int page, int amount, IpFilterDto ipFilterDto);
JSONObject getIpOptions();
void setIpOptions();
IpOptions getIpOptions();
List<PlatformOptions> getPlatformOptions();
}
......@@ -883,6 +883,7 @@
]
},
"本地": {
"本地": [
"亚马逊-1",
"ebay-1",
......@@ -898,7 +899,7 @@
"FactoryMarket-1",
"PayPal-1",
"其他平台-1"
]
]}
},
"ipDurations": [
"1周",
......
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