auth登录接口
parent
c1b11491a7
commit
f21632aeda
|
@ -0,0 +1,30 @@
|
|||
package doctor.auth.controller;
|
||||
|
||||
import doctor.auth.service.HealthService;
|
||||
import doctor.auth.vo.DoctorUserVo;
|
||||
import doctor.common.core.domain.R;
|
||||
import doctor.common.security.service.TokenService;
|
||||
import doctor.system.api.model.LoginUser;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/doctor/v1")
|
||||
public class HealthController {
|
||||
|
||||
@Autowired
|
||||
private HealthService healthService;
|
||||
|
||||
@PostMapping("/login")
|
||||
public R<?> login(@RequestParam String email,String pwd) {
|
||||
DoctorUserVo userInfo = healthService.login(email,pwd);
|
||||
return R.ok(userInfo);
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,47 @@
|
|||
package doctor.auth.service;
|
||||
|
||||
import doctor.auth.util.RSAUtils;
|
||||
import doctor.auth.util.RsaKey;
|
||||
import doctor.auth.vo.DoctorUserVo;
|
||||
import doctor.common.core.domain.R;
|
||||
import doctor.common.security.service.TokenService;
|
||||
import doctor.system.api.RemoteDoctorService;
|
||||
import doctor.system.api.model.LoginUser;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
@Component
|
||||
public class HealthService {
|
||||
@Autowired
|
||||
private RemoteDoctorService remoteDoctorService;
|
||||
@Autowired
|
||||
private TokenService tokenService;
|
||||
|
||||
public DoctorUserVo login(String email, String pwd) {
|
||||
DoctorUserVo doctorUserVo = new DoctorUserVo();
|
||||
R<LoginUser> userResult = remoteDoctorService.getDoctorUserInfo(email);
|
||||
LoginUser data = userResult.getData();
|
||||
String s="";
|
||||
try {
|
||||
s = RSAUtils.rsaDecrypt(pwd, RsaKey.PRIVATE_KEY);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
Map<String, Object> token = tokenService.createToken(data);
|
||||
String accessToken = (String) token.get("access_token");
|
||||
doctorUserVo.setSessionId(accessToken);
|
||||
doctorUserVo.setEmail(data.getSysUser().getEmail());
|
||||
doctorUserVo.setUserId(data.getSysUser().getUserId().intValue());
|
||||
doctorUserVo.setUserName(data.getSysUser().getUserName());
|
||||
doctorUserVo.setNickName(data.getSysUser().getNickName());
|
||||
doctorUserVo.setJiGuangPwd(s);
|
||||
if (data.getSysUser().getSex()=="男"){
|
||||
doctorUserVo.setSex(0);
|
||||
}else {
|
||||
doctorUserVo.setSex(1);
|
||||
}
|
||||
return doctorUserVo;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,130 @@
|
|||
package doctor.auth.vo;
|
||||
|
||||
public class DoctorUserVo {
|
||||
private Integer userId;
|
||||
private String sessionId;
|
||||
private String nickName;
|
||||
private String userName;
|
||||
private String jiGuangPwd;
|
||||
private String headPic;
|
||||
private Integer sex;
|
||||
private Integer age;
|
||||
private Integer height;
|
||||
private Integer weight;
|
||||
private String email;
|
||||
private Integer whetherBingWeChat;
|
||||
private String invitationCode;
|
||||
private Integer faceFlag;
|
||||
|
||||
public Integer getUserId() {
|
||||
return userId;
|
||||
}
|
||||
|
||||
public void setUserId(Integer userId) {
|
||||
this.userId = userId;
|
||||
}
|
||||
|
||||
public String getSessionId() {
|
||||
return sessionId;
|
||||
}
|
||||
|
||||
public void setSessionId(String sessionId) {
|
||||
this.sessionId = sessionId;
|
||||
}
|
||||
|
||||
public String getNickName() {
|
||||
return nickName;
|
||||
}
|
||||
|
||||
public void setNickName(String nickName) {
|
||||
this.nickName = nickName;
|
||||
}
|
||||
|
||||
public String getUserName() {
|
||||
return userName;
|
||||
}
|
||||
|
||||
public void setUserName(String userName) {
|
||||
this.userName = userName;
|
||||
}
|
||||
|
||||
public String getJiGuangPwd() {
|
||||
return jiGuangPwd;
|
||||
}
|
||||
|
||||
public void setJiGuangPwd(String jiGuangPwd) {
|
||||
this.jiGuangPwd = jiGuangPwd;
|
||||
}
|
||||
|
||||
public String getHeadPic() {
|
||||
return headPic;
|
||||
}
|
||||
|
||||
public void setHeadPic(String headPic) {
|
||||
this.headPic = headPic;
|
||||
}
|
||||
|
||||
public Integer getSex() {
|
||||
return sex;
|
||||
}
|
||||
|
||||
public void setSex(Integer sex) {
|
||||
this.sex = sex;
|
||||
}
|
||||
|
||||
public Integer getAge() {
|
||||
return age;
|
||||
}
|
||||
|
||||
public void setAge(Integer age) {
|
||||
this.age = age;
|
||||
}
|
||||
|
||||
public Integer getHeight() {
|
||||
return height;
|
||||
}
|
||||
|
||||
public void setHeight(Integer height) {
|
||||
this.height = height;
|
||||
}
|
||||
|
||||
public Integer getWeight() {
|
||||
return weight;
|
||||
}
|
||||
|
||||
public void setWeight(Integer weight) {
|
||||
this.weight = weight;
|
||||
}
|
||||
|
||||
public String getEmail() {
|
||||
return email;
|
||||
}
|
||||
|
||||
public void setEmail(String email) {
|
||||
this.email = email;
|
||||
}
|
||||
|
||||
public Integer getWhetherBingWeChat() {
|
||||
return whetherBingWeChat;
|
||||
}
|
||||
|
||||
public void setWhetherBingWeChat(Integer whetherBingWeChat) {
|
||||
this.whetherBingWeChat = whetherBingWeChat;
|
||||
}
|
||||
|
||||
public String getInvitationCode() {
|
||||
return invitationCode;
|
||||
}
|
||||
|
||||
public void setInvitationCode(String invitationCode) {
|
||||
this.invitationCode = invitationCode;
|
||||
}
|
||||
|
||||
public Integer getFaceFlag() {
|
||||
return faceFlag;
|
||||
}
|
||||
|
||||
public void setFaceFlag(Integer faceFlag) {
|
||||
this.faceFlag = faceFlag;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,40 @@
|
|||
package doctor.controller;
|
||||
|
||||
import com.baomidou.dynamic.datasource.annotation.DS;
|
||||
import doctor.common.core.domain.R;
|
||||
import doctor.domain.entity.DoctorUser;
|
||||
import doctor.service.IDoctorUserService;
|
||||
import doctor.system.api.domain.SysUser;
|
||||
import doctor.system.api.model.LoginUser;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/doctor")
|
||||
@DS("slave")
|
||||
public class SysDoctorController {
|
||||
|
||||
@Autowired
|
||||
private IDoctorUserService iDoctorUserService;
|
||||
|
||||
@PostMapping("/getUser")
|
||||
public R<LoginUser> getUser(String email) {
|
||||
DoctorUser user = iDoctorUserService.getUser(email);
|
||||
LoginUser loginUser = new LoginUser();
|
||||
SysUser sysUser = new SysUser();
|
||||
sysUser.setUserId(Long.valueOf(user.getId()));
|
||||
sysUser.setNickName(user.getNickName());
|
||||
sysUser.setUserName(user.getUserName());
|
||||
sysUser.setPhonenumber(user.getPhone());
|
||||
sysUser.setPassword(user.getPwd());
|
||||
if (user.getSex()==0){
|
||||
sysUser.setSex("男");
|
||||
}else {
|
||||
sysUser.setSex("女");
|
||||
}
|
||||
loginUser.setSysUser(sysUser);
|
||||
return R.ok(loginUser);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,10 @@
|
|||
package doctor.mapper;
|
||||
|
||||
import doctor.domain.entity.DoctorUser;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.mybatis.spring.annotation.MapperScan;
|
||||
|
||||
@MapperScan
|
||||
public interface IDoctorUserMapper {
|
||||
DoctorUser selectDoctorUserByEmail(@Param("email") String email);
|
||||
}
|
|
@ -0,0 +1,8 @@
|
|||
package doctor.service;
|
||||
|
||||
import doctor.domain.entity.DoctorUser;
|
||||
import doctor.system.api.model.LoginUser;
|
||||
|
||||
public interface IDoctorUserService {
|
||||
DoctorUser getUser(String email);
|
||||
}
|
|
@ -0,0 +1,19 @@
|
|||
package doctor.service.impl;
|
||||
|
||||
import doctor.mapper.IDoctorUserMapper;
|
||||
import doctor.domain.entity.DoctorUser;
|
||||
import doctor.service.IDoctorUserService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
public class IDoctorUserServiceImpl implements IDoctorUserService {
|
||||
@Autowired
|
||||
private IDoctorUserMapper iDoctorUserMapper;
|
||||
|
||||
@Override
|
||||
public DoctorUser getUser(String email) {
|
||||
DoctorUser doctorUser = iDoctorUserMapper.selectDoctorUserByEmail(email);
|
||||
return doctorUser;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper
|
||||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="doctor.mapper.IDoctorUserMapper">
|
||||
|
||||
|
||||
<select id="selectDoctorUserByEmail" resultType="doctor.domain.entity.DoctorUser">
|
||||
select * from user where email = #{email}
|
||||
</select>
|
||||
</mapper>
|
Loading…
Reference in New Issue