232 lines
7.3 KiB
TypeScript
232 lines
7.3 KiB
TypeScript
import type { TableUpperProps } from "@/app/store/common/type/header";
|
|
import { getFetch, getFetchWithCount, postFectch, putFectch } from "@/components/lib/api";
|
|
import { z } from "zod";
|
|
import { makeMdfr, makeRstr } from "../bdstReg";
|
|
import toast from "react-hot-toast";
|
|
import { baseReuseBuildingSchema, chgBuildingSchema, validationMessages } from "./type";
|
|
|
|
export const TEST_UUID= '2d4b151d-1828-41e0-91d9-4cd28ea1cc7e'
|
|
|
|
const rainyObjSchema = z.object({
|
|
bdstReuseFcltFk: z.number().nullish(),
|
|
pntfColKnd: z.string().min(1, { message: validationMessages.requiredSelect("종류") }),
|
|
pntfColArea: z.number().nullish() ,
|
|
dtfcltCpct: z.number().default(0),
|
|
filtrTrtmfctYn: z.string().default("Y"),
|
|
filtrTrtmfctCpct: z.number().nullish().default(0),
|
|
filtrTrtmfctPrs: z.string().default(""),
|
|
annRnwtQty: z.number().default(0),
|
|
oilqMeasMthd: z.string().default("").nullish(),
|
|
rgtr:z.string().nullish(),
|
|
mdfr:z.string().nullish(),
|
|
});
|
|
|
|
|
|
const rainBuildingSchema = baseReuseBuildingSchema.extend({
|
|
rainyObj: rainyObjSchema,
|
|
})
|
|
|
|
export const rainZod = z.object({
|
|
bdstInfoPk: z.number().optional(),
|
|
ctpvCd: z.number().default(0),
|
|
sggCd: z.number().default(0),
|
|
daddr: z.string().default(""),
|
|
bdstNm: z.string().default(""),
|
|
frstArchPrmsnDt: z.date().default(() => new Date()),
|
|
archChgPrmsnDt: z.coerce.date().nullish().default(null),
|
|
archArea: z.string().default(''),
|
|
archChgArea: z.number().default(0),
|
|
rgtr:z.string().nullish(),
|
|
mdfr:z.string().nullish(),
|
|
reuseBuilding: z.array(rainBuildingSchema).default([]),
|
|
chgBuilding: z.array(chgBuildingSchema).default([])
|
|
})
|
|
|
|
export type chgBuilding={
|
|
bdstInfoFk?: number|null,
|
|
archChgPrmsnDt?: Date,
|
|
archChgArea?: string,
|
|
bdstChgNm?: string
|
|
rgtr?:string|null;
|
|
mdfr?:string|null;
|
|
}
|
|
export type customRainBdst = z.infer<typeof rainZod>
|
|
|
|
export const upHeadList: TableUpperProps[] = [
|
|
{ id: "cityText", title: "시도" },
|
|
{ id: "sggText", title: "시군구" },
|
|
{ id: "bdstNm", title: "시설명" },
|
|
{ id: "daddr", title: "위치" },
|
|
{ id: "bdsgUsgText", title: "건축물용도" },
|
|
{ id: "frstArchPrmsnDt", title: "최초건축허가일" },
|
|
{ id: "archArea", title: "건축면적" },
|
|
{ id: "lawTrgtYn", title: "법적의무대상여부" },
|
|
{ id: "bdstChgYn", title: "건축물변경여부" },
|
|
];
|
|
|
|
const rainRes: customRainBdst[] = [];
|
|
|
|
|
|
export const selectClass = "w-full h-full !text-xl";
|
|
|
|
export type rainFacState = {
|
|
rain: {
|
|
isInit: boolean;
|
|
upHeadList: TableUpperProps[];
|
|
rainRes: customRainBdst[];
|
|
};
|
|
};
|
|
type rainFacSActions = {
|
|
initRain: (code:string|number) => void;
|
|
getRainData:(pageNation:number, code:string|number) =>void;
|
|
rainSearch: (txt:string,pageNation:number,code:string|number) => void;
|
|
rainBdstReg: (data: customRainBdst, code:string|number) => void;
|
|
rainBdstUpdate: (data: customRainBdst, code:string|number) => void;
|
|
};
|
|
|
|
export type rainFacType = rainFacState & rainFacSActions;
|
|
|
|
export const rainFacStateExport: rainFacState = {
|
|
rain: {
|
|
isInit: false,
|
|
rainRes: rainRes,
|
|
upHeadList: upHeadList,
|
|
},
|
|
};
|
|
|
|
const initFetch = async (code:string|number) => {
|
|
// const rainRes =await getFetch("wr", `/reuseFc/rainyInfoList/1/10/${code}`);
|
|
const rainRes =await getFetchWithCount("wr", `/reuseFc/rainyInfoList/1/10/${code}`);
|
|
console.log("데이터", rainRes)
|
|
return rainRes;
|
|
};
|
|
export const rainFacActionsExport: (set: any) => rainFacSActions = (
|
|
set: any
|
|
) => {
|
|
return {
|
|
getRainData: async(pageNation:number, code:string|number) =>{
|
|
try{
|
|
const rainRes =await getFetch("wr", `/reuseFc/rainyInfoList/${pageNation}/10/${code}`);
|
|
|
|
|
|
// 여기서 상태 업데이트
|
|
return set((state: rainFacState) => ({
|
|
...state,
|
|
rain: {
|
|
...state.rain,
|
|
rainRes: rainRes,
|
|
isInit: false,
|
|
},
|
|
}));
|
|
|
|
}catch(e){
|
|
console.log(e)
|
|
|
|
}
|
|
},
|
|
|
|
initRain: async (code:string|number) => {
|
|
try {
|
|
// 파라이터 수정 통합관리자 =0, 시관리자=시코드, 시군구 관리자= 시군구 코드 를 세번째 파라미터로 지정 / 건축물 서치가 있을경우 4번째 파라미터로 던지기 즉 1/20/42(서울시)/영현빌딩 이런식으로)
|
|
const rainRes = await initFetch(code);
|
|
// 여기서 상태 업데이트
|
|
return set((state: rainFacState) => ({
|
|
...state,
|
|
rain: {
|
|
...state.rain,
|
|
rainRes: rainRes.data,
|
|
isInit: false,
|
|
},
|
|
}));
|
|
} catch (error) {
|
|
console.log("error", error);
|
|
}
|
|
},
|
|
rainSearch: async(txt:string,pageNation:number) =>{
|
|
try{
|
|
|
|
// const rainRes = await getFetch('wr' , `/reuseFc/rainyInfoList/${pageNation}/20/41` +(txt? `/${txt}`:''))
|
|
const rainRes = await getFetchWithCount('wr' , `/reuseFc/rainyInfoList/${pageNation}/20/41` +(txt? `/${txt}`:''))
|
|
console.log("rainRes", rainRes)
|
|
set((state: rainFacState) => {
|
|
return {
|
|
rain: {
|
|
...state.rain,
|
|
rainRes: rainRes,
|
|
isInit: false,
|
|
},
|
|
};
|
|
})}
|
|
catch(erTxt){
|
|
console.log("error", erTxt)
|
|
}
|
|
},
|
|
rainBdstReg: async (data: customRainBdst,code:string|number) => {
|
|
try {
|
|
|
|
const test =await makeRstr(data);
|
|
const res = await postFectch("/reuseFc/rainyInfo", test);
|
|
if(res.status===200){
|
|
if(data.chgBuilding.length > 0){
|
|
|
|
const chPK = res?.data?.bdstInfoPk
|
|
const makeCh= res.data.chgBuilding.map((item: chgBuilding) =>
|
|
( {
|
|
...item,
|
|
bdstInfoFk: chPK,
|
|
})
|
|
);
|
|
const chch= await postFectch("/reuseFc/chgBuilding", makeCh);
|
|
|
|
if(chch.status ===200) {
|
|
toast.success("건축물 등록이 완료되었습니다.");
|
|
}else{
|
|
toast.error("건축물 증축/개축/중축 오류입니다.");
|
|
}
|
|
}else{
|
|
toast.success("건축물 등록이 완료되었습니다.");
|
|
}
|
|
}else{
|
|
toast.error("건축물 등록이 완료되었습니다.");
|
|
}
|
|
const rainRes = await initFetch(code);
|
|
set((state: rainFacState) => ({
|
|
...state,
|
|
rain: {
|
|
...state.rain,
|
|
rainRes: rainRes,
|
|
isInit: false,
|
|
},
|
|
}));
|
|
} catch (e) {
|
|
console.log("e", e);
|
|
toast.error("등록시 오류가 발생하였습니다.");
|
|
} finally {
|
|
}
|
|
},
|
|
rainBdstUpdate: async (data: customRainBdst,code:string|number) => {
|
|
try {
|
|
const chData =await makeMdfr(data);
|
|
const res = await putFectch("/reuseFc/rainyInfo", chData);
|
|
if(res.status === 200){
|
|
toast.success("수정이 완료되었습니다.");
|
|
|
|
}
|
|
const rainRes = await initFetch(code);
|
|
set((state: rainFacState) => ({
|
|
...state,
|
|
rain: {
|
|
...state.rain,
|
|
rainRes: rainRes,
|
|
isInit: false,
|
|
},
|
|
}));
|
|
} catch (e) {
|
|
console.log("e", e);
|
|
toast.error("수정시 오류가 발생하였습니다.");
|
|
} finally {
|
|
}
|
|
}
|
|
}}
|
|
|