<?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">
<!-- namespace必须指向DAO接口 -->
<mapper namespace="com.jpsoft.shinestar.modules.base.dao.PersonRoleInfoDAO">
    <resultMap id="PersonRoleInfoMap" type="com.jpsoft.shinestar.modules.base.entity.PersonRoleInfo">
        <id property="id" column="id_"/>
        <result property="personRoleName" column="person_role_name"/>
        <result property="sceneId" column="scene_id"/>
        <result property="sceneName" column="scene_name"/>
        <result property="useEnable" column="use_enable"/>
        <result property="remark" column="remark_"/>
        <result property="createBy" column="create_by"/>
        <result property="createTime" column="create_time"/>
        <result property="updateBy" column="update_by"/>
        <result property="updateTime" column="update_time"/>
        <result property="delFlag" column="del_flag"/>
        <result property="pic" column="pic_"/>
        <result property="registerEnable" column="register_enable"/>
        <result property="parentId" column="parent_id"/>
        <result property="parentName" column="parent_name"/>
    </resultMap>
    <insert id="insert" parameterType="com.jpsoft.shinestar.modules.base.entity.PersonRoleInfo">
        <!--
        <selectKey resultType="java.lang.String" order="BEFORE" keyProperty="id">
            select sys_guid() from dual
        </selectKey>
        -->
        <![CDATA[
		insert into base_person_role_info
	    (id_,person_role_name,scene_id,use_enable,remark_,create_by,create_time,update_by,
	    update_time,del_flag,pic_,register_enable,parent_id)
		values
		(
            #{id,jdbcType=VARCHAR}
            ,#{personRoleName,jdbcType=VARCHAR}
            ,#{sceneId,jdbcType=VARCHAR}
            ,#{useEnable,jdbcType= NUMERIC }
            ,#{remark,jdbcType=VARCHAR}
            ,#{createBy,jdbcType=VARCHAR}
            ,#{createTime,jdbcType= TIMESTAMP }
            ,#{updateBy,jdbcType=VARCHAR}
            ,#{updateTime,jdbcType= TIMESTAMP }
            ,#{delFlag,jdbcType= NUMERIC }
            ,#{pic,jdbcType=VARCHAR}
            ,#{registerEnable,jdbcType=BOOLEAN}
            ,#{parentId,jdbcType=VARCHAR}
		)
	]]>
    </insert>
    <delete id="delete" parameterType="string">
        delete from base_person_role_info where id_=#{id,jdbcType=VARCHAR}
    </delete>
    <update id="update" parameterType="com.jpsoft.shinestar.modules.base.entity.PersonRoleInfo">
        update base_person_role_info
        <set>
            <if test="personRoleName!=null">
                person_role_name=#{personRoleName,jdbcType=VARCHAR},
            </if>
            <if test="sceneId!=null">
                scene_id=#{sceneId,jdbcType=VARCHAR},
            </if>
            <if test="useEnable!=null">
                use_enable=#{useEnable,jdbcType= NUMERIC },
            </if>
            <if test="remark!=null">
                remark_=#{remark,jdbcType=VARCHAR},
            </if>
            <if test="createBy!=null">
                create_by=#{createBy,jdbcType=VARCHAR},
            </if>
            <if test="createTime!=null">
                create_time=#{createTime,jdbcType= TIMESTAMP },
            </if>
            <if test="updateBy!=null">
                update_by=#{updateBy,jdbcType=VARCHAR},
            </if>
            <if test="updateTime!=null">
                update_time=#{updateTime,jdbcType= TIMESTAMP },
            </if>
            <if test="delFlag!=null">
                del_flag=#{delFlag,jdbcType= NUMERIC },
            </if>
            <if test="pic!=null">
                pic_=#{pic,jdbcType=VARCHAR },
            </if>
            <if test="registerEnable!=null">
                register_enable=#{registerEnable,jdbcType=BOOLEAN },
            </if>
            <if test="parentId!=null">
                parent_id=#{parentId,jdbcType=VARCHAR},
            </if>
        </set>
        where id_=#{id}
    </update>
    <select id="get" parameterType="string" resultMap="PersonRoleInfoMap">
        select * from base_person_role_info where id_=#{0}
    </select>
    <select id="exist" parameterType="string" resultType="int">
        select count(*) from base_person_role_info where id_=#{0}
    </select>
    <select id="list" resultMap="PersonRoleInfoMap">
        select * from base_person_role_info
    </select>
    <select id="findParentId" resultMap="PersonRoleInfoMap">
        select * from base_person_role_info where del_flag = false and parent_id = #{0}
    </select>
    <select id="search" parameterType="hashmap" resultMap="PersonRoleInfoMap">
        <![CDATA[
			select a.*,
			b.scene_name,
			c.person_role_name as parent_name
			from base_person_role_info a
			left join base_scene_info b on a.scene_id = b.id_
			left join base_person_role_info c on a.parent_id = c.id_
		]]>
        <where>
            a.del_flag = 0
            <if test="searchParams.sceneId != null">
                and a.scene_id = #{searchParams.sceneId}
            </if>
            <if test="searchParams.useEnable != null">
                and a.use_enable = #{searchParams.useEnable}
            </if>
        </where>
        <foreach item="sort" collection="sortList" open="order by" separator=",">
            ${sort.name} ${sort.order}
        </foreach>
    </select>
    <select id="findBySceneId" resultMap="PersonRoleInfoMap" parameterType="string">
        select a.*,
        b.scene_name
        from base_person_role_info a
        left join base_scene_info b on a.scene_id = b.id_
        where a.del_flag = 0
        and a.scene_id = #{sceneId}
        and a.use_enable = 1
    </select>
    <select id="findByRoleNameAndSceneId" resultMap="PersonRoleInfoMap" parameterType="string">
        SELECT
        *
        FROM
        base_person_role_info
        WHERE
        del_flag = 0
        AND person_role_name = #{roleName}
        AND scene_id = #{sceneId}
        AND use_enable = 1
        limit 1
    </select>
    <select id="findAll" resultMap="PersonRoleInfoMap">
        select a.*,
        b.scene_name
        from base_person_role_info a
        left join base_scene_info b on a.scene_id = b.id_
        where
        a.del_flag=0
        order by a.scene_id,b.id_
    </select>
</mapper>