package com.gyee.runeconomy.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.gyee.runeconomy.model.PowerLosses;
import com.gyee.runeconomy.mapper.PowerLossesMapper;
import com.gyee.runeconomy.service.PowerLossesService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.Collections;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author wang
 * @since 2025-02-24
 */
@Service
public class PowerLossesServiceImpl extends ServiceImpl<PowerLossesMapper, PowerLosses> implements PowerLossesService {
    @Resource
    private PowerLossesMapper powerLossesMapper;

    @Override
    public IPage<PowerLosses> pageList(Page<PowerLosses> page, LocalDateTime startTs, LocalDateTime endTs) {
        QueryWrapper<PowerLosses> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda()
                .ge(PowerLosses::getStartTime, startTs)
                .le(PowerLosses::getEndTime, endTs)
                .orderByAsc(PowerLosses::getId); // 明确指定排序
        return powerLossesMapper.selectPage(page, queryWrapper);
    }

    @Override
    public List<PowerLosses> pageTotalList(LocalDateTime startTs, LocalDateTime endTs) {
        QueryWrapper<PowerLosses> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda()
                .ge(PowerLosses::getStartTime, startTs)
                .le(PowerLosses::getEndTime, endTs);
        return powerLossesMapper.selectList(queryWrapper);
    }
}
