From 28bbb285c284ebd02c85c6abbe1107adf2c31569 Mon Sep 17 00:00:00 2001 From: OpenCode Date: Mon, 27 Jul 2026 19:18:16 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BB=A3=E7=90=86App=E7=AB=AF=E7=99=BD?= =?UTF-8?q?=E5=90=8D=E5=8D=95=E6=8E=A5=E5=8F=A3=E5=AE=8C=E5=96=84=20-=20?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0@CoolRestController(api=3Dlist)=E4=BF=AE?= =?UTF-8?q?=E5=A4=8D=E8=B7=AF=E7=94=B1=E6=B3=A8=E5=86=8C=EF=BC=8CqueryWrap?= =?UTF-8?q?per=E9=9D=9E=E7=A9=BA=E4=BF=AE=E5=A4=8D=EF=BC=8C=E6=96=B0?= =?UTF-8?q?=E5=A2=9EaddWhitelist/whitelist/currentIp=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/AppAgentInfoController.java | 53 ++++++++++++++++++- 1 file changed, 51 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/cool/modules/agent/controller/app/AppAgentInfoController.java b/src/main/java/com/cool/modules/agent/controller/app/AppAgentInfoController.java index 35b491a..3f3c8da 100644 --- a/src/main/java/com/cool/modules/agent/controller/app/AppAgentInfoController.java +++ b/src/main/java/com/cool/modules/agent/controller/app/AppAgentInfoController.java @@ -3,24 +3,32 @@ package com.cool.modules.agent.controller.app; import cn.hutool.json.JSONObject; import com.cool.core.annotation.CoolRestController; import com.cool.core.request.R; +import com.cool.modules.agent.entity.AgentWhitelistEntity; import com.cool.modules.agent.service.AgentInfoService; +import com.cool.modules.agent.service.AgentWhitelistService; +import com.mybatisflex.core.query.QueryWrapper; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.tags.Tag; +import jakarta.servlet.http.HttpServletRequest; import lombok.RequiredArgsConstructor; import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestAttribute; +import static com.cool.modules.agent.entity.table.AgentWhitelistEntityTableDef.AGENT_WHITELIST_ENTITY; + @RequiredArgsConstructor @Tag(name = "代理", description = "App端代理") -@CoolRestController +@CoolRestController(api = {"list"}) public class AppAgentInfoController { private final AgentInfoService agentInfoService; + private final AgentWhitelistService agentWhitelistService; @Operation(summary = "代理列表") @GetMapping("/list") public R list(@RequestAttribute JSONObject requestParams) { - return R.ok(agentInfoService.list(requestParams, null)); + return R.ok(agentInfoService.list(requestParams, QueryWrapper.create())); } @Operation(summary = "代理详情") @@ -29,4 +37,45 @@ public class AppAgentInfoController { Long id = requestParams.getLong("id"); return R.ok(agentInfoService.info(id)); } + + @Operation(summary = "获取当前IP") + @GetMapping("/currentIp") + public R currentIp(HttpServletRequest request) { + String ip = request.getHeader("X-Forwarded-For"); + if (ip == null || ip.isEmpty()) { + ip = request.getHeader("X-Real-IP"); + } + if (ip == null || ip.isEmpty()) { + ip = request.getRemoteAddr(); + } + if (ip != null && ip.contains(",")) { + ip = ip.split(",")[0].trim(); + } + JSONObject result = new JSONObject(); + result.set("ip", ip); + return R.ok(result); + } + + @Operation(summary = "添加白名单IP") + @PostMapping("/addWhitelist") + public R addWhitelist(@RequestAttribute JSONObject requestParams) { + Long agentInfoId = requestParams.getLong("agentInfoId"); + String ipAddress = requestParams.getStr("ipAddress"); + + AgentWhitelistEntity entity = new AgentWhitelistEntity(); + entity.setAgentInfoId(agentInfoId); + entity.setIpAddress(ipAddress); + agentWhitelistService.save(entity); + + return R.ok(entity); + } + + @Operation(summary = "获取白名单列表") + @GetMapping("/whitelist") + public R whitelist(@RequestAttribute JSONObject requestParams) { + Long agentInfoId = requestParams.getLong("agentInfoId"); + QueryWrapper qw = QueryWrapper.create() + .where(AGENT_WHITELIST_ENTITY.AGENT_INFO_ID.eq(agentInfoId)); + return R.ok(agentWhitelistService.list(requestParams, qw)); + } }