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