|
@ -7,10 +7,14 @@ import com.yihu.jw.entity.base.patient.BasePatientDO;
|
|
|
import com.yihu.jw.restmodel.web.ObjEnvelop;
|
|
|
import com.yihu.jw.security.core.userdetails.jdbc.WlyyUserDetailsService;
|
|
|
import com.yihu.jw.security.dao.doctor.BaseDoctorDao;
|
|
|
import com.yihu.jw.security.dao.patient.BasePatientDao;
|
|
|
import com.yihu.jw.security.login.service.BaseLoginLogService;
|
|
|
import com.yihu.jw.security.model.WlyyUserSimple;
|
|
|
import com.yihu.jw.security.oauth2.provider.WlyyTokenGranter;
|
|
|
import com.yihu.jw.security.service.YkyyService;
|
|
|
import com.yihu.jw.security.utils.DateUtil;
|
|
|
import com.yihu.jw.security.utils.IdCardUtil;
|
|
|
import com.yihu.utils.security.MD5;
|
|
|
import io.swagger.annotations.Api;
|
|
|
import org.apache.commons.collections.map.HashedMap;
|
|
|
import org.slf4j.Logger;
|
|
@ -34,7 +38,9 @@ import org.springframework.web.client.RestTemplate;
|
|
|
|
|
|
import javax.annotation.PostConstruct;
|
|
|
import java.util.Date;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
import java.util.UUID;
|
|
|
|
|
|
/**
|
|
|
* Created by yeshijie on 2020/4/24.
|
|
@ -67,6 +73,8 @@ public class WlyyYkyyEndpoint extends AbstractEndpoint {
|
|
|
private AuthenticationManager authenticationManager;
|
|
|
@Autowired
|
|
|
private WlyyTokenGranter tokenGranter;
|
|
|
@Autowired
|
|
|
private BasePatientDao basePatientDao;
|
|
|
|
|
|
|
|
|
@PostConstruct
|
|
@ -156,6 +164,123 @@ public class WlyyYkyyEndpoint extends AbstractEndpoint {
|
|
|
return ObjEnvelop.getError("登录失败!");
|
|
|
}
|
|
|
|
|
|
|
|
|
/**
|
|
|
* 眼科居民登录
|
|
|
* @param verifyCode
|
|
|
* @param client_id
|
|
|
* @param login_type 用户类型 1或默认为user,2:居民登录
|
|
|
* @return
|
|
|
*/
|
|
|
@RequestMapping(value = "/oauth/ykyyPatientLogin", method = RequestMethod.POST)
|
|
|
public ObjEnvelop ykyyPatientLogin(String verifyCode, String client_id,String login_type) {
|
|
|
|
|
|
if (StringUtils.isEmpty(client_id)) {
|
|
|
throw new InvalidRequestException("client_id is null");
|
|
|
}
|
|
|
|
|
|
if (StringUtils.isEmpty(login_type)) {
|
|
|
throw new InvalidRequestException("login_type is null");
|
|
|
}
|
|
|
|
|
|
try {
|
|
|
logger.info("verifyCode :"+verifyCode);
|
|
|
|
|
|
String data = ykyyService.getPatientInfoByVerifycode(verifyCode);
|
|
|
JSONObject jsonObject = JSONObject.parseObject(data);
|
|
|
if(!jsonObject.getString("code").equalsIgnoreCase("10000")){
|
|
|
logger.info(jsonObject.getString("message"));
|
|
|
return ObjEnvelop.getError("授权登录失败!");
|
|
|
}
|
|
|
JSONObject value = jsonObject.getJSONObject("value");
|
|
|
String userId = value.getString("userId");
|
|
|
String tel = value.getString("tel");
|
|
|
String idCard = value.getString("Idcard");
|
|
|
String yktId = value.getString("yktId");
|
|
|
String name = value.getString("name");
|
|
|
|
|
|
List<BasePatientDO> basePatientDOS = basePatientDao.findByMobile(tel);
|
|
|
|
|
|
// String idCard = "352103197207090030";
|
|
|
|
|
|
if(basePatientDOS == null||basePatientDOS.size()==0){
|
|
|
BasePatientDO basePatientDO = new BasePatientDO();
|
|
|
basePatientDO.setDel("1");
|
|
|
basePatientDO.setName(name);
|
|
|
basePatientDO.setCreateTime(new Date());
|
|
|
basePatientDO.setUpdateTime(new Date());
|
|
|
basePatientDO.setYktId(yktId);
|
|
|
basePatientDO.setUserId(userId);
|
|
|
basePatientDO.setIdcard(idCard);
|
|
|
if (org.apache.commons.lang3.StringUtils.isNoneBlank(idCard)){
|
|
|
Integer age = IdCardUtil.getAgeForIdcard(idCard);
|
|
|
String sex = IdCardUtil.getSexForIdcard_new(idCard);
|
|
|
Integer sexx = null;
|
|
|
if (org.apache.commons.lang3.StringUtils.isNoneBlank(sex)){
|
|
|
sexx = Integer.parseInt(sex);
|
|
|
}
|
|
|
basePatientDO.setSex(sexx);
|
|
|
String birthday = IdCardUtil.getBirthdayForIdcardStr(idCard);
|
|
|
Date birthDay = null;
|
|
|
if (org.apache.commons.lang3.StringUtils.isNoneBlank(birthday)){
|
|
|
birthDay = DateUtil.strToDate(birthday+" 00:00:00");;
|
|
|
}
|
|
|
basePatientDO.setBirthday(birthDay);
|
|
|
|
|
|
}
|
|
|
basePatientDO.setMobile(tel);
|
|
|
String salt = UUID.randomUUID().toString().substring(0,5);
|
|
|
String pw = tel.substring(tel.length()-6,tel.length());
|
|
|
basePatientDO.setPassword(MD5.md5Hex(pw + "{" + salt + "}"));
|
|
|
basePatientDO.setSalt(salt);
|
|
|
basePatientDO.setLocked(0);
|
|
|
basePatientDO.setEnabled(1);
|
|
|
basePatientDO.setPatientStatus("1");
|
|
|
basePatientDao.save(basePatientDO);
|
|
|
}
|
|
|
|
|
|
ClientDetails authenticatedClient = clientDetailsService.loadClientByClientId(client_id);
|
|
|
|
|
|
Map<String, String> parameters = new HashedMap();
|
|
|
|
|
|
parameters.put("username", tel);
|
|
|
parameters.put("grant_type", "ihealthCode");
|
|
|
|
|
|
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());
|
|
|
}
|
|
|
|
|
|
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"));
|
|
|
String loginType = parameters.get("login_type");
|
|
|
|
|
|
BaseLoginLogDO baseLoginLogDO = new BaseLoginLogDO();
|
|
|
userDetailsService.setRolePhth(loginType, token, wlyyUserSimple.getId(), redisTemplate);
|
|
|
|
|
|
baseLoginLogDO.setUserId(wlyyUserSimple.getId());
|
|
|
baseLoginLogDO.setCreateTime(new Date());
|
|
|
String userAgent = JSONObject.toJSONString(wlyyUserSimple);
|
|
|
baseLoginLogDO.setUserAgent(userAgent);
|
|
|
baseLoginLogDO.setLoginType(loginType);
|
|
|
baseLoginLogService.save(baseLoginLogDO);
|
|
|
|
|
|
return ObjEnvelop.getSuccess("success",wlyyUserSimple);
|
|
|
|
|
|
}catch (Exception e){
|
|
|
logger.error(e);
|
|
|
}
|
|
|
return ObjEnvelop.getError("登录失败!");
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
protected TokenGranter getTokenGranter() {
|
|
|
return this.tokenGranter;
|