liujie
1 天以前 74f8b8074a2fb391b5363b4dca5f99bf31993430
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
<?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.TDriverMapper">
 
    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.stylefeng.guns.modular.system.model.TDriver">
        <id column="id" property="id" />
        <result column="code" property="code" />
        <result column="name" property="name" />
        <result column="avatar" property="avatar" />
        <result column="phone" property="phone" />
        <result column="password" property="password" />
        <result column="sex" property="sex" />
        <result column="source" property="source" />
        <result column="emergencyContact" property="emergencyContact" />
        <result column="emergencyPhone" property="emergencyPhone" />
        <result column="driverLicenseNumber" property="driverLicenseNumber" />
        <result column="driverLicense" property="driverLicense" />
        <result column="idcard" property="idcard" />
        <result column="idcardFront" property="idcardFront" />
        <result column="idcardBack" property="idcardBack" />
        <result column="inviterType" property="inviterType" />
        <result column="inviterId" property="inviterId" />
        <result column="agentId" property="agentId" />
        <result column="branchOfficeId" property="branchOfficeId" />
        <result column="balance" property="balance" />
        <result column="approvalStatus" property="approvalStatus" />
        <result column="approvalNotes" property="approvalNotes" />
        <result column="approvalUserId" property="approvalUserId" />
        <result column="approvalTime" property="approvalTime" />
        <result column="serverStatus" property="serverStatus" />
        <result column="integral" property="integral" />
        <result column="status" property="status" />
        <result column="createTime" property="createTime" />
    </resultMap>
 
    <!-- 通用查询结果列 -->
    <sql id="Base_Column_List">
        id, code, name, avatar, phone, password, sex, source, emergencyContact, emergencyPhone, driverLicenseNumber, driverLicense, idcard, idcardFront, idcardBack, inviterType, inviterId, agentId, branchOfficeId, balance, approvalStatus, approvalNotes, approvalUserId, approvalTime, serverStatus, integral, status, createTime
    </sql>
    <select id="queryIdleDriver" resultType="com.stylefeng.guns.modular.system.model.TDriver">
        select
        id as id,
        account as account,
        jobNumber as jobNumber,
        phone as phone,
        password as password,
        name as name,
        sex as sex,
        idCard as idCard,
        companyId as companyId,
        franchiseeId as franchiseeId,
        headImgUrl as headImgUrl,
        faceImgUrl as faceImgUrl,
        idCardImgUrl1 as idCardImgUrl1,
        idCardImgUrl2 as idCardImgUrl2,
        placeOfEmployment as placeOfEmployment,
        birthday as birthday,
        bankCardNumber as bankCardNumber,
        driverNationality as driverNationality,
        driverNation as driverNation,
        driverMaritalStatus as driverMaritalStatus,
        driverLanguageLevel as driverLanguageLevel,
        driverEducation as driverEducation,
        driverCensus as driverCensus,
        driverAddress as driverAddress,
        driverContactAddress as driverContactAddress,
        driverAge as driverAge,
        driveCard as driveCard,
        driveCardImgUrl as driveCardImgUrl,
        driverType as driverType,
        getDriverLicenseDate as getDriverLicenseDate,
        driverLicenseOn as driverLicenseOn,
        driverLicenseOff as driverLicenseOff,
        taxiDriver as taxiDriver,
        taxiAptitudeCard as taxiAptitudeCard,
        networkCarlssueImg as networkCarlssueImg,
        networkCarlssueOrganization as networkCarlssueOrganization,
        networkCarlssueDate as networkCarlssueDate,
        getNetworkCarProofDate as getNetworkCarProofDate,
        networkCarProofOn as networkCarProofOn,
        networkCarProofOff as networkCarProofOff,
        registerDate as registerDate,
        fullTimeDriver as fullTimeDriver,
        inDriverBlacklist as inDriverBlacklist,
        commercialType as commercialType,
        contractCompany as contractCompany,
        contractOn as contractOn,
        contractOff as contractOff,
        emergencyContact as emergencyContact,
        emergencyContactPhone as emergencyContactPhone,
        emergencyContactAddress as emergencyContactAddress,
        remark as remark,
        isPlatCar as isPlatCar,
        carId as carId,
        authState as authState,
        state as state,
        addType as addType,
        balance as balance,
        flag as flag,
        insertTime as insertTime,
        insertUser as insertUser,
        updateTime as updateTime,
        updateUser as updateUser
        from t_driver
        where flag != 3 and state = 2 and authState = 2
        <if test="null != companyId">
            <choose>
                <when test="companyId != 1">
                    and companyId = #{companyId} or franchiseeId = #{companyId}
                </when>
                <otherwise>
                    and companyId is null or companyId = 0 or companyId = 1 or franchiseeId is null or franchiseeId = 0
                </otherwise>
            </choose>
 
        </if>
        and id in
        (
        select driverId from t_driver_work where startTime &lt; now() and state = 1 and `type` like CONCAT('%', #{type}, '%')
        )
        and id in (select driverId from t_driver_orders where `type` = #{type})
    </select>
 
    <!-- 查询有车检服务权限的司机列表(分页) -->
    <select id="queryCheckServiceDrivers" resultType="com.stylefeng.guns.modular.system.controller.resp.DriverDispatchInfoResp">
        SELECT 
            d.id,
            d.name,
            d.phone,
            COALESCE(bo.branchOfficeName, '') as branchOfficeName,
            CASE 
                WHEN bo.branchOfficeName IS NOT NULL THEN bo.branchOfficeName
                ELSE ''
            END as agentName,
            d.serverStatus,
            d.approvalStatus
        FROM t_driver d
        LEFT JOIN t_branch_office bo ON d.branchOfficeId = bo.id AND bo.status = 1
        WHERE d.checkServer = #{checkServer}
        AND d.approvalStatus = #{approvalStatus}
        AND d.status = #{status}
        <if test="excludeDriverId != null">
            AND d.id != #{excludeDriverId}
        </if>
        ORDER BY d.serverStatus ASC, d.createTime DESC
        <if test="offset != null and limit != null">
            LIMIT #{offset}, #{limit}
        </if>
    </select>
 
    <!-- 查询有车检服务权限的司机列表(支持搜索) -->
    <select id="queryCheckServiceDriversWithSearch" resultType="com.stylefeng.guns.modular.system.controller.resp.DriverDispatchInfoResp">
        SELECT 
            d.id,
            d.name,
            d.phone,
            COALESCE(bo.branchOfficeName, '') as branchOfficeName,
            CASE 
                WHEN a.merchantName IS NOT NULL THEN a.merchantName
                ELSE ''
            END as agentName,
            d.serverStatus,
            d.approvalStatus
        FROM t_driver d
        LEFT JOIN t_branch_office bo ON d.branchOfficeId = bo.id AND bo.status = 1
        LEFT JOIN t_agent a ON bo.agentId = a.id AND a.status = 1
        <where>
            d.serverStatus = 1
            AND d.checkServer = #{checkServer}
            AND d.approvalStatus = #{approvalStatus}
            AND d.status = #{status}
            <if test="excludeDriverId != null">
                AND d.id != #{excludeDriverId}
            </if>
            <if test="keyword != null and keyword != ''">
                AND (d.name LIKE CONCAT('%', #{keyword}, '%') OR d.phone LIKE CONCAT('%', #{keyword}, '%'))
            </if>
            <if test="branchOfficeId != null">
                AND d.branchOfficeId = #{branchOfficeId}
            </if>
        </where>
        ORDER BY d.serverStatus ASC, d.createTime DESC
    </select>
 
    <!-- 统计有车检服务权限的司机总数(支持搜索) -->
    <select id="countCheckServiceDriversWithSearch" resultType="java.lang.Long">
        SELECT COUNT(1)
        FROM t_driver d
        LEFT JOIN t_branch_office bo ON d.branchOfficeId = bo.id AND bo.status = 1
        LEFT JOIN t_agent a ON bo.agentId = a.id AND a.status = 1
        <where>
            d.serverStatus = 1
            AND d.checkServer = #{checkServer}
            AND d.approvalStatus = #{approvalStatus}
            AND d.status = #{status}
            <if test="excludeDriverId != null">
                AND d.id != #{excludeDriverId}
            </if>
            <if test="keyword != null and keyword != ''">
                AND (d.name LIKE CONCAT('%', #{keyword}, '%') OR d.phone LIKE CONCAT('%', #{keyword}, '%'))
            </if>
        </where>
        ORDER BY d.serverStatus ASC, d.createTime DESC
    </select>
 
</mapper>