fo: 유량현황 강우시 평균 단수 처리
This commit is contained in:
@@ -26,7 +26,7 @@ export const getDaysInMonth = (yyyymm: string) => {
|
||||
return new Date(year, month, 0).getDate();
|
||||
}
|
||||
|
||||
export const roundNumber = (value : any, decimals: number) => {
|
||||
export const roundNumber = (value: any, decimals: number) => {
|
||||
if (typeof value === 'number') {
|
||||
return addCommas((Math.round(value * Math.pow(10, decimals)) / Math.pow(10, decimals)).toFixed(decimals));
|
||||
} else if (typeof value === 'string') {
|
||||
@@ -45,48 +45,48 @@ export const addCommas = (value: string | number): any => {
|
||||
index === 0 ? part : part.replace(/(\d{3})/g, '$1,')
|
||||
).join('.');
|
||||
} else if (typeof value === 'string') {
|
||||
return value.includes('.')?value.split('.').map((part, index) =>
|
||||
return value.includes('.') ? value.split('.').map((part, index) =>
|
||||
index === 0 ? part.replace(/\B(?=(\d{3})+(?!\d))/g, ",") : part
|
||||
).join('.'):String(value).replace(/\B(?=(\d{3})+(?!\d))/g, ",");
|
||||
).join('.') : String(value).replace(/\B(?=(\d{3})+(?!\d))/g, ",");
|
||||
}
|
||||
}
|
||||
|
||||
export default function DataForm({ type, column, item }: DataFormProps) {
|
||||
if(item) {
|
||||
if (item) {
|
||||
const value = item[column];
|
||||
switch(type){
|
||||
switch (type) {
|
||||
case 'date':
|
||||
if(value && typeof value === 'string' && value.length >= 8)
|
||||
if (value && typeof value === 'string' && value.length >= 8 && !value.includes('-'))
|
||||
item[column] = value.substring(0, 4) + "-" + value.substring(4, 6) + "-" + value.substring(6, 8);
|
||||
break;
|
||||
break;
|
||||
case 'number':
|
||||
if(value && value != '') {
|
||||
if (value && value != '') {
|
||||
item[column] = value.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
|
||||
}
|
||||
break;
|
||||
break;
|
||||
case 'float0':
|
||||
if(value) {
|
||||
item[column] = item[column] = String(value).includes('.')?String(Math.round(parseFloat(value.toString().replace(/,/g, '')) * 1) / 1).split('.').map((part, index) =>
|
||||
index === 0 ? part.replace(/\B(?=(\d{3})+(?!\d))/g, ",") : part
|
||||
).join('.')
|
||||
: String(value).replace(/\B(?=(\d{3})+(?!\d))/g, ",");
|
||||
if (value) {
|
||||
item[column] = item[column] = String(value).includes('.') ? String(Math.round(parseFloat(value.toString().replace(/,/g, '')) * 1) / 1).split('.').map((part, index) =>
|
||||
index === 0 ? part.replace(/\B(?=(\d{3})+(?!\d))/g, ",") : part
|
||||
).join('.')
|
||||
: String(value).replace(/\B(?=(\d{3})+(?!\d))/g, ",");
|
||||
}
|
||||
break;
|
||||
break;
|
||||
case 'float1':
|
||||
if(value) {
|
||||
if (value) {
|
||||
item[column] = roundNumber(value, 1);
|
||||
}
|
||||
break;
|
||||
break;
|
||||
case 'float2':
|
||||
if(value) {
|
||||
if (value) {
|
||||
item[column] = roundNumber(value, 2);
|
||||
}
|
||||
break;
|
||||
break;
|
||||
case 'float3':
|
||||
if(value) {
|
||||
if (value) {
|
||||
item[column] = roundNumber(value, 3);
|
||||
}
|
||||
break;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -4,14 +4,14 @@ import ListDiv from '@common/business_components/ui/list_div';
|
||||
import { Table, TableCell, TableHead, TableRow } from '@common/components/ui';
|
||||
import { useCallback, useEffect, useRef, useState } from 'react';
|
||||
|
||||
type FacilityTermModalHeaderProps<T extends { msrDt: string }> = {
|
||||
fcltyCd : string;
|
||||
type FacilityTermModalHeaderProps<T extends { msrDt: string }> = { // T는 반드시 msrDt: string 필드를 가져야 한다
|
||||
fcltyCd: string;
|
||||
fcltyName: string;
|
||||
tabName: string;
|
||||
searchYear: string;
|
||||
searchList: T[];
|
||||
ref: React.RefObject<ReturnType<T>>;
|
||||
queryClick:(returnType:ReturnType<T>) => void;
|
||||
queryClick: (returnType: ReturnType<T>) => void;
|
||||
}
|
||||
|
||||
export type ReturnType<T> = {
|
||||
@@ -21,28 +21,28 @@ export type ReturnType<T> = {
|
||||
filteredList: T[];
|
||||
}
|
||||
|
||||
export default function FacilityTermModalHeader<T extends { msrDt: string }>({
|
||||
export default function FacilityTermModalHeader<T extends { msrDt: string }>({
|
||||
searchList,
|
||||
fcltyName,
|
||||
tabName,
|
||||
fcltyName,
|
||||
tabName,
|
||||
searchYear,
|
||||
queryClick,
|
||||
ref
|
||||
}: FacilityTermModalHeaderProps<T & { msrDt: string }>) {
|
||||
const {Common} = useFoStore((state) => state);
|
||||
const { Common } = useFoStore((state) => state);
|
||||
const { selectFlowPanel } = Common;
|
||||
const [startDate, setStartDate] = useState<Date>(new Date(Number(searchYear), 0, 1));
|
||||
const [endDate, setEndDate] = useState<Date>(new Date(Number(searchYear), 11, 31));
|
||||
const startPickerRef = useRef<HTMLDivElement>(null);
|
||||
const endPickerRef = useRef<HTMLDivElement>(null);
|
||||
const [flowPanel, setFlowPanel] = useState<string>(selectFlowPanel[0]?.val ?? '00');
|
||||
const [flowPanel, setFlowPanel] = useState<string>(selectFlowPanel[0]?.val ?? '0'); // 초기값 "전체"
|
||||
const [copySearchList, setCopySearchList] = useState<T[]>(searchList);
|
||||
const [standSearchList, setStandSearchList] = useState<T[]>(searchList);
|
||||
|
||||
const isDateInRanges = (date: Date) => {
|
||||
const standYear = parseInt(searchYear);
|
||||
const isLeapYear = (standYear % 4 === 0 && standYear % 100 !== 0) || (standYear % 400 === 0);
|
||||
const dateRanges:{start:Date, end:Date}[] = [];
|
||||
const dateRanges: { start: Date, end: Date }[] = [];
|
||||
|
||||
if (tabName.includes("_summer")) {
|
||||
dateRanges.push({
|
||||
@@ -74,66 +74,66 @@ export default function FacilityTermModalHeader<T extends { msrDt: string }>({
|
||||
const standYear = Number(searchYear);
|
||||
const isLeapYear = (standYear % 4 === 0 && standYear % 100 !== 0) || (standYear % 400 === 0);
|
||||
|
||||
if(tabName.includes("_summer")) {
|
||||
startDate = new Date(Number(searchYear), 5, 1);
|
||||
endDate = new Date(Number(searchYear), 7, 31);
|
||||
if (tabName.includes("_summer")) { // 하절기
|
||||
startDate = new Date(Number(searchYear), 5, 1); // 6월 ~
|
||||
endDate = new Date(Number(searchYear), 7, 31); // 8월
|
||||
setStartDate(startDate);
|
||||
setEndDate(endDate);
|
||||
} else if (tabName.includes("_winter")) {
|
||||
startDate = new Date(Number(searchYear), 0, 1);
|
||||
endDate = new Date(Number(searchYear), 1, isLeapYear ? 29 : 28);
|
||||
} else if (tabName.includes("_winter")) { // 동절기
|
||||
startDate = new Date(Number(searchYear), 0, 1); // 1월 ~
|
||||
endDate = new Date(Number(searchYear), 1, isLeapYear ? 29 : 28); // 2월
|
||||
setStartDate(startDate);
|
||||
setEndDate(endDate);
|
||||
} else {
|
||||
} else { // 연간
|
||||
startDate = new Date(Number(searchYear), 0, 1);
|
||||
endDate = new Date(Number(searchYear), 11, 31);
|
||||
setStartDate(startDate);
|
||||
setEndDate(endDate);
|
||||
}
|
||||
|
||||
|
||||
let filteredData: T[] = [];
|
||||
|
||||
if(tabName.includes("_rain")) {
|
||||
if (tabName.includes("_rain")) { // 강우시
|
||||
filteredData = searchList.filter((item) => {
|
||||
const itemDate = new Date((item as T & { msrDt: string }).msrDt);
|
||||
const itemDateOnly = new Date(itemDate.getFullYear(), itemDate.getMonth(), itemDate.getDate());
|
||||
const startDateOnly = new Date(startDate.getFullYear(), startDate.getMonth(), startDate.getDate());
|
||||
const endDateOnly = new Date(endDate.getFullYear(), endDate.getMonth(), endDate.getDate());
|
||||
const rainEffectDay = (item as T & { rainEffectDay: number }).rainEffectDay;
|
||||
|
||||
if(flowPanel === '2'){
|
||||
|
||||
if (flowPanel === '2') { //3~10mm미만
|
||||
const infoRnDay = (item as T & { toBeInfoRnDay: number }).toBeInfoRnDay;
|
||||
return (itemDateOnly >= startDateOnly && itemDateOnly <= endDateOnly) && infoRnDay >= 3 && infoRnDay < 10;
|
||||
} else if(flowPanel === '3'){
|
||||
} else if (flowPanel === '3') { //10~20mm미만
|
||||
const infoRnDay = (item as T & { toBeInfoRnDay: number }).toBeInfoRnDay;
|
||||
return (itemDateOnly >= startDateOnly && itemDateOnly <= endDateOnly) && infoRnDay >= 10 && infoRnDay < 20;
|
||||
} else if(flowPanel === '4'){
|
||||
} else if (flowPanel === '4') { //20~30mm미만
|
||||
const infoRnDay = (item as T & { toBeInfoRnDay: number }).toBeInfoRnDay;
|
||||
return (itemDateOnly >= startDateOnly && itemDateOnly <= endDateOnly) && infoRnDay >= 20 && infoRnDay < 30;
|
||||
} else if(flowPanel === '5'){
|
||||
} else if (flowPanel === '5') { //30~40mm미만
|
||||
const infoRnDay = (item as T & { toBeInfoRnDay: number }).toBeInfoRnDay;
|
||||
return (itemDateOnly >= startDateOnly && itemDateOnly <= endDateOnly) && infoRnDay >= 30 && infoRnDay < 40;
|
||||
} else if(flowPanel === '6'){
|
||||
} else if (flowPanel === '6') { //40~50mm미만
|
||||
const infoRnDay = (item as T & { toBeInfoRnDay: number }).toBeInfoRnDay;
|
||||
return (itemDateOnly >= startDateOnly && itemDateOnly <= endDateOnly) && infoRnDay >= 40 && infoRnDay < 50;
|
||||
} else if(flowPanel === '7'){
|
||||
} else if (flowPanel === '7') { //50~60mm미만
|
||||
const infoRnDay = (item as T & { toBeInfoRnDay: number }).toBeInfoRnDay;
|
||||
return (itemDateOnly >= startDateOnly && itemDateOnly <= endDateOnly) && infoRnDay >= 50 && infoRnDay < 60;
|
||||
} else if(flowPanel === '8'){
|
||||
} else if (flowPanel === '8') {
|
||||
const infoRnDay = (item as T & { toBeInfoRnDay: number }).toBeInfoRnDay;
|
||||
return (itemDateOnly >= startDateOnly && itemDateOnly <= endDateOnly) && infoRnDay >= 60;
|
||||
} else {
|
||||
return (itemDateOnly >= startDateOnly && itemDateOnly <= endDateOnly) && (rainEffectDay ===1);
|
||||
return (itemDateOnly >= startDateOnly && itemDateOnly <= endDateOnly) && (rainEffectDay === 1);
|
||||
}
|
||||
});
|
||||
} else if(tabName.includes("_chuncheon")) {
|
||||
} else if (tabName.includes("_chuncheon")) { // 청천시
|
||||
filteredData = searchList.filter((item) => {
|
||||
const itemDate = new Date((item as T & { msrDt: string }).msrDt);
|
||||
const itemDateOnly = new Date(itemDate.getFullYear(), itemDate.getMonth(), itemDate.getDate());
|
||||
const startDateOnly = new Date(startDate.getFullYear(), startDate.getMonth(), startDate.getDate());
|
||||
const endDateOnly = new Date(endDate.getFullYear(), endDate.getMonth(), endDate.getDate());
|
||||
const rainEffectDay = (item as T & { rainEffectDay: number }).rainEffectDay;
|
||||
return (itemDateOnly >= startDateOnly && itemDateOnly <= endDateOnly) && rainEffectDay==0;
|
||||
return (itemDateOnly >= startDateOnly && itemDateOnly <= endDateOnly) && rainEffectDay == 0;
|
||||
});
|
||||
} else {
|
||||
filteredData = searchList.filter((item) => {
|
||||
@@ -149,7 +149,7 @@ export default function FacilityTermModalHeader<T extends { msrDt: string }>({
|
||||
}, [searchList, searchYear, tabName, flowPanel]);
|
||||
|
||||
const handleStartDateSelect = (day: Date | undefined) => {
|
||||
if(day && day > endDate) {
|
||||
if (day && day > endDate) {
|
||||
alert('종료일은 시작일 이전일 수 없습니다.');
|
||||
return;
|
||||
}
|
||||
@@ -172,7 +172,7 @@ export default function FacilityTermModalHeader<T extends { msrDt: string }>({
|
||||
};
|
||||
|
||||
const handleEndDateSelect = (day: Date | undefined) => {
|
||||
if(day && day < startDate) {
|
||||
if (day && day < startDate) {
|
||||
alert('종료일은 시작일 이후일 수 없습니다.');
|
||||
return;
|
||||
}
|
||||
@@ -193,7 +193,7 @@ export default function FacilityTermModalHeader<T extends { msrDt: string }>({
|
||||
});
|
||||
setCopySearchList(filteredData);
|
||||
};
|
||||
|
||||
|
||||
const fncSetFilteredList = useCallback(() => {
|
||||
queryClick({
|
||||
startDate: startDate,
|
||||
@@ -206,9 +206,9 @@ export default function FacilityTermModalHeader<T extends { msrDt: string }>({
|
||||
useEffect(() => {
|
||||
fncSetFilteredList();
|
||||
}, [fncSetFilteredList]);
|
||||
|
||||
|
||||
useEffect(() => {
|
||||
if(ref && ref.current) {
|
||||
if (ref && ref.current) {
|
||||
const customRef = ref.current;
|
||||
customRef.startDate = startDate;
|
||||
customRef.endDate = endDate;
|
||||
@@ -225,18 +225,18 @@ export default function FacilityTermModalHeader<T extends { msrDt: string }>({
|
||||
<TableRow className="!h-[20px]">
|
||||
<TableHead className="w-[120px]">{'시설명'}</TableHead>
|
||||
{tabName === "tab_term_rain" ? <TableCell className="w-[300px]">{fcltyName}</TableCell> :
|
||||
<TableCell className="w-[380px]">{fcltyName}</TableCell>}
|
||||
<TableCell className="w-[380px]">{fcltyName}</TableCell>}
|
||||
{tabName === "tab_term_rain" && (
|
||||
<>
|
||||
<TableHead className="w-[120px]">{'강수구분'}</TableHead>
|
||||
<TableCell className="w-[250px]">
|
||||
<div className="justify-center">
|
||||
<SelectBox
|
||||
selectArray={selectFlowPanel}
|
||||
<SelectBox
|
||||
selectArray={selectFlowPanel}
|
||||
value={flowPanel}
|
||||
onSelectValue={(val) => setFlowPanel(val.toString())}
|
||||
className="mx-3 w-[150px]"
|
||||
label=""
|
||||
className="mx-3 w-[150px]"
|
||||
label=""
|
||||
selectClass="w-full p-1 border rounded bg-white"
|
||||
/>
|
||||
</div>
|
||||
@@ -247,7 +247,7 @@ export default function FacilityTermModalHeader<T extends { msrDt: string }>({
|
||||
<TableCell className="">
|
||||
<div className="flex">
|
||||
<div ref={startPickerRef} className="flex justify-center">
|
||||
<DatePickerRange
|
||||
<DatePickerRange
|
||||
mode="single"
|
||||
selected={startDate}
|
||||
onSelect={(date) => handleStartDateSelect(date as Date)}
|
||||
@@ -261,7 +261,7 @@ export default function FacilityTermModalHeader<T extends { msrDt: string }>({
|
||||
<DatePickerRange
|
||||
mode="single"
|
||||
selected={endDate}
|
||||
onSelect={(date) => handleEndDateSelect(date as Date)}
|
||||
onSelect={(date) => handleEndDateSelect(date as Date)}
|
||||
className="w-full p-1 border rounded bg-white"
|
||||
disabled={(date) => !isDateInRanges(date)}
|
||||
defaultMonth={endDate}
|
||||
|
||||
Reference in New Issue
Block a user