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

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package com.example.backend.dashboard.controller;

import com.example.backend.dashboard.dto.*;
import com.example.backend.dashboard.service.DashboardService;
import jakarta.servlet.http.HttpSession;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Collections;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/api/v1/case")
@RequiredArgsConstructor
public class DashboardController {

private final DashboardService dashboardService;

// 사건 정보 조회
@GetMapping("")
public ResponseEntity<?> getCases(HttpSession session) {
List<DashboardResponse> cases = dashboardService.getCases(session);
if (cases.isEmpty()) {
return ResponseEntity.status(404)
.body(Collections.singletonMap("message", "사건이 없습니다."));
}
return ResponseEntity.ok(cases);
}

// 사건 영상 확인
@GetMapping("/{id}")
public ResponseEntity<?> getCaseVideo(@PathVariable("id") int id, HttpSession session) {
Map<String, String> videoResponse = dashboardService.getCaseVideo(id, session);
return ResponseEntity.ok(videoResponse);
}

// 출동 | 미출동 클릭 시 => 1. 이미 출동인 상태 or 2. state를 업데이트
@PutMapping("/ready/{id}")
public ResponseEntity<?> updateCaseState(@PathVariable("id") int id,
@RequestBody StateRequest request,
HttpSession session) {
Map<Integer, String> message = dashboardService.updateCaseState(id, request, session);
return ResponseEntity.ok(message);
}

// 출동 중인 사건 해결 처리
@PutMapping("/complete/{id}")
public ResponseEntity<?> completeCase(@PathVariable("id") int id,
@RequestBody SurveyRequest surveyRequest,
HttpSession session) {
Map<Integer, String> completedCase = dashboardService.completeCase(id, surveyRequest, session);
return ResponseEntity.ok(completedCase);
}

}

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

@Data
@Builder
public class ProgressResponse {
public class DashboardResponse {
private Integer id;
private String police_name;
private String police_rank;
Expand All @@ -21,22 +21,18 @@ public class ProgressResponse {

private Integer level;
private CaseCategory category;
private String video;
private CaseState state;
private String memo;

public static ProgressResponse fromEntity(CaseEntity entity) {
return ProgressResponse.builder()
public static DashboardResponse fromEntity(CaseEntity entity) {
return DashboardResponse.builder()
.id(entity.getId())
.police_name(entity.getPolice().getName())
.police_rank(String.valueOf(entity.getPolice().getRank()))
.police_name(entity.getPolice() != null ? entity.getPolice().getName() : null)
.police_rank(entity.getPolice() != null ? String.valueOf(entity.getPolice().getRank()) : null)
.address(entity.getCctv().getAddress())
.date(entity.getDate())
.level(entity.getLevel())
.category(entity.getCategory())
.video(entity.getVideo())
.state(entity.getState())
.memo(entity.getMemo())
.build();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package com.example.backend.dashboard.dto;

import com.example.backend.common.domain.CaseEntity;
import com.example.backend.common.domain.CaseEntity.CaseState;
import lombok.Getter;
import lombok.Setter;

@Getter
@Setter
public class AlarmRequest {
public class StateRequest {
private CaseState state; // "출동" or "미출동"
private CaseEntity.CaseCategory category;
}

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.example.backend.dashboard.repository;

import com.example.backend.common.domain.CaseEntity;
import org.springframework.data.jpa.repository.JpaRepository;

import java.util.List;

public interface DashboardRepository extends JpaRepository<CaseEntity, Integer> {
List<CaseEntity> findAllByOfficeIdAndStateInOrderById(int officeId, List<CaseEntity.CaseState> states);

}

This file was deleted.

Loading
Loading