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

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.lz.modules.flow.entity.FlowDepartment">
        <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="flow_ids" property="flowIds"/>
        <result column="department_level" property="departmentLevel"/>
        <result column="parent_id" property="parentId"/>
    </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, flow_ids AS flowIds, department_level AS departmentLevel, parent_id AS parentId
    </sql>




    <select id="selectFlowDepartmentById" resultType="FlowDepartment" >
        select * from lz_flow_department  where id=#{id} and is_delete = 0 limit 1
    </select>


    <insert id="insertFlowDepartment" parameterType="FlowDepartment" useGeneratedKeys="true" keyProperty="id" >
        insert into lz_flow_department(
        <if test="staffId != null">staff_id, </if>
        <if test="flowIds != null">flow_ids, </if>
        <if test="departmentLevel != null">department_level, </if>
        <if test="parentId != null">parent_id, </if>
        is_delete,
        gmt_create,
        gmt_modified
        )values(
        <if test="staffId != null">#{ staffId}, </if>
        <if test="flowIds != null">#{ flowIds}, </if>
        <if test="departmentLevel != null">#{ departmentLevel}, </if>
        <if test="parentId != null">#{ parentId}, </if>
        0,
        now(),
        now()
        )
    </insert>


    <update id="updateFlowDepartmentById" parameterType="FlowDepartment" >
        update
        lz_flow_department
        <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="flowIds != null">flow_ids = #{flowIds},</if>
            <if test="departmentLevel != null">department_level = #{departmentLevel},</if>
            <if test="parentId != null">parent_id = #{parentId}</if>
        </trim>
        ,gmt_modified = now()
        where id = #{id}
    </update>


    <update id="updateCoverFlowDepartmentById" parameterType="FlowDepartment" >
        update
            lz_flow_department
        set
            is_delete = #{isDelete},
            gmt_create = #{gmtCreate},
            staff_id = #{staffId},
            flow_ids = #{flowIds},
            department_level = #{departmentLevel},
            parent_id = #{parentId}
        ,gmt_modified = now()
        where id = #{id}
    </update>


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




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


    <select id="selectByParentId" resultType="com.lz.modules.flow.entity.FlowDepartment">
        select * from lz_flow_department  where is_delete = 0 and parent_id = #{parentId} limit 1
    </select>


</mapper>

