|  | @ -0,0 +1,799 @@
 | 
	
		
			
				|  |  | package com.yihu.jw.care.service.family;
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | import com.alibaba.fastjson.JSONArray;
 | 
	
		
			
				|  |  | import com.alibaba.fastjson.JSONObject;
 | 
	
		
			
				|  |  | import com.yihu.jw.care.dao.family.PatientFamilyMemberDao;
 | 
	
		
			
				|  |  | import com.yihu.jw.care.dao.sign.ServicePackageSignRecordDao;
 | 
	
		
			
				|  |  | import com.yihu.jw.care.service.wechat.WeiXinAccessTokenUtils;
 | 
	
		
			
				|  |  | import com.yihu.jw.entity.base.patient.BasePatientDO;
 | 
	
		
			
				|  |  | import com.yihu.jw.entity.base.patient.BasePatientFamilyMemberDO;
 | 
	
		
			
				|  |  | import com.yihu.jw.entity.base.servicePackage.ServicePackageSignRecordDO;
 | 
	
		
			
				|  |  | import com.yihu.jw.patient.dao.BasePatientDao;
 | 
	
		
			
				|  |  | import com.yihu.jw.util.common.IdCardUtil;
 | 
	
		
			
				|  |  | import com.yihu.jw.util.security.MD5;
 | 
	
		
			
				|  |  | import com.yihu.jw.util.wechat.wxhttp.HttpUtil;
 | 
	
		
			
				|  |  | import com.yihu.mysql.query.BaseJpaService;
 | 
	
		
			
				|  |  | import org.apache.commons.lang3.StringUtils;
 | 
	
		
			
				|  |  | import org.springframework.beans.factory.annotation.Autowired;
 | 
	
		
			
				|  |  | import org.springframework.stereotype.Service;
 | 
	
		
			
				|  |  | import org.springframework.transaction.annotation.Transactional;
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | import javax.annotation.PostConstruct;
 | 
	
		
			
				|  |  | import java.util.Date;
 | 
	
		
			
				|  |  | import java.util.HashMap;
 | 
	
		
			
				|  |  | import java.util.List;
 | 
	
		
			
				|  |  | import java.util.Map;
 | 
	
		
			
				|  |  | import java.util.regex.Matcher;
 | 
	
		
			
				|  |  | import java.util.regex.Pattern;
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | /**
 | 
	
		
			
				|  |  |  * @author liuwenbin on 2018/11/27.
 | 
	
		
			
				|  |  |  */
 | 
	
		
			
				|  |  | @Service
 | 
	
		
			
				|  |  | public class PatientFamilyMemberService extends BaseJpaService<BasePatientFamilyMemberDO, PatientFamilyMemberDao> {
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     Map<Integer, String> relations = new HashMap<>();
 | 
	
		
			
				|  |  |     @Autowired
 | 
	
		
			
				|  |  |     private PatientFamilyMemberDao memberDao;
 | 
	
		
			
				|  |  |     @Autowired
 | 
	
		
			
				|  |  |     private BasePatientDao patientDao;
 | 
	
		
			
				|  |  |     @Autowired
 | 
	
		
			
				|  |  |     private ServicePackageSignRecordDao signRecordDao;
 | 
	
		
			
				|  |  |     @Autowired
 | 
	
		
			
				|  |  |     private WeiXinAccessTokenUtils weiXinAccessTokenUtils;
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     @PostConstruct
 | 
	
		
			
				|  |  |     public void init() {
 | 
	
		
			
				|  |  |         relations.put(0, "其他");
 | 
	
		
			
				|  |  |         relations.put(1, "父亲");
 | 
	
		
			
				|  |  |         relations.put(2, "母亲");
 | 
	
		
			
				|  |  |         relations.put(3, "老公");
 | 
	
		
			
				|  |  |         relations.put(4, "老婆");
 | 
	
		
			
				|  |  |         relations.put(5, "儿子");
 | 
	
		
			
				|  |  |         relations.put(6, "女儿");
 | 
	
		
			
				|  |  |         relations.put(7, "未知");
 | 
	
		
			
				|  |  |         relations.put(8, "免疫关联");
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     /**
 | 
	
		
			
				|  |  |      * 家庭关系转换
 | 
	
		
			
				|  |  |      *
 | 
	
		
			
				|  |  |      * @param patient  居民
 | 
	
		
			
				|  |  |      * @param relation 关系 1父亲 2母亲 3老公 4老婆 5儿子 6女儿 7其他
 | 
	
		
			
				|  |  |      * @return
 | 
	
		
			
				|  |  |      */
 | 
	
		
			
				|  |  |     public int familyRelationTrans(BasePatientDO patient, int relation) throws Exception {
 | 
	
		
			
				|  |  |         int relationTrans = 0;
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         switch (relation) {
 | 
	
		
			
				|  |  |             case 1:
 | 
	
		
			
				|  |  |             case 2:
 | 
	
		
			
				|  |  |                 if (patient.getSex() == 1) {
 | 
	
		
			
				|  |  |                     relationTrans = 5;
 | 
	
		
			
				|  |  |                 } else if (patient.getSex() == 2) {
 | 
	
		
			
				|  |  |                     relationTrans = 6;
 | 
	
		
			
				|  |  |                 } else {
 | 
	
		
			
				|  |  |                     relationTrans = 0;
 | 
	
		
			
				|  |  |                 }
 | 
	
		
			
				|  |  |                 if (relationTrans == 0) {
 | 
	
		
			
				|  |  |                     if (IdCardUtil.getSexForIdcard(StringUtils.isEmpty(patient.getIdcard()) ? "" : patient.getIdcard()).equals("1")) {
 | 
	
		
			
				|  |  |                         relationTrans = 6;
 | 
	
		
			
				|  |  |                     } else if (IdCardUtil.getSexForIdcard(StringUtils.isEmpty(patient.getIdcard()) ? "" : patient.getIdcard()).equals("2")) {
 | 
	
		
			
				|  |  |                         relationTrans = 5;
 | 
	
		
			
				|  |  |                     }
 | 
	
		
			
				|  |  |                 }
 | 
	
		
			
				|  |  |                 break;
 | 
	
		
			
				|  |  |             case 3:
 | 
	
		
			
				|  |  |                 relationTrans = 4;
 | 
	
		
			
				|  |  |                 break;
 | 
	
		
			
				|  |  |             case 4:
 | 
	
		
			
				|  |  |                 relationTrans = 3;
 | 
	
		
			
				|  |  |                 break;
 | 
	
		
			
				|  |  |             case 5:
 | 
	
		
			
				|  |  |             case 6:
 | 
	
		
			
				|  |  |                 if (patient.getSex() == 1) {
 | 
	
		
			
				|  |  |                     relationTrans = 1;
 | 
	
		
			
				|  |  |                 } else if (patient.getSex() == 2) {
 | 
	
		
			
				|  |  |                     relationTrans = 2;
 | 
	
		
			
				|  |  |                 } else {
 | 
	
		
			
				|  |  |                     relationTrans = 0;
 | 
	
		
			
				|  |  |                 }
 | 
	
		
			
				|  |  |                 if (relationTrans == 0) {
 | 
	
		
			
				|  |  |                     if (IdCardUtil.getSexForIdcard(StringUtils.isEmpty(patient.getIdcard()) ? "" : patient.getIdcard()).equals("1")) {
 | 
	
		
			
				|  |  |                         relationTrans = 2;
 | 
	
		
			
				|  |  |                     } else if (IdCardUtil.getSexForIdcard(StringUtils.isEmpty(patient.getIdcard()) ? "" : patient.getIdcard()).equals("2")) {
 | 
	
		
			
				|  |  |                         relationTrans = 1;
 | 
	
		
			
				|  |  |                     }
 | 
	
		
			
				|  |  |                 }
 | 
	
		
			
				|  |  |                 break;
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         return relationTrans;
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     /**
 | 
	
		
			
				|  |  |      * 添加家庭成员
 | 
	
		
			
				|  |  |      *
 | 
	
		
			
				|  |  |      * @param patient 患者
 | 
	
		
			
				|  |  |      * @param member  成员
 | 
	
		
			
				|  |  |      * @param captcha 验证码
 | 
	
		
			
				|  |  |      * @param member  成员
 | 
	
		
			
				|  |  |      * @return
 | 
	
		
			
				|  |  |      */
 | 
	
		
			
				|  |  |     public int addMember(String patient, String member, String captcha, String password, int relation) throws Exception {
 | 
	
		
			
				|  |  |         if (patient.equals(member)) {
 | 
	
		
			
				|  |  |             return 0;
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         BasePatientDO p = patientDao.findById(patient);
 | 
	
		
			
				|  |  |         BasePatientDO m = patientDao.findById(member);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         if (p == null) {
 | 
	
		
			
				|  |  |             return -1;
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         // 添加的成员是否注册判断
 | 
	
		
			
				|  |  |         if (m == null) {
 | 
	
		
			
				|  |  |             return -2;
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         //家庭关系为父亲、母亲、老公、老婆时只能有一个
 | 
	
		
			
				|  |  |         if (relation > 0 && relation < 5) {
 | 
	
		
			
				|  |  |             List<BasePatientFamilyMemberDO> familyMembers = memberDao.findByPatientAndFamilyRelation(patient, relation);
 | 
	
		
			
				|  |  |             if (familyMembers != null && familyMembers.size() > 0) {
 | 
	
		
			
				|  |  |                 return -5;
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         // 验证码验证
 | 
	
		
			
				|  |  | //        if (StringUtils.isNotEmpty(captcha)) {
 | 
	
		
			
				|  |  | //            int checkStatus = smsService.check(m.getMobile(), 10, captcha);
 | 
	
		
			
				|  |  | //            if (checkStatus == -2) {
 | 
	
		
			
				|  |  | //                return -6;  // 验证码过期
 | 
	
		
			
				|  |  | //            } else if (checkStatus == -1) {
 | 
	
		
			
				|  |  | //                return -3; // 验证码错误
 | 
	
		
			
				|  |  | //            }
 | 
	
		
			
				|  |  | //        }
 | 
	
		
			
				|  |  |         if (StringUtils.isNotEmpty(password)) {
 | 
	
		
			
				|  |  |             String loginPassword = MD5.GetMD5Code(password + m.getSalt());
 | 
	
		
			
				|  |  |             if (!loginPassword.equals(m.getPassword())) {
 | 
	
		
			
				|  |  |                 return -3;
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         // 添加自己与对方的关系
 | 
	
		
			
				|  |  |         BasePatientFamilyMemberDO fm = memberDao.findByPatientAndFamilyMember(patient, member);
 | 
	
		
			
				|  |  |         // 家庭关系已存在时,不重复添加
 | 
	
		
			
				|  |  |         if (fm != null) {
 | 
	
		
			
				|  |  |             return -4;
 | 
	
		
			
				|  |  |         } else {
 | 
	
		
			
				|  |  |             fm = new BasePatientFamilyMemberDO();
 | 
	
		
			
				|  |  |             fm.setPatient(patient);
 | 
	
		
			
				|  |  |             fm.setFamilyMember(member);
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         fm.setFamilyRelation(relation);
 | 
	
		
			
				|  |  |         fm.setIsAuthorize(0);//默认授权
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         // 添加对方与自己的关系
 | 
	
		
			
				|  |  |         BasePatientFamilyMemberDO fmt = memberDao.findByPatientAndFamilyMember(member, patient);
 | 
	
		
			
				|  |  |         // 不存在则创建
 | 
	
		
			
				|  |  |         if (fmt == null) {
 | 
	
		
			
				|  |  |             fmt = new BasePatientFamilyMemberDO();
 | 
	
		
			
				|  |  |             fmt.setPatient(member);
 | 
	
		
			
				|  |  |             fmt.setFamilyMember(patient);
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         // 对方与自己的关系转换
 | 
	
		
			
				|  |  |         int relationTrans = familyRelationTrans(p, relation);
 | 
	
		
			
				|  |  |         fmt.setFamilyRelation(relationTrans);
 | 
	
		
			
				|  |  |         fmt.setIsAuthorize(1);//默认授权
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         memberDao.save(fm);
 | 
	
		
			
				|  |  |         memberDao.save(fmt);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         //设置家人openid 加入undefined 判断
 | 
	
		
			
				|  |  |         if (StringUtils.isBlank(m.getOpenid()) && StringUtils.isNotBlank(p.getOpenid()) && !"undefined".equals(p.getOpenid())) {
 | 
	
		
			
				|  |  |             m.setOpenid(p.getOpenid());
 | 
	
		
			
				|  |  |             if (m.getOpenidTime() == null) {
 | 
	
		
			
				|  |  |                 m.setOpenidTime(new Date());
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |             patientDao.save(m);
 | 
	
		
			
				|  |  |         } else if (StringUtils.isBlank(p.getOpenid()) && StringUtils.isNotBlank(m.getOpenid()) && !"undefined".equals(m.getOpenid())) {
 | 
	
		
			
				|  |  |             p.setOpenid(m.getOpenid());
 | 
	
		
			
				|  |  |             if (p.getOpenidTime() == null) {
 | 
	
		
			
				|  |  |                 p.setOpenidTime(new Date());
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |             patientDao.save(p);
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         return 1;
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     /**
 | 
	
		
			
				|  |  |      * 修改家庭成员关系
 | 
	
		
			
				|  |  |      * @param patient  居民
 | 
	
		
			
				|  |  |      * @param member   成员
 | 
	
		
			
				|  |  |      * @param relation 关系
 | 
	
		
			
				|  |  |      * @return
 | 
	
		
			
				|  |  |      */
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     public int modifyFamilyRelation(String patient, String member, int relation) throws Exception {
 | 
	
		
			
				|  |  |         BasePatientDO p = patientDao.findById(patient);
 | 
	
		
			
				|  |  |         BasePatientDO m = patientDao.findById(member);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         if (p == null) {
 | 
	
		
			
				|  |  |             return -1;
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         // 成员是否注册判断
 | 
	
		
			
				|  |  |         if (m == null) {
 | 
	
		
			
				|  |  |             return -2;
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         // 自己与对方的关系
 | 
	
		
			
				|  |  |         BasePatientFamilyMemberDO fm = memberDao.findByPatientAndFamilyMember(patient, member);
 | 
	
		
			
				|  |  |         if (fm == null) {
 | 
	
		
			
				|  |  |             return -3;
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         if (relation > 0 && relation < 5) {
 | 
	
		
			
				|  |  |             List<BasePatientFamilyMemberDO> familyMembers = memberDao.findByPatientAndFamilyRelation(patient, relation);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |             if (familyMembers != null && familyMembers.size() > 0) {
 | 
	
		
			
				|  |  |                 return -5;
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         fm.setFamilyRelation(relation);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         // 对方与自己的关系
 | 
	
		
			
				|  |  |         BasePatientFamilyMemberDO fmt = memberDao.findByPatientAndFamilyMember(member, patient);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         // 不存在则创建
 | 
	
		
			
				|  |  |         if (fmt == null) {
 | 
	
		
			
				|  |  |             fmt = new BasePatientFamilyMemberDO();
 | 
	
		
			
				|  |  |             fmt.setPatient(patient);
 | 
	
		
			
				|  |  |             fmt.setFamilyMember(member);
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         int relationTrans = familyRelationTrans(p, relation);
 | 
	
		
			
				|  |  |         fmt.setFamilyRelation(relationTrans);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         memberDao.save(fm);
 | 
	
		
			
				|  |  |         memberDao.save(fmt);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         return 1;
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     /**
 | 
	
		
			
				|  |  |      * 删除家庭成员
 | 
	
		
			
				|  |  |      * @param patient 居民
 | 
	
		
			
				|  |  |      * @param member  成员
 | 
	
		
			
				|  |  |      * @return
 | 
	
		
			
				|  |  |      */
 | 
	
		
			
				|  |  |     public int deleteMember(String patient, String member) {
 | 
	
		
			
				|  |  |         // 自己与对方的关系
 | 
	
		
			
				|  |  |         BasePatientFamilyMemberDO fm = memberDao.findByPatientAndFamilyMember(patient, member);
 | 
	
		
			
				|  |  |         if (fm == null) {
 | 
	
		
			
				|  |  |             return -1;
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         // 对方与自己的关系
 | 
	
		
			
				|  |  |         BasePatientFamilyMemberDO fmt = memberDao.findByPatientAndFamilyMember(member, patient);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         memberDao.delete(fm);
 | 
	
		
			
				|  |  |         if (fmt != null) {
 | 
	
		
			
				|  |  |             memberDao.delete(fmt);
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         return 1;
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     /**
 | 
	
		
			
				|  |  |      * 设置授权关系
 | 
	
		
			
				|  |  |      * @param patient
 | 
	
		
			
				|  |  |      * @param member
 | 
	
		
			
				|  |  |      * @param isAuthorize
 | 
	
		
			
				|  |  |      * @return
 | 
	
		
			
				|  |  |      * @throws Exception
 | 
	
		
			
				|  |  |      */
 | 
	
		
			
				|  |  |     public int authorizeMember(String patient, String member, Integer isAuthorize) throws Exception {
 | 
	
		
			
				|  |  |         BasePatientFamilyMemberDO fm = memberDao.findByPatientAndFamilyMember(patient, member);
 | 
	
		
			
				|  |  |         if (fm == null) {
 | 
	
		
			
				|  |  |             return -1;
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         fm.setIsAuthorize(isAuthorize);
 | 
	
		
			
				|  |  |         memberDao.save(fm);
 | 
	
		
			
				|  |  |         return 1;
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     /**
 | 
	
		
			
				|  |  |      * 获取居民的家庭成员
 | 
	
		
			
				|  |  |      *
 | 
	
		
			
				|  |  |      * @param patient 居民
 | 
	
		
			
				|  |  |      * @return
 | 
	
		
			
				|  |  |      */
 | 
	
		
			
				|  |  |     public JSONArray getPatientMembers(String patient, String doctorCode, boolean isContain, String current, Integer isAgree) {
 | 
	
		
			
				|  |  |         JSONArray resultArray = getPatientFamilyMembers(patient, doctorCode, isAgree);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         if (resultArray == null) {
 | 
	
		
			
				|  |  |             resultArray = new JSONArray();
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         if (isContain && !patient.equals(current)) {
 | 
	
		
			
				|  |  |             BasePatientDO p = patientDao.findById(patient);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |             JSONObject obj = new JSONObject();
 | 
	
		
			
				|  |  |             List<ServicePackageSignRecordDO> signs = signRecordDao.findByStatusAndPatient(1,patient);
 | 
	
		
			
				|  |  |             boolean jtSign = false;
 | 
	
		
			
				|  |  |             if(signs.size()>0){
 | 
	
		
			
				|  |  |                 jtSign = true;
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |             obj.put("id", p.getId());
 | 
	
		
			
				|  |  |             obj.put("name", p.getName());
 | 
	
		
			
				|  |  |             obj.put("sex", p.getSex());
 | 
	
		
			
				|  |  |             obj.put("birthday", p.getBirthday());
 | 
	
		
			
				|  |  |             obj.put("idcard", StringUtils.isEmpty(p.getIdcard()) ? "" : p.getIdcard());
 | 
	
		
			
				|  |  |             obj.put("photo", StringUtils.isEmpty(p.getPhoto()) ? "" : p.getPhoto());
 | 
	
		
			
				|  |  |             obj.put("mobile", StringUtils.isEmpty(p.getMobile()) ? "" : p.getMobile());
 | 
	
		
			
				|  |  |             obj.put("address", StringUtils.isEmpty(p.getAddress()) ? "" : p.getAddress());
 | 
	
		
			
				|  |  |             obj.put("familyRelation", "-1");
 | 
	
		
			
				|  |  |             obj.put("familyRelationName", "自己");
 | 
	
		
			
				|  |  |             obj.put("isAuthorize", 1);//0:未授权,1:已授权
 | 
	
		
			
				|  |  |             obj.put("authorizeStatus", 3);//
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |             if (jtSign) {
 | 
	
		
			
				|  |  |                 obj.put("signType", 1);
 | 
	
		
			
				|  |  |             } else {
 | 
	
		
			
				|  |  |                 obj.put("signType", 0);
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |             resultArray.add(obj);
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         return resultArray;
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     /**
 | 
	
		
			
				|  |  |      * 获取居民的家庭成员
 | 
	
		
			
				|  |  |      *
 | 
	
		
			
				|  |  |      * @param patient 居民
 | 
	
		
			
				|  |  |      * @return
 | 
	
		
			
				|  |  |      */
 | 
	
		
			
				|  |  |     public JSONArray getPatientFamilyMembers(String patient, String doctorCode, Integer isAgree) {
 | 
	
		
			
				|  |  |         JSONArray resultArray = new JSONArray();
 | 
	
		
			
				|  |  |         String sql = "select * " +
 | 
	
		
			
				|  |  |                 " from " +
 | 
	
		
			
				|  |  |                 "    base_patient_family_member t1, " +
 | 
	
		
			
				|  |  |                 "    base_patient t2 " +
 | 
	
		
			
				|  |  |                 " where " +
 | 
	
		
			
				|  |  |                 "    t2.id in (select family_member from base_patient_family_member where patient = ? ) " +
 | 
	
		
			
				|  |  |                 "    and t1.patient = ? " +
 | 
	
		
			
				|  |  |                 "    and t1.family_member = t2.id ";
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         List<Map<String, Object>> result = jdbcTemplate.queryForList(sql, new Object[]{patient, patient});
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         if (result != null && result.size() > 0) {
 | 
	
		
			
				|  |  |             for (Map<String, Object> map : result) {
 | 
	
		
			
				|  |  |                 JSONObject obj = new JSONObject();
 | 
	
		
			
				|  |  |                 List<ServicePackageSignRecordDO> signs = signRecordDao.findByStatusAndPatient(1,map.get("family_member").toString());
 | 
	
		
			
				|  |  |                 boolean jtSign = false;
 | 
	
		
			
				|  |  |                 int status = 0;
 | 
	
		
			
				|  |  |                 if(signs.size()>0){
 | 
	
		
			
				|  |  |                     jtSign = true;
 | 
	
		
			
				|  |  |                     status = 1;
 | 
	
		
			
				|  |  |                 }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |                 Integer isAuthorize = (Integer) map.get("is_authorize");
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |                 obj.put("id", map.get("id"));
 | 
	
		
			
				|  |  |                 obj.put("name", map.get("name"));
 | 
	
		
			
				|  |  |                 obj.put("sex", map.get("sex"));
 | 
	
		
			
				|  |  |                 obj.put("isAuthorize", isAuthorize);//0:未授权,1:已授权
 | 
	
		
			
				|  |  |                 obj.put("birthday", map.get("birthday"));
 | 
	
		
			
				|  |  |                 obj.put("idcard", StringUtils.isEmpty(String.valueOf(map.get("idcard"))) ? "" : map.get("idcard").toString());
 | 
	
		
			
				|  |  |                 obj.put("photo", map.get("photo"));
 | 
	
		
			
				|  |  |                 obj.put("mobile", map.get("mobile"));
 | 
	
		
			
				|  |  |                 obj.put("address", StringUtils.isEmpty(String.valueOf(map.get("address"))) ? "" : map.get("address"));
 | 
	
		
			
				|  |  |                 obj.put("familyRelation", map.get("family_relation"));
 | 
	
		
			
				|  |  |                 obj.put("familyRelationName", relations.get(map.get("family_relation")));
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |                 if (!StringUtils.isEmpty(doctorCode)) {
 | 
	
		
			
				|  |  |                     obj.put("relaholder", relations.get(map.get("family_relation")));
 | 
	
		
			
				|  |  |                     obj.put("addressCode", "");
 | 
	
		
			
				|  |  |                     obj.put("addressName", StringUtils.isEmpty(String.valueOf(map.get("address"))) ? "" : map.get("address"));
 | 
	
		
			
				|  |  |                     obj.put("status", status);
 | 
	
		
			
				|  |  |                     obj.put("source", 1);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |                     if (isAuthorize == 1) {
 | 
	
		
			
				|  |  |                         BasePatientFamilyMemberDO familyMember = memberDao.findByPatientAndFamilyMember(String.valueOf(map.get("family_member")), patient);
 | 
	
		
			
				|  |  |                         if (familyMember.getIsAuthorize() == 1) {
 | 
	
		
			
				|  |  |                             obj.put("authorizeStatus", 1);//相互授权
 | 
	
		
			
				|  |  |                         } else {
 | 
	
		
			
				|  |  |                             obj.put("authorizeStatus", 2);//居民单方向向家人授权
 | 
	
		
			
				|  |  |                         }
 | 
	
		
			
				|  |  |                     } else {
 | 
	
		
			
				|  |  |                         obj.put("authorizeStatus", 3);//居民被家人授权
 | 
	
		
			
				|  |  |                     }
 | 
	
		
			
				|  |  |                 }
 | 
	
		
			
				|  |  |                 if (jtSign) {
 | 
	
		
			
				|  |  |                     obj.put("signType", 1);
 | 
	
		
			
				|  |  |                 } else {
 | 
	
		
			
				|  |  |                     obj.put("signType", 0);
 | 
	
		
			
				|  |  |                 }
 | 
	
		
			
				|  |  |                 obj.put("state", "1");//0 :未处理;1:已同意;2:已拒绝
 | 
	
		
			
				|  |  |                 obj.put("id", map.get("id"));
 | 
	
		
			
				|  |  |                 resultArray.add(obj);
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         return resultArray;
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     /**
 | 
	
		
			
				|  |  |      * 获取有授权的家庭成员
 | 
	
		
			
				|  |  |      *
 | 
	
		
			
				|  |  |      * @param patient
 | 
	
		
			
				|  |  |      * @return
 | 
	
		
			
				|  |  |      */
 | 
	
		
			
				|  |  |     public JSONArray getAuthorizeMembers(String patient) throws Exception {
 | 
	
		
			
				|  |  |         JSONArray resultArray = new JSONArray();
 | 
	
		
			
				|  |  |         resultArray.add(getPatient(patient));
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         List<BasePatientFamilyMemberDO> list = memberDao.findByFamilyMemberAndIsAuthorize(patient, 1);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         if (list != null && list.size() > 0) {
 | 
	
		
			
				|  |  |             JSONArray tem = new JSONArray();
 | 
	
		
			
				|  |  |             for (BasePatientFamilyMemberDO member : list) {
 | 
	
		
			
				|  |  |                 JSONObject obj = new JSONObject();
 | 
	
		
			
				|  |  |                 BasePatientDO p = patientDao.findById(member.getPatient());
 | 
	
		
			
				|  |  |                 if (p == null) {
 | 
	
		
			
				|  |  |                     throw new Exception("成员为空!");
 | 
	
		
			
				|  |  |                 }
 | 
	
		
			
				|  |  |                 List<ServicePackageSignRecordDO> signs = signRecordDao.findByStatusAndPatient(1,patient);
 | 
	
		
			
				|  |  |                 boolean jtSign = false;
 | 
	
		
			
				|  |  |                 if(signs.size()>0){
 | 
	
		
			
				|  |  |                     jtSign = true;
 | 
	
		
			
				|  |  |                 }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |                 Integer relation = familyRelationTrans(p, member.getFamilyRelation());
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |                 if (signs.size() > 0){
 | 
	
		
			
				|  |  |                     obj.put("signCode",signs.get(0).getId());
 | 
	
		
			
				|  |  |                 }else {
 | 
	
		
			
				|  |  |                     obj.put("signCode","");
 | 
	
		
			
				|  |  |                 }
 | 
	
		
			
				|  |  |                 obj.put("id", p.getId());
 | 
	
		
			
				|  |  |                 obj.put("name", p.getName());
 | 
	
		
			
				|  |  |                 obj.put("sex", p.getSex());
 | 
	
		
			
				|  |  |                 obj.put("isAuthorize", member.getIsAuthorize());//0:未授权,1:已授权
 | 
	
		
			
				|  |  |                 obj.put("birthday", p.getBirthday());
 | 
	
		
			
				|  |  |                 String idCard = StringUtils.isEmpty(p.getIdcard()) ? "" : p.getIdcard();
 | 
	
		
			
				|  |  |                 obj.put("idcard", IdCardUtil.getIdcardEncode(idCard));
 | 
	
		
			
				|  |  |                 obj.put("idcardAll", idCard);
 | 
	
		
			
				|  |  |                 obj.put("photo", p.getPhoto());
 | 
	
		
			
				|  |  |                 obj.put("mobile", p.getMobile());
 | 
	
		
			
				|  |  |                 obj.put("age", IdCardUtil.getAgeByIdcardOrBirthday(p.getIdcard(),p.getBirthday()));
 | 
	
		
			
				|  |  |                 obj.put("ssc", p.getSsc());
 | 
	
		
			
				|  |  |                 obj.put("familyRelation", relation);
 | 
	
		
			
				|  |  |                 obj.put("familyRelationName", relations.get(relation));
 | 
	
		
			
				|  |  |                 obj.put("address", p.getAddress());
 | 
	
		
			
				|  |  |                 obj.put("openid", p.getOpenid());
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |                 if (jtSign) {
 | 
	
		
			
				|  |  |                     obj.put("signType", 1);
 | 
	
		
			
				|  |  |                 } else {
 | 
	
		
			
				|  |  |                     obj.put("signType", 0);
 | 
	
		
			
				|  |  |                 }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |                 if (member.getIsAuthorize() == 0) {
 | 
	
		
			
				|  |  |                     tem.add(obj);
 | 
	
		
			
				|  |  |                 } else {
 | 
	
		
			
				|  |  |                     resultArray.add(obj);
 | 
	
		
			
				|  |  |                 }
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |             if (tem.size() > 0) {
 | 
	
		
			
				|  |  |                 for (int i = 0; i < tem.size(); i++) {
 | 
	
		
			
				|  |  |                     resultArray.add(tem.get(i));
 | 
	
		
			
				|  |  |                 }
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         return resultArray;
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     /**
 | 
	
		
			
				|  |  |      * 判断成员是否注册
 | 
	
		
			
				|  |  |      *
 | 
	
		
			
				|  |  |      * @param idcard 身份证号
 | 
	
		
			
				|  |  |      * @return
 | 
	
		
			
				|  |  |      */
 | 
	
		
			
				|  |  |     public JSONObject isRegister(String idcard, String patient) {
 | 
	
		
			
				|  |  |         JSONObject result = new JSONObject();
 | 
	
		
			
				|  |  |         BasePatientDO p = patientDao.findByIdcard(idcard);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         if (p == null) {
 | 
	
		
			
				|  |  |             result.put("isRegister", 0);
 | 
	
		
			
				|  |  |         } else {
 | 
	
		
			
				|  |  |             if (patient.equals(p.getId())) {
 | 
	
		
			
				|  |  |                 result.put("isRegister", -1); //不能添加自己
 | 
	
		
			
				|  |  |                 return result;
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |             result.put("isRegister", 1);
 | 
	
		
			
				|  |  |             result.put("mobile", StringUtils.isEmpty(p.getMobile()) ? "" : p.getMobile());
 | 
	
		
			
				|  |  |             result.put("name", StringUtils.isEmpty(p.getName()) ? "" : p.getName());
 | 
	
		
			
				|  |  |             result.put("id",  p.getId());
 | 
	
		
			
				|  |  |             result.put("photo", StringUtils.isEmpty(p.getPhoto()) ? "" : p.getPhoto());
 | 
	
		
			
				|  |  |             result.put("sex", p.getSex());
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         return result;
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     public JSONObject getPatient(String patient) {
 | 
	
		
			
				|  |  |         BasePatientDO p = patientDao.findById(patient);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         JSONObject obj = new JSONObject();
 | 
	
		
			
				|  |  |         List<ServicePackageSignRecordDO> signs = signRecordDao.findByStatusAndPatient(1,patient);
 | 
	
		
			
				|  |  |         boolean jtSign = false;
 | 
	
		
			
				|  |  |         if(signs.size()>0){
 | 
	
		
			
				|  |  |             jtSign = true;
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         obj.put("id", p.getId());
 | 
	
		
			
				|  |  |         obj.put("name", p.getName());
 | 
	
		
			
				|  |  |         obj.put("sex", p.getSex());
 | 
	
		
			
				|  |  |         obj.put("birthday", p.getBirthday());
 | 
	
		
			
				|  |  |         obj.put("isAuthorize", 1);
 | 
	
		
			
				|  |  |         String idCard = StringUtils.isEmpty(p.getIdcard()) ? "" : p.getIdcard();
 | 
	
		
			
				|  |  |         obj.put("idcard", IdCardUtil.getIdcardEncode(idCard));
 | 
	
		
			
				|  |  |         obj.put("idcardAll", idCard);
 | 
	
		
			
				|  |  |         obj.put("age", IdCardUtil.getAgeByIdcardOrBirthday(p.getIdcard(),p.getBirthday()));
 | 
	
		
			
				|  |  |         obj.put("ssc", p.getSsc());
 | 
	
		
			
				|  |  |         obj.put("photo", StringUtils.isEmpty(p.getPhoto()) ? "" : p.getPhoto());
 | 
	
		
			
				|  |  |         obj.put("mobile", StringUtils.isEmpty(p.getMobile()) ? "" : p.getMobile());
 | 
	
		
			
				|  |  |         obj.put("address", StringUtils.isEmpty(p.getAddress()) ? "" : p.getAddress());
 | 
	
		
			
				|  |  |         obj.put("familyRelation", -1);
 | 
	
		
			
				|  |  |         obj.put("familyRelationName", "自己");
 | 
	
		
			
				|  |  |         obj.put("isAuthorize", 1);//0:未授权,1:已授权
 | 
	
		
			
				|  |  |         obj.put("openid", p.getOpenid());
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         if (jtSign) {
 | 
	
		
			
				|  |  |             obj.put("signType", 1);
 | 
	
		
			
				|  |  |         }else {
 | 
	
		
			
				|  |  |             obj.put("signType", 0);
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         return obj;
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     /**
 | 
	
		
			
				|  |  |      * 验证添加的家庭成员
 | 
	
		
			
				|  |  |      *
 | 
	
		
			
				|  |  |      * @param menber 预绑定成员
 | 
	
		
			
				|  |  |      * @return 0未绑定微信,1仅绑定微信,2仅绑定手机,3手机微信都绑定
 | 
	
		
			
				|  |  |      */
 | 
	
		
			
				|  |  |     public JSONObject checkFamilyMember(String menber) throws Exception {
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         JSONObject r = new JSONObject();
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         //未绑定微信,未绑定手机
 | 
	
		
			
				|  |  |         int result = 0;
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         //1.判断微信过滤
 | 
	
		
			
				|  |  |         //判断是否绑定微信,如果版绑定了微信,将状态改变为 1
 | 
	
		
			
				|  |  |         BasePatientDO p = patientDao.findById(menber);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         if (StringUtils.isNotBlank(p.getOpenid())) {
 | 
	
		
			
				|  |  |             String sus = getIsSus(p.getOpenid());
 | 
	
		
			
				|  |  |             if (StringUtils.isNotBlank(sus)) {
 | 
	
		
			
				|  |  |                 if ("1".equals(sus)) {
 | 
	
		
			
				|  |  |                     result = 1;
 | 
	
		
			
				|  |  |                 }
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         //2.判断手机过滤
 | 
	
		
			
				|  |  |         //判断是否绑定了手机
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         if (StringUtils.isNoneBlank(p.getMobile()) && isMobileNO(p.getMobile())) {
 | 
	
		
			
				|  |  |             //如果用户绑定了微信,将状态更改为4
 | 
	
		
			
				|  |  |             if (result == 1) {
 | 
	
		
			
				|  |  |                 result = 3;
 | 
	
		
			
				|  |  |                 //如果用户未绑定微信,将状态更改为2
 | 
	
		
			
				|  |  |             } else if (result == 0) {
 | 
	
		
			
				|  |  |                 result = 2;
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         //返回过滤后的状态
 | 
	
		
			
				|  |  |         r.put("state", result);
 | 
	
		
			
				|  |  |         if (result == 0) {
 | 
	
		
			
				|  |  |             r.put("mes", "未绑定微信和手机");
 | 
	
		
			
				|  |  |         } else if (result == 1) {
 | 
	
		
			
				|  |  |             r.put("mes", "仅绑定微信");
 | 
	
		
			
				|  |  |         } else if (result == 2) {
 | 
	
		
			
				|  |  |             r.put("mes", "仅绑定手机");
 | 
	
		
			
				|  |  |         } else if (result == 3) {
 | 
	
		
			
				|  |  |             r.put("mes", "手机和微信皆绑定");
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         return r;
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     /**
 | 
	
		
			
				|  |  |      * 通过用户名密码添加
 | 
	
		
			
				|  |  |      *
 | 
	
		
			
				|  |  |      * @param patient
 | 
	
		
			
				|  |  |      * @param member
 | 
	
		
			
				|  |  |      * @param password
 | 
	
		
			
				|  |  |      * @param relation
 | 
	
		
			
				|  |  |      * @return
 | 
	
		
			
				|  |  |      * @throws Exception
 | 
	
		
			
				|  |  |      */
 | 
	
		
			
				|  |  |     @Transactional
 | 
	
		
			
				|  |  |     public int addMemberByPw(String patient, String member, String password, int relation) throws Exception {
 | 
	
		
			
				|  |  |         if (patient.equals(member)) {
 | 
	
		
			
				|  |  |             return 0;
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         BasePatientDO p = patientDao.findById(patient);
 | 
	
		
			
				|  |  |         BasePatientDO m = patientDao.findById(member);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         if (p == null) {
 | 
	
		
			
				|  |  |             return -1;
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         // 添加的成员是否注册判断
 | 
	
		
			
				|  |  |         if (m == null) {
 | 
	
		
			
				|  |  |             return -2;
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         if (StringUtils.isNotEmpty(password)) {
 | 
	
		
			
				|  |  |             String loginPassword = MD5.GetMD5Code(password + m.getSalt());
 | 
	
		
			
				|  |  |             if (!loginPassword.equals(m.getPassword())) {
 | 
	
		
			
				|  |  |                 return -3;
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         return addMemberFamily(p, m, patient, member, relation);
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     @Transactional
 | 
	
		
			
				|  |  |     public int addMemberFamily(BasePatientDO p, BasePatientDO m, String patient, String member, int relation) throws Exception {
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         if (relation > 0 && relation < 5) {
 | 
	
		
			
				|  |  |             List<BasePatientFamilyMemberDO> familyMembers = memberDao.findByPatientAndFamilyRelation(patient, relation);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |             if (familyMembers != null && familyMembers.size() > 0) {
 | 
	
		
			
				|  |  |                 return -5;
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         // 添加自己与对方的关系
 | 
	
		
			
				|  |  |         BasePatientFamilyMemberDO fm = memberDao.findByPatientAndFamilyMember(patient, member);
 | 
	
		
			
				|  |  |         // 家庭关系已存在时,不重复添加
 | 
	
		
			
				|  |  |         if (fm != null) {
 | 
	
		
			
				|  |  |             return -4;
 | 
	
		
			
				|  |  |         } else {
 | 
	
		
			
				|  |  |             fm = new BasePatientFamilyMemberDO();
 | 
	
		
			
				|  |  |             fm.setPatient(patient);
 | 
	
		
			
				|  |  |             fm.setFamilyMember(member);
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         fm.setFamilyRelation(relation);
 | 
	
		
			
				|  |  |         fm.setIsAuthorize(0);//默认授权
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         // 添加对方与自己的关系
 | 
	
		
			
				|  |  |         BasePatientFamilyMemberDO fmt = memberDao.findByPatientAndFamilyMember(member, patient);
 | 
	
		
			
				|  |  |         // 不存在则创建
 | 
	
		
			
				|  |  |         if (fmt == null) {
 | 
	
		
			
				|  |  |             fmt = new BasePatientFamilyMemberDO();
 | 
	
		
			
				|  |  |             fmt.setPatient(member);
 | 
	
		
			
				|  |  |             fmt.setFamilyMember(patient);
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         // 对方与自己的关系转s
 | 
	
		
			
				|  |  |         //int relationTrans = familyRelationTrans(p, relation);
 | 
	
		
			
				|  |  |         int relationTrans = familyRelationTrans(p, relation);
 | 
	
		
			
				|  |  |         fmt.setFamilyRelation(relationTrans);
 | 
	
		
			
				|  |  |         fmt.setIsAuthorize(0);//默认授权
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         memberDao.save(fm);
 | 
	
		
			
				|  |  |         memberDao.save(fmt);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         //设置家人openid
 | 
	
		
			
				|  |  |         if (StringUtils.isBlank(m.getOpenid()) && StringUtils.isNotBlank(p.getOpenid()) && !"undefined".equals(p.getOpenid())) {
 | 
	
		
			
				|  |  |             m.setOpenid(p.getOpenid());
 | 
	
		
			
				|  |  |             if (m.getOpenidTime() == null) {
 | 
	
		
			
				|  |  |                 m.setOpenidTime(new Date());
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |             patientDao.save(m);
 | 
	
		
			
				|  |  |         } else if (StringUtils.isBlank(p.getOpenid()) && StringUtils.isNotBlank(m.getOpenid()) && !"undefined".equals(m.getOpenid())) {
 | 
	
		
			
				|  |  |             p.setOpenid(m.getOpenid());
 | 
	
		
			
				|  |  |             if (p.getOpenidTime() == null) {
 | 
	
		
			
				|  |  |                 p.setOpenidTime(new Date());
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |             patientDao.save(p);
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         return 1;
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     @Transactional
 | 
	
		
			
				|  |  |     public int addMemberByCaptcha(String patient, String member, String captcha, int relation) throws Exception {
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         if (patient.equals(member)) {
 | 
	
		
			
				|  |  |             return 0;
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         BasePatientDO p = patientDao.findById(patient);
 | 
	
		
			
				|  |  |         BasePatientDO m = patientDao.findById(member);
 | 
	
		
			
				|  |  |         if (p == null) {
 | 
	
		
			
				|  |  |             return -1;
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         // 添加的成员是否注册判断
 | 
	
		
			
				|  |  |         if (m == null) {
 | 
	
		
			
				|  |  |             return -2;
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | //        // 验证码验证
 | 
	
		
			
				|  |  | //        if (StringUtils.isNotEmpty(captcha)) {
 | 
	
		
			
				|  |  | //            int checkStatus = smsService.check(m.getMobile(), 10, captcha);
 | 
	
		
			
				|  |  | //            if (checkStatus == -2) {
 | 
	
		
			
				|  |  | //                return -6;  // 验证码过期
 | 
	
		
			
				|  |  | //            } else if (checkStatus == -1) {
 | 
	
		
			
				|  |  | //                return -3; // 验证码错误
 | 
	
		
			
				|  |  | //            }
 | 
	
		
			
				|  |  | //        }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |         return addMemberFamily(p, m, patient, member, relation);
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     /**
 | 
	
		
			
				|  |  |      * 获取subscribe
 | 
	
		
			
				|  |  |      *
 | 
	
		
			
				|  |  |      * @param openid
 | 
	
		
			
				|  |  |      * @return
 | 
	
		
			
				|  |  |      * @throws Exception
 | 
	
		
			
				|  |  |      */
 | 
	
		
			
				|  |  |     public String getIsSus(String openid) throws Exception {
 | 
	
		
			
				|  |  |         String userInfo_url = "https://api.weixin.qq.com/cgi-bin/user/info?access_token=" + weiXinAccessTokenUtils.getAccessToken() + "&openid=" + openid + "&lang=zh_CN";
 | 
	
		
			
				|  |  |         String params = "";
 | 
	
		
			
				|  |  |         String result = HttpUtil.sendGet(userInfo_url, params);
 | 
	
		
			
				|  |  |         JSONObject json = JSONObject.parseObject(result);
 | 
	
		
			
				|  |  |         if (json.containsKey("subscribe")) {
 | 
	
		
			
				|  |  |             return json.get("subscribe").toString();
 | 
	
		
			
				|  |  |         } else {
 | 
	
		
			
				|  |  |             return null;
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     public boolean isMobileNO(String number) {
 | 
	
		
			
				|  |  |         Pattern pattern = Pattern.compile("^1(3|4|5|7|8)[0-9]\\d{8}$");
 | 
	
		
			
				|  |  |         Matcher m = pattern.matcher(number);
 | 
	
		
			
				|  |  |         return m.matches();
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     /**
 | 
	
		
			
				|  |  |      * 获取已绑定家人的信息
 | 
	
		
			
				|  |  |      * @param patient
 | 
	
		
			
				|  |  |      */
 | 
	
		
			
				|  |  |     public List<BasePatientFamilyMemberDO> getByPatientAndFamilyRelation(String patient,Integer familyRelation){
 | 
	
		
			
				|  |  |         List<BasePatientFamilyMemberDO> list = null;
 | 
	
		
			
				|  |  |         if(familyRelation==null){
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |             list = memberDao.getByPatient(patient);
 | 
	
		
			
				|  |  |         }else{
 | 
	
		
			
				|  |  |             list = memberDao.getByPatientAndFamilyRelation(patient,familyRelation);
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         return list;
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     public List<BasePatientFamilyMemberDO> getByFamilyMemberAndRelation(String familyMember,Integer familyRelation){
 | 
	
		
			
				|  |  |         List<BasePatientFamilyMemberDO> list = null;
 | 
	
		
			
				|  |  |         if(familyRelation==null){
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |             list = memberDao.getByFamilyMember(familyMember);
 | 
	
		
			
				|  |  |         }else{
 | 
	
		
			
				|  |  |             list = memberDao.getByFamilyMemberAndFamilyRelation(familyMember,familyRelation);
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |         return list;
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | }
 |