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.DisPlanApprovalStep;
import com.zksy.dispatch.dto.DisPlanApprovalStepPageDTO;
import com.zksy.dispatch.mapper.DisPlanApprovalStepMapper;
import com.zksy.dispatch.service.DisPlanApprovalStepService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.List;

@Slf4j
@Service
public class DisPlanApprovalStepServiceImpl extends ServiceImpl<DisPlanApprovalStepMapper, DisPlanApprovalStep>
        implements DisPlanApprovalStepService {

    @Override
    public Page<DisPlanApprovalStep> findByPage(DisPlanApprovalStepPageDTO dto) {
        Page<DisPlanApprovalStep> page = new Page<>(dto.getPageNum(), dto.getPageSize());
        LambdaQueryWrapper<DisPlanApprovalStep> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(dto.getApprovalId() != null, DisPlanApprovalStep::getApprovalId, dto.getApprovalId());
        wrapper.eq(dto.getResult() != null && !dto.getResult().isEmpty(), DisPlanApprovalStep::getResult, dto.getResult());
        wrapper.orderByAsc(DisPlanApprovalStep::getStepOrder);
        return this.page(page, wrapper);
    }

    @Override
    public List<DisPlanApprovalStep> listByApprovalId(Long approvalId) {
        LambdaQueryWrapper<DisPlanApprovalStep> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(DisPlanApprovalStep::getApprovalId, approvalId);
        wrapper.orderByAsc(DisPlanApprovalStep::getStepOrder);
        return this.list(wrapper);
    }
}
