...
 
Commits (7)
    https://gitcode.net/roncoocom/roncoo-education/-/commit/9c494b4e9718e79e5b7383a67ff821979bae163a feat: 优化验证码发送逻辑 2023-11-27T15:21:55+08:00 fengyw fengyw@roncoo.com https://gitcode.net/roncoocom/roncoo-education/-/commit/136294a40644b1f3bc983495195b59c16fd525da feat: 优化验证码发送逻辑 2023-11-27T15:27:06+08:00 fengyw fengyw@roncoo.com https://gitcode.net/roncoocom/roncoo-education/-/commit/2cc635f7c2f8158a9f04fe4cea7cc9d15d6cb47b feat: 优化验证码发送逻辑 2023-11-27T15:29:23+08:00 fengyw fengyw@roncoo.com https://gitcode.net/roncoocom/roncoo-education/-/commit/39ebea1aac450e00534c5b79f5cb05660f08da2d feat: 优化验证码发送逻辑 2023-11-27T15:37:14+08:00 fengyw fengyw@roncoo.com https://gitcode.net/roncoocom/roncoo-education/-/commit/08d0bcaf81617ade66bcda95e58c5f9734270d4c feat: 优化验证码发送逻辑 2023-11-27T15:39:19+08:00 fengyw fengyw@roncoo.com https://gitcode.net/roncoocom/roncoo-education/-/commit/28d4a8b3673d6a36662a452c7cdf676316c3b9ec feat: 优化验证码发送逻辑 2023-11-27T15:40:17+08:00 fengyw fengyw@roncoo.com https://gitcode.net/roncoocom/roncoo-education/-/commit/90b5c3c61ed95608cb70edfc27d2419fcb0ff748 feat: 异常处理 2023-11-27T15:51:29+08:00 fengyw fengyw@roncoo.com
......@@ -29,7 +29,7 @@ public class CacheRedis {
public <T> T set(String key, T t) {
if (t != null) {
String value = t.toString();
if (!(t instanceof String)) {
if (!(t instanceof String || t instanceof Long || t instanceof Integer)) {
value = JSUtil.toJsonString(t);
}
stringRedisTemplate.opsForValue().set(key, value, timeToLive, TimeUnit.MILLISECONDS);
......@@ -43,7 +43,7 @@ public class CacheRedis {
public <T> T set(String key, T t, int time, TimeUnit timeUnit) {
if (t != null) {
String value = t.toString();
if (!(t instanceof String)) {
if (!(t instanceof String || t instanceof Long || t instanceof Integer)) {
value = JSUtil.toJsonString(t);
}
stringRedisTemplate.opsForValue().set(key, value, time, timeUnit);
......
......@@ -5,11 +5,15 @@ import com.roncoo.education.common.core.base.Result;
import com.roncoo.education.common.core.tools.JSUtil;
import feign.FeignException;
import org.springframework.http.HttpStatus;
import org.springframework.util.StringUtils;
import org.springframework.validation.FieldError;
import org.springframework.web.bind.MethodArgumentNotValidException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestControllerAdvice;
import java.util.Map;
import java.util.StringJoiner;
/**
* @author wujing
......@@ -18,27 +22,40 @@ import java.util.Map;
public class HandlerException extends BaseController {
@ExceptionHandler({FeignException.class})
@ResponseStatus(HttpStatus.OK)
@ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
public Result<String> processBizException(FeignException e) {
String msg = e.getCause().toString().split("\n|\r\n|\r")[1];
log.error(msg);
@SuppressWarnings("unchecked")
Map<String, Object> m = JSUtil.parseObject(msg, Map.class);
String msg = e.getMessage();
if (!StringUtils.hasText(msg)) {
return Result.error("服务繁忙,请重试");
}
log.error("FeignException, {}", msg);
Map<String, Object> m = JSUtil.parseArray(msg.substring(msg.lastIndexOf("[{")), Map.class).get(0);
if (null != m.get("message")) {
return Result.error(m.get("message").toString());
}
return Result.error("服务繁忙,请重试");
}
@ExceptionHandler({MethodArgumentNotValidException.class})
@ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
public Result<String> processException(MethodArgumentNotValidException ex) {
StringJoiner joiner = new StringJoiner("、");
for (FieldError fieldError : ex.getBindingResult().getFieldErrors()) {
joiner.add(fieldError.getDefaultMessage());
}
log.error("MethodArgumentNotValidException, {}", joiner);
return Result.error(joiner.toString());
}
@ExceptionHandler({BaseException.class})
@ResponseStatus(HttpStatus.OK)
@ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
public Result<String> processException(BaseException e) {
log.error("BaseException", e);
return Result.error(e.getMessage());
}
@ExceptionHandler({Exception.class})
@ResponseStatus(HttpStatus.OK)
@ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
public Result<String> processException(Exception e) {
log.error("Exception", e);
return Result.error("服务繁忙,请重试");
......
......@@ -178,15 +178,14 @@ public class ApiUsersBiz extends BaseBiz {
private Boolean sendCodeCheck(String mobile) {
String count = cacheRedis.get(Constants.RedisPre.CODE_STAT + mobile);
if (StringUtils.hasText(count)) {
int countNum = Integer.valueOf(count);
int countNum = cacheRedis.set(Constants.RedisPre.CODE_STAT + mobile, Integer.valueOf(count).intValue() + 1, 5, TimeUnit.MINUTES);
if (countNum < 2) {
cacheRedis.set(Constants.RedisPre.CODE_STAT + mobile, countNum++);
return Boolean.TRUE;
}
} else {
cacheRedis.set(Constants.RedisPre.CODE_STAT + mobile, 1);
return Boolean.FALSE;
}
return Boolean.FALSE;
cacheRedis.set(Constants.RedisPre.CODE_STAT + mobile, 1, 5, TimeUnit.MINUTES);
return Boolean.TRUE;
}
public Result<String> password(PasswordReq req) {
......