Commit 86bb1bac authored by minminyan's avatar minminyan

给用户添加婚姻状态

parent 82bc0332
...@@ -374,25 +374,27 @@ public class InnerController { ...@@ -374,25 +374,27 @@ public class InnerController {
} }
@RequestMapping("/user/spouse/save") @RequestMapping("/user/spouse/save")
public JsonResult saveSpouse(Long userId, String spousePhone, String spouseName) { public JsonResult saveSpouse(Long userId, MaritalStatus status, String spousePhone, String spouseName) {
if (userId == null || userId == 0) { if (userId == null || userId == 0) {
return JsonResult.buildErrorStateResult("用户不能为空", null); return JsonResult.buildErrorStateResult("用户不能为空", null);
} }
if (status == MaritalStatus.MARRIED) {
if (!ValidationUtil.validatePhoneNo(spousePhone)) { if (!ValidationUtil.validatePhoneNo(spousePhone)) {
return JsonResult.buildErrorStateResult("手机号格式错误", null); return JsonResult.buildErrorStateResult("手机号格式错误", null);
} }
if (StringUtils.isBlank(spouseName)) { if (StringUtils.isBlank(spouseName)) {
return JsonResult.buildErrorStateResult("配偶姓名不能为空", null); return JsonResult.buildErrorStateResult("配偶姓名不能为空", null);
} }
}
UserSpouse userSpouse = userSpouseService.findByUserId(userId); UserSpouse userSpouse = userSpouseService.findByUserId(userId);
Timestamp timestamp = new Timestamp(System.currentTimeMillis()); Timestamp timestamp = new Timestamp(System.currentTimeMillis());
if (userSpouse == null) { if (userSpouse == null) {
userSpouse = new UserSpouse(); userSpouse = new UserSpouse(userId);
}
userSpouse.setSpouseName(spouseName);
userSpouse.setSpousePhone(spousePhone);
userSpouse.setUserId(userId);
userSpouse.setCreatedAt(timestamp); userSpouse.setCreatedAt(timestamp);
}
userSpouse.setSpouseName(status == MaritalStatus.MARRIED ? spouseName : "");
userSpouse.setSpousePhone(status == MaritalStatus.MARRIED ? spousePhone : "");
userSpouse.setStatus(status);
userSpouse.setUpdateAt(timestamp); userSpouse.setUpdateAt(timestamp);
userSpouse = userSpouseService.save(userSpouse); userSpouse = userSpouseService.save(userSpouse);
return JsonResult.buildSuccessResult(null, UserSpouseRet.getUserSpouseRet(userSpouse)); return JsonResult.buildSuccessResult(null, UserSpouseRet.getUserSpouseRet(userSpouse));
...@@ -404,6 +406,10 @@ public class InnerController { ...@@ -404,6 +406,10 @@ public class InnerController {
return JsonResult.buildErrorStateResult("用户不能为空", null); return JsonResult.buildErrorStateResult("用户不能为空", null);
} }
UserSpouse userSpouse = userSpouseService.findByUserId(userId); UserSpouse userSpouse = userSpouseService.findByUserId(userId);
if (userSpouse == null) {
userSpouse = new UserSpouse(userId);
userSpouse.setStatus(MaritalStatus.UNKNOWN);
}
return JsonResult.buildSuccessResult(null, UserSpouseRet.getUserSpouseRet(userSpouse)); return JsonResult.buildSuccessResult(null, UserSpouseRet.getUserSpouseRet(userSpouse));
} }
......
package cn.quantgroup.xyqb.entity; package cn.quantgroup.xyqb.entity;
import lombok.Data; import cn.quantgroup.xyqb.entity.enumerate.MaritalStatus;
import lombok.Getter; import lombok.*;
import lombok.Setter;
import lombok.ToString;
import javax.persistence.*; import javax.persistence.*;
import java.io.Serializable; import java.io.Serializable;
...@@ -16,6 +14,7 @@ import java.sql.Timestamp; ...@@ -16,6 +14,7 @@ import java.sql.Timestamp;
@Getter @Getter
@Setter @Setter
@ToString @ToString
@NoArgsConstructor
public class UserSpouse implements Serializable { public class UserSpouse implements Serializable {
private static final long serialVersionUID = -1L; private static final long serialVersionUID = -1L;
...@@ -38,4 +37,11 @@ public class UserSpouse implements Serializable { ...@@ -38,4 +37,11 @@ public class UserSpouse implements Serializable {
@Column(name = "updated_at") @Column(name = "updated_at")
private Timestamp updateAt; private Timestamp updateAt;
@Column(name = "status")
private MaritalStatus status;
public UserSpouse(Long userId) {
this.userId = userId;
}
} }
package cn.quantgroup.xyqb.model; package cn.quantgroup.xyqb.model;
import cn.quantgroup.xyqb.entity.UserExtInfo;
import cn.quantgroup.xyqb.entity.UserSpouse; import cn.quantgroup.xyqb.entity.UserSpouse;
import cn.quantgroup.xyqb.entity.enumerate.MaritalStatus;
import lombok.Data; import lombok.Data;
import javax.persistence.Column;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import java.sql.Timestamp;
/** /**
* Created by 11 on 2017/4/19. * Created by 11 on 2017/4/19.
*/ */
@Data @Data
public class UserSpouseRet { public class UserSpouseRet {
private Long id;
private Long userId; private Long userId;
...@@ -27,6 +20,8 @@ public class UserSpouseRet { ...@@ -27,6 +20,8 @@ public class UserSpouseRet {
private Long updateAt; private Long updateAt;
private MaritalStatus status;
public static UserSpouseRet getUserSpouseRet(UserSpouse userSpouse) { public static UserSpouseRet getUserSpouseRet(UserSpouse userSpouse) {
if (userSpouse == null) { if (userSpouse == null) {
return null; return null;
...@@ -35,10 +30,13 @@ public class UserSpouseRet { ...@@ -35,10 +30,13 @@ public class UserSpouseRet {
ret.setUserId(userSpouse.getUserId()); ret.setUserId(userSpouse.getUserId());
ret.setSpouseName(userSpouse.getSpouseName()); ret.setSpouseName(userSpouse.getSpouseName());
ret.setSpousePhone(userSpouse.getSpousePhone()); ret.setSpousePhone(userSpouse.getSpousePhone());
if (userSpouse.getUpdateAt() != null) {
ret.setUpdateAt(userSpouse.getUpdateAt().getTime()); ret.setUpdateAt(userSpouse.getUpdateAt().getTime());
}
if (userSpouse.getCreatedAt() != null) {
ret.setCreatedAt(userSpouse.getCreatedAt().getTime()); ret.setCreatedAt(userSpouse.getCreatedAt().getTime());
ret.setId(userSpouse.getId()); }
ret.setId(userSpouse.getId()); ret.setStatus(userSpouse.getStatus());
return ret; return ret;
} }
} }
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