ConsultTeamDao.java 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. /*******************************************************************************
  2. * Copyright (c) 2005, 2014 springside.github.io
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. *******************************************************************************/
  6. package com.yihu.wlyy.repository.consult;
  7. import org.springframework.data.domain.Page;
  8. import org.springframework.data.domain.PageRequest;
  9. import org.springframework.data.domain.Pageable;
  10. import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
  11. import org.springframework.data.jpa.repository.Modifying;
  12. import org.springframework.data.jpa.repository.Query;
  13. import org.springframework.data.repository.PagingAndSortingRepository;
  14. import com.yihu.wlyy.entity.consult.ConsultTeam;
  15. import java.util.List;
  16. public interface ConsultTeamDao extends PagingAndSortingRepository<ConsultTeam, Long>, JpaSpecificationExecutor<ConsultTeam> {
  17. // 根據consult查詢咨询记录
  18. ConsultTeam findByConsult(String consult);
  19. @Query("select a from ConsultTeam a where a.patient = ?1 and a.del = '1' and a.status = 0")
  20. List<ConsultTeam> findUnfinishedConsult(String patient);
  21. // 统计未完成的数量
  22. @Query("select count(1) from ConsultTeam a where a.patient = ?1 and a.status = 0 and a.del = '1'and a.type=?2")
  23. int countByPatient(String patient,Integer signType);
  24. // 被指定且未结束列表
  25. @Query("select a from ConsultTeam a, ConsultTeamDoctor b where a.consult = b.consult and b.to = ?1 and a.del = '1' and b.del = '1'")
  26. Page<ConsultTeam> findDoctorList(String doctor, Pageable pageRequest);
  27. // 被指定且未结束列表
  28. @Query("select a from ConsultTeam a, ConsultTeamDoctor b where a.consult = b.consult and b.to = ?1 and a.id < ?2 and a.del = '1' and b.del = '1'")
  29. Page<ConsultTeam> findDoctorList(String doctor, long id, Pageable pageRequest);
  30. // 被指定且未结束列表
  31. @Query("select a from ConsultTeam a, ConsultTeamDoctor b where a.consult = b.consult and b.to = ?1 and a.status = 0 and a.del = '1' and b.del = '1'")
  32. Page<ConsultTeam> findDoctorPointList(String doctor, Pageable pageRequest);
  33. // 被指定且未结束列表
  34. @Query("select a from ConsultTeam a, ConsultTeamDoctor b where a.consult = b.consult and b.to = ?1 and a.id < ?2 and a.status = 0 and a.del = '1' and b.del = '1'")
  35. Page<ConsultTeam> findDoctorPointList(String doctor, long id, Pageable pageRequest);
  36. // 医生参与且未结束列表
  37. @Query("select a from ConsultTeam a, ConsultTeamDoctor b where a.consult = b.consult and b.to = ?1 and a.status = 0 and b.reply = 1 and a.del = '1' and b.del = '1'")
  38. Page<ConsultTeam> findDoctorJoinList(String doctor, Pageable pageRequest);
  39. @Query("select a from ConsultTeam a, ConsultTeamDoctor b where a.consult = b.consult and b.to = ?1 and a.id < ?2 and a.status = 0 and b.reply = 1 and a.del = '1' and b.del = '1'")
  40. Page<ConsultTeam> findDoctorJoinList(String doctor, long id, Pageable pageRequest);
  41. // 医生参与并已结束列表
  42. @Query("select a from ConsultTeam a, ConsultTeamDoctor b where a.consult = b.consult and b.to = ?1 and a.status = 1 and a.del = '1' and b.del = '1'")
  43. Page<ConsultTeam> findDoctorFinishList(String doctor, Pageable pageRequest);
  44. @Query("select a from ConsultTeam a, ConsultTeamDoctor b where a.consult = b.consult and b.to = ?1 and a.id < ?2 and a.status = 1 and a.del = '1' and b.del = '1'")
  45. Page<ConsultTeam> findDoctorFinishList(String doctor, long id, Pageable pageRequest);
  46. // 医生关闭三师咨询
  47. @Modifying
  48. @Query("update ConsultTeam a set a.status = 1 where a.consult = ?1")
  49. int updateStatusByConsult(String consult);
  50. @Modifying
  51. @Query("update ConsultTeam a set a.doctorRead = 0 where a.consult = ?1")
  52. int updateReadedByConsult(String consult);
  53. /**
  54. * 解约时结束家庭咨询
  55. *
  56. * @param patient
  57. * @return
  58. */
  59. @Modifying
  60. @Query("update ConsultTeam a set a.status = 1 where a.patient =?1 and a.type = 2")
  61. int updateStatusByPatient(String patient);
  62. // 取消三师咨询
  63. @Modifying
  64. @Query("update ConsultTeam a set a.status = -1 where a.consult = ?1 and a.status <> 1")
  65. int cancel(String consult);
  66. // 患者咨询列表(未结束)
  67. @Query("select a from ConsultTeam a where a.patient = ?1 and a.status=0 and del = '1'")
  68. Page<ConsultTeam> findNotFinishedBypatient(String patient, Pageable pageRequest);
  69. @Query("select a from ConsultTeam a where a.patient = ?1 and a.id < ?2 and a.status=0 and del = '1'")
  70. Page<ConsultTeam> findNotFinishedBypatient(String patient, long id, Pageable pageRequest);
  71. // 患者咨询列表(已结束)
  72. @Query("select a from ConsultTeam a where a.patient=?1 and a.status=1 and del = '1'")
  73. Page<ConsultTeam> findFinishedBypatient(String patient, Pageable pageRequest);
  74. @Query("select a from ConsultTeam a where a.patient=?1 and a.id < ?2 and a.status=1 and del = '1'")
  75. Page<ConsultTeam> findFinishedBypatient(String patient, long id, Pageable pageRequest);
  76. // 患者咨询列表(已取消)
  77. @Query("select a from ConsultTeam a where a.patient=?1 and a.status=-1 and del = '1'")
  78. Page<ConsultTeam> findCancelBypatient(String patient, Pageable pageRequest);
  79. @Query("select a from ConsultTeam a where a.patient=?1 and a.id < ?2 and a.status=-1 and del = '1'")
  80. Page<ConsultTeam> findCancelBypatient(String patient, long id, Pageable pageRequest);
  81. // 医生未读数量+1
  82. @Modifying
  83. @Query("update ConsultTeam a set a.doctorRead = a.doctorRead + 1 where a.consult = ?1")
  84. int increaseDoctorRead(String consult);
  85. // 患者未读数量+1
  86. @Modifying
  87. @Query("update ConsultTeam a set a.patientRead = a.patientRead + 1 where a.consult = ?1")
  88. int increasePatientRead(String consult);
  89. // 清空医生未读数量
  90. @Modifying
  91. @Query("update ConsultTeam a set a.doctorRead = 0 where a.consult = ?1")
  92. int clearDoctorRead(String consult);
  93. // 清空患者未读数量
  94. @Modifying
  95. @Query("update ConsultTeam a set a.patientRead = 0 where a.consult = ?1")
  96. int clearPatientRead(String consult);
  97. // 更新患者评价标识
  98. @Modifying
  99. @Query("update ConsultTeam a set a.commentContent = ?2, a.commentStar = ?3 where a.consult = ?4")
  100. int updateComment(String commentContent, double commentStar, String consult);
  101. // 查询医生所有未读的消息总数
  102. @Query("SELECT SUM(a.doctorRead) FROM ConsultTeam a, ConsultTeamDoctor b WHERE a.consult = b.consult AND b.to = ?1 AND a.del = '1' AND a.status = 0")
  103. int amountAllDoctorUnread(String doctor);
  104. // 查询带未读数量的所有健康咨询列表
  105. @Query("SELECT a FROM ConsultTeam a, ConsultTeamDoctor b WHERE a.consult = b.consult AND b.to = ?1 AND a.status = 0 and a.type< 3")
  106. Page<ConsultTeam> findListByUnreadDoctor(String doctor, Pageable pageRequest);
  107. // 查询带未读数量的所有健康咨询列表
  108. @Query("SELECT a FROM ConsultTeam a, ConsultTeamDoctor b WHERE a.consult = b.consult AND b.to = ?1 and a.id < ?2 AND a.status = 0 and a.type<3")
  109. Page<ConsultTeam> findListByUnreadDoctor(String doctor, long id, Pageable pageRequest);
  110. //找出当日的咨询量
  111. @Query("SELECT a FROM ConsultTeam a WHERE a.type=2 and unix_timestamp(a.czrq)>=unix_timestamp(?1) and unix_timestamp(a.czrq)<unix_timestamp(?2) ")
  112. List<ConsultTeam> findByCzrqyYesterday(String yesterday,String now);
  113. //查找
  114. @Query("SELECT a FROM ConsultTeam a WHERE a.patient=?1 and a.status=0 and a.del=1")
  115. ConsultTeam findFamousConsultByPatient(String uid);
  116. //名医咨询 -全部
  117. @Query("select a from ConsultTeam a, ConsultTeamDoctor b where a.consult = b.consult and a.type=6 and b.to = ?1 and a.id < ?2 and a.del = '1' and b.del = '1'")
  118. Page<ConsultTeam> findFamousDoctorAllList(String uid, long id, Pageable pageRequest);
  119. //名医咨询 -全部
  120. @Query("select a from ConsultTeam a, ConsultTeamDoctor b where a.consult = b.consult and a.type=6 and b.to = ?1 and a.del = '1' and b.del = '1'")
  121. Page<ConsultTeam> findFamousDoctorAllList(String uid, Pageable pageRequest);
  122. //名医咨询 -全部 带symptoms
  123. @Query("select a from ConsultTeam a, ConsultTeamDoctor b where a.consult = b.consult and a.type=6 and b.to = ?1 and a.id < ?2 and a.symptoms like ?3 and a.del = '1' and b.del = '1'")
  124. Page<ConsultTeam> findFamousDoctorAllList(String uid, long id,String title, Pageable pageRequest);
  125. //名医咨询 -全部 带symptoms
  126. @Query("select a from ConsultTeam a, ConsultTeamDoctor b where a.consult = b.consult and a.type=6 and b.to = ?1 and a.symptoms like ?2 and a.del = '1' and b.del = '1'")
  127. Page<ConsultTeam> findFamousDoctorAllList(String uid,String title, Pageable pageRequest);
  128. //名医咨询 -根据status
  129. @Query("select a from ConsultTeam a, ConsultTeamDoctor b where a.consult = b.consult and a.type=6 and b.to = ?1 and a.id < ?2 and a.status = ?3 and a.del = '1' and b.del = '1'")
  130. Page<ConsultTeam> findFamousDoctorDoingList(String uid, long id,Integer type, Pageable pageRequest);
  131. //名医咨询 -根据status
  132. @Query("select a from ConsultTeam a, ConsultTeamDoctor b where a.consult = b.consult and a.type=6 and b.to = ?1 and a.status = ?2 and a.del = '1' and b.del = '1'")
  133. Page<ConsultTeam> findFamousDoctorDoingList(String uid,Integer type, Pageable pageRequest);
  134. //名医咨询 -根据status 带symptoms
  135. @Query("select a from ConsultTeam a, ConsultTeamDoctor b where a.consult = b.consult and a.type=6 and b.to = ?1 and a.id < ?2 and a.symptoms like ?3 and a.status = ?4 and a.del = '1' and b.del = '1'")
  136. Page<ConsultTeam> findFamousDoctorDoingList(String uid, long id,String title,Integer type, Pageable pageRequest);
  137. //名医咨询 -根据status 带symptoms
  138. @Query("select a from ConsultTeam a, ConsultTeamDoctor b where a.consult = b.consult and a.type=6 and b.to = ?1 and a.symptoms like ?2 and a.status = ?3 and a.del = '1' and b.del = '1'")
  139. Page<ConsultTeam> findFamousDoctorDoingList(String uid,String title,Integer type, Pageable pageRequest);
  140. }