政策相关配置文件
This commit is contained in:
@@ -236,4 +236,26 @@ public class SysLoginController
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 登录注册二合一接口
|
||||||
|
* 根据手机号查询用户,存在则登录,不存在则注册后登录
|
||||||
|
* @param loginBody 包含姓名(必填)、电话(必填,放在username字段)、身份证(非必填)
|
||||||
|
* @return 结果
|
||||||
|
*/
|
||||||
|
@ApiOperation("登录注册二合一")
|
||||||
|
@PostMapping("/app/loginOrRegister")
|
||||||
|
public AjaxResult loginOrRegister(@RequestBody LoginBody loginBody)
|
||||||
|
{
|
||||||
|
if (loginBody == null) {
|
||||||
|
return AjaxResult.error("登录参数不能为空!");
|
||||||
|
}
|
||||||
|
if (StringUtils.isBlank(loginBody.getUsername())) {
|
||||||
|
return AjaxResult.error("电话号码不能为空!");
|
||||||
|
}
|
||||||
|
if (StringUtils.isBlank(loginBody.getName())) {
|
||||||
|
return AjaxResult.error("姓名不能为空!");
|
||||||
|
}
|
||||||
|
return loginService.loginOrRegister(loginBody);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -44,6 +44,11 @@ public class LoginBody
|
|||||||
*/
|
*/
|
||||||
private String idCard;
|
private String idCard;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 姓名
|
||||||
|
*/
|
||||||
|
private String name;
|
||||||
|
|
||||||
public String getUsername()
|
public String getUsername()
|
||||||
{
|
{
|
||||||
return username;
|
return username;
|
||||||
@@ -115,4 +120,12 @@ public class LoginBody
|
|||||||
public void setIdCard(String idCard) {
|
public void setIdCard(String idCard) {
|
||||||
this.idCard = idCard;
|
this.idCard = idCard;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setName(String name) {
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -745,4 +745,59 @@ public class SysLoginService
|
|||||||
ajax.put("isCompanyUser",appUser.getIsCompanyUser());
|
ajax.put("isCompanyUser",appUser.getIsCompanyUser());
|
||||||
return ajax;
|
return ajax;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 登录注册二合一接口
|
||||||
|
* 根据手机号查询用户,存在则登录,不存在则注册后登录
|
||||||
|
* @param loginBody 包含姓名(必填)、电话(必填)、身份证(非必填)
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
|
public AjaxResult loginOrRegister(LoginBody loginBody) {
|
||||||
|
String phone = loginBody.getUsername();
|
||||||
|
String name = loginBody.getName();
|
||||||
|
String idCard = loginBody.getIdCard();
|
||||||
|
|
||||||
|
// 根据手机号查询用户
|
||||||
|
AppUser appUser = appUserService.getPhone(phone);
|
||||||
|
boolean isNewUser = false;
|
||||||
|
|
||||||
|
if (appUser == null) {
|
||||||
|
// 用户不存在,执行注册
|
||||||
|
appUser = new AppUser();
|
||||||
|
appUser.setPhone(phone);
|
||||||
|
appUser.setName(name);
|
||||||
|
appUser.setIdCard(idCard);
|
||||||
|
appUser.setLoginDate(new Date());
|
||||||
|
appUserService.insertAppUser(appUser);
|
||||||
|
isNewUser = true;
|
||||||
|
} else {
|
||||||
|
// 用户存在,更新信息(如果传入了新值)
|
||||||
|
AppUser updateParam = new AppUser();
|
||||||
|
updateParam.setUserId(appUser.getUserId());
|
||||||
|
boolean needUpdate = false;
|
||||||
|
if (StringUtils.isNotBlank(name) && !name.equals(appUser.getName())) {
|
||||||
|
updateParam.setName(name);
|
||||||
|
appUser.setName(name);
|
||||||
|
needUpdate = true;
|
||||||
|
}
|
||||||
|
if (StringUtils.isNotBlank(idCard) && !idCard.equals(appUser.getIdCard())) {
|
||||||
|
updateParam.setIdCard(idCard);
|
||||||
|
appUser.setIdCard(idCard);
|
||||||
|
needUpdate = true;
|
||||||
|
}
|
||||||
|
updateParam.setLoginDate(new Date());
|
||||||
|
if (needUpdate) {
|
||||||
|
appUserService.updateAppUser(updateParam);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 生成token并返回
|
||||||
|
String token = loginUserIdApp(appUser);
|
||||||
|
AjaxResult ajax = AjaxResult.success();
|
||||||
|
ajax.put(Constants.TOKEN, token);
|
||||||
|
ajax.put("isNewUser", isNewUser);
|
||||||
|
ajax.put("idCard", appUser.getIdCard());
|
||||||
|
return ajax;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user