package com.sckw.fleet.repository;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sckw.core.model.base.BaseModel;
import com.sckw.fleet.dao.KwfFleetDriverMapper;
import com.sckw.fleet.model.KwfFleetDriver;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Set;


/**
 * @author PC
 * 车队-司机接口
 */
@Repository
public class KwfFleetDriverRepository extends ServiceImpl<KwfFleetDriverMapper, KwfFleetDriver> {
    public KwfFleetDriver queryOneByDriverId(Long driverId) {
        return getOne(Wrappers.<KwfFleetDriver>lambdaQuery()
                .eq(BaseModel::getDelFlag,0)
                .eq(KwfFleetDriver::getDriverId,driverId)
                .orderByDesc(BaseModel::getUpdateTime)
                .last("limit 1"));
    }

    public KwfFleetDriver findFleetByDriveId(Long driveId) {
        return getOne(Wrappers.<KwfFleetDriver>lambdaQuery()
                .eq(BaseModel::getDelFlag,0)
                .eq(KwfFleetDriver::getDriverId,driveId)
                .orderByDesc(BaseModel::getId)
                .last("limit 1"));
    }

    /**
     * 通过企业id查询订单
     * @param entId 企业id
     * @return 返回订单列表
     */
    public List<KwfFleetDriver> findFleetDriveByEntId(Long entId) {
        return list(Wrappers.<KwfFleetDriver>lambdaQuery()
                .eq(BaseModel::getDelFlag,0)
                .eq(KwfFleetDriver::getEntId,entId));
    }

    public List<KwfFleetDriver> findByFleetIds(Set<Long> feltIds) {
        return list(Wrappers.<KwfFleetDriver>lambdaQuery()
                .eq(BaseModel::getDelFlag,0)
                .in(KwfFleetDriver::getFleetId,feltIds));
    }
}
