Commit 0952200b authored by 技术部-任文超's avatar 技术部-任文超

debug:保存用户详细信息只查userId不够用,增加了以下判定:1、与用户信息是否匹配,2、详情信息独立存在则进行关联,不独立存在则返回失败

parent bb6b1aab
......@@ -263,20 +263,37 @@ public class InnerController implements IBaseController {
if (Objects.isNull(info) || !info.isValid()) {
return JsonResult.buildErrorStateResult("身份证号码错误", null);
}
User user = userService.findById(userId);
if(Objects.isNull(user)){
return JsonResult.buildErrorStateResult("用户不存在", null);
}else if(!Objects.equals(user.getPhoneNo(), phoneNo)){
return JsonResult.buildErrorStateResult("用户手机号不匹配", null);
}
Timestamp now = new Timestamp(System.currentTimeMillis());
/*
* 如果已存在记录,则更新
*/
UserDetail userDetail = userDetailService.findByUserId(userId);
Timestamp time = new Timestamp(System.currentTimeMillis());
if (null == userDetail) {
userDetail = new UserDetail();
userDetail.setCreatedAt(time);
if(Objects.isNull(userDetail)){
userDetail = userDetailService.findByPhoneNo(phoneNo);
// 按手机号查出记录,如果userId非空,说明是存疑数据或是其他用户的信息,停止修改操作,返回失败
if(Objects.nonNull(userDetail) && Objects.nonNull(userDetail.getUserId())){
return JsonResult.buildErrorStateResult("手机号已使用.", null);
}
}
if (id != null && id > 0) {
userDetail.setId(id);
if(Objects.isNull(userDetail)){
userDetail = new UserDetail();
userDetail.setCreatedAt(now);
// 这三行本不应出现,因为Service层没有提供按id查询UserDetail的方法,保留是为了兼容未知的旧有更新操作
if (id != null && id > 0) {
userDetail.setId(id);
}
}
userDetail.setUserId(userId);
userDetail.setName(name);
userDetail.setPhoneNo(phoneNo);
userDetail.setIdNo(idNo);
userDetail.setUpdatedAt(time);
userDetail.setUpdatedAt(now);
userDetail.setIdType(IdType.ID_CARD);
userDetail.setGender(info.getGender());
userDetail.setEmail(email);
......
......@@ -86,14 +86,17 @@ public class SyncUserController {
if(Objects.isNull(user)){
return JsonResult.buildErrorStateResult(null, null);
}
userDetail.setId(null);
userDetail.setUserId(user.getId());
/*
* 如果已存在记录,则更新
*/
UserDetail theUserDetail = userDetailService.findByPhoneNo(phoneNo);
UserDetail theUserDetail = userDetailService.findByUserId(user.getId());
if(Objects.isNull(theUserDetail)){
theUserDetail = userDetailService.findByUserId(user.getId());
theUserDetail = userDetailService.findByPhoneNo(phoneNo);
// 按手机号查出记录,如果userId非空,说明是存疑数据或是其他用户的信息,停止修改操作,返回失败
if(Objects.nonNull(theUserDetail) && Objects.nonNull(theUserDetail.getUserId())){
return JsonResult.buildErrorStateResult("手机号已使用.", null);
}
}
if(Objects.isNull(theUserDetail)){
userDetail.setId(null);
......
......@@ -20,6 +20,7 @@ import org.springframework.web.bind.annotation.RestController;
import java.sql.Timestamp;
import java.text.ParseException;
import java.util.Objects;
/**
* Created by Miraculous on 2017/1/3.
......@@ -53,8 +54,18 @@ public class UserDetailController implements IBaseController {
return JsonResult.buildErrorStateResult("系统错误", null);
}
Timestamp now = new Timestamp(System.currentTimeMillis());
/*
* 如果已存在记录,则更新
*/
UserDetail userDetail = userDetailService.findByUserId(user.getId());
if (null == userDetail) {
if(Objects.isNull(userDetail)){
userDetail = userDetailService.findByPhoneNo(user.getPhoneNo());
// 按手机号查出记录,如果userId非空,说明是存疑数据或是其他用户的信息,停止修改操作,返回失败
if(Objects.nonNull(userDetail) && Objects.nonNull(userDetail.getUserId())){
return JsonResult.buildErrorStateResult("手机号已使用.", null);
}
}
if(Objects.isNull(userDetail)){
userDetail = new UserDetail();
userDetail.setCreatedAt(now);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment