온배수 현황 및 중수도 지도점검 작업중
This commit is contained in:
@@ -1,14 +1,21 @@
|
||||
import { useWrStore } from "@/app/store";
|
||||
import { rainRegExcel, type rainChkZodType } from "@/app/store/prfmncReg/chkgdnReg/rainChkgdn";
|
||||
import { type rainChkZodType } from "@/app/store/prfmncReg/chkgdnReg/rainChkgdn";
|
||||
import { excelToRainChkData } from "@/app/store/prfmncReg/chkgdnReg/rainChkgdn/excel";
|
||||
import { chkgdRegExcel } from "@/app/store/prfmncReg/chkgdnReg/rainChkgdn/headList";
|
||||
import type { rswtChkZodType } from "@/app/store/prfmncReg/chkgdnReg/rswrtChkgdn";
|
||||
import {
|
||||
excelToRswtGuideData,
|
||||
excelToRswtPolution,
|
||||
} from "@/app/store/prfmncReg/chkgdnReg/rswrtChkgdn/excel";
|
||||
import { ToastFormUi } from "@/components/ui/toast/toastFromUi";
|
||||
import {
|
||||
filePicked,
|
||||
filePickedArray,
|
||||
FileUpload,
|
||||
Form,
|
||||
FormField,
|
||||
FormUi,
|
||||
Title
|
||||
Title,
|
||||
} from "@common/business_components/ui";
|
||||
import { Button, Input } from "@common/components/ui";
|
||||
import { zodResolver } from "@hookform/resolvers/zod";
|
||||
@@ -17,107 +24,199 @@ import { useForm } from "react-hook-form";
|
||||
import type { z } from "zod";
|
||||
|
||||
export default function ChkgdExcel({ type }: { type: string }) {
|
||||
const { rainChkExcelDataUPload } = useWrStore((state) => {
|
||||
return state;
|
||||
});
|
||||
const {
|
||||
rswtChkgdn,
|
||||
rainChkExcelDataUPload,
|
||||
rswtChkExceDataUpload,
|
||||
} = useWrStore((state) => {
|
||||
return state;
|
||||
});
|
||||
const [files, setFiles] = useState<File[] | null>(null);
|
||||
const [excelData , setExcelData] = useState<rainChkZodType[]>()
|
||||
const defaultValues: z.infer<typeof rainRegExcel> = rainRegExcel.parse({});
|
||||
const [excelData, setExcelData] = useState<
|
||||
rswtChkZodType[] | rainChkZodType[]
|
||||
>();
|
||||
const [excelRswtData, setExcelRswtData] = useState<rswtChkZodType[]>();
|
||||
|
||||
const form = useForm<z.infer<typeof rainRegExcel>>({
|
||||
resolver: zodResolver(rainRegExcel),
|
||||
const defaultValues: z.infer<typeof chkgdRegExcel> = chkgdRegExcel.parse({});
|
||||
|
||||
const form = useForm<z.infer<typeof chkgdRegExcel>>({
|
||||
resolver: zodResolver(chkgdRegExcel),
|
||||
defaultValues: defaultValues,
|
||||
});
|
||||
|
||||
useEffect(() => {
|
||||
if (files) {
|
||||
const file = files[0];
|
||||
if(form.getValues("chckYr").length<1 ){
|
||||
ToastFormUi({body:"파일업로드 이전에 등록년도를 작성해주세요 " ,title:'지도점검 등록'})
|
||||
setFiles(null)
|
||||
return
|
||||
}
|
||||
if (file)
|
||||
if (files) {
|
||||
const file = files[0];
|
||||
if (form.getValues("chckYr").length < 1) {
|
||||
ToastFormUi({
|
||||
body: "파일업로드 이전에 등록년도를 작성해주세요 ",
|
||||
title: "지도점검 등록",
|
||||
});
|
||||
setFiles(null);
|
||||
return;
|
||||
}
|
||||
if (file)
|
||||
if (type === "RNB") {
|
||||
filePicked(file, 0).then((res) => {
|
||||
if (res !== undefined)
|
||||
setExcelData(excelToRainChkData(res, form.getValues("chckYr")))
|
||||
setExcelData(excelToRainChkData(res, form.getValues("chckYr")));
|
||||
});
|
||||
}
|
||||
} else if (type === "RST") {
|
||||
filePickedArray(file, 0).then((res) => {
|
||||
if (res && res?.length > 1) {
|
||||
const excelArray = [];
|
||||
const guideData = excelToRswtGuideData(
|
||||
res[0],
|
||||
form.getValues("chckYr")
|
||||
);
|
||||
const polutionData = excelToRswtPolution(
|
||||
res[1],
|
||||
form.getValues("chckYr")
|
||||
);
|
||||
|
||||
|
||||
const keyGenerator = (item: rswtChkZodType) =>
|
||||
`${item.bdstRuseFcltFk}|${item.chckYmd}|${item.utztnUsgCd}`;
|
||||
const totalData: rswtChkZodType[] = guideData.map((guide) => {
|
||||
const fusion = polutionData.find(
|
||||
(polution) =>
|
||||
guide.bdstRuseFcltFk === polution.bdstRuseFcltFk &&
|
||||
guide.chckYmd === polution.chckYmd &&
|
||||
guide.utztnUsgCd === polution.utztnUsgCd
|
||||
);
|
||||
|
||||
if (fusion) {
|
||||
return {
|
||||
...guide,
|
||||
rswtrPolutions: fusion?.rswtrPolutions,
|
||||
rswtrDetails:fusion?.rswtrDetails
|
||||
};
|
||||
} else {
|
||||
return {
|
||||
...guide,
|
||||
};
|
||||
}
|
||||
});
|
||||
const guideKey = new Set(guideData.map(keyGenerator));
|
||||
|
||||
const onlypolution = polutionData.filter(
|
||||
(item) => !guideKey.has(keyGenerator(item))
|
||||
);
|
||||
|
||||
const listTotalData:rswtChkZodType[] =[
|
||||
...totalData,
|
||||
...onlypolution
|
||||
]
|
||||
|
||||
setExcelRswtData(listTotalData);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}, [files]);
|
||||
|
||||
const onSubmit =(values: z.infer<typeof rainRegExcel>)=> {
|
||||
if(values.chckYr ===''){
|
||||
ToastFormUi({body:"등록년도를 작성해주세요" ,title:'지도점검 등록'})
|
||||
return
|
||||
}else if(excelData ===undefined || excelData?.length === 0 ){
|
||||
ToastFormUi({body:"빈 파일 및 파일 오류 입니다." ,title:'지도점검 등록'})
|
||||
return
|
||||
}
|
||||
if (excelData) {
|
||||
rainChkExcelDataUPload(excelData);
|
||||
}
|
||||
|
||||
function findMatchingItems<T>(
|
||||
arrayA: T[],
|
||||
arrayB: T[],
|
||||
keySelector: (item: T) => string,
|
||||
condition?: (item: T) => boolean
|
||||
): T[] {
|
||||
const bKeySet = new Set(arrayB.map(keySelector));
|
||||
return arrayA.filter(
|
||||
(item) =>
|
||||
(!condition || condition(item)) && bKeySet.has(keySelector(item))
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
const onSubmit = (values: z.infer<typeof chkgdRegExcel>) => {
|
||||
if (values.chckYr === "") {
|
||||
ToastFormUi({ body: "등록년도를 작성해주세요", title: "지도점검 등록" });
|
||||
return;
|
||||
}
|
||||
|
||||
if (type === "RNB") {
|
||||
if (excelData === undefined || excelData?.length === 0) {
|
||||
ToastFormUi({
|
||||
body: "빈 파일 및 파일 오류 입니다.",
|
||||
title: "지도점검 등록",
|
||||
});
|
||||
return;
|
||||
} else {
|
||||
rainChkExcelDataUPload(excelData as rainChkZodType[]);
|
||||
}
|
||||
} else if (type === "RST") {
|
||||
if (excelRswtData === undefined || excelRswtData?.length === 0) {
|
||||
ToastFormUi({
|
||||
body: "빈 파일 및 파일 오류 입니다.",
|
||||
title: "중수지도점검 등록",
|
||||
});
|
||||
return;
|
||||
} else {
|
||||
rswtChkExceDataUpload(excelRswtData as rswtChkZodType[]);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<>
|
||||
<div>
|
||||
<Form {...form}>
|
||||
<form onSubmit={form.handleSubmit(onSubmit)}>
|
||||
<div>
|
||||
<Title
|
||||
title={
|
||||
type === "RNB"
|
||||
? "빗물 이용시설"
|
||||
: "중수도 이용시설" + "점검 결과등록"
|
||||
}
|
||||
></Title>
|
||||
</div>
|
||||
<div className="flex justify-between">
|
||||
<h3 className="text-2xl font-bold text-gray-900">
|
||||
{"○점검정보 입력"}
|
||||
</h3>
|
||||
<form onSubmit={form.handleSubmit(onSubmit)}>
|
||||
<div>
|
||||
<Title
|
||||
title={
|
||||
type === "RNB"
|
||||
? "빗물 이용시설"
|
||||
: "중수도 이용시설" + "점검 결과등록"
|
||||
}
|
||||
></Title>
|
||||
</div>
|
||||
<div className="flex justify-between">
|
||||
<h3 className="text-2xl font-bold text-gray-900">
|
||||
{"○점검정보 입력"}
|
||||
</h3>
|
||||
|
||||
<Button className="" type="submit">
|
||||
저장
|
||||
</Button>
|
||||
</div>
|
||||
<Button className="" type="submit">
|
||||
저장
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<FormField
|
||||
control={form.control}
|
||||
name="chckYr"
|
||||
render={({ field }) => (
|
||||
<FormUi label="등록년도">
|
||||
<Input
|
||||
className={`text-3xl`}
|
||||
type="text"
|
||||
value={field.value}
|
||||
onChange={field.onChange}
|
||||
/>
|
||||
</FormUi>
|
||||
)}
|
||||
/>
|
||||
<div>
|
||||
<FormField
|
||||
control={form.control}
|
||||
name="chckYr"
|
||||
render={({ field }) => (
|
||||
<FormUi label="등록년도">
|
||||
<Input
|
||||
className={`text-3xl`}
|
||||
type="text"
|
||||
value={field.value}
|
||||
onChange={field.onChange}
|
||||
/>
|
||||
</FormUi>
|
||||
)}
|
||||
/>
|
||||
|
||||
<FormField
|
||||
control={form.control}
|
||||
name="file"
|
||||
render={({ field }) => (
|
||||
<FormUi label="점검결과 파일">
|
||||
<FileUpload
|
||||
files={files || []}
|
||||
setFiles={(files: File[] | null ) => {
|
||||
if(files) setFiles(files)
|
||||
} }
|
||||
fileTypes="xlsx"
|
||||
></FileUpload>
|
||||
</FormUi>
|
||||
)}
|
||||
/>
|
||||
</div>
|
||||
</form>
|
||||
<FormField
|
||||
control={form.control}
|
||||
name="file"
|
||||
render={({ field }) => (
|
||||
<FormUi label="점검결과 파일">
|
||||
<FileUpload
|
||||
files={files || []}
|
||||
setFiles={(files: File[] | null) => {
|
||||
if (files) setFiles(files);
|
||||
}}
|
||||
fileTypes="xlsx"
|
||||
></FileUpload>
|
||||
</FormUi>
|
||||
)}
|
||||
/>
|
||||
</div>
|
||||
</form>
|
||||
</Form>
|
||||
</div>
|
||||
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -2,9 +2,9 @@ import { useWrStore } from "@/app/store";
|
||||
import { ScrollArea, Title, UiTable } from "@common/business_components/ui";
|
||||
import { Button } from "@common/components/ui";
|
||||
import { useEffect, useState } from "react";
|
||||
import type { splRuseWaterType } from "@/app/store/prfmncReg/chkgdnReg/rainChkgdn";
|
||||
import { headMakeprfmnc } from "@/app/ruseFcltMng/prfmncReg/chkgdnReg/TableHead";
|
||||
import { GuideDetailsTable } from "@/components/ui/table/chkgdTable/guideDetailTable/guideDetailTable";
|
||||
import type { splRuseWaterType } from "@/app/store/prfmncReg/chkgdnReg/rainChkgdn/headList";
|
||||
|
||||
export default function ChkgdModal({ type, obj }: { type: string; obj: any }) {
|
||||
const { rainChkgdn, rainChkDetilUpdate, rainChkGuidUpdate } = useWrStore(
|
||||
|
||||
@@ -7,7 +7,7 @@ import type { customRswtBdst } from "@/app/store/ruseFcltMng/fcltReg/rswtReg";
|
||||
import { useWrStore } from "@/app/store";
|
||||
import { useEffect, useState } from "react";
|
||||
import type { CommonTableProps } from "@/app/store/common/type/headder";
|
||||
import { rightTableData } from "@/components/lib/func/TableData";
|
||||
import { rainChkTableData } from "@/components/lib/func/TableData";
|
||||
import { HeadMakeColSpan } from "@common/business_components/ui/table/HeadMakeColSpan";
|
||||
|
||||
export default function SttnDetailModal({
|
||||
@@ -40,7 +40,7 @@ export default function SttnDetailModal({
|
||||
formObj.reuseBuilding[0] &&
|
||||
rainSttn.rainChkRes?.bdstRuseFcltFk
|
||||
) {
|
||||
const tableTotalData = rightTableData([rainSttn.rainChkRes]);
|
||||
const tableTotalData = rainChkTableData([rainSttn.rainChkRes]);
|
||||
const data = tableTotalData.map((item) => {
|
||||
const obj = {
|
||||
totalSplyUswtrUtztnQnt: item.totalSplyUswtrUtztnQnt,
|
||||
@@ -72,7 +72,7 @@ export default function SttnDetailModal({
|
||||
return (
|
||||
|
||||
<div>
|
||||
<Title title={"빗물이용시설 상세정보"}></Title>
|
||||
<Title title={type === "RNB" ?"빗물이용시설 상세정보":"중수도시설 상세정보"}></Title>
|
||||
<ScrollArea className={detailData.data.length>0?"h-[80vh]":"h-[70vh]"} >
|
||||
{type === "RNB" ? (
|
||||
<RainRegForm rainForm={formObj as customRainBdst} isModal={false} />
|
||||
|
||||
@@ -5,7 +5,7 @@ import type { rainChkZodType } from "@/app/store/prfmncReg/chkgdnReg/rainChkgdn"
|
||||
import { tableData } from "@/components/lib/func/commom";
|
||||
import {
|
||||
chRowspanTable,
|
||||
rightTableData
|
||||
rainChkTableData
|
||||
} from "@/components/lib/func/TableData";
|
||||
import {
|
||||
Table,
|
||||
@@ -66,13 +66,11 @@ export default function RainChkgdTable({
|
||||
rowspan: item.rainyDetails?.length,
|
||||
};
|
||||
});
|
||||
const tableTotalData = rightTableData(rainChg)
|
||||
const tableTotalData = rainChkTableData(rainChg)
|
||||
setMakeTableData(tableTotalData);
|
||||
}, [rainChkgdn.rainChk, code]);
|
||||
|
||||
useEffect(() => {
|
||||
|
||||
|
||||
//데이터를 평탄화 한것중에 체크박스 선택한 테이블만 선택
|
||||
const selectedData = makeTableData.filter((item) =>selectedIds.includes(item.chkgdnPk));
|
||||
|
||||
@@ -132,10 +130,6 @@ export default function RainChkgdTable({
|
||||
}
|
||||
},[selectedIds])
|
||||
|
||||
useEffect(() => {
|
||||
|
||||
},[])
|
||||
|
||||
|
||||
return (
|
||||
<Table variant="secondary">
|
||||
|
||||
@@ -1,30 +1,79 @@
|
||||
'use client'
|
||||
"use client";
|
||||
|
||||
import { headMakeprfmnc } from "@/app/ruseFcltMng/prfmncReg/chkgdnReg/TableHead";
|
||||
import { useWrStore } from "@/app/store";
|
||||
import { UiTable } from "@common/business_components/ui";
|
||||
import type { rswtChkZodType } from "@/app/store/prfmncReg/chkgdnReg/rswrtChkgdn";
|
||||
import { chRowspanTable } from "@/components/lib/func/TableData";
|
||||
import { Table, TableBody, TableHeader } from "@common/components/ui";
|
||||
import { useCallback, useState } from "react";
|
||||
|
||||
export default function RswtChkgdTable() {
|
||||
export default function RswtChkgdTable({
|
||||
detaiRswtlUpdate,
|
||||
handleRswtClick = () => {},
|
||||
deleteRswtData,
|
||||
}: {
|
||||
detaiRswtlUpdate: (data: rswtChkZodType[]) => void;
|
||||
handleRswtClick?: (data: any) => void;
|
||||
deleteRswtData: (selectedIds: number[]) => void;
|
||||
}) {
|
||||
const { code, rswtChkgdn, rswtChkgdnInit } = useWrStore((state) => state);
|
||||
|
||||
const { rswtChkgdn} = useWrStore((state) => state);
|
||||
const nodeList = headMakeprfmnc(rswtChkgdn?.rswtChkgdnHeadList , rswtChkgdn?.rswtHeadNm );
|
||||
|
||||
const [makeTableData, setMakeTableData] = useState<any[]>([]);
|
||||
const [selectedIds, setSelectedIds] = useState<number[]>([]);
|
||||
const [upRaintDetail, setUpRaintDetail] = useState<rswtChkZodType[]>([]);
|
||||
const toggleSelection = (pk: number, checked: boolean) => {
|
||||
setSelectedIds((prev) =>
|
||||
checked ? [...prev, pk] : prev.filter((item) => item !== pk)
|
||||
);
|
||||
};
|
||||
const handleChange = (
|
||||
rowIndex: number,
|
||||
field: keyof (typeof makeTableData)[0],
|
||||
value: string | number
|
||||
) => {
|
||||
setMakeTableData((prev) =>
|
||||
prev.map((row, idx) => {
|
||||
return idx === rowIndex ? { ...row, [field]: value } : row;
|
||||
})
|
||||
);
|
||||
};
|
||||
|
||||
return(
|
||||
|
||||
<>
|
||||
<UiTable
|
||||
tableData={[]}
|
||||
headlist={rswtChkgdn.rswtChkgdnHeadList}
|
||||
pageSize={100}
|
||||
total={10}
|
||||
headName={"지도점검 결과등록"}
|
||||
cellClick={() => { } } onPageChange={function (page: number): void {
|
||||
throw new Error("Function not implemented.");
|
||||
} } >
|
||||
{nodeList}
|
||||
</UiTable>
|
||||
</>
|
||||
)
|
||||
|
||||
}
|
||||
|
||||
const handleCellClick = useCallback(
|
||||
(index: number, headId: string) => {
|
||||
if (
|
||||
headId === "totalSplyUswtrUtztnQnt" ||
|
||||
headId === "totalRuseFcltUtztnQnt"
|
||||
) {
|
||||
handleRswtClick(makeTableData[index]);
|
||||
}
|
||||
},
|
||||
[makeTableData, handleRswtClick]
|
||||
);
|
||||
|
||||
|
||||
|
||||
|
||||
return (
|
||||
<>
|
||||
<Table variant="secondary">
|
||||
<TableHeader className="font-bold">
|
||||
{headMakeprfmnc(rswtChkgdn?.rswtChkHeadList, rswtChkgdn?.rswtHeadNm)}
|
||||
</TableHeader>
|
||||
|
||||
<TableBody>
|
||||
{chRowspanTable(
|
||||
makeTableData,
|
||||
rswtChkgdn.rswtChkHeadList,
|
||||
handleChange,
|
||||
toggleSelection,
|
||||
selectedIds,
|
||||
handleCellClick
|
||||
)}
|
||||
</TableBody>
|
||||
</Table>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user