|  | @ -7,6 +7,7 @@ import com.yihu.wlyy.entity.patient.Patient;
 | 
	
		
			
				|  |  | import com.yihu.wlyy.repository.doctor.DoctorAdminTeamDao;
 | 
	
		
			
				|  |  | import com.yihu.wlyy.repository.doctor.DoctorAdminTeamMemberDao;
 | 
	
		
			
				|  |  | import com.yihu.wlyy.service.BaseService;
 | 
	
		
			
				|  |  | import org.apache.commons.lang3.tuple.Pair;
 | 
	
		
			
				|  |  | import org.springframework.beans.factory.annotation.Autowired;
 | 
	
		
			
				|  |  | import org.springframework.data.domain.Page;
 | 
	
		
			
				|  |  | import org.springframework.data.domain.PageRequest;
 | 
	
	
		
			
				|  | @ -139,8 +140,7 @@ public class AdminTeamService extends BaseService {
 | 
	
		
			
				|  |  |      * @param doctorCode
 | 
	
		
			
				|  |  |      */
 | 
	
		
			
				|  |  |     public void addMember(long teamId, String doctorCode) {
 | 
	
		
			
				|  |  |         Integer count = memberDao.isMemberExist(teamId, doctorCode);
 | 
	
		
			
				|  |  |         if (count == null || count == 0) {
 | 
	
		
			
				|  |  |         if (!memberDao.isMemberExist(teamId, doctorCode)) {
 | 
	
		
			
				|  |  |             AdminTeamMember member = new AdminTeamMember();
 | 
	
		
			
				|  |  |             member.setTeamId(teamId);
 | 
	
		
			
				|  |  |             member.setDoctorCode(doctorCode);
 | 
	
	
		
			
				|  | @ -157,9 +157,11 @@ public class AdminTeamService extends BaseService {
 | 
	
		
			
				|  |  |      * @param teamId
 | 
	
		
			
				|  |  |      * @param doctorCode
 | 
	
		
			
				|  |  |      */
 | 
	
		
			
				|  |  |     public void removeMember(long teamId, String doctorCode) {
 | 
	
		
			
				|  |  |     public Pair<Integer, String> removeMember(long teamId, String doctorCode) {
 | 
	
		
			
				|  |  |         AdminTeamMember member = memberDao.findByTeamIdAndDoctorCodeOrderByDoctorCodeAsc(teamId, doctorCode);
 | 
	
		
			
				|  |  |         if (member != null) memberDao.delete(member);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         return null;
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     public List<Doctor> getMembers(long teamId) {
 | 
	
	
		
			
				|  | @ -195,32 +197,17 @@ public class AdminTeamService extends BaseService {
 | 
	
		
			
				|  |  |      * @param doctors
 | 
	
		
			
				|  |  |      * @return
 | 
	
		
			
				|  |  |      */
 | 
	
		
			
				|  |  |     public Map<String, Integer> getMemberSigningCount(List<Doctor> doctors) {
 | 
	
		
			
				|  |  |     public Map<String, Integer> getMemberSigningCount(long teamId, List<Doctor> doctors) {
 | 
	
		
			
				|  |  |         Map<String, Integer> counts = new HashMap<>();
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         for (Doctor doctor : doctors) {
 | 
	
		
			
				|  |  |             if (doctor.isProfessionalDoctor()) continue;
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |             boolean isHealthDoctor = doctor.isHealthDoctor();
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |             List<String> partners = new ArrayList<>();
 | 
	
		
			
				|  |  |             for (Doctor partner : doctors) {
 | 
	
		
			
				|  |  |                 if (partner == doctor) continue;
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |                 if (isHealthDoctor && partner.isGeneralDoctor()) {
 | 
	
		
			
				|  |  |                     partners.add(partner.getCode());
 | 
	
		
			
				|  |  |                 } else if (!isHealthDoctor && partner.isHealthDoctor()) {
 | 
	
		
			
				|  |  |                     partners.add(partner.getCode());
 | 
	
		
			
				|  |  |                 }
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |             Integer signingCount;
 | 
	
		
			
				|  |  |             if (partners.isEmpty()) {
 | 
	
		
			
				|  |  |                 signingCount = 0;
 | 
	
		
			
				|  |  |             } else if (isHealthDoctor) {
 | 
	
		
			
				|  |  |                 signingCount = teamDao.getHealthDoctorSignCount(doctor.getCode(), partners);
 | 
	
		
			
				|  |  |             if (doctor.isHealthDoctor()) {
 | 
	
		
			
				|  |  |                 signingCount = teamDao.getHealthDoctorSignCount(doctor.getCode(), teamId);
 | 
	
		
			
				|  |  |             } else {
 | 
	
		
			
				|  |  |                 signingCount = teamDao.getDoctorSignCount(doctor.getCode(), partners);
 | 
	
		
			
				|  |  |                 signingCount = teamDao.getDoctorSignCount(doctor.getCode(), teamId);
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |             counts.put(doctor.getCode(), signingCount);
 | 
	
	
		
			
				|  | @ -239,16 +226,7 @@ public class AdminTeamService extends BaseService {
 | 
	
		
			
				|  |  |      * @return
 | 
	
		
			
				|  |  |      */
 | 
	
		
			
				|  |  |     public List<Patient> getMemberSigningPatients(long teamId, String healthDoctorCode, int page, int size) {
 | 
	
		
			
				|  |  |         List<String> generalDoctors = new ArrayList<>();
 | 
	
		
			
				|  |  |         List<Doctor> doctors = getMembers(teamId);
 | 
	
		
			
				|  |  |         for (Doctor doctor : doctors) {
 | 
	
		
			
				|  |  |             if (doctor.getLevel() != 2) continue;
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |             generalDoctors.add(doctor.getCode());
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         Page<Patient> result = teamDao.getHealthDoctorSigningPatients(
 | 
	
		
			
				|  |  |                 healthDoctorCode, generalDoctors, new PageRequest(page, size));
 | 
	
		
			
				|  |  |         Page<Patient> result = teamDao.getHealthDoctorSigningPatients(healthDoctorCode, teamId, new PageRequest(page, size));
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         return result.getContent();
 | 
	
		
			
				|  |  |     }
 |