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.PlPsTask;
import com.yuchen.saas.park.api.vo.pldoor.PsTodayCountVO;
import com.yuchen.saas.park.api.vo.request.PlPsTaskReq;
import com.yuchen.saas.park.service.mapper.pldoor.PlPsTaskMapper;
import com.yuchen.saas.park.service.service.pldoor.PlPsTaskService;
import org.nest.springwrap.core.mp.base.BaseServiceImpl;
import org.nest.springwrap.core.mp.support.Condition;
import org.nest.springwrap.core.mp.support.NestPage;
import org.nest.springwrap.core.mp.support.Query;
import org.nest.springwrap.core.tool.api.R;
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 PlPsTaskServiceImpl extends BaseServiceImpl<PlPsTaskMapper, PlPsTask> implements PlPsTaskService {

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

    @Override
    public PsTodayCountVO getTodayPs(Long partId) {
        return null;
    }
}
