<?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.lz.modules.flow.dao.ResultGradeMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.lz.modules.flow.entity.ResultGrade">
        <id column="id" property="id"/>
        <result column="is_delete" property="isDelete"/>
        <result column="gmt_create" property="gmtCreate"/>
        <result column="gmt_modified" property="gmtModified"/>
        <result column="name" property="name"/>
        <result column="min_score" property="minScore"/>
        <result column="max_score" property="maxScore"/>
        <result column="score" property="score"/>
        <result column="group_id" property="groupId"/>
    </resultMap>


    <!-- 通用查询结果列 -->
    <sql id="Base_Column_List">
        id AS id, is_delete AS isDelete, gmt_create AS gmtCreate, gmt_modified AS gmtModified, name AS name, min_score AS minScore, max_score AS maxScore, score AS score, group_id AS groupId
    </sql>




    <select id="selectResultGradeById" resultType="ResultGrade" >
        select * from lz_result_grade  where id=#{id} and is_delete = 0 limit 1 
    </select>


    <insert id="insertResultGrade" parameterType="ResultGrade" useGeneratedKeys="true" keyProperty="id" >
        insert into lz_result_grade(
            <if test="name != null">name, </if>
            <if test="minScore != null">min_score, </if>
            <if test="maxScore != null">max_score, </if>
            <if test="score != null">score, </if>
            <if test="groupId != null">group_id, </if>
            is_delete,
            gmt_create,
            gmt_modified
        )values(
            <if test="name != null">#{ name}, </if>
            <if test="minScore != null">#{ minScore}, </if>
            <if test="maxScore != null">#{ maxScore}, </if>
            <if test="score != null">#{ score}, </if>
            <if test="groupId != null">#{ groupId}, </if>
            0,
            now(),
            now()
        )
    </insert>


    <update id="updateResultGradeById" parameterType="ResultGrade" >
        update
            lz_result_grade
        <trim prefix="set" suffixOverrides=",">
            <if test="isDelete != null">is_delete = #{isDelete},</if>
            <if test="gmtCreate != null">gmt_create = #{gmtCreate},</if>
            <if test="name != null">name = #{name},</if>
            <if test="minScore != null">min_score = #{minScore},</if>
            <if test="maxScore != null">max_score = #{maxScore},</if>
            <if test="score != null">score = #{score},</if>
            <if test="groupId != null">group_id = #{groupId}</if>                
        </trim>
        ,gmt_modified = now()
        where id = #{id}
    </update>


    <update id="updateCoverResultGradeById" parameterType="ResultGrade" >
        update
            lz_result_grade    
        set     
            is_delete = #{isDelete},
            gmt_create = #{gmtCreate},
            name = #{name},
            min_score = #{minScore},
            max_score = #{maxScore},
            score = #{score},
            group_id = #{groupId}                
        ,gmt_modified = now()
        where id = #{id}
    </update>


    <update id="deleteResultGradeById" parameterType="java.lang.Long">
        update lz_result_grade set is_delete = 1 where id=#{id} limit 1  
    </update>

    <select id="selectResultGradeByGroupId" resultType="com.lz.modules.flow.model.ResultGradeDto" >
        select * from lz_result_grade  where group_id=#{gid} and is_delete = 0
    </select>

</mapper>

