Pārlūkot izejas kodu

Merge branch 'dev' of lyr/patient-co-management into dev

sand 8 gadi atpakaļ
vecāks
revīzija
69d87b80b2

+ 49 - 49
src/main/java/com/yihu/wlyy/interceptors/DoctorInterceptor.java

@ -24,55 +24,55 @@ public class DoctorInterceptor extends BaseInterceptor {
	public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
		boolean flag = true;
		try {
//			response.setCharacterEncoding("UTF-8");
//			JSONObject json = getAgent(request);
//			if (json == null) {
//				// 未登录
//				response.getOutputStream().write(error(SystemConf.NOT_LOGIN, "请登录后再操作!").getBytes());
//				return false;
//			}
//			String tokenStr = json.has("token") ? json.getString("token") : "";
//			String uid = json.has("uid") ? json.getString("uid") : "";
//			String imei = json.has("imei") ? json.getString("imei") : "";
//
//			if (StringUtils.isEmpty(tokenStr) || StringUtils.isEmpty(imei) || StringUtils.isEmpty(uid)) {
//				response.getOutputStream().write(error(SystemConf.NOT_LOGIN, "请登录后再操作!").getBytes());
//				return false;
//			}
//
//			Token token = SystemData.doctorTokens.get(uid);
//			if (token == null) {
//				token = tokenDao.findByPatient(uid, 2);
//				if (token != null) {
//					// 加入缓存
//					SystemData.doctorTokens.put(uid, token);
//				}
//			}
//			if (token == null || token.getPlatform() != 2) {
//				// 未登录
//				response.getOutputStream().write(error(SystemConf.NOT_LOGIN, "请登录后再操作!").getBytes());
//				flag = false;
//			} else {
//				if (token.getTimeout().getTime() < new Date().getTime()) {
//					// 登录超时
//					response.getOutputStream().write(error(SystemConf.LOGIN_TIMEOUT, "登录超时,请重新登录").getBytes());
//					flag = false;
//				} else if (!StringUtils.equals(tokenStr, token.getToken()) || !StringUtils.equals(uid, token.getUser()) || !StringUtils.equals(imei, token.getImei())) {
//					// 别处登录
//					response.getOutputStream().write(error(SystemConf.LOGIN_OTHER, "帐号在别处登录,请重新登录").getBytes());
//					flag = false;
//				} else {
//					// 一天只更新一次
//					if (DateUtil.getDays(token.getCzrq(), DateUtil.getNowDateShort()) != 0) {
//						// 今天未更新,则更新缓存
//						token.setCzrq(new Date());
//						// 更新内存
//						SystemData.doctorTokens.put(uid, token);
//						// 更新数据库
//						tokenDao.save(token);
//					}
//				}
//			}
			response.setCharacterEncoding("UTF-8");
			JSONObject json = getAgent(request);
			if (json == null) {
				// 未登录
				response.getOutputStream().write(error(SystemConf.NOT_LOGIN, "请登录后再操作!").getBytes());
				return false;
			}
			String tokenStr = json.has("token") ? json.getString("token") : "";
			String uid = json.has("uid") ? json.getString("uid") : "";
			String imei = json.has("imei") ? json.getString("imei") : "";
			if (StringUtils.isEmpty(tokenStr) || StringUtils.isEmpty(imei) || StringUtils.isEmpty(uid)) {
				response.getOutputStream().write(error(SystemConf.NOT_LOGIN, "请登录后再操作!").getBytes());
				return false;
			}
			Token token = SystemData.doctorTokens.get(uid);
			if (token == null) {
				token = tokenDao.findByPatient(uid, 2);
				if (token != null) {
					// 加入缓存
					SystemData.doctorTokens.put(uid, token);
				}
			}
			if (token == null || token.getPlatform() != 2) {
				// 未登录
				response.getOutputStream().write(error(SystemConf.NOT_LOGIN, "请登录后再操作!").getBytes());
				flag = false;
			} else {
				if (token.getTimeout().getTime() < new Date().getTime()) {
					// 登录超时
					response.getOutputStream().write(error(SystemConf.LOGIN_TIMEOUT, "登录超时,请重新登录").getBytes());
					flag = false;
				} else if (!StringUtils.equals(tokenStr, token.getToken()) || !StringUtils.equals(uid, token.getUser()) || !StringUtils.equals(imei, token.getImei())) {
					// 别处登录
					response.getOutputStream().write(error(SystemConf.LOGIN_OTHER, "帐号在别处登录,请重新登录").getBytes());
					flag = false;
				} else {
					// 一天只更新一次
					if (DateUtil.getDays(token.getCzrq(), DateUtil.getNowDateShort()) != 0) {
						// 今天未更新,则更新缓存
						token.setCzrq(new Date());
						// 更新内存
						SystemData.doctorTokens.put(uid, token);
						// 更新数据库
						tokenDao.save(token);
					}
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
		}

+ 38 - 0
src/main/java/com/yihu/wlyy/repository/consult/ConsultTeamDao.java

@ -8,6 +8,7 @@ package com.yihu.wlyy.repository.consult;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.jaxb.PageAdapter;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
@ -132,6 +133,10 @@ public interface ConsultTeamDao extends PagingAndSortingRepository<ConsultTeam,
	@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")
	int amountAllDoctorUnread(String doctor);
	// 查询医生所有未读的消息总数
	@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 order by b.czrq desc")
	Page<Object> AllDoctorUnreadLast(String doctor,Pageable pageRequest);
	// 查询带未读数量的所有健康咨询列表
	@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")
	Page<ConsultTeam> findListByUnreadDoctor(String doctor, Pageable pageRequest);
@ -172,4 +177,37 @@ public interface ConsultTeamDao extends PagingAndSortingRepository<ConsultTeam,
	Page<ConsultTeam> findFamousDoctorDoingList(String uid,String title,Integer type, Pageable pageRequest);
	@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 ")
	ConsultTeam findByParientCodeAndSignTypeAndDoctor(String patientCode, String doctor, int s);
	//名医咨询 -全部 带symptoms 未处理、未回复
	@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'")
	Page<ConsultTeam> findFamousDoctorUnReplyReadList(String uid, long id,String title, Pageable pageRequest);
	//名医咨询 -全部 带symptoms 处理、未回复
	@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'")
	Page<ConsultTeam> findFamousDoctorUnReplyReadList(String uid,String title, Pageable pageRequest);
	//名医咨询 -全部 处理、未回复
	@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'")
	Page<ConsultTeam> findFamousDoctorUnReplyReadNoTitleList(String uid, long id, Pageable pageRequest);
	//名医咨询 -全部
	@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'")
	Page<ConsultTeam> findFamousDoctorUnReplyReadNoTitleList(String uid, Pageable pageRequest);
	//名医咨询 -全部 带symptoms 进行中
	@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'")
	Page<ConsultTeam> findFamousDoctorIngList(String uid, long id,String title, Pageable pageRequest);
	//名医咨询 -全部 带symptoms 进行中
	@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'")
	Page<ConsultTeam> findFamousDoctorIngList(String uid,String title, Pageable pageRequest);
	//名医咨询 -全部 进行中
	@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'")
	Page<ConsultTeam> findFamousDoctorIngNoTitleList(String uid, long id, Pageable pageRequest);
	//名医咨询 -全部 进行中
	@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'")
	Page<ConsultTeam> findFamousDoctorIngNoTitleList(String uid, Pageable pageRequest);
}

+ 9 - 0
src/main/java/com/yihu/wlyy/repository/message/MessageDao.java

@ -6,6 +6,9 @@
package com.yihu.wlyy.repository.message;
import com.yihu.wlyy.entity.message.Message;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
@ -16,9 +19,15 @@ public interface MessageDao extends PagingAndSortingRepository<Message, Long>, J
    @Query("select count(a) from Message a where a.type =1 and a.read= 1 and a.receiver=?1 ")
    int amountUnreadByReceiver(String doctor);
    @Query("select a from Message a where a.type =1 and a.read= 1 and a.receiver=?1 order by a.czrq desc")
    Page<Message> amountUnreadLastByReceiver(String doctor, Pageable pageRequest);
    @Query("select count(a) from Message a where (a.type =2 or a.type =3) and a.read= 1 and a.receiver=?1 ")
    int amountUnreadHealthByReceiver(String doctor);
    @Query("select a from Message a where (a.type =2 or a.type =3) and a.read= 1 and a.receiver=?1 order by a.czrq desc")
    Page<Message> amountUnreadHealthLastByReceiver(String doctor,Pageable pageRequest);
    @Modifying
    @Query("update Message a set a.read = 0,a.over='0' where a.id = ?1")
    int read(long msgid);

+ 787 - 722
src/main/java/com/yihu/wlyy/service/app/consult/ConsultTeamService.java

@ -45,7 +45,7 @@ import com.yihu.wlyy.util.MessageType;
/**
 * 網絡諮詢类.
 * 
 *
 * @author George
 */
// Spring Service Bean的标识.
@ -53,729 +53,794 @@ import com.yihu.wlyy.util.MessageType;
@Transactional(rollbackFor = Exception.class)
public class ConsultTeamService extends ConsultService {
	private Clock clock = Clock.DEFAULT;
	// 咨询详细记录
	@Autowired
	private ConsultTeamLogDao consultTeamLogDao;
	@Autowired
	private ConsultTeamDoctorDao consultTeamDoctorDao;
	@Autowired
	private SignFamilyDao signFamilyDao;
	@Autowired
	private DoctorPatientDao doctorPatientDao;
	@Autowired
	private DoctorTeamDao doctorTeamDao;
	@Autowired
    private Clock clock = Clock.DEFAULT;
    // 咨询详细记录
    @Autowired
    private ConsultTeamLogDao consultTeamLogDao;
    @Autowired
    private ConsultTeamDoctorDao consultTeamDoctorDao;
    @Autowired
    private SignFamilyDao signFamilyDao;
    @Autowired
    private DoctorPatientDao doctorPatientDao;
    @Autowired
    private DoctorTeamDao doctorTeamDao;
    @Autowired
    private ConsultTeamDao consultTeamDao;
	@Autowired
	private DoctorTeamMemberDao doctorTeamDoctor;
	@Autowired
	private JdbcTemplate jdbcTemplate;
	/**
	 * 查询患者是否还有未结束的三师咨询
	 * @param patient
	 * @return
	 */
	public boolean exist(String patient,Integer type) {
		int count = consultTeamDao.countByPatient(patient, type);
		return count > 0;
	}
	/**
	 * 查詢醫生網絡諮詢列表
	 * @param type 咨询类型:1、咨询我的,2、公共的, 3、参与过的,4、已结束的 5 名医咨询 全部  6 名医咨询 进行中 7 名医咨询 已结束
	 * @param id
	 * @param pagesize 每页显示数,默认为10
	 * @return
	 */
	public Page<ConsultTeam> findByDoctor(String uid, int type, long id, int pagesize,String title) {
		if (id < 0) {
			id = 0;
		}
		if (pagesize <= 0) {
			pagesize = 10;
		}
		switch (type) {
		case 0:
			// 全部
			return findByDoctorType0(uid, id, pagesize);
		case 1:
			// 咨询我的
			return findByDoctorType1(uid, type, id, pagesize);
		case 2:
			// 我感兴趣的
			return findByDoctorType2(uid, type, id, pagesize);
		case 3:
			// 我回复的
			return findByDoctorType3(uid, id, pagesize);
		case 4:
			// 已完成的
			return findByDoctorType4(uid, id, pagesize);
		case 5:
			// 5 名医咨询 全部
			return findByDoctorType5(uid, id, pagesize,title);
		case 6:
			//6 名医咨询 进行中
			return findByDoctorType6(uid, 0, id, pagesize,title);
		case 7:
			//7 名医咨询 已结束
			return findByDoctorType6(uid, 1, id, pagesize,title);
		}
		return null;
	}
	private Page<ConsultTeam> findByDoctorType5(String uid,  long id, int pagesize,String title) {
		Sort sort = new Sort(Direction.DESC, "id");
		// 分页信息
		PageRequest pageRequest = new PageRequest(0, pagesize, sort);
		if(StringUtils.isNoneEmpty(title)){
			title="%"+title+"%";
			if (id > 0) {
				return consultTeamDao.findFamousDoctorAllList(uid, id,title, pageRequest);
			} else {
				return consultTeamDao.findFamousDoctorAllList(uid,title, pageRequest);
			}
		}else{
			if (id > 0) {
				return consultTeamDao.findFamousDoctorAllList(uid, id, pageRequest);
			} else {
				return consultTeamDao.findFamousDoctorAllList(uid, pageRequest);
			}
		}
	}
	private Page<ConsultTeam> findByDoctorType6(String uid, int type, long id, int pagesize,String title) {
		// 排序
		Sort sort = new Sort(Direction.DESC, "id");
		// 分页信息
		PageRequest pageRequest = new PageRequest(0, pagesize, sort);
		if(StringUtils.isNoneEmpty(title)){
			title="%"+title+"%";
			if (id > 0) {
				return consultTeamDao.findFamousDoctorDoingList(uid, id,title,type, pageRequest);
			} else {
				return consultTeamDao.findFamousDoctorDoingList(uid, title,type,pageRequest);
			}
		}else{
			if (id > 0) {
				return consultTeamDao.findFamousDoctorDoingList(uid, id,type, pageRequest);
			} else {
				return consultTeamDao.findFamousDoctorDoingList(uid,type, pageRequest);
			}
		}
	}
	/**
	 * 查询全部咨询记录
	 * @param uid
	 * @param id
	 * @param pagesize
	 * @return
	 */
	public Page<ConsultTeam> findByDoctorType0(String uid, long id, int pagesize) {
		// 排序
		Sort sort = new Sort(Direction.DESC, "id");
		// 分页信息
		PageRequest pageRequest = new PageRequest(0, pagesize, sort);
		if (id > 0) {
			return consultTeamDao.findDoctorList(uid, id, pageRequest);
		} else {
			return consultTeamDao.findDoctorList(uid, pageRequest);
		}
	}
	/**
	 * 指定医生三师咨询列表查询
	 * @param uid 医生标识
	 * @param type 咨询类型:1、咨询我的,2、公共的, 3、参与过的,4、已结束的
	 * @param pagesize
	 * @return
	 */
	public Page<ConsultTeam> findByDoctorType1(String uid, int type, long id, int pagesize) {
		// 排序
		Sort sort = new Sort(Direction.DESC, "id");
		// 分页信息
		PageRequest pageRequest = new PageRequest(0, pagesize, sort);
		if (id > 0) {
			return consultTeamDao.findDoctorPointList(uid, id, pageRequest);
		} else {
			return consultTeamDao.findDoctorPointList(uid, pageRequest);
		}
	}
	/**
	 * 公共三师咨询列表查询
	 * @param uid 医生标识
	 * @param type 咨询类型:1、咨询我的,2、公共的, 3、参与过的,4、已结束的
	 * @param pagesize
	 * @return
	 */
	public Page<ConsultTeam> findByDoctorType2(String uid, int type, long id, int pagesize) {
		// 排序
		Sort sort = new Sort(Direction.DESC, "id");
		// 分页信息
		PageRequest pageRequest = new PageRequest(0, pagesize, sort);
		// 设置查询条件
		Map<String, SearchFilter> filters = new HashMap<String, SearchFilter>();
		// 未指定医生
		filters.put("type", new SearchFilter("type", Operator.EQ, 0));
		if (id > 0) {
			filters.put("id", new SearchFilter("id", Operator.LT, id));
		}
		// 未回复
		filters.put("status", new SearchFilter("status", Operator.EQ, 0));
		// 未作废
		filters.put("del", new SearchFilter("del", Operator.EQ, "1"));
		Specification<ConsultTeam> spec = DynamicSpecifications.bySearchFilter(filters.values(), ConsultTeam.class);
		return consultTeamDao.findAll(spec, pageRequest);
	}
	/**
	 * 医生参与过的未结束的三师咨询列表查询
	 * @param uid
	 * @param pagesize
	 * @return
	 */
	public Page<ConsultTeam> findByDoctorType3(String uid, long id, int pagesize) {
		// 排序
		Sort sort = new Sort(Direction.DESC, "id");
		// 分页信息
		PageRequest pageRequest = new PageRequest(0, pagesize, sort);
		if (id > 0) {
			return consultTeamDao.findDoctorJoinList(uid, id, pageRequest);
		} else {
			return consultTeamDao.findDoctorJoinList(uid, pageRequest);
		}
	}
	/**
	 * 医生参与过的已结束的三师咨询列表查询
	 * @param uid
	 * @param pagesize
	 * @return
	 */
	public Page<ConsultTeam> findByDoctorType4(String uid, long id, int pagesize) {
		// 排序
		Sort sort = new Sort(Direction.DESC, "id");
		// 分页信息
		PageRequest pageRequest = new PageRequest(0, pagesize, sort);
		if (id > 0) {
			return consultTeamDao.findDoctorFinishList(uid, id, pageRequest);
		} else {
			return consultTeamDao.findDoctorFinishList(uid, pageRequest);
		}
	}
	/**
	 * 网络咨询咨询日志查询
	 * @param consult 咨询标识
	 * @param pagesize 每页显示数,默认为10
	 * @return
	 */
	public Page<ConsultTeamLog> findLogByConsult(String consult, long id, int pagesize) {
		if (id < 0) {
			id = 0;
		}
		// 设置查询条件
		Map<String, SearchFilter> filters = new HashMap<String, SearchFilter>();
		filters.put("consult", new SearchFilter("consult", Operator.EQ, consult));
		if (id > 0) {
			if(pagesize>0)
				filters.put("id", new SearchFilter("id", Operator.LT, id));
			else
				filters.put("id", new SearchFilter("id", Operator.GT, id));
		}
		filters.put("del", new SearchFilter("del", Operator.EQ, "1"));
		Specification<ConsultTeamLog> spec = DynamicSpecifications.bySearchFilter(filters.values(), ConsultTeamLog.class);
		if(pagesize <= 0){
			Page<ConsultTeamLog> p = new PageImpl<>(consultTeamLogDao.findAll(spec));
			return p;
		}
		// 排序
		Sort sort = new Sort(Direction.DESC, "id");
		// 分页信息
		PageRequest pageRequest = new PageRequest(0, pagesize, sort);
		return consultTeamLogDao.findAll(spec, pageRequest);
	}
	/**
	 * 批量回复
	 * @param logs
	 * @return
	 */
	public void reply(List<ConsultTeamLog> logs, String patient) {
		for (ConsultTeamLog log : logs) {
			reply(log, patient, null, log.getType());
		}
	}
	/**
	 * 添加咨询记录
	 * @param log 日志对象
	 * @param type 类型,0问,1回复,2追问,3评价
	 * @return
	 */
	public ConsultTeamLog reply(ConsultTeamLog log, String patient, String teamOrDoctor, int type) {
		log.setCzrq(clock.getCurrentDate());
		// 保存咨询记录
		ConsultTeamLog temp = consultTeamLogDao.save(log);
		if (temp != null) {
			// 发送消息
			if (type == 1) {
				// 医生回复,给患者发消息
				// sendMessage(patient, teamOrDoctor, "三师咨询", log.getDoctorName() + "回复了您的咨询", log.getConsult(), 214, 1, 0, 0);
				// 患者未读数量+1
				consultTeamDao.increasePatientRead(log.getConsult());
				// 医生有回复
				consultTeamDoctorDao.updateReply(log.getConsult(), teamOrDoctor);
				//shenzaixin v1.2.0 推送消息给患者
				HttpUtil.sendWeixinWebsocketMsg(patient,"{busiType:'qianyuezixun',msgid:'"+log.getId()+"'}");
			} else if (type == 0 || type == 2) {
				// 查询相关联的医生
				Iterable<ConsultTeamDoctor> iterable = consultTeamDoctorDao.findByConsult(log.getConsult());
				if (iterable != null && iterable.iterator() != null && iterable.iterator().hasNext()) {
					Iterator<ConsultTeamDoctor> iterator = iterable.iterator();
					while (iterator.hasNext()) {
						// 患者提问或追问,给医生发消息
						ConsultTeamDoctor ctd = iterator.next();
						if (ctd == null) {
							continue;
						}
						// 推送消息给医生
						PushMsgTask.getInstance().put(ctd.getTo(), MessageType.MESSAGE_TYPE_DOCTOR_NEW_CONSULT_TEAM_REPLY.D_CT_02.name(), MessageType.MESSAGE_TYPE_DOCTOR_NEW_CONSULT_TEAM_REPLY.指定咨询.name(), MessageType.MESSAGE_TYPE_DOCTOR_NEW_CONSULT_TEAM_REPLY.您有新的消息.name(), temp.getConsult());
					}
				}
				// 医生未读数量+1
				consultTeamDao.increaseDoctorRead(log.getConsult());
			}
		}
		return temp;
	}
	/**
	 * 添加三师咨询
	 * @param ct 三师咨询对象
	 * @param patient 患者标识
	 * @return
	 * @throws Exception
	 */
	public int addTeamConsult(ConsultTeam ct, String patient) throws Exception {
		// 咨询三师
		if (ct.getType() == 1) {
			// 查询三师签约信息
			SignFamily sc = signFamilyDao.findBySanshiPatientYes(patient);
			if (sc == null) {
				// 不存在三师签约
				return -2;
			}
			ct.setTeam(sc.getTeamCode());
			// 设置健康管理师,三师咨询默认给健康管理师处理
			//查找病人所在的团队
			DoctorTeam doctorTeam=doctorTeamDao.findBySanshiParientCode(patient);
			//得到团队的健康管理师
			DoctorTeamMember doctorTeamMember = doctorTeamDoctor.findDoctorSanshi2ByTeam(doctorTeam.getCode(),3);
			// 设置家庭医生
			ct.setDoctor( doctorTeamMember.getMemberCode());
		} else if (ct.getType() == 2) {
			// 咨询家庭医生
			SignFamily sf = signFamilyDao.findByjiatingPatient(patient);
			if (sf == null) {
				// 不存在家庭签约
				return -1;
			}
			// 设置健康管理师,家庭医生咨询默认给健康管理师处理
			//查找病人所在的团队
			DoctorTeam doctorTeam=doctorTeamDao.findByParientCode(patient);
			//得到团队的健康管理师
			DoctorTeamMember doctorTeamMember = doctorTeamDoctor.findDoctorJiating2ByTeam(doctorTeam.getCode(),3);
			// 设置家庭医生
			ct.setDoctor( doctorTeamMember.getMemberCode());
		}
		// 设置患者信息
		ct.setPatient(patient);
		// 查询患者信息
		Patient tempPatient = patientDao.findByCode(patient);
		// 设置患者姓名
		ct.setName(tempPatient.getName());
		// 设置患者生日
		ct.setBirthday(tempPatient.getBirthday());
		//新增性别
		ct.setSex(tempPatient.getSex());
		// 设置患者头像
		ct.setPhoto(tempPatient.getPhoto());
		// 设置操作日期
		ct.setCzrq(new Date());
		ct.setDel("1");
		ct.setStatus(0);
		// 医生未读数量为1
		ct.setDoctorRead(1);
		// 添加咨询记录
		Consult consult = addConsult(ct.getPatient(), null, ct.getSymptoms(), ct.getImages(), ct.getType());
		// 设置咨询标识
		ct.setConsult(consult.getCode());
		// 保存医生咨询信息
		if (consultTeamDao.save(ct) == null) {
			throw new Exception("保存失败!");
		}
		// 添加咨询转发记录
		ConsultTeamDoctor cd = new ConsultTeamDoctor();
		cd.setConsult(consult.getCode());
		cd.setDel("1");
		cd.setCzrq(new Date());
		cd.setTo(ct.getDoctor());
		consultTeamDoctorDao.save(cd);
		// 添加医生咨询日志
		addLogs(ct);
		return 1;
	}
	/**
	 * 添加三师咨询日志
	 * @param ct
	 * @throws Exception
	 */
	private void addLogs(ConsultTeam ct) throws Exception {
		List<ConsultTeamLog> logs = new ArrayList<ConsultTeamLog>();
		// 添加问题咨询日志
		String content ="";
			content = "咨询问题:" + (StringUtils.isEmpty(ct.getSymptoms()) ? "无" : ct.getSymptoms());
		// 生成提问日志,并推送相关消息
		ConsultTeamLog infoLog = new ConsultTeamLog();
		infoLog.setConsult(ct.getConsult());
		infoLog.setContent(content);
		infoLog.setDel("1");
		infoLog.setType(0);
		infoLog.setChatType(1);
		infoLog.setCzrq(new Date());
		logs.add(infoLog);
		// 图片日志
		if (StringUtils.isNotEmpty(ct.getImages())) {
			String[] images = ct.getImages().split(",");
			for (String image : images) {
				if (StringUtils.isNoneEmpty(image)) {
					ConsultTeamLog imgLog = new ConsultTeamLog();
					// 设置咨询标识
					imgLog.setConsult(ct.getConsult());
					// 设置图片URL
					imgLog.setContent(image);
					imgLog.setDel("1");
					infoLog.setType(0);
					imgLog.setCzrq(new Date());
					// 图片类型
					imgLog.setChatType(2);
					// 添加到待保存队列
					logs.add(imgLog);
				}
			}
		}
		// 语音日志
		if (StringUtils.isNotEmpty(ct.getVoice())) {
			ConsultTeamLog voiceLog = new ConsultTeamLog();
			// 设置咨询标识
			voiceLog.setConsult(ct.getConsult());
			// 设置语音URL
			voiceLog.setContent(ct.getVoice());
			voiceLog.setDel("1");
			infoLog.setType(0);
			// 语音类型
			voiceLog.setChatType(3);
			voiceLog.setCzrq(new Date());
			// 添加到待保存队列
			logs.add(voiceLog);
		}
		if (!logs.isEmpty()) {
			Iterable<ConsultTeamLog> iterable = consultTeamLogDao.save(logs);
			if (iterable == null || iterable.iterator() == null || !iterable.iterator().hasNext()) {
				// 日志保存失败
				throw new Exception("consult team log save failed!");
			}
		}
		// 患者提问或追问,给医生发消息
		// sendMessage(ct.getDoctor(), ct.getPatient(), "三师咨询", "您有新的三师咨询消息", ct.getConsult(), 116, 1, 0, 0);
	}
	/**
	 * 查询咨询列表
	 * @param patientCode 患者标志
	 * @param status 咨询状态(0未结束,1已结束,-1 已取消)
	 * @param pageSize 页数
	 * @return
	 */
	public Page<ConsultTeam> findByPatient(String patientCode, int status, long id, int pageSize) {
		if (id < 0) {
			id = 0;
		}
		if (pageSize <= 0) {
			pageSize = 10;
		}
		// 排序
		Sort sort = new Sort(Direction.DESC, "id");
		// 分页信息
		PageRequest pageRequest = new PageRequest(0, pageSize, sort);
		Page<ConsultTeam> list = null;
		switch (status) {
		case 0:
			// 未结束
			if (id > 0) {
				list = consultTeamDao.findNotFinishedBypatient(patientCode, id, pageRequest);
			} else {
				list = consultTeamDao.findNotFinishedBypatient(patientCode, pageRequest);
			}
			break;
		case 1:
			// 已结束
			if (id > 0) {
				list = consultTeamDao.findFinishedBypatient(patientCode, id, pageRequest);
			} else {
				list = consultTeamDao.findFinishedBypatient(patientCode, pageRequest);
			}
			break;
		case -1:
			// 已取消
			if (id > 0) {
				list = consultTeamDao.findCancelBypatient(patientCode, id, pageRequest);
			} else {
				list = consultTeamDao.findCancelBypatient(patientCode, pageRequest);
			}
			break;
		}
		return list;
	}
	/**
	 * 医生关闭三师咨询
	 * @param consult 三师咨询标识
	 * @return
	 */
	public int finish(String consult) {
		return consultTeamDao.updateStatusByConsult(consult);
	}
	/**
	 * 设置咨询已读
	 *
	 * @param consult
	 * @return
	 */
	public int readMessage(String consult){
    @Autowired
    private DoctorTeamMemberDao doctorTeamDoctor;
    @Autowired
    private JdbcTemplate jdbcTemplate;
    /**
     * 查询患者是否还有未结束的三师咨询
     *
     * @param patient
     * @return
     */
    public boolean exist(String patient, Integer type) {
        int count = consultTeamDao.countByPatient(patient, type);
        return count > 0;
    }
    /**
     * 查詢醫生網絡諮詢列表
     *
     * @param type     咨询类型:1、咨询我的,2、公共的, 3、参与过的,4、已结束的 5 名医咨询 全部  6 名医咨询 进行中 7 名医咨询 已结束
     * @param id
     * @param pagesize 每页显示数,默认为10
     * @return
     */
    public Page<ConsultTeam> findByDoctor(String uid, int type, long id, int pagesize, String title) {
        if (id < 0) {
            id = 0;
        }
        if (pagesize <= 0) {
            pagesize = 10;
        }
        switch (type) {
            case 0:
                // 全部
                return findByDoctorType0(uid, id, pagesize);
            case 1:
                // 咨询我的
                return findByDoctorType1(uid, type, id, pagesize);
            case 2:
                // 我感兴趣的
                return findByDoctorType2(uid, type, id, pagesize);
            case 3:
                // 我回复的
                return findByDoctorType3(uid, id, pagesize);
            case 4:
                // 已完成的
                return findByDoctorType4(uid, id, pagesize);
            case 5:
                // 5 名医咨询 全部
                return findByDoctorType5(uid, id, pagesize, title);
            case 6:
                //6 名医咨询 进行中
                return findByDoctorTypeSix(uid, id, pagesize, title);
            case 7:
                //7 名医咨询 已结束
                return findByDoctorType6(uid, 1, id, pagesize, title);
            case 8:
                return findByDoctorType8(uid, id, pagesize, title);
        }
        return null;
    }
    private Page<ConsultTeam> findByDoctorTypeSix(String uid,long id,int pagesize,String title){
        Sort sort = new Sort(Direction.DESC, "id");
        // 分页信息
        PageRequest pageRequest = new PageRequest(0, pagesize, sort);
        if (StringUtils.isNoneEmpty(title)) {
            title = "%" + title + "%";
            if (id > 0) {
                return consultTeamDao.findFamousDoctorIngList(uid, id, title, pageRequest);
            } else {
                return consultTeamDao.findFamousDoctorIngList(uid, title, pageRequest);
            }
        } else {
            if (id > 0) {
                return consultTeamDao.findFamousDoctorIngNoTitleList(uid, id, pageRequest);
            } else {
                return consultTeamDao.findFamousDoctorIngNoTitleList(uid, pageRequest);
            }
        }
    }
    private Page<ConsultTeam> findByDoctorType8(String uid,long id,int pagesize,String title){
        Sort sort = new Sort(Direction.DESC, "id");
        // 分页信息
        PageRequest pageRequest = new PageRequest(0, pagesize, sort);
        if (StringUtils.isNoneEmpty(title)) {
            title = "%" + title + "%";
            if (id > 0) {
                return consultTeamDao.findFamousDoctorUnReplyReadList(uid, id, title, pageRequest);
            } else {
                return consultTeamDao.findFamousDoctorUnReplyReadList(uid, title, pageRequest);
            }
        } else {
            if (id > 0) {
                return consultTeamDao.findFamousDoctorUnReplyReadNoTitleList(uid, id, pageRequest);
            } else {
                return consultTeamDao.findFamousDoctorUnReplyReadNoTitleList(uid, pageRequest);
            }
        }
    }
    private Page<ConsultTeam> findByDoctorType5(String uid, long id, int pagesize, String title) {
        Sort sort = new Sort(Direction.DESC, "id");
        // 分页信息
        PageRequest pageRequest = new PageRequest(0, pagesize, sort);
        if (StringUtils.isNoneEmpty(title)) {
            title = "%" + title + "%";
            if (id > 0) {
                return consultTeamDao.findFamousDoctorAllList(uid, id, title, pageRequest);
            } else {
                return consultTeamDao.findFamousDoctorAllList(uid, title, pageRequest);
            }
        } else {
            if (id > 0) {
                return consultTeamDao.findFamousDoctorAllList(uid, id, pageRequest);
            } else {
                return consultTeamDao.findFamousDoctorAllList(uid, pageRequest);
            }
        }
    }
    private Page<ConsultTeam> findByDoctorType6(String uid, int type, long id, int pagesize, String title) {
        // 排序
        Sort sort = new Sort(Direction.DESC, "id");
        // 分页信息
        PageRequest pageRequest = new PageRequest(0, pagesize, sort);
        if (StringUtils.isNoneEmpty(title)) {
            title = "%" + title + "%";
            if (id > 0) {
                return consultTeamDao.findFamousDoctorDoingList(uid, id, title, type, pageRequest);
            } else {
                return consultTeamDao.findFamousDoctorDoingList(uid, title, type, pageRequest);
            }
        } else {
            if (id > 0) {
                return consultTeamDao.findFamousDoctorDoingList(uid, id, type, pageRequest);
            } else {
                return consultTeamDao.findFamousDoctorDoingList(uid, type, pageRequest);
            }
        }
    }
    /**
     * 查询全部咨询记录
     *
     * @param uid
     * @param id
     * @param pagesize
     * @return
     */
    public Page<ConsultTeam> findByDoctorType0(String uid, long id, int pagesize) {
        // 排序
        Sort sort = new Sort(Direction.DESC, "id");
        // 分页信息
        PageRequest pageRequest = new PageRequest(0, pagesize, sort);
        if (id > 0) {
            return consultTeamDao.findDoctorList(uid, id, pageRequest);
        } else {
            return consultTeamDao.findDoctorList(uid, pageRequest);
        }
    }
    /**
     * 指定医生三师咨询列表查询
     *
     * @param uid      医生标识
     * @param type     咨询类型:1、咨询我的,2、公共的, 3、参与过的,4、已结束的
     * @param pagesize
     * @return
     */
    public Page<ConsultTeam> findByDoctorType1(String uid, int type, long id, int pagesize) {
        // 排序
        Sort sort = new Sort(Direction.DESC, "id");
        // 分页信息
        PageRequest pageRequest = new PageRequest(0, pagesize, sort);
        if (id > 0) {
            return consultTeamDao.findDoctorPointList(uid, id, pageRequest);
        } else {
            return consultTeamDao.findDoctorPointList(uid, pageRequest);
        }
    }
    /**
     * 公共三师咨询列表查询
     *
     * @param uid      医生标识
     * @param type     咨询类型:1、咨询我的,2、公共的, 3、参与过的,4、已结束的
     * @param pagesize
     * @return
     */
    public Page<ConsultTeam> findByDoctorType2(String uid, int type, long id, int pagesize) {
        // 排序
        Sort sort = new Sort(Direction.DESC, "id");
        // 分页信息
        PageRequest pageRequest = new PageRequest(0, pagesize, sort);
        // 设置查询条件
        Map<String, SearchFilter> filters = new HashMap<String, SearchFilter>();
        // 未指定医生
        filters.put("type", new SearchFilter("type", Operator.EQ, 0));
        if (id > 0) {
            filters.put("id", new SearchFilter("id", Operator.LT, id));
        }
        // 未回复
        filters.put("status", new SearchFilter("status", Operator.EQ, 0));
        // 未作废
        filters.put("del", new SearchFilter("del", Operator.EQ, "1"));
        Specification<ConsultTeam> spec = DynamicSpecifications.bySearchFilter(filters.values(), ConsultTeam.class);
        return consultTeamDao.findAll(spec, pageRequest);
    }
    /**
     * 医生参与过的未结束的三师咨询列表查询
     *
     * @param uid
     * @param pagesize
     * @return
     */
    public Page<ConsultTeam> findByDoctorType3(String uid, long id, int pagesize) {
        // 排序
        Sort sort = new Sort(Direction.DESC, "id");
        // 分页信息
        PageRequest pageRequest = new PageRequest(0, pagesize, sort);
        if (id > 0) {
            return consultTeamDao.findDoctorJoinList(uid, id, pageRequest);
        } else {
            return consultTeamDao.findDoctorJoinList(uid, pageRequest);
        }
    }
    /**
     * 医生参与过的已结束的三师咨询列表查询
     *
     * @param uid
     * @param pagesize
     * @return
     */
    public Page<ConsultTeam> findByDoctorType4(String uid, long id, int pagesize) {
        // 排序
        Sort sort = new Sort(Direction.DESC, "id");
        // 分页信息
        PageRequest pageRequest = new PageRequest(0, pagesize, sort);
        if (id > 0) {
            return consultTeamDao.findDoctorFinishList(uid, id, pageRequest);
        } else {
            return consultTeamDao.findDoctorFinishList(uid, pageRequest);
        }
    }
    /**
     * 网络咨询咨询日志查询
     *
     * @param consult  咨询标识
     * @param pagesize 每页显示数,默认为10
     * @return
     */
    public Page<ConsultTeamLog> findLogByConsult(String consult, long id, int pagesize) {
        if (id < 0) {
            id = 0;
        }
        // 设置查询条件
        Map<String, SearchFilter> filters = new HashMap<String, SearchFilter>();
        filters.put("consult", new SearchFilter("consult", Operator.EQ, consult));
        if (id > 0) {
            if (pagesize > 0)
                filters.put("id", new SearchFilter("id", Operator.LT, id));
            else
                filters.put("id", new SearchFilter("id", Operator.GT, id));
        }
        filters.put("del", new SearchFilter("del", Operator.EQ, "1"));
        Specification<ConsultTeamLog> spec = DynamicSpecifications.bySearchFilter(filters.values(), ConsultTeamLog.class);
        if (pagesize <= 0) {
            Page<ConsultTeamLog> p = new PageImpl<>(consultTeamLogDao.findAll(spec));
            return p;
        }
        // 排序
        Sort sort = new Sort(Direction.DESC, "id");
        // 分页信息
        PageRequest pageRequest = new PageRequest(0, pagesize, sort);
        return consultTeamLogDao.findAll(spec, pageRequest);
    }
    /**
     * 批量回复
     *
     * @param logs
     * @return
     */
    public void reply(List<ConsultTeamLog> logs, String patient) {
        for (ConsultTeamLog log : logs) {
            reply(log, patient, null, log.getType());
        }
    }
    /**
     * 添加咨询记录
     *
     * @param log  日志对象
     * @param type 类型,0问,1回复,2追问,3评价
     * @return
     */
    public ConsultTeamLog reply(ConsultTeamLog log, String patient, String teamOrDoctor, int type) {
        log.setCzrq(clock.getCurrentDate());
        // 保存咨询记录
        ConsultTeamLog temp = consultTeamLogDao.save(log);
        if (temp != null) {
            // 发送消息
            if (type == 1) {
                // 医生回复,给患者发消息
                // sendMessage(patient, teamOrDoctor, "三师咨询", log.getDoctorName() + "回复了您的咨询", log.getConsult(), 214, 1, 0, 0);
                // 患者未读数量+1
                consultTeamDao.increasePatientRead(log.getConsult());
                // 医生有回复
                consultTeamDoctorDao.updateReply(log.getConsult(), teamOrDoctor);
                //shenzaixin v1.2.0 推送消息给患者
                HttpUtil.sendWeixinWebsocketMsg(patient, "{busiType:'qianyuezixun',msgid:'" + log.getId() + "'}");
            } else if (type == 0 || type == 2) {
                // 查询相关联的医生
                Iterable<ConsultTeamDoctor> iterable = consultTeamDoctorDao.findByConsult(log.getConsult());
                if (iterable != null && iterable.iterator() != null && iterable.iterator().hasNext()) {
                    Iterator<ConsultTeamDoctor> iterator = iterable.iterator();
                    while (iterator.hasNext()) {
                        // 患者提问或追问,给医生发消息
                        ConsultTeamDoctor ctd = iterator.next();
                        if (ctd == null) {
                            continue;
                        }
                        // 推送消息给医生
                        PushMsgTask.getInstance().put(ctd.getTo(), MessageType.MESSAGE_TYPE_DOCTOR_NEW_CONSULT_TEAM_REPLY.D_CT_02.name(), MessageType.MESSAGE_TYPE_DOCTOR_NEW_CONSULT_TEAM_REPLY.指定咨询.name(), MessageType.MESSAGE_TYPE_DOCTOR_NEW_CONSULT_TEAM_REPLY.您有新的消息.name(), temp.getConsult());
                    }
                }
                // 医生未读数量+1
                consultTeamDao.increaseDoctorRead(log.getConsult());
            }
        }
        return temp;
    }
    /**
     * 添加三师咨询
     *
     * @param ct      三师咨询对象
     * @param patient 患者标识
     * @return
     * @throws Exception
     */
    public int addTeamConsult(ConsultTeam ct, String patient) throws Exception {
        // 咨询三师
        if (ct.getType() == 1) {
            // 查询三师签约信息
            SignFamily sc = signFamilyDao.findBySanshiPatientYes(patient);
            if (sc == null) {
                // 不存在三师签约
                return -2;
            }
            ct.setTeam(sc.getTeamCode());
            // 设置健康管理师,三师咨询默认给健康管理师处理
            //查找病人所在的团队
            DoctorTeam doctorTeam = doctorTeamDao.findBySanshiParientCode(patient);
            //得到团队的健康管理师
            DoctorTeamMember doctorTeamMember = doctorTeamDoctor.findDoctorSanshi2ByTeam(doctorTeam.getCode(), 3);
            // 设置家庭医生
            ct.setDoctor(doctorTeamMember.getMemberCode());
        } else if (ct.getType() == 2) {
            // 咨询家庭医生
            SignFamily sf = signFamilyDao.findByjiatingPatient(patient);
            if (sf == null) {
                // 不存在家庭签约
                return -1;
            }
            // 设置健康管理师,家庭医生咨询默认给健康管理师处理
            //查找病人所在的团队
            DoctorTeam doctorTeam = doctorTeamDao.findByParientCode(patient);
            //得到团队的健康管理师
            DoctorTeamMember doctorTeamMember = doctorTeamDoctor.findDoctorJiating2ByTeam(doctorTeam.getCode(), 3);
            // 设置家庭医生
            ct.setDoctor(doctorTeamMember.getMemberCode());
        }
        // 设置患者信息
        ct.setPatient(patient);
        // 查询患者信息
        Patient tempPatient = patientDao.findByCode(patient);
        // 设置患者姓名
        ct.setName(tempPatient.getName());
        // 设置患者生日
        ct.setBirthday(tempPatient.getBirthday());
        //新增性别
        ct.setSex(tempPatient.getSex());
        // 设置患者头像
        ct.setPhoto(tempPatient.getPhoto());
        // 设置操作日期
        ct.setCzrq(new Date());
        ct.setDel("1");
        ct.setStatus(0);
        // 医生未读数量为1
        ct.setDoctorRead(1);
        // 添加咨询记录
        Consult consult = addConsult(ct.getPatient(), null, ct.getSymptoms(), ct.getImages(), ct.getType());
        // 设置咨询标识
        ct.setConsult(consult.getCode());
        // 保存医生咨询信息
        if (consultTeamDao.save(ct) == null) {
            throw new Exception("保存失败!");
        }
        // 添加咨询转发记录
        ConsultTeamDoctor cd = new ConsultTeamDoctor();
        cd.setConsult(consult.getCode());
        cd.setDel("1");
        cd.setCzrq(new Date());
        cd.setTo(ct.getDoctor());
        consultTeamDoctorDao.save(cd);
        // 添加医生咨询日志
        addLogs(ct);
        return 1;
    }
    /**
     * 添加三师咨询日志
     *
     * @param ct
     * @throws Exception
     */
    private void addLogs(ConsultTeam ct) throws Exception {
        List<ConsultTeamLog> logs = new ArrayList<ConsultTeamLog>();
        // 添加问题咨询日志
        String content = "";
        content = "咨询问题:" + (StringUtils.isEmpty(ct.getSymptoms()) ? "无" : ct.getSymptoms());
        // 生成提问日志,并推送相关消息
        ConsultTeamLog infoLog = new ConsultTeamLog();
        infoLog.setConsult(ct.getConsult());
        infoLog.setContent(content);
        infoLog.setDel("1");
        infoLog.setType(0);
        infoLog.setChatType(1);
        infoLog.setCzrq(new Date());
        logs.add(infoLog);
        // 图片日志
        if (StringUtils.isNotEmpty(ct.getImages())) {
            String[] images = ct.getImages().split(",");
            for (String image : images) {
                if (StringUtils.isNoneEmpty(image)) {
                    ConsultTeamLog imgLog = new ConsultTeamLog();
                    // 设置咨询标识
                    imgLog.setConsult(ct.getConsult());
                    // 设置图片URL
                    imgLog.setContent(image);
                    imgLog.setDel("1");
                    infoLog.setType(0);
                    imgLog.setCzrq(new Date());
                    // 图片类型
                    imgLog.setChatType(2);
                    // 添加到待保存队列
                    logs.add(imgLog);
                }
            }
        }
        // 语音日志
        if (StringUtils.isNotEmpty(ct.getVoice())) {
            ConsultTeamLog voiceLog = new ConsultTeamLog();
            // 设置咨询标识
            voiceLog.setConsult(ct.getConsult());
            // 设置语音URL
            voiceLog.setContent(ct.getVoice());
            voiceLog.setDel("1");
            infoLog.setType(0);
            // 语音类型
            voiceLog.setChatType(3);
            voiceLog.setCzrq(new Date());
            // 添加到待保存队列
            logs.add(voiceLog);
        }
        if (!logs.isEmpty()) {
            Iterable<ConsultTeamLog> iterable = consultTeamLogDao.save(logs);
            if (iterable == null || iterable.iterator() == null || !iterable.iterator().hasNext()) {
                // 日志保存失败
                throw new Exception("consult team log save failed!");
            }
        }
        // 患者提问或追问,给医生发消息
        // sendMessage(ct.getDoctor(), ct.getPatient(), "三师咨询", "您有新的三师咨询消息", ct.getConsult(), 116, 1, 0, 0);
    }
    /**
     * 查询咨询列表
     *
     * @param patientCode 患者标志
     * @param status      咨询状态(0未结束,1已结束,-1 已取消)
     * @param pageSize    页数
     * @return
     */
    public Page<ConsultTeam> findByPatient(String patientCode, int status, long id, int pageSize) {
        if (id < 0) {
            id = 0;
        }
        if (pageSize <= 0) {
            pageSize = 10;
        }
        // 排序
        Sort sort = new Sort(Direction.DESC, "id");
        // 分页信息
        PageRequest pageRequest = new PageRequest(0, pageSize, sort);
        Page<ConsultTeam> list = null;
        switch (status) {
            case 0:
                // 未结束
                if (id > 0) {
                    list = consultTeamDao.findNotFinishedBypatient(patientCode, id, pageRequest);
                } else {
                    list = consultTeamDao.findNotFinishedBypatient(patientCode, pageRequest);
                }
                break;
            case 1:
                // 已结束
                if (id > 0) {
                    list = consultTeamDao.findFinishedBypatient(patientCode, id, pageRequest);
                } else {
                    list = consultTeamDao.findFinishedBypatient(patientCode, pageRequest);
                }
                break;
            case -1:
                // 已取消
                if (id > 0) {
                    list = consultTeamDao.findCancelBypatient(patientCode, id, pageRequest);
                } else {
                    list = consultTeamDao.findCancelBypatient(patientCode, pageRequest);
                }
                break;
        }
        return list;
    }
    /**
     * 医生关闭三师咨询
     *
     * @param consult 三师咨询标识
     * @return
     */
    public int finish(String consult) {
        return consultTeamDao.updateStatusByConsult(consult);
    }
    /**
     * 设置咨询已读
     *
     * @param consult
     * @return
     */
    public int readMessage(String consult) {
        return consultTeamDao.updateReadedByConsult(consult);
	}
	/**
	 * 取消三师咨询
	 * @param consult
	 * @return
	 */
	public int cancel(String consult) {
		return consultTeamDao.cancel(consult);
	}
	public ConsultTeam findByCode(String code) {
		return consultTeamDao.findByConsult(code);
	}
	/**
	 * 三师咨询转接医生
	 * @param from 转出医生标识
	 * @param to 转入医生标识
	 * @param consult 三师咨询标识
	 * @return
	 */
	public void transfer(String from, String to, String consult) {
		// 检查是否存在
		if (consultTeamDoctorDao.isExist(consult, to) == 0) {
			// 查询医生信息
			Doctor d = doctorDao.findByCode(from);
			// 再保存
			ConsultTeamDoctor cd = new ConsultTeamDoctor();
			cd.setConsult(consult);
			cd.setDel("1");
			cd.setCzrq(new Date());
			cd.setFrom(d.getCode());
			cd.setFromName(d.getName());
			cd.setTo(to);
			consultTeamDoctorDao.save(cd);
		}
	}
	/**
	 * 查询患者视频和三师咨询记录
	 * @param patient 患者标识
	 * @param id
	 * @param pagesize
	 * @return
	 */
	public Page<Consult> findConsultRecordByPatientType(String patient, long id, int pagesize) {
		if (pagesize <= 0) {
			pagesize = 10;
		}
		// 排序
		Sort sort = new Sort(Direction.DESC, "id");
		// 分页信息
		PageRequest pageRequest = new PageRequest(0, pagesize, sort);
		// 设置查询条件
		Map<String, SearchFilter> filters = new HashMap<String, SearchFilter>();
		filters.put("patient", new SearchFilter("patient", Operator.EQ, patient));
		filters.put("type", new SearchFilter("type", Operator.LT, 3));
		if (id > 0) {
			filters.put("id", new SearchFilter("id", Operator.LT, id));
		}
		// 未作废
		filters.put("del", new SearchFilter("del", Operator.EQ, "1"));
		Specification<Consult> spec = DynamicSpecifications.bySearchFilter(filters.values(), Consult.class);
		return consultDao.findAll(spec, pageRequest);
	}
	/**
	 * 清空医生未读数量
	 * @param consult
	 */
	public void clearDoctorRead(String consult) {
		consultTeamDao.clearDoctorRead(consult);
	}
	/**
	 * 清空患者未读数量
	 * @param consult
	 */
	public void clearPatientRead(String consult) {
		consultTeamDao.clearPatientRead(consult);
	}
	/**
	 * 查询医生的咨询统计
	 *
	 * @param doctorCode
	 * @return
	 */
	public Map<String,Long> getAllCount(String doctorCode) {
		Map<String,Long> result = new HashMap<>();
		//根据医生code查询总咨询数  
		 long allCount=consultTeamDoctorDao.getAllCountByDoctorCode(doctorCode);
		
		//根据医生code查询今日咨询数
		 long todayCount=consultTeamDoctorDao.getTodayCountByDoctorCode(doctorCode);
		result.put("all",allCount);
		result.put("today",todayCount);
		return result;
	}
	/**
	 * 查找未完成咨询
	 *
	 * @param patient
	 * @return
	 */
	public List<ConsultTeam> getUnfinishedConsult(String patient){
		return consultTeamDao.findUnfinishedConsult(patient);
	}
	/**
	 * 查询患者全部的咨询数目
	 * @param patientCode
	 * @return
    }
    /**
     * 取消三师咨询
     *
     * @param consult
     * @return
     */
    public int cancel(String consult) {
        return consultTeamDao.cancel(consult);
    }
    public ConsultTeam findByCode(String code) {
        return consultTeamDao.findByConsult(code);
    }
    /**
     * 三师咨询转接医生
     *
     * @param from    转出医生标识
     * @param to      转入医生标识
     * @param consult 三师咨询标识
     * @return
     */
    public void transfer(String from, String to, String consult) {
        // 检查是否存在
        if (consultTeamDoctorDao.isExist(consult, to) == 0) {
            // 查询医生信息
            Doctor d = doctorDao.findByCode(from);
            // 再保存
            ConsultTeamDoctor cd = new ConsultTeamDoctor();
            cd.setConsult(consult);
            cd.setDel("1");
            cd.setCzrq(new Date());
            cd.setFrom(d.getCode());
            cd.setFromName(d.getName());
            cd.setTo(to);
            consultTeamDoctorDao.save(cd);
        }
    }
    /**
     * 查询患者视频和三师咨询记录
     *
     * @param patient  患者标识
     * @param id
     * @param pagesize
     * @return
     */
    public Page<Consult> findConsultRecordByPatientType(String patient, long id, int pagesize) {
        if (pagesize <= 0) {
            pagesize = 10;
        }
        // 排序
        Sort sort = new Sort(Direction.DESC, "id");
        // 分页信息
        PageRequest pageRequest = new PageRequest(0, pagesize, sort);
        // 设置查询条件
        Map<String, SearchFilter> filters = new HashMap<String, SearchFilter>();
        filters.put("patient", new SearchFilter("patient", Operator.EQ, patient));
        filters.put("type", new SearchFilter("type", Operator.LT, 3));
        if (id > 0) {
            filters.put("id", new SearchFilter("id", Operator.LT, id));
        }
        // 未作废
        filters.put("del", new SearchFilter("del", Operator.EQ, "1"));
        Specification<Consult> spec = DynamicSpecifications.bySearchFilter(filters.values(), Consult.class);
        return consultDao.findAll(spec, pageRequest);
    }
    /**
     * 清空医生未读数量
     *
     * @param consult
     */
    public void clearDoctorRead(String consult) {
        consultTeamDao.clearDoctorRead(consult);
    }
    /**
     * 清空患者未读数量
     *
     * @param consult
     */
    public void clearPatientRead(String consult) {
        consultTeamDao.clearPatientRead(consult);
    }
    /**
     * 查询医生的咨询统计
     *
     * @param doctorCode
     * @return
     */
    public Map<String, Long> getAllCount(String doctorCode) {
        Map<String, Long> result = new HashMap<>();
        //根据医生code查询总咨询数
        long allCount = consultTeamDoctorDao.getAllCountByDoctorCode(doctorCode);
        //根据医生code查询今日咨询数
        long todayCount = consultTeamDoctorDao.getTodayCountByDoctorCode(doctorCode);
        result.put("all", allCount);
        result.put("today", todayCount);
        return result;
    }
    /**
     * 查找未完成咨询
     *
     * @param patient
     * @return
     */
    public List<ConsultTeam> getUnfinishedConsult(String patient) {
        return consultTeamDao.findUnfinishedConsult(patient);
    }
    /**
     * 查询患者全部的咨询数目
     *
     * @param patientCode
     * @return
     */
	public Integer findByDoctorSize(String patientCode,String doctorCode) {
		return consultDao.findByPatient(patientCode,doctorCode);
	}
	public List<Map<String,Object>> getConsultSign(String[] consults){
		String params =  "";
		List<String> paramList = new ArrayList<>();
		for(int i = 0; i < consults.length ; i++){
			params += (i == 0?"?":",?");
		}
		paramList.addAll(Arrays.asList(consults));
		paramList.addAll(Arrays.asList(consults));
		String sqlgp = "select DISTINCT consult,to_doctor from wlyy_consult_team_doctor ctd,wlyy_doctor d where ctd.to_doctor = d.code and d.level = 2 and ctd.consult in (" + params + ") and ctd.del = '1'";
		String sqlgpm = "select DISTINCT to_doctor from wlyy_consult_team_doctor ctd,wlyy_doctor d where ctd.to_doctor = d.code and d.level = 2 and ctd.consult in (" + params + ") and ctd.del = '1'";
		String sqlQu = "select * from wlyy_quota_result where qkdoctor_code in (" + sqlgpm+ ") and quato_code = '1' and level1_type = '1'";
		String sqlQuSum = "select a.consult,sum(ifnull(b.result,0)) sign from ("+ sqlgp +") a left join (" + sqlQu+ ") b on a.to_doctor = b.qkdoctor_code group by a.consult ";
		return jdbcTemplate.queryForList(sqlQuSum,paramList.toArray());
	}
	public ConsultTeamLog oneLog(Long logId) {
		return consultTeamLogDao.findOne(logId);
	}
	public boolean isExistFamousConsult(String uid) {
		ConsultTeam consultTeam= consultTeamDao.findFamousConsultByPatient(uid);
		if(consultTeam!=null){
			return true;
		}else{
			return false;
		}
	}
	public void addFamousTeamConsult(ConsultTeam ct, String uid) throws Exception{
		// 设置患者信息
		ct.setPatient(uid);
		// 查询患者信息
		Patient tempPatient = patientDao.findByCode(uid);
		// 设置患者姓名
		ct.setName(tempPatient.getName());
		// 设置患者生日
		ct.setBirthday(tempPatient.getBirthday());
		//新增性别
		ct.setSex(tempPatient.getSex());
		// 设置患者头像
		ct.setPhoto(tempPatient.getPhoto());
		// 设置操作日期
		ct.setCzrq(new Date());
		ct.setDel("1");
		ct.setStatus(0);
		// 医生未读数量为1
		ct.setDoctorRead(1);
		// 患者未读数量为0
		ct.setPatientRead(0);
		// 添加咨询记录
		Consult consult = addConsult(ct.getPatient(), null, ct.getSymptoms(), ct.getImages(), ct.getType());
		// 设置咨询标识
		ct.setConsult(consult.getCode());
		// 保存医生咨询信息
		if (consultTeamDao.save(ct) == null) {
			throw new Exception("保存失败!");
		}
		// 添加咨询转发记录
		ConsultTeamDoctor cd = new ConsultTeamDoctor();
		cd.setConsult(consult.getCode());
		cd.setDel("1");
		cd.setCzrq(new Date());
		cd.setTo(ct.getDoctor());
		consultTeamDoctorDao.save(cd);
		// 添加医生咨询日志
		addLogs(ct);
	}
	/**
	 * 根据健康管理师和患者 找到正在进行中的咨询
	 * @param patientCode
	 * @param doctor
    public Integer findByDoctorSize(String patientCode, String doctorCode) {
        return consultDao.findByPatient(patientCode, doctorCode);
    }
    public List<Map<String, Object>> getConsultSign(String[] consults) {
        String params = "";
        List<String> paramList = new ArrayList<>();
        for (int i = 0; i < consults.length; i++) {
            params += (i == 0 ? "?" : ",?");
        }
        paramList.addAll(Arrays.asList(consults));
        paramList.addAll(Arrays.asList(consults));
        String sqlgp = "select DISTINCT consult,to_doctor from wlyy_consult_team_doctor ctd,wlyy_doctor d where ctd.to_doctor = d.code and d.level = 2 and ctd.consult in (" + params + ") and ctd.del = '1'";
        String sqlgpm = "select DISTINCT to_doctor from wlyy_consult_team_doctor ctd,wlyy_doctor d where ctd.to_doctor = d.code and d.level = 2 and ctd.consult in (" + params + ") and ctd.del = '1'";
        String sqlQu = "select * from wlyy_quota_result where qkdoctor_code in (" + sqlgpm + ") and quato_code = '1' and level1_type = '1'";
        String sqlQuSum = "select a.consult,sum(ifnull(b.result,0)) sign from (" + sqlgp + ") a left join (" + sqlQu + ") b on a.to_doctor = b.qkdoctor_code group by a.consult ";
        return jdbcTemplate.queryForList(sqlQuSum, paramList.toArray());
    }
    public ConsultTeamLog oneLog(Long logId) {
        return consultTeamLogDao.findOne(logId);
    }
    public boolean isExistFamousConsult(String uid) {
        ConsultTeam consultTeam = consultTeamDao.findFamousConsultByPatient(uid);
        if (consultTeam != null) {
            return true;
        } else {
            return false;
        }
    }
    public void addFamousTeamConsult(ConsultTeam ct, String uid) throws Exception {
        // 设置患者信息
        ct.setPatient(uid);
        // 查询患者信息
        Patient tempPatient = patientDao.findByCode(uid);
        // 设置患者姓名
        ct.setName(tempPatient.getName());
        // 设置患者生日
        ct.setBirthday(tempPatient.getBirthday());
        //新增性别
        ct.setSex(tempPatient.getSex());
        // 设置患者头像
        ct.setPhoto(tempPatient.getPhoto());
        // 设置操作日期
        ct.setCzrq(new Date());
        ct.setDel("1");
        ct.setStatus(0);
        // 医生未读数量为1
        ct.setDoctorRead(1);
        // 患者未读数量为0
        ct.setPatientRead(0);
        // 添加咨询记录
        Consult consult = addConsult(ct.getPatient(), null, ct.getSymptoms(), ct.getImages(), ct.getType());
        // 设置咨询标识
        ct.setConsult(consult.getCode());
        // 保存医生咨询信息
        if (consultTeamDao.save(ct) == null) {
            throw new Exception("保存失败!");
        }
        // 添加咨询转发记录
        ConsultTeamDoctor cd = new ConsultTeamDoctor();
        cd.setConsult(consult.getCode());
        cd.setDel("1");
        cd.setCzrq(new Date());
        cd.setTo(ct.getDoctor());
        consultTeamDoctorDao.save(cd);
        // 添加医生咨询日志
        addLogs(ct);
    }
    /**
     * 根据健康管理师和患者 找到正在进行中的咨询
     *
     * @param patientCode
     * @param doctor
     */
	public ConsultTeam getConsultByPatientAndDoctor(String patientCode, String doctor) {
		ConsultTeam consultTeam= consultTeamDao.findByParientCodeAndSignTypeAndDoctor(patientCode,doctor,2);
		return consultTeam;
	}
	public void transfers(String uid, String doctor, String consult) {
		String[] doctors=doctor.split(",");
		for(int i=0;i<doctors.length;i++){
			transfer(uid,doctors[i],consult);
		}
	}
    public ConsultTeam getConsultByPatientAndDoctor(String patientCode, String doctor) {
        ConsultTeam consultTeam = consultTeamDao.findByParientCodeAndSignTypeAndDoctor(patientCode, doctor, 2);
        return consultTeam;
    }
    public void transfers(String uid, String doctor, String consult) {
        String[] doctors = doctor.split(",");
        for (int i = 0; i < doctors.length; i++) {
            transfer(uid, doctors[i], consult);
        }
    }
}

+ 77 - 0
src/main/java/com/yihu/wlyy/service/app/message/MessageService.java

@ -1,5 +1,6 @@
package com.yihu.wlyy.service.app.message;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
@ -7,6 +8,7 @@ import javax.transaction.Transactional;
import com.yihu.wlyy.entity.message.Message;
import com.yihu.wlyy.repository.message.MessageDao;
import com.yihu.wlyy.util.DateUtil;
import org.apache.commons.lang3.StringUtils;
import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
@ -61,6 +63,81 @@ public class MessageService extends BaseService {
		return json;
	}
	/**
	 * 查询医生未读消息和最后消息
	 *
	 * @param doctor
	 * @return
	 */
	public JSONObject findDoctorAllMessage(String doctor){
		// 三师咨询未读消息总数
		int consult = 0;
		JSONObject consultJson =  new JSONObject();
		try {
			consult = consultTeamDao.amountAllDoctorUnread(doctor);
		} catch (Exception e) {
		}
		consultJson.put("amount",consult);
		if(consult > 0){
			PageRequest pageRequest = new PageRequest(0,1);
			Page<Object> msgs = consultTeamDao.AllDoctorUnreadLast(doctor,pageRequest);
			if(msgs != null && msgs.getSize() > 0){
				for(Object msg : msgs){
					Object[] msgArray = (Object[])msg;
					JSONObject msgJson = new JSONObject();
					msgJson.put("msg",msgArray[0].toString() + "向您发来一个咨询");
					msgJson.put("msgTime",msgArray[1] != null? DateUtil.dateToStr((Date) msgArray[1],DateUtil.YYYY_MM_DD):"");
					consultJson.put("lastMessage",msgJson);
				}
			}
		}
		// 签约未读消息总数
		int sign = messageDao.amountUnreadByReceiver(doctor);
		JSONObject signJson =  new JSONObject();
		signJson.put("amount",sign);
		if(sign > 0){
			PageRequest pageRequest = new PageRequest(0,1);
			Page<Message> msgs = messageDao.amountUnreadLastByReceiver(doctor,pageRequest);
			if(msgs != null && msgs.getSize() > 0){
				for(Message msg : msgs){
					JSONObject msgJson = new JSONObject();
					msgJson.put("msg",msg.getSenderName() + "申请与您签约家庭医生");
					msgJson.put("msgTime",msg.getCzrq() != null? DateUtil.dateToStr((Date) msg.getCzrq(),DateUtil.YYYY_MM_DD):"");
					signJson.put("lastMessage",msgJson);
				}
			}
		}
		// 体征指标未读消息总数
		int healthIndex = messageDao.amountUnreadHealthByReceiver(doctor);
		JSONObject indexJson =  new JSONObject();
		indexJson.put("amount",healthIndex);
		if(sign > 0){
			PageRequest pageRequest = new PageRequest(0,1);
			Page<Message> msgs = messageDao.amountUnreadHealthLastByReceiver(doctor,pageRequest);
			if(msgs != null && msgs.getSize() > 0){
				for(Message msg : msgs){
					JSONObject msgJson = new JSONObject();
					msgJson.put("msg",msg.getContent());
					msgJson.put("msgTime",msg.getCzrq() != null? DateUtil.dateToStr((Date) msg.getCzrq(),DateUtil.YYYY_MM_DD):"");
					indexJson.put("lastMessage",msgJson);
				}
			}
		}
		JSONObject json = new JSONObject();
		json.put("consult", consultJson);
		json.put("sign", signJson);
		json.put("healthIndex", indexJson);
		return json;
	}
	/**
	 * 查询健康咨询列表
	 * @param doctor 医生标识

+ 3 - 2
src/main/java/com/yihu/wlyy/service/app/sign/FamilyContractService.java

@ -511,7 +511,7 @@ public class FamilyContractService extends BaseService {
        // 消息时间
        message.setCzrq(new Date());
        // 消息内容
        message.setContent("[" + patientName + "]申请解除与您的签约关系");
        message.setContent("申请解除与您的签约关系");
        // 未读
        message.setRead(1);
        message.setReceiverName(doctorName);
@ -1301,7 +1301,8 @@ public class FamilyContractService extends BaseService {
            pagesize = 10;
        }
        // 排序
        Sort sort = new Sort(Direction.DESC, "id");
        Sort sort = new Sort(Direction.DESC, "status");
        sort.and(new Sort(Direction.DESC,"read"));
        // 分页信息
        PageRequest pageRequest = new PageRequest(0, pagesize, sort);
        // 设置查询条件

+ 61 - 1
src/main/java/com/yihu/wlyy/web/doctor/consult/DoctorConsultController.java

@ -4,6 +4,8 @@ import java.util.List;
import java.util.Map;
import com.yihu.wlyy.service.app.health.PatientHealthGuidanceService;
import com.yihu.wlyy.service.app.scheduling.DoctorWorkTimeService;
import com.yihu.wlyy.service.common.account.DoctorService;
import io.swagger.annotations.Api;
import org.apache.commons.lang3.StringUtils;
import org.json.JSONArray;
@ -45,10 +47,14 @@ public class DoctorConsultController extends WeixinBaseController {
	private DoctorInfoService doctorInfoService;
	@Autowired
	private PatientHealthGuidanceService patientHealthGuidanceService;
	@Autowired
	private DoctorService doctorService;
	@Autowired
	private DoctorWorkTimeService doctorWorkTimeService;
	/**
	 * 三师咨询列表查询
	 * @param type 咨询类型:0、全部,1、咨询我的,2、公共的, 3、参与过的,4、已结束的  5 名医咨询 全部  6 名医咨询 进行中 7 名医咨询 已结束
	 * @param type 咨询类型:0、全部,1、咨询我的,2、公共的, 3、参与过的,4、已结束的  5 名医咨询 全部  6 名医咨询 进行中 7 名医咨询 已结束 8名医咨询 待处理
	 * @param id
	 * @param pagesize 每页显示数,默认为10
	 * @return
@ -106,6 +112,60 @@ public class DoctorConsultController extends WeixinBaseController {
		}
	}
	/**
	 * 名医列表
	 * @return
	 */
	@RequestMapping(value = "famousDoctorList")
	@ResponseBody
	public String famousDoctorList(
			@RequestParam(required = false) String name,
			int page,
			int pagesize) {
		try {
			JSONArray array = new JSONArray();
			Page<Doctor>list = doctorService.famousDoctorList(name, page, pagesize);
			if (list != null) {
				for (Doctor doctor : list) {
					if (doctor == null) {
						continue;
					}
					JSONObject json = new JSONObject();
					json.put("id", doctor.getId());
					// 医生标识
					json.put("code", doctor.getCode());
					// 医生性别
					json.put("sex", doctor.getSex());
					// 医生姓名
					json.put("name", doctor.getName());
					// 所在医院名称
					json.put("hospital", doctor.getHospital());
					// 所在医院名称
					json.put("hospital_name", doctor.getHosptialName());
					// 科室名称
					json.put("dept_name", (doctor.getDeptName() == null ||
							StringUtils.isEmpty(doctor.getDeptName().toString())) ? " " : doctor.getDeptName());
					// 职称名称
					json.put("job_name", (doctor.getJobName() == null ||
							StringUtils.isEmpty(doctor.getJobName().toString())) ? " " : doctor.getJobName());
					// 头像
					json.put("photo", doctor.getPhoto());
					// 简介
					json.put("introduce", doctor.getIntroduce());
					// 专长
					json.put("expertise", doctor.getExpertise());
					// 剩余咨询次数
					json.put("num", doctorWorkTimeService.getDoctorConsultTimesRemain(doctor.getCode()));
					array.put(json);
				}
			}
			return write(200, "获取医院医生列表成功!", "list", array);
		} catch (Exception e) {
			error(e);
			return error(-1, "获取医院医生列表失败!");
		}
	}
	/**
	 * 获取咨询全科医生签约量
	 *

+ 20 - 0
src/main/java/com/yihu/wlyy/web/doctor/message/DoctorMessageController.java

@ -44,6 +44,26 @@ public class DoctorMessageController extends BaseController {
		}
	}
	/**
	 * 医生消息总数统计接口
	 * @return
	 */
	@RequestMapping(value = "messages")
	@ResponseBody
	public String messages() {
		try {
			JSONObject json = messageService.findDoctorAllMessage("6c0cfe5065e011e69f7c005056850d66");
			if (json == null) {
				return error(-1, "获取消息总数失败!");
			} else {
				return write(200, "获取消息总数成功!", "data", json);
			}
		} catch (Exception e) {
			error(e);
			return error(-1, "获取消息总数失败!");
		}
	}
	/**
	 * 健康咨询消息列表查询接口
	 * @param id

+ 31 - 18
src/main/java/com/yihu/wlyy/web/doctor/sign/DoctorFamilyContractController.java

@ -273,17 +273,26 @@ public class DoctorFamilyContractController extends WeixinBaseController {
            int type, String group,
            @RequestParam(required = false, defaultValue = "0") String expenses) {
        try {
            String checkUrl = SystemConf.getInstance().getSystemProperties().getProperty("sign_check_upload");
            String jsonString = HttpUtil.sendPost(checkUrl + "/third/sign/CheckSignFamily?idcard=" + patientIDcard, "");
            JSONObject checkJson = new JSONObject(jsonString);
            try {
                String checkUrl = SystemConf.getInstance().getSystemProperties().getProperty("sign_check_upload");
                String jsonString = HttpUtil.sendPost(checkUrl + "/third/sign/CheckSignFamily?idcard=" + patientIDcard, "");
            if (checkJson.getInt("status") == 200) {
                JSONObject jsonData = checkJson.getJSONObject("data");
                if (!StringUtils.isEmpty(jsonString)) {
                    JSONObject checkJson = new JSONObject(jsonString);
                if (jsonData.getString("status").equals("1")) {
                    return error(-1,"此身份证号已签约");
                    if (checkJson.getInt("status") == 200) {
                        JSONObject jsonData = checkJson.getJSONObject("data");
                        if (jsonData.getString("status").equals("1")) {
                            return error(-1, "此身份证号已签约");
                        }
                    }
                }
            }catch (Exception e){
                e.printStackTrace();
            }
            int res = familyContractService.handleSign(signType, getAccessToken(), healthDoctor, healthDoctorName, msgid, patientIDcard, type, disease, majorDoctor, majorDoctorName, group, expenses);
            if (res == -1) {
                return error(-1, "未知的处理类型!");
@ -468,20 +477,24 @@ public class DoctorFamilyContractController extends WeixinBaseController {
            JSONObject result = new JSONObject();
            String checkUrl = SystemConf.getInstance().getSystemProperties().getProperty("sign_check_upload");
            String jsonString = HttpUtil.sendPost(checkUrl + "/third/sign/CheckSignFamily?idcard=" + idCard, "");
            JSONObject checkJson = new JSONObject(jsonString);
            try {
                String checkUrl = SystemConf.getInstance().getSystemProperties().getProperty("sign_check_upload");
                String jsonString = HttpUtil.sendPost(checkUrl + "/third/sign/CheckSignFamily?idcard=" + idCard, "");
            if (checkJson.getInt("status") == 200) {
                JSONObject jsonData = checkJson.getJSONObject("data");
                if (!StringUtils.isEmpty(jsonString)) {
                    JSONObject checkJson = new JSONObject(jsonString);
                    if (checkJson.getInt("status") == 200) {
                        JSONObject jsonData = checkJson.getJSONObject("data");
                if (jsonData.getString("status").equals("1")) {
                    result.put("signStatus", "2");
                    result.put("msg", "病人已申请过家庭签约!");
                    return write(200, "查询成功!", "data", result);
                        if (jsonData.getString("status").equals("1")) {
                            result.put("signStatus", "2");
                            result.put("msg", "病人已申请过家庭签约!");
                            return write(200, "查询成功!", "data", result);
                        }
                    }
                }
            } else {
                return error(-1,"签约验证异常!");
            }catch (Exception e){
                e.printStackTrace();
            }
            result = familyContractService.getSanshiSingInfoByPatientIdCard(idCard);