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.DisEventPlan;
import com.zksy.dispatch.dto.DisEventPlanPageDTO;
import com.zksy.dispatch.mapper.DisEventPlanMapper;
import com.zksy.dispatch.service.DisEventPlanService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

@Slf4j
@Service
public class DisEventPlanServiceImpl extends ServiceImpl<DisEventPlanMapper, DisEventPlan>
        implements DisEventPlanService {

    @Override
    public Page<DisEventPlan> findByPage(DisEventPlanPageDTO dto) {
        Page<DisEventPlan> page = new Page<>(dto.getPageNum(), dto.getPageSize());
        LambdaQueryWrapper<DisEventPlan> wrapper = new LambdaQueryWrapper<>();
        wrapper.like(dto.getPlanName() != null && !dto.getPlanName().isEmpty(), DisEventPlan::getPlanName, dto.getPlanName());
        wrapper.eq(dto.getPlanType() != null && !dto.getPlanType().isEmpty(), DisEventPlan::getPlanType, dto.getPlanType());
        wrapper.eq(dto.getPlanLevel() != null && !dto.getPlanLevel().isEmpty(), DisEventPlan::getPlanLevel, dto.getPlanLevel());
        wrapper.eq(dto.getStatus() != null && !dto.getStatus().isEmpty(), DisEventPlan::getStatus, dto.getStatus());
        wrapper.eq(dto.getCategoryId() != null, DisEventPlan::getCategoryId, dto.getCategoryId());
        wrapper.orderByDesc(DisEventPlan::getCreateTime);
        return this.page(page, wrapper);
    }
}
