luodangjia
2024-12-10 31ce6be2d56798d9509e6d90335999064351f7f3
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
<?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.system.dao.ReassignMapper">
 
    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.stylefeng.guns.modular.system.model.Reassign">
        <id column="id" property="id"/>
        <result column="orderType" property="orderType"/>
        <result column="orderId" property="orderId"/>
        <result column="originalDriverId" property="originalDriverId"/>
        <result column="originalCarId" property="originalCarId"/>
        <result column="insertTime" property="insertTime"/>
        <result column="nowDriverId" property="nowDriverId"/>
        <result column="nowCarId" property="nowCarId"/>
        <result column="money" property="money"/>
        <result column="payType" property="payType"/>
        <result column="payTime" property="payTime"/>
        <result column="payOrder" property="payOrder"/>
        <result column="state" property="state"/>
        <result column="reason" property="reason"/>
        <result column="remark" property="remark"/>
        <result column="reviewer" property="reviewer"/>
        <result column="reviewerType" property="reviewerType"/>
        <result column="completeTime" property="completeTime"/>
    </resultMap>
 
 
 
    <select id="queryApplyReassignList" resultType="map">
        SELECT
        a.id AS id,
        DATE_FORMAT(a.insertTime, '%Y年%m月%d日%H:%i') AS applyTime,
        CASE
        WHEN a.orderType = 1 THEN c.startAddress
        WHEN a.orderType = 3 THEN b.startAddress
        WHEN a.orderType = 7 THEN t.startAddress
        ELSE NULL
        END AS startAddress,
        CASE
        WHEN a.orderType = 1 THEN c.endAddress
        WHEN a.orderType = 3 THEN b.endAddress
        WHEN a.orderType = 7 THEN t.endAddress
        ELSE NULL
        END AS endAddress,
        CONCAT(d.name, '-', f.carLicensePlate) AS applyDriver,
        CONCAT(e.name, '-', g.carLicensePlate) AS nowDriver,
        a.state AS state,
        a.orderType AS orderType
        FROM t_reassign a
        LEFT JOIN t_order_cross_city b ON (a.orderId = b.id AND a.orderType = 3)
        LEFT JOIN t_order_private_car c ON (a.orderId = c.id AND a.orderType = 1)
        LEFT JOIN t_order_transfer t ON (a.orderId = t.id AND a.orderType = 7)
        LEFT JOIN t_driver d ON (a.originalDriverId = d.id)
        LEFT JOIN t_driver e ON (a.nowDriverId = e.id)
        LEFT JOIN t_car f ON (d.carId = f.id)
        LEFT JOIN t_car g ON (e.carId = g.id)
        WHERE a.orderType IN (1, 3, 7)
        <if test="null != companyId">
            and if(d.franchiseeId is null or d.franchiseeId = 0, d.companyId = #{companyId}, d.franchiseeId = #{companyId})
        </if>
        <if test="state == 1">
            and a.state in (2) and (b.state not in (10, 12) or c.state not in (10, 12) or t.state NOT IN ( 10, 12 ))
        </if>
        <if test="state == 2">
            and a.state in (3, 4, 5)
        </if>
        order by a.insertTime desc
        <if test="null != pageNum and null != size">
            limit #{pageNum}, #{size}
        </if>
    </select>
 
 
    <select id="queryReassignInfo" resultType="map">
        SELECT
            a.id AS id,
            DATE_FORMAT( a.insertTime, '%Y.%m.%d-%H:%i' ) AS applyTime,
            CONCAT( d.`name`, '-', e.carLicensePlate ) AS applyDriver,
            a.reason AS reason,
            IF
            ( a.orderType = 1, f.nickName, g.nickName ) AS `user`,
            IF
            (
                    a.orderType = 1,
                    DATE_FORMAT( b.travelTime, '%Y.%m.%d-%H:%i' ),
                    DATE_FORMAT( c.travelTime, '%Y.%m.%d-%H:%i' )) AS travelTime,
            IF(a.orderType = 1, b.startAddress,
               IF(a.orderType = 3, c.startAddress,
                  IF(a.orderType = 7, t.startAddress, NULL))) AS startAddress,
 
            IF(a.orderType = 1, b.endAddress,
               IF(a.orderType = 3, c.endAddress,
                  IF(a.orderType = 7, t.endAddress, NULL))) AS endAddress,
 
            IF(a.orderType = 1, b.state,
               IF(a.orderType = 3, c.state,
                  IF(a.orderType = 7, t.state, NULL))) AS state,
            a.state AS `status`,
            IF
            ( a.reviewerType = 1, i.`name`, h.`name` ) AS reviewer,
            CONCAT( j.`name`, '-', k.carLicensePlate ) AS nowDriver,
            a.orderType AS orderType
        FROM
            t_reassign a
                LEFT JOIN t_order_private_car b ON ( a.orderId = b.id AND a.orderType = 1 )
                LEFT JOIN t_order_cross_city c ON ( a.orderId = c.id AND a.orderType = 3 )
                LEFT JOIN t_order_transfer t ON ( a.orderId = t.id AND a.orderType = 7 )
                LEFT JOIN t_driver d ON ( a.originalDriverId = d.id )
                LEFT JOIN t_car e ON ( a.originalCarId = e.id )
                LEFT JOIN t_user f ON ( b.userId = f.id )
                LEFT JOIN t_user g ON ( c.userId = g.id )
                LEFT JOIN sys_user h ON ( a.reviewer = h.id AND a.reviewerType = 2 )
                LEFT JOIN t_dispatch i ON ( a.reviewer = i.id AND a.reviewerType = 1 )
                LEFT JOIN t_driver j ON ( a.nowDriverId = j.id )
                LEFT JOIN t_car k ON ( a.nowCarId = k.id )
        where a.id = #{id}
    </select>
</mapper>