<?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.ResultModelMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.lz.modules.flow.entity.ResultModel">
        <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="evaluation_group_id" property="evaluationGroupId"/>
        <result column="type" property="type"/>
        <result column="weight" property="weight"/>
        <result column="max_count" property="maxCount"/>
        <result column="calculate_id" property="calculateId"/>
        <result column="grade_status" property="gradeStatus"/>
        <result column="grade_group_id" property="gradeGroupId"/>
        <result column="order_by" property="orderBy"/>
    </resultMap>


    <!-- 通用查询结果列 -->
    <sql id="Base_Column_List">
        id AS id, is_delete AS isDelete, gmt_create AS gmtCreate, gmt_modified AS gmtModified, name AS name, evaluation_group_id AS evaluationGroupId, type AS type, weight AS weight, max_count AS maxCount, calculate_id AS calculateId, grade_status AS gradeStatus, grade_group_id AS gradeGroupId, order_by AS orderBy
    </sql>




    <select id="selectResultModelById" resultType="ResultModel" >
        select * from lz_result_model  where id=#{id} and is_delete = 0 limit 1 
    </select>


    <insert id="insertResultModel" parameterType="ResultModel" useGeneratedKeys="true" keyProperty="id" >
        insert into lz_result_model(
            <if test="name != null">name, </if>
            <if test="evaluationGroupId != null">evaluation_group_id, </if>
            <if test="type != null">type, </if>
            <if test="weight != null">weight, </if>
            <if test="maxCount != null">max_count, </if>
            <if test="calculateId != null">calculate_id, </if>
            <if test="gradeStatus != null">grade_status, </if>
            <if test="gradeGroupId != null">grade_group_id, </if>
            <if test="orderBy != null">order_by, </if>
            is_delete,
            gmt_create,
            gmt_modified
        )values(
            <if test="name != null">#{ name}, </if>
            <if test="evaluationGroupId != null">#{ evaluationGroupId}, </if>
            <if test="type != null">#{ type}, </if>
            <if test="weight != null">#{ weight}, </if>
            <if test="maxCount != null">#{ maxCount}, </if>
            <if test="calculateId != null">#{ calculateId}, </if>
            <if test="gradeStatus != null">#{ gradeStatus}, </if>
            <if test="gradeGroupId != null">#{ gradeGroupId}, </if>
            <if test="orderBy != null">#{ orderBy}, </if>
            0,
            now(),
            now()
        )
    </insert>


    <update id="updateResultModelById" parameterType="ResultModel" >
        update
            lz_result_model
        <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="evaluationGroupId != null">evaluation_group_id = #{evaluationGroupId},</if>
            <if test="type != null">type = #{type},</if>
            <if test="weight != null">weight = #{weight},</if>
            <if test="maxCount != null">max_count = #{maxCount},</if>
            <if test="calculateId != null">calculate_id = #{calculateId},</if>
            <if test="gradeStatus != null">grade_status = #{gradeStatus},</if>
            <if test="gradeGroupId != null">grade_group_id = #{gradeGroupId},</if>
            <if test="orderBy != null">order_by = #{orderBy}</if>                
        </trim>
        ,gmt_modified = now()
        where id = #{id}
    </update>


    <update id="updateCoverResultModelById" parameterType="ResultModel" >
        update
            lz_result_model    
        set     
            is_delete = #{isDelete},
            gmt_create = #{gmtCreate},
            name = #{name},
            evaluation_group_id = #{evaluationGroupId},
            type = #{type},
            weight = #{weight},
            max_count = #{maxCount},
            calculate_id = #{calculateId},
            grade_status = #{gradeStatus},
            grade_group_id = #{gradeGroupId},
            order_by = #{orderBy}                
        ,gmt_modified = now()
        where id = #{id}
    </update>


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

    <select id="selectResultModelByGroupId" resultType="ResultModel" >
        select * from lz_result_model  where evaluation_group_id=#{id} and is_delete = 0
    </select>

    <select id="selectResultDtoByGroupId" resultType="com.lz.modules.flow.model.ResultModelDto" >
        select * from lz_result_model  where evaluation_group_id=#{id} and is_delete = 0 order by order_by asc
    </select>

    <update id="deleteResultModelByGroupId" parameterType="java.lang.Long">
        update lz_result_model set is_delete = 1 where evaluation_group_id=#{id}
    </update>



</mapper>

