<?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.sys.dao.RoleDAO">
    <resultMap id="RoleMap" type="Role">
        <id property="id" column="id_"/>
        <result property="name" column="name_"/>
        <result property="description" column="description_"/>
        <result property="createTime" column="create_time"/>
        <result property="updateTime" column="update_time"/>
        <result property="delFlag" column="del_flag"/>
        <result property="createBy" column="create_by"/>
        <result property="updateBy" column="update_by"/>
    </resultMap>
    <insert id="insert" parameterType="Role">
        <!--
        <selectKey resultType="java.lang.String" order="BEFORE" keyProperty="id">
            select sys_guid() from dual
        </selectKey>
        -->
        <![CDATA[
		insert into sys_role
	    (id_,name_,description_,create_time,update_time,del_flag,create_by,update_by)
		values
		(
            #{id,jdbcType=VARCHAR}
            ,#{name,jdbcType=VARCHAR}
            ,#{description,jdbcType=VARCHAR}
            ,#{createTime,jdbcType= TIMESTAMP }
            ,#{updateTime,jdbcType= TIMESTAMP }
            ,#{delFlag,jdbcType= NUMERIC }
            ,#{createBy,jdbcType=VARCHAR}
            ,#{updateBy,jdbcType=VARCHAR}
		)
	]]>
    </insert>
    <delete id="delete" parameterType="string">
        delete from sys_role where id_=#{id,jdbcType=VARCHAR}
    </delete>
    <update id="update" parameterType="Role">
        update sys_role
        <set>
            <if test="name!=null">
                name_=#{name,jdbcType=VARCHAR},
            </if>
            <if test="description!=null">
                description_=#{description,jdbcType=VARCHAR},
            </if>
            <if test="createTime!=null">
                create_time=#{createTime,jdbcType= TIMESTAMP },
            </if>
            <if test="updateTime!=null">
                update_time=#{updateTime,jdbcType= TIMESTAMP },
            </if>
            <if test="delFlag!=null">
                del_flag=#{delFlag,jdbcType= NUMERIC },
            </if>
            <if test="createBy!=null">
                create_by=#{createBy,jdbcType=VARCHAR},
            </if>
            <if test="updateBy!=null">
                update_by=#{updateBy,jdbcType=VARCHAR},
            </if>
        </set>
        where id_=#{id}
    </update>
    <select id="get" parameterType="string" resultMap="RoleMap">
        select
        id_,name_,description_,create_time,update_time,del_flag,create_by,update_by from sys_role where id_=#{0}
    </select>
    <select id="exist" parameterType="string" resultType="int">
        select count(*) from sys_role where id_=#{0}
    </select>
    <select id="list" resultMap="RoleMap">
        select * from sys_role  where del_flag=0 order by create_time asc
    </select>
    <select id="search" parameterType="hashmap" resultMap="RoleMap">
        <![CDATA[
			select * from sys_role
		]]>
            where del_flag=0
            <if test="searchParams.roleName != null">
                and name_ like #{searchParams.roleName}
            </if>
            <if test="searchParams.roleDesc != null">
                and description_ like #{searchParams.roleDesc}
            </if>
        <foreach item="sort" collection="sortList" open="order by" separator=",">
            ${sort.name} ${sort.order}
        </foreach>
    </select>

    <select id="findByName" parameterType="string" resultMap="RoleMap">
        select * from sys_role where name_=#{0}
    </select>
</mapper>