<?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.hzs.system.sys.mapper.SysApprovalBusinessSendMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.hzs.common.domain.system.sys.SysApprovalBusinessSend">
        <result column="PK_APPROVAL_BUSINESS" property="pkApprovalBusiness"/>
        <result column="PK_USER" property="pkUser"/>
    </resultMap>

    <!-- 批量插入 -->
    <insert id="insertBatch">
        insert ALL
        <foreach collection="sendIdList" item="item" index="index" separator=" ">
            into SYS_APPROVAL_BUSINESS_SEND (PK_APPROVAL_BUSINESS, PK_USER)
            values (#{pkApprovalBusiness}, #{item})
        </foreach>
        SELECT 1 FROM dual
    </insert>

    <!-- 根据审批业务ID查询审批业务抄送人 -->
    <select id="approvalSendList" resultType="com.hzs.common.domain.system.sys.ext.SysApprovalBusinessSendExt">
        select sabs.*, su.nick_name, sd.dept_name, sabr.receive_status
        from SYS_APPROVAL_BUSINESS_SEND sabs
        inner join sys_user su
        on su.user_id = sabs.pk_user
        inner join sys_dept sd
        on sd.dept_id = su.pk_dept
        left join SYS_APPROVAL_BUSINESS_RECEIVE sabr
        on sabr.pk_approval_business = sabs.pk_approval_business
        and sabr.pk_receive = sabs.pk_user
        where sabr.pk_approval_business in
        <foreach collection="pkIdList" item="item" index="index" open="(" close=")">
            <if test="index != 0">
                <choose>
                    <when test="index % 500 == 0">) or pk_approval_business IN (</when>
                    <otherwise>,</otherwise>
                </choose>
            </if>
            #{item}
        </foreach>
        order by sabs.pk_approval_business desc
    </select>

</mapper>
