하수재이용 실적 등록 테스트 완료
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
"use client";
|
||||
import { useWrStore } from "@/app/store";
|
||||
import type { FcPrfType } from "@/app/store/prfmncReg/pbnstPrfmncReg/type";
|
||||
import type { pubHasuType } from "@/app/store/ruseFcltMng/fcltReg/pbnstReg/type";
|
||||
import { excelDownload, yearOptions } from "@/components/lib/func/commom";
|
||||
import PbnPrfExcelModal from "@/components/ui/modal/chkgd/pbnPrfExcelModal/pbnPrfExcelModal";
|
||||
@@ -22,38 +23,42 @@ import { set } from "react-hook-form";
|
||||
import { Toaster } from "react-hot-toast";
|
||||
|
||||
export default function prfmncPrfmncReg() {
|
||||
const { code, prfmnc, prfmncHasuInit, } = useWrStore(
|
||||
(state) => state
|
||||
);
|
||||
const { code, prfmnc, prfmncHasuInit } = useWrStore((state) => state);
|
||||
const { pbnstPrfmncHeadList, monthHeadList, prfmncRes } = prfmnc;
|
||||
const [bdstTable, setbdstTable] = useState<pubHasuType[]>();
|
||||
const [bdstTable, setbdstTable] = useState<FcPrfType[]>();
|
||||
const [searchTxt, setSearchTxt] = useState<string>();
|
||||
const [isExcelOpen, setIsExcelOPen] = useState<boolean>(false);
|
||||
const [isExcelOpen, setIsExcelOPen] = useState<{isModal:boolean, data:FcPrfType}>({isModal:false, data:{} as FcPrfType });
|
||||
|
||||
const [searchYear, setSearchYear] = useState<string>(
|
||||
String(new Date().getFullYear())
|
||||
);
|
||||
const excelClick = useCallback(() => {
|
||||
excelDownload(
|
||||
[[]],
|
||||
"하수재이용실적",
|
||||
"sample_pbnstPrfmncReg.xlsx",
|
||||
"A1:O1"
|
||||
);
|
||||
}, [prfmnc.excelList]);
|
||||
|
||||
|
||||
const excelClick = useCallback(() => {
|
||||
console.log("dd")
|
||||
excelDownload(
|
||||
[[]],
|
||||
"하수재이용실적",
|
||||
"sample_pbnstPrfmncReg.xlsx",
|
||||
"A1:O1"
|
||||
);
|
||||
}, [prfmnc.excelList])
|
||||
|
||||
useEffect(() => {
|
||||
if (!prfmnc.isInit) {
|
||||
prfmncHasuInit("1", "11");
|
||||
}
|
||||
}, [prfmnc.isInit, prfmncHasuInit]);
|
||||
useEffect(() => {
|
||||
setbdstTable(prfmncRes)
|
||||
console.log("prfmnc.prfmncRes", prfmncRes)
|
||||
}, [prfmncRes]);
|
||||
|
||||
const cellClick = useCallback((index:number|undefined, headId:string) => {
|
||||
|
||||
if(index !== undefined)
|
||||
setIsExcelOPen({isModal:false, data:prfmncRes[index] || {} as FcPrfType})
|
||||
|
||||
}, [prfmncRes]);
|
||||
|
||||
useEffect(() => {
|
||||
if (!prfmnc.isInit) {
|
||||
prfmncHasuInit("1", "11");
|
||||
}
|
||||
}, [prfmnc.isInit, prfmncHasuInit]);
|
||||
useEffect(() => {
|
||||
setbdstTable(prfmncRes);
|
||||
}, [prfmncRes]);
|
||||
|
||||
return (
|
||||
<>
|
||||
@@ -101,7 +106,12 @@ export default function prfmncPrfmncReg() {
|
||||
<Button size={"sm"} onClick={() => {}}>
|
||||
저장
|
||||
</Button>
|
||||
<Button size={"sm"} onClick={() => {setIsExcelOPen(true)}}>
|
||||
<Button
|
||||
size={"sm"}
|
||||
onClick={() => {
|
||||
setIsExcelOPen( { ...isExcelOpen, isModal:true } );
|
||||
}}
|
||||
>
|
||||
파일등록
|
||||
</Button>
|
||||
<Button color="green" size={"sm"} onClick={excelClick}>
|
||||
@@ -124,7 +134,7 @@ export default function prfmncPrfmncReg() {
|
||||
pageSize={100}
|
||||
total={10}
|
||||
headName={"하수재이용시설 목록"}
|
||||
cellClick={() => {}}
|
||||
cellClick={(index:number|undefined, headId:string) => {cellClick(index,headId)}}
|
||||
onPageChange={(page: number) => {}}
|
||||
children={undefined}
|
||||
/>
|
||||
@@ -147,9 +157,15 @@ export default function prfmncPrfmncReg() {
|
||||
</ListDiv>
|
||||
</div>
|
||||
</ContentsDiv>
|
||||
<UiModal bodyClass={""} body={<PbnPrfExcelModal></PbnPrfExcelModal>} open={isExcelOpen} onOpenChange={() => {setIsExcelOPen(!isExcelOpen)}}></UiModal>
|
||||
<UiModal
|
||||
bodyClass={""}
|
||||
body={<PbnPrfExcelModal data={isExcelOpen.data}></PbnPrfExcelModal>}
|
||||
open={isExcelOpen.isModal}
|
||||
onOpenChange={() => {
|
||||
setIsExcelOPen({isModal:false, data:{} as pubHasuType});
|
||||
}}
|
||||
></UiModal>
|
||||
<Toaster position="top-center" />
|
||||
|
||||
</>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
import type { z } from "zod";
|
||||
import { TEST_UUID } from "../../ruseFcltMng/fcltReg/rainReg";
|
||||
import type { PrfSchema } from "./type";
|
||||
|
||||
|
||||
const nameMap = {
|
||||
@@ -20,7 +22,7 @@ import { TEST_UUID } from "../../ruseFcltMng/fcltReg/rainReg";
|
||||
};
|
||||
|
||||
|
||||
export const excelToPbnPrfData = (excelData: any[], year: string) => {
|
||||
export const excelToPbnPrfData = (excelData: any[], year: string,pbnstRuseFcltFk:string) => {
|
||||
// 월별 데이터 하나로 병합
|
||||
const merged = {} as any;
|
||||
excelData.forEach((item: any) => {
|
||||
@@ -30,14 +32,23 @@ export const excelToPbnPrfData = (excelData: any[], year: string) => {
|
||||
for (let i = 1; i <= 12; i++) {
|
||||
const month = i.toString().padStart(2, "0");
|
||||
const ym = year + month;
|
||||
|
||||
|
||||
|
||||
console.log('pbnstRuseFcltFk ', pbnstRuseFcltFk)
|
||||
if (!merged[ym]) merged[ym] = { ym };
|
||||
merged[ym][key] = Number(item[`${i}월`] ?? 0);
|
||||
}
|
||||
});
|
||||
|
||||
const pbnPrfData = Object.values(merged);
|
||||
console.log(pbnPrfData);
|
||||
const data = pbnPrfData.map((item) => {
|
||||
|
||||
return pbnPrfData;
|
||||
return({
|
||||
...(item as object),
|
||||
pbnstRuseFcltFk:pbnstRuseFcltFk,
|
||||
rgtr: TEST_UUID,
|
||||
mdfr: TEST_UUID,
|
||||
})
|
||||
})
|
||||
return data;
|
||||
};
|
||||
@@ -4,6 +4,7 @@ import type { TableUpperProps } from "../../ruseFcltMng/fcltReg/rainReg";
|
||||
export const pbnPrfRegExcelZod = z.object({
|
||||
ym: z.string().default(""),
|
||||
bscFctNm: z.string().default(""),
|
||||
pbnstRuseFcltFk:z.string(),
|
||||
pbnstRuseFcltNm: z.string().default(""),
|
||||
file: z.instanceof(File).optional(),
|
||||
});
|
||||
@@ -12,23 +13,23 @@ export const pbnstPrfmncHeadListExport: TableUpperProps[] = [
|
||||
{ id: "sido", title: "시도" },
|
||||
{ id: "gugun", title: "시군구" },
|
||||
{ id: "bscFctNm", title: "시설명" },
|
||||
{ id: "sisul", title: "재이용시설명" },
|
||||
{ id: "sisulCd", title: "재이용시설코드" },
|
||||
{ id: "ruseUtztnFcltNm", title: "재이용시설명" },
|
||||
{ id: "pbnstRuseFcltPk", title: "재이용시설코드" },
|
||||
];
|
||||
|
||||
export const monthHeadListExport: TableUpperProps[] = [
|
||||
{ id: "gubun", title: "구분" },
|
||||
{ id: "total", title: "계" },
|
||||
{ id: "mon1", title: "1월" },
|
||||
{ id: "mon2", title: "2월" },
|
||||
{ id: "mon3", title: "3월" },
|
||||
{ id: "mon4", title: "4월" },
|
||||
{ id: "mon5", title: "5월" },
|
||||
{ id: "mon6", title: "6월" },
|
||||
{ id: "mon7", title: "7월" },
|
||||
{ id: "mon8", title: "8월" },
|
||||
{ id: "mon9", title: "9월" },
|
||||
{ id: "mon10", title: "10월" },
|
||||
{ id: "mon11", title: "11월" },
|
||||
{ id: "mon12", title: "12월" },
|
||||
{ id: "ym01", title: "1월" },
|
||||
{ id: "ym02", title: "2월" },
|
||||
{ id: "ym03", title: "3월" },
|
||||
{ id: "ym04", title: "4월" },
|
||||
{ id: "ym05", title: "5월" },
|
||||
{ id: "ym06", title: "6월" },
|
||||
{ id: "ym07", title: "7월" },
|
||||
{ id: "ym08", title: "8월" },
|
||||
{ id: "ym09", title: "9월" },
|
||||
{ id: "ym10", title: "10월" },
|
||||
{ id: "ym11", title: "11월" },
|
||||
{ id: "ym12", title: "12월" },
|
||||
];
|
||||
|
||||
@@ -1,79 +1,96 @@
|
||||
import { fetchType, getFetch, postFectch } from "@/components/lib/api";
|
||||
import type { TableUpperProps } from "../../ruseFcltMng/fcltReg/rainReg";
|
||||
import {
|
||||
pbnstPrfmncHeadListExport,
|
||||
monthHeadListExport,
|
||||
} from "./headList";
|
||||
import { pbnstPrfmncHeadListExport, monthHeadListExport } from "./headList";
|
||||
import type { pubHasuType } from "../../ruseFcltMng/fcltReg/pbnstReg/type";
|
||||
import type { FcPrfType, PrfType } from "./type";
|
||||
|
||||
const pbnstPrfmncHeadList = pbnstPrfmncHeadListExport;
|
||||
const monthHeadList = monthHeadListExport;
|
||||
|
||||
export type pbnstPrfmncState = {
|
||||
prfmnc: {
|
||||
isInit: boolean;
|
||||
pbnstPrfmncHeadList: TableUpperProps[];
|
||||
monthHeadList: TableUpperProps[];
|
||||
prfmncRes: pubHasuType[];
|
||||
excelList: Number[];
|
||||
}
|
||||
}
|
||||
prfmnc: {
|
||||
isInit: boolean;
|
||||
pbnstPrfmncHeadList: TableUpperProps[];
|
||||
monthHeadList: TableUpperProps[];
|
||||
prfmncRes: FcPrfType[];
|
||||
excelList: Number[];
|
||||
};
|
||||
};
|
||||
|
||||
export const pbnstPrfmncStateExport: pbnstPrfmncState = {
|
||||
prfmnc: {
|
||||
isInit: false,
|
||||
pbnstPrfmncHeadList: pbnstPrfmncHeadList,
|
||||
monthHeadList: monthHeadList,
|
||||
prfmncRes: [],
|
||||
excelList: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],
|
||||
}
|
||||
}
|
||||
prfmnc: {
|
||||
isInit: false,
|
||||
pbnstPrfmncHeadList: pbnstPrfmncHeadList,
|
||||
monthHeadList: monthHeadList,
|
||||
prfmncRes: [],
|
||||
excelList: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],
|
||||
},
|
||||
};
|
||||
|
||||
export type pbnstPrfmncType = pbnstPrfmncState & pbnstPrfmncActions;
|
||||
|
||||
type pbnstPrfmncActions = {
|
||||
prfmncHasuInit: (page: string, sggOrCity: string) => void;
|
||||
}
|
||||
prfmncHasuInit: (page: string, sggOrCity: string) => void;
|
||||
prfmnRegData: (data:PrfType) =>void
|
||||
};
|
||||
|
||||
const checkWrRegList = async () => {
|
||||
const wrRegList = await getFetch("wr", `/reuseFc/pubFc`);
|
||||
return wrRegList;
|
||||
const wrRegList = await getFetch("wr", `/reuseFc/pubDetailList`);
|
||||
return wrRegList;
|
||||
};
|
||||
const hasuListFetch = async (page: string, sggOrCity: string) => {
|
||||
const checkWrRegListRes = await checkWrRegList();
|
||||
|
||||
const rainRes = await postFectch(
|
||||
`/prcsFclt/ruseInfo/${page ? page : 1}/10/A/${sggOrCity ? sggOrCity : "11"}/0/1/SW`,
|
||||
checkWrRegListRes,
|
||||
fetchType.COMMON
|
||||
const checkWrRegListRes = await checkWrRegList();
|
||||
const rainRes = await postFectch(
|
||||
`/prcsFclt/ruseInfo/${page ? page : 1}/10/A/${sggOrCity ? sggOrCity : "11"}/0/1/SW`,
|
||||
checkWrRegListRes?.fcltCds,
|
||||
fetchType.COMMON
|
||||
);
|
||||
const data = checkWrRegListRes.fcPrfList.map((item: FcPrfType) => {
|
||||
const findData = rainRes.data.find(
|
||||
(fclt: pubHasuType) =>
|
||||
fclt.bscFctCd === item.pbnstRuseFcltPk.substring(0, 11)
|
||||
);
|
||||
|
||||
const hasuList = rainRes.data.map((item: any) => {
|
||||
return {
|
||||
...item,
|
||||
ruse: item.ruse === false ? "N" : "Y",
|
||||
};
|
||||
});
|
||||
|
||||
return hasuList;
|
||||
};
|
||||
export const pbnstPrfmncActionsExport: (set: any) => pbnstPrfmncActions = (set: any) => {
|
||||
return {
|
||||
prfmncHasuInit: async (page: string, sggOrCity: string) => {
|
||||
try {
|
||||
const prfmncRes = await hasuListFetch(page, sggOrCity);
|
||||
console.log("prfmncRes", prfmncRes)
|
||||
return set((state: pbnstPrfmncState) => ({
|
||||
...state,
|
||||
prfmnc: {
|
||||
...state.prfmnc,
|
||||
prfmncRes: prfmncRes,
|
||||
isInit: false,
|
||||
},
|
||||
}));
|
||||
} catch (errorHasu) {
|
||||
console.log(errorHasu);
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
sido: findData?.sido,
|
||||
gugun: findData?.gugun,
|
||||
bscFctNm: findData?.bscFctNm,
|
||||
ruseUtztnFcltNm: item.ruseUtztnFcltNm,
|
||||
pbnstRuseFcltPk: item.pbnstRuseFcltPk,
|
||||
};
|
||||
});
|
||||
return data;
|
||||
};
|
||||
export const pbnstPrfmncActionsExport: (set: any) => pbnstPrfmncActions = (
|
||||
set: any
|
||||
) => {
|
||||
return {
|
||||
prfmncHasuInit: async (page: string, sggOrCity: string) => {
|
||||
try {
|
||||
const prfmncRes = await hasuListFetch(page, sggOrCity);
|
||||
console.log("prfmncRes", prfmncRes);
|
||||
return set((state: pbnstPrfmncState) => ({
|
||||
...state,
|
||||
prfmnc: {
|
||||
...state.prfmnc,
|
||||
prfmncRes: prfmncRes,
|
||||
isInit: false,
|
||||
},
|
||||
}));
|
||||
} catch (errorHasu) {
|
||||
console.log(errorHasu);
|
||||
}
|
||||
},
|
||||
prfmnRegData: async (data:PrfType) => {
|
||||
try{
|
||||
|
||||
const ressponse = await postFectch(
|
||||
"/reuseFc/pubFcPrf",
|
||||
data,
|
||||
fetchType.WR
|
||||
);
|
||||
}catch(e){
|
||||
console.log(e)
|
||||
}
|
||||
},
|
||||
};
|
||||
};
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
import { z } from "zod";
|
||||
import type { TableUpperProps } from "../../common/type/headder";
|
||||
|
||||
|
||||
|
||||
export const PrfSchema = z.object({
|
||||
pbnstRuseFcltFk: z.string(),
|
||||
ym: z.string(), // 예: "202310"
|
||||
wshwtr: z.number(),
|
||||
coolUswtr: z.number(),
|
||||
cleanUswtr: z.number(),
|
||||
drwtUswtr: z.number(),
|
||||
dltnUswtr: z.number(),
|
||||
ithlRswtr: z.number(),
|
||||
ithlEtcUswtr: z.number(),
|
||||
cleanToilUswtr: z.number(),
|
||||
resn: z.number(),
|
||||
lndwtr: z.number(),
|
||||
hydUswtr: z.number(),
|
||||
rvrKeepUswtr: z.number(),
|
||||
farmUswtr: z.number(),
|
||||
ugwtChr: z.number(),
|
||||
indstUswtr: z.number(),
|
||||
regDt: z.date().default(new Date()),
|
||||
rgtr: z.string(),
|
||||
mdfcnDt: z.date().default(new Date()),
|
||||
mdfr: z.string()
|
||||
});
|
||||
|
||||
export const FcPrfSchema = z.object({
|
||||
pbnstRuseFcltPk: z.string(),
|
||||
ruseUtztnFcltNm: z.string(),
|
||||
fcltCpct: z.number(),
|
||||
ruseCpct: z.number(),
|
||||
splyExtraCpct: z.number(),
|
||||
regDt:z.date().default(new Date()),
|
||||
rgtr: z.string(),
|
||||
mdfcnDt: z.date().default(new Date()),
|
||||
mdfr: z.string(),
|
||||
prfList: z.array(PrfSchema),
|
||||
bscFctNm:z.string().nullish()
|
||||
});
|
||||
|
||||
|
||||
export type FcPrfType = z.infer<typeof FcPrfSchema>
|
||||
export type PrfType = z.infer<typeof PrfSchema>
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { useWrStore } from "@/app/store";
|
||||
import { excelToPbnPrfData } from "@/app/store/prfmncReg/pbnstPrfmncReg/excel";
|
||||
import { pbnPrfRegExcelZod } from "@/app/store/prfmncReg/pbnstPrfmncReg/headList";
|
||||
import type { FcPrfType, PrfType } from "@/app/store/prfmncReg/pbnstPrfmncReg/type";
|
||||
import { yearOptions } from "@/components/lib/func/commom";
|
||||
import { ToastFormUi } from "@/components/ui/toast/toastFromUi";
|
||||
import {
|
||||
@@ -13,19 +14,17 @@ import {
|
||||
type SelectDataType,
|
||||
filePicked,
|
||||
} from "@common/business_components/ui";
|
||||
import { Button } from "@common/components/ui";
|
||||
import { Button, Input } from "@common/components/ui";
|
||||
import { zodResolver } from "@hookform/resolvers/zod";
|
||||
import { useEffect, useState } from "react";
|
||||
import { useForm } from "react-hook-form";
|
||||
import type { z } from "zod";
|
||||
|
||||
export default function PbnPrfExcelModal() {
|
||||
const { code, prfmnc, searchFclts } = useWrStore((state) => state);
|
||||
export default function PbnPrfExcelModal({ data }: { data: FcPrfType }) {
|
||||
const { prfmnRegData } = useWrStore((state) => state);
|
||||
|
||||
|
||||
const [bscFctNmList, setBscFctNmList] = useState<SelectDataType[] | null>(null);
|
||||
const [files, setFiles] = useState<File[] | null>(null);
|
||||
const [excelData, setExcelData] = useState<any[]>();
|
||||
const [excelData, setExcelData] = useState<PrfType[]>();
|
||||
const form = useForm<z.infer<typeof pbnPrfRegExcelZod>>({
|
||||
resolver: zodResolver(pbnPrfRegExcelZod),
|
||||
defaultValues: {
|
||||
@@ -34,27 +33,24 @@ const [excelData, setExcelData] = useState<any[]>();
|
||||
});
|
||||
const onSubmit = (values: z.infer<typeof pbnPrfRegExcelZod>) => {
|
||||
console.log(values);
|
||||
|
||||
prfmnRegData(excelData )
|
||||
|
||||
|
||||
};
|
||||
useEffect(() => {
|
||||
|
||||
if(prfmnc.prfmncRes.length > 0){
|
||||
if (data && data.bscFctNm)
|
||||
form.setValue("pbnstRuseFcltFk", data.pbnstRuseFcltPk);
|
||||
form.setValue("bscFctNm", data.bscFctNm || "");
|
||||
form.setValue("pbnstRuseFcltNm", data.ruseUtztnFcltNm);
|
||||
}, [data]);
|
||||
|
||||
const basFctNmList = prfmnc.prfmncRes.map((item)=>(
|
||||
{
|
||||
val:item.bscFctCd,
|
||||
text:item.bscFctNm
|
||||
}
|
||||
))
|
||||
setBscFctNmList(basFctNmList)
|
||||
}
|
||||
|
||||
}, [prfmnc.prfmncRes]);
|
||||
|
||||
|
||||
useEffect(()=>{
|
||||
|
||||
if(files){
|
||||
useEffect(() => {
|
||||
console.log("excelData", excelData);
|
||||
}, [excelData]);
|
||||
|
||||
useEffect(() => {
|
||||
if (files) {
|
||||
const file = files[0];
|
||||
if (form.getValues("ym").length < 1) {
|
||||
ToastFormUi({
|
||||
@@ -65,15 +61,13 @@ const [excelData, setExcelData] = useState<any[]>();
|
||||
return;
|
||||
}
|
||||
|
||||
if(file)
|
||||
filePicked(file, 0).then((res) => {
|
||||
if (res !== undefined)
|
||||
console.log(excelToPbnPrfData(res, form.getValues("ym")))
|
||||
});
|
||||
|
||||
|
||||
if (file)
|
||||
filePicked(file, 0).then((res) => {
|
||||
if (res !== undefined)
|
||||
setExcelData(excelToPbnPrfData(res as any, form.getValues("ym"),form.getValues('pbnstRuseFcltFk') ))
|
||||
});
|
||||
}
|
||||
},[files])
|
||||
}, [files]);
|
||||
|
||||
return (
|
||||
<>
|
||||
@@ -116,13 +110,11 @@ const [excelData, setExcelData] = useState<any[]>();
|
||||
name="bscFctNm"
|
||||
render={({ field }) => (
|
||||
<FormUi label="시설명">
|
||||
<SelectBox
|
||||
<Input
|
||||
className="w-1/4 text-3xl"
|
||||
selectClass={""}
|
||||
label=""
|
||||
selectArray={bscFctNmList || [] }
|
||||
value={field.value}
|
||||
onSelectValue={(val) => field.onChange(String(val))}
|
||||
onChange={field.onChange}
|
||||
readOnly
|
||||
/>
|
||||
</FormUi>
|
||||
)}
|
||||
@@ -132,13 +124,11 @@ const [excelData, setExcelData] = useState<any[]>();
|
||||
name="pbnstRuseFcltNm"
|
||||
render={({ field }) => (
|
||||
<FormUi label="재이용시설명">
|
||||
<SelectBox
|
||||
<Input
|
||||
className="w-1/4 text-3xl"
|
||||
selectClass={""}
|
||||
label=""
|
||||
selectArray={yearOptions}
|
||||
value={field.value}
|
||||
onSelectValue={(val) => field.onChange(String(val))}
|
||||
onChange={field.onChange}
|
||||
readOnly
|
||||
/>
|
||||
</FormUi>
|
||||
)}
|
||||
|
||||
Reference in New Issue
Block a user