<?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.DepartLabelMapper">
|
|
<select id="queryDepartLabelList" resultType="java.util.Map">
|
SELECT
|
s.id,
|
s.id as depart_id,
|
s.parent_id,
|
COALESCE(GROUP_CONCAT(DISTINCT d.label_name SEPARATOR ','), '') as label_name,
|
s.depart_name,
|
s.org_code,
|
s.create_time
|
FROM sys_depart s
|
LEFT JOIN t_depart_label d ON s.id = d.depart_id
|
WHERE s.del_flag = 0
|
<if test="parentCode != null and parentCode != ''">
|
AND s.org_code LIKE CONCAT(#{parentCode}, '%')
|
</if>
|
<if test="parentId != null and parentId != ''">
|
AND (s.id = #{parentId} OR FIND_IN_SET(#{parentId}, s.parent_id))
|
</if>
|
GROUP BY s.id, s.depart_name, s.org_code, s.create_time
|
<if test="labelName != null and labelName != ''">
|
HAVING FIND_IN_SET(#{labelName}, GROUP_CONCAT(DISTINCT d.label_name SEPARATOR ','))
|
</if>
|
ORDER BY s.id
|
</select>
|
|
<select id="queryAllLabelNames" resultType="java.lang.String">
|
SELECT DISTINCT SUBSTRING_INDEX(SUBSTRING_INDEX(label_name, ',', n.n), ',', -1) as label_name
|
FROM t_label
|
CROSS JOIN (
|
SELECT 1 as n UNION ALL SELECT 2 UNION ALL SELECT 3 UNION ALL
|
SELECT 4 UNION ALL SELECT 5 UNION ALL SELECT 6 UNION ALL
|
SELECT 7 UNION ALL SELECT 8 UNION ALL SELECT 9 UNION ALL SELECT 10
|
) n
|
WHERE CHAR_LENGTH(label_name) - CHAR_LENGTH(REPLACE(label_name, ',', '')) >= n.n - 1
|
AND label_type = '站点标签'
|
ORDER BY label_name
|
</select>
|
|
<select id="queryOrgOilCount" resultType="java.util.Map">
|
SELECT
|
d.id as depart_id,
|
d.org_code,
|
d.depart_name,
|
COALESCE(oil.oil_count, 0) as oilCount,
|
COALESCE(traffic.car_count, 0) as carCount,
|
COALESCE(station.station_count, 0) as stationCount,
|
COALESCE(volume.oil_volume, 0) as oilVolume
|
FROM sys_depart d
|
LEFT JOIN (
|
SELECT
|
org_code,
|
COUNT(IF(behavior=1, 1, NULL)) as oil_count
|
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
|
) oil ON d.org_code = oil.org_code
|
LEFT JOIN (
|
SELECT
|
org_code,
|
SUM(car_count) as car_count
|
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
|
) traffic ON d.org_code = traffic.org_code
|
LEFT JOIN (
|
SELECT
|
org_code,
|
COUNT(1) as station_count
|
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
|
) station ON d.org_code = station.org_code
|
LEFT JOIN (
|
SELECT
|
org_code,
|
SUM(oil_volume) as oil_volume
|
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
|
) volume ON d.org_code = volume.org_code
|
WHERE d.org_code LIKE CONCAT(#{orgCode}, '%')
|
GROUP BY d.id, d.org_code, d.depart_name
|
</select>
|
|
</mapper>
|