2313 lines
94 KiB
TypeScript
2313 lines
94 KiB
TypeScript
import {
|
|
type Dispatch,
|
|
type SetStateAction,
|
|
useCallback,
|
|
useEffect,
|
|
useMemo,
|
|
useRef,
|
|
useState,
|
|
} from "react";
|
|
import { flushSync } from "react-dom";
|
|
|
|
import { useConfirm } from "@frontend-opensource/use-react-hooks";
|
|
import { ValueType } from "realgrid";
|
|
import type { RealGridReact } from "realgrid-react";
|
|
|
|
import { useAlertStore, useGlobalProgressStore, useStatisticsInputToolbarGroupGate, useSearchConditionSidoList } from "@/shared/lib";
|
|
import { STATISTICS_INPUT_URL_PATH } from "@/shared/lib/stats-cd-input-navigation";
|
|
import { useStatisticsInputPendingNavigation } from "@/shared/lib/use-statistics-input-pending-navigation";
|
|
import { ConfirmDialog } from "@/shared/ui/confirm-dialog";
|
|
import { filterSggOptionsBySearchGugun } from "@/components/util/input/filter-sgg-options-by-search";
|
|
import { nullableTrimmedString } from "@/components/util/input/nullableString";
|
|
import { statisticsInputSewSupplyRateApi } from "@/entities/statistics/api/input/statistics-input-sew-supply-rate-service";
|
|
import { statisticsInputSewageExcretaSlurgeApi } from "@/entities/statistics/api/input/statistics-input-sewage-excreta-slurge-service";
|
|
import { statisticsApi } from "@/entities/statistics/api/statistics-service";
|
|
import { callImrServiceWithRollbackOnFailure } from "@/components/util/input/call-imr-with-rollback";
|
|
import type {
|
|
DigestorOperatingStatusSaveItem,
|
|
ExcretaSlurgeProcessingStatusSaveItem,
|
|
SewageExcretaSlurgeRequestParams,
|
|
SewageExcretaSlurgeVerificationResult,
|
|
SewageSlurgeProcessingFacStatusSaveItem,
|
|
SlurgeProcessingFacStatusSaveItem,
|
|
} from "@/entities/statistics/model/input/statistics-input-sewage-excreta-slurge-interface";
|
|
import {
|
|
SEWAGE_EXCRETA_DIGESTOR_OPERATING_STATS_CD,
|
|
SEWAGE_EXCRETA_EXCRETA_SLURGE_PROCESSING_STATS_CD,
|
|
SEWAGE_EXCRETA_SEWAGE_SLURGE_FAC_STATUS_STATS_CD,
|
|
SEWAGE_EXCRETA_SLURGE_PROCESSING_FAC_STATUS_STATS_CD,
|
|
} from "@/entities/statistics/model/input/statistics-input-sewage-excreta-slurge-interface";
|
|
import { isInputPeriodCurrent } from "@/entities/statistics/model/input/statistics-sewage-supply-rate-input-interface";
|
|
import type { StatisticsInputSubmitInfoFormData } from "@/entities/statistics/model/statistics-input-submit-info-schema";
|
|
import type { ApiResponse, cancelSubmitRequest, ImrStatusResponse, SewerageStatusInfo, Sgg, Sido } from "@/entities/statistics/model/statistics-interface";
|
|
import {
|
|
filterBySelectedAdmdstCd,
|
|
isGugunOkForToolbar,
|
|
isSubmitOkForToolbar,
|
|
resolveNoApplicableForRequest,
|
|
toInputSearchRegion,
|
|
} from "@/entities/statistics";
|
|
|
|
import { LoadingWithAnimation, Tabs, TabsContent, TabsList, TabsTrigger } from "@common/components";
|
|
|
|
import { getUserInfo } from "../../../../../../packages/common/components/src/api";
|
|
|
|
import SubmitDailog from "./SubmitDailog";
|
|
|
|
import AddArticleButton from "@/components/button/AddArticleButton";
|
|
import CancelSubmitButton from "@/components/button/CancelSubmitButton";
|
|
import DeleteArticleButton from "@/components/button/DeleteArticleButton";
|
|
import LastYearDataButton from "@/components/button/LastYearDataButton";
|
|
import NotApplicableCheckButton from "@/components/button/NotApplicableCheckButton";
|
|
import SaveButton from "@/components/button/SaveButton";
|
|
import SubmitButton from "@/components/button/SumitButton";
|
|
import UpdateOperateDataButton from "@/components/button/UpdateOperateDataButton";
|
|
import VerificationResultButton from "@/components/button/VerificationResultButton";
|
|
import DataGrid from "@/components/module/DataGrid";
|
|
import { openVerificationResultDialogIfNeeded } from "@/components/module/post-submit-verification-results";
|
|
import SearchForm from "@/components/module/SearchForm";
|
|
import { VerificationResultDialog } from "@/components/module/VerificationResultDialog";
|
|
import { VerificationResultHistoryDialog } from "@/components/module/VerificationResultHistoryDialog";
|
|
import type {
|
|
CellEditedCallback,
|
|
CellStyleCallback,
|
|
CellStyleCallbackParams,
|
|
CellStyleCallbackResult,
|
|
CellTooltipCallbackParams,
|
|
ColumnConfig,
|
|
ColumnInfo,
|
|
} from "@/components/type/DataGrid.type";
|
|
import type { SearchFormValues } from "@/components/type/SearchForm.type";
|
|
import {
|
|
DIGESTOR_OPERATING_STATUS_EN_YN_FIELD,
|
|
DigestorOperatingStatusInpColumn,
|
|
isDigestorOperatingRowDisabled,
|
|
} from "@/components/util/column/input/sewageExcretaSlurge/DigestorOperatingStatusInpColumn";
|
|
import { ExcretaSlurgeProcessingStatusInpColumn } from "@/components/util/column/input/sewageExcretaSlurge/ExcretaSlurgeProcessingStatusInpColumn";
|
|
import { SewageSlurgeProcessingFacStatusInpColumn } from "@/components/util/column/input/sewageExcretaSlurge/SewageSlurgeProcessingFacStatusInpColumn";
|
|
import { SlurgeProcessingFacStatusInpColumn } from "@/components/util/column/input/sewageExcretaSlurge/SlurgeProcessingFacStatusInpColumn";
|
|
import { fetchColumnGuidesRecord } from "@/components/util/grid/columnGuides";
|
|
import { toGridRows } from "@/components/util/grid/gridFunction";
|
|
import { toExcelExportSearchContextFromSearchForm } from "@/components/util/gridExcelExport";
|
|
import {
|
|
patchFooterVerificationByTab,
|
|
patchVerificationFailedByTab,
|
|
} from "@/components/util/input/verification-failed-flag";
|
|
import {
|
|
formatVerificationTooltip,
|
|
normalizeVerificationResultMap,
|
|
type VerificationResultLikeMap,
|
|
} from "@/components/util/input/verification-result-display";
|
|
import { useAdminStore } from "@/store/admin-store";
|
|
import { useTabStore } from "@/store/tab-store";
|
|
|
|
type GridRowWithVerification = Record<string, string | number> & {
|
|
verificationResult?: SewageExcretaSlurgeVerificationResult;
|
|
};
|
|
|
|
function mergeCellStyleResults(
|
|
...results: (CellStyleCallbackResult | undefined)[]
|
|
): CellStyleCallbackResult | undefined {
|
|
const styleNames: string[] = [];
|
|
let editable: boolean | undefined;
|
|
let readOnly: boolean | undefined;
|
|
|
|
for (const result of results) {
|
|
if (!result) continue;
|
|
if (typeof result === "string") {
|
|
styleNames.push(result);
|
|
continue;
|
|
}
|
|
if (result.styleName) styleNames.push(result.styleName);
|
|
if (result.editable === false) editable = false;
|
|
if (result.readOnly === true) readOnly = true;
|
|
}
|
|
|
|
const styleName = styleNames.join(" ").trim();
|
|
if (!styleName && editable === undefined && readOnly === undefined) {
|
|
return undefined;
|
|
}
|
|
return {
|
|
...(styleName ? { styleName } : {}),
|
|
...(editable !== undefined ? { editable } : {}),
|
|
...(readOnly !== undefined ? { readOnly } : {}),
|
|
};
|
|
}
|
|
|
|
function verificationCellStyle({
|
|
fieldName,
|
|
row,
|
|
}: CellStyleCallbackParams): CellStyleCallbackResult | undefined {
|
|
const verification = (row as GridRowWithVerification).verificationResult;
|
|
if (!verification) return;
|
|
const errors = verification[fieldName];
|
|
if (Array.isArray(errors) && errors.length > 0) {
|
|
const hasImr = errors.some((e) => e.vrfcCd === "IMR" || e.vrfcCd === "HB");
|
|
return hasImr ? "rg-cell-verify-error-imr" : "rg-cell-verify-error";
|
|
}
|
|
}
|
|
|
|
function verificationCellTooltip({
|
|
fieldName,
|
|
row,
|
|
}: CellTooltipCallbackParams): string | undefined {
|
|
const verification = (row as GridRowWithVerification).verificationResult;
|
|
if (!verification) return;
|
|
const errors = verification[fieldName];
|
|
if (Array.isArray(errors) && errors.length > 0) {
|
|
return formatVerificationTooltip(errors);
|
|
}
|
|
}
|
|
|
|
function buildSewageExcretaSlurgeSearchParam(
|
|
values: SearchFormValues,
|
|
overrides?: { mode?: string },
|
|
): SewageExcretaSlurgeRequestParams {
|
|
return {
|
|
statsYr: values.year,
|
|
ctpvNm: values.sido,
|
|
...toInputSearchRegion(sidoListRef.current, values),
|
|
fcltNm: values.fctName?.trim() || undefined,
|
|
...(overrides?.mode ? { mode: overrides.mode } : {}),
|
|
};
|
|
}
|
|
|
|
function mapListToGridRows<T extends { verificationResult?: SewageExcretaSlurgeVerificationResult }>(
|
|
list: T[] | undefined,
|
|
ctpvNm: string,
|
|
values?: SearchFormValues | null,
|
|
): GridRowWithVerification[] {
|
|
return filterBySelectedAdmdstCd(list, sidoListRef.current, values).map((item) => {
|
|
const row = toGridRows([{ ctpvNm, ...item }])[0] as GridRowWithVerification;
|
|
if (item.verificationResult) {
|
|
row.verificationResult = normalizeVerificationResultMap(item.verificationResult);
|
|
}
|
|
return row;
|
|
});
|
|
}
|
|
|
|
const SewageExcretaSlurgeInpTabList = [
|
|
SlurgeProcessingFacStatusInpColumn,
|
|
DigestorOperatingStatusInpColumn,
|
|
SewageSlurgeProcessingFacStatusInpColumn,
|
|
ExcretaSlurgeProcessingStatusInpColumn,
|
|
] as const;
|
|
|
|
const firstTabKey = SlurgeProcessingFacStatusInpColumn.tabKey;
|
|
|
|
/** 항목 추가·제외 대상 탭 — ST00110003 (ST00110001·ST00110002·ST00110004 제외) */
|
|
const ARTICLE_EDIT_TAB_KEYS = new Set<string>([
|
|
SewageSlurgeProcessingFacStatusInpColumn.tabKey,
|
|
]);
|
|
|
|
/** ST00110003 — 시군구(sggNm) 드롭다운 선택 */
|
|
const SGG_NM_DROPDOWN_TAB_KEYS = new Set<string>([
|
|
SewageSlurgeProcessingFacStatusInpColumn.tabKey,
|
|
]);
|
|
|
|
const EMPTY_PUBLIC_SEWAGE_FACILITIES_MSG =
|
|
"06. 공공하수처리시설 데이터가 없으면 전년도 데이터 조회 및 항목 추가가 불가능 합니다.";
|
|
|
|
const EMPTY_EXCRETA_TREATMENT_FACILITIES_MSG =
|
|
"07. 분뇨처리시설 데이터가 없으면 전년도 데이터 조회가 불가능 합니다.";
|
|
|
|
/** ST00110001~ST00110004 — 저장 API 연동 탭 */
|
|
const SAVE_SUPPORTED_TAB_KEYS = new Set<string>([
|
|
SlurgeProcessingFacStatusInpColumn.tabKey,
|
|
DigestorOperatingStatusInpColumn.tabKey,
|
|
SewageSlurgeProcessingFacStatusInpColumn.tabKey,
|
|
ExcretaSlurgeProcessingStatusInpColumn.tabKey,
|
|
]);
|
|
|
|
function mergeHiddenFieldsForSubmitTab(tabKey: string): string[] {
|
|
if (
|
|
tabKey === SlurgeProcessingFacStatusInpColumn.tabKey ||
|
|
tabKey === DigestorOperatingStatusInpColumn.tabKey
|
|
) {
|
|
return ["swtrmtFcltCd", "fcltSn", "admdstCd", "admdstNm"];
|
|
}
|
|
if (tabKey === SewageSlurgeProcessingFacStatusInpColumn.tabKey) {
|
|
return ["fcltSn", "admdstCd", "admdstNm"];
|
|
}
|
|
if (tabKey === ExcretaSlurgeProcessingStatusInpColumn.tabKey) {
|
|
return ["fcltSn", "admdstCd", "admdstNm", "fcltPstnCn"];
|
|
}
|
|
return [];
|
|
}
|
|
|
|
/** ST00110001~ST00110004 — 제출 API 연동 탭 */
|
|
const SUBMIT_SUPPORTED_TAB_KEYS = new Set<string>([
|
|
SlurgeProcessingFacStatusInpColumn.tabKey,
|
|
DigestorOperatingStatusInpColumn.tabKey,
|
|
SewageSlurgeProcessingFacStatusInpColumn.tabKey,
|
|
ExcretaSlurgeProcessingStatusInpColumn.tabKey,
|
|
]);
|
|
|
|
const ARTICLE_TAB_BY_KEY = new Map(
|
|
SewageExcretaSlurgeInpTabList.map((tab) => [tab.tabKey, tab]),
|
|
);
|
|
|
|
function createEmptyArticleRow(
|
|
tabKey: string,
|
|
ctpvNm: string,
|
|
sggNm = "",
|
|
): Record<string, string | number> {
|
|
const row: Record<string, string | number> = { ctpvNm, sggNm };
|
|
const columns = (ARTICLE_TAB_BY_KEY.get(tabKey)?.columns ?? []) as ColumnConfig[];
|
|
for (const col of columns) {
|
|
const fieldName = col.fieldName;
|
|
if (!fieldName || fieldName === "ctpvNm" || fieldName === "sggNm") continue;
|
|
row[fieldName] = col.valueType === ValueType.NUMBER ? 0 : "";
|
|
}
|
|
return row;
|
|
}
|
|
|
|
type ArticleFcltSnSet = Set<string>;
|
|
|
|
function extractFcltSnSet(rows: Record<string, string | number>[]): ArticleFcltSnSet {
|
|
const set = new Set<string>();
|
|
for (const row of rows) {
|
|
const fcltSn = String(row.fcltSn ?? "").trim();
|
|
if (fcltSn) set.add(fcltSn);
|
|
}
|
|
return set;
|
|
}
|
|
|
|
function setArticleFcltSnSet(
|
|
storeRef: { current: ArticleFcltSnSet },
|
|
rows: Record<string, string | number>[],
|
|
) {
|
|
storeRef.current = extractFcltSnSet(rows);
|
|
}
|
|
|
|
function isNewArticleRow(row: Record<string, string | number>): boolean {
|
|
const v = row.__isNewArticle;
|
|
return v === 1 || v === "1";
|
|
}
|
|
|
|
function clearSlurgeFacStatusArticleFcltSnTracking(
|
|
persistedRef: { current: ArticleFcltSnSet },
|
|
preYearRef: { current: ArticleFcltSnSet },
|
|
) {
|
|
persistedRef.current = new Set();
|
|
preYearRef.current = new Set();
|
|
}
|
|
|
|
/**
|
|
* ST00110001 — deleteList 대상 판별.
|
|
* fcltSn만으로는 전년도(PRE)·항목추가 행과 구분 불가 → __isNewArticle + preYear ref 사용.
|
|
*/
|
|
function isPersistedSlurgeFacStatusArticleRow(
|
|
row: Record<string, string | number>,
|
|
persistedRef: { current: ArticleFcltSnSet },
|
|
preYearRef: { current: ArticleFcltSnSet },
|
|
): boolean {
|
|
if (isNewArticleRow(row)) return false;
|
|
const fcltSn = String(row.fcltSn ?? "").trim();
|
|
if (!fcltSn) return false;
|
|
if (preYearRef.current.has(fcltSn)) return false;
|
|
return persistedRef.current.has(fcltSn);
|
|
}
|
|
|
|
/** ST00110003 등 — 전년도 조회 시 fcltSn 미제공, fcltSn 유무로 판단 */
|
|
function isPersistedArticleRowByFcltSn(row: Record<string, string | number>): boolean {
|
|
if (isNewArticleRow(row)) return false;
|
|
return String(row.fcltSn ?? "").trim() !== "";
|
|
}
|
|
|
|
const toGridColumnInfo = (tab: (typeof SewageExcretaSlurgeInpTabList)[number]): ColumnInfo => ({
|
|
columns: tab.columns ?? [],
|
|
columnLayout: tab.columnLayout ?? [],
|
|
});
|
|
|
|
function tabRowDataExists(
|
|
rowDataMap: Map<string, Record<string, string | number>[]>,
|
|
tabKey: string,
|
|
): boolean {
|
|
const rows = rowDataMap.get(tabKey);
|
|
return Array.isArray(rows) && rows.length > 0;
|
|
}
|
|
|
|
type TabToolbarSnapshot = {
|
|
showSaveInToolbar: boolean;
|
|
showEnterableToolbarButtons: boolean;
|
|
showActionToolbarCard: boolean;
|
|
};
|
|
|
|
const computeTabEnterable = (
|
|
statusInfo: SewerageStatusInfo | null | undefined,
|
|
periodEnterable: boolean,
|
|
): boolean => {
|
|
if (statusInfo?.lclgvSbmsnSttsCd) {
|
|
if (["2", "3"].includes(statusInfo.lclgvSbmsnSttsCd)) {
|
|
return false;
|
|
}
|
|
return periodEnterable;
|
|
}
|
|
return periodEnterable;
|
|
};
|
|
|
|
const sidoListRef: { current: Sido[] } = { current: [] };
|
|
|
|
function buildGugunOkForToolbar(values: SearchFormValues | null): boolean {
|
|
return isGugunOkForToolbar(sidoListRef.current, values);
|
|
}
|
|
|
|
function buildSubmitOkForToolbar(values: SearchFormValues | null): boolean {
|
|
return isSubmitOkForToolbar(sidoListRef.current, values);
|
|
}
|
|
|
|
function buildNoApplicableForRequest(
|
|
values: SearchFormValues | null,
|
|
checked: boolean,
|
|
isSaveListEmpty: boolean,
|
|
): boolean {
|
|
return resolveNoApplicableForRequest(sidoListRef.current, values, checked, isSaveListEmpty);
|
|
}
|
|
|
|
function computeTabToolbarSnapshot(
|
|
statusInfo: SewerageStatusInfo | null,
|
|
hasRowData: boolean,
|
|
treatAsSearched: boolean,
|
|
searchContext: SearchFormValues | null,
|
|
periodEnterable: boolean,
|
|
isAdminInfo: boolean,
|
|
): TabToolbarSnapshot {
|
|
const gugunOk = buildGugunOkForToolbar(searchContext);
|
|
const enterable = computeTabEnterable(statusInfo, periodEnterable);
|
|
const isSubmitted = statusInfo?.lclgvSbmsnSttsCd === "2";
|
|
const showSaveInToolbar = (enterable || isAdminInfo) && periodEnterable && gugunOk;
|
|
const showEnterableToolbarButtons = enterable && gugunOk;
|
|
const showSubmittedInInputPeriodToolbar =
|
|
isSubmitted && periodEnterable && gugunOk;
|
|
const showActionToolbarCard =
|
|
(hasRowData || treatAsSearched) &&
|
|
(showSaveInToolbar ||
|
|
showEnterableToolbarButtons ||
|
|
showSubmittedInInputPeriodToolbar);
|
|
return { showSaveInToolbar, showEnterableToolbarButtons, showActionToolbarCard };
|
|
}
|
|
|
|
function parseSggListFromResponse(res: ApiResponse<Sgg[]>): Sgg[] {
|
|
if (res.status !== "success" || res.data == null) return [];
|
|
return Array.isArray(res.data) ? res.data : [];
|
|
}
|
|
|
|
function buildSggNmColumn(
|
|
col: ColumnConfig,
|
|
canEdit: boolean,
|
|
sggOptions: Sgg[],
|
|
): ColumnConfig {
|
|
if (!canEdit) {
|
|
return { ...col, editable: false as const, styleName: "rg-cell-readonly" };
|
|
}
|
|
if (sggOptions.length === 0) {
|
|
return { ...col, editable: true, styleName: undefined };
|
|
}
|
|
const labels = sggOptions.map((s) => s.gugun);
|
|
return {
|
|
...col,
|
|
editable: true,
|
|
styleName: undefined,
|
|
editor: {
|
|
type: "dropdown",
|
|
domainOnly: true,
|
|
textReadOnly: true,
|
|
commitOnSelect: true,
|
|
dropDownWhenClick: true,
|
|
values: labels,
|
|
labels,
|
|
},
|
|
values: labels,
|
|
labels,
|
|
lookupDisplay: true,
|
|
};
|
|
}
|
|
|
|
function buildEmptyDataAlertOverrides(tabKey: string):
|
|
| { alertIfDigestorEmpty?: boolean; alertIfExcretaSlurgeEmpty?: boolean }
|
|
| undefined {
|
|
if (tabKey === DigestorOperatingStatusInpColumn.tabKey) {
|
|
return { alertIfDigestorEmpty: true };
|
|
}
|
|
if (tabKey === ExcretaSlurgeProcessingStatusInpColumn.tabKey) {
|
|
return { alertIfExcretaSlurgeEmpty: true };
|
|
}
|
|
return undefined;
|
|
}
|
|
|
|
function mergeGridRowsWithMapRows(
|
|
gridRows: Record<string, string | number>[],
|
|
mapRows: Record<string, string | number>[],
|
|
hiddenFields: string[] = [],
|
|
): Record<string, string | number>[] {
|
|
return gridRows.map((gridRow, index) => {
|
|
const mapRow = mapRows[index] ?? {};
|
|
const merged: Record<string, string | number> = { ...mapRow, ...gridRow };
|
|
if (hiddenFields.length === 0) return merged;
|
|
const next = { ...merged };
|
|
for (const field of hiddenFields) {
|
|
const fromGrid = String(gridRow[field] ?? "").trim();
|
|
const fromMap = String(mapRow[field] ?? "").trim();
|
|
next[field] = fromGrid || fromMap;
|
|
}
|
|
return next;
|
|
});
|
|
}
|
|
|
|
function toGridNumber(value: string | number | null | undefined): number {
|
|
const n = Number(value);
|
|
return Number.isFinite(n) ? n : 0;
|
|
}
|
|
|
|
function resolveSlurgeFacStatusAdmdst(
|
|
row: Record<string, string | number>,
|
|
sggOptions: Sgg[],
|
|
): { admdstCd: string | null; admdstNm: string | null } {
|
|
const sggNm = String(row.sggNm ?? "").trim();
|
|
if (sggNm) {
|
|
const matched = sggOptions.find((s) => s.gugun === sggNm);
|
|
if (matched) {
|
|
return { admdstCd: matched.bsnmCd, admdstNm: matched.gugun };
|
|
}
|
|
}
|
|
const existingCd = nullableTrimmedString(row.admdstCd);
|
|
const existingNm = nullableTrimmedString(row.admdstNm);
|
|
if (existingCd || existingNm) {
|
|
return {
|
|
admdstCd: existingCd,
|
|
admdstNm: existingNm ?? nullableTrimmedString(sggNm),
|
|
};
|
|
}
|
|
return { admdstCd: null, admdstNm: nullableTrimmedString(sggNm) };
|
|
}
|
|
|
|
/** 그리드 행 → ST00110001 저장/삭제 API 항목 */
|
|
function buildSlurgeProcessingFacStatusSaveItem(
|
|
row: Record<string, string | number>,
|
|
sggOptions: Sgg[],
|
|
): SlurgeProcessingFacStatusSaveItem {
|
|
const { admdstCd, admdstNm } = resolveSlurgeFacStatusAdmdst(row, sggOptions);
|
|
return {
|
|
admdstCd,
|
|
admdstNm,
|
|
swtrmtFcltCd: nullableTrimmedString(row.swtrmtFcltCd),
|
|
swtrmtFcltNm: nullableTrimmedString(row.swtrmtFcltNm),
|
|
fcltSn: nullableTrimmedString(row.fcltSn),
|
|
itslfQnt: toGridNumber(row.itslfQnt),
|
|
otsdInflwQnt: toGridNumber(row.otsdInflwQnt),
|
|
transfTmplntNm: nullableTrimmedString(row.transfTmplntNm),
|
|
transfPrcsQnt: toGridNumber(row.transfPrcsQnt),
|
|
sludgeFncRt: toGridNumber(row.sludgeFncRt),
|
|
itslfFrlvlRclmQnt: toGridNumber(row.itslfFrlvlRclmQnt),
|
|
itslfFrlvlIncnrQnt: toGridNumber(row.itslfFrlvlIncnrQnt),
|
|
itslfFrlvlSldQnt: toGridNumber(row.itslfFrlvlSldQnt),
|
|
itslfFrlvlDryQnt: toGridNumber(row.itslfFrlvlDryQnt),
|
|
itslfFrlvlCrbnQnt: toGridNumber(row.itslfFrlvlCrbnQnt),
|
|
itslfFrlvlCmpstgQnt: toGridNumber(row.itslfFrlvlCmpstgQnt),
|
|
cmpsPrcsFcltBzentyNm: nullableTrimmedString(row.cmpsPrcsFcltBzentyNm),
|
|
incnrPrcsLfvlm: toGridNumber(row.incnrPrcsLfvlm),
|
|
incnrPrcsPrdctRmtrlQnt: toGridNumber(row.incnrPrcsPrdctRmtrlQnt),
|
|
incnrPrcsCwthQnt: toGridNumber(row.incnrPrcsCwthQnt),
|
|
incnrPrcsFcltNm: nullableTrimmedString(row.incnrPrcsFcltNm),
|
|
sldPrcsLfvlm: toGridNumber(row.sldPrcsLfvlm),
|
|
sldPrcsCwthQnt: toGridNumber(row.sldPrcsCwthQnt),
|
|
sldPrcsFcltNm: nullableTrimmedString(row.sldPrcsFcltNm),
|
|
dryPrcsLfvlm: toGridNumber(row.dryPrcsLfvlm),
|
|
dryPrcsIncnrQnt: toGridNumber(row.dryPrcsIncnrQnt),
|
|
dryPrcsFuelQnt: toGridNumber(row.dryPrcsFuelQnt),
|
|
dryPrcsPrdctRmtrlQnt: toGridNumber(row.dryPrcsPrdctRmtrlQnt),
|
|
dryPrcsCwthQnt: toGridNumber(row.dryPrcsCwthQnt),
|
|
dryPrcsCmpstgQnt: toGridNumber(row.dryPrcsCmpstgQnt),
|
|
dryPrcsFcltNm: nullableTrimmedString(row.dryPrcsFcltNm),
|
|
crbnPrcsIncnrQnt: toGridNumber(row.crbnPrcsIncnrQnt),
|
|
crbnPrcsFuelQnt: toGridNumber(row.crbnPrcsFuelQnt),
|
|
crbnPrcsFcltNm: nullableTrimmedString(row.crbnPrcsFcltNm),
|
|
otsdCnsgnRclmQnt: toGridNumber(row.otsdCnsgnRclmQnt),
|
|
otsdCnsgnIncnrQnt: toGridNumber(row.otsdCnsgnIncnrQnt),
|
|
otsdCnsgnPwplQnt: toGridNumber(row.otsdCnsgnPwplQnt),
|
|
otsdCnsgnPrdctRmtrlQnt: toGridNumber(row.otsdCnsgnPrdctRmtrlQnt),
|
|
otsdCnsgnCwthQnt: toGridNumber(row.otsdCnsgnCwthQnt),
|
|
otsdCnsgnCmpstgQnt: toGridNumber(row.otsdCnsgnCmpstgQnt),
|
|
otsdCnsgnFcltNm: nullableTrimmedString(row.otsdCnsgnFcltNm),
|
|
cparFrlvlWholQnt: toGridNumber(row.cparFrlvlWholQnt),
|
|
rmrk: nullableTrimmedString(row.rmrk),
|
|
};
|
|
}
|
|
|
|
/** 그리드 행 → ST00110002 저장 API 항목 */
|
|
function buildDigestorOperatingStatusSaveItem(
|
|
row: Record<string, string | number>,
|
|
sggOptions: Sgg[],
|
|
): DigestorOperatingStatusSaveItem {
|
|
const { admdstCd, admdstNm } = resolveSlurgeFacStatusAdmdst(row, sggOptions);
|
|
const base = {
|
|
admdstCd,
|
|
admdstNm,
|
|
swtrmtFcltCd: nullableTrimmedString(row.swtrmtFcltCd),
|
|
swtrmtFcltNm: nullableTrimmedString(row.swtrmtFcltNm),
|
|
fcltSn: nullableTrimmedString(row.fcltSn),
|
|
gasPrcsEnYn: nullableTrimmedString(row.gasPrcsEnYn),
|
|
};
|
|
|
|
if (isDigestorOperatingRowDisabled(row)) {
|
|
return {
|
|
...base,
|
|
gasPrcsEnYn: "N",
|
|
gasPrcsCpct: 0,
|
|
actlDrvnCpct: 0,
|
|
prcsGasInputQnt: 0,
|
|
prcsGasInputSldDnst: 0,
|
|
prcsRepoOprtngDayCnt: 0,
|
|
ocrnGasQnt: 0,
|
|
prcsGasUtztnNtslQnt: 0,
|
|
prcsGasUtztnEtgtQnt: 0,
|
|
prcsGasUtztnItslfQnt: 0,
|
|
prcsGasUtztnEtcQnt: 0,
|
|
surplsGasQnt: 0,
|
|
rmrk: null,
|
|
};
|
|
}
|
|
|
|
return {
|
|
...base,
|
|
gasPrcsCpct: toGridNumber(row.gasPrcsCpct),
|
|
actlDrvnCpct: toGridNumber(row.actlDrvnCpct),
|
|
prcsGasInputQnt: toGridNumber(row.prcsGasInputQnt),
|
|
prcsGasInputSldDnst: toGridNumber(row.prcsGasInputSldDnst),
|
|
prcsRepoOprtngDayCnt: toGridNumber(row.prcsRepoOprtngDayCnt),
|
|
ocrnGasQnt: toGridNumber(row.ocrnGasQnt),
|
|
prcsGasUtztnNtslQnt: toGridNumber(row.prcsGasUtztnNtslQnt),
|
|
prcsGasUtztnEtgtQnt: toGridNumber(row.prcsGasUtztnEtgtQnt),
|
|
prcsGasUtztnItslfQnt: toGridNumber(row.prcsGasUtztnItslfQnt),
|
|
prcsGasUtztnEtcQnt: toGridNumber(row.prcsGasUtztnEtcQnt),
|
|
surplsGasQnt: toGridNumber(row.surplsGasQnt),
|
|
rmrk: nullableTrimmedString(row.rmrk),
|
|
};
|
|
}
|
|
|
|
/** 그리드 행 → ST00110003 저장/삭제 API 항목 */
|
|
function buildSewageSlurgeProcessingFacStatusSaveItem(
|
|
row: Record<string, string | number>,
|
|
sggOptions: Sgg[],
|
|
): SewageSlurgeProcessingFacStatusSaveItem {
|
|
const { admdstCd, admdstNm } = resolveSlurgeFacStatusAdmdst(row, sggOptions);
|
|
return {
|
|
admdstCd,
|
|
admdstNm,
|
|
fcltSn: nullableTrimmedString(row.fcltSn),
|
|
fcltNm: nullableTrimmedString(row.fcltNm),
|
|
prcsMthExpln: nullableTrimmedString(row.prcsMthExpln),
|
|
sludgeFcltCpct: toGridNumber(row.sludgeFcltCpct),
|
|
anlPrcsQnt: toGridNumber(row.anlPrcsQnt),
|
|
dyrgOprtngHr: toGridNumber(row.dyrgOprtngHr),
|
|
fcltAnlOprtngDayCnt: toGridNumber(row.fcltAnlOprtngDayCnt),
|
|
rmrk: nullableTrimmedString(row.rmrk),
|
|
};
|
|
}
|
|
|
|
/** 그리드 행 → ST00110004 저장 API 항목 */
|
|
function buildExcretaSlurgeProcessingStatusSaveItem(
|
|
row: Record<string, string | number>,
|
|
sggOptions: Sgg[],
|
|
): ExcretaSlurgeProcessingStatusSaveItem {
|
|
const { admdstCd, admdstNm } = resolveSlurgeFacStatusAdmdst(row, sggOptions);
|
|
return {
|
|
admdstCd,
|
|
admdstNm,
|
|
fcltSn: nullableTrimmedString(row.fcltSn),
|
|
fcltNm: nullableTrimmedString(row.fcltNm),
|
|
fcltPstnCn: nullableTrimmedString(row.fcltPstnCn),
|
|
rcycQnt: toGridNumber(row.rcycQnt),
|
|
olandLfvlm: toGridNumber(row.olandLfvlm),
|
|
incnrQnt: toGridNumber(row.incnrQnt),
|
|
fuelQnt: toGridNumber(row.fuelQnt),
|
|
etcQnt: toGridNumber(row.etcQnt),
|
|
unprcsQnt: toGridNumber(row.unprcsQnt),
|
|
swtrmtFcltNm: nullableTrimmedString(row.swtrmtFcltNm),
|
|
rmrk: nullableTrimmedString(row.rmrk),
|
|
};
|
|
}
|
|
|
|
const sleep = (ms: number) => new Promise<void>((resolve) => setTimeout(resolve, ms));
|
|
|
|
async function waitForImrJobCompleted(
|
|
jobId: string,
|
|
getStatus: (id: string) => Promise<ImrStatusResponse>,
|
|
options?: {
|
|
pollIntervalMs?: number;
|
|
maxAttempts?: number;
|
|
onProgress?: (jobProgress: number) => void;
|
|
},
|
|
): Promise<void> {
|
|
const pollIntervalMs = options?.pollIntervalMs ?? 2000;
|
|
const maxAttempts = options?.maxAttempts ?? 150;
|
|
for (let i = 0; i < maxAttempts; i++) {
|
|
const res = await getStatus(jobId);
|
|
options?.onProgress?.(Math.max(0, Math.min(100, Number(res.job_prog) || 0)));
|
|
if (res.status === "COMPLETED" && Number(res.job_prog) === 100) return;
|
|
if (res.status === "FAILED" || res.status === "ERROR" || res.status === "CANCELLED") {
|
|
throw new Error(res.error_msg || `시계열 검증이 ${res.status} 상태로 종료되었습니다.`);
|
|
}
|
|
await sleep(pollIntervalMs);
|
|
}
|
|
throw new Error("시계열 검증 완료 대기 시간이 초과되었습니다.");
|
|
}
|
|
|
|
// 하수도 통계 관리 > 11. 하수 및 분뇨찌꺼기(슬러지)처리
|
|
const SewageExcretaSlurgeInp = () => {
|
|
const { sidoList } = useSearchConditionSidoList({ isInput: true });
|
|
sidoListRef.current = sidoList;
|
|
const { isAdminInfo } = useAdminStore();
|
|
const { confirm } = useConfirm();
|
|
const { setMessage: alert } = useAlertStore((state) => state);
|
|
const toolbarGroupAllowed = useStatisticsInputToolbarGroupGate();
|
|
const showGlobalProgress = useGlobalProgressStore((state) => state.show);
|
|
const setGlobalProgress = useGlobalProgressStore((state) => state.setProgress);
|
|
const setGlobalProgressLabel = useGlobalProgressStore((state) => state.setLabel);
|
|
const hideGlobalProgress = useGlobalProgressStore((state) => state.hide);
|
|
|
|
const [isLoading, setIsLoading] = useState(false);
|
|
const [activeTab, setActiveTab] = useState<string>(firstTabKey);
|
|
const [rowDataMap, setRowDataMap] = useState<
|
|
Map<string, Record<string, string | number>[]>
|
|
>(new Map());
|
|
const [isNotApplicableByTab, setIsNotApplicableByTab] = useState<Map<string, boolean>>(
|
|
() => new Map(),
|
|
);
|
|
const [searchValues, setSearchValues] = useState<SearchFormValues | null>(null);
|
|
const [lastSearchedValues, setLastSearchedValues] = useState<SearchFormValues | null>(null);
|
|
const [hasSearched, setHasSearched] = useState(false);
|
|
const [inputPeriodEnterable, setInputPeriodEnterable] = useState(true);
|
|
const [tabStatusInfoMap, setTabStatusInfoMap] = useState<
|
|
Map<string, SewerageStatusInfo | null>
|
|
>(new Map());
|
|
const [tabStatsCdMap, setTabStatsCdMap] = useState<Map<string, string>>(new Map());
|
|
const [isVerificationFailedByTab, setIsVerificationFailedByTab] = useState<
|
|
Map<string, boolean>
|
|
>(new Map());
|
|
const [footerVerificationByTab, setFooterVerificationByTab] = useState<
|
|
Map<string, VerificationResultLikeMap | null>
|
|
>(new Map());
|
|
const [_toolbarSnapshotByTab, setToolbarSnapshotByTab] = useState<
|
|
Map<string, TabToolbarSnapshot>
|
|
>(new Map());
|
|
const [searchContextByTab, setSearchContextByTab] = useState<Map<string, SearchFormValues>>(
|
|
() => new Map(),
|
|
);
|
|
const [sggOptions, setSggOptions] = useState<Sgg[]>([]);
|
|
const [loadedTabKeys, setLoadedTabKeys] = useState<Set<string>>(() => new Set());
|
|
const [verificationHistoryOpen, setVerificationHistoryOpen] = useState(false);
|
|
const [showSubmitDialog, setShowSubmitDialog] = useState(false);
|
|
const [verificationResultDialogOpen, setVerificationResultDialogOpen] = useState(false);
|
|
const [deleteListByTab, setDeleteListByTab] = useState<
|
|
Map<string, Record<string, string | number>[]>
|
|
>(() => new Map());
|
|
const [columnGuidesByTab, setColumnGuidesByTab] = useState<
|
|
Record<string, Record<string, string>>
|
|
>({});
|
|
|
|
const searchParamRef = useRef<SewageExcretaSlurgeRequestParams | null>(null);
|
|
const searchDoneRef = useRef(false);
|
|
const periodEnterableRef = useRef(true);
|
|
const loadedTabKeysRef = useRef<Set<string>>(new Set());
|
|
const sggOptionsSidoRef = useRef<string | null>(null);
|
|
/** ST00110002 당해 조회 결과 유무(공공하수처리시설 연동) — 전년도 조회 가능 여부 */
|
|
const publicSewageFacilitiesAvailableRef = useRef(false);
|
|
/** ST00110004 당해 조회 결과 유무(분뇨처리시설 연동 데이터) — 전년도 조회 가능 여부 */
|
|
const excretaTreatmentFacilitiesAvailableRef = useRef(false);
|
|
const activeTabRef = useRef(activeTab);
|
|
const getGridDataRef = useRef<(() => Record<string, string | number>[]) | null>(null);
|
|
const getGridRef = useRef<RealGridReact | null>(null);
|
|
/** ST00110001 — 당해 연도 조회 API로 로드된 fcltSn (deleteList 대상) */
|
|
const persistedArticleFcltSnRef = useRef<ArticleFcltSnSet>(new Set());
|
|
/** ST00110001 — 전년도(PRE) 조회로 로드된 fcltSn */
|
|
const preYearArticleFcltSnRef = useRef<ArticleFcltSnSet>(new Set());
|
|
activeTabRef.current = activeTab;
|
|
|
|
const activeTabId = useTabStore((s) => s.activeTabId);
|
|
|
|
useEffect(() => {
|
|
if (activeTabId !== STATISTICS_INPUT_URL_PATH.SEWAGE_EXCRETA_SLURGE) return;
|
|
const tabKey = activeTab;
|
|
if (!tabKey) return;
|
|
if (Object.prototype.hasOwnProperty.call(columnGuidesByTab, tabKey)) return;
|
|
const statsCd = tabKey;
|
|
|
|
let cancelled = false;
|
|
void (async () => {
|
|
const next = await fetchColumnGuidesRecord(statsCd);
|
|
if (cancelled) return;
|
|
setColumnGuidesByTab((prev) =>
|
|
Object.prototype.hasOwnProperty.call(prev, tabKey)
|
|
? prev
|
|
: { ...prev, [tabKey]: next },
|
|
);
|
|
})();
|
|
return () => {
|
|
cancelled = true;
|
|
};
|
|
}, [activeTabId, activeTab, columnGuidesByTab]);
|
|
|
|
const shouldShowNotApplicable = (
|
|
hasRows: boolean,
|
|
statusInfo: SewerageStatusInfo | null | undefined,
|
|
): boolean =>
|
|
hasSearched &&
|
|
!hasRows &&
|
|
computeTabEnterable(statusInfo, inputPeriodEnterable);
|
|
|
|
const setIsNotApplicableForTab = useCallback((tabKey: string, nextValue: boolean) => {
|
|
setIsNotApplicableByTab((prev) => {
|
|
const next = new Map(prev);
|
|
next.set(tabKey, nextValue);
|
|
return next;
|
|
});
|
|
}, []);
|
|
|
|
const loadSggOptions = useCallback(async (sido: string): Promise<Sgg[]> => {
|
|
if (!sido || sido === "ALL") {
|
|
setSggOptions([]);
|
|
return [];
|
|
}
|
|
try {
|
|
const res = await statisticsApi.getSggAllList(sido);
|
|
const list = parseSggListFromResponse(res);
|
|
setSggOptions(list);
|
|
return list;
|
|
} catch {
|
|
setSggOptions([]);
|
|
return [];
|
|
}
|
|
}, []);
|
|
|
|
const markTabLoaded = (tabKey: string) => {
|
|
loadedTabKeysRef.current.add(tabKey);
|
|
setLoadedTabKeys(new Set(loadedTabKeysRef.current));
|
|
};
|
|
|
|
const commitToolbarSnapshotForLoadedTab = (
|
|
tabKey: string,
|
|
statusInfo: SewerageStatusInfo | null,
|
|
hasRowData: boolean,
|
|
searchContext: SearchFormValues,
|
|
) => {
|
|
setToolbarSnapshotByTab((prev) => {
|
|
const next = new Map(prev);
|
|
next.set(
|
|
tabKey,
|
|
computeTabToolbarSnapshot(
|
|
statusInfo,
|
|
hasRowData,
|
|
searchDoneRef.current,
|
|
searchContext,
|
|
periodEnterableRef.current,
|
|
isAdminInfo,
|
|
),
|
|
);
|
|
return next;
|
|
});
|
|
if (searchContext) {
|
|
setSearchContextByTab((prev) => {
|
|
const next = new Map(prev);
|
|
next.set(tabKey, searchContext);
|
|
return next;
|
|
});
|
|
}
|
|
};
|
|
|
|
const getTabGridRows = (tabKey: string): Record<string, string | number>[] =>
|
|
tabKey === activeTabRef.current
|
|
? (getGridDataRef.current?.() ?? rowDataMap.get(tabKey) ?? [])
|
|
: (rowDataMap.get(tabKey) ?? []);
|
|
|
|
const commitActiveGrid = () => {
|
|
const gridView = getGridRef.current?.gridView as
|
|
| { commit?: (force?: boolean) => void; cancel?: () => void }
|
|
| undefined;
|
|
try {
|
|
gridView?.commit?.(true);
|
|
} catch {
|
|
gridView?.cancel?.();
|
|
}
|
|
};
|
|
|
|
const handleActiveTabChange = async (tabKey: string) => {
|
|
const prevTabKey = activeTabRef.current;
|
|
commitActiveGrid();
|
|
const latestRowsInPrevTab = getTabGridRows(prevTabKey);
|
|
if (latestRowsInPrevTab.length > 0 || rowDataMap.has(prevTabKey)) {
|
|
setRowDataMap((prev) => {
|
|
const next = new Map(prev);
|
|
next.set(prevTabKey, latestRowsInPrevTab);
|
|
return next;
|
|
});
|
|
}
|
|
|
|
flushSync(() => {
|
|
activeTabRef.current = tabKey;
|
|
setActiveTab(tabKey);
|
|
});
|
|
|
|
if (!hasSearched || !lastSearchedValues || !searchParamRef.current) return;
|
|
|
|
if (loadedTabKeysRef.current.has(tabKey)) return;
|
|
|
|
try {
|
|
setIsLoading(true);
|
|
await loadActiveTabData(
|
|
tabKey,
|
|
searchParamRef.current,
|
|
lastSearchedValues,
|
|
true,
|
|
false,
|
|
buildEmptyDataAlertOverrides(tabKey),
|
|
);
|
|
} catch {
|
|
alert("데이터 조회 중 오류가 발생했습니다.");
|
|
} finally {
|
|
setIsLoading(false);
|
|
}
|
|
};
|
|
|
|
const applyRowMap = (
|
|
mergeIntoExistingMap: boolean,
|
|
apply: (m: Map<string, Record<string, string | number>[]>) => void,
|
|
) => {
|
|
if (mergeIntoExistingMap) {
|
|
setRowDataMap((prev) => {
|
|
const next = new Map(prev);
|
|
apply(next);
|
|
return next;
|
|
});
|
|
} else {
|
|
const next = new Map<string, Record<string, string | number>[]>();
|
|
apply(next);
|
|
setRowDataMap(next);
|
|
}
|
|
};
|
|
|
|
const syncSlurgeFacStatusArticleFcltSnTracking = (
|
|
gridRows: Record<string, string | number>[],
|
|
fromPreYear: boolean,
|
|
) => {
|
|
if (fromPreYear) {
|
|
setArticleFcltSnSet(preYearArticleFcltSnRef, gridRows);
|
|
return;
|
|
}
|
|
setArticleFcltSnSet(persistedArticleFcltSnRef, gridRows);
|
|
};
|
|
|
|
const isPersistedArticleRowForTab = useCallback(
|
|
(tabKey: string, row: Record<string, string | number>) => {
|
|
if (tabKey === SlurgeProcessingFacStatusInpColumn.tabKey) {
|
|
return isPersistedSlurgeFacStatusArticleRow(
|
|
row,
|
|
persistedArticleFcltSnRef,
|
|
preYearArticleFcltSnRef,
|
|
);
|
|
}
|
|
return isPersistedArticleRowByFcltSn(row);
|
|
},
|
|
[],
|
|
);
|
|
|
|
const loadActiveTabData = async (
|
|
tabKey: string,
|
|
param: SewageExcretaSlurgeRequestParams,
|
|
searchContext: SearchFormValues,
|
|
mergeIntoExistingMap: boolean,
|
|
updateLastSearchedValues: boolean,
|
|
overrides?: {
|
|
mode?: string;
|
|
alertIfDigestorEmpty?: boolean;
|
|
alertIfExcretaSlurgeEmpty?: boolean;
|
|
},
|
|
): Promise<boolean> => {
|
|
const requestParam = overrides?.mode ? { ...param, mode: overrides.mode } : param;
|
|
const fromPreYear = overrides?.mode === "PRE";
|
|
|
|
const applyNotApplicableForLoadedTab = (
|
|
gridRows: readonly Record<string, string | number>[],
|
|
) => {
|
|
if (!fromPreYear) {
|
|
setIsNotApplicableForTab(tabKey, gridRows.length === 0);
|
|
} else if (gridRows.length > 0) {
|
|
setIsNotApplicableForTab(tabKey, false);
|
|
}
|
|
};
|
|
|
|
if (tabKey === SlurgeProcessingFacStatusInpColumn.tabKey) {
|
|
const response =
|
|
await statisticsInputSewageExcretaSlurgeApi.getSlurgeProcessingFacStatusList(
|
|
requestParam,
|
|
);
|
|
if (response.status !== "success" || !response.data) {
|
|
alert(response.message || "데이터 조회 중 오류가 발생했습니다.");
|
|
return false;
|
|
}
|
|
const { commonInfo, statusInfo, slurgeProcessingFacStatusList } = response.data;
|
|
const gridRows = mapListToGridRows(slurgeProcessingFacStatusList, commonInfo.ctpvNm, searchContext);
|
|
syncSlurgeFacStatusArticleFcltSnTracking(gridRows, fromPreYear);
|
|
applyRowMap(mergeIntoExistingMap, (m) => {
|
|
m.set(SlurgeProcessingFacStatusInpColumn.tabKey, gridRows);
|
|
});
|
|
setTabStatusInfoMap((prev) => new Map(prev).set(tabKey, statusInfo));
|
|
setTabStatsCdMap((prev) => new Map(prev).set(tabKey, commonInfo.statsCd));
|
|
setIsVerificationFailedByTab((prev) =>
|
|
patchVerificationFailedByTab(prev, tabKey, commonInfo),
|
|
);
|
|
setFooterVerificationByTab((prev) =>
|
|
patchFooterVerificationByTab(prev, tabKey, commonInfo),
|
|
);
|
|
if (updateLastSearchedValues) setLastSearchedValues(searchContext);
|
|
commitToolbarSnapshotForLoadedTab(
|
|
tabKey,
|
|
statusInfo,
|
|
gridRows.length > 0,
|
|
searchContext,
|
|
);
|
|
applyNotApplicableForLoadedTab(gridRows);
|
|
markTabLoaded(tabKey);
|
|
return true;
|
|
}
|
|
|
|
if (tabKey === DigestorOperatingStatusInpColumn.tabKey) {
|
|
const response =
|
|
await statisticsInputSewageExcretaSlurgeApi.getDigestorOperatingStatusList(
|
|
requestParam,
|
|
);
|
|
if (response.status !== "success" || !response.data) {
|
|
alert(response.message || "데이터 조회 중 오류가 발생했습니다.");
|
|
return false;
|
|
}
|
|
const { commonInfo, statusInfo, digestorOperatingStatusList } = response.data;
|
|
const gridRows = mapListToGridRows(digestorOperatingStatusList, commonInfo.ctpvNm, searchContext);
|
|
if (!fromPreYear) {
|
|
publicSewageFacilitiesAvailableRef.current = gridRows.length > 0;
|
|
if (gridRows.length === 0 && overrides?.alertIfDigestorEmpty) {
|
|
alert(EMPTY_PUBLIC_SEWAGE_FACILITIES_MSG);
|
|
}
|
|
}
|
|
applyRowMap(mergeIntoExistingMap, (m) => {
|
|
m.set(DigestorOperatingStatusInpColumn.tabKey, gridRows);
|
|
});
|
|
setTabStatusInfoMap((prev) => new Map(prev).set(tabKey, statusInfo));
|
|
setTabStatsCdMap((prev) => new Map(prev).set(tabKey, commonInfo.statsCd));
|
|
setIsVerificationFailedByTab((prev) =>
|
|
patchVerificationFailedByTab(prev, tabKey, commonInfo),
|
|
);
|
|
setFooterVerificationByTab((prev) =>
|
|
patchFooterVerificationByTab(prev, tabKey, commonInfo),
|
|
);
|
|
if (updateLastSearchedValues) setLastSearchedValues(searchContext);
|
|
commitToolbarSnapshotForLoadedTab(
|
|
tabKey,
|
|
statusInfo,
|
|
gridRows.length > 0,
|
|
searchContext,
|
|
);
|
|
applyNotApplicableForLoadedTab(gridRows);
|
|
markTabLoaded(tabKey);
|
|
return true;
|
|
}
|
|
|
|
if (tabKey === SewageSlurgeProcessingFacStatusInpColumn.tabKey) {
|
|
const response =
|
|
await statisticsInputSewageExcretaSlurgeApi.getSewageSlurgeProcessingFacStatusList(
|
|
requestParam,
|
|
);
|
|
if (response.status !== "success" || !response.data) {
|
|
alert(response.message || "데이터 조회 중 오류가 발생했습니다.");
|
|
return false;
|
|
}
|
|
const { commonInfo, statusInfo, sewageSlurgeProcessingFacStatusList } =
|
|
response.data;
|
|
const gridRows = mapListToGridRows(
|
|
sewageSlurgeProcessingFacStatusList,
|
|
commonInfo.ctpvNm,
|
|
searchContext,
|
|
);
|
|
applyRowMap(mergeIntoExistingMap, (m) => {
|
|
m.set(SewageSlurgeProcessingFacStatusInpColumn.tabKey, gridRows);
|
|
});
|
|
setTabStatusInfoMap((prev) => new Map(prev).set(tabKey, statusInfo));
|
|
setTabStatsCdMap((prev) => new Map(prev).set(tabKey, commonInfo.statsCd));
|
|
setIsVerificationFailedByTab((prev) =>
|
|
patchVerificationFailedByTab(prev, tabKey, commonInfo),
|
|
);
|
|
setFooterVerificationByTab((prev) =>
|
|
patchFooterVerificationByTab(prev, tabKey, commonInfo),
|
|
);
|
|
if (updateLastSearchedValues) setLastSearchedValues(searchContext);
|
|
commitToolbarSnapshotForLoadedTab(
|
|
tabKey,
|
|
statusInfo,
|
|
gridRows.length > 0,
|
|
searchContext,
|
|
);
|
|
applyNotApplicableForLoadedTab(gridRows);
|
|
markTabLoaded(tabKey);
|
|
return true;
|
|
}
|
|
|
|
if (tabKey === ExcretaSlurgeProcessingStatusInpColumn.tabKey) {
|
|
const response =
|
|
await statisticsInputSewageExcretaSlurgeApi.getExcretaSlurgeProcessingStatusList(
|
|
requestParam,
|
|
);
|
|
if (response.status !== "success" || !response.data) {
|
|
alert(response.message || "데이터 조회 중 오류가 발생했습니다.");
|
|
return false;
|
|
}
|
|
const { commonInfo, statusInfo, excretaSlurgeProcessingStatusList } = response.data;
|
|
const gridRows = mapListToGridRows(
|
|
excretaSlurgeProcessingStatusList,
|
|
commonInfo.ctpvNm,
|
|
searchContext,
|
|
);
|
|
if (!fromPreYear) {
|
|
excretaTreatmentFacilitiesAvailableRef.current = gridRows.length > 0;
|
|
if (gridRows.length === 0 && overrides?.alertIfExcretaSlurgeEmpty) {
|
|
alert(EMPTY_EXCRETA_TREATMENT_FACILITIES_MSG);
|
|
}
|
|
}
|
|
applyRowMap(mergeIntoExistingMap, (m) => {
|
|
m.set(ExcretaSlurgeProcessingStatusInpColumn.tabKey, gridRows);
|
|
});
|
|
setTabStatusInfoMap((prev) => new Map(prev).set(tabKey, statusInfo));
|
|
setTabStatsCdMap((prev) => new Map(prev).set(tabKey, commonInfo.statsCd));
|
|
setIsVerificationFailedByTab((prev) =>
|
|
patchVerificationFailedByTab(prev, tabKey, commonInfo),
|
|
);
|
|
setFooterVerificationByTab((prev) =>
|
|
patchFooterVerificationByTab(prev, tabKey, commonInfo),
|
|
);
|
|
if (updateLastSearchedValues) setLastSearchedValues(searchContext);
|
|
commitToolbarSnapshotForLoadedTab(
|
|
tabKey,
|
|
statusInfo,
|
|
gridRows.length > 0,
|
|
searchContext,
|
|
);
|
|
applyNotApplicableForLoadedTab(gridRows);
|
|
markTabLoaded(tabKey);
|
|
return true;
|
|
}
|
|
|
|
alert("해당 탭 조회 API가 없습니다.");
|
|
return false;
|
|
};
|
|
|
|
const handleReset = () => {
|
|
setRowDataMap(new Map());
|
|
setTabStatusInfoMap(new Map());
|
|
setTabStatsCdMap(new Map());
|
|
setIsVerificationFailedByTab(new Map());
|
|
setFooterVerificationByTab(new Map());
|
|
setToolbarSnapshotByTab(new Map());
|
|
setSearchContextByTab(new Map());
|
|
setActiveTab(firstTabKey);
|
|
activeTabRef.current = firstTabKey;
|
|
setLastSearchedValues(null);
|
|
setHasSearched(false);
|
|
setInputPeriodEnterable(true);
|
|
searchParamRef.current = null;
|
|
setIsNotApplicableByTab(new Map());
|
|
searchDoneRef.current = false;
|
|
periodEnterableRef.current = true;
|
|
loadedTabKeysRef.current.clear();
|
|
setLoadedTabKeys(new Set());
|
|
setSggOptions([]);
|
|
publicSewageFacilitiesAvailableRef.current = false;
|
|
excretaTreatmentFacilitiesAvailableRef.current = false;
|
|
setDeleteListByTab(new Map());
|
|
clearSlurgeFacStatusArticleFcltSnTracking(
|
|
persistedArticleFcltSnRef,
|
|
preYearArticleFcltSnRef,
|
|
);
|
|
sggOptionsSidoRef.current = null;
|
|
};
|
|
|
|
const handleSearch = async (
|
|
values: SearchFormValues,
|
|
opts?: { forcedTabKey?: string },
|
|
) => {
|
|
if (!values.sido || values.sido === "ALL") {
|
|
alert("시도를 선택해주세요.");
|
|
return;
|
|
}
|
|
|
|
try {
|
|
const periodResponse = await statisticsInputSewSupplyRateApi.checkInputPeriod(
|
|
values.year || "",
|
|
);
|
|
if (periodResponse.status !== "success") {
|
|
alert(periodResponse.message);
|
|
return;
|
|
}
|
|
const periods = Array.isArray(periodResponse.data) ? periodResponse.data : [];
|
|
const periodOk = isInputPeriodCurrent(periods);
|
|
periodEnterableRef.current = periodOk;
|
|
setInputPeriodEnterable(periodOk);
|
|
} catch {
|
|
alert("입력 기간 확인 중 오류가 발생했습니다.");
|
|
return;
|
|
}
|
|
|
|
const yearChangedFromLastSearch =
|
|
lastSearchedValues != null &&
|
|
(lastSearchedValues.year ?? "") !== (values.year ?? "");
|
|
|
|
if (yearChangedFromLastSearch) {
|
|
setRowDataMap(new Map());
|
|
setTabStatusInfoMap(new Map());
|
|
setTabStatsCdMap(new Map());
|
|
setIsVerificationFailedByTab(new Map());
|
|
setFooterVerificationByTab(new Map());
|
|
setToolbarSnapshotByTab(new Map());
|
|
setSearchContextByTab(new Map());
|
|
loadedTabKeysRef.current.clear();
|
|
setLoadedTabKeys(new Set());
|
|
setDeleteListByTab(new Map());
|
|
clearSlurgeFacStatusArticleFcltSnTracking(
|
|
persistedArticleFcltSnRef,
|
|
preYearArticleFcltSnRef,
|
|
);
|
|
activeTabRef.current = firstTabKey;
|
|
setActiveTab(firstTabKey);
|
|
}
|
|
|
|
try {
|
|
setIsLoading(true);
|
|
searchDoneRef.current = true;
|
|
setHasSearched(true);
|
|
const searchParam = buildSewageExcretaSlurgeSearchParam(values);
|
|
searchParamRef.current = searchParam;
|
|
|
|
const loadedSgg = await loadSggOptions(values.sido);
|
|
sggOptionsSidoRef.current = values.sido;
|
|
if (loadedSgg.length === 0) {
|
|
alert("시군구 목록을 불러오지 못했습니다.");
|
|
return;
|
|
}
|
|
|
|
if (opts?.forcedTabKey) {
|
|
activeTabRef.current = opts.forcedTabKey;
|
|
setActiveTab(opts.forcedTabKey);
|
|
}
|
|
|
|
const ok = await loadActiveTabData(
|
|
opts?.forcedTabKey ?? activeTabRef.current,
|
|
searchParam,
|
|
values,
|
|
!yearChangedFromLastSearch,
|
|
true,
|
|
buildEmptyDataAlertOverrides(
|
|
opts?.forcedTabKey ?? activeTabRef.current,
|
|
),
|
|
);
|
|
if (!ok) return;
|
|
} catch {
|
|
alert("데이터 조회 중 오류가 발생했습니다.");
|
|
} finally {
|
|
setIsLoading(false);
|
|
}
|
|
};
|
|
|
|
const lastYearDataFunc = async () => {
|
|
const values = lastSearchedValues ?? searchValues;
|
|
if (!values?.sido || values.sido === "ALL") {
|
|
alert("시도를 선택해주세요.");
|
|
return;
|
|
}
|
|
if (!hasSearched) {
|
|
alert("먼저 데이터를 조회해주세요.");
|
|
return;
|
|
}
|
|
if (
|
|
activeTabRef.current === DigestorOperatingStatusInpColumn.tabKey &&
|
|
!publicSewageFacilitiesAvailableRef.current
|
|
) {
|
|
alert(EMPTY_PUBLIC_SEWAGE_FACILITIES_MSG);
|
|
return;
|
|
}
|
|
if (
|
|
activeTabRef.current === ExcretaSlurgeProcessingStatusInpColumn.tabKey &&
|
|
!excretaTreatmentFacilitiesAvailableRef.current
|
|
) {
|
|
alert(EMPTY_EXCRETA_TREATMENT_FACILITIES_MSG);
|
|
return;
|
|
}
|
|
|
|
try {
|
|
setIsLoading(true);
|
|
const param = buildSewageExcretaSlurgeSearchParam(values, { mode: "PRE" });
|
|
await loadActiveTabData(
|
|
activeTabRef.current,
|
|
param,
|
|
values,
|
|
true,
|
|
false,
|
|
{ mode: "PRE" },
|
|
);
|
|
} catch {
|
|
alert("데이터 조회 중 오류가 발생했습니다.");
|
|
} finally {
|
|
setIsLoading(false);
|
|
}
|
|
};
|
|
|
|
const submitFunc = () => {
|
|
void (async () => {
|
|
const tabKey = activeTabRef.current;
|
|
if (!SUBMIT_SUPPORTED_TAB_KEYS.has(tabKey)) {
|
|
alert("해당 탭은 제출 기능이 준비되지 않았습니다.");
|
|
return;
|
|
}
|
|
if (!lastSearchedValues || !searchParamRef.current) {
|
|
alert("먼저 조회를 진행해주세요.");
|
|
return;
|
|
}
|
|
if (!buildGugunOkForToolbar(lastSearchedValues)) {
|
|
alert("시군구를 선택해주세요.");
|
|
return;
|
|
}
|
|
|
|
commitActiveGrid();
|
|
const noApplicable = buildNoApplicableForRequest(searchContextByTab.get(tabKey) ?? lastSearchedValues, isNotApplicableByTab.get(tabKey) ?? false, getTabGridRows(tabKey).length === 0);
|
|
const currentData = getTabGridRows(tabKey);
|
|
if (!noApplicable && currentData.length === 0 && buildSubmitOkForToolbar(searchContextByTab.get(tabKey) ?? lastSearchedValues)) {
|
|
alert("해당사항 없음을 체크해주세요.");
|
|
return;
|
|
}
|
|
|
|
if (await confirm("제출 하시겠습니까?")) {
|
|
setShowSubmitDialog(true);
|
|
}
|
|
})();
|
|
};
|
|
|
|
const executeSubmit = async (submitInfo: StatisticsInputSubmitInfoFormData) => {
|
|
const tabKey = activeTabRef.current;
|
|
if (!SUBMIT_SUPPORTED_TAB_KEYS.has(tabKey)) {
|
|
alert("해당 탭은 제출 기능이 준비되지 않았습니다.");
|
|
return;
|
|
}
|
|
if (!lastSearchedValues || !searchParamRef.current) {
|
|
alert("먼저 조회를 진행해주세요.");
|
|
return;
|
|
}
|
|
if (!buildGugunOkForToolbar(lastSearchedValues)) {
|
|
alert("시군구를 선택해주세요.");
|
|
return;
|
|
}
|
|
|
|
commitActiveGrid();
|
|
|
|
const noApplicable = buildNoApplicableForRequest(searchContextByTab.get(tabKey) ?? lastSearchedValues, isNotApplicableByTab.get(tabKey) ?? false, getTabGridRows(tabKey).length === 0);
|
|
const currentData = getTabGridRows(tabKey);
|
|
const mapRows = rowDataMap.get(tabKey) ?? [];
|
|
|
|
const sido = lastSearchedValues.sido ?? "";
|
|
let list = sggOptions;
|
|
if (sggOptionsSidoRef.current !== sido || list.length === 0) {
|
|
list = await loadSggOptions(sido);
|
|
sggOptionsSidoRef.current = sido;
|
|
}
|
|
if (list.length === 0) {
|
|
alert("시군구 목록을 불러오지 못했습니다.");
|
|
return;
|
|
}
|
|
|
|
const isSlurgeFacTab = tabKey === SlurgeProcessingFacStatusInpColumn.tabKey;
|
|
const isDigestorTab = tabKey === DigestorOperatingStatusInpColumn.tabKey;
|
|
const isSewageSlurgeFacTab = tabKey === SewageSlurgeProcessingFacStatusInpColumn.tabKey;
|
|
const isExcretaSlurgeTab = tabKey === ExcretaSlurgeProcessingStatusInpColumn.tabKey;
|
|
const rowsForSubmit = mergeGridRowsWithMapRows(
|
|
currentData,
|
|
mapRows,
|
|
mergeHiddenFieldsForSubmitTab(tabKey),
|
|
);
|
|
|
|
const slurgeSubmitList =
|
|
noApplicable || !isSlurgeFacTab
|
|
? []
|
|
: rowsForSubmit.map((row) => buildSlurgeProcessingFacStatusSaveItem(row, list));
|
|
const digestorSubmitList =
|
|
noApplicable || !isDigestorTab
|
|
? []
|
|
: rowsForSubmit.map((row) => buildDigestorOperatingStatusSaveItem(row, list));
|
|
const sewageSlurgeFacSubmitList =
|
|
noApplicable || !isSewageSlurgeFacTab
|
|
? []
|
|
: rowsForSubmit.map((row) =>
|
|
buildSewageSlurgeProcessingFacStatusSaveItem(row, list),
|
|
);
|
|
const excretaSlurgeSubmitList =
|
|
noApplicable || !isExcretaSlurgeTab
|
|
? []
|
|
: rowsForSubmit.map((row) =>
|
|
buildExcretaSlurgeProcessingStatusSaveItem(row, list),
|
|
);
|
|
const sewageSlurgeFacDeleteList = isSewageSlurgeFacTab
|
|
? (deleteListByTab.get(tabKey) ?? [])
|
|
.filter((row) => isPersistedArticleRowForTab(tabKey, row))
|
|
.map((row) => buildSewageSlurgeProcessingFacStatusSaveItem(row, list))
|
|
: [];
|
|
|
|
if (
|
|
!noApplicable &&
|
|
buildSubmitOkForToolbar(searchContextByTab.get(tabKey) ?? lastSearchedValues) &&
|
|
((isSlurgeFacTab && slurgeSubmitList.length === 0) ||
|
|
(isDigestorTab && digestorSubmitList.length === 0) ||
|
|
(isSewageSlurgeFacTab && sewageSlurgeFacSubmitList.length === 0) ||
|
|
(isExcretaSlurgeTab && excretaSlurgeSubmitList.length === 0))
|
|
) {
|
|
alert("해당사항 없음을 체크해주세요.");
|
|
return;
|
|
}
|
|
|
|
const activeTabStatus = tabStatusInfoMap.get(tabKey) ?? null;
|
|
const statsCdForSubmit =
|
|
tabStatsCdMap.get(tabKey) ??
|
|
(isDigestorTab
|
|
? SEWAGE_EXCRETA_DIGESTOR_OPERATING_STATS_CD
|
|
: isSewageSlurgeFacTab
|
|
? SEWAGE_EXCRETA_SEWAGE_SLURGE_FAC_STATUS_STATS_CD
|
|
: isExcretaSlurgeTab
|
|
? SEWAGE_EXCRETA_EXCRETA_SLURGE_PROCESSING_STATS_CD
|
|
: SEWAGE_EXCRETA_SLURGE_PROCESSING_FAC_STATUS_STATS_CD);
|
|
|
|
const verificationQuery = {
|
|
...toInputSearchRegion(sidoListRef.current, lastSearchedValues),
|
|
ctpvNm: lastSearchedValues.sido ?? "",
|
|
statsYr: lastSearchedValues.year ?? "",
|
|
statsCd: statsCdForSubmit,
|
|
};
|
|
|
|
const reloadAfterSubmit = async () => {
|
|
if (isSlurgeFacTab || isSewageSlurgeFacTab) {
|
|
setDeleteListByTab((prev) => {
|
|
const next = new Map(prev);
|
|
next.set(tabKey, []);
|
|
return next;
|
|
});
|
|
if (isSlurgeFacTab) {
|
|
preYearArticleFcltSnRef.current = new Set();
|
|
}
|
|
}
|
|
setSggOptions(list);
|
|
await loadActiveTabData(
|
|
tabKey,
|
|
searchParamRef.current!,
|
|
lastSearchedValues,
|
|
true,
|
|
false,
|
|
);
|
|
};
|
|
|
|
const submitRequestBase = {
|
|
statsYr: lastSearchedValues.year ?? "",
|
|
ctpvNm: lastSearchedValues.sido ?? "",
|
|
...toInputSearchRegion(sidoListRef.current, lastSearchedValues),
|
|
userUuid: "",
|
|
lclgvPicNm: submitInfo.lclgvPicNm,
|
|
lclgvPicTelnoCn: submitInfo.lclgvPicTelnoCn,
|
|
lclgvKbrdrDeptNm: submitInfo.lclgvKbrdrDeptNm,
|
|
lclgvKbrdrJbgdNm: submitInfo.lclgvKbrdrJbgdNm,
|
|
lclgvIdfrNm: submitInfo.lclgvIdfrNm,
|
|
lclgvIdfrTelnoCn: submitInfo.lclgvIdfrTelnoCn,
|
|
lclgvIdfrDeptNm: submitInfo.lclgvIdfrDeptNm,
|
|
lclgvIdfrJbgdNm: submitInfo.lclgvIdfrJbgdNm,
|
|
noApplicable,
|
|
};
|
|
|
|
try {
|
|
showGlobalProgress({ label: "서버에 요청 중...", progress: 0 });
|
|
const userInfo = await getUserInfo();
|
|
setGlobalProgressLabel("일반 검증 진행 중...");
|
|
const response = isSlurgeFacTab
|
|
? await statisticsInputSewageExcretaSlurgeApi.submitSlurgeProcessingFacStatus({
|
|
...submitRequestBase,
|
|
userUuid: userInfo.userUnqId,
|
|
submitList: slurgeSubmitList,
|
|
})
|
|
: isDigestorTab
|
|
? await statisticsInputSewageExcretaSlurgeApi.submitDigestorOperatingStatus({
|
|
...submitRequestBase,
|
|
userUuid: userInfo.userUnqId,
|
|
submitList: digestorSubmitList,
|
|
})
|
|
: isSewageSlurgeFacTab
|
|
? await statisticsInputSewageExcretaSlurgeApi.submitSewageSlurgeProcessingFacStatus(
|
|
{
|
|
...submitRequestBase,
|
|
userUuid: userInfo.userUnqId,
|
|
submitList: sewageSlurgeFacSubmitList,
|
|
deleteList: sewageSlurgeFacDeleteList,
|
|
},
|
|
)
|
|
: await statisticsInputSewageExcretaSlurgeApi.submitExcretaSlurgeProcessingStatus(
|
|
{
|
|
...submitRequestBase,
|
|
userUuid: userInfo.userUnqId,
|
|
submitList: excretaSlurgeSubmitList,
|
|
},
|
|
);
|
|
|
|
if (response.status !== "success") {
|
|
alert(response.message ?? "데이터 제출 중 오류가 발생했습니다.");
|
|
return;
|
|
}
|
|
|
|
const finalStatus = response.data?.finalStatus;
|
|
const nvpassed = response.data?.nvpassed;
|
|
|
|
if (finalStatus === "5") {
|
|
setGlobalProgress(50);
|
|
setGlobalProgressLabel("시계열 검증 진행 중...");
|
|
const imrParam = {
|
|
user_id: userInfo.userUnqId,
|
|
sewer_bzmn_cd: lastSearchedValues?.bsnmCd ?? "",
|
|
stats_cd: statsCdForSubmit,
|
|
stats_yr: lastSearchedValues.year ?? "",
|
|
lae_sbmsn_stts_cd:
|
|
activeTabStatus?.lclgvSbmsnSttsCd === "4" ? "4" : "2",
|
|
gen_verify_stts_cd: nvpassed ? "1" : "2",
|
|
hb_pass_yn: response.data?.isHbPassed,
|
|
};
|
|
|
|
try {
|
|
const imrResponse = await callImrServiceWithRollbackOnFailure(imrParam, {
|
|
statsYr: lastSearchedValues.year ?? "",
|
|
statsCd: statsCdForSubmit,
|
|
sewerBzmnCd: lastSearchedValues?.bsnmCd ?? "",
|
|
rollbackStatusCode: activeTabStatus?.lclgvSbmsnSttsCd ?? "",
|
|
mdfrUuid: userInfo.userUnqId,
|
|
});
|
|
if (imrResponse.job_id) {
|
|
await waitForImrJobCompleted(
|
|
imrResponse.job_id,
|
|
(id) => statisticsApi.getImrStatus(id),
|
|
{
|
|
onProgress: (jobProgress) => {
|
|
setGlobalProgress(50 + Math.round(jobProgress / 2));
|
|
},
|
|
},
|
|
);
|
|
}
|
|
setGlobalProgress(100);
|
|
await reloadAfterSubmit();
|
|
await openVerificationResultDialogIfNeeded(
|
|
verificationQuery,
|
|
setVerificationResultDialogOpen,
|
|
{ notify: alert },
|
|
);
|
|
} catch (e) {
|
|
await reloadAfterSubmit();
|
|
await openVerificationResultDialogIfNeeded(
|
|
verificationQuery,
|
|
setVerificationResultDialogOpen,
|
|
{ notify: alert, notifySubmitComplete: false },
|
|
);
|
|
const msg =
|
|
e instanceof Error && e.message
|
|
? e.message
|
|
: "IMR 검증 중 오류가 발생했습니다.\n관리자에게 문의하세요.";
|
|
alert(msg);
|
|
}
|
|
} else {
|
|
setGlobalProgress(100);
|
|
await reloadAfterSubmit();
|
|
await openVerificationResultDialogIfNeeded(
|
|
verificationQuery,
|
|
setVerificationResultDialogOpen,
|
|
{ notify: alert },
|
|
);
|
|
}
|
|
} catch {
|
|
alert("데이터 제출 중 오류가 발생했습니다.");
|
|
} finally {
|
|
hideGlobalProgress();
|
|
setShowSubmitDialog(false);
|
|
}
|
|
};
|
|
|
|
const updateOperateDataButtonFunc = () => {
|
|
void (async () => {
|
|
if (!lastSearchedValues) {
|
|
alert("먼저 조회를 진행해주세요.");
|
|
return;
|
|
}
|
|
if (!(await confirm("자체발생량·함수율·자체 1차 처리량이 운영 데이터로 덮어씁니다."))) {
|
|
return;
|
|
}
|
|
|
|
try {
|
|
showGlobalProgress({ label: "운영 데이터 업데이트 중...", progress: 0 });
|
|
const userInfo = await getUserInfo();
|
|
const request = {
|
|
statsYr: lastSearchedValues.year ?? "",
|
|
ctpvNm: lastSearchedValues.sido ?? "",
|
|
...toInputSearchRegion(sidoListRef.current, lastSearchedValues),
|
|
userUuid: userInfo.userUnqId,
|
|
};
|
|
|
|
const response =
|
|
await statisticsInputSewageExcretaSlurgeApi.updateSlurgeProcessingFacStatusOperationData(
|
|
request,
|
|
);
|
|
if (response.status !== "success") {
|
|
alert(
|
|
response.message ||
|
|
"운영 데이터 업데이트 중 오류가 발생했습니다.",
|
|
);
|
|
return;
|
|
}
|
|
|
|
setGlobalProgress(50);
|
|
const tabKey = SlurgeProcessingFacStatusInpColumn.tabKey;
|
|
const param =
|
|
searchParamRef.current ??
|
|
buildSewageExcretaSlurgeSearchParam(lastSearchedValues);
|
|
await loadActiveTabData(tabKey, param, lastSearchedValues, true, false);
|
|
setGlobalProgress(100);
|
|
alert("운영 데이터가 업데이트되었습니다.");
|
|
} catch (error) {
|
|
const message =
|
|
error &&
|
|
typeof error === "object" &&
|
|
"response" in error
|
|
? (error as { response?: { data?: { message?: string } } })
|
|
.response?.data?.message
|
|
: undefined;
|
|
alert(message || "운영 데이터 업데이트 중 오류가 발생했습니다.");
|
|
} finally {
|
|
hideGlobalProgress();
|
|
}
|
|
})();
|
|
};
|
|
|
|
const cnacelSubmitFunc = () => {
|
|
void (async () => {
|
|
try {
|
|
if (!(await confirm("제출된 내용을 취소하시겠습니까?"))) return;
|
|
|
|
if (!lastSearchedValues || !searchParamRef.current) {
|
|
alert("먼저 조회를 진행해주세요.");
|
|
return;
|
|
}
|
|
|
|
const userInfo = await getUserInfo();
|
|
const tabKey = activeTabRef.current;
|
|
const statsCdForTab = tabStatsCdMap.get(tabKey);
|
|
if (!statsCdForTab) {
|
|
alert("먼저 조회를 진행해주세요.");
|
|
return;
|
|
}
|
|
|
|
const requestData: cancelSubmitRequest = {
|
|
...toInputSearchRegion(sidoListRef.current, lastSearchedValues),
|
|
ctpvNm: lastSearchedValues.sido ?? "",
|
|
statsYr: lastSearchedValues.year ?? "",
|
|
mdfrUuid: userInfo.userUnqId,
|
|
statsCd: statsCdForTab,
|
|
};
|
|
|
|
const response = await statisticsApi.cancelSubmit(requestData);
|
|
|
|
if (response.status === "success") {
|
|
setIsLoading(true);
|
|
await loadActiveTabData(
|
|
tabKey,
|
|
searchParamRef.current,
|
|
lastSearchedValues,
|
|
true,
|
|
false,
|
|
);
|
|
alert("제출 취소되었습니다.");
|
|
} else {
|
|
alert(response.message ?? "제출 취소 중 오류가 발생했습니다.");
|
|
}
|
|
} catch {
|
|
alert("제출 취소 중 오류가 발생했습니다.");
|
|
} finally {
|
|
setIsLoading(false);
|
|
}
|
|
})();
|
|
};
|
|
|
|
const saveFunc = () => {
|
|
void (async () => {
|
|
const tabKey = activeTabRef.current;
|
|
if (!lastSearchedValues) {
|
|
alert("먼저 조회를 진행해주세요.");
|
|
return;
|
|
}
|
|
if (!buildGugunOkForToolbar(lastSearchedValues)) {
|
|
alert("시군구를 선택해주세요.");
|
|
return;
|
|
}
|
|
if (!SAVE_SUPPORTED_TAB_KEYS.has(tabKey)) {
|
|
alert("해당 탭은 저장 기능이 준비되지 않았습니다.");
|
|
return;
|
|
}
|
|
if (!(await confirm("저장 하시겠습니까?"))) return;
|
|
|
|
commitActiveGrid();
|
|
|
|
const noApplicable = buildNoApplicableForRequest(searchContextByTab.get(tabKey) ?? lastSearchedValues, isNotApplicableByTab.get(tabKey) ?? false, getTabGridRows(tabKey).length === 0);
|
|
const currentData = getTabGridRows(tabKey);
|
|
const mapRows = rowDataMap.get(tabKey) ?? [];
|
|
|
|
const sido = lastSearchedValues.sido ?? "";
|
|
let list = sggOptions;
|
|
if (sggOptionsSidoRef.current !== sido || list.length === 0) {
|
|
list = await loadSggOptions(sido);
|
|
sggOptionsSidoRef.current = sido;
|
|
}
|
|
if (list.length === 0) {
|
|
alert("시군구 목록을 불러오지 못했습니다.");
|
|
return;
|
|
}
|
|
|
|
const baseSaveRequest = {
|
|
statsYr: lastSearchedValues.year ?? "",
|
|
ctpvNm: lastSearchedValues.sido ?? "",
|
|
...toInputSearchRegion(sidoListRef.current, lastSearchedValues),
|
|
...(noApplicable ? { noApplicable: true } : {}),
|
|
};
|
|
|
|
try {
|
|
setIsLoading(true);
|
|
const userInfo = await getUserInfo();
|
|
const userFields = {
|
|
userUuid: userInfo.userUnqId,
|
|
...(isAdminInfo ? { superAdmin: "superAdmin" as const } : {}),
|
|
};
|
|
|
|
let response: { status: string; message?: string };
|
|
|
|
if (tabKey === SlurgeProcessingFacStatusInpColumn.tabKey) {
|
|
const rowsForSave = mergeGridRowsWithMapRows(currentData, mapRows, [
|
|
"swtrmtFcltCd",
|
|
"fcltSn",
|
|
"admdstCd",
|
|
"admdstNm",
|
|
]);
|
|
|
|
const saveList = noApplicable
|
|
? []
|
|
: rowsForSave.map((row) =>
|
|
buildSlurgeProcessingFacStatusSaveItem(row, list),
|
|
);
|
|
|
|
if (!noApplicable && saveList.length === 0 && buildSubmitOkForToolbar(searchContextByTab.get(tabKey) ?? lastSearchedValues)) {
|
|
alert("해당사항 없음을 체크해주세요.");
|
|
return;
|
|
}
|
|
|
|
response =
|
|
await statisticsInputSewageExcretaSlurgeApi.saveSlurgeProcessingFacStatus(
|
|
{
|
|
...baseSaveRequest,
|
|
...userFields,
|
|
saveList,
|
|
},
|
|
);
|
|
} else if (tabKey === DigestorOperatingStatusInpColumn.tabKey) {
|
|
const rowsForSave = mergeGridRowsWithMapRows(currentData, mapRows, [
|
|
"swtrmtFcltCd",
|
|
"fcltSn",
|
|
"admdstCd",
|
|
"admdstNm",
|
|
]);
|
|
const saveList = noApplicable
|
|
? []
|
|
: rowsForSave.map((row) =>
|
|
buildDigestorOperatingStatusSaveItem(row, list),
|
|
);
|
|
|
|
if (!noApplicable && saveList.length === 0 && buildSubmitOkForToolbar(searchContextByTab.get(tabKey) ?? lastSearchedValues)) {
|
|
alert("해당사항 없음을 체크해주세요.");
|
|
return;
|
|
}
|
|
|
|
response =
|
|
await statisticsInputSewageExcretaSlurgeApi.saveDigestorOperatingStatus({
|
|
...baseSaveRequest,
|
|
...userFields,
|
|
saveList,
|
|
});
|
|
} else if (tabKey === SewageSlurgeProcessingFacStatusInpColumn.tabKey) {
|
|
const rowsForSave = mergeGridRowsWithMapRows(currentData, mapRows, [
|
|
"fcltSn",
|
|
"admdstCd",
|
|
"admdstNm",
|
|
]);
|
|
const saveList = noApplicable
|
|
? []
|
|
: rowsForSave.map((row) =>
|
|
buildSewageSlurgeProcessingFacStatusSaveItem(row, list),
|
|
);
|
|
const deleteList = (deleteListByTab.get(tabKey) ?? [])
|
|
.filter((row) => isPersistedArticleRowForTab(tabKey, row))
|
|
.map((row) => buildSewageSlurgeProcessingFacStatusSaveItem(row, list));
|
|
|
|
if (!noApplicable && saveList.length === 0 && buildSubmitOkForToolbar(searchContextByTab.get(tabKey) ?? lastSearchedValues)) {
|
|
alert("해당사항 없음을 체크해주세요.");
|
|
return;
|
|
}
|
|
|
|
response =
|
|
await statisticsInputSewageExcretaSlurgeApi.saveSewageSlurgeProcessingFacStatus(
|
|
{
|
|
...baseSaveRequest,
|
|
...userFields,
|
|
saveList,
|
|
deleteList,
|
|
},
|
|
);
|
|
} else {
|
|
const rowsForSave = mergeGridRowsWithMapRows(currentData, mapRows, [
|
|
"fcltSn",
|
|
"admdstCd",
|
|
"admdstNm",
|
|
"fcltPstnCn",
|
|
]);
|
|
const saveList = noApplicable
|
|
? []
|
|
: rowsForSave.map((row) =>
|
|
buildExcretaSlurgeProcessingStatusSaveItem(row, list),
|
|
);
|
|
|
|
if (!noApplicable && saveList.length === 0 && buildSubmitOkForToolbar(searchContextByTab.get(tabKey) ?? lastSearchedValues)) {
|
|
alert("해당사항 없음을 체크해주세요.");
|
|
return;
|
|
}
|
|
|
|
response =
|
|
await statisticsInputSewageExcretaSlurgeApi.saveExcretaSlurgeProcessingStatus(
|
|
{
|
|
...baseSaveRequest,
|
|
...userFields,
|
|
saveList,
|
|
},
|
|
);
|
|
}
|
|
|
|
if (response.status === "success") {
|
|
setDeleteListByTab((prev) => {
|
|
const next = new Map(prev);
|
|
next.set(tabKey, []);
|
|
return next;
|
|
});
|
|
if (tabKey === SlurgeProcessingFacStatusInpColumn.tabKey) {
|
|
preYearArticleFcltSnRef.current = new Set();
|
|
}
|
|
setSggOptions(list);
|
|
|
|
const param =
|
|
searchParamRef.current ??
|
|
buildSewageExcretaSlurgeSearchParam(lastSearchedValues);
|
|
await loadActiveTabData(tabKey, param, lastSearchedValues, true, false);
|
|
alert("저장되었습니다.");
|
|
} else {
|
|
alert(response.message ?? "저장 중 오류가 발생했습니다.");
|
|
}
|
|
} catch {
|
|
alert("저장 중 오류가 발생했습니다.");
|
|
} finally {
|
|
setIsLoading(false);
|
|
}
|
|
})();
|
|
};
|
|
|
|
const isCheckedRow = (row: Record<string, string | number>): boolean => {
|
|
const v = row.__checked;
|
|
return v === 1 || v === "1" || v === "Y" || v === "y" || v === "true";
|
|
};
|
|
|
|
const getCheckedItemIndexesFromGrid = (rowCount: number): number[] => {
|
|
const gridView = getGridRef.current?.gridView as
|
|
| {
|
|
getCheckedItems?: () => number[];
|
|
getCheckedRows?: () => number[];
|
|
}
|
|
| undefined;
|
|
|
|
const checked =
|
|
(typeof gridView?.getCheckedItems === "function"
|
|
? gridView.getCheckedItems()
|
|
: typeof gridView?.getCheckedRows === "function"
|
|
? gridView.getCheckedRows()
|
|
: []) ?? [];
|
|
|
|
return checked.filter(
|
|
(idx) => Number.isInteger(idx) && idx >= 0 && idx < rowCount,
|
|
);
|
|
};
|
|
|
|
const addArticleFunc = async () => {
|
|
const ctx = lastSearchedValues ?? searchValues;
|
|
if (!hasSearched || !ctx?.sido || ctx.sido === "ALL") {
|
|
alert("먼저 조회를 진행해주세요.");
|
|
return;
|
|
}
|
|
|
|
const tabKey = activeTabRef.current;
|
|
if (!ARTICLE_EDIT_TAB_KEYS.has(tabKey)) {
|
|
alert("항목을 추가할 수 없는 탭입니다.");
|
|
return;
|
|
}
|
|
|
|
const sggNm = ctx.gugun && ctx.gugun !== "ALL" ? ctx.gugun : "";
|
|
|
|
let list = sggOptions;
|
|
if (sggOptionsSidoRef.current !== ctx.sido || list.length === 0) {
|
|
list = await loadSggOptions(ctx.sido);
|
|
sggOptionsSidoRef.current = ctx.sido;
|
|
}
|
|
if (list.length === 0) {
|
|
alert("시군구 목록을 불러오지 못했습니다.");
|
|
return;
|
|
}
|
|
|
|
commitActiveGrid();
|
|
const currentRows = getTabGridRows(tabKey);
|
|
const newRow = createEmptyArticleRow(tabKey, ctx.sido, sggNm);
|
|
if (ARTICLE_EDIT_TAB_KEYS.has(tabKey)) {
|
|
newRow.__isNewArticle = 1;
|
|
}
|
|
|
|
flushSync(() => {
|
|
setSggOptions(list);
|
|
setRowDataMap((prev) => {
|
|
const next = new Map(prev);
|
|
next.set(tabKey, [...currentRows, newRow]);
|
|
return next;
|
|
});
|
|
setIsNotApplicableForTab(tabKey, false);
|
|
});
|
|
|
|
const statusInfo = tabStatusInfoMap.get(tabKey) ?? null;
|
|
commitToolbarSnapshotForLoadedTab(tabKey, statusInfo, true, ctx);
|
|
};
|
|
|
|
const deleteArticleFunc = () => {
|
|
const tabKey = activeTabRef.current;
|
|
if (!ARTICLE_EDIT_TAB_KEYS.has(tabKey)) {
|
|
alert("항목을 제외할 수 없는 탭입니다.");
|
|
return;
|
|
}
|
|
|
|
commitActiveGrid();
|
|
const currentRows = getTabGridRows(tabKey);
|
|
if (currentRows.length === 0) {
|
|
alert("삭제할 데이터가 없습니다.");
|
|
return;
|
|
}
|
|
|
|
const checkedIndexes = getCheckedItemIndexesFromGrid(currentRows.length);
|
|
const checkedIndexSet =
|
|
checkedIndexes.length > 0
|
|
? new Set(checkedIndexes)
|
|
: new Set(
|
|
currentRows
|
|
.map((row, idx) => (isCheckedRow(row) ? idx : -1))
|
|
.filter((idx) => idx >= 0),
|
|
);
|
|
|
|
const removedRows = currentRows.filter((_, idx) => checkedIndexSet.has(idx));
|
|
const nextRows = currentRows.filter((_, idx) => !checkedIndexSet.has(idx));
|
|
if (removedRows.length === 0) {
|
|
alert("삭제할 항목을 선택해주세요.");
|
|
return;
|
|
}
|
|
|
|
const persistedRemovedRows = removedRows.filter((row) =>
|
|
isPersistedArticleRowForTab(tabKey, row),
|
|
);
|
|
if (persistedRemovedRows.length > 0) {
|
|
setDeleteListByTab((prev) => {
|
|
const next = new Map(prev);
|
|
next.set(tabKey, [...(prev.get(tabKey) ?? []), ...persistedRemovedRows]);
|
|
return next;
|
|
});
|
|
}
|
|
|
|
setRowDataMap((prev) => {
|
|
const next = new Map(prev);
|
|
next.set(tabKey, nextRows);
|
|
return next;
|
|
});
|
|
|
|
const ctx = lastSearchedValues ?? searchValues;
|
|
if (ctx) {
|
|
const statusInfo = tabStatusInfoMap.get(tabKey) ?? null;
|
|
commitToolbarSnapshotForLoadedTab(
|
|
tabKey,
|
|
statusInfo,
|
|
nextRows.length > 0,
|
|
ctx,
|
|
);
|
|
}
|
|
};
|
|
|
|
const columnInfoByTab = useMemo(() => {
|
|
const map = new Map<string, ColumnInfo>();
|
|
for (const tab of SewageExcretaSlurgeInpTabList) {
|
|
const tabKey = tab.tabKey;
|
|
const canEdit =
|
|
(computeTabEnterable(
|
|
tabStatusInfoMap.get(tabKey) ?? null,
|
|
inputPeriodEnterable,
|
|
) || isAdminInfo) && inputPeriodEnterable;
|
|
const rawColumns = (tab.columns ?? []) as ColumnConfig[];
|
|
const base = canEdit
|
|
? rawColumns
|
|
: rawColumns.map((col) => ({ ...col, editable: false as const }));
|
|
const columns = base.map((col) => {
|
|
let next: ColumnConfig = col;
|
|
if (col.fieldName === "ctpvNm") {
|
|
next = { ...col, editable: false as const, styleName: "rg-cell-readonly" };
|
|
} else if (
|
|
SGG_NM_DROPDOWN_TAB_KEYS.has(tabKey) &&
|
|
col.fieldName === "sggNm"
|
|
) {
|
|
next = buildSggNmColumn(
|
|
col,
|
|
canEdit,
|
|
filterSggOptionsBySearchGugun(sggOptions, lastSearchedValues?.gugun),
|
|
);
|
|
} else if (col.fieldName === "sggNm") {
|
|
next = { ...col, editable: false as const, styleName: "rg-cell-readonly" };
|
|
}
|
|
const guide = columnGuidesByTab[tabKey]?.[col.fieldName]?.trim();
|
|
return guide ? { ...next, tooltip: guide } : next;
|
|
});
|
|
map.set(tabKey, {
|
|
columns,
|
|
columnLayout: tab.columnLayout ?? [],
|
|
});
|
|
}
|
|
return map;
|
|
}, [
|
|
tabStatusInfoMap,
|
|
inputPeriodEnterable,
|
|
isAdminInfo,
|
|
sggOptions,
|
|
hasSearched,
|
|
lastSearchedValues,
|
|
searchValues,
|
|
columnGuidesByTab,
|
|
]);
|
|
|
|
const digestorOperatingCellStyleCallback = useCallback<CellStyleCallback>(
|
|
({ row, fieldName, rowIndex, grid }) => {
|
|
if (fieldName === DIGESTOR_OPERATING_STATUS_EN_YN_FIELD) {
|
|
return undefined;
|
|
}
|
|
if (!isDigestorOperatingRowDisabled(row, grid, rowIndex)) {
|
|
return undefined;
|
|
}
|
|
return { styleName: "rg-cell-readonly", editable: false };
|
|
},
|
|
[],
|
|
);
|
|
|
|
const handleDigestorCellEdited = useCallback<CellEditedCallback>(
|
|
({ fieldName }) => {
|
|
if (fieldName !== DIGESTOR_OPERATING_STATUS_EN_YN_FIELD) {
|
|
return;
|
|
}
|
|
// 편집 중 setRowDataMap → setRows/refresh와 충돌하지 않도록 편집 완료 후 갱신
|
|
window.setTimeout(() => {
|
|
getGridRef.current?.gridView?.refresh?.();
|
|
}, 0);
|
|
},
|
|
[],
|
|
);
|
|
|
|
const resolveGridCellStyleCallback = useCallback(
|
|
(tabKey: string): CellStyleCallback =>
|
|
(params) => {
|
|
const verification = verificationCellStyle(params);
|
|
if (tabKey !== DigestorOperatingStatusInpColumn.tabKey) {
|
|
return verification;
|
|
}
|
|
return mergeCellStyleResults(
|
|
verification,
|
|
digestorOperatingCellStyleCallback(params),
|
|
);
|
|
},
|
|
[digestorOperatingCellStyleCallback],
|
|
);
|
|
|
|
const searchContextForToolbar = searchContextByTab.get(activeTab) ?? lastSearchedValues;
|
|
const activeTabStatus = tabStatusInfoMap.get(activeTab) ?? null;
|
|
const activeTabHasRowData = tabRowDataExists(rowDataMap, activeTab);
|
|
const activeTabToolbar = computeTabToolbarSnapshot(
|
|
activeTabStatus,
|
|
activeTabHasRowData,
|
|
hasSearched,
|
|
searchContextForToolbar,
|
|
inputPeriodEnterable,
|
|
isAdminInfo,
|
|
);
|
|
|
|
const {
|
|
showSaveInToolbar: baseShowSaveInToolbar,
|
|
showEnterableToolbarButtons: baseShowEnterableToolbarButtons,
|
|
showActionToolbarCard: baseShowActionToolbarCard,
|
|
} = activeTabToolbar;
|
|
|
|
const showSaveInToolbar = baseShowSaveInToolbar && toolbarGroupAllowed;
|
|
const showEnterableToolbarButtons =
|
|
baseShowEnterableToolbarButtons && toolbarGroupAllowed;
|
|
const submitOk = buildSubmitOkForToolbar(searchContextForToolbar);
|
|
const showActionToolbarCard =
|
|
toolbarGroupAllowed &&
|
|
(baseShowActionToolbarCard || (hasSearched && loadedTabKeys.has(activeTab)));
|
|
const showArticleEditButtons =
|
|
ARTICLE_EDIT_TAB_KEYS.has(activeTab) && showEnterableToolbarButtons;
|
|
const showNotApplicableForActiveTab =
|
|
loadedTabKeys.has(activeTab) &&
|
|
shouldShowNotApplicable(activeTabHasRowData, activeTabStatus) &&
|
|
submitOk;
|
|
const showSecondaryToolbarCard =
|
|
hasSearched &&
|
|
toolbarGroupAllowed &&
|
|
(showSaveInToolbar || showEnterableToolbarButtons);
|
|
const isNotApplicableForActiveTab = isNotApplicableByTab.get(activeTab) ?? false;
|
|
const setIsNotApplicableForActiveTab: Dispatch<SetStateAction<boolean>> = useCallback(
|
|
(next) => {
|
|
const tabKey = activeTabRef.current;
|
|
const current = isNotApplicableByTab.get(tabKey) ?? false;
|
|
const resolved =
|
|
typeof next === "function"
|
|
? (next as (prevState: boolean) => boolean)(current)
|
|
: next;
|
|
setIsNotApplicableForTab(tabKey, resolved);
|
|
},
|
|
[isNotApplicableByTab, setIsNotApplicableForTab],
|
|
);
|
|
|
|
const openVerificationHistoryDialog = () => {
|
|
const ctx = lastSearchedValues ?? searchValues;
|
|
const activeTabStatsCd = tabStatsCdMap.get(activeTab);
|
|
if (!ctx?.year || !ctx?.sido || !ctx?.bsnmCd || !activeTabStatsCd) {
|
|
alert("먼저 조회를 진행해주세요.");
|
|
return;
|
|
}
|
|
setVerificationHistoryOpen(true);
|
|
};
|
|
|
|
const verificationQueryContext = (() => {
|
|
const ctx = lastSearchedValues ?? searchValues;
|
|
const statsCd = tabStatsCdMap.get(activeTab);
|
|
if (!ctx?.year || !ctx?.sido || !ctx?.bsnmCd || !statsCd) return null;
|
|
return {
|
|
...toInputSearchRegion(sidoListRef.current, ctx),
|
|
ctpvNm: ctx.sido,
|
|
statsYr: ctx.year,
|
|
statsCd,
|
|
};
|
|
})();
|
|
|
|
const { verificationSearchDefaults, searchFormRemountKey } =
|
|
useStatisticsInputPendingNavigation({
|
|
urlPath: STATISTICS_INPUT_URL_PATH.SEWAGE_EXCRETA_SLURGE,
|
|
onPending: (pending) => {
|
|
activeTabRef.current = pending.tabKey;
|
|
setActiveTab(pending.tabKey);
|
|
},
|
|
onAutoSearch: (values, tabKey) =>
|
|
handleSearch(values, { forcedTabKey: tabKey }),
|
|
});
|
|
|
|
return (
|
|
<>
|
|
<div className="relative">
|
|
<SearchForm
|
|
isInput
|
|
key={searchFormRemountKey}
|
|
defaultValues={verificationSearchDefaults ?? undefined}
|
|
fctName
|
|
onSubmit={handleSearch}
|
|
onReset={handleReset}
|
|
onValuesChange={setSearchValues}
|
|
/>
|
|
{showActionToolbarCard && (
|
|
<div className="card !py-0">
|
|
<div className="flex justify-end items-center gap-[0.6rem] m-[0.6rem]">
|
|
<VerificationResultButton
|
|
VerificationResultButtonFunc={openVerificationHistoryDialog}
|
|
isVerificationFailed={
|
|
isVerificationFailedByTab.get(activeTab) === true
|
|
}
|
|
/>
|
|
{showEnterableToolbarButtons && (
|
|
<>
|
|
<LastYearDataButton
|
|
getLastYearDataFunc={() => void lastYearDataFunc()}
|
|
/>
|
|
{activeTab === SEWAGE_EXCRETA_SLURGE_PROCESSING_FAC_STATUS_STATS_CD && (
|
|
<UpdateOperateDataButton
|
|
updateOperateDataButtonFunc={updateOperateDataButtonFunc}
|
|
/>
|
|
)}
|
|
{submitOk && <SubmitButton submitFunc={submitFunc} />}
|
|
</>
|
|
)}
|
|
{activeTabStatus?.lclgvSbmsnSttsCd === "2" && submitOk && inputPeriodEnterable && (
|
|
<CancelSubmitButton cnacelSubmitFunc={cnacelSubmitFunc} />
|
|
)}
|
|
{showSaveInToolbar && <SaveButton saveFunc={saveFunc} />}
|
|
</div>
|
|
</div>
|
|
)}
|
|
{showSecondaryToolbarCard && (
|
|
<div className="card !py-0">
|
|
<div className="flex justify-end items-center gap-[0.6rem] m-[0.6rem]">
|
|
{showNotApplicableForActiveTab && (
|
|
<NotApplicableCheckButton
|
|
isCheck={isNotApplicableForActiveTab}
|
|
setIsCheck={setIsNotApplicableForActiveTab}
|
|
/>
|
|
)}
|
|
{showArticleEditButtons && (
|
|
<>
|
|
<AddArticleButton addArticleFunc={addArticleFunc} />
|
|
<DeleteArticleButton deleteArticleFunc={deleteArticleFunc} />
|
|
</>
|
|
)}
|
|
</div>
|
|
</div>
|
|
)}
|
|
{isLoading && (
|
|
<div className="absolute inset-0 z-50 [data-theme='black']:bg-transparent rounded-lg p-10 flex justify-center items-center">
|
|
<div className="relative size-[5rem]">
|
|
<LoadingWithAnimation color="primary" />
|
|
</div>
|
|
</div>
|
|
)}
|
|
<div className="flex flex-col gap-[0.6rem] mx-[0.6rem]">
|
|
<Tabs
|
|
value={activeTab}
|
|
onValueChange={(v) => void handleActiveTabChange(v)}
|
|
className="w-full"
|
|
variant="default"
|
|
>
|
|
<TabsList>
|
|
{SewageExcretaSlurgeInpTabList.map((info) => (
|
|
<TabsTrigger key={info.tabKey} value={info.tabKey}>
|
|
{info.tabLabel || info.tabKey}
|
|
</TabsTrigger>
|
|
))}
|
|
</TabsList>
|
|
{SewageExcretaSlurgeInpTabList.map((info) => {
|
|
const tabKey = info.tabKey;
|
|
const rowData = rowDataMap.get(tabKey) ?? [];
|
|
const tabStatusInfo = tabStatusInfoMap.get(tabKey) ?? null;
|
|
|
|
return (
|
|
<TabsContent key={tabKey} value={tabKey}>
|
|
<DataGrid
|
|
key={tabKey}
|
|
columnInfo={
|
|
columnInfoByTab.get(tabKey) ?? toGridColumnInfo(info)
|
|
}
|
|
rowStartNum={info.rowStartNum}
|
|
excelExportFileSuffix={info.tabLabel || tabKey}
|
|
rowData={rowData}
|
|
setRowData={(updater) => {
|
|
setRowDataMap((prev) => {
|
|
const next = new Map(prev);
|
|
const cur = next.get(tabKey) ?? [];
|
|
const nextRows =
|
|
typeof updater === "function"
|
|
? updater(cur)
|
|
: updater;
|
|
next.set(tabKey, nextRows);
|
|
return next;
|
|
});
|
|
}}
|
|
showHeaderCheckbox={ARTICLE_EDIT_TAB_KEYS.has(tabKey)}
|
|
fixedColumns={info.fixedColumns}
|
|
enableSort={false}
|
|
statusInfo={tabStatusInfo}
|
|
isExcelImport={tabRowDataExists(rowDataMap, tabKey)}
|
|
excelImportSewerBzmnCd={(lastSearchedValues ?? searchValues)?.bsnmCd}
|
|
excelExportSearchContext={toExcelExportSearchContextFromSearchForm(lastSearchedValues ?? searchValues)}
|
|
isExcelExport
|
|
getGridDataRef={
|
|
activeTab === tabKey ? getGridDataRef : undefined
|
|
}
|
|
getGridRef={
|
|
activeTab === tabKey ? getGridRef : undefined
|
|
}
|
|
cellStyleCallback={resolveGridCellStyleCallback(tabKey)}
|
|
footerVerificationResult={
|
|
footerVerificationByTab.get(tabKey) ?? null
|
|
}
|
|
cellTooltipCallback={verificationCellTooltip}
|
|
onCellEdited={
|
|
tabKey === DigestorOperatingStatusInpColumn.tabKey
|
|
? handleDigestorCellEdited
|
|
: undefined
|
|
}
|
|
/>
|
|
</TabsContent>
|
|
);
|
|
})}
|
|
</Tabs>
|
|
</div>
|
|
</div>
|
|
<VerificationResultHistoryDialog
|
|
open={verificationHistoryOpen}
|
|
onOpenChange={setVerificationHistoryOpen}
|
|
queryContext={verificationQueryContext}
|
|
onExceptionResetSubmitted={async () => {
|
|
const values = lastSearchedValues ?? searchValues;
|
|
if (!values || !searchParamRef.current) return;
|
|
await loadActiveTabData(
|
|
activeTabRef.current,
|
|
searchParamRef.current,
|
|
values,
|
|
true,
|
|
false,
|
|
);
|
|
}}
|
|
/>
|
|
<VerificationResultDialog
|
|
open={verificationResultDialogOpen}
|
|
onOpenChange={setVerificationResultDialogOpen}
|
|
queryContext={verificationQueryContext}
|
|
onExceptionSubmitted={async () => {
|
|
const values = lastSearchedValues ?? searchValues;
|
|
if (!values || !searchParamRef.current) return;
|
|
await loadActiveTabData(
|
|
activeTabRef.current,
|
|
searchParamRef.current,
|
|
values,
|
|
true,
|
|
false,
|
|
);
|
|
}}
|
|
/>
|
|
<SubmitDailog
|
|
open={showSubmitDialog}
|
|
onOpenChange={setShowSubmitDialog}
|
|
statusInfo={activeTabStatus}
|
|
onConfirm={executeSubmit}
|
|
isLoading={isLoading}
|
|
/>
|
|
<ConfirmDialog isOpen={false} />
|
|
</>
|
|
);
|
|
};
|
|
|
|
export default SewageExcretaSlurgeInp;
|