diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysLoginController.java b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysLoginController.java index 3aa2ee9..7f9f138 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysLoginController.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysLoginController.java @@ -2,7 +2,11 @@ package com.ruoyi.web.controller.system; import java.util.List; 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.validation.annotation.Validated; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; @@ -51,12 +55,16 @@ public class SysLoginController return ajax; } + @ApiOperation("app医生登录") @PostMapping("/login/app") public AjaxResult loginForApp(@RequestBody LoginBody loginBody) { - AjaxResult ajax = AjaxResult.success(); - String token = loginService.loginForApp(loginBody.getUsername(), loginBody.getPassword()); - ajax.put(Constants.TOKEN, token); - return ajax; + return loginService.loginForApp(loginBody.getUsername(), loginBody.getPassword()); + } + + @ApiOperation("app医生完善信息") + @PostMapping("/login/app/fill/info") + public AjaxResult fillInfoForDoctor(@RequestBody @Validated AppRegisterReq req) { + return loginService.loginForAppFillInfo(req); } /** diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysRegisterController.java b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysRegisterController.java index 5af8fa3..6a18a21 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysRegisterController.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysRegisterController.java @@ -37,10 +37,4 @@ public class SysRegisterController extends BaseController String msg = registerService.register(user); return StringUtils.isEmpty(msg) ? success() : error(msg); } - - @PostMapping("/register/app") - public AjaxResult registerForApp(@RequestBody @Validated AppRegisterReq req) { - registerService.registerForApp(req); - return AjaxResult.success(); - } } diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/constant/Constants.java b/ruoyi-common/src/main/java/com/ruoyi/common/constant/Constants.java index 5752c60..ef8db66 100644 --- a/ruoyi-common/src/main/java/com/ruoyi/common/constant/Constants.java +++ b/ruoyi-common/src/main/java/com/ruoyi/common/constant/Constants.java @@ -89,6 +89,8 @@ public class Constants */ public static final String TOKEN = "token"; + public static final String REQUEST_FROM = "requestFrom"; + /** * 令牌前缀 */ diff --git a/ruoyi-framework/src/main/java/com/ruoyi/framework/config/SecurityConfig.java b/ruoyi-framework/src/main/java/com/ruoyi/framework/config/SecurityConfig.java index 2159462..942c32c 100644 --- a/ruoyi-framework/src/main/java/com/ruoyi/framework/config/SecurityConfig.java +++ b/ruoyi-framework/src/main/java/com/ruoyi/framework/config/SecurityConfig.java @@ -97,7 +97,7 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter // 过滤请求 .authorizeRequests() // 对于登录login 注册register 验证码captchaImage 允许匿名访问 - .antMatchers("/login", "/login/app", "/register", "/register/app", "/captchaImage").anonymous() + .antMatchers("/login", "/login/app","/login/app/fill/info","/register", "/captchaImage").anonymous() .antMatchers( HttpMethod.GET, "/", diff --git a/ruoyi-framework/src/main/java/com/ruoyi/framework/web/service/SysLoginService.java b/ruoyi-framework/src/main/java/com/ruoyi/framework/web/service/SysLoginService.java index 7bcd82a..bde8e44 100644 --- a/ruoyi-framework/src/main/java/com/ruoyi/framework/web/service/SysLoginService.java +++ b/ruoyi-framework/src/main/java/com/ruoyi/framework/web/service/SysLoginService.java @@ -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("登录失败!"); } diff --git a/ruoyi-framework/src/main/java/com/ruoyi/framework/web/service/SysRegisterService.java b/ruoyi-framework/src/main/java/com/ruoyi/framework/web/service/SysRegisterService.java index 16a0e48..4b5f50b 100644 --- a/ruoyi-framework/src/main/java/com/ruoyi/framework/web/service/SysRegisterService.java +++ b/ruoyi-framework/src/main/java/com/ruoyi/framework/web/service/SysRegisterService.java @@ -123,62 +123,4 @@ public class SysRegisterService 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); - } - } } diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/domain/req/AppRegisterReq.java b/ruoyi-system/src/main/java/com/ruoyi/system/domain/req/AppRegisterReq.java index b8d8a03..80ef715 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/domain/req/AppRegisterReq.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/domain/req/AppRegisterReq.java @@ -18,9 +18,6 @@ public class AppRegisterReq implements Serializable { @NotBlank private String phone; - @NotBlank - private String password; - @NotNull private Long hospitalId; @@ -51,14 +48,6 @@ public class AppRegisterReq implements Serializable { this.phone = phone; } - public String getPassword() { - return password; - } - - public void setPassword(String password) { - this.password = password; - } - public Long getHospitalId() { return hospitalId; }