CustomerOtherRepository.java 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. package com.loan.system.repository;
  2. import com.loan.system.domain.dto.CustomersOtherDTO;
  3. import com.loan.system.domain.entity.Customer;
  4. import com.loan.system.domain.entity.CustomersOther;
  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.data.repository.query.Param;
  9. import org.springframework.transaction.annotation.Transactional;
  10. import java.util.Collection;
  11. import java.util.List;
  12. /**
  13. * @author EdwinXu
  14. * @date 2020/9/2 - 15:35
  15. * @Description
  16. */
  17. public interface CustomerOtherRepository extends JpaRepository<CustomersOther,Long> {
  18. @Query("select c from CustomersOther c where c.idNumber = ?1 AND c.isDelete = ?2")
  19. CustomersOther findByIdNumberAndIsDelete(String idNumber, boolean isDelete);
  20. @Transactional
  21. @Modifying
  22. @Query("UPDATE CustomersOther c SET " +
  23. "c.name = CASE WHEN :#{#customersOtherDTO.name} IS NOT NULL THEN :#{#customersOtherDTO.name} ELSE c.name END, " +
  24. "c.idNumber = CASE WHEN :#{#customersOtherDTO.idNumber} IS NOT NULL THEN :#{#customersOtherDTO.idNumber} ELSE c.idNumber END, " +
  25. "c.mobile = CASE WHEN :#{#customersOtherDTO.mobile} IS NOT NULL THEN :#{#customersOtherDTO.mobile} ELSE c.mobile END " +
  26. "WHERE c.id = :id")
  27. void updateCustomerById(@Param("customersOtherDTO") CustomersOtherDTO customersOtherDTO, @Param("id") Long id);
  28. @Query("select c from CustomersOther c where c.id = ?1 and c.isDelete = ?2")
  29. CustomersOther findByCustomerOtherId(Long Id, boolean isDelete);
  30. List<CustomersOther> findByCaseIdAndIsDelete(Long caseId, boolean isDelete);
  31. @Transactional
  32. @Modifying
  33. @Query("DELETE FROM CustomersOther c WHERE c.caseId = ?1")
  34. void deleteAllByCaseId(Long caseId);
  35. }