提交 27ad1ff1 编写于 作者: Chongwen.jiang's avatar Chongwen.jiang

日志添加,发送短信...

上级 d8650831
流水线 #22669 已失败 于阶段
in 0 second
......@@ -15,11 +15,14 @@ import com.pica.cloud.account.account.server.service.TokenService;
import com.pica.cloud.account.account.server.util.AccountUtils;
import com.pica.cloud.account.account.server.util.CryptoUtil;
import com.pica.cloud.foundation.entity.PicaResponse;
import com.pica.cloud.foundation.entity.PicaWarnException;
import com.pica.cloud.foundation.redis.CacheClient;
import com.pica.cloud.foundation.redis.ICacheClient;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
......@@ -29,6 +32,7 @@ import java.util.Map;
@Api(description = "登录资源")
@RestController
public class LoginController extends AccountBaseController {
private Logger logger = LoggerFactory.getLogger(this.getClass());
@Autowired
private LoginService loginService;
......@@ -136,16 +140,24 @@ public class LoginController extends AccountBaseController {
Long result = cacheClient.setnx(cache_prifix + request.getWeChatCode(), request.getWeChatCode());
if (result == 1) {
cacheClient.set(cache_prifix + request.getWeChatCode(), 60);
long doctorId = super.getDoctorIdByToken();
String nickname = loginService.bindWeChat(doctorId, request);
Map<String, String> map = new HashMap();
map.put("nickname", nickname);
//成功以后释放锁
cacheClient.del(cache_prifix + request.getWeChatCode());
return PicaResponse.toResponse(map);
try {
cacheClient.expire(cache_prifix + request.getWeChatCode(), 60);
long doctorId = super.getDoctorIdByToken();
String nickname = loginService.bindWeChat(doctorId, request);
Map<String, String> map = new HashMap();
map.put("nickname", nickname);
//成功以后释放锁
cacheClient.del(cache_prifix + request.getWeChatCode());
return PicaResponse.toResponse(map);
} catch (Exception e) {
logger.error("bindWeChat-" + e.getMessage(), e);
throw new PicaWarnException(AccountExceptionEnum.PICA_BIND_WECHAT_FAIL.getCode(), AccountExceptionEnum.PICA_BIND_WECHAT_FAIL.getMessage());
} finally {
//成功以后释放锁
cacheClient.del(cache_prifix + request.getWeChatCode());
return null;
}
} else {
cacheClient.del(cache_prifix + request.getWeChatCode());
return PicaResponse.toResponse(null, AccountExceptionEnum.PICA_WECHAT_UNBIND_CURRENT.getCode(),
AccountExceptionEnum.PICA_WECHAT_UNBIND_CURRENT.getMessage());
}
......
......@@ -49,6 +49,7 @@ public enum AccountExceptionEnum {
PICA_RC_60_SECOND_LIMIT("216540", "验证码发送频率过高,请{remainTime}秒后再试"),
PICA_H5_AUTH_CODE_INTERFACE_OFFED("216541", "该功能已关闭"),
PICA_MESSAGE_SERVICE_CALL_FAIL("216542", "短信发送失败"),
PICA_BIND_WECHAT_FAIL("216543", "绑定微信失败"),
xxx_xxx("","");
......
......@@ -51,9 +51,6 @@ public class RegisterServiceImpl implements RegisterService {
@Autowired
private TokenUtils tokenUtils;
@Autowired
private AgreementEntityMapper agreementEntityMapper;
@Autowired
private AgreementLogEntityMapper agreementLogEntityMapper;
......@@ -79,13 +76,14 @@ public class RegisterServiceImpl implements RegisterService {
public LoginResult register(BaseRequest baseRequest,QueryMobileEntity queryMobileEntity) {
String mobile = baseRequest.getMobile();
//对注册接口做幂等性处理:注册成功,删除缓存,注册失败提示用户
String exist = redisClient.get(Constants.REPEAT_REGISTER_PREFIX + mobile);
if (StringUtils.isBlank(exist)) {
String mobileEncrypt = AESUtil.encryptV0(mobile);
AccountInfoEntity accountInfoEntity = accountInfoDetailMapper.selectByMobile(mobileEncrypt);
if (accountInfoEntity == null) {
redisClient.set(Constants.REPEAT_REGISTER_PREFIX + mobile, mobile, 30);
try {
String nxKey = Constants.REPEAT_REGISTER_PREFIX + mobile;
Long resultNx = redisClient.setnx(nxKey, mobile);
if(resultNx == 1) {
try {
String mobileEncrypt = AESUtil.encryptV0(mobile);
AccountInfoEntity accountInfoEntity = accountInfoDetailMapper.selectByMobile(mobileEncrypt);
if (accountInfoEntity == null) {
redisClient.expire(nxKey, 30);
Date currentTime = new Date();
int productType = baseRequest.getProductType();
int sourceType = baseRequest.getSourceType();
......@@ -155,19 +153,20 @@ public class RegisterServiceImpl implements RegisterService {
processAgreement(userId);
logger.info("register-add-roleMap");
processRoleMap(userId);
redisClient.del(Constants.REPEAT_REGISTER_PREFIX + mobile);
redisClient.del(nxKey);
return result;
} catch (Exception e) {
//向上抛出异常,让异常处理框架捕获到
logger.error("register-" + e.getMessage(), e);
throw new AccountException(AccountExceptionEnum.PICA_REGISTER_FAIL);
} finally {
//如果在注册过程中抛出异常,就删除redis中的注册标记
redisClient.del(Constants.REPEAT_REGISTER_PREFIX + mobile);
} else {
logger.info("register-account is exists");
throw new AccountException(AccountExceptionEnum.PICA_ALREADY_REGISTER);
}
} else {
logger.info("register-account is exists");
throw new AccountException(AccountExceptionEnum.PICA_ALREADY_REGISTER);
} catch (Exception e) {
//向上抛出异常,让异常处理框架捕获到
logger.error("register-" + e.getMessage(), e);
throw new AccountException(AccountExceptionEnum.PICA_REGISTER_FAIL);
} finally {
//如果在注册过程中抛出异常,就删除redis中的注册标记
logger.info("register-del-nxKey");
redisClient.del(nxKey);
}
} else {
logger.info("register-key is exists");
......
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册