<select id="statTraffic" resultType="com.nuorui.module.platform.domain.vo.StatTotalVO"><![CDATA[SELECTCASEWHEN #{dateType} = 0 THEN YEAR(date_series.generated_date) -- 按年查询WHEN #{dateType} = 1 THEN DATE_FORMAT(date_series.generated_date, '%Y-%m') -- 按月查询WHEN #{dateType} = 2 THEN CONCAT(YEAR(date_series.generated_date), '-', LPAD(WEEK(date_series.generated_date), 2, '0')) -- 按周查询WHEN #{dateType} = 3 THEN DATE_FORMAT(date_series.generated_date, '%Y-%m-%d') -- 按日查询ELSE DATE_FORMAT(date_series.generated_date, '%Y-%m-%d')END AS dateStr,SUM(CASE WHEN p.direction = 1 THEN 1 ELSE 0 END) AS upTotal,SUM(CASE WHEN p.direction = 0 THEN 1 ELSE 0 END) AS downTotalFROM (SELECTCASEWHEN #{dateType} = 0 THEN DATE_SUB(CURDATE(), INTERVAL (n.n - 1) YEAR) -- 按年查询WHEN #{dateType} = 1 THEN DATE_SUB(CURDATE(), INTERVAL (n.n - 1) MONTH) -- 按月查询WHEN #{dateType} = 2 THEN DATE_SUB(CURDATE(), INTERVAL (n.n - 1) WEEK) -- 按周查询WHEN #{dateType} = 3 THEN DATE_SUB(CURDATE(), INTERVAL (n.n - 1) DAY) -- 按日查询ELSE DATE_SUB(CURDATE(), INTERVAL (n.n - 1) DAY)END AS generated_dateFROM (SELECT @rownum := @rownum + 1 AS nFROM (SELECT 1 FROM information_schema.columns LIMIT #{limit}) a, (SELECT 1) b, (SELECT @rownum := 0) c) n) date_seriesLEFT JOIN plat_vessel_traffic pON ((YEAR(p.data_time) = YEAR(date_series.generated_date) AND #{dateType} = 0) -- 按年查询OR (DATE_FORMAT(p.data_time, '%Y-%m') = DATE_FORMAT(date_series.generated_date, '%Y-%m') AND #{dateType} = 1) -- 按月查询OR (YEAR(p.data_time) = YEAR(date_series.generated_date) AND WEEK(p.data_time) = WEEK(date_series.generated_date) AND #{dateType} = 2) -- 按周查询OR (DATE_FORMAT(p.data_time, '%Y-%m-%d') = DATE_FORMAT(date_series.generated_date, '%Y-%m-%d') AND #{dateType} = 3) -- 按日查询)AND p.data_time >= DATE_SUB(CURDATE(), INTERVAL 365 DAY)GROUP BY dateStrORDER BY dateStr DESC;]]></select>