<?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.ruoyi.system.mapper.ExamineConfigMapper">
    
    <resultMap type="ExamineConfig" id="ExamineConfigResult">
        <result property="id"    column="id"    />
        <result property="columnId"    column="column_id"    />
        <result property="roleId"    column="role_id"    />
        <result property="roleName"    column="role_name"    />
        <result property="examineLevel"    column="examine_level"    />
        <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="remark"    column="remark"    />
    </resultMap>

    <sql id="selectExamineConfigVo">
        select c.id, c.column_id, c.role_id, c.examine_level, c.create_by, c.create_time, c.update_by, c.update_time, c.remark,r.role_name from examine_config c left join sys_role r
        on c.role_id = r.role_id
    </sql>

    <select id="selectExamineConfigList" parameterType="ExamineConfig" resultMap="ExamineConfigResult">
        <include refid="selectExamineConfigVo"/>
        <where>  
            <if test="roleId != null "> and c.role_id = #{roleId}</if>
            <if test="examineLevel != null  and examineLevel != ''"> and c.examine_level = #{examineLevel}</if>
        </where>
    </select>
    
    <select id="selectExamineConfigById" parameterType="Long" resultMap="ExamineConfigResult">
        <include refid="selectExamineConfigVo"/>
        where c.id = #{id}
    </select>
        
    <insert id="insertExamineConfig" parameterType="ExamineConfig" useGeneratedKeys="true" keyProperty="id">
        insert into examine_config
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="columnId != null">column_id,</if>
            <if test="roleId != null">role_id,</if>
            <if test="examineLevel != null and examineLevel != ''">examine_level,</if>
            <if test="createBy != null">create_by,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="remark != null">remark,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="columnId != null">#{columnId},</if>
            <if test="roleId != null">#{roleId},</if>
            <if test="examineLevel != null and examineLevel != ''">#{examineLevel},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="remark != null">#{remark},</if>
         </trim>
    </insert>

    <update id="updateExamineConfig" parameterType="ExamineConfig">
        update examine_config
        <trim prefix="SET" suffixOverrides=",">
            <if test="columnId != null">column_id = #{columnId},</if>
            <if test="roleId != null">role_id = #{roleId},</if>
            <if test="examineLevel != null and examineLevel != ''">examine_level = #{examineLevel},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="remark != null">remark = #{remark},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteExamineConfigById" parameterType="Long">
        delete from examine_config where id = #{id}
    </delete>

    <delete id="deleteExamineConfigByIds" parameterType="String">
        delete from examine_config where id in 
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>

    <select id="selectExamineConfigByLevel" parameterType="String" resultMap="ExamineConfigResult">
        <include refid="selectExamineConfigVo"/>
        where c.examine_level = #{level}
    </select>
</mapper>