From 47dd1ecaf0aafa66b9c39fff9c91abc1c611b02c Mon Sep 17 00:00:00 2001
From: liu <2021943741@qq.com>
Date: 星期二, 27 十月 2026 17:59:46 +0800
Subject: [PATCH] feat(wxcp): 通知支持图片/视频/Markdown/多图文模板与成员预览
---
yudao-module-wxcp/src/main/java/cn/iocoder/yudao/module/wxcp/controller/admin/notice/WxCpNoticePublicController.java | 328 ++++++++++++++
docs/sql/wxcp_module.sql | 25 +
yudao-module-wxcp/src/main/java/cn/iocoder/yudao/module/wxcp/controller/admin/notice/WxCpNoticeController.java | 23 +
yudao-module-wxcp/src/main/java/cn/iocoder/yudao/module/wxcp/controller/admin/notice/vo/WxCpNoticeArticleSaveReqVO.java | 35 +
yudao-module-system/src/main/java/cn/iocoder/yudao/module/system/enums/storage/StorageRecordTypeEnum.java | 8
docs/sql/README.md | 2
yudao-module-wxcp/src/main/java/cn/iocoder/yudao/module/wxcp/controller/admin/vo/WxCpPushReqVO.java | 28 +
yudao-module-wxcp/src/main/java/cn/iocoder/yudao/module/wxcp/dal/mysql/notice/WxCpNoticeArticleMapper.java | 30 +
yudao-module-wxcp/src/main/java/cn/iocoder/yudao/module/wxcp/controller/admin/notice/vo/WxCpNoticeRespVO.java | 33 +
yudao-module-wxcp/src/main/java/cn/iocoder/yudao/module/wxcp/service/push/WxCpMessagePushServiceImpl.java | 46 ++
yudao-module-wxcp/src/main/java/cn/iocoder/yudao/module/wxcp/controller/admin/notice/vo/WxCpNoticeArticleRespVO.java | 32 +
yudao-module-wxcp/src/main/java/cn/iocoder/yudao/module/wxcp/dal/dataobject/notice/WxCpNoticeArticleDO.java | 54 ++
yudao-module-wxcp/src/main/java/cn/iocoder/yudao/module/wxcp/enums/ErrorCodeConstants.java | 15
yudao-module-wxcp/src/main/java/cn/iocoder/yudao/module/wxcp/service/push/WxCpMessagePushService.java | 34 +
yudao-module-wxcp/src/main/java/cn/iocoder/yudao/module/wxcp/controller/admin/notice/vo/WxCpNoticeSaveReqVO.java | 27 +
yudao-module-wxcp/src/main/java/cn/iocoder/yudao/module/wxcp/enums/notice/WxCpNoticeTypeEnum.java | 4
yudao-module-wxcp/src/main/java/cn/iocoder/yudao/module/wxcp/service/notice/WxCpNoticeService.java | 52 ++
yudao-module-wxcp/src/main/java/cn/iocoder/yudao/module/wxcp/service/notice/WxCpNoticeServiceImpl.java | 572 +++++++++++++++++++++++-
18 files changed, 1,303 insertions(+), 45 deletions(-)
diff --git a/docs/sql/README.md b/docs/sql/README.md
index 51895b5..efae3cd 100644
--- a/docs/sql/README.md
+++ b/docs/sql/README.md
@@ -3,3 +3,5 @@
鏈」鐩寘鍚殑 SQL 鑴氭湰姹囨�诲涓嬶細
- [mes_pro_task_assignee.sql](mes_pro_task_assignee.sql): 澧炲姞鐢熶骇浠诲姟鎶ュ伐浜哄憳鍏宠仈琛紝鐢ㄤ簬澶氫汉鍛樻姤宸ュ垎閰嶃��
+- [wxcp_notice_image_20261027.sql](wxcp_notice_image_20261027.sql): 浼佷笟寰俊閫氱煡鏂板銆屽浘鐗囬�氱煡銆嶆ā鏉夸笌澶氶檮浠舵敮鎸侊紝浠呮洿鏂� notice_type 娉ㄩ噴锛堝浘鐗�/闄勪欢璧伴檮浠朵腑闂磋〃锛屾棤鏂板瀛楁锛夈��
+- [wxcp_notice_templates_extend_20261027.sql](wxcp_notice_templates_extend_20261027.sql): 浼佷笟寰俊閫氱煡鎵╁睍銆岃棰�/Markdown/澶氬浘鏂囥�嶆ā鏉匡紝鏂板澶氬浘鏂囧瓙琛� wxcp_notice_article锛屽苟鏇存柊 notice_type 娉ㄩ噴銆�
diff --git a/docs/sql/wxcp_module.sql b/docs/sql/wxcp_module.sql
index b27c5da..765338f 100644
--- a/docs/sql/wxcp_module.sql
+++ b/docs/sql/wxcp_module.sql
@@ -8,6 +8,8 @@
-- 娲诲姩灏侀潰 record_type = 'wxcp_activity'锛屾椿鍔ㄨ鎯呭浘鐗� record_type = 'wxcp_activity_detail'锛�
-- 鍥剧墖閫氱煡 record_type = 'wxcp_activity_image'锛岄檮浠堕�氱煡 record_type = 'wxcp_activity_file'锛�
-- 鎶ュ悕闄勪欢 record_type = 'wxcp_activity_signup'
+-- 閫氱煡妯″潡鐨勭礌鏉愬悓鐞嗭細record_type = 'wxcp_notice_image' / 'wxcp_notice_file' /
+-- 'wxcp_notice_video' / 'wxcp_notice_article_cover'
-- ============================================================
-- ----------------------------
@@ -80,7 +82,7 @@
`id` bigint NOT NULL AUTO_INCREMENT COMMENT '缂栧彿',
`title` varchar(128) NOT NULL COMMENT '閫氱煡鏍囬',
`content` text COMMENT '閫氱煡姝f枃',
- `notice_type` tinyint NOT NULL DEFAULT 1 COMMENT '閫氱煡妯℃澘锛�1绾枃鏈� 2鍥炬枃鍗$墖(濉姤/閾炬帴) 3鏂囦欢閫氱煡 4鍥炬枃娑堟伅',
+ `notice_type` tinyint NOT NULL DEFAULT 1 COMMENT '閫氱煡妯℃澘锛�1绾枃鏈� 2鍥炬枃鍗$墖(濉姤/閾炬帴) 3鏂囦欢閫氱煡 4鍥炬枃娑堟伅 5鍥剧墖閫氱煡 6瑙嗛閫氱煡 7Markdown 8澶氬浘鏂囨秷鎭�',
`summary` varchar(512) DEFAULT NULL COMMENT '鎽樿锛堝浘鏂囧崱鐗�/鍥炬枃娑堟伅锛�',
`link_url` varchar(1024) DEFAULT NULL COMMENT '璺宠浆閾炬帴锛堝~鎶�/璇︽儏锛�',
`link_btn_text` varchar(32) DEFAULT NULL COMMENT '閾炬帴鎸夐挳鏂囨',
@@ -102,6 +104,27 @@
KEY `idx_status` (`status`)
) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4 COMMENT = '浼佷笟寰俊閫氱煡';
+-- ----------------------------
+-- 閫氱煡 - 澶氬浘鏂囨秷鎭潯鐩�
+-- 浠呫�屽鍥炬枃娑堟伅銆嶆ā鏉夸娇鐢紱灏侀潰鍥惧彧瀛� blob_id锛屽湴鍧�璧伴檮浠朵腑闂磋〃
+-- ----------------------------
+CREATE TABLE IF NOT EXISTS `wxcp_notice_article` (
+ `id` bigint NOT NULL AUTO_INCREMENT COMMENT '缂栧彿',
+ `notice_id` bigint NOT NULL COMMENT '閫氱煡缂栧彿',
+ `title` varchar(128) NOT NULL COMMENT '鍥炬枃鏍囬',
+ `description` varchar(512) DEFAULT NULL COMMENT '鍥炬枃鎽樿',
+ `link_url` varchar(1024) NOT NULL COMMENT '鐐瑰嚮璺宠浆閾炬帴',
+ `cover_blob_id` bigint DEFAULT NULL COMMENT '灏侀潰鍥� Blob ID',
+ `sort_no` int NOT NULL DEFAULT 0 COMMENT '鎺掑簭鍙�',
+ `creator` varchar(64) DEFAULT '' COMMENT '鍒涘缓鑰�',
+ `create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '鍒涘缓鏃堕棿',
+ `updater` varchar(64) DEFAULT '' COMMENT '鏇存柊鑰�',
+ `update_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '鏇存柊鏃堕棿',
+ `deleted` bit(1) NOT NULL DEFAULT b'0' COMMENT '鏄惁鍒犻櫎',
+ PRIMARY KEY (`id`),
+ KEY `idx_notice_id` (`notice_id`)
+) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4 COMMENT = '浼佷笟寰俊閫氱煡澶氬浘鏂囨秷鎭潯鐩�';
+
-- ============================================================
-- 鍗囩骇鑴氭湰锛氬皝闈㈠浘浠庛�屼笟鍔¤〃瀛樺湴鍧�銆嶆敼涓恒�岄檮浠朵腑闂磋〃銆�
-- 宸插缓杩囧簱鐨勭幆澧冩墽琛屼竴娆″嵆鍙紱鏂板簱鎵ц涓婇潰鐨� CREATE TABLE 宸叉槸鏈�鏂扮粨鏋勶紝鏃犻渶鎵ц
diff --git a/yudao-module-system/src/main/java/cn/iocoder/yudao/module/system/enums/storage/StorageRecordTypeEnum.java b/yudao-module-system/src/main/java/cn/iocoder/yudao/module/system/enums/storage/StorageRecordTypeEnum.java
index 4de01bb..451e204 100644
--- a/yudao-module-system/src/main/java/cn/iocoder/yudao/module/system/enums/storage/StorageRecordTypeEnum.java
+++ b/yudao-module-system/src/main/java/cn/iocoder/yudao/module/system/enums/storage/StorageRecordTypeEnum.java
@@ -89,7 +89,13 @@
WXCP_ACTIVITY_DETAIL("wxcp_activity_detail", "浼佷笟寰俊娲诲姩璇︽儏鍥�"),
WXCP_ACTIVITY_IMAGE("wxcp_activity_image", "浼佷笟寰俊娲诲姩鍥剧墖閫氱煡"),
WXCP_ACTIVITY_FILE("wxcp_activity_file", "浼佷笟寰俊娲诲姩闄勪欢閫氱煡"),
- WXCP_ACTIVITY_SIGNUP("wxcp_activity_signup", "浼佷笟寰俊娲诲姩鎶ュ悕");
+ WXCP_ACTIVITY_SIGNUP("wxcp_activity_signup", "浼佷笟寰俊娲诲姩鎶ュ悕"),
+
+ // ===== 浼佷笟寰俊閫氱煡 =====
+ WXCP_NOTICE_IMAGE("wxcp_notice_image", "浼佷笟寰俊閫氱煡鍥剧墖"),
+ WXCP_NOTICE_FILE("wxcp_notice_file", "浼佷笟寰俊閫氱煡闄勪欢"),
+ WXCP_NOTICE_VIDEO("wxcp_notice_video", "浼佷笟寰俊閫氱煡瑙嗛"),
+ WXCP_NOTICE_ARTICLE_COVER("wxcp_notice_article_cover", "浼佷笟寰俊閫氱煡鍥炬枃灏侀潰");
private final String type;
private final String description;
diff --git a/yudao-module-wxcp/src/main/java/cn/iocoder/yudao/module/wxcp/controller/admin/notice/WxCpNoticeController.java b/yudao-module-wxcp/src/main/java/cn/iocoder/yudao/module/wxcp/controller/admin/notice/WxCpNoticeController.java
index 7e71f27..fb1ea6c 100644
--- a/yudao-module-wxcp/src/main/java/cn/iocoder/yudao/module/wxcp/controller/admin/notice/WxCpNoticeController.java
+++ b/yudao-module-wxcp/src/main/java/cn/iocoder/yudao/module/wxcp/controller/admin/notice/WxCpNoticeController.java
@@ -3,6 +3,8 @@
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
+import cn.iocoder.yudao.module.system.controller.admin.storage.vo.SystemStorageBlobRespVO;
+import cn.iocoder.yudao.module.wxcp.controller.admin.notice.vo.WxCpNoticeArticleRespVO;
import cn.iocoder.yudao.module.wxcp.controller.admin.notice.vo.WxCpNoticePageReqVO;
import cn.iocoder.yudao.module.wxcp.controller.admin.notice.vo.WxCpNoticeRespVO;
import cn.iocoder.yudao.module.wxcp.controller.admin.notice.vo.WxCpNoticeSaveReqVO;
@@ -21,6 +23,8 @@
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
+
+import java.util.List;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
@@ -112,6 +116,23 @@
}
WxCpNoticeRespVO vo = BeanUtils.toBean(notice, WxCpNoticeRespVO.class);
fillNames(vo);
+ // 绱犳潗璇︽儏闇�瑕佸洖鏄撅紝鍒楄〃椤典笉鍥炴樉浠ュ厤澶氭煡闄勪欢琛�
+ vo.setImageAttachmentList(noticeService.getNoticeImageAttachments(notice.getId()));
+ vo.setFileAttachmentList(noticeService.getNoticeFileAttachments(notice.getId()));
+ vo.setVideoAttachmentList(noticeService.getNoticeVideoAttachments(notice.getId()));
+ vo.setImageBlobIds(vo.getImageAttachmentList().stream()
+ .map(SystemStorageBlobRespVO::getId).toList());
+ vo.setFileBlobIds(vo.getFileAttachmentList().stream()
+ .map(SystemStorageBlobRespVO::getId).toList());
+ vo.setVideoBlobIds(vo.getVideoAttachmentList().stream()
+ .map(SystemStorageBlobRespVO::getId).toList());
+ vo.setArticleList(noticeService.getNoticeArticles(notice.getId()).stream().map(article -> {
+ WxCpNoticeArticleRespVO item = BeanUtils.toBean(article, WxCpNoticeArticleRespVO.class);
+ List<SystemStorageBlobRespVO> covers =
+ noticeService.getNoticeArticleCoverAttachments(article.getId());
+ item.setCoverAttachment(covers.isEmpty() ? null : covers.get(0));
+ return item;
+ }).toList());
return vo;
}
@@ -122,6 +143,8 @@
vo.setNoticeTypeName(type != null ? type.getName() : null);
WxCpPushScopeEnum scope = WxCpPushScopeEnum.valueOf(vo.getPushScope());
vo.setPushScopeName(scope != null ? scope.getName() : null);
+ // 棰勮閾炬帴鍙緷璧栭厤缃紝鍒楄〃椤典篃鑳界洿鎺ョ粰鍑猴紝鏂逛究绠$悊鍛樺鍒跺彂缁欐垚鍛�
+ vo.setPreviewUrl(noticeService.buildPreviewUrl(vo.getId()));
}
}
diff --git a/yudao-module-wxcp/src/main/java/cn/iocoder/yudao/module/wxcp/controller/admin/notice/WxCpNoticePublicController.java b/yudao-module-wxcp/src/main/java/cn/iocoder/yudao/module/wxcp/controller/admin/notice/WxCpNoticePublicController.java
new file mode 100644
index 0000000..af9d5f5
--- /dev/null
+++ b/yudao-module-wxcp/src/main/java/cn/iocoder/yudao/module/wxcp/controller/admin/notice/WxCpNoticePublicController.java
@@ -0,0 +1,328 @@
+package cn.iocoder.yudao.module.wxcp.controller.admin.notice;
+
+import cn.hutool.core.collection.CollUtil;
+import cn.hutool.core.util.StrUtil;
+import cn.iocoder.yudao.module.system.controller.admin.storage.vo.SystemStorageBlobRespVO;
+import cn.iocoder.yudao.module.wxcp.dal.dataobject.notice.WxCpNoticeDO;
+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.notice.WxCpNoticeService;
+import io.swagger.v3.oas.annotations.Operation;
+import io.swagger.v3.oas.annotations.Parameter;
+import io.swagger.v3.oas.annotations.tags.Tag;
+import jakarta.annotation.Resource;
+import jakarta.annotation.security.PermitAll;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.http.MediaType;
+import org.springframework.validation.annotation.Validated;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestParam;
+import org.springframework.web.bind.annotation.RestController;
+
+import java.net.URI;
+import java.util.List;
+import java.util.Objects;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+/**
+ * 浼佷笟寰俊閫氱煡 - 鎴愬憳棰勮椤碉紙鍏嶇櫥褰曪級
+ *
+ * 璇存槑锛氭斁鍦� controller.admin 鍖呬笅浠庤�屽甫涓� /admin-api 鍓嶇紑銆�
+ * 鍓嶇 Vite 寮�鍙戜唬鐞嗗彧杞彂 /admin-api锛岃嫢鏀惧埌 /app-api锛�
+ * 鎴愬憳鍦ㄤ紒涓氬井淇¢噷鎵撳紑閾炬帴浼氭墦鍒板墠绔潤鎬佹湇鍔¤繑鍥� 404銆�
+ *
+ * @author 瓒呯骇绠$悊鍛�
+ */
+@Tag(name = "鐢ㄦ埛 App - 浼佷笟寰俊閫氱煡棰勮")
+@RestController
+@RequestMapping("/wxcp/notice")
+@Validated
+@Slf4j
+public class WxCpNoticePublicController {
+
+ /** 琛屽唴浠g爜 */
+ private static final Pattern MD_CODE = Pattern.compile("`([^`]+)`");
+ /** 鍔犵矖 */
+ private static final Pattern MD_STRONG = Pattern.compile("\\*\\*(.+?)\\*\\*");
+ /** 閾炬帴 [鏂囨](鍦板潃) */
+ private static final Pattern MD_LINK = Pattern.compile("\\[([^\\]]+)]\\(([^)]+)\\)");
+
+ @Resource
+ private WxCpNoticeService noticeService;
+
+ @GetMapping(value = "/preview-page", produces = MediaType.TEXT_HTML_VALUE)
+ @PermitAll
+ @Operation(summary = "閫氱煡棰勮椤碉紙HTML锛�", description = "鍥剧墖/闄勪欢閫氱煡鎺ㄩ�佺粰鎴愬憳鍚庯紝鎴愬憳鎵撳紑姝ら〉鏌ョ湅鍥剧墖涓庨檮浠�")
+ @Parameter(name = "id", description = "閫氱煡缂栧彿", required = true)
+ public String previewPage(@RequestParam("id") Long id) {
+ WxCpNoticeDO notice = noticeService.getNotice(id);
+ if (notice == null) {
+ return renderMessagePage("閫氱煡涓嶅瓨鍦�", "閫氱煡鍙兘宸茶鍒犻櫎锛岃鑱旂郴閫氱煡鍙戣捣浜虹‘璁ゃ��");
+ }
+ if (!WxCpNoticeStatusEnum.PUBLISHED.getStatus().equals(notice.getStatus())) {
+ return renderMessagePage("閫氱煡鏈紑鏀�", "璇ラ�氱煡灏氭湭鍙戝竷鎴栧凡鎾ゅ洖锛岃鑱旂郴閫氱煡鍙戣捣浜虹‘璁ゃ��");
+ }
+ return renderPreviewPage(notice);
+ }
+
+ private String renderPreviewPage(WxCpNoticeDO notice) {
+ List<SystemStorageBlobRespVO> images = noticeService.getNoticeImageAttachments(notice.getId());
+ List<SystemStorageBlobRespVO> files = noticeService.getNoticeFileAttachments(notice.getId());
+ List<SystemStorageBlobRespVO> videos = noticeService.getNoticeVideoAttachments(notice.getId());
+
+ StringBuilder sb = new StringBuilder(2048);
+ sb.append("<!DOCTYPE html><html lang=\"zh-CN\"><head><meta charset=\"UTF-8\">")
+ .append("<meta name=\"viewport\" content=\"width=device-width,initial-scale=1,maximum-scale=1\">")
+ .append("<title>").append(esc(notice.getTitle())).append("</title>")
+ .append("<style>")
+ .append("*{box-sizing:border-box;-webkit-tap-highlight-color:transparent}")
+ .append("body{margin:0;padding:16px;font-family:-apple-system,BlinkMacSystemFont,'PingFang SC','Microsoft YaHei',sans-serif;")
+ .append("background:#f5f6f8;color:#1f2329;font-size:15px;line-height:1.6}")
+ .append(".card{background:#fff;border-radius:12px;padding:18px;margin-bottom:12px;box-shadow:0 1px 4px rgba(0,0,0,.06)}")
+ .append("h1{font-size:19px;margin:0 0 14px;font-weight:600;word-break:break-all}")
+ .append(".desc{white-space:pre-wrap;word-break:break-word;color:#3f444d}")
+ .append(".detail-img{display:block;margin:12px 0 0}")
+ .append(".detail-img img{display:block;width:100%;height:auto;border-radius:8px;background:#f2f3f5}")
+ .append(".file-title{font-weight:600;margin-bottom:8px}")
+ .append(".file-list div{padding:8px 0;border-bottom:1px solid #f0f1f3;word-break:break-all}")
+ .append(".file-list div:last-child{border-bottom:0}")
+ .append(".file-list a{color:#3370ff;text-decoration:none}")
+ .append(".file-size{color:#8f959e;font-size:12px;margin-left:6px}")
+ .append(".video-wrap video{display:block;width:100%;border-radius:8px;background:#000}")
+ .append(".markdown h1,.markdown h2,.markdown h3{margin:14px 0 8px;font-weight:600;line-height:1.4}")
+ .append(".markdown h1{font-size:19px}.markdown h2{font-size:17px}.markdown h3{font-size:16px}")
+ .append(".markdown p{margin:8px 0}")
+ .append(".markdown ul,.markdown ol{margin:8px 0;padding-left:20px}")
+ .append(".markdown li{margin:4px 0}")
+ .append(".markdown blockquote{margin:10px 0;padding:8px 12px;border-left:3px solid #dee0e3;")
+ .append("background:#f7f8fa;color:#646a73;border-radius:4px}")
+ .append(".markdown code{padding:1px 5px;border-radius:4px;background:#f2f3f5;font-size:13px}")
+ .append(".markdown a{color:#3370ff;text-decoration:none}")
+ .append(".btn{display:block;margin-top:16px;padding:12px;border-radius:8px;background:#3370ff;color:#fff;")
+ .append("font-size:15px;font-weight:500;text-align:center;text-decoration:none}")
+ .append(".tip{margin-top:12px;font-size:12px;color:#8f959e;text-align:center}")
+ .append("</style></head><body>");
+
+ sb.append("<div class=\"card\"><h1>").append(esc(notice.getTitle())).append("</h1>");
+ if (StrUtil.isNotBlank(notice.getContent())) {
+ if (Objects.equals(notice.getNoticeType(), WxCpNoticeTypeEnum.MARKDOWN.getType())) {
+ // Markdown 閫氱煡鍦ㄩ瑙堥〉鎸夊瘜鏂囨湰灞曠ず锛屾覆鏌撳墠宸插鐢ㄦ埛鍐呭鍋� HTML 杞箟
+ sb.append("<div class=\"desc markdown\">").append(renderMarkdown(notice.getContent())).append("</div>");
+ } else {
+ sb.append("<div class=\"desc\">").append(esc(notice.getContent())).append("</div>");
+ }
+ }
+ if (StrUtil.isNotBlank(notice.getLinkUrl())) {
+ String link = StrUtil.blankToDefault(notice.getLinkBtnText(), "鏌ョ湅璇︽儏");
+ sb.append("<a class=\"btn\" href=\"").append(esc(notice.getLinkUrl()))
+ .append("\" target=\"_blank\" rel=\"noopener\">").append(esc(link)).append("</a>");
+ }
+ sb.append("</div>");
+
+ // 鍥剧墖锛氭寜鍘熷浘姣斾緥瀹屾暣灞曠ず锛岀偣涓�涓嬬敤娴忚鍣ㄦ墦寮�鍘熷浘锛屾柟渚挎斁澶ф煡鐪�
+ if (CollUtil.isNotEmpty(images)) {
+ sb.append("<div class=\"card\">");
+ for (SystemStorageBlobRespVO image : images) {
+ String raw = StrUtil.blankToDefault(image.getPreviewURL(), image.getUrl());
+ if (StrUtil.isBlank(raw)) {
+ continue;
+ }
+ String url = toSameOriginUrl(raw);
+ sb.append("<a class=\"detail-img\" href=\"").append(esc(url))
+ .append("\" target=\"_blank\" rel=\"noopener\">")
+ .append("<img src=\"").append(esc(url)).append("\" alt=\"閫氱煡鍥剧墖\">")
+ .append("</a>");
+ }
+ sb.append("</div>");
+ }
+
+ // 瑙嗛锛氭垚鍛樼偣寮�鍗冲彲鎾斁
+ if (CollUtil.isNotEmpty(videos)) {
+ sb.append("<div class=\"card\">");
+ for (SystemStorageBlobRespVO video : videos) {
+ String raw = StrUtil.blankToDefault(video.getPreviewURL(), video.getUrl());
+ if (StrUtil.isBlank(raw)) {
+ continue;
+ }
+ String url = toSameOriginUrl(raw);
+ sb.append("<div class=\"video-wrap\"><video controls preload=\"metadata\" src=\"")
+ .append(esc(url)).append("\"></video></div>");
+ }
+ sb.append("</div>");
+ }
+
+ // 闄勪欢锛氭垚鍛樼偣寮�鍗冲彲棰勮/涓嬭浇
+ if (CollUtil.isNotEmpty(files)) {
+ sb.append("<div class=\"card\"><div class=\"file-title\">闄勪欢</div><div class=\"file-list\">");
+ for (SystemStorageBlobRespVO file : files) {
+ String raw = StrUtil.blankToDefault(file.getDownloadURL(),
+ StrUtil.blankToDefault(file.getUrl(), file.getPreviewURL()));
+ if (StrUtil.isBlank(raw)) {
+ continue;
+ }
+ String url = toSameOriginUrl(raw);
+ String name = StrUtil.blankToDefault(file.getOriginalFilename(),
+ StrUtil.blankToDefault(file.getName(), "闄勪欢"));
+ sb.append("<div><a href=\"").append(esc(url)).append("\" target=\"_blank\" rel=\"noopener\">")
+ .append(esc(name)).append("</a>");
+ if (file.getByteSize() != null) {
+ sb.append("<span class=\"file-size\">").append(formatSize(file.getByteSize())).append("</span>");
+ }
+ sb.append("</div>");
+ }
+ sb.append("</div></div>");
+ }
+
+ sb.append("<div class=\"tip\">鏉ヨ嚜浼佷笟寰俊閫氱煡锛岃鍦ㄤ紒涓氬井淇″唴鏌ョ湅</div></body></html>");
+ return sb.toString();
+ }
+
+ private String formatSize(Long bytes) {
+ if (bytes == null || bytes <= 0) {
+ return "";
+ }
+ if (bytes < 1024) {
+ return bytes + " B";
+ }
+ if (bytes < 1024 * 1024) {
+ return String.format("%.1f KB", bytes / 1024.0);
+ }
+ return String.format("%.1f MB", bytes / (1024.0 * 1024.0));
+ }
+
+ /**
+ * 鎶婇檮浠跺湴鍧�杞垚鍚屾簮鐩稿鍦板潃
+ *
+ * 闄勪欢閲屽瓨鐨勬槸甯︾鍚嶇殑缁濆鍦板潃锛屽煙鍚嶅彇鑷� yudao.storage.domain锛堥�氬父鏄唴缃戝湴鍧�锛夈��
+ * 鎴愬憳鎵嬫満閫氳繃鍏綉鍩熷悕鎵撳紑鏈〉鏃剁洿杩炲唴缃戝湴鍧�浼氬姞杞戒笉鍑哄浘鐗囷紝
+ * 杩欓噷鍓ユ帀鍗忚涓庡煙鍚嶅彧鐣� /admin-api/... 璺緞锛屼氦缁欏悓婧愪唬鐞嗚浆鍙戙��
+ */
+ private String toSameOriginUrl(String url) {
+ String trimmed = url.trim();
+ if (!StrUtil.startWithAnyIgnoreCase(trimmed, "http://", "https://")) {
+ return trimmed;
+ }
+ try {
+ URI uri = URI.create(trimmed);
+ String path = uri.getRawPath();
+ if (StrUtil.isBlank(path)) {
+ return trimmed;
+ }
+ String query = uri.getRawQuery();
+ return StrUtil.isBlank(query) ? path : path + "?" + query;
+ } catch (IllegalArgumentException e) {
+ // 鍦板潃涓嶅悎瑙勫氨鍘熸牱閫忓嚭锛屼笉鑳藉洜涓轰竴寮犲浘鐗囪鏁撮〉鎵撲笉寮�
+ log.warn("閫氱煡闄勪欢鍦板潃瑙f瀽澶辫触锛屾寜鍘熸牱杈撳嚭锛歿}", trimmed);
+ return trimmed;
+ }
+ }
+
+ private String renderMessagePage(String title, String desc) {
+ return "<!DOCTYPE html><html lang=\"zh-CN\"><head><meta charset=\"UTF-8\">"
+ + "<meta name=\"viewport\" content=\"width=device-width,initial-scale=1\">"
+ + "<title>" + esc(title) + "</title><style>"
+ + "body{margin:0;padding:60px 24px;font-family:-apple-system,'PingFang SC','Microsoft YaHei',sans-serif;"
+ + "background:#f5f6f8;color:#1f2329;text-align:center}"
+ + "h1{font-size:18px;font-weight:600;margin:0 0 12px}"
+ + "p{color:#646a73;font-size:14px;line-height:1.7;margin:0}"
+ + "</style></head><body><h1>" + esc(title) + "</h1><p>" + esc(desc) + "</p></body></html>";
+ }
+
+ /**
+ * 杞婚噺 Markdown 娓叉煋锛氬彧鏀寔浼佷笟寰俊閫氱煡甯哥敤鐨勬爣棰樸�佸姞绮椼�佸垪琛ㄣ�佸紩鐢ㄣ�佷唬鐮併�侀摼鎺ャ�佸垎闅旂嚎
+ *
+ * 瀹夊叏鍓嶆彁锛氭墍鏈夌敤鎴峰唴瀹瑰厛鐢� {@link #esc(String)} 杞箟锛屼箣鍚庢墠鎷兼帴鏍囩锛�
+ * 鍥犳涓嶄細鎵ц鍘熷 HTML锛涢摼鎺ュ彧鍏佽 http/https/绔欏唴璺緞銆�
+ */
+ private String renderMarkdown(String markdown) {
+ String normalized = markdown.replace("\r\n", "\n").replace("\r", "\n");
+ String[] lines = normalized.split("\n", -1);
+ StringBuilder html = new StringBuilder(1024);
+ boolean inList = false;
+ for (String rawLine : lines) {
+ String line = rawLine.trim();
+ if (line.isEmpty()) {
+ if (inList) {
+ html.append("</ul>");
+ inList = false;
+ }
+ continue;
+ }
+ if (line.startsWith("- ") || line.startsWith("* ")) {
+ if (!inList) {
+ html.append("<ul>");
+ inList = true;
+ }
+ html.append("<li>").append(renderInline(line.substring(2))).append("</li>");
+ continue;
+ }
+ if (inList) {
+ html.append("</ul>");
+ inList = false;
+ }
+ if (line.startsWith("### ")) {
+ html.append("<h3>").append(renderInline(line.substring(4))).append("</h3>");
+ } else if (line.startsWith("## ")) {
+ html.append("<h2>").append(renderInline(line.substring(3))).append("</h2>");
+ } else if (line.startsWith("# ")) {
+ html.append("<h1>").append(renderInline(line.substring(2))).append("</h1>");
+ } else if (line.startsWith("> ")) {
+ html.append("<blockquote>").append(renderInline(line.substring(2))).append("</blockquote>");
+ } else if ("---".equals(line) || "***".equals(line)) {
+ html.append("<hr>");
+ } else {
+ html.append("<p>").append(renderInline(line)).append("</p>");
+ }
+ }
+ if (inList) {
+ html.append("</ul>");
+ }
+ return html.toString();
+ }
+
+ /**
+ * 娓叉煋琛屽唴 Markdown锛涜緭鍏ュ凡杞箟锛岃緭鍑哄彧鍖呭惈鍙楁帶鏍囩
+ */
+ private String renderInline(String text) {
+ String result = esc(text);
+ result = MD_CODE.matcher(result).replaceAll("<code>$1</code>");
+ result = MD_STRONG.matcher(result).replaceAll("<strong>$1</strong>");
+ Matcher matcher = MD_LINK.matcher(result);
+ StringBuilder sb = new StringBuilder();
+ while (matcher.find()) {
+ String label = matcher.group(1);
+ String url = matcher.group(2).trim();
+ String replacement = isSafeUrl(url)
+ ? "<a href=\"" + url + "\" target=\"_blank\" rel=\"noopener\">" + label + "</a>"
+ : label;
+ matcher.appendReplacement(sb, Matcher.quoteReplacement(replacement));
+ }
+ matcher.appendTail(sb);
+ return sb.toString();
+ }
+
+ /**
+ * 鍙厑璁� http/https 涓庣珯鍐呰矾寰勶紝閬垮厤 javascript: 绛夊嵄闄╁崗璁�
+ */
+ private boolean isSafeUrl(String url) {
+ String lower = url.trim().toLowerCase();
+ return lower.startsWith("http://") || lower.startsWith("https://") || lower.startsWith("/");
+ }
+
+ /**
+ * HTML 杞箟锛岄伩鍏嶉�氱煡鏍囬/鍐呭閲岀殑鐗规畩瀛楃鐮村潖椤甸潰鎴栭�犳垚 XSS
+ */
+ private String esc(String raw) {
+ if (raw == null) {
+ return "";
+ }
+ return raw.replace("&", "&")
+ .replace("<", "<")
+ .replace(">", ">")
+ .replace("\"", """)
+ .replace("'", "'");
+ }
+
+}
diff --git a/yudao-module-wxcp/src/main/java/cn/iocoder/yudao/module/wxcp/controller/admin/notice/vo/WxCpNoticeArticleRespVO.java b/yudao-module-wxcp/src/main/java/cn/iocoder/yudao/module/wxcp/controller/admin/notice/vo/WxCpNoticeArticleRespVO.java
new file mode 100644
index 0000000..17ed5a4
--- /dev/null
+++ b/yudao-module-wxcp/src/main/java/cn/iocoder/yudao/module/wxcp/controller/admin/notice/vo/WxCpNoticeArticleRespVO.java
@@ -0,0 +1,32 @@
+package cn.iocoder.yudao.module.wxcp.controller.admin.notice.vo;
+
+import cn.iocoder.yudao.module.system.controller.admin.storage.vo.SystemStorageBlobRespVO;
+import io.swagger.v3.oas.annotations.media.Schema;
+import lombok.Data;
+
+@Schema(description = "绠$悊鍚庡彴 - 浼佷笟寰俊閫氱煡澶氬浘鏂囨潯鐩� Response VO")
+@Data
+public class WxCpNoticeArticleRespVO {
+
+ @Schema(description = "缂栧彿", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024")
+ private Long id;
+
+ @Schema(description = "鍥炬枃鏍囬", example = "鍏充簬2026骞存槬瀛h繍鍔ㄤ細鐨勯�氱煡")
+ private String title;
+
+ @Schema(description = "鍥炬枃鎽樿")
+ private String description;
+
+ @Schema(description = "鐐瑰嚮璺宠浆閾炬帴")
+ private String linkUrl;
+
+ @Schema(description = "灏侀潰鍥� Blob ID")
+ private Long coverBlobId;
+
+ @Schema(description = "灏侀潰鍥鹃檮浠讹紙鍚瑙堝湴鍧�锛岄�夊~锛�")
+ private SystemStorageBlobRespVO coverAttachment;
+
+ @Schema(description = "鎺掑簭鍙�")
+ private Integer sortNo;
+
+}
diff --git a/yudao-module-wxcp/src/main/java/cn/iocoder/yudao/module/wxcp/controller/admin/notice/vo/WxCpNoticeArticleSaveReqVO.java b/yudao-module-wxcp/src/main/java/cn/iocoder/yudao/module/wxcp/controller/admin/notice/vo/WxCpNoticeArticleSaveReqVO.java
new file mode 100644
index 0000000..6022f96
--- /dev/null
+++ b/yudao-module-wxcp/src/main/java/cn/iocoder/yudao/module/wxcp/controller/admin/notice/vo/WxCpNoticeArticleSaveReqVO.java
@@ -0,0 +1,35 @@
+package cn.iocoder.yudao.module.wxcp.controller.admin.notice.vo;
+
+import io.swagger.v3.oas.annotations.media.Schema;
+import jakarta.validation.constraints.NotEmpty;
+import jakarta.validation.constraints.Size;
+import lombok.Data;
+
+@Schema(description = "绠$悊鍚庡彴 - 浼佷笟寰俊閫氱煡澶氬浘鏂囨潯鐩� 鍒涘缓/淇敼 Request VO")
+@Data
+public class WxCpNoticeArticleSaveReqVO {
+
+ @Schema(description = "缂栧彿锛堜慨鏀规椂浼狅紝鏂板涓嶄紶锛�", example = "1024")
+ private Long id;
+
+ @Schema(description = "鍥炬枃鏍囬", requiredMode = Schema.RequiredMode.REQUIRED, example = "鍏充簬2026骞存槬瀛h繍鍔ㄤ細鐨勯�氱煡")
+ @NotEmpty(message = "鍥炬枃鏍囬涓嶈兘涓虹┖")
+ @Size(max = 128, message = "鍥炬枃鏍囬闀垮害涓嶈兘瓒呰繃 128 涓瓧绗�")
+ private String title;
+
+ @Schema(description = "鍥炬枃鎽樿", example = "璇峰悇鐝骇浜庢湰鍛ㄤ簲鍓嶅畬鎴愭姤鍚�")
+ @Size(max = 512, message = "鍥炬枃鎽樿闀垮害涓嶈兘瓒呰繃 512 涓瓧绗�")
+ private String description;
+
+ @Schema(description = "鐐瑰嚮璺宠浆閾炬帴", requiredMode = Schema.RequiredMode.REQUIRED, example = "https://example.com/news/1")
+ @NotEmpty(message = "鍥炬枃璺宠浆閾炬帴涓嶈兘涓虹┖")
+ @Size(max = 1024, message = "璺宠浆閾炬帴闀垮害涓嶈兘瓒呰繃 1024 涓瓧绗�")
+ private String linkUrl;
+
+ @Schema(description = "灏侀潰鍥� Blob ID锛堥�夊~锛�", example = "1024")
+ private Long coverBlobId;
+
+ @Schema(description = "鎺掑簭鍙凤紝瓒婂皬瓒婇潬鍓�", example = "1")
+ private Integer sortNo;
+
+}
diff --git a/yudao-module-wxcp/src/main/java/cn/iocoder/yudao/module/wxcp/controller/admin/notice/vo/WxCpNoticeRespVO.java b/yudao-module-wxcp/src/main/java/cn/iocoder/yudao/module/wxcp/controller/admin/notice/vo/WxCpNoticeRespVO.java
index 9bfb372..ada6764 100644
--- a/yudao-module-wxcp/src/main/java/cn/iocoder/yudao/module/wxcp/controller/admin/notice/vo/WxCpNoticeRespVO.java
+++ b/yudao-module-wxcp/src/main/java/cn/iocoder/yudao/module/wxcp/controller/admin/notice/vo/WxCpNoticeRespVO.java
@@ -1,9 +1,11 @@
package cn.iocoder.yudao.module.wxcp.controller.admin.notice.vo;
+import cn.iocoder.yudao.module.system.controller.admin.storage.vo.SystemStorageBlobRespVO;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import java.time.LocalDateTime;
+import java.util.List;
@Schema(description = "绠$悊鍚庡彴 - 浼佷笟寰俊閫氱煡 Response VO")
@Data
@@ -18,7 +20,8 @@
@Schema(description = "閫氱煡姝f枃")
private String content;
- @Schema(description = "閫氱煡妯℃澘绫诲瀷", example = "1")
+ @Schema(description = "閫氱煡妯℃澘绫诲瀷锛�1绾枃鏈� 2鍥炬枃鍗$墖 3鏂囦欢閫氱煡 4鍥炬枃娑堟伅 5鍥剧墖閫氱煡 6瑙嗛閫氱煡 7Markdown 8澶氬浘鏂囨秷鎭�",
+ example = "1")
private Integer noticeType;
@Schema(description = "閫氱煡妯℃澘绫诲瀷鍚嶇О", example = "绾枃鏈�氱煡")
@@ -36,12 +39,36 @@
@Schema(description = "鍥炬枃娑堟伅灏侀潰鍥惧湴鍧�")
private String coverUrl;
- @Schema(description = "鏂囦欢閫氱煡鐨勯檮浠� Blob ID")
+ @Schema(description = "鏂囦欢閫氱煡鐨勯檮浠� Blob ID锛堟棫鐗堝崟闄勪欢瀛楁锛�")
private Long fileBlobId;
- @Schema(description = "鏂囦欢閫氱煡鐨勯檮浠舵枃浠跺悕")
+ @Schema(description = "鏂囦欢閫氱煡鐨勯檮浠舵枃浠跺悕锛堟棫鐗堝崟闄勪欢瀛楁锛�")
private String fileName;
+ @Schema(description = "鍥剧墖閫氱煡鐨勫浘鐗� Blob ID 鍒楄〃")
+ private List<Long> imageBlobIds;
+
+ @Schema(description = "闄勪欢閫氱煡鐨勯檮浠� Blob ID 鍒楄〃")
+ private List<Long> fileBlobIds;
+
+ @Schema(description = "鍥剧墖閫氱煡鐨勫浘鐗囧垪琛紙鍚瑙堝湴鍧�锛�")
+ private List<SystemStorageBlobRespVO> imageAttachmentList;
+
+ @Schema(description = "闄勪欢閫氱煡鐨勯檮浠跺垪琛紙鍚瑙�/涓嬭浇鍦板潃锛�")
+ private List<SystemStorageBlobRespVO> fileAttachmentList;
+
+ @Schema(description = "瑙嗛閫氱煡鐨勮棰� Blob ID 鍒楄〃")
+ private List<Long> videoBlobIds;
+
+ @Schema(description = "瑙嗛閫氱煡鐨勮棰戝垪琛紙鍚瑙堝湴鍧�锛�")
+ private List<SystemStorageBlobRespVO> videoAttachmentList;
+
+ @Schema(description = "澶氬浘鏂囨秷鎭殑鍥炬枃鍒楄〃")
+ private List<WxCpNoticeArticleRespVO> articleList;
+
+ @Schema(description = "鎴愬憳棰勮椤靛湴鍧�锛堝浘鐗�/闄勪欢/瑙嗛閫氱煡鍙洿鎺ュ彂缁欐垚鍛樻煡鐪嬶級")
+ private String previewUrl;
+
@Schema(description = "鐘舵��", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
private Integer status;
diff --git a/yudao-module-wxcp/src/main/java/cn/iocoder/yudao/module/wxcp/controller/admin/notice/vo/WxCpNoticeSaveReqVO.java b/yudao-module-wxcp/src/main/java/cn/iocoder/yudao/module/wxcp/controller/admin/notice/vo/WxCpNoticeSaveReqVO.java
index 67c67c3..6028dcd 100644
--- a/yudao-module-wxcp/src/main/java/cn/iocoder/yudao/module/wxcp/controller/admin/notice/vo/WxCpNoticeSaveReqVO.java
+++ b/yudao-module-wxcp/src/main/java/cn/iocoder/yudao/module/wxcp/controller/admin/notice/vo/WxCpNoticeSaveReqVO.java
@@ -4,9 +4,12 @@
import cn.iocoder.yudao.module.wxcp.enums.activity.WxCpPushScopeEnum;
import cn.iocoder.yudao.module.wxcp.enums.notice.WxCpNoticeTypeEnum;
import io.swagger.v3.oas.annotations.media.Schema;
+import jakarta.validation.Valid;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.Size;
import lombok.Data;
+
+import java.util.List;
@Schema(description = "绠$悊鍚庡彴 - 浼佷笟寰俊閫氱煡 鍒涘缓/淇敼 Request VO")
@Data
@@ -24,7 +27,8 @@
@Size(max = 10000, message = "閫氱煡姝f枃闀垮害涓嶈兘瓒呰繃 10000 涓瓧绗�")
private String content;
- @Schema(description = "閫氱煡妯℃澘绫诲瀷锛�1-绾枃鏈� 2-鍥炬枃鍗$墖(濉姤/閾炬帴) 3-鏂囦欢閫氱煡 4-鍥炬枃娑堟伅", example = "1")
+ @Schema(description = "閫氱煡妯℃澘绫诲瀷锛�1绾枃鏈� 2鍥炬枃鍗$墖(濉姤/閾炬帴) 3鏂囦欢閫氱煡 4鍥炬枃娑堟伅 5鍥剧墖閫氱煡 6瑙嗛閫氱煡 7Markdown 8澶氬浘鏂囨秷鎭�",
+ example = "1")
@InEnum(WxCpNoticeTypeEnum.class)
private Integer noticeType;
@@ -44,13 +48,30 @@
@Size(max = 1024, message = "灏侀潰鍥惧湴鍧�闀垮害涓嶈兘瓒呰繃 1024 涓瓧绗�")
private String coverUrl;
- @Schema(description = "鏂囦欢閫氱煡鐨勯檮浠� Blob ID锛堝厛璋冪敤 /system/storage-blob/upload 涓婁紶锛�", example = "1024")
+ @Schema(description = "鏂囦欢閫氱煡鐨勯檮浠� Blob ID锛堟棫鐗堝崟闄勪欢瀛楁锛屽缓璁敼鐢� fileBlobIds锛�", example = "1024")
private Long fileBlobId;
- @Schema(description = "鏂囦欢閫氱煡鐨勯檮浠舵枃浠跺悕", example = "鍏充簬寮�灞昘X宸ヤ綔鐨勯�氱煡.pdf")
+ @Schema(description = "鏂囦欢閫氱煡鐨勯檮浠舵枃浠跺悕锛堟棫鐗堝崟闄勪欢瀛楁锛�", example = "鍏充簬寮�灞昘X宸ヤ綔鐨勯�氱煡.pdf")
@Size(max = 255, message = "鏂囦欢鍚嶉暱搴︿笉鑳借秴杩� 255 涓瓧绗�")
private String fileName;
+ @Schema(description = "鍥剧墖閫氱煡鐨勫浘鐗� Blob ID 鍒楄〃锛堟渶澶� 9 寮狅級锛沶ull = 涓嶆敼鍔紝[] = 娓呯┖", example = "[1024,1025]")
+ @Size(max = 9, message = "鍥剧墖鏈�澶氫笂浼� 9 寮�")
+ private List<Long> imageBlobIds;
+
+ @Schema(description = "闄勪欢閫氱煡鐨勯檮浠� Blob ID 鍒楄〃锛堟渶澶� 5 涓級锛沶ull = 涓嶆敼鍔紝[] = 娓呯┖", example = "[1024,1025]")
+ @Size(max = 5, message = "闄勪欢鏈�澶氫笂浼� 5 涓�")
+ private List<Long> fileBlobIds;
+
+ @Schema(description = "瑙嗛閫氱煡鐨勮棰� Blob ID 鍒楄〃锛堟渶澶� 1 涓級锛沶ull = 涓嶆敼鍔紝[] = 娓呯┖", example = "[1024]")
+ @Size(max = 1, message = "瑙嗛鏈�澶氫笂浼� 1 涓�")
+ private List<Long> videoBlobIds;
+
+ @Schema(description = "澶氬浘鏂囨秷鎭殑鍥炬枃鍒楄〃锛沶ull = 涓嶆敼鍔紝[] = 娓呯┖", example = "[]")
+ @Valid
+ @Size(max = 8, message = "澶氬浘鏂囨秷鎭渶澶� 8 绡�")
+ private List<WxCpNoticeArticleSaveReqVO> articleList;
+
@Schema(description = "鎺ㄩ�佽寖鍥达紙閫夊~锛屼笉浼犻粯璁ゅ叏鍛橈級锛涙帹閫佹椂浠嶅彲鍦ㄦ帹閫佸脊绐楅噷閲嶆柊閫夋嫨", example = "0")
@InEnum(WxCpPushScopeEnum.class)
private Integer pushScope;
diff --git a/yudao-module-wxcp/src/main/java/cn/iocoder/yudao/module/wxcp/controller/admin/vo/WxCpPushReqVO.java b/yudao-module-wxcp/src/main/java/cn/iocoder/yudao/module/wxcp/controller/admin/vo/WxCpPushReqVO.java
index af3cd22..c07f3d5 100644
--- a/yudao-module-wxcp/src/main/java/cn/iocoder/yudao/module/wxcp/controller/admin/vo/WxCpPushReqVO.java
+++ b/yudao-module-wxcp/src/main/java/cn/iocoder/yudao/module/wxcp/controller/admin/vo/WxCpPushReqVO.java
@@ -1,11 +1,15 @@
package cn.iocoder.yudao.module.wxcp.controller.admin.vo;
import cn.iocoder.yudao.framework.common.validation.InEnum;
+import cn.iocoder.yudao.module.wxcp.controller.admin.notice.vo.WxCpNoticeArticleSaveReqVO;
import cn.iocoder.yudao.module.wxcp.enums.activity.WxCpPushScopeEnum;
import io.swagger.v3.oas.annotations.media.Schema;
+import jakarta.validation.Valid;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Size;
import lombok.Data;
+
+import java.util.List;
@Schema(description = "绠$悊鍚庡彴 - 浼佷笟寰俊鎺ㄩ�� Request VO锛堟椿鍔ㄤ笌閫氱煡鍏辩敤锛�")
@Data
@@ -23,7 +27,8 @@
@Size(max = 1024, message = "鎺ㄩ�佺洰鏍囬暱搴︿笉鑳借秴杩� 1024 涓瓧绗�")
private String pushTarget;
- @Schema(description = "鎺ㄩ�佹椂閫夋嫨鐨勬ā鏉跨被鍨嬶細1绾枃鏈� 2鍥炬枃鍗$墖 3鏂囦欢閫氱煡 4鍥炬枃娑堟伅锛涗笉浼犳部鐢ㄩ�氱煡閰嶇疆", example = "2")
+ @Schema(description = "鎺ㄩ�佹椂閫夋嫨鐨勬ā鏉跨被鍨嬶細1绾枃鏈� 2鍥炬枃鍗$墖 3鏂囦欢閫氱煡 4鍥炬枃娑堟伅 5鍥剧墖閫氱煡 6瑙嗛閫氱煡 7Markdown 8澶氬浘鏂囨秷鎭紱涓嶄紶娌跨敤閫氱煡閰嶇疆",
+ example = "2")
@InEnum(cn.iocoder.yudao.module.wxcp.enums.notice.WxCpNoticeTypeEnum.class)
private Integer noticeType;
@@ -43,11 +48,28 @@
@Size(max = 1024, message = "灏侀潰鍥惧湴鍧�闀垮害涓嶈兘瓒呰繃 1024 涓瓧绗�")
private String coverUrl;
- @Schema(description = "鏂囦欢閫氱煡鐨勯檮浠� Blob ID")
+ @Schema(description = "鏂囦欢閫氱煡鐨勯檮浠� Blob ID锛堟棫鐗堝崟闄勪欢瀛楁锛屽缓璁敼鐢� fileBlobIds锛�")
private Long fileBlobId;
- @Schema(description = "鏂囦欢閫氱煡鐨勯檮浠舵枃浠跺悕")
+ @Schema(description = "鏂囦欢閫氱煡鐨勯檮浠舵枃浠跺悕锛堟棫鐗堝崟闄勪欢瀛楁锛�")
@Size(max = 255, message = "鏂囦欢鍚嶉暱搴︿笉鑳借秴杩� 255 涓瓧绗�")
private String fileName;
+ @Schema(description = "鍥剧墖閫氱煡鐨勫浘鐗� Blob ID 鍒楄〃锛涗笉浼犳部鐢ㄩ�氱煡涓婂凡淇濆瓨鐨勫浘鐗�", example = "[1024,1025]")
+ @Size(max = 9, message = "鍥剧墖鏈�澶氫笂浼� 9 寮�")
+ private List<Long> imageBlobIds;
+
+ @Schema(description = "闄勪欢閫氱煡鐨勯檮浠� Blob ID 鍒楄〃锛涗笉浼犳部鐢ㄩ�氱煡涓婂凡淇濆瓨鐨勯檮浠�", example = "[1024,1025]")
+ @Size(max = 5, message = "闄勪欢鏈�澶氫笂浼� 5 涓�")
+ private List<Long> fileBlobIds;
+
+ @Schema(description = "瑙嗛閫氱煡鐨勮棰� Blob ID 鍒楄〃锛涗笉浼犳部鐢ㄩ�氱煡涓婂凡淇濆瓨鐨勮棰�", example = "[1024]")
+ @Size(max = 1, message = "瑙嗛鏈�澶氫笂浼� 1 涓�")
+ private List<Long> videoBlobIds;
+
+ @Schema(description = "澶氬浘鏂囨秷鎭殑鍥炬枃鍒楄〃锛涗笉浼犳部鐢ㄩ�氱煡涓婂凡淇濆瓨鐨勫浘鏂�", example = "[]")
+ @Valid
+ @Size(max = 8, message = "澶氬浘鏂囨秷鎭渶澶� 8 绡�")
+ private List<WxCpNoticeArticleSaveReqVO> articleList;
+
}
diff --git a/yudao-module-wxcp/src/main/java/cn/iocoder/yudao/module/wxcp/dal/dataobject/notice/WxCpNoticeArticleDO.java b/yudao-module-wxcp/src/main/java/cn/iocoder/yudao/module/wxcp/dal/dataobject/notice/WxCpNoticeArticleDO.java
new file mode 100644
index 0000000..2726b5d
--- /dev/null
+++ b/yudao-module-wxcp/src/main/java/cn/iocoder/yudao/module/wxcp/dal/dataobject/notice/WxCpNoticeArticleDO.java
@@ -0,0 +1,54 @@
+package cn.iocoder.yudao.module.wxcp.dal.dataobject.notice;
+
+import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
+import com.baomidou.mybatisplus.annotation.KeySequence;
+import com.baomidou.mybatisplus.annotation.TableId;
+import com.baomidou.mybatisplus.annotation.TableName;
+import lombok.*;
+
+/**
+ * 浼佷笟寰俊閫氱煡 - 澶氬浘鏂囨秷鎭潯鐩� DO
+ *
+ * 浠呫�屽鍥炬枃娑堟伅銆嶆ā鏉夸娇鐢細涓�鏉¢�氱煡鍙互甯﹀绡囧浘鏂囷紙浼佷笟寰俊 news 娑堟伅鏈�澶� 8 绡囷級銆�
+ * 灏侀潰鍥句笉瀛樺湴鍧�锛屽彧瀛� blobId锛屾帹閫佹椂鍐嶅彇鍙闂湴鍧�銆�
+ *
+ * @author 瓒呯骇绠$悊鍛�
+ */
+@TableName("wxcp_notice_article")
+@KeySequence("wxcp_notice_article_seq")
+@Data
+@EqualsAndHashCode(callSuper = true)
+@ToString(callSuper = true)
+@Builder
+@NoArgsConstructor
+@AllArgsConstructor
+public class WxCpNoticeArticleDO extends BaseDO {
+
+ @TableId
+ private Long id;
+ /**
+ * 閫氱煡缂栧彿
+ */
+ private Long noticeId;
+ /**
+ * 鍥炬枃鏍囬
+ */
+ private String title;
+ /**
+ * 鍥炬枃鎽樿
+ */
+ private String description;
+ /**
+ * 鐐瑰嚮璺宠浆閾炬帴
+ */
+ private String linkUrl;
+ /**
+ * 灏侀潰鍥� Blob ID锛堥�夊~锛�
+ */
+ private Long coverBlobId;
+ /**
+ * 鎺掑簭鍙�
+ */
+ private Integer sortNo;
+
+}
diff --git a/yudao-module-wxcp/src/main/java/cn/iocoder/yudao/module/wxcp/dal/mysql/notice/WxCpNoticeArticleMapper.java b/yudao-module-wxcp/src/main/java/cn/iocoder/yudao/module/wxcp/dal/mysql/notice/WxCpNoticeArticleMapper.java
new file mode 100644
index 0000000..d5a9075
--- /dev/null
+++ b/yudao-module-wxcp/src/main/java/cn/iocoder/yudao/module/wxcp/dal/mysql/notice/WxCpNoticeArticleMapper.java
@@ -0,0 +1,30 @@
+package cn.iocoder.yudao.module.wxcp.dal.mysql.notice;
+
+import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
+import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
+import cn.iocoder.yudao.module.wxcp.dal.dataobject.notice.WxCpNoticeArticleDO;
+import org.apache.ibatis.annotations.Mapper;
+
+import java.util.List;
+
+/**
+ * 浼佷笟寰俊閫氱煡 - 澶氬浘鏂囨潯鐩� Mapper
+ *
+ * @author 瓒呯骇绠$悊鍛�
+ */
+@Mapper
+public interface WxCpNoticeArticleMapper extends BaseMapperX<WxCpNoticeArticleDO> {
+
+ default List<WxCpNoticeArticleDO> selectListByNoticeId(Long noticeId) {
+ return selectList(new LambdaQueryWrapperX<WxCpNoticeArticleDO>()
+ .eq(WxCpNoticeArticleDO::getNoticeId, noticeId)
+ .orderByAsc(WxCpNoticeArticleDO::getSortNo)
+ .orderByAsc(WxCpNoticeArticleDO::getId));
+ }
+
+ default int deleteByNoticeId(Long noticeId) {
+ return delete(new LambdaQueryWrapperX<WxCpNoticeArticleDO>()
+ .eq(WxCpNoticeArticleDO::getNoticeId, noticeId));
+ }
+
+}
diff --git a/yudao-module-wxcp/src/main/java/cn/iocoder/yudao/module/wxcp/enums/ErrorCodeConstants.java b/yudao-module-wxcp/src/main/java/cn/iocoder/yudao/module/wxcp/enums/ErrorCodeConstants.java
index febce37..53b9407 100644
--- a/yudao-module-wxcp/src/main/java/cn/iocoder/yudao/module/wxcp/enums/ErrorCodeConstants.java
+++ b/yudao-module-wxcp/src/main/java/cn/iocoder/yudao/module/wxcp/enums/ErrorCodeConstants.java
@@ -57,6 +57,21 @@
ErrorCode NOTICE_FILE_REQUIRED = new ErrorCode(1_050_003_006, "鏂囦欢閫氱煡蹇呴』涓婁紶鏂囦欢锛岃涓婁紶鍚庡啀鎺ㄩ��");
ErrorCode NOTICE_FILE_NOT_EXISTS = new ErrorCode(1_050_003_007, "閫氱煡鏂囦欢涓嶅瓨鍦ㄦ垨宸茶鍒犻櫎锛岃閲嶆柊涓婁紶");
ErrorCode NOTICE_FILE_TOO_LARGE = new ErrorCode(1_050_003_008, "閫氱煡鏂囦欢瓒呰繃浼佷笟寰俊 20MB 闄愬埗锛岃鍘嬬缉鎴栨敼鐢ㄥ浘鏂囧崱鐗囨帹閫佷笅杞介摼鎺�");
+ ErrorCode NOTICE_IMAGE_REQUIRED = new ErrorCode(1_050_003_009, "鍥剧墖閫氱煡蹇呴』鑷冲皯涓婁紶 1 寮犲浘鐗囷紝璇蜂笂浼犲悗鍐嶆帹閫�");
+ ErrorCode NOTICE_IMAGE_ONLY = new ErrorCode(1_050_003_010, "鍥剧墖閫氱煡鍙兘涓婁紶鍥剧墖鏂囦欢锛岃閲嶆柊閫夋嫨");
+ ErrorCode NOTICE_IMAGE_TOO_LARGE = new ErrorCode(1_050_003_011, "閫氱煡鍥剧墖瓒呰繃浼佷笟寰俊 10MB 闄愬埗锛岃鍘嬬缉鍚庨噸鏂颁笂浼�");
+ ErrorCode NOTICE_IMAGE_COUNT_EXCEEDED = new ErrorCode(1_050_003_012, "鍥剧墖閫氱煡鏈�澶氫笂浼� 9 寮犲浘鐗�");
+ ErrorCode NOTICE_FILE_COUNT_EXCEEDED = new ErrorCode(1_050_003_013, "闄勪欢閫氱煡鏈�澶氫笂浼� 5 涓檮浠�");
+ ErrorCode NOTICE_VIDEO_REQUIRED = new ErrorCode(1_050_003_014, "瑙嗛閫氱煡蹇呴』涓婁紶 1 涓棰戯紝璇蜂笂浼犲悗鍐嶆帹閫�");
+ ErrorCode NOTICE_VIDEO_ONLY = new ErrorCode(1_050_003_015, "瑙嗛閫氱煡鍙兘涓婁紶瑙嗛鏂囦欢锛堝 mp4锛夛紝璇烽噸鏂伴�夋嫨");
+ ErrorCode NOTICE_VIDEO_TOO_LARGE = new ErrorCode(1_050_003_016, "閫氱煡瑙嗛瓒呰繃浼佷笟寰俊 10MB 闄愬埗锛岃鍘嬬缉鍚庨噸鏂颁笂浼�");
+ ErrorCode NOTICE_MARKDOWN_CONTENT_REQUIRED = new ErrorCode(1_050_003_017, "Markdown 閫氱煡鐨勬鏂囦笉鑳戒负绌猴紝璇峰~鍐欓�氱煡鍐呭");
+ ErrorCode NOTICE_MARKDOWN_TOO_LONG = new ErrorCode(1_050_003_018,
+ "Markdown 閫氱煡姝f枃瓒呰繃浼佷笟寰俊 2048 瀛楄妭闄愬埗锛堝綋鍓� {} 瀛楄妭锛夛紝璇风簿绠�鍚庡啀鎺ㄩ��");
+ ErrorCode NOTICE_ARTICLE_REQUIRED = new ErrorCode(1_050_003_019, "澶氬浘鏂囨秷鎭嚦灏戦渶瑕� 1 绡囧浘鏂囷紝璇锋坊鍔犲悗鍐嶆帹閫�");
+ ErrorCode NOTICE_ARTICLE_TITLE_REQUIRED = new ErrorCode(1_050_003_020, "绗� {} 绡囧浘鏂囩殑鏍囬涓嶈兘涓虹┖锛岃濉啓鏍囬");
+ ErrorCode NOTICE_ARTICLE_URL_REQUIRED = new ErrorCode(1_050_003_021, "绗� {} 绡囧浘鏂囩殑璺宠浆閾炬帴涓嶈兘涓虹┖锛岃濉啓閾炬帴鍦板潃");
+ ErrorCode NOTICE_ARTICLE_COUNT_EXCEEDED = new ErrorCode(1_050_003_022, "澶氬浘鏂囨秷鎭渶澶氭坊鍔� 8 绡囧浘鏂囷紝璇峰垹闄ゅ浣欐潯鐩�");
// ========== 浼佷笟寰俊閫氳褰� 1-050-004-000 ==========
ErrorCode WXCP_API_ERROR = new ErrorCode(1_050_004_000, "璋冪敤浼佷笟寰俊鎺ュ彛澶辫触锛歟rrcode={}锛宔rrmsg={}");
diff --git a/yudao-module-wxcp/src/main/java/cn/iocoder/yudao/module/wxcp/enums/notice/WxCpNoticeTypeEnum.java b/yudao-module-wxcp/src/main/java/cn/iocoder/yudao/module/wxcp/enums/notice/WxCpNoticeTypeEnum.java
index 38b8da3..aa10585 100644
--- a/yudao-module-wxcp/src/main/java/cn/iocoder/yudao/module/wxcp/enums/notice/WxCpNoticeTypeEnum.java
+++ b/yudao-module-wxcp/src/main/java/cn/iocoder/yudao/module/wxcp/enums/notice/WxCpNoticeTypeEnum.java
@@ -18,6 +18,10 @@
CARD(2, "鍥炬枃鍗$墖锛堝~鎶�/閾炬帴锛�"),
FILE(3, "鏂囦欢閫氱煡"),
NEWS(4, "鍥炬枃娑堟伅"),
+ IMAGE(5, "鍥剧墖閫氱煡"),
+ VIDEO(6, "瑙嗛閫氱煡"),
+ MARKDOWN(7, "Markdown 閫氱煡"),
+ MULTI_NEWS(8, "澶氬浘鏂囨秷鎭�"),
;
public static final Integer[] ARRAYS = Arrays.stream(values())
diff --git a/yudao-module-wxcp/src/main/java/cn/iocoder/yudao/module/wxcp/service/notice/WxCpNoticeService.java b/yudao-module-wxcp/src/main/java/cn/iocoder/yudao/module/wxcp/service/notice/WxCpNoticeService.java
index 4e8e0a4..d0d5251 100644
--- a/yudao-module-wxcp/src/main/java/cn/iocoder/yudao/module/wxcp/service/notice/WxCpNoticeService.java
+++ b/yudao-module-wxcp/src/main/java/cn/iocoder/yudao/module/wxcp/service/notice/WxCpNoticeService.java
@@ -1,12 +1,16 @@
package cn.iocoder.yudao.module.wxcp.service.notice;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
+import cn.iocoder.yudao.module.system.controller.admin.storage.vo.SystemStorageBlobRespVO;
import cn.iocoder.yudao.module.wxcp.controller.admin.notice.vo.WxCpNoticePageReqVO;
import cn.iocoder.yudao.module.wxcp.controller.admin.notice.vo.WxCpNoticeSaveReqVO;
import cn.iocoder.yudao.module.wxcp.controller.admin.vo.WxCpPushReqVO;
import cn.iocoder.yudao.module.wxcp.controller.admin.vo.WxCpPushResultVO;
+import cn.iocoder.yudao.module.wxcp.dal.dataobject.notice.WxCpNoticeArticleDO;
import cn.iocoder.yudao.module.wxcp.dal.dataobject.notice.WxCpNoticeDO;
import jakarta.validation.Valid;
+
+import java.util.List;
/**
* 浼佷笟寰俊閫氱煡 Service 鎺ュ彛
@@ -54,6 +58,46 @@
PageResult<WxCpNoticeDO> getNoticePage(@Valid WxCpNoticePageReqVO pageReqVO);
/**
+ * 鑾峰緱鍥剧墖閫氱煡鐨勫浘鐗囧垪琛�
+ *
+ * @param noticeId 閫氱煡缂栧彿
+ * @return 鍥剧墖鍒楄〃锛堝惈棰勮鍦板潃锛�
+ */
+ List<SystemStorageBlobRespVO> getNoticeImageAttachments(Long noticeId);
+
+ /**
+ * 鑾峰緱闄勪欢閫氱煡鐨勯檮浠跺垪琛�
+ *
+ * @param noticeId 閫氱煡缂栧彿
+ * @return 闄勪欢鍒楄〃锛堝惈棰勮/涓嬭浇鍦板潃锛�
+ */
+ List<SystemStorageBlobRespVO> getNoticeFileAttachments(Long noticeId);
+
+ /**
+ * 鑾峰緱瑙嗛閫氱煡鐨勮棰戝垪琛�
+ *
+ * @param noticeId 閫氱煡缂栧彿
+ * @return 瑙嗛鍒楄〃锛堝惈棰勮鍦板潃锛�
+ */
+ List<SystemStorageBlobRespVO> getNoticeVideoAttachments(Long noticeId);
+
+ /**
+ * 鑾峰緱澶氬浘鏂囨秷鎭殑鍥炬枃鍒楄〃
+ *
+ * @param noticeId 閫氱煡缂栧彿
+ * @return 鍥炬枃鍒楄〃
+ */
+ List<WxCpNoticeArticleDO> getNoticeArticles(Long noticeId);
+
+ /**
+ * 鑾峰緱澶氬浘鏂囨潯鐩殑灏侀潰闄勪欢
+ *
+ * @param articleId 鍥炬枃鏉$洰缂栧彿
+ * @return 灏侀潰闄勪欢鍒楄〃锛堟渶澶� 1 寮狅級
+ */
+ List<SystemStorageBlobRespVO> getNoticeArticleCoverAttachments(Long articleId);
+
+ /**
* 鍙戝竷閫氱煡锛堣崏绋� -> 宸插彂甯冿級
*
* @param id 閫氱煡缂栧彿
@@ -75,4 +119,12 @@
*/
WxCpPushResultVO pushNotice(@Valid WxCpPushReqVO pushReqVO);
+ /**
+ * 鎷艰閫氱煡棰勮椤靛湴鍧�锛屾垚鍛樺湪浼佷笟寰俊鍐呮墦寮�鍚庡彲鏌ョ湅鍥剧墖涓庨檮浠�
+ *
+ * @param id 閫氱煡缂栧彿
+ * @return 棰勮椤靛湴鍧�锛涙湭閰嶇疆澶栫綉鍦板潃鍓嶇紑鏃惰繑鍥� null
+ */
+ String buildPreviewUrl(Long id);
+
}
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 25fcabf..bf61273 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
@@ -1,28 +1,44 @@
package cn.iocoder.yudao.module.wxcp.service.notice;
+import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.StrUtil;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
+import cn.iocoder.yudao.module.system.controller.admin.storage.vo.SystemStorageAttachmentListReqVO;
+import cn.iocoder.yudao.module.system.controller.admin.storage.vo.SystemStorageAttachmentSaveReqVO;
+import cn.iocoder.yudao.module.system.controller.admin.storage.vo.SystemStorageBlobRespVO;
+import cn.iocoder.yudao.module.system.dal.dataobject.storage.SystemStorageBlobDO;
+import cn.iocoder.yudao.module.system.service.storage.SystemStorageAttachmentService;
+import cn.iocoder.yudao.module.system.service.storage.SystemStorageBlobService;
+import cn.iocoder.yudao.module.wxcp.controller.admin.notice.vo.WxCpNoticeArticleSaveReqVO;
import cn.iocoder.yudao.module.wxcp.controller.admin.notice.vo.WxCpNoticePageReqVO;
import cn.iocoder.yudao.module.wxcp.controller.admin.notice.vo.WxCpNoticeSaveReqVO;
import cn.iocoder.yudao.module.wxcp.controller.admin.vo.WxCpPushReqVO;
import cn.iocoder.yudao.module.wxcp.controller.admin.vo.WxCpPushResultVO;
+import cn.iocoder.yudao.module.wxcp.dal.dataobject.notice.WxCpNoticeArticleDO;
import cn.iocoder.yudao.module.wxcp.dal.dataobject.notice.WxCpNoticeDO;
+import cn.iocoder.yudao.module.wxcp.dal.mysql.notice.WxCpNoticeArticleMapper;
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.framework.config.WxCpProperties;
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 com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
+import me.chanjar.weixin.cp.bean.article.NewArticle;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;
import java.io.File;
+import java.nio.charset.StandardCharsets;
import java.time.LocalDateTime;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
import java.util.Objects;
+import java.util.stream.Collectors;
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.module.wxcp.enums.ErrorCodeConstants.*;
@@ -43,15 +59,78 @@
*/
private static final int MAX_PUSH_CONTENT_LENGTH = 600;
+ /**
+ * 鍥剧墖閫氱煡鐨勫浘鐗囧叧鑱旇褰曠被鍨嬶紝瀵瑰簲 system_storage_attachment.record_type
+ */
+ public static final String NOTICE_IMAGE_RECORD_TYPE = "wxcp_notice_image";
+
+ /**
+ * 闄勪欢閫氱煡鐨勯檮浠跺叧鑱旇褰曠被鍨嬶紝瀵瑰簲 system_storage_attachment.record_type
+ */
+ public static final String NOTICE_FILE_RECORD_TYPE = "wxcp_notice_file";
+
+ /**
+ * 瑙嗛閫氱煡鐨勮棰戝叧鑱旇褰曠被鍨嬶紝瀵瑰簲 system_storage_attachment.record_type
+ */
+ public static final String NOTICE_VIDEO_RECORD_TYPE = "wxcp_notice_video";
+
+ /**
+ * 澶氬浘鏂囧皝闈㈠浘鐨勫叧鑱旇褰曠被鍨嬶紝record_id 涓哄浘鏂囨潯鐩紪鍙�
+ */
+ public static final String NOTICE_ARTICLE_COVER_RECORD_TYPE = "wxcp_notice_article_cover";
+
+ /**
+ * 闄勪欢鐢ㄩ�旓紝涓庡叾瀹冩ā鍧椾繚鎸佷竴鑷�
+ */
+ private static final String ATTACHMENT_APPLICATION = "file";
+
+ /**
+ * 浼佷笟寰俊鏂囦欢娑堟伅涓婇檺 20MB
+ */
+ private static final long MAX_FILE_SIZE = 20L * 1024L * 1024L;
+
+ /**
+ * 浼佷笟寰俊鍥剧墖娑堟伅涓婇檺 10MB
+ */
+ private static final long MAX_IMAGE_SIZE = 10L * 1024L * 1024L;
+
+ /**
+ * 浼佷笟寰俊瑙嗛娑堟伅涓婇檺 10MB
+ */
+ private static final long MAX_VIDEO_SIZE = 10L * 1024L * 1024L;
+
+ /**
+ * 浼佷笟寰俊 Markdown 娑堟伅涓婇檺 2048 瀛楄妭
+ */
+ private static final int MAX_MARKDOWN_BYTES = 2048;
+
+ /**
+ * 涓�娆℃帹閫佺殑鍥剧墖鏁伴噺涓婇檺
+ */
+ private static final int MAX_IMAGE_COUNT = 9;
+
+ /**
+ * 涓�娆℃帹閫佺殑闄勪欢鏁伴噺涓婇檺
+ */
+ private static final int MAX_FILE_COUNT = 5;
+
+ /**
+ * 澶氬浘鏂囨秷鎭渶澶氱瘒鏁�
+ */
+ private static final int MAX_ARTICLE_COUNT = 8;
+
@Resource
private WxCpNoticeMapper wxcpNoticeMapper;
+ @Resource
+ private WxCpNoticeArticleMapper wxcpNoticeArticleMapper;
@Resource
private WxCpMessagePushService messagePushService;
@Resource
private SystemStorageBlobService storageBlobService;
-
- /** 浼佷笟寰俊鏂囦欢娑堟伅涓婇檺 20MB */
- private static final long MAX_FILE_SIZE = 20L * 1024L * 1024L;
+ @Resource
+ private SystemStorageAttachmentService storageAttachmentService;
+ @Resource
+ private WxCpProperties wxCpProperties;
@Override
public Long createNotice(WxCpNoticeSaveReqVO createReqVO) {
@@ -66,6 +145,14 @@
notice.setPushScope(WxCpPushScopeEnum.ALL.getScope());
}
wxcpNoticeMapper.insert(notice);
+
+ // 绱犳潗缁熶竴璧伴檮浠朵腑闂磋〃锛涙柊寤烘椂 null 涓庣┖闆嗗悎閮借〃绀烘病鏈夌礌鏉�
+ bindAttachments(NOTICE_IMAGE_RECORD_TYPE, notice.getId(), createReqVO.getImageBlobIds());
+ List<Long> fileBlobIds = resolveFileBlobIds(createReqVO);
+ bindAttachments(NOTICE_FILE_RECORD_TYPE, notice.getId(), fileBlobIds);
+ bindAttachments(NOTICE_VIDEO_RECORD_TYPE, notice.getId(), createReqVO.getVideoBlobIds());
+ syncFileSnapshot(notice.getId(), fileBlobIds, createReqVO.getFileName());
+ saveArticles(notice.getId(), createReqVO.getArticleList());
return notice.getId();
}
@@ -81,12 +168,37 @@
updateObj.setPushStatus(null);
updateObj.setPushTime(null);
wxcpNoticeMapper.updateById(updateObj);
+
+ // 绱犳潗鍒楄〃 null = 涓嶆敼鍔紝[] = 娓呯┖锛涜繖鏍峰彧鏀规爣棰樻椂涓嶄細璇垹宸蹭笂浼犵殑绱犳潗
+ if (updateReqVO.getImageBlobIds() != null) {
+ bindAttachments(NOTICE_IMAGE_RECORD_TYPE, notice.getId(), updateReqVO.getImageBlobIds());
+ }
+ if (updateReqVO.getVideoBlobIds() != null) {
+ bindAttachments(NOTICE_VIDEO_RECORD_TYPE, notice.getId(), updateReqVO.getVideoBlobIds());
+ }
+ List<Long> fileBlobIds = resolveFileBlobIds(updateReqVO);
+ if (fileBlobIds != null) {
+ bindAttachments(NOTICE_FILE_RECORD_TYPE, notice.getId(), fileBlobIds);
+ syncFileSnapshot(notice.getId(), fileBlobIds, updateReqVO.getFileName());
+ }
+ if (updateReqVO.getArticleList() != null) {
+ saveArticles(notice.getId(), updateReqVO.getArticleList());
+ }
}
@Override
public void deleteNotice(Long id) {
validateNoticeExists(id);
wxcpNoticeMapper.deleteById(id);
+ storageAttachmentService.deleteAttachmentsByRecordTypeAndRecordId(NOTICE_IMAGE_RECORD_TYPE, id);
+ storageAttachmentService.deleteAttachmentsByRecordTypeAndRecordId(NOTICE_FILE_RECORD_TYPE, id);
+ storageAttachmentService.deleteAttachmentsByRecordTypeAndRecordId(NOTICE_VIDEO_RECORD_TYPE, id);
+ // 鍥炬枃鏉$洰鍙婂叾灏侀潰闄勪欢涓�璧锋竻鐞�
+ for (WxCpNoticeArticleDO article : wxcpNoticeArticleMapper.selectListByNoticeId(id)) {
+ storageAttachmentService.deleteAttachmentsByRecordTypeAndRecordId(
+ NOTICE_ARTICLE_COVER_RECORD_TYPE, article.getId());
+ }
+ wxcpNoticeArticleMapper.deleteByNoticeId(id);
}
@Override
@@ -97,6 +209,31 @@
@Override
public PageResult<WxCpNoticeDO> getNoticePage(WxCpNoticePageReqVO pageReqVO) {
return wxcpNoticeMapper.selectPage(pageReqVO);
+ }
+
+ @Override
+ public List<SystemStorageBlobRespVO> getNoticeImageAttachments(Long noticeId) {
+ return listAttachments(NOTICE_IMAGE_RECORD_TYPE, noticeId);
+ }
+
+ @Override
+ public List<SystemStorageBlobRespVO> getNoticeFileAttachments(Long noticeId) {
+ return listAttachments(NOTICE_FILE_RECORD_TYPE, noticeId);
+ }
+
+ @Override
+ public List<SystemStorageBlobRespVO> getNoticeVideoAttachments(Long noticeId) {
+ return listAttachments(NOTICE_VIDEO_RECORD_TYPE, noticeId);
+ }
+
+ @Override
+ public List<WxCpNoticeArticleDO> getNoticeArticles(Long noticeId) {
+ return wxcpNoticeArticleMapper.selectListByNoticeId(noticeId);
+ }
+
+ @Override
+ public List<SystemStorageBlobRespVO> getNoticeArticleCoverAttachments(Long articleId) {
+ return listAttachments(NOTICE_ARTICLE_COVER_RECORD_TYPE, articleId);
}
@Override
@@ -141,8 +278,20 @@
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());
+
+ // 鏈鎺ㄩ�佺殑绱犳潗锛氳姹傞噷浼犱簡灏辫鐩栵紝娌′紶鍒欐部鐢ㄩ�氱煡涓婂凡淇濆瓨鐨�
+ List<Long> imageBlobIds = pushReqVO.getImageBlobIds() != null
+ ? pushReqVO.getImageBlobIds() : toBlobIds(getNoticeImageAttachments(notice.getId()));
+ List<Long> fileBlobIds = pushReqVO.getFileBlobIds() != null
+ ? pushReqVO.getFileBlobIds() : toBlobIds(getNoticeFileAttachments(notice.getId()));
+ List<Long> videoBlobIds = pushReqVO.getVideoBlobIds() != null
+ ? pushReqVO.getVideoBlobIds() : toBlobIds(getNoticeVideoAttachments(notice.getId()));
+ List<WxCpNoticeArticleSaveReqVO> articles = pushReqVO.getArticleList() != null
+ ? pushReqVO.getArticleList() : toArticleReqList(getNoticeArticles(notice.getId()));
+ if (CollUtil.isEmpty(fileBlobIds) && notice.getFileBlobId() != null && notice.getFileBlobId() > 0) {
+ // 鍏煎鏃ф暟鎹細鍘嗗彶涓婃枃浠堕�氱煡鍙瓨浜嗕竴涓� fileBlobId
+ fileBlobIds = List.of(notice.getFileBlobId());
+ }
// 鎸夋湰娆¢�夋嫨鐨勬ā鏉跨被鍨嬫牎楠屽繀濉」
if (Objects.equals(noticeType, WxCpNoticeTypeEnum.TEXT.getType())
@@ -154,8 +303,29 @@
&& StrUtil.isBlank(linkUrl)) {
throw exception(NOTICE_LINK_URL_REQUIRED);
}
- if (Objects.equals(noticeType, WxCpNoticeTypeEnum.FILE.getType()) && fileBlobId == null) {
+ if (Objects.equals(noticeType, WxCpNoticeTypeEnum.FILE.getType())
+ && CollUtil.isEmpty(fileBlobIds)) {
throw exception(NOTICE_FILE_REQUIRED);
+ }
+ if (Objects.equals(noticeType, WxCpNoticeTypeEnum.IMAGE.getType())
+ && CollUtil.isEmpty(imageBlobIds)) {
+ throw exception(NOTICE_IMAGE_REQUIRED);
+ }
+ if (Objects.equals(noticeType, WxCpNoticeTypeEnum.VIDEO.getType())
+ && CollUtil.isEmpty(videoBlobIds)) {
+ throw exception(NOTICE_VIDEO_REQUIRED);
+ }
+ if (Objects.equals(noticeType, WxCpNoticeTypeEnum.MARKDOWN.getType())) {
+ validateMarkdownContent(buildMarkdownContent(notice));
+ }
+ if (Objects.equals(noticeType, WxCpNoticeTypeEnum.MULTI_NEWS.getType())) {
+ validateArticles(articles);
+ }
+ if (imageBlobIds.size() > MAX_IMAGE_COUNT) {
+ throw exception(NOTICE_IMAGE_COUNT_EXCEEDED);
+ }
+ if (fileBlobIds.size() > MAX_FILE_COUNT) {
+ throw exception(NOTICE_FILE_COUNT_EXCEEDED);
}
WxCpPushResultVO result;
@@ -164,11 +334,19 @@
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);
+ result = pushFileNotice(fileBlobIds, 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 if (Objects.equals(noticeType, WxCpNoticeTypeEnum.IMAGE.getType())) {
+ result = pushImageNotice(imageBlobIds, notice, scope, target);
+ } else if (Objects.equals(noticeType, WxCpNoticeTypeEnum.VIDEO.getType())) {
+ result = pushVideoNotice(videoBlobIds.get(0), notice, scope, target);
+ } else if (Objects.equals(noticeType, WxCpNoticeTypeEnum.MARKDOWN.getType())) {
+ result = messagePushService.pushMarkdown(buildMarkdownContent(notice), scope, target);
+ } else if (Objects.equals(noticeType, WxCpNoticeTypeEnum.MULTI_NEWS.getType())) {
+ result = pushMultiNewsNotice(articles, scope, target);
} else {
result = messagePushService.pushText(buildPushContent(notice), scope, target);
}
@@ -186,47 +364,150 @@
}
/**
- * 鏂囦欢閫氱煡锛氫粠绯荤粺闄勪欢涓績鍙栨枃浠讹紝浜ょ粰鎺ㄩ�佹湇鍔′笂浼犱紒涓氬井淇″苟鍙戦��
+ * 鍥剧墖閫氱煡锛氬厛鍙戜竴鏉℃枃瀛楄鏄庯紙鏈夋鏂囨椂锛夛紝鍐嶉�愬紶鍙戦�佸浘鐗�
*/
- private WxCpPushResultVO pushFileNotice(Long fileBlobId, String fileName, WxCpNoticeDO notice,
- Integer scope, String target) {
- if (fileBlobId == null) {
- throw exception(NOTICE_FILE_REQUIRED);
+ private WxCpPushResultVO pushImageNotice(List<Long> imageBlobIds, WxCpNoticeDO notice,
+ Integer scope, String target) {
+ List<WxCpPushResultVO> results = new ArrayList<>();
+ if (StrUtil.isNotBlank(notice.getContent())) {
+ // 鏂囧瓧澶辫触涓嶅奖鍝嶅悗缁浘鐗囧彂閫侊紝鏈�缁堢敱 aggregatePushResults 姹囨��
+ results.add(messagePushService.pushText(buildPushContent(notice), scope, target));
}
- SystemStorageBlobDO blob = storageBlobService.getStorageBlob(fileBlobId);
+ for (Long blobId : imageBlobIds) {
+ SystemStorageBlobDO blob = storageBlobService.getStorageBlob(blobId);
+ if (blob == null) {
+ throw exception(NOTICE_FILE_NOT_EXISTS);
+ }
+ if (StrUtil.isNotBlank(blob.getContentType())
+ && !StrUtil.startWithIgnoreCase(blob.getContentType(), "image/")) {
+ throw exception(NOTICE_IMAGE_ONLY);
+ }
+ if (blob.getByteSize() != null && blob.getByteSize() > MAX_IMAGE_SIZE) {
+ throw exception(NOTICE_IMAGE_TOO_LARGE);
+ }
+ File file = storageBlobService.getPublicFile(blob.getUidFilename(), blob.getResourceKey());
+ if (file == null || !file.exists()) {
+ throw exception(NOTICE_FILE_NOT_EXISTS);
+ }
+ results.add(messagePushService.pushImage(file, scope, target));
+ }
+ // 鍥剧墖娑堟伅鏈韩涓嶅彲鐐瑰嚮锛屽啀琛ヤ竴寮犲崱鐗囨寚鍚戦瑙堥〉锛屾垚鍛樺彲鍦ㄩ〉鍐呴�愬紶鏀惧ぇ鏌ョ湅
+ appendPreviewCard(results, notice, "鏌ョ湅鍏ㄩ儴鍥剧墖", scope, target);
+ return aggregatePushResults(results, "鍥剧墖");
+ }
+
+ /**
+ * 闄勪欢閫氱煡锛氬厛鍙戜竴鏉℃枃瀛楄鏄庯紙鏈夋鏂囨椂锛夛紝鍐嶉�愪釜鍙戦�佹枃浠�
+ */
+ private WxCpPushResultVO pushFileNotice(List<Long> fileBlobIds, WxCpNoticeDO notice,
+ Integer scope, String target) {
+ List<WxCpPushResultVO> results = new ArrayList<>();
+ if (StrUtil.isNotBlank(notice.getContent())) {
+ results.add(messagePushService.pushText(buildPushContent(notice), scope, target));
+ }
+ for (Long blobId : fileBlobIds) {
+ SystemStorageBlobDO blob = storageBlobService.getStorageBlob(blobId);
+ 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(blob.getOriginalFilename(), blob.getUidFilename());
+ results.add(messagePushService.pushFile(file, actualFileName, null, scope, target));
+ }
+ // 鏂囦欢娑堟伅鍙兘涓嬭浇鍗曚釜闄勪欢锛屽啀琛ヤ竴寮犲崱鐗囨寚鍚戦瑙堥〉锛屾垚鍛樺彲鍦ㄩ〉鍐呯湅鍒板叏閮ㄩ檮浠�
+ appendPreviewCard(results, notice, "鏌ョ湅鍏ㄩ儴闄勪欢", scope, target);
+ return aggregatePushResults(results, "闄勪欢");
+ }
+
+ /**
+ * 瑙嗛閫氱煡锛氬彂閫佽棰戞秷鎭紝骞惰ˉ涓�寮犲崱鐗囨寚鍚戦瑙堥〉
+ */
+ private WxCpPushResultVO pushVideoNotice(Long videoBlobId, WxCpNoticeDO notice,
+ Integer scope, String target) {
+ SystemStorageBlobDO blob = storageBlobService.getStorageBlob(videoBlobId);
if (blob == null) {
throw exception(NOTICE_FILE_NOT_EXISTS);
}
- if (blob.getByteSize() != null && blob.getByteSize() > MAX_FILE_SIZE) {
- throw exception(NOTICE_FILE_TOO_LARGE);
+ if (StrUtil.isNotBlank(blob.getContentType())
+ && !StrUtil.startWithIgnoreCase(blob.getContentType(), "video/")) {
+ throw exception(NOTICE_VIDEO_ONLY);
+ }
+ if (blob.getByteSize() != null && blob.getByteSize() > MAX_VIDEO_SIZE) {
+ throw exception(NOTICE_VIDEO_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);
+ List<WxCpPushResultVO> results = new ArrayList<>();
+ String description = StrUtil.blankToDefault(notice.getSummary(), notice.getContent());
+ if (description.length() > 300) {
+ description = description.substring(0, 300) + "鈥︹��";
+ }
+ results.add(messagePushService.pushVideo(file, notice.getTitle(), description, scope, target));
+ appendPreviewCard(results, notice, "鏌ョ湅閫氱煡璇︽儏", scope, target);
+ return aggregatePushResults(results, "瑙嗛");
}
/**
- * 鎸夋ā鏉跨被鍨嬫牎楠屽繀濉」
+ * 澶氬浘鏂囨秷鎭細涓�娆℃秷鎭彂閫佸绡囧浘鏂�
*/
- 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);
+ private WxCpPushResultVO pushMultiNewsNotice(List<WxCpNoticeArticleSaveReqVO> articles,
+ Integer scope, String target) {
+ List<NewArticle> newsList = new ArrayList<>(articles.size());
+ for (WxCpNoticeArticleSaveReqVO article : articles) {
+ newsList.add(NewArticle.builder()
+ .title(StrUtil.trim(article.getTitle()))
+ .description(StrUtil.blankToDefault(article.getDescription(), ""))
+ .url(StrUtil.trim(article.getLinkUrl()))
+ .picUrl(resolveArticleCoverUrl(article))
+ .build());
}
- if ((Objects.equals(type, WxCpNoticeTypeEnum.CARD.getType())
- || Objects.equals(type, WxCpNoticeTypeEnum.NEWS.getType()))
- && StrUtil.isBlank(reqVO.getLinkUrl())) {
- throw exception(NOTICE_LINK_URL_REQUIRED);
+ return messagePushService.pushMultiNews(newsList, scope, target);
+ }
+
+ /**
+ * 澶氬浘鏂囧皝闈㈠湴鍧�锛氬彇鍥炬枃鏉$洰缁戝畾鐨勫皝闈㈤檮浠讹紙閫夊~锛�
+ */
+ private String resolveArticleCoverUrl(WxCpNoticeArticleSaveReqVO article) {
+ Long articleId = article.getId();
+ if (articleId == null) {
+ // 鎺ㄩ�佹椂涓存椂娣诲姞銆佹湭钀藉簱鐨勫浘鏂囨病鏈夐檮浠跺叧绯伙紝鐩存帴蹇界暐灏侀潰
+ return null;
}
- if (Objects.equals(type, WxCpNoticeTypeEnum.FILE.getType())
- && reqVO.getFileBlobId() == null) {
- throw exception(NOTICE_FILE_REQUIRED);
+ List<SystemStorageBlobRespVO> covers = listAttachments(NOTICE_ARTICLE_COVER_RECORD_TYPE, articleId);
+ if (CollUtil.isEmpty(covers)) {
+ return null;
}
+ return StrUtil.blankToDefault(covers.get(0).getPreviewURL(), covers.get(0).getUrl());
+ }
+
+ /**
+ * 澶氭潯娑堟伅鍚堝苟缁撴灉锛氫换涓�鏉″け璐ュ嵆瑙嗕负鏁翠綋澶辫触锛屽苟鎶婂け璐ュ師鍥犳眹鎬荤粰鍓嶇
+ */
+ private WxCpPushResultVO aggregatePushResults(List<WxCpPushResultVO> results, String label) {
+ if (CollUtil.isEmpty(results)) {
+ return new WxCpPushResultVO(false, null, label + "鎺ㄩ�佸唴瀹逛负绌�", null, null);
+ }
+ List<WxCpPushResultVO> failures = results.stream()
+ .filter(r -> !Boolean.TRUE.equals(r.getSuccess()))
+ .toList();
+ if (failures.isEmpty()) {
+ return new WxCpPushResultVO(true, 0, "鎺ㄩ�佹垚鍔�", null, null);
+ }
+ String message = failures.stream()
+ .map(WxCpPushResultVO::getMessage)
+ .filter(StrUtil::isNotBlank)
+ .distinct()
+ .collect(Collectors.joining("锛�"));
+ return new WxCpPushResultVO(false, failures.get(0).getErrCode(),
+ StrUtil.blankToDefault(message, label + "鎺ㄩ�佸け璐�"), null, null);
}
/**
@@ -242,6 +523,229 @@
return content;
}
+ /**
+ * Markdown 姝f枃锛氭妸閫氱煡鏍囬浣滀负涓�绾ф爣棰樻嫾鍦ㄦ鏂囧墠锛屼究浜庢垚鍛樼涓�鐪肩湅鍒颁富棰�
+ */
+ private String buildMarkdownContent(WxCpNoticeDO notice) {
+ String body = StrUtil.blankToDefault(notice.getContent(), "");
+ if (StrUtil.isBlank(body)) {
+ return "## " + notice.getTitle();
+ }
+ if (body.startsWith("#")) {
+ return body;
+ }
+ return "## " + notice.getTitle() + "\n" + body;
+ }
+
+ /**
+ * 鏍¢獙 Markdown 鍐呭鏄惁瓒呭嚭浼佷笟寰俊 2048 瀛楄妭闄愬埗
+ */
+ private void validateMarkdownContent(String content) {
+ if (StrUtil.isBlank(content)) {
+ throw exception(NOTICE_MARKDOWN_CONTENT_REQUIRED);
+ }
+ int bytes = content.getBytes(StandardCharsets.UTF_8).length;
+ if (bytes > MAX_MARKDOWN_BYTES) {
+ throw exception(NOTICE_MARKDOWN_TOO_LONG, bytes);
+ }
+ }
+
+ /**
+ * 鏍¢獙澶氬浘鏂囨秷鎭殑鏉$洰
+ */
+ private void validateArticles(List<WxCpNoticeArticleSaveReqVO> articles) {
+ if (CollUtil.isEmpty(articles)) {
+ throw exception(NOTICE_ARTICLE_REQUIRED);
+ }
+ if (articles.size() > MAX_ARTICLE_COUNT) {
+ throw exception(NOTICE_ARTICLE_COUNT_EXCEEDED);
+ }
+ int index = 1;
+ for (WxCpNoticeArticleSaveReqVO article : articles) {
+ if (article == null || StrUtil.isBlank(article.getTitle())) {
+ throw exception(NOTICE_ARTICLE_TITLE_REQUIRED, index);
+ }
+ if (StrUtil.isBlank(article.getLinkUrl())) {
+ throw exception(NOTICE_ARTICLE_URL_REQUIRED, index);
+ }
+ index++;
+ }
+ }
+
+ // ==================== 闄勪欢涓庡浘鏂� ====================
+
+ /**
+ * 缁戝畾鍥剧墖/闄勪欢/瑙嗛鍒伴�氱煡
+ *
+ * 璧� system 妯″潡鐨勯檮浠朵腑闂磋〃锛屼笟鍔¤〃涓嶅姞鏂囦欢鍦板潃鍒椼�佷笉鑷缓 upload 鎺ュ彛銆�
+ * 浼犵┖闆嗗悎琛ㄧず娓呯┖鍏宠仈锛堝彧鍒犱腑闂磋〃璁板綍锛屼笉鍒犳枃浠舵湰韬級銆�
+ */
+ private void bindAttachments(String recordType, Long recordId, List<Long> blobIds) {
+ SystemStorageAttachmentSaveReqVO bindReqVO = new SystemStorageAttachmentSaveReqVO();
+ bindReqVO.setApplication(ATTACHMENT_APPLICATION);
+ bindReqVO.setRecordType(recordType);
+ bindReqVO.setRecordId(recordId);
+ bindReqVO.setBlobItems(toBlobItems(blobIds));
+ storageAttachmentService.bindAttachments(bindReqVO);
+ }
+
+ private List<SystemStorageAttachmentSaveReqVO.BlobItem> toBlobItems(List<Long> blobIds) {
+ if (CollUtil.isEmpty(blobIds)) {
+ return Collections.emptyList();
+ }
+ return blobIds.stream()
+ .filter(Objects::nonNull)
+ .distinct()
+ .map(blobId -> {
+ SystemStorageAttachmentSaveReqVO.BlobItem item = new SystemStorageAttachmentSaveReqVO.BlobItem();
+ item.setBlobId(blobId);
+ return item;
+ })
+ .toList();
+ }
+
+ private List<SystemStorageBlobRespVO> listAttachments(String recordType, Long recordId) {
+ SystemStorageAttachmentListReqVO listReqVO = new SystemStorageAttachmentListReqVO();
+ listReqVO.setApplication(ATTACHMENT_APPLICATION);
+ listReqVO.setRecordType(recordType);
+ listReqVO.setRecordId(recordId);
+ return storageAttachmentService.listAttachments(listReqVO);
+ }
+
+ private List<Long> toBlobIds(List<SystemStorageBlobRespVO> attachments) {
+ if (CollUtil.isEmpty(attachments)) {
+ return Collections.emptyList();
+ }
+ // 搴曞眰鏄� selectByIds锛屼笉鎵胯杩斿洖椤哄簭锛岃繖閲屾寜 blobId 鍗囧簭锛堝嵆涓婁紶鍏堝悗锛変繚璇佹帹閫侀『搴忕ǔ瀹�
+ return attachments.stream()
+ .map(SystemStorageBlobRespVO::getId)
+ .filter(Objects::nonNull)
+ .sorted()
+ .toList();
+ }
+
+ /**
+ * 淇濆瓨澶氬浘鏂囨潯鐩細鍏堟竻绌哄啀鎻掑叆锛屼繚璇佹彁浜ら『搴忓氨鏄睍绀洪『搴�
+ */
+ private void saveArticles(Long noticeId, List<WxCpNoticeArticleSaveReqVO> articles) {
+ if (articles == null) {
+ return;
+ }
+ // 娓呮帀鏃ф潯鐩強鍏跺皝闈㈤檮浠跺叧绯�
+ for (WxCpNoticeArticleDO article : wxcpNoticeArticleMapper.selectListByNoticeId(noticeId)) {
+ storageAttachmentService.deleteAttachmentsByRecordTypeAndRecordId(
+ NOTICE_ARTICLE_COVER_RECORD_TYPE, article.getId());
+ }
+ wxcpNoticeArticleMapper.deleteByNoticeId(noticeId);
+
+ int index = 1;
+ for (WxCpNoticeArticleSaveReqVO item : articles) {
+ if (item == null) {
+ continue;
+ }
+ WxCpNoticeArticleDO article = WxCpNoticeArticleDO.builder()
+ .noticeId(noticeId)
+ .title(StrUtil.trim(item.getTitle()))
+ .description(StrUtil.trim(item.getDescription()))
+ .linkUrl(StrUtil.trim(item.getLinkUrl()))
+ .coverBlobId(item.getCoverBlobId())
+ .sortNo(item.getSortNo() != null ? item.getSortNo() : index)
+ .build();
+ wxcpNoticeArticleMapper.insert(article);
+ if (item.getCoverBlobId() != null) {
+ bindAttachments(NOTICE_ARTICLE_COVER_RECORD_TYPE, article.getId(),
+ List.of(item.getCoverBlobId()));
+ }
+ index++;
+ }
+ }
+
+ private List<WxCpNoticeArticleSaveReqVO> toArticleReqList(List<WxCpNoticeArticleDO> articles) {
+ if (CollUtil.isEmpty(articles)) {
+ return Collections.emptyList();
+ }
+ return articles.stream().map(article -> {
+ WxCpNoticeArticleSaveReqVO item = new WxCpNoticeArticleSaveReqVO();
+ item.setId(article.getId());
+ item.setTitle(article.getTitle());
+ item.setDescription(article.getDescription());
+ item.setLinkUrl(article.getLinkUrl());
+ item.setCoverBlobId(article.getCoverBlobId());
+ item.setSortNo(article.getSortNo());
+ return item;
+ }).toList();
+ }
+
+ /**
+ * 鍏煎鏃х増鍗曢檮浠跺瓧娈� fileBlobId锛氭湭浼� fileBlobIds 鏃跺綋浣滃彧鏈変竴涓檮浠�
+ */
+ private List<Long> resolveFileBlobIds(WxCpNoticeSaveReqVO reqVO) {
+ if (reqVO.getFileBlobIds() != null) {
+ return reqVO.getFileBlobIds();
+ }
+ if (reqVO.getFileBlobId() != null) {
+ return List.of(reqVO.getFileBlobId());
+ }
+ return null;
+ }
+
+ /**
+ * 鎶婇涓檮浠跺洖鍐欏埌鏃х増 fileBlobId/fileName 瀛楁锛屼究浜庤�佸墠绔垪琛ㄧ洿鎺ュ睍绀�
+ */
+ private void syncFileSnapshot(Long noticeId, List<Long> fileBlobIds, String fileName) {
+ if (fileBlobIds == null) {
+ return;
+ }
+ if (CollUtil.isEmpty(fileBlobIds)) {
+ // 闄勪欢娓呯┖鏃舵樉寮忕疆绌猴細updateById 浼氬拷鐣� null 瀛楁锛屽繀椤荤敤 UpdateWrapper
+ wxcpNoticeMapper.update(null, new LambdaUpdateWrapper<WxCpNoticeDO>()
+ .eq(WxCpNoticeDO::getId, noticeId)
+ .set(WxCpNoticeDO::getFileBlobId, null)
+ .set(WxCpNoticeDO::getFileName, null));
+ return;
+ }
+ Long firstBlobId = fileBlobIds.get(0);
+ String actualFileName = fileName;
+ if (StrUtil.isBlank(actualFileName)) {
+ SystemStorageBlobDO blob = storageBlobService.getStorageBlob(firstBlobId);
+ actualFileName = blob != null ? blob.getOriginalFilename() : null;
+ }
+ wxcpNoticeMapper.updateById(WxCpNoticeDO.builder()
+ .id(noticeId).fileBlobId(firstBlobId).fileName(actualFileName).build());
+ }
+
+ /**
+ * 鍥剧墖/闄勪欢/瑙嗛鎺ㄩ�佸悗杩藉姞棰勮椤靛崱鐗�
+ *
+ * 鏈厤缃缃戝湴鍧�鍓嶇紑鏃朵笉杩藉姞锛岄伩鍏嶆帹閫佷竴涓墦涓嶅紑鐨勯摼鎺ャ��
+ */
+ private void appendPreviewCard(List<WxCpPushResultVO> results, WxCpNoticeDO notice,
+ String btnText, Integer scope, String target) {
+ String previewUrl = buildPreviewUrl(notice.getId());
+ if (StrUtil.isBlank(previewUrl)) {
+ log.warn("[appendPreviewCard][鏈厤缃� wx.cp.signup-url-prefix锛岃烦杩囬瑙堝崱鐗� noticeId={}]", notice.getId());
+ return;
+ }
+ String description = StrUtil.isNotBlank(notice.getContent())
+ ? StrUtil.blankToDefault(notice.getSummary(), notice.getContent())
+ : "鐐瑰嚮涓嬫柟鎸夐挳鏌ョ湅閫氱煡鍐呭";
+ if (description.length() > 300) {
+ description = description.substring(0, 300) + "鈥︹��";
+ }
+ results.add(messagePushService.pushCard(notice.getTitle(), description, previewUrl, btnText, scope, target));
+ }
+
+ @Override
+ public String buildPreviewUrl(Long id) {
+ String prefix = wxCpProperties.getSignupUrlPrefix();
+ if (StrUtil.isBlank(prefix)) {
+ return null;
+ }
+ // 鍘绘帀缁撳熬鏂滄潬锛岄伩鍏嶆嫾鍑� //admin-api
+ String base = StrUtil.removeSuffix(prefix.trim(), "/");
+ return base + "/admin-api/wxcp/notice/preview-page?id=" + id;
+ }
+
private WxCpNoticeDO validateNoticeExists(Long id) {
if (id == null) {
throw exception(NOTICE_NOT_EXISTS);
@@ -253,4 +757,4 @@
return notice;
}
-}
+}
\ No newline at end of file
diff --git a/yudao-module-wxcp/src/main/java/cn/iocoder/yudao/module/wxcp/service/push/WxCpMessagePushService.java b/yudao-module-wxcp/src/main/java/cn/iocoder/yudao/module/wxcp/service/push/WxCpMessagePushService.java
index 32540a9..039a6f6 100644
--- a/yudao-module-wxcp/src/main/java/cn/iocoder/yudao/module/wxcp/service/push/WxCpMessagePushService.java
+++ b/yudao-module-wxcp/src/main/java/cn/iocoder/yudao/module/wxcp/service/push/WxCpMessagePushService.java
@@ -72,4 +72,38 @@
*/
WxCpPushResultVO pushImage(java.io.File file, Integer scope, String target);
+ /**
+ * 鎺ㄩ�佽棰戞秷鎭細鍏堟妸瑙嗛涓婁紶鍒颁紒涓氬井淇℃崲鍙� mediaId锛屽啀鍙戦�佽棰�
+ *
+ * @param file 瑙嗛鏂囦欢
+ * @param title 瑙嗛鏍囬
+ * @param description 瑙嗛鎻忚堪锛屽彲涓虹┖
+ * @param scope 鎺ㄩ�佽寖鍥�
+ * @param target 鎺ㄩ�佺洰鏍�
+ * @return 鎺ㄩ�佺粨鏋�
+ */
+ WxCpPushResultVO pushVideo(java.io.File file, String title, String description,
+ Integer scope, String target);
+
+ /**
+ * 鎺ㄩ�� Markdown 娑堟伅锛岄�傚悎甯︽爣棰樸�佸姞绮椼�佸垪琛ㄣ�佸紩鐢ㄧ瓑鎺掔増鐨勬寮忛�氱煡
+ *
+ * @param content Markdown 鍐呭锛堜紒涓氬井淇¢檺鍒� 2048 瀛楄妭锛�
+ * @param scope 鎺ㄩ�佽寖鍥�
+ * @param target 鎺ㄩ�佺洰鏍�
+ * @return 鎺ㄩ�佺粨鏋�
+ */
+ WxCpPushResultVO pushMarkdown(String content, Integer scope, String target);
+
+ /**
+ * 鎺ㄩ�佸鍥炬枃娑堟伅锛堜竴娆℃秷鎭甫澶氱瘒鏂囩珷锛�
+ *
+ * @param articles 鍥炬枃鍒楄〃锛屼紒涓氬井淇¢檺鍒� 1~8 绡�
+ * @param scope 鎺ㄩ�佽寖鍥�
+ * @param target 鎺ㄩ�佺洰鏍�
+ * @return 鎺ㄩ�佺粨鏋�
+ */
+ WxCpPushResultVO pushMultiNews(java.util.List<me.chanjar.weixin.cp.bean.article.NewArticle> articles,
+ Integer scope, String target);
+
}
diff --git a/yudao-module-wxcp/src/main/java/cn/iocoder/yudao/module/wxcp/service/push/WxCpMessagePushServiceImpl.java b/yudao-module-wxcp/src/main/java/cn/iocoder/yudao/module/wxcp/service/push/WxCpMessagePushServiceImpl.java
index 2feb14c..7c027c8 100644
--- a/yudao-module-wxcp/src/main/java/cn/iocoder/yudao/module/wxcp/service/push/WxCpMessagePushServiceImpl.java
+++ b/yudao-module-wxcp/src/main/java/cn/iocoder/yudao/module/wxcp/service/push/WxCpMessagePushServiceImpl.java
@@ -131,6 +131,52 @@
}
}
+ @Override
+ public WxCpPushResultVO pushVideo(java.io.File file, String title, String description,
+ Integer scope, String target) {
+ if (file == null || !file.exists()) {
+ return new WxCpPushResultVO(false, null, "瑙嗛鏂囦欢涓嶅瓨鍦紝鏃犳硶鎺ㄩ��", null, null);
+ }
+ try {
+ // 浼佷笟寰俊瑙嗛娑堟伅瑕佹眰鍏堢敤 video 绫诲瀷涓婁紶鎹㈠彇 mediaId
+ WxMediaUploadResult upload = wxCpService.getMediaService().upload("video", file);
+ if (upload == null || StrUtil.isBlank(upload.getMediaId())) {
+ return new WxCpPushResultVO(false, null, "瑙嗛涓婁紶浼佷笟寰俊澶辫触", null, null);
+ }
+ WxCpMessage message = WxCpMessage.VIDEO()
+ .agentId(agentId())
+ .mediaId(upload.getMediaId())
+ .title(StrUtil.blankToDefault(title, "閫氱煡瑙嗛"))
+ .description(StrUtil.blankToDefault(description, ""))
+ .build();
+ return doSend(message, scope, target, "video");
+ } catch (Exception e) {
+ log.error("[pushVideo][瑙嗛涓婁紶鎴栨帹閫佸紓甯� file={}]", file.getName(), e);
+ return new WxCpPushResultVO(false, null, "瑙嗛鎺ㄩ�佸紓甯革細" + e.getMessage(), null, null);
+ }
+ }
+
+ @Override
+ public WxCpPushResultVO pushMarkdown(String content, Integer scope, String target) {
+ WxCpMessage message = WxCpMessage.MARKDOWN()
+ .agentId(agentId())
+ .content(content)
+ .build();
+ return doSend(message, scope, target, "markdown");
+ }
+
+ @Override
+ public WxCpPushResultVO pushMultiNews(java.util.List<NewArticle> articles, Integer scope, String target) {
+ if (articles == null || articles.isEmpty()) {
+ return new WxCpPushResultVO(false, null, "鍥炬枃鍐呭涓虹┖锛屾棤娉曟帹閫�", null, null);
+ }
+ WxCpMessage message = WxCpMessage.NEWS()
+ .agentId(agentId())
+ .articles(articles)
+ .build();
+ return doSend(message, scope, target, "multi_news");
+ }
+
/**
* 缁熶竴澶勭悊鎺ユ敹鑰呰В鏋愩�佸彂閫佷笌閿欒鍖呰
*/
--
Gitblit v1.9.3