|  | @ -0,0 +1,379 @@
 | 
	
		
			
				|  |  | /*******************************************************************************
 | 
	
		
			
				|  |  |  * Copyright (c) 2005, 2014 springside.github.io
 | 
	
		
			
				|  |  |  * <p>
 | 
	
		
			
				|  |  |  * Licensed under the Apache License, Version 2.0 (the "License");
 | 
	
		
			
				|  |  |  *******************************************************************************/
 | 
	
		
			
				|  |  | package com.yihu.jw.door.dao.common;
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | import com.yihu.jw.entity.door.SignFamily;
 | 
	
		
			
				|  |  | import org.springframework.data.domain.Page;
 | 
	
		
			
				|  |  | 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;
 | 
	
		
			
				|  |  | import org.springframework.data.repository.PagingAndSortingRepository;
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | import java.util.Date;
 | 
	
		
			
				|  |  | import java.util.List;
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | public interface SignFamilyDao extends PagingAndSortingRepository<SignFamily, Long>, JpaSpecificationExecutor<SignFamily> {
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     @Query("select count(1) from SignFamily a where a.idcard = ?1 and a.type = 2 and a.status >= 0")
 | 
	
		
			
				|  |  |     int hasSingStatus(String idcard);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     @Modifying
 | 
	
		
			
				|  |  |     @Query("update SignFamily a set a.mobile = ?2 where a.patient = ?1")
 | 
	
		
			
				|  |  |     int updatePatientMobile(String patient, String mobile);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     //更新有效签约患者手机号
 | 
	
		
			
				|  |  |     @Modifying
 | 
	
		
			
				|  |  |     @Query("update SignFamily a set a.mobile = ?2 where a.patient = ?1 and a.status > 0 ")
 | 
	
		
			
				|  |  |     int updateSignMobile(String patient, String mobile);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     @Query("select a from SignFamily a where a.idcard = ?1 and status = ?2 and a.type = 2")
 | 
	
		
			
				|  |  |     SignFamily findByPatientStatus(String idcard, int status);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     @Query("select a from SignFamily a where a.patient = ?1 and status = ?2 and a.type = 2")
 | 
	
		
			
				|  |  |     SignFamily findByPatientCodeStatus(String patient, int status);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     @Query("select a from SignFamily a where a.patient = ?1 and status >= ?2 and a.type = 2")
 | 
	
		
			
				|  |  |     SignFamily findByPatientCodeStatus2(String patient, int status);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     @Query("select a from SignFamily a where a.patient = ?1 and a.type = ?2 and a.status >= 1")
 | 
	
		
			
				|  |  |     SignFamily findByPatientAndType(String patient, int type);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     SignFamily findByFamilyCode(String familyCode);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     SignFamily findByTeamCode(String TeamCode);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     @Query("select a from SignFamily a where a.teamCode = ?1 and a.type = 2 and a.code=?2")
 | 
	
		
			
				|  |  |     List<SignFamily> findByTeamCodeIsValid(String teamCode, String code);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     @Query("select a from SignFamily a where a.doctor = ?1 and a.patient = ?2 and a.type = 2 and a.status >= 0")
 | 
	
		
			
				|  |  |     SignFamily findByDoctorPatient(String doctor, String patient);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     @Query("select a from SignFamily a where a.doctor = ?1 and a.patient = ?2 and (a.type = 2 or a.type=1) and a.status >= 0")
 | 
	
		
			
				|  |  |     List<SignFamily> findSSandFamilyByDoctorPatient(String doctor, String patient);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     @Query("select a from SignFamily a where a.doctorHealth = ?1 and a.patient = ?2 and a.type = 2 and a.status >= 0 ")
 | 
	
		
			
				|  |  |     SignFamily findByDoctorHealthPatient(String doctor, String patient);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     @Query("select a from SignFamily a where a.doctor = ?1 and a.patient = ?2 and a.type = 1 and a.status > 0")
 | 
	
		
			
				|  |  |     SignFamily findSsSignByDoctorPatient(String doctor, String patient);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     @Query(value = "select a from SignFamily a where a.doctor =?1 and a.patient = ?2 and a.status =0 and a.signYear =?3")
 | 
	
		
			
				|  |  |     List<SignFamily> findByDoctorAndPatientOverDue(String doctor, String patient, String signYear);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     @Query(value = "select a from SignFamily a where a.doctorHealth =?1 and a.patient = ?2 and a.status =0 and a.signYear =?3")
 | 
	
		
			
				|  |  |     List<SignFamily> findByDoctorHealthAndPatient(String doctorHealth, String patient, String signYear);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     @Query(value = "select a from SignFamily a where a.doctor =?1 and a.patient = ?2 and a.signYear =?3 and a.status = 1 and a.expensesStatus ='1'")
 | 
	
		
			
				|  |  |     List<SignFamily> findByDoctorAndPatientIsValid(String doctor, String patient, String signYear);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     @Query(value = "select a from SignFamily a where a.doctorHealth =?1 and a.patient = ?2 and a.signYear =?3 and a.status = 1 and a.expensesStatus ='1'")
 | 
	
		
			
				|  |  |     List<SignFamily> findByDoctorHealthAndPatientIsValid(String doctorHealth, String patient, String signYear);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     @Query("select a from SignFamily a where a.doctor = ?1 and a.patient = ?2 and a.status = 1 and a.type = 2")
 | 
	
		
			
				|  |  |     SignFamily findByFamilyDoctorAndPatient(String doctor, String patient);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     @Query("select a from SignFamily a where a.doctor = ?1 and a.patient = ?2 and a.status = 1 and a.type = 1")
 | 
	
		
			
				|  |  |     SignFamily findBySanshiDoctorAndPatient(String doctor, String patient);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     @Query("select a from SignFamily a where a.doctor = ?1 and a.openid = ?2 and a.type = 2 and a.status >= 0")
 | 
	
		
			
				|  |  |     SignFamily findByDoctorOpenid(String doctor, String openid);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     @Query("select a from SignFamily a where a.doctor = ?1 and a.idcard = ?2 and a.type = 2 and a.status >= 0")
 | 
	
		
			
				|  |  |     SignFamily findByDoctorIdcard(String doctor, String idcard);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     @Query("select a from SignFamily a where a.idcard = ?1 and a.type = 2 and a.status >= 0")
 | 
	
		
			
				|  |  |     SignFamily findByIdcard(String idcard);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     @Query("select a from SignFamily a where a.idcard = ?1 and a.type = 2 and a.status > 0 and a.expensesStatus ='1'")
 | 
	
		
			
				|  |  |     SignFamily getExpensesSignByIdcard(String idcard);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     @Query("select a from SignFamily a where a.idcard = ?1 and a.type =1 and a.status >= 0")
 | 
	
		
			
				|  |  |     SignFamily findSSByIdcard(String idcard);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     @Query("select a from SignFamily a where a.idcard = ?1 ")
 | 
	
		
			
				|  |  |     List<SignFamily> findAllByIdcard(String idcard);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     @Query("select a from SignFamily a where a.idcard = ?1 and a.status >= 0")
 | 
	
		
			
				|  |  |     List<SignFamily> findSSandJTByIdcard(String idcard);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     @Query("select a from SignFamily a where a.openid = ?1 and a.type = 2 and a.status >= 0")
 | 
	
		
			
				|  |  |     SignFamily findByOpenid(String openid);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     // 取消签约申请
 | 
	
		
			
				|  |  |     @Modifying
 | 
	
		
			
				|  |  |     @Query("update SignFamily a set a.status = -1 where a.patient = ?1 and a.doctor = ?2 and a.type = 2 and a.status = 0")
 | 
	
		
			
				|  |  |     void unsignByPatient(String patient, String doctor);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     // 取消签约申请
 | 
	
		
			
				|  |  |     @Modifying
 | 
	
		
			
				|  |  |     @Query("update SignFamily a set a.status = -1 where a.openid = ?1 and a.doctor = ?2 and a.type = 2 and a.status = 0")
 | 
	
		
			
				|  |  |     void unsignByOpenid(String openid, String doctor);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     // 查询医生的签约数量
 | 
	
		
			
				|  |  |     @Query("select count(1) from SignFamily a where a.doctor = ?1")
 | 
	
		
			
				|  |  |     int countByDoctor(String doctor);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     // 查询医生的签约数量
 | 
	
		
			
				|  |  |     @Query("select count(1) from SignFamily a")
 | 
	
		
			
				|  |  |     int countByDoctor();
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     // 更新状态为待解约
 | 
	
		
			
				|  |  |     @Modifying
 | 
	
		
			
				|  |  |     @Query("update SignFamily a set a.status = 2 where a.patient = ?1 and a.doctor = ?2 and a.status = 1 and a.type = 2")
 | 
	
		
			
				|  |  |     int surrender(String patient, String doctor);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     // 更新待签约状态为拒绝或同意状态
 | 
	
		
			
				|  |  |     @Modifying
 | 
	
		
			
				|  |  |     @Query("update SignFamily a set a.status = ?1 where a.patient = ?2 and a.status = 0 and a.type = 2")
 | 
	
		
			
				|  |  |     int handleSign(int status, String patient);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     // 更新已签约状态为解约
 | 
	
		
			
				|  |  |     @Modifying
 | 
	
		
			
				|  |  |     @Query("update SignFamily a set a.status = -3, a.reason = ?1 where a.patient = ?2 and a.status = 2 and a.type = 2")
 | 
	
		
			
				|  |  |     int handleSurrender(String reason, String patient);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     // 拒绝解约
 | 
	
		
			
				|  |  |     @Modifying
 | 
	
		
			
				|  |  |     @Query("update SignFamily a set a.status = 1 where a.patient = ?1 and a.status = 2 and a.type = 2")
 | 
	
		
			
				|  |  |     int refuseSurrender(String patient);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     // 查询患者已生效的家庭签约
 | 
	
		
			
				|  |  |     @Query("select a from SignFamily a where a.patient = ?1 and a.type = 2 and a.status > 0")
 | 
	
		
			
				|  |  |     SignFamily findSignByPatient(String patient);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     @Modifying
 | 
	
		
			
				|  |  |     @Query("update SignFamily a set a.openid = ?1 where patient = ?2")
 | 
	
		
			
				|  |  |     int updateOpenidByPatient(String openid, String patient);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     // 查询已签约的总数
 | 
	
		
			
				|  |  |     @Query("select count(1) from SignFamily a where (a.doctor = ?1 or a.doctorHealth = ?1) and (a.status = 1 or a.status = 2) and a.type = 2")
 | 
	
		
			
				|  |  |     int countAmountSignedByDoctor(String doctor);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     // 查询待签约总数
 | 
	
		
			
				|  |  |     @Query("select count(1) from SignFamily a where (a.doctor = ?1 or a.doctorHealth = ?1) and a.status = 0 and a.type = 2")
 | 
	
		
			
				|  |  |     int countAmountUnsignByDoctor(String doctor);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     // 查询团队中的健康管理师 sf.doctorHealth,sf.doctorHealthName,
 | 
	
		
			
				|  |  |     //select sf.doctorHealth,sf.doctorHealthName,count(*) totalContract from SignFamily sf where sf.healthDoctor = ?1
 | 
	
		
			
				|  |  |     @Query("select sf.doctorHealth,sf.doctorHealthName,count(sf)  from SignFamily sf where sf.doctorHealth = ?1")
 | 
	
		
			
				|  |  |     List<Object> findTeamHealthDoctors(String healthDoctor);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     @Query("select a from SignFamily a where a.mobile = ?1 and a.type = 2 and a.status >= 0")
 | 
	
		
			
				|  |  |     SignFamily findByMobile(String mobile);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     @Query("select a from SignFamily a where a.patient = ?1 and a.type =1 and a.status >= 1")
 | 
	
		
			
				|  |  |     SignFamily findBySanshiPatient(String code);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     @Query("select a from SignFamily a where a.patient = ?1 and a.type =1 and a.status >= 0")
 | 
	
		
			
				|  |  |     SignFamily findBySsPatient(String code);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     @Query("select a from SignFamily a where a.patient = ?1 and a.type =2 and a.status >= 1")
 | 
	
		
			
				|  |  |     SignFamily findByjiatingPatient(String code);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     @Query("select a from SignFamily a where a.patient = ?1 and a.type =2 and a.status = 1")
 | 
	
		
			
				|  |  |     SignFamily findByjiatingPatientYes(String code);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     @Query("select a from SignFamily a where a.patient = ?1 and a.type =1 and a.status = 1")
 | 
	
		
			
				|  |  |     SignFamily findBySanshiPatientYes(String id);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     @Query("select a from SignFamily a where a.idcard = ?1 and a.type = 1 and a.status in (0,1,2,3)")
 | 
	
		
			
				|  |  |     SignFamily findByPatientSanshiSignInfo(String idCard);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     @Query("select a from SignFamily a where a.idcard = ?1 and a.type = 2 and a.status in (0,1,2,3)")
 | 
	
		
			
				|  |  |     SignFamily findByPatientFamilySignInfo(String idCard);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     @Query("select a from SignFamily a where a.patient = ?1 and a.type =2 and a.status >=0")
 | 
	
		
			
				|  |  |     SignFamily findByjiatingPatientStatus0(String patient);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     //查找昨天的家庭签约数据
 | 
	
		
			
				|  |  |     @Query(" from SignFamily a where  a.type =2 and a.status = 1  and unix_timestamp(a.applyDate)>=unix_timestamp(?1) and unix_timestamp(a.applyDate)<unix_timestamp(?2) and a.expensesStatus=1 ")
 | 
	
		
			
				|  |  |     List<SignFamily> findByJiatingSignYesterdayExpensesStatus(String yesterday, String today);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     //查找昨天的家庭签约数据
 | 
	
		
			
				|  |  |     @Query(" from SignFamily a where  a.type =2 and a.status >= 1  and  unix_timestamp(a.applyDate)<=unix_timestamp(?1) and a.expensesStatus=1 ")
 | 
	
		
			
				|  |  |     List<SignFamily> findByJiatingSignYesterdayExpensesStatus(String yesterday);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     //查找昨天的家庭签约数据
 | 
	
		
			
				|  |  |     @Query(" from SignFamily a where  a.type =2 and a.status >= 1  and  unix_timestamp(a.applyDate)<=unix_timestamp(?1) ")
 | 
	
		
			
				|  |  |     List<SignFamily> findByJiatingSignYesterday(String yesterday);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     //查找昨天的家庭解约数据
 | 
	
		
			
				|  |  |     @Query(" from SignFamily a where  a.type =2 and a.status in (-3,-4) and unix_timestamp(a.applyUnsignDate)>=unix_timestamp(?1) and unix_timestamp(a.applyUnsignDate)<unix_timestamp(?2) and a.expensesStatus=1")
 | 
	
		
			
				|  |  |     List<SignFamily> findByJiatingUnSignYesterdayExpensesStatus(String yesterday, String today);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     //查找昨天的家庭待数据
 | 
	
		
			
				|  |  |     @Query(" from SignFamily a where  a.type =2 and a.status =0  and unix_timestamp(a.patientApplyDate)>=unix_timestamp(?1) and unix_timestamp(a.patientApplyDate)<unix_timestamp(?2)")
 | 
	
		
			
				|  |  |     List<SignFamily> findByJiatingWaitSignYesterdayExpensesStatus(String yesterday, String today);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     //查找昨天的家庭待改签
 | 
	
		
			
				|  |  |     @Query(" from SignFamily a where  a.type =2 and a.status =100  and unix_timestamp(a.patientApplyDate)>=unix_timestamp(?1) and unix_timestamp(a.patientApplyDate)<unix_timestamp(?2) and a.expensesStatus=1 ")
 | 
	
		
			
				|  |  |     List<SignFamily> findByJiatingChaangeSignYesterdayExpensesStatus(String yesterday, String now);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     @Query("select a from SignFamily a where a.patient = ?1 and a.type = 1 and a.status in (0,1,2)")
 | 
	
		
			
				|  |  |     SignFamily findSanshiSignByPatient(String patientCode);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     @Query("select a from SignFamily a where a.patient = ?1 and a.type = 2 and a.status in (0,1,2)")
 | 
	
		
			
				|  |  |     SignFamily findFamilySignByPatient(String patientCode);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     @Query("select a from SignFamily a where a.patient = ?1 and a.type = 2 and a.status =-4 and a.signYear =?2")
 | 
	
		
			
				|  |  |     SignFamily findFamilySignByPatientOverDue(String patientCode, String signYear);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     @Query("select a from SignFamily a where a.patient = ?1 and a.type =2 and a.status >= 0")
 | 
	
		
			
				|  |  |     SignFamily findByPatient(String patient);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     @Query("select a from SignFamily a where a.teamCode = ?1 and a.type =2 and a.status >= 0")
 | 
	
		
			
				|  |  |     SignFamily findByTeam(String teamCode);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     @Query("select a from SignFamily a where a.patient = ?1 and a.type =2 and a.status >= 0")
 | 
	
		
			
				|  |  |     List<SignFamily> findByPatients(String patient);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     @Query("select a from SignFamily a where a.patient = ?1 and a.type =2 and a.signYear =?2 and a.status in (-4,1,2,3) order by a.id desc ")
 | 
	
		
			
				|  |  |     List<SignFamily> findByPatientsLastYear(String patient, String signYear);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     @Query("select a from SignFamily a where a.idcard = ?1 and a.type = 1 and a.status >= 0")
 | 
	
		
			
				|  |  |     SignFamily findBySanshiIdcard(String idcard);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     @Query("select a from SignFamily a where a.patient = ?1 and a.type = ?2 and a.status > 0")
 | 
	
		
			
				|  |  |     SignFamily findSignByPatient(String patient, int type);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     SignFamily findByCode(String code);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     @Query(" from SignFamily a where a.patient = ?1 and a.type = ?2 and (a.status=-3 or a.status=-4)  order by a.id desc")
 | 
	
		
			
				|  |  |     List<SignFamily> findLastJySignByPatient(String patient, int type);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     @Query(" from SignFamily a where  a.type =1 and unix_timestamp(a.czrq)=unix_timestamp( ?1 )  ")
 | 
	
		
			
				|  |  |     List<SignFamily> findByDate(String s);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     @Modifying
 | 
	
		
			
				|  |  |     @Query("update SignFamily set expenses_type = ?1 where patient = ?2 and status > 0 and type = 2")
 | 
	
		
			
				|  |  |     int updateExpensesType(String expensesType, String patient);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     @Query("select count(*) from SignFamily where patient = ?1 and status > 0 and type = 1")
 | 
	
		
			
				|  |  |     int countPatientSsSign(String patient);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     @Query("select count(*) from SignFamily where patient = ?1 and status > 0 and type = 2")
 | 
	
		
			
				|  |  |     int countPatientJtSign(String patient);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     // 查询患者已生效的家庭签约
 | 
	
		
			
				|  |  |     @Query("select a from SignFamily a where a.patient = ?1 and a.type = 2 and a.status = 0")
 | 
	
		
			
				|  |  |     SignFamily findSigningByPatient(String patient);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     //找出家庭签约中 团队是空的值
 | 
	
		
			
				|  |  |     @Query("select a from SignFamily a where a.type = 2 and a.status = 1 and a.adminTeamId is null")
 | 
	
		
			
				|  |  |     List<SignFamily> findBySignTypeAndTeamCode();
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     //找出没有健康管理师的签约数据
 | 
	
		
			
				|  |  |     @Query("select a from SignFamily a where a.type = 2 and a.status >= 1 and a.doctorHealth is null and a.adminTeamId = ?1 order by a.czrq desc")
 | 
	
		
			
				|  |  |     List<SignFamily> findNoHealthSignFamilyNum(Long teamCode);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     //找出没有健康管理师的签约数据
 | 
	
		
			
				|  |  |     @Query("select a from SignFamily a where a.type = 2 and a.status >= 1 and a.doctorHealth is null and a.doctor=?1 order by a.czrq desc")
 | 
	
		
			
				|  |  |     Page<SignFamily> findNoHealthSignFamilyHealth(String doctor, Pageable pageRequest);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     @Query("select a from SignFamily a where a.type = ?1 and a.signSource = ?2 and a.status > 0 order by a.id")
 | 
	
		
			
				|  |  |     Page<SignFamily> findByTypeAndSignSource(Integer type, String signSource, Pageable pageable);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     @Query("select a from SignFamily a where a.type = ?1 and a.signSource = ?2 and a.status > 0 and a.id >= ?3 and a.id <= ?4 order by a.id")
 | 
	
		
			
				|  |  |     Page<SignFamily> findByTypeAndSignSourceAndId(Integer type, String signSource, Long start, Long end, Pageable pageable);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     @Query("select a from SignFamily a where a.patient = ?1 and a.status >= 0")
 | 
	
		
			
				|  |  |     List<SignFamily> findAllSignByPatient(String patient);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     /**
 | 
	
		
			
				|  |  |      * 获取所有有效的签约信息(不包含-1 -2)
 | 
	
		
			
				|  |  |      *
 | 
	
		
			
				|  |  |      * @param patient
 | 
	
		
			
				|  |  |      * @return
 | 
	
		
			
				|  |  |      */
 | 
	
		
			
				|  |  |     @Query("select a from SignFamily a where a.patient = ?1 and a.status <> -1 and a.status <> -2 order by a.czrq")
 | 
	
		
			
				|  |  |     List<SignFamily> findAllActiveSignByPatient(String patient);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     @Query("select a.patient from SignFamily a where a.doctor = ?1 and a.type = 2 and a.status > 0 and a.doctorHealth is null")
 | 
	
		
			
				|  |  |     List<String> findNohealthByDoctor(String doctor);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     /**
 | 
	
		
			
				|  |  |      * 获取团队中有效的患者
 | 
	
		
			
				|  |  |      *
 | 
	
		
			
				|  |  |      * @param teamCode
 | 
	
		
			
				|  |  |      * @param status
 | 
	
		
			
				|  |  |      * @return
 | 
	
		
			
				|  |  |      */
 | 
	
		
			
				|  |  |     @Query("select count(f) from SignFamily f where f.adminTeamId = ?1 and f.status >= ?2 ")
 | 
	
		
			
				|  |  |     int findByAdminTeamIdAndStatus(long teamCode, int status);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     @Query("select f from SignFamily f where f.patient = ?1 and f.adminTeamId = ?2 and f.status > 0 and f.type = ?3")
 | 
	
		
			
				|  |  |     SignFamily findByPatientAndAdminTeamId(String patient, Long teamCode, Integer type);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     //根据医生和居民判断是否存在签约关系(全科及健管)
 | 
	
		
			
				|  |  |     @Query("select count(1) from SignFamily f where f.status > 0 and f.patient = ?1 and ( f.doctor = ?2 or doctorHealth = ?2  )")
 | 
	
		
			
				|  |  |     int findByPatientAndDoctor(String patient, String doctor);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     @Query(value = "select a from SignFamily a where a.patient = ?1 and a.signYear =?2 and a.status >= 0")
 | 
	
		
			
				|  |  |     List<SignFamily> findByDoctorAndPatientHossPost(String patient, String signYear);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     @Query(value = " select a.*  from wlyy_sign_family a where a.patient = ?1  and a.status = -4 order by a.apply_date desc limit 0,1", nativeQuery = true)
 | 
	
		
			
				|  |  |     SignFamily findOutTimeSigningByPatient(String patient);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     @Query(value = " select a.*  from wlyy_sign_family a where a.patient = ?1  and a.status = -4 and a.team_code = ?2 order by a.apply_date desc limit 0,1", nativeQuery = true)
 | 
	
		
			
				|  |  |     SignFamily findOutTimeSigningByPatientAndTeamCode(String patient, String teamCode);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     //      完成缴费后更新签约开始时间begin 缴费状态expensesStatus 医保流水号medical_insurance_num  扣费时间expenses_time
 | 
	
		
			
				|  |  |     @Modifying
 | 
	
		
			
				|  |  |     @Query("update SignFamily a set a.begin = ?2 ,a.medicalInsuranceNum=?3,a.expensesStatus = ?4,a.expensesTime = ?2,a.signPaySource = ?5 where a.code = ?1 ")
 | 
	
		
			
				|  |  |     int updatePatientBegin(String code, Date begin, String medicalInsuranceNum, String expensesStatus, int signPaySource);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     //查询居民的扣费状态
 | 
	
		
			
				|  |  |     @Query(" select a from SignFamily a where a.patient = ?1 ")
 | 
	
		
			
				|  |  |     SignFamily findPatientExpensesStatus(String patient);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     // 查询团队已签约的总数
 | 
	
		
			
				|  |  |     @Query("select count(1) from SignFamily a where  a.adminTeamId = ?1 and (a.status = 1 or a.status = 2) and a.type = 2")
 | 
	
		
			
				|  |  |     int countAmountSignedByAdminTeam(Long id);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     // 查询已签约未缴费居民
 | 
	
		
			
				|  |  |     @Query("select a from SignFamily a where  a.patient = ?1 and a.type = 2 and a.expensesStatus = '0' and a.status >0")
 | 
	
		
			
				|  |  |     SignFamily findUnpay(String patient);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     //根据身份证号码查询该人的签约情况
 | 
	
		
			
				|  |  |     @Query("select count(1) from SignFamily a where a.idcard=?1 and a.status>0 and a.type=2")
 | 
	
		
			
				|  |  |     int hasSignCount(String idcard);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     //根据patient查找有效签约的hospital
 | 
	
		
			
				|  |  |     @Query("select a.hospital from SignFamily a where a.patient = ?1 and a.status = 1 and a.expensesStatus = '1'")
 | 
	
		
			
				|  |  |     String getHospital(String patient);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     //查看团队内医生签约人数
 | 
	
		
			
				|  |  |     @Query("select count(1) from SignFamily a where a.status > 0 and a.adminTeamId = ?1 and (a.doctor = ?2 or a.doctorHealth = ?2)")
 | 
	
		
			
				|  |  |     int countByAdminTeamId(Long adminTeamId, String doctor);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     //根据居民和医生找出居民签约团队
 | 
	
		
			
				|  |  |     @Query("select f from SignFamily f where f.status > 0 and f.patient = ?1 and ( f.doctor = ?2 or doctorHealth = ?2  )")
 | 
	
		
			
				|  |  |     SignFamily findSignFamilyByPatientAndDoctor(String patient, String doctor);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     //根据居民获取有效的签约
 | 
	
		
			
				|  |  |     List<SignFamily> findByPatientAndExpensesStatusAndStatus(String patient, String expensesStatus, Integer status);
 | 
	
		
			
				|  |  |     //根据居民找出居民签约团队
 | 
	
		
			
				|  |  |     @Query("select a from SignFamily a where a.patient = ?1 and a.status = 1 and a.expensesStatus = '1'")
 | 
	
		
			
				|  |  |     SignFamily findSignFamilyByPatient(String patient);
 | 
	
		
			
				|  |  |     //根据居民查出有效签约
 | 
	
		
			
				|  |  |     @Query("select a from SignFamily a where a.patient = ?1 and a.status > 0 order by czrq desc")
 | 
	
		
			
				|  |  |     List<SignFamily> getSignFamilyByPatient(String patient);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     @Query("select count(distinct a.patient) from SignFamily a where  a.status = 1 and a.expensesStatus = '1'")
 | 
	
		
			
				|  |  |     int allCountSignNum();
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     @Modifying
 | 
	
		
			
				|  |  |     @Query("update SignFamily p set p.ssc = ?1 where p.idcard = ?2 and p.status=1")
 | 
	
		
			
				|  |  |     int updateSscByIdCard(String ssc, String idCard);
 | 
	
		
			
				|  |  |     
 | 
	
		
			
				|  |  |     //根据年份,社区查出有效签约居民
 | 
	
		
			
				|  |  |     @Query("select a from SignFamily a where a.signYear = ?1 and a.status = 1 and a.hospital = ?2")
 | 
	
		
			
				|  |  |     List<SignFamily> getSignFamilyBySignYearAndStatusAndHospital(String signyear, String hospital);
 | 
	
		
			
				|  |  | }
 |