Procházet zdrojové kódy

注册成功,并登陆,将信息返回

chenyongxing před 6 roky
rodič
revize
50223ca1e9

+ 13 - 0
common/common-entity/src/main/java/com/yihu/jw/entity/base/patient/BasePatientDO.java

@ -201,6 +201,11 @@ public class BasePatientDO extends UuidIdentityEntityWithOperator {
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+08:00")
    private Date openidTime;
    /**
     * 绑定电子社保卡主体(共济为操作人code,医社保关联patient_medicare_card)
     */
    private String principalCode;
    /**
     * 居民预警状态:0为标准,1为预警状态
     */
@ -458,6 +463,14 @@ public class BasePatientDO extends UuidIdentityEntityWithOperator {
        this.openidTime = openidTime;
    }
    @Column(name = "principal_code")
    public String getPrincipalCode() {
        return principalCode;
    }
    public void setPrincipalCode(String principalCode) {
        this.principalCode = principalCode;
    }
    @Column(name = "standard_status")
    public Integer getStandardStatus() {
        return standardStatus;

+ 2 - 1
server/svr-authentication/src/main/java/com/yihu/jw/security/core/userdetails/SaltUser.java

@ -36,7 +36,8 @@ public class SaltUser implements UserDetails, CredentialsContainer {
    }
    public SaltUser(String username, String password, String salt, boolean enabled, boolean accountNonExpired, boolean credentialsNonExpired, boolean accountNonLocked, Collection<? extends GrantedAuthority> authorities) {
        if(username != null && !"".equals(username) && password != null) {
        //居民使用验证码注册,密码没有默认值, 可能为空 password != null
        if(username != null && !"".equals(username)) {
            this.username = username;
            this.password = password;
            this.salt = salt;

+ 6 - 0
server/svr-authentication/src/main/java/com/yihu/jw/security/core/userdetails/jdbc/WlyyUserDetailsService.java

@ -97,6 +97,8 @@ public class WlyyUserDetailsService extends JdbcDaoSupport implements UserDetail
        //1或默认查找user表,为平台管理员账号
        if(StringUtils.isBlank(loginType)||"1".equals(loginType)){
            users = this.getJdbcTemplate().query(DEFAULT_USER_DETAILS_STATEMENT, new BeanPropertyRowMapper(WlyyUserDetails.class), username, username, username);
            //如果users为空,可能为预注册用户,从redis查找
            //todo cyx
            //2.为医生登录账号
        }else if("2".equals(loginType)){
            users = this.getJdbcTemplate().query(DEFAULT_DOCTOR_DETAILS_STATEMENT, new BeanPropertyRowMapper(WlyyUserDetails.class), username, username);
@ -260,4 +262,8 @@ public class WlyyUserDetailsService extends JdbcDaoSupport implements UserDetail
        }
        return true;
    }
    public void updateOpenId(String openid,String userId){
        this.getJdbcTemplate().update("update base_patient p set p.openid = ? where p.id= ?",openid ,userId);
    }
}

+ 103 - 2
server/svr-authentication/src/main/java/com/yihu/jw/security/oauth2/provider/endpoint/WlyyLoginEndpoint.java

@ -166,9 +166,12 @@ public class WlyyLoginEndpoint extends AbstractEndpoint {
        wlyyUserSimple.setState(parameters.get("state"));
        String loginType = parameters.get("login_type");
        String openid = parameters.get("openid");
        //更新患者openId
        if(!StringUtils.isEmpty(openid) && !"undefined".equalsIgnoreCase(openid) && "3".equalsIgnoreCase(loginType)){
            userDetailsService.updateOpenId(openid,wlyyUserSimple.getId());
        }
        userDetailsService.setRolePhth(loginType,token,wlyyUserSimple.getId(),redisTemplate);
        return getResponse(wlyyUserSimple);
    }
@ -372,6 +375,95 @@ public class WlyyLoginEndpoint extends AbstractEndpoint {
        return new ResponseEntity<>(oauth2Envelop, headers, HttpStatus.OK);
    }
    /**
     * 登陆
     * @param parameters
     * 不定入参:
     * login_type 用户类型 1或默认为user,2:医生登录,3:患者登录
     * mobile:手机号
     * captcha:验证码
     * clientId:
     * login_type 用户类型 1或默认为user,2:医生登录,3:患者登录
     * @param httpSession
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/oauth/registAndLogin", method = RequestMethod.POST)
    public ResponseEntity<Oauth2Envelop<WlyyUserSimple>> registAndLogin(@RequestParam Map<String, String> parameters, HttpSession httpSession) throws Exception {
        //用于标记是否注册成功
        boolean registFlag = false;
        String client_id = parameters.get("client_id");
        if (StringUtils.isEmpty(client_id)) {
            throw new InvalidRequestException("client_id is null");
        }
        String type = parameters.get("login_type");
        if (StringUtils.isEmpty(type)) {
            throw new InvalidRequestException("regist type is null");
        }
        //type :1居民  2:医生
        if("3".equals(type)){
            String mobile = parameters.get("mobile");
            String captcha = parameters.get("captcha");
            HttpHeaders reqHeaders = new HttpHeaders();
            MultiValueMap<String, String> params = new LinkedMultiValueMap<>();
            params.add("mobile", mobile);
            params.add("captcha", captcha);
            params.add("openid", parameters.get("openid"));
            HttpEntity<MultiValueMap<String, String>> httpEntity = new HttpEntity<>(params, reqHeaders);
            Map<String, Object> result = restTemplate.postForObject("http://svr-patient-111:10021/basePatient/regist", httpEntity, HashMap.class);//svr-patient
            Map<String,Object> obj = (Map<String, Object>) result.get("obj");
            if("1".equals(obj.get("code"))){
                registFlag = true;
                parameters.put("username",mobile);
                wlyyRedisVerifyCodeService.store(client_id, mobile, captcha, 120);
            }else{
                return getFailedResponse(obj.get("message").toString(),-1,null);
            }
        }else{
            return getFailedResponse("暂不提供其他类型人员注册",-1,null);
        }
        if(registFlag){
            parameters.put("grant_type", "captcha");
            ClientDetails authenticatedClient = clientDetailsService.loadClientByClientId(client_id);
            TokenRequest tokenRequest = oAuth2RequestFactory.createTokenRequest(parameters, authenticatedClient);
            if (authenticatedClient != null) {
                oAuth2RequestValidator.validateScope(tokenRequest, authenticatedClient);
            }
            OAuth2AccessToken token = getTokenGranter().grant(tokenRequest.getGrantType(), tokenRequest);
            if (token == null) {
                throw new UnsupportedGrantTypeException("Unsupported grant type: " + tokenRequest.getGrantType());
            }
            /*如果是移动端登陆则移除之前的token,
            在网关处通过HTTP状态码告知前端是过期(402)还是账号在别处登陆(403),
            实现同一账号只能在一处登陆*/
            HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
            if (request.getHeader("login-device") != null && request.getHeader("login-device").equals("mobile")) {
                tokenStore.removeAccessToken(token.getValue());
                tokenStore.removeRefreshToken(token.getRefreshToken().getValue());
                token = getTokenGranter().grant(tokenRequest.getGrantType(), tokenRequest);
            }
            if (token == null) {
                throw new UnsupportedGrantTypeException("Unsupported grant type: " + tokenRequest.getGrantType());
            }
            WlyyUserSimple wlyyUserSimple = userDetailsService.authSuccess(parameters.get("username"));
            wlyyUserSimple.setAccessToken(token.getValue());
            wlyyUserSimple.setTokenType(token.getTokenType());
            wlyyUserSimple.setExpiresIn(token.getExpiresIn());
            wlyyUserSimple.setRefreshToken(token.getRefreshToken().getValue());
            wlyyUserSimple.setUser(parameters.get("username"));
            wlyyUserSimple.setState(parameters.get("state"));
            String loginType = parameters.get("login_type");
            userDetailsService.setRolePhth(loginType,token,wlyyUserSimple.getId(),redisTemplate);
            return getResponse(wlyyUserSimple);
        }
        return null;
    }
    @Override
    protected TokenGranter getTokenGranter() {
        return this.tokenGranter;
@ -392,6 +484,15 @@ public class WlyyLoginEndpoint extends AbstractEndpoint {
        return new ResponseEntity<>(oauth2Envelop, headers, HttpStatus.OK);
    }
    private ResponseEntity<Oauth2Envelop<WlyyUserSimple>> getFailedResponse(String message ,int status,WlyyUserSimple ehrUserSimple) {
        HttpHeaders headers = new HttpHeaders();
        headers.set("Cache-Control", "no-store");
        headers.set("Pragma", "no-cache");
        Oauth2Envelop<WlyyUserSimple> oauth2Envelop = new Oauth2Envelop<>(message, status, ehrUserSimple);
        return new ResponseEntity<>(oauth2Envelop, headers, HttpStatus.OK);
    }
    @Override
    protected WebResponseExceptionTranslator getExceptionTranslator() {
        return wlyyOAuth2ExceptionTranslator;

+ 6 - 6
svr/svr-healthy-house/src/main/java/com/yihu/jw/healthyhouse/service/user/LoginService.java

@ -250,12 +250,12 @@ public class LoginService  extends BaseJpaService {
        ObjectMapper objectMapper = new ObjectMapper();
        HashMap<String, Object> result = objectMapper.readValue(resultStr,HashMap.class);
            Long expire = 600L;
            wlyyRedisVerifyCodeService.store(clientId, phone, captcha, expire.intValue());
            HttpHeaders headers = new HttpHeaders();
            headers.set("Cache-Control", "no-store");
            headers.set("Pragma", "no-cache");
            return new ResponseEntity<>(result, headers, HttpStatus.OK);
        Long expire = 600L;
        wlyyRedisVerifyCodeService.store(clientId, phone, captcha, expire.intValue());
        HttpHeaders headers = new HttpHeaders();
        headers.set("Cache-Control", "no-store");
        headers.set("Pragma", "no-cache");
        return new ResponseEntity<>(result, headers, HttpStatus.OK);
    }

+ 4 - 10
svr/svr-patient/src/main/java/com/yihu/jw/patient/endpoint/personal_info/PatientEndpoint.java

@ -53,19 +53,13 @@ public class PatientEndpoint extends EnvelopRestEndpoint {
    @ApiOperation("居民注册接口")
    @RequestMapping(value = BaseRequestMapping.BasePatient.Regist, method = RequestMethod.POST)
    @ResponseBody
    public Envelop regist(@ApiParam(value = "手机号", name = "mobile") @RequestParam(required = true) String mobile,
    public ObjEnvelop regist(@ApiParam(value = "手机号", name = "mobile") @RequestParam(required = true) String mobile,
                          @ApiParam(value = "验证码", name = "captcha") @RequestParam(value = "captcha", required = true) String captcha,
                          @ApiParam(value = "微信openId", name = "openid") @RequestParam(value = "openid", required = false) String openid,
                          @ApiParam(value = "密码", name = "password") @RequestParam(value = "password", required = false) String password) {
        Envelop envelop = new Envelop();
        ObjEnvelop envelop = new ObjEnvelop();
        Map<String, Object> result = patientService.regist(mobile, captcha, password, openid);
        if ("-1".equals(result.get("code"))) {
            envelop.setStatus(-1);
            envelop.setMessage(result.get("message") + "");
        } else {
            envelop.setStatus(200);
            envelop.setMessage(result.get("message") + "");
        }
        envelop.setObj(result);
        return envelop;
    }
@ -199,7 +193,7 @@ public class PatientEndpoint extends EnvelopRestEndpoint {
    @GetMapping(value = "bespeakRegist")
    @ApiOperation(value = "发送验证码")
    @ApiOperation(value = "预注册测试接口")
    public Envelop bespeakRegist(
            @ApiParam(name = "mobile", value = "手机号")
            @RequestParam(value = "mobile", required = true) String mobile) throws Exception {

+ 0 - 3
svr/svr-patient/src/main/java/com/yihu/jw/patient/service/personal_Info/PatientMedicareCardService.java

@ -1,12 +1,9 @@
package com.yihu.jw.patient.service.personal_Info;
import com.yihu.jw.entity.base.patient.BasePatientDO;
import com.yihu.jw.entity.base.patient.PatientMedicareCardDO;
import com.yihu.jw.exception.business.patient.PatientCardNotFoundException;
import com.yihu.jw.exception.business.patient.PatientNotFoundException;
import com.yihu.jw.patient.dao.BasePatientDao;
import com.yihu.jw.patient.dao.BasePatientMedicareCardDao;
import com.yihu.jw.patient.dao.personal_info.PatientMedicareCardDao;
import com.yihu.jw.patient.service.BasePatientMedicardCardService;
import com.yihu.jw.util.security.MD5;
import org.springframework.beans.factory.annotation.Autowired;