From 5d34bdd3c426bb2ca5f6627424ae67984f745603 Mon Sep 17 00:00:00 2001
From: liu <2021943741@qq.com>
Date: 星期三, 21 十月 2026 18:28:59 +0800
Subject: [PATCH] feat: 新增资产/用车/采购模块,完善课题、会员、财务与企微功能
---
yudao-module-wxcp/src/main/java/cn/iocoder/yudao/module/wxcp/service/notice/WxCpNoticeServiceImpl.java | 98 +++++++++++++++++++++++++++++++++++++++++++++++-
1 files changed, 95 insertions(+), 3 deletions(-)
diff --git a/yudao-module-wxcp/src/main/java/cn/iocoder/yudao/module/wxcp/service/notice/WxCpNoticeServiceImpl.java b/yudao-module-wxcp/src/main/java/cn/iocoder/yudao/module/wxcp/service/notice/WxCpNoticeServiceImpl.java
index 494e29e..25fcabf 100644
--- a/yudao-module-wxcp/src/main/java/cn/iocoder/yudao/module/wxcp/service/notice/WxCpNoticeServiceImpl.java
+++ b/yudao-module-wxcp/src/main/java/cn/iocoder/yudao/module/wxcp/service/notice/WxCpNoticeServiceImpl.java
@@ -11,12 +11,16 @@
import cn.iocoder.yudao.module.wxcp.dal.mysql.notice.WxCpNoticeMapper;
import cn.iocoder.yudao.module.wxcp.enums.activity.WxCpPushScopeEnum;
import cn.iocoder.yudao.module.wxcp.enums.notice.WxCpNoticeStatusEnum;
+import cn.iocoder.yudao.module.wxcp.enums.notice.WxCpNoticeTypeEnum;
import cn.iocoder.yudao.module.wxcp.service.push.WxCpMessagePushService;
+import cn.iocoder.yudao.module.system.dal.dataobject.storage.SystemStorageBlobDO;
+import cn.iocoder.yudao.module.system.service.storage.SystemStorageBlobService;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;
+import java.io.File;
import java.time.LocalDateTime;
import java.util.Objects;
@@ -43,10 +47,18 @@
private WxCpNoticeMapper wxcpNoticeMapper;
@Resource
private WxCpMessagePushService messagePushService;
+ @Resource
+ private SystemStorageBlobService storageBlobService;
+
+ /** 浼佷笟寰俊鏂囦欢娑堟伅涓婇檺 20MB */
+ private static final long MAX_FILE_SIZE = 20L * 1024L * 1024L;
@Override
public Long createNotice(WxCpNoticeSaveReqVO createReqVO) {
WxCpNoticeDO notice = BeanUtils.toBean(createReqVO, WxCpNoticeDO.class);
+ if (notice.getNoticeType() == null) {
+ notice.setNoticeType(WxCpNoticeTypeEnum.TEXT.getType());
+ }
notice.setStatus(WxCpNoticeStatusEnum.DRAFT.getStatus());
notice.setPushStatus(0);
// 鎺ㄩ�佽寖鍥撮�夊~锛屼笉浼犻粯璁ゅ叏鍛橈紱鎺ㄩ�佹椂杩樿兘鍦ㄥ脊绐楅噷鏀�
@@ -121,9 +133,45 @@
scope = WxCpPushScopeEnum.ALL.getScope();
}
- // 閫氱煡鐢ㄧ函鏂囨湰鎺ㄩ�侊細娌℃湁鍙烦杞殑璇︽儏椤碉紝鑰� textcard 绫诲瀷寮哄埗瑕佹眰 url
- WxCpPushResultVO result = messagePushService.pushText(
- buildPushContent(notice), scope, target);
+ // 鎺ㄩ�佹椂鍏佽閲嶆柊閫夋嫨妯℃澘绫诲瀷锛涙湭閫夋嫨鍒欐部鐢ㄩ�氱煡涓婁繚瀛樼殑妯℃澘
+ Integer noticeType = pushReqVO.getNoticeType() != null
+ ? pushReqVO.getNoticeType()
+ : (notice.getNoticeType() != null ? notice.getNoticeType() : WxCpNoticeTypeEnum.TEXT.getType());
+ String summary = StrUtil.blankToDefault(pushReqVO.getSummary(), notice.getSummary());
+ String linkUrl = StrUtil.blankToDefault(pushReqVO.getLinkUrl(), notice.getLinkUrl());
+ String linkBtnText = StrUtil.blankToDefault(pushReqVO.getLinkBtnText(), notice.getLinkBtnText());
+ String coverUrl = StrUtil.blankToDefault(pushReqVO.getCoverUrl(), notice.getCoverUrl());
+ Long fileBlobId = pushReqVO.getFileBlobId() != null ? pushReqVO.getFileBlobId() : notice.getFileBlobId();
+ String fileName = StrUtil.blankToDefault(pushReqVO.getFileName(), notice.getFileName());
+
+ // 鎸夋湰娆¢�夋嫨鐨勬ā鏉跨被鍨嬫牎楠屽繀濉」
+ if (Objects.equals(noticeType, WxCpNoticeTypeEnum.TEXT.getType())
+ && StrUtil.isBlank(notice.getContent())) {
+ throw exception(NOTICE_CONTENT_REQUIRED);
+ }
+ if ((Objects.equals(noticeType, WxCpNoticeTypeEnum.CARD.getType())
+ || Objects.equals(noticeType, WxCpNoticeTypeEnum.NEWS.getType()))
+ && StrUtil.isBlank(linkUrl)) {
+ throw exception(NOTICE_LINK_URL_REQUIRED);
+ }
+ if (Objects.equals(noticeType, WxCpNoticeTypeEnum.FILE.getType()) && fileBlobId == null) {
+ throw exception(NOTICE_FILE_REQUIRED);
+ }
+
+ WxCpPushResultVO result;
+ if (Objects.equals(noticeType, WxCpNoticeTypeEnum.CARD.getType())) {
+ result = messagePushService.pushCard(notice.getTitle(),
+ StrUtil.blankToDefault(summary, notice.getContent()),
+ linkUrl, StrUtil.blankToDefault(linkBtnText, "鍘诲~鎶�"), scope, target);
+ } else if (Objects.equals(noticeType, WxCpNoticeTypeEnum.FILE.getType())) {
+ result = pushFileNotice(fileBlobId, fileName, notice, scope, target);
+ } else if (Objects.equals(noticeType, WxCpNoticeTypeEnum.NEWS.getType())) {
+ result = messagePushService.pushNews(notice.getTitle(),
+ StrUtil.blankToDefault(summary, notice.getContent()),
+ linkUrl, coverUrl, scope, target);
+ } else {
+ result = messagePushService.pushText(buildPushContent(notice), scope, target);
+ }
if (Boolean.TRUE.equals(result.getSuccess())) {
wxcpNoticeMapper.updateById(WxCpNoticeDO.builder()
@@ -138,6 +186,50 @@
}
/**
+ * 鏂囦欢閫氱煡锛氫粠绯荤粺闄勪欢涓績鍙栨枃浠讹紝浜ょ粰鎺ㄩ�佹湇鍔′笂浼犱紒涓氬井淇″苟鍙戦��
+ */
+ private WxCpPushResultVO pushFileNotice(Long fileBlobId, String fileName, WxCpNoticeDO notice,
+ Integer scope, String target) {
+ if (fileBlobId == null) {
+ throw exception(NOTICE_FILE_REQUIRED);
+ }
+ SystemStorageBlobDO blob = storageBlobService.getStorageBlob(fileBlobId);
+ if (blob == null) {
+ throw exception(NOTICE_FILE_NOT_EXISTS);
+ }
+ if (blob.getByteSize() != null && blob.getByteSize() > MAX_FILE_SIZE) {
+ throw exception(NOTICE_FILE_TOO_LARGE);
+ }
+ File file = storageBlobService.getPublicFile(blob.getUidFilename(), blob.getResourceKey());
+ if (file == null || !file.exists()) {
+ throw exception(NOTICE_FILE_NOT_EXISTS);
+ }
+ String actualFileName = StrUtil.blankToDefault(fileName, blob.getOriginalFilename());
+ return messagePushService.pushFile(file, actualFileName, buildPushContent(notice), scope, target);
+ }
+
+ /**
+ * 鎸夋ā鏉跨被鍨嬫牎楠屽繀濉」
+ */
+ private void validateNoticeByType(WxCpNoticeSaveReqVO reqVO) {
+ Integer type = reqVO.getNoticeType() != null
+ ? reqVO.getNoticeType() : WxCpNoticeTypeEnum.TEXT.getType();
+ if (Objects.equals(type, WxCpNoticeTypeEnum.TEXT.getType())
+ && StrUtil.isBlank(reqVO.getContent())) {
+ throw exception(NOTICE_CONTENT_REQUIRED);
+ }
+ if ((Objects.equals(type, WxCpNoticeTypeEnum.CARD.getType())
+ || Objects.equals(type, WxCpNoticeTypeEnum.NEWS.getType()))
+ && StrUtil.isBlank(reqVO.getLinkUrl())) {
+ throw exception(NOTICE_LINK_URL_REQUIRED);
+ }
+ if (Objects.equals(type, WxCpNoticeTypeEnum.FILE.getType())
+ && reqVO.getFileBlobId() == null) {
+ throw exception(NOTICE_FILE_REQUIRED);
+ }
+ }
+
+ /**
* 鎷艰鎺ㄩ�佹鏂囷細鏍囬鍔犵矖鏍峰紡鐢ㄤ笉浜嗭紝鏀圭敤銆愩�戝寘瑁癸紱杩囬暱鍒欐埅鏂苟鎻愮ず
*/
private String buildPushContent(WxCpNoticeDO notice) {
--
Gitblit v1.9.3