123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303 |
- <?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.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 and s.scene_type_name=#{scene.sceneTypeName}
- <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>
- </mapper>
|