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

code review。

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