<?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.zcxk.dao.SceneTypeMapper">
    <resultMap type="SceneTypeEntity" id="SceneTypeResult">
        <result property="id" column="id"/>
        <result property="tenantId" column="tenant_id"/>
        <result property="parentScenetypeId" column="parent_scenetype_id"/>
        <result property="sceneTypeName" column="scene_type_name"/>
        <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="sceneTypeColumns">
         a.id as "id" ,
         a.tenant_id as "tenantId" ,
         a.parent_scenetype_id as "parentScenetypeId" ,
         a.scene_type_name as "sceneTypeName" ,
         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" 
     </sql>
    <!--  根据主键获取实体   -->
    <select id="findSceneTypeById" resultType="com.zcxk.entity.SceneTypeEntity">
        SELECT
        <include refid="sceneTypeColumns"/>
        FROM sms_scene_type a
        WHERE a.id = #{id} and  a.status = 1
    </select>

    <!--  根据获取实体List   -->
    <select id="findList" resultType="com.zcxk.entity.SceneTypeEntity">
        SELECT
        <include refid="sceneTypeColumns"/>
        FROM sms_scene_type a
        <where>
            a.status = 1
            <if test="tenantId != null  and tenantId != ''">and a.tenant_id = #{tenantId}</if>
            <if test="parentScenetypeId != null ">and a.parent_scenetype_id = #{parentScenetypeId}</if>
            <if test="sceneTypeName != null  and sceneTypeName != ''">
                and a.scene_type_name LIKE concat('%',#{sceneTypeName},'%')
            </if>
        </where>
        order  by a.date_create
    </select>
    <!--  根据主键获取租户菜单  -->
    <select id="findByParentSceneTypeIds" resultType="com.zcxk.entity.SceneTypeEntity">
        select a.id
        FROM sms_scene_type a
        WHERE a.status=1 and  a.parent_scenetype_id in
        <foreach collection = "Ids" item = "dramaId" open = "(" close = ")" separator = "," >
            #{dramaId}
        </foreach>
    </select>

    <!--  根据获取实体 page   -->
    <select id="findPage" resultType="com.zcxk.entity.SceneTypeEntity">
        SELECT
        <include refid="sceneTypeColumns"/>
        FROM sms_scene_type a
        <where>
            a.status = 1
            <if test="sceneType.tenantId != null  and sceneType.tenantId != ''">
            and a.tenant_id = #{sceneType.tenantId}
            </if>
            <if test="sceneType.sceneTypeName != null  and sceneType.sceneTypeName != ''">
                and a.scene_type_name LIKE concat('%',#{sceneType.sceneTypeName},'%')
            </if>
        </where>
        order  by a.date_create
    </select>
</mapper>