Commit 22aa121d authored by Administrator's avatar Administrator

Merge branch 'staging' into 'master'

Staging

See merge request !30
parents 1a948058 ff36b3ca
......@@ -2,9 +2,11 @@ package com.edgec.browserbackend.account.dto;
import com.edgec.browserbackend.account.domain.Account;
import com.edgec.browserbackend.account.domain.Promotion;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import java.util.Date;
@JsonIgnoreProperties(ignoreUnknown = true)
public class AccountPromotionDto {
private String username;
private Date signupDate;
......
package com.edgec.browserbackend.account.dto;
import com.edgec.browserbackend.account.domain.Promotion;
import com.edgec.browserbackend.account.domain.UserPrePaidBilling;
import org.springframework.data.domain.Page;
......@@ -18,6 +19,9 @@ public class BillQueryResultDto {
double childBankTransfer;
double childBalanceUsed;
String promoter;
Promotion promotion;
public double getParentExpense() {
return parentExpense;
}
......@@ -97,4 +101,20 @@ public class BillQueryResultDto {
public void setParentBalanceUsed(double parentBalanceUsed) {
this.parentBalanceUsed = parentBalanceUsed;
}
public Promotion getPromotion() {
return promotion;
}
public void setPromoter(String promoter) {
this.promoter = promoter;
}
public String getPromoter() {
return promoter;
}
public void setPromotion(Promotion promotion) {
this.promotion = promotion;
}
}
......@@ -107,9 +107,6 @@ public class AccountServiceImpl implements AccountService {
@Autowired
private UserAuthService userAuthService;
@Autowired
private UserRepository userRepository;
@Autowired
private ShopService shopService;
......@@ -530,7 +527,10 @@ public class AccountServiceImpl implements AccountService {
param.put("referral", inviter.getName() + "(" + user.getPromotionCode() + ")");
else
param.put("referral", "123456");
com.edgec.browserbackend.common.commons.utils.SmsUtils.sendNewAccountSms("15919921106", com.edgec.browserbackend.common.commons.utils.SmsUtils.SmsTemplateCode.NEWACCOUNT, param);
com.edgec.browserbackend.common.commons.utils.SmsUtils.sendNewAccountSms("13570690305", com.edgec.browserbackend.common.commons.utils.SmsUtils.SmsTemplateCode.NEWACCOUNT, param);
com.edgec.browserbackend.common.commons.utils.SmsUtils.sendNewAccountSms("13802945832", com.edgec.browserbackend.common.commons.utils.SmsUtils.SmsTemplateCode.NEWACCOUNT, param);
if (inviter != null) {
paymentService.bankTransferInsertion(account.getName(), 12);
......
......@@ -172,6 +172,14 @@ public class AdministratorServiceImpl implements AdministratorService {
billQueryResultDto.setParentWithdrawn(parentwithdrawn);
billQueryResultDto.setParentBalanceUsed(parentbalanceused);
Account promoter = null;
if (account.getPromotionCode() != null)
promoter = accountRepository.findByPromotion(account.getPromotionCode());
if (promoter != null)
billQueryResultDto.setPromoter(promoter.getName());
billQueryResultDto.setPromotion(account.getPromotion());
return billQueryResultDto;
}
......@@ -427,7 +435,7 @@ public class AdministratorServiceImpl implements AdministratorService {
}
}
}
if (x.getPromotion().isSale())
if (finalAccount.getPromotion().isSale())
promotion.setAllGift(promotion.getAllGift() + totalCommission * 0.1 + secondCommission * 0.02);
else
promotion.setAllGift(promotion.getAllGift() + totalCommission * 0.08);
......
package com.edgec.browserbackend.auth.controller;
import com.edgec.browserbackend.account.dto.ResultDto;
import com.edgec.browserbackend.auth.domain.User;
import com.edgec.browserbackend.auth.domain.UserPasswordReset;
import com.edgec.browserbackend.auth.service.UserAuthService;
......@@ -13,6 +14,8 @@ import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;
import java.security.Principal;
import java.util.HashMap;
import java.util.Map;
@RestController
@RequestMapping("/auth")
......@@ -95,8 +98,18 @@ public class UserController {
}
@RequestMapping(path = "/changepass", method = RequestMethod.PUT)
public void changePassword(@Valid @RequestBody UserPasswordReset userPasswordReset) {
userAuthService.changePassword(userPasswordReset);
public ResultDto changePassword(@Valid @RequestBody UserPasswordReset userPasswordReset) {
ResultDto resultDto = new ResultDto();
try {
resultDto.setData(userAuthService.changePassword(userPasswordReset));
resultDto.setStatus(0);
} catch (Exception e) {
resultDto.setStatus(-1);
Map<String, Object> statusInfo = new HashMap<>();
statusInfo.put("message", e.getMessage());
resultDto.setStatusInfo(statusInfo);
}
return resultDto;
}
......
......@@ -121,7 +121,7 @@ public class UserAuthServiceImpl implements UserAuthService {
}
@Override
public void changePassword(UserPasswordReset userPasswordReset) {
public boolean changePassword(UserPasswordReset userPasswordReset) {
User existing = repository.findById(userPasswordReset.getUsername()).orElseThrow(() -> new ClientRequestException(AuthErrorCode.NAMENOTEXIST, "user does not exist: " + userPasswordReset.getUsername()));
if (!StringUtils.isEmpty(userPasswordReset.getPassword())) {
//change password with old password
......@@ -131,7 +131,7 @@ public class UserAuthServiceImpl implements UserAuthService {
String newhash = encoder.encode(userPasswordReset.getNewPassword());
existing.setPassword(newhash);
repository.save(existing);
return;
return true;
} else {
throw new ClientRequestException(AuthErrorCode.AUTHENTICATION_ERROR, "Wrong password used.");
}
......@@ -143,12 +143,12 @@ public class UserAuthServiceImpl implements UserAuthService {
existing.setPassword(newhash);
existing.setVerificationCode("");
repository.save(existing);
return;
return true;
} else {
throw new ClientRequestException(AuthErrorCode.AUTHENTICATION_ERROR, "Wrong verification code.");
}
}
throw new ClientRequestException(AuthErrorCode.OTHERS, "Wrong password change request.");
return false;
}
......
......@@ -16,7 +16,7 @@ public interface UserAuthService {
void unlock(User user, String unlock);
void changePassword(UserPasswordReset userPasswordReset);
boolean changePassword(UserPasswordReset userPasswordReset);
void deleteUser(String name);
......
......@@ -3,10 +3,7 @@ package com.edgec.browserbackend.browser.controller;
import com.edgec.browserbackend.account.dto.ResultDto;
import com.edgec.browserbackend.browser.ErrorCode.BrowserErrorCode;
import com.edgec.browserbackend.browser.domain.Shop;
import com.edgec.browserbackend.browser.dto.ShopPageResultDto;
import com.edgec.browserbackend.browser.dto.ShopResultDto;
import com.edgec.browserbackend.browser.dto.ShopRequestDto;
import com.edgec.browserbackend.browser.dto.ShopStringResultDto;
import com.edgec.browserbackend.browser.dto.*;
import com.edgec.browserbackend.browser.service.IpAndShopService;
import com.edgec.browserbackend.browser.service.ShopService;
import com.edgec.browserbackend.common.commons.error.ClientRequestException;
......@@ -230,4 +227,21 @@ public class ShopController {
}
return resultDto;
}
@RequestMapping(value = "/query", method = RequestMethod.POST)
public ResultDto queryShop(Principal principal, @RequestBody ShopRequestDto shopRequestDto) {
ResultDto resultDto = new ResultDto();
try {
ShopResultDto shopDto = shopService.queryShop(principal.getName(), shopRequestDto.getShopId());
resultDto.setData(shopDto);
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;
}
}
......@@ -21,7 +21,7 @@ public class IpResource implements Serializable {
private String vendorCn;
private String region;
private String regionCn;
//0:正常, 1:已过期, 2:即将过期, 3:正在分配, 4:未使用, 5:已失效, 6:未分配
//0:正常, 1:已过期, 2:即将过期, 3:正在分配, 4:未使用, 5:已失效, 6:未分配, 7:未缴费
private int status;
private List<String> port;
private long purchasedTime;
......@@ -48,7 +48,7 @@ public class IpResource implements Serializable {
private String unit;
private int period;
private String tid;
private boolean specialLine;
public String getDetails() {
return details;
......@@ -226,14 +226,6 @@ public class IpResource implements Serializable {
this.period = period;
}
public String getTid() {
return tid;
}
public void setTid(String tid) {
this.tid = tid;
}
public double getPrice() {
return price;
}
......@@ -281,4 +273,12 @@ public class IpResource implements Serializable {
public void setProxyUsername(String proxyUsername) {
this.proxyUsername = proxyUsername;
}
public boolean isSpecialLine() {
return specialLine;
}
public void setSpecialLine(boolean specialLine) {
this.specialLine = specialLine;
}
}
......@@ -2,5 +2,6 @@ package com.edgec.browserbackend.browser.domain;
public enum IpType {
LOCAL,
VENDOR;
VENDOR,
OWN;
}
......@@ -6,7 +6,7 @@ package com.edgec.browserbackend.browser.domain;
* @CreateTime 2020/3/12 4:01 下午
**/
public enum Vendor {
aliyun("阿里云"), JDCLOUD("京东云"), aws("亚马逊云"), awscn("亚马逊中国"), tencent("腾讯云"), local("本地");
aliyun("阿里云"), JDCLOUD("京东云"), aws("亚马逊云"), awscn("亚马逊中国"), tencent("腾讯云"), local("本地"), own("自有");
private String value;
......
......@@ -29,6 +29,8 @@ public class IpResourceRequestDto {
private int ipkeptperiod = 7;
private String startscript = "";
//自有IP需要传proxy的账号
private String username;
private String password;
private String instanceSpecKey;
private String imageKey;
......@@ -196,4 +198,12 @@ public class IpResourceRequestDto {
public void setShopId(String shopId) {
this.shopId = shopId;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
}
......@@ -174,11 +174,15 @@ public class IpResourceServiceImpl implements IpResourceService {
throw new ClientRequestException(BrowserErrorCode.INFORMATIONNOTCOMPELETE);
if (ipResourceRequestDto.getRegionCn() == null)
throw new ClientRequestException(BrowserErrorCode.INFORMATIONNOTCOMPELETE);
List<String> vendorPrices = priceList.get(ipResourceRequestDto.getRegionCn());
String price = vendorPrices.stream()
.filter(x -> Vendor.valueOf(ipResourceRequestDto.getVendor()).getValue().equals(x.substring(0, x.indexOf("-"))))
.map(x -> x.substring(x.lastIndexOf("-") + 1)).collect(Collectors.joining());
double newprice = ipResourceRequestDto.getUnit().equals("week") ? (Integer.valueOf(price)/3) : Integer.valueOf(price);
double newprice = 0;
if (!ipResourceRequestDto.getVendor().equals("own")) {
List<String> vendorPrices = priceList.get(ipResourceRequestDto.getRegionCn());
String price = vendorPrices.stream()
.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);
}
IpChargeResultDto ipChargeResultDto = accountService.preChargeByMoney(username, newprice * ipResourceRequestDto.getAmount() * ipResourceRequestDto.getPeriod());
if (!ipChargeResultDto.isSuccess()) {
throw new ClientRequestException(AccountErrorCode.NOTENOUGHBALANCE);
......@@ -195,7 +199,30 @@ public class IpResourceServiceImpl implements IpResourceService {
for (int i = 0; i < ipResourceRequestDto.getAmount(); i++) {
IpResource ipResource = new IpResource();
if (!ipResourceRequestDto.getVendor().equals("local")) {
if (ipResourceRequestDto.getVendor().equals("local")) {
ipResource.setAddr("本地Ip未使用");
ipResource.setIpType(IpType.LOCAL);
ipResource.setVendor(Vendor.valueOf(ipResourceRequestDto.getVendor()));
ipResource.setVendorCn("本地");
ipResource.setStatus(4);
ipResource.setUsername(USERNAME);
if (ipResourceRequestDto.getUnit().equals("week"))
ipResource.setValidTime(Instant.now().atZone(ZoneOffset.UTC).plusWeeks(ipResourceRequestDto.getPeriod()).toInstant().toEpochMilli());
else
ipResource.setValidTime(Instant.now().atZone(ZoneOffset.UTC).plusMonths(ipResourceRequestDto.getPeriod()).toInstant().toEpochMilli());
ipResource.setPort(port);
} else if (ipResourceRequestDto.getVendor().equals("own")) {
if (ipResourceRequestDto.getAddr() == null || ipResourceRequestDto.getAddr().size() == 0)
throw new ClientRequestException(BrowserErrorCode.INFORMATIONNOTCOMPELETE);
ipResource.setAddr(ipResourceRequestDto.getAddr().get(0));
ipResource.setIpType(IpType.OWN);
ipResource.setVendor(Vendor.valueOf(ipResourceRequestDto.getVendor()));
ipResource.setVendorCn("自有");
ipResource.setStatus(4);
ipResource.setUsername(ipResourceRequestDto.getUsername());
ipResource.setValidTime(Instant.now().atZone(ZoneOffset.UTC).toInstant().toEpochMilli());
ipResource.setPort(ipResourceRequestDto.getPorts());
} else {
ipResource.setAddr("");
ipResource.setIpType(IpType.VENDOR);
ipResource.setVendor(Vendor.valueOf(ipResourceRequestDto.getVendor()));
......@@ -212,20 +239,11 @@ public class IpResourceServiceImpl implements IpResourceService {
}
ipResource.setStatus(6);
ipResource.setValidTime(Instant.now().plusSeconds(3600*24*30).toEpochMilli());
} else {
ipResource.setAddr("本地Ip未使用");
ipResource.setIpType(IpType.LOCAL);
ipResource.setVendor(Vendor.valueOf(ipResourceRequestDto.getVendor()));
ipResource.setVendorCn("本地");
ipResource.setStatus(4);
if (ipResourceRequestDto.getUnit().equals("week"))
ipResource.setValidTime(Instant.now().atZone(ZoneOffset.UTC).plusWeeks(ipResourceRequestDto.getPeriod()).toInstant().toEpochMilli());
else
ipResource.setValidTime(Instant.now().atZone(ZoneOffset.UTC).plusMonths(ipResourceRequestDto.getPeriod()).toInstant().toEpochMilli());
ipResource.setUsername(USERNAME);
ipResource.setPort(port);
}
ipResource.setPurchasedTime(Instant.now().toEpochMilli());
ipResource.setPort(port);
ipResource.setUsername(USERNAME);
if (account.getParent() != null)
ipResource.setUserParent(account.getParent());
ipResource.setRegion(ipResourceRequestDto.getRegion());
......@@ -243,8 +261,10 @@ public class IpResourceServiceImpl implements IpResourceService {
ipIds.add(ipResource1.getId());
}
IpChargeRequestDto ipChargeRequestDto = buildIpChargeRequestDto(ipResourceRequestDto, 1, ipResourceRequestDto.getPayMethod());
accountService.chargeByMoney(username, newprice * ipChargeRequestDto.getAmount() * ipChargeRequestDto.getPeriod(), ipChargeRequestDto);
if (!ipResourceRequestDto.getVendor().equals("own")) {
IpChargeRequestDto ipChargeRequestDto = buildIpChargeRequestDto(ipResourceRequestDto, 1, ipResourceRequestDto.getPayMethod());
accountService.chargeByMoney(username, newprice * ipChargeRequestDto.getAmount() * ipChargeRequestDto.getPeriod(), ipChargeRequestDto);
}
if (ipResourceRequestDto.getShopId() != null) {
ShopRequestDto shopRequestDto = new ShopRequestDto();
......@@ -270,7 +290,11 @@ public class IpResourceServiceImpl implements IpResourceService {
AtomicReference<Double> totalprice = new AtomicReference<>((double) 0);
ipResourceRequestDto.getAddr().stream().map(x -> ipResourceRepository.findByAddrAndIsDeleted(x, false))
.forEach(ipResource -> {
List<String> prices = priceList.get(ipResource.getRegionCn());
List<String> prices;
if (!ipResourceRequestDto.getVendor().equals("own"))
prices = priceList.get(ipResource.getRegionCn());
else
prices = priceList.get("自有");
for(String vendorprice:prices) {
if (ipResource.getVendor().getValue().equals(vendorprice.substring(0, vendorprice.indexOf("-"))))
totalprice.updateAndGet(v -> new Double( v + Double.valueOf(vendorprice.substring(vendorprice.lastIndexOf("-") + 1))));
......@@ -288,11 +312,13 @@ public class IpResourceServiceImpl implements IpResourceService {
RestTemplate restTemplate = new RestTemplate();
HashMap<String, Object> map = new HashMap<>();
map.put("iplist", ipResourceRequestDto.getAddr());
int period = 0;
period = ipResourceRequestDto.getPeriod();
if (ipResourceRequestDto.getUnit().equals("month") && ipResourceRequestDto.getPeriod() == 6)
ipResourceRequestDto.setPeriod(7);
period = 7;
else if (ipResourceRequestDto.getUnit().equals("month") && ipResourceRequestDto.getPeriod() == 12)
ipResourceRequestDto.setPeriod(14);
map.put("period", ipResourceRequestDto.getPeriod());
period = 14;
map.put("period", period);
map.put("unit", ipResourceRequestDto.getUnit());
HttpHeaders headers = buildPostHeader();
HttpEntity<Map<String, Object>> entity = new HttpEntity<>(map, headers);
......@@ -326,7 +352,11 @@ public class IpResourceServiceImpl implements IpResourceService {
if (ipResourceRequestDto.getIpId() != null && ipResourceRequestDto.getIpId().size() > 0) {
ipResourceRequestDto.getIpId().forEach(x -> {
IpResource ipResource = ipResourceRepository.findByIdAndIsDeleted(x, false);
List<String> vendorPrices = priceList.get(ipResource.getRegionCn());
List<String> vendorPrices;
if (!ipResourceRequestDto.getVendor().equals("own"))
vendorPrices = priceList.get(ipResource.getRegionCn());
else
vendorPrices = priceList.get("自有");
String price = vendorPrices.stream()
.filter(vendorprice -> ipResource.getVendor().getValue().equals(vendorprice.substring(0, vendorprice.indexOf("-"))))
.map(vendorprice -> vendorprice.substring(vendorprice.lastIndexOf("-") + 1)).collect(Collectors.joining());
......
......@@ -301,6 +301,28 @@ public class ShopServiceImpl implements ShopService {
}
}
@Override
public ShopResultDto queryShop(String username, String shopId) {
Account account = accountRepository.findByName(username);
if (account == null) {
throw new ClientRequestException(AccountErrorCode.NAMENOTEXIST);
}
UserShop userShop = userShopRepository.findByUsernameAndShopId(username, shopId);
if (account.getPermission() < 8 || userShop == null) {
throw new ClientRequestException(AccountErrorCode.NOPERMISSION);
}
Shop shop = shopRepository.findById(shopId).orElse(null);
if (shop == null) {
throw new ClientRequestException(BrowserErrorCode.SHOPNOTEXIST);
}
IpResource ipResource = ipResourceRepository.findByShopIdAndIsDeleted(shopId, false);
if (ipResource == null)
throw new ClientRequestException(BrowserErrorCode.IPNOTEXIST);
String group = userShopRepository.findByUsernameAndShopId(username, shop.getShopId()).getGroupId();
ShopResultDto shopResultDto = ShopResultDto.of(shop, group, ipResource);
return shopResultDto;
}
@Override
public ShopPageResultDto getShopList(String username, String groupId, int page, int amount, ShopFilterDto shopFilterDto) {
if (amount > 100)
......
......@@ -2,10 +2,7 @@ package com.edgec.browserbackend.browser.service;
import com.edgec.browserbackend.browser.domain.Shop;
import com.edgec.browserbackend.browser.domain.ShopSummary;
import com.edgec.browserbackend.browser.dto.ShopFilterDto;
import com.edgec.browserbackend.browser.dto.ShopPageResultDto;
import com.edgec.browserbackend.browser.dto.ShopRequestDto;
import com.edgec.browserbackend.browser.dto.ShopResultDto;
import com.edgec.browserbackend.browser.dto.*;
import org.springframework.web.multipart.MultipartFile;
import java.io.IOException;
......@@ -25,6 +22,8 @@ public interface ShopService {
void assignShops(String username, List<String> shopIds, List<String> users);
ShopResultDto queryShop(String username, String shopId);
ShopPageResultDto getShopList(String username, String groupId, int page, int amount, ShopFilterDto shopFilterDto);
ShopSummary getShopSummary(String username);
......
......@@ -95,11 +95,13 @@ public class BrowserTask {
HashMap<String, Object> map = new HashMap<>();
map.put("name", ipResource.getUsername());
map.put("region", ipResource.getRegion());
int period = 0;
period = ipResource.getPeriod();
if (ipResource.getUnit().equals("month") && ipResource.getPeriod() == 6)
ipResource.setPeriod(7);
period = 7;
else if (ipResource.getUnit().equals("month") && ipResource.getPeriod() == 12)
ipResource.setPeriod(14);
map.put("period", String.valueOf(ipResource.getPeriod()));
period = 14;
map.put("period", String.valueOf(period));
map.put("provider", ipResource.getVendor());
map.put("unit", ipResource.getUnit());
map.put("amount", 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