Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ public class CaseStatsOverviewResponse {
private int recentCase;
private int todayCase;
private String mostCase;
private String patrolRegion;
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,25 @@

import com.example.backend.common.domain.CaseStatsOverviewEntity;
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 java.util.Optional;

@Repository
public interface CaseStatsOverviewRepository extends JpaRepository<CaseStatsOverviewEntity, Integer> {
Optional<CaseStatsOverviewEntity> findByOfficeId(int officeId);

@Query(value = """
SELECT ci.address
FROM case_stats_category csc
JOIN cctv_info ci ON csc.cctv_id = ci.id
WHERE csc.office_id = :officeId
AND csc.date >= NOW() - INTERVAL '1 month'
GROUP BY ci.address
ORDER BY SUM(csc.fire_count + csc.assault_count + csc.crowd_congestion_count + csc.weapon_count + csc.swoon_count) DESC
LIMIT 1
""", nativeQuery = true)
Optional<String> findAddressWithMostIncidentsLastMonth(@Param("officeId") int officeId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,16 @@ public CaseStatsOverviewResponse getOverview(HttpSession session) {
CaseStatsOverviewEntity stats = statsOverviewRepository.findByOfficeId(officeId)
.orElseThrow(() -> new NoSuchElementException("해당 office_id에 대한 통계 데이터가 없습니다."));

// 최근 한 달간 데이터를 기준으로 사건 건수가 가장 많은 CCTV 주소 조회
String patrolRegionAddress = statsOverviewRepository.findAddressWithMostIncidentsLastMonth(officeId)
.orElse("정보 없음");

// 응답 생성 (순찰 강화 지역은 주소만 포함)
return new CaseStatsOverviewResponse(
stats.getRecentCaseCount(), // 지난 7일간 사건 수
stats.getTodayCaseCount(), // 오늘 사건 수
stats.getMostCase().name() // 이번 달 가장 많이 발생 한 사건 유형
stats.getMostCase().name(), // 이번 달 가장 많이 발생한 사건 유형
patrolRegionAddress // 순찰 강화 지역 (주소)
);
}

Expand Down
Loading