<?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.GradTableMapper">
    
    <resultMap type="GradTable" id="GradTableResult">
        <result property="uesrName"    column="uesr_name"    />
        <result property="userId"    column="user_id"    />
        <result property="certId"    column="cert_id"    />
        <result property="issueDate"    column="issue_date"    />
        <result property="certName"    column="cert_name"    />
        <result property="courseName"    column="course_name"    />
        <result property="courseHours"    column="course_hours"    />
        <result property="level"    column="level"    />
        <result property="startDate"    column="start_date"    />
        <result property="endDate"    column="end_date"    />
        <result property="picture"    column="picture"    />
        <result property="userPhone"    column="user_phone"    />
        <result property="userEmail"    column="user_email"    />
        <result property="updateDate"    column="update_date"    />
        <result property="id"    column="id"    />
        <result property="certType"    column="cert_type"    />
    </resultMap>

    <sql id="selectGradTableVo">
        select uesr_name, user_id, cert_id, issue_date, cert_name, course_name, course_hours, level, start_date, end_date, picture, user_phone, user_email, update_date, id, cert_type from grad_table
    </sql>

    <select id="selectGradTableList" parameterType="GradTable" resultMap="GradTableResult">
        <include refid="selectGradTableVo"/>
        <where>  
            <if test="uesrName != null  and uesrName != ''"> and uesr_name like concat('%', #{uesrName}, '%')</if>
            <if test="userId != null  and userId != ''"> and user_id = #{userId}</if>
            <if test="certId != null  and certId != ''"> and cert_id = #{certId}</if>
            <if test="certName != null  and certName != ''"> and cert_name like concat('%', #{certName}, '%')</if>
            <if test="courseName != null  and courseName != ''"> and course_name like concat('%', #{courseName}, '%')</if>
            <if test="courseHours != null  and courseHours != ''"> and course_hours = #{courseHours}</if>
            <if test="level != null  and level != ''"> and level = #{level}</if>
            <if test="userPhone != null  and userPhone != ''"> and user_phone = #{userPhone}</if>
            <if test="userEmail != null  and userEmail != ''"> and user_email = #{userEmail}</if>
            <if test="certType != null "> and cert_type = #{certType}</if>
        </where>
    </select>
    
    <select id="selectGradTableById" parameterType="Long" resultMap="GradTableResult">
        <include refid="selectGradTableVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertGradTable" parameterType="GradTable" useGeneratedKeys="true" keyProperty="id">
        insert into grad_table
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="uesrName != null and uesrName != ''">uesr_name,</if>
            <if test="userId != null and userId != ''">user_id,</if>
            <if test="certId != null and certId != ''">cert_id,</if>
            <if test="issueDate != null">issue_date,</if>
            <if test="certName != null and certName != ''">cert_name,</if>
            <if test="courseName != null">course_name,</if>
            <if test="courseHours != null and courseHours != ''">course_hours,</if>
            <if test="level != null">level,</if>
            <if test="startDate != null">start_date,</if>
            <if test="endDate != null">end_date,</if>
            <if test="picture != null">picture,</if>
            <if test="userPhone != null">user_phone,</if>
            <if test="userEmail != null">user_email,</if>
            <if test="updateDate != null">update_date,</if>
            <if test="certType != null">cert_type,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="uesrName != null and uesrName != ''">#{uesrName},</if>
            <if test="userId != null and userId != ''">#{userId},</if>
            <if test="certId != null and certId != ''">#{certId},</if>
            <if test="issueDate != null">#{issueDate},</if>
            <if test="certName != null and certName != ''">#{certName},</if>
            <if test="courseName != null">#{courseName},</if>
            <if test="courseHours != null and courseHours != ''">#{courseHours},</if>
            <if test="level != null">#{level},</if>
            <if test="startDate != null">#{startDate},</if>
            <if test="endDate != null">#{endDate},</if>
            <if test="picture != null">#{picture},</if>
            <if test="userPhone != null">#{userPhone},</if>
            <if test="userEmail != null">#{userEmail},</if>
            <if test="updateDate != null">#{updateDate},</if>
            <if test="certType != null">#{certType},</if>
         </trim>
    </insert>

    <update id="updateGradTable" parameterType="GradTable">
        update grad_table
        <trim prefix="SET" suffixOverrides=",">
            <if test="uesrName != null and uesrName != ''">uesr_name = #{uesrName},</if>
            <if test="userId != null and userId != ''">user_id = #{userId},</if>
            <if test="certId != null and certId != ''">cert_id = #{certId},</if>
            <if test="issueDate != null">issue_date = #{issueDate},</if>
            <if test="certName != null and certName != ''">cert_name = #{certName},</if>
            <if test="courseName != null">course_name = #{courseName},</if>
            <if test="courseHours != null and courseHours != ''">course_hours = #{courseHours},</if>
            <if test="level != null">level = #{level},</if>
            <if test="startDate != null">start_date = #{startDate},</if>
            <if test="endDate != null">end_date = #{endDate},</if>
            <if test="picture != null">picture = #{picture},</if>
            <if test="userPhone != null">user_phone = #{userPhone},</if>
            <if test="userEmail != null">user_email = #{userEmail},</if>
            <if test="updateDate != null">update_date = #{updateDate},</if>
            <if test="certType != null">cert_type = #{certType},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteGradTableById" parameterType="Long">
        delete from grad_table where id = #{id}
    </delete>

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