-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: 좌표 근처 시설 가져오는 메서드 추가 및 스케줄러 순서 오류 변경
- 세부정보 갱신을 제일 마지막으로 변경 - 수행시간을 로그로 남김(차후 필요없게 되면 제거 예정)
- Loading branch information
Showing
20 changed files
with
309 additions
and
107 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package org.healthmap.app.config; | ||
|
||
import org.springframework.boot.autoconfigure.domain.EntityScan; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.data.jpa.repository.config.EnableJpaRepositories; | ||
|
||
@Configuration | ||
@EntityScan(basePackages = "org.healthmap.db") | ||
@EnableJpaRepositories(basePackages = "org.healthmap.db") | ||
public class JpaConfig { | ||
} |
38 changes: 0 additions & 38 deletions
38
app/src/main/java/org/healthmap/app/controller/DrugstoreController.java
This file was deleted.
Oops, something went wrong.
35 changes: 35 additions & 0 deletions
35
app/src/main/java/org/healthmap/app/controller/HealthMapController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package org.healthmap.app.controller; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import org.healthmap.app.dto.HealthMapRequestDto; | ||
import org.healthmap.app.dto.HealthMapResponseDto; | ||
import org.healthmap.app.service.HealthMapService; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.ModelAttribute; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
import java.util.List; | ||
|
||
@RestController | ||
@RequiredArgsConstructor | ||
@RequestMapping("/healthmap") | ||
public class HealthMapController { | ||
private final HealthMapService healthMapService; | ||
|
||
@GetMapping | ||
public HealthMapRequestDto findAllDrugstore() { | ||
return null; | ||
} | ||
|
||
@GetMapping("/around") | ||
public ResponseEntity<List<HealthMapResponseDto>> findDrugstoreAround( | ||
@ModelAttribute HealthMapRequestDto requestDto | ||
) { | ||
List<HealthMapResponseDto> nearByMedicalFacility = healthMapService.getNearByMedicalFacility(requestDto); | ||
|
||
return ResponseEntity.ok(nearByMedicalFacility); | ||
} | ||
|
||
} |
21 changes: 21 additions & 0 deletions
21
app/src/main/java/org/healthmap/app/converter/HealthMapConverter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package org.healthmap.app.converter; | ||
|
||
import org.healthmap.app.dto.HealthMapResponseDto; | ||
import org.healthmap.db.medicalfacility.MedicalFacilityEntity; | ||
import org.locationtech.jts.geom.Point; | ||
|
||
public class HealthMapConverter { | ||
public static HealthMapResponseDto toHealthMapResponseDto(MedicalFacilityEntity entity, double distance) { | ||
Point coordinate = entity.getCoordinate(); | ||
double longitude = coordinate.getX(); | ||
double latitude = coordinate.getY(); | ||
return HealthMapResponseDto.of( | ||
entity.getId(), entity.getName(), entity.getAddress(), entity.getPhoneNumber(), entity.getUrl(), entity.getPostNumber(), | ||
entity.getType(), entity.getState(), entity.getCity(), entity.getTown(), latitude, longitude, entity.getParking(), | ||
entity.getParkingEtc(), entity.getTreatmentMon(), entity.getTreatmentTue(), entity.getTreatmentWed(), entity.getTreatmentThu(), | ||
entity.getTreatmentFri(), entity.getTreatmentSat(), entity.getTreatmentSun(), entity.getReceiveWeek(), entity.getReceiveSat(), | ||
entity.getLunchWeek(), entity.getLunchSat(), entity.getNoTreatmentSun(), entity.getNoTreatmentHoliday(), entity.getEmergencyDay(), | ||
entity.getEmergencyNight(), distance | ||
); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
17 changes: 17 additions & 0 deletions
17
app/src/main/java/org/healthmap/app/dto/HealthMapRequestDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package org.healthmap.app.dto; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import lombok.Setter; | ||
|
||
@Setter | ||
@Getter | ||
@AllArgsConstructor | ||
public class HealthMapRequestDto { | ||
private double latitude; | ||
private double longitude; | ||
|
||
public static HealthMapRequestDto of(double latitude, double longitude) { | ||
return new HealthMapRequestDto(latitude, longitude); | ||
} | ||
} |
58 changes: 58 additions & 0 deletions
58
app/src/main/java/org/healthmap/app/dto/HealthMapResponseDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package org.healthmap.app.dto; | ||
|
||
import lombok.AccessLevel; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
|
||
@AllArgsConstructor(access = AccessLevel.PROTECTED) | ||
@NoArgsConstructor | ||
@Getter | ||
public class HealthMapResponseDto { | ||
private String code; //암호화 요양 기호 | ||
private String name; //요양기관명(병원명) | ||
private String address; //주소 | ||
private String phoneNumber; //전화번호 | ||
private String pageUrl; //병원 홈페이지 | ||
private String postNumber; //우편번호 | ||
private String type; //종별코드명 | ||
private String state; //시도코드명 | ||
private String city; //시군구코드 | ||
private String town; //읍면동 | ||
private double latitude; | ||
private double longitude; | ||
private String parking; | ||
private String parkingEtc; | ||
private String treatmentMon; // 진료시간_월 | ||
private String treatmentTue; | ||
private String treatmentWed; | ||
private String treatmentThu; | ||
private String treatmentFri; | ||
private String treatmentSat; | ||
private String treatmentSun; | ||
private String receiveWeek; // 접수시간_평일 | ||
private String receiveSat; // 접수시간_토요일 | ||
private String lunchWeek; // 점심시간_평일 | ||
private String lunchSat; // 점심시간_토 | ||
private String noTreatmentSun; // 일요일 휴진 | ||
private String noTreatmentHoliday; // 공휴일 휴진 | ||
private String emergencyDay; | ||
private String emergencyNight; | ||
private double distance; | ||
|
||
public static HealthMapResponseDto of( | ||
String code, String name, String address, String phoneNumber, String pageUrl, String postNumber, String type, | ||
String state, String city, String town, double latitude, double longitude, String parking, String parkingEtc, String treatmentMon, | ||
String treatmentTue, String treatmentWed, String treatmentThu, String treatmentFri, String treatmentSat, String treatmentSun, | ||
String receiveWeek, String receiveSat, String lunchWeek, String lunchSat, String noTreatmentSun, String noTreatmentHoliday, | ||
String emergencyDay, String emergencyNight, double distance) { | ||
return new HealthMapResponseDto( | ||
code, name, address, phoneNumber, pageUrl, postNumber, type, state, city, | ||
town, latitude, longitude, parking, parkingEtc, treatmentMon, treatmentTue, treatmentWed, | ||
treatmentThu, treatmentFri, treatmentSat, treatmentSun, receiveWeek, receiveSat, | ||
lunchWeek, lunchSat, noTreatmentSun, noTreatmentHoliday, emergencyDay, emergencyNight, distance | ||
); | ||
} | ||
|
||
} |
39 changes: 39 additions & 0 deletions
39
app/src/main/java/org/healthmap/app/service/HealthMapService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package org.healthmap.app.service; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.healthmap.app.converter.HealthMapConverter; | ||
import org.healthmap.app.dto.HealthMapRequestDto; | ||
import org.healthmap.app.dto.HealthMapResponseDto; | ||
import org.healthmap.db.medicalfacility.MedicalFacilityEntity; | ||
import org.healthmap.db.medicalfacility.MedicalFacilityRepository; | ||
import org.springframework.stereotype.Service; | ||
|
||
import java.util.List; | ||
import java.util.Optional; | ||
import java.util.stream.Collectors; | ||
|
||
@RequiredArgsConstructor | ||
@Service | ||
@Slf4j | ||
public class HealthMapService { | ||
private final MedicalFacilityRepository medicalFacilityRepository; | ||
|
||
// 2km 이내의 시설 찾기 | ||
public List<HealthMapResponseDto> getNearByMedicalFacility(HealthMapRequestDto requestDto) { | ||
int range = 2; | ||
List<Object[]> nearMedicalFacility = medicalFacilityRepository.findNearMedicalFacility(requestDto.getLatitude(), requestDto.getLongitude(), range); | ||
List<HealthMapResponseDto> healthMapResponseDtoList = Optional.ofNullable(nearMedicalFacility) | ||
.map(objList -> objList.stream() | ||
.map(x -> { | ||
MedicalFacilityEntity entity = (MedicalFacilityEntity) x[0]; | ||
double distance = (double) x[1]; | ||
return HealthMapConverter.toHealthMapResponseDto(entity, distance); | ||
}) | ||
.collect(Collectors.toList()) | ||
) | ||
.orElseThrow(() -> new NullPointerException("값이 없습니다.")); | ||
log.info("healthMapResponseDtoList size : {}", healthMapResponseDtoList.size()); | ||
return healthMapResponseDtoList; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
spring: | ||
profiles: | ||
include: | ||
- secret | ||
datasource: | ||
driver-class-name: com.mysql.cj.jdbc.Driver | ||
url: jdbc:mysql://localhost:13306/healthmap?useSSL=false&allowPublicKeyRetrieval=true&characterEncoding=UTF-8&serverTimezone=Asia/Seoul | ||
username: root |
26 changes: 26 additions & 0 deletions
26
app/src/test/java/org/healthmap/app/service/HealthMapServiceTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package org.healthmap.app.service; | ||
|
||
import org.assertj.core.api.Assertions; | ||
import org.healthmap.app.dto.HealthMapRequestDto; | ||
import org.healthmap.app.dto.HealthMapResponseDto; | ||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
|
||
import java.util.List; | ||
|
||
@SpringBootTest | ||
class HealthMapServiceTest { | ||
@Autowired | ||
private HealthMapService healthMapService; | ||
|
||
@Test | ||
@DisplayName("좌표 근처의 병원, 약국을 가져온다") | ||
void test() { | ||
HealthMapRequestDto healthMapRequestDto = HealthMapRequestDto.of(37.4828517, 126.9963104); | ||
List<HealthMapResponseDto> nearByMedicalFacility = healthMapService.getNearByMedicalFacility(healthMapRequestDto); | ||
|
||
Assertions.assertThat(nearByMedicalFacility).isNotEmpty(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 20 additions & 3 deletions
23
db/src/main/java/org/healthmap/db/medicalfacility/CustomMedicalFacilityRepositoryImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,40 @@ | ||
package org.healthmap.db.medicalfacility; | ||
|
||
import jakarta.persistence.EntityManager; | ||
import jakarta.persistence.Query; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Repository; | ||
|
||
import java.util.List; | ||
|
||
@RequiredArgsConstructor | ||
@Repository | ||
public class CustomMedicalFacilityRepositoryImpl implements CustomMedicalFacilityRepository{ | ||
public class CustomMedicalFacilityRepositoryImpl implements CustomMedicalFacilityRepository { | ||
private final EntityManager em; | ||
|
||
|
||
@Override | ||
public void customSaveAll(List<MedicalFacilityEntity> entityList) { | ||
for(MedicalFacilityEntity entity : entityList) { | ||
for (MedicalFacilityEntity entity : entityList) { | ||
em.persist(entity); | ||
} | ||
em.flush(); | ||
em.clear(); | ||
} | ||
|
||
@Override | ||
public List<Object[]> findNearMedicalFacility(double latitude, double longitude, int range) { | ||
String nativeQuery = "SELECT m.*, " + | ||
"ST_Distance_Sphere(ST_GeomFromText(CONCAT('POINT(', ?1, ' ', ?2, ')'), 4326), coordinate) AS distance " + | ||
"FROM medical_facility m " + | ||
"WHERE ST_Distance_Sphere(ST_GeomFromText(CONCAT('POINT(', ?1, ' ', ?2, ')'), 4326), coordinate) <= ?3 " + | ||
"ORDER BY distance limit 30"; | ||
Query query = em.createNativeQuery(nativeQuery, "MedicalFacilityMapping"); | ||
query.setParameter(1, latitude); | ||
query.setParameter(2, longitude); | ||
query.setParameter(3, range * 1000); | ||
|
||
List<Object[]> result = query.getResultList(); | ||
|
||
return result; | ||
} | ||
} |
Oops, something went wrong.