From 3985b78ba3edb619049210327514d06e6934a0c5 Mon Sep 17 00:00:00 2001 From: xd <844539747@qq.com> Date: Fri, 26 Apr 2024 16:44:40 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B6=88=E6=81=AF=E9=80=9A=E7=9F=A5-=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0=E8=AF=A6=E6=83=85=E9=A1=B5=E5=8F=8A=E6=9B=B4=E5=A4=9A?= =?UTF-8?q?=E5=B1=95=E7=A4=BA=E9=A1=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../system/SysNoticeController.java | 57 ++++++++++--- .../ruoyi/system/domain/SysNoticeUser.java | 27 ++++++ .../ruoyi/system/mapper/SysNoticeMapper.java | 11 ++- .../system/service/ISysNoticeService.java | 10 ++- .../service/impl/SysNoticeServiceImpl.java | 13 ++- .../mapper/system/SysNoticeMapper.xml | 23 ++++- ruoyi-ui/src/api/system/notice.js | 9 ++ .../src/layout/components/NavbarNotice.vue | 85 ++++++++++++++----- 8 files changed, 195 insertions(+), 40 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 f896c75..8de16a1 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 @@ -7,6 +7,8 @@ import java.util.stream.Collectors; import com.alibaba.fastjson2.JSONObject; import com.ruoyi.common.constant.WebsocketConst; +import com.ruoyi.common.core.domain.model.LoginUser; +import com.ruoyi.common.utils.DateUtils; import com.ruoyi.framework.websocket.WebSocket; import com.ruoyi.system.domain.NoticeUserSelect; import com.ruoyi.system.domain.SysNoticeUser; @@ -77,8 +79,8 @@ public class SysNoticeController extends BaseController notice.setCreateBy(getUsername()); noticeService.insertNotice(notice); //推送消息插入中间表 - String userName = getLoginUser().getUsername();//当前登陆者 - insertNoticeUser(userName,notice,noticeService,null); + LoginUser loginUser = getLoginUser();//当前登陆者 + insertNoticeUser(loginUser,notice,noticeService,null); }catch (Exception e){ return error("系统异常"); } @@ -113,19 +115,46 @@ public class SysNoticeController extends BaseController * @return */ @GetMapping("/navbarNoticelist") - public Map> navbarNoticelist() + public Map> navbarNoticelist() { String userName = getLoginUser().getUsername();//当前登陆者 - List list = noticeService.navbarNoticelist(userName); - Map> groupedByNoticeType = list.stream() - .collect(Collectors.groupingBy(SysNotice::getNoticeType)); + List list = noticeService.navbarNoticelist(userName); + Map> groupedByNoticeType = list.stream() + .collect(Collectors.groupingBy(SysNoticeUser::getNoticeType)); for(String key:groupedByNoticeType.keySet()){ - List lt = groupedByNoticeType.get(key); - lt.sort((t1, t2) -> t2.getCreateTime().compareTo(t1.getCreateTime())); + List lt = groupedByNoticeType.get(key); + lt.sort((t1, t2) -> t2.getSendTime().compareTo(t1.getSendTime())); } return groupedByNoticeType; } + /** + * 导航面板 消息通知-更多 + * @return + */ + @GetMapping("/navbarNoticeMorelist") + public List> navbarNoticeMorelist(SysNoticeUser sysNoticeUser) + { + String userName = getLoginUser().getUsername();//当前登陆者 + String noticeType = sysNoticeUser.getNoticeType();//消息类型 + List list = noticeService.navbarNoticeMorelist(userName,noticeType); + + Map map = new HashMap<>(); + List> listMap = new ArrayList>(); + + Map> groupedByNoticeType = list.stream() + .collect(Collectors.groupingBy(SysNoticeUser::getSendTimeFormat)); + for(String key:groupedByNoticeType.keySet()){ + List lt = groupedByNoticeType.get(key); + lt.sort((t1, t2) -> t2.getSendTime().compareTo(t1.getSendTime())); + map = new HashMap<>(); + map.put("date",key); + map.put("data",lt); + listMap.add(map); + } + return listMap; + } + /** * 导航面板 消息通知 获取详细信息 */ @@ -149,11 +178,11 @@ public class SysNoticeController extends BaseController /** * 推送消息插入中间表 - * @param userName 发送对象排除自身 + * @param loginUser 发送对象排除自身 * @param notice 发送信息对象 * @param noticeService 接口 */ - public static void insertNoticeUser(String userName,SysNotice notice,ISysNoticeService noticeService,List userNames) throws IOException { + public static void insertNoticeUser(LoginUser loginUser,SysNotice notice,ISysNoticeService noticeService,List userNames) throws IOException { List sysNoticeUsers = new ArrayList(); JSONObject obj = new JSONObject(); @@ -166,12 +195,15 @@ public class SysNoticeController extends BaseController SysNoticeUser sysNoticeUser = null; CopyOnWriteArraySet webSocketSet = WebSocket.getWebSocketSet();//获取在线用户 + Date sendTime = DateUtils.getNowDate(); for (WebSocket item : webSocketSet) { String username = item.sid; - if(!username.equals(userName)){ + if(!username.equals(loginUser.getUsername())){ sysNoticeUser = new SysNoticeUser(); sysNoticeUser.setNoticeId(notice.getNoticeId()); sysNoticeUser.setUserId(username); + sysNoticeUser.setSendUser(loginUser.getUser().getNickName()); + sysNoticeUser.setSendTime(sendTime); sysNoticeUsers.add(sysNoticeUser); } } @@ -185,12 +217,15 @@ public class SysNoticeController extends BaseController } SysNoticeUser sysNoticeUser = null; CopyOnWriteArraySet webSocketSet = WebSocket.getWebSocketSet();//获取在线用户 + Date sendTime = DateUtils.getNowDate(); for (WebSocket item : webSocketSet) { String username = item.sid; if(userNames.contains(username)){ sysNoticeUser = new SysNoticeUser(); sysNoticeUser.setNoticeId(notice.getNoticeId()); sysNoticeUser.setUserId(username); + sysNoticeUser.setSendUser(loginUser.getUser().getNickName()); + sysNoticeUser.setSendTime(sendTime); sysNoticeUsers.add(sysNoticeUser); } } 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 c2d8852..fc2afa2 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 @@ -1,10 +1,19 @@ package com.ruoyi.system.domain; +import java.text.SimpleDateFormat; +import java.util.Date; + public class SysNoticeUser { private Long noticeId; + + private String noticeTitle; + private String noticeType; private String userId; private String isRead; + private String sendUser; + private Date sendTime; + public Long getNoticeId() { return noticeId; } @@ -17,6 +26,14 @@ public class SysNoticeUser { return userId; } + public String getNoticeType() { return noticeType; } + + public void setNoticeType(String noticeType) { this.noticeType = noticeType; } + + public String getNoticeTitle() { return noticeTitle; } + + public void setNoticeTitle(String noticeTitle) { this.noticeTitle = noticeTitle; } + public void setUserId(String userId) { this.userId = userId; } @@ -24,4 +41,14 @@ public class SysNoticeUser { public String getIsRead() { return isRead; } public void setIsRead(String isRead) { this.isRead = isRead; } + + public String getSendUser() { return sendUser; } + + public void setSendUser(String sendUser) { this.sendUser = sendUser; } + + public Date getSendTime() { return sendTime; } + + public void setSendTime(Date sendTime) { this.sendTime = sendTime; } + + public String getSendTimeFormat() { return new SimpleDateFormat("yyyy-MM-dd").format(sendTime); } } 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 f6cd7ab..254877f 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 @@ -5,6 +5,7 @@ import java.util.List; import com.ruoyi.system.domain.NoticeUserSelect; import com.ruoyi.system.domain.SysNotice; import com.ruoyi.system.domain.SysNoticeUser; +import org.apache.ibatis.annotations.Param; /** * 通知公告表 数据层 @@ -65,7 +66,15 @@ public interface SysNoticeMapper * 消息推送信息获取 * @return */ - List navbarNoticelist(String userName); + List navbarNoticelist(String userName); + + /** + * 导航面板 消息通知-更多 + * @param userName + * @param noticeType + * @return + */ + List navbarNoticeMorelist(@Param("userName") String userName,@Param("noticeType") String noticeType); /** * 批量插入消息-用户 中间表 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 65c776f..6a35e03 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,15 @@ public interface ISysNoticeService * 导航面板 消息通知 * @return */ - List navbarNoticelist(String userName); + List navbarNoticelist(String userName); + + /** + * 导航面板 消息通知-更多 + * @param userName + * @param noticeType + * @return + */ + List navbarNoticeMorelist(String userName, String noticeType); /** * 批量插入消息-用户 中间表 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 0f9e477..52436ee 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,10 +120,21 @@ public class SysNoticeServiceImpl implements ISysNoticeService * @return */ @Override - public List navbarNoticelist(String userName) { + public List navbarNoticelist(String userName) { return noticeMapper.navbarNoticelist(userName); } + /** + * 导航面板 消息通知-更多 + * @param userName + * @param noticeType + * @return + */ + @Override + public List navbarNoticeMorelist(String userName, String noticeType) { + return noticeMapper.navbarNoticeMorelist(userName,noticeType); + } + /** * 批量插入消息-用户 中间表 * @param sysNoticeUsers diff --git a/ruoyi-system/src/main/resources/mapper/system/SysNoticeMapper.xml b/ruoyi-system/src/main/resources/mapper/system/SysNoticeMapper.xml index 7cf6318..e12ddda 100644 --- a/ruoyi-system/src/main/resources/mapper/system/SysNoticeMapper.xml +++ b/ruoyi-system/src/main/resources/mapper/system/SysNoticeMapper.xml @@ -86,8 +86,8 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" - + select a.notice_id noticeId, a.notice_title noticeTitle, a.notice_type noticeType,b.sendUser,b.sendTime from sys_notice a inner join sys_user_notice b on a.notice_id = b.noticeId @@ -98,13 +98,28 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" order by create_time desc + + - insert into sys_user_notice(noticeId,userId) + insert into sys_user_notice(noticeId,userId,sendUser,sendTime) values ( #{item.noticeId,jdbcType=INTEGER}, - #{item.userId,jdbcType=VARCHAR} + #{item.userId,jdbcType=VARCHAR}, + #{item.sendUser,jdbcType=VARCHAR}, + #{item.sendTime,jdbcType=TIMESTAMP} ) diff --git a/ruoyi-ui/src/api/system/notice.js b/ruoyi-ui/src/api/system/notice.js index 26508bb..f8c71f1 100644 --- a/ruoyi-ui/src/api/system/notice.js +++ b/ruoyi-ui/src/api/system/notice.js @@ -52,6 +52,15 @@ export function navbarNoticelist(query) { }) } +// 导航面板 消息通知-更多 +export function navbarNoticeMorelist(query) { + return request({ + url: '/system/notice/navbarNoticeMorelist', + method: 'get', + params: query + }) +} + // 导航面板 消息通知 获取详细信息 export function getNavbarNotice(noticeId) { return request({ diff --git a/ruoyi-ui/src/layout/components/NavbarNotice.vue b/ruoyi-ui/src/layout/components/NavbarNotice.vue index bbb4e19..c8b0132 100644 --- a/ruoyi-ui/src/layout/components/NavbarNotice.vue +++ b/ruoyi-ui/src/layout/components/NavbarNotice.vue @@ -9,28 +9,25 @@ - - {{item.noticeTitle}} + + {{item.noticeTitle}} + {{parseTime(item.sendTime, '{y}-{m}-{d} {h}:{i}:{s}')}} - + 更多消息 - - {{item.noticeTitle}} + + {{item.noticeTitle}} + {{parseTime(item.sendTime, '{y}-{m}-{d} {h}:{i}:{s}')}} - + 更多消息 - - {{item.noticeTitle}} + + {{item.noticeTitle}} + {{parseTime(item.sendTime, '{y}-{m}-{d} {h}:{i}:{s}')}} - + 更多消息 @@ -62,10 +59,37 @@ + + +
+ + + +

{{item.noticeTitle}}

+

{{item.sendUser}} 提交于 {{parseTime(item.sendTime, '{y}-{m}-{d} {h}:{i}:{s}')}}

+
+ 详情 +
+
+
+
+
+