From 49baa39cd16fca9d778696050eacdcaf75879a0a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A2=A8=E5=A4=A7=E5=8F=94?= <494979559@qq.com> Date: Thu, 18 Jul 2024 18:17:35 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AF=86=E9=92=A5=E5=AF=B9=E6=8E=A5=E5=8F=A3?= =?UTF-8?q?=E5=AE=8C=E5=96=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ss/access/service/AccessService.java | 5 +++- .../service/impl/AccessServiceImpl.java | 14 ++++++++-- .../controller/api/ApiDeviceController.java | 17 ------------ .../AppAccessController.java} | 26 +++++++++++++++---- 4 files changed, 37 insertions(+), 25 deletions(-) delete mode 100644 smart-switch-web/src/main/java/com/ruoyi/web/controller/api/ApiDeviceController.java rename smart-switch-web/src/main/java/com/ruoyi/web/controller/{api/ApiAccessController.java => app/AppAccessController.java} (52%) diff --git a/smart-switch-service/src/main/java/com/ruoyi/ss/access/service/AccessService.java b/smart-switch-service/src/main/java/com/ruoyi/ss/access/service/AccessService.java index ea8e74e8..d49fb3ac 100644 --- a/smart-switch-service/src/main/java/com/ruoyi/ss/access/service/AccessService.java +++ b/smart-switch-service/src/main/java/com/ruoyi/ss/access/service/AccessService.java @@ -88,5 +88,8 @@ public interface AccessService */ boolean deleteCache(String accessKey); - AccessApplyVO reset(Long accessId); + /** + * 重置秘钥 + */ + String reset(Long accessId); } diff --git a/smart-switch-service/src/main/java/com/ruoyi/ss/access/service/impl/AccessServiceImpl.java b/smart-switch-service/src/main/java/com/ruoyi/ss/access/service/impl/AccessServiceImpl.java index 1dbd0985..55014578 100644 --- a/smart-switch-service/src/main/java/com/ruoyi/ss/access/service/impl/AccessServiceImpl.java +++ b/smart-switch-service/src/main/java/com/ruoyi/ss/access/service/impl/AccessServiceImpl.java @@ -208,7 +208,17 @@ public class AccessServiceImpl implements AccessService } @Override - public AccessApplyVO reset(Long accessId) { - return null; + public String reset(Long accessId) { + ServiceUtil.assertion(accessId == null, "秘钥ID不允许为空"); + + String secret = SecurityUtils.genSecret(64); + Access access = new Access(); + access.setAccessId(accessId); + access.setAccessSecret(secret); + + int update = accessMapper.updateAccess(access); + ServiceUtil.assertion(update != 1, "重置秘钥失败"); + + return secret; } } diff --git a/smart-switch-web/src/main/java/com/ruoyi/web/controller/api/ApiDeviceController.java b/smart-switch-web/src/main/java/com/ruoyi/web/controller/api/ApiDeviceController.java deleted file mode 100644 index ea6d0bc8..00000000 --- a/smart-switch-web/src/main/java/com/ruoyi/web/controller/api/ApiDeviceController.java +++ /dev/null @@ -1,17 +0,0 @@ -package com.ruoyi.web.controller.api; - -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; - -/** - * 第三方API 设备Controller - * @author wjh - * 2024/7/17 - */ -@RestController -@RequestMapping("/openapi/v1/device") -public class ApiDeviceController { - - - -} diff --git a/smart-switch-web/src/main/java/com/ruoyi/web/controller/api/ApiAccessController.java b/smart-switch-web/src/main/java/com/ruoyi/web/controller/app/AppAccessController.java similarity index 52% rename from smart-switch-web/src/main/java/com/ruoyi/web/controller/api/ApiAccessController.java rename to smart-switch-web/src/main/java/com/ruoyi/web/controller/app/AppAccessController.java index f80457e5..9462dfd3 100644 --- a/smart-switch-web/src/main/java/com/ruoyi/web/controller/api/ApiAccessController.java +++ b/smart-switch-web/src/main/java/com/ruoyi/web/controller/app/AppAccessController.java @@ -1,22 +1,26 @@ -package com.ruoyi.web.controller.api; +package com.ruoyi.web.controller.app; import com.ruoyi.common.core.controller.BaseController; import com.ruoyi.common.core.domain.AjaxResult; -import com.ruoyi.framework.web.service.SysLoginService; +import com.ruoyi.common.core.page.TableDataInfo; +import com.ruoyi.ss.access.domain.AccessQuery; import com.ruoyi.ss.access.domain.AccessVO; import com.ruoyi.ss.access.service.AccessService; import io.swagger.annotations.ApiOperation; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; +import java.util.List; +import java.util.Objects; + /** * 第三方认证接口 * @author wjh * 2024/7/17 */ @RestController -@RequestMapping("/openapi/v1/access") -public class ApiAccessController extends BaseController { +@RequestMapping("/app/access") +public class AppAccessController extends BaseController { @Autowired private AccessService accessService; @@ -31,7 +35,19 @@ public class ApiAccessController extends BaseController { @PutMapping("/{accessId}/reset") public AjaxResult reset(@PathVariable Long accessId) { AccessVO access = accessService.selectAccessByAccessId(accessId); - return success(accessService.reset(accessId)); + if (access == null || !Objects.equals(access.getUserId(), getUserId())) { + return error("您无权操作"); + } + return AjaxResult.success("操作成功", accessService.reset(accessId)); + } + + @ApiOperation("查询本人秘钥列表") + @GetMapping("/list") + public TableDataInfo list(AccessQuery query) { + query.setUserId(getUserId()); + startPage(); + List list = accessService.selectAccessList(query); + return getDataTable(list); } }