package com.zksy.dispatch.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zksy.dispatch.domain.DisEventGrade;
import com.zksy.dispatch.dto.DisEventGradePageDTO;
import com.zksy.dispatch.mapper.DisEventGradeMapper;
import com.zksy.dispatch.service.DisEventGradeService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.List;

@Slf4j
@Service
public class DisEventGradeServiceImpl extends ServiceImpl<DisEventGradeMapper, DisEventGrade>
        implements DisEventGradeService {

    @Override
    public Page<DisEventGrade> findByPage(DisEventGradePageDTO dto) {
        Page<DisEventGrade> page = new Page<>(dto.getPageNum(), dto.getPageSize());
        LambdaQueryWrapper<DisEventGrade> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(dto.getCategory() != null && !dto.getCategory().isEmpty(), DisEventGrade::getCategory, dto.getCategory());
        wrapper.eq(dto.getLevel() != null && !dto.getLevel().isEmpty(), DisEventGrade::getLevel, dto.getLevel());
        wrapper.eq(dto.getStatus() != null && !dto.getStatus().isEmpty(), DisEventGrade::getStatus, dto.getStatus());
        wrapper.orderByAsc(DisEventGrade::getCategory);
        wrapper.orderByAsc(DisEventGrade::getLevel);
        return this.page(page, wrapper);
    }

    @Override
    public List<DisEventGrade> listByCategory(String category) {
        LambdaQueryWrapper<DisEventGrade> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(DisEventGrade::getCategory, category);
        wrapper.orderByAsc(DisEventGrade::getLevel);
        return this.list(wrapper);
    }
}
