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

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.lz.modules.flow.entity.StaffRole">
        <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="staff_id" property="staffId"/>
        <result column="role" property="role"/>
    </resultMap>


    <!-- 通用查询结果列 -->
    <sql id="Base_Column_List">
        id AS id, is_delete AS isDelete, gmt_create AS gmtCreate, gmt_modified AS gmtModified, staff_id AS staffId, role AS role
    </sql>




    <select id="selectStaffRoleById" resultType="StaffRole" >
        select * from lz_staff_role  where id=#{id} and is_delete = 0 limit 1 
    </select>


    <insert id="insertStaffRole" parameterType="StaffRole" useGeneratedKeys="true" keyProperty="id" >
        insert into lz_staff_role(
            <if test="staffId != null">staff_id, </if>
            <if test="role != null">role, </if>
            is_delete,
            gmt_create,
            gmt_modified
        )values(
            <if test="staffId != null">#{ staffId}, </if>
            <if test="role != null">#{ role}, </if>
            0,
            now(),
            now()
        )
    </insert>


    <update id="updateStaffRoleById" parameterType="StaffRole" >
        update
            lz_staff_role
        <trim prefix="set" suffixOverrides=",">
            <if test="isDelete != null">is_delete = #{isDelete},</if>
            <if test="gmtCreate != null">gmt_create = #{gmtCreate},</if>
            <if test="staffId != null">staff_id = #{staffId},</if>
            <if test="role != null">role = #{role}</if>                
        </trim>
        ,gmt_modified = now()
        where id = #{id}
    </update>


    <update id="updateCoverStaffRoleById" parameterType="StaffRole" >
        update
            lz_staff_role    
        set     
            is_delete = #{isDelete},
            gmt_create = #{gmtCreate},
            staff_id = #{staffId},
            role = #{role}                
        ,gmt_modified = now()
        where id = #{id}
    </update>


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

    <select id="selectByStaffId" resultType="com.lz.modules.flow.entity.StaffRole">
            select * from lz_staff_role  where  is_delete = 0 and staff_id = #{staffId} limit 1
    </select>


</mapper>

