From 8ae8c5498da43d15e8fc511c7534fc9ff4a9c750 Mon Sep 17 00:00:00 2001 From: 疯狂的狮子Li <15040126243@163.com> Date: 星期六, 14 一月 2023 00:58:30 +0800 Subject: [PATCH] fix 修复 多数据源适配 jakarta 异常 bug (临时) --- ruoyi-common/src/main/java/com/ruoyi/common/captcha/UnsignedMathGenerator.java | 121 ++++++++++++++++++++------------------- 1 files changed, 62 insertions(+), 59 deletions(-) diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/captcha/UnsignedMathGenerator.java b/ruoyi-common/src/main/java/com/ruoyi/common/captcha/UnsignedMathGenerator.java index 9c0f26f..022fefc 100644 --- a/ruoyi-common/src/main/java/com/ruoyi/common/captcha/UnsignedMathGenerator.java +++ b/ruoyi-common/src/main/java/com/ruoyi/common/captcha/UnsignedMathGenerator.java @@ -6,6 +6,8 @@ import cn.hutool.core.util.RandomUtil; import com.ruoyi.common.utils.StringUtils; +import java.io.Serial; + /** * 鏃犵鍙疯绠楃敓鎴愬櫒 * @@ -13,73 +15,74 @@ */ public class UnsignedMathGenerator implements CodeGenerator { - private static final long serialVersionUID = -5514819971774091076L; + @Serial + private static final long serialVersionUID = -5514819971774091076L; - private static final String operators = "+-*"; + private static final String OPERATORS = "+-*"; - /** - * 鍙備笌璁$畻鏁板瓧鏈�澶ч暱搴� - */ - private final int numberLength; + /** + * 鍙備笌璁$畻鏁板瓧鏈�澶ч暱搴� + */ + private final int numberLength; - /** - * 鏋勯�� - */ - public UnsignedMathGenerator() { - this(2); - } + /** + * 鏋勯�� + */ + public UnsignedMathGenerator() { + this(2); + } - /** - * 鏋勯�� - * - * @param numberLength 鍙備笌璁$畻鏈�澶ф暟瀛椾綅鏁� - */ - public UnsignedMathGenerator(int numberLength) { - this.numberLength = numberLength; - } + /** + * 鏋勯�� + * + * @param numberLength 鍙備笌璁$畻鏈�澶ф暟瀛椾綅鏁� + */ + public UnsignedMathGenerator(int numberLength) { + this.numberLength = numberLength; + } - @Override - public String generate() { - final int limit = getLimit(); - int min = RandomUtil.randomInt(limit); - int max = RandomUtil.randomInt(min, limit); - String number1 = Integer.toString(max); - String number2 = Integer.toString(min); - number1 = StringUtils.rightPad(number1, this.numberLength, CharUtil.SPACE); - number2 = StringUtils.rightPad(number2, this.numberLength, CharUtil.SPACE); + @Override + public String generate() { + final int limit = getLimit(); + int a = RandomUtil.randomInt(limit); + int b = RandomUtil.randomInt(limit); + String max = Integer.toString(Math.max(a,b)); + String min = Integer.toString(Math.min(a,b)); + max = StringUtils.rightPad(max, this.numberLength, CharUtil.SPACE); + min = StringUtils.rightPad(min, this.numberLength, CharUtil.SPACE); - return number1 + RandomUtil.randomChar(operators) + number2 + '='; - } + return max + RandomUtil.randomChar(OPERATORS) + min + '='; + } - @Override - public boolean verify(String code, String userInputCode) { - int result; - try { - result = Integer.parseInt(userInputCode); - } catch (NumberFormatException e) { - // 鐢ㄦ埛杈撳叆闈炴暟瀛� - return false; - } + @Override + public boolean verify(String code, String userInputCode) { + int result; + try { + result = Integer.parseInt(userInputCode); + } catch (NumberFormatException e) { + // 鐢ㄦ埛杈撳叆闈炴暟瀛� + return false; + } - final int calculateResult = (int) Calculator.conversion(code); - return result == calculateResult; - } + final int calculateResult = (int) Calculator.conversion(code); + return result == calculateResult; + } - /** - * 鑾峰彇楠岃瘉鐮侀暱搴� - * - * @return 楠岃瘉鐮侀暱搴� - */ - public int getLength() { - return this.numberLength * 2 + 2; - } + /** + * 鑾峰彇楠岃瘉鐮侀暱搴� + * + * @return 楠岃瘉鐮侀暱搴� + */ + public int getLength() { + return this.numberLength * 2 + 2; + } - /** - * 鏍规嵁闀垮害鑾峰彇鍙備笌璁$畻鏁板瓧鏈�澶у�� - * - * @return 鏈�澶у�� - */ - private int getLimit() { - return Integer.parseInt("1" + StringUtils.repeat('0', this.numberLength)); - } + /** + * 鏍规嵁闀垮害鑾峰彇鍙備笌璁$畻鏁板瓧鏈�澶у�� + * + * @return 鏈�澶у�� + */ + private int getLimit() { + return Integer.parseInt("1" + StringUtils.repeat('0', this.numberLength)); + } } -- Gitblit v1.9.3