<?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.dongjian.dashboard.back.dao.ex.DeviceInfoMapperExt" >
<sql id= "deviceDataSelect" >
basic_floor.floor_id as floorId,
basic_floor.name as floorName,
device_info.id,
device_info.device_id,
device_info.device_name,
device_info.device_sn,
type.device_category_id categoryId,
device_info.retain_alert,
device_info.monitoring_point_name,
basic_asset_class_big.id monitoringPointCategoryId,
basic_asset_class_big.class_name as monitoringPointCategoryName,
data_provider.name as dataProviderName,
data_provider.thumbnail_base64 as dataProviderThumbnailBase64,
device_info.gateway_info_id,
data_provider_gateway_info.name as gatewayInfoName,
device_info.unit,
device_info.data_mapping
</sql>
<sql id= "deviceDataFromAndJoin" >
from device_info
left join basic_monitoring_asset on device_info.asset_id = basic_monitoring_asset.equipment_id
left join basic_space on basic_monitoring_asset.space_id = basic_space.space_id
left join basic_floor on basic_space.floor_id = basic_floor.floor_id
left join basic_building on basic_floor.building_id = basic_building.building_id
left join data_provider on data_provider.id = device_info.data_provider_id
left join data_provider_gateway_info on data_provider_gateway_info.id = device_info.gateway_info_id
left join type on device_info.type_id = type.id
left join basic_asset_class_big on basic_asset_class_big.id = basic_monitoring_asset.class_big_id
</sql>
<sql id= "deviceDataCommonWhere" >
<if test= "keyword != null and keyword != ''" >
and device_info.monitoring_point_name LIKE CONCAT('%',#{keyword},'%')
</if>
<if test= "companyIdList != null and companyIdList.size() > 0" >
and device_info.company_id in
<foreach collection= "companyIdList" item= "companyId" open= "(" separator= "," close= ")" >
#{companyId}
</foreach>
</if>
<if test= "deviceIdList != null and deviceIdList.size() > 0" >
and device_info.device_id in
<foreach collection= "deviceIdList" item= "deviceId" open= "(" separator= "," close= ")" >
#{deviceId}
</foreach>
</if>
and device_info.flag = 0 and device_info.device_id LIKE '%\_85' and basic_monitoring_asset.flag != 1 and basic_space.flag != 1 and basic_floor.flag != 1 and basic_building.flag != 1
and type.device_category_id in
<foreach collection= "categoryIdList" item= "categoryId" open= "(" separator= "," close= ")" >
#{categoryId}
</foreach>
</sql>
<sql id= "deviceOrder" >
order by device_info.id desc
</sql>
<sql id= "drrOrder" >
ORDER BY
<choose >
<when test= "sortField == 'monitoringPointCategoryName'" >
basic_asset_class_big.class_name
</when>
<when test= "sortField == 'floorName'" >
basic_floor.name
</when>
<when test= "sortField == 'uploadTimestamp'" >
drr.receive_ts
</when>
<otherwise >
drr.receive_ts
</otherwise>
</choose>
<choose >
<when test= "sortOrder == 'asc' or sortOrder == 'ASC'" >
ASC
</when>
<otherwise >
DESC
</otherwise>
</choose>
</sql>
<select id= "getDevice4AccumulateData" resultType= "com.dongjian.dashboard.back.vo.data.DeviceAccumulateData" >
select
<include refid= "deviceDataSelect" />
,drr.raw_data,
drr.receive_ts uploadTimestamp,
2 as classId
<include refid= "deviceDataFromAndJoin" />
left join device_rawdata_realtime drr on drr.device_id = device_info.device_id
<where >
<if test= "buildingId != null" >
and basic_building.building_id = #{buildingId}
</if>
<include refid= "deviceDataCommonWhere" />
</where>
<include refid= "drrOrder" />
</select>
<select id= "getDevice4AccumulateDataByGroup" resultType= "com.dongjian.dashboard.back.vo.data.DeviceAccumulateData" >
select
<include refid= "deviceDataSelect" />
,drr.raw_data,
drr.receive_ts uploadTimestamp,
2 as classId
<include refid= "deviceDataFromAndJoin" />
left join device_rawdata_realtime drr on drr.device_id = device_info.device_id
left join dashboard_device_group_relation ddgr on ddgr.device_info_id = device_info.id
<where >
<if test= "buildingId != null" >
and basic_building.building_id = #{buildingId}
</if>
and ddgr.device_group_id = #{deviceGroupId}
<include refid= "deviceDataCommonWhere" />
</where>
<include refid= "drrOrder" />
</select>
<select id= "getDevice4MeasureData" resultType= "com.dongjian.dashboard.back.vo.data.DeviceMeasureData" >
select
<include refid= "deviceDataSelect" />
,drr.raw_data,
drr.receive_ts uploadTimestamp,
3 as classId
<include refid= "deviceDataFromAndJoin" />
left join device_rawdata_realtime drr on drr.device_id = device_info.device_id
<where >
<if test= "buildingId != null" >
and basic_building.building_id = #{buildingId}
</if>
<include refid= "deviceDataCommonWhere" />
</where>
<include refid= "drrOrder" />
</select>
<select id= "getDevice4MeasureDataByGroup" resultType= "com.dongjian.dashboard.back.vo.data.DeviceMeasureData" >
select
<include refid= "deviceDataSelect" />
,drr.raw_data,
drr.receive_ts uploadTimestamp,
3 as classId
<include refid= "deviceDataFromAndJoin" />
left join device_rawdata_realtime drr on drr.device_id = device_info.device_id
left join dashboard_device_group_relation ddgr on ddgr.device_info_id = device_info.id
<where >
<if test= "buildingId != null" >
and basic_building.building_id = #{buildingId}
</if>
and ddgr.device_group_id = #{deviceGroupId}
<include refid= "deviceDataCommonWhere" />
</where>
<include refid= "drrOrder" />
</select>
<sql id= "BaStatusOrder" >
ORDER BY
<choose >
<when test= "sortField == 'monitoringPointCategoryName'" >
basic_asset_class_big.class_name
</when>
<when test= "sortField == 'floorName'" >
basic_floor.name
</when>
<when test= "sortField == 'uploadTimestamp'" >
bss.latest_ts
</when>
<otherwise >
bss.latest_ts
</otherwise>
</choose>
<choose >
<when test= "sortOrder == 'asc' or sortOrder == 'ASC'" >
ASC
</when>
<otherwise >
DESC
</otherwise>
</choose>
</sql>
<select id= "getDevice4BaStatusData" resultType= "com.dongjian.dashboard.back.vo.data.DeviceBaStatusData" >
select
<include refid= "deviceDataSelect" />
,bss.latest_ts uploadTimestamp,
bss.continuous_running_time,
bss.last_start_time,
bss.last_stop_time,
# bss.is_running runningStatus,
4 as classId
<include refid= "deviceDataFromAndJoin" />
left join ba_status_statistics bss on bss.device_info_id = device_info.id
<where >
<if test= "buildingId != null" >
and basic_building.building_id = #{buildingId}
</if>
<include refid= "deviceDataCommonWhere" />
</where>
<include refid= "BaStatusOrder" />
</select>
<select id= "getDevice4BaStatusDataByGroup" resultType= "com.dongjian.dashboard.back.vo.data.DeviceBaStatusData" >
select
<include refid= "deviceDataSelect" />
,bss.latest_ts uploadTimestamp,
bss.continuous_running_time,
bss.last_start_time,
bss.last_stop_time,
bss.is_running runningStatus,
4 as classId
<include refid= "deviceDataFromAndJoin" />
left join dashboard_device_group_relation ddgr on ddgr.device_info_id = device_info.id
left join ba_status_statistics bss on bss.device_info_id = device_info.id
<where >
<if test= "buildingId != null" >
and basic_building.building_id = #{buildingId}
</if>
and ddgr.device_group_id = #{deviceGroupId}
<include refid= "deviceDataCommonWhere" />
</where>
<include refid= "BaStatusOrder" />
</select>
<sql id= "alertHistoryOrder" >
ORDER BY
<choose >
<when test= "sortField == 'monitoringPointCategoryName'" >
basic_asset_class_big.class_name
</when>
<when test= "sortField == 'floorName'" >
basic_floor.name
</when>
<when test= "sortField == 'uploadTimestamp'" >
alert_history.receive_ts
</when>
<otherwise >
device_info.id
</otherwise>
</choose>
<choose >
<when test= "sortOrder == 'asc' or sortOrder == 'ASC'" >
ASC
</when>
<otherwise >
DESC
</otherwise>
</choose>
</sql>
<select id= "getDevice4AlarmData" resultType= "com.dongjian.dashboard.back.vo.data.DeviceAlarmData" >
select
<include refid= "deviceDataSelect" />
,device_info.alarm_level alertLevel,
alert_history.receive_ts uploadTimestamp,
alert_history.confirm_status,
alert_history.handle_status,
alert_history.id alertHistoryId,
1 as classId,
basic_monitoring_asset.`symbol` assetSymbol
from
alert_history
left join device_info on alert_history.device_id = device_info.device_id
left join basic_monitoring_asset on device_info.asset_id = basic_monitoring_asset.equipment_id
left join basic_space on basic_monitoring_asset.space_id = basic_space.space_id
left join basic_floor on basic_space.floor_id = basic_floor.floor_id
left join basic_building on basic_floor.building_id = basic_building.building_id
left join data_provider on data_provider.id = device_info.data_provider_id
left join data_provider_gateway_info on data_provider_gateway_info.id = device_info.gateway_info_id
left join type on device_info.type_id = type.id
left join basic_asset_class_big on basic_asset_class_big.id = basic_monitoring_asset.class_big_id
<where >
and device_info.flag = 0 and basic_monitoring_asset.flag != 1
and basic_space.flag != 1 and basic_floor.flag != 1 and basic_building.flag != 1
<if test= "buildingId != null" >
and basic_building.building_id = #{buildingId}
</if>
<include refid= "deviceDataCommonWhere" />
<choose >
<when test= "searchType == 1" >
AND (
(alert_history.handle_status != 3 AND alert_history.handle_status != 4)
OR (alert_history.handle_status = 4 AND alert_history.retain_alert = 1)
)
</when>
<when test= "searchType == 2" >
</when>
<when test= "searchType == 3" >
AND alert_history.confirm_status = 0
</when>
<otherwise >
</otherwise>
</choose>
</where>
<include refid= "alertHistoryOrder" />
</select>
<select id= "getDevice4AlarmDataByGroup" resultType= "com.dongjian.dashboard.back.vo.data.DeviceAlarmData" >
select
<include refid= "deviceDataSelect" />
,device_info.alarm_level alertLevel,
alert_history.receive_ts uploadTimestamp,
alert_history.confirm_status,
alert_history.handle_status,
alert_history.id alertHistoryId,
1 as classId,
basic_monitoring_asset.`symbol` assetSymbol
from
alert_history
left join device_info on alert_history.device_id = device_info.device_id
left join basic_monitoring_asset on device_info.asset_id = basic_monitoring_asset.equipment_id
left join basic_space on basic_monitoring_asset.space_id = basic_space.space_id
left join basic_floor on basic_space.floor_id = basic_floor.floor_id
left join basic_building on basic_floor.building_id = basic_building.building_id
left join data_provider on data_provider.id = device_info.data_provider_id
left join data_provider_gateway_info on data_provider_gateway_info.id = device_info.gateway_info_id
left join type on device_info.type_id = type.id
left join basic_asset_class_big on basic_asset_class_big.id = basic_monitoring_asset.class_big_id
left join dashboard_device_group_relation ddgr on ddgr.device_info_id = device_info.id
<where >
and device_info.flag = 0 and basic_monitoring_asset.flag != 1
and basic_space.flag != 1 and basic_floor.flag != 1 and basic_building.flag != 1
<if test= "buildingId != null" >
and basic_building.building_id = #{buildingId}
</if>
and ddgr.device_group_id = #{deviceGroupId}
<include refid= "deviceDataCommonWhere" />
<choose >
<when test= "searchType == 1" >
AND (
(alert_history.handle_status != 3 AND alert_history.handle_status != 4)
OR (alert_history.handle_status = 4 AND alert_history.retain_alert = 1)
)
</when>
<when test= "searchType == 2" >
</when>
<when test= "searchType == 3" >
AND alert_history.confirm_status = 0
</when>
<otherwise >
</otherwise>
</choose>
</where>
<include refid= "alertHistoryOrder" />
</select>
<!-- 公共字段 -->
<sql id= "commonDeviceSelectFields" >
device_info.id,
device_info.company_id,
device_info.device_name,
device_info.device_id,
device_info.device_sn,
type.device_category_id categoryId,
device_info.flag,
type.name as typeName,
basic_building.building_id,
basic_building.name as buildingName,
basic_floor.floor_id as floorId,
basic_floor.name as floorName,
basic_space.space_id as spaceId,
basic_space.name as spaceName,
basic_project.id as projectId,
basic_project.project_name,
basic_monitoring_asset.equipment_id as assetId,
basic_monitoring_asset.symbol as assetSymbol,
device_info.remark,
device_info.monitoring_point_name,
basic_asset_class_big.id monitoringPointCategoryId,
basic_asset_class_big.class_name as monitoringPointCategoryName,
device_info.data_provider_id,
data_provider.name as dataProviderName,
device_info.gateway_info_id,
data_provider_gateway_info.name as gatewayInfoName
</sql>
<!-- 公共 JOIN -->
<sql id= "commonDeviceJoins" >
from device_info
left join basic_monitoring_asset on device_info.asset_id = basic_monitoring_asset.equipment_id
left join basic_space on basic_monitoring_asset.space_id = basic_space.space_id
left join basic_floor on basic_space.floor_id = basic_floor.floor_id
left join basic_building on basic_floor.building_id = basic_building.building_id
left join basic_asset_class_big on basic_asset_class_big.id = basic_monitoring_asset.class_big_id
left join data_provider on data_provider.id = device_info.data_provider_id
left join data_provider_gateway_info on data_provider_gateway_info.id = device_info.gateway_info_id
left join type on device_info.type_id = type.id
left join basic_project on device_info.project_id = basic_project.id
</sql>
<select id= "getListPage" resultType= "com.dongjian.dashboard.back.vo.device.DeviceVO" >
select
<include refid= "commonDeviceSelectFields" />
<include refid= "commonDeviceJoins" />
<where >
<if test= "buildingId != null" >
and basic_building.building_id = #{buildingId}
</if>
<if test= "monitoringPointName != null and monitoringPointName != '' " >
and device_info.monitoring_point_name LIKE CONCAT('%',#{keyword},'%')
</if>
<if test= "companyIdList != null and companyIdList.size() > 0" >
and device_info.company_id in
<foreach collection= "companyIdList" item= "companyId" open= "(" separator= "," close= ")" >
#{companyId}
</foreach>
</if>
and device_info.flag = 0 and device_info.device_id LIKE '%\_85' and basic_monitoring_asset.flag != 1 and basic_space.flag != 1 and basic_floor.flag != 1 and basic_building.flag != 1
and type.device_category_id in
<foreach collection= "categoryIdList" item= "categoryId" open= "(" separator= "," close= ")" >
#{categoryId}
</foreach>
</where>
<include refid= "deviceOrder" />
</select>
<select id= "selectOne" resultType= "com.dongjian.dashboard.back.vo.device.DeviceVO" >
select
<include refid= "commonDeviceSelectFields" />
<include refid= "commonDeviceJoins" />
where device_info.id = #{deviceInfoId}
</select>
</mapper>