Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/hotfix/disaster_region_category'…
Browse files Browse the repository at this point in the history
… into dev-check
  • Loading branch information
nohy6630 committed Nov 20, 2023
2 parents 9204aa1 + b2d315f commit 005d0dc
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 55 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,25 +29,25 @@ public class DisasterController {
유저가 등록한 지역은 유저가 인증을 위해 같이 보내야하는 jwt 토큰으로부터 알아서 추출해서 처리할 것입니다.
""")
@PostMapping("/latest")
public ResponseEntity<LatestDisasterResponse> getLatestDisaster(@Valid @RequestBody LatestDisasterRequest latestDisasterRequest) {
return ResponseEntity.ok(disasterService.getLatestDisaster(latestDisasterRequest));
public ResponseEntity<LatestDisasterResponse> getLatestDisaster(Authentication authentication, @Valid @RequestBody LatestDisasterRequest latestDisasterRequest) {
return ResponseEntity.ok(disasterService.getLatestDisaster(authentication.getName(), latestDisasterRequest));
}

@Operation(summary = "재난상황 커뮤니티 데이터 가져오기", description = """
재난상황 페이지에서 필요한 재난목록과 그와 관련된 대화(댓글)들을 가져옵니다.
""")
@GetMapping("/situation")
public ResponseEntity<SituationHomeResponse> getSituationHome(Authentication authentication){
public ResponseEntity<SituationHomeResponse> getSituationHome(Authentication authentication) {
return ResponseEntity.ok(disasterService.getSituationHome(authentication.getName()));
}

@Operation(summary = "해당 재난과 관련된 모든 커뮤니티 대화 가져오기", description = """
정렬기준(최신순: time, 인기순: popularity) 과 재난상황 id를 파라미터로 전달해주세요.
커뮤니티-재난상황-댓글더보기 페이지에서 사용하는 API입니다.
""")
@GetMapping("/{sort}/{disasterId}")
public ResponseEntity<SituationDetailResponse> getSituationDetail(Authentication authentication, @PathVariable Long disasterId, @PathVariable String sort){
public ResponseEntity<SituationDetailResponse> getSituationDetail(Authentication authentication, @PathVariable Long disasterId, @PathVariable String sort) {
return ResponseEntity.ok(disasterService.getSituationDetail(authentication.getName(), disasterId, sort));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

import javax.swing.text.html.Option;
import java.time.LocalDateTime;
import java.util.List;
import java.util.Optional;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ public void collectData() {
break;
String[] locations = disaster.getLocationName().split(",");
for (String loc : locations) {
if (disasterTypeMap.get(disasterNum).equals(DisasterType.OTHERS) && disaster.getMsg().contains("실종"))
disasterTypeMap.put(disasterNum, DisasterType.MISSING);
disasterService.save(SaveDisasterRequest.of(
disasterTypeMap.get(disasterNum),
loc.replace(" 전체", ""),//이 부분은 메시지 내부 파싱하여 더 정확한 주소를 저장하도록 수정해야함
Expand Down Expand Up @@ -128,7 +130,7 @@ public void collectData() {

private void crawlingDisasterTypeV2() {
disasterTypeMap.clear();
try (WebClient webClient = new WebClient()){
try (WebClient webClient = new WebClient()) {
webClient.getOptions().setJavaScriptEnabled(true);
webClient.getOptions().setCssEnabled(false);
HtmlPage htmlPage = webClient.getPage(disasterProperties.getCrawlingUrl());
Expand All @@ -142,7 +144,7 @@ private void crawlingDisasterTypeV2() {
DisasterType.kor2code(types.get(i).text())
);
}
} catch (IOException e){
} catch (IOException e) {
throw new NotFoundCrawlingException();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,8 @@
import java.awt.print.Pageable;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.*;
import java.util.stream.Collectors;

@Service
@RequiredArgsConstructor
Expand All @@ -45,14 +43,23 @@ public class DisasterService {
private final ConversationService conversationService;
private final ConversationRepository conversationRepository;

public LatestDisasterResponse getLatestDisaster(LatestDisasterRequest latestDisasterRequest) {
public LatestDisasterResponse getLatestDisaster(String email, LatestDisasterRequest latestDisasterRequest) {
String address = locationProvider.pos2address(latestDisasterRequest.getLatitude(), latestDisasterRequest.getLongitude());
LocalDateTime time = LocalDateTime.now().minusDays(1);
List<Disaster> disasters = disasterRepository.findDisastersInAddressAfterTime(address, time);
if (!disasters.isEmpty())
return LatestDisasterResponse.of(disasters.get(0));
else
Set<Disaster> disasters = new HashSet<>(disasterRepository.findDisastersInAddressAfterTime(address, time));
Member member = memberService.findByEmail(email);
for (NotificationRegion notificationRegion : member.getNotificationRegions()) {
disasters.addAll(disasterRepository.findDisastersInAddressAfterTime(notificationRegion.getLocation(), time));
}
disasters.removeIf(disaster -> !isValidDisasterType(disaster.getDisasterType(), member.getNotificationDisasters()));

if(disasters.isEmpty())
return LatestDisasterResponse.notExist();

return LatestDisasterResponse.of(disasters.stream()
.sorted(Comparator.comparing(Disaster::getGeneratedAt).reversed())
.toList()
.get(0));
}

@Transactional
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,51 @@
@Getter
@RequiredArgsConstructor
public enum DisasterType {
CIVIL_DEFENSE("민방공"),
TERROR("테러"),
//자연재난
DROUGHT("가뭄"),
STRONG_WIND("강풍"),
DRYNESS("건조"),
HEAVY_SNOWFALL("대설"),
TIDAL_WAVE("대조기"),
FINE_DUST("미세먼지"),
WILDFIRE("산불"),
LANDSLIDE("산사태"),
FOG("안개"),
EARTHQUAKE("지진"),
TSUNAMI("해일"),
FLOOD("홍수"),
TYPHOON("태풍"),
WILDFIRE("산불"),
NATURAL_DISASTER("자연재난"),
INFECTIOUS_DISEASE("감염병"),
HEATWAVE("폭염"),
ROUGH_SEA("풍랑"),
COLD_WAVE("한파"),
HEAVY_RAIN("호우"),
FLOOD("홍수"),

//사회재난
GAS("가스"),
TRAFFIC("교통"),
FINANCE("금융"),
COLLAPSE("붕괴"),
WATER_SUPPLY("수도"),
ENERGY("에너지"),
MEDICAL("의료"),
INFECTIOUS_DISEASE("전염병"),
POWER_OUTAGE("정전"),
COMMUNICATION("통신"),
EXPLOSION("폭발"),
FIRE("화재"),
OTHERS("기타");
ENVIRONMENTAL_POLLUTION("환경오염사고"),
AI("AI"),

//비상대비
EMERGENCY("비상사태"),
TERROR("테러"),
CHEMICAL("화생방사고"),

//기타
MISSING("실종"),
OTHERS("기타"),

//추후 삭제예정
NATURAL_DISASTER("자연재난");

private final String description;

Expand All @@ -27,42 +60,23 @@ public String getDescription() {
}

public static DisasterType kor2code(String kor) {
for (DisasterType type : values()) {
if (kor.equals(type.getDescription()))
return type;
}
//1대1 매핑이 되지 않는 카테고리들 처리
switch (kor) {
case "민방공" -> {
return CIVIL_DEFENSE;
}
case "테러" -> {
return TERROR;
}
case "산사태" -> {
return LANDSLIDE;
}
case "지진" -> {
return EARTHQUAKE;
}
case "지진해일" -> {
return TSUNAMI;
}
case "홍수" -> {
return FLOOD;
}
case "태풍" -> {
return TYPHOON;
}
case "산불" -> {
return WILDFIRE;
}
case "건조", "폭염", "미세먼지", "대조기", "가뭄", "대설", "한파", "황사", "강풍", "호우", "풍랑", "안개" -> {
return NATURAL_DISASTER;
return EARTHQUAKE;
}
case "전염병" -> {
return INFECTIOUS_DISEASE;
case "황사" -> {
return OTHERS;
}
case "화재" -> {
return FIRE;
case "교통통제", "교통사고" -> {
return TRAFFIC;
}
case "화생방사고", "폭동", "비상사태", "기타", "교통통제", "붕괴", "폭발", "교통사고", "환경오염사고", "에너지", "통신", "교통", "금융", "의료", "수도", "정전", "가스", "AI" -> {
return OTHERS;
case "폭동", "민방공" -> {
return EMERGENCY;
}
}
throw new InvalidDisasterTypeException();
Expand Down

0 comments on commit 005d0dc

Please sign in to comment.