<?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="cn.ezhizao.project.system.mapper.SysRoleInItMapper">

    <resultMap type="cn.ezhizao.project.system.domain.SysRoleInIt" id="SysRoleInItResult">
        <id column="id" property="id"/>
    </resultMap>


    <select id="getList" parameterType="SysRoleInIt" resultMap="SysRoleInItResult">
        SELECT * FROM sys_role_init
        <trim prefix=" WHERE" suffix="" suffixOverrides="AND">
            deleted = 0
            <if test="roleName != null  and roleName != ''">AND role_name like concat('%', #{roleName}, '%')</if>
        </trim>
    </select>

    <select id="getById" parameterType="SysRoleInIt" resultMap="SysRoleInItResult">
        SELECT * FROM sys_role_init
        WHERE id=#{id}
        AND deleted=0
    </select>

    <update id="updateRoleInIt" parameterType="SysRoleInIt">
        update sys_role_init
        <set>
            <if test="roleName!= null">role_name=#{roleName},</if>
            <if test="remark!= null">remark=#{remark},</if>
            <if test="menuCheckStrictly!= null">menu_check_strictly=#{menuCheckStrictly},</if>
            <if test="roleKey!= null">role_key=#{roleKey},</if>
        </set>
        <where>
            id=#{id}
        </where>
    </update>

    <insert id="insertRoleInIt" useGeneratedKeys="true" keyProperty="id" parameterType="SysRoleInIt">
        insert into sys_role_init(
        role_name
        <if test="remark != null and remark != ''">,remark</if>
        <if test="menuCheckStrictly != null ">,menu_check_strictly</if>
        <if test="roleKey!= null and roleKey != '' ">,role_key</if>
        )values(
        #{roleName}
        <if test="remark != null and remark != '' ">,#{remark}</if>
        <if test="menuCheckStrictly != null ">,#{menuCheckStrictly}</if>
        <if test="roleKey!= null  and roleKey != ''">,#{roleKey}</if>
        )
    </insert>

    <update id="deleteRoleInItByIds" parameterType="Long">
        update sys_role_init set deleted = 1 where id in
        <foreach collection="ids" item="id" open="(" separator="," close=")">
            #{id}
        </foreach>
    </update>

    <delete id="physicalDelete">
        DELETE FROM sys_role_init
        <trim prefix=" WHERE" suffix="" suffixOverrides="AND">
            <if test="id != null">
                id = #{id} AND
            </if>
       <!-- 删除条件为其他外键可以在这里加 -->
        </trim>
    </delete>
</mapper>
