Pu Zhibing
18 小时以前 f5781289aaedc8460437154e179d85652995e7b8
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
<?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.OrderRideMapper">
 
    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.stylefeng.guns.modular.shunfeng.model.OrderRide">
        <id column="id" property="id" />
        <result column="addTime" property="addTime" />
        <result column="userId" property="userId" />
        <result column="startTime" property="startTime" />
        <result column="num" property="num" />
        <result column="startName" property="startName" />
        <result column="endName" property="endName" />
        <result column="lxPhone" property="lxPhone" />
        <result column="isDai" property="isDai" />
        <result column="money" property="money" />
        <result column="state" property="state" />
        <result column="isEvaluate" property="isEvaluate" />
        <result column="isComplaint" property="isComplaint" />
        <result column="startLon" property="startLon" />
        <result column="startLat" property="startLat" />
        <result column="endLon" property="endLon" />
        <result column="endLat" property="endLat" />
        <result column="travelId" property="travelId" />
        <result column="payType" property="payType" />
    </resultMap>
 
    <!-- 通用查询结果列 -->
    <sql id="Base_Column_List">
        id, addTime, userId, startTime, num, startName, endName, lxPhone, isDai, money, state, isEvaluate, isComplaint, startLon, startLat, endLon, endLat, travelId, name, identity, payType
    </sql>
    <!--用户顺风车订单 type :1待处理的订单,2根据线路、时间,人数综合匹配排序 3按时间排序最早,4距离最近排序,5价格最高 and r.startTime>=now()-->
    <select id="getOrderRide" resultType="com.stylefeng.guns.modular.shunfeng.model.vo.OrderRideVo">
        select r.*,calculate_distance(#{lat},#{lon},r.startLat, r.startLon) as distance,u.avatar as headImg,u.sex,u.totalOrders,u.nickName as name,
        r.id as userOrderId,t.id as  driverOrderId, r.startLon as lon, r.startLat as lat
        from app_order_ride r
        left join app_order_travel t on r.travelId=t.id
        left join t_user u on r.userId=u.id
        left join t_user u1 on r.driverId=u1.driverId
        <where>
            <if test="userId!=null">
                and r.userId = #{userId}
            </if>
            <if test="type==1">
                and r.state in (1,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 r.money desc
        </if>
        LIMIT #{current},#{size}
    </select>
    <!--获取用户身份和司机身份的订单 只需要按照时间排序-->
    <select id="getOrderRideAndTravel" resultType="com.stylefeng.guns.modular.shunfeng.model.vo.OrderRideVo">
       select * from (
         select r.addTime,r.startTime,1 as type,r.state,r.startName,r.endName,r.userId,t.driverId,r.num,r.id as userOrderId,t.id as driverOrderId,r.money, r.startLon as lon, r.startLat as lat from app_order_ride r
                left join app_order_travel t on r.travelId=t.id where r.userId=#{userId}
        UNION
        select t.addTime,t.startTime,2 as type,t.state,t.startName,t.endName,0,t.driverId,r.num,r.id as userOrderId,t.id as driverOrderId,0 as money, r.startLon as lon, r.startLat as lat  from app_order_travel t
                left join app_order_ride r on r.travelId=t.id where t.driverId=#{driverId}
        ) o
        order by o.addTime desc
        LIMIT #{current},#{size}
    </select>
    <!--获取订单详情-->
    <select id="getOrderInfo" resultType="com.stylefeng.guns.modular.shunfeng.model.vo.OrderRideInfoVo">
        select r.addTime,r.startTime,r.endName,r.startName,r.money,r.id as userOrderId,r.state,t.id as driverOrderId,r.isEvaluate,t.isComplaint,
        r.num,r.userId,r.driverId ,u.avatar as headImg,CASE  when r.isDai=1 then r.lxPhone else u.phone end as phone,u.sex,u.nickName as name,u.totalOrders,
        calculate_distance(#{lat},#{lon},r.startLat, r.startLon) as distance,r.startLat as lat, r.startLon as lon,r.endLon endLon,r.endLat endLat,
        t.startLat as latDriver, t.startLon as lonDriver,t.endLon endLonDriver,t.endLat endLatDriver
        from (select * from app_order_ride where id=#{userOrderId}) r
        left join app_order_travel t on r.travelId=t.id
        left join app_driver_ride d on d.id=r.driverId
        left join t_user u on r.userId=u.id
    </select>
 
    <select id="queryMyOrderList" resultType="java.util.Map">
        SELECT
            *
        FROM
            (
                SELECT
                    id AS orderId,
                    DATE_FORMAT( addTime, '%Y-%m-%d %H:%i' ) AS orderTime,
                    DATE_FORMAT( startTime, '%m月%d日 %H:%i' ) AS TIME,
        startName AS startAddress,
        endName AS endAddress,
        driverId AS driverId,
        ( 8 ) AS orderType,
        1 AS rideUserType,
        startLon as startLon,
        startLat as startLat,
        state AS state
                FROM
                    app_order_ride
                WHERE
                    userId = #{uid}
 
                UNION all
 
                SELECT
                    t1.id AS orderId,
                    DATE_FORMAT( t1.addTime, '%Y-%m-%d %H:%i' ) AS orderTime,
                    DATE_FORMAT( t1.startTime, '%m月%d日 %H:%i' ) AS TIME,
                    t1.startName AS startAddress,
                    t1.endName AS endAddress,
                    t1.driverId AS driverId,
                    ( 8 ) AS orderType,
                    2 AS rideUserType,
                    t1.startLon as startLon,
                    t1.startLat as startLat,
                    t1.state AS state
                FROM
                    app_order_travel t1
                    LEFT JOIN t_user t2 ON t1.driverId = t2.driverId
                WHERE
                    t2.id = #{uid}
            ) as t
        ORDER BY
            t.orderTime DESC
            LIMIT #{pageNum}, #{size}
    </select>
</mapper>