| 
					
				 | 
			
			
				@ -23,11 +23,13 @@ import org.springframework.security.core.userdetails.UsernameNotFoundException; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import org.springframework.security.oauth2.common.OAuth2AccessToken; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import org.springframework.security.oauth2.provider.ClientDetails; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import org.springframework.security.oauth2.provider.ClientDetailsService; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import org.springframework.transaction.annotation.Transactional; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import org.springframework.web.context.request.RequestContextHolder; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import org.springframework.web.context.request.ServletRequestAttributes; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import javax.servlet.http.HttpServletRequest; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import javax.sql.DataSource; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import java.security.KeyPair; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import java.sql.Timestamp; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import java.util.*; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import java.util.concurrent.TimeUnit; 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@ -43,13 +45,16 @@ public class WlyyUserDetailsService extends JdbcDaoSupport implements UserDetail 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    private static final String DEFAULT_DOCTOR_DETAILS_STATEMENT = "SELECT * FROM base_doctor d WHERE d.mobile = ? OR d.idcard = ?"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    private static final String DEFAULT_PATIENT_DETAILS_STATEMENT = "SELECT * FROM base_patient p WHERE p.mobile = ? OR p.idcard = ?"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    private static final String DEFAULT_PATIENT_DETAILS_ID_STATEMENT = "SELECT * FROM base_patient p WHERE p.id = ? "; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    private static final String DEFAULT_PATIENT_DETAILS_IDCARD_STATEMENT = "SELECT * FROM base_patient p WHERE p.idcard = ? "; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    private static final String DEFAULT_PATIENT_INSERT_STATEMENT = 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            "INSERT into base_patient (`id`,`ihealth_openid`,`ihealth_openid_time`,`idcard`,`password`,`salt`,`name`,`birthday`,`sex`,`mobile`," + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            "INSERT into base_patient (`id`,`photo`,`idcard`,`password`,`salt`,`name`,`birthday`,`sex`,`mobile`," + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    "`province_code`,`province_name`,`city_code`,`city_name`,`town_code`,`town_name`,`street_code`,`street_name`,`address`," + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    "`del`,`locked`,`enabled`,`login_failure_count`,`login_date`) " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    " values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    " values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    private static final String PATIENT_INSERT_WEHCAT = "insert into base_patient_wechat (`id`,`wechat_id`,`patient_id`,`openid`,`create_time`) values(?,?,?,?,?)"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    private static final String BespeakRegist = "bespeakRegist:"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@ -112,7 +117,7 @@ public class WlyyUserDetailsService extends JdbcDaoSupport implements UserDetail 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } else if ("2".equals(loginType)) {//2.为医生账号 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            //解除锁定 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            this.getJdbcTemplate().update("update base_doctor d set d.login_failure_count = 0, d.locked = 0 where d.mobile = ? or d.idcard = ?", username, username); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } else if ("3".equals(loginType)) { //3.患者账号 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } else if ("3".equals(loginType) || "4".equals(loginType)) { //3.患者账号 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            //解除锁定 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            this.getJdbcTemplate().update("update base_patient p set p.login_failure_count = 5, p.locked = 0 where p.mobile = ? or p.idcard = ?", username, username); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } //... 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@ -126,6 +131,7 @@ public class WlyyUserDetailsService extends JdbcDaoSupport implements UserDetail 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @param username 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @return 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    @Transactional 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    public List<WlyyUserDetails> getWlyyUserDetails(String username) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        String loginType = getLogintype(); 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@ -150,7 +156,7 @@ public class WlyyUserDetailsService extends JdbcDaoSupport implements UserDetail 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            users = this.getJdbcTemplate().query(DEFAULT_PATIENT_DETAILS_STATEMENT, new BeanPropertyRowMapper(WlyyUserDetails.class), username, username); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            // 去i健康查询用户 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        }else if("4".equals(loginType)){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            users = this.getJdbcTemplate().query(DEFAULT_PATIENT_DETAILS_ID_STATEMENT, new BeanPropertyRowMapper(WlyyUserDetails.class), username); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            users = this.getJdbcTemplate().query(DEFAULT_PATIENT_DETAILS_IDCARD_STATEMENT, new BeanPropertyRowMapper(WlyyUserDetails.class), getIdcard()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            if ((null == users || users.size() == 0) && "4".equals(loginType)) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                List<NameValuePair> params = new ArrayList<>(); 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@ -163,7 +169,7 @@ public class WlyyUserDetailsService extends JdbcDaoSupport implements UserDetail 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                try{ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    res = httpClientUtil.post(iHealthUserInfoUrl, params, "UTF-8"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                }catch (Exception e){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    logger.error("远程请求i健康用户信息异常败:" + e.getMessage()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    logger.error("远程请求i健康用户信息异常:" + e.getMessage()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    return users; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                if(null == res){ 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@ -177,8 +183,7 @@ public class WlyyUserDetailsService extends JdbcDaoSupport implements UserDetail 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                try { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    this.getJdbcTemplate().update(DEFAULT_PATIENT_INSERT_STATEMENT, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                            new Object[]{patient.getString("code"), 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                    patient.getString("openid"), 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                    new Date(), 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                    patient.getString("photo"), 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                    patient.getString("idcard"), 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                    patient.getString("password"), 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                    patient.getString("salt"), 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@ -203,7 +208,22 @@ public class WlyyUserDetailsService extends JdbcDaoSupport implements UserDetail 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    ); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                }catch (Exception e){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    e.printStackTrace(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    logger.error("将i健康居民数据同步到互联网医院居民表失败:" + e.getMessage()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    return users; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                try { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    this.getJdbcTemplate().update(PATIENT_INSERT_WEHCAT, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                            new Object[]{ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                    UUID.randomUUID().toString(), 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                    getWechatId(), 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                    patient.getString("code"), 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                    getOpenid(), 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                                    new Date() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    ); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                }catch (Exception e){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    logger.error("将i健康居民微信openid数据同步到互联网医院居民微信关联表失败:" + e.getMessage()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    return users; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                WlyyUserDetails user = new WlyyUserDetails(); 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@ -367,7 +387,7 @@ public class WlyyUserDetailsService extends JdbcDaoSupport implements UserDetail 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } else if("4".equals(loginType)){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            //更新登录时间 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            this.getJdbcTemplate().update("update base_patient p set p.login_failure_count = 0, p.login_date = ? where p.mobile = ? or p.idcard = ?", new Date(), username, username); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            users = this.getJdbcTemplate().query(DEFAULT_PATIENT_DETAILS_ID_STATEMENT, new BeanPropertyRowMapper(WlyyUserSimple.class), username); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            users = this.getJdbcTemplate().query(DEFAULT_PATIENT_DETAILS_IDCARD_STATEMENT, new BeanPropertyRowMapper(WlyyUserSimple.class), getIdcard()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        return users; 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@ -402,7 +422,7 @@ public class WlyyUserDetailsService extends JdbcDaoSupport implements UserDetail 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    /** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * 获取i健康用户登录openid型 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * 获取用户登录的clientId 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @return 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     */ 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@ -415,23 +435,44 @@ public class WlyyUserDetailsService extends JdbcDaoSupport implements UserDetail 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        return clientId; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    /** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * 获取用户登录的wechatId 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @return 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    public String getWechatId() { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    public boolean setRolePhth(String loginType, OAuth2AccessToken token, String id, StringRedisTemplate redisTemplate) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        if (org.apache.commons.lang.StringUtils.isBlank(loginType) || "1".equals(loginType)) { //1或默认查找user表,为平台管理员账号 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            String key = "wlyy2:auth:token:" + token.getValue(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            redisTemplate.opsForValue().set(key, "/**"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            redisTemplate.expire(key, token.getExpiresIn(), TimeUnit.SECONDS); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } else if ("2".equals(loginType)) {//2.为医生账号 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        String wechatId = request.getParameter("wechat_id"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } else if ("3".equals(loginType) || "4".equals(loginType)) { //3.患者账号 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        return wechatId; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  /** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * 获取用户登录的idcard 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @return 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    public String getIdcard() { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        KeyPair keyPair = (KeyPair) request.getSession().getAttribute("privateKey"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        String idcard = com.yihu.jw.security.utils.RSAUtils.decryptBase64(request.getParameter("idcard"), keyPair); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        return idcard; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    public boolean setRolePhth(String loginType, OAuth2AccessToken token, String id, StringRedisTemplate redisTemplate) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        if (org.apache.commons.lang.StringUtils.isBlank(loginType) || "1".equals(loginType) || "2".equals(loginType) || "3".equals(loginType) || "4".equals(loginType)) { //1或默认查找user表,为平台管理员账号 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            String key = "wlyy2:auth:token:" + token.getValue(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            redisTemplate.opsForValue().set(key, "/**"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            redisTemplate.expire(key, token.getExpiresIn(), TimeUnit.SECONDS); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } else { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            return false; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            return true; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        return true; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        return false; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    public void updateOpenId(String openid, String userId) { 
			 |