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

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.lz.modules.flow.entity.StaffRoleEvaluationGroup">
        <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="role_id" property="roleId"/>
        <result column="evaluation_group_id" property="evaluationGroupId"/>
        <result column="is_select" property="isSelect"/>
    </resultMap>


    <!-- 通用查询结果列 -->
    <sql id="Base_Column_List">
        id AS id, is_delete AS isDelete, gmt_create AS gmtCreate, gmt_modified AS gmtModified, role_id AS roleId, evaluation_group_id AS evaluationGroupId, is_select AS isSelect
    </sql>



    <select id="selectStaffRoleEvaluationGroupById" resultType="StaffRoleEvaluationGroup" >
        select * from lz_staff_role_evaluation_group  where id=#{id} and is_delete = 0 limit 1 
    </select>



    <insert id="insertStaffRoleEvaluationGroup" parameterType="StaffRoleEvaluationGroup" useGeneratedKeys="true" keyProperty="id" >
        insert into lz_staff_role_evaluation_group(
            <if test="roleId != null">role_id, </if>
            <if test="evaluationGroupId != null">evaluation_group_id, </if>
            <if test="isSelect != null">is_select, </if>
            is_delete,
            gmt_create,
            gmt_modified
        )values(
            <if test="roleId != null">#{ roleId}, </if>
            <if test="evaluationGroupId != null">#{ evaluationGroupId}, </if>
            <if test="isSelect != null">#{ isSelect}, </if>
            0,
            now(),
            now()
        )
    </insert>


    <update id="updateStaffRoleEvaluationGroupById" parameterType="StaffRoleEvaluationGroup" >
        update
            lz_staff_role_evaluation_group
        <trim prefix="set" suffixOverrides=",">
            <if test="isDelete != null">is_delete = #{isDelete},</if>
            <if test="gmtCreate != null">gmt_create = #{gmtCreate},</if>
            <if test="roleId != null">role_id = #{roleId},</if>
            <if test="evaluationGroupId != null">evaluation_group_id = #{evaluationGroupId},</if>
            <if test="isSelect != null">is_select = #{isSelect}</if>                
        </trim>
        ,gmt_modified = now()
        where id = #{id}
    </update>


    <update id="updateCoverStaffRoleEvaluationGroupById" parameterType="StaffRoleEvaluationGroup" >
        update
            lz_staff_role_evaluation_group    
        set     
            is_delete = #{isDelete},
            gmt_create = #{gmtCreate},
            role_id = #{roleId},
            evaluation_group_id = #{evaluationGroupId},
            is_select = #{isSelect}                
        ,gmt_modified = now()
        where id = #{id}
    </update>


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




    <select id="selectStaffRoleEvaluationGroupBy" resultType="com.lz.modules.app.dto.EvaluationGroupInfo">
        select ev.id as id ,ev.name as name,eg.is_select as isSelect from lz_staff_role_evaluation_group eg
        left join lz_evaluation_group ev on eg.evaluation_group_id = ev.id
        where eg.role_id  = #{roleId} and ev.is_delete = 0 and eg.is_delete = 0
    </select>


    <delete id="deleteStaffRoleEvaluationGroupByRoleId">
        delete from lz_staff_role_evaluation_group where role_id = #{roleId}
    </delete>

    <select id="selectEvaluationGroupIdsByRoleId">
        select evaluation_group_id from lz_staff_role_evaluation_group  where is_delete = 0 and role_id = #{roleId} and is_select = 1
    </select>

    <select id="selectStaffRoleEvaluationsGroupByStaffRoles" resultType="StaffRoleEvaluationGroup" >
        select * from lz_staff_role_evaluation_group  where is_delete = 0 and
        role_id in (
        <foreach collection="list" item="item" separator=",">
            #{item.id}
        </foreach>
        )
    </select>
    <select id="selectEvaluationGroupIdsByRoleIdGroupId"
            resultType="com.lz.modules.flow.entity.StaffRoleEvaluationGroup">
        select * from lz_staff_role_evaluation_group  where is_delete = 0 and role_id = #{roleId} and evaluation_group_id = #{groupId}
    </select>

</mapper>

