| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317 |
- <?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.xunmei.iot.mapper.IotCommonSensorMapper">
- <select id="selectPageData" resultType="com.xunmei.iot.vo.sensor.SensorPageVo">
- <choose>
- <when test=" request.deviceTypeList!= null and request.deviceTypeList.size() > 0 ">
- <choose>
- <when test=" request.inputTypeList!= null and request.inputTypeList.size() > 0">
- select c.* from
- ( select s.id,ds.id as device_status_id, s.org_id, s.org_name,s.org_path, s.device_name,
- s.device_type, ds.info as info,s.device_code, ds.state_update_time as update_time,ds.state
- from iot_device_info s left join iot_device_status ds on s.id=ds.device_id
- where s.deleted=0 and s.device_type in
- <foreach collection="request.deviceTypeList" index="index" item="item" open="(" separator="," close=")">
- #{item}
- </foreach>
- union all
- select s.id,ds.id as device_status_id, s.org_id, s.org_name,s.org_path, s.defence_area_name as device_name,
- s.sensor_type as device_type, ds.info as info,s.alarm_host_code as device_code,ds.state_update_time as update_time,ds.state
- from iot_alarm_defence_area s left join iot_device_status ds on s.id=ds.device_id
- where s.deleted=0 and s.sensor_type in
- <foreach collection="request.inputTypeList" index="index" item="item" open="(" separator=","
- close=")">
- #{item}
- </foreach>) c where 1=1
- <if test="request.orgId!= null">
- and c.org_id=#{request.orgId}
- </if>
- <if test="request.orgPath!= null">
- and c.org_path like CONCAT(#{request.orgPath}, '%')
- </if>
- <if test="request.deviceName != null and request.deviceName!= ''">
- and c.device_name like CONCAT('%',#{request.deviceName},'%')
- </if>
- <if test="request.state!= null">
- and c.state = #{request.state}
- </if>
- <if test="request.startTime!= null">
- and c.update_time >=#{request.startTime}
- </if>
- <if test="request.endTime!= null">
- and c.update_time <![CDATA[<=]]> #{request.endTime}
- </if>
- order by c.update_time desc
- </when>
- <otherwise>
- select s.id,ds.id as device_status_id, s.org_id, s.org_name,s.org_path, s.device_name,
- s.device_type, ds.info as info,s.device_code, ds.state_update_time as update_time,ds.state
- from iot_device_info s left join iot_device_status ds on s.id=ds.device_id
- where s.deleted=0 and s.device_type in
- <foreach collection="request.deviceTypeList" index="index" item="item" open="(" separator="," close=")">
- #{item}
- </foreach>
- <if test="request.orgId!= null">
- and s.org_id=#{request.orgId}
- </if>
- <if test="request.orgPath!= null">
- and s.org_path like CONCAT(#{request.orgPath}, '%')
- </if>
- <if test="request.deviceName != null and request.deviceName!= ''">
- and s.device_name like CONCAT('%',#{request.deviceName},'%')
- </if>
- <if test="request.state!= null">
- and ds.state = #{request.state}
- </if>
- <if test="request.startTime!= null">
- and ds.state_update_time >=#{request.startTime}
- </if>
- <if test="request.endTime!= null">
- and ds.state_update_time <![CDATA[<=]]> #{request.endTime}
- </if>
- order by ds.state_update_time desc
- </otherwise>
- </choose>
- </when>
- <otherwise>
- select s.id,ds.id as device_status_id, s.org_id, s.org_name,s.org_path, s.defence_area_name as device_name,
- s.sensor_type as device_type, ds.info as info,s.alarm_host_code as device_code, ds.state_update_time as update_time,ds.state
- from iot_alarm_defence_area s left join iot_device_status ds on s.id=ds.device_id
- where s.deleted=0 and s.sensor_type in
- <foreach collection="request.inputTypeList" index="index" item="item" open="(" separator="," close=")">
- #{item}
- </foreach>
- <if test="request.orgId!= null">
- and s.org_id=#{request.orgId}
- </if>
- <if test="request.orgPath!= null">
- and s.org_path like CONCAT(#{request.orgPath}, '%')
- </if>
- <if test="request.deviceName != null and request.deviceName!= ''">
- and s.defence_area_name like CONCAT('%',#{request.deviceName},'%')
- </if>
- <if test="request.state!= null">
- and ds.state = #{request.state}
- </if>
- <if test="request.startTime!= null">
- and ds.state_update_time >=#{request.startTime}
- </if>
- <if test="request.endTime!= null">
- and ds.state_update_time <![CDATA[<=]]> #{request.endTime}
- </if>
- order by ds.state_update_time desc
- </otherwise>
- </choose>
- </select>
- <select id="selectAppPageData" resultType="com.xunmei.iot.vo.sensor.SensorAppPageVo">
- select s.id, s.org_id, s.org_name, s.device_name, ds.device_type, ds.info as info, ds.state_update_time,ds.state
- from iot_device_info s left join iot_device_status ds on s.id=ds.device_id
- where s.deleted=0
- <if test="request.orgId!= null">
- and s.org_id=#{request.orgId}
- </if>
- <if test="request.orgPath!= null">
- and s.org_path like CONCAT(#{request.orgPath}, '%')
- </if>
- <if test="request.state!= null">
- and ds.state = #{request.state}
- </if>
- <if test="request.deviceType!= null and request.deviceType!= ''">
- and s.device_product = #{request.deviceType}
- </if>
- <if test="request.defenceAreaType != null and request.defenceAreaType.size()>0">
- UNION ALL
- SELECT a.id,
- a.org_id,
- a.org_name,
- a.defence_area_name,
- a.sensor_type,
- a.state_text as info,
- a.state_update_time,
- if(a.state='alarm',1,0) as state
- FROM `iot_alarm_defence_area` a
- where a.deleted=0
- <if test="request.orgId!= null">
- and a.org_id=#{request.orgId}
- </if>
- <if test="request.orgPath!= null">
- and a.org_path like CONCAT(#{request.orgPath}, '%')
- </if>
- <if test="request.state!= null">
- and a.state = #{request.state}
- </if>
- and a.sensor_type in
- <foreach collection="request.defenceAreaType" index="index" item="item" open="(" separator="," close=")">
- #{item}
- </foreach>
- </if>
- </select>
- <select id="stateStatistic" resultType="com.xunmei.iot.vo.sensor.SensorAppStateVo">
- SELECT sum(state=0) as normal,
- sum(state=1) as alarm
- from iot_sensor s
- where s.deleted=0
- <if test="request.orgId!= null">
- and s.org_id=#{request.orgId}
- </if>
- <if test="request.orgPath!= null">
- and s.org_path like CONCAT(#{request.orgPath}, '%')
- </if>
- <!-- <if test="request.deviceType!= null and request.deviceType!= ''">-->
- <!-- and s.device_type = #{request.deviceType}-->
- <!-- </if>-->
- </select>
- <select id="selectSensorLogDataPage" resultType="com.xunmei.iot.vo.sensor.SensorPageVo">
- select s.id, org_id, org_name, device_name, infos as info,device_code,state_update_time as updateTime from
- iot_sensor_log s
- <where>
- <if test="request.orgId!= null">
- and s.org_id=#{request.orgId}
- </if>
- <if test="request.orgPath!= null">
- and s.org_path like CONCAT(#{request.orgPath}, '%')
- </if>
- <if test="request.deviceName != null and request.deviceName!= ''">
- and s.device_name like CONCAT('%',#{request.deviceName},'%')
- </if>
- <if test="request.deviceCode != null and request.deviceCode!= ''">
- and s.device_code =#{request.deviceCode}
- </if>
- <if test="request.startTime!= null">
- and s.state_update_time >=#{request.startTime}
- </if>
- <if test="request.endTime!= null">
- and s.state_update_time <![CDATA[<=]]> #{request.endTime}
- </if>
- </where>
- order by s.create_time desc
- </select>
- <select id="selectByIds" resultType="com.xunmei.common.core.domain.iot.domain.IotSensor">
- SELECT
- org_id,
- org_path,
- b.short_name as org_name,
- device_name as deviceName,
- infos AS info,
- CONCAT(org_id,'-',device_code) as deviceCode
- FROM
- iot_sensor a
- LEFT JOIN sys_org b ON a.org_id = b.id
- where a.deleted=0 and a.device_code in
- <foreach collection="deviceIds" index="index" item="item" open="(" separator="," close=")">
- #{item}
- </foreach>
- </select>
- <select id="selectListData" resultType="com.xunmei.iot.vo.sensor.SensorExportVo">
- <choose>
- <when test=" request.deviceTypeList!= null and request.deviceTypeList.size() > 0 ">
- <choose>
- <when test=" request.inputTypeList!= null and request.inputTypeList.size() > 0">
- select c.* from
- ( select s.org_id,s.org_path,s.org_name,s.device_name, s.device_type, ds.info as info,ds.state_update_time as update_time,ds.state
- from iot_device_info s left join iot_device_status ds on s.id=ds.device_id
- where s.deleted=0 and s.device_type in
- <foreach collection="request.deviceTypeList" index="index" item="item" open="(" separator="," close=")">
- #{item}
- </foreach>
- union all
- select s.org_id,s.org_path,s.org_name,s.defence_area_name as device_name,s.sensor_type as device_type, ds.info as info,ds.state_update_time as update_time,ds.state
- from iot_alarm_defence_area s left join iot_device_status ds on s.id=ds.device_id
- where s.deleted=0 and s.sensor_type in
- <foreach collection="request.inputTypeList" index="index" item="item" open="(" separator="," close=")">
- #{item}
- </foreach> ) c where 1=1
- <if test="request.orgId!= null">
- and c.org_id=#{request.orgId}
- </if>
- <if test="request.orgPath!= null">
- and c.org_path like CONCAT(#{request.orgPath}, '%')
- </if>
- <if test="request.deviceName != null and request.deviceName!= ''">
- and c.device_name like CONCAT('%',#{request.deviceName},'%')
- </if>
- <if test="request.state!= null">
- and c.state = #{request.state}
- </if>
- <if test="request.startTime!= null">
- and c.update_time >=#{request.startTime}
- </if>
- <if test="request.endTime!= null">
- and c.update_time <![CDATA[<=]]> #{request.endTime}
- </if>
- order by c.update_time desc
- </when>
- <otherwise>
- select s.org_name,s.device_name, s.device_type, ds.info as info,ds.state_update_time as update_time,ds.state
- from iot_device_info s left join iot_device_status ds on s.id=ds.device_id
- where s.deleted=0 and s.device_type in
- <foreach collection="request.deviceTypeList" index="index" item="item" open="(" separator="," close=")">
- #{item}
- </foreach>
- <if test="request.orgId!= null">
- and s.org_id=#{request.orgId}
- </if>
- <if test="request.orgPath!= null">
- and s.org_path like CONCAT(#{request.orgPath}, '%')
- </if>
- <if test="request.deviceName != null and request.deviceName!= ''">
- and s.device_name like CONCAT('%',#{request.deviceName},'%')
- </if>
- <if test="request.state!= null">
- and ds.state = #{request.state}
- </if>
- <if test="request.startTime!= null">
- and ds.state_update_time >=#{request.startTime}
- </if>
- <if test="request.endTime!= null">
- and ds.state_update_time <![CDATA[<=]]> #{request.endTime}
- </if>
- order by ds.state_update_time desc
- </otherwise>
- </choose>
- </when>
- <otherwise>
- select s.org_name,s.defence_area_name as device_name,
- s.sensor_type as device_type, ds.info as info,ds.state_update_time as update_time,ds.state
- from iot_alarm_defence_area s left join iot_device_status ds on s.id=ds.device_id
- where s.deleted=0 and s.sensor_type in
- <foreach collection="request.inputTypeList" index="index" item="item" open="(" separator="," close=")">
- #{item}
- </foreach>
- <if test="request.orgId!= null">
- and s.org_id=#{request.orgId}
- </if>
- <if test="request.orgPath!= null">
- and s.org_path like CONCAT(#{request.orgPath}, '%')
- </if>
- <if test="request.deviceName != null and request.deviceName!= ''">
- and s.defence_area_name like CONCAT('%',#{request.deviceName},'%')
- </if>
- <if test="request.state!= null">
- and ds.state = #{request.state}
- </if>
- <if test="request.startTime!= null">
- and ds.state_update_time >=#{request.startTime}
- </if>
- <if test="request.endTime!= null">
- and ds.state_update_time <![CDATA[<=]]> #{request.endTime}
- </if>
- order by ds.state_update_time desc
- </otherwise>
- </choose>
- </select>
- <select id="selectListSensor" resultType="com.xunmei.common.core.domain.iot.domain.IotSensor">
- SELECT id,org_id,org_path,device_name,device_type,device_code,ifnull(a.state,0) as state
- FROM
- iot_sensor a
- where a.org_path like concat(#{orgPath},'%') and a.deleted=0
- </select>
- </mapper>
|