<?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.jeeplus.modules.oa.dao.OaNotifyDetailDao">

	<insert id="batchInsert" parameterType="java.util.Map">
		INSERT INTO oa_notify_detail
		(notify_id ,handler_id, flag)
		VALUES
		<foreach collection="handlerList" item="linkman" separator=",">
			( #{notifyId}, #{linkman.id}, #{flag})
		</foreach>
	</insert>

	<delete id="deleteHandlers">
		DELETE FROM oa_notify_detail
		WHERE notify_id = #{notifyId}
		AND flag = #{flag}
	</delete>

    <select id="queryUserList" resultType="User">
        SELECT t1.id,t1.name,t1.photo,GROUP_CONCAT(t3.name ORDER BY t3.parent_ids SEPARATOR '-') AS 'officeName'
        FROM oa_notify_detail t
        LEFT JOIN sys_user t1 ON t.handler_id = t1.id
        LEFT JOIN sys_office t2 ON t1.office_id = t2.id
        LEFT JOIN sys_office t3 ON (FIND_IN_SET(t3.id,t2.parent_ids) OR t3.id = t2.id)
        WHERE t.notify_id = #{id} AND flag = 0
        GROUP BY t1.id;
    </select>

    <select id="queryOfficeList" resultType="Office">
        SELECT t1.id,GROUP_CONCAT(t2.name ORDER BY t2.parent_ids SEPARATOR '-') AS 'name'
        FROM oa_notify_detail t
        LEFT JOIN sys_office t1 ON t.handler_id = t1.id
	    LEFT JOIN sys_office t2 ON (FIND_IN_SET(t2.id,t1.parent_ids) OR t2.id = t1.id)
	    WHERE t.notify_id = #{id} AND flag = 1
	    GROUP BY t1.id;
    </select>
</mapper>