From b7551f7e7ab6634ed7485f37b12cdd2051b9a30a Mon Sep 17 00:00:00 2001 From: huangqizhen <15552608129@163.com> Date: Sat, 10 Jan 2026 13:47:35 +0800 Subject: [PATCH] =?UTF-8?q?1.7=20=E4=BF=AE=E6=94=B9=E9=A3=9E=E4=B9=A6?= =?UTF-8?q?=E6=8A=A5=E8=AD=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/example/demo/Util/FeiShuAlertUtil.java | 4 ++-- .../java/com/example/demo/config/EnvConfig.java | 14 +++++++---- .../demo/controller/Temporary/RedController.java | 28 +++++++++++++++------- 3 files changed, 32 insertions(+), 14 deletions(-) diff --git a/src/main/java/com/example/demo/Util/FeiShuAlertUtil.java b/src/main/java/com/example/demo/Util/FeiShuAlertUtil.java index 2cd59cf..824db0d 100644 --- a/src/main/java/com/example/demo/Util/FeiShuAlertUtil.java +++ b/src/main/java/com/example/demo/Util/FeiShuAlertUtil.java @@ -28,7 +28,7 @@ public class FeiShuAlertUtil { private static String webhookUrl; private static final String FEISHU_WEBHOOK_URL_PROD = "https://open.feishu.cn/open-apis/bot/v2/hook/1a515b19-b64f-46b7-9486-35842b9539fe"; - private static final String FEISHU_WEBHOOK_URL_TEST = webhookUrl; + private static final String FEISHU_WEBHOOK_URL_TEST = "https://open.feishu.cn/open-apis/bot/v2/hook/8dd2bcc4-6492-487b-9dc5-bb7b27d43ccf"; private static final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); static { @@ -115,7 +115,7 @@ public class FeiShuAlertUtil { String FEISHU_WEBHOOK_URL; String environment = EnvConfig.ENV; System.out.println("当前环境变量:" + environment); - if (Objects.equals(environment, "unknown") || environment.equals("dev")) { + if (Objects.equals(environment, "unknown") || environment.equals("dev")|| environment.equals("test")) { FEISHU_WEBHOOK_URL = FEISHU_WEBHOOK_URL_TEST; } else { FEISHU_WEBHOOK_URL = FEISHU_WEBHOOK_URL_PROD; diff --git a/src/main/java/com/example/demo/config/EnvConfig.java b/src/main/java/com/example/demo/config/EnvConfig.java index 1e7df48..e865522 100644 --- a/src/main/java/com/example/demo/config/EnvConfig.java +++ b/src/main/java/com/example/demo/config/EnvConfig.java @@ -1,6 +1,9 @@ package com.example.demo.config; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Configuration; +import org.springframework.stereotype.Component; /** * @program: GOLD @@ -10,9 +13,12 @@ import org.springframework.context.annotation.Configuration; * @create: 2025−06-29 13:55 * @Version 1.0 **/ -@Configuration +@Component public class EnvConfig { - public static final String ENV = "dev"; - public static final String ENV_PROD = "prod"; - public static final String ENV_TEST = "test"; + public static String ENV; + + @Value("${spring.profiles.active}") + public void setEnv(String env) { + EnvConfig.ENV = env; + } } diff --git a/src/main/java/com/example/demo/controller/Temporary/RedController.java b/src/main/java/com/example/demo/controller/Temporary/RedController.java index 14344d8..fb68368 100644 --- a/src/main/java/com/example/demo/controller/Temporary/RedController.java +++ b/src/main/java/com/example/demo/controller/Temporary/RedController.java @@ -1,8 +1,10 @@ package com.example.demo.controller.Temporary; +import com.example.demo.config.GlobalExceptionHandler; import com.example.demo.domain.vo.Red; import com.example.demo.domain.vo.coin.AuditRequest; import com.example.demo.domain.vo.coin.Result; +import com.example.demo.exception.SystemException; import com.example.demo.service.Temporary.RedService; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; @@ -27,26 +29,29 @@ import java.math.BigDecimal; public class RedController { @Autowired private RedService redService; + @Autowired + private GlobalExceptionHandler globalExceptionHandler; + @RequestMapping("/Red") public Result selectSum(@RequestBody Red red) { try { - redService.selectSum(red.getJwcode(),red.getType()); - } - catch (Exception e) { - return Result.error(e.getMessage()); + redService.selectSum(red.getJwcode(), red.getType()); + } catch (Exception e) { + return Result.error(e.getMessage()); } - return Result.success(redService.selectSum(red.getJwcode(),red.getType())); + return Result.success(redService.selectSum(red.getJwcode(), red.getType())); } + @RequestMapping("/RedList") public Result selectRedList(@RequestBody Red red) { try { redService.selectRedList(red.getJwcode()); - } - catch (Exception e) { - return Result.error(e.getMessage()); + } catch (Exception e) { + return Result.error(e.getMessage()); } return Result.success(redService.selectRedList(red.getJwcode())); } + @RequestMapping("/RedTest") public Result selectRedTest(@RequestBody AuditRequest request) throws Exception { try { @@ -55,8 +60,15 @@ public class RedController { } catch (Exception e) { return Result.error(e.getMessage()); + //redService.checkRed(request.getPrice(), request.getLinkId()); } return Result.success(redService.checkRed(request.getPrice(),request.getLinkId())); // return Result.success(redService.consumeRed(request.getLinkId())); + //return Result.success(redService.checkRed(request.getPrice(), request.getLinkId())); + } + + @RequestMapping("/ceshi") + public Result ceshi() { + throw new SystemException("测试异常"); } }