提交 e50f1f0a 编写于 作者: rushui.chen's avatar rushui.chen

20191029 接口幂等性

上级 d7475b2a
流水线 #16439 已失败 于阶段
in 0 second
......@@ -48,7 +48,6 @@ public class PasswordController extends AccountBaseController {
@PostMapping(value = "/modify")
public PicaResponse modifyPassword(@RequestBody EncryptEntity entity) throws Exception {
Long doctorId= super.getDoctorIdByToken();
// AESUtil.encryptV0(picaUser.getMobile())
Doctor doctorInfo = doctorService.getDoctorInfo(doctorId.intValue());
String mobile = doctorInfo.getMobilePhone();
AccountInfoEntity accountInfoEntity = accountInfoDetailMapper.selectByMobile(mobile);
......
......@@ -29,7 +29,7 @@ import org.springframework.web.bind.annotation.RestController;
public class RegisterController extends AccountBaseController {
private final String REPEAT_REGISTER_PREFIX = "repeat-register—";
@Autowired
private RegisterService registerService;
......@@ -47,32 +47,18 @@ public class RegisterController extends AccountBaseController {
BaseRequest request = CryptoUtil.decrypt(entity, BaseRequest.class);
String mobile = request.getMobile();
//接口幂等性处理(redis中没有就进行注册逻辑,如果已经存在,就不处理)
String exist = redisClient.get(REPEAT_REGISTER_PREFIX + mobile);
if (StringUtils.isBlank(exist)) {
String authCode = request.getAuthCode();
String flag = AccountTypeEnum.SYSCODE_TYPE_REGISTER.getCode() + "";
accountUtils.checkMobilePhoneAndAuthCode(mobile, flag, authCode);
accountUtils.checkPassword(request.getPassword());
redisClient.set(REPEAT_REGISTER_PREFIX + mobile, mobile, 30);
LoginResult result = null;
try {
request.setFlag(AccountTypeEnum.SYSCODE_TYPE_REGISTER.getCode());
request.setProductType(super.getProductType());
request.setSourceType(super.getSourceType());
request.setLoginIp(super.getIpAddr());
result = registerService.register(request);
} catch (Exception e) {
//向上抛出异常,让异常处理框架捕获到
throw new AccountException(AccountExceptionEnum.PICA_REGISTER_FAIL);
} finally {
//如果在注册过程中抛出异常,就删除redis中的注册标记
redisClient.del(REPEAT_REGISTER_PREFIX + mobile);
}
redisClient.del(REPEAT_REGISTER_PREFIX + mobile);
return PicaResponse.toResponse(result);
} else {
return PicaResponse.toResponse(null, AccountExceptionEnum.PICA_ALREADY_REGISTER.getCode(), "正在注册中,请勿重复提交");
}
}
//"sourceType":6 表示长海项目
......
......@@ -16,10 +16,13 @@ import com.pica.cloud.account.account.server.util.AESUtil;
import com.pica.cloud.account.account.server.util.AccountUtils;
import com.pica.cloud.account.account.server.util.ExecutorServiceUtils;
import com.pica.cloud.account.account.server.util.TokenUtils;
import com.pica.cloud.foundation.entity.PicaResponse;
import com.pica.cloud.foundation.redis.ICacheClient;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;
import java.io.ByteArrayOutputStream;
......@@ -31,6 +34,8 @@ import java.util.concurrent.ExecutorService;
@Service
public class RegisterServiceImpl implements RegisterService {
private final String REPEAT_REGISTER_PREFIX = "repeat-register—";
private Logger logger = LoggerFactory.getLogger(this.getClass());
@Autowired
......@@ -61,7 +66,8 @@ public class RegisterServiceImpl implements RegisterService {
private AgreementLogEntityMapper agreementLogEntityMapper;
@Autowired
private DoctorMapper doctorMapper;
@Qualifier("cacheMigrateClient")
private ICacheClient redisClient;
/**
* 1)注册功能:默认未完善信息;
......@@ -74,9 +80,14 @@ public class RegisterServiceImpl implements RegisterService {
@Override
public LoginResult register(BaseRequest baseRequest) {
String mobile = baseRequest.getMobile();
//对注册接口做幂等性处理:注册成功,删除缓存,注册失败提示用户
String exist = redisClient.get(REPEAT_REGISTER_PREFIX + mobile);
if (StringUtils.isBlank(exist)) {
String mobileEncrypt = AESUtil.encryptV0(mobile);
AccountInfoEntity accountInfoEntity = accountInfoDetailMapper.selectByMobile(mobileEncrypt);
if (accountInfoEntity == null) {
redisClient.set(REPEAT_REGISTER_PREFIX + mobile, mobile, 30);
try {
Date currentTime = new Date();
int productType = baseRequest.getProductType();
int sourceType = baseRequest.getSourceType();
......@@ -148,7 +159,18 @@ public class RegisterServiceImpl implements RegisterService {
AccountTypeEnum.LOG_TYPE_LOGIN.getCode());
picaLogUtils.info(entity);
processAgreement(userId);
redisClient.del(REPEAT_REGISTER_PREFIX + mobile);
return result;
} catch (Exception e) {
//向上抛出异常,让异常处理框架捕获到
throw new AccountException(AccountExceptionEnum.PICA_REGISTER_FAIL);
} finally {
//如果在注册过程中抛出异常,就删除redis中的注册标记
redisClient.del(REPEAT_REGISTER_PREFIX + mobile);
}
} else {
throw new AccountException(AccountExceptionEnum.PICA_ALREADY_REGISTER);
}
} else {
throw new AccountException(AccountExceptionEnum.PICA_ALREADY_REGISTER);
}
......
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册