Commit 6aae1d14 authored by renjie's avatar renjie

修改account字段为username

parent 45c586c7
...@@ -13,7 +13,7 @@ import java.time.format.DateTimeFormatter; ...@@ -13,7 +13,7 @@ import java.time.format.DateTimeFormatter;
public class LoginHistory { public class LoginHistory {
@Id @Id
private String id; private String id;
private String account; private String username;
private String nickname; private String nickname;
private String loginIp; private String loginIp;
private String loginPlace; private String loginPlace;
...@@ -26,7 +26,7 @@ public class LoginHistory { ...@@ -26,7 +26,7 @@ public class LoginHistory {
public LoginHistory(LoginHistoryDto loginHistoryDto) { public LoginHistory(LoginHistoryDto loginHistoryDto) {
if (loginHistoryDto.getAccount() != null) if (loginHistoryDto.getAccount() != null)
this.account = loginHistoryDto.getAccount(); this.username = loginHistoryDto.getAccount();
if (loginHistoryDto.getNickname() != null) if (loginHistoryDto.getNickname() != null)
this.nickname = loginHistoryDto.getNickname(); this.nickname = loginHistoryDto.getNickname();
if (loginHistoryDto.getLoginIp() != null) if (loginHistoryDto.getLoginIp() != null)
...@@ -72,12 +72,12 @@ public class LoginHistory { ...@@ -72,12 +72,12 @@ public class LoginHistory {
this.loginIp = loginIp; this.loginIp = loginIp;
} }
public String getAccount() { public String getUsername() {
return account; return username;
} }
public void setAccount(String account) { public void setUsername(String username) {
this.account = account; this.username = username;
} }
public long getLoginTime() { public long getLoginTime() {
......
...@@ -12,7 +12,7 @@ import java.time.format.DateTimeFormatter; ...@@ -12,7 +12,7 @@ import java.time.format.DateTimeFormatter;
public class OperationHistory { public class OperationHistory {
@Id @Id
private String id; private String id;
private String account; private String username;
private String nickname; private String nickname;
private String loginIp; private String loginIp;
private String loginPlace; private String loginPlace;
...@@ -26,7 +26,7 @@ public class OperationHistory { ...@@ -26,7 +26,7 @@ public class OperationHistory {
public OperationHistory(OperationHistoryDto operationHistoryDto) { public OperationHistory(OperationHistoryDto operationHistoryDto) {
if (operationHistoryDto.getAccount() != null) if (operationHistoryDto.getAccount() != null)
this.account = operationHistoryDto.getAccount(); this.username = operationHistoryDto.getAccount();
if (operationHistoryDto.getNickname() != null) if (operationHistoryDto.getNickname() != null)
this.nickname = operationHistoryDto.getNickname(); this.nickname = operationHistoryDto.getNickname();
if (operationHistoryDto.getLoginIp() != null) if (operationHistoryDto.getLoginIp() != null)
...@@ -50,12 +50,12 @@ public class OperationHistory { ...@@ -50,12 +50,12 @@ public class OperationHistory {
this.id = id; this.id = id;
} }
public String getAccount() { public String getUsername() {
return account; return username;
} }
public void setAccount(String account) { public void setUsername(String username) {
this.account = account; this.username = username;
} }
public long getOperationTime() { public long getOperationTime() {
......
...@@ -21,8 +21,8 @@ public class LoginHistoryDto { ...@@ -21,8 +21,8 @@ public class LoginHistoryDto {
} }
public LoginHistoryDto(LoginHistory loginHistory) { public LoginHistoryDto(LoginHistory loginHistory) {
if (loginHistory.getAccount() != null) if (loginHistory.getUsername() != null)
this.account = loginHistory.getAccount(); this.account = loginHistory.getUsername();
if (loginHistory.getNickname() != null) if (loginHistory.getNickname() != null)
this.nickname = loginHistory.getNickname(); this.nickname = loginHistory.getNickname();
if (loginHistory.getLoginIp() != null) if (loginHistory.getLoginIp() != null)
......
...@@ -21,8 +21,8 @@ public class OperationHistoryDto { ...@@ -21,8 +21,8 @@ public class OperationHistoryDto {
} }
public OperationHistoryDto(OperationHistory operationHistory) { public OperationHistoryDto(OperationHistory operationHistory) {
if (operationHistory.getAccount() != null) if (operationHistory.getUsername() != null)
this.account = operationHistory.getAccount(); this.account = operationHistory.getUsername();
if (operationHistory.getNickname() != null) if (operationHistory.getNickname() != null)
this.nickname = operationHistory.getNickname(); this.nickname = operationHistory.getNickname();
if (operationHistory.getLoginIp() != null) if (operationHistory.getLoginIp() != null)
......
...@@ -8,11 +8,11 @@ import org.springframework.data.mongodb.repository.MongoRepository; ...@@ -8,11 +8,11 @@ import org.springframework.data.mongodb.repository.MongoRepository;
import java.util.List; import java.util.List;
public interface LoginHistoryRepository extends MongoRepository<LoginHistory, String> { public interface LoginHistoryRepository extends MongoRepository<LoginHistory, String> {
LoginHistory findFirstByAccount(String account); LoginHistory findFirstByUsername(String username);
Page<LoginHistory> findByAdministratorAndLoginTimeGreaterThanOrderByLoginTime(String administrator, long time, Pageable pageable); Page<LoginHistory> findByAdministratorAndLoginTimeGreaterThanOrderByLoginTime(String administrator, long time, Pageable pageable);
Page<LoginHistory> findByAccountAndLoginTimeGreaterThanOrderByLoginTime(String account, long time, Pageable pageable); Page<LoginHistory> findByUsernameAndLoginTimeGreaterThanOrderByLoginTime(String username, long time, Pageable pageable);
int countByAccount(String account); int countByUsername(String username);
} }
...@@ -6,10 +6,10 @@ import org.springframework.data.domain.Pageable; ...@@ -6,10 +6,10 @@ import org.springframework.data.domain.Pageable;
import org.springframework.data.mongodb.repository.MongoRepository; import org.springframework.data.mongodb.repository.MongoRepository;
public interface OperationHistoryRepository extends MongoRepository<OperationHistory, String> { public interface OperationHistoryRepository extends MongoRepository<OperationHistory, String> {
OperationHistory findFirstByAccount(String account); OperationHistory findFirstByUsername(String username);
Page<OperationHistory> findByAdministratorAndOperationTimeGreaterThanOrderByOperationTimeDesc(String administrator, long time, Pageable pageable); Page<OperationHistory> findByAdministratorAndOperationTimeGreaterThanOrderByOperationTimeDesc(String administrator, long time, Pageable pageable);
Page<OperationHistory> findByAccountAndOperationTimeGreaterThanOrderByOperationTimeDesc(String account, long time, Pageable pageable); Page<OperationHistory> findByUsernameAndOperationTimeGreaterThanOrderByOperationTimeDesc(String username, long time, Pageable pageable);
int countByAccount(String account); int countByUsername(String username);
} }
...@@ -39,12 +39,12 @@ public class HistoryServiceImpl implements HistoryService { ...@@ -39,12 +39,12 @@ public class HistoryServiceImpl implements HistoryService {
Account account = accountRepository.findById(username).orElse(null); Account account = accountRepository.findById(username).orElse(null);
if (account == null) if (account == null)
throw new ClientRequestException(AccountErrorCode.NAMENOTEXIST); throw new ClientRequestException(AccountErrorCode.NAMENOTEXIST);
int num = loginHistoryRepository.countByAccount(username); int num = loginHistoryRepository.countByUsername(username);
if (num > 10000) if (num > 10000)
loginHistoryRepository.delete(loginHistoryRepository.findFirstByAccount(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.setAccount(username); loginHistory.setUsername(username);
if (account.getParent() == null) if (account.getParent() == null)
loginHistory.setAdministrator(username); loginHistory.setAdministrator(username);
else else
...@@ -58,12 +58,12 @@ public class HistoryServiceImpl implements HistoryService { ...@@ -58,12 +58,12 @@ public class HistoryServiceImpl implements HistoryService {
Account account = accountRepository.findById(username).orElse(null); Account account = accountRepository.findById(username).orElse(null);
if (account == null) if (account == null)
throw new ClientRequestException(AccountErrorCode.NAMENOTEXIST); throw new ClientRequestException(AccountErrorCode.NAMENOTEXIST);
int num = operationHistoryRepository.countByAccount(username); int num = operationHistoryRepository.countByUsername(username);
if (num > 10000) if (num > 10000)
operationHistoryRepository.delete(operationHistoryRepository.findFirstByAccount(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.setAccount(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);
...@@ -88,7 +88,7 @@ public class HistoryServiceImpl implements HistoryService { ...@@ -88,7 +88,7 @@ public class HistoryServiceImpl implements HistoryService {
if (account.getParent() == null) { if (account.getParent() == null) {
loginHistoryPage = loginHistoryRepository.findByAdministratorAndLoginTimeGreaterThanOrderByLoginTime(username, time, pageable); loginHistoryPage = loginHistoryRepository.findByAdministratorAndLoginTimeGreaterThanOrderByLoginTime(username, time, pageable);
} else { } else {
loginHistoryPage = loginHistoryRepository.findByAccountAndLoginTimeGreaterThanOrderByLoginTime(username, time, pageable); loginHistoryPage = loginHistoryRepository.findByUsernameAndLoginTimeGreaterThanOrderByLoginTime(username, time, pageable);
} }
List<LoginHistoryDto> loginHistoryDtoList = new ArrayList<>(); List<LoginHistoryDto> loginHistoryDtoList = new ArrayList<>();
...@@ -120,7 +120,7 @@ public class HistoryServiceImpl implements HistoryService { ...@@ -120,7 +120,7 @@ public class HistoryServiceImpl implements HistoryService {
if (account.getParent() == null) { if (account.getParent() == null) {
operationHistories = operationHistoryRepository.findByAdministratorAndOperationTimeGreaterThanOrderByOperationTimeDesc(username, time, pageable); operationHistories = operationHistoryRepository.findByAdministratorAndOperationTimeGreaterThanOrderByOperationTimeDesc(username, time, pageable);
} else { } else {
operationHistories = operationHistoryRepository.findByAccountAndOperationTimeGreaterThanOrderByOperationTimeDesc(username, time, pageable); operationHistories = operationHistoryRepository.findByUsernameAndOperationTimeGreaterThanOrderByOperationTimeDesc(username, time, pageable);
} }
List<OperationHistoryDto> operationHistoryDtos = new ArrayList<>(); List<OperationHistoryDto> operationHistoryDtos = new ArrayList<>();
......
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