| 
					
				 | 
			
			
				@ -0,0 +1,78 @@ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				package com.yihu.jw.care.endpoint.third.patient; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.entity.base.wx.BasePatientWechatDo; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.restmodel.web.Envelop; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.restmodel.web.endpoint.EnvelopRestEndpoint; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.rm.patient.PatientRequestMapping; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.wechat.dao.BasePatientWechatDao; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.wechat.service.WechatInfoService; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import io.swagger.annotations.Api; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import org.apache.axis.utils.StringUtils; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import org.springframework.beans.factory.annotation.Autowired; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import org.springframework.beans.factory.annotation.Value; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import org.springframework.data.redis.core.StringRedisTemplate; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import org.springframework.web.bind.annotation.*; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import java.util.Date; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import java.util.List; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import java.util.concurrent.TimeUnit; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				/** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 * Created by Bing on 2021/5/28. 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				@RestController 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				@RequestMapping(value = "/cloudCare/noLogin/patient") 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				@Api(value = "患者不用登陆访问控制类", description = "患者不用登陆访问控制类") 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				public class PatientNoLoginEndPoint extends EnvelopRestEndpoint { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    @Value("${wechat.id}") 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    private String wxId; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    @Autowired 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    private StringRedisTemplate redisTemplate; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    @Autowired 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    private WechatInfoService wechatInfoService; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    @Autowired 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    private BasePatientWechatDao basePatientWechatDao; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    /** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * 获取微信openid 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @param code 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @return 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    @RequestMapping(value = "/getOpenidByCode", method = {RequestMethod.POST, RequestMethod.GET}) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    @ResponseBody 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    public Envelop getOpenidByCode(String code, @RequestParam(value = "patientId", required = false)String patientId) throws Exception { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        try { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            //通过redis获取openid, 获取不到,则调用微信接口去取 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            String key = wxId+":code"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            String openid = redisTemplate.opsForValue().get(key); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            if(!StringUtils.isEmpty(openid)){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                return success(PatientRequestMapping.Wechat.api_success,openid); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            openid = wechatInfoService.getOpenidByCode(code, wxId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            if (!StringUtils.isEmpty(patientId)){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                List<BasePatientWechatDo> list = basePatientWechatDao.findByWechatIdAndPatientId(wxId,patientId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                if (list!=null&&list.size()>0){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    for (BasePatientWechatDo basePatientWechatDo:list){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        basePatientWechatDo.setOpenid(openid); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        basePatientWechatDao.save(basePatientWechatDo); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                }else { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    BasePatientWechatDo basePatientWechatDo = new BasePatientWechatDo(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    basePatientWechatDo.setPatientId(patientId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    basePatientWechatDo.setWechatId(wxId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    basePatientWechatDo.setCreateTime(new Date()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    basePatientWechatDo.setOpenid(openid); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    basePatientWechatDao.save(basePatientWechatDo); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            redisTemplate.opsForValue().set(key,openid); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            redisTemplate.expire(key,10, TimeUnit.SECONDS); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            return success(PatientRequestMapping.Wechat.api_success,openid); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } catch (Exception e){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            return  failedException(e); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				} 
			 |