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