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.PlPsOrder;
import com.yuchen.saas.park.api.entity.pldoor.PlPsOrder;
import com.yuchen.saas.park.api.vo.request.PlPsOrderReq;
import com.yuchen.saas.park.service.mapper.pldoor.PlPsOrderMapper;
import com.yuchen.saas.park.service.service.pldoor.PlPsOrderService;
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;

import javax.annotation.Resource;

/**
 * <p>
 * 智慧配送订单 服务实现类
 * </p>
 *
 * @author miaoqs
 * @since 2024-07-31
 */
@Service
public class PlPsOrderServiceImpl extends BaseServiceImpl<PlPsOrderMapper, PlPsOrder> implements PlPsOrderService {

    @Override
    public IPage<PlPsOrder> pageByparam(PlPsOrderReq plPsOrderReq, Query query) {
        IPage<PlPsOrder> pages = page(Condition.getPage(query),
                new LambdaQueryWrapper<PlPsOrder>()
                        .eq(Func.isNotEmpty(plPsOrderReq.getParkId()), PlPsOrder::getParkId,
                                plPsOrderReq.getParkId())
                        .eq(Func.isNotEmpty(plPsOrderReq.getElementId()), PlPsOrder::getElementId,
                                plPsOrderReq.getElementId())
                        .eq(Func.isNotEmpty(plPsOrderReq.getBuildingId()), PlPsOrder::getBuildingId,
                                plPsOrderReq.getBuildingId())
                        .eq(Func.isNotEmpty(plPsOrderReq.getRoomNumberId()), PlPsOrder::getRoomNumberId,
                                plPsOrderReq.getRoomNumberId())
                        .eq(Func.isNotEmpty(plPsOrderReq.getOrderState()), PlPsOrder::getOrderState,
                                plPsOrderReq.getOrderState())
                        .eq(Func.isNotEmpty(plPsOrderReq.getPsRobotId()), PlPsOrder::getPsRobotId,
                                plPsOrderReq.getPsRobotId())
                        .eq(Func.isNotEmpty(plPsOrderReq.getOrderNo()), PlPsOrder::getOrderNo,
                                plPsOrderReq.getOrderNo())
                        .eq(Func.isNotEmpty(plPsOrderReq.getRecipientName()), PlPsOrder::getRecipientName,
                                plPsOrderReq.getRecipientName())
                        .eq(Func.isNotEmpty(plPsOrderReq.getConsigneePhone()), PlPsOrder::getConsigneePhone,
                                plPsOrderReq.getConsigneePhone())
                        .between(Func.isNotEmpty(plPsOrderReq.getCreateStartTime()) && Func.isNotEmpty(plPsOrderReq.getCreateEndTime()),
                                PlPsOrder::getCreateTime, plPsOrderReq.getCreateStartTime(), plPsOrderReq.getCreateEndTime())
                        .between(Func.isNotEmpty(plPsOrderReq.getScheduledStartTime()) && Func.isNotEmpty(plPsOrderReq.getScheduledEndTime()),
                                PlPsOrder::getScheduledTime, plPsOrderReq.getScheduledStartTime(), plPsOrderReq.getScheduledEndTime())
                        .orderByDesc(PlPsOrder::getCreateTime));
        return pages;
    }
}
