longz
2026-06-04 da780b14b8db78043d2c0f27d3bfd73111e6d550
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
136
137
138
139
140
141
142
<?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.TLineMapper">
 
    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.stylefeng.guns.modular.system.model.TLine">
        <id column="id" property="id" />
        <result column="name" property="name" />
        <result column="shiftInterval" property="shiftInterval" />
        <result column="dispatchPhone" property="dispatchPhone" />
        <result column="rakeRate" property="rakeRate" />
        <result column="state" property="state" />
        <result column="insertTime" property="insertTime" />
    </resultMap>
 
    <!-- 通用查询结果列 -->
    <sql id="Base_Column_List">
        id, name, shiftInterval, dispatchPhone, rakeRate, state, insertTime
    </sql>
 
    <!--根据条件查询线路列表-->
    <select id="getLineList" resultType="map" parameterType="com.baomidou.mybatisplus.plugins.Page">
        SELECT * FROM (SELECT IFNULL(ls.num,0) as shiftNum,su.`name` as insertUser,IFNULL(lc.num,0) as companyNum,ll.* FROM t_line as ll
        LEFT JOIN (SELECT COUNT(id) as num,lineId FROM t_line_shift where state != 3 GROUP BY lineId) as ls on ls.lineId = ll.id
        LEFT JOIN sys_user as su on su.id = ll.insertUserId
        LEFT JOIN (SELECT COUNT(id) as num,lineId FROM t_line_company GROUP BY lineId) as lc on lc.lineId = ll.id
        ) as o
        <where>
            o.state != 3
            <if test="beginTime != null and beginTime != '' and endTime != null and endTime != ''">
                AND (o.insertTime between CONCAT(#{beginTime},' 00:00:00') and CONCAT(#{endTime},' 23:59:59'))
            </if>
            <if test="name != null and name != ''">
                and o.name LIKE CONCAT('%',#{name},'%')
            </if>
            <if test="insertUser != null and insertUser != ''">
                and o.insertUser LIKE CONCAT('%',#{insertUser},'%')
            </if>
            <if test="state != null and state != ''">
                and o.state = #{state}
            </if>
            <if test="companyId != null">
                and (o.id in (select lineId from t_line_company where companyId = #{companyId}) or o.companyId = #{companyId})
            </if>
        </where>
        order by o.id desc
    </select>
 
    <!--根据线路ID查询线路已分配公司-->
    <select id="getLineCompanyList" resultType="java.util.Map">
        SELECT cc.`name` as companyName,lc.* FROM t_line_company as lc
        LEFT JOIN t_company as cc on cc.id = lc.companyId
        where lc.lineId = #{lineId}
    </select>
 
    <!--行程列表-->
    <select id="getTravelList" resultType="map" parameterType="com.baomidou.mybatisplus.plugins.Page">
        SELECT
            lsd.id as lineShiftDriverId,
            CONCAT(DATE_FORMAT(lsd.`day`, '%Y-%m-%d'), ' ', ls.startTime, ' - ', ls.endTime) as shiftTime,
            l.`name` as lineName,
            IFNULL(s.city, '') as city,
            CONCAT(d.`name`, '-', d.phone) as driver,
            COUNT(oc.id) as orderNum,
            '排班' as tripType,
            case
                when NOW() &lt; STR_TO_DATE(CONCAT(DATE_FORMAT(lsd.`day`, '%Y-%m-%d'), ' ', ls.startTime, ':00'), '%Y-%m-%d %H:%i:%s') then 1
                when NOW() &gt; STR_TO_DATE(CONCAT(DATE_FORMAT(lsd.`day`, '%Y-%m-%d'), ' ', ls.endTime, ':00'), '%Y-%m-%d %H:%i:%s') then 3
                else 2
            end as status,
            lsd.driverId as driverId,
            ls.lineId as lineId,
            lsd.`day` as day
        FROM t_line_shift_driver lsd
        LEFT JOIN t_line_shift ls on ls.id = lsd.lineShiftId and ls.state != 3
        LEFT JOIN t_line l on l.id = ls.lineId and l.state != 3
        LEFT JOIN t_driver d on d.id = lsd.driverId and d.flag != 3
        LEFT JOIN t_line_site lsite on lsite.lineId = l.id and lsite.type = 1
        LEFT JOIN t_site s on s.id = lsite.siteId
        LEFT JOIN t_order_cross_city oc on oc.lineShiftDriverId = lsd.id and oc.lineId = ls.lineId and oc.isDelete = 1
        <where>
            l.id is not null
            <if test="city != null and city != ''">
                and s.city LIKE CONCAT('%',#{city},'%')
            </if>
            <if test="lineName != null and lineName != ''">
                and l.name LIKE CONCAT('%',#{lineName},'%')
            </if>
            <if test="driverKeyword != null and driverKeyword != ''">
                and (d.name LIKE CONCAT('%',#{driverKeyword},'%') or d.phone LIKE CONCAT('%',#{driverKeyword},'%'))
            </if>
            <if test="roleType != null and roleType != '' and roleType != 1">
                and (l.id in (select lineId from t_line_company where companyId = #{companyId}) or l.companyId = #{companyId})
            </if>
        </where>
        GROUP BY lsd.id
        <if test="status != null">
            HAVING status = #{status}
        </if>
        order by lsd.day desc, ls.startTime desc, lsd.id desc
    </select>
 
    <!--行程对应订单列表-->
    <select id="getTravelOrders" resultType="map" parameterType="com.baomidou.mybatisplus.plugins.Page">
        SELECT
            o.id as id,
            o.orderNum as orderNum,
            o.travelId as travelId,
            o.travelTime as travelTime,
            o.passengers as passengers,
            o.passengersPhone as passengersPhone,
            o.startAddress as startAddress,
            o.endAddress as endAddress,
            o.orderMoney as orderMoney,
            o.state as state,
            CONCAT(d.`name`, '-', d.phone) as driver,
            l.`name` as lineName
        FROM t_order_cross_city o
        LEFT JOIN t_driver d on d.id = o.driverId
        LEFT JOIN t_line l on l.id = o.lineId
        <where>
            o.isDelete = 1
            <if test="lineShiftDriverId != null">
                and o.lineShiftDriverId = #{lineShiftDriverId}
            </if>
            <if test="lineId != null">
                and o.lineId = #{lineId}
            </if>
            <if test="driverId != null">
                and o.driverId = #{driverId}
            </if>
            <if test="roleType != null and roleType != '' and roleType == 2">
                and (o.companyId = #{companyId} or FIND_IN_SET(o.companyId,(SELECT GROUP_CONCAT(id) as ids FROM t_company where superiorId = #{companyId} GROUP BY superiorId)))
            </if>
            <if test="roleType != null and roleType != '' and roleType == 3">
                and o.companyId = #{companyId}
            </if>
        </where>
        order by o.id desc
    </select>
 
</mapper>