From 62ebf974a40725997a4514862b0c800ed80a2d7c Mon Sep 17 00:00:00 2001 From: xd <844539747@qq.com> Date: Fri, 26 Apr 2024 13:35:44 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B6=88=E6=81=AF=E5=8F=91=E9=80=81=E6=8C=87?= =?UTF-8?q?=E5=AE=9A=E7=94=A8=E6=88=B7=20=E9=85=8D=E7=BD=AE=E7=AE=A1?= =?UTF-8?q?=E7=90=86=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../system/SysNoticeController.java | 68 +++++++++++++------ .../com/ruoyi/system/domain/SysNotice.java | 7 -- .../ruoyi/system/domain/SysNoticeUser.java | 11 ++- .../ruoyi/system/mapper/SysNoticeMapper.java | 27 +++++++- .../system/service/ISysNoticeService.java | 26 ++++++- .../service/impl/SysNoticeServiceImpl.java | 40 ++++++++++- .../mapper/system/SysNoticeMapper.xml | 35 ++++++++-- ruoyi-ui/src/api/system/notice.js | 17 +++++ .../src/layout/components/NavbarNotice.vue | 4 +- .../components/Tools/PeopleSelect/index.vue | 1 + .../noticeUserSelect/index.vue | 38 +++++++++-- 11 files changed, 227 insertions(+), 47 deletions(-) diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysNoticeController.java b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysNoticeController.java index 6650e07..f896c75 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysNoticeController.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysNoticeController.java @@ -77,8 +77,8 @@ public class SysNoticeController extends BaseController notice.setCreateBy(getUsername()); noticeService.insertNotice(notice); //推送消息插入中间表 - Long userId = getLoginUser().getUserId();//当前登陆者 - insertNoticeUser(userId,notice,noticeService,null); + String userName = getLoginUser().getUsername();//当前登陆者 + insertNoticeUser(userName,notice,noticeService,null); }catch (Exception e){ return error("系统异常"); } @@ -115,8 +115,8 @@ public class SysNoticeController extends BaseController @GetMapping("/navbarNoticelist") public Map> navbarNoticelist() { - Long userId = getLoginUser().getUserId();//当前登陆者 - List list = noticeService.navbarNoticelist(userId); + String userName = getLoginUser().getUsername();//当前登陆者 + List list = noticeService.navbarNoticelist(userName); Map> groupedByNoticeType = list.stream() .collect(Collectors.groupingBy(SysNotice::getNoticeType)); for(String key:groupedByNoticeType.keySet()){ @@ -133,10 +133,14 @@ public class SysNoticeController extends BaseController public AjaxResult getNavbarNoticeInfo(@PathVariable Long noticeId) { try{ - //更新消息表 isRead字段 设置 为 1-已读 - SysNotice sysNotice = noticeService.selectNoticeById(noticeId); - sysNotice.setIsRead("1"); - noticeService.updateNotice(sysNotice); + String userName = getLoginUser().getUsername();//当前登陆者 + //更新sys_user_notice推送消息插入中间表 isRead字段 设置 为 1-已读 + SysNoticeUser sysNoticeUser = new SysNoticeUser(); + sysNoticeUser.setNoticeId(noticeId); + sysNoticeUser.setUserId(userName); + sysNoticeUser.setIsRead("1"); + noticeService.updateSysNoticeUser(sysNoticeUser); + }catch(Exception e){ return error("系统异常"); } @@ -145,11 +149,11 @@ public class SysNoticeController extends BaseController /** * 推送消息插入中间表 - * @param userId 发送对象排除自身 + * @param userName 发送对象排除自身 * @param notice 发送信息对象 * @param noticeService 接口 */ - public static void insertNoticeUser(Long userId,SysNotice notice,ISysNoticeService noticeService,List userIds) throws IOException { + public static void insertNoticeUser(String userName,SysNotice notice,ISysNoticeService noticeService,List userNames) throws IOException { List sysNoticeUsers = new ArrayList(); JSONObject obj = new JSONObject(); @@ -163,11 +167,11 @@ public class SysNoticeController extends BaseController SysNoticeUser sysNoticeUser = null; CopyOnWriteArraySet webSocketSet = WebSocket.getWebSocketSet();//获取在线用户 for (WebSocket item : webSocketSet) { - String userid = item.sid; - if(!userid.equals(String.valueOf(userId))){ + String username = item.sid; + if(!username.equals(userName)){ sysNoticeUser = new SysNoticeUser(); sysNoticeUser.setNoticeId(notice.getNoticeId()); - sysNoticeUser.setUserId(Long.valueOf(userid)); + sysNoticeUser.setUserId(username); sysNoticeUsers.add(sysNoticeUser); } } @@ -175,18 +179,18 @@ public class SysNoticeController extends BaseController noticeService.insertNoticeUserBatch(sysNoticeUsers); } }else{ - if(userIds!=null&&userIds.size()>0){ - for(String uid:userIds){ - WebSocket.sendInfo(obj.toString(),uid); + if(userNames!=null&&userNames.size()>0){ + for(String names:userNames){ + WebSocket.sendInfo(obj.toString(),names); } SysNoticeUser sysNoticeUser = null; CopyOnWriteArraySet webSocketSet = WebSocket.getWebSocketSet();//获取在线用户 for (WebSocket item : webSocketSet) { - String userid = item.sid; - if(userIds.contains(userid)){ + String username = item.sid; + if(userNames.contains(username)){ sysNoticeUser = new SysNoticeUser(); sysNoticeUser.setNoticeId(notice.getNoticeId()); - sysNoticeUser.setUserId(Long.valueOf(userid)); + sysNoticeUser.setUserId(username); sysNoticeUsers.add(sysNoticeUser); } } @@ -208,4 +212,30 @@ public class SysNoticeController extends BaseController List list = noticeService.listNoticeEventUser(noticeUserSelect); return list; } + + @PostMapping("/saveNoticeEventUser") + public AjaxResult saveNoticeEventUser(@RequestBody List list) + { + try{ + if(list!=null&&list.size()>0){ + String noticeEventType = list.get(0).getNoticeEventType(); + noticeService.deleteNoticeEventUserByType(noticeEventType); + noticeService.insertNoticeEventUserBatch(list); + } + }catch (Exception e){ + return error("系统异常"); + } + return success(); + } + + @PostMapping("/delNoticeEventUser") + public AjaxResult delNoticeEventUser(@RequestBody NoticeUserSelect noticeUserSelect) + { + try{ + noticeService.deleteNoticeEventUser(noticeUserSelect); + }catch (Exception e){ + return error("系统异常"); + } + return success(); + } } diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/domain/SysNotice.java b/ruoyi-system/src/main/java/com/ruoyi/system/domain/SysNotice.java index 941d405..9c6c73f 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/domain/SysNotice.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/domain/SysNotice.java @@ -35,9 +35,6 @@ public class SysNotice extends BaseEntity /** 公告状态(0正常 1关闭) */ private String status; - /** 公告是否已读(0未读 1已读) */ - private String isRead; - public Long getNoticeId() { return noticeId; @@ -97,10 +94,6 @@ public class SysNotice extends BaseEntity return status; } - public String getIsRead() { return isRead; } - - public void setIsRead(String isRead) { this.isRead = isRead; } - @Override public String toString() { return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE) diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/domain/SysNoticeUser.java b/ruoyi-system/src/main/java/com/ruoyi/system/domain/SysNoticeUser.java index 0c69c09..c2d8852 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/domain/SysNoticeUser.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/domain/SysNoticeUser.java @@ -2,7 +2,8 @@ package com.ruoyi.system.domain; public class SysNoticeUser { private Long noticeId; - private Long userId; + private String userId; + private String isRead; public Long getNoticeId() { return noticeId; @@ -12,11 +13,15 @@ public class SysNoticeUser { this.noticeId = noticeId; } - public Long getUserId() { + public String getUserId() { return userId; } - public void setUserId(Long userId) { + public void setUserId(String userId) { this.userId = userId; } + + public String getIsRead() { return isRead; } + + public void setIsRead(String isRead) { this.isRead = isRead; } } diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/mapper/SysNoticeMapper.java b/ruoyi-system/src/main/java/com/ruoyi/system/mapper/SysNoticeMapper.java index 9709274..f6cd7ab 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/mapper/SysNoticeMapper.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/mapper/SysNoticeMapper.java @@ -65,7 +65,7 @@ public interface SysNoticeMapper * 消息推送信息获取 * @return */ - List navbarNoticelist(Long userId); + List navbarNoticelist(String userName); /** * 批量插入消息-用户 中间表 @@ -73,10 +73,35 @@ public interface SysNoticeMapper */ void insertNoticeUserBatch(List sysNoticeUsers); + /** + * 更新消息-用户 中间表 + * @param sysNoticeUser + */ + void updateSysNoticeUser(SysNoticeUser sysNoticeUser); + /** * 获取对应消息对象的 人员 * @param noticeUserSelect * @return */ List listNoticeEventUser(NoticeUserSelect noticeUserSelect); + + /** + * 删除对应消息对象的 人员 + * @param noticeEventType + */ + void deleteNoticeEventUserByType(String noticeEventType); + + /** + * 批量插入对应消息对象的 人员 + * @param list + */ + void insertNoticeEventUserBatch(List list); + + /** + * 删除对应消息对象的 人员 + * @param noticeUserSelect + */ + void deleteNoticeEventUser(NoticeUserSelect noticeUserSelect); + } diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/service/ISysNoticeService.java b/ruoyi-system/src/main/java/com/ruoyi/system/service/ISysNoticeService.java index 3928699..65c776f 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/service/ISysNoticeService.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/service/ISysNoticeService.java @@ -65,7 +65,7 @@ public interface ISysNoticeService * 导航面板 消息通知 * @return */ - List navbarNoticelist(Long userId); + List navbarNoticelist(String userName); /** * 批量插入消息-用户 中间表 @@ -73,10 +73,34 @@ public interface ISysNoticeService */ void insertNoticeUserBatch(List sysNoticeUsers); + /** + * 更新消息-用户 中间表 + * @param sysNoticeUser + */ + void updateSysNoticeUser(SysNoticeUser sysNoticeUser); + /** * 获取对应消息对象的 人员 * @param noticeUserSelect * @return */ List listNoticeEventUser(NoticeUserSelect noticeUserSelect); + + /** + * 删除对应消息对象的 人员 + * @param noticeEventType + */ + void deleteNoticeEventUserByType(String noticeEventType); + + /** + * 批量插入对应消息对象的 人员 + * @param list + */ + void insertNoticeEventUserBatch(List list); + + /** + * 删除对应消息对象的 人员 + * @param noticeUserSelect + */ + void deleteNoticeEventUser(NoticeUserSelect noticeUserSelect); } diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysNoticeServiceImpl.java b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysNoticeServiceImpl.java index 7f239fc..0f9e477 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysNoticeServiceImpl.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysNoticeServiceImpl.java @@ -120,8 +120,8 @@ public class SysNoticeServiceImpl implements ISysNoticeService * @return */ @Override - public List navbarNoticelist(Long userId) { - return noticeMapper.navbarNoticelist(userId); + public List navbarNoticelist(String userName) { + return noticeMapper.navbarNoticelist(userName); } /** @@ -133,6 +133,15 @@ public class SysNoticeServiceImpl implements ISysNoticeService noticeMapper.insertNoticeUserBatch(sysNoticeUsers); } + /** + * 更新消息-用户 中间表 + * @param sysNoticeUser + */ + @Override + public void updateSysNoticeUser(SysNoticeUser sysNoticeUser) { + noticeMapper.updateSysNoticeUser(sysNoticeUser); + } + /** * 获取对应消息对象的 人员 * @param noticeUserSelect @@ -142,4 +151,31 @@ public class SysNoticeServiceImpl implements ISysNoticeService public List listNoticeEventUser(NoticeUserSelect noticeUserSelect) { return noticeMapper.listNoticeEventUser(noticeUserSelect); } + + /** + * 删除对应消息对象的 人员 + * @param noticeEventType + */ + @Override + public void deleteNoticeEventUserByType(String noticeEventType) { + noticeMapper.deleteNoticeEventUserByType(noticeEventType); + } + + /** + * 批量插入对应消息对象的 人员 + * @param list + */ + @Override + public void insertNoticeEventUserBatch(List list) { + noticeMapper.insertNoticeEventUserBatch(list); + } + + /** + * 删除对应消息对象的 人员 + * @param noticeUserSelect + */ + @Override + public void deleteNoticeEventUser(NoticeUserSelect noticeUserSelect) { + noticeMapper.deleteNoticeEventUser(noticeUserSelect); + } } diff --git a/ruoyi-system/src/main/resources/mapper/system/SysNoticeMapper.xml b/ruoyi-system/src/main/resources/mapper/system/SysNoticeMapper.xml index cce51e8..7cf6318 100644 --- a/ruoyi-system/src/main/resources/mapper/system/SysNoticeMapper.xml +++ b/ruoyi-system/src/main/resources/mapper/system/SysNoticeMapper.xml @@ -15,11 +15,10 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" - - select notice_id, notice_title, notice_type, notice_content, status, create_by, create_time, update_by, update_time, remark, isRead + select notice_id, notice_title, notice_type, notice_content, status, create_by, create_time, update_by, update_time, remark from sys_notice @@ -71,8 +70,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" notice_content = #{noticeContentBit}, status = #{status}, update_by = #{updateBy}, - update_time = getdate(), - isRead = #{isRead} + update_time = getdate() where notice_id = #{noticeId} @@ -93,9 +91,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" from sys_notice a inner join sys_user_notice b on a.notice_id = b.noticeId - and b.userId = #{userId} + and b.userId = #{userName} and CONVERT(date, a.create_time) = CONVERT(date, GETDATE()) - and a.status = '0' and a.isRead = '0' + and a.status = '0' and b.isRead = '0' order by create_time desc @@ -106,11 +104,15 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" ( #{item.noticeId,jdbcType=INTEGER}, - #{item.userId,jdbcType=INTEGER} + #{item.userId,jdbcType=VARCHAR} ) + + update sys_user_notice set isRead = #{isRead} where noticeId = #{noticeId} and userId = #{userId} + + + + delete from sys_event_user where notice_event_type = #{noticeEventType} + + + + insert into sys_event_user(notice_event_type,notice_event_user_id) + values + + ( + #{item.noticeEventType,jdbcType=VARCHAR}, + #{item.userName,jdbcType=VARCHAR} + ) + + + + + delete from sys_event_user where notice_event_type = #{noticeEventType} and notice_event_user_id = #{userName} + + diff --git a/ruoyi-ui/src/api/system/notice.js b/ruoyi-ui/src/api/system/notice.js index 9566138..26508bb 100644 --- a/ruoyi-ui/src/api/system/notice.js +++ b/ruoyi-ui/src/api/system/notice.js @@ -69,3 +69,20 @@ export function listNoticeEventUser(query) { }) } +// 保存对应消息对象的 人员 +export function saveNoticeEventUser(data) { + return request({ + url: '/system/notice/saveNoticeEventUser', + method: 'post', + data: data + }) +} + +// 删除对应消息对象的 人员 +export function delNoticeEventUser(data) { + return request({ + url: '/system/notice/delNoticeEventUser', + method: 'post', + data: data + }) +} diff --git a/ruoyi-ui/src/layout/components/NavbarNotice.vue b/ruoyi-ui/src/layout/components/NavbarNotice.vue index d4c0ddf..bbb4e19 100644 --- a/ruoyi-ui/src/layout/components/NavbarNotice.vue +++ b/ruoyi-ui/src/layout/components/NavbarNotice.vue @@ -131,7 +131,7 @@ }); }, initWebSocket() { - var userId = this.$store.state.user.id; + var userName = this.$store.state.user.name; // WebSocket与普通的请求所用协议有所不同,ws等同于http,wss等同于https // 当前浏览器Location对象 const nowLocation = window.location; @@ -150,7 +150,7 @@ const webSocketApiUrl = 'ws://' + host + '/' + websocket_pattern; // 当前WebSocket的请求地址前缀, // /websocket/template-push/ 就是我后端配置的websocket端点地址 - let url = webSocketApiUrl + '/websocket/message/'+userId; + let url = webSocketApiUrl + '/websocket/message/'+userName; this.websock = new WebSocket(url) this.websock.onopen = this.websocketOnopen this.websock.onerror = this.websocketOnerror diff --git a/ruoyi-ui/src/views/components/Tools/PeopleSelect/index.vue b/ruoyi-ui/src/views/components/Tools/PeopleSelect/index.vue index f6102da..21c7022 100644 --- a/ruoyi-ui/src/views/components/Tools/PeopleSelect/index.vue +++ b/ruoyi-ui/src/views/components/Tools/PeopleSelect/index.vue @@ -289,6 +289,7 @@ //第一步要做的 checkedUsers 为数组如['admin','ry'] 在父组件调用此方法并传入要回显的数组可进行复选框回显操作 getAllUserList(checkedUsers = []) { + this.userList = []; //查出所有的用户,用于根据不同情况筛选显示 listUser({pageNum: 1,pageSize: 2147483647,status: "0"}).then(response => { this.allUserList = response.rows; diff --git a/ruoyi-ui/src/views/noticeUserSelect/noticeUserSelect/index.vue b/ruoyi-ui/src/views/noticeUserSelect/noticeUserSelect/index.vue index cc22dbd..4b981ed 100644 --- a/ruoyi-ui/src/views/noticeUserSelect/noticeUserSelect/index.vue +++ b/ruoyi-ui/src/views/noticeUserSelect/noticeUserSelect/index.vue @@ -14,7 +14,7 @@ 选择人员 - 保 存 +
@@ -23,7 +23,7 @@
{{ item.nickName }} - 删除 + 删除
@@ -35,13 +35,13 @@