316 lines
9.3 KiB
TypeScript
316 lines
9.3 KiB
TypeScript
import { fetchType, getFetch, getFetchWithCount } from "@/components/lib/api";
|
|
import type {
|
|
EnvPartSelectDataType,
|
|
SelectDataType,
|
|
} from "@common/business_components/ui";
|
|
import {
|
|
bdstFilterYn,
|
|
bdstIncenYn,
|
|
chBuCd,
|
|
ruseBizMthdCd,
|
|
ruseSeCd,
|
|
yn,
|
|
} from "./basicCode";
|
|
export const btnClass = "p-4 m-2 text-white rounded-sm text-lg font-medium ";
|
|
|
|
const laeSecd = "41";
|
|
export const lwCds: Record<string, SelectDataType[]> = {};
|
|
|
|
const codeMApping = {
|
|
WR001: "bdstUsgCd",
|
|
WR002: "rswtBdstType",
|
|
WR003: "rainFcltCd",
|
|
WR004: "bdstGrntchClass",
|
|
WR005: "rswtPrscCdMthdCd", // 아직 디 못바꿈
|
|
WR006: "orgwtKndCd", //작업 완ㅛ
|
|
WR007: "ruseMngMtd", // 작업완료
|
|
WR008: "rusePrcsMthdCd", //w작업완료
|
|
WR009: "erctUswtrPrcsMeth", //w작업완료
|
|
WR010: "ruseFcltSpot", // inout은 yn 만 사용해야 함으로 해당 코드는 사용안함.
|
|
WR011: "pplQulity",
|
|
WR012: "pplLenght",
|
|
WR013: "bdstFilterYn", // 사용 불가 yn만 사용해야함으로 해당코드 사용 안함
|
|
WR014: "rainRswtMng", // 지도점검 등록 시변경
|
|
WR015: "rainFcltFlowRate", //지도점검 등록 시변경
|
|
WR016: "dmdUszCd", // 지도점검 등록 시변경
|
|
WR017: "sewageInFcltUse", //하수재이용 장내
|
|
WR018: "sewageOutFclttUse", // 하수재이용 장외
|
|
WR019: "htdPowerMthdCd",
|
|
WR020: "htdUtztnUsgCd",
|
|
};
|
|
export const getCommonUpCd = async (set: any) => {
|
|
try {
|
|
let lwCdCode: Record<string, SelectDataType[]> = {};
|
|
const upCd = await getFetchWithCount(
|
|
fetchType.LOCAL,
|
|
"/cms-service/api/v1/up-codes?keyword=&upCd=&cdSe=&useYn=Y&siteId=WR&page=0&size=100&sort=string"
|
|
);
|
|
|
|
const upWrCode: string[] = upCd.content
|
|
.filter((item: any) => item.upCd.slice(0, 2) === "WR")
|
|
.map((cd: any) => cd.upCd);
|
|
|
|
await Promise.all(
|
|
upWrCode.map(async (cd) => {
|
|
const mapping = codeMApping[cd as keyof typeof codeMApping];
|
|
if (!mapping) return;
|
|
|
|
const lwCd = await getFetchWithCount(
|
|
fetchType.LOCAL,
|
|
`/cms-service/api/v1/lwpo-cds/up-cd/${cd}`
|
|
);
|
|
|
|
const list = Array.isArray(lwCd) ? lwCd : (lwCd.content ?? []);
|
|
lwCds[mapping] = list.map((it: any) => ({
|
|
text: it.lwpoCdNm,
|
|
val: it.lwpoCd,
|
|
}));
|
|
})
|
|
);
|
|
lwCdCode = lwCds;
|
|
set((state: comCodeState) => ({
|
|
code: {
|
|
...state.code,
|
|
rainFcltCd: lwCdCode["rainFcltCd"] ?? [],
|
|
bdstUsgCd: lwCdCode["bdstUsgCd"] ?? [],
|
|
orgwtKndCd: lwCdCode["orgwtKndCd"] ?? [],
|
|
pplQulity: lwCdCode["pplQulity"] ?? [],
|
|
pplLenght: lwCdCode["pplLenght"] ?? [],
|
|
dmdUszCd: lwCdCode["dmdUszCd"] ?? [],
|
|
ruseMngMtd: lwCdCode["ruseMngMtd"] ?? [],
|
|
rusePrcsMthdCd: lwCdCode["rusePrcsMthdCd"] ?? [],
|
|
erctUswtrPrcsMeth: lwCdCode["erctUswtrPrcsMeth"] ?? [],
|
|
bdstGrntchClass: lwCdCode["bdstGrntchClass"] ?? [],
|
|
htdPowerMthdCd: lwCdCode["htdPowerMthdCd"] ?? [],
|
|
htdUtztnUsgCd: lwCdCode["htdUtztnUsgCd"] ?? [],
|
|
rswtBdstType: lwCdCode["rswtBdstType"] ?? [],
|
|
bdstTotalUsgType:
|
|
lwCdCode["bdstUsgCd"]?.concat(lwCdCode["rswtBdstType"] || []) ?? [],
|
|
},
|
|
}));
|
|
} catch (e) {
|
|
console.log("com code error ", e);
|
|
}
|
|
};
|
|
//물재이용 주소 코드: devU01TX0FVVEgyMDI1MDgyNTEwMzkwNDExNjEwNTM=
|
|
export const buildingType = {
|
|
RST: "RST",
|
|
RNB: "RNB",
|
|
HTB: "HTB",
|
|
};
|
|
export const getSggCd = async (set: any) => {
|
|
const sgg = await getFetch("common", "/addr/sgg");
|
|
/* const sggCd = sgg.map((item: any) => ({
|
|
val: item.adstDstrCd,
|
|
text: item.gugun,
|
|
})); */
|
|
|
|
const sggCd = [
|
|
// { text: "전체", val: '0' },
|
|
...sgg.map((item: any) => ({
|
|
text: item.gugun || "",
|
|
val: String(item.adstDstrCd) || "",
|
|
})),
|
|
];
|
|
|
|
set((state: comCodeState) => ({
|
|
code: {
|
|
...state.code,
|
|
sggCd: sggCd,
|
|
},
|
|
}));
|
|
};
|
|
export const getCityCd = async (set: any) => {
|
|
const city = await getFetch("common", "/addr/city");
|
|
const cityCd = city.map((item: any) => ({
|
|
val: item.adstDstrCd,
|
|
text: item.sido,
|
|
}));
|
|
cityCd.unshift({ val: "0", text: "전체" });
|
|
set((state: comCodeState) => ({
|
|
code: {
|
|
...state.code,
|
|
cityCd: cityCd,
|
|
},
|
|
}));
|
|
};
|
|
|
|
// 권역 API 호출 함수 추가
|
|
export const getRegionCd = async (set: any) => {
|
|
try {
|
|
const rvbsn = await getFetch("common", "/addr/sarea");
|
|
const rvbsnCd = rvbsn.map((item: any) => ({
|
|
val: item.rvbsnCd,
|
|
text: item.rvbsn,
|
|
}));
|
|
rvbsnCd.unshift({ val: "0", text: "전체" });
|
|
set((state: comCodeState) => ({
|
|
code: {
|
|
...state.code,
|
|
rvbsnCd: rvbsnCd,
|
|
},
|
|
}));
|
|
} catch (error) {
|
|
console.error("권역 데이터를 가져오는데 실패했습니다:", error);
|
|
}
|
|
};
|
|
|
|
// 중권역 API 호출 함수 추가
|
|
export const getMiddleRegionCd = async (set: any) => {
|
|
try {
|
|
const mdmbsn = await getFetch("common", "/addr/midArea");
|
|
const mdmbsnCd = mdmbsn.map((item: any) => ({
|
|
val: item.rvbsnCd,
|
|
text: item.mdmbsn,
|
|
}));
|
|
mdmbsnCd.unshift({ val: "0", text: "전체" });
|
|
set((state: comCodeState) => ({
|
|
code: {
|
|
...state.code,
|
|
mdmbsnCd: mdmbsnCd,
|
|
},
|
|
}));
|
|
} catch (error) {
|
|
console.error("중권역 데이터를 가져오는데 실패했습니다:", error);
|
|
}
|
|
};
|
|
|
|
// 단위유역 API 호출 함수 추가
|
|
export const getUnitWaterShedCd = async (set: any) => {
|
|
try {
|
|
const lgbsn = await getFetch("common", "/addr/largeArea");
|
|
const lgbsnCd = lgbsn.map((item: any) => ({
|
|
val: item.rvbsnCd,
|
|
text: item.lgbsn,
|
|
}));
|
|
lgbsnCd.unshift({ val: "0", text: "전체" });
|
|
set((state: comCodeState) => ({
|
|
code: {
|
|
...state.code,
|
|
lgbsnCd: lgbsnCd,
|
|
},
|
|
}));
|
|
} catch (error) {
|
|
console.error("대영역 데이터를 가져오는데 실패했습니다:", error);
|
|
}
|
|
};
|
|
|
|
// 환경청 데이터
|
|
export const getEnvPartCd = async (set: any) => {
|
|
try {
|
|
const lclgvrnmnt = await getFetch("common", "/addr/govArea");
|
|
const lclgvrnmntCd = lclgvrnmnt.map((item: any) => ({
|
|
val: item.lclgvrnmntCd,
|
|
text: item.lclgvrnmntNm,
|
|
adstDliStrCd: item.adstDliStrCd || "",
|
|
}));
|
|
lclgvrnmntCd.unshift({ val: "0", text: "전체", adstDliStrCd: "" });
|
|
set((state: comCodeState) => ({
|
|
code: {
|
|
...state.code,
|
|
lclgvrnmntCd: lclgvrnmntCd,
|
|
},
|
|
}));
|
|
} catch (error) {
|
|
console.error("환경청 데이터를 가져오는데 실패했습니다:", error);
|
|
}
|
|
};
|
|
|
|
export type comCodeState = {
|
|
code: {
|
|
isInit: boolean;
|
|
chBuCd: SelectDataType[];
|
|
rainFcltCd: SelectDataType[];
|
|
bdstUsgCd: SelectDataType[];
|
|
cityCd: SelectDataType[];
|
|
sggCd: SelectDataType[];
|
|
rvbsnCd: SelectDataType[];
|
|
mdmbsnCd: SelectDataType[];
|
|
lgbsnCd: SelectDataType[];
|
|
lclgvrnmntCd: EnvPartSelectDataType[];
|
|
orgwtKndCd: SelectDataType[];
|
|
yn: SelectDataType[];
|
|
pplQulity: SelectDataType[];
|
|
pplLenght: SelectDataType[];
|
|
dmdUszCd: SelectDataType[];
|
|
buildingType: {
|
|
RST: string;
|
|
RNB: string;
|
|
HTB: string;
|
|
};
|
|
ruseMngMtd: SelectDataType[];
|
|
ruseSeCd: SelectDataType[];
|
|
ruseBizMthdCd: SelectDataType[];
|
|
rusePrcsMthdCd: SelectDataType[];
|
|
erctUswtrPrcsMeth: SelectDataType[];
|
|
bdstFilterYn: SelectDataType[];
|
|
bdstIncenYn: SelectDataType[];
|
|
bdstGrntchClass: SelectDataType[];
|
|
// rswtPrscCdMthdCd: SelectDataType[];
|
|
htdPowerMthdCd: SelectDataType[];
|
|
htdUtztnUsgCd: SelectDataType[];
|
|
rswtBdstType: SelectDataType[];
|
|
bdstTotalUsgType: SelectDataType[];
|
|
userSiSggCd: string;
|
|
};
|
|
};
|
|
|
|
export type comCodeType = comCodeState & comCodeActions;
|
|
|
|
export const comCodeStateExport: comCodeState = {
|
|
code: {
|
|
isInit: false,
|
|
rainFcltCd: lwCds["rainFcltCd"] ?? [],
|
|
bdstUsgCd: lwCds["bdstUsgCd"] ?? [],
|
|
chBuCd: chBuCd,
|
|
orgwtKndCd: lwCds["orgwtKndCd"] ?? [],
|
|
cityCd: [],
|
|
sggCd: [],
|
|
rvbsnCd: [],
|
|
mdmbsnCd: [],
|
|
lgbsnCd: [],
|
|
lclgvrnmntCd: [],
|
|
pplQulity: lwCds["pplQulity"] ?? [],
|
|
pplLenght: lwCds["pplLenght"] ?? [],
|
|
yn: yn,
|
|
dmdUszCd: lwCds["dmdUszCd"] ?? [],
|
|
buildingType: buildingType,
|
|
ruseMngMtd: lwCds["ruseMngMtd"] ?? [],
|
|
ruseSeCd: ruseSeCd,
|
|
ruseBizMthdCd: ruseBizMthdCd,
|
|
rusePrcsMthdCd: lwCds["rusePrcsMthdCd"] ?? [],
|
|
erctUswtrPrcsMeth: lwCds["erctUswtrPrcsMeth"] ?? [],
|
|
bdstFilterYn: bdstFilterYn,
|
|
bdstIncenYn: bdstIncenYn,
|
|
bdstGrntchClass: lwCds["bdstGrntchClass"] ?? [],
|
|
// rswtPrscCdMthdCd: rswtPrscCdMthdCd, // 공단연락오면 바꿔야함
|
|
htdPowerMthdCd: lwCds["htdPowerMthdCd"] ?? [],
|
|
htdUtztnUsgCd: lwCds["htdUtztnUsgCd"] ?? [],
|
|
userSiSggCd: laeSecd,
|
|
rswtBdstType: lwCds["rswtBdstType"] ?? [],
|
|
bdstTotalUsgType: lwCds["bdstTotalUsgType"] ?? [],
|
|
},
|
|
};
|
|
|
|
export type comCodeActions = {
|
|
returnCodeText: (val: string, codeName: string) => string;
|
|
returnTextCode: (text: string, codeName: string) => string;
|
|
};
|
|
|
|
export const codeActionExport: (set: any, get:any) => comCodeActions = (set: any, get:any) => {
|
|
return {
|
|
returnCodeText: (val: string, codeName: string) => {
|
|
|
|
const codeList = get().code[codeName] || [];
|
|
const found = codeList.find((item) => item.val === val);
|
|
|
|
return found ? found.text : val;
|
|
},
|
|
returnTextCode: (text: string, codeName: string) => {
|
|
const codeList = get().code[codeName] || [];
|
|
const found = codeList.find((item) => item.text === text);
|
|
return found ? found.val : text;
|
|
},
|
|
};
|
|
};
|