package com.rj.service;

import com.rj.entity.AudioManagementStatistics;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.ActiveProfiles;

import java.time.LocalDate;
import java.util.List;

import static org.junit.jupiter.api.Assertions.*;

/**
 * 门店录音统计服务测试类
 * 
 * @author 李中华 ,spllzh
 * @since 2025-08-07
 */
//@SpringBootTest
//@ActiveProfiles("test")
public class AudioManagementStatisticsServiceTest {

    @Autowired
    private IAudioManagementStatisticsService audioStatisticsService;

    @Test
    public void testGenerateStatisticsByDate() {
        // 测试生成指定日期的统计数据
        LocalDate testDate = LocalDate.now().minusDays(1);
        int count = audioStatisticsService.generateStatisticsByDate(testDate);
        
        assertTrue(count >= 0, "统计记录数应该大于等于0");
        System.out.println("生成统计记录数: " + count);
    }

    @Test
    public void testGenerateYesterdayStatistics() {
        // 测试生成昨天的统计数据
        int count = audioStatisticsService.generateYesterdayStatistics();
        
        assertTrue(count >= 0, "统计记录数应该大于等于0");
        System.out.println("生成昨天统计记录数: " + count);
    }

    @Test
    public void testGetStatisticsByDateRange() {
        // 测试查询日期范围的统计数据
        LocalDate startDate = LocalDate.now().minusDays(7);
        LocalDate endDate = LocalDate.now().minusDays(1);
        
        List<AudioManagementStatistics> statistics = audioStatisticsService.getStatisticsByDateRange(startDate, endDate);
        
        assertNotNull(statistics, "统计列表不应该为null");
        System.out.println("查询到统计记录数: " + statistics.size());
        
        // 打印统计信息
        for (AudioManagementStatistics stat : statistics) {
            System.out.println("门店: " + stat.getDealershipName() + 
                             ", 日期: " + stat.getStatisticsDate() + 
                             ", 录音数量: " + stat.getDealershipRecordingCount() + 
                             ", 总时长: " + stat.getDealershipTotalDuration() + "秒" +
                             ", 平均时长: " + stat.getDealershipAvgDuration() + "秒");
        }
    }

    @Test
    public void testGetStatisticsByDealership() {
        // 测试查询指定门店的统计数据
        Long dealershipId = 1L; // 假设门店ID为1
        LocalDate startDate = LocalDate.now().minusDays(7);
        LocalDate endDate = LocalDate.now().minusDays(1);
        
        List<AudioManagementStatistics> statistics = audioStatisticsService.getStatisticsByDealership(dealershipId, startDate, endDate);
        
        assertNotNull(statistics, "统计列表不应该为null");
        System.out.println("查询到门店统计记录数: " + statistics.size());
    }

    @Test
    public void testGetStatisticsBySales() {
        // 测试查询指定销售人员的统计数据
        String salesId = "sales001"; // 假设销售人员ID
        LocalDate startDate = LocalDate.now().minusDays(30); // 最近30天
        LocalDate endDate = LocalDate.now().minusDays(1);
        
        List<AudioManagementStatistics> statistics = audioStatisticsService.getStatisticsBySales(salesId, startDate, endDate);
        
        assertNotNull(statistics, "统计列表不应该为null");
        System.out.println("查询到销售人员统计记录数: " + statistics.size());
        
        // 打印销售人员统计信息
        for (AudioManagementStatistics stat : statistics) {
            System.out.println("销售人员ID: " + stat.getSalesId() + 
                             ", 日期: " + stat.getStatisticsDate() + 
                             ", 录音数量: " + stat.getSalesRecordingCount() + 
                             ", 总时长: " + stat.getSalesTotalDuration() + "秒" +
                             ", 平均时长: " + stat.getSalesAvgDuration() + "秒");
        }
    }
}
