431 lines
15 KiB
TypeScript
431 lines
15 KiB
TypeScript
import { client, stClient } from "@/shared/api";
|
|
import { withAuthHeader } from "@/shared/api/with-auth-header";
|
|
import { ENDPOINT } from "@/shared/config";
|
|
|
|
import {
|
|
type ApiResponse,
|
|
type cancelSubmitRequest,
|
|
type cancelSubmitResponse,
|
|
type CheckStatusCodeRequest,
|
|
type CheckStatusCodeResponse,
|
|
type CodesRefreshResponse,
|
|
type getReviewOpinionDetailRequest,
|
|
type getReviewOpinionDetailResponse,
|
|
type ImrRequest,
|
|
type ImrResponse,
|
|
type ImrStatusResponse,
|
|
type ReviewerInfoRequest,
|
|
type ReviewerInfoResponse,
|
|
type rollbackStatusRequest,
|
|
type rollbackStatusResponse,
|
|
type ReviewInputSaveRequest,
|
|
type ReviewOpinionSaveRequest,
|
|
type ReviewOpinionSaveResponse,
|
|
type ReviewReturnSaveRequest,
|
|
type ReviewReturnSaveResponse,
|
|
type ReviewSubmitRequest,
|
|
type ReviewSubmitResponse,
|
|
type SearchCondition,
|
|
type Sgg,
|
|
type StatiscicsExceptionResetRequest,
|
|
type StatiscicsExceptionResetResponse,
|
|
type StatiscicsManagementReviewHistoryRequest,
|
|
type StatiscicsManagementReviewHistoryResponse,
|
|
type StatisticsColumnGuideListResponse,
|
|
type StatisticsLogDetailResponse,
|
|
type StatisticsLogRequest,
|
|
type StatisticsLogResponse,
|
|
type StatisticsService,
|
|
type StatsInputPeriodDeleteApiResponse,
|
|
type StatsInputPeriodDeleteRequest,
|
|
type StatsInputPeriodDetailRequest,
|
|
type StatsInputPeriodDetailResponse,
|
|
type StatsInputPeriodListApiResponse,
|
|
type StatsInputPeriodListRequest,
|
|
type StatsInputPeriodSaveApiResponse,
|
|
type StatsInputPeriodSaveRequest,
|
|
type StatsInputStatusApproveBatchRequest,
|
|
type StatsInputStatusApproveKind,
|
|
type StatsInputStatusApproveResponse,
|
|
type SubmitExceptionRequest,
|
|
type SubmitExceptionResponse,
|
|
type SubmitVerifyExceptionRequest,
|
|
type SubmitVerifyExceptionResponse,
|
|
type unSubmitDataRequest,
|
|
type unSubmitDataResponse,
|
|
type VerificationResultListRequest,
|
|
type VerificationResultListResponse,
|
|
} from "../model/statistics-interface";
|
|
|
|
export class StatisticsApiService implements StatisticsService {
|
|
public async getSidoList(params?: {
|
|
instSeCd?: string;
|
|
isInput?: boolean;
|
|
}): Promise<ApiResponse<SearchCondition>> {
|
|
const response = await stClient.get<ApiResponse<SearchCondition>>(
|
|
`${ENDPOINT.ST_SERVICE.COMMON}/search-condition`,
|
|
{ params },
|
|
);
|
|
return response.data;
|
|
}
|
|
|
|
public async getSidoListInput(params?: {
|
|
instSeCd?: string;
|
|
isInput?: boolean;
|
|
}): Promise<ApiResponse<SearchCondition>> {
|
|
const response = await stClient.get<ApiResponse<SearchCondition>>(
|
|
`${ENDPOINT.ST_SERVICE.COMMON}/search-condition-input`,
|
|
{ params },
|
|
);
|
|
return response.data;
|
|
}
|
|
|
|
public async getSggList(
|
|
sidoName: string,
|
|
params?: { instSeCd?: string; gugunSkipYn?: "Y" | "N" },
|
|
): Promise<ApiResponse<Sgg[]>> {
|
|
const response = await stClient.get<ApiResponse<Sgg[]>>(
|
|
`${ENDPOINT.ST_SERVICE.COMMON}/sgg`,
|
|
{ params: { sidoName, ...params } },
|
|
);
|
|
return response.data;
|
|
}
|
|
|
|
public async getSggAllList(
|
|
sidoName: string,
|
|
params?: { instSeCd?: string; gugunSkipYn?: "Y" | "N" },
|
|
): Promise<ApiResponse<Sgg[]>> {
|
|
const response = await stClient.get<ApiResponse<Sgg[]>>(
|
|
`${ENDPOINT.ST_SERVICE.COMMON}/sgg-all`,
|
|
{ params: { sidoName, ...params } },
|
|
);
|
|
return response.data;
|
|
}
|
|
|
|
/** 통계 입력 기간(연도·분류별) 목록 조회 — 경로는 백엔드 스펙에 맞게 수정 */
|
|
public async getStatsInputPeriodList(
|
|
params?: StatsInputPeriodListRequest,
|
|
): Promise<StatsInputPeriodListApiResponse> {
|
|
const response = await stClient.get<StatsInputPeriodListApiResponse>(
|
|
`${ENDPOINT.ST_SERVICE.DASHBOARD}/schedule-info/list`,
|
|
withAuthHeader({ params }),
|
|
);
|
|
return response.data;
|
|
}
|
|
|
|
public async getStatsInputPeriodDetail(
|
|
params: StatsInputPeriodDetailRequest,
|
|
): Promise<StatsInputPeriodDetailResponse> {
|
|
const response = await stClient.get<StatsInputPeriodDetailResponse>(
|
|
`${ENDPOINT.ST_SERVICE.DASHBOARD}/schedule-info/detail`,
|
|
withAuthHeader({ params }),
|
|
);
|
|
return response.data;
|
|
}
|
|
|
|
/** 통계 입력 기간 저장 — 경로는 백엔드 스펙에 맞게 수정 */
|
|
public async saveStatsInputPeriod(
|
|
param: StatsInputPeriodSaveRequest,
|
|
): Promise<StatsInputPeriodSaveApiResponse> {
|
|
const response = await stClient.post<StatsInputPeriodSaveApiResponse>(
|
|
`${ENDPOINT.ST_SERVICE.DASHBOARD}/schedule-info`,
|
|
param,
|
|
withAuthHeader(),
|
|
);
|
|
return response.data;
|
|
}
|
|
|
|
/** 통계 입력 기간 삭제 — JSON body. HTTP 메서드·URL은 백엔드 스펙에 맞게 수정 */
|
|
public async deleteStatsInputPeriod(
|
|
param: StatsInputPeriodDeleteRequest,
|
|
): Promise<StatsInputPeriodDeleteApiResponse> {
|
|
const response =
|
|
await stClient.delete<StatsInputPeriodDeleteApiResponse>(
|
|
`${ENDPOINT.ST_SERVICE.DASHBOARD}/schedule-info`,
|
|
withAuthHeader({ data: param }),
|
|
);
|
|
return response.data;
|
|
}
|
|
|
|
// 입력 - 제출 취소
|
|
public async cancelSubmit(
|
|
param: cancelSubmitRequest,
|
|
): Promise<cancelSubmitResponse> {
|
|
const response = await stClient.put<cancelSubmitResponse>(
|
|
`${ENDPOINT.ST_SERVICE.INPUTCOMMON}/cancel-submit`,
|
|
param,
|
|
);
|
|
return response.data;
|
|
}
|
|
|
|
// 입력 - 검증 이전 상태로 롤백
|
|
public async rollbackStatus(
|
|
param: rollbackStatusRequest,
|
|
): Promise<rollbackStatusResponse> {
|
|
const response = await stClient.put<rollbackStatusResponse>(
|
|
`${ENDPOINT.ST_SERVICE.INPUTCOMMON}/rollback-status`,
|
|
param,
|
|
);
|
|
return response.data;
|
|
}
|
|
|
|
public async callImrService(param: ImrRequest): Promise<ImrResponse> {
|
|
const response = await client.post<ImrResponse>(
|
|
`${ENDPOINT.STATVERIFY_SERVICE.IMR}`,
|
|
param,
|
|
);
|
|
return response.data;
|
|
}
|
|
|
|
public async getImrStatus(param: string): Promise<ImrStatusResponse> {
|
|
const response = await client.get<ImrStatusResponse>(
|
|
`${ENDPOINT.STATVERIFY_SERVICE.IMR}/status/${param}`,
|
|
);
|
|
return response.data;
|
|
}
|
|
|
|
// 예외 제출
|
|
public async submitException(
|
|
param: SubmitExceptionRequest,
|
|
): Promise<SubmitExceptionResponse> {
|
|
const response = await stClient.post<SubmitExceptionResponse>(
|
|
`${ENDPOINT.ST_SERVICE.INPUTCOMMON}/submit-exception`,
|
|
param,
|
|
);
|
|
return response.data;
|
|
}
|
|
|
|
public async getLogList(
|
|
param: StatisticsLogRequest,
|
|
): Promise<StatisticsLogResponse> {
|
|
const response = await stClient.get<StatisticsLogResponse>(
|
|
`${ENDPOINT.ST_SERVICE.INPUTCOMMON}/logs`,
|
|
{ params: param },
|
|
);
|
|
return response.data;
|
|
}
|
|
|
|
public async getLogDetail(
|
|
param: string,
|
|
): Promise<StatisticsLogDetailResponse> {
|
|
const response = await stClient.get<StatisticsLogDetailResponse>(
|
|
`${ENDPOINT.ST_SERVICE.INPUTCOMMON}/logs/${param}`,
|
|
);
|
|
return response.data;
|
|
}
|
|
|
|
/** 컬럼 가이드 목록 조회 — GET `.../common/column-guides?statsCd=` */
|
|
public async getColumnGuides(
|
|
param: string,
|
|
): Promise<StatisticsColumnGuideListResponse> {
|
|
const response = await stClient.get<StatisticsColumnGuideListResponse>(
|
|
`${ENDPOINT.ST_SERVICE.INPUTCOMMON}/column-guides`,
|
|
{ params: { statsCd: param } },
|
|
);
|
|
return response.data;
|
|
}
|
|
|
|
public async saveReviewOpinion(
|
|
param: ReviewOpinionSaveRequest,
|
|
): Promise<ReviewOpinionSaveResponse> {
|
|
const response = await stClient.post<ReviewOpinionSaveResponse>(
|
|
`${ENDPOINT.ST_SERVICE.REVIEW}/opinion-save`,
|
|
param,
|
|
);
|
|
return response.data;
|
|
}
|
|
|
|
public async getReviewOpinionDetail(
|
|
param: getReviewOpinionDetailRequest,
|
|
): Promise<getReviewOpinionDetailResponse> {
|
|
const response = await stClient.get<getReviewOpinionDetailResponse>(
|
|
`${ENDPOINT.ST_SERVICE.REVIEW}/opinion-select`,
|
|
{ params: param },
|
|
);
|
|
return response.data;
|
|
}
|
|
|
|
public async saveReviewReturn(
|
|
param: ReviewReturnSaveRequest,
|
|
): Promise<ReviewReturnSaveResponse> {
|
|
const { type, ...body } = param;
|
|
const response = await stClient.post<ReviewReturnSaveResponse>(
|
|
`${ENDPOINT.ST_SERVICE.STATS}/reject`,
|
|
body,
|
|
{ params: { type } },
|
|
);
|
|
return response.data;
|
|
}
|
|
|
|
/** 입력 반려 — JSON body는 `ReviewInputSaveRequest`(type 제외) 항목의 배열, `type`은 쿼리 */
|
|
public async saveInputReturn(
|
|
items: ReviewInputSaveRequest[],
|
|
): Promise<ReviewReturnSaveResponse> {
|
|
if (items.length === 0) {
|
|
throw new Error("saveInputReturn: 항목이 비어 있습니다.");
|
|
}
|
|
const [first] = items;
|
|
if (!first) {
|
|
throw new Error("saveInputReturn: 항목이 비어 있습니다.");
|
|
}
|
|
const type = first.type;
|
|
if (!items.every((i) => i.type === type)) {
|
|
throw new Error(
|
|
"saveInputReturn: 모든 항목의 type이 같아야 합니다.",
|
|
);
|
|
}
|
|
const body = items.map(({ type: _t, rjctOpnnCn, ...rest }) => {
|
|
const row: Record<string, string> = {
|
|
statsYr: rest.statsYr,
|
|
sewerBzmnCd: rest.sewerBzmnCd,
|
|
statsCd: rest.statsCd,
|
|
mdfrUuid: rest.mdfrUuid,
|
|
};
|
|
if (rest.vrfcSn != null && String(rest.vrfcSn).trim() !== "") {
|
|
row.vrfcSn = String(rest.vrfcSn);
|
|
}
|
|
const trimmed = rjctOpnnCn?.trim();
|
|
if (trimmed) row.rjctOpnnCn = trimmed;
|
|
return row;
|
|
});
|
|
const response = await stClient.post<ReviewReturnSaveResponse>(
|
|
`${ENDPOINT.ST_SERVICE.STATS}/reject`,
|
|
body,
|
|
{ params: { type } },
|
|
);
|
|
return response.data;
|
|
}
|
|
|
|
/** 통계 입력 현황 일괄 승인 — 쿼리 `type`(기본 `INPUT`), body는 `{ list }` */
|
|
public async approveStatsInputStatus(
|
|
param: StatsInputStatusApproveBatchRequest,
|
|
type: StatsInputStatusApproveKind = "INPUT",
|
|
): Promise<StatsInputStatusApproveResponse> {
|
|
const response = await stClient.post<StatsInputStatusApproveResponse>(
|
|
`${ENDPOINT.ST_SERVICE.STATS}/approve`,
|
|
param.list,
|
|
withAuthHeader({ params: { type } }),
|
|
);
|
|
return response.data;
|
|
}
|
|
|
|
public async submitReview(
|
|
param: ReviewSubmitRequest,
|
|
): Promise<ReviewSubmitResponse> {
|
|
const response = await stClient.post<ReviewSubmitResponse>(
|
|
`${ENDPOINT.ST_SERVICE.REVIEW}/submit`,
|
|
param,
|
|
withAuthHeader(),
|
|
);
|
|
return response.data;
|
|
}
|
|
|
|
public async getVerificationResultList(
|
|
param: VerificationResultListRequest,
|
|
): Promise<VerificationResultListResponse> {
|
|
const { statsCd, ...rest } = param;
|
|
const params: VerificationResultListRequest = {
|
|
...rest,
|
|
...(statsCd && statsCd !== "ALL" ? { statsCd } : {}),
|
|
};
|
|
const response = await stClient.get<VerificationResultListResponse>(
|
|
`${ENDPOINT.ST_SERVICE.INPUTVERIFY}/results/input`,
|
|
{ params },
|
|
);
|
|
return response.data;
|
|
}
|
|
|
|
public async SubmitVerifyException(
|
|
param: SubmitVerifyExceptionRequest,
|
|
): Promise<SubmitVerifyExceptionResponse> {
|
|
const response = await stClient.put<SubmitVerifyExceptionResponse>(
|
|
`${ENDPOINT.ST_SERVICE.INPUTVERIFY}/results/exception`,
|
|
param,
|
|
);
|
|
return response.data;
|
|
}
|
|
|
|
public async getReviewerInfo(
|
|
param: ReviewerInfoRequest,
|
|
): Promise<ReviewerInfoResponse> {
|
|
const response = await stClient.get<ReviewerInfoResponse>(
|
|
`${ENDPOINT.ST_SERVICE.REVIEW}/reviewer-info`,
|
|
withAuthHeader({ params: param }),
|
|
);
|
|
return response.data;
|
|
}
|
|
|
|
public async getStatiscicsManagementReviewHistory(
|
|
param: StatiscicsManagementReviewHistoryRequest,
|
|
): Promise<StatiscicsManagementReviewHistoryResponse> {
|
|
const response =
|
|
await stClient.get<StatiscicsManagementReviewHistoryResponse>(
|
|
`${ENDPOINT.ST_SERVICE.REVIEW}/stats-review`,
|
|
{ params: param },
|
|
);
|
|
return response.data;
|
|
}
|
|
|
|
public async StatiscicsExceptionReset(
|
|
param: StatiscicsExceptionResetRequest,
|
|
): Promise<StatiscicsExceptionResetResponse> {
|
|
const response = await stClient.put<StatiscicsExceptionResetResponse>(
|
|
`${ENDPOINT.ST_SERVICE.INPUTVERIFY}/results/exception/reset`,
|
|
param,
|
|
);
|
|
return response.data;
|
|
}
|
|
|
|
public async CheckStatusCode(
|
|
param: CheckStatusCodeRequest,
|
|
): Promise<CheckStatusCodeResponse> {
|
|
const response = await stClient.get<CheckStatusCodeResponse>(
|
|
`${ENDPOINT.ST_SERVICE.INPUTCOMMON}/status-code`,
|
|
{ params: param },
|
|
);
|
|
return response.data;
|
|
}
|
|
|
|
public async getUnSubmitData(
|
|
param: unSubmitDataRequest,
|
|
): Promise<unSubmitDataResponse> {
|
|
const response = await stClient.get<unSubmitDataResponse>(
|
|
`${ENDPOINT.ST_SERVICE.DASHBOARD}/submission-status`,
|
|
{ params: param },
|
|
);
|
|
return response.data;
|
|
}
|
|
|
|
/** 입력 서비스 공통 코드 메모리 캐시 동기화 */
|
|
public async refreshCommonCodes(): Promise<CodesRefreshResponse> {
|
|
const response = await stClient.post<CodesRefreshResponse>(
|
|
`${ENDPOINT.ST_SERVICE.INPUTCOMMON}/codes-refresh`,
|
|
null,
|
|
withAuthHeader(),
|
|
);
|
|
return response.data;
|
|
}
|
|
|
|
/** 관리 서비스 공통 코드 메모리 캐시 동기화 */
|
|
public async refreshManagementCommonCodes(): Promise<CodesRefreshResponse> {
|
|
const response = await stClient.post<CodesRefreshResponse>(
|
|
`${ENDPOINT.ST_SERVICE.COMMON}/codes/refresh`,
|
|
null,
|
|
withAuthHeader(),
|
|
);
|
|
return response.data;
|
|
}
|
|
|
|
/** 입력/관리 공통 코드 캐시 동기화 (한쪽 실패해도 다른 쪽은 완료) */
|
|
public async refreshAllCommonCodes(): Promise<
|
|
PromiseSettledResult<CodesRefreshResponse>[]
|
|
> {
|
|
return Promise.allSettled([
|
|
this.refreshCommonCodes(),
|
|
this.refreshManagementCommonCodes(),
|
|
]);
|
|
}
|
|
}
|
|
|
|
export const statisticsApi = new StatisticsApiService();
|