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

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

    <!-- 批量插入审批业务涉及会员 -->
    <insert id="insertBatch">
        insert ALL
        <foreach collection="pkMemberList" item="item" index="index" separator=" ">
            into SYS_APPROVAL_BUSINESS_MEMBER (PK_APPROVAL_BUSINESS, PK_MEMBER)
            values (#{pkApprovalBusiness}, #{item})
        </foreach>
        SELECT 1 FROM dual
    </insert>

    <!-- 查询用户审核中业务数量 -->
    <select id="queryProcessingApproval" resultType="com.hzs.system.sys.dto.ApprovalMemberNumDTO">
        select sabm.*
        from (select sabm.pk_member, count(sabm.pk_member) data_count
        from sys_approval_business sab
        left join sys_approval_business_member sabm
        on sabm.pk_approval_business = sab.pk_id
        where sab.del_flag = 0
        and sab.pk_country = #{pkCountry}
        and sab.approval_status in (2, 3)
        and sabm.pk_member in
        <foreach collection="pkMemberList" item="item" open="(" close=")" separator=",">
            #{item}
        </foreach>
        group by sabm.pk_member) sabm
        where sabm.data_count != 0
    </select>

</mapper>
