File tree Expand file tree Collapse file tree 3 files changed +22
-1
lines changed
backend/src/main/java/com/example/backend/analysis Expand file tree Collapse file tree 3 files changed +22
-1
lines changed Original file line number Diff line number Diff line change @@ -8,4 +8,5 @@ public class CaseStatsOverviewResponse {
88 private int recentCase ;
99 private int todayCase ;
1010 private String mostCase ;
11+ private String patrolRegion ;
1112}
Original file line number Diff line number Diff line change 22
33import com .example .backend .common .domain .CaseStatsOverviewEntity ;
44import org .springframework .data .jpa .repository .JpaRepository ;
5+ import org .springframework .data .jpa .repository .Query ;
6+ import org .springframework .data .repository .query .Param ;
57import org .springframework .stereotype .Repository ;
68
79import java .util .Optional ;
810
911@ Repository
1012public interface CaseStatsOverviewRepository extends JpaRepository <CaseStatsOverviewEntity , Integer > {
1113 Optional <CaseStatsOverviewEntity > findByOfficeId (int officeId );
14+
15+ @ Query (value = """
16+ SELECT ci.address
17+ FROM case_stats_category csc
18+ JOIN cctv_info ci ON csc.cctv_id = ci.id
19+ WHERE csc.office_id = :officeId
20+ AND csc.date >= NOW() - INTERVAL '1 month'
21+ GROUP BY ci.address
22+ ORDER BY SUM(csc.fire_count + csc.assault_count + csc.crowd_congestion_count + csc.weapon_count + csc.swoon_count) DESC
23+ LIMIT 1
24+ """ , nativeQuery = true )
25+ Optional <String > findAddressWithMostIncidentsLastMonth (@ Param ("officeId" ) int officeId );
1226}
Original file line number Diff line number Diff line change @@ -58,10 +58,16 @@ public CaseStatsOverviewResponse getOverview(HttpSession session) {
5858 CaseStatsOverviewEntity stats = statsOverviewRepository .findByOfficeId (officeId )
5959 .orElseThrow (() -> new NoSuchElementException ("해당 office_id에 대한 통계 데이터가 없습니다." ));
6060
61+ // 최근 한 달간 데이터를 기준으로 사건 건수가 가장 많은 CCTV 주소 조회
62+ String patrolRegionAddress = statsOverviewRepository .findAddressWithMostIncidentsLastMonth (officeId )
63+ .orElse ("정보 없음" );
64+
65+ // 응답 생성 (순찰 강화 지역은 주소만 포함)
6166 return new CaseStatsOverviewResponse (
6267 stats .getRecentCaseCount (), // 지난 7일간 사건 수
6368 stats .getTodayCaseCount (), // 오늘 사건 수
64- stats .getMostCase ().name () // 이번 달 가장 많이 발생 한 사건 유형
69+ stats .getMostCase ().name (), // 이번 달 가장 많이 발생한 사건 유형
70+ patrolRegionAddress // 순찰 강화 지역 (주소)
6571 );
6672 }
6773
You can’t perform that action at this time.
0 commit comments