소스정리
This commit is contained in:
@@ -40,10 +40,4 @@ public class MainController {
|
||||
return HttpUtil.responseList(bodArtiService.selectList(srch));
|
||||
}
|
||||
|
||||
@GetMapping("/cms/test")
|
||||
@ResponseBody
|
||||
public ResponseEntity<String> test() {
|
||||
List<Station> stations = stationService.getStations();
|
||||
return ResponseEntity.ok("테스트 ㅇ! 건수: " + stations.size());
|
||||
}
|
||||
}
|
||||
@@ -9,6 +9,7 @@ import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@@ -32,10 +33,31 @@ public class StationController extends BaseController<Station,String,StationRepo
|
||||
@PostMapping("list.json")
|
||||
@ResponseBody
|
||||
public Map<String,Object> list(Station station){
|
||||
stationService.getStations();
|
||||
return svcSelectList(station);
|
||||
}
|
||||
|
||||
@PostMapping("view.json")
|
||||
@ResponseBody
|
||||
public Map<String, Object> viewData(Station station) throws JsonDataException {
|
||||
return svcSelectOne(station);
|
||||
}
|
||||
|
||||
@PostMapping("insert.json")
|
||||
@ResponseBody
|
||||
public Map<String, Object> insert(Station station) throws JsonDataException {
|
||||
return svcInsert(station);
|
||||
}
|
||||
|
||||
@PostMapping("update.json")
|
||||
@ResponseBody
|
||||
public Map<String, Object> update(Station station) throws JsonDataException {
|
||||
return svcUpdate(station);
|
||||
}
|
||||
@PostMapping("delete.json")
|
||||
@ResponseBody
|
||||
public Map<String, Object> delete(Station station) throws JsonDataException {
|
||||
return svcDelete(station.getStationId());
|
||||
}
|
||||
@Override
|
||||
protected void chkSelectList(List list) throws JsonDataException {
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@ package net.jwsi.jcms.vpp.station;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@@ -20,17 +21,63 @@ public class StationDto {
|
||||
|
||||
public Station toEntity() {
|
||||
Station station = new Station();
|
||||
station.setStationId(this.stId);
|
||||
station.setProviderId(this.providerId);
|
||||
station.setStationId(this.stId);
|
||||
station.setStNm(this.stNm);
|
||||
station.setAddrRdM(this.addrRd);
|
||||
station.setAddrLdM(this.addrLd);
|
||||
|
||||
String[] rdParts = splitAddress(this.addrRd);
|
||||
station.setAddrRdM(rdParts[0]);
|
||||
station.setAddrRdD(rdParts[1]);
|
||||
|
||||
String[] ldParts = splitAddress(this.addrLd);
|
||||
station.setAddrLdM(ldParts[0]);
|
||||
station.setAddrLdD(ldParts[1]);
|
||||
|
||||
station.setStFacilTpCd(this.stFacilTp);
|
||||
station.setStFacilDTpCd(this.stFacilDTp);
|
||||
station.setParkingFeeYn(this.parkingFee);
|
||||
station.setParkingFeeDetl(this.parkingFeeDetl);
|
||||
|
||||
station.setParkingFeeDetl(this.parkingFeeDetl != null ? this.parkingFeeDetl : "");
|
||||
station.setPnuNo(this.pnuNo);
|
||||
station.setPnuDoNm(this.pnuNm);
|
||||
|
||||
if (StringUtils.hasText(this.pnuNm)) {
|
||||
String[] pnuTokens = this.pnuNm.trim().split("\\s+");
|
||||
if (pnuTokens.length > 0) station.setPnuDoNm(pnuTokens[0]);
|
||||
if (pnuTokens.length > 1) station.setPnuSiNm(pnuTokens[1]);
|
||||
|
||||
if (pnuTokens.length > 2) {
|
||||
StringBuilder dongBuilder = new StringBuilder();
|
||||
for (int i = 2; i < pnuTokens.length; i++) {
|
||||
dongBuilder.append(pnuTokens[i]).append(" ");
|
||||
}
|
||||
station.setPnuDongNm(dongBuilder.toString().trim());
|
||||
}
|
||||
}
|
||||
|
||||
return station;
|
||||
}
|
||||
|
||||
private String[] splitAddress(String addr) {
|
||||
if (!StringUtils.hasText(addr)) {
|
||||
return new String[]{"", ""};
|
||||
}
|
||||
|
||||
String[] tokens = addr.trim().split("\\s+");
|
||||
StringBuilder main = new StringBuilder();
|
||||
StringBuilder detail = new StringBuilder();
|
||||
boolean foundNumber = false;
|
||||
|
||||
for (String token : tokens) {
|
||||
if (!foundNumber) {
|
||||
main.append(token).append(" ");
|
||||
if (token.matches(".*\\d+.*")) {
|
||||
foundNumber = true;
|
||||
}
|
||||
} else {
|
||||
detail.append(token).append(" ");
|
||||
}
|
||||
}
|
||||
|
||||
return new String[]{main.toString().trim(), detail.toString().trim()};
|
||||
}
|
||||
}
|
||||
@@ -34,8 +34,8 @@ public class StationService extends BaseService<Station,String,StationRepository
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public List<Station> getStations() {
|
||||
|
||||
@Scheduled(cron = "0 0 0 * * *")
|
||||
public void getStations() {
|
||||
ApiResponse<List<StationDto>> response = apiClient.fetchStations(baseUrl, apiToken);
|
||||
|
||||
if (response == null || !Integer.valueOf(200).equals(response.getCode())) {
|
||||
@@ -46,7 +46,6 @@ public class StationService extends BaseService<Station,String,StationRepository
|
||||
List<StationDto> dtoList = response.getData();
|
||||
if (dtoList == null || dtoList.isEmpty()) {
|
||||
log.info("가져온 충전소 데이터가 없습니다.");
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
List<Station> entityList = dtoList.stream()
|
||||
@@ -57,7 +56,6 @@ public class StationService extends BaseService<Station,String,StationRepository
|
||||
|
||||
log.info("총 {}건의 충전소 데이터가 DB에 동기화되었습니다.", savedStations.size());
|
||||
|
||||
return savedStations;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -82,8 +80,11 @@ public class StationService extends BaseService<Station,String,StationRepository
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Specification<Station> getSpecification(Station station) {
|
||||
return null;
|
||||
protected Specification<Station> getSpecification(Station srch) {
|
||||
if(srch == null) return null;
|
||||
Specification<Station> rst = null;
|
||||
rst = addWhere(rst, srch.getStationId(), StationSpecification.stId(srch.getStationId()));
|
||||
return rst;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
package net.jwsi.jcms.vpp.station;
|
||||
|
||||
|
||||
import org.springframework.data.jpa.domain.Specification;
|
||||
|
||||
public class StationSpecification {
|
||||
|
||||
public static Specification<Station> stId(String stId) {
|
||||
return (root, query, criteriaBuilder) -> criteriaBuilder.equal(root.get("stId"), stId);
|
||||
}
|
||||
}
|
||||
@@ -12,54 +12,12 @@
|
||||
<input type="text" id="stNmLike" name="stNmLike" class="form-control" placeholder="충전소명 입력" maxlength="50">
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-lg-4 col-sm-6 col-xs-12 pb-1">
|
||||
<div class="input-group">
|
||||
<span class="input-group-text" style="width:200px">주소 도로명 메인</span>
|
||||
<input type="text" id="addrRdMLike" name="addrRdMLike" class="form-control" placeholder="주소 도로명 메인 입력" maxlength="50">
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-lg-4 col-sm-6 col-xs-12 pb-1">
|
||||
<div class="input-group">
|
||||
<span class="input-group-text" style="width:200px">주소 도로명 상세</span>
|
||||
<input type="text" id="addrRdDLike" name="addrRdDLike" class="form-control" placeholder="주소 도로명 상세 입력" maxlength="50">
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-lg-4 col-sm-6 col-xs-12 pb-1">
|
||||
<div class="input-group">
|
||||
<span class="input-group-text" style="width:200px">주소 지번 메인</span>
|
||||
<input type="text" id="addrLdMLike" name="addrLdMLike" class="form-control" placeholder="주소 지번 메인 입력" maxlength="50">
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-lg-4 col-sm-6 col-xs-12 pb-1">
|
||||
<div class="input-group">
|
||||
<span class="input-group-text" style="width:200px">주소 지번 상세</span>
|
||||
<input type="text" id="addrLdDLike" name="addrLdDLike" class="form-control" placeholder="주소 지번 상세 입력" maxlength="50">
|
||||
</div>
|
||||
</div>
|
||||
<!-- <div class="col-lg-4 col-sm-6 col-xs-12 pb-1">-->
|
||||
<!-- <div class="input-group">-->
|
||||
<!-- <span class="input-group-text" style="width:200px">시설 구분 코드</span>-->
|
||||
<!-- <select id="stFacilTpCdLike" name="stFacilTpCdLike" class="form-control"></select>-->
|
||||
<!-- </div>-->
|
||||
<!-- </div>-->
|
||||
<!-- <div class="col-lg-4 col-sm-6 col-xs-12 pb-1">-->
|
||||
<!-- <div class="input-group">-->
|
||||
<!-- <span class="input-group-text" style="width:200px">시설 상세 구분 코드</span>-->
|
||||
<!-- <select id="stFacilDTpCdLike" name="stFacilDTpCdLike" class="form-control"></select>-->
|
||||
<!-- </div>-->
|
||||
<!-- </div>-->
|
||||
<div class="col-lg-4 col-sm-6 col-xs-12 pb-1">
|
||||
<div class="input-group">
|
||||
<span class="input-group-text" style="width:200px">주차비 상세정보</span>
|
||||
<input type="text" id="parkingFeeDetlLike" name="parkingFeeDetlLike" class="form-control" placeholder="주차비 상세정보 입력" maxlength="50">
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-lg-4 col-sm-6 col-xs-12 pb-1">
|
||||
<div class="input-group">
|
||||
<span class="input-group-text" style="width:200px">PNU 코드</span>
|
||||
<input type="text" id="pnuNoLike" name="pnuNoLike" class="form-control" placeholder="PNU 코드 입력" maxlength="50">
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-lg-4 col-sm-6 col-xs-12 pb-1">
|
||||
<div class="input-group">
|
||||
<span class="input-group-text" style="width:200px">법정동 도 명</span>
|
||||
@@ -102,27 +60,18 @@
|
||||
</div>
|
||||
</div>
|
||||
<script th:inline="none">
|
||||
const rootPath = "/system/vppStation/";
|
||||
const rootPath = "/cms/station/";
|
||||
let datatable;
|
||||
// const stFacilTpCdCdList = getCdDtlList("####"); const stFacilDTpCdCdList = getCdDtlList("####");
|
||||
|
||||
$(document).ready(function() {
|
||||
// setSearchCdDtlOptions("stFacilTpCdLike", stFacilTpCdCdList);
|
||||
// setSearchCdDtlOptions("stFacilDTpCdLike", stFacilDTpCdCdList);
|
||||
const className = "dt-head-center dt-body-center";
|
||||
datatable = newDataTable(
|
||||
"#datatable",
|
||||
rootPath + "list.json",
|
||||
function(d) {
|
||||
if (strUtil.isNotEmpty($('#stNmLike').val())) {d.stNm = $('#stNmLike').val();}
|
||||
if (strUtil.isNotEmpty($('#addrRdMLike').val())) {d.addrRdM = $('#addrRdMLike').val();}
|
||||
if (strUtil.isNotEmpty($('#addrRdDLike').val())) {d.addrRdD = $('#addrRdDLike').val();}
|
||||
if (strUtil.isNotEmpty($('#addrLdMLike').val())) {d.addrLdM = $('#addrLdMLike').val();}
|
||||
if (strUtil.isNotEmpty($('#addrLdDLike').val())) {d.addrLdD = $('#addrLdDLike').val();}
|
||||
// if (strUtil.isNotEmpty($('#stFacilTpCdLike').val())) {d.stFacilTpCd = $('#stFacilTpCdLike').val();}
|
||||
// if (strUtil.isNotEmpty($('#stFacilDTpCdLike').val())) {d.stFacilDTpCd = $('#stFacilDTpCdLike').val();}
|
||||
if (strUtil.isNotEmpty($('#parkingFeeDetlLike').val())) {d.parkingFeeDetl = $('#parkingFeeDetlLike').val();}
|
||||
if (strUtil.isNotEmpty($('#pnuNoLike').val())) {d.pnuNo = $('#pnuNoLike').val();}
|
||||
if (strUtil.isNotEmpty($('#pnuDoNmLike').val())) {d.pnuDoNm = $('#pnuDoNmLike').val();}
|
||||
if (strUtil.isNotEmpty($('#pnuSiNmLike').val())) {d.pnuSiNm = $('#pnuSiNmLike').val();}
|
||||
if (strUtil.isNotEmpty($('#pnuDongNmLike').val())) {d.pnuDongNm = $('#pnuDongNmLike').val();}
|
||||
@@ -132,21 +81,11 @@
|
||||
order: [],
|
||||
columns: [
|
||||
{title: "충전소명", name: "ST_NM", data: "stNm", className, orderable: false},
|
||||
{title: "주소 도로명 메인", name: "ADDR_RD_M", data: "addrRdM", className, orderable: false},
|
||||
{title: "주소 도로명 상세", name: "ADDR_RD_D", data: "addrRdD", className, orderable: false},
|
||||
{title: "주소 지번 메인", name: "ADDR_LD_M", data: "addrLdM", className, orderable: false},
|
||||
{title: "주소 지번 상세", name: "ADDR_LD_D", data: "addrLdD", className, orderable: false},
|
||||
// {title: "시설 구분 코드", name: "st_facil_tp_cd", data: "stFacilTpCd", className, orderable: false,
|
||||
// render: (data, type, row) => getCdDtlDtColNm(stFacilTpCdCdList, row["stFacilTpCd"]) },
|
||||
// {title: "시설 상세 구분 코드", name: "st_facil_d_tp_cd", data: "stFacilDTpCd", className, orderable: false,
|
||||
// render: (data, type, row) => getCdDtlDtColNm(stFacilDTpCdCdList, row["stFacilDTpCd"]) },
|
||||
{title: "주차비 여부", name: "parking_fee_yn", data: "parkingFeeYn", className, orderable: false},
|
||||
{title: "주차비 상세정보", name: "PARKING_FEE_DETL", data: "parkingFeeDetl", className, orderable: false},
|
||||
{title: "PNU 코드", name: "pnu_no", data: "pnuNo", className, orderable: false},
|
||||
{title: "법정동 도 명", name: "PNU_DO_NM", data: "pnuDoNm", className, orderable: false},
|
||||
{title: "법정동 시 명", name: "PNU_SI_NM", data: "pnuSiNm", className, orderable: false},
|
||||
{title: "법정동 읍면동 명", name: "PNU_DONG_NM", data: "pnuDongNm", className, orderable: false},
|
||||
null
|
||||
{title: "기능", orderable: false, width: "140px", className,
|
||||
render: (data, type, row) => { return mkRowDataFunctions( { stationId: row['stationId'] },row['stNm'], true, true, true);}
|
||||
}
|
||||
],
|
||||
allCheck: false,
|
||||
});
|
||||
@@ -171,8 +110,8 @@
|
||||
}),
|
||||
new ModalInput({
|
||||
inputType: ModalInputType.hidden,
|
||||
inputId: "stId",
|
||||
inputName: "stId",
|
||||
inputId: "stationId",
|
||||
inputName: "stationId",
|
||||
hasOldPk: true,
|
||||
inputLabel: "충전소ID",
|
||||
inputPlaceholder: "충전소ID",
|
||||
@@ -236,26 +175,6 @@
|
||||
minLen: 0,
|
||||
maxLen: 250,
|
||||
}),
|
||||
// new ModalInput({
|
||||
// inputType: ModalInputType.select,
|
||||
// inputId: "stFacilTpCd",
|
||||
// inputName: "stFacilTpCd",
|
||||
// inputLabel: "시설 구분 코드",
|
||||
// inputPlaceholder: "시설 구분 코드",
|
||||
// isReq: false,
|
||||
// isEnable: true,
|
||||
// itemArray: toCdDtlItemArray(stFacilTpCdCdList),
|
||||
// }),
|
||||
// new ModalInput({
|
||||
// inputType: ModalInputType.select,
|
||||
// inputId: "stFacilDTpCd",
|
||||
// inputName: "stFacilDTpCd",
|
||||
// inputLabel: "시설 상세 구분 코드",
|
||||
// inputPlaceholder: "시설 상세 구분 코드",
|
||||
// isReq: false,
|
||||
// isEnable: true,
|
||||
// itemArray: toCdDtlItemArray(stFacilDTpCdCdList),
|
||||
// }),
|
||||
new ModalInput({
|
||||
inputType: ModalInputType.switch,
|
||||
inputId: "parkingFeeYn",
|
||||
@@ -352,8 +271,6 @@
|
||||
$("#addrRdDLike").val("");
|
||||
$("#addrLdMLike").val("");
|
||||
$("#addrLdDLike").val("");
|
||||
// $("#stFacilTpCdLike").val("");
|
||||
// $("#stFacilDTpCdLike").val("");
|
||||
$("#parkingFeeDetlLike").val("");
|
||||
$("#pnuNoLike").val("");
|
||||
$("#pnuDoNmLike").val("");
|
||||
|
||||
@@ -23,22 +23,22 @@ class StationServiceTest {
|
||||
@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() + ") ======");
|
||||
}
|
||||
}
|
||||
// @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