<?xml version="1.0" encoding="UTF-8"?>

<!--
  ~
  ~      Copyright (c) 2018-2025, lengleng All rights reserved.
  ~
  ~  Redistribution and use in source and binary forms, with or without
  ~  modification, are permitted provided that the following conditions are met:
  ~
  ~ Redistributions of source code must retain the above copyright notice,
  ~  this list of conditions and the following disclaimer.
  ~  Redistributions in binary form must reproduce the above copyright
  ~  notice, this list of conditions and the following disclaimer in the
  ~  documentation and/or other materials provided with the distribution.
  ~  Neither the name of the yifu4cloud.com developer nor the names of its
  ~  contributors may be used to endorse or promote products derived from
  ~  this software without specific prior written permission.
  ~  Author: lengleng (wangiegie@gmail.com)
  ~
  -->

<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">

<mapper namespace="com.yifu.cloud.plus.v1.ekp.mapper.EkpBankPayTaskMapper">

  <resultMap id="ekpBankPayTaskMap" type="com.yifu.cloud.plus.v1.ekp.entity.EkpBankPayTask">
    <id property="fdId" column="fd_id"/>
    <result property="fdCustomerName" column="fd_customer_name"/>
    <result property="fdProjectName" column="fd_project_name"/>
    <result property="fdProjectCode" column="fd_project_code"/>
    <result property="fdProvince" column="fd_province"/>
    <result property="fdCity" column="fd_city"/>
    <result property="fdTown" column="fd_town"/>
    <result property="fdMoney" column="fd_money"/>
    <result property="fdPayType" column="fd_pay_type"/>
    <result property="fdBankName" column="fd_bank_name"/>
    <result property="fdBankNo" column="fd_bank_no"/>
    <result property="fdBankAccount" column="fd_bank_account"/>
    <result property="fdCustomerServer" column="fd_customer_server"/>
    <result property="fdCreater" column="fd_creater"/>
    <result property="fdGrantStatus" column="fd_grant_status"/>
    <result property="fdSubmitCashier" column="fd_submit_cashier"/>
    <result property="fdCreateTime" column="fd_create_time"/>
    <result property="fdSettlementNo" column="fd_settlement_no"/>
    <result property="fdSettlementId" column="fd_settlement_id"/>
    <result property="fdFailHandleStatus" column="fd_fail_handle_status"/>
    <result property="fdAttaId" column="fd_atta_id"/>
    <result property="fdAttaName" column="fd_atta_name"/>
    <result property="fdAttaSrc" column="fd_atta_src"/>
    <result property="fdDownloadNum" column="fd_download_num"/>
    <result property="fdFailNum" column="fd_fail_num"/>
    <result property="fdGrantNum" column="fd_grant_num"/>

	  <result property="fdWxNo" column="fd_wx_no"/>
	  <result property="fdMdCode" column="fd_md_dcode"/>
	  <result property="fdErrorMsg" column="fd_error_msg"/>
  </resultMap>
    <sql id="Base_Column_List">
                a.fd_id,
                a.fd_customer_name,
                a.fd_project_name,
                a.fd_project_code,
                a.fd_province,
                a.fd_city,
                a.fd_town,
                a.fd_money,
                a.fd_pay_type,
                a.fd_bank_name,
                a.fd_bank_no,
                a.fd_bank_account,
                a.fd_customer_server,
                a.fd_creater,
                a.fd_grant_status,
                a.fd_submit_cashier,
                a.fd_create_time,
                a.fd_settlement_no,
                a.fd_settlement_id,
                a.fd_fail_handle_status,
                a.fd_atta_id,
                a.fd_atta_name,
                a.fd_atta_src,
                a.fd_download_num,
                a.fd_fail_num,
                a.fd_grant_num,
                a.fd_wx_no,
                a.fd_md_dcode,
                a.fd_error_msg
    </sql>

	<!-- 获取发放中的主表，查询结果 -->
	<select id="getEkpBankMainByNeedResultMain" resultType="com.yifu.cloud.plus.v1.ekp.vo.EkpBankResultVo">
		select a.fd_id fdId,a.fd_wx_no fdWxNo
		     ,count(d.fd_id) num,a.fd_bank_name fdBankName,a.fd_bank_no fdBankNo,a.fd_bank_account fdBankAccount
			,a.fd_grant_num fdGrantNum,a.fd_atta_src fdAttaSrc
		from ekp_bank_pay_task a left join ekp_bank_grant_detail d on a.fd_id = d.fd_parent_id
		where a.fd_grant_status = '发放中' and a.fd_pay_type = #{typeName}
		GROUP BY a.fd_id
	</select>

	<!-- 获取发放中的明细表，查询结果 -->
	<select id="getEkpBankMainByNeedResultDetail" resultType="com.yifu.cloud.plus.v1.ekp.vo.EkpBankResultVo">
		select d.fd_id fdId,d.fd_wx_no fdWxNo,d.fd_parent_id fdParentId,d.fd_fail_num fdFailNum,d.fd_salary_id fdSalaryId
		     ,'1' num,a.fd_bank_name fdBankName,a.fd_bank_no fdBankNo,a.fd_bank_account fdBankAccount,d.fd_payee_name fdPayeeName
			,d.fd_grant_num fdGrantNum,d.fd_recipient_bank fdRecipientBank,d.fd_atta_src fdAttaSrc,d.fd_money fdMoney
		from ekp_bank_grant_detail d left join ekp_bank_pay_task a on a.fd_id = d.fd_parent_id
		where a.fd_grant_status = '已发放' and d.fd_grant_status = '发放失败' and d.fd_handle_status = '发放中' and a.fd_pay_type = #{typeName}
	</select>

	<!-- 获取发放中的主表，查询结果 -->
	<select id="getEkpBankMainByNeedResultMainByOther" resultType="com.yifu.cloud.plus.v1.ekp.vo.EkpBankResultVo">
		select a.fd_id fdId,a.fd_wx_no fdWxNo
		     ,count(d.fd_id) num,a.fd_bank_name fdBankName,a.fd_bank_no fdBankNo,a.fd_bank_account fdBankAccount
			,a.fd_grant_num fdGrantNum,a.fd_atta_src fdAttaSrc,a.fd_pay_type fdPayType
		from ekp_bank_pay_task a left join ekp_bank_grant_detail d on a.fd_id = d.fd_parent_id
		where a.fd_grant_status = '发放中' and a.fd_pay_type in ("非扣税","报销")
		GROUP BY a.fd_id
	</select>

	<!-- 获取发放中的明细表，查询结果 -->
	<select id="getEkpBankMainByNeedResultDetailByOther" resultType="com.yifu.cloud.plus.v1.ekp.vo.EkpBankResultVo">
		select d.fd_id fdId,d.fd_wx_no fdWxNo,d.fd_parent_id fdParentId,d.fd_fail_num fdFailNum,d.fd_salary_id fdSalaryId
		     ,'1' num,a.fd_bank_name fdBankName,a.fd_bank_no fdBankNo,a.fd_bank_account fdBankAccount,d.fd_payee_name fdPayeeName
			,d.fd_grant_num fdGrantNum,d.fd_recipient_bank fdRecipientBank,d.fd_atta_src fdAttaSrc,d.fd_money fdMoney,a.fd_pay_type fdPayType
		from ekp_bank_grant_detail d left join ekp_bank_pay_task a on a.fd_id = d.fd_parent_id
		where a.fd_grant_status = '已发放' and d.fd_grant_status = '发放失败' and d.fd_handle_status = '发放中' and a.fd_pay_type in ("非扣税","报销")
	</select>



</mapper>
