记得上下班打卡 | git大法好,push需谨慎

Commit deba8015 authored by zhengfuxin's avatar zhengfuxin

修改验证。

parent f95fa375
......@@ -6,6 +6,9 @@ import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.Past;
import javax.validation.constraints.Positive;
import java.io.Serializable;
import java.time.LocalDate;
import java.time.LocalDateTime;
......@@ -21,6 +24,9 @@ import java.time.LocalDateTime;
@ApiModel(value = "smileUser", description = "smile的user")
@Data
public class SmileUserVO implements Serializable {
public interface saveOne{}
public interface saveTwo{}
public interface saveThree{}
private static final long serialVersionUID = 1L;
......@@ -32,12 +38,14 @@ public class SmileUserVO implements Serializable {
* 照片
*/
@ApiModelProperty(value = "照片")
@NotBlank(groups = {saveOne.class},message = "照片必传")
private String img;
/**
* 真实姓名
*/
@ApiModelProperty(value = "真实姓名")
@NotBlank(groups = {saveOne.class},message = "真实姓名必传")
private String name;
/**
......@@ -45,66 +53,77 @@ public class SmileUserVO implements Serializable {
*/
@ApiModelProperty(value = "生日(yyyy-MM-dd)")
@JsonFormat(shape=JsonFormat.Shape.STRING, pattern= DateUtil.DATE_SMALL_STR)
@Past(groups = {saveOne.class},message = "生日必传")
private LocalDate birthday;
/**
* 性别(1:男(默认),2:女)
*/
@ApiModelProperty(value = "性别(1:男(默认),2:女)")
@Positive(groups = {saveOne.class},message = "性别必传")
private Integer sex;
/**
* 手机号
*/
@ApiModelProperty(value = "手机号")
@NotBlank(groups = {saveOne.class},message = "手机必传")
private String phone;
/**
* 省key
*/
@ApiModelProperty(value = "省key")
@NotBlank(groups = {saveOne.class},message = "省必传")
private String provinceId;
/**
* 省
*/
@ApiModelProperty(value = "省")
@NotBlank(groups = {saveOne.class},message = "省必传")
private String province;
/**
* 市key
*/
@ApiModelProperty(value = "市key")
@NotBlank(groups = {saveOne.class},message = "市必传")
private String cityId;
/**
* 市
*/
@ApiModelProperty(value = "市")
@NotBlank(groups = {saveOne.class},message = "市必传")
private String city;
/**
* 区key
*/
@ApiModelProperty(value = "区key")
@NotBlank(groups = {saveOne.class},message = "区必传")
private String areaId;
/**
* 区
*/
@ApiModelProperty(value = "区")
@NotBlank(groups = {saveOne.class},message = "区必传")
private String area;
/**
* 详细地址
*/
@ApiModelProperty(value = "详细地址")
@NotBlank(groups = {saveOne.class},message = "详细地址必传")
private String address;
/**
* 微信号
*/
@ApiModelProperty(value = "微信号")
@NotBlank(groups = {saveOne.class},message = "微信号必传")
private String wechat;
/**
......@@ -123,24 +142,28 @@ public class SmileUserVO implements Serializable {
* 身份证号
*/
@ApiModelProperty(value = "身份证号")
@NotBlank(groups = {saveTwo.class},message = "身份证号必传")
private String idCard;
/**
* 学校名称
*/
@ApiModelProperty(value = "学校名称")
@NotBlank(groups = {saveOne.class},message = "学校名称必传")
private String schoolName;
/**
* 专业
*/
@ApiModelProperty(value = "专业")
@NotBlank(groups = {saveOne.class},message = "专业必传")
private String schoolMajor;
/**
* 身份(1:在校学生(默认),2已毕业)
*/
@ApiModelProperty(value = "身份(1:在校学生(默认),2已毕业)")
@Positive(groups = {saveOne.class},message = "身份必传")
private Integer identity;
/**
......@@ -159,6 +182,7 @@ public class SmileUserVO implements Serializable {
* 自我介绍
*/
@ApiModelProperty(value = "自我介绍")
@NotBlank(groups = {saveThree.class},message = "自我介绍必传")
private String introduce;
/**
......
......@@ -17,6 +17,10 @@ import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.validation.BindingResult;
import org.springframework.validation.ObjectError;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.MethodArgumentNotValidException;
import org.springframework.web.bind.annotation.*;
import java.util.List;
......@@ -94,7 +98,14 @@ public class SmileUserController {
//
@PostMapping("saveOrUpdateUserOneStep")
@ApiOperation("增加或者删除第一步")
public ResponseDto saveOrUpdateUserOneStep(@RequestBody SmileUserVO smileUserVO) {
public ResponseDto saveOrUpdateUserOneStep(@Validated(SmileUserVO.saveOne.class) @RequestBody SmileUserVO smileUserVO, MethodArgumentNotValidException exception) {
BindingResult result = exception.getBindingResult();
if (result.hasErrors()) {
List<ObjectError> errors = result.getAllErrors();
if (errors != null) {
return ResponseDto.failure(errors.get(0).getDefaultMessage());
}
}
String userId = CurrentUtil.getCurrentUid();
SmileUserVO smileUserVORedis= (SmileUserVO) redisUtil.get(SmileRedisConst.SMILE_USER.concat(userId));
smileUserVO.setUid(userId);
......@@ -109,7 +120,14 @@ public class SmileUserController {
@PostMapping("saveOrUpdateUserTwoStep")
@ApiOperation("增加或者删除第二步")
public ResponseDto saveOrUpdateUserTwoStep(@RequestBody SmileUserVO smileUserVO) {
public ResponseDto saveOrUpdateUserTwoStep(@Validated(SmileUserVO.saveTwo.class)@RequestBody SmileUserVO smileUserVO, MethodArgumentNotValidException exception) {
BindingResult result = exception.getBindingResult();
if (result.hasErrors()) {
List<ObjectError> errors = result.getAllErrors();
if (errors != null) {
return ResponseDto.failure(errors.get(0).getDefaultMessage());
}
}
if(StringUtil.isNotBlank(smileUserVO.getIdCard())&&StringUtil.isNotBlank(smileUserVO.getName())){
String userId = CurrentUtil.getCurrentUid();
if(validate(smileUserVO.getName(),smileUserVO.getIdCard(),userId)){
......@@ -152,7 +170,14 @@ public class SmileUserController {
}
@PostMapping("saveOrUpdateUserThreeStep")
@ApiOperation("增加或者删除第三步")
public ResponseDto saveOrUpdateUserThreeStep(@RequestBody SmileUserVO smileUserVO) {
public ResponseDto saveOrUpdateUserThreeStep(@Validated(SmileUserVO.saveThree.class) @RequestBody SmileUserVO smileUserVO, MethodArgumentNotValidException exception) {
BindingResult result = exception.getBindingResult();
if (result.hasErrors()) {
List<ObjectError> errors = result.getAllErrors();
if (errors != null) {
return ResponseDto.failure(errors.get(0).getDefaultMessage());
}
}
String userId = CurrentUtil.getCurrentUid();
smileUserVO.setUid(userId);
SmileUserVO smileUserVORedis= (SmileUserVO) redisUtil.get(SmileRedisConst.SMILE_USER.concat(userId));
......
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