248 lines
8.0 KiB
TypeScript
248 lines
8.0 KiB
TypeScript
import { fetchType, getFetch } from "@/components/lib/api";
|
|
import type { TableUpperProps } from "../../common/type/header";
|
|
import { excelRainStat } from "./excel";
|
|
import { rainStatHeadListExport } from "./headList";
|
|
import type { SelectDataType } from "@common/business_components/ui";
|
|
|
|
export type RainStatProps = {
|
|
cityText: string;
|
|
ctpvCd: string; //시도
|
|
sggCd: string; //시군구
|
|
areaNm: string; //행정구역명
|
|
bdstNm: string; //시설명
|
|
bdstUsgCd: string; //건축물용도코드
|
|
daddr: string; //주소
|
|
lawTrgtYn: string; //법적의무대상여부
|
|
instlCmptnDt: string; //설치완료일자
|
|
instlCst: number; //설치비용
|
|
pntfColKnd: string; //접수면종류
|
|
filtrTrtmfctYn: string; //여과등처리시설유무
|
|
archArea: number; //건축연면적
|
|
dtfcltCpct: number; //처리용량(저류조용량)
|
|
wtrUsqty: number; //연간사용량
|
|
utztnUsgCd: string; //이용용도코드
|
|
anlOperCst: number; //연간운영비
|
|
annRnwtQty: number; //물사용량
|
|
jungsudo: number; //중수도이용량
|
|
dachae: number; //대체수이용량
|
|
lndwtr: number; //조경용수
|
|
cleanToilUswtr: number; //청소화장실용수
|
|
resn: number; //세척살수용수
|
|
farmUswtr: number; //농업용수
|
|
indstUswtr: number; //공업용수
|
|
hydUswtr: number; //친수용수
|
|
ithlEtcUswtr: number; //기타
|
|
tmp: number; //개소
|
|
guideStats: GuideStatProps[];
|
|
};
|
|
|
|
export type GuideStatProps = {
|
|
utztnUsgCd: string;
|
|
splyUswtrUtztnQnt: number;
|
|
ruseFcltUtztnQnt: number;
|
|
};
|
|
|
|
type ExcelType = {
|
|
[key: string]: string | number | undefined;
|
|
};
|
|
|
|
const excelDownList: ExcelType[] = [];
|
|
|
|
const fetchRainStatList = async (year: string) => {
|
|
const res = await getFetch(fetchType.WR, `/reuseChk/rainy/stat/${year}`);
|
|
return res;
|
|
};
|
|
|
|
type rainStatActions = {
|
|
searchRainStatList: (year: string, city: SelectDataType[]) => void;
|
|
};
|
|
|
|
export type rainStatState = {
|
|
rainStat: {
|
|
rainStatHeadList: TableUpperProps[];
|
|
rainStatList: RainStatProps[];
|
|
excelList: ExcelType[];
|
|
rainDetailList: [][];
|
|
};
|
|
};
|
|
|
|
export type rainStatType = rainStatState & rainStatActions;
|
|
|
|
export const rainStatExport: rainStatState = {
|
|
rainStat: {
|
|
rainStatHeadList: rainStatHeadListExport,
|
|
rainStatList: [],
|
|
excelList: [],
|
|
rainDetailList: [],
|
|
},
|
|
};
|
|
export const rainStatActionsExport = (
|
|
set: (fn: (state: rainStatState) => rainStatState) => void
|
|
) => {
|
|
return {
|
|
searchRainStatList: async (year: string, city: SelectDataType[]) => {
|
|
const res = await fetchRainStatList(year);
|
|
const cityArr: any[] = [];
|
|
|
|
|
|
res.filter((resFilter: RainStatProps) =>
|
|
city.some((cityCd) =>
|
|
resFilter.ctpvCd?.trim() === cityCd.val.trim()
|
|
)
|
|
)
|
|
.forEach((item: RainStatProps) => {
|
|
let obj = cityArr.find((e) => {
|
|
return e.ctpvCd == item.ctpvCd;
|
|
});
|
|
|
|
if (obj) {
|
|
obj.instlCst += item.instlCst;
|
|
obj.dtfcltCpct += item.dtfcltCpct;
|
|
obj.wtrUsqty += item.wtrUsqty;
|
|
obj.anlOperCst += item.anlOperCst;
|
|
obj.tmp += 1;
|
|
} else {
|
|
obj = {};
|
|
obj.ctpvCd = item.ctpvCd;
|
|
obj.instlCst = item.instlCst;
|
|
obj.tmp = 1;
|
|
obj.dtfcltCpct = item.dtfcltCpct;
|
|
obj.wtrUsqty = item.wtrUsqty;
|
|
obj.anlOperCst = item.anlOperCst;
|
|
|
|
cityArr.push(obj);
|
|
}
|
|
|
|
if (item.guideStats && item.guideStats.length > 0) {
|
|
item.guideStats.forEach((guide: GuideStatProps) => {
|
|
rainStatHeadListExport.forEach((headItem: TableUpperProps) => {
|
|
if (headItem.title == guide.utztnUsgCd) {
|
|
if (!obj[headItem.id] || typeof obj[headItem.id] !== "number")
|
|
obj[headItem.id] = 0;
|
|
if (typeof obj[headItem.id] === "number") {
|
|
obj[headItem.id] += guide.ruseFcltUtztnQnt;
|
|
}
|
|
}
|
|
});
|
|
});
|
|
}
|
|
});
|
|
|
|
const totalObj = {
|
|
ctpvCd: "0",
|
|
tmp: 0,
|
|
instlCst: 0, //설치비
|
|
dtfcltCpct: 0, //저류조용량
|
|
bdstUsgCd: 0, //연간사용량
|
|
lndwtr: 0, //조경용수
|
|
cleanToilUswtr: 0, //청소화장실용수
|
|
resn: 0, //세척살수용수
|
|
farmUswtr: 0, //농업용수
|
|
indstUswtr: 0, //공업용수
|
|
hydUswtr: 0, //친수용수
|
|
ithlEtcUswtr: 0, //기타
|
|
anlOperCst: 0, //연간운영비
|
|
} as any;
|
|
|
|
cityArr.forEach((item) => {
|
|
// if(item.ctpvCd === '0') return; // Skip total object if exists
|
|
totalObj.tmp += !isNaN(Number(item.tmp)) ? Number(item.tmp) : 0;
|
|
totalObj.instlCst += !isNaN(Number(item.instlCst))
|
|
? Number(item.instlCst)
|
|
: 0;
|
|
totalObj.dtfcltCpct += !isNaN(Number(item.dtfcltCpct))
|
|
? Number(item.dtfcltCpct)
|
|
: 0;
|
|
totalObj.bdstUsgCd += !isNaN(Number(item.bdstUsgCd))
|
|
? Number(item.bdstUsgCd)
|
|
: 0;
|
|
totalObj.lndwtr += !isNaN(Number(item.lndwtr))
|
|
? Number(item.lndwtr)
|
|
: 0;
|
|
totalObj.cleanToilUswtr += !isNaN(Number(item.cleanToilUswtr))
|
|
? Number(item.cleanToilUswtr)
|
|
: 0;
|
|
totalObj.resn += !isNaN(Number(item.resn)) ? Number(item.resn) : 0;
|
|
totalObj.farmUswtr += !isNaN(Number(item.farmUswtr))
|
|
? Number(item.farmUswtr)
|
|
: 0;
|
|
totalObj.indstUswtr += !isNaN(Number(item.indstUswtr))
|
|
? Number(item.indstUswtr)
|
|
: 0;
|
|
totalObj.hydUswtr += !isNaN(Number(item.hydUswtr))
|
|
? Number(item.hydUswtr)
|
|
: 0;
|
|
totalObj.ithlEtcUswtr += !isNaN(Number(item.ithlEtcUswtr))
|
|
? Number(item.ithlEtcUswtr)
|
|
: 0;
|
|
totalObj.anlOperCst += !isNaN(Number(item.anlOperCst))
|
|
? Number(item.anlOperCst)
|
|
: 0;
|
|
|
|
excelDownList.push({
|
|
ctpvCd: item.ctpvCd,
|
|
tmp: item.tmp,
|
|
instlCst: item.instlCst, //설치비
|
|
dtfcltCpct: item.dtfcltCpct, //저류조용량
|
|
bdstUsgCd: item.bdstUsgCd, //연간사용량
|
|
lndwtr: item.lndwtr, //조경용수
|
|
cleanToilUswtr: item.cleanToilUswtr, //청소화장실용수
|
|
resn: item.resn, //세척살수용수
|
|
farmUswtr: item.farmUswtr, //농업용수
|
|
indstUswtr: item.indstUswtr, //공업용수
|
|
hydUswtr: item.hydUswtr, //친수용수
|
|
ithlEtcUswtr: item.ithlEtcUswtr, //기타
|
|
anlOperCst: item.anlOperCst, //연간운영비
|
|
});
|
|
});
|
|
|
|
|
|
//상세
|
|
const rainDetailList: RainStatProps[] = [];
|
|
res.forEach((item: RainStatProps) => {
|
|
const utztnUsgArray = new Array<string>();
|
|
item.guideStats.forEach((guideStat) => {
|
|
utztnUsgArray.push(guideStat.utztnUsgCd);
|
|
});
|
|
rainDetailList.push({
|
|
...item,
|
|
utztnUsgCd: utztnUsgArray.join(", "),
|
|
});
|
|
});
|
|
const excelDetailData = excelRainStat(rainDetailList);
|
|
/* const rainStatHeadList = data.map((item:RainStatProps) => ({
|
|
...item,
|
|
ctpvCd:item.ctpvCd,
|
|
sggCd:item.sggCd,
|
|
areaNm:item.areaNm,
|
|
archArea:item.archArea,
|
|
dtfcltCpct:item.dtfcltCpct,
|
|
annRnwtQty:item.annRnwtQty,
|
|
jungsudo:item.jungsudo,
|
|
dachae:item.dachae,
|
|
way1:item.way1,
|
|
way2:item.way2,
|
|
way3:item.way3,
|
|
way4:item.way4,
|
|
way5:item.way5,
|
|
way6:item.way6,
|
|
way7:item.way7,
|
|
yearMoney:item.yearMoney,
|
|
})) */
|
|
|
|
console.log(" cityArr ", cityArr);
|
|
console.log(" excelDownList ", excelDownList);
|
|
|
|
cityArr.unshift(totalObj);
|
|
set((state: rainStatState) => ({
|
|
rainStat: {
|
|
...state.rainStat,
|
|
rainDetailList: excelDetailData as [][],
|
|
rainStatList: cityArr,
|
|
excelList: excelDownList,
|
|
},
|
|
}));
|
|
},
|
|
};
|
|
};
|