123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677 |
- <?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.SceneMapper">
- <resultMap type="SceneEntity" id="SceneResult">
- <result property="id" column="id"/>
- <result property="tenantId" column="tenant_id"/>
- <result property="parentSceneId" column="parent_scene_id"/>
- <result property="parentSceneIds" column="parent_scene_ids"/>
- <result property="sceneName" column="scene_name"/>
- <result property="companyOrgId" column="company_org_id"/>
- <result property="deptOrgId" column="dept_org_id"/>
- <result property="sceneTypeId" column="scene_type_id"/>
- <result property="enableState" column="enable_state"/>
- <result property="runTime" column="run_time"/>
- <result property="address" column="address"/>
- <result property="pointX" column="point_x"/>
- <result property="pointY" column="point_y"/>
- <result property="remark" column="remark"/>
- <result property="status" column="status"/>
- <result property="dateCreate" column="date_create"/>
- <result property="createBy" column="create_by"/>
- <result property="dateUpdate" column="date_update"/>
- <result property="updateBy" column="update_by"/>
- </resultMap>
- <!-- 实体栏位 -->
- <sql id="sceneColumns">
- a.id as "id" ,
- a.tenant_id as "tenantId" ,
- a.parent_scene_id as "parentSceneId" ,
- a.parent_scene_ids as "parentSceneIds" ,
- a.scene_name as "sceneName" ,
- a.company_org_id as "companyOrgId" ,
- a.dept_org_id as "deptOrgId" ,
- a.scene_type_id as "sceneTypeId" ,
- a.enable_state as "enableState" ,
- a.run_time as "runTime" ,
- a.address as "address" ,
- a.point_x as "pointX" ,
- a.point_y as "pointY" ,
- a.remark as "remark" ,
- a.status as "status" ,
- a.date_create as "dateCreate" ,
- a.create_by as "createBy" ,
- a.date_update as "dateUpdate" ,
- a.update_by as "updateBy",
- s.scene_type_name as "sceneTypeName"
- </sql>
- <sql id="deviceJoins">
- left join sms_scene_type s on s.id =a.scene_type_id and s.status=1
- </sql>
- <!-- 根据主键获取实体 -->
- <select id="findSceneById" resultType="com.huaxu.entity.SceneEntity">
- SELECT
- <include refid="sceneColumns"/>
- FROM sms_scene a
- <include refid="deviceJoins"/>
- WHERE a.id = #{id} and a.status=1
- </select>
- <!-- 根据获取实体List -->
- <select id="findList" resultType="com.huaxu.entity.SceneEntity">
- SELECT
- <include refid="sceneColumns"/>
- FROM sms_scene a
- <include refid="deviceJoins"/>
- <where>
- a.status=1
- <if test="scene.companyOrgId!=null and scene.deptOrgId!=null">
- and a.DEPT_ORG_ID = #{scene.deptOrgId} and a.COMPANY_ORG_ID = #{scene.companyOrgId}
- </if>
- <if test="scene.companyOrgId!=null and scene.deptOrgId == null">
- and a.DEPT_ORG_ID is null and a.COMPANY_ORG_ID = #{scene.companyOrgId}
- </if>
- <if test="scene.tenantId != null and scene.tenantId != ''">and a.tenant_id = #{scene.tenantId}</if>
- <if test="scene.parentSceneId != null ">and a.parent_scene_id = #{scene.parentSceneId}</if>
- <if test="scene.sceneName != null and scene.sceneName != ''">
- and a.scene_name LIKE concat('%',#{scene.sceneName},'%')
- </if>
- <if test="scene.sceneTypeId != null ">and a.scene_type_id = #{scene.sceneTypeId}</if>
- <if test="scene.userType!=null and scene.userType!=-999 and scene.userType!=-9999 and scene.programItems != null and scene.programItems.size() > 0">
- <if test="scene.permissonType == 5 or scene.permissonType == 2">
- and ( a.DEPT_ORG_ID in
- <foreach collection="scene.programItems" item="item" open="(" close=")" separator=",">
- #{item.orgId}
- </foreach>
- or
- a.COMPANY_ORG_ID in
- <foreach collection="scene.programItems" item="item" open="(" close=")" separator=",">
- #{item.orgId}
- </foreach>
- )
- </if>
- <if test="scene.permissonType == 4 or scene.permissonType == 3">
- and a.DEPT_ORG_ID in
- <foreach collection="scene.programItems" item="item" open="(" close=")" separator=",">
- #{item.orgId}
- </foreach>
- </if>
- <if test="scene.permissonType == 1">
- and a.COMPANY_ORG_ID in
- <foreach collection="scene.programItems" item="item" open="(" close=")" separator=",">
- #{item.orgId}
- </foreach>
- and (a.DEPT_ORG_ID is null or a.DEPT_ORG_ID =0)
- </if>
- </if>
- </where>
- order by a.date_create
- </select>
- <!-- 根据主键获取租户菜单 -->
- <select id="findBySceneTypeIds" resultType="com.huaxu.entity.SceneEntity">
- select a.id
- FROM sms_scene a
- <include refid="deviceJoins"/>
- WHERE a.scene_type_id in
- <foreach collection = "Ids" item = "dramaId" open = "(" close = ")" separator = "," >
- #{dramaId}
- </foreach>
- </select>
- <!-- 根据主键获取租户菜单 -->
- <select id="findByParentSceneIds" resultType="com.huaxu.entity.SceneEntity">
- select a.id
- FROM sms_scene a
- <include refid="deviceJoins"/>
- WHERE a.status=1 and a.parent_scene_id in
- <foreach collection = "Ids" item = "dramaId" open = "(" close = ")" separator = "," >
- #{dramaId}
- </foreach>
- </select>
- <select id="findByParentIdsLike" resultType="com.huaxu.entity.SceneEntity">
- SELECT
- <include refid="sceneColumns"/>
- FROM sms_scene a
- <include refid="deviceJoins"/>
- <where>
- a.status=1
- <if test="scene.companyOrgId != null ">and a.COMPANY_ORG_ID=#{scene.companyOrgId}</if>
- <if test="scene.tenantId != null and scene.tenantId != ''">and a.tenant_id = #{scene.tenantId}</if>
- <if test="scene.parentSceneIds != null ">and a.parent_scene_ids LIKE #{scene.parentSceneIds}</if>
- <if test="scene.userType!=null and scene.userType!=-999 and scene.userType!=-9999 and scene.programItems != null and scene.programItems.size() > 0">
- <if test="scene.permissonType == 5 or scene.permissonType == 2">
- and ( a.DEPT_ORG_ID in
- <foreach collection="scene.programItems" item="item" open="(" close=")" separator=",">
- #{item.orgId}
- </foreach>
- or
- a.COMPANY_ORG_ID in
- <foreach collection="scene.programItems" item="item" open="(" close=")" separator=",">
- #{item.orgId}
- </foreach>
- )
- </if>
- <if test="scene.permissonType == 4 or scene.permissonType == 3">
- and a.DEPT_ORG_ID in
- <foreach collection="scene.programItems" item="item" open="(" close=")" separator=",">
- #{item.orgId}
- </foreach>
- </if>
- <if test="scene.permissonType == 1">
- and a.COMPANY_ORG_ID in
- <foreach collection="scene.programItems" item="item" open="(" close=")" separator=",">
- #{item.orgId}
- </foreach>
- and (a.DEPT_ORG_ID is null or a.DEPT_ORG_ID =0)
- </if>
- </if>
- </where>
- </select>
- <!-- 根据获取实体 page -->
- <select id="findPage" resultType="com.huaxu.entity.SceneEntity">
- SELECT
- <include refid="sceneColumns"/>
- FROM sms_scene a
- <include refid="deviceJoins"/>
- <where>
- a.status=1 and a.parent_scene_id=0
- <if test="scene.companyOrgId!=null">
- and a.COMPANY_ORG_ID = #{scene.companyOrgId}
- </if>
- <if test="scene.deptOrgId != null">
- and a.DEPT_ORG_ID = #{scene.deptOrgId}
- </if>
- <if test="scene.tenantId != null and scene.tenantId != ''">and a.tenant_id = #{scene.tenantId}</if>
- <if test="scene.parentSceneId != null ">and a.parent_scene_id = #{scene.parentSceneId}</if>
- <if test="scene.sceneName != null and scene.sceneName != ''">
- and a.scene_name LIKE concat('%',#{scene.sceneName},'%')
- </if>
- <if test="scene.sceneTypeId != null ">and a.scene_type_id = #{scene.sceneTypeId}</if>
- <if test="scene.userType!=null and scene.userType!=-999 and scene.userType!=-9999 and scene.programItems != null and scene.programItems.size() > 0">
- <if test="scene.permissonType == 5 or scene.permissonType == 2">
- and ( a.DEPT_ORG_ID in
- <foreach collection="scene.programItems" item="item" open="(" close=")" separator=",">
- #{item.orgId}
- </foreach>
- or
- a.COMPANY_ORG_ID in
- <foreach collection="scene.programItems" item="item" open="(" close=")" separator=",">
- #{item.orgId}
- </foreach>
- )
- </if>
- <if test="scene.permissonType == 4 or scene.permissonType == 3">
- and a.DEPT_ORG_ID in
- <foreach collection="scene.programItems" item="item" open="(" close=")" separator=",">
- #{item.orgId}
- </foreach>
- </if>
- <if test="scene.permissonType == 1">
- and a.COMPANY_ORG_ID in
- <foreach collection="scene.programItems" item="item" open="(" close=")" separator=",">
- #{item.orgId}
- </foreach>
- and (a.DEPT_ORG_ID is null or a.DEPT_ORG_ID =0)
- </if>
- </if>
- </where>
- order by a.date_create desc
- </select>
- <!--一级场景查询-->
- <select id="selectByTypeName" resultType="com.huaxu.entity.SceneEntity">
- SELECT
- <include refid="sceneColumns"/>
- FROM sms_scene a
- <include refid="deviceJoins"/>
- <where>
- a.parent_scene_id=0 and a.status=1 and a.enable_state=1
- <if test="scene.sceneTypeName == null ">
- and (s.scene_type_name='水源' or s.scene_type_name='水厂')
- </if>
- <if test="scene.sceneTypeName != null ">
- and s.scene_type_name=#{scene.sceneTypeName}
- </if>
- <if test="scene.companyOrgId != null ">and a.COMPANY_ORG_ID=#{scene.companyOrgId}</if>
- <if test="scene.tenantId != null and scene.tenantId != ''">and a.tenant_id = #{scene.tenantId}</if>
- <if test="scene.userType!=null and scene.userType!=-999 and scene.userType!=-9999 and scene.programItems != null and scene.programItems.size() > 0">
- <if test="scene.permissonType == 5 or scene.permissonType == 2">
- and ( a.DEPT_ORG_ID in
- <foreach collection="scene.programItems" item="item" open="(" close=")" separator=",">
- #{item.orgId}
- </foreach>
- or
- a.COMPANY_ORG_ID in
- <foreach collection="scene.programItems" item="item" open="(" close=")" separator=",">
- #{item.orgId}
- </foreach>
- )
- </if>
- <if test="scene.permissonType == 4 or scene.permissonType == 3">
- and a.DEPT_ORG_ID in
- <foreach collection="scene.programItems" item="item" open="(" close=")" separator=",">
- #{item.orgId}
- </foreach>
- </if>
- <if test="scene.permissonType == 1">
- and a.COMPANY_ORG_ID in
- <foreach collection="scene.programItems" item="item" open="(" close=")" separator=",">
- #{item.orgId}
- </foreach>
- and (a.DEPT_ORG_ID is null or a.DEPT_ORG_ID =0)
- </if>
- </if>
- </where>
- order by a.date_create
- </select>
- <!--根据一级场景查询所有场景信息-->
- <select id="findByParentId" resultType="com.huaxu.entity.SceneEntity">
- SELECT
- <include refid="sceneColumns"/>
- FROM sms_scene a
- <include refid="deviceJoins"/>
- <where>
- a.status=1
- <if test="scene.parentSceneIds != null ">and a.parent_scene_ids LIKE #{scene.parentSceneIds}</if>
- <if test="scene.tenantId != null and scene.tenantId != ''">and a.tenant_id = #{scene.tenantId}</if>
- <if test="scene.userType!=null and scene.userType!=-999 and scene.userType!=-9999 and scene.programItems != null and scene.programItems.size() > 0">
- <if test="scene.permissonType == 5 or scene.permissonType == 2">
- and ( a.DEPT_ORG_ID in
- <foreach collection="scene.programItems" item="item" open="(" close=")" separator=",">
- #{item.orgId}
- </foreach>
- or
- a.COMPANY_ORG_ID in
- <foreach collection="scene.programItems" item="item" open="(" close=")" separator=",">
- #{item.orgId}
- </foreach>
- )
- </if>
- <if test="scene.permissonType == 4 or scene.permissonType == 3">
- and a.DEPT_ORG_ID in
- <foreach collection="scene.programItems" item="item" open="(" close=")" separator=",">
- #{item.orgId}
- </foreach>
- </if>
- <if test="scene.permissonType == 1">
- and a.COMPANY_ORG_ID in
- <foreach collection="scene.programItems" item="item" open="(" close=")" separator=",">
- #{item.orgId}
- </foreach>
- and (a.DEPT_ORG_ID is null or a.DEPT_ORG_ID =0)
- </if>
- </if>
- </where>
- order by a.date_create
- </select>
- <!--根据场景id查询一级场景信息-->
- <select id="findParentSceneById" resultType="com.huaxu.entity.SceneEntity">
- select t1.scene_name as "sceneName",t2.id as "parentSceneId",t2.scene_name as "parentSceneName"
- from sms_scene t1
- left join sms_scene t2 on substring_index(substring_index(t1.parent_scene_ids, ',', 2), ',', -1)=t2.id
- where t1.id=#{id}
- </select>
- <!--根据用户权限统计一级场景个数-->
- <select id="findSceneAmount" resultType="map">
- select a.sceneTypeName,amount,newAmount from
- (
- select count(a.ID) amount,b.SCENE_TYPE_NAME sceneTypeName
- from sms_scene a INNER JOIN sms_scene_type b on a.SCENE_TYPE_ID=b.ID
- <where>
- a.PARENT_SCENE_ID=0
- and a.STATUS=1
- <if test="scene.tenantId != null and scene.tenantId != ''">
- and a.tenant_id = #{scene.tenantId}
- </if>
- <if test="scene.userType!=null and scene.userType!=-999 and scene.userType!=-9999 and scene.programItems != null and scene.programItems.size() > 0">
- <if test="scene.permissonType == 5 or scene.permissonType == 2">
- and ( a.DEPT_ORG_ID in
- <foreach collection="scene.programItems" item="item" open="(" close=")" separator=",">
- #{item.orgId}
- </foreach>
- or
- a.COMPANY_ORG_ID in
- <foreach collection="scene.programItems" item="item" open="(" close=")" separator=",">
- #{item.orgId}
- </foreach>
- )
- </if>
- <if test="scene.permissonType == 4 or scene.permissonType == 3">
- and a.DEPT_ORG_ID in
- <foreach collection="scene.programItems" item="item" open="(" close=")" separator=",">
- #{item.orgId}
- </foreach>
- </if>
- <if test="scene.permissonType == 1">
- and a.COMPANY_ORG_ID in
- <foreach collection="scene.programItems" item="item" open="(" close=")" separator=",">
- #{item.orgId}
- </foreach>
- and (a.DEPT_ORG_ID is null or a.DEPT_ORG_ID =0)
- </if>
- </if>
- and SCENE_TYPE_NAME in('水源','水厂','泵站')
- </where>
- group by b.SCENE_TYPE_NAME
- ) a left join
- (
- select count(a.ID) newAmount,b.SCENE_TYPE_NAME sceneTypeName
- from sms_scene a INNER JOIN sms_scene_type b on a.SCENE_TYPE_ID=b.ID
- <where>
- a.PARENT_SCENE_ID=0
- and a.STATUS=1
- <if test="months != null">
- and a.run_time>=date_sub(date_format(curdate(), '%y-%m-1' ), interval #{months}-1 month)
- </if>
- <if test="scene.tenantId != null and scene.tenantId != ''">
- and a.tenant_id = #{scene.tenantId}
- </if>
- <if test="scene.userType!=null and scene.userType!=-999 and scene.userType!=-9999 and scene.programItems != null and scene.programItems.size() > 0">
- <if test="scene.permissonType == 5 or scene.permissonType == 2">
- and ( a.DEPT_ORG_ID in
- <foreach collection="scene.programItems" item="item" open="(" close=")" separator=",">
- #{item.orgId}
- </foreach>
- or
- a.COMPANY_ORG_ID in
- <foreach collection="scene.programItems" item="item" open="(" close=")" separator=",">
- #{item.orgId}
- </foreach>
- )
- </if>
- <if test="scene.permissonType == 4 or scene.permissonType == 3">
- and a.DEPT_ORG_ID in
- <foreach collection="scene.programItems" item="item" open="(" close=")" separator=",">
- #{item.orgId}
- </foreach>
- </if>
- <if test="scene.permissonType == 1">
- and a.COMPANY_ORG_ID in
- <foreach collection="scene.programItems" item="item" open="(" close=")" separator=",">
- #{item.orgId}
- </foreach>
- and (a.DEPT_ORG_ID is null or a.DEPT_ORG_ID =0)
- </if>
- </if>
- and SCENE_TYPE_NAME in('水源','水厂','泵站')
- </where>
- group by b.SCENE_TYPE_NAME
- ) b
- on a.sceneTypeName = b.sceneTypeName
- union all
- select '户表' , ifnull(sum(user_meter_count),0) amount,sum(user_meter_add_count) newAmount
- from sms_month_revenue a
- <where>
- <if test="months != null">
- and a.collect_date>=date_sub(date_format(curdate(), '%y-%m-1' ), interval #{months}-1 month)
- </if>
- <if test="scene.tenantId != null and scene.tenantId != ''">
- and a.tenant_id = #{scene.tenantId}
- </if>
- <if test="scene.userType!=null and scene.userType!=-999 and scene.userType!=-9999 and scene.programItems != null and scene.programItems.size() > 0">
- <if test="scene.permissonType == 5 or scene.permissonType == 2">
- and a.COMPANY_ORG_ID in
- <foreach collection="scene.programItems" item="item" open="(" close=")" separator=",">
- #{item.orgId}
- </foreach>
- </if>
- <if test="scene.permissonType == 1">
- and a.COMPANY_ORG_ID in
- <foreach collection="scene.programItems" item="item" open="(" close=")" separator=",">
- #{item.orgId}
- </foreach>
- </if>
- </if>
- </where>
- </select>
- <!--报警场景及报警设备查询-->
- <select id="selectAlarmSceneAndDevice" resultType="map">
- select amount, id, scene_id, name, sort from(
- select count(1) amount, a.id,a.id scene_id, a.SCENE_NAME name,2 sort
- from sms_scene a INNER JOIN sms_scene_type b on a.SCENE_TYPE_ID=b.ID
- INNER JOIN sms_alarm_details c on c.PARENT_SCENE_ID=a.ID
- <where>
- a.PARENT_SCENE_ID=0 and a.STATUS=1
- <if test="scene.tenantId != null and scene.tenantId != ''">
- and a.tenant_id = #{scene.tenantId}
- </if>
- <if test="scene.userType!=null and scene.userType!=-999 and scene.userType!=-9999 and scene.programItems != null and scene.programItems.size() > 0">
- <if test="scene.permissonType == 5 or scene.permissonType == 2">
- and ( a.DEPT_ORG_ID in
- <foreach collection="scene.programItems" item="item" open="(" close=")" separator=",">
- #{item.orgId}
- </foreach>
- or
- a.COMPANY_ORG_ID in
- <foreach collection="scene.programItems" item="item" open="(" close=")" separator=",">
- #{item.orgId}
- </foreach>
- )
- </if>
- <if test="scene.permissonType == 4 or scene.permissonType == 3">
- and a.DEPT_ORG_ID in
- <foreach collection="scene.programItems" item="item" open="(" close=")" separator=",">
- #{item.orgId}
- </foreach>
- </if>
- <if test="scene.permissonType == 1">
- and a.COMPANY_ORG_ID in
- <foreach collection="scene.programItems" item="item" open="(" close=")" separator=",">
- #{item.orgId}
- </foreach>
- and (a.DEPT_ORG_ID is null or a.DEPT_ORG_ID =0)
- </if>
- </if>
- and c.alarm_start_time >= date_format(#{startDate,jdbcType=VARCHAR},'%Y-%m-%d')
- and c.alarm_start_time < date_format(#{endDate,jdbcType=VARCHAR},'%Y-%m-%d')
- and SCENE_TYPE_NAME in('水源','水厂','泵站')
- </where>
- group by a.scene_name, a.id, sort
- union all
- select count(*) amount, id, GROUP_CONCAT(DISTINCT scene_id SEPARATOR ',') scene_id, name,1 sort from
- (
- select d.id,c.PARENT_SCENE_ID scene_id, d.device_name name
- from sms_alarm_details c
- INNER JOIN sms_device d on c.DEVICE_ID=d.ID
- INNER JOIN sms_scene a on c.PARENT_SCENE_ID=a.ID
- INNER JOIN sms_scene_type b on a.SCENE_TYPE_ID=b.ID
- <where>
- a.PARENT_SCENE_ID=0 and a.STATUS=1
- <if test="scene.tenantId != null and scene.tenantId != ''">
- and a.tenant_id = #{scene.tenantId}
- </if>
- <if test="scene.userType!=null and scene.userType!=-999 and scene.userType!=-9999 and scene.programItems != null and scene.programItems.size() > 0">
- <if test="scene.permissonType == 5 or scene.permissonType == 2">
- and ( a.DEPT_ORG_ID in
- <foreach collection="scene.programItems" item="item" open="(" close=")" separator=",">
- #{item.orgId}
- </foreach>
- or
- a.COMPANY_ORG_ID in
- <foreach collection="scene.programItems" item="item" open="(" close=")" separator=",">
- #{item.orgId}
- </foreach>
- )
- </if>
- <if test="scene.permissonType == 4 or scene.permissonType == 3">
- and a.DEPT_ORG_ID in
- <foreach collection="scene.programItems" item="item" open="(" close=")" separator=",">
- #{item.orgId}
- </foreach>
- </if>
- <if test="scene.permissonType == 1">
- and a.COMPANY_ORG_ID in
- <foreach collection="scene.programItems" item="item" open="(" close=")" separator=",">
- #{item.orgId}
- </foreach>
- and (a.DEPT_ORG_ID is null or a.DEPT_ORG_ID =0)
- </if>
- </if>
- and c.alarm_start_time >= date_format(#{startDate,jdbcType=VARCHAR},'%Y-%m-%d')
- and c.alarm_start_time < date_format(#{endDate,jdbcType=VARCHAR},'%Y-%m-%d')
- and SCENE_TYPE_NAME='管网'
- </where>
- ) t1
- group by name, id, scene_id, sort ) t
- order by amount desc
- </select>
- <select id="selectMonthAlarmTimes" resultType="map">
- select count(1) 数量, DATE_FORMAT(c.DATE_CREATE,'%Y-%m-%d') 日期
- <if test="sort == 2">
- from sms_scene a INNER JOIN sms_scene_type b on a.SCENE_TYPE_ID=b.ID
- INNER JOIN sms_alarm_details c on c.PARENT_SCENE_ID=a.ID
- where a.ID = #{scene.id}
- </if>
- <if test="sort == 1">
- from sms_scene a inner join sms_scene_type b on a.SCENE_TYPE_ID=b.ID
- INNER JOIN sms_alarm_details c on c.PARENT_SCENE_ID=a.ID
- where a.PARENT_SCENE_ID=0 and a.STATUS=1
- and c.device_id = #{scene.id}
- and b.SCENE_TYPE_NAME='管网'
- <if test="scene.tenantId != null and scene.tenantId != ''">
- and a.tenant_id = #{scene.tenantId}
- </if>
- <if test="scene.userType!=null and scene.userType!=-999 and scene.userType!=-9999 and scene.programItems != null and scene.programItems.size() > 0">
- <if test="scene.permissonType == 5 or scene.permissonType == 2">
- and ( a.DEPT_ORG_ID in
- <foreach collection="scene.programItems" item="item" open="(" close=")" separator=",">
- #{item.orgId}
- </foreach>
- or
- a.COMPANY_ORG_ID in
- <foreach collection="scene.programItems" item="item" open="(" close=")" separator=",">
- #{item.orgId}
- </foreach>
- )
- </if>
- <if test="scene.permissonType == 4 or scene.permissonType == 3">
- and a.DEPT_ORG_ID in
- <foreach collection="scene.programItems" item="item" open="(" close=")" separator=",">
- #{item.orgId}
- </foreach>
- </if>
- <if test="scene.permissonType == 1">
- and a.COMPANY_ORG_ID in
- <foreach collection="scene.programItems" item="item" open="(" close=")" separator=",">
- #{item.orgId}
- </foreach>
- and (a.DEPT_ORG_ID is null or a.DEPT_ORG_ID =0)
- </if>
- </if>
- </if>
- and c.alarm_start_time >= date_format(#{startDate,jdbcType=VARCHAR},'%Y-%m-%d')
- and c.alarm_start_time < date_format(#{endDate,jdbcType=VARCHAR},'%Y-%m-%d')
- group by DATE_FORMAT(c.DATE_CREATE,'%Y-%m-%d')
- </select>
- <select id="selectYearAlarmTimes" resultType="map">
- select count(1) 数量, DATE_FORMAT(c.DATE_CREATE,'%Y-%m') 日期
- <if test="sort == 2">
- from sms_scene a INNER JOIN sms_scene_type b on a.SCENE_TYPE_ID=b.ID
- INNER JOIN sms_alarm_details c on c.PARENT_SCENE_ID=a.ID
- where a.ID = #{scene.id}
- </if>
- <if test="sort == 1">
- from sms_scene a inner join sms_scene_type b on a.SCENE_TYPE_ID=b.ID
- INNER JOIN sms_alarm_details c on c.PARENT_SCENE_ID=a.ID
- where a.PARENT_SCENE_ID=0 and a.STATUS=1
- and c.device_id = #{scene.id}
- and b.SCENE_TYPE_NAME='管网'
- <if test="scene.tenantId != null and scene.tenantId != ''">
- and a.tenant_id = #{scene.tenantId}
- </if>
- <if test="scene.userType!=null and scene.userType!=-999 and scene.userType!=-9999 and scene.programItems != null and scene.programItems.size() > 0">
- <if test="scene.permissonType == 5 or scene.permissonType == 2">
- and ( a.DEPT_ORG_ID in
- <foreach collection="scene.programItems" item="item" open="(" close=")" separator=",">
- #{item.orgId}
- </foreach>
- or
- a.COMPANY_ORG_ID in
- <foreach collection="scene.programItems" item="item" open="(" close=")" separator=",">
- #{item.orgId}
- </foreach>
- )
- </if>
- <if test="scene.permissonType == 4 or scene.permissonType == 3">
- and a.DEPT_ORG_ID in
- <foreach collection="scene.programItems" item="item" open="(" close=")" separator=",">
- #{item.orgId}
- </foreach>
- </if>
- <if test="scene.permissonType == 1">
- and a.COMPANY_ORG_ID in
- <foreach collection="scene.programItems" item="item" open="(" close=")" separator=",">
- #{item.orgId}
- </foreach>
- and (a.DEPT_ORG_ID is null or a.DEPT_ORG_ID =0)
- </if>
- </if>
- </if>
- and c.date_create >= date_format(#{startDate,jdbcType=VARCHAR},'%Y-%m-%d')
- and c.date_create < date_format(#{endDate,jdbcType=VARCHAR},'%Y-%m-%d')
- group by DATE_FORMAT(c.DATE_CREATE,'%Y-%m')
- </select>
- <select id="selectAlarmLable" resultType="map">
- select amount 数量, label 标签 from
- (
- select count(1) amount, concat(label,op) label from
- (
- select if(d.REMARK is null,e.NAME,d.REMARK) label,CASE WHEN ALARM_CONDITION='>' OR ALARM_CONDITION='>=' then '高'
- WHEN ALARM_CONDITION='<' OR ALARM_CONDITION='<=' then '低'
- ELSE '' END op
- <if test="sort == 2">
- from sms_scene a INNER JOIN sms_scene_type b on a.SCENE_TYPE_ID=b.ID
- INNER JOIN sms_alarm_details c on c.PARENT_SCENE_ID=a.ID
- INNER JOIN sms_device_attribute e on e.ID = c.ATTRIBUTE_ID and e.STATUS=1
- LEFT JOIN sms_device_parm d on d.ATTRIBUTE_ID = c.ATTRIBUTE_ID and d.DEVICE_ID=c.DEVICE_ID and d.TENANT_ID=c.TENANT_ID and d.PARENT_SCENE_ID=c.PARENT_SCENE_ID and d.STATUS=1
- INNER JOIN sms_alarm_setting f on f.device_id = c.device_id and f.SCENE_ID=c.SCENE_ID and f.ATTRIBUTE_ID=c.ATTRIBUTE_ID and f.STATUS=1
- where a.ID = #{scene.id}
- </if>
- <if test="sort == 1">
- from sms_alarm_details c
- INNER JOIN sms_device_attribute e on e.ID = c.ATTRIBUTE_ID and e.STATUS=1
- LEFT JOIN sms_device_parm d on d.ATTRIBUTE_ID = c.ATTRIBUTE_ID and d.DEVICE_ID=c.DEVICE_ID and d.TENANT_ID=c.TENANT_ID and d.PARENT_SCENE_ID=c.PARENT_SCENE_ID and d.STATUS=1
- INNER JOIN sms_alarm_setting f on f.device_id = c.device_id and f.SCENE_ID=c.SCENE_ID and f.ATTRIBUTE_ID=c.ATTRIBUTE_ID and f.STATUS=1
- where c.device_id = #{scene.id}
- </if>
- and c.date_create >= date_format(#{startDate,jdbcType=VARCHAR},'%Y-%m-%d')
- and c.date_create < date_format(#{endDate,jdbcType=VARCHAR},'%Y-%m-%d')
- ) t1
- group by concat(label,op)
- union all
- select count(1) amount, label from
- (
- select '离线' label
- <if test="sort == 2">
- from sms_scene a INNER JOIN sms_scene_type b on a.SCENE_TYPE_ID=b.ID
- INNER JOIN sms_alarm_details c on c.PARENT_SCENE_ID=a.ID
- where a.ID = #{scene.id} and alarm_type='状态报警'
- </if>
- <if test="sort == 1">
- from sms_alarm_details c
- where c.device_id = #{scene.id} and alarm_type='状态报警'
- </if>
- and c.alarm_start_time >= date_format(#{startDate,jdbcType=VARCHAR},'%Y-%m-%d')
- and c.alarm_start_time < date_format(#{endDate,jdbcType=VARCHAR},'%Y-%m-%d')
- ) t1
- group by label
- ) t2
- order by amount desc
- </select>
- <select id="selectAlarmDeviceIdBySenceId" resultType="map">
- select DISTINCT c.device_id from sms_scene a INNER JOIN sms_scene_type b on a.SCENE_TYPE_ID=b.ID
- INNER JOIN sms_alarm_details c on c.PARENT_SCENE_ID=a.ID
- where a.ID = #{id}
- </select>
- </mapper>
|