Merge pull request #6 from won-ktds/front

dashboard
This commit is contained in:
yyoooona 2025-06-19 20:41:15 +09:00 committed by GitHub
commit e393565cac
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -232,6 +232,7 @@
<p class="text-caption text-grey-darken-1 mb-0">맞춤형 마케팅 제안</p>
</div>
</div>
</div>
</v-card-title>
@ -244,7 +245,7 @@
<div v-else-if="aiRecommendation" class="ai-recommendation-content">
<!-- 추천 제목 -->
<div class="recommendation-header mb-4">
</div>
<!-- 스크롤 가능한 콘텐츠 영역 -->
@ -783,115 +784,146 @@ const updateDashboardMetrics = (salesData) => {
}
/**
* 차트 데이터 업데이트 (수정 - 핵심 차트 연동 로직)
* 차트 데이터 업데이트 (하드코딩된 7 데이터 사용)
*/
const updateChartData = (salesData) => {
try {
console.log('📊 [CHART] 차트 데이터 업데이트 시작:', salesData)
// yearSales
if (salesData.yearSales && salesData.yearSales.length > 0) {
// Sales
const salesDataPoints = salesData.yearSales.slice(-7).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) //
return {
label: index === salesData.yearSales.length - 1 ? '오늘' : label,
sales: Math.round(amount),
target: Math.round(amount * 1.1), // 110%
date: sale.salesDate,
originalSales: originalAmount, //
originalTarget: Math.round(originalAmount * 1.1) //
}
})
// 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 = 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) //
console.log('📊 [CHART] 변환된 7일 데이터:', salesDataPoints)
// ''
const displayLabel = index === hardcodedSalesData.length - 1 ? '오늘' : label
// 7
chartData.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) //
})
}
}
if (weeklyData.length > 0) {
chartData.value['30d'] = weeklyData
originalChartData.value['30d'] = weeklyData //
console.log('📊 [CHART] 30일(주간) 데이터 생성:', weeklyData)
}
return {
label: displayLabel,
sales: Math.round(amount),
target: Math.round(amount * 1.1), // 110%
date: sale.salesDate,
originalSales: originalAmount,
originalTarget: Math.round(originalAmount * 1.1)
}
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 //
console.log('📊 [CHART] 90일(월간) 데이터 생성:', monthlyData)
}
})
console.log('📊 [CHART] 변환된 7일 차트 데이터:', salesDataPoints)
// 7
chartData.value['7d'] = salesDataPoints
originalChartData.value['7d'] = salesDataPoints
// 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)
}
//
nextTick(() => {
drawChart()
})
console.log('📊 [CHART] 차트 데이터 업데이트 완료')
} else {
console.warn('⚠️ [CHART] yearSales 데이터가 없음, 기본 차트 유지')
}
]
chartData.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)
}
]
chartData.value['90d'] = monthlyData
originalChartData.value['90d'] = monthlyData
console.log('📊 [CHART] 90일(월간) 데이터 생성:', monthlyData)
//
nextTick(() => {
drawChart()
})
console.log('📊 [CHART] 하드코딩된 차트 데이터 업데이트 완료')
} catch (error) {
console.error('❌ [CHART] 차트 데이터 업데이트 실패:', error)
//