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

20200116 使用redis分布式锁防止重复提交

上级 c8054f17
流水线 #20904 已失败 于阶段
in 0 second
......@@ -13,6 +13,7 @@ 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.redis.CacheClient;
import com.pica.cloud.foundation.redis.ICacheClient;
import com.pica.cloud.foundation.utils.utils.CommonUtil;
import io.swagger.annotations.Api;
......@@ -47,6 +48,11 @@ public class LoginController extends AccountBaseController {
@Autowired
private DoctorService doctorService;
@Autowired
private CacheClient cacheClient;
private String cache_prifix = "cache-";
/**
* 密码登录接口
*
......@@ -131,11 +137,19 @@ public class LoginController extends AccountBaseController {
@PostMapping("/login/wechat/bind")
public PicaResponse bindWeChat(@RequestBody EncryptEntity entity) throws Exception {
BaseRequest request = CryptoUtil.decrypt(entity, BaseRequest.class);
long doctorId = super.getDoctorIdByToken();
String nickname = loginService.bindWeChat(doctorId, request);
Map<String, String> map = new HashMap();
map.put("nickname", nickname);
return PicaResponse.toResponse(map);
Long result = cacheClient.setnx(cache_prifix + request.getUnionId(), request.getUnionId());
if (result == 1) {
cacheClient.set(cache_prifix + request.getUnionId(), 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.getUnionId());
return PicaResponse.toResponse(map);
} else {
throw new AccountException(AccountExceptionEnum.PICA_WECHAT_UNBIND_CURRENT);
}
}
@ApiOperation("微信解除绑定接口")
......
......@@ -27,7 +27,8 @@ public enum AccountExceptionEnum {
PICA_NOT_EXIST("216519", "该用户不存在"),
PICA_REGISTER_FAIL("216520", "注册失败"),
PICA_WECHAT_CODE_ERROR("216521", "微信登录授权code不正确"),
PICA_WECHAT_UNBIND("216522", "该微信号已绑定其他云鹊医账户,你可以使用微信登录云鹊医,在「设置」页解除绑定");
PICA_WECHAT_UNBIND("216522", "该微信号已绑定其他云鹊医账户,你可以使用微信登录云鹊医,在「设置」页解除绑定"),
PICA_WECHAT_UNBIND_CURRENT("216523", "正在绑定中,请稍等");
private String code;
......
......@@ -30,7 +30,7 @@
<include refid="Base_Column_List"/>
from account_union
where union_id = #{unionId} and delete_flag = 1
limit 1
limit 1
</select>
<!--解除绑定关系-->
......
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册