fix
longz
2026-04-30 83ff381c5c0e62c98cb9e3dd8e1d82771b1dc23f
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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
<?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.LineShiftDriverMapper">
 
    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.stylefeng.guns.modular.system.model.LineShiftDriver">
        <id column="id" property="id"/>
        <result column="lineShiftId" property="lineShiftId"/>
        <result column="driverId" property="driverId"/>
        <result column="day" property="day"/>
        <result column="laveSeat" property="laveSeat"/>
        <result column="laveSeatNumber" property="laveSeatNumber"/>
        <result column="totalSeat" property="totalSeat"/>
        <result column="inserTime" property="inserTime"/>
        <result column="assignType" property="assignType"/>
    </resultMap>
 
 
 
    <select id="query" resultType="LineShiftDriver">
        select
        id as id,
        lineShiftId as lineShiftId,
        driverId as driverId,
        `day` as `day`,
        laveSeat as laveSeat,
        laveSeatNumber as laveSeatNumber,
        totalSeat as totalSeat,
        inserTime as inserTime,
        assignType as assignType
        from t_line_shift_driver where 1 = 1
        <if test="null != lineShiftId">
            and lineShiftId = #{lineShiftId}
        </if>
        <if test="null != driverId">
            and driverId = #{driverId}
        </if>
        <if test="null != time">
            and DATE_FORMAT(`day`, '%Y-%m-%d') = DATE_FORMAT(#{time}, '%Y-%m-%d')
        </if>
        order by `day`
    </select>
 
 
    <select id="queryNotInLineShiftDriver" resultType="map">
        select
        d.id as id,
        CONCAT(d.`name`, '-', d.phone) as `name`
        from t_driver d
        left join t_driver_line dl on (d.id = dl.driverId)
        where d.authState = 2 and d.flag != 3 and dl.lineId in
        (
            select lineId from t_line_shift where id = #{lineShiftId}
        )
        and d.id not in
        (
            select lsd.driverId
            from t_line_shift_driver lsd
            left join t_line_shift ls on (lsd.lineShiftId = ls.id)
            where ls.id = #{lineShiftId} and DATE_FORMAT(lsd.`day`, '%Y-%m-%d') = DATE_FORMAT(#{time}, '%Y-%m-%d')
        )
    </select>
 
    <select id="getMonthScheduleStats" resultType="map">
        select
            DATE_FORMAT(lsd.`day`, '%Y-%m-%d') as dayStr,
            COUNT(lsd.id) as assignNum,
            SUM(case when lsd.assignType = 2 then 1 else 0 end) as manualNum
        from t_line_shift_driver lsd
        left join t_line_shift ls on lsd.lineShiftId = ls.id
        left join t_driver d on d.id = lsd.driverId
        where ls.lineId = #{lineId}
          and ls.state != 3
          and DATE_FORMAT(lsd.`day`, '%Y-%m-%d') between #{monthStart} and #{monthEnd}
          and d.flag != 3
          and exists (
            select 1 from t_line_company lc
            where lc.lineId = #{lineId}
              and (lc.companyId = d.companyId or lc.companyId = d.franchiseeId)
          )
        group by DATE_FORMAT(lsd.`day`, '%Y-%m-%d')
    </select>
 
    <select id="getDayShiftSchedule" resultType="map">
        select
            ls.id as lineShiftId,
            ls.startTime as startTime,
            ls.endTime as endTime,
            ls.carNum as carNum,
            COUNT(lsd.id) as assignNum,
            SUM(case when lsd.assignType = 2 then 1 else 0 end) as manualNum
        from t_line_shift ls
        left join t_line_shift_driver lsd on ls.id = lsd.lineShiftId and DATE_FORMAT(lsd.`day`, '%Y-%m-%d') = #{day}
        left join t_driver d on d.id = lsd.driverId
        where ls.lineId = #{lineId}
          and ls.state != 3
          and (lsd.id is null or d.flag != 3)
          and (
            lsd.id is null or exists (
                select 1 from t_line_company lc
                where lc.lineId = #{lineId}
                  and (lc.companyId = d.companyId or lc.companyId = d.franchiseeId)
            )
          )
        group by ls.id, ls.startTime, ls.endTime, ls.carNum
        order by ls.startTime asc
    </select>
 
    <select id="getDayShiftDrivers" resultType="map">
        select
            lsd.id as id,
            lsd.driverId as driverId,
            d.`name` as driverName,
            d.phone as driverPhone,
            lsd.assignType as assignType
        from t_line_shift_driver lsd
        left join t_driver d on d.id = lsd.driverId
        left join t_line_shift ls on ls.id = lsd.lineShiftId
        where lsd.lineShiftId = #{lineShiftId}
          and DATE_FORMAT(lsd.`day`, '%Y-%m-%d') = #{day}
          and d.flag != 3
          and exists (
            select 1 from t_line_company lc
            where lc.lineId = ls.lineId
              and (lc.companyId = d.companyId or lc.companyId = d.franchiseeId)
          )
        order by d.`name` asc, d.phone asc
    </select>
 
    <select id="getAvailableDrivers" resultType="map">
        select
            d.id as driverId,
            d.`name` as driverName,
            d.phone as driverPhone,
            ifnull(cm.seat, 5) as seatNum
        from t_driver d
        left join t_driver_line dl on dl.driverId = d.id
        left join t_car c on c.id = d.carId
        left join t_car_model cm on cm.id = c.carModelId
        where d.flag != 3
          and d.authState = 2
          and dl.lineId = #{lineId}
          and exists (
            select 1 from t_line_company lc
            where lc.lineId = #{lineId}
              and (lc.companyId = d.companyId or lc.companyId = d.franchiseeId)
          )
          and d.id not in (
            select driverId from t_line_shift_driver
            where lineShiftId = #{lineShiftId}
              and DATE_FORMAT(`day`, '%Y-%m-%d') = #{day}
          )
        order by d.`name` asc, d.phone asc
    </select>
 
    <select id="getManualSchedulesForCopy" resultType="LineShiftDriver">
        select
            lsd.id as id,
            lsd.lineShiftId as lineShiftId,
            lsd.driverId as driverId,
            lsd.`day` as `day`,
            lsd.laveSeat as laveSeat,
            lsd.laveSeatNumber as laveSeatNumber,
            lsd.totalSeat as totalSeat,
            lsd.inserTime as inserTime,
            lsd.assignType as assignType
        from t_line_shift_driver lsd
        left join t_line_shift ls on ls.id = lsd.lineShiftId
        left join t_driver d on d.id = lsd.driverId
        where lsd.assignType = 2
          and ls.lineId = #{lineId}
          and ls.state != 3
          and DATE_FORMAT(lsd.`day`, '%Y-%m-%d') between #{sourceStart} and #{sourceEnd}
          and d.flag != 3
          and exists (
            select 1 from t_line_company lc
            where lc.lineId = #{lineId}
              and (lc.companyId = d.companyId or lc.companyId = d.franchiseeId)
          )
        order by lsd.`day`, lsd.lineShiftId, lsd.driverId
    </select>
 
    <select id="countExistsSchedule" resultType="java.lang.Integer">
        select count(1)
        from t_line_shift_driver
        where lineShiftId = #{lineShiftId}
          and driverId = #{driverId}
          and DATE_FORMAT(`day`, '%Y-%m-%d') = #{day}
    </select>
 
    <select id="getSchedulesByLineAndDay" resultType="LineShiftDriver">
        select
        lsd.id as id,
        lsd.lineShiftId as lineShiftId,
        lsd.driverId as driverId,
        lsd.`day` as `day`,
        lsd.laveSeat as laveSeat,
        lsd.laveSeatNumber as laveSeatNumber,
        lsd.totalSeat as totalSeat,
        lsd.inserTime as inserTime,
        lsd.assignType as assignType
        from t_line_shift_driver lsd
        left join t_line_shift ls on ls.id = lsd.lineShiftId
        where ls.lineId = #{lineId}
          and ls.state != 3
          and DATE_FORMAT(lsd.`day`, '%Y-%m-%d') = #{day}
        order by lsd.lineShiftId, lsd.driverId
    </select>
</mapper>