高效能源监控管理系统
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

1064 lines
39 KiB

<?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.mh.system.mapper.energy.EnergyMapper">
<sql id="commonGroupSql">
<if test="timeType != null and timeType != '' and timeType == 'month'" >
,EXTRACT(MONTH FROM cur_time)
</if>
<if test="timeType != null and timeType != '' and timeType == 'day'" >
,EXTRACT(MONTH FROM cur_time),EXTRACT(DAY FROM cur_time)
</if>
<if test="timeType != null and timeType != '' and timeType == 'hour'" >
,EXTRACT(MONTH FROM cur_time),EXTRACT(DAY FROM cur_time),EXTRACT(HOUR FROM cur_time)
</if>
</sql>
<sql id="commonSelectSql">
<if test="timeType != null and timeType != '' and timeType == 'month'" >
,EXTRACT(MONTH FROM cur_time) as monthStr
</if>
<if test="timeType != null and timeType != '' and timeType == 'day'" >
,EXTRACT(MONTH FROM cur_time) as monthStr,EXTRACT(DAY FROM cur_time) as dayStr
</if>
<if test="timeType != null and timeType != '' and timeType == 'hour'" >
,EXTRACT(MONTH FROM cur_time) as monthStr,EXTRACT(DAY FROM cur_time) as dayStr,EXTRACT(HOUR FROM cur_time) as hourStr
</if>
</sql>
<sql id="commonLastGroupSql">
<if test="timeType != null and timeType != '' and timeType == 'month'" >
,EXTRACT(MONTH FROM cur_time)
</if>
<if test="timeType != null and timeType != '' and timeType == 'day'" >
,EXTRACT(MONTH FROM (cur_time + INTERVAL '1 day')), EXTRACT(DAY FROM (cur_time + INTERVAL '1 day'))
</if>
<if test="timeType != null and timeType != '' and timeType == 'hour'" >
,EXTRACT(MONTH FROM (cur_time + INTERVAL '1 hour')), EXTRACT(DAY FROM (cur_time + INTERVAL '1 hour')), EXTRACT(HOUR FROM (cur_time + INTERVAL '1 hour'))
</if>
</sql>
<sql id="commonLastSelectSql">
<if test="timeType != null and timeType != '' and timeType == 'month'" >
,EXTRACT(MONTH FROM cur_time) as monthStr
</if>
<if test="timeType != null and timeType != '' and timeType == 'day'" >
,EXTRACT(MONTH FROM (cur_time + INTERVAL '1 day')) as monthStr,EXTRACT(DAY FROM (cur_time + INTERVAL '1 day')) as dayStr
</if>
<if test="timeType != null and timeType != '' and timeType == 'hour'" >
,EXTRACT(MONTH FROM (cur_time + INTERVAL '1 hour')) as monthStr,EXTRACT(DAY FROM (cur_time + INTERVAL '1 hour')) as dayStr,EXTRACT(HOUR FROM (cur_time + INTERVAL '1 hour')) as hourStr
</if>
</sql>
<sql id="commonYOYWhereSql">
<if test='timeType != null and timeType != "" and timeType == "month"'>
and a.monthStr = b.monthStr
</if>
<if test='timeType != null and timeType != "" and timeType == "day"'>
and a.monthStr = b.monthStr and a.dayStr = b.dayStr
</if>
<if test='timeType != null and timeType != "" and timeType == "hour"'>
and a.monthStr = b.monthStr and a.dayStr = b.dayStr and a.hourStr = b.hourStr
</if>
order by timeStr
</sql>
<select id="queryOneTableYoy" resultType="com.mh.common.core.domain.entity.ConsumptionAnalyze">
SELECT
b.timeStr,
b.deviceType,
b.sumValue AS curValue,
a.sumValue AS lastValue,
CASE
WHEN a.sumValue > 0 THEN CONCAT(CAST((b.sumValue - a.sumValue) / a.sumValue * 100 AS NUMERIC(18, 2)), '%')
ELSE '同期无数据'
END AS yoy
FROM (
SELECT
<choose>
<when test="paramType != null and paramType != '' and paramType == 'system' ">
CAST(COALESCE(AVG(CASE WHEN calc_value!= 0 THEN calc_value ELSE NULL END), 0) * 1.0 AS NUMERIC(15, 2)) AS sumValue,
</when>
<otherwise>
SUM(calc_value) AS sumValue,
</otherwise>
</choose>
device_type AS deviceType,
TO_CHAR(cur_time, 'YYYY-MM-DD HH24:MI:SS') AS timeStr,
EXTRACT(YEAR FROM cur_time) AS yearStr
<include refid="commonSelectSql" />
FROM ${lastTableName} dh
WHERE cur_time >= #{yoyStartTime}::timestamp
AND cur_time &lt;= #{yoyEndTime}::timestamp
AND calc_value IS NOT NULL
<if test='paramType!= null and paramType!= "" and paramType!= "system" '>
and dh.device_num in (
select
cpm.mt_num
from
collection_params_manage cpm
join device_ledger dl on
cpm.device_ledger_id = dl.id
<if test="paramType != null and paramType != '' ">
and dl.device_type = #{paramType}
</if>
<if test="systemType != null and systemType != '' ">
and cpm.system_type = #{systemType}
</if>
and cpm.grade = 40 and cpm.terminal_device_type = '15' )
</if>
GROUP BY device_type, TO_CHAR(cur_time, 'YYYY-MM-DD HH24:MI:SS'), EXTRACT(YEAR FROM cur_time)
<include refid="commonGroupSql" />
UNION ALL
SELECT
<choose>
<when test="paramType!= null and paramType!= '' and paramType == 'system' ">
CAST(COALESCE(AVG(CASE WHEN calc_value!= 0 THEN calc_value ELSE NULL END), 0) * 1.0 AS NUMERIC(15, 2)) AS sumValue,
</when>
<otherwise>
SUM(calc_value) AS sumValue,
</otherwise>
</choose>
device_type AS deviceType,
TO_CHAR(cur_time, 'YYYY-MM-DD HH24:MI:SS') AS timeStr,
EXTRACT(YEAR FROM cur_time) AS yearStr
<include refid="commonSelectSql" />
FROM ${curTableName} dh
WHERE cur_time >= #{startTime}::timestamp
AND cur_time &lt;= #{endTime}::timestamp
AND calc_value IS NOT NULL
<if test='paramType!= null and paramType!= "" and paramType!= "system" '>
and dh.device_num in (
select
cpm.mt_num
from
collection_params_manage cpm
join device_ledger dl on
cpm.device_ledger_id = dl.id
<if test="paramType != null and paramType != '' ">
and dl.device_type = #{paramType}
</if>
<if test="systemType != null and systemType != '' ">
and cpm.system_type = #{systemType}
</if>
and cpm.grade = 40 and cpm.terminal_device_type = '15' )
</if>
GROUP BY device_type, TO_CHAR(cur_time, 'YYYY-MM-DD HH24:MI:SS'), EXTRACT(YEAR FROM cur_time)
<include refid="commonGroupSql" />
) a RIGHT JOIN (
SELECT
<choose>
<when test="paramType!= null and paramType!= '' and paramType == 'system' ">
CAST(COALESCE(AVG(CASE WHEN calc_value!= 0 THEN calc_value ELSE NULL END), 0) * 1.0 AS NUMERIC(15, 2)) AS sumValue,
</when>
<otherwise>
SUM(calc_value) AS sumValue,
</otherwise>
</choose>
device_type AS deviceType,
TO_CHAR(cur_time, 'YYYY-MM-DD HH24:MI:SS') AS timeStr,
EXTRACT(YEAR FROM cur_time) AS yearStr
<include refid="commonSelectSql" />
FROM ${lastTableName} dh
WHERE cur_time >= #{startTime}::timestamp AND cur_time &lt;= #{endTime}::timestamp
AND calc_value IS NOT NULL
<if test='paramType!= null and paramType!= "" and paramType!= "system" '>
and dh.device_num in (
select
cpm.mt_num
from
collection_params_manage cpm
join device_ledger dl on
cpm.device_ledger_id = dl.id
<if test="paramType != null and paramType != '' ">
and dl.device_type = #{paramType}
</if>
<if test="systemType != null and systemType != '' ">
and cpm.system_type = #{systemType}
</if>
and cpm.grade = 40 and cpm.terminal_device_type = '15' )
</if>
GROUP BY device_type, TO_CHAR(cur_time, 'YYYY-MM-DD HH24:MI:SS'), EXTRACT(YEAR FROM cur_time)
<include refid="commonGroupSql" />
UNION ALL
SELECT
<choose>
<when test="paramType!= null and paramType!= '' and paramType == 'system' ">
CAST(COALESCE(AVG(CASE WHEN calc_value!= 0 THEN calc_value ELSE NULL END), 0) * 1.0 AS NUMERIC(15, 2)) AS sumValue,
</when>
<otherwise>
SUM(calc_value) AS sumValue,
</otherwise>
</choose>
device_type AS deviceType,
TO_CHAR(cur_time, 'YYYY-MM-DD HH24:MI:SS') AS timeStr,
EXTRACT(YEAR FROM cur_time) AS yearStr
<include refid="commonSelectSql" />
FROM ${curTableName} dh
WHERE cur_time >= #{startTime}::timestamp AND cur_time &lt;= #{endTime}::timestamp
AND calc_value IS NOT NULL
<if test='paramType!= null and paramType!= "" and paramType!= "system" '>
and dh.device_num in (
select
cpm.mt_num
from
collection_params_manage cpm
join device_ledger dl on
cpm.device_ledger_id = dl.id
<if test="paramType != null and paramType != '' ">
and dl.device_type = #{paramType}
</if>
<if test="systemType != null and systemType != '' ">
and cpm.system_type = #{systemType}
</if>
and cpm.grade = 40 and cpm.terminal_device_type = '15' )
</if>
GROUP BY device_type, TO_CHAR(cur_time, 'YYYY-MM-DD HH24:MI:SS'), EXTRACT(YEAR FROM cur_time)
<include refid="commonGroupSql" />
) b ON (a.yearStr::integer + 1) = b.yearStr
<include refid="commonYOYWhereSql"/>
</select>
<select id="queryManyTableYoy" resultType="com.mh.common.core.domain.entity.ConsumptionAnalyze">
SELECT
b.timeStr,
b.deviceType,
b.sumValue AS curValue,
a.sumValue AS lastValue,
CASE
WHEN a.sumValue > 0
THEN CONCAT( ( (b.sumValue - a.sumValue) / a.sumValue * 100 )::NUMERIC(18,2), '%' )
ELSE '同期无数据'
END AS yoy
FROM (
SELECT
SUM(calc_value) AS sumValue,
device_type AS deviceType,
SUBSTRING(TO_CHAR(cur_time, 'YYYY-MM-DD HH24:MI:SS') FROM 1 FOR ${len}) AS timeStr,
EXTRACT(YEAR FROM cur_time)::INTEGER AS yearStr
<include refid="commonSelectSql" />
FROM ${yoyLastTableName} dh
WHERE
cur_time >= #{yoyStartTime}::timestamp AND cur_time &lt;= #{yoyEndTime}::timestamp
and dh.device_num in (
select
cpm.mt_num
from
collection_params_manage cpm
join device_ledger dl on
cpm.device_ledger_id = dl.id
<if test="paramType != null and paramType != '' ">
and dl.device_type = #{paramType}
</if>
<if test="systemType != null and systemType != '' ">
and cpm.system_type = #{systemType}
</if>
and cpm.grade = 40 and cpm.terminal_device_type = '15' )
GROUP BY
device_type,
SUBSTRING(TO_CHAR(cur_time, 'YYYY-MM-DD HH24:MI:SS') FROM 1 FOR ${len}),
EXTRACT(YEAR FROM cur_time)
<include refid="commonGroupSql" />
UNION ALL
SELECT
SUM(calc_value) AS sumValue,
device_type AS deviceType,
SUBSTRING(TO_CHAR(cur_time, 'YYYY-MM-DD HH24:MI:SS') FROM 1 FOR ${len}) AS timeStr,
EXTRACT(YEAR FROM cur_time)::INTEGER AS yearStr
<include refid="commonSelectSql" />
FROM ${yoyCurTableName} dh
WHERE
cur_time >= #{yoyStartTime}::timestamp AND cur_time &lt;= #{yoyEndTime}::timestamp
and dh.device_num in (
select
cpm.mt_num
from
collection_params_manage cpm
join device_ledger dl on
cpm.device_ledger_id = dl.id
<if test="paramType != null and paramType != '' ">
and dl.device_type = #{paramType}
</if>
<if test="systemType != null and systemType != '' ">
and cpm.system_type = #{systemType}
</if>
and cpm.grade = 40 and cpm.terminal_device_type = '15' )
GROUP BY
device_type,
SUBSTRING(TO_CHAR(cur_time, 'YYYY-MM-DD HH24:MI:SS') FROM 1 FOR ${len}),
EXTRACT(YEAR FROM cur_time)
<include refid="commonGroupSql" />
) a
RIGHT JOIN (
SELECT
SUM(calc_value) AS sumValue,
device_type AS deviceType,
SUBSTRING(TO_CHAR(cur_time, 'YYYY-MM-DD HH24:MI:SS') FROM 1 FOR ${len}) AS timeStr,
EXTRACT(YEAR FROM cur_time)::INTEGER AS yearStr
<include refid="commonSelectSql" />
FROM ${lastTableName} dh
WHERE
cur_time >= #{startTime}::timestamp AND cur_time &lt;= #{endTime}::timestamp
and dh.device_num in (
select
cpm.mt_num
from
collection_params_manage cpm
join device_ledger dl on
cpm.device_ledger_id = dl.id
<if test="paramType != null and paramType != '' ">
and dl.device_type = #{paramType}
</if>
<if test="systemType != null and systemType != '' ">
and cpm.system_type = #{systemType}
</if>
and cpm.grade = 40 and cpm.terminal_device_type = '15' )
GROUP BY
device_type,
SUBSTRING(TO_CHAR(cur_time, 'YYYY-MM-DD HH24:MI:SS') FROM 1 FOR ${len}),
EXTRACT(YEAR FROM cur_time)
<include refid="commonGroupSql" />
UNION ALL
SELECT
SUM(calc_value) AS sumValue,
device_type AS deviceType,
SUBSTRING(TO_CHAR(cur_time, 'YYYY-MM-DD HH24:MI:SS') FROM 1 FOR ${len}) AS timeStr,
EXTRACT(YEAR FROM cur_time)::INTEGER AS yearStr
<include refid="commonSelectSql" />
FROM ${curTableName} dh
WHERE
cur_time >= #{startTime}::timestamp AND cur_time &lt;= #{endTime}::timestamp
and dh.device_num in (
select
cpm.mt_num
from
collection_params_manage cpm
join device_ledger dl on
cpm.device_ledger_id = dl.id
<if test="paramType != null and paramType != '' ">
and dl.device_type = #{paramType}
</if>
<if test="systemType != null and systemType != '' ">
and cpm.system_type = #{systemType}
</if>
and cpm.grade = 40 and cpm.terminal_device_type = '15' )
GROUP BY
device_type,
SUBSTRING(TO_CHAR(cur_time, 'YYYY-MM-DD HH24:MI:SS') FROM 1 FOR ${len}),
EXTRACT(YEAR FROM cur_time)
<include refid="commonGroupSql" />
) b ON a.yearStr + 1 = b.yearStr
<include refid="commonYOYWhereSql"/>
</select>
<select id="queryMonthAndYearMom" resultType="com.mh.common.core.domain.entity.ConsumptionAnalyze">
SELECT
t1.timeStr,
t1.sumValue AS curValue,
t2.sumValue AS lastValue,
CASE
WHEN t2.sumValue > 0 THEN CONCAT(CAST((t1.sumValue - t2.sumValue) / t2.sumValue * 100 AS NUMERIC(18, 2)), '%')
ELSE '上期无数据'
END AS mom
FROM (
SELECT
TO_CHAR(cur_time, 'YYYY-MM-DD HH24:MI:SS') AS timeStr,
<choose>
<when test="paramType != null and paramType != '' and paramType == 'system' ">
CAST(COALESCE(AVG(CASE WHEN calc_value!= 0 THEN calc_value ELSE NULL END), 0) * 1.0 AS NUMERIC(15, 2)) AS sumValue,
</when>
<otherwise>
SUM(calc_value) AS sumValue,
</otherwise>
</choose>
EXTRACT(YEAR FROM cur_time) AS yearStr
<if test="timeType != null and timeType != '' and timeType == 'month'">
,EXTRACT(MONTH FROM cur_time) AS monthStr
</if>
FROM ${tableName} dh
WHERE cur_time >= #{startTime}::timestamp AND cur_time &lt;= #{endTime}::timestamp
AND calc_value IS NOT NULL
<if test='paramType!= null and paramType!= "" and paramType!= "system" '>
and dh.device_num in (
select
cpm.mt_num
from
collection_params_manage cpm
join device_ledger dl on
cpm.device_ledger_id = dl.id
<if test="paramType != null and paramType != '' ">
and dl.device_type = #{paramType}
</if>
<if test="systemType != null and systemType != '' ">
and cpm.system_type = #{systemType}
</if>
and cpm.grade = 40 and cpm.terminal_device_type = '15' )
</if>
GROUP BY TO_CHAR(cur_time, 'YYYY-MM-DD HH24:MI:SS'), EXTRACT(YEAR FROM cur_time)
<if test="timeType!= null and timeType!= '' and timeType == 'month'">
,EXTRACT(MONTH FROM cur_time)
</if>
) t1
LEFT JOIN (
SELECT
<choose>
<when test="paramType!= null and paramType!= '' and paramType == 'system' ">
CAST(COALESCE(AVG(CASE WHEN calc_value!= 0 THEN calc_value ELSE NULL END), 0) * 1.0 AS NUMERIC(15, 2)) AS sumValue,
</when>
<otherwise>
SUM(calc_value) AS sumValue,
</otherwise>
</choose>
EXTRACT(YEAR FROM cur_time) AS yearStr
<if test="timeType!= null and timeType!= '' and timeType == 'month'">
,EXTRACT(MONTH FROM cur_time) AS monthStr
</if>
FROM ${tableName} dh
WHERE cur_time >= #{momStartTime}::timestamp AND cur_time &lt;= #{momEndTime}::timestamp
AND calc_value IS NOT NULL
<if test='paramType!= null and paramType!= "" and paramType!= "system" '>
and dh.device_num in (
select
cpm.mt_num
from
collection_params_manage cpm
join device_ledger dl on
cpm.device_ledger_id = dl.id
<if test="paramType != null and paramType != '' ">
and dl.device_type = #{paramType}
</if>
<if test="systemType != null and systemType != '' ">
and cpm.system_type = #{systemType}
</if>
and cpm.grade = 40 and cpm.terminal_device_type = '15' )
</if>
GROUP BY EXTRACT(YEAR FROM cur_time)
<if test="timeType!= null and timeType!= '' and timeType == 'month'">
,EXTRACT(MONTH FROM cur_time)
</if>
) t2 ON
<choose>
<when test="timeType!= null and timeType!= '' and timeType == 'month'">
t1.monthStr = t2.monthStr + 1
</when>
<otherwise>
t1.yearStr = t2.yearStr + 1
</otherwise>
</choose>
ORDER BY timeStr
</select>
<select id="queryOneTableMom" resultType="com.mh.common.core.domain.entity.ConsumptionAnalyze">
select
t1.timeStr,
t1.sumValue as curValue,
t2.sumValue as lastValue,
case
when t2.sumValue > 0 then concat(to_char( ((t1.sumValue - t2.sumValue)/t2.sumValue*100), 'FM999999999990.00'), '%')
else '上期无数据'
end as mom
from
(
select
substring(to_char(cur_time, 'YYYY-MM-DD HH24:MI:SS') from 1 for ${len}) as timeStr,
<choose>
<when test="paramType != null and paramType != '' and paramType == 'system' ">
cast(coalesce(avg(case when calc_value != 0 then calc_value else null end),0)*1.0 as numeric(15,2)) as sumValue,
</when>
<otherwise>
sum(calc_value) as sumValue,
</otherwise>
</choose>
extract(year from cur_time) as yearStr
<include refid="commonSelectSql"/>
from
${tableName} dh
where
cur_time >= #{startTime}::timestamp
and cur_time &lt;= #{endTime}::timestamp
and calc_value is not null
<if test="paramType != null and paramType != '' and paramType != 'system'">
and dh.device_num in (
select
cpm.mt_num
from
collection_params_manage cpm
join device_ledger dl on
cpm.device_ledger_id = dl.id
<if test="paramType != null and paramType != '' ">
and dl.device_type = #{paramType}
</if>
<if test="systemType != null and systemType != '' ">
and cpm.system_type = #{systemType}
</if>
and cpm.grade = 40 and cpm.terminal_device_type = '15' )
</if>
group by
substring(to_char(cur_time, 'YYYY-MM-DD HH24:MI:SS') from 1 for ${len}),
extract(year from cur_time)
<include refid="commonGroupSql"/>
) t1
left join
(
select
<choose>
<when test="paramType != null and paramType != '' and paramType == 'system' ">
cast(coalesce(avg(case when calc_value != 0 then calc_value else null end),0)*1.0 as numeric(15,2)) as sumValue,
</when>
<otherwise>
sum(calc_value) as sumValue,
</otherwise>
</choose>
extract(year from cur_time) as yearStr
<include refid="commonLastSelectSql"/>
from
${tableName} dh
where
cur_time >= #{momStartTime}::timestamp
and cur_time &lt;= #{momEndTime}::timestamp
and calc_value is not null
<if test="paramType != null and paramType != '' and paramType != 'system'">
and dh.device_num in (
select
cpm.mt_num
from
collection_params_manage cpm
join device_ledger dl on
cpm.device_ledger_id = dl.id
<if test="paramType != null and paramType != '' ">
and dl.device_type = #{paramType}
</if>
<if test="systemType != null and systemType != '' ">
and cpm.system_type = #{systemType}
</if>
and cpm.grade = 40 and cpm.terminal_device_type = '15' )
</if>
group by
extract(year from cur_time)
<include refid="commonLastGroupSql"/>
) t2 on
<choose>
<when test="timeType != null and timeType != '' and timeType == 'day'">
t1.yearStr = t2.yearStr and t1.monthStr = t2.monthStr and t1.dayStr = t2.dayStr
</when>
<otherwise>
t1.yearStr = t2.yearStr and t1.monthStr = t2.monthStr and t1.dayStr = t2.dayStr and t1.hourStr = t2.hourStr
</otherwise>
</choose>
order by timeStr
</select>
<select id="queryManyTableMom" resultType="com.mh.common.core.domain.entity.ConsumptionAnalyze">
select
t1.timeStr,
t1.sumValue as curValue,
t2.sumValue as lastValue,
case
when t2.sumValue > 0 then concat(to_char( ((t1.sumValue - t2.sumValue)/t2.sumValue*100), 'FM999999999990.00'), '%')
else '上期无数据'
end as mom
from
(
select
substring(to_char(cur_time, 'YYYY-MM-DD HH24:MI:SS') from 1 for ${len}) as timeStr,
sum(calc_value) as sumValue,
extract(year from cur_time) as yearStr
<include refid="commonSelectSql"/>
from
${tableName1} dh
where
cur_time >= #{startTime}::timestamp
and cur_time &lt;= #{endTime}::timestamp
and dh.device_num in (
select
cpm.mt_num
from
collection_params_manage cpm
join device_ledger dl on
cpm.device_ledger_id = dl.id
<if test="paramType != null and paramType != '' ">
and dl.device_type = #{paramType}
</if>
<if test="systemType != null and systemType != '' ">
and cpm.system_type = #{systemType}
</if>
and cpm.grade = 40 and cpm.terminal_device_type = '15' )
group by
substring(to_char(cur_time, 'YYYY-MM-DD HH24:MI:SS') from 1 for ${len}),
extract(year from cur_time)
<include refid="commonGroupSql"/>
union all
select
substring(to_char(cur_time, 'YYYY-MM-DD HH24:MI:SS') from 1 for ${len}) as timeStr,
sum(calc_value) as sumValue,
extract(year from cur_time) as yearStr
<include refid="commonSelectSql"/>
from
${tableName2} dh
where
cur_time >= #{startTime}::timestamp
and cur_time &lt;= #{endTime}::timestamp
and dh.device_num in (
select
cpm.mt_num
from
collection_params_manage cpm
join device_ledger dl on
cpm.device_ledger_id = dl.id
<if test="paramType != null and paramType != '' ">
and dl.device_type = #{paramType}
</if>
<if test="systemType != null and systemType != '' ">
and cpm.system_type = #{systemType}
</if>
and cpm.grade = 40 and cpm.terminal_device_type = '15' )
group by
substring(to_char(cur_time, 'YYYY-MM-DD HH24:MI:SS') from 1 for ${len}),
extract(year from cur_time)
<include refid="commonGroupSql"/>
) t1
left join
(
select
sum(calc_value) as sumValue,
extract(year from cur_time) as yearStr
<include refid="commonLastSelectSql"/>
from
${tableName1} dh
where
cur_time >= #{momStartTime}::timestamp
and cur_time &lt;= #{momEndTime}::timestamp
and dh.device_num in (
select
cpm.mt_num
from
collection_params_manage cpm
join device_ledger dl on
cpm.device_ledger_id = dl.id
<if test="paramType != null and paramType != '' ">
and dl.device_type = #{paramType}
</if>
<if test="systemType != null and systemType != '' ">
and cpm.system_type = #{systemType}
</if>
and cpm.grade = 40 and cpm.terminal_device_type = '15' )
group by
extract(year from cur_time)
<include refid="commonLastGroupSql"/>
union all
select
sum(calc_value) as sumValue,
extract(year from cur_time) as yearStr
<include refid="commonLastSelectSql"/>
from
${tableName2} dh
where
cur_time >= #{momStartTime}::timestamp
and cur_time &lt;= #{momEndTime}::timestamp
and dh.device_num in (
select
cpm.mt_num
from
collection_params_manage cpm
join device_ledger dl on
cpm.device_ledger_id = dl.id
<if test="paramType != null and paramType != '' ">
and dl.device_type = #{paramType}
</if>
<if test="systemType != null and systemType != '' ">
and cpm.system_type = #{systemType}
</if>
and cpm.grade = 40 and cpm.terminal_device_type = '15' )
group by
extract(year from cur_time)
<include refid="commonLastGroupSql"/>
) t2 on
<choose>
<when test="timeType != null and timeType != '' and timeType == 'day'">
t1.yearStr = t2.yearStr and t1.monthStr = t2.monthStr and t1.dayStr = t2.dayStr
</when>
<otherwise>
t1.yearStr = t2.yearStr and t1.monthStr = t2.monthStr and t1.dayStr = t2.dayStr and t1.hourStr = t2.hourStr
</otherwise>
</choose>
order by timeStr
</select>
<select id="queryDeviceOneTable" resultType="com.mh.common.core.domain.entity.ConsumptionAnalyze">
select
SUM(coalesce(dm.calc_value, 0)) as curValue,
TO_CHAR(dm.cur_time,
<choose>
<when test='len == 4'>'YYYY'</when>
<when test='len == 7'>'YYYY-MM'</when>
<when test='len == 10'>'YYYY-MM-DD'</when>
<when test='len == 13'>'YYYY-MM-DD HH24'</when>
<when test='len == 16'>'YYYY-MM-DD HH24:MI'</when>
<otherwise>'YYYY-MM-DD HH24:MI:SS'</otherwise>
</choose>
) as timeStr
from
${curTableName} dm
where
dm.cur_time >= #{startTime}::timestamp
and dm.cur_time &lt;= #{endTime}::timestamp
and dm.device_num in(
select
cpm.mt_num
from
collection_params_manage cpm
join
device_ledger dl
on
cpm.device_ledger_id = dl.id
where
dl.device_type = '5'
and cpm.terminal_device_type = #{deviceType}
and cpm.is_use = '0'
and cpm.grade = 40
group by
cpm.mt_num
)
group by
TO_CHAR(dm.cur_time,
<choose>
<when test='len == 4'>'YYYY'</when>
<when test='len == 7'>'YYYY-MM'</when>
<when test='len == 10'>'YYYY-MM-DD'</when>
<when test='len == 13'>'YYYY-MM-DD HH24'</when>
<when test='len == 16'>'YYYY-MM-DD HH24:MI'</when>
<otherwise>'YYYY-MM-DD HH24:MI:SS'</otherwise>
</choose>
order by timeStr
</select>
<select id="queryDeviceManyTable" resultType="com.mh.common.core.domain.entity.ConsumptionAnalyze">
<if test="lastTableName != curTableName">
select
SUM(coalesce(dm.calc_value, 0)) as curValue,
TO_CHAR(dm.cur_time,
<choose>
<when test='len == 4'>'YYYY'</when>
<when test='len == 7'>'YYYY-MM'</when>
<when test='len == 10'>'YYYY-MM-DD'</when>
<when test='len == 13'>'YYYY-MM-DD HH24'</when>
<when test='len == 16'>'YYYY-MM-DD HH24:MI'</when>
<otherwise>'YYYY-MM-DD HH24:MI:SS'</otherwise>
</choose>
) as timeStr
from
${lastTableName} dm
where
dm.cur_time >= #{startTime}::timestamp
and dm.cur_time &lt;= #{endTime}::timestamp
and dm.device_num in(
select
cpm.mt_num
from
collection_params_manage cpm
join
device_ledger dl
on
cpm.device_ledger_id = dl.id
where
dl.device_type = '5'
and cpm.terminal_device_type = #{deviceType}
<if test="systemType != null and systemType != ''">
and cpm.system_type = #{systemType}
</if>
and cpm.is_use = '0'
and cpm.grade = 40
group by
cpm.mt_num
)
group by
TO_CHAR(dm.cur_time,
<choose>
<when test='len == 4'>'YYYY'</when>
<when test='len == 7'>'YYYY-MM'</when>
<when test='len == 10'>'YYYY-MM-DD'</when>
<when test='len == 13'>'YYYY-MM-DD HH24'</when>
<when test='len == 16'>'YYYY-MM-DD HH24:MI'</when>
<otherwise>'YYYY-MM-DD HH24:MI:SS'</otherwise>
</choose>
)
union all
</if>
select
SUM(coalesce(dm.calc_value, 0)) as curValue,
TO_CHAR(dm.cur_time,
<choose>
<when test='len == 4'>'YYYY'</when>
<when test='len == 7'>'YYYY-MM'</when>
<when test='len == 10'>'YYYY-MM-DD'</when>
<when test='len == 13'>'YYYY-MM-DD HH24'</when>
<when test='len == 16'>'YYYY-MM-DD HH24:MI'</when>
<otherwise>'YYYY-MM-DD HH24:MI:SS'</otherwise>
</choose>
) as timeStr
from
${curTableName} dm
where
dm.cur_time >= #{startTime}::timestamp
and dm.cur_time &lt;= #{endTime}::timestamp
and dm.device_num in(
select
cpm.mt_num
from
collection_params_manage cpm
join
device_ledger dl
on
cpm.device_ledger_id = dl.id
where
dl.device_type = '5'
and cpm.terminal_device_type = #{deviceType}
<if test="systemType != null and systemType != ''">
and cpm.system_type = #{systemType}
</if>
and cpm.is_use = '0'
and cpm.grade = 40
group by
cpm.mt_num
)
group by
TO_CHAR(dm.cur_time,
<choose><when test='len == 4'>'YYYY'</when>
<when test='len == 7'>'YYYY-MM'</when>
<when test='len == 10'>'YYYY-MM-DD'</when>
<when test='len == 13'>'YYYY-MM-DD HH24'</when>
<when test='len == 16'>'YYYY-MM-DD HH24:MI'</when>
<otherwise>'YYYY-MM-DD HH24:MI:SS'</otherwise>
</choose>
)
order by timeStr
</select>
<select id="queryLineDataSysByOne" resultType="com.mh.common.core.domain.entity.ConsumptionAnalyze">
select
sum(coalesce(calc_value,0)) as curValue,
'efrMeter' as deviceType,
TO_CHAR(dm.cur_time,
'YYYY-MM-DD HH24:MI') as timeStr
from
${curTable} dm
where
dm.cur_time >= #{startTime}::timestamp
and dm.cur_time &lt;= #{endTime}::timestamp
and dm.device_num in (
select
cpm.mt_num
from
collection_params_manage cpm
join device_ledger dl
on
cpm.device_ledger_id = dl.id
and dl.device_type = '5'
and cpm.grade = 140
and cpm.terminal_device_type = '15'
)
group by
device_type,
TO_CHAR(dm.cur_time,
'YYYY-MM-DD HH24:MI')
union all
select
sum(coalesce(calc_value,0)) as curValue,
'efrCloud' as deviceType,
TO_CHAR(dm.cur_time,
'YYYY-MM-DD HH24:MI') as timeStr
from
${curTable} dm
where
dm.cur_time >= #{startTime}::timestamp
and dm.cur_time &lt;= #{endTime}::timestamp
and dm.device_num in (
select
cpm.mt_num
from
collection_params_manage cpm
join device_ledger dl
on
cpm.device_ledger_id = dl.id
and dl.device_type = '6'
and cpm.grade = 140
and cpm.terminal_device_type = '15'
)
group by
device_type,
TO_CHAR(dm.cur_time,
'YYYY-MM-DD HH24:MI')
</select>
<select id="queryLineDataSysByMany" resultType="com.mh.common.core.domain.entity.ConsumptionAnalyze">
select
sum(coalesce(calc_value,0)) as curValue,
'efrMeter' as deviceType,
TO_CHAR(dm.cur_time,
'YYYY-MM-DD HH24:MI') as timeStr
from
${lastTable} dm
where
dm.cur_time >= #{startTime}::timestamp
and dm.cur_time &lt;= #{endTime}::timestamp
and dm.device_num in (
select
cpm.mt_num
from
collection_params_manage cpm
join device_ledger dl
on
cpm.device_ledger_id = dl.id
and dl.device_type = '5'
and cpm.grade = 140
)
group by
device_type,
TO_CHAR(dm.cur_time,
'YYYY-MM-DD HH24:MI')
union all
select
sum(coalesce(calc_value,0)) as curValue,
'efrCloud' as deviceType,
TO_CHAR(dm.cur_time,
'YYYY-MM-DD HH24:MI') as timeStr
from
${lastTable} dm
where
dm.cur_time >= #{startTime}::timestamp
and dm.cur_time &lt;= #{endTime}::timestamp
and dm.device_num in (
select
cpm.mt_num
from
collection_params_manage cpm
join device_ledger dl
on
cpm.device_ledger_id = dl.id
and dl.device_type = '6'
and cpm.grade = 140
)
group by
device_type,
TO_CHAR(dm.cur_time,
'YYYY-MM-DD HH24:MI')
union all
select
sum(coalesce(calc_value,0)) as curValue,
'efrMeter' as deviceType,
TO_CHAR(dm.cur_time,
'YYYY-MM-DD HH24:MI') as timeStr
from
${curTable} dm
where
dm.cur_time >= #{startTime}::timestamp
and dm.cur_time &lt;= #{endTime}::timestamp
and dm.device_num in (
select
cpm.mt_num
from
collection_params_manage cpm
join device_ledger dl
on
cpm.device_ledger_id = dl.id
and dl.device_type = '5'
and cpm.grade = 140
)
group by
device_type,
TO_CHAR(dm.cur_time,
'YYYY-MM-DD HH24:MI')
union all
select
sum(coalesce(calc_value,0)) as curValue,
'efrCloud' as deviceType,
TO_CHAR(dm.cur_time,
'YYYY-MM-DD HH24:MI') as timeStr
from
${curTable} dm
where
dm.cur_time >= #{startTime}::timestamp
and dm.cur_time &lt;= #{endTime}::timestamp
and dm.device_num in (
select
cpm.mt_num
from
collection_params_manage cpm
join device_ledger dl
on
cpm.device_ledger_id = dl.id
and dl.device_type = '6'
and cpm.grade = 140
)
group by
device_type,
TO_CHAR(dm.cur_time,
'YYYY-MM-DD HH24:MI')
</select>
<select id="queryDeviceLineManyTable" resultType="com.mh.common.core.domain.entity.ConsumptionAnalyze">
<if test="lastTableName != curTableName">
select
SUM(coalesce(dm.calc_value, 0)) as curValue,
dm.cur_time as timeStr
from
${lastTableName} dm
where
dm.cur_time >= #{startTime}::timestamp
and dm.cur_time &lt;= #{endTime}::timestamp
and dm.device_num in(
select
cpm.mt_num
from
collection_params_manage cpm
join
device_ledger dl
on
cpm.device_ledger_id = dl.id
where
dl.device_type = '5'
and cpm.terminal_device_type = #{deviceType}
<if test="systemType != null and systemType != ''">
and cpm.system_type = #{systemType}
</if>
and cpm.is_use = '0'
and cpm.grade = 40
group by
cpm.mt_num
)
group by
dm.cur_time
union all
</if>
select
SUM(coalesce(dm.calc_value, 0)) as curValue,
dm.cur_time as timeStr
from
${curTableName} dm
where
dm.cur_time >= #{startTime}::timestamp
and dm.cur_time &lt;= #{endTime}::timestamp
and dm.device_num in(
select
cpm.mt_num
from
collection_params_manage cpm
join
device_ledger dl
on
cpm.device_ledger_id = dl.id
where
dl.device_type = '5'
and cpm.terminal_device_type = #{deviceType}
<if test="systemType != null and systemType != ''">
and cpm.system_type = #{systemType}
</if>
and cpm.is_use = '0'
and cpm.grade = 40
group by
cpm.mt_num
)
group by
dm.cur_time
order by timeStr
</select>
</mapper>