| 
					
				 | 
			
			
				@ -454,615 +454,6 @@ public class TalkGroupService extends BaseService { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        return discussionGroupMemberDao.countByMemberCode(doctor); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    /** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * 搜索转发医生 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @param doctor 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @param filter 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @return 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    public JSONObject searchImDoctor(String doctor, String filter) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        JSONObject result = new JSONObject(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        String sqlDoc = "select * from wlyy_doctor where name like ? "; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        String sqlTalkGroup = "select DISTINCT g.* from " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                " (select " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                "   gi.* " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                " from" + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                "  wlyy_talk_group_member mi " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                "  ,wlyy_talk_group gi " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                " where mi.group_code = gi.code and mi.member_code = ?) g " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                " left join wlyy_talk_group_member m on g.code = m.group_code where g.type = 2 and g.name like ? or m.member_name like ? "; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        String sqlTeam = "select DISTINCT t.* from " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                " (select " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                "   ti.* " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                " from" + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                "  wlyy_admin_team_member mi " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                "  ,wlyy_admin_team ti " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                " where mi.team_id = ti.id and mi.doctor_code = ?) t " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                " left join wlyy_admin_team_member m on t.id = m.team_id join wlyy_doctor d on m.doctor_code = d.code where t.name like ? or d.name like ? "; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        List<Doctor> doctors = jdbcTemplate.query(sqlDoc, new Object[]{"%" + filter + "%"}, new BeanPropertyRowMapper(Doctor.class)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        List<WlyyTalkGroup> groups = jdbcTemplate.query(sqlTalkGroup, new Object[]{doctor, "%" + filter + "%", "%" + filter + "%"}, new BeanPropertyRowMapper(WlyyTalkGroup.class)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        List<AdminTeam> teams = jdbcTemplate.query(sqlTeam, new Object[]{doctor, "%" + filter + "%", "%" + filter + "%"}, new BeanPropertyRowMapper(AdminTeam.class)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        if (doctors != null && doctors.size() > 0) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            JSONArray docArray = new JSONArray(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            for (Doctor doc : doctors) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                JSONObject json = new JSONObject(doc); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                if (json.has("password")) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    json.remove("password"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                if (json.has("salt")) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    json.remove("salt"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                docArray.put(json); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            result.put("doctor", docArray); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        if (groups != null && groups.size() > 0) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            JSONArray groupsArray = new JSONArray(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            for (WlyyTalkGroup group : groups) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                JSONObject json = new JSONObject(group); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                List<WlyyTalkGroupMember> members = findTalkGroupMembers(group.getCode()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                json.put("members", members); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                groupsArray.put(json); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            result.put("groupChat", groupsArray); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        if (teams != null && teams.size() > 0) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            JSONArray teamArray = new JSONArray(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            for (AdminTeam team : teams) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                JSONObject json = new JSONObject(team); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                List<Doctor> members = teamService.getMembers(team.getId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                if (members != null && members.size() > 0) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    JSONArray memberArray = new JSONArray(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    for (Doctor doc : members) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        JSONObject dJson = new JSONObject(doc); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        if (dJson.has("password")) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                            dJson.remove("password"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        if (dJson.has("salt")) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                            dJson.remove("salt"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        memberArray.put(dJson); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    json.put("members", memberArray); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                } else { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    json.put("members", new JSONArray()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                teamArray.put(json); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            result.put("teamChat", teamArray); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        return result; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    /** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * 查询医生IM列表 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @param doctor 医生 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @param type   聊天对象类型 1:居民 2:医生 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @return 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    public JSONObject getImList(String doctor, int type, int page, int pagesize) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        JSONObject result = new JSONObject(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        result.put("oneChat", getOneImList(doctor, type, page, pagesize)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        result.put("groupChat", getTalkgroupList(doctor, type, page, pagesize)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        if (type == 2) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            result.put("teamChat", getTeamChatList(doctor, page, pagesize)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        return result; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    /** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * 查询医生一对一IM列表 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @param doctor 医生 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @param type   聊天对象类型 1:居民 2:医生 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @return 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    public JSONArray getOneImList(String doctor, int type, int page, int pagesize) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        JSONArray list = new JSONArray(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        JSONArray imList = new JSONArray(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        String sqlP = ""; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        if (type == 1) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            sqlP = "select code,name,photo,sex,idcard,mobile from wlyy_patient where code = ? "; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } else { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            sqlP = "select code,name,photo,sex,idcard,mobile,level from wlyy_doctor where code = ? "; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        for (int i = 0; i < imList.length(); i++) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            JSONObject im = imList.getJSONObject(i); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            JSONObject json = new JSONObject(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            Map<String, Object> map = jdbcTemplate.queryForMap(sqlP, new Object[]{im.get("")}); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            if (map != null) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                json.put("name", map.get("name")); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                json.put("sex", map.get("sex")); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                json.put("idcard", map.get("idcard")); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                json.put("age", IdCardUtil.getAgeForIdcard(map.get("idcard") != null ? String.valueOf(map.get("idcard")) : "")); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                json.put("photo", map.get("photo")); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                json.put("mobile", map.get("mobile")); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                if (type == 2) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    json.put("level", map.get("level")); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            list.put(json); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        return list; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    /** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * 查询医生讨论组列表 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @param doctor   医生 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @param type     聊天对象类型 1:咨询 2:其他 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @param page     第几页 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @param pagesize 页大小 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @return 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    public JSONArray getTalkgroupList(String doctor, int type, int page, int pagesize) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        JSONArray list = new JSONArray(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        String sqlGroup = "select * " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                " from" + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                "     wlyy_talk_group g" + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                " join" + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                "     wlyy_talk_group_member m" + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                "  on g.code = m.group_code" + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                " where" + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                "     m.member_code = ? and g.type = " + (type == 1 ? "1" : "2") + " limit " + page * pagesize + "," + pagesize; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        List<WlyyTalkGroup> talkGroups = jdbcTemplate.query(sqlGroup, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                new Object[]{doctor}, new BeanPropertyRowMapper(WlyyTalkGroup.class)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        for (WlyyTalkGroup group : talkGroups) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            JSONObject obj = new JSONObject(group); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            List<WlyyTalkGroupMember> members = findTalkGroupMembers(group.getCode()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            JSONArray mArray = new JSONArray(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            for (WlyyTalkGroupMember member : members) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                JSONObject mJson = new JSONObject(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                mJson.put("memberCode", member.getMemberCode()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                mJson.put("memberName", member.getMemberName()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                mJson.put("type", member.getType()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                Map<String, Object> mObj = null; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                if (member.getType() == 4) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    String sqlP = "select code,name,photo,sex,idcard,mobile from wlyy_patient where code = ? "; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    mObj = jdbcTemplate.queryForMap(sqlP, new Object[]{member.getMemberCode()}); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                } else { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    String sqlP = "select code,name,photo,sex,idcard,mobile,level from wlyy_doctor where code = ? "; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    mObj = jdbcTemplate.queryForMap(sqlP, new Object[]{member.getMemberCode()}); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                if (mObj != null) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    mJson.put("memberName", mObj.get("name")); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    mJson.put("sex", mObj.get("sex")); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    mJson.put("idcard", mObj.get("idcard")); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    mJson.put("age", IdCardUtil.getAgeForIdcard(mObj.get("idcard") != null ? String.valueOf(mObj.get("idcard")) : "")); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    mJson.put("photo", mObj.get("photo")); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    if (member.getType() != 4) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        mJson.put("level", mObj.get("level")); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                mArray.put(mJson); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            obj.put("members", mArray); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            list.put(obj); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        return list; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    /** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * 查询团队聊天 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @param doctor 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @param page 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @param pagesize 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @return 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    public JSONArray getTeamChatList(String doctor, int page, int pagesize) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        String sql = "select t.* from wlyy_admin_team t" + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                " join wlyy_admin_team_member m" + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                " on t.id = m.team_id" + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                " where m.doctor_code = ? limit " + page * pagesize + "," + pagesize; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        List<AdminTeam> teams = jdbcTemplate.query(sql, new Object[]{doctor}, new BeanPropertyRowMapper(AdminTeam.class)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        JSONArray teamArray = new JSONArray(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        if (teams != null) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            for (AdminTeam team : teams) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                JSONObject json = new JSONObject(team); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                List<Doctor> members = teamService.getMembers(team.getId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                if (members != null && members.size() > 0) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    JSONArray memberArray = new JSONArray(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    for (Doctor doc : members) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        JSONObject dJson = new JSONObject(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        dJson.put("memberCode", doc.getCode()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        dJson.put("memberName", doc.getName()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        dJson.put("sex", doc.getSex()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        dJson.put("idcard", doc.getIdcard()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        dJson.put("age", IdCardUtil.getAgeForIdcard(doc.getIdcard())); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        dJson.put("photo", doc.getPhoto()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        dJson.put("level", doc.getLevel()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        memberArray.put(dJson); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    json.put("members", memberArray); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                } else { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    json.put("members", new JSONArray()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                teamArray.put(json); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        return teamArray; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    /** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * 查询医生最近联系IM列表 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @param doctor 医生 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @param type   聊天对象类型 1:居民 2:医生 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @return 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    public JSONObject getRecentImList(String doctor, int type) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        JSONObject result = new JSONObject(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        if (type == 1) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            result.put("oneChat", getRecentOneImList(doctor, type)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } else { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            result.put("oneChat", getRecentOneImList(doctor, type)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            result.put("groupChat", getRecentGroupImList(doctor)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        return result; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    /** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * 获取最近联系一对一IM列表 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @param doctor 医生 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @return 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    public JSONArray getRecentOneImList(String doctor, int type) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        JSONArray list = new JSONArray(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        JSONArray imList = new JSONArray(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        String sqlP = ""; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        if (type == 1) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            sqlP = "select code,name,photo,sex,idcard,mobile from wlyy_patient where code = ? "; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } else { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            sqlP = "select code,name,photo,sex,idcard,mobile,level from wlyy_doctor where code = ? "; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        for (int i = 0; i < imList.length(); i++) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            JSONObject im = imList.getJSONObject(i); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            JSONObject json = new JSONObject(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            Map<String, Object> map = jdbcTemplate.queryForMap(sqlP, new Object[]{im.get("")}); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            if (map != null) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                json.put("code", map.get("code")); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                json.put("name", map.get("name")); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                json.put("sex", map.get("sex")); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                json.put("idcard", map.get("idcard")); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                json.put("age", IdCardUtil.getAgeForIdcard(map.get("idcard") != null ? String.valueOf(map.get("idcard")) : "")); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                json.put("photo", map.get("photo")); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                json.put("mobile", map.get("mobile")); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                if (type == 2) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    json.put("level", map.get("level")); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            list.put(json); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        return list; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    /** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * 获取最近联系的讨论组或团队群聊 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @param doctor 医生 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @return 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    public JSONArray getRecentGroupImList(String doctor) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        JSONArray list = new JSONArray(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        JSONArray imList = new JSONArray(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        for (int i = 0; i < imList.length(); i++) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            JSONObject im = imList.getJSONObject(i); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            JSONObject json = new JSONObject(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            String sqlG = ""; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            String sqlP = "select code,name,photo,sex,idcard,mobile,level from wlyy_doctor where code = ? "; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            Map<String, Object> map = jdbcTemplate.queryForMap(sqlP, new Object[]{im.get("")}); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            if (map != null) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                json.put("code", map.get("code")); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                json.put("name", map.get("name")); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                json.put("sex", map.get("sex")); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                json.put("idcard", map.get("idcard")); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                json.put("age", IdCardUtil.getAgeForIdcard(map.get("idcard") != null ? String.valueOf(map.get("idcard")) : "")); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                json.put("photo", map.get("photo")); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                json.put("mobile", map.get("mobile")); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                json.put("level", map.get("level")); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            list.put(json); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        return list; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    /** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * IM搜索 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @param doctor     医生 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @param type       搜索类型 1:居民 2: 医生 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @param searchType 搜索类型 1:居民 2:居民聊天记录 3:医生 4:群聊 5:医生聊天记录 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @param page       第几页 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @param pagesize   页大小 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @return 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    public JSONObject searchIm(String doctor, String filter, int type, int searchType, int page, int pagesize) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        JSONObject result = new JSONObject(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        if (type == 1) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            if (searchType == -1 || searchType == 1) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                result.put("patient", searchPatients(filter, doctor, page, pagesize)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            if (searchType == -1 || searchType == 2) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                //result.put("patientChatRecord", searchPatients(filter, doctor, page, pagesize)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } else { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            if (searchType == -1 || searchType == 3) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                result.put("doctor", searchDoctors(filter, page, pagesize)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            if (searchType == -1 || searchType == 4) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                result.put("groupChat", searchDoctorGroupChat(filter, doctor, page, pagesize)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            if (searchType == -1 || searchType == 5) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                //result.put("doctorChatRecord", searchPatients(filter, doctor, page, pagesize)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        return result; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    /** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * 搜索医生签约患者 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @param filter 搜索关键字 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @param doctor 医生 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @return 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    public JSONArray searchPatients(String filter, String doctor, int page, int pagesize) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        JSONArray reArray = new JSONArray(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        int start = page * pagesize; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        int size = pagesize; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        String sql = "select distinct t.* from (" + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                " select " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                "     f.patient " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                "     ,f.name " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                "     ,f.openid " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                "     ,f.admin_team_code " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                "     ,p.sex " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                "     ,p.idcard " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                "     ,p.photo " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                " from " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                "     wlyy_sign_family f,wlyy_patient p " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                " where " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                "      f.patient = p.code and f.doctor = ? and f.status > 0 and f.name like ? " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                " union all " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                "select " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                "     f1.patient " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                "     ,f1.name " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                "     ,f1.openid " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                "     ,f1.admin_team_code " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                "     ,p1.sex " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                "     ,p1.idcard " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                "     ,p1.photo " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                " from " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                "     wlyy_sign_family f1,wlyy_patient p1" + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                " where " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                "     f1.patient = p1.code and f1.doctor_health = ? and f1.status > 0 and f1.name like ? " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                ") t  limit " + start + "," + size; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        List<Map<String, Object>> result = jdbcTemplate.queryForList(sql, new Object[]{doctor, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                "%" + filter + "%", doctor, "%" + filter + "%"}); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        if (result != null && result.size() > 0) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            for (Map<String, Object> p : result) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                JSONObject pJson = new JSONObject(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                pJson.put("code", p.get("patient")); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                pJson.put("name", p.get("name") != null ? p.get("name") : ""); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                pJson.put("openid", p.get("openid") != null ? p.get("openid") : ""); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                pJson.put("adminTeamCode", p.get("admin_team_code") != null ? p.get("admin_team_code") : ""); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                pJson.put("sex", p.get("sex") != null ? p.get("sex") : ""); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                pJson.put("age", p.get("idcard") != null ? IdCardUtil.getAgeForIdcard(String.valueOf(p.get("idcard"))) : ""); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                pJson.put("photo", p.get("photo") != null ? p.get("photo") : ""); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                pJson.put("idcard", p.get("idcard") != null ? p.get("idcard") : ""); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                reArray.put(pJson); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        return reArray; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    /** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * 搜索医生与居民聊天记录 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @param filter   搜索关键字 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @param doctor   医生 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @param page     第几页 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @param pagesize 页大小 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @return 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    public JSONArray searchPatientRecords(String filter, String doctor, int page, int pagesize) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        return null; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    /** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * 搜索医生 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @param filter   搜索关键字 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @param page     第几页 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @param pagesize 页大小 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @return 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    public JSONArray searchDoctors(String filter, int page, int pagesize) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        String sql = "select * from wlyy_doctor where name like ? limit " + page * pagesize + "," + pagesize; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        List<Doctor> doctorList = jdbcTemplate.query(sql, new Object[]{"%" + filter + "%"}, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                new BeanPropertyRowMapper(Doctor.class)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        JSONArray docArray = new JSONArray(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        if (doctorList != null) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            for (Doctor doc : doctorList) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                JSONObject docJson = new JSONObject(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                docJson.put("code", doc.getCode()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                docJson.put("name", doc.getName()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                docJson.put("sex", doc.getSex()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                docJson.put("age", IdCardUtil.getAgeForIdcard(doc.getIdcard())); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                docJson.put("idcard", doc.getIdcard()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                docJson.put("mobile", doc.getMobile()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                docJson.put("level", doc.getLevel()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                docJson.put("photo", doc.getPhoto()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                docJson.put("hospital", doc.getHospital()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                docJson.put("hospitalName", doc.getHospitalName()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                docArray.put(docJson); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        return docArray; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    /** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * 搜索医生群聊 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @param filter   搜索关键字 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @param doctor   医生 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @param page     第几页 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @param pagesize 页大小 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @return 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    public JSONArray searchDoctorGroupChat(String filter, String doctor, int page, int pagesize) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        JSONArray result = new JSONArray(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        String sqlTalkGroup = "select g.code,'1' type from " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                " (select " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                "   gi.* " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                " from" + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                "  wlyy_talk_group_member mi " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                "  ,wlyy_talk_group gi " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                " where mi.group_code = gi.code and mi.member_code = ?) g " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                " left join wlyy_talk_group_member m on g.code = m.group_code" + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                " where g.type = 2 and (g.name like ? or m.member_name like ?) "; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        String sqlTeam = "select cast(t.id as CHAR) code,'2' type from " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                " (select " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                "   ti.* " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                " from" + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                "  wlyy_admin_team_member mii " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                "  ,wlyy_admin_team ti " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                " where mii.team_id = ti.id and mii.doctor_code = ?) t " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                " left join wlyy_admin_team_member mm on t.id = mm.team_id join wlyy_doctor d" + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                " on mm.doctor_code = d.code where t.name like ? or d.name like ? "; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        String sql = "select DISTINCT o.* from (" + sqlTalkGroup + " union all " 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                + sqlTeam + ") o limit " + page * pagesize + "," + pagesize; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        List<Map<String, Object>> mapList = jdbcTemplate.queryForList(sql, new Object[]{doctor, "%" + filter + "%", 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                "%" + filter + "%", doctor, "%" + filter + "%", "%" + filter + "%"}); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        if (mapList != null) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            for (Map<String, Object> map : mapList) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                JSONObject json = new JSONObject(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                List<Doctor> members = null; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                if (String.valueOf(map.get("type")).equals("1")) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    WlyyTalkGroup group = discussionGroupDao.findByCode(map.get("code").toString()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    String sqlDoc = "select d.* from" + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                            " wlyy_talk_group_member m" + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                            " join wlyy_doctor d" + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                            " on m.memebr_code = d.code" + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                            " where m.group_code = ? "; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    members = jdbcTemplate.query(sqlDoc, new Object[]{map.get("code").toString()}, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                            new BeanPropertyRowMapper(Doctor.class)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    json.put("code", group.getCode()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    json.put("name", group.getName()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    json.put("type", "1"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                } else { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    AdminTeam team = teamService.getTeam(Long.valueOf(map.get("code").toString())); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    members = teamService.getMembers(Long.valueOf(map.get("code").toString())); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    json.put("code", String.valueOf(team.getId())); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    json.put("name", team.getName()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    json.put("type", "2"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                JSONArray mArray = new JSONArray(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                if (members != null) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    for (Doctor doc : members) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        JSONObject docJson = new JSONObject(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        docJson.put("code", doc.getCode()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        docJson.put("name", doc.getName()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        docJson.put("sex", doc.getSex()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        docJson.put("age", IdCardUtil.getAgeForIdcard(doc.getIdcard())); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        docJson.put("idcard", doc.getIdcard()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        docJson.put("mobile", doc.getMobile()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        docJson.put("level", doc.getLevel()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        docJson.put("photo", doc.getPhoto()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        docJson.put("hospital", doc.getHospital()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        docJson.put("hospitalName", doc.getHospitalName()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        mArray.put(docJson); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                json.put("members", mArray); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                result.put(json); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        return result; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    /** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * 搜索医生聊天记录 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @param filter   搜索关键字 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @param doctor   医生 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @param page     第几页 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @param pagesize 页大小 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @return 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    public JSONArray searchDoctorRecords(String filter, String doctor, int page, int pagesize) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        return null; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    public List<WlyyTalkGroup> findTalkGroupByConsult(String consult) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        return discussionGroupDao.findByConsult(consult); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    public ConsultTeam findConsultByGroup(String groupCode) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        WlyyTalkGroup w = discussionGroupDao.findByCode(groupCode); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        return consultTeamDao.findByConsult(w.getConsultCode()); 
			 |