From 089d208760c4513eead2431905813e4532ad1d62 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B1=B1=E4=B8=9C=E4=BA=91=E5=88=99?= Date: Fri, 28 Feb 2025 11:10:50 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E6=B6=88=E6=81=AF=E9=80=9A?= =?UTF-8?q?=E7=9F=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../yunze/cn/config/RabbitMQConnection.java | 4 +- .../yunze/common/constant/CacheConstants.java | 44 ++++++++ .../exception/user/BlackListException.java | 16 +++ .../user/UserNotExistsException.java | 16 +++ ...UserPasswordRetryLimitExceedException.java | 16 +++ .../context/AuthenticationContextHolder.java | 28 +++++ .../context/PermissionContextHolder.java | 27 +++++ .../mapper/mysql/SysNoticeMapper.xml | 1 + .../src/components/message/notification.vue | 101 ++++++++++++++++++ yunze-ui/src/layout/components/Navbar.vue | 71 ++++++++++-- 10 files changed, 311 insertions(+), 13 deletions(-) create mode 100644 yunze-common/src/main/java/com/yunze/common/constant/CacheConstants.java create mode 100644 yunze-common/src/main/java/com/yunze/common/exception/user/BlackListException.java create mode 100644 yunze-common/src/main/java/com/yunze/common/exception/user/UserNotExistsException.java create mode 100644 yunze-common/src/main/java/com/yunze/common/exception/user/UserPasswordRetryLimitExceedException.java create mode 100644 yunze-framework/src/main/java/com/yunze/framework/security/context/AuthenticationContextHolder.java create mode 100644 yunze-framework/src/main/java/com/yunze/framework/security/context/PermissionContextHolder.java create mode 100644 yunze-ui/src/components/message/notification.vue diff --git a/yunze-business/src/main/java/com/yunze/cn/config/RabbitMQConnection.java b/yunze-business/src/main/java/com/yunze/cn/config/RabbitMQConnection.java index 6d70321..487cb30 100644 --- a/yunze-business/src/main/java/com/yunze/cn/config/RabbitMQConnection.java +++ b/yunze-business/src/main/java/com/yunze/cn/config/RabbitMQConnection.java @@ -57,8 +57,8 @@ public class RabbitMQConnection { connectionFactory.setPort(5672); connectionFactory.setRequestedHeartbeat( 40 ); //4.设置账户和密码 - connectionFactory.setUsername("AhZywl#Mq"); - connectionFactory.setPassword("ZhiYuanWuLian@0317"); + connectionFactory.setUsername("test"); + connectionFactory.setPassword("test@2018"); //5.设置VirtualHost connectionFactory.setVirtualHost("/VirtualHosts"); return connectionFactory.newConnection(); diff --git a/yunze-common/src/main/java/com/yunze/common/constant/CacheConstants.java b/yunze-common/src/main/java/com/yunze/common/constant/CacheConstants.java new file mode 100644 index 0000000..56fe418 --- /dev/null +++ b/yunze-common/src/main/java/com/yunze/common/constant/CacheConstants.java @@ -0,0 +1,44 @@ +package com.yunze.common.constant; + +/** + * 缓存的key 常量 + * + * @author ruoyi + */ +public class CacheConstants +{ + /** + * 登录用户 redis key + */ + public static final String LOGIN_TOKEN_KEY = "login_tokens:"; + + /** + * 验证码 redis key + */ + public static final String CAPTCHA_CODE_KEY = "captcha_codes:"; + + /** + * 参数管理 cache key + */ + public static final String SYS_CONFIG_KEY = "sys_config:"; + + /** + * 字典管理 cache key + */ + public static final String SYS_DICT_KEY = "sys_dict:"; + + /** + * 防重提交 redis key + */ + public static final String REPEAT_SUBMIT_KEY = "repeat_submit:"; + + /** + * 限流 redis key + */ + public static final String RATE_LIMIT_KEY = "rate_limit:"; + + /** + * 登录账户密码错误次数 redis key + */ + public static final String PWD_ERR_CNT_KEY = "pwd_err_cnt:"; +} diff --git a/yunze-common/src/main/java/com/yunze/common/exception/user/BlackListException.java b/yunze-common/src/main/java/com/yunze/common/exception/user/BlackListException.java new file mode 100644 index 0000000..507c1ca --- /dev/null +++ b/yunze-common/src/main/java/com/yunze/common/exception/user/BlackListException.java @@ -0,0 +1,16 @@ +package com.yunze.common.exception.user; + +/** + * 黑名单IP异常类 + * + * @author ruoyi + */ +public class BlackListException extends UserException +{ + private static final long serialVersionUID = 1L; + + public BlackListException() + { + super("login.blocked", null); + } +} diff --git a/yunze-common/src/main/java/com/yunze/common/exception/user/UserNotExistsException.java b/yunze-common/src/main/java/com/yunze/common/exception/user/UserNotExistsException.java new file mode 100644 index 0000000..8e47ec5 --- /dev/null +++ b/yunze-common/src/main/java/com/yunze/common/exception/user/UserNotExistsException.java @@ -0,0 +1,16 @@ +package com.yunze.common.exception.user; + +/** + * 用户不存在异常类 + * + * @author ruoyi + */ +public class UserNotExistsException extends UserException +{ + private static final long serialVersionUID = 1L; + + public UserNotExistsException() + { + super("user.not.exists", null); + } +} diff --git a/yunze-common/src/main/java/com/yunze/common/exception/user/UserPasswordRetryLimitExceedException.java b/yunze-common/src/main/java/com/yunze/common/exception/user/UserPasswordRetryLimitExceedException.java new file mode 100644 index 0000000..79f7785 --- /dev/null +++ b/yunze-common/src/main/java/com/yunze/common/exception/user/UserPasswordRetryLimitExceedException.java @@ -0,0 +1,16 @@ +package com.yunze.common.exception.user; + +/** + * 用户错误最大次数异常类 + * + * @author ruoyi + */ +public class UserPasswordRetryLimitExceedException extends UserException +{ + private static final long serialVersionUID = 1L; + + public UserPasswordRetryLimitExceedException(int retryLimitCount, int lockTime) + { + super("user.password.retry.limit.exceed", new Object[] { retryLimitCount, lockTime }); + } +} diff --git a/yunze-framework/src/main/java/com/yunze/framework/security/context/AuthenticationContextHolder.java b/yunze-framework/src/main/java/com/yunze/framework/security/context/AuthenticationContextHolder.java new file mode 100644 index 0000000..d50cf24 --- /dev/null +++ b/yunze-framework/src/main/java/com/yunze/framework/security/context/AuthenticationContextHolder.java @@ -0,0 +1,28 @@ +package com.yunze.framework.security.context; + +import org.springframework.security.core.Authentication; + +/** + * 身份验证信息 + * + * @author ruoyi + */ +public class AuthenticationContextHolder +{ + private static final ThreadLocal contextHolder = new ThreadLocal<>(); + + public static Authentication getContext() + { + return contextHolder.get(); + } + + public static void setContext(Authentication context) + { + contextHolder.set(context); + } + + public static void clearContext() + { + contextHolder.remove(); + } +} diff --git a/yunze-framework/src/main/java/com/yunze/framework/security/context/PermissionContextHolder.java b/yunze-framework/src/main/java/com/yunze/framework/security/context/PermissionContextHolder.java new file mode 100644 index 0000000..5365622 --- /dev/null +++ b/yunze-framework/src/main/java/com/yunze/framework/security/context/PermissionContextHolder.java @@ -0,0 +1,27 @@ +package com.yunze.framework.security.context; + +import com.yunze.common.core.text.Convert; +import org.springframework.web.context.request.RequestAttributes; +import org.springframework.web.context.request.RequestContextHolder; + +/** + * 权限信息 + * + * @author ruoyi + */ +public class PermissionContextHolder +{ + private static final String PERMISSION_CONTEXT_ATTRIBUTES = "PERMISSION_CONTEXT"; + + public static void setContext(String permission) + { + RequestContextHolder.currentRequestAttributes().setAttribute(PERMISSION_CONTEXT_ATTRIBUTES, permission, + RequestAttributes.SCOPE_REQUEST); + } + + public static String getContext() + { + return Convert.toStr(RequestContextHolder.currentRequestAttributes().getAttribute(PERMISSION_CONTEXT_ATTRIBUTES, + RequestAttributes.SCOPE_REQUEST)); + } +} diff --git a/yunze-system/src/main/resources/mapper/mysql/SysNoticeMapper.xml b/yunze-system/src/main/resources/mapper/mysql/SysNoticeMapper.xml index e22aab8..2e4e2af 100644 --- a/yunze-system/src/main/resources/mapper/mysql/SysNoticeMapper.xml +++ b/yunze-system/src/main/resources/mapper/mysql/SysNoticeMapper.xml @@ -40,6 +40,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" AND create_by like CONCAT( #{createBy}, '%') + ORDER BY create_time DESC diff --git a/yunze-ui/src/components/message/notification.vue b/yunze-ui/src/components/message/notification.vue new file mode 100644 index 0000000..825cd1c --- /dev/null +++ b/yunze-ui/src/components/message/notification.vue @@ -0,0 +1,101 @@ + + + + + diff --git a/yunze-ui/src/layout/components/Navbar.vue b/yunze-ui/src/layout/components/Navbar.vue index 3cb1a92..5650b51 100644 --- a/yunze-ui/src/layout/components/Navbar.vue +++ b/yunze-ui/src/layout/components/Navbar.vue @@ -15,16 +15,16 @@
@@ -61,6 +60,7 @@
+ @@ -75,21 +75,40 @@ import SizeSelect from '@/components/SizeSelect' import YunZeGit from '@/components/RuoYi/Git' import YunZeDoc from '@/components/RuoYi/Doc' import MyCardHeaderSearch from '@/components/MyCardHeaderSearch' +import Notification from '@/components/message/notification' - - +import { listNotice, getNotice, delNotice, addNotice, updateNotice } from "@/api/system/notice"; export default { + components: { + Notification, MyCardHeaderSearch, Breadcrumb, TopNav, Hamburger, Screenfull, SizeSelect, - YunZeGit, YunZeDoc }, + data(){ + return{ + visable:false, + notifyValue:0, + noticeList:[], // 查询参数 + queryParams: { + pageNum: 1, + pageSize: 10, + noticeTitle: undefined, + createBy: undefined, + status: undefined + }, + + } + }, + created() { + this.getList() + }, /*Search,*/ computed: { ...mapGetters([ @@ -115,9 +134,33 @@ export default { } }, methods: { + /** 查询公告列表 */ + getList() { + listNotice(this.queryParams).then(response => { + this.noticeList = response.rows; + this.notifyValue = response.total; + // if (this.notifyValue>0){ + // this.$notify({ + // title: '提示', + // offset: 70, + // message: '您当前有未读的消息,请注意查看 !', + // type: 'success', + // onClick: () => { + // this.visable=true; + // this.$refs.toNotifices.currentNotifices(); + // } + // }); + // } + }); + }, toggleSideBar() { this.$store.dispatch('app/toggleSideBar') }, + showNotifices(){ + this.getList() + this.visable=true; + this.$refs.toNotifices.currentNotifices(); + }, async logout() { this.$confirm('确定注销并退出系统吗?', '提示', { confirmButtonText: '确定', @@ -133,7 +176,14 @@ export default { } -