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

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.lz.modules.flow.entity.EvaluationGroup">
        <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="manager_ids" property="managerIds"/>
        <result column="dep_ids" property="depIds"/>
        <result column="staff_ids" property="staffIds"/>
        <result column="out_ids" property="outIds"/>
        <result column="copy_id" property="copyId"/>
    </resultMap>


    <!-- 通用查询结果列 -->
    <sql id="Base_Column_List">
        id AS id, is_delete AS isDelete, gmt_create AS gmtCreate, gmt_modified AS gmtModified, name AS name, manager_ids AS managerIds, dep_ids AS depIds, staff_ids AS staffIds, out_ids AS outIds, copy_id AS copyId
    </sql>




    <select id="selectEvaluationGroupById" resultType="EvaluationGroup" >
        select * from lz_evaluation_group  where id=#{id} and is_delete = 0 limit 1
    </select>


    <insert id="insertEvaluationGroup" parameterType="EvaluationGroup" useGeneratedKeys="true" keyProperty="id" >
        insert into lz_evaluation_group(
        <if test="name != null">name, </if>
        <if test="managerIds != null">manager_ids, </if>
        <if test="depIds != null">dep_ids, </if>
        <if test="staffIds != null">staff_ids, </if>
        <if test="outIds != null">out_ids, </if>
        <if test="copyId != null">copy_id, </if>
        is_delete,
        gmt_create,
        gmt_modified
        )values(
        <if test="name != null">#{ name}, </if>
        <if test="managerIds != null">#{ managerIds}, </if>
        <if test="depIds != null">#{ depIds}, </if>
        <if test="staffIds != null">#{ staffIds}, </if>
        <if test="outIds != null">#{ outIds}, </if>
        <if test="copyId != null">#{ copyId}, </if>
        0,
        now(),
        now()
        )
    </insert>


    <update id="updateEvaluationGroupById" parameterType="EvaluationGroup" >
        update
        lz_evaluation_group
        <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="managerIds != null">manager_ids = #{managerIds},</if>
            <if test="depIds != null">dep_ids = #{depIds},</if>
            <if test="staffIds != null">staff_ids = #{staffIds},</if>
            <if test="outIds != null">out_ids = #{outIds},</if>
            <if test="copyId != null">copy_id = #{copyId}</if>
        </trim>
        ,gmt_modified = now()
        where id = #{id}
    </update>


    <update id="updateCoverEvaluationGroupById" parameterType="EvaluationGroup" >
        update
            lz_evaluation_group
        set
            is_delete = #{isDelete},
            gmt_create = #{gmtCreate},
            name = #{name},
            manager_ids = #{managerIds},
            dep_ids = #{depIds},
            staff_ids = #{staffIds},
            out_ids = #{outIds},
            copy_id = #{copyId}
        ,gmt_modified = now()
        where id = #{id}
    </update>


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

    <select id="seleteEvaluationGroupByReq" resultType="EvaluationGroup" >
        select * from lz_evaluation_group  where is_delete = 0 and copy_id = 0
        <if test="req.startTime != null"><![CDATA[and gmt_create > #{req.startTime}]]></if>
        <if test="req.endTime != null"><![CDATA[and gmt_create < #{req.endTime}]]></if>
        <if test="req.name != null and req.name != ''">and name like concat('%', #{req.name} '%') </if>
    </select>

    <select id="selectEvaluationGroupByIds" resultType="EvaluationGroup" >
        select * from lz_evaluation_group  where is_delete = 0 and id in (
        <foreach collection="ids" item="id" separator=",">
            #{id}
        </foreach>
        )
    </select>

    <select id="selectEvaluationGroupByName" resultType="EvaluationGroup" >
        select * from lz_evaluation_group  where name=#{name} and is_delete = 0 limit 1
    </select>

</mapper>

