From e59dc804abbba5dd42c7adb5181f98e6d78ad47e Mon Sep 17 00:00:00 2001 From: ZhouXY108 Date: Thu, 16 Feb 2023 11:52:07 +0800 Subject: [PATCH 1/5] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=9F=A5=E8=AF=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/MenuManagementController.java | 10 ++- .../system/application/query/MenuQueries.java | 22 +++++++ .../application/query/PermissionQueries.java | 10 --- .../query/params/MenuQueryParams.java | 18 ++++++ .../query/result/MenuViewObject.java | 64 +++++-------------- .../service/MenuManagementService.java | 13 +++- 6 files changed, 76 insertions(+), 61 deletions(-) create mode 100644 plusone-system/plusone-system-application/src/main/java/xyz/zhouxy/plusone/system/application/query/MenuQueries.java delete mode 100644 plusone-system/plusone-system-application/src/main/java/xyz/zhouxy/plusone/system/application/query/PermissionQueries.java create mode 100644 plusone-system/plusone-system-application/src/main/java/xyz/zhouxy/plusone/system/application/query/params/MenuQueryParams.java diff --git a/plusone-system/plusone-system-application/src/main/java/xyz/zhouxy/plusone/system/application/controller/MenuManagementController.java b/plusone-system/plusone-system-application/src/main/java/xyz/zhouxy/plusone/system/application/controller/MenuManagementController.java index c1ca515..1c7c59e 100644 --- a/plusone-system/plusone-system-application/src/main/java/xyz/zhouxy/plusone/system/application/controller/MenuManagementController.java +++ b/plusone-system/plusone-system-application/src/main/java/xyz/zhouxy/plusone/system/application/controller/MenuManagementController.java @@ -15,6 +15,7 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; +import xyz.zhouxy.plusone.system.application.query.params.MenuQueryParams; import xyz.zhouxy.plusone.system.application.service.MenuManagementService; import xyz.zhouxy.plusone.system.application.service.command.CreateMenuCommand; import xyz.zhouxy.plusone.system.application.service.command.UpdateMenuCommand; @@ -66,7 +67,14 @@ public class MenuManagementController { public RestfulResult findById(@PathVariable("id") Long id) { adminAuthLogic.checkPermission("sys-menu-details"); var result = service.findById(id); - return RestfulResult.success("查询成功", result); + return success("查询成功", result); + } + + @GetMapping + public RestfulResult queryMenuTree(MenuQueryParams queryParams) { + adminAuthLogic.checkPermission("sys-menu-query"); + var result = service.queryMenuTree(queryParams); + return success("查询成功", result); } @GetMapping("queryByAccountId") diff --git a/plusone-system/plusone-system-application/src/main/java/xyz/zhouxy/plusone/system/application/query/MenuQueries.java b/plusone-system/plusone-system-application/src/main/java/xyz/zhouxy/plusone/system/application/query/MenuQueries.java new file mode 100644 index 0000000..33a62d2 --- /dev/null +++ b/plusone-system/plusone-system-application/src/main/java/xyz/zhouxy/plusone/system/application/query/MenuQueries.java @@ -0,0 +1,22 @@ +package xyz.zhouxy.plusone.system.application.query; + +import java.util.List; + +import org.springframework.stereotype.Component; + +import xyz.zhouxy.plusone.system.application.query.params.MenuQueryParams; +import xyz.zhouxy.plusone.system.application.query.result.MenuViewObject; + +/** + * + * + * @author ZhouXY + */ +@Component +public class MenuQueries { + + public List queryMenuTree(MenuQueryParams queryParams) { + return null; + } + +} diff --git a/plusone-system/plusone-system-application/src/main/java/xyz/zhouxy/plusone/system/application/query/PermissionQueries.java b/plusone-system/plusone-system-application/src/main/java/xyz/zhouxy/plusone/system/application/query/PermissionQueries.java deleted file mode 100644 index 4de7330..0000000 --- a/plusone-system/plusone-system-application/src/main/java/xyz/zhouxy/plusone/system/application/query/PermissionQueries.java +++ /dev/null @@ -1,10 +0,0 @@ -package xyz.zhouxy.plusone.system.application.query; - -/** - * - * - * @author ZhouXY - */ -public interface PermissionQueries { - // TODO【添加】 权限信息查询器 -} diff --git a/plusone-system/plusone-system-application/src/main/java/xyz/zhouxy/plusone/system/application/query/params/MenuQueryParams.java b/plusone-system/plusone-system-application/src/main/java/xyz/zhouxy/plusone/system/application/query/params/MenuQueryParams.java new file mode 100644 index 0000000..e691338 --- /dev/null +++ b/plusone-system/plusone-system-application/src/main/java/xyz/zhouxy/plusone/system/application/query/params/MenuQueryParams.java @@ -0,0 +1,18 @@ +package xyz.zhouxy.plusone.system.application.query.params; + +import lombok.Getter; +import lombok.Setter; +import lombok.ToString; +import xyz.zhouxy.plusone.constant.EntityStatus; + +@ToString +public class MenuQueryParams { + private @Getter @Setter String name; + private @Getter @Setter String path; + private @Getter @Setter String title; + private @Getter @Setter Boolean hidden; + private @Getter @Setter EntityStatus status; + private @Getter @Setter String component; + private @Getter @Setter Boolean cache; + private @Getter @Setter String resource; +} diff --git a/plusone-system/plusone-system-application/src/main/java/xyz/zhouxy/plusone/system/application/query/result/MenuViewObject.java b/plusone-system/plusone-system-application/src/main/java/xyz/zhouxy/plusone/system/application/query/result/MenuViewObject.java index 316eafe..e2f732f 100644 --- a/plusone-system/plusone-system-application/src/main/java/xyz/zhouxy/plusone/system/application/query/result/MenuViewObject.java +++ b/plusone-system/plusone-system-application/src/main/java/xyz/zhouxy/plusone/system/application/query/result/MenuViewObject.java @@ -25,60 +25,28 @@ import xyz.zhouxy.plusone.system.domain.model.menu.Menu.MenuType; @JsonInclude(JsonInclude.Include.NON_NULL) public class MenuViewObject implements IWithOrderNumber { - @Getter - @Setter - Integer type; + private @Getter @Setter Integer type; - @Getter - @Setter - String typeName; + private @Getter @Setter String typeName; - @Getter - @Setter - Long id; - @Getter - @Setter - Long parentId; + private @Getter @Setter Long id; + private @Getter @Setter Long parentId; - @Getter - @Setter - String name; + private @Getter @Setter String name; // 若 type 为 MENU_ITEM 且 path 以 http:// 或 https:// 开头则被识别为外链 - @Getter - @Setter - String path; - @Getter - @Setter - String title; - @Getter - @Setter - String icon; - @Getter - @Setter - boolean hidden; - @Getter - @Setter - int orderNumber; - @Getter - @Setter - Integer status; - @Getter - @Setter - String remarks; + private @Getter @Setter String path; + private @Getter @Setter String title; + private @Getter @Setter String icon; + private @Getter @Setter boolean hidden; + private @Getter @Setter int orderNumber; + private @Getter @Setter Integer status; + private @Getter @Setter String remarks; // MENU_ITEM - @Getter - @Setter - String component; - @Getter - @Setter - Boolean cache; - @Getter - @Setter - String resource; - @Getter - @Setter - List actions; + private @Getter @Setter String component; + private @Getter @Setter Boolean cache; + private @Getter @Setter String resource; + private @Getter @Setter List actions; // MENU_LIST List children; diff --git a/plusone-system/plusone-system-application/src/main/java/xyz/zhouxy/plusone/system/application/service/MenuManagementService.java b/plusone-system/plusone-system-application/src/main/java/xyz/zhouxy/plusone/system/application/service/MenuManagementService.java index b8b07d4..ef57775 100644 --- a/plusone-system/plusone-system-application/src/main/java/xyz/zhouxy/plusone/system/application/service/MenuManagementService.java +++ b/plusone-system/plusone-system-application/src/main/java/xyz/zhouxy/plusone/system/application/service/MenuManagementService.java @@ -17,6 +17,8 @@ import xyz.zhouxy.plusone.constant.EntityStatus; import xyz.zhouxy.plusone.domain.IWithOrderNumber; import xyz.zhouxy.plusone.exception.DataNotExistException; import xyz.zhouxy.plusone.system.application.exception.UnsupportedMenuTypeException; +import xyz.zhouxy.plusone.system.application.query.MenuQueries; +import xyz.zhouxy.plusone.system.application.query.params.MenuQueryParams; import xyz.zhouxy.plusone.system.application.query.result.MenuViewObject; import xyz.zhouxy.plusone.system.application.service.command.CreateMenuCommand; import xyz.zhouxy.plusone.system.application.service.command.UpdateMenuCommand; @@ -36,10 +38,12 @@ public class MenuManagementService { private final MenuService menuService; private final MenuRepository menuRepository; + private final MenuQueries menuQueries; - MenuManagementService(MenuService roleRepository, MenuRepository menuRepository) { - this.menuService = roleRepository; + MenuManagementService(MenuService menuService, MenuRepository menuRepository, MenuQueries menuQueries) { + this.menuService = menuService; this.menuRepository = menuRepository; + this.menuQueries = menuQueries; } // ==================== create ==================== @@ -123,6 +127,11 @@ public class MenuManagementService { return MenuViewObject.of(menu.orElseThrow(DataNotExistException::new)); } + @Transactional(propagation = Propagation.SUPPORTS) + public List queryMenuTree(MenuQueryParams queryParams) { + return menuQueries.queryMenuTree(queryParams); + } + @Transactional(propagation = Propagation.SUPPORTS) public List queryByAccountId(Long accountId) { var menus = menuService.queryAllMenuListByAccountId(accountId); From b6301d2dc90e3befa314880339d9daa5af20930f Mon Sep 17 00:00:00 2001 From: ZhouXY108 Date: Tue, 4 Apr 2023 00:48:22 +0800 Subject: [PATCH 2/5] =?UTF-8?q?=E7=AE=80=E5=8C=96=E3=80=81=E9=87=8D?= =?UTF-8?q?=E6=9E=84=E4=BB=A3=E7=A0=81=E3=80=82=E4=BF=AE=E5=A4=8D=E9=94=99?= =?UTF-8?q?=E8=AF=AF=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../plusone/system/util/PasswordUtil.java | 32 ++++++++----------- 1 file changed, 13 insertions(+), 19 deletions(-) diff --git a/plusone-system/plusone-system-common/src/main/java/xyz/zhouxy/plusone/system/util/PasswordUtil.java b/plusone-system/plusone-system-common/src/main/java/xyz/zhouxy/plusone/system/util/PasswordUtil.java index 015a5f6..a924eff 100644 --- a/plusone-system/plusone-system-common/src/main/java/xyz/zhouxy/plusone/system/util/PasswordUtil.java +++ b/plusone-system/plusone-system-common/src/main/java/xyz/zhouxy/plusone/system/util/PasswordUtil.java @@ -7,9 +7,7 @@ import java.security.NoSuchAlgorithmException; import javax.annotation.Nonnull; -import lombok.extern.slf4j.Slf4j; -import xyz.zhouxy.plusone.constant.ErrorCodeConsts; -import xyz.zhouxy.plusone.exception.BizException; +import xyz.zhouxy.plusone.exception.SysException; import xyz.zhouxy.plusone.util.RandomUtil; /** @@ -17,7 +15,6 @@ import xyz.zhouxy.plusone.util.RandomUtil; * * @author ZhouXY */ -@Slf4j public final class PasswordUtil { private static final char[] SALT_BASE_CHAR_ARRAY = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ~`!@#$%^&*()_-+={}[]|\\:;\"',.<>?/" .toCharArray(); @@ -35,12 +32,12 @@ public final class PasswordUtil { int i = length > 0 ? length / 2 : 0; var passwordWithSalt = salt.substring(0, i) + password - + salt.substring(1); - String sha512Hex = sha512Hex(passwordWithSalt); - if (sha512Hex == null) { - throw new BizException(ErrorCodeConsts.DEFAULT_ERROR_CODE, "未知错误:哈希加密失败!"); + + salt.substring(i); + try { + return sha512Hex(passwordWithSalt); + } catch (NoSuchAlgorithmException e) { + throw new SysException(e); } - return sha512Hex; } /** @@ -57,15 +54,12 @@ public final class PasswordUtil { throw new IllegalStateException("Utility class"); } - private static String sha512Hex(String data) { - try { - MessageDigest messageDigest = MessageDigest.getInstance("SHA-512"); - messageDigest.update(data.getBytes(StandardCharsets.UTF_8)); - byte[] result = messageDigest.digest(); - return new BigInteger(1, result).toString(16); - } catch (NoSuchAlgorithmException e) { - log.error("{}", e); - } - return null; + @Nonnull + @SuppressWarnings("null") + private static String sha512Hex(String data) throws NoSuchAlgorithmException { + MessageDigest messageDigest = MessageDigest.getInstance("SHA-512"); + messageDigest.update(data.getBytes(StandardCharsets.UTF_8)); + byte[] result = messageDigest.digest(); + return new BigInteger(1, result).toString(16); } } From b2bc6b3a6f0bcf4df26960841fac77a7f78eb1c7 Mon Sep 17 00:00:00 2001 From: ZhouXY108 Date: Tue, 4 Apr 2023 00:54:15 +0800 Subject: [PATCH 3/5] =?UTF-8?q?=E5=BA=94=E6=8A=9B=E5=87=BA=20SysException?= =?UTF-8?q?=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../zhouxy/plusone/system/domain/model/account/Password.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/plusone-system/plusone-system-domain/src/main/java/xyz/zhouxy/plusone/system/domain/model/account/Password.java b/plusone-system/plusone-system-domain/src/main/java/xyz/zhouxy/plusone/system/domain/model/account/Password.java index d810c58..1e84525 100644 --- a/plusone-system/plusone-system-domain/src/main/java/xyz/zhouxy/plusone/system/domain/model/account/Password.java +++ b/plusone-system/plusone-system-domain/src/main/java/xyz/zhouxy/plusone/system/domain/model/account/Password.java @@ -8,9 +8,8 @@ import javax.annotation.Nonnull; import org.springframework.util.Assert; import xyz.zhouxy.plusone.commons.constant.PatternConsts; -import xyz.zhouxy.plusone.constant.ErrorCodeConsts; import xyz.zhouxy.plusone.domain.IValueObject; -import xyz.zhouxy.plusone.exception.BizException; +import xyz.zhouxy.plusone.exception.SysException; import xyz.zhouxy.plusone.system.util.PasswordUtil; /** @@ -37,7 +36,7 @@ public class Password implements IValueObject { } var salt = PasswordUtil.generateRandomSalt(); if (salt == null) { - throw new BizException(ErrorCodeConsts.DEFAULT_ERROR_CODE, "未知错误:生成随机盐失败"); + throw new SysException("未知错误:生成随机盐失败"); } this.saltVal = salt; this.passwordVal = PasswordUtil.hashPassword(password, salt); From 7ef077629645f32823e26fe559b46377244eee8c Mon Sep 17 00:00:00 2001 From: ZhouXY108 Date: Tue, 4 Apr 2023 00:55:04 +0800 Subject: [PATCH 4/5] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=AF=B9=20TencentCloudS?= =?UTF-8?q?DKException=20=E7=9A=84=E5=A4=84=E7=90=86=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../zhouxy/plusone/sms/TencentSmsServiceImpl.java | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/plusone-basic/plusone-basic-infrastructure/src/main/java/xyz/zhouxy/plusone/sms/TencentSmsServiceImpl.java b/plusone-basic/plusone-basic-infrastructure/src/main/java/xyz/zhouxy/plusone/sms/TencentSmsServiceImpl.java index 1355b6b..6e64628 100644 --- a/plusone-basic/plusone-basic-infrastructure/src/main/java/xyz/zhouxy/plusone/sms/TencentSmsServiceImpl.java +++ b/plusone-basic/plusone-basic-infrastructure/src/main/java/xyz/zhouxy/plusone/sms/TencentSmsServiceImpl.java @@ -1,5 +1,7 @@ package xyz.zhouxy.plusone.sms; +import org.springframework.stereotype.Service; + import com.tencentcloudapi.common.Credential; import com.tencentcloudapi.common.exception.TencentCloudSDKException; import com.tencentcloudapi.common.profile.ClientProfile; @@ -8,11 +10,8 @@ import com.tencentcloudapi.sms.v20210111.SmsClient; import com.tencentcloudapi.sms.v20210111.models.SendSmsRequest; import com.tencentcloudapi.sms.v20210111.models.SendSmsResponse; -import org.springframework.stereotype.Service; - import lombok.extern.slf4j.Slf4j; -import xyz.zhouxy.plusone.constant.ErrorCodeConsts; -import xyz.zhouxy.plusone.exception.BizException; +import xyz.zhouxy.plusone.exception.SysException; import xyz.zhouxy.plusone.sms.SmsProperties.SmsCredentialProperties; import xyz.zhouxy.plusone.sms.SmsProperties.SmsHttpProperties; import xyz.zhouxy.plusone.sms.SmsProperties.SmsProxyProperties; @@ -62,14 +61,13 @@ public class TencentSmsServiceImpl implements SmsService { var res = client.SendSms(req); // 输出json格式的字符串回包 - System.out.println(SendSmsResponse.toJsonString(res)); + log.info(SendSmsResponse.toJsonString(res)); // 也可以取出单个值,你可以通过官网接口文档或跳转到response对象的定义处查看返回字段的定义 // System.out.println(res.getRequestId()); } catch (TencentCloudSDKException e) { - log.error(e.getMessage(), e); - throw new BizException(ErrorCodeConsts.DEFAULT_ERROR_CODE, e); + throw new SysException(e); } } From 0dc78a2b890e67b0ea1ad171dab981673b3625b4 Mon Sep 17 00:00:00 2001 From: ZhouXY108 Date: Tue, 4 Apr 2023 01:08:08 +0800 Subject: [PATCH 5/5] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=20TODO?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../xyz/zhouxy/plusone/system/application/query/MenuQueries.java | 1 + 1 file changed, 1 insertion(+) diff --git a/plusone-system/plusone-system-application/src/main/java/xyz/zhouxy/plusone/system/application/query/MenuQueries.java b/plusone-system/plusone-system-application/src/main/java/xyz/zhouxy/plusone/system/application/query/MenuQueries.java index 33a62d2..ec1355b 100644 --- a/plusone-system/plusone-system-application/src/main/java/xyz/zhouxy/plusone/system/application/query/MenuQueries.java +++ b/plusone-system/plusone-system-application/src/main/java/xyz/zhouxy/plusone/system/application/query/MenuQueries.java @@ -16,6 +16,7 @@ import xyz.zhouxy.plusone.system.application.query.result.MenuViewObject; public class MenuQueries { public List queryMenuTree(MenuQueryParams queryParams) { + // TODO【添加】 实现该查询 return null; }