Commit 54138c3c authored by renjie's avatar renjie

付费功能

删除ip修改
parent ab204c18
......@@ -7,8 +7,10 @@ public class IpChargeRequestDto {
private String unit="month";
private String target;
//0 -- newip, 1 --renew, 2 --ipkeptfee, 3 --deleteip, 4 -- stopinstanceonly , 5 -- bindinstance, 6 -- refundipkeptfee
//0 -- 充值, 1 -- newip, 2 --renew, 3 --ipkeptfee, 4 --deleteip,
private int chargeType = 0;
//0 -- 余额, 2 -- 支付宝, 3 -- 微信
private int payMethod = 0;
private float daysPerMonth = 0;
......@@ -87,4 +89,12 @@ public class IpChargeRequestDto {
public void setAmount(int amount) {
this.amount = amount;
}
public int getPayMethod() {
return payMethod;
}
public void setPayMethod(int payMethod) {
this.payMethod = payMethod;
}
}
......@@ -35,6 +35,9 @@ public class UserPrePaidBilling {
private BillStatus status;
//0 -- 余额, 2 -- 支付宝, 3 -- 微信
private int payMethod;
private boolean isPrepaid;
private String user;
......@@ -46,8 +49,7 @@ public class UserPrePaidBilling {
private float ownBillingCost = 0;
private float total;
//0 -- newip, 1 --renew, 2 --ipkeptfee, 3 --deleteip, 4 -- stopinstanceonly , 5 -- bindinstance, 6 -- refundipkeptfee
//7 -- newcvm , 8 -- renewcvm , 9 -- intelligroup
//0 -- 充值, 1 -- newip, 2 --renew, 3 --ipkeptfee, 4 --deleteip,
private int chargeType;
private String target;
......@@ -221,4 +223,12 @@ public class UserPrePaidBilling {
public void setUser(String user) {
this.user = user;
}
public int getPayMethod() {
return payMethod;
}
public void setPayMethod(int payMethod) {
this.payMethod = payMethod;
}
}
......@@ -53,8 +53,10 @@ public enum AccountErrorCode implements ErrorCode {
NOPERMISSION(ACCOUNT_BASE+140, "You have no right to do this operarion"),
GROUPMAX(ACCOUNT_BASE+141, "You can not have more groups"),
SHOPMAX(ACCOUNT_BASE+141, "You can not have more shops"),
CHILDMAX(ACCOUNT_BASE+141, "You can not have more subUsers");
SHOPMAX(ACCOUNT_BASE+142, "You can not have more shops"),
CHILDMAX(ACCOUNT_BASE+143, "You can not have more subUsers"),
NOTENOUGHBALANCE(ErrorCode.ACCOUNT_BASE+150, "Your balance is not enough");
......
......@@ -213,21 +213,19 @@ public class AccountServiceImpl implements AccountService {
userBalanceRepository.incrementBalance(userBalance, -(float) money, (float) money);
userBalance = userBalanceRepository.findById(name).orElse(null);
charge.setBalance(Math.round(userBalance.getBalanced()));
charge.setSuccess(true);
UserPrePaidBilling bill = new UserPrePaidBilling();
bill.setChargeType(requestDto.getChargeType());
bill.setServices(Services.valueOf(requestDto.getServices()));
bill.setAmount(requestDto.getAmount());
bill.setUnit(requestDto.getUnit());
bill.setPeriod(requestDto.getPeriod());
bill.setPayMethod(requestDto.getPayMethod());
bill.setUsername(name);
bill.setTotal((float) money);
bill.setStatus(BillStatus.PAID);
bill.setPrepaid(true);
bill.setUsername(name);
bill.setTimestamp(Instant.now().toEpochMilli());
......
......@@ -3,6 +3,7 @@ package com.edgec.browserbackend.browser.controller;
import com.edgec.browserbackend.account.dto.ResultDto;
import com.edgec.browserbackend.browser.dto.*;
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;
......@@ -28,7 +29,13 @@ public class IpControlloer {
List<IpResourceDto> ipResourceDto = ipResourceService.buyIp(principal.getName(), ipResourceRequestDto);
resultDto.setData(ipResourceDto);
resultDto.setStatus(0);
}catch (Exception e) {
} 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);
} catch (Exception e) {
resultDto.setStatus(-1);
Map<String, Object> statusInfo = new HashMap<>();
statusInfo.put("code", 80001);
......@@ -44,7 +51,13 @@ public class IpControlloer {
try {
resultDto.setData(ipResourceService.renewIp(principal.getName(), ipResourceRequestDto));
resultDto.setStatus(0);
}catch (Exception e) {
} 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);
} catch (Exception e) {
resultDto.setStatus(-1);
Map<String, Object> statusInfo = new HashMap<>();
statusInfo.put("code", 80001);
......@@ -60,7 +73,7 @@ public class IpControlloer {
try {
resultDto.setData(ipResourceService.deleteIp(principal.getName(), ipResourceRequestDto.getAddr()));
resultDto.setStatus(0);
}catch (Exception e) {
} catch (Exception e) {
resultDto.setStatus(-1);
Map<String, Object> statusInfo = new HashMap<>();
statusInfo.put("code", 80001);
......@@ -78,10 +91,10 @@ public class IpControlloer {
ipListRequestDto.getAmount(), ipListRequestDto.getIpFilterDto());
resultDto.setData(ipResourceDto);
resultDto.setStatus(0);
}catch (Exception e) {
}catch (ClientRequestException e) {
resultDto.setStatus(-1);
Map<String, Object> statusInfo = new HashMap<>();
statusInfo.put("code", 80001);
statusInfo.put("code", e.getErrorCode());
statusInfo.put("message", e.getMessage());
resultDto.setStatusInfo(statusInfo);
}
......
......@@ -15,8 +15,9 @@ public class IpResource {
private String id;
private String addr;
private IpType ipType = IpType.VENDOR;
private String vendor;
private Vendor vendor;
private String region;
private String regionCn;
//0:正常, 1:已过期, 2:即将过期
private int status;
private List<String> port;
......@@ -57,6 +58,14 @@ public class IpResource {
this.region = region;
}
public String getRegionCn() {
return regionCn;
}
public void setRegionCn(String regionCn) {
this.regionCn = regionCn;
}
public int getStatus() {
return status;
}
......@@ -105,11 +114,11 @@ public class IpResource {
this.addr = ipAddr;
}
public String getVendor() {
public Vendor getVendor() {
return vendor;
}
public void setVendor(String vendor) {
public void setVendor(Vendor vendor) {
this.vendor = vendor;
}
......
package com.edgec.browserbackend.browser.domain;
/**
* @Desc
* @Author jason
* @CreateTime 2020/3/12 4:01 下午
**/
public enum Vendor {
aliyun("阿里云"), JDCLOUD("京东云"), aws("亚马逊云"), awscn("亚马逊中国"), tencent("腾讯云");
private String value;
private Vendor(String value) {
this.value = value;
}
public String getValue() {
return value;
}
}
package com.edgec.browserbackend.browser.dto;
import com.edgec.browserbackend.browser.domain.IpResource;
import com.edgec.browserbackend.browser.domain.IpStatus;
import com.edgec.browserbackend.browser.domain.IpType;
import com.edgec.browserbackend.browser.domain.Shop;
import com.edgec.browserbackend.browser.domain.*;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import java.util.List;
......@@ -12,7 +9,7 @@ import java.util.List;
public class IpResourceDto {
private String id;
private String addr;
private String vendor;
private Vendor vendor;
private String region;
private int status;
private List<String> port;
......@@ -67,11 +64,11 @@ public class IpResourceDto {
this.region = region;
}
public String getVendor() {
public Vendor getVendor() {
return vendor;
}
public void setVendor(String vendor) {
public void setVendor(Vendor vendor) {
this.vendor = vendor;
}
......
......@@ -2,6 +2,8 @@ package com.edgec.browserbackend.browser.dto;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import javax.validation.constraints.Max;
import javax.validation.constraints.Min;
import java.util.ArrayList;
import java.util.List;
......@@ -9,8 +11,12 @@ import java.util.List;
public class IpResourceRequestDto {
private String name;
private String region;
private String regionCn;
private String vendor="aliyun";
private String logintype = "password";
@Max(12)
@Min(1)
private int period = 1;
private String unit="month";
private int amount = 1;
......@@ -83,6 +89,14 @@ public class IpResourceRequestDto {
this.region = region;
}
public String getRegionCn() {
return regionCn;
}
public void setAutorenew(boolean autorenew) {
this.autorenew = autorenew;
}
public int getIpkeptperiod() {
return ipkeptperiod;
}
......
......@@ -10,11 +10,11 @@ import java.util.List;
public interface IpResourceRepository extends MongoRepository<IpResource, String> {
IpResource findByAddrAndIsDeleted(String addr, boolean isDeleted);
List<IpResource> findByIdIn(List<String> ipIds);
List<IpResource> findByOwnerAndShopIdIsNull(String owner);
List<IpResource> findByOwnerAndStatusAndShopIdIsNull(String owner, int status);
List<IpResource> findByStatusAndIdIn(int status, List<String> ipIds);
Page<IpResource> findByAddrLikeAndIdIn(String addr, List<String> ipIds, Pageable pageable);
Page<IpResource> findByVendorLikeAndIdIn(String vendor, List<String> ipIds, Pageable pageable);
Page<IpResource> findByRegionLikeAndIdIn(String region, List<String> ipIds, Pageable pageable);
List<IpResource> findByIdInAndIsDeleted(List<String> ipIds, boolean isDeleted);
List<IpResource> findByOwnerAndIsDeletedAndShopIdIsNull(String owner, boolean isDeleted);
List<IpResource> findByOwnerAndStatusAndIsDeletedAndShopIdIsNull(String owner, int status, boolean isDeleted);
List<IpResource> findByStatusAndIdInAndIsDeleted(int status, List<String> ipIds, boolean isDeleted);
Page<IpResource> findByAddrLikeAndIdInAndIsDeleted(String addr, List<String> ipIds, boolean isDeleted, Pageable pageable);
Page<IpResource> findByVendorLikeAndIdInAndIsDeleted(String vendor, List<String> ipIds, boolean isDeleted, Pageable pageable);
Page<IpResource> findByRegionLikeAndIdInAndIsDeleted(String region, List<String> ipIds, boolean isDeleted, Pageable 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