ContractRepository.java 5.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. package com.loan.system.repository;
  2. import com.loan.system.domain.entity.Contract;
  3. import com.loan.system.domain.vo.ContractVO;
  4. import io.swagger.models.Contact;
  5. import org.springframework.data.jpa.repository.JpaRepository;
  6. import org.springframework.data.jpa.repository.Modifying;
  7. import org.springframework.data.jpa.repository.Query;
  8. import org.springframework.transaction.annotation.Transactional;
  9. import java.util.Collection;
  10. import java.util.List;
  11. /**
  12. * @author EdwinXu
  13. * @date 2020/9/2 - 15:35
  14. * @Description
  15. */
  16. public interface ContractRepository extends JpaRepository<Contract,Long> {
  17. boolean existsByCaseIdAndBusinessAttrAndIsDelete(Long caseId, String businessAttr, boolean b);
  18. @Query("SELECT c FROM Contract c WHERE c.caseId = :caseId AND c.businessAttr = :businessAttr AND c.isDelete = :isDelete")
  19. Contract findByCaseIdAndBusinessAttrAndIsDelete(Long caseId, String businessAttr, boolean b);
  20. @Transactional
  21. @Modifying
  22. @Query("UPDATE Contract c SET " +
  23. "c.businessAttr = CASE WHEN :#{#contract.businessAttr} IS NOT NULL THEN :#{#contract.businessAttr} ELSE c.businessAttr END, " +
  24. "c.caseId = CASE WHEN :#{#contract.caseId} IS NOT NULL THEN :#{#contract.caseId} ELSE c.caseId END, " +
  25. "c.customerId = CASE WHEN :#{#contract.customerId} IS NOT NULL THEN :#{#contract.customerId} ELSE c.customerId END, " +
  26. "c.contractNo = CASE WHEN :#{#contract.contractNo} IS NOT NULL THEN :#{#contract.contractNo} ELSE c.contractNo END, " +
  27. "c.contractName = CASE WHEN :#{#contract.contractName} IS NOT NULL THEN :#{#contract.contractName} ELSE c.contractName END, " +
  28. "c.contractVersion = CASE WHEN :#{#contract.contractVersion} IS NOT NULL THEN :#{#contract.contractVersion} ELSE c.contractVersion END, " +
  29. "c.contractAmount = CASE WHEN :#{#contract.contractAmount} IS NOT NULL THEN :#{#contract.contractAmount} ELSE c.contractAmount END, " +
  30. "c.interestRate = CASE WHEN :#{#contract.interestRate} IS NOT NULL THEN :#{#contract.interestRate} ELSE c.interestRate END, " +
  31. "c.loanPeriod = CASE WHEN :#{#contract.loanPeriod} IS NOT NULL THEN :#{#contract.loanPeriod} ELSE c.loanPeriod END, " +
  32. "c.content = CASE WHEN :#{#contract.content} IS NOT NULL THEN :#{#contract.content} ELSE c.content END, " +
  33. "c.signedByCustomer = CASE WHEN :#{#contract.signedByCustomer} IS NOT NULL THEN :#{#contract.signedByCustomer} ELSE c.signedByCustomer END, " +
  34. "c.signedId = CASE WHEN :#{#contract.signedId} IS NOT NULL THEN :#{#contract.signedId} ELSE c.signedId END, " +
  35. "c.signedTime = CASE WHEN :#{#contract.signedTime} IS NOT NULL THEN :#{#contract.signedTime} ELSE c.signedTime END, " +
  36. "c.updateTime = CASE WHEN :#{#contract.updateTime} IS NOT NULL THEN :#{#contract.updateTime} ELSE c.updateTime END, " +
  37. "c.isDelete = :isDelete " +
  38. "WHERE c.id = :id ")
  39. void updateContractById(Long id, Contract contract, boolean isDelete);
  40. List<Contract> findByCaseIdAndIsDelete(Long caseId, boolean isDelete);
  41. @Transactional
  42. @Modifying
  43. @Query("UPDATE Contract c SET c.isPush = true WHERE c.id = :contractId")
  44. void updateIsPushById(Long contractId);
  45. @Query("SELECT c FROM Contract c WHERE c.caseId = ?1 AND c.isPush = ?2 AND c.isDelete = ?3 ")
  46. List<Contract> findByCaseIdAndIsPush(Long caseId,Boolean isPush,boolean isDelete);
  47. @Transactional
  48. @Modifying
  49. @Query("update Contract c set c.isDelete= true WHERE c.caseId = ?1")
  50. void deleteAllByCaseId(Long caseID);
  51. @Transactional
  52. @Modifying
  53. @Query("UPDATE Contract c SET c.contractNo = ?2 WHERE c.id = ?1")
  54. void updateContractNoById(Long id, String contractNo);
  55. @Query("SELECT c FROM Contract c WHERE c.id = ?1")
  56. Contract findContractById(Long contractId);
  57. @Transactional
  58. @Modifying
  59. @Query("UPDATE Contract c SET c.signedByCustomer = false WHERE c.id = ?1")
  60. void updateSignedCustomerById(Long contractId);
  61. @Transactional
  62. @Modifying
  63. @Query("UPDATE Contract c set c.signedId = null WHERE c.signedId = ?1")
  64. void deleteSigned(Long signedId);
  65. @Transactional
  66. @Modifying
  67. @Query("UPDATE Contract c SET " +
  68. "c.isCleared = CASE WHEN :isCleared IS NOT NULL THEN :isCleared ELSE c.isCleared END," +
  69. "c.interestAmount = CASE WHEN :interest IS NOT NULL THEN :interest ELSE c.interestAmount END," +
  70. "c.financeUserId = CASE WHEN :currentId IS NOT NULL THEN :currentId ELSE c.financeUserId END" +
  71. " where c.id= :contractId and c.isDelete =:isDelete")
  72. void updateRepayById(boolean isCleared, Double interest, Long currentId, Long contractId, boolean isDelete);
  73. @Query("SELECT c.interestAmount FROM Contract c WHERE c.caseId = ?1 AND c.isDelete = ?2")
  74. List<Double> findIntersetByCaseIdAndIsDelete(Long caseId, boolean b);
  75. @Query("select c from Contract c where c.caseId= ?1 and c.isDelete = ?2")
  76. List<Contract> findByCaseIdAndIsDelete2(Long caseId, boolean b);
  77. }