Commit d704c0c6 authored by 李健华's avatar 李健华

客服系统修改手机号及记录接口

parent 58939807
......@@ -5,6 +5,7 @@ import cn.quantgroup.xyqb.controller.modifyphoneno.req.*;
import cn.quantgroup.xyqb.controller.modifyphoneno.resp.ProgressResp;
import cn.quantgroup.xyqb.entity.ModifyPhoneNo;
import cn.quantgroup.xyqb.entity.User;
import cn.quantgroup.xyqb.entity.UserModifyPhoneRecord;
import cn.quantgroup.xyqb.model.JsonResult;
import cn.quantgroup.xyqb.service.user.IModifyPhoneNoService;
import com.fasterxml.jackson.databind.ObjectMapper;
......@@ -30,6 +31,7 @@ public class ModifyPhoneNoController implements IBaseController {
@Resource
private IModifyPhoneNoService modifyPhoneNoService;
@GetMapping("/progress")
public JsonResult<ProgressResp> progress() {
User user = getCurrentUserFromRedis();
......@@ -107,10 +109,35 @@ public class ModifyPhoneNoController implements IBaseController {
/*------------------------------------------------------------------------------------------------------------*/
/**
* 客服系统修改手机号
* @param modifyPhoneRecord
* @return
*/
@PostMapping("/submitModify")
public JsonResult submitModify(@Valid @RequestBody ModifyPhoneRecord modifyPhoneRecord) {
modifyPhoneNoService.submitModify(modifyPhoneRecord);
return JsonResult.buildSuccessResult();
}
/**
* 金融修改手机号
* @param modifyPhoneRecord
* @return
*/
@PostMapping("/financial/submitModify")
public JsonResult financialSubmitModify(@Valid @RequestBody ModifyPhoneRecord modifyPhoneRecord) {
modifyPhoneNoService.financialSubmitModify(modifyPhoneRecord);
return JsonResult.buildSuccessResult();
}
@PostMapping( "/modifyPhoneNolist")
public JsonResult getModifyPhoneNolist(@RequestParam("userId") Long userId,
@RequestParam(value = "pageNo", defaultValue = "1", required = false) int pageNo,
@RequestParam(value = "pageSize", defaultValue = "10", required = false) int pageSize) {
Page<UserModifyPhoneRecord> pageData = modifyPhoneNoService.query(userId, pageNo, pageSize);
return JsonResult.buildSuccessResult("修改手机号列表", pageData);
}
}
......@@ -3,6 +3,7 @@ package cn.quantgroup.xyqb.service.user;
import cn.quantgroup.xyqb.controller.modifyphoneno.req.*;
import cn.quantgroup.xyqb.controller.modifyphoneno.resp.ProgressResp;
import cn.quantgroup.xyqb.entity.ModifyPhoneNo;
import cn.quantgroup.xyqb.entity.UserModifyPhoneRecord;
import org.springframework.data.domain.Page;
/**
......@@ -32,4 +33,8 @@ public interface IModifyPhoneNoService {
void audit(AuditReq auditReq);
void submitModify(ModifyPhoneRecord modifyPhoneRecord);
void financialSubmitModify(ModifyPhoneRecord modifyPhoneRecord);
Page<UserModifyPhoneRecord> query(Long userId, int pageNo, int pageSize);
}
......@@ -4,6 +4,7 @@ import cn.quantgroup.xyqb.aspect.limit.AccessLimit;
import cn.quantgroup.xyqb.controller.modifyphoneno.req.*;
import cn.quantgroup.xyqb.controller.modifyphoneno.resp.ProgressResp;
import cn.quantgroup.xyqb.entity.ModifyPhoneNo;
import cn.quantgroup.xyqb.entity.User;
import cn.quantgroup.xyqb.entity.UserModifyPhoneRecord;
import cn.quantgroup.xyqb.exception.DataException;
import cn.quantgroup.xyqb.model.JsonResult;
......@@ -247,8 +248,18 @@ public class ModifyPhoneNoServiceImpl implements IModifyPhoneNoService {
try {
if (lock.lock()) {
if (modifyPhoneRecord.getCurPhoneNo().equals(modifyPhoneRecord.getPrevPhoneNo())) {
throw new DataException("新旧手机号相同");
throw new DataException("新手机号已存在,不支持更换");
}
User user = userService.findById(modifyPhoneRecord.getUserId());
if (user == null) {
throw new DataException("用户不存在");
}
if (!modifyPhoneRecord.getPrevPhoneNo().equals(user.getPhoneNo()) && !modifyPhoneRecord.getPrevPhoneNo().equals(user.getEncryptedPhoneNo())) {
throw new DataException("原手机号填写不符");
}
// 请求其他系统信息
HashMap<String, String> parameters = new HashMap<>();
HashMap<String, String> headers = new HashMap<>();
......@@ -278,12 +289,64 @@ public class ModifyPhoneNoServiceImpl implements IModifyPhoneNoService {
} catch (Exception e) {
e.printStackTrace();
throw new DataException(e.getMessage());
} finally {
lock.unlock();
}
}
@Override
@Transactional(rollbackFor = Exception.class)
public void financialSubmitModify(ModifyPhoneRecord modifyPhoneRecord) {
String lockKey = "modifyPhone:".concat(modifyPhoneRecord.getCurPhoneNo());
RedisLock lock = new RedisLock(redisTemplate, lockKey);
try {
if (lock.lock()) {
if (modifyPhoneRecord.getCurPhoneNo().equals(modifyPhoneRecord.getPrevPhoneNo())) {
throw new DataException("新手机号已存在,不支持更换");
}
User user = userService.findById(modifyPhoneRecord.getUserId());
if (user == null) {
throw new DataException("用户不存在");
}
if (!modifyPhoneRecord.getPrevPhoneNo().equals(user.getPhoneNo()) && !modifyPhoneRecord.getPrevPhoneNo().equals(user.getEncryptedPhoneNo())) {
throw new DataException("原手机号填写不符");
}
userService.submitModifyPhone(modifyPhoneRecord.getPrevPhoneNo(), modifyPhoneRecord.getCurPhoneNo());
UserModifyPhoneRecord record = new UserModifyPhoneRecord();
BeanUtils.copyProperties(modifyPhoneRecord, record);
modifyPhoneRecordRepository.saveAndFlush(record);
}
} catch (Exception e) {
e.printStackTrace();
log.error("金融来修改手机号失败--{}, 原因:---", JSONObject.toJSONString(modifyPhoneRecord), e);
String failString = String.format("金融来修改手机号失败--%s", e.getMessage());
throw new DataException(failString);
} finally {
lock.unlock();
}
}
@Override
public Page<UserModifyPhoneRecord> query(Long userId, int pageNo, int pageSize) {
Pageable pageable = getPageable(pageNo, pageSize);
Page<UserModifyPhoneRecord> userModifyPhoneRecord = modifyPhoneRecordRepository.findAll((root, query, criteriaBuilder) -> {
List<Predicate> predicates = Lists.newArrayList();
predicates.add(criteriaBuilder.equal(root.get("userId"),userId));
query.where(predicates.toArray(new Predicate[predicates.size()]));
return query.getRestriction();
}, pageable);
return userModifyPhoneRecord;
}
private Pageable getPageable(int currentPage, int pageSize) {
return new PageRequest(currentPage - 1, pageSize, new Sort(Sort.Direction.DESC, "id"));
}
/**
* 验证用户是否允许修改手机号
* <p>
......
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