package com.yn.bftl.thirdparty.common.repository;

import com.yn.bftl.common.modules.subaccount.entity.Subaccount;
import com.yn.bftl.common.modules.subaccount.enums.SubaccountState;
import com.yn.bftl.common.modules.subaccount.enums.SubaccountType;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * 分账表Repository
 *
 * @author chendehuihuo
 * @date 2021/11/23
 **/
@Repository
public interface SubaccountRepository extends JpaRepository<Subaccount, Long> {

    Subaccount findFirstByShippingId(Long shippingId);

    Subaccount findFirstByShippingIdAndCompanyId(Long shippingId, Long companyId);

    Subaccount findFirstByShippingIdAndSubaccountState(Long shippingId, SubaccountState subaccountState);

    List<Subaccount> findAllBySubaccountState(SubaccountState subaccountState);

    Subaccount findFirstByBizOrderNo(String bizOrderNo);

    /**
     * 分账单-根据第三方分账单号查询
     *
     * @param externalId:第三方分账单号
     * @return 分账列表
     * @author huabiao
     * @create 2022/9/23  14:46
     */
    List<Subaccount> findAllByExternalId(String externalId);

    /**
     * 分账列表-根据订单查询
     *
     * @param orderId:订单ID
     * @return 分账记录数组
     * @author huabiao
     * @create 2022/12/16  15:54
     */
    List<Subaccount> findAllByOrdersId(Long orderId);

    /**
     * 分账列表-根据订发货单查询
     *
     * @param shippingId:发货单ID
     * @return 分账记录数组
     * @author huabiao
     * @create 2022/12/16  15:54
     */
    List<Subaccount> findAllByShippingId(Long shippingId);

    /**
     * 分账列表-根据分账类型查询
     *
     * @param subaccountNo 分账单号
     * @return 分账记录
     * @author huabiao
     * @create 2023/3/22  17:05
     */
    Subaccount findBySubaccountNo(String subaccountNo);

    /**
     * 分账记录-根据订单ID和分账类型查询
     *
     * @param orderId        订单ID
     * @param subaccountType 分账类型
     * @return 分账记录
     * @author huabiao
     * @create 2023/3/22  17:35
     */
    Subaccount findByOrdersIdAndSubaccountType(Long orderId, SubaccountType subaccountType);

}
