package com.loan.system.repository;

import com.loan.system.domain.entity.Collateral;
import com.loan.system.domain.entity.Disbursement;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author EdwinXu
 * @date 2020/9/2 - 15:35
 * @Description
 */
public interface DisbursementRepository extends JpaRepository<Disbursement,Long> {

    @Query("select d from Disbursement d where d.caseId = ?1")
    Disbursement findDisbursementDetailsById(Long caseId);

    @Query("select d from Disbursement d where d.caseId = ?1 and d.isDelete = ?2")
    Disbursement getDisbursementByCaseIdAndIsDelete(Long caseId, boolean isDelete);

    @Transactional
    @Modifying
    @Query("update Disbursement d set d.payoutApproveUserId = ?1 where d.id = ?2")
    void updateApprovalUserById(Long currentId, Long id);

    @Transactional
    @Modifying
    @Query("update Disbursement d set d.payoutOperatorUserId = ?1 where d.id = ?2")
    void updateOperationUserById(Long currentId, Long id);

    @Transactional
    @Modifying
    @Query("update Disbursement d set d.comments = ?1 where d.id = ?2")
    void updateCommentsById(String comments, Long id);
}