Commit 7917ffcf authored by renjie's avatar renjie

修改shop接口bug

parent 5fc74d35
package com.edgec.browserbackend.browser.controller; package com.edgec.browserbackend.browser.controller;
import com.edgec.browserbackend.account.dto.ResultDto;
import com.edgec.browserbackend.browser.domain.IpResource;
import com.edgec.browserbackend.browser.dto.FilterDto;
import com.edgec.browserbackend.browser.dto.IpResourceDto;
import com.edgec.browserbackend.browser.dto.IpResourceRequestDto;
import com.edgec.browserbackend.browser.dto.ShopStringResultDto;
import com.edgec.browserbackend.browser.service.IpResourceService;
import com.edgec.browserbackend.common.commons.error.ClientRequestException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import java.security.Principal;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@RestController @RestController
@RequestMapping("/ip") @RequestMapping("/ip")
public class IpControlloer { public class IpControlloer {
@Autowired
private IpResourceService ipResourceService;
@RequestMapping(value = "/buy", method = RequestMethod.POST)
public ResultDto buyIp(Principal principal, @RequestBody IpResourceRequestDto ipResourceRequestDto){
ResultDto resultDto = new ResultDto();
try {
IpResourceDto ipResourceDto = ipResourceService.buyIp(principal.getName(), ipResourceRequestDto);
resultDto.setData(ipResourceDto);
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;
}
void renewIp(String username, IpResourceRequestDto ipResourceRequestDto) {
}
void deleteIp(String username, String ipAddr) {
}
List<IpResourceDto> getIpList(String username, int type, int page, int amount, FilterDto filterDto) {
return null;
}
} }
...@@ -12,12 +12,12 @@ import java.util.List; ...@@ -12,12 +12,12 @@ import java.util.List;
public class IpResource { public class IpResource {
@Id @Id
private String id; private String id;
private String ipAddr; private String addr;
private IpType ipType; private IpType ipType;
private String ipProvider; private String ipProvider;
private String ipRegion; private String ipRegion;
private IpStatus ipStatus; private IpStatus ipStatus;
private List<Interval> ports; private List<Interval> port;
private long createdAt; private long createdAt;
private long validTime; private long validTime;
private long leftTime; private long leftTime;
...@@ -102,11 +102,11 @@ public class IpResource { ...@@ -102,11 +102,11 @@ public class IpResource {
} }
public String getIpAddr() { public String getIpAddr() {
return ipAddr; return addr;
} }
public void setIpAddr(String ipAddr) { public void setIpAddr(String ipAddr) {
this.ipAddr = ipAddr; this.addr = ipAddr;
} }
public String getIpProvider() { public String getIpProvider() {
...@@ -126,11 +126,11 @@ public class IpResource { ...@@ -126,11 +126,11 @@ public class IpResource {
} }
public List<Interval> getPorts() { public List<Interval> getPorts() {
return ports; return port;
} }
public void setPorts(List<Interval> ports) { public void setPorts(List<Interval> ports) {
this.ports = ports; this.port = ports;
} }
public String getOwner() { public String getOwner() {
......
...@@ -9,6 +9,7 @@ import java.util.List; ...@@ -9,6 +9,7 @@ import java.util.List;
public class IpResourceRequestDto { public class IpResourceRequestDto {
private String name; private String name;
private String region; private String region;
private String vendor="aliyun";
private String logintype = "password"; private String logintype = "password";
private int period = 1; private int period = 1;
private String unit="month"; private String unit="month";
...@@ -18,11 +19,102 @@ public class IpResourceRequestDto { ...@@ -18,11 +19,102 @@ public class IpResourceRequestDto {
private String instanceSpecKey; private String instanceSpecKey;
private String imageKey; private String imageKey;
private String provider="aliyun";
private List<String> ports; private List<String> ports;
private String system = "linux"; private String system = "linux";
private List<String> iplist = new ArrayList<>(); private List<String> iplist = new ArrayList<>();
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAmount() {
return amount;
}
public void setAmount(int amount) {
this.amount = amount;
}
public String getImageKey() {
return imageKey;
}
public void setPorts(List<String> ports) {
this.ports = ports;
}
public int getPeriod() {
return period;
}
public void setImageKey(String imageKey) {
this.imageKey = imageKey;
}
public String getUnit() {
return unit;
}
public void setPeriod(int period) {
this.period = period;
}
public String getRegion() {
return region;
}
public void setUnit(String unit) {
this.unit = unit;
}
public List<String> getPorts() {
return ports;
}
public void setRegion(String region) {
this.region = region;
}
public int getIpkeptperiod() {
return ipkeptperiod;
}
public List<String> getIplist() {
return iplist;
}
public void setIplist(List<String> iplist) {
this.iplist = iplist;
}
public String getInstanceSpecKey() {
return instanceSpecKey;
}
public void setInstanceSpecKey(String instanceSpecKey) {
this.instanceSpecKey = instanceSpecKey;
}
public String getVendor() {
return vendor;
}
public void setVendor(String vendor) {
this.vendor = vendor;
}
public String getSystem() {
return system;
}
public void setSystem(String system) {
this.system = system;
}
} }
...@@ -109,8 +109,8 @@ public class ShopRequestDto { ...@@ -109,8 +109,8 @@ public class ShopRequestDto {
return shopIds; return shopIds;
} }
public void setShopIds(List<String> shopId) { public void setShopIds(List<String> shopIds) {
this.shopIds = shopId; this.shopIds = shopIds;
} }
public List<String> getToUsers() { public List<String> getToUsers() {
......
...@@ -4,5 +4,5 @@ import com.edgec.browserbackend.browser.domain.IpResource; ...@@ -4,5 +4,5 @@ import com.edgec.browserbackend.browser.domain.IpResource;
import org.springframework.data.mongodb.repository.MongoRepository; import org.springframework.data.mongodb.repository.MongoRepository;
public interface IpResourceRepository extends MongoRepository<IpResource, String> { public interface IpResourceRepository extends MongoRepository<IpResource, String> {
IpResource findByIpAddrAndIsDeleted(String ipAddr, boolean isDeleted); IpResource findByAddrAndIsDeleted(String addr, boolean isDeleted);
} }
...@@ -34,14 +34,14 @@ public class IpResourceServiceImpl implements IpResourceService { ...@@ -34,14 +34,14 @@ public class IpResourceServiceImpl implements IpResourceService {
@Override @Override
public IpResource getIpResourceByIpAddr(String ipAddr) { public IpResource getIpResourceByIpAddr(String ipAddr) {
IpResource ipResource = ipResourceRepository.findByIpAddrAndIsDeleted(ipAddr, false); IpResource ipResource = ipResourceRepository.findByAddrAndIsDeleted(ipAddr, false);
if (ipResource == null) if (ipResource == null)
throw new ClientRequestException(BrowserErrorCode.IPNOTEXIST); throw new ClientRequestException(BrowserErrorCode.IPNOTEXIST);
return ipResource; return ipResource;
} }
@Override @Override
public IpResource buyIp(String username, IpResourceRequestDto ipResourceRequestDto) { public IpResourceDto buyIp(String username, IpResourceRequestDto ipResourceRequestDto) {
RestTemplate restTemplate = new RestTemplate(); RestTemplate restTemplate = new RestTemplate();
return null; return null;
} }
......
...@@ -155,7 +155,7 @@ public class ShopServiceImpl implements ShopService { ...@@ -155,7 +155,7 @@ public class ShopServiceImpl implements ShopService {
if (shop.getIpId() != null && shop.getIp() != null) { if (shop.getIpId() != null && shop.getIp() != null) {
unBindShop(username, shopId, shop.getIp()); unBindShop(username, shopId, shop.getIp());
} }
IpResource ipResource = ipResourceRepository.findByIpAddrAndIsDeleted(ipAddr, false); IpResource ipResource = ipResourceRepository.findByAddrAndIsDeleted(ipAddr, false);
if (ipResource == null) if (ipResource == null)
throw new ClientRequestException(BrowserErrorCode.IPNOTEXIST); throw new ClientRequestException(BrowserErrorCode.IPNOTEXIST);
try { try {
...@@ -188,7 +188,7 @@ public class ShopServiceImpl implements ShopService { ...@@ -188,7 +188,7 @@ public class ShopServiceImpl implements ShopService {
Shop shop = shopRepository.findById(shopId).orElse(null); Shop shop = shopRepository.findById(shopId).orElse(null);
if (shop == null) if (shop == null)
throw new ClientRequestException(BrowserErrorCode.SHOPNOTEXIST); throw new ClientRequestException(BrowserErrorCode.SHOPNOTEXIST);
IpResource ipResource = ipResourceRepository.findByIpAddrAndIsDeleted(ipAddr, false); IpResource ipResource = ipResourceRepository.findByAddrAndIsDeleted(ipAddr, false);
if (ipResource == null) if (ipResource == null)
throw new ClientRequestException(BrowserErrorCode.IPNOTEXIST); throw new ClientRequestException(BrowserErrorCode.IPNOTEXIST);
if (!ipAddr.equals(shop.getIp())) if (!ipAddr.equals(shop.getIp()))
...@@ -299,7 +299,7 @@ public class ShopServiceImpl implements ShopService { ...@@ -299,7 +299,7 @@ public class ShopServiceImpl implements ShopService {
return new ArrayList<>(); return new ArrayList<>();
List<ShopDto> shopDtos = new ArrayList<>(); List<ShopDto> shopDtos = new ArrayList<>();
shops.stream().forEach(x -> { shops.stream().forEach(x -> {
IpResource ipResource = ipResourceRepository.findByIpAddrAndIsDeleted(x.getIp(), false); IpResource ipResource = ipResourceRepository.findByAddrAndIsDeleted(x.getIp(), false);
shopDtos.add(ShopDto.of(x, ipResource)); shopDtos.add(ShopDto.of(x, ipResource));
}); });
return shopDtos; return shopDtos;
......
...@@ -11,7 +11,7 @@ public interface IpResourceService { ...@@ -11,7 +11,7 @@ public interface IpResourceService {
IpResource getIpResourceByIpAddr(String ipAddr); IpResource getIpResourceByIpAddr(String ipAddr);
IpResource buyIp(String username, IpResourceRequestDto ipResourceRequestDto); IpResourceDto buyIp(String username, IpResourceRequestDto ipResourceRequestDto);
void renewIp(String username, IpResourceRequestDto ipResourceRequestDto); void renewIp(String username, IpResourceRequestDto ipResourceRequestDto);
......
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