|
@@ -9,6 +9,7 @@
|
|
|
</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>
|
|
@@ -20,6 +21,11 @@
|
|
|
<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">
|
|
@@ -31,18 +37,16 @@
|
|
|
<if test="type != null and type ==3">
|
|
|
r.`HOUR` as "dateLabel",
|
|
|
</if>
|
|
|
- cast(ifnull(r.AVG_VALUE,'') as char)+""+ifnull(da.UNIT,'') as "monitorData"
|
|
|
+ cast(ifnull(r.AVG_VALUE,'') as char)+ifnull(da.UNIT,'') as "monitorData"
|
|
|
,r.AVG_VALUE as "data"
|
|
|
,r.COLLECT_DATE as "date"
|
|
|
|
|
|
- ,r.DEVICE_ID as "deviceId"
|
|
|
- ,r.DEVICE_CODE as "devoceCode"
|
|
|
- ,r.DEVICE_NAME as "deviceName"
|
|
|
+ ,d.DEVICE_CODE as "devoceCode"
|
|
|
+ ,d.DEVICE_NAME as "deviceName"
|
|
|
,r.ATTRIBUTE_NAME as "attributeName"
|
|
|
|
|
|
from ${tableName} r
|
|
|
- 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
|
|
|
+ <include refid="MonitorDataReportJoins"/>
|
|
|
where dp.IS_CHART = 1 and r.PARENT_SCENE_ID=#{sceneId}
|
|
|
<if test="year != null">
|
|
|
and r.year=#{year}
|
|
@@ -53,20 +57,290 @@
|
|
|
<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.LATEST_VALUE -r2.LATEST_VALUE,'') as char)+ifnull(da.UNIT,'') as "monitorData"
|
|
|
+ ,ifnull((r.LATEST_VALUE -r2.LATEST_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"/>
|
|
|
+
|
|
|
<if test="type != null and type ==1">
|
|
|
- order by r.`MONTH` asc
|
|
|
+ left join sms_year_report r2 on r.DEVICE_ID=r2.DEVICE_ID and r.ATTRIBUTE_ID=r2.ATTRIBUTE_ID
|
|
|
+ and r.year=r2.`YEAR`and r.`MONTH`-1=r2.`MONTH`
|
|
|
</if>
|
|
|
<if test="type != null and type ==2">
|
|
|
- order by r.`DAY` asc
|
|
|
+ left join sms_month_report r2 on r.DEVICE_ID=r2.DEVICE_ID and r.ATTRIBUTE_ID=r2.ATTRIBUTE_ID
|
|
|
+ and r.year=r2.`YEAR`and r.`MONTH`=r2.`MONTH`and r.`DAY`-1=r2.`DAY`
|
|
|
</if>
|
|
|
<if test="type != null and type ==3">
|
|
|
- order by r.`HOUR` asc
|
|
|
+ left join sms_day_report r2 on r.DEVICE_ID=r2.DEVICE_ID and r.ATTRIBUTE_ID=r2.ATTRIBUTE_ID
|
|
|
+ and r.year=r2.`YEAR`and r.`MONTH`=r2.`MONTH` and r.`DAY`=r2.`DAY` and r.`HOUR`-1 =r2.`HOUR`
|
|
|
+ </if>
|
|
|
+
|
|
|
+ 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="updatedd" resultType="java.lang.Integer">
|
|
|
- select 1
|
|
|
-</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>
|