Skip to content

Commit 33d819c

Browse files
authored
Merge pull request #97 from kookmin-sw/backend
[Backend] merge: 4차 API 연동
2 parents dcc3550 + 430d8b1 commit 33d819c

17 files changed

+242
-411
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

backend/src/main/java/com/example/backend/dashboard/controller/AlarmListController.java

Lines changed: 0 additions & 40 deletions
This file was deleted.
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
package com.example.backend.dashboard.controller;
2+
3+
import com.example.backend.dashboard.dto.*;
4+
import com.example.backend.dashboard.service.DashboardService;
5+
import jakarta.servlet.http.HttpSession;
6+
import lombok.RequiredArgsConstructor;
7+
import org.springframework.http.ResponseEntity;
8+
import org.springframework.web.bind.annotation.*;
9+
10+
import java.util.Collections;
11+
import java.util.List;
12+
import java.util.Map;
13+
14+
@RestController
15+
@RequestMapping("/api/v1/case")
16+
@RequiredArgsConstructor
17+
public class DashboardController {
18+
19+
private final DashboardService dashboardService;
20+
21+
// 사건 정보 조회
22+
@GetMapping("")
23+
public ResponseEntity<?> getCases(HttpSession session) {
24+
List<DashboardResponse> cases = dashboardService.getCases(session);
25+
if (cases.isEmpty()) {
26+
return ResponseEntity.status(404)
27+
.body(Collections.singletonMap("message", "사건이 없습니다."));
28+
}
29+
return ResponseEntity.ok(cases);
30+
}
31+
32+
// 사건 영상 확인
33+
@GetMapping("/{id}")
34+
public ResponseEntity<?> getCaseVideo(@PathVariable("id") int id, HttpSession session) {
35+
Map<String, String> videoResponse = dashboardService.getCaseVideo(id, session);
36+
return ResponseEntity.ok(videoResponse);
37+
}
38+
39+
// 출동 | 미출동 클릭 시 => 1. 이미 출동인 상태 or 2. state를 업데이트
40+
@PutMapping("/ready/{id}")
41+
public ResponseEntity<?> updateCaseState(@PathVariable("id") int id,
42+
@RequestBody StateRequest request,
43+
HttpSession session) {
44+
Map<Integer, String> message = dashboardService.updateCaseState(id, request, session);
45+
return ResponseEntity.ok(message);
46+
}
47+
48+
// 출동 중인 사건 해결 처리
49+
@PutMapping("/complete/{id}")
50+
public ResponseEntity<?> completeCase(@PathVariable("id") int id,
51+
@RequestBody SurveyRequest surveyRequest,
52+
HttpSession session) {
53+
Map<Integer, String> completedCase = dashboardService.completeCase(id, surveyRequest, session);
54+
return ResponseEntity.ok(completedCase);
55+
}
56+
57+
}

backend/src/main/java/com/example/backend/dashboard/controller/ProgressController.java

Lines changed: 0 additions & 56 deletions
This file was deleted.

backend/src/main/java/com/example/backend/dashboard/dto/AlarmResponse.java

Lines changed: 0 additions & 55 deletions
This file was deleted.

backend/src/main/java/com/example/backend/dashboard/dto/ProgressResponse.java renamed to backend/src/main/java/com/example/backend/dashboard/dto/DashboardResponse.java

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
@Data
1212
@Builder
13-
public class ProgressResponse {
13+
public class DashboardResponse {
1414
private Integer id;
1515
private String police_name;
1616
private String police_rank;
@@ -21,22 +21,18 @@ public class ProgressResponse {
2121

2222
private Integer level;
2323
private CaseCategory category;
24-
private String video;
2524
private CaseState state;
26-
private String memo;
2725

28-
public static ProgressResponse fromEntity(CaseEntity entity) {
29-
return ProgressResponse.builder()
26+
public static DashboardResponse fromEntity(CaseEntity entity) {
27+
return DashboardResponse.builder()
3028
.id(entity.getId())
31-
.police_name(entity.getPolice().getName())
32-
.police_rank(String.valueOf(entity.getPolice().getRank()))
29+
.police_name(entity.getPolice() != null ? entity.getPolice().getName() : null)
30+
.police_rank(entity.getPolice() != null ? String.valueOf(entity.getPolice().getRank()) : null)
3331
.address(entity.getCctv().getAddress())
3432
.date(entity.getDate())
3533
.level(entity.getLevel())
3634
.category(entity.getCategory())
37-
.video(entity.getVideo())
3835
.state(entity.getState())
39-
.memo(entity.getMemo())
4036
.build();
4137
}
4238

backend/src/main/java/com/example/backend/dashboard/dto/AlarmRequest.java renamed to backend/src/main/java/com/example/backend/dashboard/dto/StateRequest.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
package com.example.backend.dashboard.dto;
22

3+
import com.example.backend.common.domain.CaseEntity;
34
import com.example.backend.common.domain.CaseEntity.CaseState;
45
import lombok.Getter;
56
import lombok.Setter;
67

78
@Getter
89
@Setter
9-
public class AlarmRequest {
10+
public class StateRequest {
1011
private CaseState state; // "출동" or "미출동"
12+
private CaseEntity.CaseCategory category;
1113
}

backend/src/main/java/com/example/backend/dashboard/dto/SurveyResponse.java

Lines changed: 0 additions & 13 deletions
This file was deleted.

0 commit comments

Comments
 (0)