소스정리
This commit is contained in:
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
package net.jwsi.jcms_vpp;
|
package net.jwsi.jcms.vpp;
|
||||||
|
|
||||||
import net.jwsi.jcms.JcmsCmsApp;
|
import net.jwsi.jcms.JcmsCmsApp;
|
||||||
import org.springframework.boot.SpringApplication;
|
import org.springframework.boot.SpringApplication;
|
||||||
+7
-1
@@ -1,10 +1,11 @@
|
|||||||
package net.jwsi.jcms_vpp;
|
package net.jwsi.jcms.vpp;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import net.jwsi.jcms.cms.board.arti.BodArti;
|
import net.jwsi.jcms.cms.board.arti.BodArti;
|
||||||
import net.jwsi.jcms.cms.board.arti.BodArtiService;
|
import net.jwsi.jcms.cms.board.arti.BodArtiService;
|
||||||
import net.jwsi.jcms.exception.JsonDataException;
|
import net.jwsi.jcms.exception.JsonDataException;
|
||||||
import net.jwsi.jcms.utils.HttpUtil;
|
import net.jwsi.jcms.utils.HttpUtil;
|
||||||
|
import net.jwsi.jcms.vpp.station.StationService;
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
import org.springframework.stereotype.Controller;
|
import org.springframework.stereotype.Controller;
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
@@ -15,6 +16,7 @@ import java.util.Map;
|
|||||||
@Controller
|
@Controller
|
||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
public class MainController {
|
public class MainController {
|
||||||
|
private final StationService stationService;
|
||||||
final private String path = "system/";
|
final private String path = "system/";
|
||||||
final private String root = "/"+path;
|
final private String root = "/"+path;
|
||||||
@Value("${jcms.manager-path:system}")
|
@Value("${jcms.manager-path:system}")
|
||||||
@@ -33,4 +35,8 @@ public class MainController {
|
|||||||
public Map<String, Object> listData(BodArti srch) throws JsonDataException {
|
public Map<String, Object> listData(BodArti srch) throws JsonDataException {
|
||||||
return HttpUtil.responseList(bodArtiService.selectList(srch));
|
return HttpUtil.responseList(bodArtiService.selectList(srch));
|
||||||
}
|
}
|
||||||
|
@GetMapping("/sync-station")
|
||||||
|
public Object syncStation() {
|
||||||
|
return stationService.getStations();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
+3
-4
@@ -1,8 +1,7 @@
|
|||||||
package net.jwsi.jcms_vpp.common.client;
|
package net.jwsi.jcms.vpp.api;
|
||||||
|
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import net.jwsi.jcms_vpp.Api.ApiResponse;
|
import net.jwsi.jcms.vpp.station.StationDto;
|
||||||
import net.jwsi.jcms_vpp.station.StationDto;
|
|
||||||
import org.springframework.core.ParameterizedTypeReference;
|
import org.springframework.core.ParameterizedTypeReference;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
import org.springframework.web.client.RestClient;
|
import org.springframework.web.client.RestClient;
|
||||||
@@ -18,7 +17,7 @@ public class ApiClient {
|
|||||||
private final RestClient restClient;
|
private final RestClient restClient;
|
||||||
|
|
||||||
public ApiResponse<List<StationDto>> fetchStations(String baseUrl, String token) {
|
public ApiResponse<List<StationDto>> fetchStations(String baseUrl, String token) {
|
||||||
URI uri = UriComponentsBuilder.fromHttpUrl(baseUrl)
|
URI uri = UriComponentsBuilder.fromUriString(baseUrl)
|
||||||
.path("/api/station/list")
|
.path("/api/station/list")
|
||||||
.build()
|
.build()
|
||||||
.toUri();
|
.toUri();
|
||||||
+2
-2
@@ -1,4 +1,4 @@
|
|||||||
package net.jwsi.jcms_vpp.Api;
|
package net.jwsi.jcms.vpp.api;
|
||||||
|
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.Setter;
|
import lombok.Setter;
|
||||||
@@ -11,5 +11,5 @@ public class ApiResponse<T> {
|
|||||||
private Integer code;
|
private Integer code;
|
||||||
private String httpStatus;
|
private String httpStatus;
|
||||||
private String message;
|
private String message;
|
||||||
private List<T> data;
|
private T data;
|
||||||
}
|
}
|
||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
package net.jwsi.jcms_vpp.global.config;
|
package net.jwsi.jcms.vpp.api;
|
||||||
|
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
package net.jwsi.jcms_vpp.station;
|
package net.jwsi.jcms.vpp.station;
|
||||||
|
|
||||||
import jakarta.persistence.Entity;
|
import jakarta.persistence.Entity;
|
||||||
import jakarta.persistence.Id;
|
import jakarta.persistence.Id;
|
||||||
+1
-4
@@ -1,13 +1,10 @@
|
|||||||
package net.jwsi.jcms_vpp.station;
|
package net.jwsi.jcms.vpp.station;
|
||||||
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import net.jwsi.jcms.base.BaseController;
|
import net.jwsi.jcms.base.BaseController;
|
||||||
import net.jwsi.jcms.base.BaseEntity;
|
|
||||||
import net.jwsi.jcms.base.BaseService;
|
|
||||||
import net.jwsi.jcms.exception.JsonDataException;
|
import net.jwsi.jcms.exception.JsonDataException;
|
||||||
import org.springframework.stereotype.Controller;
|
import org.springframework.stereotype.Controller;
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
import org.springframework.web.bind.annotation.ResponseBody;
|
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@@ -0,0 +1,44 @@
|
|||||||
|
package net.jwsi.jcms.vpp.station;
|
||||||
|
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
public class StationDto {
|
||||||
|
private String stationId;
|
||||||
|
private String providerId;
|
||||||
|
private String stNm;
|
||||||
|
private String addrRdM;
|
||||||
|
private String addrRdD;
|
||||||
|
private String addrLdM;
|
||||||
|
private String addrLdD;
|
||||||
|
private String stFacilTpCd;
|
||||||
|
private String stFacilDTpCd;
|
||||||
|
private String parkingFeeYn;
|
||||||
|
private String parkingFeeDetl;
|
||||||
|
private String pnuNo;
|
||||||
|
private String pnuDoNm;
|
||||||
|
private String pnuDongNm;
|
||||||
|
private String pnuSiNm;
|
||||||
|
|
||||||
|
public Station toEntity() {
|
||||||
|
Station station = new Station();
|
||||||
|
station.setStationId(this.stationId);
|
||||||
|
station.setProviderId(this.providerId);
|
||||||
|
station.setStNm(this.stNm);
|
||||||
|
station.setAddrRdM(this.addrRdM);
|
||||||
|
station.setAddrRdD(this.addrRdD);
|
||||||
|
station.setAddrLdM(this.addrLdM);
|
||||||
|
station.setAddrLdD(this.addrLdD);
|
||||||
|
station.setStFacilTpCd(this.stFacilTpCd);
|
||||||
|
station.setStFacilDTpCd(this.stFacilDTpCd);
|
||||||
|
station.setParkingFeeYn(this.parkingFeeYn);
|
||||||
|
station.setParkingFeeDetl(this.parkingFeeDetl);
|
||||||
|
station.setPnuNo(this.pnuNo);
|
||||||
|
station.setPnuDoNm(this.pnuDoNm);
|
||||||
|
station.setPnuDongNm(this.pnuDongNm);
|
||||||
|
station.setPnuSiNm(this.pnuSiNm);
|
||||||
|
return station;
|
||||||
|
}
|
||||||
|
}
|
||||||
+1
-2
@@ -1,8 +1,7 @@
|
|||||||
package net.jwsi.jcms_vpp.station;
|
package net.jwsi.jcms.vpp.station;
|
||||||
|
|
||||||
import net.jwsi.jcms.base.BaseRecStRepository;
|
import net.jwsi.jcms.base.BaseRecStRepository;
|
||||||
import org.springframework.stereotype.Repository;
|
import org.springframework.stereotype.Repository;
|
||||||
import org.springframework.web.bind.annotation.ResponseBody;
|
|
||||||
|
|
||||||
@Repository
|
@Repository
|
||||||
public interface StationRepository extends BaseRecStRepository<Station,String> {
|
public interface StationRepository extends BaseRecStRepository<Station,String> {
|
||||||
+37
-11
@@ -1,39 +1,60 @@
|
|||||||
package net.jwsi.jcms_vpp.station;
|
package net.jwsi.jcms.vpp.station;
|
||||||
|
|
||||||
|
import jakarta.transaction.Transactional;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import net.jwsi.jcms.base.BaseService;
|
import net.jwsi.jcms.base.BaseService;
|
||||||
import net.jwsi.jcms.base.EnumSqlType;
|
import net.jwsi.jcms.base.EnumSqlType;
|
||||||
import net.jwsi.jcms.utils.HttpUtil;
|
import net.jwsi.jcms.utils.HttpUtil;
|
||||||
import net.jwsi.jcms.utils.LoginUtil;
|
import net.jwsi.jcms.utils.LoginUtil;
|
||||||
import net.jwsi.jcms_vpp.Api.ApiResponse;
|
import net.jwsi.jcms.vpp.api.ApiResponse;
|
||||||
import net.jwsi.jcms_vpp.common.client.ApiClient;
|
import net.jwsi.jcms.vpp.api.ApiClient;
|
||||||
import org.springframework.data.domain.Page;
|
import org.springframework.data.domain.Page;
|
||||||
import org.springframework.data.jpa.domain.Specification;
|
import org.springframework.data.jpa.domain.Specification;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
@Service
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
|
@Service
|
||||||
public class StationService extends BaseService<Station,String,StationRepository> {
|
public class StationService extends BaseService<Station,String,StationRepository> {
|
||||||
|
|
||||||
private final ApiClient apiClient;
|
private final ApiClient apiClient;
|
||||||
private final String API_TOKEN = System.getenv("API_TOKEN");
|
private final String API_TOKEN = System.getenv("API_TOKEN");
|
||||||
}
|
|
||||||
|
|
||||||
public StationService(StationRepository repository, ApiClient apiClient) {
|
public StationService(StationRepository repository, ApiClient apiClient) {
|
||||||
super(repository);
|
super(repository);
|
||||||
this.apiClient = apiClient;
|
this.apiClient = apiClient;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<StationDto> getStations() {
|
|
||||||
ApiResponse<List<StationDto>> response = apiClient.fetchStations("http://dev.jinwoosi.co.kr:8072/api/st/list", API_TOKEN);
|
|
||||||
|
|
||||||
if (response != null && Integer.valueOf(200).equals(response.getCode())) {
|
@Transactional
|
||||||
return response.getData(); // List<StationDto> 반환됨
|
public List<Station> getStations() {
|
||||||
|
String baseUrl = "http://dev.jinwoosi.co.kr:8072/api/st/list";
|
||||||
|
|
||||||
|
ApiResponse<List<StationDto>> response = apiClient.fetchStations(baseUrl, API_TOKEN);
|
||||||
|
|
||||||
|
if (response == null || !Integer.valueOf(200).equals(response.getCode())) {
|
||||||
|
String msg = (response != null) ? response.getMessage() : "응답 없음";
|
||||||
|
throw new RuntimeException("API 호출 실패: " + msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new RuntimeException("API호출 실패: " + response.getMessage());
|
List<StationDto> dtoList = response.getData();
|
||||||
|
if (dtoList == null || dtoList.isEmpty()) {
|
||||||
|
log.info("가져온 충전소 데이터가 없습니다.");
|
||||||
|
return Collections.emptyList();
|
||||||
|
}
|
||||||
|
|
||||||
|
List<Station> entityList = dtoList.stream()
|
||||||
|
.map(StationDto::toEntity)
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
|
||||||
|
List<Station> savedStations = super.repository.saveAll(entityList);
|
||||||
|
|
||||||
|
log.info("총 {}건의 충전소 데이터가 DB에 동기화되었습니다.", savedStations.size());
|
||||||
|
|
||||||
|
return savedStations;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -48,7 +69,7 @@ public class StationService extends BaseService<Station,String,StationRepository
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Station newSearchParam(Station station) {
|
protected Station newSearchParam(Station station) {
|
||||||
if (station == null) station = new Station();
|
if(station == null){ station = new Station();}
|
||||||
return station;
|
return station;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -72,3 +93,8 @@ public class StationService extends BaseService<Station,String,StationRepository
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -1,18 +0,0 @@
|
|||||||
package net.jwsi.jcms_vpp.station;
|
|
||||||
|
|
||||||
import lombok.Getter;
|
|
||||||
import lombok.Setter;
|
|
||||||
|
|
||||||
@Getter
|
|
||||||
@Setter
|
|
||||||
public class StationDto {
|
|
||||||
private String providerId;
|
|
||||||
private String providerNm;
|
|
||||||
private String bizTaxId;
|
|
||||||
private String ceo;
|
|
||||||
private String tel;
|
|
||||||
private String fax;
|
|
||||||
private String email;
|
|
||||||
private String zipCode;
|
|
||||||
private String addr;
|
|
||||||
}
|
|
||||||
@@ -2,6 +2,8 @@ spring:
|
|||||||
config:
|
config:
|
||||||
activate:
|
activate:
|
||||||
on-profile: dev
|
on-profile: dev
|
||||||
|
main:
|
||||||
|
allow-bean-definition-overriding: true
|
||||||
jpa:
|
jpa:
|
||||||
open-in-view: true
|
open-in-view: true
|
||||||
show-sql: true
|
show-sql: true
|
||||||
|
|||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
package net.jwsi.jcms_vpp;
|
package net.jwsi.jcms.vpp;
|
||||||
|
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.springframework.boot.test.context.SpringBootTest;
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
@@ -0,0 +1,44 @@
|
|||||||
|
package net.jwsi.jcms.vpp.station;
|
||||||
|
|
||||||
|
import org.assertj.core.api.Assertions;
|
||||||
|
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 org.springframework.test.context.ActiveProfiles;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
|
||||||
|
@SpringBootTest
|
||||||
|
@Transactional
|
||||||
|
@ActiveProfiles("dev")
|
||||||
|
class StationServiceTest {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private StationService stationService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private StationRepository stationRepository;
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@DisplayName("외부 API를 호출하여 DB에 충전소 정보가 정상 저장되는지 테스트")
|
||||||
|
void saveAndGetStationsTest() {
|
||||||
|
List<Station> savedStations = stationService.getStations();
|
||||||
|
|
||||||
|
System.out.println("====== 저장된 건수: " + savedStations.size() + " ======");
|
||||||
|
|
||||||
|
Assertions.assertThat(savedStations).isNotNull();
|
||||||
|
|
||||||
|
if (!savedStations.isEmpty()) {
|
||||||
|
Station firstStation = savedStations.get(0);
|
||||||
|
Station found = stationRepository.findById(firstStation.getStationId()).orElse(null);
|
||||||
|
|
||||||
|
assertThat(found).isNotNull();
|
||||||
|
assertThat(found.getStationId()).isEqualTo(firstStation.getStationId());
|
||||||
|
System.out.println("====== DB 저장 확인 완료 (Station ID: " + found.getStationId() + ") ======");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user