From 33eb91ecca5447a1dc18e4a94b5540417acd8b97 Mon Sep 17 00:00:00 2001 From: "1437892690@qq.com" <1437892690@qq.com> Date: Tue, 10 Dec 2024 18:45:43 +0800 Subject: [PATCH 1/6] =?UTF-8?q?[=E5=8A=9F=E8=83=BD]=20=E7=B3=BB=E7=BB=9F?= =?UTF-8?q?=E5=85=AC=E5=91=8A=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 关联 #[1308783484043264]系统公告优化 http://192.168.0.96:8090/demo/rdm.html#/story-detail/939050947543040/939050947543042/1308783484043264 --- .../framework/dao/mapper/UserSessionMapper.java | 5 +++++ .../framework/dao/mapper/UserSessionMapper.xml | 12 ++++++++++++ 2 files changed, 17 insertions(+) diff --git a/src/main/java/neatlogic/framework/dao/mapper/UserSessionMapper.java b/src/main/java/neatlogic/framework/dao/mapper/UserSessionMapper.java index 9ada037d6..3e8bc5070 100644 --- a/src/main/java/neatlogic/framework/dao/mapper/UserSessionMapper.java +++ b/src/main/java/neatlogic/framework/dao/mapper/UserSessionMapper.java @@ -49,6 +49,11 @@ public interface UserSessionMapper { @Param("pageSize") Integer pageSize ); + List getOnlineUserUuidListByUserUuidListAndGreaterThanSessionTime( + @Param("userUuidList") List userUuidList, + @Param("sessionTime") Date sessionTime + ); + int getUserSessionCountByDate(String limitDate); int insertUserSession(@Param("userUuid") String userUuid, @Param("tokenHash") String tokenHash, @Param("tokenCreateTime") Long tokenCreateTime, @Param("authInfoHash") String authInfoHash); diff --git a/src/main/java/neatlogic/framework/dao/mapper/UserSessionMapper.xml b/src/main/java/neatlogic/framework/dao/mapper/UserSessionMapper.xml index d684e43ac..b26db4d93 100644 --- a/src/main/java/neatlogic/framework/dao/mapper/UserSessionMapper.xml +++ b/src/main/java/neatlogic/framework/dao/mapper/UserSessionMapper.xml @@ -121,6 +121,18 @@ along with this program. If not, see .--> + + + + + + update `system_notice` @@ -435,6 +451,19 @@ where `id` = #{id} + + update `system_notice_user` @@ -553,6 +582,24 @@ + + INSERT INTO `system_notice_user` ( + `system_notice_id`, + `user_uuid`, + `is_read` + ) + SELECT DISTINCT + a.`id`, '${userUuid}', 0 + FROM `system_notice` a + JOIN `system_notice_recipient` b ON a.`id` = b.`system_notice_id` + WHERE a.`status` = 'issued' + AND a.`id` NOT IN (SELECT `system_notice_id` FROM `system_notice_user` WHERE `user_uuid` = #{userUuid} + AND b.`uuid` IN + + #{uuid} + + + delete from `system_notice` @@ -576,4 +623,15 @@ + + + + DELETE FROM `system_notice_user` WHERE `system_notice_id` = #{value} + + diff --git a/src/main/java/neatlogic/framework/systemnotice/service/ISystemNoticeCrossoverService.java b/src/main/java/neatlogic/framework/systemnotice/service/ISystemNoticeCrossoverService.java new file mode 100644 index 000000000..407e6cb7a --- /dev/null +++ b/src/main/java/neatlogic/framework/systemnotice/service/ISystemNoticeCrossoverService.java @@ -0,0 +1,67 @@ +/* + * Copyright (C) 2024 深圳极向量科技有限公司 All Rights Reserved. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package neatlogic.framework.systemnotice.service; + +import neatlogic.framework.crossover.ICrossoverService; +import neatlogic.framework.systemnotice.dto.SystemNoticeVo; + +public interface ISystemNoticeCrossoverService extends ICrossoverService { + + /** + * @Description: 清理掉system_notice_user中因删除公告或更改公告通知对象而遗留的记录 + * @Author: laiwt + * @Date: 2021/1/20 11:10 + * @Params: [] + * @Returns: void + **/ + public void clearSystemNoticeUser(); + + /** + * @Description: 检查是否存在【已下发却到了失效时间的】公告,如果有,则停用 + * @Author: laiwt + * @Date: 2021/1/20 11:12 + * @Params: [] + * @Returns: void + **/ + public void stopExpiredSystemNotice(); + + /** + * @Description: 在system_notice_user插入【当前用户可看的】、【已下发的】公告 + * @Author: laiwt + * @Date: 2021/1/20 11:12 + * @Params: [] + * @Returns: void + **/ + public void pullIssuedSystemNotice(); + + /** + * @Description: 检查是否存在【当前用户可看的】、【到了生效时间,却还没下发】公告, + * 如果有则下发给当前用户 + * @Author: laiwt + * @Date: 2021/1/20 11:13 + * @Params: [] + * @Returns: void + **/ + public void pullActiveSystemNotice(); + + /** + * 下发公告 + * @param systemNoticeVo + */ + boolean issueSystemNotice(SystemNoticeVo systemNoticeVo); +} diff --git a/src/main/java/neatlogic/module/framework/systemnotice/service/SystemNoticeService.java b/src/main/java/neatlogic/module/framework/systemnotice/service/SystemNoticeService.java new file mode 100644 index 000000000..55eaa8177 --- /dev/null +++ b/src/main/java/neatlogic/module/framework/systemnotice/service/SystemNoticeService.java @@ -0,0 +1,74 @@ +/* + * Copyright (C) 2024 深圳极向量科技有限公司 All Rights Reserved. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package neatlogic.module.framework.systemnotice.service; + + +import neatlogic.framework.systemnotice.dto.SystemNoticeVo; + +/** + * @Title: SystemNoticeService + * @Package: neatlogic.framework.systemnotice.service + * @Description: + * @Author: laiwt + * @Date: 2021/1/20 11:00 + **/ +public interface SystemNoticeService { + + /** + * @Description: 清理掉system_notice_user中因删除公告或更改公告通知对象而遗留的记录 + * @Author: laiwt + * @Date: 2021/1/20 11:10 + * @Params: [] + * @Returns: void + **/ + public void clearSystemNoticeUser(); + + /** + * @Description: 检查是否存在【已下发却到了失效时间的】公告,如果有,则停用 + * @Author: laiwt + * @Date: 2021/1/20 11:12 + * @Params: [] + * @Returns: void + **/ + public void stopExpiredSystemNotice(); + + /** + * @Description: 在system_notice_user插入【当前用户可看的】、【已下发的】公告 + * @Author: laiwt + * @Date: 2021/1/20 11:12 + * @Params: [] + * @Returns: void + **/ + public void pullIssuedSystemNotice(); + + /** + * @Description: 检查是否存在【当前用户可看的】、【到了生效时间,却还没下发】公告, + * 如果有则下发给当前用户 + * @Author: laiwt + * @Date: 2021/1/20 11:13 + * @Params: [] + * @Returns: void + **/ + public void pullActiveSystemNotice(); + + /** + * 下发公告 + * @param systemNoticeVo + */ + boolean issueSystemNotice(SystemNoticeVo systemNoticeVo); +} diff --git a/src/main/java/neatlogic/module/framework/systemnotice/service/SystemNoticeServiceImpl.java b/src/main/java/neatlogic/module/framework/systemnotice/service/SystemNoticeServiceImpl.java new file mode 100644 index 000000000..b4b14aef7 --- /dev/null +++ b/src/main/java/neatlogic/module/framework/systemnotice/service/SystemNoticeServiceImpl.java @@ -0,0 +1,224 @@ +/* + * Copyright (C) 2024 深圳极向量科技有限公司 All Rights Reserved. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package neatlogic.module.framework.systemnotice.service; + +import neatlogic.framework.asynchronization.thread.NeatLogicThread; +import neatlogic.framework.asynchronization.threadlocal.UserContext; +import neatlogic.framework.asynchronization.threadpool.CachedThreadPool; +import neatlogic.framework.common.config.Config; +import neatlogic.framework.common.constvalue.GroupSearch; +import neatlogic.framework.common.constvalue.UserType; +import neatlogic.framework.common.dto.BasePageVo; +import neatlogic.framework.common.util.PageUtil; +import neatlogic.framework.dao.mapper.RoleMapper; +import neatlogic.framework.dao.mapper.TeamMapper; +import neatlogic.framework.dao.mapper.UserSessionMapper; +import neatlogic.framework.service.UserService; +import neatlogic.framework.systemnotice.dao.mapper.SystemNoticeMapper; +import neatlogic.framework.systemnotice.dto.SystemNoticeRecipientVo; +import neatlogic.framework.systemnotice.dto.SystemNoticeUserVo; +import neatlogic.framework.systemnotice.dto.SystemNoticeVo; +import org.apache.commons.collections4.CollectionUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import javax.annotation.Resource; +import java.util.*; +import java.util.concurrent.TimeUnit; +import java.util.stream.Collectors; + +/** + * @Title: SystemNoticeServiceImpl + * @Package: neatlogic.framework.systemnotice.service + * @Description: + * @Author: laiwt + * @Date: 2021/1/20 11:02 + **/ +@Service +public class SystemNoticeServiceImpl implements SystemNoticeService{ + + @Autowired + private SystemNoticeMapper systemNoticeMapper; + + @Autowired + private RoleMapper roleMapper; + + @Autowired + private TeamMapper teamMapper; + + @Resource + private UserSessionMapper userSessionMapper; + + @Resource + private UserService userService; + + @Override + public void clearSystemNoticeUser() { + List recipientUuidList = getRecipientUuidList(); + Set noticeIdList = new HashSet<>(); + /** 获取system_notice_user中,因公告被删除而残留的记录 **/ + noticeIdList.addAll(systemNoticeMapper.getNotExistsNoticeIdListFromNoticeUserByUserUuid(UserContext.get().getUserUuid(true))); + /** 获取system_notice_user中,因更改公告通知对象而残留的记录 **/ + noticeIdList.addAll(systemNoticeMapper.getNotInNoticeScopeNoticeIdListByUserUuid(recipientUuidList,UserContext.get().getUserUuid(true))); + /** 清理掉上述两种记录 **/ + if(CollectionUtils.isNotEmpty(noticeIdList)){ + systemNoticeMapper.deleteSystemNoticeUserByUserUuid(UserContext.get().getUserUuid(true),noticeIdList); + } + } + + @Override + public void stopExpiredSystemNotice() { + List recipientUuidList = getRecipientUuidList(); + List expiredNoticeList = systemNoticeMapper.getExpiredNoticeListByRecipientUuidList(recipientUuidList); + if (CollectionUtils.isNotEmpty(expiredNoticeList)) { + for (SystemNoticeVo vo : expiredNoticeList) { + systemNoticeMapper.stopSystemNoticeById(vo); + } + } + } + + @Override + public void pullIssuedSystemNotice() { +// List recipientUuidList = getRecipientUuidList(); +// List issuedNoticeList = systemNoticeMapper.getIssuedNoticeIdListByRecipientUuidList(recipientUuidList); +// if (CollectionUtils.isNotEmpty(issuedNoticeList)) { +// List noticeUserVoList = new ArrayList<>(); +// for (Long id : issuedNoticeList) { +// noticeUserVoList.add(new SystemNoticeUserVo(id, UserContext.get().getUserUuid(true))); +// } +// systemNoticeMapper.batchInsertSystemNoticeUser(noticeUserVoList); +// } + String userUuid = UserContext.get().getUserUuid(); + List uuidList = UserContext.get().getUuidList(); + uuidList.add(userUuid); + uuidList.add(UserType.ALL.getValue()); + systemNoticeMapper.insertInsertSystemNoticeUser(userUuid, uuidList); + } + + @Override + public void pullActiveSystemNotice() { + List recipientUuidList = getRecipientUuidList(); + List hasBeenActiveNoticeList = systemNoticeMapper.getHasBeenActiveNoticeListByRecipientUuidList(recipientUuidList); + if (CollectionUtils.isNotEmpty(hasBeenActiveNoticeList)) { + List currentUserNoticeList = new ArrayList<>(); + /** 更改这些公告的状态为已下发 **/ + for (SystemNoticeVo vo : hasBeenActiveNoticeList) { + vo.setStatus(SystemNoticeVo.Status.ISSUED.getValue()); + vo.setIssueTime(vo.getStartTime()); + systemNoticeMapper.updateSystemNoticeStatus(vo); + currentUserNoticeList.add(new SystemNoticeUserVo(vo.getId(), UserContext.get().getUserUuid(true))); + /** 如果没有忽略已读,那么更改is_read为0 **/ + if(vo.getIgnoreRead() != null && vo.getIgnoreRead() == 0){ + systemNoticeMapper.updateSystemNoticeUserReadStatus(vo.getId(),UserContext.get().getUserUuid(true),0); + } + } + /** 发送给当前用户 **/ + if (CollectionUtils.isNotEmpty(currentUserNoticeList)) { + systemNoticeMapper.batchInsertSystemNoticeUser(currentUserNoticeList); + } + } + } + + @Override + public boolean issueSystemNotice(SystemNoticeVo vo) { + Integer PAGE_SIZE = 100; + /* 如果没有忽略已读,则把system_notice_user中的is_read设为0 **/ + if (vo.getIgnoreRead() != null && vo.getIgnoreRead() == 0) { + /* 经测试,该语句update 53万条数据耗时约1.2s,故不单独开线程执行 **/ + systemNoticeMapper.updateReadStatusToNotReadByNoticeId(vo.getId()); + } else { + systemNoticeMapper.deleteSystemNoticeUserByNoticeId(vo.getId()); + } + + List recipientList = systemNoticeMapper.getRecipientListByNoticeId(vo.getId()); + if (CollectionUtils.isNotEmpty(recipientList)) { + long expireTime = System.currentTimeMillis() - TimeUnit.MINUTES.toMillis(Config.USER_EXPIRETIME()); + if (recipientList.stream().anyMatch(o -> UserType.ALL.getValue().equals(o.getUuid()))) { + /* 如果通知范围是所有人,那么找出当前所有的在线用户 **/ + int allOnlineUserCount = userSessionMapper.getAllOnlineUserCount(new Date(expireTime)); + if (allOnlineUserCount > 0) { + CachedThreadPool.execute(new NeatLogicThread("NOTICE-INSERTER") { + @Override + protected void execute() { + Date expireDate = new Date(expireTime); + BasePageVo pageVo = new BasePageVo(); + pageVo.setPageSize(PAGE_SIZE); + pageVo.setPageCount(PageUtil.getPageCount(allOnlineUserCount, pageVo.getPageSize())); + List noticeUserVoList = new ArrayList<>(); + for (int i = 1; i <= pageVo.getPageCount(); i++) { + pageVo.setCurrentPage(i); + List allOnlineUser = userSessionMapper.getAllOnlineUser(expireDate, pageVo.getStartNum(), pageVo.getPageSize()); + if (CollectionUtils.isNotEmpty(allOnlineUser)) { + allOnlineUser.forEach(o -> noticeUserVoList.add(new SystemNoticeUserVo(vo.getId(), o))); + systemNoticeMapper.batchInsertSystemNoticeUser(noticeUserVoList); + noticeUserVoList.clear(); + } + } + } + }); + } + } else { + List userUuidList = recipientList.stream() + .filter(o -> GroupSearch.USER.getValue().equals(o.getType())) + .map(SystemNoticeRecipientVo::getUuid) + .collect(Collectors.toList()); + List teamUuidList = recipientList.stream() + .filter(o -> GroupSearch.TEAM.getValue().equals(o.getType())) + .map(SystemNoticeRecipientVo::getUuid) + .collect(Collectors.toList()); + List roleUuidList = recipientList.stream() + .filter(o -> GroupSearch.ROLE.getValue().equals(o.getType())) + .map(SystemNoticeRecipientVo::getUuid) + .collect(Collectors.toList()); + List allUserUuidlist = userService.getUserUuidListByUserUuidListAndTeamUuidListAndRoleUuidList(userUuidList, teamUuidList, roleUuidList); + if (CollectionUtils.isNotEmpty(allUserUuidlist)) { + CachedThreadPool.execute(new NeatLogicThread("NOTICE-INSERTER") { + @Override + protected void execute() { + Date expireDate = new Date(expireTime); + List noticeUserVoList = new ArrayList<>(); + for (int fromIndex = 0; fromIndex < allUserUuidlist.size(); fromIndex += PAGE_SIZE) { + int toIndex = fromIndex + PAGE_SIZE; + if (toIndex > allUserUuidlist.size()) { + toIndex = allUserUuidlist.size(); + } + List list = allUserUuidlist.subList(fromIndex, toIndex); + List onlineUserList = userSessionMapper.getOnlineUserUuidListByUserUuidListAndGreaterThanSessionTime(list, expireDate); + if (CollectionUtils.isNotEmpty(onlineUserList)) { + onlineUserList.forEach(o -> noticeUserVoList.add(new SystemNoticeUserVo(vo.getId(), o))); + systemNoticeMapper.batchInsertSystemNoticeUser(noticeUserVoList); + noticeUserVoList.clear(); + } + } + } + }); + } + } + } + return true; + } + + private List getRecipientUuidList(){ + List uuidList = new ArrayList<>(); + uuidList.add(UserContext.get().getUserUuid(true)); + uuidList.add(UserType.ALL.getValue()); + uuidList.addAll(teamMapper.getTeamUuidListByUserUuid(UserContext.get().getUserUuid(true))); + uuidList.addAll(roleMapper.getRoleUuidListByUserUuid(UserContext.get().getUserUuid(true))); + return uuidList; + } +} -- Gitee From 0083eb41dbad1c92933bbb5e37f3defd228d4a73 Mon Sep 17 00:00:00 2001 From: "1437892690@qq.com" <1437892690@qq.com> Date: Tue, 10 Dec 2024 20:04:01 +0800 Subject: [PATCH 4/6] =?UTF-8?q?[=E5=8A=9F=E8=83=BD]=20=E7=B3=BB=E7=BB=9F?= =?UTF-8?q?=E5=85=AC=E5=91=8A=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 关联 #[1308783484043264]系统公告优化 http://192.168.0.96:8090/demo/rdm.html#/story-detail/939050947543040/939050947543042/1308783484043264 --- .../service/SystemNoticeServiceImpl.java | 37 +++++++++++++++---- 1 file changed, 30 insertions(+), 7 deletions(-) diff --git a/src/main/java/neatlogic/module/framework/systemnotice/service/SystemNoticeServiceImpl.java b/src/main/java/neatlogic/module/framework/systemnotice/service/SystemNoticeServiceImpl.java index b4b14aef7..239f132ed 100644 --- a/src/main/java/neatlogic/module/framework/systemnotice/service/SystemNoticeServiceImpl.java +++ b/src/main/java/neatlogic/module/framework/systemnotice/service/SystemNoticeServiceImpl.java @@ -18,6 +18,7 @@ package neatlogic.module.framework.systemnotice.service; import neatlogic.framework.asynchronization.thread.NeatLogicThread; +import neatlogic.framework.asynchronization.threadlocal.TenantContext; import neatlogic.framework.asynchronization.threadlocal.UserContext; import neatlogic.framework.asynchronization.threadpool.CachedThreadPool; import neatlogic.framework.common.config.Config; @@ -28,11 +29,17 @@ import neatlogic.framework.common.util.PageUtil; import neatlogic.framework.dao.mapper.RoleMapper; import neatlogic.framework.dao.mapper.TeamMapper; import neatlogic.framework.dao.mapper.UserSessionMapper; +import neatlogic.framework.scheduler.core.IJob; +import neatlogic.framework.scheduler.core.SchedulerManager; +import neatlogic.framework.scheduler.dto.JobObject; +import neatlogic.framework.scheduler.exception.ScheduleHandlerNotFoundException; import neatlogic.framework.service.UserService; import neatlogic.framework.systemnotice.dao.mapper.SystemNoticeMapper; import neatlogic.framework.systemnotice.dto.SystemNoticeRecipientVo; import neatlogic.framework.systemnotice.dto.SystemNoticeUserVo; import neatlogic.framework.systemnotice.dto.SystemNoticeVo; +import neatlogic.framework.systemnotice.service.ISystemNoticeCrossoverService; +import neatlogic.module.framework.systemnotice.schedule.StopSystemNoticeJob; import org.apache.commons.collections4.CollectionUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -50,7 +57,7 @@ import java.util.stream.Collectors; * @Date: 2021/1/20 11:02 **/ @Service -public class SystemNoticeServiceImpl implements SystemNoticeService{ +public class SystemNoticeServiceImpl implements SystemNoticeService, ISystemNoticeCrossoverService { @Autowired private SystemNoticeMapper systemNoticeMapper; @@ -64,6 +71,9 @@ public class SystemNoticeServiceImpl implements SystemNoticeService{ @Resource private UserSessionMapper userSessionMapper; + @Resource + private SchedulerManager schedulerManager; + @Resource private UserService userService; @@ -74,10 +84,10 @@ public class SystemNoticeServiceImpl implements SystemNoticeService{ /** 获取system_notice_user中,因公告被删除而残留的记录 **/ noticeIdList.addAll(systemNoticeMapper.getNotExistsNoticeIdListFromNoticeUserByUserUuid(UserContext.get().getUserUuid(true))); /** 获取system_notice_user中,因更改公告通知对象而残留的记录 **/ - noticeIdList.addAll(systemNoticeMapper.getNotInNoticeScopeNoticeIdListByUserUuid(recipientUuidList,UserContext.get().getUserUuid(true))); + noticeIdList.addAll(systemNoticeMapper.getNotInNoticeScopeNoticeIdListByUserUuid(recipientUuidList, UserContext.get().getUserUuid(true))); /** 清理掉上述两种记录 **/ - if(CollectionUtils.isNotEmpty(noticeIdList)){ - systemNoticeMapper.deleteSystemNoticeUserByUserUuid(UserContext.get().getUserUuid(true),noticeIdList); + if (CollectionUtils.isNotEmpty(noticeIdList)) { + systemNoticeMapper.deleteSystemNoticeUserByUserUuid(UserContext.get().getUserUuid(true), noticeIdList); } } @@ -123,8 +133,8 @@ public class SystemNoticeServiceImpl implements SystemNoticeService{ systemNoticeMapper.updateSystemNoticeStatus(vo); currentUserNoticeList.add(new SystemNoticeUserVo(vo.getId(), UserContext.get().getUserUuid(true))); /** 如果没有忽略已读,那么更改is_read为0 **/ - if(vo.getIgnoreRead() != null && vo.getIgnoreRead() == 0){ - systemNoticeMapper.updateSystemNoticeUserReadStatus(vo.getId(),UserContext.get().getUserUuid(true),0); + if (vo.getIgnoreRead() != null && vo.getIgnoreRead() == 0) { + systemNoticeMapper.updateSystemNoticeUserReadStatus(vo.getId(), UserContext.get().getUserUuid(true), 0); } } /** 发送给当前用户 **/ @@ -210,10 +220,23 @@ public class SystemNoticeServiceImpl implements SystemNoticeService{ } } } + if (vo.getEndTime() != null) { + IJob jobHandler = SchedulerManager.getHandler(StopSystemNoticeJob.class.getName()); + if (jobHandler == null) { + throw new ScheduleHandlerNotFoundException(StopSystemNoticeJob.class.getName()); + } + String tenantUuid = TenantContext.get().getTenantUuid(); + JobObject jobObject = new JobObject.Builder(vo.getId().toString(), jobHandler.getGroupName(), jobHandler.getClassName(), tenantUuid) + .withBeginTime(vo.getEndTime()) + .withIntervalInSeconds(60 * 60) + .withRepeatCount(0) + .build(); + schedulerManager.loadJob(jobObject); + } return true; } - private List getRecipientUuidList(){ + private List getRecipientUuidList() { List uuidList = new ArrayList<>(); uuidList.add(UserContext.get().getUserUuid(true)); uuidList.add(UserType.ALL.getValue()); -- Gitee From bdddd72b5c19afe1103ec59579cd09eccfb5903e Mon Sep 17 00:00:00 2001 From: "1437892690@qq.com" <1437892690@qq.com> Date: Tue, 10 Dec 2024 20:57:39 +0800 Subject: [PATCH 5/6] =?UTF-8?q?[=E5=8A=9F=E8=83=BD]=20=E7=B3=BB=E7=BB=9F?= =?UTF-8?q?=E5=85=AC=E5=91=8A=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 关联 #[1308783484043264]系统公告优化 http://192.168.0.96:8090/demo/rdm.html#/story-detail/939050947543040/939050947543042/1308783484043264 --- .../dao/mapper/SystemNoticeMapper.xml | 2 +- .../schedule/IssueSystemNoticeJob.java | 97 +++++++++++++++++++ .../schedule/StopSystemNoticeJob.java | 92 ++++++++++++++++++ 3 files changed, 190 insertions(+), 1 deletion(-) create mode 100644 src/main/java/neatlogic/module/framework/systemnotice/schedule/IssueSystemNoticeJob.java create mode 100644 src/main/java/neatlogic/module/framework/systemnotice/schedule/StopSystemNoticeJob.java diff --git a/src/main/java/neatlogic/framework/systemnotice/dao/mapper/SystemNoticeMapper.xml b/src/main/java/neatlogic/framework/systemnotice/dao/mapper/SystemNoticeMapper.xml index a60635445..e5413bc07 100755 --- a/src/main/java/neatlogic/framework/systemnotice/dao/mapper/SystemNoticeMapper.xml +++ b/src/main/java/neatlogic/framework/systemnotice/dao/mapper/SystemNoticeMapper.xml @@ -593,7 +593,7 @@ FROM `system_notice` a JOIN `system_notice_recipient` b ON a.`id` = b.`system_notice_id` WHERE a.`status` = 'issued' - AND a.`id` NOT IN (SELECT `system_notice_id` FROM `system_notice_user` WHERE `user_uuid` = #{userUuid} + AND a.`id` NOT IN (SELECT `system_notice_id` FROM `system_notice_user` WHERE `user_uuid` = #{userUuid}) AND b.`uuid` IN #{uuid} diff --git a/src/main/java/neatlogic/module/framework/systemnotice/schedule/IssueSystemNoticeJob.java b/src/main/java/neatlogic/module/framework/systemnotice/schedule/IssueSystemNoticeJob.java new file mode 100644 index 000000000..b0ae2fd3b --- /dev/null +++ b/src/main/java/neatlogic/module/framework/systemnotice/schedule/IssueSystemNoticeJob.java @@ -0,0 +1,97 @@ +/* + * Copyright (C) 2024 深圳极向量科技有限公司 All Rights Reserved. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package neatlogic.module.framework.systemnotice.schedule; + +import neatlogic.framework.asynchronization.threadlocal.TenantContext; +import neatlogic.framework.scheduler.core.JobBase; +import neatlogic.framework.scheduler.dto.JobObject; +import neatlogic.framework.systemnotice.dao.mapper.SystemNoticeMapper; +import neatlogic.framework.systemnotice.dto.SystemNoticeVo; +import neatlogic.module.framework.systemnotice.service.SystemNoticeService; +import org.quartz.DisallowConcurrentExecution; +import org.quartz.JobExecutionContext; +import org.springframework.stereotype.Component; + +import javax.annotation.Resource; +import java.util.List; +import java.util.Objects; + +@Component +@DisallowConcurrentExecution +public class IssueSystemNoticeJob extends JobBase { + + @Resource + private SystemNoticeMapper systemNoticeMapper; + + @Resource + private SystemNoticeService systemNoticeService; + + @Override + public String getGroupName() { + return TenantContext.get().getTenantUuid() + "-ISSUE-SYSTEMNOTICE"; + } + + @Override + public void reloadJob(JobObject jobObject) { + String tenantUuid = jobObject.getTenantUuid(); + TenantContext.get().switchTenant(tenantUuid); + Long noticeId = Long.valueOf(jobObject.getJobName()); + SystemNoticeVo systemNotice = systemNoticeMapper.getSystemNoticeById(noticeId); + if (systemNotice != null && Objects.equals(systemNotice.getStatus(), SystemNoticeVo.Status.NOTISSUED.getValue()) && systemNotice.getStartTime() != null) { + JobObject.Builder newJobObjectBuilder = new JobObject.Builder(noticeId.toString(), this.getGroupName(), this.getClassName(), TenantContext.get().getTenantUuid()) + .withBeginTime(systemNotice.getStartTime()) + .withIntervalInSeconds(60 * 60) + .withRepeatCount(0); + JobObject newJobObject = newJobObjectBuilder.build(); + schedulerManager.loadJob(newJobObject); + } + } + + @Override + public void initJob(String tenantUuid) { + List noticeIdList = systemNoticeMapper.getNotIssuedNoticeIdList(); + for(Long noticeId : noticeIdList) { + JobObject.Builder jobObjectBuilder = new JobObject.Builder(noticeId.toString(), this.getGroupName(), this.getClassName(), TenantContext.get().getTenantUuid()); + JobObject jobObject = jobObjectBuilder.build(); + this.reloadJob(jobObject); + } + + } + + @Override + protected Boolean isMyHealthy(JobObject jobObject) { + Long noticeId = Long.valueOf(jobObject.getJobName()); + SystemNoticeVo systemNotice = systemNoticeMapper.getSystemNoticeById(noticeId); + if (systemNotice != null && Objects.equals(systemNotice.getStatus(), SystemNoticeVo.Status.NOTISSUED.getValue()) && systemNotice.getStartTime() != null) { + return true; + } + return false; + } + + @Override + public void executeInternal(JobExecutionContext context, JobObject jobObject) throws Exception { + Long noticeId = Long.valueOf(jobObject.getJobName()); + SystemNoticeVo systemNotice = systemNoticeMapper.getSystemNoticeById(noticeId); + if (systemNotice != null && Objects.equals(systemNotice.getStatus(), SystemNoticeVo.Status.NOTISSUED.getValue()) && systemNotice.getStartTime() != null) { + systemNoticeService.issueSystemNotice(systemNotice); + systemNotice.setStatus(SystemNoticeVo.Status.ISSUED.getValue()); + systemNotice.setIssueTime(systemNotice.getStartTime()); + systemNoticeMapper.updateSystemNoticeIssueInfo(systemNotice); + } + } +} diff --git a/src/main/java/neatlogic/module/framework/systemnotice/schedule/StopSystemNoticeJob.java b/src/main/java/neatlogic/module/framework/systemnotice/schedule/StopSystemNoticeJob.java new file mode 100644 index 000000000..028986f2e --- /dev/null +++ b/src/main/java/neatlogic/module/framework/systemnotice/schedule/StopSystemNoticeJob.java @@ -0,0 +1,92 @@ +/* + * Copyright (C) 2024 深圳极向量科技有限公司 All Rights Reserved. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package neatlogic.module.framework.systemnotice.schedule; + +import neatlogic.framework.asynchronization.threadlocal.TenantContext; +import neatlogic.framework.common.constvalue.SystemUser; +import neatlogic.framework.scheduler.core.JobBase; +import neatlogic.framework.scheduler.dto.JobObject; +import neatlogic.framework.systemnotice.dao.mapper.SystemNoticeMapper; +import neatlogic.framework.systemnotice.dto.SystemNoticeVo; +import org.quartz.DisallowConcurrentExecution; +import org.quartz.JobExecutionContext; +import org.springframework.stereotype.Component; + +import javax.annotation.Resource; +import java.util.List; +import java.util.Objects; + +@Component +@DisallowConcurrentExecution +public class StopSystemNoticeJob extends JobBase { + + @Resource + private SystemNoticeMapper systemNoticeMapper; + + + @Override + public String getGroupName() { + return TenantContext.get().getTenantUuid() + "-STOP-SYSTEMNOTICE"; + } + + @Override + public void reloadJob(JobObject jobObject) { + String tenantUuid = jobObject.getTenantUuid(); + TenantContext.get().switchTenant(tenantUuid); + Long noticeId = Long.valueOf(jobObject.getJobName()); + SystemNoticeVo systemNotice = systemNoticeMapper.getSystemNoticeById(noticeId); + if (systemNotice != null && Objects.equals(systemNotice.getStatus(), SystemNoticeVo.Status.ISSUED.getValue()) && systemNotice.getEndTime() != null) { + JobObject.Builder newJobObjectBuilder = new JobObject.Builder(noticeId.toString(), this.getGroupName(), this.getClassName(), TenantContext.get().getTenantUuid()) + .withBeginTime(systemNotice.getEndTime()) + .withIntervalInSeconds(60 * 60) + .withRepeatCount(0); + JobObject newJobObject = newJobObjectBuilder.build(); + schedulerManager.loadJob(newJobObject); + } + } + + @Override + public void initJob(String tenantUuid) { + List noticeIdList = systemNoticeMapper.getIssuedNoticeIdList(); + for(Long noticeId : noticeIdList) { + JobObject.Builder jobObjectBuilder = new JobObject.Builder(noticeId.toString(), this.getGroupName(), this.getClassName(), TenantContext.get().getTenantUuid()); + JobObject jobObject = jobObjectBuilder.build(); + this.reloadJob(jobObject); + } + } + + @Override + protected Boolean isMyHealthy(JobObject jobObject) { + Long noticeId = Long.valueOf(jobObject.getJobName()); + SystemNoticeVo systemNotice = systemNoticeMapper.getSystemNoticeById(noticeId); + if (systemNotice != null && Objects.equals(systemNotice.getStatus(), SystemNoticeVo.Status.ISSUED.getValue()) && systemNotice.getEndTime() != null) { + return true; + } + return false; + } + + @Override + public void executeInternal(JobExecutionContext context, JobObject jobObject) throws Exception { + Long noticeId = Long.valueOf(jobObject.getJobName()); + SystemNoticeVo systemNotice = systemNoticeMapper.getSystemNoticeById(noticeId); + if (systemNotice != null && Objects.equals(systemNotice.getStatus(), SystemNoticeVo.Status.ISSUED.getValue()) && systemNotice.getStartTime() != null) { + systemNotice.setLcu(SystemUser.SYSTEM.getUserUuid()); + systemNoticeMapper.stopSystemNoticeById(systemNotice); + } + } +} -- Gitee From 6f45e5c0b3cbacde728f1ec65981eafa9d5d2999 Mon Sep 17 00:00:00 2001 From: "1437892690@qq.com" <1437892690@qq.com> Date: Tue, 10 Dec 2024 21:12:27 +0800 Subject: [PATCH 6/6] =?UTF-8?q?[=E5=8A=9F=E8=83=BD]=20=E7=B3=BB=E7=BB=9F?= =?UTF-8?q?=E5=85=AC=E5=91=8A=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 关联 #[1308783484043264]系统公告优化 http://192.168.0.96:8090/demo/rdm.html#/story-detail/939050947543040/939050947543042/1308783484043264 --- .../LoginPullSystemNoticeProcessor.java | 56 +++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 src/main/java/neatlogic/module/framework/systemnotice/login/handler/LoginPullSystemNoticeProcessor.java diff --git a/src/main/java/neatlogic/module/framework/systemnotice/login/handler/LoginPullSystemNoticeProcessor.java b/src/main/java/neatlogic/module/framework/systemnotice/login/handler/LoginPullSystemNoticeProcessor.java new file mode 100644 index 000000000..8ee6cbcd9 --- /dev/null +++ b/src/main/java/neatlogic/module/framework/systemnotice/login/handler/LoginPullSystemNoticeProcessor.java @@ -0,0 +1,56 @@ +/* + * Copyright (C) 2024 深圳极向量科技有限公司 All Rights Reserved. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package neatlogic.module.framework.systemnotice.login.handler; + +import neatlogic.framework.login.core.LoginPostProcessorBase; +import neatlogic.module.framework.systemnotice.service.SystemNoticeService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +/** + * @Title: LoginPullSystemNoticeProcessor + * @Package neatlogic.framework.message.login.handler + * @Description: 登录后拉取系统公告处理器 + * @Author: laiwt + * @Date: 2021/1/15 15:38 + **/ +@Service +public class LoginPullSystemNoticeProcessor extends LoginPostProcessorBase { + + @Autowired + private SystemNoticeService systemNoticeService; + + @Override + protected void myLoginAfterInitialization() { + /** 清理掉system_notice_user中因删除公告或更改公告通知对象而遗留的记录 **/ +// systemNoticeService.clearSystemNoticeUser(); + + /** 检查是否存在【已下发却到了失效时间的】公告,如果有,则停用 **/ +// systemNoticeService.stopExpiredSystemNotice(); + + /** 在system_notice_user插入【当前用户可看的】、【已下发的】公告 **/ + systemNoticeService.pullIssuedSystemNotice(); + + /** + * 检查是否存在【当前用户可看的】、【到了生效时间,却还没下发】公告,如果有,则下发给当前用户 + * 其他的通知用户,如果在线则由前端定时拉取,如果离线则登录时拉取 + **/ +// systemNoticeService.pullActiveSystemNotice(); + } + +} -- Gitee