package com.loan.system.repository;

import com.loan.system.domain.dto.ApprovalRecordDTO;
import com.loan.system.domain.entity.Repayment;
import com.loan.system.domain.entity.RepaymentRecord;
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 RepaymentRecordRepository extends JpaRepository<RepaymentRecord,Long> {

    List<RepaymentRecord> findByRepaymentIdAndIsDelete(Long repaymentId, boolean isDelete);

    @Transactional
    @Modifying
    @Query("update RepaymentRecord r set r.approvalComment = ?1," +
            "r.approvalDecision=?2," +
            "r.approvalUserId= ?3 where r.id = ?4")
    void updateApprovalByRepaymentId(String comments, String decision, Long approvalId,Long id);

    @Transactional
    @Modifying
    @Query("update RepaymentRecord r set r.amount = ?1," +
            "r.repayBank = ?2, r.repayLocation = ?3 ,r.repayAccount = ?4 where  r.id = ?5")
    void updateRepaymentRecordById(Double amount, String repayBank, String repayLocation, String repayAccount, Long recordId);
}