123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332 |
- <?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.huaxu.dao.MonitorDataReportMapper">
- <resultMap id="MonitorDataChartReportMap" type="com.huaxu.dto.MonitorDataChartReportDeviceDto">
- <result property="devoceCode" column="devoceCode" jdbcType="INTEGER"/>
- <result property="deviceName" column="deviceName" jdbcType="INTEGER"/>
- <collection property="attributeData" resultMap="AttributeData"/>
- </resultMap>
- <resultMap id="AttributeData" type="com.huaxu.dto.MonitorDataChartReportAttributeDto">
- <result property="attributeType" column="attributeType"/>
- <result property="attributeName" column="attributeName"/>
- <collection property="monitorDataChartReportValue" resultMap="MonitorDataChartReportValue"/>
- </resultMap>
- <resultMap id="MonitorDataChartReportValue" type="com.huaxu.dto.MonitorDataChartReportValueDto">
- <result property="dateLabel" column="dateLabel" />
- <result property="monitorData" column="monitorData" />
- <result property="data" column="data"/>
- <result property="date" column="date"/>
- </resultMap>
- <sql id="MonitorDataReportJoins">
- left join sms_device_parm dp on dp.DEVICE_ID=r.DEVICE_ID and dp.ATTRIBUTE_ID = r.ATTRIBUTE_ID
- left join sms_device_attribute da on da.id=r.ATTRIBUTE_ID
- left join sms_device d on d.id=r.DEVICE_ID
- </sql>
- <select id="MonitorDataChartReport" resultMap="MonitorDataChartReportMap">
- select
- <if test="type != null and type ==1">
- r.`MONTH` as "dateLabel",
- </if>
- <if test="type != null and type ==2">
- r.`DAY` as "dateLabel",
- </if>
- <if test="type != null and type ==3">
- r.`HOUR` as "dateLabel",
- </if>
- cast(ifnull(r.AVG_VALUE,'') as char)+ifnull(da.UNIT,'') as "monitorData"
- ,r.AVG_VALUE as "data"
- ,r.COLLECT_DATE as "date"
- ,d.DEVICE_CODE as "devoceCode"
- ,d.DEVICE_NAME as "deviceName"
- ,r.ATTRIBUTE_NAME as "attributeName"
- from ${tableName} r
- <include refid="MonitorDataReportJoins"/>
- where dp.IS_CHART = 1 and r.PARENT_SCENE_ID=#{sceneId}
- <if test="year != null">
- and r.year=#{year}
- </if>
- <if test="month != null">
- and r.month=#{month}
- </if>
- <if test="day != null">
- and r.day=#{day}
- </if>
- <if test="tenantId != null and tenantId != '' ">
- and d.tenant_id = #{tenantId}
- </if>
- <if test="userType!=null and userType!=-999 and userType!=-9999 and programItems != null and programItems.size() > 0">
- <if test="permissonType == 5 or permissonType == 2">
- and ( d.DEPT_ORG_ID in
- <foreach collection="programItems" item="item" open="(" close=")" separator=",">
- #{item.orgId}
- </foreach>
- or
- d.COMPANY_ORG_ID in
- <foreach collection="programItems" item="item" open="(" close=")" separator=",">
- #{item.orgId}
- </foreach>
- )
- </if>
- <if test="permissonType == 4 or permissonType == 3">
- and d.DEPT_ORG_ID in
- <foreach collection="programItems" item="item" open="(" close=")" separator=",">
- #{item.orgId}
- </foreach>
- </if>
- <if test="permissonType == 1">
- and d.COMPANY_ORG_ID in
- <foreach collection="programItems" item="item" open="(" close=")" separator=",">
- #{item.orgId}
- </foreach>
- and (d.DEPT_ORG_ID is null or d.DEPT_ORG_ID =0)
- </if>
- </if>
- <if test="type != null and type ==1">
- order by d.DEVICE_CODE,r.ATTRIBUTE_NAME,r.`MONTH` asc
- </if>
- <if test="type != null and type ==2">
- order by d.DEVICE_CODE,r.ATTRIBUTE_NAME,r.`DAY` asc
- </if>
- <if test="type != null and type ==3">
- order by d.DEVICE_CODE,r.ATTRIBUTE_NAME,r.`HOUR` asc
- </if>
- </select>
- <select id="MonitorDataEnergyReport" resultMap="MonitorDataChartReportMap">
- select
- <if test="type != null and type ==1">
- r.`MONTH` as "dateLabel",
- </if>
- <if test="type != null and type ==2">
- r.`DAY` as "dateLabel",
- </if>
- <if test="type != null and type ==3">
- r.`HOUR` as "dateLabel",
- </if>
- cast(ifnull(r.SUM_VALUE,0) as char)+ifnull(da.UNIT,'') as "monitorData"
- ,ifnull(r.SUM_VALUE ,0) as "data"
- ,r.COLLECT_DATE as "date"
- ,d.DEVICE_CODE as "devoceCode"
- ,d.DEVICE_NAME as "deviceName"
- ,da.ATTRIBUTE_TYPE as "attributeType"
- ,if(da.ATTRIBUTE_TYPE=3,'用水量','耗电量') as "attributeName"
- <if test="type != null and type ==1">
- from sms_year_report r
- </if>
- <if test="type != null and type ==2">
- from sms_month_report r
- </if>
- <if test="type != null and type ==3">
- from sms_day_report r
- </if>
- <include refid="MonitorDataReportJoins"/>
- where (da.ATTRIBUTE_TYPE=3 or da.ATTRIBUTE_TYPE=5)
- <if test="sceneIds != null and sceneIds.size()>0">
- and r.PARENT_SCENE_ID in
- <foreach collection="sceneIds" item="item" open="(" close=")" separator=",">
- #{item}
- </foreach>
- </if>
- <if test="tenantId != null and tenantId != '' ">
- and d.tenant_id = #{tenantId}
- </if>
- <if test="userType!=null and userType!=-999 and userType!=-9999 and programItems != null and programItems.size() > 0">
- <if test="permissonType == 5 or permissonType == 2">
- and ( d.DEPT_ORG_ID in
- <foreach collection="programItems" item="item" open="(" close=")" separator=",">
- #{item.orgId}
- </foreach>
- or
- d.COMPANY_ORG_ID in
- <foreach collection="programItems" item="item" open="(" close=")" separator=",">
- #{item.orgId}
- </foreach>
- )
- </if>
- <if test="permissonType == 4 or permissonType == 3">
- and d.DEPT_ORG_ID in
- <foreach collection="programItems" item="item" open="(" close=")" separator=",">
- #{item.orgId}
- </foreach>
- </if>
- <if test="permissonType == 1">
- and d.COMPANY_ORG_ID in
- <foreach collection="programItems" item="item" open="(" close=")" separator=",">
- #{item.orgId}
- </foreach>
- and (d.DEPT_ORG_ID is null or d.DEPT_ORG_ID =0)
- </if>
- </if>
- <if test="type != null and type ==1">
- and r.year=#{year}
- order by d.DEVICE_CODE,da.ATTRIBUTE_TYPE asc,r.`MONTH` asc
- </if>
- <if test="type != null and type ==2">
- and r.year=#{year} and r.month=#{month}
- order by d.DEVICE_CODE,da.ATTRIBUTE_TYPE asc,r.`day` asc
- </if>
- <if test="type != null and type ==3">
- and r.year=#{year} and r.month=#{month} and r.day=#{day}
- order by d.DEVICE_CODE,da.ATTRIBUTE_TYPE asc,r.`hour` asc
- </if>
- </select>
- <select id="MonitorDataQualityReport" resultMap="MonitorDataChartReportMap">
- select
- <if test="type != null and type ==1">
- r.`MONTH` as "dateLabel",
- </if>
- <if test="type != null and type ==2">
- r.`DAY` as "dateLabel",
- </if>
- <if test="type != null and type ==3">
- r.`HOUR` as "dateLabel",
- </if>
- cast(ifnull(r.AVG_VALUE,'') as char)+ifnull(da.UNIT,'') as "monitorData"
- ,r.AVG_VALUE as "data"
- ,r.COLLECT_DATE as "date"
- ,d.DEVICE_CODE as "devoceCode"
- ,d.DEVICE_NAME as "deviceName"
- ,da.ATTRIBUTE_TYPE as "attributeType"
- ,if(da.ATTRIBUTE_TYPE=8,'PH',if(da.ATTRIBUTE_TYPE=11,'余氯','浊度')) as "attributeName"
- <if test="type != null and type ==1">
- from sms_year_report r
- </if>
- <if test="type != null and type ==2">
- from sms_month_report r
- </if>
- <if test="type != null and type ==3">
- from sms_day_report r
- </if>
- <include refid="MonitorDataReportJoins"/>
- where (da.ATTRIBUTE_TYPE=8 or da.ATTRIBUTE_TYPE=11 or da.ATTRIBUTE_TYPE=10)
- <if test="sceneIds != null and sceneIds.size()>0">
- and r.PARENT_SCENE_ID in
- <foreach collection="sceneIds" item="item" open="(" close=")" separator=",">
- #{item}
- </foreach>
- </if>
- <if test="tenantId != null and tenantId != '' ">
- and d.tenant_id = #{tenantId}
- </if>
- <if test="userType!=null and userType!=-999 and userType!=-9999 and programItems != null and programItems.size() > 0">
- <if test="permissonType == 5 or permissonType == 2">
- and ( d.DEPT_ORG_ID in
- <foreach collection="programItems" item="item" open="(" close=")" separator=",">
- #{item.orgId}
- </foreach>
- or
- d.COMPANY_ORG_ID in
- <foreach collection="programItems" item="item" open="(" close=")" separator=",">
- #{item.orgId}
- </foreach>
- )
- </if>
- <if test="permissonType == 4 or permissonType == 3">
- and d.DEPT_ORG_ID in
- <foreach collection="programItems" item="item" open="(" close=")" separator=",">
- #{item.orgId}
- </foreach>
- </if>
- <if test="permissonType == 1">
- and d.COMPANY_ORG_ID in
- <foreach collection="programItems" item="item" open="(" close=")" separator=",">
- #{item.orgId}
- </foreach>
- and (d.DEPT_ORG_ID is null or d.DEPT_ORG_ID =0)
- </if>
- </if>
- <if test="type != null and type ==1">
- and r.year=#{year}
- order by d.DEVICE_CODE,da.ATTRIBUTE_TYPE asc,r.`MONTH` asc
- </if>
- <if test="type != null and type ==2">
- and r.year=#{year} and r.month=#{month}
- order by d.DEVICE_CODE,da.ATTRIBUTE_TYPE asc,r.`day` asc
- </if>
- <if test="type != null and type ==3">
- and r.year=#{year} and r.month=#{month} and r.day=#{day}
- order by d.DEVICE_CODE,da.ATTRIBUTE_TYPE asc,r.`hour` asc
- </if>
- </select>
- <select id="DeviceAlarmReport" resultMap="MonitorDataChartReportMap">
- select
- a.*,DATE_ADD(#{beginDate},INTERVAL a.dateLabel ${dateType}) as "date"
- from (
- select
- ${dateType}(ad.ALARM_START_TIME) as "dateLabel"
- ,count(1) as "monitorData"
- ,count(1) as "data"
- ,d.DEVICE_CODE as "devoceCode"
- ,d.DEVICE_NAME as "deviceName"
- ,'报警次数' as "attributeName"
- from sms_alarm_details ad
- left join sms_device d on ad.DEVICE_ID=d.ID
- left join sms_scene s on s.id = d.SCENE_ID and s.`STATUS` = 1
- left join sms_scene ps on s.PARENT_SCENE_IDS LIKE concat('%,', ps.id ,',%') and ps.PARENT_SCENE_ID ='0' and ps.`STATUS` = 1
- where ad.ALARM_START_TIME < #{endDate} and ad.ALARM_START_TIME >= #{beginDate}
- <if test="sceneIds != null and sceneIds.size()>0">
- and ps.id in
- <foreach collection="sceneIds" item="item" open="(" close=")" separator=",">
- #{item}
- </foreach>
- </if>
- <if test="tenantId != null and tenantId != '' ">
- and d.tenant_id = #{tenantId}
- </if>
- <if test="userType!=null and userType!=-999 and userType!=-9999 and programItems != null and programItems.size() > 0">
- <if test="permissonType == 5 or permissonType == 2">
- and ( d.DEPT_ORG_ID in
- <foreach collection="programItems" item="item" open="(" close=")" separator=",">
- #{item.orgId}
- </foreach>
- or
- d.COMPANY_ORG_ID in
- <foreach collection="programItems" item="item" open="(" close=")" separator=",">
- #{item.orgId}
- </foreach>
- )
- </if>
- <if test="permissonType == 4 or permissonType == 3">
- and d.DEPT_ORG_ID in
- <foreach collection="programItems" item="item" open="(" close=")" separator=",">
- #{item.orgId}
- </foreach>
- </if>
- <if test="permissonType == 1">
- and d.COMPANY_ORG_ID in
- <foreach collection="programItems" item="item" open="(" close=")" separator=",">
- #{item.orgId}
- </foreach>
- and (d.DEPT_ORG_ID is null or d.DEPT_ORG_ID =0)
- </if>
- </if>
- group by d.DEVICE_CODE,d.DEVICE_NAME,${dateType}(ad.ALARM_START_TIME)
- )a
- order by devoceCode,deviceName,dateLabel
- </select>
- </mapper>
|