|
|
|
@@ -6,16 +6,13 @@ import org.springframework.stereotype.Service;
|
|
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
import ru.soune.nocopy.dto.search.GlobalSearchStatisticsResponse;
|
|
|
|
|
import ru.soune.nocopy.entity.company.Company;
|
|
|
|
|
import ru.soune.nocopy.entity.search.GlobalSearchResult;
|
|
|
|
|
import ru.soune.nocopy.entity.search.GlobalSearchTask;
|
|
|
|
|
import ru.soune.nocopy.entity.user.User;
|
|
|
|
|
import ru.soune.nocopy.repository.GlobalSearchResultRepository;
|
|
|
|
|
import ru.soune.nocopy.repository.GlobalSearchTaskRepository;
|
|
|
|
|
import ru.soune.nocopy.repository.UserRepository;
|
|
|
|
|
import ru.soune.nocopy.repository.ViolationRepository;
|
|
|
|
|
import ru.soune.nocopy.repository.*;
|
|
|
|
|
|
|
|
|
|
import java.time.LocalDateTime;
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
import java.util.Arrays;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
|
|
@Slf4j
|
|
|
|
@@ -35,7 +32,7 @@ public class GlobalSearchStatisticsService {
|
|
|
|
|
public GlobalSearchStatisticsResponse getStatistics(Long userId, Integer limit, Integer days) {
|
|
|
|
|
User user = userRepository.findById(userId).orElseThrow();
|
|
|
|
|
Company company = user.getCompany();
|
|
|
|
|
List<Long> userIds = company == null ? Arrays.asList(userId):
|
|
|
|
|
List<Long> userIds = company == null ? List.of(userId) :
|
|
|
|
|
user.getCompany()
|
|
|
|
|
.getUsers()
|
|
|
|
|
.stream()
|
|
|
|
@@ -83,9 +80,16 @@ public class GlobalSearchStatisticsService {
|
|
|
|
|
List<GlobalSearchStatisticsResponse.SearchStatDto> recentSearchDtos = new ArrayList<>();
|
|
|
|
|
|
|
|
|
|
for (GlobalSearchTask task : recentTasks) {
|
|
|
|
|
long violationsCount = getViolationsCountForTask(task.getTaskId());
|
|
|
|
|
List<GlobalSearchResult> globalSearchResults = resultRepository.findByTaskId(task.getTaskId());
|
|
|
|
|
List<String> fileIds = globalSearchResults.stream()
|
|
|
|
|
.map(GlobalSearchResult::getFileId)
|
|
|
|
|
.toList();
|
|
|
|
|
|
|
|
|
|
recentSearchDtos.add(GlobalSearchStatisticsResponse.SearchStatDto.fromEntity(task, violationsCount));
|
|
|
|
|
GlobalSearchStatisticsResponse.SearchStatDto searchStatDto =
|
|
|
|
|
GlobalSearchStatisticsResponse.SearchStatDto.fromEntity(task,
|
|
|
|
|
violationRepository.countByFileEntityIdIn(fileIds), fileIds);
|
|
|
|
|
|
|
|
|
|
recentSearchDtos.add(searchStatDto);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return GlobalSearchStatisticsResponse.builder()
|
|
|
|
@@ -94,16 +98,4 @@ public class GlobalSearchStatisticsService {
|
|
|
|
|
.recentSearches(recentSearchDtos)
|
|
|
|
|
.build();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Transactional(readOnly = true)
|
|
|
|
|
public long getViolationsCountForTask(String taskId) {
|
|
|
|
|
List<String> fileIds = resultRepository.findByTaskId(taskId).stream()
|
|
|
|
|
.map(result -> result.getFileId())
|
|
|
|
|
.toList();
|
|
|
|
|
|
|
|
|
|
if (fileIds.isEmpty()) {
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
return violationRepository.countByFileEntityIdIn(fileIds);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|