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

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.lz.modules.flow.entity.ResultScore">
        <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="acquire_score" property="acquireScore"/>
        <result column="detail_id" property="detailId"/>
        <result column="approval_id" property="approvalId"/>
        <result column="score_comment" property="scoreComment"/>
        <result column="weight" property="weight"/>
    </resultMap>


    <!-- 通用查询结果列 -->
    <sql id="Base_Column_List">
        id AS id, is_delete AS isDelete, gmt_create AS gmtCreate, gmt_modified AS gmtModified, acquire_score AS acquireScore, detail_id AS detailId, approval_id AS approvalId, score_comment AS scoreComment, weight AS weight
    </sql>




    <select id="selectResultScoreById" resultType="ResultScore" >
        select * from lz_result_score  where id=#{id} and is_delete = 0 limit 1
    </select>


    <insert id="insertResultScore" parameterType="ResultScore" useGeneratedKeys="true" keyProperty="id" >
        insert into lz_result_score(
        <if test="acquireScore != null">acquire_score, </if>
        <if test="detailId != null">detail_id, </if>
        <if test="approvalId != null">approval_id, </if>
        <if test="scoreComment != null">score_comment, </if>
        <if test="weight != null">weight, </if>
        is_delete,
        gmt_create,
        gmt_modified
        )values(
        <if test="acquireScore != null">#{ acquireScore}, </if>
        <if test="detailId != null">#{ detailId}, </if>
        <if test="approvalId != null">#{ approvalId}, </if>
        <if test="scoreComment != null">#{ scoreComment}, </if>
        <if test="weight != null">#{ weight}, </if>
        0,
        now(),
        now()
        )
    </insert>


    <update id="updateResultScoreById" parameterType="ResultScore" >
        update
        lz_result_score
        <trim prefix="set" suffixOverrides=",">
            <if test="isDelete != null">is_delete = #{isDelete},</if>
            <if test="gmtCreate != null">gmt_create = #{gmtCreate},</if>
            <if test="acquireScore != null">acquire_score = #{acquireScore},</if>
            <if test="detailId != null">detail_id = #{detailId},</if>
            <if test="approvalId != null">approval_id = #{approvalId},</if>
            <if test="scoreComment != null">score_comment = #{scoreComment},</if>
            <if test="weight != null">weight = #{weight}</if>
        </trim>
        ,gmt_modified = now()
        where id = #{id}
    </update>


    <update id="updateCoverResultScoreById" parameterType="ResultScore" >
        update
            lz_result_score
        set
            is_delete = #{isDelete},
            gmt_create = #{gmtCreate},
            acquire_score = #{acquireScore},
            detail_id = #{detailId},
            approval_id = #{approvalId},
            score_comment = #{scoreComment},
            weight = #{weight}
        ,gmt_modified = now()
        where id = #{id}
    </update>


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

    <select id="selectResultScoresByDetailId" resultType="ResultScore" >
        select * from lz_result_score  where detail_id=#{id} and is_delete = 0
    </select>

    <select id="selectResultScoresByDetailIdAndOrderByStaffIds" resultType="ResultScore" >
        select * from lz_result_score  where detail_id=#{id} and is_delete = 0 order by field(approval_id,
        <foreach collection="list" item="item" separator=",">
            #{item.approvalId}
        </foreach>
        )
    </select>

</mapper>

