package com.loan.system.repository;

import com.loan.system.domain.entity.Collateral;
import com.loan.system.domain.entity.Repayment;
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 RepaymentRepository extends JpaRepository<Repayment,Long> {

    @Query("select r from Repayment r where r.caseId = ?1 and r.isDelete = ?2")
    Repayment findByCaseIdAndIsDelete(Long caseId, boolean isDelete);

    @Transactional
    @Modifying
    @Query("update Repayment r set r.approvalUserId = ?1 where r.caseId = ?2")
    void updateApprovalUserByCaseId(Long currentId, Long caseId);

    @Transactional
    @Modifying
    @Query("update Repayment r set r.isCleared = ?1 where r.caseId = ?2")
    void updateIsClearedByCaseId(boolean isClear, Long caseId);

    @Transactional
    @Modifying
    @Query("update Repayment r set r.interest = ?1 , r.confirmedId = ?2 , r.confirmedAt = ?3 where  r.caseId = ?4")
    void updateIntersetsByCaseId(Double interest, Long conformId, String conformTime,Long caseId);

    @Transactional
    @Modifying
    @Query("update Repayment r set r.repayWay = ?1 where r.caseId = ?2")
    void updateRepayWayByCaseId(String repayWay, Long caseId);
}