package com.cpxt.biz.mapper;

import java.util.List;
import java.util.Map;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.cpxt.biz.domain.BizOrder;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

/**
 * 订单Mapper接口
 * 
 * @author YIN
 * @date 2024-12-16
 */
@Mapper
public interface BizOrderMapper extends BaseMapper<BizOrder>
{
    @Select("select * from biz_order order by id desc limit 1")
    BizOrder selectLastestOrder();

    @Select("select SUM(line_distance) as distance from biz_order ${ew.customSqlSegment}")
    Double selectSumDistance(@Param("ew") LambdaQueryWrapper<BizOrder> queryWrapper);

    @Select("SELECT receiver_area as area,COUNT(receiver_area) as count FROM biz_order WHERE order_status != '4' GROUP BY receiver_area")
    List<Map<String, Long>> selectAreaOverview();

    @Select("SELECT t.area from (SELECT receiver_area as area,COUNT(receiver_area) as count FROM biz_order WHERE order_status != '4' GROUP BY receiver_area) t")
    List<String> selectAreaNameOverview();

    @Select("SELECT t.count from (SELECT receiver_area as area,COUNT(receiver_area) as count FROM biz_order WHERE order_status != '4' GROUP BY receiver_area) t")
    List<Long> selectAreaCountOverview();

    @Select("select * from biz_order where order_sn = #{orderSn} and status = 1")
    BizOrder selectByOrderSn(String orderSn);
}
