Commit 5e1894fb authored by 王亮's avatar 王亮

Merge branch 'feature/modify-phone-no-20221117' into 'master'

Feature/modify phone no 20221117

See merge request !10
parents 3574c68a ffe7b8bb
package cn.quantgroup.customer.entity;
/**
* Created by FrankChow on 15/7/15.
*/
public enum Reason {
ABANDONED("原注册手机已经废弃"),
SYNCHRONOUSCHANGE("电商侧手机号需同步修改金融侧"),
ORTHER("其它原因"),
;
private String name;
Reason(String name) {
this.name = name;
}
public String getName() {
return name;
}
@Override
public String toString() {
return name;
}
}
...@@ -7,7 +7,9 @@ public enum ErrorCodeEnum { ...@@ -7,7 +7,9 @@ public enum ErrorCodeEnum {
RETURN_ERROR(7001L, "返回值异常"), RETURN_ERROR(7001L, "返回值异常"),
PARAM_ERROR(7002L, "参数异常"), PARAM_ERROR(7002L, "参数异常"),
NO_TOKEN(8001L,"缺少token信息"), NO_TOKEN(8001L,"缺少token信息"),
ILLEGAL_TOKEN(8002L,"token信息有误"); ILLEGAL_TOKEN(8002L,"token信息有误"),
PHONE_EQUALS(8003L, "新手机号已存在,不支持更换"),
;
public String getMessage() { public String getMessage() {
......
package cn.quantgroup.customer.exception;
import cn.quantgroup.customer.rest.vo.JsonResult;
import lombok.extern.slf4j.Slf4j;
import org.hibernate.exception.DataException;
import org.springframework.http.HttpStatus;
import org.springframework.jdbc.BadSqlGrammarException;
import org.springframework.validation.BindException;
import org.springframework.validation.BindingResult;
import org.springframework.validation.ObjectError;
import org.springframework.web.bind.MethodArgumentNotValidException;
import org.springframework.web.bind.MissingServletRequestParameterException;
import org.springframework.web.bind.annotation.*;
import javax.validation.ConstraintViolation;
import javax.validation.ConstraintViolationException;
import javax.validation.ValidationException;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
/**
* Created by Miraculous on 15/7/6.
* 出现异常,进入这个handler。
*/
@Slf4j
@ControllerAdvice
@RestController
public class ExceptionHandlers {
private static final JsonResult EXCEPTION_RESULT = new JsonResult("服务出错。", (long) HttpStatus.INTERNAL_SERVER_ERROR.value(), null);
@ExceptionHandler(ValidationException.class)
public JsonResult validException(ValidationException exception) {
ConstraintViolationException exs = (ConstraintViolationException) exception;
Set<ConstraintViolation<?>> constraintViolations = exs.getConstraintViolations();
if (constraintViolations.isEmpty()) {
log.error("这里出了个错....", exception.getMessage());
return null;
}
String message = constraintViolations.iterator().next().getMessage();
return JsonResult.buildErrorStateResult(message, null);
}
@ExceptionHandler({MethodArgumentNotValidException.class, BindException.class})
@ResponseBody
@ResponseStatus(HttpStatus.OK)
public JsonResult handleBindException(Exception e) {
BindingResult result = null;
if (e instanceof MethodArgumentNotValidException) {
result = ((MethodArgumentNotValidException) e).getBindingResult();
} else if (e instanceof BindException) {
result = ((BindException) e).getBindingResult();
}
if (result != null) {
List<ObjectError> errors = result.getAllErrors();
StringBuilder sb = new StringBuilder();
if (errors != null && errors.size() > 0) {
Iterator<ObjectError> iterator = errors.iterator();
ObjectError err = null;
while ((err = iterator.next()) != null) {
sb.append(err.getDefaultMessage());
if (iterator.hasNext()) {
sb.append("; ");
} else {
sb.append("。");
break;
}
}
}
return JsonResult.buildErrorStateResult(sb.toString(), null);
}
return null;
}
@ExceptionHandler({DataException.class})
@ResponseBody
@ResponseStatus(HttpStatus.OK)
public JsonResult handleDataException(DataException e) {
return JsonResult.buildErrorStateResult(e.getMessage(), null);
}
@ExceptionHandler(BadSqlGrammarException.class)
@ResponseBody
@ResponseStatus(HttpStatus.OK)
public JsonResult handleBadSqlGrammarException(BadSqlGrammarException e) {
log.error("sql语法解析异常 error sql = 【{}】", e.getSql(), e);
return JsonResult.buildErrorStateResult("参数错误。", null);
}
@ExceptionHandler(MissingServletRequestParameterException.class)
@ResponseStatus(HttpStatus.OK)
@ResponseBody
public JsonResult handelMissingServletRequestParameterException(MissingServletRequestParameterException re) {
return JsonResult.buildErrorStateResult(re.getMessage(), null);
}
}
package cn.quantgroup.customer.rest;
import cn.quantgroup.customer.enums.ErrorCodeEnum;
import cn.quantgroup.customer.rest.param.phone.ModifyPhoneRecord;
import cn.quantgroup.customer.rest.vo.JsonResult;
import cn.quantgroup.customer.service.IUserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import javax.validation.Valid;
@Validated
@Slf4j
@RestController
@RequestMapping("/v1")
public class UserModifyPhoneController {
@Autowired
private IUserService userService;
/**
* 修改手机号
*/
@PostMapping(value = "/modify/phoneNo")
public JsonResult modifyPhoneNo(@Valid @RequestBody ModifyPhoneRecord modifyPhoneRecord) {
if (modifyPhoneRecord.getCurPhoneNo().equals(modifyPhoneRecord.getPrevPhoneNo())) {
return JsonResult.buildErrorStateResult(ErrorCodeEnum.PHONE_EQUALS.getMessage(), ErrorCodeEnum.PHONE_EQUALS.getCode());
}
return userService.submitModiyPhoneNo(modifyPhoneRecord);
}
/**
* 获取修改手机号列表
* @return
*/
@PostMapping(value = "/modifyPhoneNolist")
public JsonResult modifyPhoneNolist(@RequestParam Long userId,
@RequestParam(defaultValue = "1", required = false) int pageNo,
@RequestParam(defaultValue = "10", required = false) int pageSize) {
return userService.modifyPhoneNolist(userId, pageNo, pageSize);
}
}
package cn.quantgroup.customer.rest.param.phone;
import cn.quantgroup.customer.entity.Reason;
import cn.quantgroup.customer.util.ValidationUtil;
import lombok.Data;
import org.hibernate.validator.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Pattern;
import java.io.Serializable;
@Data
public class ModifyPhoneRecord implements Serializable {
@NotNull(message = "用户ID不能为空")
private Long userId;
@NotBlank(message = "原手机号不能为空")
@Pattern(regexp = ValidationUtil.phoneRegExp, message = "原手机号码格式错误")
private String prevPhoneNo;
@NotBlank(message = "新手机号不能为空")
@Pattern(regexp = ValidationUtil.phoneRegExp, message = "新手机号码格式错误")
private String curPhoneNo;
@NotNull(message = "修改原因不能为空")
private Reason reason;
@NotBlank(message = "操作人不能为空")
private String operator;
private String remark;
}
\ No newline at end of file
...@@ -5,6 +5,7 @@ import cn.quantgroup.customer.rest.param.ordermapping.OrderQueryParam; ...@@ -5,6 +5,7 @@ import cn.quantgroup.customer.rest.param.ordermapping.OrderQueryParam;
import cn.quantgroup.customer.rest.param.phone.ModifyPhoneAudit; import cn.quantgroup.customer.rest.param.phone.ModifyPhoneAudit;
import cn.quantgroup.customer.rest.param.phone.ModifyPhoneFeedback; import cn.quantgroup.customer.rest.param.phone.ModifyPhoneFeedback;
import cn.quantgroup.customer.rest.param.phone.ModifyPhoneQuery; import cn.quantgroup.customer.rest.param.phone.ModifyPhoneQuery;
import cn.quantgroup.customer.rest.param.phone.ModifyPhoneRecord;
import cn.quantgroup.customer.rest.param.user.UserCombinationParam; import cn.quantgroup.customer.rest.param.user.UserCombinationParam;
import cn.quantgroup.customer.rest.param.user.UserQueryParam; import cn.quantgroup.customer.rest.param.user.UserQueryParam;
import cn.quantgroup.customer.rest.vo.JsonResult; import cn.quantgroup.customer.rest.vo.JsonResult;
...@@ -104,4 +105,8 @@ public interface IUserService extends UserDetailsService { ...@@ -104,4 +105,8 @@ public interface IUserService extends UserDetailsService {
MoResult<String> queryPointDetailByPage(UserQueryParam userQueryParam); MoResult<String> queryPointDetailByPage(UserQueryParam userQueryParam);
MoResult<String> queryUserCouponInfoByUserParam(UserQueryParam userQueryParam); MoResult<String> queryUserCouponInfoByUserParam(UserQueryParam userQueryParam);
JsonResult submitModiyPhoneNo(ModifyPhoneRecord modifyPhoneRecord);
JsonResult modifyPhoneNolist(Long userId, int pageNo, int pageSize);
} }
...@@ -17,6 +17,7 @@ import cn.quantgroup.customer.rest.param.ordermapping.OrderQueryParam; ...@@ -17,6 +17,7 @@ import cn.quantgroup.customer.rest.param.ordermapping.OrderQueryParam;
import cn.quantgroup.customer.rest.param.phone.ModifyPhoneAudit; import cn.quantgroup.customer.rest.param.phone.ModifyPhoneAudit;
import cn.quantgroup.customer.rest.param.phone.ModifyPhoneFeedback; import cn.quantgroup.customer.rest.param.phone.ModifyPhoneFeedback;
import cn.quantgroup.customer.rest.param.phone.ModifyPhoneQuery; import cn.quantgroup.customer.rest.param.phone.ModifyPhoneQuery;
import cn.quantgroup.customer.rest.param.phone.ModifyPhoneRecord;
import cn.quantgroup.customer.rest.param.user.UserCombinationParam; import cn.quantgroup.customer.rest.param.user.UserCombinationParam;
import cn.quantgroup.customer.rest.param.user.UserQueryParam; import cn.quantgroup.customer.rest.param.user.UserQueryParam;
import cn.quantgroup.customer.rest.vo.JsonResult; import cn.quantgroup.customer.rest.vo.JsonResult;
...@@ -46,12 +47,15 @@ import org.springframework.beans.factory.annotation.Value; ...@@ -46,12 +47,15 @@ import org.springframework.beans.factory.annotation.Value;
import org.springframework.security.core.userdetails.UserDetails; import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UsernameNotFoundException; import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.time.LocalDate; import java.time.LocalDate;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Objects; import java.util.Objects;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import static cn.quantgroup.customer.constant.Constant.GSON; import static cn.quantgroup.customer.constant.Constant.GSON;
@Slf4j @Slf4j
...@@ -1227,6 +1231,63 @@ public class UserServiceImpl implements IUserService { ...@@ -1227,6 +1231,63 @@ public class UserServiceImpl implements IUserService {
} }
@Override
public JsonResult submitModiyPhoneNo(ModifyPhoneRecord modifyPhoneRecord) {
String url = userSysUrl + "/v1/user/modify/phone_no/submitModify";
Map param = GSON.fromJson(GSON.toJson(modifyPhoneRecord), Map.class);
try {
Map<String, String> header = Maps.newHashMap();
header.put("Content-type", "application/json");
String result = httpService.post(url, header, param);
System.out.println(result);
JSONObject userJsonObject =null;
if(result != null){
userJsonObject = JSONObject.parseObject(result);
String userBusinessCode = userJsonObject.getString("businessCode");
if("0000".equals(userBusinessCode)){
return JsonResult.buildSuccessResult(userJsonObject.getString("msg"),userJsonObject.get("data"));
}else{
return JsonResult.buildErrorStateResult(userJsonObject.getString("msg"),userJsonObject.get("data"));
}
}else{
return JsonResult.buildErrorStateResult(userJsonObject.getString("msg"),userJsonObject.get("data"));
}
} catch (Exception e) {
log.error("[user][query modify phoneNo] 网络通讯异常,modifyPhoneRecord:{},ex:{}", modifyPhoneRecord, ExceptionUtils.getStackTrace(e));
throw new BusinessException(ErrorCodeEnum.NET_ERROR);
}
}
@Override
public JsonResult modifyPhoneNolist(Long userId, int pageNo, int pageSize) {
String url = userSysUrl + "/v1/user/modify/phone_no/modifyPhoneNolist";
Map<String, String> param = new HashMap<String, String>();
param.put("userId", String.valueOf(userId));
param.put("pageNo", String.valueOf(pageNo));
param.put("pageSize", String.valueOf(pageSize));
try {
Map<String, String> header = Maps.newHashMap();
header.put("Content-type", "application/x-www-form-urlencoded");
String result = httpService.post(url, header, param);
System.out.println(result);
JSONObject userJsonObject =null;
if(result != null){
userJsonObject = JSONObject.parseObject(result);
String userBusinessCode = userJsonObject.getString("businessCode");
if("0000".equals(userBusinessCode)){
return JsonResult.buildSuccessResult(userJsonObject.getString("msg"),userJsonObject.get("data"));
}else{
return JsonResult.buildErrorStateResult(userJsonObject.getString("msg"),userJsonObject.get("data"));
}
}else{
return JsonResult.buildErrorStateResult(userJsonObject.getString("msg"),userJsonObject.get("data"));
}
} catch (Exception e) {
throw new BusinessException(ErrorCodeEnum.NET_ERROR);
}
}
/** /**
*根据userid和phoneNo获取基本信息 *根据userid和phoneNo获取基本信息
* @param xUserUserSysResult * @param xUserUserSysResult
......
...@@ -14,6 +14,7 @@ import static java.util.regex.Pattern.compile; ...@@ -14,6 +14,7 @@ import static java.util.regex.Pattern.compile;
import static java.util.regex.Pattern.matches; import static java.util.regex.Pattern.matches;
public class ValidationUtil { public class ValidationUtil {
public static final String phoneRegExp = "^1[3456789][0-9]{9}$";
public static boolean validatePhoneNo(String phoneNo) { public static boolean validatePhoneNo(String phoneNo) {
if (StringUtils.isEmpty(phoneNo)) { if (StringUtils.isEmpty(phoneNo)) {
......
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