Files
frontend/apps/as/src/pages/sewer-bsc-plan/lib/payload-utils.ts
T

177 lines
6.1 KiB
TypeScript

import type {
EsntlAtchFileItem,
EsntlAtchFileMngTreeResponseDto,
SewerBscPlanApplySaveRequestDto,
SewerBscPlanDetResponseDto,
SewerBscPlanSplmntDmndItem,
} from "@/entities/sewer-bsc-plan";
import type { SplmntDmndDialogConfirmPayload } from "@/widgets/pbadms-sprt";
import type { ChecklistFormState, ReviewStepCode } from "../model/view-types";
import { toCklstSaveDto } from "./checklist-utils";
import { recalcFnrsCstSumAmt } from "./fnrs-cst-form-utils";
import { type ReviewOpinionGetFormDataResult, toRvwOpnnSaveDto } from "./review-opinion-utils";
export function toEsntlAtchFileSaveDto(
esntlFileList: EsntlAtchFileMngTreeResponseDto[],
): EsntlAtchFileItem[] {
const esntlMap = new Map<string, string>();
for (const item of esntlFileList) {
if (!item.esntlAtchFileId || !item.atflCd) continue;
esntlMap.set(item.esntlAtchFileId, item.atflCd);
}
return Array.from(esntlMap.entries()).map(([esntlAtchFileId, atchFileGroupId]) => ({
esntlAtchFileId,
atchFileGroupId,
}));
}
export function buildSavePayload(
data: SewerBscPlanDetResponseDto,
checklistFormState: ChecklistFormState,
reviewStep: ReviewStepCode,
prgrsSttsComCd: string,
): SewerBscPlanApplySaveRequestDto {
const detDto = data.detDto;
const dtl = data.activeDtlDto;
if (!detDto) {
throw new Error("상세 정보(detDto)가 없습니다.");
}
const cklstResultRows = data.cklstResultRows ?? [];
const esntlFileList = data.esntlFileList ?? [];
return {
sewerBscPlan: {
sewerBscPlanDocNo: detDto.sewerBscPlanDocNo,
admdstCd: detDto.admdstCd,
envoSeComCd: detDto.envoSeComCd,
sewerBscPlanSeComCd: detDto.sewerBscPlanSeComCd,
sewerBscPlanNm: detDto.sewerBscPlanNm,
taskSeComCd: detDto.taskSeComCd,
prgrsSttsComCd,
},
sewerBscPlanDtl: {
sewerBscPlanDocNo: detDto.sewerBscPlanDocNo,
chgCycl: dtl?.chgCycl ?? detDto.chgCycl,
aplcntNm: dtl?.aplcntNm,
aplcntMblTelno: dtl?.aplcntMblTelno,
aplcntOgdpNm: dtl?.aplcntOgdpNm,
aplcntEmlAddr: dtl?.aplcntEmlAddr,
dsgnrNm: dtl?.dsgnrNm,
dsgnrTelno: dtl?.dsgnrTelno,
dsgnrOgdpNm: dtl?.dsgnrOgdpNm,
dsgnrEmlAddr: dtl?.dsgnrEmlAddr,
planYr: dtl?.planYr,
crtrYr: dtl?.crtrYr,
bizOtlnCn: dtl?.bizOtlnCn,
frlvlGoalYr: dtl?.frlvlGoalYr,
sclvlGoalYr: dtl?.sclvlGoalYr,
thlvlGoalYr: dtl?.thlvlGoalYr,
folvlGoalYr: dtl?.folvlGoalYr,
atchFileGroupId: dtl?.atchFileGroupId,
},
sewerBscPlanOtlnList: (data.otlnList ?? []).map((item) => ({
planStpNo: item.planStpNo,
sewerPlanPpltnCnt: item.sewerPlanPpltnCnt,
sewerPrcsPpltnCnt: item.sewerPrcsPpltnCnt,
sewerPsplyRt: item.sewerPsplyRt,
})),
bizCstList: (data.bizCstList ?? []).map((item) => ({
planStpNo: item.planStpNo,
acntgSeCd: item.acntgSeCd,
cstrnAmt: item.cstrnAmt,
})),
fnrsCstList: (data.fnrsCstList ?? []).map((item) =>
recalcFnrsCstSumAmt({
planStpNo: item.planStpNo ?? 1,
gvexpAmt: item.gvexpAmt ?? 0,
lcexpAmt: item.lcexpAmt ?? 0,
orgprBdchgAmt: item.orgprBdchgAmt ?? 0,
etcAmt: item.etcAmt ?? 0,
sumAmt: item.sumAmt ?? 0,
}),
),
sewerBscPlanTmplntList: (data.tmplntList ?? []).map((item) => ({
swtrmtFcltCd: item.swtrmtFcltCd,
atchFileGroupId: item.atchFileGroupId,
sewerBscPlanTmplntDtlList: (item.sewerBscPlanTmplntDtlList ?? []).map((dtlItem) => ({
planStpNo: dtlItem.planStpNo,
swtrmtFcltCd: dtlItem.swtrmtFcltCd ?? item.swtrmtFcltCd,
prcsZoneArea: dtlItem.prcsZoneArea,
swtrmtPpltnCnt: dtlItem.swtrmtPpltnCnt,
planSwqty: dtlItem.planSwqty,
fcltCpct: dtlItem.fcltCpct,
sprsysDrtwPplLen: dtlItem.sprsysDrtwPplLen,
sprsysExlnPplLen: dtlItem.sprsysExlnPplLen,
cbsysPplLen: dtlItem.cbsysPplLen,
icptgPplLen: dtlItem.icptgPplLen,
drgCnt: dtlItem.drgCnt,
drtwRlyPumpCnt: dtlItem.drtwRlyPumpCnt,
drtwPumpCnt: dtlItem.drtwPumpCnt,
exlnPumpCnt: dtlItem.exlnPumpCnt,
})),
})),
cklstResultList: toCklstSaveDto(cklstResultRows, checklistFormState, reviewStep),
esntlAtchFileList: toEsntlAtchFileSaveDto(esntlFileList),
};
}
export function buildTechReviewReplyPayload(
data: SewerBscPlanDetResponseDto,
checklistFormState: ChecklistFormState,
reviewStep: ReviewStepCode,
prgrsSttsComCd: string,
techReViewSaveCd: string,
reviewOpinionFormData?: ReviewOpinionGetFormDataResult | null,
opnrNm?: string,
): SewerBscPlanApplySaveRequestDto {
return {
...buildSavePayload(data, checklistFormState, reviewStep, prgrsSttsComCd),
techReViewSaveCd,
rvwStpCd: reviewStep,
rvwOpnnList: toRvwOpnnSaveDto(data, reviewOpinionFormData, opnrNm),
};
}
export function buildSupplementReqPayload(
data: SewerBscPlanDetResponseDto,
payload: SplmntDmndDialogConfirmPayload,
checklistFormState: ChecklistFormState,
): SewerBscPlanApplySaveRequestDto {
const existingItems: SewerBscPlanSplmntDmndItem[] = (data.splmntDmndList ?? []).map((item) =>
toSplmntDmndSaveItem(item),
);
const newItems: SewerBscPlanSplmntDmndItem[] = payload.items.map((item) => ({
splmntDmndSn: null,
splmntArtclComCd: item.splmntArtclComCd,
splmntDmndCn: item.splmntDmndCn,
splmntDmndAtchFileGroupId: item.splmntDmndAtchFileGroupId,
cmptnYn: "N",
}));
return {
...buildSavePayload(data, checklistFormState, "LOCAL", "SL"),
splmntDmndList: [...existingItems, ...newItems],
};
}
export function toSplmntDmndSaveItem(item: SewerBscPlanSplmntDmndItem): SewerBscPlanSplmntDmndItem {
return {
splmntDmndSn: item.splmntDmndSn,
splmntArtclComCd: item.splmntArtclComCd,
splmntDmndCn: item.splmntDmndCn,
splmntDmndDt: item.splmntDmndDt,
splmntDmndAtchFileGroupId: item.splmntDmndAtchFileGroupId,
splmntCn: item.splmntCn,
splmntPicNm: item.splmntPicNm,
splmntCmptnDt: item.splmntCmptnDt,
splmntAtchFileGroupId: item.splmntAtchFileGroupId,
cmptnYn: item.cmptnYn,
};
}