Skip to content

Commit abadb4f

Browse files
authored
Merge pull request #94 from kookmin-sw/feat/93
[Backend] feat: Overview API 에 순찰 강화 지역 추가
2 parents 268b575 + d0673b2 commit abadb4f

File tree

3 files changed

+22
-1
lines changed

3 files changed

+22
-1
lines changed

backend/src/main/java/com/example/backend/analysis/dto/CaseStatsOverviewResponse.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff 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
}

backend/src/main/java/com/example/backend/analysis/repository/CaseStatsOverviewRepository.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,25 @@
22

33
import com.example.backend.common.domain.CaseStatsOverviewEntity;
44
import org.springframework.data.jpa.repository.JpaRepository;
5+
import org.springframework.data.jpa.repository.Query;
6+
import org.springframework.data.repository.query.Param;
57
import org.springframework.stereotype.Repository;
68

79
import java.util.Optional;
810

911
@Repository
1012
public 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
}

backend/src/main/java/com/example/backend/analysis/service/CaseStatsService.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff 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

0 commit comments

Comments
 (0)