190 lines
5.8 KiB
TypeScript
190 lines
5.8 KiB
TypeScript
export const SEWER_BSC_PLAN_VIEW_BUTTON_ACTION = {
|
|
strg: "strg",
|
|
aply: "aply",
|
|
del: "del",
|
|
rvwRply: "rvwRply",
|
|
rqstTechRvw: "rqstTechRvw",
|
|
dsgntRvwr: "dsgntRvwr",
|
|
rvwStrg: "rvwStrg",
|
|
rvwCmptn: "rvwCmptn",
|
|
dmndSplmnt: "dmndSplmnt",
|
|
atrzAprv: "atrzAprv",
|
|
atrzRply: "atrzRply",
|
|
} as const;
|
|
|
|
export type SewerBscPlanViewButtonAction =
|
|
(typeof SEWER_BSC_PLAN_VIEW_BUTTON_ACTION)[keyof typeof SEWER_BSC_PLAN_VIEW_BUTTON_ACTION];
|
|
|
|
const ROLE_STATUS_BUTTON_ACTIONS: Record<string, Record<string, SewerBscPlanViewButtonAction[]>> = {
|
|
ROLE_USER05: {
|
|
"": [
|
|
SEWER_BSC_PLAN_VIEW_BUTTON_ACTION.strg,
|
|
SEWER_BSC_PLAN_VIEW_BUTTON_ACTION.aply,
|
|
SEWER_BSC_PLAN_VIEW_BUTTON_ACTION.del,
|
|
],
|
|
SV: [
|
|
SEWER_BSC_PLAN_VIEW_BUTTON_ACTION.strg,
|
|
SEWER_BSC_PLAN_VIEW_BUTTON_ACTION.aply,
|
|
SEWER_BSC_PLAN_VIEW_BUTTON_ACTION.del,
|
|
],
|
|
},
|
|
ROLE_USER03: {
|
|
LE: [SEWER_BSC_PLAN_VIEW_BUTTON_ACTION.rvwRply, SEWER_BSC_PLAN_VIEW_BUTTON_ACTION.rqstTechRvw],
|
|
TP: [SEWER_BSC_PLAN_VIEW_BUTTON_ACTION.rvwRply],
|
|
},
|
|
};
|
|
|
|
const ROLE_USER01_ATRZ_STATUS_CODES = ["ER", "SL", "TE"] as const;
|
|
|
|
const ROLE_USER01_ATRZ_STATUS_ACTIONS: Record<
|
|
string,
|
|
Record<string, SewerBscPlanViewButtonAction[]>
|
|
> = {
|
|
ER: {
|
|
ATRZ01: [SEWER_BSC_PLAN_VIEW_BUTTON_ACTION.dsgntRvwr],
|
|
},
|
|
SL: {},
|
|
TE: {
|
|
ATRZ02: [
|
|
SEWER_BSC_PLAN_VIEW_BUTTON_ACTION.rvwStrg,
|
|
SEWER_BSC_PLAN_VIEW_BUTTON_ACTION.rvwCmptn,
|
|
SEWER_BSC_PLAN_VIEW_BUTTON_ACTION.dmndSplmnt,
|
|
],
|
|
ATRZ03: [SEWER_BSC_PLAN_VIEW_BUTTON_ACTION.atrzAprv],
|
|
ATRZ99: [SEWER_BSC_PLAN_VIEW_BUTTON_ACTION.atrzRply],
|
|
},
|
|
};
|
|
|
|
/**
|
|
* Fork-Join (병렬 결재 6인 체제: 관로2 + 시설2 + 정책병합2) 전용 상태별 버튼 액션 매핑
|
|
* - Stage 2: 관로/시설 실무검토자(ATRZ02), 부서승인자(ATRZ03)
|
|
* - Stage 3: 정책총괄 종합병합자(ATRZ04), 최종회신자(ATRZ99)
|
|
* - 하수도기본계획은 100% 무조건 Fork-Join 결재 라인으로 동작
|
|
*/
|
|
const ROLE_USER01_FORK_JOIN_ATRZ_STATUS_ACTIONS: Record<
|
|
string,
|
|
Record<string, SewerBscPlanViewButtonAction[]>
|
|
> = {
|
|
ER: {
|
|
ATRZ01: [SEWER_BSC_PLAN_VIEW_BUTTON_ACTION.dsgntRvwr],
|
|
},
|
|
SL: {},
|
|
TE: {
|
|
ATRZ02: [
|
|
SEWER_BSC_PLAN_VIEW_BUTTON_ACTION.rvwStrg,
|
|
SEWER_BSC_PLAN_VIEW_BUTTON_ACTION.rvwCmptn,
|
|
SEWER_BSC_PLAN_VIEW_BUTTON_ACTION.dmndSplmnt,
|
|
],
|
|
ATRZ03: [SEWER_BSC_PLAN_VIEW_BUTTON_ACTION.atrzRply],
|
|
ATRZ04: [SEWER_BSC_PLAN_VIEW_BUTTON_ACTION.atrzAprv],
|
|
ATRZ99: [SEWER_BSC_PLAN_VIEW_BUTTON_ACTION.atrzRply],
|
|
},
|
|
TP: {},
|
|
};
|
|
|
|
function resolveButtonConfigs(
|
|
actions: SewerBscPlanViewButtonAction[],
|
|
): SewerBscPlanViewButtonAction[] {
|
|
return actions.map((action) => SEWER_BSC_PLAN_VIEW_BUTTON_ACTION[action]);
|
|
}
|
|
|
|
const PENDING_APPROVAL_ACTIONS = new Set<SewerBscPlanViewButtonAction>([
|
|
SEWER_BSC_PLAN_VIEW_BUTTON_ACTION.rvwStrg,
|
|
SEWER_BSC_PLAN_VIEW_BUTTON_ACTION.dmndSplmnt,
|
|
SEWER_BSC_PLAN_VIEW_BUTTON_ACTION.rvwCmptn,
|
|
SEWER_BSC_PLAN_VIEW_BUTTON_ACTION.atrzAprv,
|
|
SEWER_BSC_PLAN_VIEW_BUTTON_ACTION.atrzRply,
|
|
]);
|
|
|
|
export interface GetButtonConfigsOptions {
|
|
hasPendingApprovalRequest?: boolean;
|
|
isForkJoin?: boolean;
|
|
branchSeCd?: string;
|
|
branchSttsCd?: string;
|
|
}
|
|
|
|
function resolveRoleUser01AtrzButtonActions(
|
|
prgrsSttsComCd: string,
|
|
atrzSeComCdList: string[],
|
|
options?: GetButtonConfigsOptions,
|
|
): SewerBscPlanViewButtonAction[] {
|
|
let effectiveStatus = prgrsSttsComCd;
|
|
const isForkJoin = options?.isForkJoin ?? true;
|
|
|
|
if (isForkJoin && options?.branchSttsCd) {
|
|
switch (options.branchSttsCd) {
|
|
case "SUPPLEMENT":
|
|
// 본인 브랜치가 보완요청 중이면 검토/승인 버튼 숨김
|
|
return [];
|
|
case "COMPLETED":
|
|
// 본인 브랜치 승인 완료 후 타 브랜치 대기 중이면 검토/승인 버튼 숨김
|
|
return [];
|
|
case "WAITING":
|
|
return [];
|
|
case "IN_PROGRESS":
|
|
effectiveStatus = "TE";
|
|
break;
|
|
}
|
|
}
|
|
|
|
const atrzStatusMap = isForkJoin
|
|
? ROLE_USER01_FORK_JOIN_ATRZ_STATUS_ACTIONS[effectiveStatus]
|
|
: ROLE_USER01_ATRZ_STATUS_ACTIONS[effectiveStatus];
|
|
if (!atrzStatusMap || atrzSeComCdList.length === 0) return [];
|
|
|
|
const seen = new Set<SewerBscPlanViewButtonAction>();
|
|
const actions: SewerBscPlanViewButtonAction[] = [];
|
|
|
|
for (const atrzSeComCd of atrzSeComCdList) {
|
|
const mappedActions = atrzStatusMap[atrzSeComCd];
|
|
if (!mappedActions) continue;
|
|
|
|
for (const action of mappedActions) {
|
|
if (seen.has(action)) continue;
|
|
seen.add(action);
|
|
actions.push(action);
|
|
}
|
|
}
|
|
|
|
return actions.filter((action) => {
|
|
const needsPendingApproval = PENDING_APPROVAL_ACTIONS.has(action);
|
|
if (needsPendingApproval && options?.hasPendingApprovalRequest === false) return false;
|
|
return true;
|
|
});
|
|
}
|
|
|
|
export function needsRoleUser01AtrzResolve(
|
|
dtlInstCd: string | undefined,
|
|
prgrsSttsComCd: string,
|
|
): boolean {
|
|
return (
|
|
dtlInstCd === "ROLE_USER01" &&
|
|
ROLE_USER01_ATRZ_STATUS_CODES.includes(
|
|
prgrsSttsComCd as (typeof ROLE_USER01_ATRZ_STATUS_CODES)[number],
|
|
)
|
|
);
|
|
}
|
|
|
|
export function getButtonConfigs(
|
|
dtlInstCd: string | undefined,
|
|
prgrsSttsComCd: string,
|
|
atrzSeComCdList?: string[],
|
|
options?: GetButtonConfigsOptions,
|
|
): SewerBscPlanViewButtonAction[] {
|
|
if (!dtlInstCd) return [];
|
|
|
|
if (needsRoleUser01AtrzResolve(dtlInstCd, prgrsSttsComCd)) {
|
|
return resolveButtonConfigs(
|
|
resolveRoleUser01AtrzButtonActions(prgrsSttsComCd, atrzSeComCdList ?? [], options),
|
|
);
|
|
}
|
|
|
|
const statusMap = ROLE_STATUS_BUTTON_ACTIONS[dtlInstCd];
|
|
if (!statusMap) return [];
|
|
|
|
const actions = statusMap[prgrsSttsComCd];
|
|
if (!actions) return [];
|
|
|
|
return resolveButtonConfigs(actions);
|
|
}
|