<?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 like concat(#{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 < #{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 < #{endTime}</if>
|
<if test="orgCode != null and orgCode != ''">and org_code like concat(#{orgCode}, '%')</if>
|
</where>
|
</sql>
|
<sql id="statBeforeOilFreqCondition">
|
<where>
|
and behavior = 1
|
<if test="beforeStartTime != null and beforeStartTime != ''">and start_time >= #{beforeStartTime}</if>
|
<if test="beforeEndTime != null and beforeEndTime != ''">and start_time < #{beforeEndTime}</if>
|
<if test="orgCode != null and orgCode != ''">and org_code like concat(#{orgCode}, '%')</if>
|
</where>
|
</sql>
|
<sql id="statAfterOilFreqCondition">
|
<where>
|
and behavior = 1
|
<if test="afterStartTime != null and afterStartTime != ''">and start_time >= #{afterStartTime}</if>
|
<if test="afterEndTime != null and afterEndTime != ''">and start_time < #{afterEndTime}</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 < #{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 < #{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 < #{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 < #{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 < #{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 < #{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="statisOilFreqCompare" resultType="java.util.Map" parameterType="com.tievd.jyz.entity.vo.DataStatisReqVo">
|
select
|
l.licenseNum licenseNum,
|
ifnull(b.beforeOilCount, 0) beforeOilCount,
|
ifnull(a.afterOilCount, 0) afterOilCount,
|
ifnull(a.afterOilCount, 0) - ifnull(b.beforeOilCount, 0) diffOilCount,
|
case
|
when ifnull(b.beforeOilCount, 0) = 0 then null
|
else round((ifnull(a.afterOilCount, 0) - ifnull(b.beforeOilCount, 0)) * 100 / ifnull(b.beforeOilCount, 0), 2)
|
end diffRate
|
from (
|
select license_num licenseNum from t_oil_record
|
<include refid="statBeforeOilFreqCondition"/>
|
union
|
select license_num licenseNum from t_oil_record
|
<include refid="statAfterOilFreqCondition"/>
|
) l
|
left join (
|
select license_num licenseNum, count(1) beforeOilCount
|
from t_oil_record
|
<include refid="statBeforeOilFreqCondition"/>
|
group by license_num
|
) b on l.licenseNum = b.licenseNum
|
left join (
|
select license_num licenseNum, count(1) afterOilCount
|
from t_oil_record
|
<include refid="statAfterOilFreqCondition"/>
|
group by license_num
|
) a on l.licenseNum = a.licenseNum
|
order by afterOilCount desc, beforeOilCount desc, licenseNum asc
|
limit 200
|
</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>
|
|
<select id="getVehicleFrequencyBeforeActivity" resultType="java.util.Map">
|
SELECT
|
COUNT(DISTINCT license_num) as totalVehicles,
|
COUNT(*) as totalOilRecords,
|
AVG(oil_volume) as avgOilVolume,
|
SUM(oil_volume) as totalOilVolume
|
FROM t_oil_record
|
WHERE start_time < #{startTime}
|
<foreach collection="orgCodes" item="orgCode" open="AND (" separator=" OR " close=")">
|
org_code LIKE concat(#{orgCode}, '%')
|
</foreach>
|
</select>
|
|
<select id="getVehicleFrequencyDuringActivity" resultType="java.util.Map">
|
SELECT
|
COUNT(DISTINCT license_num) as totalVehicles,
|
COUNT(*) as totalOilRecords,
|
AVG(oil_volume) as avgOilVolume,
|
SUM(oil_volume) as totalOilVolume
|
FROM t_oil_record
|
WHERE start_time >= #{startTime} AND start_time <= #{endTime}
|
<foreach collection="orgCodes" item="orgCode" open="AND (" separator=" OR " close=")">
|
org_code LIKE concat(#{orgCode}, '%')
|
</foreach>
|
</select>
|
|
<select id="getVehicleFrequencyAfterActivity" resultType="java.util.Map">
|
SELECT
|
COUNT(DISTINCT license_num) as totalVehicles,
|
COUNT(*) as totalOilRecords,
|
AVG(oil_volume) as avgOilVolume,
|
SUM(oil_volume) as totalOilVolume
|
FROM t_oil_record
|
WHERE start_time > #{endTime}
|
<foreach collection="orgCodes" item="orgCode" open="AND (" separator=" OR " close=")">
|
org_code LIKE concat(#{orgCode}, '%')
|
</foreach>
|
</select>
|
</mapper>
|