From 10b88a7ff17caf92f3d4e8a550c1085a70c2517a Mon Sep 17 00:00:00 2001
From: gongchunyi <deslre0381@gmail.com>
Date: 星期四, 28 五月 2026 17:43:26 +0800
Subject: [PATCH] Merge dev_New_pro into dev_山西_晋和园_pro
---
src/main/java/com/ruoyi/project/system/service/impl/SysNoticeServiceImpl.java | 109 +++++++++++++++++++++++++++++++++++++++++++++++-------
1 files changed, 94 insertions(+), 15 deletions(-)
diff --git a/src/main/java/com/ruoyi/project/system/service/impl/SysNoticeServiceImpl.java b/src/main/java/com/ruoyi/project/system/service/impl/SysNoticeServiceImpl.java
index dcbcded..3fc9475 100644
--- a/src/main/java/com/ruoyi/project/system/service/impl/SysNoticeServiceImpl.java
+++ b/src/main/java/com/ruoyi/project/system/service/impl/SysNoticeServiceImpl.java
@@ -4,6 +4,8 @@
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.ruoyi.collaborativeApproval.mapper.EnterpriseNewsMapper;
+import com.ruoyi.collaborativeApproval.pojo.EnterpriseNews;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.project.system.domain.SysDept;
import com.ruoyi.project.system.domain.SysNotice;
@@ -15,26 +17,35 @@
import com.ruoyi.project.system.mapper.SysUserMapper;
import com.ruoyi.project.system.service.ISysNoticeService;
import lombok.RequiredArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
+import java.util.HashSet;
import java.util.List;
+import java.util.Set;
import java.util.stream.Collectors;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
/**
* 鍏憡 鏈嶅姟灞傚疄鐜�
*
* @author ruoyi
*/
+@Slf4j
@Service
@RequiredArgsConstructor
public class SysNoticeServiceImpl extends ServiceImpl<SysNoticeMapper, SysNotice> implements ISysNoticeService {
+
+ private static final Pattern ENTERPRISE_NEWS_ID_PATTERN = Pattern.compile("[?&]id=(\\d+)");
private final SysNoticeMapper noticeMapper;
private final SysUserMapper userMapper;
private final SysDeptMapper deptMapper;
private final SysUserDeptMapper userDeptMapper;
private final UnipushService unipushService;
+ private final EnterpriseNewsMapper enterpriseNewsMapper;
/**
* 鏌ヨ鍏憡淇℃伅
@@ -78,9 +89,24 @@
* @return 缁撴灉
*/
@Override
+ @Transactional(rollbackFor = Exception.class)
public int updateNotice(SysNotice notice)
{
- return noticeMapper.updateNotice(notice);
+ if (notice == null || notice.getNoticeId() == null) {
+ return 0;
+ }
+ SysNotice dbNotice = noticeMapper.selectNoticeById(notice.getNoticeId());
+ if (dbNotice == null) {
+ return 0;
+ }
+ boolean needSyncNewsReadCount = isEnterpriseNewsNotice(dbNotice)
+ && notice.getStatus() != null
+ && !notice.getStatus().equals(dbNotice.getStatus());
+ int rows = noticeMapper.updateNotice(notice);
+ if (rows > 0 && needSyncNewsReadCount) {
+ syncEnterpriseNewsReadCount(dbNotice.getJumpPath());
+ }
+ return rows;
}
/**
@@ -117,10 +143,17 @@
@Override
public int readAll() {
Long userId = SecurityUtils.getUserId();
- return noticeMapper.update(null, Wrappers.<SysNotice>lambdaUpdate()
+ List<SysNotice> unreadNotices = noticeMapper.selectList(Wrappers.<SysNotice>lambdaQuery()
+ .eq(SysNotice::getConsigneeId, userId)
+ .eq(SysNotice::getStatus, "0"));
+ int rows = noticeMapper.update(null, Wrappers.<SysNotice>lambdaUpdate()
.eq(SysNotice::getConsigneeId, userId)
.eq(SysNotice::getStatus, "0")
.set(SysNotice::getStatus, "1"));
+ if (rows > 0) {
+ syncEnterpriseNewsReadCount(unreadNotices);
+ }
+ return rows;
}
@Override
@@ -128,14 +161,10 @@
Long userId = SecurityUtils.getLoginUser().getUserId();
Long tenantId = SecurityUtils.getLoginUser().getTenantId();
List<SysNotice> sysNotices = consigneeId.stream()
- .map(it -> convertSysNotice(title, message, it, tenantId, jumpPath, unipushService.convertWebPathToAppPath(jumpPath), userId))
+ .map(it -> convertSysNotice(title, message, it, tenantId, jumpPath, jumpPath, userId))
.collect(Collectors.toList());
noticeMapper.insert(sysNotices);
- try {
- unipushService.sendClientMessage(sysNotices);
- } catch (Exception e) {
- log.error("APP鎺ㄩ�侀�氱煡澶辫触锛屽師鍥�: {}", e);
- }
+ log.info("鍏憡宸蹭繚瀛樿嚦鏁版嵁搴擄紝鎺ㄩ�佸姛鑳藉凡绂佺敤");
}
@Override
@@ -182,16 +211,12 @@
it.getUserId(),
it.getTenantId(),
jumpPath,
- unipushService.convertWebPathToAppPath(jumpPath),
+ jumpPath,
userId
))
.collect(Collectors.toList());
noticeMapper.insert(collect);
- try {
- unipushService.sendClientMessage(collect);
- } catch (Exception e) {
- log.error("APP鎺ㄩ�侀�氱煡澶辫触锛屽師鍥�: {}", e);
- }
+ log.info("鍏憡宸蹭繚瀛樿嚦鏁版嵁搴擄紝鎺ㄩ�佸姛鑳藉凡绂佺敤");
}
@@ -220,9 +245,63 @@
return false;
}
sysNotice.setStatus("1");
- return noticeMapper.update(null, Wrappers.<SysNotice>lambdaUpdate()
+ boolean updated = noticeMapper.update(null, Wrappers.<SysNotice>lambdaUpdate()
.eq(SysNotice::getNoticeId, noticeId)
.eq(SysNotice::getStatus, "0")
.set(SysNotice::getStatus, "1")) > 0;
+ if (updated) {
+ syncEnterpriseNewsReadCount(sysNotice.getJumpPath());
+ }
+ return updated;
+ }
+
+ private boolean isEnterpriseNewsNotice(SysNotice sysNotice) {
+ return sysNotice != null
+ && sysNotice.getJumpPath() != null
+ && sysNotice.getJumpPath().contains("/enterpriseNews?id=");
+ }
+
+ private void syncEnterpriseNewsReadCount(List<SysNotice> notices) {
+ if (notices == null || notices.isEmpty()) {
+ return;
+ }
+ Set<String> jumpPaths = new HashSet<>();
+ for (SysNotice notice : notices) {
+ if (isEnterpriseNewsNotice(notice)) {
+ jumpPaths.add(notice.getJumpPath());
+ }
+ }
+ for (String jumpPath : jumpPaths) {
+ syncEnterpriseNewsReadCount(jumpPath);
+ }
+ }
+
+ private void syncEnterpriseNewsReadCount(String jumpPath) {
+ Long newsId = parseEnterpriseNewsId(jumpPath);
+ if (newsId == null) {
+ return;
+ }
+ long readCount = noticeMapper.selectCount(Wrappers.<SysNotice>lambdaQuery()
+ .eq(SysNotice::getStatus, "1")
+ .eq(SysNotice::getJumpPath, jumpPath));
+ EnterpriseNews enterpriseNews = new EnterpriseNews();
+ enterpriseNews.setId(newsId);
+ enterpriseNews.setReadCount((int) readCount);
+ enterpriseNewsMapper.updateById(enterpriseNews);
+ }
+
+ private Long parseEnterpriseNewsId(String jumpPath) {
+ if (jumpPath == null || !jumpPath.startsWith("/enterpriseNews")) {
+ return null;
+ }
+ Matcher matcher = ENTERPRISE_NEWS_ID_PATTERN.matcher(jumpPath);
+ if (!matcher.find()) {
+ return null;
+ }
+ try {
+ return Long.parseLong(matcher.group(1));
+ } catch (NumberFormatException e) {
+ return null;
+ }
}
}
--
Gitblit v1.9.3