Commit 4a022416 authored by jim's avatar jim

Merge remote-tracking branch 'origin/master'

parents 5abd5ff7 2a7e3083
package com.edgec.browserbackend.account.domain;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import org.hibernate.validator.constraints.Length;
import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.mapping.Document;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
@NoArgsConstructor
@Getter
@Setter
@Document(collection = "accounts")
@JsonIgnoreProperties(ignoreUnknown = true)
public class Account {
/**
* 账户id
*/
@Id
private String name;
/**
* 父账户
*/
private String parent;
//子用户使用
/**
* 子用户使用的密码
*/
private String password;
private Date lastSeen;
......@@ -44,6 +58,13 @@ public class Account {
private boolean allowedToCreateSubUser = false;
/**
* 操作与权重
* <p>
* 下载 cookie:1
* 上传 cookie:2
* 店铺管理(增删改店铺、绑定与解绑ip):4
*/
private int permission = -1;
private Promotion promotion;
......@@ -64,24 +85,8 @@ public class Account {
private List<String> queryIpUrlList = new ArrayList<>();
public Date getSignupDate() {
return signupDate;
}
public void setSignupDate(Date signupDate) {
this.signupDate = signupDate;
}
public boolean isPrePaid() {
return isPrePaid;
}
public void setPrePaid(boolean prePaid) {
isPrePaid = prePaid;
}
public Account() {
}
@Length(min = 0, max = 20000)
private String note;
public Account(AccountDto account) {
this.setName(account.getName());
......@@ -94,191 +99,5 @@ public class Account {
this.setWhiteList(account.getWhiteList());
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getCompanyName() {
return companyName;
}
public void setCompanyName(String companyName) {
this.companyName = companyName;
}
public String getJobTitle() {
return jobTitle;
}
public void setJobTitle(String jobTitle) {
this.jobTitle = jobTitle;
}
public String getPhoneNumber() {
return phoneNumber;
}
public void setPhoneNumber(String phoneNumber) {
this.phoneNumber = phoneNumber;
}
@Length(min = 0, max = 20000)
private String note;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Date getLastSeen() {
return lastSeen;
}
public void setLastSeen(Date lastSeen) {
this.lastSeen = lastSeen;
}
public String getNote() {
return note;
}
public void setNote(String note) {
this.note = note;
}
public String getParent() {
return parent;
}
public void setParent(String parent) {
this.parent = parent;
}
public boolean isAllowedToCreateSubUser() {
return allowedToCreateSubUser;
}
public void setAllowedToCreateSubUser(boolean allowedToCreateSubUser) {
this.allowedToCreateSubUser = allowedToCreateSubUser;
}
public String getLockReason() {
return lockReason;
}
public void setLockReason(String lockReason) {
this.lockReason = lockReason;
}
public String getToken() {
return token;
}
public void setToken(String token) {
this.token = token;
}
public int getPermission() {
return permission;
}
public void setPermission(int permission) {
this.permission = permission;
}
public List<String> getWhiteList() {
return whiteList;
}
public void setWhiteList(List<String> whiteList) {
this.whiteList = whiteList;
}
public int getChildCount() {
return childCount;
}
public void setChildCount(int childCount) {
this.childCount = childCount;
}
public int getGroupCount() {
return groupCount;
}
public void setGroupCount(int groupCount) {
this.groupCount = groupCount;
}
public int getShopCount() {
return shopCount;
}
public void setShopCount(int shopCount) {
this.shopCount = shopCount;
}
public Promotion getPromotion() {
return promotion;
}
public void setPromotion(Promotion promotion) {
this.promotion = promotion;
}
public String getNickname() {
return nickname;
}
public void setNickname(String nickname) {
this.nickname = nickname;
}
public String getComment() {
return comment;
}
public void setComment(String comment) {
this.comment = comment;
}
public List<String> getQueryIpUrlList() {
return queryIpUrlList;
}
public void setQueryIpUrlList(List<String> queryIpUrlList) {
this.queryIpUrlList = queryIpUrlList;
}
public int getAuthorized() {
return authorized;
}
public void setAuthorized(int authorized) {
this.authorized = authorized;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getPromotionCode() {
return promotionCode;
}
public void setPromotionCode(String promotionCode) {
this.promotionCode = promotionCode;
}
}
package com.edgec.browserbackend.account.repository;
import com.edgec.browserbackend.account.domain.Account;
import com.edgec.browserbackend.browser.dto.PageInfo;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.mongodb.repository.MongoRepository;
......@@ -9,11 +8,12 @@ import org.springframework.stereotype.Repository;
import java.util.Date;
import java.util.List;
import java.util.Optional;
@Repository
public interface AccountRepository extends MongoRepository<Account, String>, AccountRepositoryCustom {
Account findByName(String name);
Optional<Account> findByName(String name);
Account findByEmail(String email);
......@@ -37,6 +37,7 @@ public interface AccountRepository extends MongoRepository<Account, String>, Acc
Page<Account> findAllBySignupDateBetweenAndParentIsNullAndAuthorized(Pageable pageable, Date startDate, Date endDate, int authorized);
@Override
Page<Account> findAll(Pageable pageable);
List<Account> findByNameIn(List<String> names);
......
......@@ -4,21 +4,18 @@ import com.alibaba.fastjson.JSONObject;
import com.alipay.api.AlipayClient;
import com.alipay.api.DefaultAlipayClient;
import com.alipay.api.request.AlipayFundTransToaccountTransferRequest;
import com.alipay.api.request.AlipayFundTransUniTransferRequest;
import com.alipay.api.request.AlipayTradePagePayRequest;
import com.alipay.api.request.AlipayTradeQueryRequest;
import com.alipay.api.response.AlipayFundTransToaccountTransferResponse;
import com.alipay.api.response.AlipayFundTransUniTransferResponse;
import com.alipay.api.response.AlipayTradePagePayResponse;
import com.alipay.api.response.AlipayTradeQueryResponse;
import com.edgec.browserbackend.account.controller.AccountController;
import com.edgec.browserbackend.account.domain.*;
import com.edgec.browserbackend.account.exception.AccountErrorCode;
import com.edgec.browserbackend.account.repository.*;
import com.edgec.browserbackend.account.service.AccountService;
import com.edgec.browserbackend.account.service.PaymentService;
import com.edgec.browserbackend.account.controller.AccountController;
import com.edgec.browserbackend.account.domain.*;
import com.edgec.browserbackend.account.service.SmsUtils;
import com.edgec.browserbackend.account.service.UserPrePaidBillingService;
import com.edgec.browserbackend.alipay.AlipayConfig;
import com.edgec.browserbackend.alipay.CloudamAlipayConfig;
import com.edgec.browserbackend.alipay.VpsAlipayConfig;
......@@ -32,10 +29,8 @@ import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.stereotype.Service;
import javax.swing.text.Document;
import java.text.SimpleDateFormat;
import java.time.Instant;
import java.time.YearMonth;
......@@ -176,12 +171,12 @@ public class PaymentServiceImpl implements PaymentService {
if (chargeType == 0) {
UserPrePaidBilling bill = new UserPrePaidBilling();
Account account = accountRepository.findByName(byTradeNo.getUsername());
Account account = accountRepository.findByName(byTradeNo.getUsername()).orElseThrow(() -> new ClientRequestException(AccountErrorCode.NAMENOTEXIST));
if (account != null && account.getParent() != null)
bill.setAdministrator(account.getParent());
else
bill.setAdministrator(account.getName());
bill.setTradeNo(new SimpleDateFormat("yyyyMMddHHmmss").format(new Date())+ SmsUtils.createRandom(true, 4));
bill.setTradeNo(new SimpleDateFormat("yyyyMMddHHmmss").format(new Date()) + SmsUtils.createRandom(true, 4));
bill.setChargeType(0);
bill.setAmount(0);
bill.setUnit(null);
......@@ -308,12 +303,12 @@ public class PaymentServiceImpl implements PaymentService {
if (chargeType == 0) {
UserPrePaidBilling bill = new UserPrePaidBilling();
Account account = accountRepository.findByName(byTradeNo.getUsername());
Account account = accountRepository.findByName(byTradeNo.getUsername()).orElseThrow(() -> new ClientRequestException(AccountErrorCode.NAMENOTEXIST));
if (account != null && account.getParent() != null)
bill.setAdministrator(account.getParent());
else
bill.setAdministrator(account.getName());
bill.setTradeNo(new SimpleDateFormat("yyyyMMddHHmmss").format(new Date())+ SmsUtils.createRandom(true, 4));
bill.setTradeNo(new SimpleDateFormat("yyyyMMddHHmmss").format(new Date()) + SmsUtils.createRandom(true, 4));
bill.setChargeType(0);
bill.setAmount(0);
bill.setUnit(null);
......@@ -365,7 +360,7 @@ public class PaymentServiceImpl implements PaymentService {
public String alipayPutPayOrder(String username, int amount, String by) {
Account byName = accountService.findByName(username);
if (byName == null )
if (byName == null)
throw new ClientRequestException(AccountErrorCode.NAMENOTEXIST, "account does not exist: " + username);
if (byName.getPermission() < 4)
throw new ClientRequestException(AccountErrorCode.NOPERMISSION, "account does not have permission: " + username);
......@@ -483,12 +478,12 @@ public class PaymentServiceImpl implements PaymentService {
UserBalance userBalance = userBalanceRepository.findById(username).orElse(null);
UserPrePaidBilling bill = new UserPrePaidBilling();
Account account = accountRepository.findByName(username);
Account account = accountRepository.findByName(username).orElseThrow(() -> new ClientRequestException(AccountErrorCode.NAMENOTEXIST));
if (account != null && account.getParent() != null)
bill.setAdministrator(account.getParent());
else
bill.setAdministrator(account.getName());
bill.setTradeNo(new SimpleDateFormat("yyyyMMddHHmmss").format(new Date())+ SmsUtils.createRandom(true, 4));
bill.setTradeNo(new SimpleDateFormat("yyyyMMddHHmmss").format(new Date()) + SmsUtils.createRandom(true, 4));
bill.setChargeType(0);
bill.setAmount(0);
bill.setUnit(null);
......@@ -645,7 +640,7 @@ public class PaymentServiceImpl implements PaymentService {
if (response == null)
throw new ClientRequestException(BrowserErrorCode.UNKNOWN);
if(response.isSuccess()){
if (response.isSuccess()) {
internalOrder.setSucceed(true);
userWithdrawRepository.save(internalOrder);
......@@ -654,7 +649,7 @@ public class PaymentServiceImpl implements PaymentService {
bill.setAdministrator(byName.getParent());
else
bill.setAdministrator(byName.getName());
bill.setTradeNo(new SimpleDateFormat("yyyyMMddHHmmss").format(new Date())+ SmsUtils.createRandom(true, 4));
bill.setTradeNo(new SimpleDateFormat("yyyyMMddHHmmss").format(new Date()) + SmsUtils.createRandom(true, 4));
bill.setChargeType(4);
bill.setAmount(0);
bill.setUnit(null);
......@@ -675,7 +670,7 @@ public class PaymentServiceImpl implements PaymentService {
userPrePaidBillingRepository.save(bill);
return true;
}else{
} else {
byName.getPromotion().setAllGift(byName.getPromotion().getAllGift() + amount);
byName.getPromotion().setWithdrawn(byName.getPromotion().getWithdrawn() - amount);
accountRepository.save(byName);
......
......@@ -2,9 +2,11 @@ package com.edgec.browserbackend.account.service.impl;
import com.alibaba.fastjson.JSONObject;
import com.edgec.browserbackend.account.domain.*;
import com.edgec.browserbackend.account.exception.AccountErrorCode;
import com.edgec.browserbackend.account.repository.AccountRepository;
import com.edgec.browserbackend.account.repository.UserLackMoneyRepository;
import com.edgec.browserbackend.account.service.UserLackMoneyService;
import com.edgec.browserbackend.common.commons.error.ClientRequestException;
import com.edgec.browserbackend.common.commons.utils.SmsUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
......@@ -28,9 +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();
......@@ -45,7 +47,7 @@ public class UserLackMoneyServiceImpl implements UserLackMoneyService {
//发送短信提醒
if (totalUnpaid > 0 && ifMessageRemind) {
Account account = repository.findByName(username);
Account account = repository.findByName(username).orElseThrow(() -> new ClientRequestException(AccountErrorCode.NAMENOTEXIST));
String telephone = account.getPhoneNumber();
JSONObject param = new JSONObject();
param.put("billsamount", billsAmount);
......
......@@ -8,13 +8,16 @@ public class AccountServicePool {
private static final int POOL_COUNT = 10;
public static final ExecutorService taskPool = Executors.newFixedThreadPool(POOL_COUNT, new ThreadFactory() {
int count = 1;
public static final ExecutorService taskPool = Executors.newFixedThreadPool(
POOL_COUNT,
new ThreadFactory() {
int count = 1;
@Override
public Thread newThread(Runnable runnable) {
return new Thread(runnable, "account-service-pool" + count++);
}
});
@Override
public Thread newThread(Runnable runnable) {
return new Thread(runnable, "account-service-pool" + count++);
}
}
);
}
......@@ -27,7 +27,7 @@ public class OAuthResponseExceptionTranslator extends DefaultWebResponseExceptio
private ResponseEntity<OAuth2Exception> handleOAuth2Exception(OAuth2Exception e, AuthErrorCode error) throws IOException {
IntelligroupOauthException ex = new IntelligroupOauthException(error.getReason(), error.getReason(), error.getCode());
IntelligroupOauthException ex = new IntelligroupOauthException(error.getReason(), error.getReason(), error.getCode());
int status = e.getHttpErrorCode();
HttpHeaders headers = new HttpHeaders();
headers.set("Cache-Control", "no-store");
......@@ -36,8 +36,7 @@ public class OAuthResponseExceptionTranslator extends DefaultWebResponseExceptio
headers.set("WWW-Authenticate", String.format("%s %s", OAuth2AccessToken.BEARER_TYPE, e.getSummary()));
}
ResponseEntity<OAuth2Exception> response = new ResponseEntity<OAuth2Exception>(ex, headers,
HttpStatus.valueOf(status));
ResponseEntity<OAuth2Exception> response = new ResponseEntity<OAuth2Exception>(ex, headers, HttpStatus.valueOf(status));
return response;
}
......@@ -47,7 +46,7 @@ public class OAuthResponseExceptionTranslator extends DefaultWebResponseExceptio
// Try to extract a SpringSecurityException from the stacktrace
Throwable[] causeChain = throwableAnalyzer.determineCauseChain(e);
Exception ase = (AuthenticationException) throwableAnalyzer.getFirstThrowableOfType(AuthenticationException.class,
Exception ase = (AuthenticationException) throwableAnalyzer.getFirstThrowableOfType(AuthenticationException.class,
causeChain);
if (ase != null) {
AuthErrorCode code = AuthErrorCode.AUTHENTICATION_ERROR;
......
package com.edgec.browserbackend.auth.config;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.oauth2.config.annotation.web.configuration.EnableResourceServer;
......@@ -13,14 +9,12 @@ import org.springframework.security.oauth2.config.annotation.web.configuration.R
@EnableResourceServer
public class ResourceServerConfiguration extends ResourceServerConfigurerAdapter {
private Logger logger = LoggerFactory.getLogger(ResourceServerConfiguration.class);
@Override
public void configure(HttpSecurity http) throws Exception {
http
.authorizeRequests()
.antMatchers("/oauth/**").permitAll()
.antMatchers("/shop/**","/ip/**","/group/**","/0xadministrator/**","/user/**","/history/**").authenticated()
.antMatchers("/shop/**", "/ip/**", "/group/**", "/0xadministrator/**", "/user/**", "/history/**").authenticated()
.and()
//关闭跨站请求防护
.csrf().disable();
......
......@@ -16,6 +16,7 @@ import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.context.request.WebRequest;
import org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler;
@Deprecated
@ControllerAdvice
public class AuthErrorHandler extends ResponseEntityExceptionHandler {
......
package com.edgec.browserbackend.auth.domain.mongo;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import org.springframework.data.annotation.Id;
import org.springframework.data.annotation.PersistenceConstructor;
import org.springframework.data.mongodb.core.mapping.Document;
......@@ -8,6 +11,9 @@ import java.time.Instant;
import java.util.Arrays;
import java.util.Objects;
@NoArgsConstructor
@Getter
@Setter
@Document
public class MongoOAuth2AccessToken {
......@@ -21,8 +27,6 @@ public class MongoOAuth2AccessToken {
private String refreshToken;
private long createdAt;
public MongoOAuth2AccessToken() {
}
@PersistenceConstructor
public MongoOAuth2AccessToken(final String tokenId,
......@@ -42,33 +46,6 @@ public class MongoOAuth2AccessToken {
this.createdAt = Instant.now().toEpochMilli();
}
public String getTokenId() {
return tokenId;
}
public byte[] getToken() {
return token;
}
public String getAuthenticationId() {
return authenticationId;
}
public String getUsername() {
return username;
}
public String getClientId() {
return clientId;
}
public byte[] getAuthentication() {
return authentication;
}
public String getRefreshToken() {
return refreshToken;
}
@Override
public int hashCode() {
......@@ -100,11 +77,4 @@ public class MongoOAuth2AccessToken {
'}';
}
public long getCreatedAt() {
return createdAt;
}
public void setCreatedAt(long createdAt) {
this.createdAt = createdAt;
}
}
package com.edgec.browserbackend.auth.domain.mongo;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;
import org.apache.commons.lang3.builder.ToStringBuilder;
......@@ -9,6 +12,9 @@ import org.springframework.data.mongodb.core.mapping.Document;
import java.time.Instant;
@Getter
@Setter
@NoArgsConstructor
@Document
public class MongoOAuth2RefreshToken {
......@@ -18,8 +24,6 @@ public class MongoOAuth2RefreshToken {
private byte[] authentication;
private long createdAt;
public MongoOAuth2RefreshToken() {
}
@PersistenceConstructor
public MongoOAuth2RefreshToken(final String tokenId,
......@@ -31,18 +35,6 @@ public class MongoOAuth2RefreshToken {
this.createdAt = Instant.now().toEpochMilli();
}
public String getTokenId() {
return tokenId;
}
public byte[] getToken() {
return token;
}
public byte[] getAuthentication() {
return authentication;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
......@@ -75,12 +67,4 @@ public class MongoOAuth2RefreshToken {
.append("authentication", authentication)
.toString();
}
public long getCreatedAt() {
return createdAt;
}
public void setCreatedAt(long createdAt) {
this.createdAt = createdAt;
}
}
......@@ -27,6 +27,9 @@ public class IpControlloer {
@Autowired
private IpResourceService ipResourceService;
/**
* 购买IP资源
*/
@RequestMapping(value = "/buy", method = RequestMethod.POST)
public ResultDto buyIp(Principal principal, @RequestBody IpResourceRequestDto ipResourceRequestDto) {
ResultDto resultDto = new ResultDto();
......@@ -72,6 +75,9 @@ public class IpControlloer {
return resultDto;
}
/**
* 删除指定IP资源
*/
@RequestMapping(value = "/del", method = RequestMethod.POST)
public ResultDto deleteIp(Principal principal, @RequestBody IpResourceRequestDto ipResourceRequestDto) {
ResultDto resultDto = new ResultDto();
......
......@@ -34,7 +34,7 @@ public class ShopController {
@Autowired
private IpAndShopService ipAndShopService;
@RequestMapping(value = "/add", method = RequestMethod.POST)
@PostMapping("/add")
public ResultDto addShop(Principal principal, @RequestBody ShopResultDto shopResultDto) {
ResultDto resultDto = new ResultDto();
try {
......@@ -48,7 +48,7 @@ public class ShopController {
return resultDto;
}
@RequestMapping(value = "/multiadd", method = RequestMethod.POST)
@PostMapping("/multiadd")
public ResultDto addShops(Principal principal, @RequestParam("file") MultipartFile file) {
ResultDto resultDto = new ResultDto();
String name = file.getOriginalFilename();
......@@ -123,6 +123,9 @@ public class ShopController {
return resultDto;
}
/**
* 移动店铺 到 分组
*/
@RequestMapping(value = "/transfer", method = RequestMethod.POST)
public ResultDto transferShop(Principal principal, @RequestBody ShopRequestDto shopRequestDto) {
ResultDto resultDto = new ResultDto();
......
package com.edgec.browserbackend.browser.domain;
import java.io.Serializable;
import java.util.StringTokenizer;
import lombok.Data;
public class BindHistory {
@Data
public class BindHistory {
private String shopName;
private String ip;
private String platform;
private String unbindTime;
public BindHistory(){
}
public String getShopName() {
return shopName;
}
public void setShopName(String shopName) {
this.shopName = shopName;
}
public String getIp() {
return ip;
}
public void setPlatform(String platform) {
this.platform = platform;
}
public String getPlatform() {
return platform;
}
public void setIp(String ip) {
this.ip = ip;
}
public String getUnbindTime() {
return unbindTime;
}
public void setUnbindTime(String unbindTime) {
this.unbindTime = unbindTime;
}
}
package com.edgec.browserbackend.browser.domain;
import org.apache.commons.lang3.StringUtils;
import lombok.Getter;
import lombok.Setter;
import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.mapping.Document;
import org.springframework.util.StringUtils;
import java.util.List;
@Getter
@Setter
@Document(collection = "groups")
public class Group {
/**
* 组 id
*/
@Id
private String id;
/**
* 组名
*/
private String name;
/**
* 组创建者
*/
private String owner;
/**
* 组详情
*/
private String details;
public void of(Group group){
if (StringUtils.isNotBlank(group.getId()))
public void of(Group group) {
if (!StringUtils.isEmpty(group.getId())) {
this.setId(group.getId());
if (StringUtils.isNotBlank(group.getOwner()))
this.setOwner(group.getOwner());
if (StringUtils.isNotBlank(group.getDetails()))
this.setDetails(group.getDetails());
if (StringUtils.isNotBlank(group.getName()))
this.setName(group.getName());
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
}
public String getOwner() {
return owner;
}
public void setOwner(String owner) {
this.owner = owner;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
if (!StringUtils.isEmpty(group.getOwner())) {
this.setOwner(group.getOwner());
}
public String getDetails() {
return details;
}
if (!StringUtils.isEmpty(group.getDetails())) {
this.setDetails(group.getDetails());
}
public void setDetails(String details) {
this.details = details;
if (!StringUtils.isEmpty(group.getName())) {
this.setName(group.getName());
}
}
}
package com.edgec.browserbackend.browser.domain;
import lombok.Data;
import org.springframework.data.mongodb.core.mapping.Document;
@Data
@Document(collection = "ipcountrecord")
public class IpCountRecord {
private String username;
private long timestamp;
private long ip_using;
private long ip_all;
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public long getIp_all() {
return ip_all;
}
public void setIp_all(long ip_all) {
this.ip_all = ip_all;
}
public long getIp_using() {
return ip_using;
}
private String username;
public void setIp_using(long ip_using) {
this.ip_using = ip_using;
}
private long timestamp;
public long getTimestamp() {
return timestamp;
}
private long ip_using;
public void setTimestamp(long timestamp) {
this.timestamp = timestamp;
}
private long ip_all;
}
package com.edgec.browserbackend.browser.domain;
import lombok.Getter;
import lombok.Setter;
import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.mapping.Document;
......@@ -11,6 +13,9 @@ import java.util.Map;
* @Author jason
* @CreateTime 2020/3/12 10:30 上午
**/
@Getter
@Setter
@Document("ipOptions")
public class IpOptions {
......@@ -21,39 +26,9 @@ public class IpOptions {
private Map<String, List<String>> ipPlatForm;
private Map<String, Map<String, List<String>>> supportedPlatForm;
private Map<String, Map<String, List<String>>> supportedPlatForm;
private List<String> ipDurations;
public List<String> getIpDurations() {
return ipDurations;
}
public void setIpDurations(List<String> ipDurations) {
this.ipDurations = ipDurations;
}
public Map<String, List<String>> getIpPlatForm() {
return ipPlatForm;
}
public void setIpPlatForm(Map<String, List<String>> ipPlatForm) {
this.ipPlatForm = ipPlatForm;
}
public Map<String, List<String>> getIpRegion() {
return ipRegion;
}
public void setIpRegion(Map<String, List<String>> ipRegion) {
this.ipRegion = ipRegion;
}
public Map<String, Map<String, List<String>>> getSupportedPlatForm() {
return supportedPlatForm;
}
public void setSupportedPlatForm(Map<String, Map<String, List<String>>> supportedPlatForm) {
this.supportedPlatForm = supportedPlatForm;
}
}
package com.edgec.browserbackend.browser.domain;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.mapping.Document;
......@@ -9,6 +12,9 @@ import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
@Getter
@Setter
@NoArgsConstructor
@Document(collection = "ipresource")
@JsonIgnoreProperties(ignoreUnknown = true)
public class IpResource implements Serializable {
......@@ -53,270 +59,14 @@ public class IpResource implements Serializable {
private String unit;
private int period;
public IpResource() {
}
public String getDetails() {
return details;
}
public void setDetails(String details) {
this.details = details;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getRegion() {
return region;
}
public void setRegion(String region) {
this.region = region;
}
public String getRegionCn() {
return regionCn;
}
public void setRegionCn(String regionCn) {
this.regionCn = regionCn;
}
public int getStatus() {
return status;
}
public void setStatus(int status) {
this.status = status;
}
public IpType getIpType() {
return ipType;
}
public void setIpType(IpType ipType) {
this.ipType = ipType;
}
public List<BindHistory> getBindHistory() {
return bindHistory;
}
public void setBindHistory(List<BindHistory> bindHistory) {
this.bindHistory = bindHistory;
}
public long getPurchasedTime() {
return purchasedTime;
}
public void setPurchasedTime(long purchasedTime) {
this.purchasedTime = purchasedTime;
}
public long getValidTime() {
return validTime;
}
public void setValidTime(long validTime) {
this.validTime = validTime;
}
public Vendor getVendor() {
return vendor;
}
public void setVendor(Vendor vendor) {
this.vendor = vendor;
}
public boolean isDeleted() {
return isDeleted;
}
public void setDeleted(boolean deleted) {
isDeleted = deleted;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public List<String> getPort() {
return port;
}
public void setPort(List<String> port) {
this.port = port;
}
public String getAddr() {
return addr;
}
public void setAddr(String addr) {
this.addr = addr;
}
public String getUserParent() {
return userParent;
}
public void setUserParent(String userParent) {
this.userParent = userParent;
}
public List<String> getProtocol() {
return protocol;
}
public void setProtocol(List<String> protocol) {
this.protocol = protocol;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getOwner() {
return owner;
}
public void setOwner(String owner) {
this.owner = owner;
}
public boolean isLocked() {
return isLocked;
}
public void setLocked(boolean locked) {
isLocked = locked;
}
public long getLockTimestamp() {
return lockTimestamp;
}
public void setLockTimestamp(long lockTimestamp) {
this.lockTimestamp = lockTimestamp;
}
public String getUnit() {
return unit;
}
public void setUnit(String unit) {
this.unit = unit;
}
public int getPeriod() {
return period;
}
public void setPeriod(int period) {
this.period = period;
}
public double getPrice() {
return price;
}
public void setPrice(double price) {
this.price = price;
}
public List<String> getShopIds() {
return shopIds;
}
public void setShopIds(List<String> shopIds) {
this.shopIds = shopIds;
}
public String getVendorCn() {
return vendorCn;
}
public void setVendorCn(String vendorCn) {
this.vendorCn = vendorCn;
}
public String getProxyPassword() {
return proxyPassword;
}
public void setProxyPassword(String proxyPassword) {
this.proxyPassword = proxyPassword;
}
public String getProxyUsername() {
return proxyUsername;
}
public void setProxyUsername(String proxyUsername) {
this.proxyUsername = proxyUsername;
}
public boolean isSpecialLine() {
return specialLine;
}
public void setSpecialLine(boolean specialLine) {
this.specialLine = specialLine;
}
public long getHealthLockTimestamp() {
return healthLockTimestamp;
}
public void setHealthLockTimestamp(long healthLockTimestamp) {
this.healthLockTimestamp = healthLockTimestamp;
}
public boolean isUsingSpecialLine() {
return usingSpecialLine;
}
public void setUsingSpecialLine(boolean usingSpecialLine) {
this.usingSpecialLine = usingSpecialLine;
}
public boolean isBind() {
return bind;
}
public void setBind(boolean bind) {
this.bind = bind;
}
public String getShopId() {
return shopId;
}
public void setShopId(String shopId) {
this.shopId = shopId;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof IpResource)) return false;
if (this == o) {
return true;
}
if (!(o instanceof IpResource)) {
return false;
}
IpResource that = (IpResource) o;
return Objects.equals(getId(), that.getId());
}
......
package com.edgec.browserbackend.browser.domain;
public class IpSummary {
private int total;
private int unbind;
private int willExpire;
private int expired;
public int getExpired() {
return expired;
}
import lombok.Data;
public void setExpired(int expired) {
this.expired = expired;
}
public int getTotal() {
return total;
}
@Data
public class IpSummary {
public void setTotal(int total) {
this.total = total;
}
/**
* ip 总数
*/
private int total;
public int getUnbind() {
return unbind;
}
/**
* 未绑定 ip 数
*/
private int unbind;
public void setUnbind(int unbind) {
this.unbind = unbind;
}
/**
* 将要过期的 ip 数
*/
private int willExpire;
public int getWillExpire() {
return willExpire;
}
/**
* 已过期的 ip 数
*/
private int expired;
public void setWillExpire(int willExpire) {
this.willExpire = willExpire;
}
}
package com.edgec.browserbackend.browser.domain;
public enum IpType {
/**
* 本地ip,即 ip 地址没有设置任何代理
*/
LOCAL,
/**
* ip代理
*/
VENDOR,
/**
* 自有ip,即该ip不是从我们系统购买的
*/
OWN;
}
package com.edgec.browserbackend.browser.domain;
import com.edgec.browserbackend.browser.dto.OperationHistoryDto;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.mapping.Document;
......@@ -8,6 +11,9 @@ import java.time.LocalDateTime;
import java.time.ZoneOffset;
import java.time.format.DateTimeFormatter;
@Getter
@Setter
@NoArgsConstructor
@Document(collection = "operationhistory")
public class OperationHistory {
@Id
......@@ -20,89 +26,31 @@ public class OperationHistory {
private long operationTime;
private String administrator;
public OperationHistory() {
}
public OperationHistory(OperationHistoryDto operationHistoryDto) {
if (operationHistoryDto.getAccount() != null)
if (operationHistoryDto.getAccount() != null) {
this.username = operationHistoryDto.getAccount();
if (operationHistoryDto.getNickname() != null)
}
if (operationHistoryDto.getNickname() != null) {
this.nickname = operationHistoryDto.getNickname();
if (operationHistoryDto.getLoginIp() != null)
}
if (operationHistoryDto.getLoginIp() != null) {
this.loginIp = operationHistoryDto.getLoginIp();
if (operationHistoryDto.getLoginPlace() != null)
}
if (operationHistoryDto.getLoginPlace() != null) {
this.loginPlace = operationHistoryDto.getLoginPlace();
if (operationHistoryDto.getOperation() != null)
}
if (operationHistoryDto.getOperation() != null) {
this.operation = operationHistoryDto.getOperation();
}
if (operationHistoryDto.getOperationTime() != null) {
DateTimeFormatter format = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
LocalDateTime localDateTime = LocalDateTime.parse(operationHistoryDto.getOperationTime(), format);
this.operationTime = localDateTime.toInstant(ZoneOffset.UTC).toEpochMilli();
}
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public long getOperationTime() {
return operationTime;
}
public void setOperationTime(long operationTime) {
this.operationTime = operationTime;
}
public String getLoginIp() {
return loginIp;
}
public void setLoginIp(String loginIp) {
this.loginIp = loginIp;
}
public String getLoginPlace() {
return loginPlace;
}
public void setLoginPlace(String loginPlace) {
this.loginPlace = loginPlace;
}
public String getNickname() {
return nickname;
}
public void setNickname(String nickname) {
this.nickname = nickname;
}
public String getOperation() {
return operation;
}
public void setOperation(String operation) {
this.operation = operation;
}
public String getAdministrator() {
return administrator;
}
public void setAdministrator(String administrator) {
this.administrator = administrator;
}
}
package com.edgec.browserbackend.browser.domain;
import org.springframework.data.annotation.Id;
import lombok.Getter;
import lombok.Setter;
import org.springframework.data.mongodb.core.mapping.Document;
import java.util.List;
import java.util.Map;
/**
......@@ -11,26 +11,13 @@ import java.util.Map;
* @Author jason
* @CreateTime 2020/3/12 11:44 上午
**/
@Getter
@Setter
@Document("platformoptions")
public class PlatformOptions {
private String platform;
private Map<String, String> subPlatform;
public Map<String, String> getSubPlatform() {
return subPlatform;
}
public void setPlatform(String platform) {
this.platform = platform;
}
public String getPlatform() {
return platform;
}
public void setSubPlatform(Map<String, String> subPlatform) {
this.subPlatform = subPlatform;
}
}
package com.edgec.browserbackend.browser.domain;
import lombok.Getter;
import lombok.Setter;
import org.springframework.data.mongodb.core.mapping.Document;
@Getter
@Setter
@Document(collection = "proxyconfig")
public class ProxyConfig {
private long timestamp;
private String configFileId;
public long getTimestamp() {
return timestamp;
}
public void setConfigFileId(String configFileId) {
this.configFileId = configFileId;
}
public String getConfigFileId() {
return configFileId;
}
public void setTimestamp(long timestamp) {
this.timestamp = timestamp;
}
}
package com.edgec.browserbackend.browser.domain;
import com.alibaba.fastjson.JSONObject;
import com.edgec.browserbackend.browser.dto.ShopResultDto;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.mapping.Document;
@Getter
@Setter
@NoArgsConstructor
@Document(collection = "shop")
@JsonIgnoreProperties(ignoreUnknown = true)
public class Shop {
/**
* 商铺 id
*/
@Id
private String shopId;
/**
* 商铺名称
*/
private String shopName;
/**
* 商铺拥有者,谁创建谁拥有
*/
private String owner;
/**
* 商铺 id
*/
private TransferStatus transferStatus;
/**
* 商铺url
*/
private String shopUrl;
/**
* 商铺所在的平台
*/
private String shopPlatform;
/**
* 商铺账号
*/
private String shopAccount;
/**
* 商铺密码
*/
private String shopPassword;
/**
* 商铺平台(操作系统 + 浏览器版本)
*/
private String shopUA;
/**
* 商铺的 cookie 信息
*/
private String shopCookie;
/**
* 商铺创建时间
*/
private long createTime;
public Shop(){
/**
* 创建店铺使用
*/
public Shop of(ShopResultDto shopResultDto) {
if (shopResultDto.getShopUrl() != null) {
this.setShopUrl(shopResultDto.getShopUrl());
}
}
if (shopResultDto.getOwner() != null) {
this.setOwner(shopResultDto.getOwner());
}
if (shopResultDto.getShopPlatform() != null) {
this.setShopPlatform(shopResultDto.getShopPlatform());
}
if (shopResultDto.getShopName() != null) {
this.setShopName(shopResultDto.getShopName());
}
if (shopResultDto.getTransferStatus() != null) {
this.setTransferStatus(shopResultDto.getTransferStatus());
}
if (shopResultDto.getShopAccount() != null) {
this.setShopAccount(shopResultDto.getShopAccount());
}
if (shopResultDto.getShopPassword() != null) {
this.setShopPassword(shopResultDto.getShopPassword());
}
if (shopResultDto.getShopUA() != null) {
this.setShopUA(shopResultDto.getShopUA());
}
if (shopResultDto.getShopCookie() != null) {
this.setShopCookie(shopResultDto.getShopCookie());
}
if (shopResultDto.getCreateTime() != 0) {
this.setCreateTime(shopResultDto.getCreateTime());
}
//创建店铺使用
public Shop of(ShopResultDto shop) {
if (shop.getShopUrl() != null)
this.setShopUrl(shop.getShopUrl());
if (shop.getOwner() != null)
this.setOwner(shop.getOwner());
if (shop.getShopPlatform() != null)
this.setShopPlatform(shop.getShopPlatform());
if (shop.getShopName() != null)
this.setShopName(shop.getShopName());
if (shop.getTransferStatus() != null)
this.setTransferStatus(shop.getTransferStatus());
if (shop.getShopAccount() != null)
this.setShopAccount(shop.getShopAccount());
if (shop.getShopPassword() != null)
this.setShopPassword(shop.getShopPassword());
if (shop.getShopUA() != null)
this.setShopUA(shop.getShopUA());
if (shop.getShopCookie() != null)
this.setShopCookie(shop.getShopCookie());
if (shop.getCreateTime() != 0)
this.setCreateTime(shop.getCreateTime());
return this;
}
......@@ -83,95 +139,7 @@ public class Shop {
this.setShopCookie(shop.getShopCookie());
if (shop.getCreateTime() != 0)
this.setCreateTime(shop.getCreateTime());
return this;
}
public String getShopId() {
return shopId;
}
public String getShopUrl() {
return shopUrl;
}
public String getOwner() {
return owner;
}
public String getShopPlatform() {
return shopPlatform;
}
public String getShopName() {
return shopName;
}
public TransferStatus getTransferStatus() {
return transferStatus;
}
public void setShopId(String shopId) {
this.shopId = shopId;
}
public void setShopUrl(String shopUrl) {
this.shopUrl = shopUrl;
}
public void setOwner(String owner) {
this.owner = owner;
}
public void setShopPlatform(String shopPlatform) {
this.shopPlatform = shopPlatform;
}
public void setShopName(String shopName) {
this.shopName = shopName;
}
public void setTransferStatus(TransferStatus transferStatus) {
this.transferStatus = transferStatus;
}
public String getShopAccount() {
return shopAccount;
}
public void setShopAccount(String shopAccount) {
this.shopAccount = shopAccount;
}
public String getShopPassword() {
return shopPassword;
}
public void setShopPassword(String shopPassword) {
this.shopPassword = shopPassword;
}
public String getShopCookie() {
return shopCookie;
}
public void setShopCookie(String shopCookie) {
this.shopCookie = shopCookie;
}
public String getShopUA() {
return shopUA;
}
public void setShopUA(String shopUA) {
this.shopUA = shopUA;
}
public long getCreateTime() {
return createTime;
}
public void setCreateTime(long createTime) {
this.createTime = createTime;
return this;
}
}
package com.edgec.browserbackend.browser.domain;
public class ShopSummary {
private int total;
private int unbind;
private int willExpire;
private int expired;
public int getExpired() {
return expired;
}
public void setExpired(int expired) {
this.expired = expired;
}
import lombok.Getter;
import lombok.Setter;
public int getTotal() {
return total;
}
public void setTotal(int total) {
this.total = total;
}
@Getter
@Setter
public class ShopSummary {
public int getUnbind() {
return unbind;
}
/**
* 商铺 总数
*/
private int total;
public void setUnbind(int unbind) {
this.unbind = unbind;
}
/**
* 未绑定商铺数
*/
private int unbind;
public int getWillExpire() {
return willExpire;
}
/**
* 即将过期商铺数
*/
private int willExpire;
public void setWillExpire(int willExpire) {
this.willExpire = willExpire;
}
/**
* 已过期商铺数
*/
private int expired;
}
package com.edgec.browserbackend.browser.domain;
import lombok.Getter;
import lombok.Setter;
import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.mapping.Document;
import java.util.List;
@Getter
@Setter
@Document("specialline")
public class SpecialLine {
/**
* 专线 id
*/
@Id
private String Id;
/**
* 专线 ip
*/
private String ip;
private List<String> proxyProtocol; //专线使用的协议
private List<String> proxyPort; //专线使用的端口
private String username; //专线代理服务器用户名
private String password; //专线代理服务器密码
public String getIp() {
return ip;
}
public void setIp(String ip) {
this.ip = ip;
}
public String getId() {
return Id;
}
public void setId(String id) {
Id = id;
}
public List<String> getProxyProtocol() {
return proxyProtocol;
}
public void setProxyProtocol(List<String> proxyProtocol) {
this.proxyProtocol = proxyProtocol;
}
public List<String> getProxyPort() {
return proxyPort;
}
public void setProxyPort(List<String> proxyPort) {
this.proxyPort = proxyPort;
}
/**
* 专线使用的协议
*/
private List<String> proxyProtocol;
public String getPassword() {
return password;
}
/**
* 专线使用的端口
*/
private List<String> proxyPort;
public void setPassword(String password) {
this.password = password;
}
/**
* 专线代理服务器用户名
*/
private String username;
public String getUsername() {
return username;
}
/**
* 专线代理服务器密码
*/
private String password;
public void setUsername(String username) {
this.username = username;
}
}
package com.edgec.browserbackend.browser.domain;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.mapping.Document;
import java.util.List;
/**
* @author cloudam
* 这是一个中间表,关联 user 、shop、 group 表
*/
@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
@Document(collection = "usershop")
public class UserShop {
......@@ -17,56 +27,13 @@ public class UserShop {
private String groupId;
public UserShop(){
}
public UserShop(String username, String shopId) {
this.username = username;
this.shopId = shopId;
}
public UserShop(String username, String shopId, String groupId) {
this.username = username;
this.shopId = shopId;
this.groupId = groupId;
}
public UserShop(String username, String shopId, String groupId, String ipId) {
this.username = username;
this.shopId = shopId;
this.groupId = groupId;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getShopId() {
return shopId;
}
public void setShopId(String shopId) {
this.shopId = shopId;
}
public String getGroupId() {
return groupId;
}
public void setGroupId(String groupId) {
this(username, shopId);
this.groupId = groupId;
}
}
......@@ -4,13 +4,31 @@ package com.edgec.browserbackend.browser.domain;
* @Desc
* @Author jason
* @CreateTime 2020/3/12 4:01 下午
**/
*/
public enum Vendor {
aliyun("阿里云"), JDCLOUD("京东云"), aws("亚马逊云"), awscn("亚马逊中国"), tencent("腾讯云"), local("本地"), own("自有");
/**
* 本平台提供的代理ip
*/
aliyun("阿里云"),
JDCLOUD("京东云"),
aws("亚马逊云"),
awscn("亚马逊中国"),
tencent("腾讯云"),
/**
* 本地ip,即 ip 地址没有设置任何代理
*/
local("本地"),
/**
* 用户自己已经拥有的代理ip
*/
own("自有");
private String value;
private Vendor(String value) {
Vendor(String value) {
this.value = value;
}
......
package com.edgec.browserbackend.browser.dto;
import lombok.Getter;
import lombok.Setter;
import org.apache.commons.lang3.StringUtils;
@Getter
@Setter
public class IpFilterDto {
String region;
String addr;
String vendor;
public String getAddr() {
return addr;
}
public void setAddr(String addr) {
this.addr = addr;
}
public String getRegion() {
return region;
}
public void setRegion(String region) {
this.region = region;
}
public String getVendor() {
return vendor;
}
public void setVendor(String vendor) {
this.vendor = vendor;
public boolean isEmpty() {
boolean flag = false;
if (StringUtils.isEmpty(region) && StringUtils.isEmpty(addr) && StringUtils.isEmpty(vendor)) {
flag = true;
}
return flag;
}
}
......@@ -2,12 +2,14 @@ package com.edgec.browserbackend.browser.dto;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import java.util.ArrayList;
import java.util.List;
@JsonIgnoreProperties(ignoreUnknown = true)
public class IpListRequestDto {
/**
* 1: 全部;  2: 即将过期 ; 3: 已过期; 4: 未绑定; 5: 已分配
*/
private int groupType;
private int page;
private int amount;
private IpFilterDto filter;
......
package com.edgec.browserbackend.browser.dto;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
@Data
@NoArgsConstructor
@AllArgsConstructor
public class PageInfo {
int currentPage;
int totalPages;
int totalItems;
public int getCurrentPage() {
return currentPage;
}
public void setCurrentPage(int currentPage) {
this.currentPage = currentPage;
}
public int getTotalPages() {
return totalPages;
}
public void setTotalPages(int totalPage) {
this.totalPages = totalPage;
}
public int getTotalItems() {
return totalItems;
}
public void setTotalItems(int totalItems) {
this.totalItems = totalItems;
}
}
package com.edgec.browserbackend.browser.dto;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import lombok.Getter;
import lombok.Setter;
import org.apache.commons.lang3.StringUtils;
@Getter
@Setter
@JsonIgnoreProperties(ignoreUnknown = true)
public class ShopFilterDto {
private String shopName;
......@@ -9,35 +14,11 @@ public class ShopFilterDto {
private String shopAccount;
private int bindIp;
public String getShopAccount() {
return shopAccount;
}
public void setShopAccount(String shopAccount) {
this.shopAccount = shopAccount;
}
public String getIpRegion() {
return IpRegion;
}
public void setIpRegion(String ipRegion) {
IpRegion = ipRegion;
}
public String getShopName() {
return shopName;
}
public void setShopName(String shopName) {
this.shopName = shopName;
}
public int getBindIp() {
return bindIp;
}
public void setBindIp(int bindIp) {
this.bindIp = bindIp;
public boolean isEmpty() {
boolean flag = false;
if (StringUtils.isEmpty(shopName) && StringUtils.isEmpty(IpRegion) && StringUtils.isEmpty(shopAccount)) {
flag = true;
}
return flag;
}
}
package com.edgec.browserbackend.browser.dto;
import lombok.Data;
@Data
public class ShopStringResultDto {
String id;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
}
......@@ -58,35 +58,12 @@ public class IpResourceRepositoryCustomImpl implements IpResourceRepositoryCusto
@Override
public boolean healthLock(IpResource ipResource) {
Document doc = new Document();
BasicQuery basicQuery = new BasicQuery(doc);
Criteria criteria = new Criteria();
criteria.orOperator(where("id").is(ipResource.getId()).and("isLocked").is(false).and("status").is(ipResource.getStatus()).and("isDeleted").is(false),
where("healthLockTimestamp").lte(Instant.now().minusSeconds(300).toEpochMilli()).and("status").is(ipResource.getStatus()).and("isDeleted").is(false));
basicQuery.addCriteria(criteria);
Update update = new Update();
update.set("isLocked", true).set("healthLockTimestamp", Instant.now().toEpochMilli());
UpdateResult result = mongoTemplate.updateFirst(basicQuery, update, IpResource.class);
if (result.getModifiedCount() < 1)
return false;
else
return true;
return true;
}
@Override
public boolean unLockHealth(String id) {
Document doc = new Document();
BasicQuery basicQuery = new BasicQuery(doc);
basicQuery.addCriteria(where("id").is(id));
Update update = new Update();
update.set("isLocked", false).set("healthLockTimestamp", Instant.now().toEpochMilli());
UpdateResult result = mongoTemplate.updateFirst(basicQuery, update, IpResource.class);
if (result.getModifiedCount() < 1)
return false;
else
return true;
return true;
}
@Override
......@@ -112,7 +89,7 @@ public class IpResourceRepositoryCustomImpl implements IpResourceRepositoryCusto
MatchOperation match = Aggregation.match(matchCriteria);
SampleOperation sample = Aggregation.sample(100);
SampleOperation sample = Aggregation.sample(20);
AggregationResults<IpResource> results = mongoTemplate.aggregate(Aggregation.newAggregation(match, sample), IpResource.class, IpResource.class);
List<IpResource> mappedResults = results.getMappedResults();
......@@ -136,10 +113,10 @@ public class IpResourceRepositoryCustomImpl implements IpResourceRepositoryCusto
}
@Override
public boolean deleteShopId(String ipId, String shopId, BindHistory bindHistory) {
public boolean deleteShopId(String id, String shopId, BindHistory bindHistory) {
Document doc = new Document();
BasicQuery basicQuery = new BasicQuery(doc);
basicQuery.addCriteria(where("id").is(ipId).and("isDeleted").is(false));
basicQuery.addCriteria(where("id").is(id).and("isDeleted").is(false));
Update update = new Update();
update.pull("shopIds", shopId).push("bindhistory", bindHistory);
UpdateResult result = mongoTemplate.updateFirst(basicQuery, update, IpResource.class);
......@@ -186,18 +163,23 @@ public class IpResourceRepositoryCustomImpl implements IpResourceRepositoryCusto
UnwindOperation unwind = Aggregation.unwind("shopIds");
MatchOperation matchshopId = Aggregation.match(where("shopIds").in(shopIds));
List<IpResourceUnwindResultDto> ipResourceUnwindResultDtos = mongoTemplate.aggregate(
Aggregation.newAggregation(matchOperation, unwind, matchshopId), IpResource.class, IpResourceUnwindResultDto.class).getMappedResults();
Aggregation.newAggregation(matchOperation, unwind, matchshopId), IpResource.class, IpResourceUnwindResultDto.class
).getMappedResults();
if (ipResourceUnwindResultDtos.isEmpty()) {
return new ArrayList<>();
}
HashMap<String, IpResource> ipResourceHashMap = new HashMap<>();
ipResourceUnwindResultDtos.forEach(x -> {
if (ipResourceHashMap.containsKey(x.getId())) {
ipResourceHashMap.get(x.getId()).getShopIds().add(x.getShopId());
} else {
ipResourceHashMap.put(x.getId(), x.toResource());
}
});
ipResourceUnwindResultDtos.forEach(
x -> {
if (ipResourceHashMap.containsKey(x.getId())) {
ipResourceHashMap.get(x.getId()).getShopIds().add(x.getShopId());
} else {
ipResourceHashMap.put(x.getId(), x.toResource());
}
}
);
List<IpResource> result = new ArrayList<>();
Set<Map.Entry<String, IpResource>> entry = ipResourceHashMap.entrySet();
for (Map.Entry<String, IpResource> e : entry) {
......
......@@ -37,7 +37,7 @@ public class GroupServiceImpl implements GroupService {
public String addGroup(String username, String groupName) {
if (StringUtils.isBlank(username) || StringUtils.isBlank(groupName))
throw new ClientRequestException(BrowserErrorCode.INFORMATIONNOTCOMPELETE);
Account account = accountRepository.findByName(username);
Account account = accountRepository.findByName(username).orElseThrow(() -> new ClientRequestException(AccountErrorCode.NAMENOTEXIST));
if (account == null)
throw new ClientRequestException(AccountErrorCode.NAMENOTEXIST);
if (account.getGroupCount() >= 100)
......@@ -79,14 +79,14 @@ public class GroupServiceImpl implements GroupService {
public void deleteGroup(String username, String groupId) {
if (StringUtils.isBlank(username) || StringUtils.isBlank(groupId))
throw new ClientRequestException(BrowserErrorCode.INFORMATIONNOTCOMPELETE);
Account account = accountRepository.findByName(username);
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);
//可以优化
account.setGroupCount(account.getGroupCount()-1);
account.setGroupCount(account.getGroupCount() - 1);
accountRepository.save(account);
} catch (Exception e) {
logger.error("fail to delete group", e.getMessage());
......@@ -106,7 +106,7 @@ public class GroupServiceImpl implements GroupService {
groups.stream().forEach(x -> {
groupDtos.add(new GroupDto(x.getId(), x.getName(), x.getDetails()));
});
} catch (Exception e){
} catch (Exception e) {
logger.error("fail to delete group", e.getMessage());
throw new ClientRequestException(BrowserErrorCode.UNKNOWN);
}
......
......@@ -44,10 +44,7 @@ public class IpAndShopServiceImpl implements IpAndShopService {
@Override
public void bindShop(String username, ShopRequestDto shopRequestDto) {
// 1. 根据id 来获取账户
Account account = accountRepository.findByName(username);
if (account == null) {
throw new ClientRequestException(AccountErrorCode.NAMENOTEXIST);
}
Account account = accountRepository.findByName(username).orElseThrow(() -> new ClientRequestException(AccountErrorCode.NAMENOTEXIST));
String shopId = shopRequestDto.getShopId();
// 2.获取当前账户下指定的商铺
......@@ -62,10 +59,10 @@ public class IpAndShopServiceImpl implements IpAndShopService {
IpResource ipResource = null;
if (StringUtils.isNotBlank(shopRequestDto.getIpAddr())) {
ipResource = ipResourceRepository.findByAddrAndIsDeleted(shopRequestDto.getIpAddr(), false);
} else if (StringUtils.isNotBlank(shopRequestDto.getIpId())) {
}
if (StringUtils.isNotBlank(shopRequestDto.getIpId())) {
ipResource = ipResourceRepository.findByIdAndIsDeleted(shopRequestDto.getIpId(), false);
}
if (ipResource == null) {
throw new ClientRequestException(BrowserErrorCode.IPNOTEXIST);
}
......@@ -87,40 +84,56 @@ public class IpAndShopServiceImpl implements IpAndShopService {
@Override
public void unBindShop(String username, ShopRequestDto shopRequestDto) {
String shopId = null;
if (StringUtils.isNotBlank(shopRequestDto.getShopId()))
shopId = shopRequestDto.getShopId();
Account account = accountRepository.findByName(username);
if (account == null) {
throw new ClientRequestException(AccountErrorCode.NAMENOTEXIST);
}
UserShop userShop = userShopRepository.findByUsernameAndShopId(username, shopId);
if (account.getPermission() < 4 || userShop == null) {
// 1. 检查当前账户是否存在,是否具备操作权限
Account account = accountRepository.findByName(username).orElseThrow(() -> new ClientRequestException(AccountErrorCode.NAMENOTEXIST));
if (account.getPermission() < 4) {
throw new ClientRequestException(AccountErrorCode.NOPERMISSION);
}
Shop shop = shopRepository.findById(shopId).orElse(null);
if (shop == null)
String shopId = shopRequestDto.getShopId();
// 2. 查找当前用户是否已经绑定商铺 以及 关联商铺的绑定 (一个商铺可以被多个用户持有)
UserShop userShop = userShopRepository.findByUsernameAndShopId(username, shopId);
if (userShop == null) {
throw new ClientRequestException(BrowserErrorCode.SHOPNOTEXIST);
}
// 3. 查找商铺信息
Shop shop = shopRepository.findById(shopId).orElseThrow(() -> new ClientRequestException(BrowserErrorCode.SHOPNOTEXIST));
// 4. 查找当前商铺绑定的 ip 资源是否存在
IpResource ipResource = null;
if (StringUtils.isNotBlank(shopRequestDto.getIpAddr())) {
ipResource = ipResourceRepository.findByAddrAndIsDeleted(shopRequestDto.getIpAddr(), false);
} else if (StringUtils.isNotBlank(shopRequestDto.getIpId())) {
}
if (StringUtils.isNotBlank(shopRequestDto.getIpId())) {
ipResource = ipResourceRepository.findByIdAndIsDeleted(shopRequestDto.getIpId(), false);
}
if (ipResource == null)
if (ipResource == null) {
throw new ClientRequestException(BrowserErrorCode.IPNOTEXIST);
if (ipResource.getShopIds() == null && !ipResource.getShopIds().contains(shop.getShopId()))
}
// 5. 若存在,ip资源是否绑定了该店铺(一个ip资源可以被多个店铺绑定)
if (ipResource.getShopIds() == null && !ipResource.getShopIds().contains(shop.getShopId())) {
throw new ClientRequestException(BrowserErrorCode.IPNOTBINDTOSHOP);
}
// 封装 ip 资源绑定的历史信息
BindHistory bindHistory = new BindHistory();
bindHistory.setIp(ipResource.getAddr());
bindHistory.setPlatform(shop.getShopPlatform());
bindHistory.setShopName(shop.getShopName());
bindHistory.setUnbindTime(ZonedDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
try {
BindHistory bindHistory = new BindHistory();
bindHistory.setIp(ipResource.getAddr());
bindHistory.setPlatform(shop.getShopPlatform());
bindHistory.setShopName(shop.getShopName());
bindHistory.setUnbindTime(ZonedDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
// 6. IP资源解除绑定的店铺并更新ip资源的绑定历史
ipResourceRepository.deleteShopId(ipResource.getId(), shopId, bindHistory);
// 7. 更新 ip 资源的绑定状态为 未绑定
IpResource newIp = ipResourceRepository.findById(ipResource.getId()).orElse(null);
if (newIp.getShopIds() == null || newIp.getShopIds().size() == 0)
if (newIp.getShopIds() == null || !newIp.getShopIds().contains(shopId)) {
ipResourceRepository.updateBind(ipResource.getId(), false);
}
} catch (Exception e) {
logger.error("fail to unbind", e.getMessage());
throw new ClientRequestException(BrowserErrorCode.UNKNOWN);
......@@ -132,10 +145,8 @@ public class IpAndShopServiceImpl implements IpAndShopService {
List<String> shopIds = null;
if (shopRequestDto.getShopIds() != null && shopRequestDto.getShopIds().size() > 0)
shopIds = shopRequestDto.getShopIds();
Account account = accountRepository.findByName(username);
if (account == null) {
throw new ClientRequestException(AccountErrorCode.NAMENOTEXIST);
}
Account account = accountRepository.findByName(username).orElseThrow(() -> new ClientRequestException(AccountErrorCode.NAMENOTEXIST));
IpResource ipResource = null;
if (StringUtils.isNotBlank(shopRequestDto.getIpAddr())) {
ipResource = ipResourceRepository.findByAddrAndIsDeleted(shopRequestDto.getIpAddr(), false);
......
......@@ -2,9 +2,11 @@ package com.edgec.browserbackend.browser.task;
import com.alibaba.fastjson.JSONObject;
import com.edgec.browserbackend.account.domain.Account;
import com.edgec.browserbackend.account.exception.AccountErrorCode;
import com.edgec.browserbackend.account.repository.AccountRepository;
import com.edgec.browserbackend.browser.domain.IpResource;
import com.edgec.browserbackend.browser.repository.IpResourceRepository;
import com.edgec.browserbackend.common.commons.error.ClientRequestException;
import com.edgec.browserbackend.common.commons.utils.SmsUtils;
import net.javacrumbs.shedlock.core.SchedulerLock;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -56,7 +58,7 @@ public class ExpireSoonWarn {
}
private void sendToAccount(String username, int day, int amount, List<String> ips) {
Account account = accountRepository.findByName(username);
Account account = accountRepository.findByName(username).orElseThrow(() -> new ClientRequestException(AccountErrorCode.NAMENOTEXIST));
JSONObject param = new JSONObject();
param.put("day", day);
param.put("amount", amount);
......
......@@ -29,7 +29,7 @@ public class PaymentTask {
@Scheduled(fixedDelay = 60000)
public void checkPayments() {
long now = new Date().getTime();
long now = System.currentTimeMillis();
Date date_5min = new Date(now - 5 * 60 * 1000);
Date date_10min = new Date(now - 10 * 60 * 1000);
List<UserPayment> unfinishedPayments = userPaymentRepository.findAllByPaymentDateBetweenAndSucceed(
......
package com.edgec.browserbackend.common.commons.kafka;
@Deprecated
public final class KafkaUtils {
public static final String TOPIC_NAME_C3_MINIONS = "tp.minions.c3";
public static final String CONSUMER_GROUP_C3_MINIONS = "cg.minions.c3";
public static final TopicDef TOPIC_C3_MINIONS = new TopicDef(TOPIC_NAME_C3_MINIONS, 12, 2);
public static final TopicDef TOPIC_C3_MINIONS = new TopicDef(TOPIC_NAME_C3_MINIONS, 12, 2);
public static class TopicDef {
......
package com.edgec.browserbackend.common.commons.utils;
@Deprecated
public class CommonStringUtils {
public static int getLongestCommonSubstring(String a, String b) {
......@@ -10,16 +11,16 @@ public class CommonStringUtils {
int[][] dp = new int[m][n];
for(int i=0; i<m; i++){
for(int j=0; j<n; j++){
if(a.charAt(i) == b.charAt(j)){
if(i==0 || j==0){
dp[i][j]=1;
}else{
dp[i][j] = dp[i-1][j-1]+1;
for (int i = 0; i < m; i++) {
for (int j = 0; j < n; j++) {
if (a.charAt(i) == b.charAt(j)) {
if (i == 0 || j == 0) {
dp[i][j] = 1;
} else {
dp[i][j] = dp[i - 1][j - 1] + 1;
}
if(max < dp[i][j])
if (max < dp[i][j])
max = dp[i][j];
}
......
package com.edgec.browserbackend.common.commons.utils;
@Deprecated
public final class Pair<S, T> {
private S first;
......
......@@ -3,6 +3,7 @@ package com.edgec.browserbackend.common.commons.utils;
import java.util.Comparator;
import java.util.concurrent.*;
@Deprecated
public class PriorityThreadPoolExecutor extends ThreadPoolExecutor {
private Comparator comparator;
......
......@@ -9,16 +9,23 @@ import java.io.*;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
@Deprecated
public class RemoteShellExecutor {
private Logger logger = LoggerFactory.getLogger(RemoteShellExecutor.class);
private Connection conn;
/** 远程机器IP */
/**
* 远程机器IP
*/
private String ip;
/** 用户名 */
/**
* 用户名
*/
private String osUsername;
/** 密码 */
/**
* 密码
*/
private String password;
private String charset = Charset.defaultCharset().toString();
......@@ -33,6 +40,7 @@ public class RemoteShellExecutor {
/**
* 登录
*
* @return
* @throws IOException
*/
......@@ -182,18 +190,16 @@ public class RemoteShellExecutor {
// 6. 关闭输入流
out.close();
// 7. 等待,除非1.连接关闭;2.输出数据传送完毕;3.进程状态为退出;4.超时
session.waitForCondition(ChannelCondition.CLOSED | ChannelCondition.EOF | ChannelCondition.EXIT_STATUS , 30000);
session.waitForCondition(ChannelCondition.CLOSED | ChannelCondition.EOF | ChannelCondition.EXIT_STATUS, 30000);
logger.error("Here is the output from stdout:");
while (true)
{
while (true) {
String line = stdoutReader.readLine();
if (line == null)
break;
System.out.println(line);
}
logger.error("Here is the output from stderr:");
while (true)
{
while (true) {
String line = stderrReader.readLine();
if (line == null)
break;
......@@ -253,18 +259,16 @@ public class RemoteShellExecutor {
scpOutputStream.flush();
scpOutputStream.close();
session.waitForCondition(ChannelCondition.CLOSED | ChannelCondition.EOF | ChannelCondition.EXIT_STATUS , 30000);
session.waitForCondition(ChannelCondition.CLOSED | ChannelCondition.EOF | ChannelCondition.EXIT_STATUS, 30000);
logger.error("Here is the output from stdout:");
while (true)
{
while (true) {
String line = stdoutReader.readLine();
if (line == null)
break;
System.out.println(line);
}
logger.error("Here is the output from stderr:");
while (true)
{
while (true) {
String line = stderrReader.readLine();
if (line == null)
break;
......@@ -278,7 +282,7 @@ public class RemoteShellExecutor {
} catch (IOException e) {
logger.error(e.getMessage());
throw new Exception("登录远程机器失败" + ip);
}finally {
} finally {
if (conn != null) {
conn.close();
}
......
......@@ -10,6 +10,7 @@ import java.time.ZonedDateTime;
import java.time.temporal.ChronoUnit;
import java.util.Iterator;
@Deprecated
public class TimestampUtils {
......
......@@ -2,6 +2,7 @@ package com.edgec.browserbackend.common.commons.utils;
import java.util.UUID;
@Deprecated
public class UUIDGenerator {
public static String gen(Boolean withoutDashes) {
return withoutDashes ? UUID.randomUUID().toString().replace("-", "")
......
package com.edgec.browserbackend.common.constant;
@Deprecated
public interface InstanceStatus {
String STOPPING = "Stopping";
......
......@@ -5,51 +5,31 @@ import java.lang.reflect.Modifier;
import java.util.HashSet;
import java.util.Set;
@Deprecated
public class SpecialUsers {
public static final Set<String> CLOUDAM_USERS = new HashSet<>();
public static final String VPS_CLOUD_ACCOUNT_NAME = "vpsclient";
public static final String CVM_CLOUD_ACCOUNT_NAME = "cvmclient";
public static final String C3_ECC_ACCOUNT_NAME = "eccclient"; // 电商云集群
public static final String C3_IP_ACCOUNT_NAME = "c3ipclient"; //c3 ip云
public static final String SUPERBROWSER = "superbrowser";
public static final String ECOMMERCEBROWSER = "ecommercebrowser";
public static final String JKBROWSER = "jkbrowser";
/**
* 电商云集群
*/
public static final String C3_ECC_ACCOUNT_NAME = "eccclient";
/**
* c3 ip云
*/
public static final String C3_IP_ACCOUNT_NAME = "c3ipclient";
public static final String SUPER_BROWSER = "superbrowser";
public static final String ECOMMERCE_BROWSER = "ecommercebrowser";
//新增用户名写在上边
public static void main(String[] args) {
for (String cloudamUser : CLOUDAM_USERS) {
System.out.println(cloudamUser);
}
}
public static final String JK_BROWSER = "jkbrowser";
static {
Field[] fields = SpecialUsers.class.getFields();
......@@ -69,5 +49,4 @@ public class SpecialUsers {
}
}
}
package com.edgec.browserbackend.common.dto;
import lombok.Data;
@Deprecated
@Data
public class BaseResponse<T> {
private String requestId;
......@@ -7,38 +11,4 @@ public class BaseResponse<T> {
private String message;
private T data;
public String getRequestId() {
return requestId;
}
public void setRequestId(String requestId) {
this.requestId = requestId;
}
public Result getResult() {
return result;
}
public void setResult(Result result) {
this.result = result;
}
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
public T getData() {
return data;
}
public void setData(T data) {
this.data = data;
}
}
package com.edgec.browserbackend.common.dto;
@Deprecated
public enum Result {
SUCCESS,
......
......@@ -2,6 +2,7 @@ package com.edgec.browserbackend.common.utils;
import java.time.Instant;
@Deprecated
public class PollerUtils {
public static void poll(int timeoutInSeconds, int intervalInSeconds, Evaluator evaluator) {
......@@ -12,7 +13,7 @@ public class PollerUtils {
while (!result) {
long end = Instant.now().toEpochMilli();
if((end - start) > timeoutInSeconds * 1000)
if ((end - start) > timeoutInSeconds * 1000)
return;
try {
Thread.sleep(intervalInSeconds * 1000);
......
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