<?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.huyi.service.common.companyAcc.mapper.CompanyAccMapper">

    <select id="selectCompanyAccList" parameterType="map" resultType="map">
        SELECT
          PAI_ACCNO 'value',
          CASE  WHEN PAI_ACCNO = #{paramMap.zfpcrAccount}  THEN 0  ELSE  1  END  'flag'
        FROM
          pay_acc_inf
          LEFT JOIN sys_company
            ON scy_id = PAI_CSTNO
            AND scy_type = '01'
        WHERE 1=1
        <if test="paramMap.zfpcrAccount != null  and paramMap.zfpcrAccount != ''">
            AND (PAI_ACCNO = #{paramMap.zfpcrAccount} OR (PAI_STATUS = '2'
            AND PAI_ACCTYPE = '00'))
        </if>
        <if test="paramMap.zfpcrAccount == null  or paramMap.zfpcrAccount == ''">
            and PAI_STATUS = '2'
            AND PAI_ACCTYPE = '00'
        </if>
          UNION

        SELECT
          PBAI_BANKACCOUNT_ID 'value',
          CASE  WHEN PBAI_BANKACCOUNT_ID = #{paramMap.zfpcrAccount} THEN 0  ELSE  1  END  'flag'
        FROM
          pay_bank_acc_inf
          LEFT JOIN sys_company
            ON scy_id = PBAI_CSTNO
        AND scy_type = '01'
        WHERE 1=1
        <if test="paramMap.zfpcrAccount != null  and paramMap.zfpcrAccount != ''">
            AND (PBAI_BANKACCOUNT_ID = #{paramMap.zfpcrAccount} OR PBAI_STATUS = '0')
        </if>
        <if test="paramMap.zfpcrAccount == null  or paramMap.zfpcrAccount == ''">
            and PBAI_STATUS = '0'
        </if>
        ORDER BY  flag ASC
    </select>
</mapper>