Pu Zhibing
2025-05-16 4c99ee7028c3fe58a2cd4b8273b22c75c45574fc
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
<?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.IncomeMapper">
 
    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.stylefeng.guns.modular.system.model.Income">
        <id column="id" property="id"/>
        <result column="userType" property="userType"/>
        <result column="objectId" property="objectId"/>
        <result column="type" property="type"/>
        <result column="incomeId" property="incomeId"/>
        <result column="orderType" property="orderType"/>
        <result column="money" property="money"/>
        <result column="insertTime" property="insertTime"/>
    </resultMap>
    <select  id="getList" resultType="map" parameterType="com.baomidou.mybatisplus.plugins.Page">
        SELECT
            aa.times,
            ROUND(sum(aa.activityMoney), 2) as activityMoney,
            ROUND(sum(aa.onlineMoney), 2) as onlineMoney,
            ROUND(sum(aa.cashMoney), 2) as cashMoney
        FROM (
            SELECT
                date_format(insertTime, '%Y-%m-%d') times,
                SUM(CASE WHEN type = 1 THEN money ELSE 0 END) activityMoney,
                SUM(CASE WHEN type = 1 THEN 0 ELSE money END) onlineMoney,
                0 cashMoney
            FROM
                t_income
            WHERE userType=2 AND objectId=#{id} GROUP BY date_format(insertTime, '%Y-%m-%d')
            union all
            select date_format(travelTime, '%Y-%m-%d') times, 0, 0, ROUND(sum(payMoney), 2) from t_order_private_car where driverId = #{id} and payType = 4 and state in (8, 9) and isDelete = 1 GROUP BY date_format(travelTime, '%Y-%m-%d')
            union all
            select date_format(travelTime, '%Y-%m-%d') times, 0, 0, ROUND(sum(payMoney), 2) from t_order_logistics where driverId = #{id} and payType = 4 and state in (8, 9) and isDelete = 1 GROUP BY date_format(travelTime, '%Y-%m-%d')
        ) AS aa GROUP BY aa.times ORDER BY aa.times DESC
    </select>
    <select  id="getExcelList" resultType="map">
        SELECT
            aa.times,
            ROUND(sum(aa.activityMoney), 2) as activityMoney,
            ROUND(sum(aa.onlineMoney), 2) as onlineMoney,
            ROUND(sum(aa.cashMoney), 2) as cashMoney
        FROM (
             SELECT
                 date_format(insertTime, '%Y-%m-%d') times,
                 SUM(CASE WHEN type = 1 THEN money ELSE 0 END) activityMoney,
                 SUM(CASE WHEN type = 1 THEN 0 ELSE money END) onlineMoney,
                 0 cashMoney
             FROM
                 t_income
             WHERE userType=2 AND objectId=#{id} GROUP BY date_format(insertTime, '%Y-%m-%d')
             union all
             select date_format(travelTime, '%Y-%m-%d') times, 0, 0, ROUND(sum(payMoney), 2) from t_order_private_car where driverId = #{id} and payType = 4 and state in (8, 9) and isDelete = 1 GROUP BY date_format(travelTime, '%Y-%m-%d')
             union all
             select date_format(travelTime, '%Y-%m-%d') times, 0, 0, ROUND(sum(payMoney), 2) from t_order_logistics where driverId = #{id} and payType = 4 and state in (8, 9) and isDelete = 1 GROUP BY date_format(travelTime, '%Y-%m-%d')
        ) AS aa GROUP BY aa.times ORDER BY aa.times DESC
    </select>
    <select  id="getList1" resultType="map" parameterType="com.baomidou.mybatisplus.plugins.Page">
            select aa.startTime as times, aa.driverNum, bb.duration as timeNumber from (
                select a.startTime, count(a.driverId) as driverNum from (
                    select DATE_FORMAT(startTime, '%Y-%m-%d') as startTime, driverId from t_driver_work group by DATE_FORMAT(startTime, '%Y-%m-%d'), driverId
                ) as a group by a.startTime
            ) as aa
            left join (
                select DATE_FORMAT(startTime, '%Y-%m-%d') as startTime, sum(if(endTime is null, UNIX_TIMESTAMP(), UNIX_TIMESTAMP(endTime)) - UNIX_TIMESTAMP(startTime)) as duration from t_driver_work group by DATE_FORMAT(startTime, '%Y-%m-%d')
            ) as bb on (aa.startTime = bb.startTime)
            ORDER BY aa.startTime DESC
    </select>
    <select  id="getList2" resultType="map" parameterType="com.baomidou.mybatisplus.plugins.Page">
        select
        CONCAT(b.firstName, ' ', b.lastName) as `name`,
        a.duration as timeNumber
        from (select DATE_FORMAT(startTime, '%Y-%m-%d') as startTime, driverId, sum(if(endTime is null, UNIX_TIMESTAMP(), UNIX_TIMESTAMP(endTime)) - UNIX_TIMESTAMP(startTime)) as duration from t_driver_work group by DATE_FORMAT(startTime, '%Y-%m-%d'), driverId) as a
        left join t_driver b on (a.driverId = b.id)
        where a.startTime = #{times}
    </select>
    <select  id="getTotal" resultType="map">
      SELECT COUNT(o.driverId) driverNum,SUM(o.timeNumber) timeNumber from (SELECT
    w.driverId,
    CONCAT(d.firstName, ' ', d.lastName) as NAME,
    o.timeNumber
FROM
    t_driver_work w
LEFT JOIN t_driver d ON d.id = w.driverId
LEFT JOIN (
    SELECT
        IFNULL(SUM(o.timeNumber), 0) timeNumber,
        driverId
    FROM
        (
            SELECT
                TIMESTAMPDIFF(
                    MINUTE,
                    startTime,
                    CASE
                WHEN endTime IS NULL THEN
                    NOW()
                ELSE
                    endTime
                END
                ) timeNumber,
                driverId
            FROM
                t_driver_work
            WHERE
                date_format(startTime, '%Y-%m-%d') = #{times}
 
        ) o GROUP BY
                driverId
) o ON o.driverId = d.id
WHERE
    date_format(startTime, '%Y-%m-%d') = #{times}
GROUP BY
    w.driverId) o
    </select>
 
</mapper>