|
|
|
|
@ -1,6 +1,9 @@
|
|
|
|
|
package go.kr.project.carInspectionPenalty.registration.service.impl;
|
|
|
|
|
|
|
|
|
|
import egovframework.exception.MessageException;
|
|
|
|
|
import go.kr.project.api.model.VehicleApiResponseVO;
|
|
|
|
|
import go.kr.project.api.model.request.BasicRequest;
|
|
|
|
|
import go.kr.project.api.service.VehicleInfoService;
|
|
|
|
|
import go.kr.project.carInspectionPenalty.registration.config.CarFfnlgTxtParseConfig;
|
|
|
|
|
import go.kr.project.carInspectionPenalty.registration.mapper.CarFfnlgTrgtMapper;
|
|
|
|
|
import go.kr.project.carInspectionPenalty.registration.model.CarFfnlgTrgtVO;
|
|
|
|
|
@ -21,6 +24,7 @@ import java.util.ArrayList;
|
|
|
|
|
import java.util.HashMap;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
import java.util.Objects;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 자동차 과태료 대상 Service 구현체
|
|
|
|
|
@ -29,9 +33,10 @@ import java.util.Map;
|
|
|
|
|
@RequiredArgsConstructor
|
|
|
|
|
@Slf4j
|
|
|
|
|
public class CarFfnlgTrgtServiceImpl implements CarFfnlgTrgtService {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private final CarFfnlgTrgtMapper mapper;
|
|
|
|
|
private final CarFfnlgTxtParseConfig parseConfig;
|
|
|
|
|
private final VehicleInfoService vehicleInfoService;
|
|
|
|
|
|
|
|
|
|
// 날짜 형식 (YYYYMMDD)
|
|
|
|
|
private static final DateTimeFormatter DATE_FORMATTER = DateTimeFormatter.ofPattern("yyyyMMdd");
|
|
|
|
|
@ -889,4 +894,161 @@ public class CarFfnlgTrgtServiceImpl implements CarFfnlgTrgtService {
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 선택된 목록에 대해 API 호출 및 기본정보/등록원부 비교
|
|
|
|
|
*
|
|
|
|
|
* @param targetList 선택된 과태료 대상 목록
|
|
|
|
|
* @return 비교 결과
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
public Map<String, Object> compareWithApi(List<Map<String, String>> targetList) {
|
|
|
|
|
log.info("========== API 호출 및 비교 시작 ==========");
|
|
|
|
|
log.info("선택된 데이터 건수: {}", targetList != null ? targetList.size() : 0);
|
|
|
|
|
|
|
|
|
|
if (targetList == null || targetList.isEmpty()) {
|
|
|
|
|
throw new IllegalArgumentException("선택된 데이터가 없습니다.");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
List<Map<String, Object>> compareResults = new ArrayList<>();
|
|
|
|
|
int successCount = 0;
|
|
|
|
|
int failCount = 0;
|
|
|
|
|
|
|
|
|
|
for (Map<String, String> target : targetList) {
|
|
|
|
|
String carFfnlgTrgtId = target.get("carFfnlgTrgtId");
|
|
|
|
|
String vhclno = target.get("vhclno");
|
|
|
|
|
String inspYmd = target.get("inspYmd");
|
|
|
|
|
|
|
|
|
|
log.info("처리 중 - 차량번호: {}, 검사일자: {}", vhclno, inspYmd);
|
|
|
|
|
|
|
|
|
|
Map<String, Object> compareResult = new HashMap<>();
|
|
|
|
|
compareResult.put("carFfnlgTrgtId", carFfnlgTrgtId);
|
|
|
|
|
compareResult.put("vhclno", vhclno);
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
// 1. 기존 데이터 조회
|
|
|
|
|
CarFfnlgTrgtVO existingData = new CarFfnlgTrgtVO();
|
|
|
|
|
existingData.setCarFfnlgTrgtId(carFfnlgTrgtId);
|
|
|
|
|
existingData = mapper.selectOne(existingData);
|
|
|
|
|
|
|
|
|
|
if (existingData == null) {
|
|
|
|
|
compareResult.put("success", false);
|
|
|
|
|
compareResult.put("message", "기존 데이터를 찾을 수 없습니다.");
|
|
|
|
|
failCount++;
|
|
|
|
|
compareResults.add(compareResult);
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 2. API 호출 (통합 조회)
|
|
|
|
|
BasicRequest apiRequest = new BasicRequest();
|
|
|
|
|
apiRequest.setVhrno(vhclno);
|
|
|
|
|
apiRequest.setLevyStdde(inspYmd != null ? inspYmd.replace("-", "") : "");
|
|
|
|
|
apiRequest.setInqireSeCode("01"); // 조회구분코드 기본값
|
|
|
|
|
|
|
|
|
|
VehicleApiResponseVO apiResponse = vehicleInfoService.getVehicleInfo(apiRequest);
|
|
|
|
|
|
|
|
|
|
if (!apiResponse.isSuccess()) {
|
|
|
|
|
compareResult.put("success", false);
|
|
|
|
|
compareResult.put("message", "API 호출 실패: " + apiResponse.getMessage());
|
|
|
|
|
failCount++;
|
|
|
|
|
compareResults.add(compareResult);
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 3. 데이터 비교
|
|
|
|
|
Map<String, Object> comparisonDetail = compareData(existingData, apiResponse);
|
|
|
|
|
|
|
|
|
|
compareResult.put("success", true);
|
|
|
|
|
compareResult.put("message", "비교 완료");
|
|
|
|
|
compareResult.put("comparisonDetail", comparisonDetail);
|
|
|
|
|
successCount++;
|
|
|
|
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
log.error("데이터 비교 중 오류 발생 - 차량번호: {}", vhclno, e);
|
|
|
|
|
compareResult.put("success", false);
|
|
|
|
|
compareResult.put("message", "비교 중 오류: " + e.getMessage());
|
|
|
|
|
failCount++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
compareResults.add(compareResult);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Map<String, Object> resultData = new HashMap<>();
|
|
|
|
|
resultData.put("compareResults", compareResults);
|
|
|
|
|
resultData.put("totalCount", targetList.size());
|
|
|
|
|
resultData.put("successCount", successCount);
|
|
|
|
|
resultData.put("failCount", failCount);
|
|
|
|
|
|
|
|
|
|
log.info("========== API 호출 및 비교 완료 ==========");
|
|
|
|
|
log.info("성공: {}건, 실패: {}건", successCount, failCount);
|
|
|
|
|
|
|
|
|
|
return resultData;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 기존 데이터와 API 응답 데이터를 비교하는 로직
|
|
|
|
|
* TODO: 실제 비교 로직은 요구사항에 맞게 수정 필요
|
|
|
|
|
*
|
|
|
|
|
* @param existingData 기존 과태료 대상 데이터
|
|
|
|
|
* @param apiResponse API 응답 데이터
|
|
|
|
|
* @return 비교 결과 상세
|
|
|
|
|
*/
|
|
|
|
|
private Map<String, Object> compareData(CarFfnlgTrgtVO existingData, VehicleApiResponseVO apiResponse) {
|
|
|
|
|
Map<String, Object> comparison = new HashMap<>();
|
|
|
|
|
|
|
|
|
|
// 기본정보 비교
|
|
|
|
|
if (apiResponse.getBasicInfo() != null && apiResponse.getBasicInfo().getRecord() != null
|
|
|
|
|
&& !apiResponse.getBasicInfo().getRecord().isEmpty()) {
|
|
|
|
|
Map<String, String> basicComparison = new HashMap<>();
|
|
|
|
|
|
|
|
|
|
// 예시: 차량번호 비교
|
|
|
|
|
String existingVhclno = existingData.getVhclno();
|
|
|
|
|
String apiVhclno = apiResponse.getBasicInfo().getRecord().get(0).getVhrno();
|
|
|
|
|
basicComparison.put("차량번호_일치여부", Objects.equals(existingVhclno, apiVhclno) ? "일치" : "불일치");
|
|
|
|
|
basicComparison.put("기존_차량번호", existingVhclno);
|
|
|
|
|
basicComparison.put("API_차량번호", apiVhclno);
|
|
|
|
|
|
|
|
|
|
// 예시: 소유자명 비교
|
|
|
|
|
String existingOwnrNm = existingData.getOwnrNm();
|
|
|
|
|
String apiOwnrNm = apiResponse.getBasicInfo().getRecord().get(0).getMberNm();
|
|
|
|
|
basicComparison.put("소유자명_일치여부", Objects.equals(existingOwnrNm, apiOwnrNm) ? "일치" : "불일치");
|
|
|
|
|
basicComparison.put("기존_소유자명", existingOwnrNm);
|
|
|
|
|
basicComparison.put("API_소유자명", apiOwnrNm);
|
|
|
|
|
|
|
|
|
|
comparison.put("기본정보_비교", basicComparison);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 등록원부 비교
|
|
|
|
|
if (apiResponse.getLedgerInfo() != null) {
|
|
|
|
|
Map<String, String> ledgerComparison = new HashMap<>();
|
|
|
|
|
|
|
|
|
|
// 예시: 차량번호 비교 (등록원부)
|
|
|
|
|
String existingVhclno = existingData.getVhclno();
|
|
|
|
|
String apiVhclno = apiResponse.getLedgerInfo().getVhrno();
|
|
|
|
|
ledgerComparison.put("차량번호_일치여부", Objects.equals(existingVhclno, apiVhclno) ? "일치" : "불일치");
|
|
|
|
|
|
|
|
|
|
// TODO: 추가적인 등록원부 필드 비교 로직 작성
|
|
|
|
|
// 예: 차대번호, 등록일자 등
|
|
|
|
|
|
|
|
|
|
comparison.put("등록원부_비교", ledgerComparison);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 전체 일치 여부 판단
|
|
|
|
|
boolean allMatched = true;
|
|
|
|
|
if (apiResponse.getBasicInfo() != null && apiResponse.getBasicInfo().getRecord() != null
|
|
|
|
|
&& !apiResponse.getBasicInfo().getRecord().isEmpty()) {
|
|
|
|
|
String existingVhclno = existingData.getVhclno();
|
|
|
|
|
String apiVhclno = apiResponse.getBasicInfo().getRecord().get(0).getVhrno();
|
|
|
|
|
String existingOwnrNm = existingData.getOwnrNm();
|
|
|
|
|
String apiOwnrNm = apiResponse.getBasicInfo().getRecord().get(0).getMberNm();
|
|
|
|
|
|
|
|
|
|
if (!Objects.equals(existingVhclno, apiVhclno) || !Objects.equals(existingOwnrNm, apiOwnrNm)) {
|
|
|
|
|
allMatched = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
comparison.put("전체_일치여부", allMatched ? "일치" : "불일치");
|
|
|
|
|
|
|
|
|
|
return comparison;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|