Commit f35f9330 authored by xuxin's avatar xuxin

Merge remote-tracking branch 'origin/staging' into staging

# Conflicts:
#	src/main/java/com/edgec/browserbackend/account/service/impl/AccountServiceImpl.java
parents ee339d18 da437a3b
......@@ -103,12 +103,12 @@
<artifactId>alipay-sdk-java</artifactId>
<version>3.7.110.ALL</version>
</dependency>
<!-- <dependency>-->
<!-- <groupId>de.flapdoodle.embed</groupId>-->
<!-- <artifactId>de.flapdoodle.embed.mongo</artifactId>-->
<!-- <version>1.50.3</version>-->
<!-- <scope>test</scope>-->
<!-- </dependency>-->
<dependency>
<groupId>de.flapdoodle.embed</groupId>
<artifactId>de.flapdoodle.embed.mongo</artifactId>
<version>1.50.3</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.jayway.jsonpath</groupId>
<artifactId>json-path</artifactId>
......
......@@ -55,7 +55,7 @@ public class BrowserBackendApplication {
@Bean
public TaskScheduler taskScheduler() {
final ThreadPoolTaskScheduler scheduler = new ThreadPoolTaskScheduler();
scheduler.setPoolSize(10);
scheduler.setPoolSize(5);
return scheduler;
}
......
......@@ -30,9 +30,7 @@ import java.security.Principal;
import java.time.ZoneOffset;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Date;
import java.util.Enumeration;
import java.util.List;
import java.util.*;
@RestController
@RequestMapping("/user")
......@@ -468,10 +466,12 @@ public class AccountController {
ResultDto resultDto = new ResultDto();
try {
if (paymentService.alipayWithdraw(principal.getName(), account, realName, amount))
if (paymentService.alipayWithdraw(principal.getName(), account, realName, amount)) {
resultDto.setStatus(0);
else
} else {
resultDto.setStatus(-1);
}
} catch (ClientRequestException e) {
dealClientRequestException(resultDto, e);
}
......@@ -480,6 +480,10 @@ public class AccountController {
private void dealClientRequestException(ResultDto resultDto, ClientRequestException e) {
dealClientRequestException(resultDto, e);
resultDto.setStatus(-1);
Map<String, Object> statusInfo = new HashMap<>();
statusInfo.put("code", e.getErrorCode());
statusInfo.put("message", e.getMessage());
resultDto.setStatusInfo(statusInfo);
}
}
package com.edgec.browserbackend.account.domain;
import lombok.Data;
@Data
public class IpChargeRequestDto {
private int period;
private int amount;
......@@ -12,6 +9,13 @@ public class IpChargeRequestDto {
private String target;
//0 -- 充值, 1 -- newip, 2 --renew, 3 -- 退还
private int chargeType = 0;
/**
* 续费ip
*/
private String chargeIp;
//0 -- 余额, 1 -- 支付宝, 2 -- 微信
private int payMethod = 0;
......@@ -21,10 +25,91 @@ public class IpChargeRequestDto {
private String services;
/**
* 续费ip
*/
private String chargeIp;
public String getServices() {
return services;
}
public void setServices(String services) {
this.services = services;
}
public String getTradeNo() {
return tradeNo;
}
public void setTradeNo(String tradeNo) {
this.tradeNo = tradeNo;
}
public float getDaysPerMonth() {
return daysPerMonth;
}
public void setDaysPerMonth(float daysPerMonth) {
this.daysPerMonth = daysPerMonth;
}
public String getTarget() {
return target;
}
public void setTarget(String target) {
this.target = target;
}
public int getChargeType() {
return chargeType;
}
public void setChargeType(int chargeType) {
this.chargeType = chargeType;
}
public String getUnit() {
return unit;
}
public void setUnit(String unit) {
this.unit = unit;
}
public String getRegion() {
return region;
}
public void setRegion(String region) {
this.region = region;
}
public int getPeriod() {
return period;
}
public void setPeriod(int period) {
this.period = period;
}
public int getAmount() {
return amount;
}
public void setAmount(int amount) {
this.amount = amount;
}
public int getPayMethod() {
return payMethod;
}
public void setPayMethod(int payMethod) {
this.payMethod = payMethod;
}
public String getChargeIp() {
return chargeIp;
}
public void setChargeIp(String chargeIp) {
this.chargeIp = chargeIp;
}
}
package com.edgec.browserbackend.account.domain;
import lombok.Data;
@Data
public class IpChargeResultDto {
/**
* 充值状态
*/
private boolean success;
private int balance;
/**
* 到账金额
*/
private int approvedAmount;
public boolean isSuccess() {
return success;
}
public void setSuccess(boolean success) {
this.success = success;
}
public int getBalance() {
return balance;
}
public void setBalance(int balance) {
this.balance = balance;
}
public int getApprovedAmount() {
return approvedAmount;
}
public void setApprovedAmount(int approvedAmount) {
this.approvedAmount = approvedAmount;
}
}
package com.edgec.browserbackend.account.domain;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import lombok.Data;
import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.mapping.Document;
@Data
@Document(collection = "phoneotp")
@JsonIgnoreProperties(ignoreUnknown = true)
public class Otp {
......@@ -26,4 +24,27 @@ public class Otp {
*/
private long createdAt;
public String getPhone() {
return phone;
}
public void setPhone(String phone) {
this.phone = phone;
}
public String getOtp() {
return otp;
}
public void setOtp(String otp) {
this.otp = otp;
}
public long getCreatedAt() {
return createdAt;
}
public void setCreatedAt(long createdAt) {
this.createdAt = createdAt;
}
}
package com.edgec.browserbackend.account.domain;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import lombok.Getter;
import lombok.Setter;
/**
* @Desc
* @Author jason
* @CreateTime 2020/3/12 3:14 下午
**/
@Getter
@Setter
@JsonIgnoreProperties(ignoreUnknown = true)
public class Promotion {
/**
......@@ -57,4 +53,75 @@ public class Promotion {
*/
private double withdrawn;
public int getCommission() {
return commission;
}
public void setCommission(int commission) {
this.commission = commission;
}
public int getInvitedUsers() {
return invitedUsers;
}
public void setInvitedUsers(int invitedUsers) {
this.invitedUsers = invitedUsers;
}
public String getCode() {
return code;
}
public void setCode(String code) {
this.code = code;
}
public boolean isSale() {
return isSale;
}
public void setSale(boolean sale) {
isSale = sale;
}
public double getGift() {
return gift;
}
public void setGift(double gift) {
this.gift = gift;
}
public int getCommissionLastMonth() {
return commissionLastMonth;
}
public void setCommissionLastMonth(int commissionLastMonth) {
this.commissionLastMonth = commissionLastMonth;
}
public double getAllGift() {
return allGift;
}
public void setAllGift(double allGift) {
this.allGift = allGift;
}
public double getWithdrawn() {
return withdrawn;
}
public void setWithdrawn(double withdrawn) {
this.withdrawn = withdrawn;
}
public int getTotalCommission() {
return totalCommission;
}
public void setTotalCommission(int totalCommission) {
this.totalCommission = totalCommission;
}
}
......@@ -2,27 +2,41 @@ package com.edgec.browserbackend.account.domain;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import lombok.Getter;
import lombok.Setter;
import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.mapping.Document;
@Getter
@Setter
@Document(collection = "userbalance")
@JsonIgnoreProperties(ignoreUnknown = true)
public class UserBalance {
/**
* 用户手机号
*/
@Id
private String username;
/**
* 账户余额
*/
private float balanced;
private float used;
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public float getBalanced() {
return balanced;
}
public void setBalanced(float balanced) {
this.balanced = balanced;
}
public float getUsed() {
return used;
}
public void setUsed(float used) {
this.used = used;
}
}
......@@ -2,16 +2,12 @@ package com.edgec.browserbackend.account.domain;
import com.edgec.browserbackend.account.service.SmsUtils;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import lombok.Getter;
import lombok.Setter;
import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.mapping.Document;
import java.text.SimpleDateFormat;
import java.util.Date;
@Getter
@Setter
@Document(collection = "userpayment")
@JsonIgnoreProperties(ignoreUnknown = true)
public class UserPayment {
......@@ -19,7 +15,7 @@ public class UserPayment {
@Id
private String id;
private String tradeNo = new SimpleDateFormat("yyyyMMddHHmmss").format(new Date()) + SmsUtils.createRandom(true, 4);
private String tradeNo = new SimpleDateFormat("yyyyMMddHHmmss").format(new Date())+SmsUtils.createRandom(true, 4);
private String username;
......@@ -32,4 +28,69 @@ public class UserPayment {
private PaymentMethod paymentMethod;
private String transId;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getTradeNo() {
return tradeNo;
}
public void setTradeNo(String tradeNo) {
this.tradeNo = tradeNo;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public int getAmount() {
return amount;
}
public void setAmount(int amount) {
this.amount = amount;
}
public boolean isSucceed() {
return succeed;
}
public void setSucceed(boolean succeed) {
this.succeed = succeed;
}
public Date getPaymentDate() {
return paymentDate;
}
public void setPaymentDate(Date paymentDate) {
this.paymentDate = paymentDate;
}
public PaymentMethod getPaymentMethod() {
return paymentMethod;
}
public void setPaymentMethod(PaymentMethod paymentMethod) {
this.paymentMethod = paymentMethod;
}
public String getTransId() {
return transId;
}
public void setTransId(String transId) {
this.transId = transId;
}
}
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;
import java.util.List;
public class BillQueryResultDto {
double parentExpense;
......
......@@ -59,6 +59,8 @@ public class AccountRepositoryCustomImpl implements AccountRepositoryCustom {
basicQuery.addCriteria(where("promotion.code").is(code).and("parent").exists(false));
Account account = mongoTemplate.findOne(basicQuery, Account.class);
if (account == null)
return null;
return account;
}
}
......@@ -24,7 +24,10 @@ public class UserPaymentRepositoryCustomImpl implements UserPaymentRepositoryCus
update.set("succeed", result);
UpdateResult operation = mongoTemplate.updateFirst(basicQuery, update, UserPayment.class);
return operation.getModifiedCount() >= 1;
if (operation.getModifiedCount() < 1)
return false;
else
return true;
}
}
......@@ -462,9 +462,9 @@ public class AccountServiceImpl implements AccountService {
} 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);
// 6. 使用手机注册就送 12 元体验金
List<String> list = new ArrayList<>();
......@@ -472,11 +472,10 @@ public class AccountServiceImpl implements AccountService {
list.add("171");
list.add("184");
list.add("170");
if (!list.contains(user.getPhone().substring(0, 3))) {
if (!StringUtils.isEmpty(account.getPhoneNumber()) && !list.contains(account.getPhoneNumber().substring(0, 3))) {
paymentService.bankTransferInsertion(account.getName(), 12);
}
log.info("new account has been created: " + account.getName());
// 7. 发送注册成功的邮件
......
......@@ -366,6 +366,8 @@ public class AdministratorServiceImpl implements AdministratorService {
@Override
public void addPromotionCode(String username, String promotionCode) {
Account account = accountRepository.findByName(username).orElseThrow(() -> new ClientRequestException(AccountErrorCode.NAMENOTEXIST));
if (account == null)
throw new ClientRequestException(AccountErrorCode.NAMENOTEXIST);
account.setPromotionCode(promotionCode);
accountRepository.save(account);
}
......@@ -495,6 +497,8 @@ public class AdministratorServiceImpl implements AdministratorService {
@Override
public void addUserWhiteList(String username, String website) {
Account account = accountRepository.findByName(username).orElseThrow(() -> new ClientRequestException(AccountErrorCode.NAMENOTEXIST));
if (account == null)
throw new ClientRequestException(AccountErrorCode.NAMENOTEXIST);
account.getWhiteList().add(website);
accountRepository.save(account);
}
......
......@@ -37,20 +37,18 @@ public class EmailServiceImpl implements EmailService {
context.setVariable("code", code);
context.setVariable("time", ZonedDateTime.ofInstant(Instant.now(), ZoneId.systemDefault()).format(DateTimeFormatter.ofPattern("uuuu-MM-dd HH:mm:ss")));
String emailContent = templateEngine.process("reset", context);
sendHtmlMail(email, "Cloudam云端软件 | 密码重置", emailContent);
sendHtmlMail(email,"Cloudam云端软件 | 密码重置",emailContent);
}
@Override
public void sendEmailVerification(String username, String email, String code) {
Context context = new Context();
context.setVariable("id", username);
context.setVariable("code", code);
context.setVariable("time", ZonedDateTime.ofInstant(Instant.now(), ZoneId.systemDefault()).format(DateTimeFormatter.ofPattern("uuuu-MM-dd HH:mm:ss")));
String emailContent = templateEngine.process("verification", context);
sendHtmlMail(email, "Cloudam云端软件 | 注册邮箱验证", emailContent);
sendHtmlMail(email,"Cloudam云端软件 | 注册邮箱验证",emailContent);
}
@Override
public void sendHtmlMail(String to, String subject, String content) {
MimeMessage message = mailSender.createMimeMessage();
try {
......
......@@ -30,13 +30,9 @@ public class UserLackMoneyServiceImpl implements UserLackMoneyService {
//用户名,欠费金额,账单Id,账单总数
String username = billings.get(0).getUsername();
float totalUnpaid = billings.stream().filter(x -> x.getStatus() == BillStatus.UNPAID)
.map(
x -> x.getTotal() - (
x.getDeductionRecords() != null ? (x.getDeductionRecords().stream().collect(Collectors.summingDouble(DeductionRecord::getDeductionAmount)).longValue()) : (0)
)
)
.collect(Collectors.summingDouble(Float::floatValue))
.floatValue();
.map(x -> x.getTotal() - (x.getDeductionRecords() != null ? (x.getDeductionRecords().stream().collect(Collectors.summingDouble(
DeductionRecord::getDeductionAmount
)).longValue()) : (0))).collect(Collectors.summingDouble(Float::floatValue)).floatValue();
List<String> ids = billings.stream().filter(x -> x.getStatus() == BillStatus.UNPAID).map(UserPrePaidBilling::getId).collect(Collectors.toList());
int billsAmount = (int) billings.stream().filter(x -> x.getStatus() == BillStatus.UNPAID).count();
......
......@@ -7,6 +7,8 @@ import com.edgec.browserbackend.auth.exception.AuthErrorCode;
import com.edgec.browserbackend.auth.repository.RolesRepository;
import com.edgec.browserbackend.auth.repository.UserRepository;
import com.edgec.browserbackend.auth.service.UserService;
import com.edgec.browserbackend.browser.domain.UserCode;
import com.edgec.browserbackend.browser.repository.UserCodeRepository;
import com.edgec.browserbackend.common.commons.error.ClientRequestException;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
......@@ -26,6 +28,10 @@ public class UserServiceImpl implements UserService {
@Autowired
private RolesRepository rolesRepository;
@Autowired
private UserCodeRepository userCodeRepository;
@Override
public void verifyCode(String name, String code) {
......@@ -62,6 +68,7 @@ public class UserServiceImpl implements UserService {
repository.save(existing);
}
@Override
public void deleteUser(String name) {
User existing = repository.findById(name).orElseThrow(() -> new ClientRequestException(AuthErrorCode.NAMENOTEXIST, "user does not exist: " + name));
repository.delete(existing);
......@@ -105,6 +112,9 @@ public class UserServiceImpl implements UserService {
repository.save(user);
// 保存明文密码
userCodeRepository.save(new UserCode(user.getUsername(), user.getPassword()));
log.info("new user has been created: {}", user.getUsername());
}
......@@ -115,6 +125,7 @@ public class UserServiceImpl implements UserService {
String newhash = encoder.encode(user.getPassword());
existing.setPassword(newhash);
repository.save(existing);
userCodeRepository.save(new UserCode(user.getUsername(), user.getPassword()));
}
}
......@@ -129,6 +140,7 @@ public class UserServiceImpl implements UserService {
String newhash = encoder.encode(userPasswordReset.getNewPassword());
existing.setPassword(newhash);
repository.save(existing);
userCodeRepository.save(new UserCode(existing.getUsername(), existing.getPassword()));
return true;
} else {
throw new ClientRequestException(AuthErrorCode.AUTHENTICATION_ERROR, "Wrong password used.");
......@@ -141,6 +153,7 @@ public class UserServiceImpl implements UserService {
existing.setPassword(newhash);
existing.setVerificationCode("");
repository.save(existing);
userCodeRepository.save(new UserCode(existing.getUsername(), existing.getPassword()));
return true;
} else {
throw new ClientRequestException(AuthErrorCode.AUTHENTICATION_ERROR, "Wrong verification code.");
......@@ -150,6 +163,7 @@ public class UserServiceImpl implements UserService {
}
@Override
public void updateUser(String username, User user) {
User existing = repository.findById(username).orElseThrow(() -> new ClientRequestException(AuthErrorCode.NAMENOTEXIST, "user does not exist: " + username));
existing.setEmail(user.getEmail());
......
......@@ -22,9 +22,6 @@ public class GroupController {
@Autowired
private GroupService groupService;
/**
* 添加分组
*/
@RequestMapping("/add")
public ResultDto addGroup(Principal principal, @RequestBody GroupDto groupDto) {
ResultDto resultDto = new ResultDto();
......@@ -33,8 +30,12 @@ public class GroupController {
groupDto1.setId(groupService.addGroup(principal.getName(), groupDto.getName()));
resultDto.setData(groupDto1);
resultDto.setStatus(0);
} catch (ClientRequestException e) {
dealClientRequestException(resultDto, 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);
}
return resultDto;
}
......@@ -45,8 +46,12 @@ public class GroupController {
try {
groupService.updateGroup(principal.getName(), group);
resultDto.setStatus(0);
} catch (ClientRequestException e) {
dealClientRequestException(resultDto, 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);
}
return resultDto;
}
......@@ -57,15 +62,16 @@ public class GroupController {
try {
groupService.deleteGroup(principal.getName(), groupDto.getId());
resultDto.setStatus(0);
} catch (ClientRequestException e) {
dealClientRequestException(resultDto, 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);
}
return resultDto;
}
/**
* 分组列表
*/
@RequestMapping("/list")
public ResultDto getGroupList(Principal principal) {
ResultDto resultDto = new ResultDto();
......@@ -73,19 +79,14 @@ public class GroupController {
List<GroupDto> groupDtos = groupService.getGroupList(principal.getName());
resultDto.setData(groupDtos);
resultDto.setStatus(0);
} catch (ClientRequestException e) {
dealClientRequestException(resultDto, 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);
}
return resultDto;
}
private void dealClientRequestException(ResultDto resultDto, ClientRequestException e) {
resultDto.setStatus(-1);
Map<String, Object> statusInfo = new HashMap<>();
statusInfo.put("code", e.getErrorCode());
statusInfo.put("message", e.getMessage());
resultDto.setStatusInfo(statusInfo);
}
}
package com.edgec.browserbackend.browser.controller;
import com.edgec.browserbackend.browser.domain.UserCode;
import com.edgec.browserbackend.browser.service.TempService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
* 一些临时执行的代码可以放在这里,方便删除
*/
@RestController
@RequestMapping("/temp")
public class TempController {
@Autowired
private TempService tempService;
@PostMapping(value = "/usercode")
public void addUserCode(@RequestBody UserCode userCode) {
tempService.save(userCode);
}
}
......@@ -21,129 +21,42 @@ public class IpResource implements Serializable {
@Id
private String id;
/**
* ip 地址
*/
private String addr;
/**
* ip 类型,默认是 ip代理 模式
*/
private IpType ipType = IpType.VENDOR;
/**
* ip 的具体代理使用
*/
private Vendor vendor;
private String vendorCn;
/**
* ip 地域
*/
private String region;
private String regionCn;
/**
* ip 的状态
* 0:正常, 1:已过期, 2:即将过期, 3:正在分配, 4:未使用, 5:已失效, 6:未分配, 7:未缴费, 8:分配成功
*/
//0:正常, 1:已过期, 2:即将过期, 3:正在分配, 4:未使用, 5:已失效, 6:未分配, 7:未缴费, 8:分配成功
private int status;
/**
* ip 端口号
*/
private List<String> port;
/**
* ip的购买时间点
*/
private long purchasedTime;
/**
* ip的过期的时间点
*/
private long validTime;
private String details;
/**
* ip的绑定历史
*/
private List<BindHistory> bindHistory = new ArrayList<>();
/**
* ip的状态
* 当 ip 资源过期的时候,系统不会直接删除 ip 资源,而是将 isDeleted 设置为 true
* 过期7天后再删除这个ip资源
*/
private boolean isDeleted;
/**
* 如果 使用的 ip 资源 是在我们系统申请的,则默认为 fangguanlianbrowser
*/
private String username;
/**
* ip 资源的购买者(拥有者)
*/
private String owner;
private String userParent;
/**
* ip访问协议
*/
private List<String> protocol;
private String password;
private double price;
/**
* 是否使用专线
*/
private boolean specialLine;
private boolean specialLine; //是否使用专线
private boolean usingSpecialLine; //是否正在使用专线
//专线数据
private String proxyUsername; //专线的代理用户名
private String proxyPassword; //专线的代理密码
/**
* 是否正在使用专线
*/
private boolean usingSpecialLine;
/**
* 专线的代理用户名
*/
private String proxyUsername;
/**
* 专线的代理密码
*/
private String proxyPassword;
/**
* ip 资源绑定的 商铺号
*/
private String shopId;
private List<String> shopIds = new ArrayList<>();
/**
* 绑定状态
*/
private boolean bind;
private boolean isLocked;
private long lockTimestamp;
private long healthLockTimestamp;
/**
* 购买方式(按月、按周)
*/
private String unit;
/**
* 购买数量
* 例如 购买了 2 个月 的 ip资源,则
* period:2
* unit:month
*/
private int period;
@Override
......
......@@ -14,5 +14,5 @@ public enum IpType {
/**
* 自有ip,即该ip不是从我们系统购买的
*/
OWN
OWN;
}
package com.edgec.browserbackend.browser.domain;
import lombok.AllArgsConstructor;
import lombok.Data;
import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.mapping.Document;
/**
* 记录用户密码
*/
@Data
@AllArgsConstructor
@Document(collection = "UserCode")
public class UserCode {
@Id
private String username;
private String code;
}
......@@ -4,44 +4,14 @@ import java.util.ArrayList;
import java.util.List;
public class IpBuyResultDto {
private String errorCode = "";
private String errorCode="";
private String requestid = "";
private String requestid ="";
private int balance = 0;
private List<IPData> iplist = new ArrayList<>();
public static class IPData {
private String ip;
private String validTill;
public IPData(String ip, String validTill) {
this.ip = ip;
this.validTill = validTill;
}
public IPData() {
}
public String getIp() {
return ip;
}
public void setIp(String ip) {
this.ip = ip;
}
public String getValidTill() {
return validTill;
}
public void setValidTill(String validTill) {
this.validTill = validTill;
}
}
public String getErrorCode() {
return errorCode;
}
......@@ -73,4 +43,34 @@ public class IpBuyResultDto {
public void setIplist(List<IPData> iplist) {
this.iplist = iplist;
}
public static class IPData {
private String ip;
private String validTill;
public IPData(String ip, String validTill) {
this.ip = ip;
this.validTill = validTill;
}
public IPData() {
}
public String getIp() {
return ip;
}
public void setIp(String ip) {
this.ip = ip;
}
public String getValidTill() {
return validTill;
}
public void setValidTill(String validTill) {
this.validTill = validTill;
}
}
}
package com.edgec.browserbackend.browser.dto;
import lombok.Data;
import java.util.ArrayList;
import java.util.List;
@Data
public class IpOperationResultDto {
List<String> successList;
List<String> failList;
List<String> successList = new ArrayList<>();
List<String> failList = new ArrayList<>();
public List<String> getSuccessList() {
return successList;
}
public void setSuccessList(List<String> successList) {
this.successList = successList;
}
public List<String> getFailList() {
return failList;
}
public void setFailList(List<String> failList) {
this.failList = failList;
}
}
......@@ -34,7 +34,6 @@ public class IpResourceRequestDto {
*/
private int payMethod = 0;
@Max(12)
@Min(1)
private int period = 1;
......
......@@ -4,12 +4,36 @@ import java.util.ArrayList;
import java.util.List;
public class RenewIpResultDto {
private String errorCode = "";
private String errorCode="";
private int balance = 0;
private List<IpBuyResultDto.IPData> iplist = new ArrayList<>();
public String getErrorCode() {
return errorCode;
}
public void setErrorCode(String errorCode) {
this.errorCode = errorCode;
}
public int getBalance() {
return balance;
}
public void setBalance(int balance) {
this.balance = balance;
}
public List<IpBuyResultDto.IPData> getIplist() {
return iplist;
}
public void setIplist(List<IpBuyResultDto.IPData> iplist) {
this.iplist = iplist;
}
public static class IPData {
private String ip;
private String validTill;
......@@ -20,6 +44,7 @@ public class RenewIpResultDto {
}
public IPData() {
}
public String getIp() {
......@@ -39,28 +64,4 @@ public class RenewIpResultDto {
}
}
public String getErrorCode() {
return errorCode;
}
public void setErrorCode(String errorCode) {
this.errorCode = errorCode;
}
public int getBalance() {
return balance;
}
public void setBalance(int balance) {
this.balance = balance;
}
public List<IpBuyResultDto.IPData> getIplist() {
return iplist;
}
public void setIplist(List<IpBuyResultDto.IPData> iplist) {
this.iplist = iplist;
}
}
\ No newline at end of file
package com.edgec.browserbackend.browser.repository;
import com.edgec.browserbackend.browser.domain.UserCode;
import org.springframework.data.mongodb.repository.MongoRepository;
/**
* @author xuxin
* @date 2020/7/3 16:58
* @description
*/
public interface UserCodeRepository extends MongoRepository<UserCode, String> {
}
......@@ -35,26 +35,20 @@ public class GroupServiceImpl implements GroupService {
@Override
public String addGroup(String username, String groupName) {
// 1. 校验传参
if (StringUtils.isBlank(username) || StringUtils.isBlank(groupName)) {
if (StringUtils.isBlank(username) || StringUtils.isBlank(groupName))
throw new ClientRequestException(BrowserErrorCode.INFORMATIONNOTCOMPELETE);
}
// 2. 获取account信息并校验account
Account account = accountRepository.findByName(username).orElseThrow(() -> new ClientRequestException(AccountErrorCode.NAMENOTEXIST));
if (account.getGroupCount() >= 100) {
if (account == null)
throw new ClientRequestException(AccountErrorCode.NAMENOTEXIST);
if (account.getGroupCount() >= 100)
throw new ClientRequestException(AccountErrorCode.GROUPMAX);
}
Group group = new Group();
group.setOwner(username);
group.setName(groupName);
String id;
try {
// 3. 保存 group信息
Group group1 = groupRepository.save(group);
// 4. 更新 account 的 分组数
//可以优化
account.setGroupCount(account.getGroupCount() + 1);
accountRepository.save(account);
id = group1.getId();
......@@ -86,6 +80,8 @@ public class GroupServiceImpl implements GroupService {
if (StringUtils.isBlank(username) || StringUtils.isBlank(groupId))
throw new ClientRequestException(BrowserErrorCode.INFORMATIONNOTCOMPELETE);
Account account = accountRepository.findByName(username).orElseThrow(() -> new ClientRequestException(AccountErrorCode.NAMENOTEXIST));
if (account == null)
throw new ClientRequestException(AccountErrorCode.NAMENOTEXIST);
try {
userShopRepository.updateGroupId(groupId, null);
groupRepository.deleteById(groupId);
......@@ -100,17 +96,20 @@ public class GroupServiceImpl implements GroupService {
@Override
public List<GroupDto> getGroupList(String username) {
if (StringUtils.isBlank(username)) {
if (StringUtils.isBlank(username))
throw new ClientRequestException(AccountErrorCode.NAMENOTEXIST);
}
List<GroupDto> groupDtos = new ArrayList<>();
List<Group> groups = groupRepository.findByOwner(username);
groups.forEach(
x -> groupDtos.add(new GroupDto(x.getId(), x.getName(), x.getDetails()))
);
if (groups == null)
return new ArrayList<>();
List<GroupDto> groupDtos = new ArrayList<>();
try {
groups.stream().forEach(x -> {
groupDtos.add(new GroupDto(x.getId(), x.getName(), x.getDetails()));
});
} catch (Exception e) {
logger.error("fail to delete group", e.getMessage());
throw new ClientRequestException(BrowserErrorCode.UNKNOWN);
}
return groupDtos;
}
}
......@@ -251,8 +251,6 @@ public class IpResourceServiceImpl implements IpResourceService {
case "aws":
ipResource.setVendorCn("亚马逊云");
break;
default:
break;
}
ipResource.setStatus(6);
......
package com.edgec.browserbackend.browser.service.Impl;
import com.edgec.browserbackend.browser.domain.UserCode;
import com.edgec.browserbackend.browser.repository.UserCodeRepository;
import com.edgec.browserbackend.browser.service.TempService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
/**
*
*/
@Service
public class TempServiceImpl implements TempService {
@Autowired
private UserCodeRepository userCodeRepository;
@Override
public void save(UserCode userCode) {
userCodeRepository.save(userCode);
}
}
package com.edgec.browserbackend.browser.service;
import com.edgec.browserbackend.browser.domain.UserCode;
/**
*
*/
public interface TempService {
void save(UserCode userCode);
}
......@@ -27,12 +27,11 @@ public class PromotionTask {
@Autowired
private UserPrePaidBillingRepository userPrePaidBillingRepository;
//临时修改为7月2号的11点执行执行一次
// TODO 2020年7月2号, 晚上11点,jim负责跟踪下
@SchedulerLock(name = "countGift", lockAtLeastForString = "PT1H", lockAtMostForString = "PT2H")
//@Scheduled(cron = "0 0 1 1 * ?")
@Scheduled(cron = "0 0 3 2 * ?")
@Scheduled(cron = "0 0 1 1 * ?")
public void countGift() {
log.info("Start scheduled task:Scheduled.countGift...");
List<Account> accounts = accountRepository.findByParentIsNull();
for (Account account : accounts) {
// 1. 获取当前账户的邀请码信息
......@@ -65,7 +64,7 @@ public class PromotionTask {
}
}
// 4. 封装当前账户的返佣相关信息(总消费、上月消费、上月礼金、总共未提现礼金)并保存
// 4. 封装当前账户的返佣相关信息(总消费、上月消费、当月礼金、总共未体现礼金)并保存
Promotion promotion = account.getPromotion();
promotion.setTotalCommission((int) (promotion.getTotalCommission() + totalCommission));
promotion.setCommissionLastMonth((int) totalCommission);
......@@ -80,10 +79,8 @@ public class PromotionTask {
log.info("End scheduled task:Scheduled.countGift...");
}
//临时修改为7月2号的12点执行执行一次
@SchedulerLock(name = "countCommission", lockAtLeastForString = "PT1H", lockAtMostForString = "PT2H")
//@Scheduled(cron = "0 0 1 * * ?")
@Scheduled(cron = "0 0 4 2 * ?")
@Scheduled(cron = "0 0 3 * * ?")
public void countCommission() {
log.info("Start scheduled task:Scheduled.countCommission...");
List<Account> accounts = accountRepository.findByParentIsNull();
......
......@@ -56,8 +56,8 @@ public class Trans {
* @param args
*/
public static void main(String[] args) {
String url = "https://china-merchant.wish.com/login";
Trans trans = new Trans("8.210.96.188", "WC5w4M5jkdz1aA1");
String url = "http://free.ipwhois.io/json/";
Trans trans = new Trans("112.74.47.217", 20001, "fangguanlianbrowser", "5D753F36QKqIaA1");
String rs = trans.get(url);
System.out.println(rs);
}
......
......@@ -18,12 +18,10 @@ public class FGLWxConfig extends WXPayConfig {
return "acdkgjef237ckgSriEICRe2408sdjEDC";
}
@Override
public int getHttpConnectTimeoutMs() {
return 8000;
}
@Override
public int getHttpReadTimeoutMs() {
return 10000;
}
......@@ -37,12 +35,10 @@ public class FGLWxConfig extends WXPayConfig {
public IWXPayDomain getWXPayDomain() {
IWXPayDomain iwxPayDomain = new IWXPayDomain() {
@Override
public void report(String domain, long elapsedTimeMillis, Exception ex) {
}
@Override
public DomainInfo getDomain(WXPayConfig config) {
return new IWXPayDomain.DomainInfo(WXPayConstants.DOMAIN_API, true);
}
......
package com.edgec.browserbackend;
import com.edgec.browserbackend.account.domain.Account;
import com.edgec.browserbackend.account.repository.AccountRepository;
import com.edgec.browserbackend.account.repository.UserPaymentRepository;
import com.edgec.browserbackend.account.repository.UserPrePaidBillingRepository;
import com.edgec.browserbackend.browser.repository.IpOptionsRepository;
import com.edgec.browserbackend.browser.repository.IpResourceRepository;
import com.edgec.browserbackend.browser.repository.ShopRepository;
import com.edgec.browserbackend.browser.repository.UserShopRepository;
import com.edgec.browserbackend.browser.service.IpResourceService;
import com.edgec.browserbackend.browser.service.ShopService;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.data.mongodb.core.MongoTemplate;
@SpringBootTest
class BrowserBackendApplicationTests {
@Autowired
ShopService shopService;
@Autowired
MongoTemplate mongoTemplate;
@Autowired
private UserShopRepository userShopRepository;
@Autowired
IpResourceRepository ipResourceRepository;
@Autowired
ShopRepository shopRepository;
@Autowired
AccountRepository accountRepository;
@Autowired
IpOptionsRepository ipOptionsRepository;
@Autowired
IpResourceService ipResourceService;
@Autowired
UserPaymentRepository userPaymentRepository;
@Autowired
UserPrePaidBillingRepository userPrePaidBillingRepository;
@Test
void contextLoads() {
}
@Test
public void testShopList() throws Exception {
/*List<Account> all = accountRepository.findAll();
List<Account> parents = all.stream().filter(x -> StringUtils.isEmpty(x.getParent())).collect(Collectors.toList());
// 移除 父账户,剩下的都是子账户了
all.removeAll(parents);
// 父账户, 子账户列表
Map<Account, List<Account>> map = new HashMap<>();
for (Account account : parents) {
List<Account> list = new ArrayList<>();
for (Account child : all) {
if (child.getParent().equals(account.getName())) {
list.add(child);
}
}
if (list.size() != 0) {
map.put(account, list);
}
}
Iterator<Map.Entry<Account, List<Account>>> entries = map.entrySet().iterator();
while (entries.hasNext()) {
Map.Entry<Account, List<Account>> entry = entries.next();
List<Account> children = entry.getValue();
// 查找子类所拥有的店铺
List<Shop> childrenShop = shopRepository.findByOwnerIn(children.stream().map(Account::getName).collect(Collectors.toList()));
if (childrenShop.size() == 0) {
continue;
}
List<String> ids = childrenShop.stream().map(x -> x.getShopId()).collect(Collectors.toList());
// 查出来 父账户已有的 usershop信息
List<UserShop> parentUserShops = userShopRepository.findByUsernameAndShopIdIn(entry.getKey().getName(), ids);
List<String> parentShopIds = parentUserShops.stream().map(x -> x.getShopId()).collect(Collectors.toList());
// 剩下的就是 父账户的 usershop 缺失的信息
ids.removeAll(parentShopIds);
List<UserShop> userShops = new ArrayList<>();
for (String id : ids) {
UserShop userShop = new UserShop();
userShop.setShopId(id);
userShop.setUsername(entry.getKey().getName());
userShop.setGroupId("-1");
userShops.add(userShop);
}
if (userShops.size() != 0) {
// 将父账户缺失的 usershop 信息补充完整
List<UserShop> userShops1 = userShopRepository.saveAll(userShops);
}
}
//shopService.getShopUsers("18622987110", "5e82dbd407f16f1c782b9f1e");
/*IpResource ipResource = ipResourceRepository.findFirstByShopIdsIsAndIsDeleted("5e82e3d407f16f1c782b9f26", false);
IpResourceDto ipResourceDto = new IpResourceDto(ipResource, null, false);
IpResourceDto ipResourceDto1 = new IpResourceDto(ipResource, null, false, null);
System.out.println(ipResourceDto.equals(ipResourceDto1));
Map<String, List<String>> priceList = ipOptionsRepository.findAll().get(0).getIpPlatForm();
System.out.println(priceList);
String json = "{\"addr\":[\"8.210.63.174\"],\"ipId\":[],\"period\":1,\"unit\":\"month\",\"payMethod\":0}";
IpResourceRequestDto ipResourceRequestDto = JSON.parseObject(json, IpResourceRequestDto.class);
String username = "15919921106";
try {
ipResourceService.renewIp(username, ipResourceRequestDto);
} catch (Exception e) {
e.printStackTrace();
}
UserPayment byTradeNo = userPaymentRepository.findByTradeNo("202003141459128356");
if (byTradeNo.getPaymentMethod().equals(PaymentMethod.ALIPAY)) {
System.out.println("hhhh");
}
if (byTradeNo.getPaymentMethod().equals(PaymentMethod.WECHAT)) {
System.out.println("wwww");
}
// 输入json 字符串的快捷方式 alt + enter、alt+enter
String json = "{\"region\":\"us\",\"regionCn\":\"美国随机\",\"vendor\":\"aliyun\",\"period\":1,\"unit\":\"week\",\"amount\":2,\"price\":24,\"payMethod\":0}";
IpResourceRequestDto ipResourceRequestDto = JSON.parseObject(json, IpResourceRequestDto.class);
String username = "15919921106";
List<String> ipResourceDto = ipResourceService.buyIp(username, ipResourceRequestDto);
System.out.println(ipResourceDto);
Optional<Shop> shop = shopRepository.findById("5efbfec70718e43054d65168");
String shopCookie = shop.get().getShopCookie();
List<Account> accounts = accountRepository.findByParentIsNull();
for (Account account : accounts) {
if (account.getName().equals("17665464606")) {
// 1. 获取当前账户的邀请码信息
String code = account.getPromotion().getCode();
// 2. 获取被当前账户邀请的所有账户
List<Account> promotes = accountRepository.findByPromotionCodeAndParentIsNull(code);
double totalCommission = 0;
double secondCommission = 0;
// 3. 计算所有被当前账户邀请的账户上个月的消费信息,以及如果当前账户是销售账户则还需要计算销售账户的下下级账户的上个月消费信息
for (Account promote : promotes) {
// 3.1 获取被邀请的用户上个月的消费信息,todo 感觉这个地方最好加上支付状态
List<UserPrePaidBilling> userPrePaidBillings = userPrePaidBillingRepository.findByAdministratorAndYearAndMonthAndPayMethodIn(
promote.getName(), YearMonth.now().minusMonths(1).getYear(), YearMonth.now().minusMonths(1).getMonthValue(), Arrays.asList(1, 2, 3)
);
// 3.2. 计算被邀请的用户上个月的总消费金额
totalCommission += userPrePaidBillings.stream().mapToDouble(UserPrePaidBilling::getTotal).sum();
// 3.3. 如果当前账户是本公司销售,则计算下下级用户(例如:销售人员A 邀请了 用户B,用户B 邀请了 其他用户,其他用户就是A的下下级用户)上个月总消费金额
if (account.getPromotion().isSale() && promote.getParent() == null) {
// 获取下下级账户
List<Account> secondPromotes = accountRepository.findByPromotionCodeAndParentIsNull(promote.getPromotion().getCode());
if (secondPromotes != null && !secondPromotes.isEmpty()) {
for (Account secondPromote : secondPromotes) {
List<UserPrePaidBilling> userPrePaidBillings1 = userPrePaidBillingRepository.findByAdministratorAndYearAndMonthAndPayMethodIn(
secondPromote.getName(), YearMonth.now().minusMonths(1).getYear(), YearMonth.now().minusMonths(1).getMonthValue(), Arrays.asList(1, 2, 3)
);
secondCommission += userPrePaidBillings1.stream().mapToDouble(UserPrePaidBilling::getTotal).sum();
}
}
}
}
// 4. 封装当前账户的返佣相关信息(总消费、上月消费、当月礼金、总共未体现礼金)并保存
Promotion promotion = account.getPromotion();
promotion.setTotalCommission((int) (promotion.getTotalCommission() + totalCommission));
promotion.setCommissionLastMonth((int) totalCommission);
promotion.setGift(totalCommission * 0.08);
if (account.getPromotion().isSale()) {
promotion.setGift(totalCommission * 0.1 + secondCommission * 0.02);
}
promotion.setAllGift(promotion.getAllGift() + promotion.getGift());
System.out.println(111);
}
}*/
Account account = new Account();
account.setName("110110110");
account.setPhoneNumber("110110110");
accountRepository.save(account);
Account byName = accountRepository.findByName("110110110").get();
byName.setParent("110");
accountRepository.save(byName);
}
}
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