AdminTeamService.java 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. package com.yihu.wlyy.service.app.team;
  2. import com.yihu.wlyy.entity.doctor.profile.Doctor;
  3. import com.yihu.wlyy.entity.doctor.team.admin.AdminTeam;
  4. import com.yihu.wlyy.entity.doctor.team.admin.AdminTeamMember;
  5. import com.yihu.wlyy.entity.patient.Patient;
  6. import com.yihu.wlyy.repository.doctor.DoctorAdminTeamDao;
  7. import com.yihu.wlyy.repository.doctor.DoctorAdminTeamMemberDao;
  8. import com.yihu.wlyy.service.BaseService;
  9. import org.springframework.beans.factory.annotation.Autowired;
  10. import org.springframework.data.domain.Page;
  11. import org.springframework.data.domain.PageRequest;
  12. import org.springframework.data.domain.Pageable;
  13. import org.springframework.stereotype.Component;
  14. import org.springframework.transaction.annotation.Transactional;
  15. import java.util.*;
  16. /**
  17. * 医生行政团队服务。
  18. *
  19. * @author Sand
  20. */
  21. @Component
  22. @Transactional
  23. public class AdminTeamService extends BaseService {
  24. @Autowired
  25. DoctorAdminTeamDao teamDao;
  26. @Autowired
  27. DoctorAdminTeamMemberDao memberDao;
  28. //-----------------Team Operation----------------------
  29. public long getTeamCount() {
  30. return teamDao.count();
  31. }
  32. public AdminTeam createTeam(String teamName, String leaderCode, String orgCode) {
  33. AdminTeam team = new AdminTeam();
  34. team.setName(teamName);
  35. team.setLeaderCode(leaderCode);
  36. team.setOrgCode(orgCode);
  37. team.setAvailable(true);
  38. team.setCreateTime(new Date());
  39. saveTeam(team);
  40. return team;
  41. }
  42. public AdminTeam getTeam(long id) {
  43. AdminTeam team = teamDao.findOne(id);
  44. return team;
  45. }
  46. public AdminTeam updateTeamName(long teamId, String teamName) {
  47. AdminTeam team = getTeam(teamId);
  48. if (team != null) {
  49. if (teamName != null) team.setName(teamName);
  50. saveTeam(team);
  51. }
  52. return team;
  53. }
  54. public AdminTeam updateTeamLeader(long teamId, String doctorCode) {
  55. AdminTeam team = getTeam(teamId);
  56. if (team != null) {
  57. if (doctorCode != null) team.setLeaderCode(doctorCode);
  58. saveTeam(team);
  59. }
  60. return team;
  61. }
  62. public List<AdminTeam> getDoctorTeams(String doctorCode){
  63. return memberDao.findDoctorTeams(doctorCode);
  64. }
  65. //-----------------Member Operation----------------------
  66. public void addMember(long teamId, String doctorCode){
  67. Integer count = memberDao.isMemberExist(teamId, doctorCode);
  68. if(count == null || count == 0) {
  69. AdminTeamMember member = new AdminTeamMember();
  70. member.setTeamId(teamId);
  71. member.setDoctorCode(doctorCode);
  72. member.setJoinTime(new Date());
  73. saveMember(member);
  74. }
  75. }
  76. public void removeMember(long teamId, String doctorCode){
  77. AdminTeamMember member = memberDao.findByTeamIdAndDoctorCodeOrderByDoctorCodeAsc(teamId, doctorCode);
  78. if(member != null) memberDao.delete(member);
  79. }
  80. public List<Doctor> getMembers(long teamId){
  81. return memberDao.findAllMembers(teamId);
  82. }
  83. public List<Doctor> getExcludedMembers(String orgCode, long teamId, int page, int size){
  84. Pageable pageable = new PageRequest(page, size);
  85. Page<Doctor> doctors = memberDao.findTeamExcludedMembers(orgCode, teamId, pageable);
  86. if (doctors == null) return null;
  87. return doctors.getContent();
  88. }
  89. public Map<String, Integer> getMemberSigningCount(List<Doctor> doctors){
  90. Map<String, Integer> counts = new HashMap<>();
  91. for (Doctor doctor : doctors){
  92. if (!(doctor.getLevel() == 2 || doctor.getLevel() == 3)) continue;
  93. boolean isHealthDoctor = doctor.getLevel() == 3;
  94. List<String> partners = new ArrayList<>();
  95. for (Doctor partner : doctors){
  96. if(partner == doctor) continue;
  97. if (isHealthDoctor && partner.getLevel() == 2){
  98. partners.add(partner.getCode());
  99. } else if (!isHealthDoctor && partner.getLevel() == 3) {
  100. partners.add(partner.getCode());
  101. }
  102. }
  103. Integer signingCount = 0;
  104. if(partners.isEmpty()){
  105. signingCount = 0;
  106. } else if (isHealthDoctor){
  107. signingCount = teamDao.getHealthDoctorSignCount(doctor.getCode(), partners);
  108. } else {
  109. signingCount = teamDao.getDoctorSignCount(doctor.getCode(), partners);
  110. }
  111. counts.put(doctor.getCode(), signingCount);
  112. }
  113. return counts;
  114. }
  115. public List<Patient> getMemberSigningPatients(long teamId, String doctorCode, int page, int size){
  116. List<String> healthDoctors = new ArrayList<>();
  117. List<Doctor> doctors = getMembers(teamId);
  118. for (Doctor doctor : doctors){
  119. if (doctor.getLevel() != 3) continue;
  120. healthDoctors.add(doctor.getCode());
  121. }
  122. Page<Patient> result = teamDao.getHealthDoctorSigningPatients(
  123. doctorCode, healthDoctors,
  124. new PageRequest(page, size));
  125. return result.getContent();
  126. }
  127. private void saveTeam(AdminTeam team) {
  128. teamDao.save(team);
  129. }
  130. private void saveMember(AdminTeamMember member){
  131. memberDao.save(member);
  132. }
  133. }