package com.yuchen.saas.park.service.service.pldoor.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.yuchen.saas.park.api.entity.pldoor.PlPsTask;
import com.yuchen.saas.park.api.entity.pldoor.PlPsWarning;
import com.yuchen.saas.park.api.entity.pldoor.PlPsWarning;
import com.yuchen.saas.park.api.vo.request.PlPsWarningReq;
import com.yuchen.saas.park.service.mapper.pldoor.PlPsWarningMapper;
import com.yuchen.saas.park.service.service.pldoor.PlPsWarningService;
import org.nest.springwrap.core.mp.base.BaseServiceImpl;
import org.nest.springwrap.core.mp.support.Condition;
import org.nest.springwrap.core.mp.support.Query;
import org.nest.springwrap.core.tool.utils.Func;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 智慧配送告警 服务实现类
 * </p>
 *
 * @author miaoqs
 * @since 2024-07-31
 */
@Service
public class PlPsWarningServiceImpl extends BaseServiceImpl<PlPsWarningMapper, PlPsWarning> implements PlPsWarningService {

    @Override
    public IPage<PlPsWarning> pageByparam(PlPsWarningReq plPsWarningReq, Query query) {
        IPage<PlPsWarning> pages = page(Condition.getPage(query),
                new LambdaQueryWrapper<PlPsWarning>()
                        .eq(Func.isNotEmpty(plPsWarningReq.getParkId()), PlPsWarning::getParkId,
                                plPsWarningReq.getParkId())
                        .eq(Func.isNotEmpty(plPsWarningReq.getWarningGrade()), PlPsWarning::getWarningGrade,
                                plPsWarningReq.getWarningGrade())
                        .eq(Func.isNotEmpty(plPsWarningReq.getWarningEquipment()), PlPsWarning::getWarningEquipment,
                                plPsWarningReq.getWarningEquipment())
                        .eq(Func.isNotEmpty(plPsWarningReq.getWarningAddress()), PlPsWarning::getWarningAddress,
                                plPsWarningReq.getWarningAddress())
                        .eq(Func.isNotEmpty(plPsWarningReq.getEquipmentAddress()), PlPsWarning::getEquipmentAddress,
                                plPsWarningReq.getEquipmentAddress())
                        .between(Func.isNotEmpty(plPsWarningReq.getWarningStartTime()) && Func.isNotEmpty(plPsWarningReq.getWarningEndTime()),
                                PlPsWarning::getWarningTime, plPsWarningReq.getWarningStartTime(), plPsWarningReq.getWarningEndTime())
                        .between(Func.isNotEmpty(plPsWarningReq.getCloseStartTime()) && Func.isNotEmpty(plPsWarningReq.getCloseEndTime()),
                                PlPsWarning::getCloseTime, plPsWarningReq.getCloseStartTime(), plPsWarningReq.getCloseEndTime())
                        .orderByDesc(PlPsWarning::getCreateTime));
        return pages;
    }
}
