package org.jeecg.modules.ziyangxcj.service.impl;

import org.jeecg.modules.ziyangxcj.entity.ZiyangXcjOnline;
import org.jeecg.modules.ziyangxcj.mapper.ZiyangXcjOnlineMapper;
import org.jeecg.modules.ziyangxcj.service.IZiyangXcjOnlineService;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

/**
 * @Description: ziyang_xcj_online
 * @Author: jeecg-boot
 * @Date:   2025-11-22
 * @Version: V1.0
 */
@Service
public class ZiyangXcjOnlineServiceImpl extends ServiceImpl<ZiyangXcjOnlineMapper, ZiyangXcjOnline> implements IZiyangXcjOnlineService {

    @Override
    public IPage<ZiyangXcjOnline> queryHistoryDataByMonth(Page<ZiyangXcjOnline> page, String month) {
        // 构造历史表名
        String tableName = "ziyang_xcj_history_" + month;
        // 查询历史数据
        return baseMapper.queryHistoryDataByMonth(page, tableName);
    }

    @Override
    public IPage<ZiyangXcjOnline> queryHistoryDataByTimeRange(Page<ZiyangXcjOnline> page, String startTime, String endTime) {
        // 根据开始时间确定要查询的历史表名
        LocalDateTime startDateTime = LocalDateTime.parse(startTime, DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
        String tableName = "ziyang_xcj_history_" + startDateTime.format(DateTimeFormatter.ofPattern("yyyyMM"));

        // 查询历史数据
        return baseMapper.queryHistoryDataByTimeRange(page, tableName, startTime, endTime);
    }
}
