ConsultTeamDao.java 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  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.domain.jaxb.PageAdapter;
  11. import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
  12. import org.springframework.data.jpa.repository.Modifying;
  13. import org.springframework.data.jpa.repository.Query;
  14. import org.springframework.data.repository.PagingAndSortingRepository;
  15. import com.yihu.wlyy.entity.consult.ConsultTeam;
  16. import java.util.List;
  17. public interface ConsultTeamDao extends PagingAndSortingRepository<ConsultTeam, Long>, JpaSpecificationExecutor<ConsultTeam> {
  18. // 根據consult查詢咨询记录
  19. ConsultTeam findByConsult(String consult);
  20. @Query("select a from ConsultTeam a where a.patient = ?1 and a.del = '1' and a.status = 0")
  21. List<ConsultTeam> findUnfinishedConsult(String patient);
  22. // 统计未完成的数量
  23. @Query("select count(1) from ConsultTeam a where a.patient = ?1 and a.status = 0 and a.del = '1'and a.type=?2")
  24. int countByPatient(String patient,Integer signType);
  25. // 被指定且未结束列表
  26. @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' and a.type<3")
  27. Page<ConsultTeam> findDoctorList(String doctor, Pageable pageRequest);
  28. // 被指定且未结束列表
  29. @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' and a.type<3")
  30. Page<ConsultTeam> findDoctorList(String doctor, long id, Pageable pageRequest);
  31. // 被指定且未结束列表
  32. @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' and a.type<3 ")
  33. Page<ConsultTeam> findDoctorPointList(String doctor, Pageable pageRequest);
  34. // 被指定且未结束列表
  35. @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' and a.type<3 ")
  36. Page<ConsultTeam> findDoctorPointList(String doctor, long id, Pageable pageRequest);
  37. // 被指定且未结束列表
  38. @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' and (a.type = 1 or a.type = 2 or a.type = 6) ")
  39. Page<ConsultTeam> findDoctorAllList(String doctor, long id, Pageable pageRequest);
  40. // 被指定且未结束列表
  41. @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' and (a.type = 1 or a.type = 2 or a.type = 6) ")
  42. Page<ConsultTeam> findDoctorAllList(String doctor, Pageable pageRequest);
  43. // 医生参与且未结束列表
  44. @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' and a.type<3")
  45. Page<ConsultTeam> findDoctorJoinList(String doctor, Pageable pageRequest);
  46. @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' and a.type<3 ")
  47. Page<ConsultTeam> findDoctorJoinList(String doctor, long id, Pageable pageRequest);
  48. // 医生参与并已结束列表
  49. @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' and a.type<3")
  50. Page<ConsultTeam> findDoctorFinishList(String doctor, Pageable pageRequest);
  51. @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' and a.type<3")
  52. Page<ConsultTeam> findDoctorFinishList(String doctor, long id, Pageable pageRequest);
  53. // 医生关闭三师咨询
  54. @Modifying
  55. @Query("update ConsultTeam a set a.status = 1 where a.consult = ?1")
  56. int updateStatusByConsult(String consult);
  57. @Modifying
  58. @Query("update ConsultTeam a set a.doctorRead = 0 where a.consult = ?1")
  59. int updateReadedByConsult(String consult);
  60. /**
  61. * 解约时结束家庭咨询
  62. *
  63. * @param patient
  64. * @return
  65. */
  66. @Modifying
  67. @Query("update ConsultTeam a set a.status = 1 where a.patient =?1 and a.type = 2")
  68. int updateStatusByPatient(String patient);
  69. // 取消三师咨询
  70. @Modifying
  71. @Query("update ConsultTeam a set a.status = -1 where a.consult = ?1 and a.status <> 1")
  72. int cancel(String consult);
  73. // 患者咨询列表(未结束)
  74. @Query("select a from ConsultTeam a where a.patient = ?1 and a.status=0 and del = '1'")
  75. Page<ConsultTeam> findNotFinishedBypatient(String patient, Pageable pageRequest);
  76. @Query("select a from ConsultTeam a where a.patient = ?1 and a.id < ?2 and a.status=0 and del = '1'")
  77. Page<ConsultTeam> findNotFinishedBypatient(String patient, long id, Pageable pageRequest);
  78. // 患者咨询列表(已结束)
  79. @Query("select a from ConsultTeam a where a.patient=?1 and a.status=1 and del = '1'")
  80. Page<ConsultTeam> findFinishedBypatient(String patient, Pageable pageRequest);
  81. @Query("select a from ConsultTeam a where a.patient=?1 and a.id < ?2 and a.status=1 and del = '1'")
  82. Page<ConsultTeam> findFinishedBypatient(String patient, long id, Pageable pageRequest);
  83. // 患者咨询列表(已取消)
  84. @Query("select a from ConsultTeam a where a.patient=?1 and a.status=-1 and del = '1'")
  85. Page<ConsultTeam> findCancelBypatient(String patient, Pageable pageRequest);
  86. @Query("select a from ConsultTeam a where a.patient=?1 and a.id < ?2 and a.status=-1 and del = '1'")
  87. Page<ConsultTeam> findCancelBypatient(String patient, long id, Pageable pageRequest);
  88. // 医生未读数量+1
  89. @Modifying
  90. @Query("update ConsultTeam a set a.doctorRead = a.doctorRead + 1 where a.consult = ?1")
  91. int increaseDoctorRead(String consult);
  92. // 患者未读数量+1
  93. @Modifying
  94. @Query("update ConsultTeam a set a.patientRead = a.patientRead + 1 where a.consult = ?1")
  95. int increasePatientRead(String consult);
  96. // 清空医生未读数量
  97. @Modifying
  98. @Query("update ConsultTeam a set a.doctorRead = 0 where a.consult = ?1")
  99. int clearDoctorRead(String consult);
  100. // 清空患者未读数量
  101. @Modifying
  102. @Query("update ConsultTeam a set a.patientRead = 0 where a.consult = ?1")
  103. int clearPatientRead(String consult);
  104. // 更新患者评价标识
  105. @Modifying
  106. @Query("update ConsultTeam a set a.commentContent = ?2, a.commentStar = ?3 where a.consult = ?4")
  107. int updateComment(String commentContent, double commentStar, String consult);
  108. // 查询医生所有未读的消息总数
  109. @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 AND a.type <> 6")
  110. int amountAllDoctorUnread(String doctor);
  111. // 查询医生所有未读的消息总数
  112. @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 AND a.type = 6")
  113. int amountAlFamouslDoctorUnread(String doctor);
  114. // 查询医生所有未读的消息总数
  115. @Query("SELECT a.name,b.czrq FROM ConsultTeam a, ConsultTeamDoctor b WHERE a.consult = b.consult AND b.to = ?1 AND a.del = '1' AND a.status = 0 AND a.type <> 6 order by b.czrq desc")
  116. Page<Object> AllDoctorUnreadLast(String doctor,Pageable pageRequest);
  117. // 查询医生所有未读的消息总数
  118. @Query("SELECT a.name,b.czrq FROM ConsultTeam a, ConsultTeamDoctor b WHERE a.consult = b.consult AND b.to = ?1 AND a.del = '1' AND a.status = 0 AND a.type = 6 order by b.czrq desc")
  119. Page<Object> AllDoctorFamousUnreadLast(String doctor,Pageable pageRequest);
  120. // 查询带未读数量的所有健康咨询列表
  121. @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")
  122. Page<ConsultTeam> findListByUnreadDoctor(String doctor, Pageable pageRequest);
  123. // 查询带未读数量的所有健康咨询列表
  124. @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")
  125. Page<ConsultTeam> findListByUnreadDoctor(String doctor, long id, Pageable pageRequest);
  126. //找出当日的咨询量
  127. @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) ")
  128. List<ConsultTeam> findByCzrqyYesterday(String yesterday,String now);
  129. //查找
  130. @Query("SELECT a FROM ConsultTeam a WHERE a.patient=?1 and a.status=0 and a.del=1 and a.type=6")
  131. ConsultTeam findFamousConsultByPatient(String uid);
  132. //名医咨询 -全部
  133. @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'")
  134. Page<ConsultTeam> findFamousDoctorAllList(String uid, long id, Pageable pageRequest);
  135. //名医咨询 -全部
  136. @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'")
  137. Page<ConsultTeam> findFamousDoctorAllList(String uid, Pageable pageRequest);
  138. //名医咨询 -全部 带symptoms
  139. @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'")
  140. Page<ConsultTeam> findFamousDoctorAllList(String uid, long id,String title, Pageable pageRequest);
  141. //名医咨询 -全部 带symptoms
  142. @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'")
  143. Page<ConsultTeam> findFamousDoctorAllList(String uid,String title, Pageable pageRequest);
  144. //名医咨询 -根据status
  145. @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'")
  146. Page<ConsultTeam> findFamousDoctorDoingList(String uid, long id,Integer type, Pageable pageRequest);
  147. //名医咨询 -根据status
  148. @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'")
  149. Page<ConsultTeam> findFamousDoctorDoingList(String uid,Integer type, Pageable pageRequest);
  150. //名医咨询 -根据status 带symptoms
  151. @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'")
  152. Page<ConsultTeam> findFamousDoctorDoingList(String uid, long id,String title,Integer type, Pageable pageRequest);
  153. //名医咨询 -根据status 带symptoms
  154. @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'")
  155. Page<ConsultTeam> findFamousDoctorDoingList(String uid,String title,Integer type, Pageable pageRequest);
  156. @Query("select a from ConsultTeam a where a.type=?3 and a.del = '1' and a.patient=?1 and a.doctor=?2 and a.status=0 ")
  157. ConsultTeam findByParientCodeAndSignTypeAndDoctor(String patientCode, String doctor, int s);
  158. //名医咨询 -全部 带symptoms 未处理、未回复
  159. @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 = 0 and (a.doctorRead > 0 or b.reply <> 1) and a.del = '1' and b.del = '1'")
  160. Page<ConsultTeam> findFamousDoctorUnReplyReadList(String uid, long id,String title, Pageable pageRequest);
  161. //名医咨询 -全部 带symptoms 处理、未回复
  162. @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 = 0 and (a.doctorRead > 0 or b.reply <> 1) and a.del = '1' and b.del = '1'")
  163. Page<ConsultTeam> findFamousDoctorUnReplyReadList(String uid,String title, Pageable pageRequest);
  164. //名医咨询 -全部 处理、未回复
  165. @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 = 0 and (a.doctorRead > 0 or b.reply <> 1) and a.del = '1' and b.del = '1'")
  166. Page<ConsultTeam> findFamousDoctorUnReplyReadNoTitleList(String uid, long id, Pageable pageRequest);
  167. //名医咨询 -全部
  168. @Query("select a from ConsultTeam a, ConsultTeamDoctor b where a.consult = b.consult and a.type=6 and b.to = ?1 and a.status = 0 and (a.doctorRead > 0 or b.reply <> 1) and a.del = '1' and b.del = '1'")
  169. Page<ConsultTeam> findFamousDoctorUnReplyReadNoTitleList(String uid, Pageable pageRequest);
  170. //名医咨询 -全部 带symptoms 进行中
  171. @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 = 0 and b.reply = 1 and a.del = '1' and b.del = '1'")
  172. Page<ConsultTeam> findFamousDoctorIngList(String uid, long id,String title, Pageable pageRequest);
  173. //名医咨询 -全部 带symptoms 进行中
  174. @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 = 0 and b.reply = 1 and a.del = '1' and b.del = '1'")
  175. Page<ConsultTeam> findFamousDoctorIngList(String uid,String title, Pageable pageRequest);
  176. //名医咨询 -全部 进行中
  177. @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 = 0 and b.reply = 1 and a.del = '1' and b.del = '1'")
  178. Page<ConsultTeam> findFamousDoctorIngNoTitleList(String uid, long id, Pageable pageRequest);
  179. //名医咨询 -全部 进行中
  180. @Query("select a from ConsultTeam a, ConsultTeamDoctor b where a.consult = b.consult and a.type=6 and b.to = ?1 and a.status = 0 and b.reply = 1 and a.del = '1' and b.del = '1'")
  181. Page<ConsultTeam> findFamousDoctorIngNoTitleList(String uid, Pageable pageRequest);
  182. // 最近24小时内未回复的项目
  183. @Query("FROM ConsultTeam a where CURRENT_TIME - a.czrq < 86400 and a.status = 0 order by a.czrq desc")
  184. Page<ConsultTeam> getUnresponsedConsultIn24Hours(Pageable pageable);
  185. // 更新超过24小时未回复的项目,多加一分钟,防止过于频繁更新
  186. @Modifying
  187. @Query("UPDATE ConsultTeam a set a.status = -2 where CURRENT_TIME - a.czrq > 87840")
  188. void updateUnresponsedConsultOver24Hours();
  189. }