医生账号登录接口

master
heminjian502 2 years ago
parent 773421b462
commit c007e3a740

@ -2,7 +2,11 @@ package com.ruoyi.web.controller.system;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
import com.ruoyi.system.domain.req.AppRegisterReq;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestBody;
@ -51,12 +55,16 @@ public class SysLoginController
return ajax; return ajax;
} }
@ApiOperation("app医生登录")
@PostMapping("/login/app") @PostMapping("/login/app")
public AjaxResult loginForApp(@RequestBody LoginBody loginBody) { public AjaxResult loginForApp(@RequestBody LoginBody loginBody) {
AjaxResult ajax = AjaxResult.success(); return loginService.loginForApp(loginBody.getUsername(), loginBody.getPassword());
String token = loginService.loginForApp(loginBody.getUsername(), loginBody.getPassword()); }
ajax.put(Constants.TOKEN, token);
return ajax; @ApiOperation("app医生完善信息")
@PostMapping("/login/app/fill/info")
public AjaxResult fillInfoForDoctor(@RequestBody @Validated AppRegisterReq req) {
return loginService.loginForAppFillInfo(req);
} }
/** /**

@ -37,10 +37,4 @@ public class SysRegisterController extends BaseController
String msg = registerService.register(user); String msg = registerService.register(user);
return StringUtils.isEmpty(msg) ? success() : error(msg); return StringUtils.isEmpty(msg) ? success() : error(msg);
} }
@PostMapping("/register/app")
public AjaxResult registerForApp(@RequestBody @Validated AppRegisterReq req) {
registerService.registerForApp(req);
return AjaxResult.success();
}
} }

@ -89,6 +89,8 @@ public class Constants
*/ */
public static final String TOKEN = "token"; public static final String TOKEN = "token";
public static final String REQUEST_FROM = "requestFrom";
/** /**
* *
*/ */

@ -97,7 +97,7 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter
// 过滤请求 // 过滤请求
.authorizeRequests() .authorizeRequests()
// 对于登录login 注册register 验证码captchaImage 允许匿名访问 // 对于登录login 注册register 验证码captchaImage 允许匿名访问
.antMatchers("/login", "/login/app", "/register", "/register/app", "/captchaImage").anonymous() .antMatchers("/login", "/login/app","/login/app/fill/info","/register", "/captchaImage").anonymous()
.antMatchers( .antMatchers(
HttpMethod.GET, HttpMethod.GET,
"/", "/",

@ -2,9 +2,11 @@ package com.ruoyi.framework.web.service;
import javax.annotation.Resource; import javax.annotation.Resource;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.UserStatus; import com.ruoyi.common.enums.UserStatus;
import com.ruoyi.common.utils.*; import com.ruoyi.common.utils.*;
import com.ruoyi.system.domain.TDoctor; import com.ruoyi.system.domain.TDoctor;
import com.ruoyi.system.domain.req.AppRegisterReq;
import com.ruoyi.system.mapper.TDoctorMapper; import com.ruoyi.system.mapper.TDoctorMapper;
import com.ruoyi.system.service.impl.UserTokenService; import com.ruoyi.system.service.impl.UserTokenService;
import org.slf4j.Logger; import org.slf4j.Logger;
@ -29,6 +31,8 @@ import com.ruoyi.framework.manager.factory.AsyncFactory;
import com.ruoyi.system.service.ISysConfigService; import com.ruoyi.system.service.ISysConfigService;
import com.ruoyi.system.service.ISysUserService; import com.ruoyi.system.service.ISysUserService;
import java.util.Date;
import java.util.Map;
import java.util.Objects; import java.util.Objects;
/** /**
@ -106,10 +110,90 @@ public class SysLoginService
return tokenService.createToken(loginUser); return tokenService.createToken(loginUser);
} }
public String loginForApp(String username, String password) { public AjaxResult loginForApp(String username, String password) {
SysUser sysUser = checkLoginUser(username, password); AjaxResult ajax = AjaxResult.success();
String token = buildTokenByDoctor(sysUser); // 查询用户是否注册过 或者注册过已被删除
return token; TDoctor tDoctor = tDoctorMapper.selectTDoctorByPhone(username);
if (Objects.isNull(tDoctor) || "2".equals(tDoctor.getDelFlag())) {
// 未注册或已删除 返回flag app跳完善信息页面
ajax.put("flag", false);
} else {
SysUser sysUser = userService.selectUserByUserName(username);
LoginUser loginUser = new LoginUser();
loginUser.setUserId(sysUser.getUserId());
loginUser.setUser(sysUser);
String token = userTokenService.createToken(loginUser);
AsyncManager.me().execute(AsyncFactory.recordLogininfor(sysUser.getUserName(), Constants.LOGIN_SUCCESS, MessageUtils.message("user.login.success")));
recordLoginInfo(sysUser.getUserId());
ajax.put(Constants.TOKEN, token);
ajax.put("flag", true);
}
ajax.put(Constants.REQUEST_FROM, "app");
return ajax;
}
public AjaxResult loginForAppFillInfo(AppRegisterReq req) {
// 查询sys_user数据
SysUser sysUser = userService.selectUserByPhone(req.getPhone());
if (Objects.nonNull(sysUser)) {
if ("2".equals(sysUser.getDelFlag())) {
// 医生账号被删除 重新注册
sysUser.setDelFlag("0");
sysUser.setPassword(SecurityUtils.encryptPassword("123456"));
sysUser.setUserName(req.getPhone());
sysUser.setNickName(req.getName());
sysUser.setStatus("0");
userService.updateUser(sysUser);
}
} else {
// 注册
sysUser = new SysUser();
sysUser.setPhonenumber(req.getPhone());
sysUser.setUserName(req.getPhone());
sysUser.setNickName(req.getName());
sysUser.setStatus("0");
sysUser.setDelFlag("0");
sysUser.setPassword(SecurityUtils.encryptPassword("123456"));
Long[] roles = new Long[]{3L};
sysUser.setRoleIds(roles);
userService.insertUser(sysUser);
}
// 查询医生表数据
TDoctor tDoctor = tDoctorMapper.selectTDoctorByPhone(req.getPhone());
if (Objects.nonNull(tDoctor)) {
if ("2".equals(tDoctor.getDelFlag())) {
// 重新注册
tDoctor.setDelFlag("0");
tDoctor.setUpdateTime(new Date());
tDoctor.setHospitalId(req.getHospitalId());
tDoctor.setName(req.getName());
tDoctor.setSpeciality(req.getSpeciality());
tDoctor.setMedicalLicense(req.getMedicalLicense());
tDoctor.setUserId(sysUser.getUserId());
tDoctorMapper.updateTDoctor(tDoctor);
}
} else {
// 注册
tDoctor = new TDoctor();
tDoctor.setDelFlag("0");
tDoctor.setPhone(req.getPhone());
tDoctor.setUpdateTime(new Date());
tDoctor.setCreateTime(new Date());
tDoctor.setHospitalId(req.getHospitalId());
tDoctor.setName(req.getName());
tDoctor.setSpeciality(req.getSpeciality());
tDoctor.setMedicalLicense(req.getMedicalLicense());
tDoctor.setUserId(sysUser.getUserId());
tDoctorMapper.insertTDoctor(tDoctor);
}
LoginUser loginUser = new LoginUser();
loginUser.setUserId(sysUser.getUserId());
loginUser.setUser(sysUser);
String token = userTokenService.createToken(loginUser);
AsyncManager.me().execute(AsyncFactory.recordLogininfor(sysUser.getUserName(), Constants.LOGIN_SUCCESS, MessageUtils.message("user.login.success")));
AjaxResult ajaxResult = AjaxResult.success();
ajaxResult.put(Constants.TOKEN, token);
return ajaxResult;
} }
private String buildTokenByDoctor(SysUser sysUser) { private String buildTokenByDoctor(SysUser sysUser) {
@ -122,6 +206,7 @@ public class SysLoginService
loginUser.setUserId(sysUser.getUserId()); loginUser.setUserId(sysUser.getUserId());
loginUser.setUser(sysUser); loginUser.setUser(sysUser);
String token = userTokenService.createToken(loginUser); String token = userTokenService.createToken(loginUser);
AsyncManager.me().execute(AsyncFactory.recordLogininfor(sysUser.getUserName(), Constants.LOGIN_SUCCESS, MessageUtils.message("user.login.success")));
return token; return token;
} }
@ -141,7 +226,7 @@ public class SysLoginService
{ {
log.info("登录用户:{} 已被停用.", username); log.info("登录用户:{} 已被停用.", username);
throw new ServiceException("对不起,您的账号:" + username + " 已停用"); throw new ServiceException("对不起,您的账号:" + username + " 已停用");
} else if (!SecurityUtils.matchesPassword(user.getPassword(), password)) { } else if (!SecurityUtils.matchesPassword(password, user.getPassword())) {
log.info("登录用户:{} 密码不正确.", username); log.info("登录用户:{} 密码不正确.", username);
throw new ServiceException("登录失败!"); throw new ServiceException("登录失败!");
} }

@ -123,62 +123,4 @@ public class SysRegisterService
throw new CaptchaException(); throw new CaptchaException();
} }
} }
public void registerForApp(AppRegisterReq req) {
// 查询sys_user数据
SysUser sysUser = userService.selectUserByPhone(req.getPhone());
if (Objects.nonNull(sysUser)) {
if ("2".equals(sysUser.getDelFlag())) {
// 医生账号被删除 重新注册
sysUser.setDelFlag("0");
sysUser.setPassword(SecurityUtils.encryptPassword(req.getPassword()));
sysUser.setUserName(req.getPhone());
sysUser.setNickName(req.getName());
sysUser.setStatus("0");
userService.updateUser(sysUser);
} else {
throw new ServiceException("该手机号已注册。");
}
} else {
// 注册
sysUser = new SysUser();
sysUser.setPhonenumber(req.getPhone());
sysUser.setUserName(req.getPhone());
sysUser.setNickName(req.getName());
sysUser.setStatus("0");
sysUser.setDelFlag("0");
sysUser.setPassword(SecurityUtils.encryptPassword(req.getPassword()));
userService.insertUser(sysUser);
}
// 查询医生表数据
TDoctor tDoctor = tDoctorMapper.selectTDoctorByPhone(req.getPhone());
if (Objects.nonNull(tDoctor)) {
if ("2".equals(tDoctor.getDelFlag())) {
// 重新注册
tDoctor.setDelFlag("0");
tDoctor.setUpdateTime(new Date());
tDoctor.setHospitalId(req.getHospitalId());
tDoctor.setName(req.getName());
tDoctor.setSpeciality(req.getSpeciality());
tDoctor.setMedicalLicense(req.getMedicalLicense());
tDoctor.setUserId(sysUser.getUserId());
tDoctorMapper.updateTDoctor(tDoctor);
} else {
throw new ServiceException("该手机号已注册。");
}
} else {
// 注册
tDoctor = new TDoctor();
tDoctor.setDelFlag("0");
tDoctor.setPhone(req.getPhone());
tDoctor.setUpdateTime(new Date());
tDoctor.setCreateTime(new Date());
tDoctor.setHospitalId(req.getHospitalId());
tDoctor.setName(req.getName());
tDoctor.setSpeciality(req.getSpeciality());
tDoctor.setMedicalLicense(req.getMedicalLicense());
tDoctor.setUserId(sysUser.getUserId());
tDoctorMapper.insertTDoctor(tDoctor);
}
}
} }

@ -18,9 +18,6 @@ public class AppRegisterReq implements Serializable {
@NotBlank @NotBlank
private String phone; private String phone;
@NotBlank
private String password;
@NotNull @NotNull
private Long hospitalId; private Long hospitalId;
@ -51,14 +48,6 @@ public class AppRegisterReq implements Serializable {
this.phone = phone; this.phone = phone;
} }
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public Long getHospitalId() { public Long getHospitalId() {
return hospitalId; return hospitalId;
} }

Loading…
Cancel
Save