ContractRepository.java 3.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. package com.loan.system.repository;
  2. import com.loan.system.domain.entity.Contract;
  3. import com.loan.system.domain.vo.ContractVO;
  4. import org.springframework.data.jpa.repository.JpaRepository;
  5. import org.springframework.data.jpa.repository.Modifying;
  6. import org.springframework.data.jpa.repository.Query;
  7. import org.springframework.transaction.annotation.Transactional;
  8. import java.util.Collection;
  9. import java.util.List;
  10. /**
  11. * @author EdwinXu
  12. * @date 2020/9/2 - 15:35
  13. * @Description
  14. */
  15. public interface ContractRepository extends JpaRepository<Contract,Long> {
  16. boolean existsByCaseIdAndBusinessAttrAndIsDelete(Long caseId, String businessAttr, boolean b);
  17. @Query("SELECT c FROM Contract c WHERE c.caseId = :caseId AND c.businessAttr = :businessAttr AND c.isDelete = :isDelete")
  18. Contract findByCaseIdAndBusinessAttrAndIsDelete(Long caseId, String businessAttr, boolean b);
  19. @Transactional
  20. @Modifying
  21. @Query("UPDATE Contract c SET " +
  22. "c.businessAttr = CASE WHEN :#{#contract.businessAttr} IS NOT NULL THEN :#{#contract.businessAttr} ELSE c.businessAttr END, " +
  23. "c.caseId = CASE WHEN :#{#contract.caseId} IS NOT NULL THEN :#{#contract.caseId} ELSE c.caseId END, " +
  24. "c.customerId = CASE WHEN :#{#contract.customerId} IS NOT NULL THEN :#{#contract.customerId} ELSE c.customerId END, " +
  25. "c.contractNo = CASE WHEN :#{#contract.contractNo} IS NOT NULL THEN :#{#contract.contractNo} ELSE c.contractNo END, " +
  26. "c.contractName = CASE WHEN :#{#contract.contractName} IS NOT NULL THEN :#{#contract.contractName} ELSE c.contractName END, " +
  27. "c.contractVersion = CASE WHEN :#{#contract.contractVersion} IS NOT NULL THEN :#{#contract.contractVersion} ELSE c.contractVersion END, " +
  28. "c.contractAmount = CASE WHEN :#{#contract.contractAmount} IS NOT NULL THEN :#{#contract.contractAmount} ELSE c.contractAmount END, " +
  29. "c.interestRate = CASE WHEN :#{#contract.interestRate} IS NOT NULL THEN :#{#contract.interestRate} ELSE c.interestRate END, " +
  30. "c.loanPeriod = CASE WHEN :#{#contract.loanPeriod} IS NOT NULL THEN :#{#contract.loanPeriod} ELSE c.loanPeriod END, " +
  31. "c.content = CASE WHEN :#{#contract.content} IS NOT NULL THEN :#{#contract.content} ELSE c.content END, " +
  32. "c.signedByCustomer = CASE WHEN :#{#contract.signedByCustomer} IS NOT NULL THEN :#{#contract.signedByCustomer} ELSE c.signedByCustomer END, " +
  33. "c.sifnedId = CASE WHEN :#{#contract.sifnedId} IS NOT NULL THEN :#{#contract.sifnedId} ELSE c.sifnedId END, " +
  34. "c.signedTime = CASE WHEN :#{#contract.signedTime} IS NOT NULL THEN :#{#contract.signedTime} ELSE c.signedTime END, " +
  35. "c.updateTime = CASE WHEN :#{#contract.updateTime} IS NOT NULL THEN :#{#contract.updateTime} ELSE c.updateTime END, " +
  36. "c.isDelete = CASE WHEN :isDelete IS NOT NULL THEN :isDelete ELSE c.isDelete END " +
  37. "WHERE c.id = :id and c.isDelete = :isDelete")
  38. void updateContractById(Long id, Contract contract, boolean isDelete);
  39. List<Contract> findByCaseIdAndIsDelete(Long caseId, boolean isDelete);
  40. @Transactional
  41. @Modifying
  42. @Query("UPDATE Contract c SET c.isPush = true WHERE c.id = :contractId")
  43. void updateIsPushById(Long contractId);
  44. @Query("SELECT c FROM Contract c WHERE c.caseId = ?1 AND c.isPush = ?2 AND c.isDelete = ?3 ")
  45. List<Contract> findByCaseIdAndIsPush(Long caseId,Boolean isPush,boolean isDelete);
  46. @Transactional
  47. @Modifying
  48. @Query("delete FROM Contract c WHERE c.caseId = ?1")
  49. void deleteAllByCaseId(Long caseID);
  50. @Transactional
  51. @Modifying
  52. @Query("UPDATE Contract c SET c.contractNo = ?2 WHERE c.id = ?1")
  53. void updateContractNoById(Long id, String contractNo);
  54. @Query("SELECT c FROM Contract c WHERE c.id = ?1")
  55. Contract findContractById(Long contractId);
  56. }