package com.ruoyi.system.mapper;

import java.math.BigDecimal;
import java.util.List;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.ruoyi.system.domain.RiderPosition;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

/**
 * RiderPositionMapper接口
 *
 * @author ruoyi
 * @date 2023-07-31
 */
public interface RiderPositionMapper  extends BaseMapper<RiderPosition>
{
    /**
     * 查询RiderPosition
     *
     * @param id RiderPosition主键
     * @return RiderPosition
     */
    public RiderPosition selectRiderPositionById(Long id);

    /**
     * 查询RiderPosition列表
     *
     * @param riderPosition RiderPosition
     * @return RiderPosition集合
     */
    public List<RiderPosition> selectRiderPositionList(RiderPosition riderPosition);

    /**
     * 新增RiderPosition
     *
     * @param riderPosition RiderPosition
     * @return 结果
     */
    public int insertRiderPosition(RiderPosition riderPosition);

    /**
     * 修改RiderPosition
     *
     * @param riderPosition RiderPosition
     * @return 结果
     */
    public int updateRiderPosition(RiderPosition riderPosition);

    /**
     * 删除RiderPosition
     *
     * @param id RiderPosition主键
     * @return 结果
     */
    public int deleteRiderPositionById(Long id);

    /**
     * 批量删除RiderPosition
     *
     * @param ids 需要删除的数据主键集合
     * @return 结果
     */
    public int deleteRiderPositionByIds(Long[] ids);


    @Select("select rp.*,(st_distance(point(rp.longitude,rp.latitude),point(#{longitude},#{latitude}))*111195/1000) as juli "
            + "from rider_position rp where not exists (select 1 from pos_order po where po.qs_id=rp.rider_id "
            + "and po.type=0 and po.state in (0,1,2) and po.delivery_status in (1,2) and po.after_sale_status=0) "
            + "and rp.rider_id not in (select user_id from info_user where offline='1' and user_type='2') "
            + "order by juli asc limit #{num}")
    public List<RiderPosition> getAcceptRiderList(@Param("longitude") BigDecimal longitude, @Param("latitude")BigDecimal latitude,@Param("num")int num);
}
