lanan-system/dl-module-rescue/src/main/resources/mapper/rescue/RescueInfoMapper.xml
2025-11-04 14:45:29 +08:00

2014 lines
88 KiB
XML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?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="cn.iocoder.yudao.module.rescue.mapper.RescueInfoMapper">
<select id="selectRescueInfoList" parameterType="cn.iocoder.yudao.module.rescue.domain.RescueInfo"
resultType="cn.iocoder.yudao.module.rescue.domain.RescueInfo">
SELECT ri.*,
roi.order_status,
roi.set_money,
roi.id AS orderId,
roi.order_signing_person_id AS orderSigningPersonId,
roi.order_signing_person_name AS orderSigningPersonName,
roi.order_signing_charge_id AS orderSigningChargeId,
roi.order_signing_charge_name AS orderSigningChargeName,
roi.validation_real_name AS orderSigningRealName,
roi.payment_name AS paymentName,
roi.payment_time AS paymentTime,
roi.order_signing_remark AS orderSigningRemark
FROM rescue_info ri
left join rescue_order_info roi on roi.rescue_info_id = ri.id and roi.deleted = '0'
<where>
1 = 1
and ri.deleted = '0' AND ri.is_revoke = '0'
<if test="map.rescueStatus != null">
<choose>
<when test="map.rescueStatus == '1'.toString()">
<!-- 救援中 -->
and (ri.rescue_status = '1' or ri.rescue_status = '2' or ri.rescue_status = '3' or ri.rescue_status = '4')
</when>
<when test="map.rescueStatus == '2'.toString()">
<!--待支付 -->
and roi.order_status = '1'
</when>
<when test="map.rescueStatus == '3'.toString()">
<!-- 待取车 -->
and ri.rescue_status = '6'
</when>
<when test="map.rescueStatus == '4'.toString()">
<!-- 评价 -->
and roi.order_status = '2'
</when>
<!--<when test="map.rescueStatus == '5'.toString()">
&lt;!&ndash; 评价 &ndash;&gt;
and roi.order_status = '2' or roi.order_status = '3'
</when>-->
<when test="map.rescueStatus == '5'.toString()">
<!-- 已完成 -->
and (ri.rescue_status = '5' or ri.rescue_status = '8' or roi.order_status = '3')
</when>
<when test="map.rescueStatus == '8'.toString()">
<!-- 已还车 -->
and ri.rescue_status = '8'
</when>
<when test="map.rescueStatus == '9'.toString()">
<!-- 扣车中未解扣 -->
and (ri.rescue_type = '5' and ri.rescue_status <![CDATA[<]]> '6')
</when>
<when test="map.rescueStatus == '10'.toString()">
<!-- 已收款 -->
and roi.if_confirm_pay = '1'
</when>
<when test="map.rescueStatus == '11'.toString()">
<!-- 待收款 -->
and roi.if_confirm_pay = '0'
</when>
</choose>
</if>
<!-- <if test="map.licenseNum != null">
and ri.license_num like concat('%', #{map.licenseNum}, '%')
</if>-->
<if test="map.licenseNum != null and map.licenseNum != ''">
and (ri.license_num like concat('%', #{map.licenseNum}, '%')
or ri.connection_phone like concat('%', #{map.licenseNum}, '%')
or ri.connection_name like concat('%', #{map.licenseNum}, '%')
or ri.driver_name like concat('%', #{map.licenseNum}, '%')
or ri.driver_car_num like concat('%', #{map.licenseNum}, '%')
or ri.second_dispatch_name like concat('%', #{map.licenseNum}, '%'))
</if>
<if test="map.startTimeStr!=null and map.startTimeStr!='' ">
AND ri.rescue_time &gt;= #{map.startTimeStr}
</if>
<if test="map.endTimeStr!=null and map.endTimeStr!='' ">
AND ri.rescue_time &lt;= #{map.endTimeStr}
</if>
<!--<if test="map.deptList != null and map.deptList.size()>0">
and ri.dept_id in
<foreach collection="map.deptList" separator="," item="item" open="(" close=")">
#{item}
</foreach>
</if>-->
<if test="map.channel!=null and map.channel!='' ">
AND ri.channel = #{map.channel}
</if>
<if test="map.source!=null and map.source!='' ">
AND ri.source = #{map.source}
</if>
<if test="map.driverName!=null and map.driverName!='' ">
AND ri.driver_name = #{map.driverName}
</if>
<if test="map.driverCarNum!=null and map.driverCarNum!='' ">
AND ri.driver_car_num = #{map.driverCarNum}
</if>
<if test="map.secondDispatchName!=null and map.secondDispatchName!='' ">
AND ri.second_dispatch_name = #{map.secondDispatchName}
</if>
<if test="map.faultType!=null and map.faultType!='' ">
AND ri.fault_type = #{map.faultType}
</if>
<if test="map.rescuePosition!=null and map.rescuePosition!='' ">
AND ri.rescue_position like concat('%', #{map.rescuePosition}, '%')
</if>
<if test="map.carBrand!=null and map.carBrand!='' ">
AND ri.car_brand = #{map.carBrand}
</if>
<if test="map.carType!=null and map.carType!='' ">
AND ri.car_type = #{map.carType}
</if>
<if test="map.estimateDownCar!=null and map.estimateDownCar!='' ">
AND ri.estimate_down_car = #{map.estimateDownCar}
</if>
<if test="map.ifNewEnergy!=null and map.ifNewEnergy!='' ">
AND ri.if_new_energy = #{map.ifNewEnergy}
</if>
<if test="map.rescueType!=null and map.rescueType!='' ">
AND ri.rescue_type = #{map.rescueType}
</if>
<if test="map.feeType!=null and map.feeType!='' ">
AND ri.fee_type = #{map.feeType}
</if>
<if test="map.isKouChe!=null and map.isKouChe!='' ">
AND ri.is_kou_che = #{map.isKouChe}
</if>
<if test="map.transferReason != null and map.transferReason != '' ">
AND EXISTS (
SELECT 1
FROM rescue_info_detail rd
WHERE rd.rescue_info_id = ri.id AND rd.deleted = '0'
AND rd.title = '车辆移交'
AND rd.auto_remark LIKE '%移交事由:%'
AND TRIM(SUBSTRING_INDEX(SUBSTRING_INDEX(
rd.auto_remark, '移交事由:', -1), ',', 1))
= #{map.transferReason}
)
</if>
</where>
order by ri.create_time desc
</select>
<select id="selectRescueInfoListSecondDispatcher" parameterType="cn.iocoder.yudao.module.rescue.domain.RescueInfo"
resultType="cn.iocoder.yudao.module.rescue.domain.RescueInfo">
SELECT ri.*,
roi.order_status,
roi.set_money,
roi.id AS orderId,
roi.order_signing_person_id AS orderSigningPersonId,
roi.order_signing_person_name AS orderSigningPersonName,
roi.order_signing_charge_id AS orderSigningChargeId,
roi.order_signing_charge_name AS orderSigningChargeName,
roi.payment_name AS paymentName,
roi.payment_time AS paymentTime,
roi.validation_real_name AS orderSigningRealName
FROM rescue_info ri
left join rescue_order_info roi on roi.rescue_info_id = ri.id and roi.deleted = '0'
<where>
1 = 1
and ri.deleted = '0' AND ri.is_revoke = '0'
and ri.second_dispatch_id = #{map.userId}
<if test="map.rescueStatus != null">
<choose>
<when test="map.rescueStatus == '1'.toString()">
<!-- 救援中 -->
and (ri.rescue_status = '1' or ri.rescue_status = '2' or ri.rescue_status = '3' or ri.rescue_status = '4')
</when>
<when test="map.rescueStatus == '2'.toString()">
<!--待支付 -->
and roi.order_status = '1'
</when>
<when test="map.rescueStatus == '3'.toString()">
<!-- 待取车 -->
and ri.rescue_status = '6'
</when>
<when test="map.rescueStatus == '4'.toString()">
<!-- 评价 -->
and roi.order_status = '2'
</when>
<when test="map.rescueStatus == '5'.toString()">
<!-- 评价 -->
-- and roi.order_status = '3'
and (ri.rescue_status = '5' or ri.rescue_status = '8' or roi.order_status = '3')
</when>
<when test="map.rescueStatus == '8'.toString()">
<!-- 已还车 -->
and ri.rescue_status = '8'
</when>
<when test="map.rescueStatus == '9'.toString()">
<!-- 扣车中未解扣 -->
and (ri.rescue_type = '5' and ri.rescue_status <![CDATA[<]]> '6')
</when>
</choose>
</if>
<!--<if test="map.licenseNum != null">
and ri.license_num like concat('%', #{map.licenseNum}, '%')
</if>-->
<if test="map.licenseNum != null and map.licenseNum != ''">
and (ri.license_num like concat('%', #{map.licenseNum}, '%')
or ri.connection_phone like concat('%', #{map.licenseNum}, '%')
or ri.connection_name like concat('%', #{map.licenseNum}, '%')
or ri.driver_name like concat('%', #{map.licenseNum}, '%')
or ri.driver_car_num like concat('%', #{map.licenseNum}, '%'))
</if>
<if test="map.startTimeStr!=null and map.startTimeStr!='' ">
AND ri.rescue_time &gt;= #{map.startTimeStr}
</if>
<if test="map.endTimeStr!=null and map.endTimeStr!='' ">
AND ri.rescue_time &lt;= #{map.endTimeStr}
</if>
<!--<if test="map.deptList != null and map.deptList.size()>0">
and ri.dept_id in
<foreach collection="map.deptList" separator="," item="item" open="(" close=")">
#{item}
</foreach>
</if>-->
<if test="map.channel!=null and map.channel!='' ">
AND ri.channel = #{map.channel}
</if>
<if test="map.source!=null and map.source!='' ">
AND ri.source = #{map.source}
</if>
<if test="map.driverName!=null and map.driverName!='' ">
AND ri.driver_name = #{map.driverName}
</if>
<if test="map.driverCarNum!=null and map.driverCarNum!='' ">
AND ri.driver_car_num = #{map.driverCarNum}
</if>
<if test="map.secondDispatchName!=null and map.secondDispatchName!='' ">
AND ri.second_dispatch_name = #{map.secondDispatchName}
</if>
</where>
order by ri.create_time desc
</select>
<select id="selectRescueInfoRevokeList" parameterType="cn.iocoder.yudao.module.rescue.domain.RescueInfo"
resultType="cn.iocoder.yudao.module.rescue.domain.RescueInfo">
SELECT ri.*,
roi.order_status,
roi.set_money,
roi.id AS orderId,
roi.order_signing_person_id AS orderSigningPersonId,
roi.order_signing_person_name AS orderSigningPersonName,
roi.order_signing_charge_id AS orderSigningChargeId,
roi.order_signing_charge_name AS orderSigningChargeName,
roi.validation_real_name AS orderSigningRealName,
roi.order_signing_remark AS orderSigningRemark
FROM rescue_info ri
left join rescue_order_info roi on roi.rescue_info_id = ri.id
<where>
1 = 1
and ri.deleted = '0' AND ri.is_revoke = '1'
<if test="map.licenseNum != null and map.licenseNum != ''">
and (ri.license_num like concat('%', #{map.licenseNum}, '%')
or ri.connection_phone like concat('%', #{map.licenseNum}, '%')
or ri.connection_name like concat('%', #{map.licenseNum}, '%')
or ri.driver_name like concat('%', #{map.licenseNum}, '%')
or ri.driver_car_num like concat('%', #{map.licenseNum}, '%'))
</if>
<if test="map.startTimeStr!=null and map.startTimeStr!='' ">
AND ri.revoke_time &gt;= #{map.startTimeStr}
</if>
<if test="map.endTimeStr!=null and map.endTimeStr!='' ">
AND ri.revoke_time &lt;= #{map.endTimeStr}
</if>
</where>
order by ri.create_time desc
</select>
<select id="selectRescueInfoRevokeListSecondDispatcher" parameterType="cn.iocoder.yudao.module.rescue.domain.RescueInfo"
resultType="cn.iocoder.yudao.module.rescue.domain.RescueInfo">
SELECT ri.*,
roi.order_status,
roi.set_money,
roi.id AS orderId,
roi.order_signing_person_id AS orderSigningPersonId,
roi.order_signing_person_name AS orderSigningPersonName,
roi.order_signing_charge_id AS orderSigningChargeId,
roi.order_signing_charge_name AS orderSigningChargeName,
roi.validation_real_name AS orderSigningRealName
FROM rescue_info ri
left join rescue_order_info roi on roi.rescue_info_id = ri.id
<where>
1 = 1
and ri.deleted = '0' AND ri.is_revoke = '1'
and ri.second_dispatch_id = #{map.userId}
<if test="map.licenseNum != null and map.licenseNum != ''">
and (ri.license_num like concat('%', #{map.licenseNum}, '%')
or ri.connection_phone like concat('%', #{map.licenseNum}, '%')
or ri.connection_name like concat('%', #{map.licenseNum}, '%')
or ri.driver_name like concat('%', #{map.licenseNum}, '%')
or ri.driver_car_num like concat('%', #{map.licenseNum}, '%'))
</if>
<if test="map.startTimeStr!=null and map.startTimeStr!='' ">
AND ri.revoke_time &gt;= #{map.startTimeStr}
</if>
<if test="map.endTimeStr!=null and map.endTimeStr!='' ">
AND ri.revoke_time &lt;= #{map.endTimeStr}
</if>
</where>
order by ri.create_time desc
</select>
<select id="selectRescueInfoAndOrderById" resultType="cn.iocoder.yudao.module.rescue.domain.RescueInfo">
SELECT ri.*,
roi.order_status,
roi.set_money,
roi.id as rescueOrderId,
roi.pay_type,
roi.pay_money,
roi.pay_time,
roi.order_signing_person_name,
roi.order_signing_charge_name,
roi.order_signing_remark,
roi.if_confirm_pay,
roi.confirm_payment_person_name,
roi.confirm_payment_time,
roi.confirm_payment_person_remark
FROM rescue_info ri
left join rescue_order_info roi on roi.rescue_info_id = ri.id
where ri.deleted = '0' AND ri.is_revoke = '0' and ri.id = #{id}
order by ri.create_time desc
</select>
<select id="selectRescueListSystem2" resultType="cn.iocoder.yudao.module.rescue.domain.RescueInfo">
SELECT ri.*,
roi.order_status,
roi.set_money,
roi.id as rescueOrderId,
roi.pay_type,
roi.pay_money,
roi.pay_time,
roi.order_signing_person_name,
roi.order_signing_charge_name,
roi.order_signing_remark,
roi.if_confirm_pay,
roi.account_number,
roi.confirm_payment_person_name,
roi.confirm_payment_time,
roi.confirm_payment_person_remark,
roi.if_billed,
roi.billed_userid,
roi.billed_username ,
roi.billed_qrcode,
roi.billed_remark
FROM rescue_info ri
left join rescue_order_info roi on roi.rescue_info_id = ri.id
where ri.deleted = '0' AND ri.is_revoke = '0'
<if test="map.orderStatus != null and map.orderStatus != ''">
and roi.order_status = #{map.orderStatus}
</if>
<if test="map.channel != null and map.channel != ''">
and ri.channel = #{map.channel}
</if>
<if test="map.ifConfirmPay != null and map.ifConfirmPay != ''">
and roi.if_confirm_pay = #{map.ifConfirmPay}
</if>
<if test="map.source != null and map.source != ''">
and ri.source = #{map.source}
</if>
<if test="map.secondDispatchName != null and map.secondDispatchName != ''">
and ri.second_dispatch_name = #{map.secondDispatchName}
</if>
<if test="map.rescueStatus != null and map.rescueStatus != ''">
and if(#{map.rescueStatus} = 0, ri.rescue_status not in(6,8,9), ri.rescue_status = #{map.rescueStatus})
</if>
<if test="map.licenseNum != null">
and ri.license_num like concat('%', #{map.licenseNum}, '%')
</if>
<if test="map.connectionName != null">
and ri.connection_name like concat('%', #{map.connectionName}, '%')
</if>
<if test="map.connectionPhone != null">
and ri.connection_phone like concat('%', #{map.connectionPhone}, '%')
</if>
<if test="map.driverName != null">
and ri.driver_name like concat('%', #{map.driverName}, '%')
</if>
<if test="map.driverCarNum != null">
and ri.driver_car_num like concat('%', #{map.driverCarNum}, '%')
</if>
<if test="map.rescueType != null">
and ri.rescue_type = #{map.rescueType}
</if>
<if test="map.feeType != null">
and ri.fee_type = #{map.feeType}
</if>
<if test="map.flag != null">
and ri.driver_id is not null
</if>
<if test="map.rescueStart != null and map.rescueEnd != null">
and rescue_time between
concat(#{map.rescueStart}, ' 00:00:00') and concat(#{map.rescueEnd}, ' 23:59:59')
</if>
<if test="map.deptId != null">
and if(#{map.deptId} = 0, ri.dept_id is null, ri.dept_id = #{map.deptId})
</if>
order by ri.create_time desc
</select>
<select id="selectRescueListByRevoke" resultType="cn.iocoder.yudao.module.rescue.domain.RescueInfo">
SELECT ri.*,
roi.order_status,
roi.set_money,
roi.id as rescueOrderId,
roi.pay_type,
roi.pay_money,
roi.pay_time,
roi.order_signing_person_name,
roi.order_signing_charge_name,
roi.order_signing_remark,
roi.if_confirm_pay,
roi.confirm_payment_person_name,
roi.confirm_payment_time,
roi.confirm_payment_person_remark
FROM rescue_info ri
left join rescue_order_info roi on roi.rescue_info_id = ri.id
where ri.deleted = '0' AND ri.is_revoke = '1'
<if test="map.orderStatus != null and map.orderStatus != ''">
and roi.order_status = #{map.orderStatus}
</if>
<if test="map.rescueStatus != null and map.rescueStatus != ''">
and if(#{map.rescueStatus} = 0, ri.rescue_status not in(6,8,9), ri.rescue_status = #{map.rescueStatus})
</if>
<if test="map.licenseNum != null">
and ri.license_num like concat('%', #{map.licenseNum}, '%')
</if>
<if test="map.connectionName != null">
and ri.connection_name like concat('%', #{map.connectionName}, '%')
</if>
<if test="map.driverName != null">
and ri.driver_name like concat('%', #{map.driverName}, '%')
</if>
<if test="map.driverCarNum != null">
and ri.driver_car_num like concat('%', #{map.driverCarNum}, '%')
</if>
<if test="map.rescueType != null">
and ri.rescue_type = #{map.rescueType}
</if>
<if test="map.feeType != null">
and ri.fee_type = #{map.feeType}
</if>
<if test="map.flag != null">
and ri.driver_id is not null
</if>
<if test="map.rescueStart != null and map.rescueEnd != null">
and rescue_time between
concat(#{map.rescueStart}, ' 00:00:00') and concat(#{map.rescueEnd}, ' 23:59:59')
</if>
<if test="map.deptId != null">
and if(#{map.deptId} = 0, ri.dept_id is null, ri.dept_id = #{map.deptId})
</if>
order by ri.create_time desc
</select>
<select id="listData" resultType="com.alibaba.fastjson.JSONObject">
SELECT sum(set_money / 100) as allMoney,
count(1) as allNum,
sum(case
when ri.car_type = '1' then (set_money / 100) *
${rescueTcBig}
when ri.car_type = '2' then (set_money / 100) * ${rescueTcMid}
when ri.car_type = '3' then (set_money / 100) * ${rescueTcSmall}
else 0 end) as tcAll
FROM rescue_info ri
left join rescue_order_info roi on roi.rescue_info_id = ri.id
<where>
<if test="driverName != null">
and ri.driver_name like concat('%', #{driverName}, '%')
</if>
<if test="driverCarNum != null">
and ri.driver_car_num like concat('%', #{driverCarNum}, '%')
</if>
<if test="flag != null">
and ri.driver_id is not null
</if>
<if test="rescueStart != null">
and rescue_time like concat(#{rescueStart}, '%')
</if>
</where>
</select>
<select id="selectRescueInfoListApp" parameterType="cn.iocoder.yudao.module.rescue.domain.RescueInfo"
resultType="cn.iocoder.yudao.module.rescue.domain.RescueInfo">
SELECT ri.*,
roi.order_status,
roi.set_money
FROM rescue_info ri
left join rescue_order_info roi on roi.rescue_info_id = ri.id
<where>
(ri.user_id = #{map.userId} or connection_phone = #{map.connectionPhone})
<if test="map.rescueStatus != null">
<!-- <choose>-->
<!-- <when test="map.rescueStatus == '1'.toString()">-->
<!-- &lt;!&ndash; 救援中 &ndash;&gt;-->
<!-- and (ri.rescue_status = '1' or ri.rescue_status = '2' or ri.rescue_status = '3')-->
<!-- </when>-->
<!-- <when test="map.rescueStatus == '2'.toString()">-->
<!-- &lt;!&ndash;待支付 &ndash;&gt;-->
<!-- and roi.order_status ='1'-->
<!-- </when>-->
<!-- <when test="map.rescueStatus == '3'.toString()">-->
<!-- &lt;!&ndash; 待取车 &ndash;&gt;-->
<!-- and ri.rescue_status ='6'-->
<!-- </when>-->
<!-- <when test="map.rescueStatus == '4'.toString()">-->
<!-- &lt;!&ndash; 评价 &ndash;&gt;-->
<!-- and roi.order_status ='2'-->
<!-- </when>-->
<!-- <when test="map.rescueStatus == '5'.toString()">-->
<!-- &lt;!&ndash; 评价 &ndash;&gt;-->
<!-- and roi.order_status ='3'-->
<!-- </when>-->
<!-- <when test="map.rescueStatus == '8'.toString()">-->
<!-- &lt;!&ndash; 已还车 &ndash;&gt;-->
<!-- and ri.rescue_status ='8'-->
<!-- </when>-->
<!-- </choose>-->
<!--
目前数据库有救援状态2、3、4、5、6、8、9订单状态0123几个状态
救援状态:
2待救援
3救援中
5已完成
6待取车/已解扣
8已取走/已还车
9扣车中
订单状态:
0已成单
1待支付
2待评价
3已完成
字典:救援状态:jy_status:记A,扣车状态:rescue_status:记B,救援订单状态jy_order_status:记C
2、3、5独在A
6、8在A、B都有使用地方不一样
9独在B
订单状态只在C
-->
<choose>
<!-- 首页查询:待救援和救援中 -->
<when test="map.rescueStatus == '1'.toString() ">
and (ri.rescue_status = '2' or ri.rescue_status = '3')
</when>
<!-- 待支付 -->
<when test="map.rescueStatus == '2'.toString() ">
and roi.order_status ='1'
</when>
<!-- 待取车 -->
<when test="map.rescueStatus == '3'.toString() ">
and ri.rescue_status ='6'
</when>
<!-- 待评价 -->
<when test="map.rescueStatus == '4'.toString() ">
and roi.order_status ='2'
</when>
<!-- 已完成 -->
<when test="map.rescueStatus == '5'.toString() ">
and roi.order_status ='3'
</when>
</choose>
</if>
<if test="map.licenseNum != null">
and ri.license_num like concat('%', #{map.licenseNum}, '%')
</if>
</where>
order by ri.create_time desc
</select>
<select id="getKcList" parameterType="cn.iocoder.yudao.module.rescue.domain.RescueInfo"
resultType="cn.iocoder.yudao.module.rescue.domain.RescueInfo">
select *
from rescue_info ri
<where>
dept_id = #{map.deptId}
and rescue_type = '5'
<if test="map.connectionName != null and map.connectionName != ''">
and (connection_name like concat('%', #{map.connectionName}, '%') or connection_phone like concat('%',
#{map.connectionPhone},
'%') or
license_num like concat('%', #{map.licenseNum}, '%'))
</if>
<if test="map.rescueStatus != null">
<choose>
<when test="map.rescueStatus == '1'.toString()">
<!-- 扣车中 -->
and rescue_status <![CDATA[<]]> '6'
</when>
<when test="map.rescueStatus == '2'.toString()">
<!-- 已解 -->
and rescue_status <![CDATA[>=]]> '6'
</when>
</choose>
</if>
</where>
order by create_time desc
</select>
<select id="driverList" resultType="cn.iocoder.yudao.module.rescue.domain.DriverInfo">
SELECT su.id AS userId,
su.nickname AS nickName,
su.mobile AS phonenumber,
su.sex as sex,
su.avatar as avatar,
di.*
FROM driver_info di
INNER JOIN system_users su ON di.user_id = su.id
AND su.deleted = '0'
WHERE 1 = 1
AND di.deleted = '0'
AND di.staff_type = 'jysj'
<if test="map.nickName != null and map.nickName != ''">
and su.nickname like concat('%', #{map.nickName}, '%')
</if>
<if test="map.phonenumber != null and map.phonenumber != ''">
and su.mobile like concat('%', #{map.phonenumber}, '%')
</if>
<if test="map.driveStatus != null and map.driveStatus != ''">
and di.driver_status = #{map.driveStatus}
</if>
<if test="map.authStatus != null and map.authStatus != ''">
and di.auth_status = #{map.authStatus}
</if>
<if test="map.carType != null and map.carType != ''">
and di.car_type = #{map.carType}
</if>
<if test="map.carLicenseNum != null and map.carLicenseNum != ''">
and di.car_license_num like concat('%', #{map.carLicenseNum}, '%')
</if>
order by di.create_time desc
</select>
<select id="driverListApp" resultType="cn.iocoder.yudao.module.rescue.dto.DriverInfo2Dto">
SELECT di.*,
su.nickname as real_name,
rci.rescue_car_num
FROM driver_info di
INNER JOIN system_users su ON di.user_id = su.id AND su.deleted = '0'
left join system_dept sd on sd.id = di.dept_id
inner join rescue_car_info rci on rci.possessor_id = di.id
WHERE di.auth_status = '2'
<if test="searchValue != null and searchValue != ''">
and (su.nickname like concat('%', #{searchValue}, '%') or
di.phonenumber like concat('%', #{searchValue}, '%')
or rci.rescue_car_num like concat('%', #{searchValue}, '%'))
</if>
order by di.create_time desc
</select>
<!--<select id="driverListAppNew" resultType="cn.iocoder.yudao.module.rescue.dto.DriverInfo2Dto">
SELECT
di.*,
su.nickname as real_name,
car_data.rescue_car_num,
car_data.driver_car_category
FROM
driver_info di
INNER JOIN
system_users su ON di.user_id = su.id AND su.deleted = '0'
LEFT JOIN
system_dept sd ON sd.id = di.dept_id AND sd.deleted = 0
INNER JOIN (
SELECT
rdcr.driver_id,
COALESCE(
MAX(CASE WHEN rdcr.is_primary = 1 THEN rci.rescue_car_num END),
SUBSTRING_INDEX(GROUP_CONCAT(rci.rescue_car_num ORDER BY rdcr.is_primary DESC, rdcr.create_time SEPARATOR ','), ',', 1)
) as rescue_car_num
FROM
rescue_driver_car_relation rdcr
INNER JOIN
rescue_car_info rci ON rci.id = rdcr.car_id AND rci.deleted = 0
WHERE
rdcr.deleted = 0
<if test="searchValue != null and searchValue != ''">
AND rci.rescue_car_num like concat('%', #{searchValue}, '%')
</if>
GROUP BY
rdcr.driver_id
HAVING
rescue_car_num IS NOT NULL
) car_data ON car_data.driver_id = di.id
WHERE
di.auth_status = '2'
AND di.deleted = 0
<if test="searchValue != null and searchValue != ''">
AND (su.nickname like concat('%', #{searchValue}, '%')
OR di.phonenumber like concat('%', #{searchValue}, '%')
OR car_data.rescue_car_num like concat('%', #{searchValue}, '%'))
</if>
ORDER BY
di.create_time DESC;
</select>-->
<select id="driverListAppNew" resultType="cn.iocoder.yudao.module.rescue.dto.DriverInfo2Dto">
SELECT
di.*,
su.nickname as real_name,
car_data.rescue_car_num,
car_data.driver_car_category
FROM
driver_info di
INNER JOIN
system_users su ON di.user_id = su.id AND su.deleted = '0'
LEFT JOIN
system_dept sd ON sd.id = di.dept_id AND sd.deleted = 0
INNER JOIN (
SELECT
rdcr.driver_id,
COALESCE(
MAX(CASE WHEN rdcr.is_primary = 1 THEN rci.rescue_car_num END),
SUBSTRING_INDEX(GROUP_CONCAT(rci.rescue_car_num ORDER BY rdcr.is_primary DESC, rdcr.create_time SEPARATOR ','), ',', 1)
) as rescue_car_num,
COALESCE(
MAX(CASE WHEN rdcr.is_primary = 1 THEN rci.car_category END),
SUBSTRING_INDEX(GROUP_CONCAT(rci.car_category ORDER BY rdcr.is_primary DESC, rdcr.create_time SEPARATOR ','), ',', 1)
) as driver_car_category
FROM
rescue_driver_car_relation rdcr
INNER JOIN
rescue_car_info rci ON rci.id = rdcr.car_id AND rci.deleted = 0
WHERE
rdcr.deleted = 0
<if test="searchValue != null and searchValue != ''">
AND rci.rescue_car_num like concat('%', #{searchValue}, '%')
</if>
GROUP BY
rdcr.driver_id
HAVING
rescue_car_num IS NOT NULL
) car_data ON car_data.driver_id = di.id
WHERE
di.auth_status = '2'
AND di.deleted = 0
<if test="searchValue != null and searchValue != ''">
AND (su.nickname like concat('%', #{searchValue}, '%')
OR di.phonenumber like concat('%', #{searchValue}, '%')
OR car_data.rescue_car_num like concat('%', #{searchValue}, '%'))
</if>
ORDER BY
di.create_time DESC;
</select>
<select id="secondDriverListApp" resultType="cn.iocoder.yudao.module.rescue.dto.DriverInfo2Dto">
SELECT di.*,
su.nickname as real_name,
rci.rescue_car_num
FROM driver_info di
INNER JOIN system_users su ON di.user_id = su.id AND su.deleted = '0'
left join system_dept sd on sd.id = di.dept_id
inner join rescue_car_info rci on rci.possessor_id = di.id
WHERE di.auth_status = '2'
AND FIND_IN_SET(#{userId}, di.second_dispatcher_id) > 0
<if test="searchValue != null and searchValue != ''">
and (su.nickname like concat('%', #{searchValue}, '%') or
di.phonenumber like concat('%', #{searchValue}, '%')
or rci.rescue_car_num like concat('%', #{searchValue}, '%'))
</if>
order by di.create_time desc
</select>
<!--<select id="secondDriverListAppNew" resultType="cn.iocoder.yudao.module.rescue.dto.DriverInfo2Dto">
SELECT
di.*,
su.nickname as real_name,
car_data.rescue_car_num
FROM
driver_info di
INNER JOIN
system_users su ON di.user_id = su.id AND su.deleted = '0'
LEFT JOIN
system_dept sd ON sd.id = di.dept_id AND sd.deleted = 0
INNER JOIN (
SELECT
rdcr.driver_id,
COALESCE(
MAX(CASE WHEN rdcr.is_primary = 1 THEN rci.rescue_car_num END),
SUBSTRING_INDEX(GROUP_CONCAT(rci.rescue_car_num ORDER BY rdcr.is_primary DESC, rdcr.create_time SEPARATOR ','), ',', 1)
) as rescue_car_num
FROM
rescue_driver_car_relation rdcr
INNER JOIN
rescue_car_info rci ON rci.id = rdcr.car_id AND rci.deleted = 0
WHERE
rdcr.deleted = 0
<if test="searchValue != null and searchValue != ''">
AND rci.rescue_car_num like concat('%', #{searchValue}, '%')
</if>
GROUP BY
rdcr.driver_id
HAVING
rescue_car_num IS NOT NULL
) car_data ON car_data.driver_id = di.id
WHERE
di.auth_status = '2'
AND di.deleted = 0
AND FIND_IN_SET(#{userId}, di.second_dispatcher_id) > 0
<if test="searchValue != null and searchValue != ''">
AND (su.nickname like concat('%', #{searchValue}, '%')
OR di.phonenumber like concat('%', #{searchValue}, '%')
OR car_data.rescue_car_num like concat('%', #{searchValue}, '%'))
</if>
ORDER BY
di.create_time DESC;
</select>-->
<select id="secondDriverListAppNew" resultType="cn.iocoder.yudao.module.rescue.dto.DriverInfo2Dto">
SELECT
di.*,
su.nickname as real_name,
car_data.rescue_car_num,
car_data.driver_car_category
FROM
driver_info di
INNER JOIN
system_users su ON di.user_id = su.id AND su.deleted = '0'
LEFT JOIN
system_dept sd ON sd.id = di.dept_id AND sd.deleted = 0
INNER JOIN (
SELECT
rdcr.driver_id,
COALESCE(
MAX(CASE WHEN rdcr.is_primary = 1 THEN rci.rescue_car_num END),
SUBSTRING_INDEX(GROUP_CONCAT(rci.rescue_car_num ORDER BY rdcr.is_primary DESC, rdcr.create_time SEPARATOR ','), ',', 1)
) as rescue_car_num,
COALESCE(
MAX(CASE WHEN rdcr.is_primary = 1 THEN rci.car_category END),
SUBSTRING_INDEX(GROUP_CONCAT(rci.car_category ORDER BY rdcr.is_primary DESC, rdcr.create_time SEPARATOR ','), ',', 1)
) as driver_car_category
FROM
rescue_driver_car_relation rdcr
INNER JOIN
rescue_car_info rci ON rci.id = rdcr.car_id AND rci.deleted = 0
WHERE
rdcr.deleted = 0
<if test="searchValue != null and searchValue != ''">
AND rci.rescue_car_num like concat('%', #{searchValue}, '%')
</if>
GROUP BY
rdcr.driver_id
HAVING
rescue_car_num IS NOT NULL
) car_data ON car_data.driver_id = di.id
WHERE
di.auth_status = '2'
AND di.deleted = 0
AND FIND_IN_SET(#{userId}, di.second_dispatcher_id) > 0
<if test="searchValue != null and searchValue != ''">
AND (su.nickname like concat('%', #{searchValue}, '%')
OR di.phonenumber like concat('%', #{searchValue}, '%')
OR car_data.rescue_car_num like concat('%', #{searchValue}, '%'))
</if>
ORDER BY
di.create_time DESC;
</select>
<select id="driverInMap2" resultType="java.util.Map">
SELECT IFNULL(sum(di.driver_status = '1'), 0) as kxNum,
IFNULL(sum(di.driver_status = '2'), 0) as ztNum,
IFNULL(sum(di.driver_status = '3'), 0) as mlNum,
IFNULL(sum(di.driver_status = '4'), 0) as lxNum
FROM driver_info di
INNER JOIN system_users su ON di.user_id = su.id
AND su.deleted = '0'
LEFT JOIN system_dept sd ON sd.id = di.dept_id
INNER JOIN rescue_car_info rci ON rci.possessor_id = di.id
WHERE di.auth_status = '2'
</select>
<update id="dealOverTimeRescue">
UPDATE rescue_info
SET need_system = '1'
WHERE need_system = '0'
AND driver_id IS NULL
AND TIMESTAMPDIFF(
MINUTE, rescue_time,
NOW()) > 5
AND rescue_status = '2'
</update>
<select id="getOverTimeRescue" resultType="cn.iocoder.yudao.module.rescue.domain.RescueInfo">
SELECT ri.*,
MAX(rdi.driver_level) as driverLevel
FROM rescue_info ri
INNER JOIN rescue_driver_info rdi ON ri.id = rdi.rescue_id
WHERE ri.driver_id IS NULL
AND ri.rescue_status = '2'
GROUP BY ri.id
HAVING TIMESTAMPDIFF(
MINUTE, MAX(rdi.create_time),
NOW()) <![CDATA[>]]> 3
</select>
<select id="getRescueStatistics" resultType="java.util.Map">
SELECT IFNULL(sum(ri.rescue_status = '2' or ri.rescue_status = '3'), 0) as jyzNum,
IFNULL(sum(roi.order_status = '1'), 0) as dzfNum,
IFNULL(sum(ri.rescue_status = '6'), 0) as dqcNum,
IFNULL(sum(ri.rescue_status <![CDATA[>=]]> '5'), 0) as ywcNum,
IFNULL(sum(ri.is_wei_xiu = '1'), 0) as zwxNum
FROM rescue_info ri
left join rescue_order_info roi on roi.rescue_info_id = ri.id
where ri.user_id = #{userId}
or connection_phone = #{connectionPhone}
</select>
<select id="getRescueStatisticsByAdmin" resultType="java.util.Map">
SELECT IFNULL(sum(ri.rescue_status = '3' or ri.rescue_status = '4'), 0) as jyzNum,
IFNULL(sum(roi.order_status = '1'), 0) as dzfNum,
IFNULL(sum(ri.rescue_status = '6'), 0) as dqcNum,
IFNULL(sum(ri.rescue_status <![CDATA[>=]]> '5'), 0) as ywcNum,
IFNULL(sum(ri.is_wei_xiu = '1'), 0) as zwxNum,
IFNULL(count(ri.id), 0) as yjdNum,
IFNULL(sum(roi.set_money), 0) as yingskNum,
IFNULL(sum(CASE WHEN roi.if_confirm_pay = '1' THEN roi.pay_money ELSE 0 END), 0) as yiskNum,
IFNULL(sum(CASE WHEN roi.if_confirm_pay = '0' THEN roi.set_money ELSE 0 END), 0) as dskNum
FROM rescue_info ri
left join rescue_order_info roi on roi.rescue_info_id = ri.id AND roi.deleted = 0
where 1 = 1 AND ri.deleted = 0 AND ri.is_revoke = 0
<if test="map.deptList != null and map.deptList.size()>0">
and ri.dept_id in
<foreach collection="map.deptList" separator="," item="item" open="(" close=")">
#{item}
</foreach>
</if>
<if test="map.startTimeStr!=null and map.startTimeStr!='' ">
AND ri.create_time &gt;= #{map.startTimeStr}
</if>
<if test="map.endTimeStr!=null and map.endTimeStr!='' ">
AND ri.create_time &lt;= #{map.endTimeStr}
</if>
<if test="map.channel!=null and map.channel!='' ">
AND ri.channel = #{map.channel}
</if>
<if test="map.source!=null and map.source!='' ">
AND ri.source = #{map.source}
</if>
<if test="map.driverName!=null and map.driverName!='' ">
AND ri.driver_name = #{map.driverName}
</if>
<if test="map.driverCarNum!=null and map.driverCarNum!='' ">
AND ri.driver_car_num = #{map.driverCarNum}
</if>
<if test="map.secondDispatchName!=null and map.secondDispatchName!='' ">
AND ri.second_dispatch_name = #{map.secondDispatchName}
</if>
</select>
<select id="getRescueStatisticsBySecondDispatcher" resultType="java.util.Map">
SELECT IFNULL(sum(ri.rescue_status = '3' or ri.rescue_status = '4'), 0) as jyzNum,
IFNULL(sum(roi.order_status = '1'), 0) as dzfNum,
IFNULL(sum(ri.rescue_status = '6'), 0) as dqcNum,
IFNULL(sum(ri.rescue_status <![CDATA[>=]]> '5'), 0) as ywcNum,
IFNULL(sum(ri.is_wei_xiu = '1'), 0) as zwxNum,
IFNULL(count(ri.id), 0) as yjdNum,
IFNULL(sum(roi.set_money), 0) as yingskNum,
IFNULL(sum(CASE WHEN roi.if_confirm_pay = '1' THEN roi.pay_money ELSE 0 END), 0) as yiskNum,
IFNULL(sum(CASE WHEN roi.if_confirm_pay = '0' THEN roi.set_money ELSE 0 END), 0) as dskNum
FROM rescue_info ri
left join rescue_order_info roi on roi.rescue_info_id = ri.id AND roi.deleted = 0
where 1 = 1 AND ri.deleted = 0 AND ri.is_revoke = 0
AND ri.second_dispatch_id = #{map.userId}
<if test="map.deptList != null and map.deptList.size()>0">
and ri.dept_id in
<foreach collection="map.deptList" separator="," item="item" open="(" close=")">
#{item}
</foreach>
</if>
<if test="map.startTimeStr!=null and map.startTimeStr!='' ">
AND ri.create_time &gt;= #{map.startTimeStr}
</if>
<if test="map.endTimeStr!=null and map.endTimeStr!='' ">
AND ri.create_time &lt;= #{map.endTimeStr}
</if>
<if test="map.channel!=null and map.channel!='' ">
AND ri.channel = #{map.channel}
</if>
<if test="map.source!=null and map.source!='' ">
AND ri.source = #{map.source}
</if>
<if test="map.driverName!=null and map.driverName!='' ">
AND ri.driver_name = #{map.driverName}
</if>
<if test="map.driverCarNum!=null and map.driverCarNum!='' ">
AND ri.driver_car_num = #{map.driverCarNum}
</if>
<if test="map.secondDispatchName!=null and map.secondDispatchName!='' ">
AND ri.second_dispatch_name = #{map.secondDispatchName}
</if>
</select>
<delete id="deleteOtherInfo1">
DELETE
FROM rescue_info_detail
WHERE rescue_info_id = #{rescueId};
</delete>
<delete id="deleteOtherInfo2">
DELETE
FROM rescue_driver_info
WHERE rescue_id = #{rescueId};
</delete>
<select id="getDriverCarNum" resultType="com.alibaba.fastjson.JSONObject">
SELECT count(1) as allNum,
ifnull(sum(case
when start_scale is null then 0
when end_scale is null then 0
else end_scale - start_scale end), 0) as allDistance
FROM rescue_info
where driver_id = #{driverId}
and driver_car_num = #{carNum}
and rescue_time like concat(#{time}, '%')
</select>
<select id="getRescueInfoByDriver" resultType="cn.iocoder.yudao.module.rescue.domain.RescueInfo">
SELECT ri.*,
roi.order_status,
roi.set_money,
roi.id as rescueOrderId,
roi.pay_money,
roi.pay_time
FROM rescue_info ri
left join rescue_order_info roi on roi.rescue_info_id = ri.id
where driver_id is not null
<if test="map.rescueStart != null and map.rescueEnd != null">
and rescue_time between concat(#{map.rescueStart}, ' 00:00:00')
and concat(#{map.rescueEnd}, ' 23:59:59')
</if>
<if test="map.licenseNum != null">
and ri.license_num like concat('%', #{map.licenseNum}, '%')
</if>
<if test="map.feeType != null">
and ri.fee_type = #{map.feeType}
</if>
<if test="map.flag != null">
and ri.driver_id is not null
</if>
<if test="map.rescueStart != null and map.rescueEnd != null">
and rescue_time between concat(#{map.rescueStart}, ' 00:00:00')
and concat(#{map.rescueEnd}, ' 23:59:59')
</if>
<if test="map.driverName != null">
and ri.driver_name like concat('%', #{map.driverName}, '%')
</if>
<if test="map.driverCarNum != null">
and ri.driver_car_num like concat('%', #{map.driverCarNum}, '%')
</if>
<if test="map.rescueStartMonth != null">
and rescue_time like concat(#{map.rescueStartMonth}, '%')
</if>
order by ri.driver_name desc
</select>
<select id="statisticsInfo" resultType="com.alibaba.fastjson.JSONObject">
SELECT IFNULL(sum(roi.set_money), 0) / 100 as money,
count(ri.id) as rescueNum,
su.nickname as driverName
FROM driver_info di
LEFT JOIN rescue_info ri on ri.driver_id = di.id and ri.rescue_time <![CDATA[>=]]> #{startTime} and
ri.rescue_time <![CDATA[<=]]> #{endTime}
LEFT JOIN rescue_order_info roi on ri.id = roi.rescue_info_id
INNER JOIN system_users su on di.user_id = su.id
GROUP BY di.id
ORDER BY rescueNum desc
</select>
<select id="listBuckle" resultType="cn.iocoder.yudao.module.rescue.vo.BuckleVO">
SELECT sd.id,
sd.name AS buckle_name,
t1.buckle_count
FROM (SELECT dept_id,
count(*) AS buckle_count
FROM rescue_info
WHERE rescue_type = '5'
AND deleted = '0'
GROUP BY dept_id) t1
LEFT JOIN system_dept sd ON t1.dept_id = sd.id
ORDER BY sd.id desc
</select>
<select id="selectManageAnalyze" resultType="java.util.Map">
WITH rescue_types AS (SELECT '1' AS rescue_type, '拖车' AS rescue_type_desc
UNION ALL
SELECT '2', '送油'
UNION ALL
SELECT '3', '搭电'
UNION ALL
SELECT '4', '换台'
UNION ALL
SELECT '5', '扣车')
SELECT rt.rescue_type_desc AS rescueType,
COUNT(ri.rescue_type) AS typeCount,
ROUND((COUNT(ri.rescue_type) * 100.0 / NULLIF((SELECT COUNT(*)
FROM rescue_info
WHERE deleted = b'0'
AND rescue_time BETWEEN #{startTime} AND #{endTime}
AND tenant_id = #{tenantId}), 0)), 2) AS percentage
FROM rescue_types rt
LEFT JOIN
rescue_info ri ON rt.rescue_type = ri.rescue_type
AND ri.rescue_time BETWEEN #{startTime} AND #{endTime}
AND ri.tenant_id = #{tenantId}
GROUP BY rt.rescue_type_desc
ORDER BY rt.rescue_type;
</select>
<select id="selectDriverSort" resultType="java.util.Map">
SELECT ROW_NUMBER() OVER (ORDER BY COALESCE(SUM(roi.pay_money), 0) DESC) AS sort, su.nickname,
COALESCE(SUM(roi.set_money), 0) AS money,
COALESCE(COUNT(roi.id), 0) AS count
FROM
driver_info di
LEFT JOIN
system_users su
ON di.user_id = su.id
LEFT JOIN
rescue_info ri ON di.id = ri.driver_id
LEFT JOIN
rescue_order_info roi ON ri.id = roi.rescue_info_id
WHERE roi.pay_time BETWEEN #{startTime}
AND #{endTime}
GROUP BY
su.nickname,
di.id
ORDER BY
COALESCE (SUM (roi.set_money), 0) DESC;
</select>
<select id="selectRescueOrderByRoad" resultType="java.util.Map">
select COALESCE((select value from system_dict_data where dict_type = #{dictType} and id = ri.section_road),
'其他') name,
count(1) as count
from rescue_info ri
group by name;
</select>
<select id="getOnInternal" resultType="cn.iocoder.yudao.module.rescue.vo.DriverStaffSaveVO">
SELECT DISTINCT
su.id AS userId,
su.nickname,
su.username,
su.user_type,
su.remark,
su.dept_id,
su.mobile,
su.password,
su.avatar,
su.sex,
su.status,
di.id AS driverId,
di.age,
di.folder_id,
di.staff_type
FROM driver_info di
INNER JOIN system_users su ON di.user_id = su.id AND su.deleted = 0
LEFT JOIN system_user_role sur ON su.id = sur.user_id AND sur.deleted = 0
LEFT JOIN system_role sr ON sur.role_id = sr.id AND sr.service_package_id = 'jiuyuan' AND sr.deleted = 0
<where>
di.deleted = 0
and su.id = #{id}
</where>
</select>
<select id="getAll" resultType="cn.iocoder.yudao.module.rescue.vo.DriverInfoExportVO">
SELECT su.username,
su.nickname,
su.mobile,
su.sex,
GROUP_CONCAT(DISTINCT sr2.name SEPARATOR ',') AS roleNames
FROM driver_info di
INNER JOIN system_users su ON di.user_id = su.id AND su.deleted = 0
LEFT JOIN system_user_role sr ON su.id = sr.user_id AND sr.deleted = 0
INNER JOIN system_role role ON role.id = sr.role_id AND role.deleted = 0 AND role.code = 'jysj'
LEFT JOIN system_role sr2 ON sr.role_id = sr2.id AND sr2.service_package_id = 'jiuyuan'
<if test="entity.status != null">
AND su.status = #{entity.status}
</if>
<if test="entity.nickname != null">
AND (su.nickname like CONCAT('%',#{entity.nickname},'%') OR su.username like
CONCAT('%',#{entity.nickname},'%'))
</if>
GROUP BY su.username, su.nickname, su.mobile, su.sex
ORDER BY su.nickname
</select>
<update id="revokeRescueInfo">
update rescue_info set is_revoke = 1,revoke_user_id = #{userId},revoke_user_name = #{userName}, revoke_time = #{time} where id = #{id}
</update>
<update id="updateBilled">
update rescue_order_info
<if test="billed != null">
set billed_qrcode = #{billed_qrcode}
</if>
<if test="billed == null">
set billed_remark = #{billed_remark}
</if>
where rescue_info_id = #{id}
</update>
<select id="driverStatistics" parameterType="cn.iocoder.yudao.module.rescue.vo.StatisticsStaffVO"
resultType="cn.iocoder.yudao.module.rescue.vo.StatisticsStaffVO">
SELECT
su.id AS userId,
su.avatar,
ri.driver_name,
di.id AS driver_id,
COUNT(ri.id) AS rescueNum,
COALESCE(SUM(
CASE
WHEN ri.end_scale IS NOT NULL
AND ri.start_scale IS NOT NULL
AND ri.end_scale > ri.start_scale
THEN ri.end_scale - ri.start_scale
ELSE 0
END
), 0) AS mileage,
COALESCE(SUM(roi.set_money), 0) AS money
FROM driver_info di
INNER JOIN system_users su ON di.user_id = su.id AND su.deleted = 0
LEFT JOIN rescue_info ri ON di.id = ri.driver_id AND ri.deleted = 0 and ri.is_revoke = 0
LEFT JOIN rescue_order_info roi ON roi.rescue_info_id = ri.id AND roi.deleted = 0
WHERE di.deleted = 0
AND ri.driver_id IS NOT NULL
AND ri.driver_name IS NOT NULL
<if test="vo.startTimeStr!=null and vo.startTimeStr!='' ">
AND ri.rescue_time &gt;= #{vo.startTimeStr}
</if>
<if test="vo.endTimeStr!=null and vo.endTimeStr!='' ">
AND ri.rescue_time &lt;= #{vo.endTimeStr}
</if>
<if test="vo.driverType!=null and vo.driverType!='' ">
AND di.driver_type = #{vo.driverType}
</if>
GROUP BY
su.id,
su.avatar,
ri.driver_name,
di.id
ORDER BY rescueNum DESC
</select>
<select id="carStatistics" parameterType="cn.iocoder.yudao.module.rescue.vo.StatisticsStaffVO"
resultType="cn.iocoder.yudao.module.rescue.vo.StatisticsStaffVO">
SELECT
rci.rescue_car_num AS driver_car_num,
COUNT(ri.id) AS rescueNum,
COALESCE(SUM(
CASE
WHEN ri.end_scale IS NOT NULL
AND ri.start_scale IS NOT NULL
AND ri.end_scale > ri.start_scale
THEN ri.end_scale - ri.start_scale
ELSE 0
END
), 0) AS mileage,
COALESCE(SUM(roi.set_money), 0) AS money
FROM
rescue_car_info rci
LEFT JOIN rescue_info ri ON rci.rescue_car_num = ri.driver_car_num AND ri.deleted = 0
LEFT JOIN rescue_order_info roi ON roi.rescue_info_id = ri.id AND roi.deleted = 0
WHERE
rci.deleted = 0 and ri.is_revoke = 0
<if test="vo.startTimeStr!=null and vo.startTimeStr!='' ">
AND ri.rescue_time &gt;= #{vo.startTimeStr}
</if>
<if test="vo.endTimeStr!=null and vo.endTimeStr!='' ">
AND ri.rescue_time &lt;= #{vo.endTimeStr}
</if>
<if test="vo.rescueCarOwn!=null and vo.rescueCarOwn!='' ">
AND rci.rescue_car_own = #{vo.rescueCarOwn}
</if>
GROUP BY
rci.rescue_car_num
ORDER BY
rescueNum DESC
</select>
<!-- <select id="dispatchStatistics" parameterType="cn.iocoder.yudao.module.rescue.vo.StatisticsStaffVO"-->
<!-- resultType="cn.iocoder.yudao.module.rescue.vo.StatisticsStaffVO">-->
<!-- SELECT-->
<!-- u.id AS userId,-->
<!-- u.nickname AS driverName,-->
<!-- COUNT(r.id) AS createRescueNum,-->
<!-- SUM(CASE WHEN r.is_dispatched_to_scene = '1' THEN 1 ELSE 0 END) AS toSceneNum,-->
<!-- SUM(CASE WHEN r.is_wei_xiu = '1' THEN 1 ELSE 0 END) AS toRepairNum,-->
<!-- SUM(CASE WHEN r.rescue_status = '7' THEN 1 ELSE 0 END) AS confirmCompleteNum-->
<!-- FROM-->
<!-- rescue_info r-->
<!-- INNER JOIN system_users u ON u.id = r.creator AND u.deleted = 0-->
<!-- WHERE-->
<!-- r.deleted = 0-->
<!-- <if test="vo.startTimeStr!=null and vo.startTimeStr!='' ">-->
<!-- AND r.rescue_time &gt;= #{vo.startTimeStr}-->
<!-- </if>-->
<!-- <if test="vo.endTimeStr!=null and vo.endTimeStr!='' ">-->
<!-- AND r.rescue_time &lt;= #{vo.endTimeStr}-->
<!-- </if>-->
<!-- GROUP BY-->
<!-- u.id, u.nickname-->
<!-- HAVING-->
<!-- COUNT(r.id) > 0-->
<!-- ORDER BY-->
<!-- createRescueNum DESC;-->
<!-- </select>-->
<select id="dispatchStatistics" parameterType="cn.iocoder.yudao.module.rescue.vo.StatisticsStaffVO"
resultType="cn.iocoder.yudao.module.rescue.vo.StatisticsStaffVO">
SELECT
u.id AS userId,
u.nickname AS driverName,
COUNT(r.id) AS createRescueNum,
SUM(CASE WHEN r.is_dispatched_to_scene = '1' THEN 1 ELSE 0 END) AS toSceneNum,
SUM(CASE WHEN r.is_wei_xiu = '1' THEN 1 ELSE 0 END) AS toRepairNum,
SUM(CASE WHEN r.rescue_status = '5' THEN 1 ELSE 0 END) AS confirmCompleteNum
FROM
rescue_info r
INNER JOIN system_users u ON u.id = r.second_dispatch_id AND u.deleted = 0
WHERE
r.deleted = 0
AND r.is_revoke = 0
AND u.id IN (
SELECT user_id
FROM system_user_role sur
WHERE sur.tenant_id = #{vo.tenantId}
AND sur.deleted = 0
<if test="vo.roleCode != null and vo.roleCode != ''">
AND sur.role_id = (
SELECT id FROM system_role WHERE `code` = #{vo.roleCode} AND tenant_id = #{vo.tenantId} AND deleted = 0
)
</if>
<if test="vo.roleCode == null or vo.roleCode == ''">
-- 当没有传入roleCode时查询ddzx和second_dispatcher角色
AND sur.role_id IN (
SELECT id FROM system_role WHERE `code` IN ('ddzx', 'second_dispatcher')
AND tenant_id = #{vo.tenantId} AND deleted = 0
)
</if>
)
<if test="vo.startTimeStr!=null and vo.startTimeStr!='' ">
AND r.rescue_time &gt;= #{vo.startTimeStr}
</if>
<if test="vo.endTimeStr!=null and vo.endTimeStr!='' ">
AND r.rescue_time &lt;= #{vo.endTimeStr}
</if>
GROUP BY
u.id, u.nickname
HAVING
COUNT(r.id) > 0
ORDER BY
createRescueNum DESC;
</select>
<select id="getAllRescueOrder" resultType="cn.iocoder.yudao.module.rescue.domain.RescueInfo">
SELECT ri.*,
roi.order_status,
roi.set_money,
roi.id AS orderId,
roi.order_signing_person_id AS orderSigningPersonId,
roi.order_signing_person_name AS orderSigningPersonName,
roi.order_signing_charge_id AS orderSigningChargeId,
roi.order_signing_charge_name AS orderSigningChargeName,
roi.validation_real_name AS orderSigningRealName,
roi.payment_name AS paymentName,
roi.payment_time AS paymentTime,
roi.order_signing_remark AS orderSigningRemark
FROM rescue_info ri
left join rescue_order_info roi on roi.rescue_info_id = ri.id and roi.deleted = '0'
where ri.deleted = '0' AND ri.is_revoke = '0' and ri.rescue_status = 2
ORDER BY
rescue_time DESC;
</select>
<select id="selectRescueStatisticsInfoList" parameterType="cn.iocoder.yudao.module.rescue.domain.RescueInfo"
resultType="cn.iocoder.yudao.module.rescue.domain.RescueInfo">
SELECT ri.*,
roi.order_status,
roi.set_money,
roi.id AS orderId,
roi.order_signing_person_id AS orderSigningPersonId,
roi.order_signing_person_name AS orderSigningPersonName,
roi.order_signing_charge_id AS orderSigningChargeId,
roi.order_signing_charge_name AS orderSigningChargeName,
roi.validation_real_name AS orderSigningRealName,
roi.payment_name AS paymentName,
roi.payment_time AS paymentTime,
roi.order_signing_remark AS orderSigningRemark
FROM rescue_info ri
left join rescue_order_info roi on roi.rescue_info_id = ri.id and roi.deleted = '0'
<where>
1 = 1
and ri.deleted = '0' AND ri.is_revoke = '0'
<if test="map.connectionName!=null and map.connectionName!='' ">
and (ri.connection_name like concat('%', #{map.connectionName}, '%')
or ri.car_owner like concat('%', #{map.connectionName}, '%'))
</if>
<if test="map.connectionPhone!=null and map.connectionPhone!='' ">
and (ri.connection_phone like concat('%', #{map.connectionPhone}, '%')
or ri.car_owner_phone like concat('%', #{map.connectionPhone}, '%'))
</if>
<if test="map.driverCarNum != null and map.driverCarNum != '' ">
and ri.driver_car_num = #{map.driverCarNum}
</if>
<if test="map.faultType != null and map.faultType != '' ">
and ri.fault_type = #{map.faultType}
</if>
<if test="map.licenseNum != null and map.licenseNum != '' ">
and ri.license_num = #{map.licenseNum}
</if>
<if test="map.phenomenon != null and map.phenomenon != '' ">
and ri.phenomenon = #{map.phenomenon}
</if>
<if test="map.rescueStatus != null and map.rescueStatus != '' ">
and ri.rescue_status = #{map.rescueStatus}
</if>
<if test="map.rescueType != null and map.rescueType != '' ">
and ri.rescue_type = #{map.rescueType}
</if>
<if test="map.rescuePosition!=null and map.rescuePosition!='' ">
and ri.rescue_position like concat('%', #{map.rescuePosition}, '%')
</if>
<if test="map.driverId != null">
and ri.driver_id = #{map.driverId}
</if>
<if test="map.secondDispatchId != null">
and ri.second_dispatch_id = #{map.secondDispatchId}
</if>
<if test="map.startTimeStr!=null and map.startTimeStr!='' ">
AND ri.rescue_time &gt;= #{map.startTimeStr}
</if>
<if test="map.endTimeStr!=null and map.endTimeStr!='' ">
AND ri.rescue_time &lt;= #{map.endTimeStr}
</if>
<if test="map.channel!=null and map.channel!='' ">
AND ri.channel = #{map.channel}
</if>
<if test="map.source!=null and map.source!='' ">
AND ri.source = #{map.source}
</if>
</where>
order by ri.create_time desc
</select>
<select id="selectRescueStatisticsInfoListSecondDispatcher" parameterType="cn.iocoder.yudao.module.rescue.domain.RescueInfo"
resultType="cn.iocoder.yudao.module.rescue.domain.RescueInfo">
SELECT ri.*,
roi.order_status,
roi.set_money,
roi.id AS orderId,
roi.order_signing_person_id AS orderSigningPersonId,
roi.order_signing_person_name AS orderSigningPersonName,
roi.order_signing_charge_id AS orderSigningChargeId,
roi.order_signing_charge_name AS orderSigningChargeName,
roi.validation_real_name AS orderSigningRealName,
roi.payment_name AS paymentName,
roi.payment_time AS paymentTime,
roi.order_signing_remark AS orderSigningRemark
FROM rescue_info ri
left join rescue_order_info roi on roi.rescue_info_id = ri.id and roi.deleted = '0'
<where>
1 = 1
and ri.deleted = '0' AND ri.is_revoke = '0'
and ri.second_dispatch_id = #{map.userId}
<if test="map.connectionName!=null and map.connectionName!='' ">
and (ri.connection_name like concat('%', #{map.connectionName}, '%')
or ri.car_owner like concat('%', #{map.connectionName}, '%'))
</if>
<if test="map.connectionPhone!=null and map.connectionPhone!='' ">
and (ri.connection_phone like concat('%', #{map.connectionPhone}, '%')
or ri.car_owner_phone like concat('%', #{map.connectionPhone}, '%'))
</if>
<if test="map.driverCarNum != null and map.driverCarNum != '' ">
and ri.driver_car_num = #{map.driverCarNum}
</if>
<if test="map.faultType != null and map.faultType != '' ">
and ri.fault_type = #{map.faultType}
</if>
<if test="map.licenseNum != null and map.licenseNum != '' ">
and ri.license_num = #{map.licenseNum}
</if>
<if test="map.phenomenon != null and map.phenomenon != '' ">
and ri.phenomenon = #{map.phenomenon}
</if>
<if test="map.rescueStatus != null and map.rescueStatus != '' ">
and ri.rescue_status = #{map.rescueStatus}
</if>
<if test="map.rescueType != null and map.rescueType != '' ">
and ri.rescue_type = #{map.rescueType}
</if>
<if test="map.rescuePosition!=null and map.rescuePosition!='' ">
and ri.rescue_position like concat('%', #{map.rescuePosition}, '%')
</if>
<if test="map.driverId != null">
and ri.driver_id = #{map.driverId}
</if>
<if test="map.secondDispatchId != null">
and ri.second_dispatch_id = #{map.secondDispatchId}
</if>
<if test="map.startTimeStr!=null and map.startTimeStr!='' ">
AND ri.rescue_time &gt;= #{map.startTimeStr}
</if>
<if test="map.endTimeStr!=null and map.endTimeStr!='' ">
AND ri.rescue_time &lt;= #{map.endTimeStr}
</if>
<if test="map.channel!=null and map.channel!='' ">
AND ri.channel = #{map.channel}
</if>
<if test="map.source!=null and map.source!='' ">
AND ri.source = #{map.source}
</if>
</where>
order by ri.create_time desc
</select>
<select id="getRescueStatisticsInfoNum" resultType="java.util.Map" parameterType="cn.iocoder.yudao.module.rescue.domain.RescueInfo">
SELECT
IFNULL(sum(ri.rescue_status = '3' or ri.rescue_status = '4'), 0) as jyzNum,
IFNULL(sum(roi.order_status = '1'), 0) as dzfNum,
IFNULL(sum(ri.rescue_status = '6'), 0) as dqcNum,
IFNULL(sum(ri.rescue_status <![CDATA[>=]]> '5'), 0) as ywcNum,
IFNULL(sum(ri.is_wei_xiu = '1'), 0) as zwxNum,
IFNULL(count(ri.id), 0) as yjdNum,
sum(roi.if_confirm_pay = '1') as confirmPayNum,
IFNULL(sum(roi.set_money), 0) as yingskNum,
IFNULL(sum(CASE WHEN roi.if_confirm_pay = '1' THEN roi.pay_money ELSE 0 END), 0) as yiskNum,
IFNULL(sum(CASE WHEN roi.if_confirm_pay = '0' THEN roi.set_money ELSE 0 END), 0) as dskNum
FROM rescue_info ri
left join rescue_order_info roi on roi.rescue_info_id = ri.id and roi.deleted = '0'
<where>
1 = 1
and ri.deleted = '0' AND ri.is_revoke = '0'
<if test="map.connectionName!=null and map.connectionName!='' ">
and (ri.connection_name like concat('%', #{map.connectionName}, '%')
or ri.car_owner like concat('%', #{map.connectionName}, '%'))
</if>
<if test="map.connectionPhone!=null and map.connectionPhone!='' ">
and (ri.connection_phone like concat('%', #{map.connectionPhone}, '%')
or ri.car_owner_phone like concat('%', #{map.connectionPhone}, '%'))
</if>
<if test="map.driverCarNum != null and map.driverCarNum != '' ">
and ri.driver_car_num = #{map.driverCarNum}
</if>
<if test="map.driverName != null and map.driverName != '' ">
and ri.driver_name = #{map.driverName}
</if>
<if test="map.channel != null and map.channel != '' ">
and ri.channel = #{map.channel}
</if>
<if test="map.ifConfirmPay != null and map.ifConfirmPay != '' ">
and roi.if_confirm_pay = #{map.ifConfirmPay}
</if>
<if test="map.source != null and map.source != '' ">
and ri.source = #{map.source}
</if>
<if test="map.feeType != null and map.feeType != '' ">
and ri.fee_type = #{map.feeType}
</if>
<if test="map.orderStatus != null and map.orderStatus != '' ">
and roi.order_status = #{map.orderStatus}
</if>
<if test="map.faultType != null and map.faultType != '' ">
and ri.fault_type = #{map.faultType}
</if>
<if test="map.licenseNum != null and map.licenseNum != '' ">
and ri.license_num = #{map.licenseNum}
</if>
<if test="map.phenomenon != null and map.phenomenon != '' ">
and ri.phenomenon = #{map.phenomenon}
</if>
<if test="map.rescueStatus != null and map.rescueStatus != '' ">
and ri.rescue_status = #{map.rescueStatus}
</if>
<if test="map.rescueType != null and map.rescueType != '' ">
and ri.rescue_type = #{map.rescueType}
</if>
<if test="map.rescuePosition!=null and map.rescuePosition!='' ">
and ri.rescue_position like concat('%', #{map.rescuePosition}, '%')
</if>
<if test="map.driverId != null">
and ri.driver_id = #{map.driverId}
</if>
<if test="map.secondDispatchId != null">
and ri.second_dispatch_id = #{map.secondDispatchId}
</if>
<if test="map.secondDispatchName != null and map.secondDispatchName !='' ">
and ri.second_dispatch_name = #{map.secondDispatchName}
</if>
<if test="map.startTimeStr!=null and map.startTimeStr!='' ">
AND ri.rescue_time &gt;= #{map.startTimeStr}
</if>
<if test="map.endTimeStr!=null and map.endTimeStr!='' ">
AND ri.rescue_time &lt;= #{map.endTimeStr}
</if>
<if test="map.rescueStart!=null and map.rescueStart!='' ">
AND ri.rescue_time &gt;= #{map.rescueStart}
</if>
<if test="map.rescueEnd!=null and map.rescueEnd!='' ">
AND ri.rescue_time &lt;= #{map.rescueEnd}
</if>
</where>
</select>
<select id="getRescueStatisticsInfoNumSecondDispatcher" resultType="java.util.Map" parameterType="cn.iocoder.yudao.module.rescue.domain.RescueInfo">
SELECT
IFNULL(sum(ri.rescue_status = '3' or ri.rescue_status = '4'), 0) as jyzNum,
IFNULL(sum(roi.order_status = '1'), 0) as dzfNum,
IFNULL(sum(ri.rescue_status = '6'), 0) as dqcNum,
IFNULL(sum(ri.rescue_status <![CDATA[>=]]> '5'), 0) as ywcNum,
IFNULL(sum(ri.is_wei_xiu = '1'), 0) as zwxNum,
IFNULL(count(ri.id), 0) as yjdNum,
sum(roi.if_confirm_pay = '1') as confirmPayNum,
IFNULL(sum(roi.set_money), 0) as yingskNum,
IFNULL(sum(CASE WHEN roi.if_confirm_pay = '1' THEN roi.pay_money ELSE 0 END), 0) as yiskNum,
IFNULL(sum(CASE WHEN roi.if_confirm_pay = '0' THEN roi.set_money ELSE 0 END), 0) as dskNum
FROM rescue_info ri
left join rescue_order_info roi on roi.rescue_info_id = ri.id and roi.deleted = '0'
<where>
1 = 1
and ri.deleted = '0' AND ri.is_revoke = '0'
<if test="map.connectionName!=null and map.connectionName!='' ">
and (ri.connection_name like concat('%', #{map.connectionName}, '%')
or ri.car_owner like concat('%', #{map.connectionName}, '%'))
</if>
<if test="map.connectionPhone!=null and map.connectionPhone!='' ">
and (ri.connection_phone like concat('%', #{map.connectionPhone}, '%')
or ri.car_owner_phone like concat('%', #{map.connectionPhone}, '%'))
</if>
<if test="map.driverCarNum != null and map.driverCarNum != '' ">
and ri.driver_car_num = #{map.driverCarNum}
</if>
<if test="map.driverName != null and map.driverName != '' ">
and ri.driver_name = #{map.driverName}
</if>
<if test="map.channel != null and map.channel != '' ">
and ri.channel = #{map.channel}
</if>
<if test="map.source != null and map.source != '' ">
and ri.source = #{map.source}
</if>
<if test="map.ifConfirmPay != null and map.ifConfirmPay != '' ">
and roi.if_confirm_pay = #{map.ifConfirmPay}
</if>
<if test="map.feeType != null and map.feeType != '' ">
and ri.fee_type = #{map.feeType}
</if>
<if test="map.orderStatus != null and map.orderStatus != '' ">
and roi.order_status = #{map.orderStatus}
</if>
<if test="map.faultType != null and map.faultType != '' ">
and ri.fault_type = #{map.faultType}
</if>
<if test="map.licenseNum != null and map.licenseNum != '' ">
and ri.license_num = #{map.licenseNum}
</if>
<if test="map.phenomenon != null and map.phenomenon != '' ">
and ri.phenomenon = #{map.phenomenon}
</if>
<if test="map.rescueStatus != null and map.rescueStatus != '' ">
and ri.rescue_status = #{map.rescueStatus}
</if>
<if test="map.rescueType != null and map.rescueType != '' ">
and ri.rescue_type = #{map.rescueType}
</if>
<if test="map.rescuePosition!=null and map.rescuePosition!='' ">
and ri.rescue_position like concat('%', #{map.rescuePosition}, '%')
</if>
<if test="map.driverId != null">
and ri.driver_id = #{map.driverId}
</if>
<if test="map.secondDispatchId != null">
and ri.second_dispatch_id = #{map.secondDispatchId}
</if>
<if test="map.secondDispatchName != null and map.secondDispatchName !='' ">
and ri.second_dispatch_name = #{map.secondDispatchName}
</if>
<if test="map.startTimeStr!=null and map.startTimeStr!='' ">
AND ri.rescue_time &gt;= #{map.startTimeStr}
</if>
<if test="map.endTimeStr!=null and map.endTimeStr!='' ">
AND ri.rescue_time &lt;= #{map.endTimeStr}
</if>
<if test="map.rescueStart!=null and map.rescueStart!='' ">
AND ri.rescue_time &gt;= #{map.rescueStart}
</if>
<if test="map.rescueEnd!=null and map.rescueEnd!='' ">
AND ri.rescue_time &lt;= #{map.rescueEnd}
</if>
</where>
</select>
<select id="driverStatisticsSecond" parameterType="cn.iocoder.yudao.module.rescue.vo.StatisticsStaffVO"
resultType="cn.iocoder.yudao.module.rescue.vo.StatisticsStaffVO">
SELECT
su.id AS userId,
su.avatar,
di.id AS driver_id,
su.nickname AS driver_name,
COALESCE(COUNT(ri.id), 0) AS rescueNum,
COALESCE(SUM(
CASE
WHEN ri.end_scale IS NOT NULL
AND ri.start_scale IS NOT NULL
AND ri.end_scale > ri.start_scale
THEN ri.end_scale - ri.start_scale
ELSE 0
END
), 0) AS mileage,
COALESCE(SUM(roi.set_money), 0) AS money
FROM driver_info di
INNER JOIN system_users su ON di.user_id = su.id AND su.deleted = 0
LEFT JOIN rescue_info ri ON ri.driver_id = di.id
AND ri.deleted = 0 and ri.is_revoke = 0
AND ri.driver_name IS NOT NULL
AND ri.driver_id IS NOT NULL
AND ri.second_dispatch_id = #{vo.secondUserId}
LEFT JOIN rescue_order_info roi ON roi.rescue_info_id = ri.id AND roi.deleted = 0
WHERE di.deleted = 0
AND FIND_IN_SET(#{vo.secondUserId}, di.second_dispatcher_id) > 0
<if test="vo.startTimeStr!=null and vo.startTimeStr!='' ">
AND ri.rescue_time &gt;= #{vo.startTimeStr}
</if>
<if test="vo.endTimeStr!=null and vo.endTimeStr!='' ">
AND ri.rescue_time &lt;= #{vo.endTimeStr}
</if>
<if test="vo.driverType!=null and vo.driverType!='' ">
AND di.driver_type = #{vo.driverType}
</if>
GROUP BY
su.id,
su.avatar,
di.id,
su.nickname
ORDER BY rescueNum DESC
</select>
<select id="carStatisticsSecond" parameterType="cn.iocoder.yudao.module.rescue.vo.StatisticsStaffVO"
resultType="cn.iocoder.yudao.module.rescue.vo.StatisticsStaffVO">
SELECT
rci.rescue_car_num AS driverCarNum,
COALESCE(COUNT(ri.id), 0) AS rescueNum,
COALESCE(SUM(
CASE
WHEN ri.end_scale IS NOT NULL
AND ri.start_scale IS NOT NULL
AND ri.end_scale > ri.start_scale
THEN ri.end_scale - ri.start_scale
ELSE 0
END
), 0) AS mileage,
COALESCE(SUM(roi.set_money), 0) AS money
FROM rescue_car_info rci
INNER JOIN rescue_driver_car_relation rdcr ON rci.id = rdcr.car_id AND rdcr.deleted = 0
INNER JOIN driver_info di ON rdcr.driver_id = di.id AND di.deleted = 0
LEFT JOIN rescue_info ri ON ri.driver_car_num = rci.rescue_car_num
AND ri.deleted = 0 and ri.is_revoke = 0
AND ri.second_dispatch_id = #{vo.secondUserId}
LEFT JOIN rescue_order_info roi ON roi.rescue_info_id = ri.id AND roi.deleted = 0
WHERE rci.deleted = 0
AND FIND_IN_SET(#{vo.secondUserId}, di.second_dispatcher_id) > 0
<if test="vo.startTimeStr!=null and vo.startTimeStr!='' ">
AND ri.rescue_time &gt;= #{vo.startTimeStr}
</if>
<if test="vo.endTimeStr!=null and vo.endTimeStr!='' ">
AND ri.rescue_time &lt;= #{vo.endTimeStr}
</if>
<if test="vo.rescueCarOwn!=null and vo.rescueCarOwn!='' ">
AND rci.rescue_car_own = #{vo.rescueCarOwn}
</if>
GROUP BY
rci.rescue_car_num
ORDER BY rescueNum DESC
</select>
<select id="dispatchStatisticsSecond" parameterType="cn.iocoder.yudao.module.rescue.vo.StatisticsStaffVO"
resultType="cn.iocoder.yudao.module.rescue.vo.StatisticsStaffVO">
SELECT
u.id AS userId,
u.nickname AS driverName,
COUNT(r.id) AS createRescueNum,
SUM(CASE WHEN r.is_dispatched_to_scene = '1' THEN 1 ELSE 0 END) AS toSceneNum,
SUM(CASE WHEN r.is_wei_xiu = '1' THEN 1 ELSE 0 END) AS toRepairNum,
SUM(CASE WHEN r.rescue_status = '5' THEN 1 ELSE 0 END) AS confirmCompleteNum
FROM
rescue_info r
INNER JOIN system_users u ON u.id = r.second_dispatch_id AND u.deleted = 0
WHERE
r.deleted = 0
AND r.is_revoke = 0
AND u.id IN (
SELECT user_id
FROM system_user_role sur
WHERE sur.tenant_id = #{vo.tenantId}
AND sur.deleted = 0
AND sur.role_id = (
SELECT id FROM system_role WHERE `code` = 'second_dispatcher' AND tenant_id = #{vo.tenantId} AND deleted = 0
)
AND sur.role_id = (
SELECT id FROM system_role WHERE `code` = 'second_dispatcher'
AND tenant_id = #{vo.tenantId} AND deleted = 0
)
)
<if test="vo.startTimeStr!=null and vo.startTimeStr!='' ">
AND r.rescue_time &gt;= #{vo.startTimeStr}
</if>
<if test="vo.endTimeStr!=null and vo.endTimeStr!='' ">
AND r.rescue_time &lt;= #{vo.endTimeStr}
</if>
GROUP BY
u.id, u.nickname
HAVING
COUNT(r.id) > 0
ORDER BY
createRescueNum DESC;
</select>
<!-- <select id="rescueCarList" resultType="cn.iocoder.yudao.module.rescue.domain.RescueInfo">-->
<!-- SELECT-->
<!-- ri.*,-->
<!-- rci.rescue_car_own AS rescueCarOwn,-->
<!-- rci.rescue_car_brand AS rescueCarBrand,-->
<!-- roi.order_status,-->
<!-- roi.set_money,-->
<!-- roi.id AS orderId-->
<!--&#45;&#45; IFNULL(TIMESTAMPDIFF(YEAR, rci.car_buy_time, CURDATE()), 0) AS carAge,-->
<!--&#45;&#45; COALESCE(SUM(-->
<!--&#45;&#45; CASE-->
<!--&#45;&#45; WHEN ri.end_scale IS NOT NULL-->
<!--&#45;&#45; AND ri.start_scale IS NOT NULL-->
<!--&#45;&#45; AND ri.end_scale > ri.start_scale-->
<!--&#45;&#45; THEN ri.end_scale - ri.start_scale-->
<!--&#45;&#45; ELSE 0-->
<!--&#45;&#45; END-->
<!--&#45;&#45; ), 0) AS mileage-->
<!-- FROM rescue_car_info rci-->
<!-- LEFT JOIN rescue_info ri ON rci.rescue_car_num = ri.driver_car_num AND ri.deleted = 0-->
<!-- LEFT JOIN rescue_order_info roi ON roi.rescue_info_id = ri.id AND roi.deleted = 0-->
<!-- WHERE-->
<!-- rci.deleted = 0-->
<!-- <if test="map.rescueCarOwn != null and map.rescueCarOwn != ''">-->
<!-- and rci.rescue_car_own = #{map.rescueCarOwn}-->
<!-- </if>-->
<!-- <if test="map.orderStatus != null and map.orderStatus != ''">-->
<!-- and roi.order_status = #{map.orderStatus}-->
<!-- </if>-->
<!-- <if test="map.channel != null and map.channel != ''">-->
<!-- and ri.channel = #{map.channel}-->
<!-- </if>-->
<!-- <if test="map.secondDispatchName != null and map.secondDispatchName != ''">-->
<!-- and ri.second_dispatch_name = #{map.secondDispatchName}-->
<!-- </if>-->
<!-- <if test="map.rescueTime != null">-->
<!-- and ri.rescue_time between-->
<!-- concat(#{map.rescueTime}, ' 00:00:00') and concat(#{map.rescueTime}, ' 23:59:59')-->
<!-- </if>-->
<!-- <if test="map.licenseNum != null">-->
<!-- and ri.license_num like concat('%', #{map.licenseNum}, '%')-->
<!-- </if>-->
<!-- <if test="map.driverName != null">-->
<!-- and ri.driver_name like concat('%', #{map.driverName}, '%')-->
<!-- </if>-->
<!-- <if test="map.driverCarNum != null">-->
<!-- and ri.driver_car_num like concat('%', #{map.driverCarNum}, '%')-->
<!-- </if>-->
<!-- <if test="map.rescueStart != null and map.rescueEnd != null">-->
<!-- and rescue_time between-->
<!-- concat(#{map.rescueStart}, ' 00:00:00') and concat(#{map.rescueEnd}, ' 23:59:59')-->
<!-- </if>-->
<!-- GROUP BY-->
<!-- rci.rescue_car_num-->
<!-- ORDER BY-->
<!-- ri.create_time DESC-->
<!-- </select>-->
<select id="rescueCarList" resultType="cn.iocoder.yudao.module.rescue.domain.RescueInfo">
SELECT
rci.rescue_car_own AS rescueCarOwn, -- 车辆归属
rci.rescue_car_brand AS rescueCarBrand, -- 车辆品牌型号
rci.rescue_car_num AS driverCarNum, -- 车牌号
su.nickname AS driverName -- 司机姓名(从 system_users 表中获取)
FROM rescue_car_info rci
-- 通过司机与车辆的关联表连接救援车辆与司机信息
LEFT JOIN rescue_driver_car_relation rdcr ON rci.id = rdcr.car_id
-- 通过司机ID连接司机信息
LEFT JOIN driver_info di ON rdcr.driver_id = di.id
-- 通过用户ID连接系统用户表获取司机的用户昵称即司机的姓名
LEFT JOIN system_users su ON di.user_id = su.id
WHERE rci.deleted = 0 -- 车辆未删除
AND di.deleted = 0 -- 司机信息未删除
AND su.deleted = 0 -- 用户信息未删除
AND rci.tenant_id = 180 -- 根据租户ID进行筛选
<if test="map.rescueCarOwn != null and map.rescueCarOwn != ''">
AND rci.rescue_car_own = #{map.rescueCarOwn}
</if>
<if test="map.rescueCarBrand != null and map.rescueCarBrand != ''">
AND rci.rescue_car_brand LIKE CONCAT('%', #{map.rescueCarBrand}, '%')
</if>
<if test="map.driverCarNum != null and map.driverCarNum != '' ">
AND rci.rescue_car_num = #{map.driverCarNum}
</if>
<if test="map.driverName != null and map.driverName != '' ">
AND su.nickname = #{map.driverName}
</if>
ORDER BY rci.create_time DESC;
</select>
<select id="selectCarAgeAndMileage" resultType="cn.iocoder.yudao.module.rescue.vo.RescueCarStatRespVO">
SELECT
rci.rescue_car_num AS rescueCarNum,
IFNULL(TIMESTAMPDIFF(YEAR, rci.car_buy_time, CURDATE()), 0) AS carAge,
COALESCE(SUM(
CASE
WHEN ri.end_scale IS NOT NULL
AND ri.start_scale IS NOT NULL
AND ri.end_scale > ri.start_scale
THEN ri.end_scale - ri.start_scale
ELSE 0
END
), 0) AS mileage
FROM rescue_car_info rci
LEFT JOIN rescue_info ri
ON rci.rescue_car_num = ri.driver_car_num AND ri.deleted = 0
WHERE rci.deleted = 0
GROUP BY
rci.rescue_car_num,
rci.car_buy_time
ORDER BY rci.rescue_car_num
</select>
<select id="getRescueCarKPI" resultType="cn.iocoder.yudao.module.rescue.domain.RescueInfo">
SELECT
ri.driver_car_num AS driverCarNum,
ri.second_dispatch_name AS secondDispatchName,
DATE(ri.rescue_time) AS rescueTime,
ri.channel AS channel,
CASE
WHEN ri.end_scale IS NOT NULL
AND ri.start_scale IS NOT NULL
AND ri.end_scale > ri.start_scale
THEN (ri.end_scale - ri.start_scale)
ELSE 0
END AS mileage,
roi.order_status AS orderStatus,
roi.set_money AS setMoney
FROM rescue_info ri
LEFT JOIN rescue_order_info roi
ON roi.rescue_info_id = ri.id AND roi.deleted = '0'
<where>
ri.deleted = '0'
<!-- 按车牌过滤 -->
<if test="driverCarNum != null and driverCarNum != ''">
AND ri.driver_car_num = #{driverCarNum}
</if>
<if test="channel != null and channel != ''">
AND ri.channel = #{channel}
</if>
<if test="secondDispatchName != null and secondDispatchName != ''">
AND ri.second_dispatch_name = #{secondDispatchName}
</if>
<if test="startTime!=null and startTime!='' and endTime!=null and endTime!=''">
and rescue_time between
concat(#{startTime}, ' 00:00:00') and concat(#{endTime}, ' 23:59:59')
</if>
</where>
ORDER BY ri.rescue_time DESC
</select>
</mapper>