<?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.ho.user.mapper.SysRoleMapper">

    <sql id="Base_Column_List">
        id
        , `name`,code, description, `status`, create_time, update_time, deleted
    </sql>

    <select id="selectByPrimaryKey" parameterType="java.lang.Integer" resultType="com.ho.common.tools.entity.SysRole">
        select
        <include refid="Base_Column_List"/>
        from sys_role
        where id = #{id}
    </select>

    <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer">
        delete
        from sys_role
        where id = #{id}
    </delete>

    <insert id="insert" parameterType="com.ho.common.tools.entity.SysRole">
        insert into sys_role (`name`, code, description,
                              `status`, create_time, update_time,
                              deleted)
        values (#{name,jdbcType=VARCHAR}, #{code,jdbcType=VARCHAR}, #{description,jdbcType=VARCHAR},
                #{status,jdbcType=TINYINT}, #{createTime,jdbcType=TIMESTAMP}, #{updateTime,jdbcType=TIMESTAMP},
                #{deleted,jdbcType=TINYINT})
    </insert>

    <insert id="insertSelective" parameterType="com.ho.common.tools.entity.SysRole" useGeneratedKeys="true"
            keyProperty="id">
        insert into sys_role
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">
                id,
            </if>
            <if test="name != null">
                `name`,
            </if>
            <if test="code != null">
                `code`,
            </if>
            <if test="description != null">
                description,
            </if>
            <if test="status != null">
                `status`,
            </if>
            <if test="createTime != null">
                create_time,
            </if>
            <if test="updateTime != null">
                update_time,
            </if>
            <if test="deleted != null">
                deleted,
            </if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">
                #{id},
            </if>
            <if test="name != null">
                #{name,jdbcType=VARCHAR},
            </if>
            <if test="code != null">
                #{code,jdbcType=VARCHAR},
            </if>
            <if test="description != null">
                #{description,jdbcType=VARCHAR},
            </if>
            <if test="status != null">
                #{status,jdbcType=TINYINT},
            </if>
            <if test="createTime != null">
                #{createTime,jdbcType=TIMESTAMP},
            </if>
            <if test="updateTime != null">
                #{updateTime,jdbcType=TIMESTAMP},
            </if>
            <if test="deleted != null">
                #{deleted,jdbcType=TINYINT},
            </if>
        </trim>
    </insert>

    <update id="updateByPrimaryKeySelective" parameterType="com.ho.common.tools.entity.SysRole">
        update sys_role
        <set>
            <if test="name != null">
                `name` = #{name,jdbcType=VARCHAR},
            </if>
            <if test="description != null">
                description = #{description,jdbcType=VARCHAR},
            </if>
            <if test="status != null">
                `status` = #{status,jdbcType=TINYINT},
            </if>
            <if test="createTime != null">
                create_time = #{createTime,jdbcType=TIMESTAMP},
            </if>
            <if test="updateTime != null">
                update_time = #{updateTime,jdbcType=TIMESTAMP},
            </if>
            <if test="deleted != null">
                deleted = #{deleted,jdbcType=TINYINT},
            </if>
        </set>
        where id = #{id}
    </update>

    <update id="updateByPrimaryKey" parameterType="com.ho.common.tools.entity.SysRole">
        update sys_role
        set `name`      = #{name,jdbcType=VARCHAR},
            description = #{description,jdbcType=VARCHAR},
            `status`    = #{status,jdbcType=TINYINT},
            create_time = #{createTime,jdbcType=TIMESTAMP},
            update_time = #{updateTime,jdbcType=TIMESTAMP},
            deleted     = #{deleted,jdbcType=TINYINT}
        where id = #{id}
    </update>

    <select id="selectAll" resultType="com.ho.common.tools.entity.SysRole"
            parameterType="com.ho.user.vo.req.RolePageReqVO">
        select
        <include refid="Base_Column_List"></include>
        from sys_role
        <where>
            deleted=1
            <if test="roleName!=null and roleName!=''">
                AND name LIKE concat('%',#{roleName},'%')
            </if>
            <if test="status != null">
                AND `status` = #{status}
            </if>
            <if test="startTime!=null and startTime!=''">
                AND create_time &gt;= #{startTime}
            </if>
            <if test="endTime!=null and endTime!=''">
                AND create_time &lt;= #{endTime}
            </if>
            <if test="roleId!=null and roleId!='' ">
                AND id=#{roleId}
            </if>
            and code !='SUPER_ROLE'
        </where>
    </select>

    <select id="getRoleInfoByIds" resultType="com.ho.common.tools.entity.SysRole">
        select
        <include refid="Base_Column_List"></include>
        from sys_role
        where id in
        <foreach item="item" collection="list" open="(" separator="," close=")">
            #{item}
        </foreach>
        and status = 1
    </select>

    <select id="selectOthers" resultType="com.ho.common.tools.entity.SysRole"
            parameterType="com.ho.user.vo.req.RoleUpdateReqVO">
        select
        <include refid="Base_Column_List"></include>
        from sys_role
        <where>
            deleted=1
            <if test="name!=null and name!=''">
                AND name = #{name}
            </if>

            <if test="id!=null ">
                AND id !=#{id}
            </if>

        </where>
    </select>

    <select id="selectListByCondition" resultType="com.ho.common.tools.entity.SysRole"
            parameterType="com.ho.user.vo.req.RolePageReqVO">
        select
        <include refid="Base_Column_List"></include>
        from sys_role
        <where>
            deleted=1
            <if test="roleName!=null and roleName!=''">
                AND name =#{roleName}
            </if>
            <if test="startTime!=null and startTime!=''">
                AND create_time &gt;= #{startTime}
            </if>
            <if test="endTime!=null and endTime!=''">
                AND create_time &lt;= #{endTime}
            </if>
            <if test="roleId!=null and roleId!='' ">
                AND id=#{roleId}
            </if>
            <if test="status!=null and status!='' or status==0 ">
                AND `status`=#{status}
            </if>
        </where>
    </select>

    <select id="findByCode" resultType="com.ho.common.tools.entity.SysRole">
        select
        <include refid="Base_Column_List"></include>
        from sys_role
        <where>
            deleted=1
            and code = #{roleCode}
        </where>
    </select>

</mapper>