Commit 98485f4c authored by 杨锐's avatar 杨锐

code review。

parent 5a775628
package cn.quantgroup.xyqb.config.http;
import cn.quantgroup.xyqb.service.http.IHttpService;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.client.SimpleClientHttpRequestFactory;
......@@ -12,7 +13,12 @@ import org.springframework.web.client.RestTemplate;
* Time: 上午11:37
*
* @author: yangrui
*
* @deprecated Use
* {@link IHttpService}}
* instead. 统一.
*/
@Deprecated
@Configuration
public class RestTemplateConfig {
......
package cn.quantgroup.xyqb.controller.modifyphoneno.req;
import cn.quantgroup.user.enums.ModifyPhoneNoApplyStatusEnum;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.hibernate.validator.constraints.Range;
import javax.validation.constraints.NotNull;
......@@ -16,10 +16,9 @@ import javax.validation.constraints.NotNull;
public class AuditReq {
@NotNull(message = "id不能为空")
private Long id;
@ApiModelProperty("申请状态 0处理中; 1修改完成; 2不允许修改;")
@ApiModelProperty("申请状态 INIT处理中; DONE修改完成; NO_ALLOW不允许修改;")
@NotNull(message = "申请状态不能为空")
@Range(min = 0, max = 2, message = "申请状态不合法。")
private Integer applyStatus;
private ModifyPhoneNoApplyStatusEnum applyStatus;
@ApiModelProperty("申请状态补充原因")
private String applyStatusReason;
}
package cn.quantgroup.xyqb.controller.modifyphoneno.req;
import cn.quantgroup.user.enums.ModifyPhoneNoApplyStatusEnum;
import cn.quantgroup.user.enums.ModifyPhoneNoProcessingStatusEnum;
import cn.quantgroup.xyqb.controller.req.Page;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.hibernate.validator.constraints.Range;
/**
* Date: 2019/11/5
......@@ -35,14 +36,12 @@ public class ModifyPhoneNoQueryReq extends Page {
/**
* 申请状态 0处理中; 1修改完成; 2不允许修改;
*/
@ApiModelProperty("申请状态 0处理中; 1修改完成; 2不允许修改;")
@Range(min = 0, max = 2, message = "申请状态不合法。")
private Integer applyStatus;
@ApiModelProperty("申请状态 INIT 处理中; DONE 修改完成; NO_ALLOW 不允许修改;")
private ModifyPhoneNoApplyStatusEnum applyStatus;
/**
* 处理状态 0待人工处理 1待用户反馈结果 2已反馈
*/
@ApiModelProperty("处理状态 0待人工处理; 1待用户反馈结果; 2已反馈")
@Range(min = 0, max = 2, message = "处理状态不合法。")
private Integer processingStatus;
@ApiModelProperty("处理状态 INIT 待人工处理; WAIT_4_USER_FEEDBACK 待用户反馈结果; DONE 已反馈;")
private ModifyPhoneNoProcessingStatusEnum processingStatus;
}
......@@ -11,10 +11,12 @@ import cn.quantgroup.xyqb.entity.ModifyPhoneNo;
import cn.quantgroup.xyqb.exception.DataException;
import cn.quantgroup.xyqb.repository.IModifyPhoneNoRepository;
import cn.quantgroup.xyqb.repository.IUserDetailRepository;
import cn.quantgroup.xyqb.service.http.IHttpService;
import cn.quantgroup.xyqb.service.sms.ISmsService;
import cn.quantgroup.xyqb.service.user.IModifyPhoneNoService;
import cn.quantgroup.xyqb.service.user.IUserService;
import cn.quantgroup.xyqb.util.DateUtilsV1;
import com.alibaba.fastjson.JSONObject;
import com.google.common.collect.Lists;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
......@@ -26,7 +28,6 @@ import org.springframework.data.domain.Sort;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.client.RestTemplate;
import javax.annotation.Resource;
import javax.persistence.criteria.*;
......@@ -49,7 +50,7 @@ public class ModifyPhoneNoServiceImpl implements IModifyPhoneNoService {
@Resource
private ISmsService smsService;
@Resource
private RestTemplate restTemplate;
private IHttpService httpService;
@Resource
private IUserService userService;
......@@ -58,18 +59,18 @@ public class ModifyPhoneNoServiceImpl implements IModifyPhoneNoService {
/**
* @param id user.id
* @param userId user.id
* @param step1Req
* @return
*/
@Override
@Transactional(rollbackFor = Exception.class)
public Long saveStep1(Long id, Step1Req step1Req) {
public Long saveStep1(Long userId, Step1Req step1Req) {
// TODO: 2019/11/4 并发访问
allowModify(id, step1Req.getName(), step1Req.getIdCard(), step1Req.getPrevPhoneNo(), step1Req.getCurPhoneNo(),
allowModify(userId, step1Req.getName(), step1Req.getIdCard(), step1Req.getPrevPhoneNo(), step1Req.getCurPhoneNo(),
step1Req.getSmsCode());
ModifyPhoneNo modifyPhoneNo = Step1Req.adapt(step1Req);
modifyPhoneNo.setUserId(id);
modifyPhoneNo.setUserId(userId);
modifyPhoneNoRepository.saveAndFlush(modifyPhoneNo);
return modifyPhoneNo.getId();
}
......@@ -91,14 +92,14 @@ public class ModifyPhoneNoServiceImpl implements IModifyPhoneNoService {
/**
* 查询用户手机号修改进度
*
* @param id user.id
* @param userId user.id
* @return 进度 0初始化(用户未填写过申请单或提交过的申请单均已处理完成且反馈);
* 1已填写基本信息,未上传身份证图片;
* 2已填写基本信息,且已上传身份证图片
*/
@Override
public Integer progress(Long id) {
ModifyPhoneNo modifyPhoneNo = modifyPhoneNoRepository.findFirstByUserIdAndApplyStatus(id, ModifyPhoneNoApplyStatusEnum.INIT.getType());
public Integer progress(Long userId) {
ModifyPhoneNo modifyPhoneNo = modifyPhoneNoRepository.findFirstByUserIdAndApplyStatus(userId, ModifyPhoneNoApplyStatusEnum.INIT.getType());
if (modifyPhoneNo == null) {
return 0;
}
......@@ -131,10 +132,10 @@ public class ModifyPhoneNoServiceImpl implements IModifyPhoneNoService {
list.add(criteriaBuilder.lessThanOrEqualTo(root.get("createAt"), DateUtilsV1.strToDate(modifyPhoneNoQueryReq.getEndAt(), DateUtilsV1.YMD_FORMAT)));
}
if (modifyPhoneNoQueryReq.getApplyStatus() != null) {
list.add(criteriaBuilder.equal(root.get("applyStatus"), modifyPhoneNoQueryReq.getApplyStatus()));
list.add(criteriaBuilder.equal(root.get("applyStatus"), modifyPhoneNoQueryReq.getApplyStatus().getType()));
}
if (modifyPhoneNoQueryReq.getProcessingStatus() != null) {
list.add(criteriaBuilder.equal(root.get("processingStatus"), modifyPhoneNoQueryReq.getProcessingStatus()));
list.add(criteriaBuilder.equal(root.get("processingStatus"), modifyPhoneNoQueryReq.getProcessingStatus().getType()));
}
Predicate[] arr = new Predicate[list.size()];
return criteriaBuilder.and(list.toArray(arr));
......@@ -164,11 +165,11 @@ public class ModifyPhoneNoServiceImpl implements IModifyPhoneNoService {
if (modifyPhoneNo == null) {
throw new DataException("数据不存在。");
}
if (ModifyPhoneNoApplyStatusEnum.NO_ALLOW.getType() == auditReq.getApplyStatus()) {
if (ModifyPhoneNoApplyStatusEnum.NO_ALLOW == auditReq.getApplyStatus()) {
modifyPhoneNo.setApplyStatus(ModifyPhoneNoApplyStatusEnum.NO_ALLOW.getType());
modifyPhoneNo.setApplyStatusReason(auditReq.getApplyStatusReason());
}
if (ModifyPhoneNoApplyStatusEnum.DONE.getType() == auditReq.getApplyStatus()) {
if (ModifyPhoneNoApplyStatusEnum.DONE == auditReq.getApplyStatus()) {
allowModifyHttp(modifyPhoneNo.getUserId());
userService.modifyPhoneNo(modifyPhoneNo.getPrevPhoneNo(), modifyPhoneNo.getCurPhoneNo());
modifyPhoneNo.setApplyStatus(ModifyPhoneNoApplyStatusEnum.DONE.getType());
......@@ -184,7 +185,7 @@ public class ModifyPhoneNoServiceImpl implements IModifyPhoneNoService {
* 用户有还款中的订单,不允许修改。
* </p>
*
* @param id user.id
* @param userId user.id
* @param name 注册人真实姓名
* @param idCard 注册人身份证件号
* @param prevPhoneNo 当前手机号码
......@@ -192,28 +193,34 @@ public class ModifyPhoneNoServiceImpl implements IModifyPhoneNoService {
* @param smsCode 新手机号码短信验证码
* @return
*/
public void allowModify(Long id, String name, String idCard, String prevPhoneNo, String curPhoneNo, String smsCode) {
if (modifyPhoneNoRepository.findFirstByUserIdAndApplyStatus(id, ModifyPhoneNoProcessingStatusEnum.INIT.getType()) != null) {
public void allowModify(Long userId, String name, String idCard, String prevPhoneNo, String curPhoneNo, String smsCode) {
if (modifyPhoneNoRepository.findFirstByUserIdAndApplyStatus(userId, ModifyPhoneNoProcessingStatusEnum.INIT.getType()) != null) {
throw new DataException("已存在处理中的申请单,不支持再次更换。");
}
if (userDetailRepository.findByUserIdAndPhoneNoAndNameAndIdNo(id, prevPhoneNo, name, idCard) == null) {
throw new DataException("姓名、身份证、电话号不符。");
if (userDetailRepository.findByUserIdAndPhoneNoAndNameAndIdNo(userId, prevPhoneNo, name, idCard) == null) {
throw new DataException("信息填写有误,请重新填写。");
}
if (userDetailRepository.findOneByPhoneNo(curPhoneNo) != null) {
throw new DataException("新手机号已存在,不支持更换。");
throw new DataException("信息填写有误,请重新填写。");
}
if (!smsService.verifyPhoneAndCode(curPhoneNo, smsCode)) {
throw new DataException("验证码不正确。");
}
allowModifyHttp(id);
allowModifyHttp(userId);
}
public void allowModifyHttp(Long id) {
log.info("allowModify userId = 【{}】", id);
UserLoanStatusResp userLoanStatusResp = restTemplate.getForObject(apiHttps + "?userId=" + id, UserLoanStatusResp.class);
log.info("allowModify userLoanStatusResp = 【{}】", userLoanStatusResp);
if (!userLoanStatusResp.isSuccess() || !userLoanStatusResp.isData()) {
throw new DataException("用户存在订单,不支持修改。");
/**
* @param userId user.id
*/
public void allowModifyHttp(Long userId) {
log.info("allowModify userId = 【{}】", userId);
String res = httpService.get(apiHttps + "?userId=" + userId);
log.info("allowModify res = 【{}】", res);
if (StringUtils.isNotBlank(res)) {
UserLoanStatusResp userLoanStatusResp = JSONObject.parseObject(res, UserLoanStatusResp.class);
if (!userLoanStatusResp.isSuccess() || !userLoanStatusResp.isData()) {
throw new DataException("用户存在订单,不支持修改。");
}
}
}
}
......@@ -215,12 +215,12 @@ public class UserServiceImpl implements IUserService {
User newPhoneUser = userRepository.findByPhoneNo(newPhoneNo);
if (Objects.nonNull(newPhoneUser)) {
//新手机号已存在
throw new DataException("新手机号已存在。");
throw new DataException("信息填写有误,请重新填写。");
}
User oldPhoneUser = userRepository.findByPhoneNo(oldPhoneNo);
if (Objects.isNull(oldPhoneUser)) {
//这不是扯了.旧手机号不存在.
throw new DataException("旧手机号不存在。");
throw new DataException("信息填写有误,请重新填写。");
}
//2. 执行修改
//2.1 修改 user 表
......
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