CollateralRepository.java 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. package com.loan.system.repository;
  2. import com.loan.system.domain.entity.Collateral;
  3. import org.springframework.data.jpa.repository.JpaRepository;
  4. import org.springframework.data.jpa.repository.Modifying;
  5. import org.springframework.data.jpa.repository.Query;
  6. import org.springframework.transaction.annotation.Transactional;
  7. import java.util.List;
  8. /**
  9. * @author EdwinXu
  10. * @date 2020/9/2 - 15:35
  11. * @Description
  12. */
  13. public interface CollateralRepository extends JpaRepository<Collateral,Long> {
  14. List<Collateral> findByCaseIdAndIsDelete(Long caseId, boolean isDelete);
  15. @Transactional
  16. @Modifying
  17. @Query("UPDATE Collateral c SET " +
  18. "c.caseId = CASE WHEN :#{#collateral.caseId} IS NOT NULL THEN :#{#collateral.caseId} ELSE c.caseId END, " +
  19. "c.contractId = CASE WHEN :#{#collateral.contractId} IS NOT NULL THEN :#{#collateral.contractId} ELSE c.contractId END, " +
  20. "c.collateralName = CASE WHEN :#{#collateral.collateralName} IS NOT NULL THEN :#{#collateral.collateralName} ELSE c.collateralName END, " +
  21. "c.collateralType = CASE WHEN :#{#collateral.collateralType} IS NOT NULL THEN :#{#collateral.collateralType} ELSE c.collateralType END, " +
  22. "c.ownerCustomerId = CASE WHEN :#{#collateral.ownerCustomerId} IS NOT NULL THEN :#{#collateral.ownerCustomerId} ELSE c.ownerCustomerId END, " +
  23. "c.allocatedAmount = CASE WHEN :#{#collateral.allocatedAmount} IS NOT NULL THEN :#{#collateral.allocatedAmount} ELSE c.allocatedAmount END, " +
  24. "c.address = CASE WHEN :#{#collateral.address} IS NOT NULL THEN :#{#collateral.address} ELSE c.address END, " +
  25. "c.currentAddress = CASE WHEN :#{#collateral.currentAddress} IS NOT NULL THEN :#{#collateral.currentAddress} ELSE c.currentAddress END, " +
  26. "c.evalPrice = CASE WHEN :#{#collateral.evalPrice} IS NOT NULL THEN :#{#collateral.evalPrice} ELSE c.evalPrice END, " +
  27. "c.isInvolvedInLitigation = CASE WHEN :#{#collateral.isInvolvedInLitigation} IS NOT NULL THEN :#{#collateral.isInvolvedInLitigation} ELSE c.isInvolvedInLitigation END, " +
  28. "c.staus = CASE WHEN :#{#collateral.staus} IS NOT NULL THEN :#{#collateral.staus} ELSE c.staus END, " +
  29. "c.updateTime = CASE WHEN :#{#collateral.updateTime} IS NOT NULL THEN :#{#collateral.updateTime} ELSE c.updateTime END, " +
  30. "c.isDelete = CASE WHEN :isDelete IS NOT NULL THEN :isDelete ELSE c.isDelete END " +
  31. "WHERE c.id = :id and c.isDelete = false")
  32. void updateCollateralById(Long id, Collateral collateral, boolean isDelete);
  33. @Query("SELECT c FROM Collateral c WHERE c.collateralName = ?1 AND c.caseId = ?2 AND c.isDelete = ?3")
  34. Collateral findCollateralByNameAndCaseId(String collateralName, Long caseId, boolean isDelete);
  35. @Transactional
  36. @Modifying
  37. @Query("delete FROM Collateral c WHERE c.caseId = ?1")
  38. void deleteAllByCaseId(Long caseId);
  39. //逻辑删除
  40. @Modifying
  41. @Transactional
  42. @Query("UPDATE Collateral c SET c.isDelete = true , c.updateTime = CURRENT_TIMESTAMP WHERE c.id = ?1")
  43. void deleteById(Long id);
  44. @Modifying
  45. @Transactional
  46. @Query("UPDATE Collateral c SET c.staus = ?2 ,c.updateTime = CURRENT_TIMESTAMP WHERE c.id = ?1 And c.isDelete= false ")
  47. void updateCollateralStatusByid(Long id, String status);
  48. @Query("SELECT c FROM Collateral c WHERE c.id = ?1 And c.isDelete = false")
  49. Collateral findCollateralById(Long id);
  50. }