|  | @ -15,14 +15,13 @@ import com.yihu.wlyy.service.common.account.AccessTokenService;
 | 
	
		
			
				|  |  | import com.yihu.wlyy.service.common.account.PatientService;
 | 
	
		
			
				|  |  | import com.yihu.wlyy.service.common.account.TokenService;
 | 
	
		
			
				|  |  | import com.yihu.wlyy.service.common.login.LoginLogService;
 | 
	
		
			
				|  |  | import com.yihu.wlyy.service.third.ylz.YLZUserService;
 | 
	
		
			
				|  |  | import com.yihu.wlyy.task.PushMsgTask;
 | 
	
		
			
				|  |  | import com.yihu.wlyy.util.HttpUtil;
 | 
	
		
			
				|  |  | import com.yihu.wlyy.util.IdcardValidator;
 | 
	
		
			
				|  |  | import com.yihu.wlyy.util.MD5;
 | 
	
		
			
				|  |  | import com.yihu.wlyy.util.RSAUtils;
 | 
	
		
			
				|  |  | import com.yihu.wlyy.util.*;
 | 
	
		
			
				|  |  | import com.yihu.wlyy.web.WeixinBaseController;
 | 
	
		
			
				|  |  | import com.yihu.wlyy.wechat.util.WeiXinOpenIdUtils;
 | 
	
		
			
				|  |  | import com.yihu.wlyy.wechat.util.WeiXinTagUtil;
 | 
	
		
			
				|  |  | import com.ylzinfo.ehc.empi.sdk.dto.response.UserInfoResponse;
 | 
	
		
			
				|  |  | import io.swagger.annotations.Api;
 | 
	
		
			
				|  |  | import org.apache.commons.lang3.StringUtils;
 | 
	
		
			
				|  |  | import org.json.JSONObject;
 | 
	
	
		
			
				|  | @ -34,6 +33,7 @@ import org.springframework.web.bind.annotation.RequestMethod;
 | 
	
		
			
				|  |  | import org.springframework.web.bind.annotation.RequestParam;
 | 
	
		
			
				|  |  | import org.springframework.web.bind.annotation.ResponseBody;
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | import java.io.UnsupportedEncodingException;
 | 
	
		
			
				|  |  | import java.net.URLDecoder;
 | 
	
		
			
				|  |  | import java.util.*;
 | 
	
		
			
				|  |  | 
 | 
	
	
		
			
				|  | @ -73,6 +73,8 @@ public class WechatController extends WeixinBaseController {
 | 
	
		
			
				|  |  |     private WeiXinTagUtil weiXinTagUtil;
 | 
	
		
			
				|  |  |     @Autowired
 | 
	
		
			
				|  |  |     private RSAUtils rsaUtils;
 | 
	
		
			
				|  |  |     @Autowired
 | 
	
		
			
				|  |  |     private YLZUserService ylzUserService;
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     /**
 | 
	
	
		
			
				|  | @ -132,7 +134,7 @@ public class WechatController extends WeixinBaseController {
 | 
	
		
			
				|  |  |             // 解密身份证号
 | 
	
		
			
				|  |  |             //idcard = RSAUtils.getInstance(patientService).decryptString(idcard);
 | 
	
		
			
				|  |  |             rsaUtils.setBaseService(patientService);
 | 
	
		
			
				|  |  |             idcard =rsaUtils.decryptString(idcard);
 | 
	
		
			
				|  |  |             idcard = rsaUtils.decryptString(idcard);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |             idcard = URLDecoder.decode(idcard, "UTF-8");
 | 
	
		
			
				|  |  |             idcard = StringUtils.reverse(idcard);
 | 
	
	
		
			
				|  | @ -192,7 +194,8 @@ public class WechatController extends WeixinBaseController {
 | 
	
		
			
				|  |  |                          @RequestParam(value = "mobile", required = true) String mobile,
 | 
	
		
			
				|  |  |                          @RequestParam(value = "captcha", required = true) String captcha,
 | 
	
		
			
				|  |  |                          @RequestParam(value = "openid", required = true) String openid,
 | 
	
		
			
				|  |  |                          @RequestParam(value = "password", required = true) String password) {
 | 
	
		
			
				|  |  |                          @RequestParam(value = "password", required = true) String password,
 | 
	
		
			
				|  |  |                          @RequestParam(value = "token", required = false) String token) {
 | 
	
		
			
				|  |  |         try {
 | 
	
		
			
				|  |  |             if (StringUtils.isEmpty(name)) {
 | 
	
		
			
				|  |  |                 return error(-1, "姓名不允许为空!");
 | 
	
	
		
			
				|  | @ -240,7 +243,62 @@ public class WechatController extends WeixinBaseController {
 | 
	
		
			
				|  |  |             } else {
 | 
	
		
			
				|  |  |                 return error(-1, "请输入正确的身份证号!");
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  |             //==========================同步易联众的医保卡号=============================
 | 
	
		
			
				|  |  |             //判断此人有没有厦门社保卡 没有补给注册
 | 
	
		
			
				|  |  |             //判断身份证号与姓名是否一致
 | 
	
		
			
				|  |  |             //判断身份证和社保卡是否一致  统一只存英文字母开头的医保卡
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |             if (!org.springframework.util.StringUtils.isEmpty(token)) {
 | 
	
		
			
				|  |  |                 UserInfoResponse userInfoResponse = ylzUserService.getUserByToken(token);
 | 
	
		
			
				|  |  |                 if (userInfoResponse.getCardInfo() != null && userInfoResponse.getCardInfo().size() > 0) {
 | 
	
		
			
				|  |  |                     List<UserInfoResponse.CardInfo> cards = userInfoResponse.getCardInfo();
 | 
	
		
			
				|  |  |                     Boolean hasCard = false;
 | 
	
		
			
				|  |  |                     UserInfoResponse.CardInfo cardInfo = null;
 | 
	
		
			
				|  |  |                     for (UserInfoResponse.CardInfo card : cards) {
 | 
	
		
			
				|  |  |                         //如果患者有正常状态的社保卡
 | 
	
		
			
				|  |  |                         if ("01".equals(card.getCardType()) && "normal".equals("state")) {
 | 
	
		
			
				|  |  |                             hasCard = true;
 | 
	
		
			
				|  |  |                             cardInfo = card;
 | 
	
		
			
				|  |  |                             break;
 | 
	
		
			
				|  |  |                         }
 | 
	
		
			
				|  |  |                     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |                     if (!hasCard) {
 | 
	
		
			
				|  |  |                         return error(-1, "医保卡不存在,必须使用正常状态的厦门医保卡");
 | 
	
		
			
				|  |  |                     }
 | 
	
		
			
				|  |  |                     if (name.compareTo(userInfoResponse.getName() == null ? "" : userInfoResponse.getName()) != 0) {
 | 
	
		
			
				|  |  |                         return error(-1, "身份证号与姓名不一致<br/>请检查后重新输入");
 | 
	
		
			
				|  |  |                     }
 | 
	
		
			
				|  |  |                     if (ssc.compareTo(cardInfo.getCardNo() == null ? "" : cardInfo.getCardNo()) != 0) {
 | 
	
		
			
				|  |  |                         return error(-1, "身份证号与医保卡号不一致,请检查后重新输入");
 | 
	
		
			
				|  |  |                     } else {
 | 
	
		
			
				|  |  |                         ssc = cardInfo.getCardNo();//统一只存英文字母开头的医保卡
 | 
	
		
			
				|  |  |                     }
 | 
	
		
			
				|  |  |                     SocialSecurityInfo socialSecurityInfo = socialSecurityInfoDao.findBySfzh18Max(idcard);
 | 
	
		
			
				|  |  |                     //如果我们表没有记录那就新增一条记录
 | 
	
		
			
				|  |  |                     if(socialSecurityInfo==null){
 | 
	
		
			
				|  |  |                         socialSecurityInfo=new SocialSecurityInfo();
 | 
	
		
			
				|  |  |                         socialSecurityInfo.setXming0(name);
 | 
	
		
			
				|  |  |                         socialSecurityInfo.setXbie00(IdCardUtil.getSexForIdcard(idcard));
 | 
	
		
			
				|  |  |                         socialSecurityInfo.setCsrqi0(IdCardUtil.getBirthdayForIdcardStr(idcard));
 | 
	
		
			
				|  |  |                         socialSecurityInfo.setSfzh18(idcard);
 | 
	
		
			
				|  |  |                         socialSecurityInfo.setGrsfen("8");
 | 
	
		
			
				|  |  |                         socialSecurityInfo.setId0000(idcard);
 | 
	
		
			
				|  |  |                         socialSecurityInfo.setGzztai("01");
 | 
	
		
			
				|  |  |                         socialSecurityInfo.setCardno(ssc);
 | 
	
		
			
				|  |  |                         socialSecurityInfoDao.save(socialSecurityInfo);
 | 
	
		
			
				|  |  |                     }
 | 
	
		
			
				|  |  |                     //如果医保卡不一致更新{
 | 
	
		
			
				|  |  |                     if(!socialSecurityInfo.getCardno().equals(ssc)){
 | 
	
		
			
				|  |  |                         socialSecurityInfo.setCardno(ssc);
 | 
	
		
			
				|  |  |                     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |                 }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |             }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |             //==============================旧版验证=========================
 | 
	
		
			
				|  |  | //            SocialSecurityInfo socialSecurityInfo = socialSecurityInfoDao.findBySfzh18Max(idcard);
 | 
	
		
			
				|  |  | //
 | 
	
		
			
				|  |  | //            if (socialSecurityInfo != null) {
 | 
	
	
		
			
				|  | @ -258,6 +316,7 @@ public class WechatController extends WeixinBaseController {
 | 
	
		
			
				|  |  | //                return error(-1, "对不起,暂不支持16年6月份之后办理的医保卡注册");
 | 
	
		
			
				|  |  | //            }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |             //==========================旧版验证=============================
 | 
	
		
			
				|  |  |             Patient patient = patientDao.findByIdcard(idcard);
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |             if (patient == null) {
 | 
	
	
		
			
				|  | @ -278,7 +337,7 @@ public class WechatController extends WeixinBaseController {
 | 
	
		
			
				|  |  |             password = StringUtils.reverse(password);
 | 
	
		
			
				|  |  |             patient.setPassword(MD5.GetMD5Code(password + salt));
 | 
	
		
			
				|  |  |             patient.setSsc(ssc);
 | 
	
		
			
				|  |  |             if(!"undefined".equals(openid)&&StringUtils.isNotBlank(openid)){
 | 
	
		
			
				|  |  |             if (!"undefined".equals(openid) && StringUtils.isNotBlank(openid)) {
 | 
	
		
			
				|  |  |                 patient.setOpenid(openid);
 | 
	
		
			
				|  |  |                 patient.setOpenidTime(new Date());
 | 
	
		
			
				|  |  |             }
 | 
	
	
		
			
				|  | @ -287,7 +346,7 @@ public class WechatController extends WeixinBaseController {
 | 
	
		
			
				|  |  | //                patient.setOpenidTime(new Date());
 | 
	
		
			
				|  |  | //            }
 | 
	
		
			
				|  |  |             JSONObject json = patientService.register(idcard, ssc, name, mobile, MD5.GetMD5Code(password + salt)
 | 
	
		
			
				|  |  |                     ,salt,openid,3);
 | 
	
		
			
				|  |  |                     , salt, openid, 3);
 | 
	
		
			
				|  |  |             if (json != null) {
 | 
	
		
			
				|  |  |                 try {
 | 
	
		
			
				|  |  |                     Patient p = patientDao.findByIdcard(idcard);
 | 
	
	
		
			
				|  | @ -307,6 +366,7 @@ public class WechatController extends WeixinBaseController {
 | 
	
		
			
				|  |  |         }
 | 
	
		
			
				|  |  |     }
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |     /**
 | 
	
		
			
				|  |  |      * 患者微信登录接口
 | 
	
		
			
				|  |  |      *
 | 
	
	
		
			
				|  | @ -384,22 +444,22 @@ public class WechatController extends WeixinBaseController {
 | 
	
		
			
				|  |  |                     if (StringUtils.isNotBlank(openid) && !"undefined".equals(openid)) {//undefined不更新数据库
 | 
	
		
			
				|  |  |                         //patient.setOpenid(openid);
 | 
	
		
			
				|  |  |                         //1.判斷居民OPenid是不是空
 | 
	
		
			
				|  |  |                         if(StringUtils.isNotBlank(p.getOpenid())){
 | 
	
		
			
				|  |  |                         if (StringUtils.isNotBlank(p.getOpenid())) {
 | 
	
		
			
				|  |  |                             //如果OPenid与原来用户不相等,则判断登录的openids是否被大于10人登录
 | 
	
		
			
				|  |  |                             if(!p.getOpenid().equals(openid)){
 | 
	
		
			
				|  |  |                             if (!p.getOpenid().equals(openid)) {
 | 
	
		
			
				|  |  |                                 //判断登录的openids是否被大于10人登录
 | 
	
		
			
				|  |  |                                 if(!patientService.checkOpenidCount(openid)){
 | 
	
		
			
				|  |  |                                     errorMessage ="您已超过系统允许登录的最大居民账号数量,当前不再允许使用该微信登录新的居民账号,请使用其他微信号进行登录";
 | 
	
		
			
				|  |  |                                 if (!patientService.checkOpenidCount(openid)) {
 | 
	
		
			
				|  |  |                                     errorMessage = "您已超过系统允许登录的最大居民账号数量,当前不再允许使用该微信登录新的居民账号,请使用其他微信号进行登录";
 | 
	
		
			
				|  |  |                                     return error(-2, errorMessage);
 | 
	
		
			
				|  |  |                                 }
 | 
	
		
			
				|  |  |                             }
 | 
	
		
			
				|  |  |                             patientService.updatePatient(p, openid);
 | 
	
		
			
				|  |  |                         }else{
 | 
	
		
			
				|  |  |                         } else {
 | 
	
		
			
				|  |  |                             // 判断登录的openids是否被大于10人登录
 | 
	
		
			
				|  |  |                             if(!patientService.checkOpenidCount(openid)){
 | 
	
		
			
				|  |  |                                 errorMessage ="您已超过系统允许登录的最大居民账号数量,当前不再允许使用该微信登录新的居民账号,请使用其他微信号进行登录";
 | 
	
		
			
				|  |  |                             if (!patientService.checkOpenidCount(openid)) {
 | 
	
		
			
				|  |  |                                 errorMessage = "您已超过系统允许登录的最大居民账号数量,当前不再允许使用该微信登录新的居民账号,请使用其他微信号进行登录";
 | 
	
		
			
				|  |  |                                 return error(-2, errorMessage);
 | 
	
		
			
				|  |  |                             }else{
 | 
	
		
			
				|  |  |                             } else {
 | 
	
		
			
				|  |  |                                 //未达到上限更新用户openid
 | 
	
		
			
				|  |  |                                 patientService.updatePatient(p, openid);
 | 
	
		
			
				|  |  |                             }
 | 
	
	
		
			
				|  | @ -422,7 +482,7 @@ public class WechatController extends WeixinBaseController {
 | 
	
		
			
				|  |  |                     loginLog.setLoginType("1");
 | 
	
		
			
				|  |  |                     loginLogService.saveLog(loginLog);
 | 
	
		
			
				|  |  |                     //判断是否打过标签
 | 
	
		
			
				|  |  |                    //if (!(Patient.isWchatTage.yes.getValue() == p.getIsWxtag())) {
 | 
	
		
			
				|  |  |                     //if (!(Patient.isWchatTage.yes.getValue() == p.getIsWxtag())) {
 | 
	
		
			
				|  |  | 
 | 
	
		
			
				|  |  |                     //清空患者的微信标签
 | 
	
		
			
				|  |  |                     weiXinTagUtil.deleteTagWithOpenid(p.getOpenid());
 | 
	
	
		
			
				|  | @ -510,22 +570,22 @@ public class WechatController extends WeixinBaseController {
 | 
	
		
			
				|  |  |                     if (StringUtils.isNotBlank(openid) && !"undefined".equals(openid)) {//undefined不更新数据库
 | 
	
		
			
				|  |  |                         //patient.setOpenid(openid);
 | 
	
		
			
				|  |  |                         //1.判斷居民OPenid是不是空
 | 
	
		
			
				|  |  |                         if(StringUtils.isNotBlank(p.getOpenid())){
 | 
	
		
			
				|  |  |                         if (StringUtils.isNotBlank(p.getOpenid())) {
 | 
	
		
			
				|  |  |                             //如果OPenid与原来用户不相等,则判断登录的openids是否被大于10人登录
 | 
	
		
			
				|  |  |                             if(!p.getOpenid().equals(openid)){
 | 
	
		
			
				|  |  |                             if (!p.getOpenid().equals(openid)) {
 | 
	
		
			
				|  |  |                                 //判断登录的openids是否被大于10人登录
 | 
	
		
			
				|  |  |                                 if(!patientService.checkOpenidCount(openid)){
 | 
	
		
			
				|  |  |                                     errorMessage ="您已超过系统允许登录的最大居民账号数量,当前不再允许使用该微信登录新的居民账号,请使用其他微信号进行登录";
 | 
	
		
			
				|  |  |                                 if (!patientService.checkOpenidCount(openid)) {
 | 
	
		
			
				|  |  |                                     errorMessage = "您已超过系统允许登录的最大居民账号数量,当前不再允许使用该微信登录新的居民账号,请使用其他微信号进行登录";
 | 
	
		
			
				|  |  |                                     return error(-2, errorMessage);
 | 
	
		
			
				|  |  |                                 }
 | 
	
		
			
				|  |  |                             }
 | 
	
		
			
				|  |  |                             patientService.updatePatient(p, openid);
 | 
	
		
			
				|  |  |                         }else{
 | 
	
		
			
				|  |  |                         } else {
 | 
	
		
			
				|  |  |                             // 判断登录的openids是否被大于10人登录
 | 
	
		
			
				|  |  |                             if(!patientService.checkOpenidCount(openid)){
 | 
	
		
			
				|  |  |                                 errorMessage ="您已超过系统允许登录的最大居民账号数量,当前不再允许使用该微信登录新的居民账号,请使用其他微信号进行登录";
 | 
	
		
			
				|  |  |                             if (!patientService.checkOpenidCount(openid)) {
 | 
	
		
			
				|  |  |                                 errorMessage = "您已超过系统允许登录的最大居民账号数量,当前不再允许使用该微信登录新的居民账号,请使用其他微信号进行登录";
 | 
	
		
			
				|  |  |                                 return error(-2, errorMessage);
 | 
	
		
			
				|  |  |                             }else{
 | 
	
		
			
				|  |  |                             } else {
 | 
	
		
			
				|  |  |                                 //未达到上限更新用户openid
 | 
	
		
			
				|  |  |                                 patientService.updatePatient(p, openid);
 | 
	
		
			
				|  |  |                             }
 |