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

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.jeecg.modules.gijcj.entity.BuZyGijcj_6Online;
import org.jeecg.modules.gijcj.mapper.BuZyGijcj_6OnlineMapper;
import org.jeecg.modules.gijcj.service.IBuZyGijcj_6OnlineService;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

/**
 * @Description: bu_zy_gijcj_6_online
 * @Author: jeecg-boot
 * @Date:   2026-01-23
 * @Version: V1.0
 */
@Service
public class BuZyGijcj_6OnlineServiceImpl extends ServiceImpl<BuZyGijcj_6OnlineMapper, BuZyGijcj_6Online> implements IBuZyGijcj_6OnlineService {
    
    @Autowired
    private BuZyGijcj_6OnlineMapper buZyGijcj_6OnlineMapper;

    /**
     * 使用自定义resultMap进行分页查询
     */
    @Override
    public IPage<BuZyGijcj_6Online> pageListWithCustomFields(Page<BuZyGijcj_6Online> page, Wrapper<BuZyGijcj_6Online> wrapper) {
        List<BuZyGijcj_6Online> records = buZyGijcj_6OnlineMapper.selectWithCustomFields(wrapper);
        page.setRecords(records);
        return page;
    }

    /**
     * 按月份查询历史数据
     */
    @Override
    public IPage<BuZyGijcj_6Online> queryHistoryDataByMonth(Page<BuZyGijcj_6Online> page, String month) {
        // 创建查询条件
        com.baomidou.mybatisplus.core.conditions.query.QueryWrapper<BuZyGijcj_6Online> wrapper = 
            new com.baomidou.mybatisplus.core.conditions.query.QueryWrapper<BuZyGijcj_6Online>();
        
        // 使用自定义字段查询方法
        List<BuZyGijcj_6Online> records = buZyGijcj_6OnlineMapper.selectWithCustomFields(wrapper);
        page.setRecords(records);
        page.setTotal(records.size()); // 设置总记录数
        
        return page;
    }

    /**
     * 按时间范围查询历史数据
     */
    @Override
    public IPage<BuZyGijcj_6Online> queryHistoryDataByTimeRange(Page<BuZyGijcj_6Online> page, String startTime, String endTime) {
        // 根据开始时间确定表名（例如：从时间字符串中提取年月）
        String month = startTime.substring(0, 7).replace("-", "");
        String tableName = "bu_zy_gijcj_6_history_" + month;
        // 查询历史数据
        return buZyGijcj_6OnlineMapper.queryHistoryDataByTimeRange(page, tableName, startTime, endTime);
    }
}