260617_01_ENH: 배정 테스트를 위해 개발 중도 커밋
This commit is contained in:
146
src/lib/gwcf/performance-status.ts
Normal file
146
src/lib/gwcf/performance-status.ts
Normal file
@@ -0,0 +1,146 @@
|
||||
import {PerformanceAssign, PerformanceFull, PerformanceMonitoringVisit, PerformanceReview, UserCompact} from "@/types/gwcf";
|
||||
import type {StatusPillVariant} from "@/components/gwcf/StatusPill";
|
||||
|
||||
export const LOCAL_GOVERNMENT_REVIEW_TYPE = 3;
|
||||
export const MONITORING_ASSIGN_TYPE = 1;
|
||||
export const WRITTEN_REVIEW_ASSIGN_TYPE = 2;
|
||||
|
||||
export type MonitoringSlot = {
|
||||
assign?: PerformanceAssign;
|
||||
user?: UserCompact;
|
||||
visit?: PerformanceMonitoringVisit;
|
||||
};
|
||||
|
||||
export type StatusDisplay = {
|
||||
label: string;
|
||||
variant: StatusPillVariant;
|
||||
};
|
||||
|
||||
export const getMonitoringSlots = (performance: Partial<PerformanceFull>): [MonitoringSlot, MonitoringSlot] => {
|
||||
const confirmedAssigns = (performance.performanceAssignList ?? [])
|
||||
.filter((assign) => assign.assignType === MONITORING_ASSIGN_TYPE && assign.assignConfirm)
|
||||
.sort((a, b) => a.id - b.id);
|
||||
|
||||
const visits = performance.performanceMonitoringVisitMap ?? {};
|
||||
|
||||
return [0, 1].map((index) => {
|
||||
const assign = confirmedAssigns[index];
|
||||
const userVisits = assign ? visits[assign.assignUser] ?? [] : [];
|
||||
const visit = assign
|
||||
? userVisits.find((item) => item.regUser === assign.assignUser) ?? userVisits[0]
|
||||
: undefined;
|
||||
|
||||
return {assign, visit};
|
||||
}) as [MonitoringSlot, MonitoringSlot];
|
||||
};
|
||||
|
||||
export const getReviewByType = (performance: Partial<PerformanceFull>, reviewType: number) => {
|
||||
const map = performance.performanceReviewMap ?? {};
|
||||
for (const [userId, reviews] of Object.entries(map)) {
|
||||
const review = reviews.find((item) => item.reviewType === reviewType);
|
||||
if (review) return {userId, review};
|
||||
}
|
||||
return undefined;
|
||||
};
|
||||
|
||||
export const getReviewRows = (performance: Partial<PerformanceFull>) => {
|
||||
return Object.entries(performance.performanceReviewMap ?? {}).flatMap(([userId, reviews]) =>
|
||||
reviews.map((review) => ({userId, review}))
|
||||
);
|
||||
};
|
||||
|
||||
export const getWrittenReviewRows = (performance: Partial<PerformanceFull>) => {
|
||||
const reviewRows = getReviewRows(performance).filter(({review}) => review.reviewType !== LOCAL_GOVERNMENT_REVIEW_TYPE);
|
||||
const reviewByUser = new Map(reviewRows.map((row) => [row.userId, row.review]));
|
||||
|
||||
const assignedUserIds = (performance.performanceAssignList ?? [])
|
||||
.filter((assign) => assign.assignType !== MONITORING_ASSIGN_TYPE)
|
||||
.map((assign) => assign.assignUser);
|
||||
|
||||
const userIds = Array.from(new Set([...assignedUserIds, ...reviewRows.map((row) => row.userId)]));
|
||||
|
||||
return userIds.map((userId) => ({
|
||||
userId,
|
||||
assign: (performance.performanceAssignList ?? []).find(
|
||||
(assign) => assign.assignType !== MONITORING_ASSIGN_TYPE && assign.assignUser === userId
|
||||
),
|
||||
review: reviewByUser.get(userId),
|
||||
}));
|
||||
};
|
||||
|
||||
export const formatDateTime = (date: Date) => {
|
||||
if (Number.isNaN(date.getTime())) return "-";
|
||||
const pad = (value: number) => String(value).padStart(2, "0");
|
||||
return `${date.getFullYear()}-${pad(date.getMonth() + 1)}-${pad(date.getDate())} ${pad(date.getHours())}:${pad(date.getMinutes())}`;
|
||||
};
|
||||
|
||||
export const getMonitoringRecordedAt = (visit?: PerformanceMonitoringVisit) => {
|
||||
if (visit?.regDt) return formatDateTime(new Date(visit.regDt));
|
||||
|
||||
const timestamp = visit?.gpsRaw?.timestamp;
|
||||
if (typeof timestamp === "number") return formatDateTime(new Date(timestamp));
|
||||
if (typeof timestamp === "string") return formatDateTime(new Date(timestamp));
|
||||
return "-";
|
||||
};
|
||||
|
||||
export const getMonitoringRecordedUser = (visit?: PerformanceMonitoringVisit) => {
|
||||
return visit?.regUser || "-";
|
||||
};
|
||||
|
||||
export const isReviewComplete = (review?: PerformanceReview) => {
|
||||
return Boolean(review?.pdfFileName || review?.pdfConvert);
|
||||
};
|
||||
|
||||
const normalizeStatusLabel = (label?: string) => label?.replace(/\s/g, "") ?? "";
|
||||
|
||||
export const getReviewStatusDisplay = (
|
||||
label?: string,
|
||||
review?: PerformanceReview,
|
||||
assigned = Boolean(review)
|
||||
): StatusDisplay => {
|
||||
if (!assigned) return {label: "미배치", variant: "danger"};
|
||||
|
||||
const normalized = normalizeStatusLabel(label);
|
||||
if (normalized.includes("완료")) return {label: label || "완료", variant: "done"};
|
||||
if (normalized.includes("진행")) return {label: label || "진행중", variant: "inprogress"};
|
||||
|
||||
return {label: label || "미진행", variant: "pending"};
|
||||
};
|
||||
|
||||
export const getWrittenReviewerSimpleReviewStatusDisplay = (
|
||||
review?: PerformanceReview,
|
||||
allowInProgress = false,
|
||||
label?: string
|
||||
): StatusDisplay => {
|
||||
if (isReviewComplete(review)) return {label: "완료", variant: "done"};
|
||||
|
||||
if (allowInProgress && normalizeStatusLabel(label).includes("진행")) {
|
||||
return {label: "진행중", variant: "inprogress"};
|
||||
}
|
||||
|
||||
return {label: "미완료", variant: "pending"};
|
||||
};
|
||||
|
||||
export const getWrittenReviewerSimpleMonitoringStatusDisplay = (slot?: MonitoringSlot): StatusDisplay => {
|
||||
return slot?.visit
|
||||
? {label: "완료", variant: "done"}
|
||||
: {label: "미완료", variant: "pending"};
|
||||
};
|
||||
|
||||
export const getMonitoringStatusDisplay = (label?: string, slot?: MonitoringSlot): StatusDisplay => {
|
||||
if (!slot?.assign) return {label: "미배치", variant: "danger"};
|
||||
if (!slot.visit) return {label: "미진행", variant: "pending"};
|
||||
|
||||
const normalized = normalizeStatusLabel(label);
|
||||
if (normalized.includes("완료")) return {label: label || "완료", variant: "done"};
|
||||
if (normalized.includes("도착")) return {label: label || "도착", variant: "arrived"};
|
||||
if (normalized.includes("출발")) return {label: label || "출발", variant: "departed"};
|
||||
|
||||
return {label: label || "미진행", variant: "pending"};
|
||||
};
|
||||
|
||||
export const getAssignStatusDisplay = (confirmed: boolean): StatusDisplay => {
|
||||
return confirmed
|
||||
? {label: "확정", variant: "done"}
|
||||
: {label: "요청", variant: "inprogress"};
|
||||
};
|
||||
119
src/lib/gwcf/view.ts
Normal file
119
src/lib/gwcf/view.ts
Normal file
@@ -0,0 +1,119 @@
|
||||
import {Code, PerformanceCompact, PerformanceFull, UserFull} from "@/types/gwcf";
|
||||
import {CodeGroup} from "@/query/code";
|
||||
|
||||
export const ROLE = {
|
||||
ADMIN: 1001,
|
||||
RESEARCHER: 1002,
|
||||
FIELD_INSPECTOR: 1003,
|
||||
CONTACT_AGENT: 1004,
|
||||
FOUNDATION: 2011,
|
||||
WRITTEN_REVIEWER: 2021,
|
||||
MONITORING: 9003,
|
||||
} as const;
|
||||
|
||||
export const getRoleGroup = (role?: number | null) => {
|
||||
if (!role) return 0;
|
||||
return Math.floor(role / 1000) * 1000;
|
||||
};
|
||||
|
||||
export const isInternalRole = (role?: number | null) => getRoleGroup(role) === 1000;
|
||||
export const isExternalRole = (role?: number | null) => getRoleGroup(role) === 2000;
|
||||
export const isMonitoringRole = (role?: number | null) => getRoleGroup(role) === 9000;
|
||||
export const isFoundationRole = (role?: number | null) => role === ROLE.FOUNDATION;
|
||||
export const isWrittenReviewerRole = (role?: number | null) => role === ROLE.WRITTEN_REVIEWER;
|
||||
|
||||
export const getCodeLabel = (
|
||||
codes: Partial<Record<CodeGroup, Code[]>>,
|
||||
group: CodeGroup,
|
||||
value: number | string | undefined | null
|
||||
) => {
|
||||
if (value === undefined || value === null || value === "") return "";
|
||||
const numericValue = Number(value);
|
||||
const found = codes[group]?.find((code) => code.codeValue === numericValue);
|
||||
return found?.codeLabel ?? String(value);
|
||||
};
|
||||
|
||||
export const getDetailValue = (
|
||||
detail: Record<string, string> | undefined,
|
||||
keys: string[],
|
||||
fallback = ""
|
||||
) => {
|
||||
if (!detail) return fallback;
|
||||
for (const key of keys) {
|
||||
const value = detail[key];
|
||||
if (value !== undefined && value !== "") return value;
|
||||
}
|
||||
return fallback;
|
||||
};
|
||||
|
||||
export const includesText = (value: unknown, keyword: string) => {
|
||||
if (!keyword) return true;
|
||||
return String(value ?? "").toLowerCase().includes(keyword.toLowerCase());
|
||||
};
|
||||
|
||||
export const filterPerformance = (
|
||||
item: PerformanceCompact | PerformanceFull,
|
||||
filters: {
|
||||
businessType?: string | string[];
|
||||
genre?: string | string[];
|
||||
area?: string | string[];
|
||||
monitoringDate?: string;
|
||||
keyword?: string;
|
||||
}
|
||||
) => {
|
||||
const keyword = filters.keyword?.trim() ?? "";
|
||||
const schedule = item.performanceMonitoringSchedule;
|
||||
const matches = (filter: string | string[] | undefined, value: number | string) => {
|
||||
if (!filter || filter.length === 0) return true;
|
||||
const values = Array.isArray(filter) ? filter : [filter];
|
||||
return values.includes(String(value));
|
||||
};
|
||||
|
||||
return (
|
||||
matches(filters.businessType, item.businessType) &&
|
||||
matches(filters.genre, item.performanceGenre) &&
|
||||
matches(filters.area, item.performanceArea) &&
|
||||
(!filters.monitoringDate || schedule?.monitoringDate === filters.monitoringDate) &&
|
||||
(
|
||||
includesText(item.id, keyword) ||
|
||||
includesText(item.performanceName, keyword) ||
|
||||
includesText(item.artistName, keyword)
|
||||
)
|
||||
);
|
||||
};
|
||||
|
||||
export const filterUser = (
|
||||
user: UserFull,
|
||||
filters: {
|
||||
area?: string | string[];
|
||||
gender?: string | string[];
|
||||
genre?: string | string[];
|
||||
keyword?: string;
|
||||
}
|
||||
) => {
|
||||
const detail = user.userDetail ?? {};
|
||||
const area = getDetailValue(detail, ["area", "userArea", "region"]);
|
||||
const gender = getDetailValue(detail, ["gender", "userGender"]);
|
||||
const genre = getDetailValue(detail, ["genre", "performanceGenre", "reviewGenre"]);
|
||||
const keyword = filters.keyword?.trim() ?? "";
|
||||
const matches = (filter: string | string[] | undefined, value: string) => {
|
||||
if (!filter || filter.length === 0) return true;
|
||||
const values = Array.isArray(filter) ? filter : [filter];
|
||||
return values.includes(value);
|
||||
};
|
||||
|
||||
return (
|
||||
matches(filters.area, area) &&
|
||||
matches(filters.gender, gender) &&
|
||||
matches(filters.genre, genre) &&
|
||||
(
|
||||
includesText(user.userId, keyword) ||
|
||||
includesText(user.userName, keyword) ||
|
||||
includesText(user.userTeam, keyword) ||
|
||||
includesText(user.userCmpn, keyword) ||
|
||||
includesText(user.memo, keyword) ||
|
||||
includesText(getDetailValue(detail, ["tel", "phone", "userTel"]), keyword) ||
|
||||
includesText(getDetailValue(detail, ["email", "userEmail"]), keyword)
|
||||
)
|
||||
);
|
||||
};
|
||||
Reference in New Issue
Block a user