<?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.app.dao.StaffDao">

    <!-- 可根据自己的需求，是否要使用 -->
    <resultMap type="com.lz.modules.app.entity.StaffEntity" id="staffMap">
        <id column="id" property="id"/>
        <result column="is_delete" property="isDelete"/>
        <result column="create_time" property="createTime"/>
        <result column="update_time" property="updateTime"/>
        <result column="name" property="name"/>
        <result column="gender" property="gender"/>
        <result column="birthday" property="birthday"/>
        <result column="marital_status" property="maritalStatus"/>
        <result column="national" property="national"/>
        <result column="political_landscape" property="politicalLandscape"/>
        <result column="mobile" property="mobile"/>
        <result column="province" property="province"/>
        <result column="emergency_contact" property="emergencyContact"/>
        <result column="emergency_contact_relation" property="emergencyContactRelation"/>
        <result column="emergency_contact_phone" property="emergencyContactPhone"/>
        <result column="email" property="email"/>
        <result column="current_address" property="currentAddress"/>
        <result column="open_id" property="openId"/>
        <result column="employee_id" property="employeeId"/>
        <result column="union_id" property="unionId"/>
        <result column="avatar" property="avatar"/>
        <result column="job_number" property="jobNumber"/>
        <result column="password" property="password"/>
        <result column="salt" property="salt"/>
    </resultMap>



    <!-- 通用查询结果列 -->
    <sql id="Base_Column_List">
        id AS id, is_delete AS isDelete, create_time AS createTime, update_time AS updateTime, name AS name, gender AS gender, birthday AS birthday, marital_status AS maritalStatus, national AS national, political_landscape AS politicalLandscape, mobile AS mobile, province AS province, emergency_contact AS emergencyContact, emergency_contact_relation AS emergencyContactRelation, emergency_contact_phone AS emergencyContactPhone, email AS email, current_address AS currentAddress, open_id AS openId, employee_id AS employeeId, union_id AS unionId, parent_id AS parentId, is_master AS isMaster
    </sql>




    <select id="selectStaffById" resultType="StaffEntity" >
        select * from lz_staff  where id=#{id} and is_delete = 0 limit 1
    </select>


    <insert id="insertStaff" parameterType="StaffEntity" useGeneratedKeys="true" keyProperty="id" >
        insert into lz_staff(
        <if test="name != null">name, </if>
        <if test="gender != null">gender, </if>
        <if test="birthday != null">birthday, </if>
        <if test="maritalStatus != null">marital_status, </if>
        <if test="national != null">national, </if>
        <if test="politicalLandscape != null">political_landscape, </if>
        <if test="mobile != null">mobile, </if>
        <if test="province != null">province, </if>
        <if test="emergencyContact != null">emergency_contact, </if>
        <if test="emergencyContactRelation != null">emergency_contact_relation, </if>
        <if test="emergencyContactPhone != null">emergency_contact_phone, </if>
        <if test="email != null">email, </if>
        <if test="currentAddress != null">current_address, </if>
        <if test="openId != null">open_id, </if>
        <if test="employeeId != null">employee_id, </if>
        <if test="unionId != null">union_id, </if>
        <if test="avatar != null">avatar, </if>
        <if test="jobNumber != null">job_number, </if>
        <if test="password != null">password, </if>
        <if test="salt != null">salt, </if>
        is_delete,
        create_time,
        update_time
        )values(
        <if test="name != null">#{ name}, </if>
        <if test="gender != null">#{ gender}, </if>
        <if test="birthday != null">#{ birthday}, </if>
        <if test="maritalStatus != null">#{ maritalStatus}, </if>
        <if test="national != null">#{ national}, </if>
        <if test="politicalLandscape != null">#{ politicalLandscape}, </if>
        <if test="mobile != null">#{ mobile}, </if>
        <if test="province != null">#{ province}, </if>
        <if test="emergencyContact != null">#{ emergencyContact}, </if>
        <if test="emergencyContactRelation != null">#{ emergencyContactRelation}, </if>
        <if test="emergencyContactPhone != null">#{ emergencyContactPhone}, </if>
        <if test="email != null">#{ email}, </if>
        <if test="currentAddress != null">#{ currentAddress}, </if>
        <if test="openId != null">#{ openId}, </if>
        <if test="employeeId != null">#{ employeeId}, </if>
        <if test="unionId != null">#{ unionId}, </if>
        <if test="avatar != null">#{ avatar}, </if>
        <if test="jobNumber != null">#{ jobNumber}, </if>
        <if test="password != null">#{ password}, </if>
        <if test="salt != null">#{ salt}, </if>
        0,
        now(),
        now()
        )
    </insert>


    <update id="updateStaffById" parameterType="StaffEntity" >
        update
        lz_staff
        <trim prefix="set" suffixOverrides=",">
            <if test="isDelete != null">is_delete = #{isDelete},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="name != null">name = #{name},</if>
            <if test="gender != null">gender = #{gender},</if>
            <if test="birthday != null">birthday = #{birthday},</if>
            <if test="maritalStatus != null">marital_status = #{maritalStatus},</if>
            <if test="national != null">national = #{national},</if>
            <if test="politicalLandscape != null">political_landscape = #{politicalLandscape},</if>
            <if test="mobile != null">mobile = #{mobile},</if>
            <if test="province != null">province = #{province},</if>
            <if test="emergencyContact != null">emergency_contact = #{emergencyContact},</if>
            <if test="emergencyContactRelation != null">emergency_contact_relation = #{emergencyContactRelation},</if>
            <if test="emergencyContactPhone != null">emergency_contact_phone = #{emergencyContactPhone},</if>
            <if test="email != null">email = #{email},</if>
            <if test="currentAddress != null">current_address = #{currentAddress},</if>
            <if test="openId != null">open_id = #{openId},</if>
            <if test="employeeId != null">employee_id = #{employeeId},</if>
            <if test="unionId != null">union_id = #{unionId},</if>
            <if test="avatar != null">avatar = #{avatar},</if>
            <if test="jobNumber != null">job_number = #{jobNumber},</if>
            <if test="password != null">password = #{password},</if>
            <if test="salt != null">salt = #{salt}</if>
        </trim>
        ,update_time = now()
        where id = #{id}
    </update>


    <update id="updateCoverStaffById" parameterType="StaffEntity" >
        update
            lz_staff
        set
            is_delete = #{isDelete},
            create_time = #{createTime},
            name = #{name},
            gender = #{gender},
            birthday = #{birthday},
            marital_status = #{maritalStatus},
            national = #{national},
            political_landscape = #{politicalLandscape},
            mobile = #{mobile},
            province = #{province},
            emergency_contact = #{emergencyContact},
            emergency_contact_relation = #{emergencyContactRelation},
            emergency_contact_phone = #{emergencyContactPhone},
            email = #{email},
            current_address = #{currentAddress},
            open_id = #{openId},
            employee_id = #{employeeId},
            union_id = #{unionId},
            avatar = #{avatar},
            job_number = #{jobNumber},
            password = #{password},
            salt = #{salt}
        ,update_time = now()
        where id = #{id}
    </update>


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


    <select id="getStaffInfoByOpenId" resultType="com.lz.modules.app.entity.StaffEntity">
        select * from lz_staff where is_delete=0 and open_id = #{openId}
	</select>

    <update id="updateStaff" parameterType="StaffEntity">
        UPDATE lz_staff
        <set>
            update_time = now(),
            <if test="name != null and name != '' ">
                name = #{name,jdbcType=VARCHAR},
            </if>
            <if test="gender != null">
                gender = #{gender,jdbcType=INTEGER},
            </if>
            <if test="birthday != null and birthday != '' ">
                birthday = #{birthday,jdbcType=TIMESTAMP},
            </if>
            <if test="maritalStatus != null">
                marital_status = #{maritalStatus,jdbcType=INTEGER},
            </if>
            <if test="national != null and national != '' ">
                national = #{national,jdbcType=VARCHAR},
            </if>
            <if test="politicalLandscape != null and politicalLandscape != '' ">
                political_landscape = #{politicalLandscape,jdbcType=VARCHAR},
            </if>
            <if test="mobile != null and mobile != '' ">
                mobile = #{mobile,jdbcType=VARCHAR},
            </if>
            <if test="province != null and province != '' ">
                province = #{province,jdbcType=VARCHAR},
            </if>
            <if test="emergencyContact != null and emergencyContact != '' ">
                emergency_contact = #{emergencyContact,jdbcType=VARCHAR},
            </if>
            <if test="emergencyContactRelation != null and emergencyContactRelation != '' ">
                emergency_contact_relation = #{emergencyContactRelation,jdbcType=VARCHAR},
            </if>
            <if test="emergencyContactPhone != null and emergencyContactPhone != '' ">
                emergency_contact_phone = #{emergencyContactPhone,jdbcType=VARCHAR},
            </if>
            <if test="email != null and email != '' ">
                email = #{email,jdbcType=VARCHAR},
            </if>
            <if test="currentAddress != null and currentAddress != '' ">
                current_address = #{currentAddress,jdbcType=VARCHAR},
            </if>
            <if test="employeeId != null and employeeId != '' ">
                employee_id = #{employeeId,jdbcType=VARCHAR},
            </if>
            <if test="unionId != null and unionId != '' ">
                union_id = #{unionId,jdbcType=VARCHAR},
            </if>
            <if test="openId != null and openId != '' ">
                open_id = #{openId,jdbcType=VARCHAR},
            </if>
            <if test="jobNumber != null and jobNumber != '' ">
                job_number = #{jobNumber,jdbcType=VARCHAR},
            </if>
            <if test="avatar != null and avatar != '' ">
                avatar = #{avatar,jdbcType=VARCHAR}
            </if>

        </set>
        WHERE is_delete = 0 AND id = #{id ,jdbcType=BIGINT}
    </update>

    <insert id="addStaffBatch">
        INSERT INTO lz_staff(name,gender,mobile,email,open_id,employee_id,union_id,avatar,job_number)
        VALUES
        <foreach collection="staffs" item="staff" separator=",">
            (#{staff.name},#{staff.gender},#{staff.mobile},#{staff.email},#{staff.openId},#{staff.employeeId},#{staff.unionId},#{staff.avatar},#{staff.jobNumber})
        </foreach>
    </insert>

    <select id="getByName" resultType="com.lz.modules.app.entity.StaffEntity">
        select * from lz_staff where is_delete=0 and name = #{name}
	</select>


    <select id="getStaffInfos" resultType="com.lz.modules.app.dto.StaffDto">
        select ls.id staffId,if(lso.employee_no='', lso.staff_no,lso.employee_no) staff_no,ls.name,lso.position,
        case lso.staff_status when 0 then '在职' else '离职' end staff_status,
        if(ls.id in (select staff_id from lz_departments_staff_relate where is_delete=0 and is_leader=1
        <if test="departmentId != null and departmentId != ''">
            and department_id=#{departmentId}
        </if>
        ),1,0) department_leader
        from lz_staff ls,lz_staff_occupation lso
        where lso.staff_id=ls.id and ls.is_delete=0
        and lso.staff_status=#{staffStatus}
        <if test="name != null and name != ''">
            and ls.name like concat('%',#{name},'%')
        </if>
        order by department_leader desc
        limit #{startIndex}, #{pageLimit}
    </select>

    <select id="getStaffInfoCount" resultType="java.lang.Integer">
        select count(ls.id) count
        from lz_staff ls,lz_staff_occupation lso
        where lso.staff_id=ls.id and ls.is_delete=0
        and lso.staff_status=#{staffStatus}
        <if test="name != null and name != ''">
            and ls.name like concat('%',#{name},'%')
        </if>
        and (ls.id in (
        select dsr.staff_id from lz_departments_staff_relate dsr where dsr.is_delete=0
        <if test="departmentId != null and departmentId != ''">
            and dsr.department_id=#{departmentId}
        </if>
        )
        or ls.employee_id in (
        select sr.leader_employee_id from lz_departments sr where sr.is_delete=0
        <if test="departmentId != null and departmentId != ''">
            and sr.department_id=#{departmentId}
        </if>
        ))
    </select>

    <select id="getBaseInfo" resultType="com.lz.modules.app.dto.StaffBaseInfoDto">
        select name staffName,gender,DATE_FORMAT(birthday,'%Y-%m-%d') birthday,marital_status,national,political_landscape,mobile,current_address from lz_staff where id=#{staffId}
    </select>

    <select id="getStatisticalData" resultType="com.lz.modules.app.dto.StaffStatisticalDto">
        select
        count(DISTINCT(ls.nowin_staff)) totalStaffCount,
        count(DISTINCT(td.leader_employee_id)) managementCount,
        ifnull(round(count(DISTINCT(td.leader_employee_id))/count(DISTINCT(ls.id))*100,2),0) managementRate,
        count(DISTINCT(ls.new_staff)) newStaffCount,
        count(DISTINCT(ls.leave_staff)) leaveStaffCount,
        ifnull(round(count(DISTINCT(ls.leave_staff))/(count(DISTINCT(ls.leave_staff))+count(DISTINCT(ls.nowin_staff)))*100,2),0)
        leaveRate
        from
        (select * from lz_staff ll
        left join
        (select staff_id as new_staff from lz_staff_occupation where date(entry_time) between #{beginDate} and
        #{endDate}) so1
        on so1.new_staff=ll.id
        left join
        (select staff_id as leave_staff from lz_staff_occupation where date(resignation_time) between #{beginDate} and
        #{endDate}) so2
        on so2.leave_staff=ll.id
        left join
        (select staff_id as nowin_staff from lz_staff_occupation where date(resignation_time)>=#{endDate} or
        resignation_time is null) so3
        on so3.nowin_staff=ll.id) ls,
        lz_departments_staff_relate dsr,
        (select * from lz_departments
        <if test="departmentId != null and departmentId != ''">
            where find_in_set(department_id, getChildList(#{departmentId}))
        </if>
        ) td
        where ls.is_delete=0 and ls.id=dsr.staff_id
        and dsr.department_id=td.department_id
    </select>

    <select id="getGenderData" resultType="com.lz.modules.app.dto.GraphicsStatisticalDto">
        select
        case gender when 1 then '男'
        when 2 then '女'
        else '未知'
        end category,
        count(gender) number
        from lz_staff
        where is_delete=0 and id in (select so.staff_id from lz_staff_occupation so where date(so.resignation_time)<![CDATA[ >= ]]>#{endDate} or
        so.resignation_time is null)
        <if test="departmentId != null and departmentId != ''">
            and id in (select dsr.staff_id from lz_departments_staff_relate dsr,lz_departments ld where
            dsr.department_id=ld.department_id and find_in_set(ld.department_id, getChildList(#{departmentId})))
        </if>
        group by gender
    </select>

    <select id="getAgeData" resultType="com.lz.modules.app.dto.GraphicsStatisticalDto">
        select
        if(birthday=0,'未知',concat(birthday,'后')) category,
        count(birthday) number
        from (
        select
        id,ifnull(CONCAT(left(date_format(birthday,'%y'),1),'0'),0) birthday
        from lz_staff
        where is_delete=0 and id in (select so.staff_id from lz_staff_occupation so where date(so.resignation_time)<![CDATA[ >= ]]>#{endDate} or
        so.resignation_time is null)
        <if test="departmentId != null and departmentId != ''">
            and id in (select dsr.staff_id from lz_departments_staff_relate dsr,lz_departments ld where
            dsr.department_id=ld.department_id and find_in_set(ld.department_id, getChildList(#{departmentId})))
        </if>
        ) t
        group by t.birthday
    </select>

    <select id="getJobSeniorityData" resultType="com.lz.modules.app.dto.GraphicsStatisticalDto">
        select
        t.jobYear category,
        count(jobYear) number
        from (
        select staff_id,
        case
        when TIMESTAMPDIFF(YEAR,job_begin_time,DATE_FORMAT(NOW(), '%Y-%m-%d %H:%i:%S')) <![CDATA[ >= ]]> 0 and
        TIMESTAMPDIFF(YEAR,job_begin_time,DATE_FORMAT(NOW(), '%Y-%m-%d %H:%i:%S'))<![CDATA[ < ]]>3
        then '0-3年'
        when TIMESTAMPDIFF(YEAR,job_begin_time,DATE_FORMAT(NOW(), '%Y-%m-%d %H:%i:%S')) <![CDATA[ >= ]]> 3 and
        TIMESTAMPDIFF(YEAR,job_begin_time,DATE_FORMAT(NOW(), '%Y-%m-%d %H:%i:%S'))<![CDATA[ < ]]>5
        then '3-5年'
        when TIMESTAMPDIFF(YEAR,job_begin_time,DATE_FORMAT(NOW(), '%Y-%m-%d %H:%i:%S')) <![CDATA[ >= ]]> 5 and
        TIMESTAMPDIFF(YEAR,job_begin_time,DATE_FORMAT(NOW(), '%Y-%m-%d %H:%i:%S'))<![CDATA[ < ]]>10
        then '5-10年'
        when TIMESTAMPDIFF(YEAR,job_begin_time,DATE_FORMAT(NOW(), '%Y-%m-%d %H:%i:%S')) <![CDATA[ >= ]]> 10
        then '10年以上' else '未知' end jobYear from lz_staff_occupation ls
        where ls.is_delete=0 and ls.staff_id in (select so.staff_id from lz_staff_occupation so where date(so.resignation_time)<![CDATA[ >= ]]>#{endDate}
        or so.resignation_time is null)
        <if test="departmentId != null and departmentId != ''">
            and ls.staff_id in (select dsr.staff_id from lz_departments_staff_relate dsr,lz_departments ld where
            dsr.department_id=ld.department_id and find_in_set(ld.department_id, getChildList(#{departmentId})))
        </if>
        ) t
        group by t.jobYear
    </select>

    <select id="getEducationData" resultType="com.lz.modules.app.dto.GraphicsStatisticalDto">
        select
        y.education category,
        count(education) number
        from (
        select t.id,ifnull(se.education,'未知') education from
        (select ls.id from lz_staff ls
        where ls.is_delete=0 and ls.id in (select so.staff_id from lz_staff_occupation so where date(so.resignation_time)<![CDATA[ >= ]]>#{endDate} or
        so.resignation_time is null)
        <if test="departmentId != null and departmentId != ''">
            and ls.id in (select dsr.staff_id from lz_departments_staff_relate dsr,lz_departments ld where
            dsr.department_id=ld.department_id and find_in_set(ld.department_id, getChildList(#{departmentId})))
        </if>) t
        left join lz_staff_education se on
        se.staff_id=t.id
        ) y
        group by y.education

    </select>


    <select id="selectByName" resultType="com.lz.modules.app.entity.StaffEntity">
         select * from lz_staff where is_delete=0  AND name LIKE CONCAT('%',#{name},'%')
    </select>

    <select id="selectByIds" resultType="com.lz.modules.app.entity.StaffEntity">
        select * from lz_staff where is_delete=0 and id in
        <foreach collection="staffIds" item="item" index="index" separator="," open="(" close=")">
            #{item}
        </foreach>
    </select>

    <insert id="addStaff" useGeneratedKeys="true"  keyProperty="id">

        INSERT INTO lz_staff(name,gender,mobile,email,open_id,employee_id,union_id,avatar,job_number)
        VALUES
            (#{name},#{gender},#{mobile},#{email},#{openId},#{employeeId},#{unionId},#{avatar},#{jobNumber})
    </insert>

    <select id="selectByRang" resultType="com.lz.modules.app.entity.StaffEntity">
        select * from lz_staff where is_delete=0 and id > #{id}
    </select>
    <select id="selectByPhone" resultType="com.lz.modules.app.entity.StaffEntity">
        select * from lz_staff where is_delete = 0 and ( mobile = #{phone} or mobile = concat('+86',#{phone},'')) limit 1
    </select>

    <select id="selectStaffByEmployeeId" resultType="com.lz.modules.app.entity.StaffEntity">
        select * from lz_staff where is_delete = 0 and  employee_id = #{employeeId} limit 1
    </select>

    <select id="selectBySearchName" resultType="com.lz.modules.app.entity.SearchStaffEntity">
        select staf.id, staf.name, occ.position, concat(staf.name, '-', occ.position) as 'desc' from lz_staff staf LEFT JOIN lz_staff_occupation occ on staf.id = occ.staff_id where staf.is_delete = 0
         <if test="model.name != null and model.name != ''"></if>
          AND staf.name LIKE CONCAT('%',#{model.name},'%')
    </select>

    <select id="selectAll" resultType="com.lz.modules.app.entity.StaffEntity">
        select * from lz_staff where is_delete = 0
    </select>

    <select id="getPositionByStaffIds" resultType="com.lz.modules.app.dto.ReportProgressListDto">
        SELECT o.staff_id,name staffName,position from lz_staff s
        LEFT JOIN
        lz_staff_occupation o
        on s.id = o.staff_id
        where s.is_delete=0 and o.is_delete=0
        and s.id in
        <foreach collection="staffIds" item="item" index="index" separator="," open="(" close=")">
            #{item}
        </foreach>
        <if test="req.staffName != null and req.staffName !=''">
            and name LIKE CONCAT('%',#{req.staffName},'%')
        </if>
    </select>

    <select id="selectStaffSimpleInfoByIds" resultType="com.lz.modules.app.dto.StaffSimpleDto">
        select staff.id as id, staff.name as name, occupation.position as position  from lz_staff staff join lz_staff_occupation occupation on staff.id=occupation.staff_id where staff.id in (
        <foreach collection="ids" item="id" separator=",">
            #{id}
        </foreach>
        ) and occupation.staff_status=0 order by field(staff.id,
        <foreach collection="ids" item="id" separator=",">
            #{id}
        </foreach>
        )
    </select>

    <select id="getDepatAllStaffInfos" resultType="com.lz.modules.app.dto.StaffDto">
        select jj.staff_id, jj.name, jj.department_leader, occ.position as position,
        case occ.staff_status when 0 then '在职' else '离职' end staff_status
        from (select staff.id as staff_id, staff.name as name, relate.is_leader as department_leader
              from lz_departments_staff_relate relate join lz_staff staff on staff.id = relate.staff_id
              where relate.department_id = #{departmentId} and relate.is_delete=0 and staff.is_delete=0 group by relate.staff_id) jj
       join lz_staff_occupation occ on jj.staff_id=occ.staff_id where occ.staff_status=0 and occ.is_delete=0

    </select>

    <select id="selectAllStaffSimpleInfos" resultType="com.lz.modules.app.entity.StaffSimpleInfo">
        select staff.id as id, staff.job_number as job_number, staff.name as name, staff.employee_id as employee_id, occupation.position as position
          , #{depart.departmentId} as department_id, #{depart.departmentName} as department_name
          from lz_staff staff join lz_staff_occupation occupation on staff.id=occupation.staff_id where staff.id in (
            select staff_id from lz_departments_staff_relate where department_id = #{depart.departmentId} and is_delete=0
        ) and occupation.staff_status=0 and staff.is_delete=0 and occupation.is_delete=0
    </select>
    <select id="selectStaffSimpleInfos" resultType="com.lz.modules.app.entity.StaffSimpleInfo">
        select info.id as id, info.job_number as job_number, info.name as name, info.position,
        info.department_id as department_id, info.employee_id as employee_id, dep.department_name as department_name from (
            select staffinfo.id as id, staffinfo.job_number as job_number, staffinfo.name as name,
            staffinfo.position, staffinfo.employee_id as employee_id, relate.department_id as department_id from (
                select staff.id as id, staff.job_number as job_number, staff.name as name,staff.employee_id as employee_id, occupation.position as position
                from lz_staff staff join lz_staff_occupation occupation on staff.id=occupation.staff_id where staff.id in (
                    <foreach collection="sIds" item="item" separator=",">
                        #{item}
                    </foreach>
                ) and occupation.staff_status=0 and occupation.is_delete=0 and staff.is_delete=0
            ) as staffinfo left join lz_departments_staff_relate relate on staffinfo.id = relate.staff_id
        ) as info left join lz_departments dep on info.department_id = dep.department_id GROUP BY info.id
    </select>
    
    <select id="selectOnJobByIds" resultType="com.lz.modules.app.entity.StaffEntity">
        select staff.*
          from lz_staff staff join lz_staff_occupation occupation on staff.id=occupation.staff_id where staff.id in (
            <foreach collection="mIds" item="item" separator=",">
                #{item}
            </foreach>
        ) and occupation.staff_status=0 and staff.is_delete=0 and occupation.is_delete=0
    </select>

    <select id="selectStaffSimpleInfo" resultType="com.lz.modules.app.entity.StaffSimpleInfo">
        select info.id as id, info.job_number as job_number, info.name as name, info.position,
        info.department_id as department_id, info.employee_id as employee_id, dep.department_name as department_name from (
        select staffinfo.id as id, staffinfo.job_number as job_number, staffinfo.name as name,
        staffinfo.position, staffinfo.employee_id as employee_id, relate.department_id as department_id from (
        select staff.id as id, staff.job_number as job_number, staff.name as name,staff.employee_id as employee_id, occupation.position as position
        from lz_staff staff join lz_staff_occupation occupation on staff.id=occupation.staff_id where staff.id = #{staffId}
         and occupation.staff_status=0 and occupation.is_delete=0 and staff.is_delete=0
        ) as staffinfo left join lz_departments_staff_relate relate on staffinfo.id = relate.staff_id
        ) as info left join lz_departments dep on info.department_id = dep.department_id GROUP BY info.id
    </select>

    <select id="selectNamesByIds" resultType="com.lz.modules.app.entity.StaffEntity">
        select * from lz_staff where id in (
            <foreach collection="list" item="item" separator=",">
                #{item}
            </foreach>
        ) order by field(id,
            <foreach collection="list" item="item" separator=",">
                #{item}
            </foreach>
        )
    </select>

    <select id="selectStaffsByGroupId" resultType="com.lz.modules.app.entity.StaffEntity">
        select staff.* from (select * from lz_staff where id in (
            select staff_id from lz_staff_role where is_delete = 0 and (evaluation_group_id = #{copyId} or evaluation_group_id = 0)
        ) and is_delete=0) as staff join lz_staff_occupation as occupation on staff.id = occupation.staff_id where occupation.staff_status=0

    </select>

    <select id="findManger" resultType="com.lz.modules.app.entity.StaffEntity">
        select staff.* from lz_staff as staff join lz_flow_record as record
        on record.approval_staff_id = staff.id
        where record.record_id = #{recordId} and record.flow_process=#{flowProcess}

    </select>
</mapper>
