Commit 319323e5 authored by renjie's avatar renjie

操作日志

parent 97bc113a
......@@ -6,7 +6,11 @@ import org.springframework.data.domain.Pageable;
import org.springframework.data.mongodb.repository.MongoRepository;
public interface LoginHistoryRepository extends MongoRepository<LoginHistory, String> {
LoginHistory findFirstByAccount(String account);
Page<LoginHistory> findByAdministratorOrderByLoginTime(String administrator, Pageable pageable);
Page<LoginHistory> findByAccountOrderByLoginTime(String account, Pageable pageable);
int countByAccount(String account);
}
......@@ -6,6 +6,10 @@ import org.springframework.data.domain.Pageable;
import org.springframework.data.mongodb.repository.MongoRepository;
public interface OperationHistoryRepository extends MongoRepository<OperationHistory, String> {
OperationHistory findFirstByAccount(String account);
Page<OperationHistory> findByAdministratorOrderByOperationTimeDesc(String administrator, Pageable pageable);
Page<OperationHistory> findByAccountOrderByOperationTimeDesc(String account, Pageable pageable);
int countByAccount(String account);
}
......@@ -38,6 +38,9 @@ public class HistoryServiceImpl implements HistoryService {
Account account = accountRepository.findById(username).orElse(null);
if (account == null)
throw new ClientRequestException(AccountErrorCode.NAMENOTEXIST);
int num = loginHistoryRepository.countByAccount(username);
if (num > 10000)
loginHistoryRepository.delete(loginHistoryRepository.findFirstByAccount(username));
LoginHistory loginHistory = new LoginHistory(loginHistoryDto);
loginHistory.setLoginTime(Instant.now().toEpochMilli());
loginHistory.setAccount(username);
......@@ -54,6 +57,9 @@ public class HistoryServiceImpl implements HistoryService {
Account account = accountRepository.findById(username).orElse(null);
if (account == null)
throw new ClientRequestException(AccountErrorCode.NAMENOTEXIST);
int num = operationHistoryRepository.countByAccount(username);
if (num > 10000)
operationHistoryRepository.delete(operationHistoryRepository.findFirstByAccount(username));
OperationHistory operationHistory = new OperationHistory(operationHistoryDto);
operationHistory.setOperationTime(Instant.now().toEpochMilli());
operationHistory.setAccount(username);
......
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