DocumentRepository.java 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. package com.loan.system.repository;
  2. import com.loan.system.domain.dto.DocumentDTO;
  3. import com.loan.system.domain.dto.query.DocumentQueryDTO;
  4. import com.loan.system.domain.entity.DictBusinessType;
  5. import com.loan.system.domain.entity.Document;
  6. import com.loan.system.domain.vo.DocumentVO;
  7. import org.springframework.data.domain.Page;
  8. import org.springframework.data.domain.Pageable;
  9. import org.springframework.data.jpa.repository.JpaRepository;
  10. import org.springframework.data.jpa.repository.Modifying;
  11. import org.springframework.data.jpa.repository.Query;
  12. import org.springframework.transaction.annotation.Transactional;
  13. import java.util.List;
  14. /**
  15. * @author EdwinXu
  16. * @date 2020/9/2 - 15:35
  17. * @Description
  18. */
  19. public interface DocumentRepository extends JpaRepository<Document,Long> {
  20. List<Document> findByCaseId(Long caseId);
  21. @Query("select d from Document d where d.id = ?1 and d.isDelete =?2")
  22. Document findByDocumentIdAndIsDelete(Long signId, Boolean isDelete);
  23. @Transactional
  24. @Modifying
  25. @Query("UPDATE Document d SET " +
  26. "d.ownerId = CASE WHEN :#{#document.ownerId} IS NOT NULL THEN :#{#document.ownerId} ELSE d.ownerId END, " +
  27. "d.docType = CASE WHEN :#{#document.docType} IS NOT NULL THEN :#{#document.docType} ELSE d.docType END, " +
  28. "d.filePath = CASE WHEN :#{#document.filePath} IS NOT NULL THEN :#{#document.filePath} ELSE d.filePath END, " +
  29. "d.fileName = CASE WHEN :#{#document.fileName} IS NOT NULL THEN :#{#document.fileName} ELSE d.fileName END, " +
  30. "d.fileSize = CASE WHEN :#{#document.fileSize} IS NOT NULL THEN :#{#document.fileSize} ELSE d.fileSize END ," +
  31. "d.updateTime = CASE WHEN :#{#document.updateTime} IS NOT NULL THEN :#{#document.updateTime} ELSE d.updateTime END " +
  32. "WHERE d.caseId = :caseId AND d.dictType = :dictType")
  33. void updateByCaseIdAndDictType(Long caseId, String dictType, Document document);
  34. @Transactional
  35. @Modifying
  36. @Query("DELETE FROM Document d WHERE d.caseId = :caseId AND d.dictType = :fileType")
  37. void deleteFileByCaseIdAndDictType(Long caseId, String fileType);
  38. @Query("select d from Document d where d.dictType in ?1 and d.caseId = ?2 and d.isDelete = ?3")
  39. List<Document> findByFileTypesAndCaseIdAndIsDelete(List<String> fileTypes, Long caseId, boolean b);
  40. @Query("select d from Document d where d.isDelete = ?1")
  41. Page<Document> findAllAndIdDelete(boolean b , Pageable pageable );
  42. @Transactional
  43. @Modifying
  44. @Query("update Document d set d.isDelete = false WHERE d.id in ?1")
  45. void deleteByIds(List<Long> ids);
  46. @Query("SELECT lc FROM Document lc WHERE " +
  47. "(:#{#query.caseId} IS NULL OR lc.caseId = :#{#query.caseId}) AND " +
  48. "(:#{#query.docType} IS NULL OR lc.docType = :#{#query.docType}) AND " +
  49. "(:#{#query.originName} IS NULL OR lc.originName like %:#{#query.originName}%) AND " +
  50. "(:#{#query.dictType} IS NULL OR lc.dictType = :#{#query.dictType} AND " +
  51. "lc.isDelete = false)")
  52. Page<Document> findByQuery(DocumentQueryDTO query, Pageable pageable);
  53. }