package com.fizz.business.service.impl;

import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.fizz.business.domain.RollHistory;
import com.fizz.business.form.RollHistoryForm;
import com.fizz.business.mapper.RollHistoryMapper;
import com.fizz.business.service.RollHistoryService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class RollHistoryServiceImpl extends ServiceImpl<RollHistoryMapper, RollHistory> implements RollHistoryService {
    @Override
    public List<String> getChangeIdList() {
        return baseMapper.getChangeIdList();
    }

    @Override
    public List<String> getRollIdList() {
        return baseMapper.getRollIdList();
    }

    @Override
    public PageInfo<RollHistory> getRollHistory(RollHistoryForm rollHistoryForm) {

        // 调用分页查询方法，获取EventRecords的分页结果
        PageHelper.startPage(rollHistoryForm.getPageNum(), rollHistoryForm.getPageSize());

        LambdaQueryWrapper<RollHistory> queryWrapper = new LambdaQueryWrapper<>();
        if(ObjectUtil.isNotEmpty(rollHistoryForm.getStartTime())){
            queryWrapper.ge(RollHistory::getChangeTime,rollHistoryForm.getStartTime());
        }
        if(ObjectUtil.isNotEmpty(rollHistoryForm.getEndTime())){
            queryWrapper.le(RollHistory::getChangeTime,rollHistoryForm.getEndTime());
        }
        if(ObjectUtil.isNotEmpty(rollHistoryForm.getChangeId())){
            queryWrapper.eq(RollHistory::getChangeid,rollHistoryForm.getChangeId());
        }
        if(ObjectUtil.isNotEmpty(rollHistoryForm.getRollid())){
            queryWrapper.eq(RollHistory::getRollid,rollHistoryForm.getRollid());
        }
        queryWrapper.orderByDesc(RollHistory::getChangeTime);

        List<RollHistory> list = this.list(queryWrapper);
        PageInfo<RollHistory> pageInfo = new PageInfo<>(list);

        return pageInfo;
    }
}

