<?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="im.zhaojun.system.mapper.RoleMapper">
    <resultMap id="BaseResultMap" type="im.zhaojun.system.model.Role">
        <id column="role_id" jdbcType="INTEGER" property="roleId"/>
        <result column="role_name" jdbcType="VARCHAR" property="roleName"/>
        <result column="remark" jdbcType="VARCHAR" property="remark"/>
        <result column="create_time" jdbcType="VARCHAR" property="createTime"/>
        <result column="modify_time" jdbcType="VARCHAR" property="modifyTime"/>
    </resultMap>
    <sql id="Base_Column_List">
        role_id,
        role_name,
        remark,
        create_time,
        modify_time
    </sql>
    <select id="selectByPrimaryKey" parameterType="java.lang.Integer" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List"/>
        from role
        where role_id = #{roleId,jdbcType=INTEGER}
    </select>
    <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer">
        delete
        from role
        where role_id = #{roleId,jdbcType=INTEGER}
    </delete>
    <insert id="insert"  parameterType="im.zhaojun.system.model.Role">
        insert into role (role_id,role_name, remark,create_time ,modify_time )
        select max(role_id)+1, #{roleName,jdbcType=VARCHAR}, #{remark,jdbcType=VARCHAR},#{createTime,jdbcType=VARCHAR},#{modifyTime,jdbcType=VARCHAR}   from role
    </insert>
    <update id="updateByPrimaryKey" parameterType="im.zhaojun.system.model.Role">
        update role
        set role_name = #{roleName,jdbcType=VARCHAR},
            remark    = #{remark,jdbcType=VARCHAR},
            modify_time    = #{modifyTime,jdbcType=VARCHAR}
        where role_id = #{roleId,jdbcType=INTEGER}
    </update>

    <select id="selectAll" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List"/>
        from role
    </select>

    <select id="selectAllByQuery" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List"/>
        from role
        <where>
            <if test="roleName != null and roleName != ''">
                AND role_name like concat('%', #{roleName}, '%')
            </if>
        </where>
    </select>

    <select id="count" resultType="java.lang.Integer">
        select
        count(*)
        from role
    </select>




</mapper>