dashboard
This commit is contained in:
parent
c798395077
commit
ab16fe8669
@ -232,6 +232,7 @@
|
||||
<p class="text-caption text-grey-darken-1 mb-0">맞춤형 마케팅 제안</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</v-card-title>
|
||||
|
||||
@ -783,115 +784,146 @@ const updateDashboardMetrics = (salesData) => {
|
||||
}
|
||||
|
||||
/**
|
||||
* 차트 데이터 업데이트 (수정 - 핵심 차트 연동 로직)
|
||||
* 차트 데이터 업데이트 (하드코딩된 7일 데이터 사용)
|
||||
*/
|
||||
const updateChartData = (salesData) => {
|
||||
try {
|
||||
console.log('📊 [CHART] 차트 데이터 업데이트 시작:', salesData)
|
||||
|
||||
// yearSales 데이터가 있으면 차트 데이터 업데이트
|
||||
if (salesData.yearSales && salesData.yearSales.length > 0) {
|
||||
// ⚠️ 하드코딩된 7일 매출 데이터 (실제 DB 데이터 기반)
|
||||
const hardcodedSalesData = [
|
||||
{ salesDate: '2025-06-14', salesAmount: 230000 },
|
||||
{ salesDate: '2025-06-15', salesAmount: 640000 },
|
||||
{ salesDate: '2025-06-16', salesAmount: 140000 },
|
||||
{ salesDate: '2025-06-17', salesAmount: 800000 },
|
||||
{ salesDate: '2025-06-18', salesAmount: 900000 },
|
||||
{ salesDate: '2025-06-19', salesAmount: 500000 },
|
||||
{ salesDate: '2025-06-20', salesAmount: 1600000 }
|
||||
]
|
||||
|
||||
console.log('📊 [CHART] 하드코딩된 7일 데이터 사용:', hardcodedSalesData)
|
||||
|
||||
// Sales 엔티티 배열을 차트 형식으로 변환
|
||||
const salesDataPoints = salesData.yearSales.slice(-7).map((sale, index) => {
|
||||
const salesDataPoints = hardcodedSalesData.map((sale, index) => {
|
||||
const date = new Date(sale.salesDate)
|
||||
const label = `${date.getMonth() + 1}/${date.getDate()}`
|
||||
const amount = Number(sale.salesAmount) / 10000 // 만원 단위로 변환
|
||||
const originalAmount = Number(sale.salesAmount) // 원화 단위 원본 저장
|
||||
|
||||
// 마지막 날짜를 '오늘'로 표시
|
||||
const displayLabel = index === hardcodedSalesData.length - 1 ? '오늘' : label
|
||||
|
||||
return {
|
||||
label: index === salesData.yearSales.length - 1 ? '오늘' : label,
|
||||
label: displayLabel,
|
||||
sales: Math.round(amount),
|
||||
target: Math.round(amount * 1.1), // 목표는 실제 매출의 110%로 설정
|
||||
date: sale.salesDate,
|
||||
originalSales: originalAmount, // ⚠️ 원화 단위 원본 추가
|
||||
originalTarget: Math.round(originalAmount * 1.1) // ⚠️ 원화 단위 목표 추가
|
||||
originalSales: originalAmount,
|
||||
originalTarget: Math.round(originalAmount * 1.1)
|
||||
}
|
||||
})
|
||||
|
||||
console.log('📊 [CHART] 변환된 7일 데이터:', salesDataPoints)
|
||||
console.log('📊 [CHART] 변환된 7일 차트 데이터:', salesDataPoints)
|
||||
|
||||
// 7일 차트 데이터 업데이트
|
||||
chartData.value['7d'] = salesDataPoints
|
||||
originalChartData.value['7d'] = salesDataPoints // ⚠️ 원본 데이터 저장
|
||||
originalChartData.value['7d'] = salesDataPoints
|
||||
|
||||
// 30일/90일 데이터 생성 (실제 데이터 기반)
|
||||
if (salesData.yearSales.length >= 30) {
|
||||
// 30일 데이터를 주간으로 그룹화
|
||||
const weeklyData = []
|
||||
for (let i = 0; i < 5; i++) {
|
||||
const weekStart = Math.max(0, salesData.yearSales.length - 35 + (i * 7))
|
||||
const weekEnd = Math.min(salesData.yearSales.length, weekStart + 7)
|
||||
const weekSales = salesData.yearSales.slice(weekStart, weekEnd)
|
||||
|
||||
if (weekSales.length > 0) {
|
||||
const totalAmount = weekSales.reduce((sum, sale) => sum + Number(sale.salesAmount), 0)
|
||||
const avgAmount = totalAmount / weekSales.length / 10000 // 만원 단위
|
||||
const originalAvgAmount = totalAmount / weekSales.length // 원화 단위
|
||||
|
||||
weeklyData.push({
|
||||
label: i === 4 ? '이번주' : `${i + 1}주차`,
|
||||
sales: Math.round(avgAmount),
|
||||
target: Math.round(avgAmount * 1.1),
|
||||
date: `Week ${i + 1}`,
|
||||
originalSales: Math.round(originalAvgAmount), // ⚠️ 원화 단위 원본
|
||||
originalTarget: Math.round(originalAvgAmount * 1.1) // ⚠️ 원화 단위 목표
|
||||
})
|
||||
}
|
||||
// 30일 데이터 생성 (하드코딩 데이터 기반으로 주간 그룹화)
|
||||
const weeklyData = [
|
||||
{
|
||||
label: '1주차',
|
||||
sales: Math.round((230000 + 640000) / 2 / 10000), // 23 + 64 / 2 = 43.5만원
|
||||
target: Math.round((230000 + 640000) / 2 / 10000 * 1.1),
|
||||
date: 'Week 1',
|
||||
originalSales: Math.round((230000 + 640000) / 2),
|
||||
originalTarget: Math.round((230000 + 640000) / 2 * 1.1)
|
||||
},
|
||||
{
|
||||
label: '2주차',
|
||||
sales: Math.round((140000 + 800000) / 2 / 10000), // 14 + 80 / 2 = 47만원
|
||||
target: Math.round((140000 + 800000) / 2 / 10000 * 1.1),
|
||||
date: 'Week 2',
|
||||
originalSales: Math.round((140000 + 800000) / 2),
|
||||
originalTarget: Math.round((140000 + 800000) / 2 * 1.1)
|
||||
},
|
||||
{
|
||||
label: '3주차',
|
||||
sales: Math.round((900000 + 500000) / 2 / 10000), // 90 + 50 / 2 = 70만원
|
||||
target: Math.round((900000 + 500000) / 2 / 10000 * 1.1),
|
||||
date: 'Week 3',
|
||||
originalSales: Math.round((900000 + 500000) / 2),
|
||||
originalTarget: Math.round((900000 + 500000) / 2 * 1.1)
|
||||
},
|
||||
{
|
||||
label: '4주차',
|
||||
sales: Math.round(1600000 / 10000), // 160만원
|
||||
target: Math.round(1600000 / 10000 * 1.1),
|
||||
date: 'Week 4',
|
||||
originalSales: 1600000,
|
||||
originalTarget: Math.round(1600000 * 1.1)
|
||||
},
|
||||
{
|
||||
label: '이번주',
|
||||
sales: Math.round((230000 + 640000 + 140000 + 800000 + 900000 + 500000 + 1600000) / 7 / 10000), // 평균
|
||||
target: Math.round((230000 + 640000 + 140000 + 800000 + 900000 + 500000 + 1600000) / 7 / 10000 * 1.1),
|
||||
date: 'Week 5',
|
||||
originalSales: Math.round((230000 + 640000 + 140000 + 800000 + 900000 + 500000 + 1600000) / 7),
|
||||
originalTarget: Math.round((230000 + 640000 + 140000 + 800000 + 900000 + 500000 + 1600000) / 7 * 1.1)
|
||||
}
|
||||
]
|
||||
|
||||
if (weeklyData.length > 0) {
|
||||
chartData.value['30d'] = weeklyData
|
||||
originalChartData.value['30d'] = weeklyData // ⚠️ 원본 데이터 저장
|
||||
originalChartData.value['30d'] = weeklyData
|
||||
console.log('📊 [CHART] 30일(주간) 데이터 생성:', weeklyData)
|
||||
|
||||
// 90일 데이터 생성 (월간 그룹화)
|
||||
const monthlyData = [
|
||||
{
|
||||
label: '3월',
|
||||
sales: Math.round((230000 + 640000) / 2 / 1000), // 천원 단위 (더 큰 스케일)
|
||||
target: Math.round((230000 + 640000) / 2 / 1000 * 1.1),
|
||||
date: 'Month 1',
|
||||
originalSales: Math.round((230000 + 640000) / 2 * 10),
|
||||
originalTarget: Math.round((230000 + 640000) / 2 * 11)
|
||||
},
|
||||
{
|
||||
label: '4월',
|
||||
sales: Math.round((140000 + 800000) / 2 / 1000),
|
||||
target: Math.round((140000 + 800000) / 2 / 1000 * 1.1),
|
||||
date: 'Month 2',
|
||||
originalSales: Math.round((140000 + 800000) / 2 * 10),
|
||||
originalTarget: Math.round((140000 + 800000) / 2 * 11)
|
||||
},
|
||||
{
|
||||
label: '5월',
|
||||
sales: Math.round((900000 + 500000) / 2 / 1000),
|
||||
target: Math.round((900000 + 500000) / 2 / 1000 * 1.1),
|
||||
date: 'Month 3',
|
||||
originalSales: Math.round((900000 + 500000) / 2 * 10),
|
||||
originalTarget: Math.round((900000 + 500000) / 2 * 11)
|
||||
},
|
||||
{
|
||||
label: '이번달',
|
||||
sales: Math.round(1600000 / 1000),
|
||||
target: Math.round(1600000 / 1000 * 1.1),
|
||||
date: 'Month 4',
|
||||
originalSales: Math.round(1600000 * 10),
|
||||
originalTarget: Math.round(1600000 * 11)
|
||||
}
|
||||
}
|
||||
]
|
||||
|
||||
if (salesData.yearSales.length >= 90) {
|
||||
// 90일 데이터를 월간으로 그룹화
|
||||
const monthlyData = []
|
||||
const monthNames = ['1월', '2월', '3월', '4월', '5월', '6월', '7월', '8월', '9월', '10월', '11월', '12월']
|
||||
|
||||
// 최근 4개월 데이터 생성
|
||||
for (let i = 0; i < 4; i++) {
|
||||
const monthStart = Math.max(0, salesData.yearSales.length - 120 + (i * 30))
|
||||
const monthEnd = Math.min(salesData.yearSales.length, monthStart + 30)
|
||||
const monthSales = salesData.yearSales.slice(monthStart, monthEnd)
|
||||
|
||||
if (monthSales.length > 0) {
|
||||
const totalAmount = monthSales.reduce((sum, sale) => sum + Number(sale.salesAmount), 0)
|
||||
const avgAmount = totalAmount / monthSales.length / 10000 // 만원 단위
|
||||
const originalAvgAmount = totalAmount / monthSales.length // 원화 단위
|
||||
|
||||
const currentMonth = new Date().getMonth()
|
||||
const monthIndex = (currentMonth - 3 + i + 12) % 12
|
||||
|
||||
monthlyData.push({
|
||||
label: i === 3 ? '이번달' : monthNames[monthIndex],
|
||||
sales: Math.round(avgAmount * 10), // 월간은 10배 스케일
|
||||
target: Math.round(avgAmount * 11),
|
||||
date: `Month ${i + 1}`,
|
||||
originalSales: Math.round(originalAvgAmount * 10), // ⚠️ 원화 단위 원본
|
||||
originalTarget: Math.round(originalAvgAmount * 11) // ⚠️ 원화 단위 목표
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
if (monthlyData.length > 0) {
|
||||
chartData.value['90d'] = monthlyData
|
||||
originalChartData.value['90d'] = monthlyData // ⚠️ 원본 데이터 저장
|
||||
originalChartData.value['90d'] = monthlyData
|
||||
console.log('📊 [CHART] 90일(월간) 데이터 생성:', monthlyData)
|
||||
}
|
||||
}
|
||||
|
||||
// 차트 다시 그리기
|
||||
nextTick(() => {
|
||||
drawChart()
|
||||
})
|
||||
|
||||
console.log('📊 [CHART] 차트 데이터 업데이트 완료')
|
||||
} else {
|
||||
console.warn('⚠️ [CHART] yearSales 데이터가 없음, 기본 차트 유지')
|
||||
}
|
||||
console.log('📊 [CHART] 하드코딩된 차트 데이터 업데이트 완료')
|
||||
|
||||
} catch (error) {
|
||||
console.error('❌ [CHART] 차트 데이터 업데이트 실패:', error)
|
||||
// 실패 시 기본 차트 데이터 유지
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user