SELECT
motorcade_id,
organization_name,
motorcade_name,
motorcade_image,
motorcade_describtion,
motorcade_status,
motorcade_header_id,
motorcade_header_name,
motorcade_header_account,
motorcade_score,
create_time,
create_by,
create_by_name,
update_time,
update_by,
update_by_name,
del_flag,
check_person_id,
check_person_name,
check_person_time,
motorcade_dissolution_status
FROM
motorcade
del_flag = 1
and motorcade_id = #{motorcadeId}
and motorcade_name like concat('%', #{motorcadeName}, '%')
and motorcade_image = #{motorcadeImage}
and motorcade_describtion = #{motorcadeDescribtion}
and motorcade_status = #{motorcadeStatus}
and motorcade_header_id = #{motorcadeHeaderId}
and motorcade_header_name like concat('%', #{motorcadeHeaderName}, '%')
and motorcade_header_account like concat('%', #{motorcadeHeaderAccount}, '%')
and motorcade_score = #{motorcadeScore}
and create_by_name like concat('%', #{createByName}, '%')
and update_by_name like concat('%', #{updateByName}, '%')
and motorcade_dissolution_status = #{motorcadeDissolutionStatus}
and organization_name like concat('%', #{organizationName}, '%')
AND organization_id in
#{id}
SELECT
m.motorcade_id,
m.organization_id,
m.organization_name,
m.top_organization_id,
COUNT(d.user_id) AS driver_num,
SUM(u.vehicle_num) AS vehicle_num,
m.motorcade_name,
m.motorcade_image,
m.motorcade_describtion,
m.motorcade_status,
m.motorcade_header_id,
m.motorcade_reject_reason,
m.black_list_reason,
m.motorcade_header_name,
m.motorcade_header_account,
m.motorcade_score,
m.create_time,
m.create_by,
m.create_by_name,
m.update_time,
m.update_by,
m.update_by_name,
m.del_flag,
m.check_person_id,
m.check_person_name,
m.check_person_time,
m.motorcade_dissolution_status,
m.default_flag
FROM
motorcade m
LEFT JOIN
motorcade_driver d
ON m.motorcade_id = d.motorcade_id and d.del_flag = 1
LEFT JOIN
(SELECT
u.user_id,
COUNT(b.vehicle_id) AS vehicle_num
FROM
user_driver u
LEFT JOIN
driver_vehicle_bind b
ON u.user_id = b.driver_bind_id and b.del_flag = 1
WHERE
u.del_flag = 1
GROUP BY
u.user_id) u
ON u.user_id = d.user_id
m.del_flag = 1
and m.check_person_name like concat('%', #{checkPersonName}, '%')
/*添加时间*/
and DATE_FORMAT(m.create_time,'%Y-%m-%d') =]]> DATE_FORMAT(#{createTimeFrom},'%Y-%m-%d')
and DATE_FORMAT(m.create_time,'%Y-%m-%d') DATE_FORMAT(#{createTimeTo},'%Y-%m-%d')
/*审核时间*/
and DATE_FORMAT(m.check_person_time,'%Y-%m-%d') =]]> DATE_FORMAT(#{userAuthTimeFrom},'%Y-%m-%d')
and DATE_FORMAT(m.check_person_time,'%Y-%m-%d') DATE_FORMAT(#{userAuthTimeTo},'%Y-%m-%d')
and m.motorcade_name like concat('%', #{motorcadeName}, '%')
and m.motorcade_image = #{motorcadeImage}
and m.motorcade_describtion = #{motorcadeDescribtion}
and m.motorcade_status = #{motorcadeStatus}
and m.motorcade_header_id = #{motorcadeHeaderId}
and m.motorcade_header_name like concat('%', #{motorcadeHeaderName}, '%')
and m.motorcade_header_account like concat('%', #{motorcadeHeaderAccount}, '%')
and m.motorcade_score = #{motorcadeScore}
and m.create_by_name like concat('%', #{createByName}, '%')
and m.update_by_name like concat('%', #{updateByName}, '%')
and m.motorcade_dissolution_status = #{motorcadeDissolutionStatus}
and m.organization_name like concat('%', #{organizationName}, '%')
and m.organization_id = #{organizationId}
and m.organization_name IS NOT NULL
and m.top_organization_id = #{topOrganizationId}
and m.organization_name IS NOT NULL
AND m.organization_id in
#{id}
GROUP BY
m.motorcade_id
order by m.create_time desc
SELECT
m.motorcade_id
FROM
motorcade m
LEFT JOIN
motorcade_driver d
ON m.motorcade_id = d.motorcade_id AND d.del_flag = 1
WHERE
m.del_flag = 1
AND d.user_id = #{values}
SELECT
b.*
FROM
motorcade a
LEFT JOIN motorcade_driver b ON a.motorcade_id = b.motorcade_id
AND b.del_flag = 1
WHERE
a.del_flag = 1
AND a.motorcade_header_id = #{driverId}
SELECT
m.*,
COUNT( d.user_id ) AS driver_num,
SUM( dvb.vehicle_num ) AS vehicle_num,
WM_CONCAT(d.user_id) AS userIds,
u.user_phone
FROM
motorcade m
LEFT JOIN motorcade_driver d ON m.motorcade_id = d.motorcade_id AND d.del_flag = 1
LEFT JOIN "USER" u ON u.user_id = m.motorcade_header_id
LEFT JOIN (
SELECT
u.user_id,
COUNT( u.user_id ) AS vehicle_num
FROM
driver_vehicle_bind u
WHERE
u.del_flag = 1
GROUP BY
u.user_id
) dvb ON dvb.user_id = d.user_id AND d.del_flag = 1
WHERE
m.del_flag = 1
GROUP BY
m.motorcade_id
ORDER BY
m.create_time DESC
AND m.motorcade_id = #{motorcadeDo.motorcadeId}
AND (m.motorcade_header_id = #{motorcadeDo.myMotorcadeUserId} or d.user_id = #{motorcadeDo.myMotorcadeUserId})
AND m.motorcade_header_id = #{motorcadeDo.motorcadeHeaderId}
AND d.user_id = #{motorcadeDo.userId}
select md.motorcade_driver_id,
u.user_name,
u.user_id,
u.user_account,
group_concat( DISTINCT dvb.vehicle_license_plate_number) as vehiclePlateNumbers,
count(dvb.vehicle_license_plate_number) as vehicleNum,
ud.driver_fill,
md.create_time,
mc.agreement_url,
u.create_by,
m.motorcade_header_id,
mc.contract_status,
mc.file_id,
mc.agreement_url_pdf
from motorcade_driver md
left join "USER" u on md.user_id = u.user_id and u.del_flag = 1
left join user_driver ud on ud.user_id = md.user_id and ud.del_flag = 1
left join driver_vehicle_bind dvb
on md.user_id = dvb.driver_bind_id and dvb.del_flag = 1
left join motorcade m on m.motorcade_id = md.motorcade_id
LEFT JOIN motorcade_collection mc ON mc.user_id = md.user_id and mc.motorcade_header_id = m.motorcade_header_id
where md.del_flag = 1 and md.motorcade_id = #{motorcadeDo.motorcadeId}
group by motorcade_driver_id
select
u.user_account,
u.user_phone,
u.user_name,
dvb.vehicle_license_plate_number,
ud.*,
r.roleCode
from user_driver ud
left join "USER" u on ud.user_id = u.user_id
LEFT JOIN (SELECT
user_id,
LISTAGG(DISTINCT r.role_code, '&') WITHIN GROUP(ORDER BY r.role_code) AS roleCode
FROM
role r
LEFT JOIN user_role ur ON r.role_id = ur.role_id
AND ur.del_flag = 1
WHERE
r.del_flag = 1
AND role_code IN ( 'driver', 'carrier', 'captain' )
GROUP BY
user_id
) r ON r.user_id = u.user_id
left join motorcade_driver md on md.user_id = ud.user_id and md.del_flag = 1
left join driver_vehicle_bind dvb on u.user_id = dvb.user_id and dvb.del_flag = 1 and dvb.default_flag = 1
ud.del_flag = 1
and u.del_flag = 1
and ud.driver_fill = 3
and u.top_organization_id = #{motorcadeDriverDO.topOrganizationId}
and r.roleCode not like '%carrier%' and r.roleCode not like '%captain%'
and (md.motorcade_id != #{motorcadeDriverDO.motorcadeId} or md.motorcade_id is null)
and u.user_phone = #{motorcadeDriverDO.userPhone}
and u.user_name like concat('%', #{motorcadeDriverDO.userName}, '%')
and dvb.vehicle_license_plate_number like concat('%', #{motorcadeDriverDO.vehicleLicensePlateNumber}, '%')
group by u.user_id
SELECT
m.motorcade_id,
m.motorcade_name
FROM
motorcade m
LEFT JOIN
motorcade_driver d
ON m.motorcade_id = d.motorcade_id and d.del_flag = 1
m.del_flag = 1
and m.organization_id = #{organizationId}
and m.organization_name IS NOT NULL
and m.top_organization_id = #{topOrganizationId}
and m.organization_name IS NOT NULL