Commit 54138c3c authored by renjie's avatar renjie

付费功能

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