Pu Zhibing
2025-08-08 6dbd3b95671e6ac00a442b9866331397af1b10ba
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.stylefeng.guns.modular.shunfeng.dao.OrderTravelMapper">
 
    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.stylefeng.guns.modular.shunfeng.model.OrderTravel">
        <id column="id" property="id" />
        <result column="addTime" property="addTime" />
        <result column="driverId" property="driverId" />
        <result column="startTime" property="startTime" />
        <result column="num" property="num" />
        <result column="startName" property="startName" />
        <result column="endName" property="endName" />
        <result column="money" property="money" />
        <result column="state" property="state" />
        <result column="startLon" property="startLon" />
        <result column="startLat" property="startLat" />
        <result column="endLon" property="endLon" />
        <result column="endLat" property="endLat" />
    </resultMap>
 
    <!-- 通用查询结果列 -->
    <sql id="Base_Column_List">
        id, addTime, driverId, startTime, num, startName, endName, money, state, startLon, startLat, endLon, endLat
    </sql>
    <!--顺风车司机订单行程 type :1待处理的订单,2根据线路、时间,人数综合匹配排序 3按时间排序,4距离最近排序 and r.startTime>=now()-->
    <select id="getOrderTravel" resultType="com.stylefeng.guns.modular.shunfeng.model.vo.OrderRideVo">
        select r.*,calculate_distance(#{lat},#{lon},r.startLat, r.startLon)  as distance,d.totalOrders,u.sex,u.avatar as headImg,u.nickName as name,
        r.id as driverOrderId,i.id as userOrderId
        from app_order_travel r
        left join app_order_ride i on i.travelId=r.id
        left join t_user u on u.driverId = r.driverId
        left join app_driver_ride d on d.id=r.driverId
        <where>
            <if test="driverId!=null">
                and r.driverId = #{driverId}
            </if>
            <if test="type==1">
                and r.state in (2,3,4)
            </if>
            <if test="type>1">
                and r.state = 2
            </if>
        </where>
        <if test="type==1">
          order by r.startTime desc
        </if>
        <if test="type==2">
            order by calculate_distance(#{lat},#{lon}, r.startLat,r.startLon)  asc,r.startTime desc,(r.num-#{num}) asc
        </if>
        <if test="type==3">
            order by r.startTime asc
        </if>
        <if test="type==4">
            order by calculate_distance(#{lat},#{lon}, r.startLat,r.startLon)  asc
        </if>
        LIMIT #{current},#{size}
    </select>
    <!--根据订单id获取订单详情-->
    <select id="getOrderInfo" resultType="com.stylefeng.guns.modular.shunfeng.model.vo.OrderRideInfoVo">
        select t.addTime,r.startTime,r.endName,r.startName,r.money,r.id as userOrderId,r.state,t.id as driverOrderId,r.isComplaint,r.num,
        r.userId,r.driverId,u.avatar as headImg,u.phone,u.sex,u.nickName as realName as name,d.carNum,d.carType,d.totalOrders,IFNULL(format(d.evaluateScore/d.evaluateNum,2),0)as evaluateScore,r.evaluateScoreUser,r.isEvaluate
        ,r.content
        from (select * from app_order_travel where id= #{driverOrderId}) t
        left join app_order_ride r on t.id=r.travelId
        left join app_driver_ride d on d.id=t.driverId
        left join t_user u on d.id=u.driverId
    </select>
</mapper>