package com.usky.park.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.usky.common.core.bean.CommonPage;
import com.usky.park.domain.EventLc;
import com.usky.park.mapper.EventLcMapper;
import com.usky.park.service.EventLcService;
import com.usky.common.mybatis.core.AbstractCrudService;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 梯控历史事件表 服务实现类
 * </p>
 *
 * @author zyj
 * @since 2023-04-10
 */
@Service
public class EventLcServiceImpl extends AbstractCrudService<EventLcMapper, EventLc> implements EventLcService {

    @Override
    public CommonPage<EventLc> eventLcList(String personName,String cardNo,String liftName,String startDate,String endDate,Integer pageNum,Integer pageSize){
        IPage<EventLc> page = new Page<>(pageNum,pageSize);
        List<EventLc> list = new ArrayList<>();
        LambdaQueryWrapper<EventLc> queryWrapper = Wrappers.lambdaQuery();
        queryWrapper.like(StringUtils.isNotBlank(personName),EventLc::getPersonName,personName)
                    .like(StringUtils.isNotBlank(cardNo),EventLc::getCardNo,cardNo)
                    .like(StringUtils.isNotBlank(liftName),EventLc::getLiftName,liftName)
                    .between(StringUtils.isNotBlank(startDate)&&StringUtils.isNotBlank(endDate),EventLc::getEventTime,startDate,endDate)
                    .orderByDesc(EventLc::getId);
        page = this.page(page,queryWrapper);
        list = page.getRecords();

        return new CommonPage<>(list,page.getTotal(),pageNum,pageSize);
    }

}
