Merge pull request '쿼리문 덜복잡해도 작성되게 수정' (#161) from lhj into main
Reviewed-on: http://39.117.244.52:3000/kjs/ERP-node/pulls/161
This commit is contained in:
commit
ca2904dfc4
|
|
@ -240,31 +240,77 @@ export default function CustomMetricTestWidget({ element }: CustomMetricTestWidg
|
|||
문자열: stringColumns,
|
||||
});
|
||||
|
||||
// 🆕 각 행을 메트릭 카드로 표시 (숫자 컬럼 여부와 관계없이)
|
||||
console.log(`✅ [${sourceName}] 각 행을 메트릭 카드로 변환`);
|
||||
// 🆕 자동 집계 로직: 집계 컬럼 이름으로 판단 (count, 개수, sum, avg 등)
|
||||
const isAggregated = numericColumns.some((col) =>
|
||||
/count|개수|sum|합계|avg|평균|min|최소|max|최대|total|전체/i.test(col)
|
||||
);
|
||||
|
||||
rows.forEach((row, index) => {
|
||||
// 라벨: 첫 번째 컬럼 (보통 ID나 이름)
|
||||
const labelField = columns[0];
|
||||
const label = String(row[labelField] || `항목 ${index + 1}`);
|
||||
if (isAggregated && numericColumns.length > 0) {
|
||||
// 집계 컬럼이 있으면 이미 집계된 데이터로 판단 (GROUP BY 결과)
|
||||
console.log(`✅ [${sourceName}] 집계된 데이터로 판단 (집계 컬럼 발견: ${numericColumns.join(", ")})`);
|
||||
|
||||
// 값: 숫자 컬럼이 있으면 사용, 없으면 행 번호
|
||||
const valueField = numericColumns.length > 0 ? numericColumns[0] : null;
|
||||
const value = valueField ? Number(row[valueField]) || 0 : index + 1;
|
||||
rows.forEach((row, index) => {
|
||||
// 라벨: 첫 번째 문자열 컬럼
|
||||
const labelField = stringColumns[0] || columns[0];
|
||||
const label = String(row[labelField] || `항목 ${index + 1}`);
|
||||
|
||||
console.log(` [${sourceName}] 메트릭: ${label} = ${value}`);
|
||||
// 값: 첫 번째 숫자 컬럼
|
||||
const valueField = numericColumns[0];
|
||||
const value = Number(row[valueField]) || 0;
|
||||
|
||||
console.log(` [${sourceName}] 메트릭: ${label} = ${value}`);
|
||||
|
||||
allMetrics.push({
|
||||
label: label,
|
||||
value: value,
|
||||
field: valueField,
|
||||
aggregation: "custom",
|
||||
color: colors[allMetrics.length % colors.length],
|
||||
sourceName: sourceName,
|
||||
rawData: [row],
|
||||
});
|
||||
});
|
||||
} else {
|
||||
// 숫자 컬럼이 없으면 자동 집계 (마지막 컬럼 기준)
|
||||
console.log(`✅ [${sourceName}] 자동 집계 모드 (숫자 컬럼 없음)`);
|
||||
|
||||
// 마지막 컬럼을 집계 기준으로 사용
|
||||
const aggregateField = columns[columns.length - 1];
|
||||
console.log(` [${sourceName}] 집계 기준 컬럼: ${aggregateField}`);
|
||||
|
||||
// 해당 컬럼의 값별로 카운트
|
||||
const countMap = new Map<string, number>();
|
||||
rows.forEach((row) => {
|
||||
const value = String(row[aggregateField] || "기타");
|
||||
countMap.set(value, (countMap.get(value) || 0) + 1);
|
||||
});
|
||||
|
||||
// 카운트 결과를 메트릭으로 변환
|
||||
countMap.forEach((count, label) => {
|
||||
console.log(` [${sourceName}] 자동 집계: ${label} = ${count}개`);
|
||||
|
||||
allMetrics.push({
|
||||
label: label,
|
||||
value: count,
|
||||
field: aggregateField,
|
||||
aggregation: "count",
|
||||
color: colors[allMetrics.length % colors.length],
|
||||
sourceName: sourceName,
|
||||
rawData: rows.filter((row) => String(row[aggregateField]) === label),
|
||||
});
|
||||
});
|
||||
|
||||
// 전체 개수도 추가
|
||||
allMetrics.push({
|
||||
label: label,
|
||||
value: value,
|
||||
field: valueField || labelField,
|
||||
aggregation: "custom",
|
||||
label: "전체",
|
||||
value: rows.length,
|
||||
field: "count",
|
||||
aggregation: "count",
|
||||
color: colors[allMetrics.length % colors.length],
|
||||
sourceName: sourceName,
|
||||
rawData: [row], // 🆕 해당 행만 저장 (상세보기용)
|
||||
fullData: rows, // 🆕 전체 데이터도 저장
|
||||
rawData: rows,
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
// 🆕 숫자 컬럼이 없을 때의 기존 로직은 주석 처리
|
||||
if (false) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue