@@ -35,9 +35,6 @@ public class MonitoringStatusResponse {
|
|||||||
@JsonProperty("is_active")
|
@JsonProperty("is_active")
|
||||||
private boolean isActive;
|
private boolean isActive;
|
||||||
|
|
||||||
@JsonProperty("new_violations_count")
|
|
||||||
private long newViolationsCount;
|
|
||||||
|
|
||||||
@JsonProperty("need_add_tokens")
|
@JsonProperty("need_add_tokens")
|
||||||
private boolean needAddTokens;
|
private boolean needAddTokens;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,76 +0,0 @@
|
|||||||
package ru.soune.nocopy.entity.monitoring;
|
|
||||||
|
|
||||||
import jakarta.persistence.*;
|
|
||||||
import lombok.*;
|
|
||||||
import ru.soune.nocopy.entity.file.FileEntity;
|
|
||||||
|
|
||||||
import java.time.LocalDateTime;
|
|
||||||
|
|
||||||
@Data
|
|
||||||
@Builder
|
|
||||||
@NoArgsConstructor
|
|
||||||
@AllArgsConstructor
|
|
||||||
@Entity
|
|
||||||
@Table(name = "found_violations",
|
|
||||||
indexes = {
|
|
||||||
@Index(name = "idx_file_id", columnList = "file_id"),
|
|
||||||
@Index(name = "idx_found_at", columnList = "found_at")
|
|
||||||
})
|
|
||||||
public class FoundViolationEntity {
|
|
||||||
|
|
||||||
@Id
|
|
||||||
@GeneratedValue(strategy = GenerationType.UUID)
|
|
||||||
private String id;
|
|
||||||
|
|
||||||
@ManyToOne(fetch = FetchType.LAZY)
|
|
||||||
@JoinColumn(name = "file_id", nullable = false)
|
|
||||||
private FileEntity file;
|
|
||||||
|
|
||||||
@Column(name = "user_id", nullable = false)
|
|
||||||
private Long userId;
|
|
||||||
|
|
||||||
@Column(name = "file_id_copy", nullable = false)
|
|
||||||
private String fileId;
|
|
||||||
|
|
||||||
@Column(name = "file_name_copy")
|
|
||||||
private String fileName;
|
|
||||||
|
|
||||||
@Column(name = "found_url", nullable = false, length = 2048)
|
|
||||||
private String foundUrl;
|
|
||||||
|
|
||||||
@Column(name = "page_url", length = 2048)
|
|
||||||
private String pageUrl;
|
|
||||||
|
|
||||||
@Column(name = "page_title")
|
|
||||||
private String pageTitle;
|
|
||||||
|
|
||||||
@Column(name = "host")
|
|
||||||
private String host;
|
|
||||||
|
|
||||||
@Column(name = "image_width")
|
|
||||||
private Integer imageWidth;
|
|
||||||
|
|
||||||
@Column(name = "image_height")
|
|
||||||
private Integer imageHeight;
|
|
||||||
|
|
||||||
@Enumerated(EnumType.STRING)
|
|
||||||
@Column(name = "search_engine", nullable = false)
|
|
||||||
private SearchEngine searchEngine;
|
|
||||||
|
|
||||||
@Column(name = "search_session_id")
|
|
||||||
private String searchSessionId;
|
|
||||||
|
|
||||||
@Column(name = "found_at", nullable = false)
|
|
||||||
private LocalDateTime foundAt;
|
|
||||||
|
|
||||||
@Column(name = "is_new", nullable = false)
|
|
||||||
private boolean isNew = true;
|
|
||||||
|
|
||||||
@Column(name = "is_notified", nullable = false)
|
|
||||||
private boolean isNotified = false;
|
|
||||||
|
|
||||||
@PrePersist
|
|
||||||
public void prePersist() {
|
|
||||||
this.foundAt = LocalDateTime.now();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,30 +0,0 @@
|
|||||||
package ru.soune.nocopy.repository;
|
|
||||||
|
|
||||||
import org.springframework.data.domain.Pageable;
|
|
||||||
import org.springframework.data.jpa.repository.JpaRepository;
|
|
||||||
import org.springframework.data.jpa.repository.Query;
|
|
||||||
import org.springframework.data.repository.query.Param;
|
|
||||||
import org.springframework.stereotype.Repository;
|
|
||||||
import ru.soune.nocopy.entity.monitoring.FoundViolationEntity;
|
|
||||||
|
|
||||||
import java.time.LocalDateTime;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
@Repository
|
|
||||||
public interface FoundViolationRepository extends JpaRepository<FoundViolationEntity, String> {
|
|
||||||
|
|
||||||
List<FoundViolationEntity> findByFileIdOrderByFoundAtDesc(String fileId);
|
|
||||||
|
|
||||||
List<FoundViolationEntity> findByUserIdOrderByFoundAtDesc(Long userId);
|
|
||||||
|
|
||||||
@Query("SELECT fv FROM FoundViolationEntity fv WHERE fv.userId = :userId AND fv.isNew = true")
|
|
||||||
List<FoundViolationEntity> findNewViolationsByUser(@Param("userId") Long userId);
|
|
||||||
|
|
||||||
@Query("SELECT fv FROM FoundViolationEntity fv WHERE fv.file.id = :fileId AND fv.foundUrl = :foundUrl")
|
|
||||||
List<FoundViolationEntity> findDuplicate(@Param("fileId") String fileId, @Param("foundUrl") String foundUrl);
|
|
||||||
|
|
||||||
List<FoundViolationEntity> findByFoundAtBetween(LocalDateTime start, LocalDateTime end);
|
|
||||||
|
|
||||||
@Query("SELECT COUNT(fv) FROM FoundViolationEntity fv WHERE fv.userId = :userId AND fv.isNew = true")
|
|
||||||
long countNewByUserId(@Param("userId") Long userId);
|
|
||||||
}
|
|
||||||
@@ -15,7 +15,6 @@ import ru.soune.nocopy.entity.user.User;
|
|||||||
import ru.soune.nocopy.exception.UserNotHavePermission;
|
import ru.soune.nocopy.exception.UserNotHavePermission;
|
||||||
import ru.soune.nocopy.repository.FileEntityRepository;
|
import ru.soune.nocopy.repository.FileEntityRepository;
|
||||||
import ru.soune.nocopy.repository.FileMonitoringRepository;
|
import ru.soune.nocopy.repository.FileMonitoringRepository;
|
||||||
import ru.soune.nocopy.repository.FoundViolationRepository;
|
|
||||||
import ru.soune.nocopy.repository.UserRepository;
|
import ru.soune.nocopy.repository.UserRepository;
|
||||||
import ru.soune.nocopy.service.tariff.TariffService;
|
import ru.soune.nocopy.service.tariff.TariffService;
|
||||||
|
|
||||||
@@ -31,8 +30,6 @@ public class FileMonitoringService {
|
|||||||
|
|
||||||
private final FileEntityRepository fileRepository;
|
private final FileEntityRepository fileRepository;
|
||||||
|
|
||||||
private final FoundViolationRepository violationRepository;
|
|
||||||
|
|
||||||
private final TariffService tariffService;
|
private final TariffService tariffService;
|
||||||
|
|
||||||
private final UserRepository userRepository;
|
private final UserRepository userRepository;
|
||||||
@@ -93,7 +90,6 @@ public class FileMonitoringService {
|
|||||||
FileMonitoringEntity monitoring = monitoringRepository.findByFileId(fileId).orElse(null);
|
FileMonitoringEntity monitoring = monitoringRepository.findByFileId(fileId).orElse(null);
|
||||||
FileEntity file = fileRepository.findById(fileId).orElseThrow();
|
FileEntity file = fileRepository.findById(fileId).orElseThrow();
|
||||||
User user = userRepository.findById(userId).orElseThrow();
|
User user = userRepository.findById(userId).orElseThrow();
|
||||||
long newViolations = violationRepository.countNewByUserId(userId);
|
|
||||||
|
|
||||||
return MonitoringStatusResponse.builder()
|
return MonitoringStatusResponse.builder()
|
||||||
.fileId(fileId)
|
.fileId(fileId)
|
||||||
@@ -103,7 +99,6 @@ public class FileMonitoringService {
|
|||||||
.lastRun(monitoring != null ? monitoring.getLastRun() : null)
|
.lastRun(monitoring != null ? monitoring.getLastRun() : null)
|
||||||
.lastRunStatus(monitoring != null ? monitoring.getLastRunStatus() : null)
|
.lastRunStatus(monitoring != null ? monitoring.getLastRunStatus() : null)
|
||||||
.isActive(monitoring != null && monitoring.isActive())
|
.isActive(monitoring != null && monitoring.isActive())
|
||||||
.newViolationsCount(newViolations)
|
|
||||||
.needAddTokens(checkTokensForMonitoring(user, monitoring.getMonitoringType()))
|
.needAddTokens(checkTokensForMonitoring(user, monitoring.getMonitoringType()))
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user