From 687de61668aa8594abe337b0b898483655492f49 Mon Sep 17 00:00:00 2001 From: rsone001 Date: Fri, 27 Nov 2026 16:02:08 +0900 Subject: [PATCH] =?UTF-8?q?[ST]=20-=20refactor:=209=EB=B2=88=EC=A7=80?= =?UTF-8?q?=ED=91=9C,12-1,=2012-2=20=EC=A7=80=ED=91=9C=20=EB=B3=B8?= =?UTF-8?q?=EC=B2=AD=20=EB=8D=B0=EC=9D=B4=ED=84=B0=20=EC=B2=98=EB=A6=AC?= =?UTF-8?q?=EB=A5=BC=20=EC=9C=84=ED=95=B4=20=EB=A1=9C=EC=A7=81=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../input/SewageExcretaRelatedInp.tsx | 96 +++++++++++++++---- .../statistics/input/SewerageFinanceInp.tsx | 24 ++++- .../statistics/api/statistics-service.ts | 11 +++ apps/st/src/entities/statistics/index.ts | 3 + .../lib/jeonnam-gwangju-sido-all-toolbar.ts | 35 +++++++ .../statistics/model/statistics-interface.ts | 1 + 6 files changed, 149 insertions(+), 21 deletions(-) create mode 100644 apps/st/src/entities/statistics/lib/jeonnam-gwangju-sido-all-toolbar.ts diff --git a/apps/st/src/components/statistics/input/SewageExcretaRelatedInp.tsx b/apps/st/src/components/statistics/input/SewageExcretaRelatedInp.tsx index f5daa4888..5588ba8cb 100644 --- a/apps/st/src/components/statistics/input/SewageExcretaRelatedInp.tsx +++ b/apps/st/src/components/statistics/input/SewageExcretaRelatedInp.tsx @@ -5,7 +5,7 @@ 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 { useAlertStore, useGlobalProgressStore, useStatisticsInputToolbarGroupGate, useSearchConditionSidoList, useUserStore } 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"; @@ -42,6 +42,7 @@ import type { import { filterBySelectedAdmdstCd, isGugunOkForToolbar, + isJeonnamGwangjuSidoAllToolbarException, isSubmitOkForToolbar, resolveNoApplicableForRequest, toInputSearchRegion, @@ -174,12 +175,43 @@ const computeTabEnterable = ( }; const sidoListRef: { current: Sido[] } = { current: [] }; +const relatedToolbarUserIdRef: { current: string } = { current: "" }; -function buildGugunOkForToolbar(values: SearchFormValues | null): boolean { +function isJeonnamGwangjuSidoAllToolbarTab(tabKey: string | null | undefined): boolean { + return Boolean(tabKey && ARTICLE_EDIT_TAB_KEYS.has(tabKey)); +} + +function buildGugunOkForToolbar( + values: SearchFormValues | null, + tabKey?: string | null, +): boolean { + if ( + isJeonnamGwangjuSidoAllToolbarTab(tabKey) && + isJeonnamGwangjuSidoAllToolbarException( + sidoListRef.current, + values, + relatedToolbarUserIdRef.current, + ) + ) { + return true; + } return isGugunOkForToolbar(sidoListRef.current, values); } -function buildSubmitOkForToolbar(values: SearchFormValues | null): boolean { +function buildSubmitOkForToolbar( + values: SearchFormValues | null, + tabKey?: string | null, +): boolean { + if ( + isJeonnamGwangjuSidoAllToolbarTab(tabKey) && + isJeonnamGwangjuSidoAllToolbarException( + sidoListRef.current, + values, + relatedToolbarUserIdRef.current, + ) + ) { + return true; + } return isSubmitOkForToolbar(sidoListRef.current, values); } @@ -198,8 +230,9 @@ function computeTabToolbarSnapshot( searchContext: SearchFormValues | null, periodEnterable: boolean, isAdminInfo: boolean, + tabKey?: string | null, ): TabToolbarSnapshot { - const gugunOk = buildGugunOkForToolbar(searchContext); + const gugunOk = buildGugunOkForToolbar(searchContext, tabKey); const enterable = computeTabEnterable(statusInfo, periodEnterable); const isSubmitted = statusInfo?.lclgvSbmsnSttsCd === "2"; const showSaveInToolbar = (enterable || isAdminInfo) && periodEnterable && gugunOk; @@ -616,6 +649,8 @@ async function waitForImrJobCompleted( const SewageExcretaRelatedInp = () => { const { sidoList } = useSearchConditionSidoList({ isInput: true }); sidoListRef.current = sidoList; + const userId = useUserStore((state) => state.userInfo?.userId ?? ""); + relatedToolbarUserIdRef.current = userId; const { setMessage: alert } = useAlertStore((state) => state); const { confirm } = useConfirm(); const isAdminInfo = useAdminStore((state) => state.isAdminInfo); @@ -679,6 +714,8 @@ const SewageExcretaRelatedInp = () => { /** ST00120001·ST00120002 — 전년도(PRE) 조회로 로드된 ognzSn */ const preYearArticleOgnzSnByTabRef = useRef>(new Map()); const sggOptionsSidoRef = useRef(null); + const sggHeadOptionsRef = useRef([]); + const sggHeadOptionsSidoRef = useRef(null); activeTabRef.current = activeTab; const activeTabId = useTabStore((s) => s.activeTabId); @@ -747,6 +784,22 @@ const SewageExcretaRelatedInp = () => { } }, []); + const loadSggHeadOptions = useCallback(async (sido: string): Promise => { + if (!sido || sido === "ALL") { + sggHeadOptionsRef.current = []; + return []; + } + try { + const res = await statisticsApi.getSggAllHeadList(sido); + const list = parseSggListFromResponse(res); + sggHeadOptionsRef.current = list; + return list; + } catch { + sggHeadOptionsRef.current = []; + return []; + } + }, []); + const commitToolbarSnapshotForLoadedTab = ( tabKey: string, statusInfo: SewerageStatusInfo | null, @@ -764,6 +817,7 @@ const SewageExcretaRelatedInp = () => { searchContext, periodEnterableRef.current, isAdminInfo, + tabKey, ), ); return next; @@ -1071,6 +1125,8 @@ const SewageExcretaRelatedInp = () => { ); setSggOptions([]); sggOptionsSidoRef.current = null; + sggHeadOptionsRef.current = []; + sggHeadOptionsSidoRef.current = null; setVerificationHistoryOpen(false); }; @@ -1266,7 +1322,7 @@ const SewageExcretaRelatedInp = () => { alert("먼저 조회를 진행해주세요."); return; } - if (!buildGugunOkForToolbar(lastSearchedValues)) { + if (!buildGugunOkForToolbar(lastSearchedValues, tabKey)) { alert("시군구를 선택해주세요."); return; } @@ -1275,7 +1331,7 @@ const SewageExcretaRelatedInp = () => { const noApplicable = buildNoApplicableForRequest(searchContextByTab.get(tabKey) ?? lastSearchedValues, isNotApplicableByTab.get(tabKey) ?? false, getTabGridRows(tabKey).length === 0); const currentData = getTabGridRows(tabKey); if (NOT_APPLICABLE_TAB_KEYS.has(tabKey)) { - if (!noApplicable && currentData.length === 0 && buildSubmitOkForToolbar(searchContextByTab.get(tabKey) ?? lastSearchedValues)) { + if (!noApplicable && currentData.length === 0 && buildSubmitOkForToolbar(searchContextByTab.get(tabKey) ?? lastSearchedValues, tabKey)) { alert("해당사항 없음을 체크해주세요."); return; } @@ -1300,7 +1356,7 @@ const SewageExcretaRelatedInp = () => { alert("먼저 조회를 진행해주세요."); return; } - if (!buildGugunOkForToolbar(lastSearchedValues)) { + if (!buildGugunOkForToolbar(lastSearchedValues, tabKey)) { alert("시군구를 선택해주세요."); return; } @@ -1380,7 +1436,7 @@ const SewageExcretaRelatedInp = () => { ) .map((row) => buildPublicInstitutionIndustrySaveItem(row, list)); - if (!noApplicable && submitList.length === 0 && buildSubmitOkForToolbar(searchContextByTab.get(tabKey) ?? lastSearchedValues)) { + if (!noApplicable && submitList.length === 0 && buildSubmitOkForToolbar(searchContextByTab.get(tabKey) ?? lastSearchedValues, tabKey)) { alert("해당사항 없음을 체크해주세요."); return; } @@ -1558,7 +1614,7 @@ const SewageExcretaRelatedInp = () => { alert("먼저 조회를 진행해주세요."); return; } - if (!buildGugunOkForToolbar(lastSearchedValues)) { + if (!buildGugunOkForToolbar(lastSearchedValues, tabKey)) { alert("시군구를 선택해주세요."); return; } @@ -1662,7 +1718,7 @@ const SewageExcretaRelatedInp = () => { ) .map((row) => buildPublicInstitutionIndustrySaveItem(row, list)); - if (!noApplicable && saveList.length === 0 && buildSubmitOkForToolbar(searchContextByTab.get(tabKey) ?? lastSearchedValues)) { + if (!noApplicable && saveList.length === 0 && buildSubmitOkForToolbar(searchContextByTab.get(tabKey) ?? lastSearchedValues, tabKey)) { alert("해당사항 없음을 체크해주세요."); return; } @@ -1725,21 +1781,20 @@ const SewageExcretaRelatedInp = () => { alert("먼저 조회를 진행해주세요."); return; } - if (!buildGugunOkForToolbar(ctx)) { + const tabKey = activeTabRef.current; + if (!buildGugunOkForToolbar(ctx, tabKey)) { alert("시군구를 선택해주세요."); return; } - - const tabKey = activeTabRef.current; if (!ARTICLE_EDIT_TAB_KEYS.has(tabKey)) { alert("항목을 추가할 수 없는 탭입니다."); return; } - let list = sggOptions; - if (sggOptionsSidoRef.current !== ctx.sido || list.length === 0) { - list = await loadSggOptions(ctx.sido); - sggOptionsSidoRef.current = ctx.sido; + let list = sggHeadOptionsRef.current; + if (sggHeadOptionsSidoRef.current !== ctx.sido || list.length === 0) { + list = await loadSggHeadOptions(ctx.sido); + sggHeadOptionsSidoRef.current = ctx.sido; } if (list.length === 0) { alert("시군구 목록을 불러오지 못했습니다."); @@ -1807,7 +1862,7 @@ const SewageExcretaRelatedInp = () => { alert("먼저 조회를 진행해주세요."); return; } - if (!buildGugunOkForToolbar(ctx)) { + if (!buildGugunOkForToolbar(ctx, tabKey)) { alert("시군구를 선택해주세요."); return; } @@ -1941,6 +1996,7 @@ const SewageExcretaRelatedInp = () => { searchContextForToolbar, inputPeriodEnterable, isAdminInfo, + activeTab, ); const showSaveInToolbar = activeTabToolbar.showSaveInToolbar && toolbarGroupAllowed; @@ -1951,8 +2007,8 @@ const SewageExcretaRelatedInp = () => { (activeTabToolbar.showActionToolbarCard || (hasSearched && loadedTabKeys.has(activeTab))); const showArticleEditButtons = ARTICLE_EDIT_TAB_KEYS.has(activeTab) && showEnterableToolbarButtons; - const gugunOk = buildGugunOkForToolbar(searchContextForToolbar); - const submitOk = buildSubmitOkForToolbar(searchContextForToolbar); + const gugunOk = buildGugunOkForToolbar(searchContextForToolbar, activeTab); + const submitOk = buildSubmitOkForToolbar(searchContextForToolbar, activeTab); const showNotApplicableForActiveTab = NOT_APPLICABLE_TAB_KEYS.has(activeTab) && loadedTabKeys.has(activeTab) && diff --git a/apps/st/src/components/statistics/input/SewerageFinanceInp.tsx b/apps/st/src/components/statistics/input/SewerageFinanceInp.tsx index 5787a52c8..9083b505e 100644 --- a/apps/st/src/components/statistics/input/SewerageFinanceInp.tsx +++ b/apps/st/src/components/statistics/input/SewerageFinanceInp.tsx @@ -2,7 +2,7 @@ import { useEffect, useMemo, useRef, useState } from "react"; import { useConfirm } from "@frontend-opensource/use-react-hooks"; -import { useAlertStore, useGlobalProgressStore, useSearchConditionSidoList } from "@/shared/lib"; +import { useAlertStore, useGlobalProgressStore, useSearchConditionSidoList, useUserStore } 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 { statisticsInputSewSupplyRateApi } from "@/entities/statistics/api/input/statistics-input-sew-supply-rate-service"; @@ -41,6 +41,7 @@ import type { import { filterBySelectedAdmdstCd, isGugunOkForToolbar, + isJeonnamGwangjuSidoAllToolbarException, isSubmitOkForToolbar, toInputSearchRegion, } from "@/entities/statistics"; @@ -133,12 +134,31 @@ const computeTabEnterable = ( }; const sidoListRef: { current: Sido[] } = { current: [] }; +const financeToolbarUserIdRef: { current: string } = { current: "" }; function buildGugunOkForToolbar(values: SearchFormValues | null): boolean { + if ( + isJeonnamGwangjuSidoAllToolbarException( + sidoListRef.current, + values, + financeToolbarUserIdRef.current, + ) + ) { + return true; + } return isGugunOkForToolbar(sidoListRef.current, values); } function buildSubmitOkForToolbar(values: SearchFormValues | null): boolean { + if ( + isJeonnamGwangjuSidoAllToolbarException( + sidoListRef.current, + values, + financeToolbarUserIdRef.current, + ) + ) { + return true; + } return isSubmitOkForToolbar(sidoListRef.current, values); } @@ -356,6 +376,8 @@ async function waitForImrJobCompleted( const SewerageFinanceInp = () => { const { sidoList } = useSearchConditionSidoList({ isInput: true }); sidoListRef.current = sidoList; + const userId = useUserStore((state) => state.userInfo?.userId ?? ""); + financeToolbarUserIdRef.current = userId; const { setMessage: alert } = useAlertStore((state) => state); const { confirm } = useConfirm(); const { isAdminInfo } = useAdminStore(); diff --git a/apps/st/src/entities/statistics/api/statistics-service.ts b/apps/st/src/entities/statistics/api/statistics-service.ts index 314f5e026..58e0ecf65 100644 --- a/apps/st/src/entities/statistics/api/statistics-service.ts +++ b/apps/st/src/entities/statistics/api/statistics-service.ts @@ -102,6 +102,17 @@ export class StatisticsApiService implements StatisticsService { return response.data; } + public async getSggAllHeadList( + sidoName: string, + params?: { instSeCd?: string; gugunSkipYn?: "Y" | "N" }, + ): Promise> { + const response = await stClient.get>( + `${ENDPOINT.ST_SERVICE.COMMON}/sgg-all-head`, + { params: { sidoName, ...params } }, + ); + return response.data; + } + /** 통계 입력 기간(연도·분류별) 목록 조회 — 경로는 백엔드 스펙에 맞게 수정 */ public async getStatsInputPeriodList( params?: StatsInputPeriodListRequest, diff --git a/apps/st/src/entities/statistics/index.ts b/apps/st/src/entities/statistics/index.ts index 390dfb71c..047388249 100644 --- a/apps/st/src/entities/statistics/index.ts +++ b/apps/st/src/entities/statistics/index.ts @@ -10,6 +10,9 @@ export { dashboardApi } from "./api/dashboard/dashboard-service"; export { useScheduleInfo } from "./api/dashboard/schedule-info-queries"; export { scheduleInfoApi } from "./api/dashboard/schedule-info-service"; export { imrApi } from "./api/imr-api"; +export { + isJeonnamGwangjuSidoAllToolbarException, +} from "./lib/jeonnam-gwangju-sido-all-toolbar"; export { filterBySelectedAdmdstCd, findSidoBySearch, diff --git a/apps/st/src/entities/statistics/lib/jeonnam-gwangju-sido-all-toolbar.ts b/apps/st/src/entities/statistics/lib/jeonnam-gwangju-sido-all-toolbar.ts new file mode 100644 index 000000000..423827128 --- /dev/null +++ b/apps/st/src/entities/statistics/lib/jeonnam-gwangju-sido-all-toolbar.ts @@ -0,0 +1,35 @@ +import { findSidoBySearch, type SidoGugunLookup } from "./sido-gugun"; + +import type { Sido } from "../model/statistics-interface"; + +/** 전남광주통합특별시 — 도 목록에 있어 시군구 전체 조회 시 버튼이 숨겨짐 */ +export const JEONNAM_GWANGJU_UNIFIED_SIDO_CD = "1200000000"; + +export const SIDO_ALL_TOOLBAR_USER_IDS = new Set(["CLEANWATER", "S3291"]); + +function isEmptyOrAllGugun(values: SidoGugunLookup | null | undefined): boolean { + const gugun = values?.gugun?.trim() ?? ""; + return !gugun || gugun === "ALL"; +} + +function isJeonnamGwangjuUnifiedSido( + sidoList: readonly Sido[] | undefined, + values: SidoGugunLookup | null | undefined, +): boolean { + if (!values) return false; + const sido = findSidoBySearch(sidoList, values); + const cd = (sido?.bsnmCd ?? values.bsnmCd ?? "").trim(); + if (cd === JEONNAM_GWANGJU_UNIFIED_SIDO_CD) return true; + return (values.sido ?? "").trim() === "전남광주통합특별시"; +} + +export function isJeonnamGwangjuSidoAllToolbarException( + sidoList: readonly Sido[] | undefined, + values: SidoGugunLookup | null | undefined, + userId: string | null | undefined, +): boolean { + if (!SIDO_ALL_TOOLBAR_USER_IDS.has((userId ?? "").trim().toUpperCase())) { + return false; + } + return isJeonnamGwangjuUnifiedSido(sidoList, values) && isEmptyOrAllGugun(values); +} diff --git a/apps/st/src/entities/statistics/model/statistics-interface.ts b/apps/st/src/entities/statistics/model/statistics-interface.ts index e8aa204ec..6efa8d02d 100644 --- a/apps/st/src/entities/statistics/model/statistics-interface.ts +++ b/apps/st/src/entities/statistics/model/statistics-interface.ts @@ -562,6 +562,7 @@ export interface StatisticsService { getSidoListInput(params?: { instSeCd?: string }): Promise>; getSggList(sidoName: string, params?: { instSeCd?: string; gugunSkipYn?: "Y" | "N" }): Promise>; getSggAllList(sidoName: string, params?: { instSeCd?: string; gugunSkipYn?: "Y" | "N" }): Promise>; + getSggAllHeadList(sidoName: string, params?: { instSeCd?: string; gugunSkipYn?: "Y" | "N" }): Promise>; getStatsInputPeriodList(params?: StatsInputPeriodListRequest): Promise; getStatsInputPeriodDetail(param: StatsInputPeriodDetailRequest): Promise; saveStatsInputPeriod(param: StatsInputPeriodSaveRequest): Promise;