Commit e90964d0 authored by xuxin's avatar xuxin

浏览器bug修复

parent 7d5c94f5
package com.edgec.browserbackend; package com.edgec.browserbackend;
import com.mongodb.MongoClient;
import net.javacrumbs.shedlock.core.LockProvider;
import org.apache.catalina.Context;
import org.apache.catalina.connector.Connector;
import org.springframework.beans.factory.SmartInitializingSingleton;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.SpringApplication; import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory;
import org.springframework.boot.web.servlet.server.ServletWebServerFactory;
import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.core.convert.converter.Converter; import org.springframework.core.convert.converter.Converter;
import org.springframework.data.convert.Jsr310Converters; import org.springframework.data.convert.Jsr310Converters;
import org.springframework.data.mongodb.core.convert.MongoCustomConversions; import org.springframework.data.mongodb.core.convert.MongoCustomConversions;
import org.springframework.scheduling.TaskScheduler;
import org.springframework.scheduling.annotation.EnableScheduling; import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;
import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity; import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
import org.springframework.security.oauth2.config.annotation.web.configuration.EnableAuthorizationServer;
import org.springframework.security.oauth2.provider.token.AuthenticationKeyGenerator; import org.springframework.security.oauth2.provider.token.AuthenticationKeyGenerator;
import org.springframework.security.oauth2.provider.token.DefaultAuthenticationKeyGenerator; import org.springframework.security.oauth2.provider.token.DefaultAuthenticationKeyGenerator;
import org.springframework.web.cors.CorsConfiguration; import org.springframework.web.cors.CorsConfiguration;
...@@ -35,10 +24,8 @@ import java.time.LocalDate; ...@@ -35,10 +24,8 @@ import java.time.LocalDate;
import java.time.ZoneId; import java.time.ZoneId;
import java.time.ZonedDateTime; import java.time.ZonedDateTime;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
import java.util.concurrent.CompletableFuture;
@SpringBootApplication @SpringBootApplication
@EnableGlobalMethodSecurity(prePostEnabled = true) @EnableGlobalMethodSecurity(prePostEnabled = true)
......
...@@ -33,7 +33,7 @@ import java.time.format.DateTimeFormatter; ...@@ -33,7 +33,7 @@ import java.time.format.DateTimeFormatter;
import java.util.*; import java.util.*;
@RestController @RestController
@RequestMapping("user") @RequestMapping("/user")
public class AccountController { public class AccountController {
public static final String WECHAT_PAY_CALLBACK_URL = "https://cloudam.cn/accounts/0xwxpaycallback/"; public static final String WECHAT_PAY_CALLBACK_URL = "https://cloudam.cn/accounts/0xwxpaycallback/";
......
...@@ -7,37 +7,37 @@ public enum AccountErrorCode implements ErrorCode { ...@@ -7,37 +7,37 @@ public enum AccountErrorCode implements ErrorCode {
/* client errors */ /* client errors */
UNKNOWN(ErrorCode.COMMON_UNKNOWN,"unknown"), UNKNOWN(ErrorCode.COMMON_UNKNOWN, "unknown"),
NAMEEXIST(ACCOUNT_BASE+100, "Username exists"), NAMEEXIST(ACCOUNT_BASE + 100, "Username exists"),
NAMENOTEXIST(ACCOUNT_BASE+102, "Username does not exist"), NAMENOTEXIST(ACCOUNT_BASE + 102, "Username does not exist"),
EMAILEXIST(ACCOUNT_BASE+101, "Email exists"), EMAILEXIST(ACCOUNT_BASE + 101, "Email exists"),
EMAILNOTEXIST(ACCOUNT_BASE+103, "Email does not exist"), EMAILNOTEXIST(ACCOUNT_BASE + 103, "Email does not exist"),
NAMEOREMAILNOTEXIST(ACCOUNT_BASE+104, "Username or Email does not exist"), NAMEOREMAILNOTEXIST(ACCOUNT_BASE + 104, "Username or Email does not exist"),
NOTALLOWEDTOCREATESUBUSER(ACCOUNT_BASE+105, "The account isn't allowed to create sub user"), NOTALLOWEDTOCREATESUBUSER(ACCOUNT_BASE + 105, "The account isn't allowed to create sub user"),
PHONEEXIST(ACCOUNT_BASE+106, "Phone number exists"), PHONEEXIST(ACCOUNT_BASE + 106, "Phone number exists"),
OTPWRONG(ACCOUNT_BASE+107, "otp invalid or expires"), OTPWRONG(ACCOUNT_BASE + 107, "otp invalid or expires"),
OTPSENDFAILS(ACCOUNT_BASE+108, "otp sends failure"), OTPSENDFAILS(ACCOUNT_BASE + 108, "otp sends failure"),
PHONENOTEXIST(ACCOUNT_BASE+109, "Can not find account with phone number"), PHONENOTEXIST(ACCOUNT_BASE + 109, "Can not find account with phone number"),
INVALIDTOKEN(ErrorCode.COMMON_INVALID_TOKEN, "Invalid token"), INVALIDTOKEN(ErrorCode.COMMON_INVALID_TOKEN, "Invalid token"),
UNAUTHORIZED(ErrorCode.COMMON_UNAUTHRORIZED, "Unauthorized operation"), UNAUTHORIZED(ErrorCode.COMMON_UNAUTHRORIZED, "Unauthorized operation"),
NAMEEMPTY(ACCOUNT_BASE+110, "Username connot be empty"), NAMEEMPTY(ACCOUNT_BASE + 110, "Username connot be empty"),
EMAILEMPTY(ACCOUNT_BASE+111, "Email connot be empty"), EMAILEMPTY(ACCOUNT_BASE + 111, "Email connot be empty"),
PHONEEMPTY(ACCOUNT_BASE+112, "PhoneNumber connot be empty"), PHONEEMPTY(ACCOUNT_BASE + 112, "PhoneNumber connot be empty"),
AGENCYNOEXIST(ACCOUNT_BASE+113, "uuid dose not exists"), AGENCYNOEXIST(ACCOUNT_BASE + 113, "uuid dose not exists"),
CHILDSCALINGSTATEUNABATED(ACCOUNT_BASE+114, "Can't delete child whose still have scaling group "), CHILDSCALINGSTATEUNABATED(ACCOUNT_BASE + 114, "Can't delete child whose still have scaling group "),
BINDORDERERROR_NOTEXIST(ACCOUNT_BASE+115,"This order is not exist"), BINDORDERERROR_NOTEXIST(ACCOUNT_BASE + 115, "This order is not exist"),
BINDORDERERROR_BINDBYOTHERS(ACCOUNT_BASE+116,"This order has been bind by others"), BINDORDERERROR_BINDBYOTHERS(ACCOUNT_BASE + 116, "This order has been bind by others"),
BINDORDERERROR_NOTQUALIFIED(ACCOUNT_BASE+117,"You don't have free qualified"), BINDORDERERROR_NOTQUALIFIED(ACCOUNT_BASE + 117, "You don't have free qualified"),
BINDORDERERROR_HAVEORDER(ACCOUNT_BASE+118,"You have an unpaid order"), BINDORDERERROR_HAVEORDER(ACCOUNT_BASE + 118, "You have an unpaid order"),
BINDORDERERROR_NOTKNOW(ACCOUNT_BASE+119,"Order generate error,please try again"), BINDORDERERROR_NOTKNOW(ACCOUNT_BASE + 119, "Order generate error,please try again"),
/* http request error */ /* http request error */
OTHERS(ErrorCode.COMMON_OTHERS, "http request error"), OTHERS(ErrorCode.COMMON_OTHERS, "http request error"),
...@@ -45,19 +45,22 @@ public enum AccountErrorCode implements ErrorCode { ...@@ -45,19 +45,22 @@ public enum AccountErrorCode implements ErrorCode {
/* server errors */ /* server errors */
EMAILSENTERROR(ErrorCode.COMMON_SERVER_ERROR, "email sending error"), EMAILSENTERROR(ErrorCode.COMMON_SERVER_ERROR, "email sending error"),
/** wechat errors */ /**
WECHATERROR(ACCOUNT_BASE+120, "Wechat order generation error"), * wechat errors
*/
WECHATERROR(ACCOUNT_BASE + 120, "Wechat order generation error"),
/** alipay errors */ /**
ALIPAYERROR(ACCOUNT_BASE+130, "Alipay order generation error"), * alipay errors
*/
ALIPAYERROR(ACCOUNT_BASE + 130, "Alipay order generation error"),
NOPERMISSION(ACCOUNT_BASE+140, "You have no right to do this operarion"), NOPERMISSION(ACCOUNT_BASE + 140, "You have no right to do this operarion"),
GROUPMAX(ACCOUNT_BASE+141, "You can not have more groups"), GROUPMAX(ACCOUNT_BASE + 141, "You can not have more groups"),
SHOPMAX(ACCOUNT_BASE+142, "You can not have more shops"), SHOPMAX(ACCOUNT_BASE + 142, "You can not have more shops"),
CHILDMAX(ACCOUNT_BASE+143, "You can not have more subUsers"), CHILDMAX(ACCOUNT_BASE + 143, "You can not have more subUsers"),
NOTENOUGHBALANCE(ErrorCode.ACCOUNT_BASE+150, "Your balance is not enough");
NOTENOUGHBALANCE(ErrorCode.ACCOUNT_BASE + 150, "Your balance is not enough");
private final int code; private final int code;
...@@ -68,10 +71,12 @@ public enum AccountErrorCode implements ErrorCode { ...@@ -68,10 +71,12 @@ public enum AccountErrorCode implements ErrorCode {
this.reason = reasonPhrase; this.reason = reasonPhrase;
} }
@Override
public int value() { public int value() {
return this.code; return this.code;
} }
@Override
@JsonValue @JsonValue
public int getCode() { public int getCode() {
return code; return code;
...@@ -82,6 +87,7 @@ public enum AccountErrorCode implements ErrorCode { ...@@ -82,6 +87,7 @@ public enum AccountErrorCode implements ErrorCode {
return Integer.toString(this.code); return Integer.toString(this.code);
} }
@Override
public String getReason() { public String getReason() {
return reason; return reason;
} }
......
package com.edgec.browserbackend.account.service.impl; package com.edgec.browserbackend.account.service.impl;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.edgec.browserbackend.account.dto.*;
import com.edgec.browserbackend.account.service.AccountService;
import com.edgec.browserbackend.account.service.PaymentService;
import com.edgec.browserbackend.account.domain.*; import com.edgec.browserbackend.account.domain.*;
import com.edgec.browserbackend.account.dto.*;
import com.edgec.browserbackend.account.exception.AccountErrorCode; import com.edgec.browserbackend.account.exception.AccountErrorCode;
import com.edgec.browserbackend.account.repository.*; import com.edgec.browserbackend.account.repository.*;
import com.edgec.browserbackend.account.service.AccountService;
import com.edgec.browserbackend.account.service.EmailService; import com.edgec.browserbackend.account.service.EmailService;
import com.edgec.browserbackend.account.service.PaymentService;
import com.edgec.browserbackend.account.service.SmsUtils; import com.edgec.browserbackend.account.service.SmsUtils;
import com.edgec.browserbackend.account.utils.AccountServicePool; import com.edgec.browserbackend.account.utils.AccountServicePool;
import com.edgec.browserbackend.auth.exception.AuthErrorCode; import com.edgec.browserbackend.auth.exception.AuthErrorCode;
...@@ -33,7 +33,7 @@ import org.springframework.transaction.annotation.Transactional; ...@@ -33,7 +33,7 @@ import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.Assert; import org.springframework.util.Assert;
import org.thymeleaf.util.StringUtils; import org.thymeleaf.util.StringUtils;
import java.io.*; import java.io.File;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.time.Instant; import java.time.Instant;
import java.time.YearMonth; import java.time.YearMonth;
...@@ -322,7 +322,8 @@ public class AccountServiceImpl implements AccountService { ...@@ -322,7 +322,8 @@ public class AccountServiceImpl implements AccountService {
@Override @Override
public ResultDto getAccountByName(String name) { public ResultDto getAccountByName(String name) {
Assert.hasLength(name); Assert.hasLength(name, "账户名不能为空");
ResultDto resultDto = new ResultDto(); ResultDto resultDto = new ResultDto();
try { try {
Account account = this.findByName(name); Account account = this.findByName(name);
...@@ -398,6 +399,7 @@ public class AccountServiceImpl implements AccountService { ...@@ -398,6 +399,7 @@ public class AccountServiceImpl implements AccountService {
return resultDto; return resultDto;
} }
@Override
public void deleteByName(String name) { public void deleteByName(String name) {
userService.deleteUser(name); userService.deleteUser(name);
repository.deleteById(name); repository.deleteById(name);
...@@ -411,6 +413,7 @@ public class AccountServiceImpl implements AccountService { ...@@ -411,6 +413,7 @@ public class AccountServiceImpl implements AccountService {
return create(user, null); return create(user, null);
} }
@Override
public void deleteSub(String parent, String child) { public void deleteSub(String parent, String child) {
Assert.hasText(parent); Assert.hasText(parent);
Account childAccount = repository.findByName(child); Account childAccount = repository.findByName(child);
...@@ -1177,8 +1180,7 @@ public class AccountServiceImpl implements AccountService { ...@@ -1177,8 +1180,7 @@ public class AccountServiceImpl implements AccountService {
CompanyAuthorize companyAuthorize = companyAuthorizeRepository.findByUsername(username); CompanyAuthorize companyAuthorize = companyAuthorizeRepository.findByUsername(username);
account.setCompanyName(companyAuthorize.getCompanyName()); account.setCompanyName(companyAuthorize.getCompanyName());
repository.save(account); repository.save(account);
} } else {
else {
account.setAuthorized(3); account.setAuthorized(3);
account.setCompanyName(null); account.setCompanyName(null);
repository.save(account); repository.save(account);
......
...@@ -30,9 +30,10 @@ public class WebSecurityConfig extends WebSecurityConfigurerAdapter { ...@@ -30,9 +30,10 @@ public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
.csrf().disable(); .csrf().disable();
} }
@Override
public void configure(WebSecurity web) throws Exception { public void configure(WebSecurity web) throws Exception {
web.ignoring() web.ignoring()
.antMatchers( "/user/authCode", "/user/signUp", .antMatchers("/user/authCode", "/user/signUp",
"/user/forgot**", "/0xadministrator/getconfig**"); "/user/forgot**", "/0xadministrator/getconfig**");
} }
......
...@@ -8,16 +8,16 @@ public enum AuthErrorCode implements ErrorCode { ...@@ -8,16 +8,16 @@ public enum AuthErrorCode implements ErrorCode {
/* http request error */ /* http request error */
OTHERS(ErrorCode.COMMON_OTHERS, "http request error"), OTHERS(ErrorCode.COMMON_OTHERS, "http request error"),
AUTHENTICATION_ERROR(ErrorCode.AUTH_BASE+100, "authentication failure"), AUTHENTICATION_ERROR(ErrorCode.AUTH_BASE + 100, "authentication failure"),
AUTHORIZATION_ERROR(ErrorCode.AUTH_BASE+200, "authorization failure"), AUTHORIZATION_ERROR(ErrorCode.AUTH_BASE + 200, "authorization failure"),
NAMEEXIST(AUTH_BASE+106, "Username exists"), NAMEEXIST(AUTH_BASE + 106, "Username exists"),
NAMENOTEXIST(AUTH_BASE+102, "Username does not exist"), NAMENOTEXIST(AUTH_BASE + 102, "Username does not exist"),
EMAILEXIST(AUTH_BASE+101, "Email exists"), EMAILEXIST(AUTH_BASE + 101, "Email exists"),
EMAILNOTEXIST(AUTH_BASE+103, "Email does not exist"), EMAILNOTEXIST(AUTH_BASE + 103, "Email does not exist"),
NAMEOREMAILNOTEXIST(AUTH_BASE+104, "Username or Email does not exist"), NAMEOREMAILNOTEXIST(AUTH_BASE + 104, "Username or Email does not exist"),
WRONGEMAILCODE(AUTH_BASE+105, "Wrong verification code"), WRONGEMAILCODE(AUTH_BASE + 105, "Wrong verification code"),
LOGINTIMESEXCEEDED(AUTH_BASE+107, "Login times exceeded"), LOGINTIMESEXCEEDED(AUTH_BASE + 107, "Login times exceeded"),
/* server errors */ /* server errors */
INTERNALSERVERERROR(ErrorCode.COMMON_SERVER_ERROR, "internal server error"); INTERNALSERVERERROR(ErrorCode.COMMON_SERVER_ERROR, "internal server error");
...@@ -31,11 +31,13 @@ public enum AuthErrorCode implements ErrorCode { ...@@ -31,11 +31,13 @@ public enum AuthErrorCode implements ErrorCode {
this.reason = reasonPhrase; this.reason = reasonPhrase;
} }
@Override
public int value() { public int value() {
return this.code; return this.code;
} }
@JsonValue @JsonValue
@Override
public int getCode() { public int getCode() {
return code; return code;
} }
...@@ -45,6 +47,7 @@ public enum AuthErrorCode implements ErrorCode { ...@@ -45,6 +47,7 @@ public enum AuthErrorCode implements ErrorCode {
return Integer.toString(this.code); return Integer.toString(this.code);
} }
@Override
public String getReason() { public String getReason() {
return reason; return reason;
} }
......
...@@ -12,8 +12,6 @@ import org.springframework.context.ApplicationListener; ...@@ -12,8 +12,6 @@ import org.springframework.context.ApplicationListener;
import org.springframework.security.authentication.event.AuthenticationSuccessEvent; import org.springframework.security.authentication.event.AuthenticationSuccessEvent;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import java.util.Date;
@Component @Component
public class AuthenticationSuccessEventListener implements ApplicationListener<AuthenticationSuccessEvent> { public class AuthenticationSuccessEventListener implements ApplicationListener<AuthenticationSuccessEvent> {
...@@ -30,9 +28,9 @@ public class AuthenticationSuccessEventListener implements ApplicationListener<A ...@@ -30,9 +28,9 @@ public class AuthenticationSuccessEventListener implements ApplicationListener<A
User user = userRepository.findById(username).orElse(null); User user = userRepository.findById(username).orElse(null);
if (user != null) { if (user != null) {
UserAttemptsLogin userAttempts = userAttemptsLoginRepository.findById(username).orElse(null); UserAttemptsLogin userAttempts = userAttemptsLoginRepository.findById(username).orElse(null);
if(userAttempts != null) { if (userAttempts != null) {
if (userAttempts.getAttempts() >= 20) { if (userAttempts.getAttempts() >= 20) {
if (userAttempts.getDate().getTime() >= (new Date().getTime() - 600000)) if (userAttempts.getDate().getTime() >= (System.currentTimeMillis() - 600000))
throw new ClientRequestException(AuthErrorCode.LOGINTIMESEXCEEDED, "Login times exceeded"); throw new ClientRequestException(AuthErrorCode.LOGINTIMESEXCEEDED, "Login times exceeded");
} else if (userAttempts.getAttempts() != 0) { } else if (userAttempts.getAttempts() != 0) {
saveUserAttemptsLogin(username, 0); saveUserAttemptsLogin(username, 0);
......
...@@ -7,20 +7,20 @@ public enum BrowserErrorCode implements ErrorCode { ...@@ -7,20 +7,20 @@ public enum BrowserErrorCode implements ErrorCode {
/* client errors */ /* client errors */
UNKNOWN(ErrorCode.COMMON_UNKNOWN,"unknown"), UNKNOWN(ErrorCode.COMMON_UNKNOWN, "unknown"),
INFORMATIONNOTCOMPELETE(BROWSER_BASE+100, "The information about shop does not complete"), INFORMATIONNOTCOMPELETE(BROWSER_BASE + 100, "The information about shop does not complete"),
SHOPNOTEXIST(BROWSER_BASE+101, "The shop does not exist"), SHOPNOTEXIST(BROWSER_BASE + 101, "The shop does not exist"),
SHOP_BINDED(BROWSER_BASE + 102, "The shop has bind with ip"),
IPNOTEXIST(BROWSER_BASE+201, "The ip do not exist"), IPNOTEXIST(BROWSER_BASE + 201, "The ip do not exist"),
IPNOTBINDTOSHOP(BROWSER_BASE+202, "The ip does not bind this shop."), IPNOTBINDTOSHOP(BROWSER_BASE + 202, "The ip does not bind this shop."),
GROUPNOTEXIST(BROWSER_BASE+301, "The group does not exist"), GROUPNOTEXIST(BROWSER_BASE + 301, "The group does not exist"),
IPTRANSACTIONNOTEXIST(BROWSER_BASE+401, "The ipTransaction does not exist"), IPTRANSACTIONNOTEXIST(BROWSER_BASE + 401, "The ipTransaction does not exist"),
COMPANYAUTHORIZEEXIST(BROWSER_BASE+501, "The authority exists"),
COMPANYAUTHORIZENOTEXIST(BROWSER_BASE+502, "The authority dose not exist");
COMPANYAUTHORIZEEXIST(BROWSER_BASE + 501, "The authority exists"),
COMPANYAUTHORIZENOTEXIST(BROWSER_BASE + 502, "The authority dose not exist");
private final int code; private final int code;
...@@ -31,11 +31,13 @@ public enum BrowserErrorCode implements ErrorCode { ...@@ -31,11 +31,13 @@ public enum BrowserErrorCode implements ErrorCode {
this.reason = reasonPhrase; this.reason = reasonPhrase;
} }
@Override
public int value() { public int value() {
return this.code; return this.code;
} }
@JsonValue @JsonValue
@Override
public int getCode() { public int getCode() {
return code; return code;
} }
...@@ -45,6 +47,7 @@ public enum BrowserErrorCode implements ErrorCode { ...@@ -45,6 +47,7 @@ public enum BrowserErrorCode implements ErrorCode {
return Integer.toString(this.code); return Integer.toString(this.code);
} }
@Override
public String getReason() { public String getReason() {
return reason; return reason;
} }
......
package com.edgec.browserbackend.browser.controller; package com.edgec.browserbackend.browser.controller;
import com.edgec.browserbackend.account.dto.ResultDto; import com.edgec.browserbackend.account.dto.ResultDto;
import com.edgec.browserbackend.browser.domain.OperationHistory;
import com.edgec.browserbackend.browser.dto.HistoryListRequestDto; import com.edgec.browserbackend.browser.dto.HistoryListRequestDto;
import com.edgec.browserbackend.browser.dto.IpResourceRequestDto;
import com.edgec.browserbackend.browser.dto.LoginHistoryDto; import com.edgec.browserbackend.browser.dto.LoginHistoryDto;
import com.edgec.browserbackend.browser.dto.OperationHistoryDto; import com.edgec.browserbackend.browser.dto.OperationHistoryDto;
import com.edgec.browserbackend.browser.service.HistoryService; import com.edgec.browserbackend.browser.service.HistoryService;
...@@ -32,11 +30,7 @@ public class HistoryController { ...@@ -32,11 +30,7 @@ public class HistoryController {
historyService.addLoginHistory(principal.getName(), loginHistoryDto); historyService.addLoginHistory(principal.getName(), loginHistoryDto);
resultDto.setStatus(0); resultDto.setStatus(0);
} catch (ClientRequestException e) { } catch (ClientRequestException e) {
resultDto.setStatus(-1); dealClientRequestException(resultDto, e);
Map<String, Object> statusInfo = new HashMap<>();
statusInfo.put("code", e.getErrorCode());
statusInfo.put("message", e.getMessage());
resultDto.setStatusInfo(statusInfo);
} }
return resultDto; return resultDto;
} }
...@@ -48,11 +42,7 @@ public class HistoryController { ...@@ -48,11 +42,7 @@ public class HistoryController {
historyService.addOperationHistory(principal.getName(), operationHistoryDto); historyService.addOperationHistory(principal.getName(), operationHistoryDto);
resultDto.setStatus(0); resultDto.setStatus(0);
} catch (ClientRequestException e) { } catch (ClientRequestException e) {
resultDto.setStatus(-1); dealClientRequestException(resultDto, e);
Map<String, Object> statusInfo = new HashMap<>();
statusInfo.put("code", e.getErrorCode());
statusInfo.put("message", e.getMessage());
resultDto.setStatusInfo(statusInfo);
} }
return resultDto; return resultDto;
} }
...@@ -64,11 +54,7 @@ public class HistoryController { ...@@ -64,11 +54,7 @@ public class HistoryController {
resultDto.setData(historyService.getLoginHistories(principal.getName(), historyListRequestDto)); resultDto.setData(historyService.getLoginHistories(principal.getName(), historyListRequestDto));
resultDto.setStatus(0); resultDto.setStatus(0);
} catch (ClientRequestException e) { } catch (ClientRequestException e) {
resultDto.setStatus(-1); dealClientRequestException(resultDto, e);
Map<String, Object> statusInfo = new HashMap<>();
statusInfo.put("code", e.getErrorCode());
statusInfo.put("message", e.getMessage());
resultDto.setStatusInfo(statusInfo);
} }
return resultDto; return resultDto;
} }
...@@ -80,12 +66,16 @@ public class HistoryController { ...@@ -80,12 +66,16 @@ public class HistoryController {
resultDto.setData(historyService.getOperationHistories(principal.getName(), historyListRequestDto)); resultDto.setData(historyService.getOperationHistories(principal.getName(), historyListRequestDto));
resultDto.setStatus(0); resultDto.setStatus(0);
} catch (ClientRequestException e) { } catch (ClientRequestException e) {
dealClientRequestException(resultDto, e);
}
return resultDto;
}
private void dealClientRequestException(ResultDto resultDto, ClientRequestException e) {
resultDto.setStatus(-1); resultDto.setStatus(-1);
Map<String, Object> statusInfo = new HashMap<>(); Map<String, Object> statusInfo = new HashMap<>();
statusInfo.put("code", e.getErrorCode()); statusInfo.put("code", e.getErrorCode());
statusInfo.put("message", e.getMessage()); statusInfo.put("message", e.getMessage());
resultDto.setStatusInfo(statusInfo); resultDto.setStatusInfo(statusInfo);
} }
return resultDto;
}
} }
package com.edgec.browserbackend.browser.controller; package com.edgec.browserbackend.browser.controller;
import com.edgec.browserbackend.account.dto.ResultDto; import com.edgec.browserbackend.account.dto.ResultDto;
import com.edgec.browserbackend.browser.dto.*; import com.edgec.browserbackend.browser.dto.IpListRequestDto;
import com.edgec.browserbackend.browser.dto.IpPageResultDto;
import com.edgec.browserbackend.browser.dto.IpResourceRequestDto;
import com.edgec.browserbackend.browser.dto.IpResourceUpdateDto;
import com.edgec.browserbackend.browser.service.IpResourceService; import com.edgec.browserbackend.browser.service.IpResourceService;
import com.edgec.browserbackend.common.auth.Securitys; import com.edgec.browserbackend.common.auth.Securitys;
import com.edgec.browserbackend.common.commons.error.ClientRequestException; import com.edgec.browserbackend.common.commons.error.ClientRequestException;
...@@ -25,7 +28,7 @@ public class IpControlloer { ...@@ -25,7 +28,7 @@ public class IpControlloer {
private IpResourceService ipResourceService; private IpResourceService ipResourceService;
@RequestMapping(value = "/buy", method = RequestMethod.POST) @RequestMapping(value = "/buy", method = RequestMethod.POST)
public ResultDto buyIp(Principal principal, @RequestBody IpResourceRequestDto ipResourceRequestDto){ public ResultDto buyIp(Principal principal, @RequestBody IpResourceRequestDto ipResourceRequestDto) {
ResultDto resultDto = new ResultDto(); ResultDto resultDto = new ResultDto();
try { try {
List<String> ipResourceDto = ipResourceService.buyIp(principal.getName(), ipResourceRequestDto); List<String> ipResourceDto = ipResourceService.buyIp(principal.getName(), ipResourceRequestDto);
...@@ -93,7 +96,7 @@ public class IpControlloer { ...@@ -93,7 +96,7 @@ public class IpControlloer {
ipListRequestDto.getAmount(), ipListRequestDto.getFilter()); ipListRequestDto.getAmount(), ipListRequestDto.getFilter());
resultDto.setData(ipResourceDto); resultDto.setData(ipResourceDto);
resultDto.setStatus(0); resultDto.setStatus(0);
}catch (ClientRequestException e) { } catch (ClientRequestException e) {
resultDto.setStatus(-1); resultDto.setStatus(-1);
Map<String, Object> statusInfo = new HashMap<>(); Map<String, Object> statusInfo = new HashMap<>();
statusInfo.put("code", e.getErrorCode()); statusInfo.put("code", e.getErrorCode());
...@@ -110,6 +113,12 @@ public class IpControlloer { ...@@ -110,6 +113,12 @@ public class IpControlloer {
try { try {
ipResourceService.updateIp(principal.getName(), ipResourceUpdateDto); ipResourceService.updateIp(principal.getName(), ipResourceUpdateDto);
resultDto.setStatus(0); resultDto.setStatus(0);
} catch (ClientRequestException e) {
resultDto.setStatus(-1);
Map<String, Object> statusInfo = new HashMap<>();
statusInfo.put("code", e.getErrorCode().getCode());
statusInfo.put("message", e.getErrorCode().getReason());
resultDto.setStatusInfo(statusInfo);
} catch (Exception e) { } catch (Exception e) {
resultDto.setStatus(-1); resultDto.setStatus(-1);
Map<String, Object> statusInfo = new HashMap<>(); Map<String, Object> statusInfo = new HashMap<>();
......
...@@ -43,11 +43,7 @@ public class ShopController { ...@@ -43,11 +43,7 @@ public class ShopController {
resultDto.setData(shopStringResultDto); resultDto.setData(shopStringResultDto);
resultDto.setStatus(0); resultDto.setStatus(0);
} catch (ClientRequestException e) { } catch (ClientRequestException e) {
resultDto.setStatus(-1); dealClientRequestException(resultDto, e);
Map<String, Object> statusInfo = new HashMap<>();
statusInfo.put("code", e.getErrorCode());
statusInfo.put("message", e.getMessage());
resultDto.setStatusInfo(statusInfo);
} }
return resultDto; return resultDto;
} }
...@@ -73,10 +69,7 @@ public class ShopController { ...@@ -73,10 +69,7 @@ public class ShopController {
statusInfo.put("message", e.getMessage()); statusInfo.put("message", e.getMessage());
resultDto.setStatusInfo(statusInfo); resultDto.setStatusInfo(statusInfo);
} }
return resultDto; return resultDto;
} }
@RequestMapping(value = "/update", method = RequestMethod.POST) @RequestMapping(value = "/update", method = RequestMethod.POST)
...@@ -88,11 +81,7 @@ public class ShopController { ...@@ -88,11 +81,7 @@ public class ShopController {
resultDto.setData(shopStringResultDto); resultDto.setData(shopStringResultDto);
resultDto.setStatus(0); resultDto.setStatus(0);
} catch (ClientRequestException e) { } catch (ClientRequestException e) {
resultDto.setStatus(-1); dealClientRequestException(resultDto, e);
Map<String, Object> statusInfo = new HashMap<>();
statusInfo.put("code", e.getErrorCode());
statusInfo.put("message", e.getMessage());
resultDto.setStatusInfo(statusInfo);
} }
return resultDto; return resultDto;
} }
...@@ -104,11 +93,7 @@ public class ShopController { ...@@ -104,11 +93,7 @@ public class ShopController {
shopService.deleteShop(principal.getName(), shopRequestDto.getShopId()); shopService.deleteShop(principal.getName(), shopRequestDto.getShopId());
resultDto.setStatus(0); resultDto.setStatus(0);
} catch (ClientRequestException e) { } catch (ClientRequestException e) {
resultDto.setStatus(-1); dealClientRequestException(resultDto, e);
Map<String, Object> statusInfo = new HashMap<>();
statusInfo.put("code", e.getErrorCode());
statusInfo.put("message", e.getMessage());
resultDto.setStatusInfo(statusInfo);
} }
return resultDto; return resultDto;
} }
...@@ -121,11 +106,7 @@ public class ShopController { ...@@ -121,11 +106,7 @@ public class ShopController {
resultDto.setStatus(0); resultDto.setStatus(0);
} catch (ClientRequestException e) { } catch (ClientRequestException e) {
logger.error("fail to bind shop", e); logger.error("fail to bind shop", e);
resultDto.setStatus(-1); dealClientRequestException(resultDto, e);
Map<String, Object> statusInfo = new HashMap<>();
statusInfo.put("code", e.getErrorCode());
statusInfo.put("message", e.getMessage());
resultDto.setStatusInfo(statusInfo);
} }
return resultDto; return resultDto;
} }
...@@ -137,11 +118,7 @@ public class ShopController { ...@@ -137,11 +118,7 @@ public class ShopController {
ipAndShopService.unBindShop(principal.getName(), shopRequestDto); ipAndShopService.unBindShop(principal.getName(), shopRequestDto);
resultDto.setStatus(0); resultDto.setStatus(0);
} catch (ClientRequestException e) { } catch (ClientRequestException e) {
resultDto.setStatus(-1); dealClientRequestException(resultDto, e);
Map<String, Object> statusInfo = new HashMap<>();
statusInfo.put("code", e.getErrorCode());
statusInfo.put("message", e.getMessage());
resultDto.setStatusInfo(statusInfo);
} }
return resultDto; return resultDto;
} }
...@@ -153,11 +130,7 @@ public class ShopController { ...@@ -153,11 +130,7 @@ public class ShopController {
shopService.transferShop(principal.getName(), shopRequestDto.getShopId(), shopRequestDto.getToGroup()); shopService.transferShop(principal.getName(), shopRequestDto.getShopId(), shopRequestDto.getToGroup());
resultDto.setStatus(0); resultDto.setStatus(0);
} catch (ClientRequestException e) { } catch (ClientRequestException e) {
resultDto.setStatus(-1); dealClientRequestException(resultDto, e);
Map<String, Object> statusInfo = new HashMap<>();
statusInfo.put("code", e.getErrorCode());
statusInfo.put("message", e.getMessage());
resultDto.setStatusInfo(statusInfo);
} }
return resultDto; return resultDto;
} }
...@@ -169,11 +142,7 @@ public class ShopController { ...@@ -169,11 +142,7 @@ public class ShopController {
shopService.assignShops(principal.getName(), shopRequestDto.getShopIds(), shopRequestDto.getToUsers()); shopService.assignShops(principal.getName(), shopRequestDto.getShopIds(), shopRequestDto.getToUsers());
resultDto.setStatus(0); resultDto.setStatus(0);
} catch (ClientRequestException e) { } catch (ClientRequestException e) {
resultDto.setStatus(-1); dealClientRequestException(resultDto, e);
Map<String, Object> statusInfo = new HashMap<>();
statusInfo.put("code", e.getErrorCode());
statusInfo.put("message", e.getMessage());
resultDto.setStatusInfo(statusInfo);
} }
return resultDto; return resultDto;
} }
...@@ -182,16 +151,11 @@ public class ShopController { ...@@ -182,16 +151,11 @@ public class ShopController {
public ResultDto getShopList(Principal principal, @RequestBody ShopRequestDto shopRequestDto) { public ResultDto getShopList(Principal principal, @RequestBody ShopRequestDto shopRequestDto) {
ResultDto resultDto = new ResultDto(); ResultDto resultDto = new ResultDto();
try { try {
ShopPageResultDto shopDtos = shopService.getShopList(principal.getName(), shopRequestDto.getGroup(), shopRequestDto.getPage(), ShopPageResultDto shopDtos = shopService.getShopList(principal.getName(), shopRequestDto.getGroup(), shopRequestDto.getPage(), shopRequestDto.getAmount(), shopRequestDto.getFilter());
shopRequestDto.getAmount(), shopRequestDto.getFilter());
resultDto.setData(shopDtos); resultDto.setData(shopDtos);
resultDto.setStatus(0); resultDto.setStatus(0);
} catch (ClientRequestException e) { } catch (ClientRequestException e) {
resultDto.setStatus(-1); dealClientRequestException(resultDto, e);
Map<String, Object> statusInfo = new HashMap<>();
statusInfo.put("code", e.getErrorCode());
statusInfo.put("message", e.getMessage());
resultDto.setStatusInfo(statusInfo);
} }
logger.error(JSONObject.toJSONString(resultDto)); logger.error(JSONObject.toJSONString(resultDto));
return resultDto; return resultDto;
...@@ -205,11 +169,7 @@ public class ShopController { ...@@ -205,11 +169,7 @@ public class ShopController {
resultDto.setData(subUsers); resultDto.setData(subUsers);
resultDto.setStatus(0); resultDto.setStatus(0);
} catch (ClientRequestException e) { } catch (ClientRequestException e) {
resultDto.setStatus(-1); dealClientRequestException(resultDto, e);
Map<String, Object> statusInfo = new HashMap<>();
statusInfo.put("code", e.getErrorCode());
statusInfo.put("message", e.getMessage());
resultDto.setStatusInfo(statusInfo);
} }
return resultDto; return resultDto;
} }
...@@ -222,11 +182,7 @@ public class ShopController { ...@@ -222,11 +182,7 @@ public class ShopController {
resultDto.setData(subUsers); resultDto.setData(subUsers);
resultDto.setStatus(0); resultDto.setStatus(0);
} catch (ClientRequestException e) { } catch (ClientRequestException e) {
resultDto.setStatus(-1); dealClientRequestException(resultDto, e);
Map<String, Object> statusInfo = new HashMap<>();
statusInfo.put("code", e.getErrorCode());
statusInfo.put("message", e.getMessage());
resultDto.setStatusInfo(statusInfo);
} }
return resultDto; return resultDto;
} }
...@@ -239,12 +195,16 @@ public class ShopController { ...@@ -239,12 +195,16 @@ public class ShopController {
resultDto.setData(shopDto); resultDto.setData(shopDto);
resultDto.setStatus(0); resultDto.setStatus(0);
} catch (ClientRequestException e) { } catch (ClientRequestException e) {
dealClientRequestException(resultDto, e);
}
return resultDto;
}
private void dealClientRequestException(ResultDto resultDto, ClientRequestException e) {
resultDto.setStatus(-1); resultDto.setStatus(-1);
Map<String, Object> statusInfo = new HashMap<>(); Map<String, Object> statusInfo = new HashMap<>();
statusInfo.put("code", e.getErrorCode()); statusInfo.put("code", e.getErrorCode());
statusInfo.put("message", e.getMessage()); statusInfo.put("message", e.getMessage());
resultDto.setStatusInfo(statusInfo); resultDto.setStatusInfo(statusInfo);
} }
return resultDto;
}
} }
...@@ -36,39 +36,44 @@ public class HistoryServiceImpl implements HistoryService { ...@@ -36,39 +36,44 @@ public class HistoryServiceImpl implements HistoryService {
@Override @Override
public void addLoginHistory(String username, LoginHistoryDto loginHistoryDto) { public void addLoginHistory(String username, LoginHistoryDto loginHistoryDto) {
Account account = accountRepository.findById(username).orElse(null); Account account = accountRepository.findById(username)
if (account == null) .orElseThrow(() -> new ClientRequestException(AccountErrorCode.NAMENOTEXIST));
throw new ClientRequestException(AccountErrorCode.NAMENOTEXIST);
int num = loginHistoryRepository.countByUsername(username); int num = loginHistoryRepository.countByUsername(username);
if (num > 10000) if (num > 10000) {
loginHistoryRepository.delete(loginHistoryRepository.findFirstByUsername(username)); loginHistoryRepository.delete(loginHistoryRepository.findFirstByUsername(username));
}
LoginHistory loginHistory = new LoginHistory(loginHistoryDto); LoginHistory loginHistory = new LoginHistory(loginHistoryDto);
loginHistory.setLoginTime(Instant.now().toEpochMilli()); loginHistory.setLoginTime(Instant.now().toEpochMilli());
loginHistory.setUsername(username); loginHistory.setUsername(username);
if (account.getParent() == null) if (account.getParent() == null) {
loginHistory.setAdministrator(username); loginHistory.setAdministrator(username);
else } else {
loginHistory.setAdministrator(account.getParent()); loginHistory.setAdministrator(account.getParent());
}
loginHistory.setNickname(account.getNickname()); loginHistory.setNickname(account.getNickname());
loginHistoryRepository.save(loginHistory); loginHistoryRepository.save(loginHistory);
} }
@Override @Override
public void addOperationHistory(String username, OperationHistoryDto operationHistoryDto) { public void addOperationHistory(String username, OperationHistoryDto operationHistoryDto) {
Account account = accountRepository.findById(username).orElse(null); Account account = accountRepository.findById(username).orElseThrow(() -> new ClientRequestException(AccountErrorCode.NAMENOTEXIST));
if (account == null)
throw new ClientRequestException(AccountErrorCode.NAMENOTEXIST);
int num = operationHistoryRepository.countByUsername(username); int num = operationHistoryRepository.countByUsername(username);
if (num > 10000) if (num > 10000) {
operationHistoryRepository.delete(operationHistoryRepository.findFirstByUsername(username)); operationHistoryRepository.delete(operationHistoryRepository.findFirstByUsername(username));
}
OperationHistory operationHistory = new OperationHistory(operationHistoryDto); OperationHistory operationHistory = new OperationHistory(operationHistoryDto);
operationHistory.setOperationTime(Instant.now().toEpochMilli()); operationHistory.setOperationTime(Instant.now().toEpochMilli());
operationHistory.setUsername(username); operationHistory.setUsername(username);
operationHistory.setNickname(account.getNickname()); operationHistory.setNickname(account.getNickname());
if (account.getParent() == null) if (account.getParent() == null) {
operationHistory.setAdministrator(username); operationHistory.setAdministrator(username);
else } else {
operationHistory.setAdministrator(account.getParent()); operationHistory.setAdministrator(account.getParent());
}
operationHistoryRepository.save(operationHistory); operationHistoryRepository.save(operationHistory);
} }
...@@ -99,7 +104,7 @@ public class HistoryServiceImpl implements HistoryService { ...@@ -99,7 +104,7 @@ public class HistoryServiceImpl implements HistoryService {
PageInfo pageInfo = new PageInfo(); PageInfo pageInfo = new PageInfo();
pageInfo.setCurrentPage(loginHistoryPage.getNumber()); pageInfo.setCurrentPage(loginHistoryPage.getNumber());
pageInfo.setTotalPages(loginHistoryPage.getTotalPages()); pageInfo.setTotalPages(loginHistoryPage.getTotalPages());
pageInfo.setTotalItems((int)loginHistoryPage.getTotalElements()); pageInfo.setTotalItems((int) loginHistoryPage.getTotalElements());
historyPageResultDto.setHistoryPage(pageInfo); historyPageResultDto.setHistoryPage(pageInfo);
return historyPageResultDto; return historyPageResultDto;
} }
...@@ -131,7 +136,7 @@ public class HistoryServiceImpl implements HistoryService { ...@@ -131,7 +136,7 @@ public class HistoryServiceImpl implements HistoryService {
PageInfo pageInfo = new PageInfo(); PageInfo pageInfo = new PageInfo();
pageInfo.setCurrentPage(operationHistories.getNumber()); pageInfo.setCurrentPage(operationHistories.getNumber());
pageInfo.setTotalPages(operationHistories.getTotalPages()); pageInfo.setTotalPages(operationHistories.getTotalPages());
pageInfo.setTotalItems((int)operationHistories.getTotalElements()); pageInfo.setTotalItems((int) operationHistories.getTotalElements());
historyPageResultDto.setHistoryPage(pageInfo); historyPageResultDto.setHistoryPage(pageInfo);
return historyPageResultDto; return historyPageResultDto;
} }
......
...@@ -43,18 +43,22 @@ public class IpAndShopServiceImpl implements IpAndShopService { ...@@ -43,18 +43,22 @@ public class IpAndShopServiceImpl implements IpAndShopService {
@Override @Override
public void bindShop(String username, ShopRequestDto shopRequestDto) { public void bindShop(String username, ShopRequestDto shopRequestDto) {
String shopId = shopRequestDto.getShopId(); // 1. 根据id 来获取账户
Account account = accountRepository.findByName(username); Account account = accountRepository.findByName(username);
if (account == null) { if (account == null) {
throw new ClientRequestException(AccountErrorCode.NAMENOTEXIST); throw new ClientRequestException(AccountErrorCode.NAMENOTEXIST);
} }
String shopId = shopRequestDto.getShopId();
// 2.获取当前账户下指定的商铺
UserShop userShop = userShopRepository.findByUsernameAndShopId(username, shopId); UserShop userShop = userShopRepository.findByUsernameAndShopId(username, shopId);
if (account.getPermission() < 4 || userShop == null) { if (account.getPermission() < 4 || userShop == null) {
throw new ClientRequestException(AccountErrorCode.NOPERMISSION); throw new ClientRequestException(AccountErrorCode.NOPERMISSION);
} }
Shop shop = shopRepository.findById(shopId).orElse(null); // 3.根据shopId获取商铺的详情
if (shop == null) Shop shop = shopRepository.findById(shopId).orElseThrow(() -> new ClientRequestException(BrowserErrorCode.SHOPNOTEXIST));
throw new ClientRequestException(BrowserErrorCode.SHOPNOTEXIST);
// 4.根据传入的id或者addr查询是否有指定的 ip 资源
IpResource ipResource = null; IpResource ipResource = null;
if (StringUtils.isNotBlank(shopRequestDto.getIpAddr())) { if (StringUtils.isNotBlank(shopRequestDto.getIpAddr())) {
ipResource = ipResourceRepository.findByAddrAndIsDeleted(shopRequestDto.getIpAddr(), false); ipResource = ipResourceRepository.findByAddrAndIsDeleted(shopRequestDto.getIpAddr(), false);
...@@ -62,14 +66,18 @@ public class IpAndShopServiceImpl implements IpAndShopService { ...@@ -62,14 +66,18 @@ public class IpAndShopServiceImpl implements IpAndShopService {
ipResource = ipResourceRepository.findByIdAndIsDeleted(shopRequestDto.getIpId(), false); ipResource = ipResourceRepository.findByIdAndIsDeleted(shopRequestDto.getIpId(), false);
} }
if (ipResource == null) if (ipResource == null) {
throw new ClientRequestException(BrowserErrorCode.IPNOTEXIST); throw new ClientRequestException(BrowserErrorCode.IPNOTEXIST);
}
// 5.根据shopId来查询指定 isDeleted 为 false 的 ip资源
IpResource bind = ipResourceRepository.findFirstByShopIdsIsAndIsDeleted(shopId, false); IpResource bind = ipResourceRepository.findFirstByShopIdsIsAndIsDeleted(shopId, false);
if (bind != null) { if (bind != null) {
return; throw new ClientRequestException(BrowserErrorCode.SHOP_BINDED);
} }
try { try {
// 6.绑定ip,将shopId添加到ip资源中,且将 bind 状态设置为 true
ipResourceRepository.addShopId(ipResource.getId(), shopId); ipResourceRepository.addShopId(ipResource.getId(), shopId);
} catch (Exception e) { } catch (Exception e) {
logger.error("fail to bind shop and ip", e); logger.error("fail to bind shop and ip", e);
......
...@@ -47,33 +47,11 @@ public class IpResourceServiceImpl implements IpResourceService { ...@@ -47,33 +47,11 @@ public class IpResourceServiceImpl implements IpResourceService {
private static String USERNAME = "fangguanlianbrowser"; private static String USERNAME = "fangguanlianbrowser";
public static List<String> region = Arrays.asList( public static List<String> region = Arrays.asList(
"asiapa", "asiapa", "hongkong", "japan", "s-korea", "us", "malaysia",
"hongkong", "yajiada", "singapore", "australia", "germany", "uk", "brazil",
"japan", "moscow", "canada", "france", "sweden", "s-korea", "india", "meast",
"s-korea", "brazil", "virginia", "ohio", "california", "oregon", "ireland", "london", "ireland"
"us", );
"malaysia",
"yajiada",
"singapore",
"australia",
"germany",
"uk",
"brazil",
"moscow",
"canada",
"france",
"sweden",
"s-korea",
"india",
"meast",
"brazil",
"virginia",
"ohio",
"california",
"oregon",
"ireland",
"london",
"ireland");
private static List<String> port = Arrays.asList("20000", "20001"); private static List<String> port = Arrays.asList("20000", "20001");
...@@ -734,24 +712,41 @@ public class IpResourceServiceImpl implements IpResourceService { ...@@ -734,24 +712,41 @@ public class IpResourceServiceImpl implements IpResourceService {
@Override @Override
public void updateIp(String username, IpResourceUpdateDto ipResourceUpdateDto) { public void updateIp(String username, IpResourceUpdateDto ipResourceUpdateDto) {
// 1. 根据id 来获取账户
Account account = accountRepository.findByName(username); Account account = accountRepository.findByName(username);
if (account == null) if (account == null) {
throw new ClientRequestException(AccountErrorCode.NAMENOTEXIST); throw new ClientRequestException(AccountErrorCode.NAMENOTEXIST);
if (account.getPermission() < 8) }
/// 这个地方本来是8,现在由于更新ip失败,改为和绑定店铺时一样的 4
if (account.getPermission() < 4) {
throw new ClientRequestException(AccountErrorCode.NOPERMISSION); throw new ClientRequestException(AccountErrorCode.NOPERMISSION);
}
// 2.根据传入的id查询是否有指定的 isDelete 为 false的 ip 资源
IpResource ipResource = ipResourceRepository.findByIdAndIsDeleted(ipResourceUpdateDto.getIpId(), false); IpResource ipResource = ipResourceRepository.findByIdAndIsDeleted(ipResourceUpdateDto.getIpId(), false);
if (ipResource == null) if (ipResource == null) {
throw new ClientRequestException(BrowserErrorCode.IPNOTEXIST); throw new ClientRequestException(BrowserErrorCode.IPNOTEXIST);
}
// 封装 ipResource 部分信息
dealIpResource(ipResourceUpdateDto, ipResource);
// 3.更新ip资源
ipResourceRepository.save(ipResource);
}
private void dealIpResource(IpResourceUpdateDto ipResourceUpdateDto, IpResource ipResource) {
if (StringUtils.isNotBlank(ipResourceUpdateDto.getAddr())) { if (StringUtils.isNotBlank(ipResourceUpdateDto.getAddr())) {
ipResource.setAddr(ipResourceUpdateDto.getAddr()); ipResource.setAddr(ipResourceUpdateDto.getAddr());
} }
if (StringUtils.isNotBlank(ipResource.getRegion()) && region.contains(ipResource.getRegion())) { if (StringUtils.isNotBlank(ipResource.getRegion()) && region.contains(ipResource.getRegion())) {
ipResource.setProxyUsername(ipResource.getAddr()); ipResource.setProxyUsername(ipResource.getAddr());
ipResource.setProxyPassword(genRandom(3, 12)); ipResource.setProxyPassword(genRandom(3, 12));
ipResource.setSpecialLine(true); ipResource.setSpecialLine(true);
} }
ipResource.setStatus(ipResourceUpdateDto.getStatus()); ipResource.setStatus(ipResourceUpdateDto.getStatus());
ipResourceRepository.save(ipResource);
} }
@Override @Override
......
...@@ -26,7 +26,7 @@ public class ClientRequestException extends IllegalArgumentException { ...@@ -26,7 +26,7 @@ public class ClientRequestException extends IllegalArgumentException {
this.errorCode = errorCode; this.errorCode = errorCode;
} }
public ClientRequestException(int errorCode, String message){ public ClientRequestException(int errorCode, String message) {
super(message); super(message);
} }
......
...@@ -12,7 +12,6 @@ public interface ErrorCode { ...@@ -12,7 +12,6 @@ public interface ErrorCode {
public static final int COMMON_UNAUTHRORIZED = 100004; public static final int COMMON_UNAUTHRORIZED = 100004;
public static final int ACCOUNT_BASE = 400000; public static final int ACCOUNT_BASE = 400000;
public static final int AUTH_BASE = 500000; public static final int AUTH_BASE = 500000;
...@@ -20,9 +19,11 @@ public interface ErrorCode { ...@@ -20,9 +19,11 @@ public interface ErrorCode {
public static final int BROWSER_BASE = 600000; public static final int BROWSER_BASE = 600000;
int value() ; int value();
@JsonValue @JsonValue
int getCode() ; int getCode();
String getReason();
} }
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