-
Notifications
You must be signed in to change notification settings - Fork 0
[refactor/#131-refactor-safety-calculator] 안전 점수 계산 최적화 #132
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: dev
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -12,18 +12,15 @@ public class HomeSafetyRepository { | |||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| // 범죄주의구역 내부 최대 리스크 레벨 | ||||||||||||||||||||||||||||||||||||||||||||||||
| public int findInsideMaxRiskLevel(double lat, double lon) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| String sql = """ | ||||||||||||||||||||||||||||||||||||||||||||||||
| SELECT COALESCE(MAX(c.risk_level), 0) | ||||||||||||||||||||||||||||||||||||||||||||||||
| FROM crime_prone_area c | ||||||||||||||||||||||||||||||||||||||||||||||||
| WHERE ST_Contains( | ||||||||||||||||||||||||||||||||||||||||||||||||
| c.geometry, | ||||||||||||||||||||||||||||||||||||||||||||||||
| ST_Transform( | ||||||||||||||||||||||||||||||||||||||||||||||||
| ST_SetSRID(ST_MakePoint(?1, ?2), 4326), | ||||||||||||||||||||||||||||||||||||||||||||||||
| 5179 | ||||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||||
| """; | ||||||||||||||||||||||||||||||||||||||||||||||||
| WITH target AS ( | ||||||||||||||||||||||||||||||||||||||||||||||||
| SELECT ST_Transform(ST_SetSRID(ST_MakePoint(?1, ?2), 4326), 5179) AS g | ||||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||||
| SELECT COALESCE(MAX(c.risk_level), 0) | ||||||||||||||||||||||||||||||||||||||||||||||||
| FROM crime_prone_area c, target | ||||||||||||||||||||||||||||||||||||||||||||||||
| WHERE c.geometry && target.g | ||||||||||||||||||||||||||||||||||||||||||||||||
| AND ST_Contains(c.geometry, target.g) | ||||||||||||||||||||||||||||||||||||||||||||||||
| """; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| return ((Number) em.createNativeQuery(sql) | ||||||||||||||||||||||||||||||||||||||||||||||||
| .setParameter(1, lon) | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -34,21 +31,17 @@ WHERE ST_Contains( | |||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| // 범죄주의구역 300m 내 존재 여부 | ||||||||||||||||||||||||||||||||||||||||||||||||
| public boolean existsCrimeWithin300m(double lat, double lon) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| String sql = """ | ||||||||||||||||||||||||||||||||||||||||||||||||
| SELECT EXISTS ( | ||||||||||||||||||||||||||||||||||||||||||||||||
| SELECT 1 | ||||||||||||||||||||||||||||||||||||||||||||||||
| FROM crime_prone_area c | ||||||||||||||||||||||||||||||||||||||||||||||||
| WHERE ST_DWithin( | ||||||||||||||||||||||||||||||||||||||||||||||||
| c.geometry, | ||||||||||||||||||||||||||||||||||||||||||||||||
| ST_Transform( | ||||||||||||||||||||||||||||||||||||||||||||||||
| ST_SetSRID(ST_MakePoint(?1, ?2), 4326), | ||||||||||||||||||||||||||||||||||||||||||||||||
| 5179 | ||||||||||||||||||||||||||||||||||||||||||||||||
| ), | ||||||||||||||||||||||||||||||||||||||||||||||||
| 300 | ||||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||||
| """; | ||||||||||||||||||||||||||||||||||||||||||||||||
| WITH target AS ( | ||||||||||||||||||||||||||||||||||||||||||||||||
| SELECT ST_Transform(ST_SetSRID(ST_MakePoint(?1, ?2), 4326), 5179) AS g | ||||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||||
| SELECT EXISTS ( | ||||||||||||||||||||||||||||||||||||||||||||||||
| SELECT 1 | ||||||||||||||||||||||||||||||||||||||||||||||||
| FROM crime_prone_area c, target | ||||||||||||||||||||||||||||||||||||||||||||||||
| WHERE c.geometry && ST_Expand(target.g, 300) | ||||||||||||||||||||||||||||||||||||||||||||||||
| AND ST_DWithin(c.geometry, target.g, 300) | ||||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||||
| """; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| return (Boolean) em.createNativeQuery(sql) | ||||||||||||||||||||||||||||||||||||||||||||||||
| .setParameter(1, lon) | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -59,51 +52,38 @@ WHERE ST_DWithin( | |||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| // 경찰서 / 파출소 최소 거리 | ||||||||||||||||||||||||||||||||||||||||||||||||
| public int findNearestPoliceDistanceMeter(double lat, double lon) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| String sql = """ | ||||||||||||||||||||||||||||||||||||||||||||||||
| SELECT COALESCE( | ||||||||||||||||||||||||||||||||||||||||||||||||
| MIN( | ||||||||||||||||||||||||||||||||||||||||||||||||
| ST_Distance( | ||||||||||||||||||||||||||||||||||||||||||||||||
| ST_Transform( | ||||||||||||||||||||||||||||||||||||||||||||||||
| ST_SetSRID(ST_MakePoint(p.longitude, p.latitude), 4326), | ||||||||||||||||||||||||||||||||||||||||||||||||
| 5179 | ||||||||||||||||||||||||||||||||||||||||||||||||
| ), | ||||||||||||||||||||||||||||||||||||||||||||||||
| ST_Transform( | ||||||||||||||||||||||||||||||||||||||||||||||||
| ST_SetSRID(ST_MakePoint(?1, ?2), 4326), | ||||||||||||||||||||||||||||||||||||||||||||||||
| 5179 | ||||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||||
| ), | ||||||||||||||||||||||||||||||||||||||||||||||||
| 999999 | ||||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||||
| FROM police_office p | ||||||||||||||||||||||||||||||||||||||||||||||||
| """; | ||||||||||||||||||||||||||||||||||||||||||||||||
| WITH target AS ( | ||||||||||||||||||||||||||||||||||||||||||||||||
| SELECT ST_Transform(ST_SetSRID(ST_MakePoint(?1, ?2), 4326), 5179) AS g | ||||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||||
| SELECT COALESCE( | ||||||||||||||||||||||||||||||||||||||||||||||||
| ST_Distance(p.geom_5179, target.g), | ||||||||||||||||||||||||||||||||||||||||||||||||
| 999999 | ||||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||||
| FROM police_office p, target | ||||||||||||||||||||||||||||||||||||||||||||||||
| WHERE p.geom_5179 IS NOT NULL | ||||||||||||||||||||||||||||||||||||||||||||||||
| ORDER BY p.geom_5179 <-> target.g | ||||||||||||||||||||||||||||||||||||||||||||||||
| LIMIT 1 | ||||||||||||||||||||||||||||||||||||||||||||||||
| """; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+56
to
+67
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: find . -name "HomeSafetyRepository.java" -type f 2>/dev/null | head -20Repository: D-ingle/backend Length of output: 137 🏁 Script executed: cat -n ./src/main/java/com/example/Dingle/safety/repository/HomeSafetyRepository.java | sed -n '50,80p'Repository: D-ingle/backend Length of output: 1147 🏁 Script executed: cat -n ./src/main/java/com/example/Dingle/safety/repository/HomeSafetyRepository.java | head -20Repository: D-ingle/backend Length of output: 806 🏁 Script executed: rg "findNearestPoliceDistanceMeter" --type java -A 5 -B 5Repository: D-ingle/backend Length of output: 2691 🏁 Script executed: cat -n ./src/main/java/com/example/Dingle/property/service/openAI/SafetyExplanationService.java | grep -A 30 "findNearestPoliceDistanceMeter" | head -40Repository: D-ingle/backend Length of output: 1712 🏁 Script executed: cat -n ./src/main/java/com/example/Dingle/property/service/openAI/SafetyExplanationService.java | sed -n '1,80p'Repository: D-ingle/backend Length of output: 4196 경찰서 최근접 거리 쿼리에서 빈 결과 처리 누락으로 인한 NoResultException 발생 위험 현재 쿼리 구조에서 제안된 수정처럼 수정 예시 String sql = """
WITH target AS (
SELECT ST_Transform(ST_SetSRID(ST_MakePoint(?1, ?2), 4326), 5179) AS g
)
- SELECT COALESCE(
- ST_Distance(p.geom_5179, target.g),
- 999999
- )
- FROM police_office p, target
- WHERE p.geom_5179 IS NOT NULL
- ORDER BY p.geom_5179 <-> target.g
- LIMIT 1
+ SELECT COALESCE((
+ SELECT ST_Distance(p.geom_5179, target.g)
+ FROM police_office p, target
+ WHERE p.geom_5179 IS NOT NULL
+ ORDER BY p.geom_5179 <-> target.g
+ LIMIT 1
+ ), 999999)
""";빈 📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| return ((Number) em.createNativeQuery(sql) | ||||||||||||||||||||||||||||||||||||||||||||||||
| .setParameter(1, lon) | ||||||||||||||||||||||||||||||||||||||||||||||||
| .setParameter(2, lat) | ||||||||||||||||||||||||||||||||||||||||||||||||
| .getSingleResult()).intValue(); | ||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| // CCTV 50m 내 개수 | ||||||||||||||||||||||||||||||||||||||||||||||||
| public int countCctvWithin50m(double lat, double lon) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| String sql = """ | ||||||||||||||||||||||||||||||||||||||||||||||||
| SELECT COUNT(*) | ||||||||||||||||||||||||||||||||||||||||||||||||
| FROM safety s | ||||||||||||||||||||||||||||||||||||||||||||||||
| WHERE s.infra_type = 'CCTV' | ||||||||||||||||||||||||||||||||||||||||||||||||
| AND ST_DWithin( | ||||||||||||||||||||||||||||||||||||||||||||||||
| ST_Transform( | ||||||||||||||||||||||||||||||||||||||||||||||||
| ST_SetSRID(ST_MakePoint(s.longitude, s.latitude), 4326), | ||||||||||||||||||||||||||||||||||||||||||||||||
| 5179 | ||||||||||||||||||||||||||||||||||||||||||||||||
| ), | ||||||||||||||||||||||||||||||||||||||||||||||||
| ST_Transform( | ||||||||||||||||||||||||||||||||||||||||||||||||
| ST_SetSRID(ST_MakePoint(?1, ?2), 4326), | ||||||||||||||||||||||||||||||||||||||||||||||||
| 5179 | ||||||||||||||||||||||||||||||||||||||||||||||||
| ), | ||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | ||||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||||
| """; | ||||||||||||||||||||||||||||||||||||||||||||||||
| SELECT COUNT(*) | ||||||||||||||||||||||||||||||||||||||||||||||||
| FROM safety s | ||||||||||||||||||||||||||||||||||||||||||||||||
| WHERE s.infra_type = 'CCTV' | ||||||||||||||||||||||||||||||||||||||||||||||||
| AND s.geom_5179 IS NOT NULL | ||||||||||||||||||||||||||||||||||||||||||||||||
| AND ST_DWithin( | ||||||||||||||||||||||||||||||||||||||||||||||||
| s.geom_5179, | ||||||||||||||||||||||||||||||||||||||||||||||||
| ST_Transform(ST_SetSRID(ST_MakePoint(?1, ?2), 4326), 5179), | ||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | ||||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||||
| """; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| return ((Number) em.createNativeQuery(sql) | ||||||||||||||||||||||||||||||||||||||||||||||||
| .setParameter(1, lon) | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -113,23 +93,17 @@ AND ST_DWithin( | |||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| // 보안등 50m 내 개수 | ||||||||||||||||||||||||||||||||||||||||||||||||
| public int countSafetyLightWithin50m(double lat, double lon) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| String sql = """ | ||||||||||||||||||||||||||||||||||||||||||||||||
| SELECT COUNT(*) | ||||||||||||||||||||||||||||||||||||||||||||||||
| FROM safety s | ||||||||||||||||||||||||||||||||||||||||||||||||
| WHERE s.infra_type = 'SAFETY_LIGHT' | ||||||||||||||||||||||||||||||||||||||||||||||||
| AND ST_DWithin( | ||||||||||||||||||||||||||||||||||||||||||||||||
| ST_Transform( | ||||||||||||||||||||||||||||||||||||||||||||||||
| ST_SetSRID(ST_MakePoint(s.longitude, s.latitude), 4326), | ||||||||||||||||||||||||||||||||||||||||||||||||
| 5179 | ||||||||||||||||||||||||||||||||||||||||||||||||
| ), | ||||||||||||||||||||||||||||||||||||||||||||||||
| ST_Transform( | ||||||||||||||||||||||||||||||||||||||||||||||||
| ST_SetSRID(ST_MakePoint(?1, ?2), 4326), | ||||||||||||||||||||||||||||||||||||||||||||||||
| 5179 | ||||||||||||||||||||||||||||||||||||||||||||||||
| ), | ||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | ||||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||||
| """; | ||||||||||||||||||||||||||||||||||||||||||||||||
| SELECT COUNT(*) | ||||||||||||||||||||||||||||||||||||||||||||||||
| FROM safety s | ||||||||||||||||||||||||||||||||||||||||||||||||
| WHERE s.infra_type = 'SAFETY_LIGHT' | ||||||||||||||||||||||||||||||||||||||||||||||||
| AND s.geom_5179 IS NOT NULL | ||||||||||||||||||||||||||||||||||||||||||||||||
| AND ST_DWithin( | ||||||||||||||||||||||||||||||||||||||||||||||||
| s.geom_5179, | ||||||||||||||||||||||||||||||||||||||||||||||||
| ST_Transform(ST_SetSRID(ST_MakePoint(?1, ?2), 4326), 5179), | ||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | ||||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||||
| """; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
| return ((Number) em.createNativeQuery(sql) | ||||||||||||||||||||||||||||||||||||||||||||||||
| .setParameter(1, lon) | ||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🏁 Script executed:
Repository: D-ingle/backend
Length of output: 1684
🏁 Script executed:
Repository: D-ingle/backend
Length of output: 1621
🏁 Script executed:
Repository: D-ingle/backend
Length of output: 915
baseUrl 제거로 인한 런타임 오류 발생 - 반드시 복구 필요
상대 경로
/v2/local/search/address.json를 사용하는KaKaoGeocodingService.getGeoPoint()가 이WebClient를 주입받아 사용하고 있습니다. baseUrl이 없으면 상대 경로를 절대 URL로 변환할 수 없어 런타임에 실패합니다.baseUrl 파라미터와
.baseUrl(baseUrl)설정을 복구하고, 해당 설정값을application.properties또는application.yml에 추가해야 합니다:또는 yml 형식:
🤖 Prompt for AI Agents