yanghb
2023-04-21 0481353111afb43a2322e18530dde26f1d841ead
ManagementTravel/guns-admin/src/main/java/com/stylefeng/guns/modular/system/dao/mapping/TDriverMapper.xml
@@ -66,6 +66,7 @@
        <result column="addType" property="addType" />
        <result column="laveBusinessMoney" property="laveBusinessMoney"/>
        <result column="businessMoney" property="businessMoney"/>
        <result column="mchtNo" property="mchtNo"/>
    </resultMap>
    <!-- 通用查询结果列 -->
@@ -80,7 +81,7 @@
        LEFT JOIN (select * from t_company where type = 3 and flag != 3) as cc2 on cc2.id = dd.franchiseeId
        LEFT JOIN (
        SELECT
        GROUP_CONCAT(case when type = 1 then '快车'
        GROUP_CONCAT(case when type = 1 then '专车'
        when type = 2 then '出租车'
        when type = 3 then '跨城出行'
        when type = 4 then '小件物流-同城'
@@ -122,7 +123,7 @@
        LEFT JOIN (select * from t_company where flag != 3) as cc on cc.id = dd.companyId
        LEFT JOIN (
        SELECT
        GROUP_CONCAT(case when type = 1 then '快车'
        GROUP_CONCAT(case when type = 1 then '专车'
        when type = 2 then '出租车'
        when type = 3 then '跨城出行'
        when type = 4 then '小件物流-同城'
@@ -141,7 +142,7 @@
        LEFT JOIN (select * from t_car where state = 1) as ci on ci.id = dd.carId
        LEFT JOIN (
        SELECT
        GROUP_CONCAT(case when type = 1 then '快车'
        GROUP_CONCAT(case when type = 1 then '专车'
        when type = 2 then '出租车'
        when type = 3 then '跨城出行'
        when type = 4 then '小件物流-同城'
@@ -205,7 +206,7 @@
        LEFT JOIN (select * from t_car_brand where state = 1) as cb on cb.id = ci.carBrandId
        LEFT JOIN (
        SELECT
        GROUP_CONCAT(case when type = 1 then '快车'
        GROUP_CONCAT(case when type = 1 then '专车'
        when type = 2 then '出租车'
        when type = 3 then '跨城出行'
        when type = 4 then '小件物流-同城'
@@ -269,7 +270,7 @@
        LEFT JOIN (select * from t_car where state = 1) as ci on ci.id = dd.carId
        LEFT JOIN (
        SELECT
        GROUP_CONCAT(case when type = 1 then '快车'
        GROUP_CONCAT(case when type = 1 then '专车'
        when type = 2 then '出租车'
        when type = 3 then '跨城出行'
        when type = 4 then '小件物流-同城'
@@ -299,246 +300,4 @@
        order by o.id desc
    </select>
    <select id="orderRevenueDetailsList" resultType="map">
        select
        a.id,
        b.insertTime,
        a.`name`,
        b.orderNum,
        b.orderType,
        c.money
        from t_driver a
        left join (
        select id, orderNum, driverId, 1 as orderType, DATE_FORMAT(insertTime, '%Y-%m-%d %H:%i:%s') as insertTime from t_order_private_car where state in (8, 9) and isDelete = 1 and pid is not null
        union all
        select id, orderNum, driverId, 2 as orderType, DATE_FORMAT(insertTime, '%Y-%m-%d %H:%i:%s') as insertTime from t_order_taxi where state in (8, 9) and isDelete = 1
        union all
        select id, orderNum, driverId, 3 as orderType, DATE_FORMAT(insertTime, '%Y-%m-%d %H:%i:%s') as insertTime from t_order_cross_city where state in (8, 9) and isDelete = 1
        union all
        select id, orderNum, driverId, type as orderType, DATE_FORMAT(insertTime, '%Y-%m-%d %H:%i:%s') as insertTime from t_order_logistics where state in (6, 9) and isDelete = 1
        union all
        select id, orderNum, driverId, 7 as orderType, DATE_FORMAT(insertTime, '%Y-%m-%d %H:%i:%s') as insertTime from t_order_call where state in (8, 9) and isDelete = 1
        ) b on (a.id = b.driverId)
        left join (select * from t_income where userType = 2 and type = 2) c on (b.id = c.incomeId and b.orderType = c.orderType)
        where a.flag != 3 and a.authState = 2 and c.money > 0
        <if test="null != companyId">
            and a.companyId = #{companyId}
        </if>
        <if test="null != driverName and '' != driverName">
            and a.`name` like CONCAT('%', #{driverName}, '%')
        </if>
        <if test="null != driverPhone and '' != driverPhone">
            and a.phone like CONCAT('%', #{driverPhone}, '%')
        </if>
        <if test="null != startTime and '' != startTime and null != endTime and '' != endTime">
            and b.insertTime between #{startTime} and #{endTime}
        </if>
        order by b.insertTime desc
    </select>
    <select id="orderRevenueDetailsListSum" resultType="double">
        select
        sum(c.money) as money
        from t_driver a
        left join (
        select id, orderNum, driverId, 1 as orderType, DATE_FORMAT(insertTime, '%Y-%m-%d %H:%i:%s') as insertTime from t_order_private_car where state in (8, 9) and isDelete = 1 and pid is not null
        union all
        select id, orderNum, driverId, 2 as orderType, DATE_FORMAT(insertTime, '%Y-%m-%d %H:%i:%s') as insertTime from t_order_taxi where state in (8, 9) and isDelete = 1
        union all
        select id, orderNum, driverId, 3 as orderType, DATE_FORMAT(insertTime, '%Y-%m-%d %H:%i:%s') as insertTime from t_order_cross_city where state in (8, 9) and isDelete = 1
        union all
        select id, orderNum, driverId, type as orderType, DATE_FORMAT(insertTime, '%Y-%m-%d %H:%i:%s') as insertTime from t_order_logistics where state in (6, 9) and isDelete = 1
        union all
        select id, orderNum, driverId, 7 as orderType, DATE_FORMAT(insertTime, '%Y-%m-%d %H:%i:%s') as insertTime from t_order_call where state in (8, 9) and isDelete = 1
        ) b on (a.id = b.driverId)
        left join (select * from t_income where userType = 2 and type = 2) c on (b.id = c.incomeId and b.orderType = c.orderType)
        where a.flag != 3 and a.authState = 2 and c.money > 0
        <if test="null != companyId">
            and a.companyId = #{companyId}
        </if>
        <if test="null != driverName and '' != driverName">
            and a.`name` like CONCAT('%', #{driverName}, '%')
        </if>
        <if test="null != driverPhone and '' != driverPhone">
            and a.phone like CONCAT('%', #{driverPhone}, '%')
        </if>
        <if test="null != startTime and '' != startTime and null != endTime and '' != endTime">
            and b.insertTime between #{startTime} and #{endTime}
        </if>
        order by b.insertTime desc
    </select>
    <select id="exportOrderRevenueDetails" resultType="map">
        select
        a.id,
        b.insertTime,
        a.`name`,
        b.orderNum,
        b.orderType,
        c.money
        from t_driver a
        left join (
        select id, orderNum, driverId, 1 as orderType, DATE_FORMAT(insertTime, '%Y-%m-%d %H:%i:%s') as insertTime from t_order_private_car where state in (8, 9) and isDelete = 1 and pid is not null
        union all
        select id, orderNum, driverId, 2 as orderType, DATE_FORMAT(insertTime, '%Y-%m-%d %H:%i:%s') as insertTime from t_order_taxi where state in (8, 9) and isDelete = 1
        union all
        select id, orderNum, driverId, 3 as orderType, DATE_FORMAT(insertTime, '%Y-%m-%d %H:%i:%s') as insertTime from t_order_cross_city where state in (8, 9) and isDelete = 1
        union all
        select id, orderNum, driverId, type as orderType, DATE_FORMAT(insertTime, '%Y-%m-%d %H:%i:%s') as insertTime from t_order_logistics where state in (6, 9) and isDelete = 1
        union all
        select id, orderNum, driverId, 7 as orderType, DATE_FORMAT(insertTime, '%Y-%m-%d %H:%i:%s') as insertTime from t_order_call where state in (8, 9) and isDelete = 1
        ) b on (a.id = b.driverId)
        left join (select * from t_income where userType = 2 and type = 2) c on (b.id = c.incomeId and b.orderType = c.orderType)
        where a.flag != 3 and a.authState = 2 and c.money > 0
        <if test="null != companyId">
            and a.companyId = #{companyId}
        </if>
        <if test="null != driverName and '' != driverName">
            and a.`name` like CONCAT('%', #{driverName}, '%')
        </if>
        <if test="null != driverPhone and '' != driverPhone">
            and a.phone like CONCAT('%', #{driverPhone}, '%')
        </if>
        <if test="null != startTime and '' != startTime and null != endTime and '' != endTime">
            and b.insertTime between #{startTime} and #{endTime}
        </if>
        order by b.insertTime desc
    </select>
    <select id="otherSpendingDetailList" resultType="map">
        select
        da.travelTime,
        b.name,
        b.phone,
        da.type,
        da.thankYouFee,
        (da.holidayFee + da.amount) as amount
        from (
            select travelTime, type, driverId, sum(thankYouFee) as thankYouFee, sum(holidayFee) as holidayFee, sum(amount) as amount from (
            select DATE_FORMAT(a.travelTime, '%Y-%m-%d') as travelTime, 1 as type, driverId, ifnull(thankYouFee, 0) as thankYouFee, ifnull(holidayFee, 0) as holidayFee, (select ifnull(sum(amount), 0) from t_order_additional_fee where orderType = 1 and orderId = a.id) as amount
            from t_order_private_car a
            union all
            select DATE_FORMAT(a.travelTime, '%Y-%m-%d') as travelTime, 2 as type, driverId, ifnull(thankYouFee, 0) as thankYouFee, ifnull(holidayFee, 0) as holidayFee, (select ifnull(sum(amount), 0) from t_order_additional_fee where orderType = 2 and orderId = a.id) as amount
            from t_order_taxi a
            union all
            select DATE_FORMAT(a.travelTime, '%Y-%m-%d') as travelTime, 3 as type, driverId, ifnull(thankYouFee, 0) as thankYouFee, ifnull(holidayFee, 0) as holidayFee, (select ifnull(sum(amount), 0) from t_order_additional_fee where orderType = 3 and orderId = a.id) as amount
            from t_order_cross_city a
            union all
            select DATE_FORMAT(a.travelTime, '%Y-%m-%d') as travelTime, type as type, driverId, ifnull(thankYouFee, 0) as thankYouFee, ifnull(holidayFee, 0) as holidayFee, (select ifnull(sum(amount), 0) from t_order_additional_fee where orderType = type and orderId = a.id) as amount
            from t_order_logistics a
            union all
            select DATE_FORMAT(a.travelTime, '%Y-%m-%d') as travelTime, 7 as type, driverId, ifnull(thankYouFee, 0) as thankYouFee, ifnull(holidayFee, 0) as holidayFee, (select ifnull(sum(amount), 0) from t_order_additional_fee where orderType = 7 and orderId = a.id) as amount
            from t_order_call a
            ) as aa group by aa.travelTime, aa.type, aa.driverId
        ) as da
        left join t_driver b on (da.driverId = b.id)
        where (da.thankYouFee > 0 or da.amount > 0)
        <if test="null != driverName and '' != driverName">
            and b.name like CONCAT('%', #{driverName}, '%')
        </if>
        <if test="null != driverPhone and '' != driverPhone">
            and b.phone like CONCAT('%', #{driverPhone}, '%')
        </if>
        <if test="null != startTime and '' != startTime and null != endTime and '' != endTime">
            and da.travelTime between #{startTime} and #{endTime}
        </if>
        order by da.travelTime desc
        <if test="null != offset and null != limit">
            limit #{offset}, #{limit}
        </if>
    </select>
    <select id="otherSpendingDetailListCount" resultType="int">
        select count(1) from (
        select travelTime, type, driverId, sum(thankYouFee) as thankYouFee, sum(amount) as amount from (
        select DATE_FORMAT(a.travelTime, '%Y-%m-%d') as travelTime, 1 as type, driverId, ifnull(thankYouFee, 0) as thankYouFee, (select ifnull(sum(amount), 0) from t_order_additional_fee where orderType = 1 and orderId = a.id) as amount
        from t_order_private_car a
        union all
        select DATE_FORMAT(a.travelTime, '%Y-%m-%d') as travelTime, 2 as type, driverId, ifnull(thankYouFee, 0) as thankYouFee, (select ifnull(sum(amount), 0) from t_order_additional_fee where orderType = 2 and orderId = a.id) as amount
        from t_order_taxi a
        union all
        select DATE_FORMAT(a.travelTime, '%Y-%m-%d') as travelTime, 3 as type, driverId, ifnull(thankYouFee, 0) as thankYouFee, (select ifnull(sum(amount), 0) from t_order_additional_fee where orderType = 3 and orderId = a.id) as amount
        from t_order_cross_city a
        union all
        select DATE_FORMAT(a.travelTime, '%Y-%m-%d') as travelTime, type as type, driverId, ifnull(thankYouFee, 0) as thankYouFee, (select ifnull(sum(amount), 0) from t_order_additional_fee where orderType = type and orderId = a.id) as amount
        from t_order_logistics a
        union all
        select DATE_FORMAT(a.travelTime, '%Y-%m-%d') as travelTime, 7 as type, driverId, ifnull(thankYouFee, 0) as thankYouFee, (select ifnull(sum(amount), 0) from t_order_additional_fee where orderType = 7 and orderId = a.id) as amount
        from t_order_call a
        ) as aa group by aa.travelTime, aa.type, aa.driverId
        ) as da
        left join t_driver b on (da.driverId = b.id)
        where (da.thankYouFee > 0 or da.amount > 0)
        <if test="null != driverName and '' != driverName">
            and b.name like CONCAT('%', #{driverName}, '%')
        </if>
        <if test="null != driverPhone and '' != driverPhone">
            and b.phone like CONCAT('%', #{driverPhone}, '%')
        </if>
        <if test="null != startTime and '' != startTime and null != endTime and '' != endTime">
            and da.travelTime between #{startTime} and #{endTime}
        </if>
    </select>
    <select id="otherSpendingDetailListSum" resultType="map">
        select ifnull(sum(thankYouFee), 0) as thankYouFee, (ifnull(sum(holidayFee), 0) + ifnull(sum(amount), 0)) as amount from (
        select travelTime, type, driverId, sum(thankYouFee) as thankYouFee, sum(holidayFee) as holidayFee, sum(amount) as amount from (
        select DATE_FORMAT(a.travelTime, '%Y-%m-%d') as travelTime, 1 as type, driverId, ifnull(thankYouFee, 0) as thankYouFee, ifnull(holidayFee, 0) as holidayFee, (select ifnull(sum(amount), 0) from t_order_additional_fee where orderType = 1 and orderId = a.id) as amount
        from t_order_private_car a
        union all
        select DATE_FORMAT(a.travelTime, '%Y-%m-%d') as travelTime, 2 as type, driverId, ifnull(thankYouFee, 0) as thankYouFee, ifnull(holidayFee, 0) as holidayFee, (select ifnull(sum(amount), 0) from t_order_additional_fee where orderType = 2 and orderId = a.id) as amount
        from t_order_taxi a
        union all
        select DATE_FORMAT(a.travelTime, '%Y-%m-%d') as travelTime, 3 as type, driverId, ifnull(thankYouFee, 0) as thankYouFee, ifnull(holidayFee, 0) as holidayFee, (select ifnull(sum(amount), 0) from t_order_additional_fee where orderType = 3 and orderId = a.id) as amount
        from t_order_cross_city a
        union all
        select DATE_FORMAT(a.travelTime, '%Y-%m-%d') as travelTime, type as type, driverId, ifnull(thankYouFee, 0) as thankYouFee, ifnull(holidayFee, 0) as holidayFee, (select ifnull(sum(amount), 0) from t_order_additional_fee where orderType = type and orderId = a.id) as amount
        from t_order_logistics a
        union all
        select DATE_FORMAT(a.travelTime, '%Y-%m-%d') as travelTime, 7 as type, driverId, ifnull(thankYouFee, 0) as thankYouFee, ifnull(holidayFee, 0) as holidayFee, (select ifnull(sum(amount), 0) from t_order_additional_fee where orderType = 7 and orderId = a.id) as amount
        from t_order_call a
        ) as aa group by aa.travelTime, aa.type, aa.driverId
        ) as da
        left join t_driver b on (da.driverId = b.id)
        where (da.thankYouFee > 0 or da.amount > 0)
        <if test="null != driverName and '' != driverName">
            and b.name like CONCAT('%', #{driverName}, '%')
        </if>
        <if test="null != driverPhone and '' != driverPhone">
            and b.phone like CONCAT('%', #{driverPhone}, '%')
        </if>
        <if test="null != startTime and '' != startTime and null != endTime and '' != endTime">
            and da.travelTime between #{startTime} and #{endTime}
        </if>
    </select>
</mapper>