zxl
2026-03-20 ee8b4f41b25d510eda0b1c7ec553b73f6d7dd7e6
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
<?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.tievd.jyz.mapper.OilRecordMapper">
    <select
            id="statisOilPosition"
            resultType="java.util.Map">
        SELECT p.oil_position oilPosition, count(o.id) count
        FROM
        t_oil_position p
        left join t_oil_record o on p.oil_position=o.oil_position and o.license_num=#{licenseNum}
        where p.org_code like concat(#{orgCode}, '%')
        GROUP BY p.oil_position
    </select>
    <select
            id="statisByMonth"
            resultType="java.util.Map">
        SELECT CONCAT(MONTH(start_time), '月') months, count(id) count
        FROM  t_oil_record
        where org_code like concat(#{orgCode}, '%') and license_num=#{licenseNum}
        GROUP BY months;
    </select>
    <select
            id="statisByHour"
            resultType="java.util.Map">
        SELECT CONCAT(HOUR(start_time),':00') hours, count(id) count
        FROM  t_oil_record
        where org_code like concat(#{orgCode}, '%') and license_num=#{licenseNum}
        GROUP BY hours;
    </select>
 
    <select
            id="statisByStayTime"
            resultType="java.util.Map">
        SELECT
        CEIL(spand_time/5) phrase,
        case(CEIL(spand_time/5))
            when 1 then '5分钟内'
            when 2 then '10分钟内'
            when 3 then '15分钟内'
            when 4 then '20分钟内'
            when 5 then '25分钟内'
            else '25分钟以上'
        end    stayTime,
        count(id) count
        FROM  t_oil_record
        where org_code like concat(#{orgCode}, '%') and license_num=#{licenseNum}
        GROUP BY stayTime
        order by phrase
    </select>
 
    <select id="getStatisOilVolume" resultType="java.util.Map">
        select
        oil_position oilPosition, count(1) oilCount,  sum(oil_volume) OilVolume
        from t_oil_record
        where org_code =#{orgCode}
        <if test="dateMonth != null and dateMonth != ''">and DATE_FORMAT(start_time, '%Y-%m')=#{dateMonth}</if>
        GROUP BY oil_position
    </select>
 
    <select id="getOilVolumeTotal" resultType="java.util.Map">
        select
        count(1) oilCountTotal,  sum(oil_volume) OilVolumeTotal
        from t_oil_record
        where org_code like concat(#{orgCode}, '%')
        <if test="dateMonth != null and dateMonth != ''">and DATE_FORMAT(start_time, '%Y-%m')=#{dateMonth}</if>
    </select>
    <select id="descOilVolumeList" parameterType="java.util.Map" resultType="com.tievd.jyz.entity.vo.OilVolumeVo">
        select r.license_num, c.model_name, r.oil_volume, r.start_time, r.org_code from
        t_oil_record r
        LEFT JOIN t_car_info c on r.license_num = c.license_num
        where
        r.org_code=#{map.orgCode} and r.oil_position=#{map.oilPosition}
        <if test="map.dateMonth != null and map.dateMonth != ''">and DATE_FORMAT(r.start_time, '%Y-%m')=#{map.dateMonth}</if>
        <if test="map.dateDay != null and map.dateDay != ''">and DATE_FORMAT(r.start_time, '%Y-%m-%d')=#{map.dateDay}</if>
    </select>
 
    <!--|||||||||||||||||||||||||||||||||||||||||||||-->
 
    <sql id="statRecordCondition">
        <where>
            <if test="startTime != null and startTime != ''">and start_time >= #{startTime}</if>
            <if test="endTime != null and endTime != ''">and start_time &lt; #{endTime}</if>
            <if test="orgCode != null and orgCode != ''">and org_code like concat(#{orgCode}, '%')</if>
        </where>
    </sql>
    <sql id="statTrafficCondition">
        <where>
            <if test="startTime != null and startTime != ''">and capture_time >= #{startTime}</if>
            <if test="endTime != null and endTime != ''">and capture_time &lt; #{endTime}</if>
            <if test="orgCode != null and orgCode != ''">and org_code like concat(#{orgCode}, '%')</if>
        </where>
    </sql>
    <select id="statisTotal" parameterType="com.tievd.jyz.entity.vo.DataStatisReqVo" resultType="com.tievd.jyz.entity.vo.StatDataTableVo">
        select
        *,
        ROUND(sumSpand/appearCount) spandAvg,
        ROUND(appearCount*100/carCount, 2) entryRate,
        ROUND(oilCount*100/appearCount, 2) oilRate,
        ROUND((oilCount-onceOilCount)*100/oilCount, 2) rebackRate
        from (
            select
            carCount carCount,
            count(1) appearCount,
            count(if(behavior=1,1,null)) oilCount,
            sum(oil_volume) oilVolume,
            sum(spand_time) sumSpand,
            count(DISTINCT if(behavior=1, r.license_num, null)) onceOilCount
            from t_oil_record r
            join (
            select sum(car_count) carCount from t_traffic_flow
            <where>
                <if test="startTime != null and startTime != ''">and capture_time >= #{startTime}</if>
                <if test="endTime != null and endTime != ''">and capture_time &lt; #{endTime}</if>
                <if test="orgCode != null and orgCode != ''">and org_code like concat(#{orgCode}, '%')</if>
            </where>
            ) f
            <where>
                <if test="startTime != null and startTime != ''">and start_time >= #{startTime}</if>
                <if test="endTime != null and endTime != ''">and start_time &lt; #{endTime}</if>
                <if test="orgCode != null and orgCode != ''">and org_code like concat(#{orgCode}, '%')</if>
            </where>
        ) t
    </select>
    <select id="statisOrgTopTraffic" parameterType="com.tievd.jyz.entity.vo.DataStatisReqVo" resultType="java.util.Map">
        select
        d.depart_name orgName,
        d.org_code orgCode,
        IFNULL(carCount,0) carCount,
        IFNULL(apperaCount,0) apperaCount,
        if(carCount is null, 0, ROUND(apperaCount*100/carCount, 2)) entryRate
        from sys_depart d
        LEFT JOIN
        (
            select count(1) apperaCount,  org_code from t_oil_record
            <where>
                <if test="startTime != null and startTime != ''">and start_time >= #{startTime}</if>
                <if test="endTime != null and endTime != ''">and start_time &lt; #{endTime}</if>
            </where>
            GROUP BY org_code
        ) r on d.org_code = r.org_code
        left join
        (
            select sum(car_count) carCount,  org_code from t_traffic_flow
            <where>
                <if test="startTime != null and startTime != ''">and capture_time >= #{startTime}</if>
                <if test="endTime != null and endTime != ''">and capture_time &lt; #{endTime}</if>
            </where>
            GROUP BY org_code
        ) f  on d.org_code = f.org_code
        where d.org_category=3
        <if test="orgCode != null and orgCode != ''">and d.org_code like concat(#{orgCode}, '%')</if>
        order by carCount desc
        limit 10
    </select>
    <select id="statisOrgTopOil" resultType="java.util.Map" parameterType="com.tievd.jyz.entity.vo.DataStatisReqVo">
        select
        org_name orgName,
        org_code orgCode,
        count(if(behavior=1, 1, null)) oilCount,
        ROUND(count(if(behavior=1, 1, null))*100/count(1), 2) oilRate
        from t_oil_record
        <where>
            <if test="startTime != null and startTime != ''">and start_time >= #{startTime}</if>
            <if test="endTime != null and endTime != ''">and start_time &lt; #{endTime}</if>
            <if test="orgCode != null and orgCode != ''">and org_code like concat(#{orgCode}, '%')</if>
        </where>
        GROUP BY org_code
        limit 10
    </select>
 
    <select id="statisOrgTopVolume" resultType="java.util.Map" parameterType="com.tievd.jyz.entity.vo.DataStatisReqVo">
        select
        org_name orgName,
        org_code orgCode,
        count(if(behavior=1, 1, null)) oilCount,
        sum(oil_volume) oilVolume
        from t_oil_record
        <where>
            <if test="startTime != null and startTime != ''">and start_time >= #{startTime}</if>
            <if test="endTime != null and endTime != ''">and start_time &lt; #{endTime}</if>
            <if test="orgCode != null and orgCode != ''">and org_code like concat(#{orgCode}, '%')</if>
        </where>
        GROUP BY org_code
        limit 10
    </select>
    <select id="statFanByModel" resultType="com.tievd.jyz.entity.vo.StatDataTableVo" parameterType="com.tievd.jyz.entity.vo.DataStatisReqVo">
        select
        count(if(behavior=1,1,null)) oilCount,
        sum(oil_volume) oilVolume,
        m.model_Name modelName
        from t_sys_car_model m
        left join t_oil_record r on m.model_code = r.model_code
        <include refid="statRecordCondition" />
        GROUP BY m.model_code
    </select>
 
    <select id="statFanByPosition" resultType="com.tievd.jyz.entity.vo.StatDataTableVo" parameterType="com.tievd.jyz.entity.vo.DataStatisReqVo">
        select
        count(if(behavior=1,1,null)) oilCount,
        sum(oil_volume) oilVolume,
        oil_position oilPosition
        from t_oil_record
        <include refid="statRecordCondition" />
        and oil_position != ''
        GROUP BY oil_position
    </select>
    <select id="statBarByModel" resultType="com.tievd.jyz.entity.vo.StatDataTableVo" parameterType="com.tievd.jyz.entity.vo.DataStatisReqVo">
        select m.model_name modelName, oilCount, carCount
        from t_sys_car_model m
        LEFT JOIN (
          select model_code, count(if(behavior=1,1,null)) oilCount
          from t_oil_record
          <include refid="statRecordCondition" />
          GROUP BY model_code
        ) r on m.model_code = r.model_code
        LEFT JOIN (
          select model_code, sum(car_count) carCount
          from t_traffic_flow
          <include refid="statTrafficCondition" />
          GROUP BY model_code
        ) f on m.model_code = f.model_code
    </select>
</mapper>