/** * ๐Ÿ“„ Store Index * Zustand ์Šคํ† ์–ด ์ธ๋ฑ์Šค ํŒŒ์ผ * * - ์‹œ๋„ ๋ฐ์ดํ„ฐ ์กฐํšŒ ๋ฐ ์ปค์Šคํ…€ ์ •๋ ฌ ๊ธฐ๋Šฅ * - ์‹œ๊ตฐ๊ตฌ ๋ฐ์ดํ„ฐ ์กฐํšŒ ๋ฐ ์•ŒํŒŒ๋ฒณ ์ •๋ ฌ ๊ธฐ๋Šฅ * - ์‚ฌ์—… ๊ตฌ๋ถ„ ์ฝ”๋“œ ์กฐํšŒ ๋ฐ ์ƒํƒœ ๊ด€๋ฆฌ * - ์‚ฌ์—… ์œ ํ˜• ์ฝ”๋“œ ์กฐํšŒ ๋ฐ ํ•„ํ„ฐ๋ง ๊ธฐ๋Šฅ * - GeoServer WFS๋ฅผ ํ†ตํ•œ ์ง€๋ฆฌ ๋ฐ์ดํ„ฐ ๊ฐ€์ ธ์˜ค๊ธฐ * - CMS ์„œ๋น„์Šค๋ฅผ ํ†ตํ•œ ์ฝ”๋“œ ๋ฐ์ดํ„ฐ ๊ฐ€์ ธ์˜ค๊ธฐ * * ๐Ÿ”— ์‚ฌ์šฉ API * - ์‹œ๋„ ๋ฐ์ดํ„ฐ ์กฐํšŒ: GET /geoserver/hasudo/ows (GeoServer) * - ์‹œ๊ตฐ๊ตฌ ๋ฐ์ดํ„ฐ ์กฐํšŒ: GET /geoserver/hasudo/ows (GeoServer) * - ์‚ฌ์—… ๊ตฌ๋ถ„ ์ฝ”๋“œ ์กฐํšŒ: GET /api/v1/code/cache/BIZSECD (cms-service) * - ์‚ฌ์—… ์œ ํ˜• ์ฝ”๋“œ ์กฐํšŒ: GET /api/v1/code/cache/BIZTYCD (cms-service) */ import { getCmsData } from "@/components/lib/api"; export type BIZ_CD_TYPE = { lwpoCd: string, upCd: string, lwpoCdNm: string, unit: string, prntLwpoCd: null }; // ์‹œ๋„ ๋ฐ์ดํ„ฐ ์กฐํšŒ export const fetchCtpv = async (set: (state: any) => void) => { const url = `/geoserver/hasudo/ows?service=WFS&version=1.0.0&request=GetFeature&typeName=hasudo:tb_ms_ctpv&outputFormat=application/json&propertyName=mctpv_korn_nm,mctpv_cd`; const res = await fetch(url).then(res => res.json()); const list = res.features .map((f: any) => ({ text: f.properties.mctpv_korn_nm, val: f.properties.mctpv_cd, })) .sort((a:any, b:any) => { // ์ปค์Šคํ…€ ์ˆœ์„œ ์ •์˜ const customOrder = [ "์„œ์šธํŠน๋ณ„์‹œ", "๋ถ€์‚ฐ๊ด‘์—ญ์‹œ", "๋Œ€๊ตฌ๊ด‘์—ญ์‹œ", "์ธ์ฒœ๊ด‘์—ญ์‹œ", "๊ด‘์ฃผ๊ด‘์—ญ์‹œ", "๋Œ€์ „๊ด‘์—ญ์‹œ", "์šธ์‚ฐ๊ด‘์—ญ์‹œ", "์„ธ์ข…ํŠน๋ณ„์ž์น˜์‹œ", "๊ฒฝ๊ธฐ๋„", "๊ฐ•์›ํŠน๋ณ„์ž์น˜๋„", // ๊ฒฝ๊ธฐ๋„ ๋‹ค์Œ์— ๋ฐฐ์น˜ "์ถฉ์ฒญ๋ถ๋„", "์ถฉ์ฒญ๋‚จ๋„", "์ „๋ถํŠน๋ณ„์ž์น˜๋„", // ์ถฉ์ฒญ๋‚จ๋„ ๋‹ค์Œ์— ๋ฐฐ์น˜ "์ „๋ผ๋‚จ๋„", "๊ฒฝ์ƒ๋ถ๋„", "๊ฒฝ์ƒ๋‚จ๋„", "์ œ์ฃผํŠน๋ณ„์ž์น˜๋„" ]; const indexA = customOrder.indexOf(a.text); const indexB = customOrder.indexOf(b.text); // ๋‘˜ ๋‹ค ์ปค์Šคํ…€ ์ˆœ์„œ์— ์žˆ์œผ๋ฉด ํ•ด๋‹น ์ˆœ์„œ๋กœ if (indexA !== -1 && indexB !== -1) { return indexA - indexB; } // ํ•˜๋‚˜๋งŒ ์ปค์Šคํ…€ ์ˆœ์„œ์— ์žˆ์œผ๋ฉด ๊ทธ๊ฒƒ์„ ์•ž์œผ๋กœ if (indexA !== -1) return -1; if (indexB !== -1) return 1; // ๋‘˜ ๋‹ค ์ปค์Šคํ…€ ์ˆœ์„œ์— ์—†์œผ๋ฉด ๊ธฐ๋ณธ ์•ŒํŒŒ๋ฒณ ์ˆœ์„œ return a.text.localeCompare(b.text, 'ko'); }); set({ ctpv: list }); }; // ์‹œ๊ตฐ๊ตฌ ๋ฐ์ดํ„ฐ ์กฐํšŒ export const fetchSgg = async (set: (state: any) => void) => { const url = `/geoserver/hasudo/ows?service=WFS&version=1.0.0&request=GetFeature&typeName=hasudo:tb_ms_sgg&outputFormat=application/json&propertyName=sgg_cd,sgg_korn_nm`; const res = await fetch(url).then(res => res.json()); const list = res.features .map((f: any) => ({ text: f.properties.sgg_korn_nm, val: f.properties.sgg_cd, })) .sort((a:any, b:any) => a.text.localeCompare(b.text, 'ko')); set({ sgg: list }); }; export const fetchBIZ_SE_CD = async (set: (state: any) => void) => { try { const res = await getCmsData(`/api/v1/code/cache/BIZSECD`); set({ BIZ_SE_CD: res }); } catch (e: any) { // alert("BIZ_SE_CD ๋ฐ์ดํ„ฐ ๋กœ๋“œ ์‹คํŒจ: " + e.message); console.error("BIZ_SE_CD ๋ฐ์ดํ„ฐ ๋กœ๋“œ ์‹คํŒจ:", e); } }; export const fetchBIZ_TY_CD = async (set: (state: any) => void) => { try { const res = await getCmsData(`/api/v1/code/cache/BIZTYCD`); const filtered: BIZ_CD_TYPE[] = Array.isArray(res) ? (res as BIZ_CD_TYPE[]).filter(item => item?.lwpoCd !== "AQAAA") : []; set({ BIZ_TY_CD: filtered }); } catch (e: any) { // alert("BIZ_TY_CD ๋ฐ์ดํ„ฐ ๋กœ๋“œ ์‹คํŒจ: " + e.message); console.error("BIZ_TY_CD ๋ฐ์ดํ„ฐ ๋กœ๋“œ ์‹คํŒจ:", e); } };