|
|
|
@ -2,9 +2,11 @@ package com.ruoyi.framework.web.service;
|
|
|
|
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
|
|
|
|
|
|
|
import com.ruoyi.common.core.domain.AjaxResult;
|
|
|
|
|
import com.ruoyi.common.enums.UserStatus;
|
|
|
|
|
import com.ruoyi.common.utils.*;
|
|
|
|
|
import com.ruoyi.system.domain.TDoctor;
|
|
|
|
|
import com.ruoyi.system.domain.req.AppRegisterReq;
|
|
|
|
|
import com.ruoyi.system.mapper.TDoctorMapper;
|
|
|
|
|
import com.ruoyi.system.service.impl.UserTokenService;
|
|
|
|
|
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.ISysUserService;
|
|
|
|
|
|
|
|
|
|
import java.util.Date;
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
import java.util.Objects;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
@ -106,10 +110,90 @@ public class SysLoginService
|
|
|
|
|
return tokenService.createToken(loginUser);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public String loginForApp(String username, String password) {
|
|
|
|
|
SysUser sysUser = checkLoginUser(username, password);
|
|
|
|
|
String token = buildTokenByDoctor(sysUser);
|
|
|
|
|
return token;
|
|
|
|
|
public AjaxResult loginForApp(String username, String password) {
|
|
|
|
|
AjaxResult ajax = AjaxResult.success();
|
|
|
|
|
// 查询用户是否注册过 或者注册过已被删除
|
|
|
|
|
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) {
|
|
|
|
@ -122,6 +206,7 @@ public class SysLoginService
|
|
|
|
|
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")));
|
|
|
|
|
return token;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -141,7 +226,7 @@ public class SysLoginService
|
|
|
|
|
{
|
|
|
|
|
log.info("登录用户:{} 已被停用.", username);
|
|
|
|
|
throw new ServiceException("对不起,您的账号:" + username + " 已停用");
|
|
|
|
|
} else if (!SecurityUtils.matchesPassword(user.getPassword(), password)) {
|
|
|
|
|
} else if (!SecurityUtils.matchesPassword(password, user.getPassword())) {
|
|
|
|
|
log.info("登录用户:{} 密码不正确.", username);
|
|
|
|
|
throw new ServiceException("登录失败!");
|
|
|
|
|
}
|
|
|
|
|