From f8f286d2a1f1304b5d13f8a023da9ffbc87278e2 Mon Sep 17 00:00:00 2001
From: lixiaolong <702156524@qq.com>
Date: Tue, 27 Oct 2026 09:04:41 +0800
Subject: [PATCH] =?UTF-8?q?feat(assistant):=20=E6=96=B0=E5=A2=9E=E7=94=A8?=
=?UTF-8?q?=E6=88=B7=E6=A0=B8=E5=AF=B9=E5=8A=9F=E8=83=BD=E5=B9=B6=E4=BC=98?=
=?UTF-8?q?=E5=8C=96=E5=AF=B9=E8=AF=9D=E6=B5=81=E7=A8=8B?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
- 新增 user.check 功能用于核对人员是否已有系统账号
- 在 assistant-table-layout.js 中为用户表格添加 checkedIdentity 和 matchResult 字段
- 优化 AssistantConversationService 中的任务记忆和澄清流程
- 支持对草稿特定行进行修改,无需重新填写整张表
- 限制 user.check 操作最大查询数量为 100 条记录
- 实现中断任务恢复机制,保持原始请求上下文
- 添加针对多行数据选择性修改的目标行标识支持
---
mobile-app/src/core/assistant-display.ts | 5 +-
mobile-app/src/screens/Assistant.tsx | 6 +-
.../tests/assistant-notification.test.mjs | 14 ++
.../project/ProjectArchiveController.java | 10 +-
.../web/service/archive/ArchiveAccess.java | 3 +
.../web/service/archive/ArchiveAnalytics.java | 69 ++++++++
.../web/service/archive/ArchiveCosts.java | 14 +-
.../web/service/archive/ArchiveExporter.java | 10 +-
.../web/service/archive/ArchivePersonnel.java | 40 +++++
.../web/service/archive/ArchiveReview.java | 52 ++++++
.../web/service/archive/ArchiveService.java | 81 ++++++---
.../assistant/AssistantBusinessRules.java | 4 +-
.../assistant/AssistantExtendedActions.java | 5 +-
.../assistant/AssistantModelClient.java | 70 +++++++-
.../assistant/AssistantNoticeContent.java | 62 +++++++
.../AssistantNotificationService.java | 112 +++++++++---
.../assistant/BusinessActionRegistry.java | 24 ++-
.../service/archive/ArchiveAnalyticsTest.java | 23 +++
.../web/service/archive/ArchiveFlowTest.java | 99 ++++++++++-
.../service/archive/ArchiveReviewTest.java | 17 ++
.../AssistantBusinessContractTest.java | 5 +
.../assistant/AssistantNoticeContentTest.java | 57 ++++++
.../AssistantNotificationBroadcastTest.java | 138 +++++++++++++++
.../AssistantNotificationModelLiveTest.java | 39 ++++-
.../static/assistant-guides/feedback-1.svg | 17 ++
.../static/assistant-guides/feedback-2.svg | 15 ++
.../static/assistant-guides/feedback-3.svg | 11 ++
ruoyi-ui-vue3/src/api/archive/index.js | 6 +
.../BusinessAssistant/AssistantDraft.vue | 8 +
.../AssistantNoticeContent.vue | 28 +++
.../AssistantNotificationPreview.vue | 37 ++++
.../components/PurchaseSheet/PastePreview.vue | 56 ++++--
.../src/components/PurchaseSheet/index.vue | 16 +-
ruoyi-ui-vue3/src/router/index.js | 1 +
.../src/utils/assistant-draft-edit.js | 9 +
ruoyi-ui-vue3/src/utils/assistant-notice.js | 31 ++++
.../src/utils/assistant-notification.js | 5 +
ruoyi-ui-vue3/src/utils/purchase-sheet.js | 23 ++-
.../src/views/archive/ArchiveCost.vue | 71 ++++----
.../src/views/archive/ArchiveFiles.vue | 19 +-
.../src/views/archive/ArchiveItemStatus.vue | 17 +-
.../src/views/archive/ArchiveLaborRates.vue | 26 +++
.../src/views/archive/ArchiveReview.vue | 51 ++++++
.../views/archive/archive-cost-validation.js | 16 ++
.../src/views/archive/archive-model.js | 30 ++--
.../src/views/archive/archive-workflow.js | 37 ++++
.../src/views/archive/cost-analysis.vue | 90 ++++++++++
ruoyi-ui-vue3/src/views/archive/index.vue | 143 ++++++++++-----
.../tests/runtime/archive-analysis.spec.js | 23 +++
.../tests/runtime/archive-cost-select.spec.js | 17 ++
.../runtime/archive-cost-validation.spec.js | 9 +
.../tests/runtime/archive-module.spec.js | 164 +++++++++++++++---
.../tests/runtime/archive-review.spec.js | 29 ++++
.../tests/runtime/archive-workflow.spec.js | 41 +++++
.../tests/runtime/assistant-notice.spec.js | 38 ++++
.../runtime/assistant-notification.spec.js | 73 ++++++++
.../tests/runtime/purchase-excel-edit.spec.js | 5 +
.../runtime/purchase-paste-preview.spec.js | 18 +-
.../ui/archive-workflow/analysis-data.mjs | 10 ++
.../tests/ui/archive-workflow/index.html | 8 +
.../tests/ui/archive-workflow/mock-api.mjs | 31 ++++
.../tests/ui/archive-workflow/responsive.html | 1 +
.../tests/ui/archive-workflow/vite.config.mjs | 10 ++
.../tests/ui/purchase-paste-editor/index.html | 10 ++
.../ui/purchase-paste-editor/vite.config.mjs | 4 +
.../tests/unit/purchase-paste-issues.test.mjs | 19 ++
sql/projectdev/20261021_project_archive.sql | 5 +-
.../20261026_archive_cost_analysis.sql | 13 ++
68 files changed, 2019 insertions(+), 231 deletions(-)
create mode 100644 mobile-app/tests/assistant-notification.test.mjs
create mode 100644 ruoyi-admin/src/main/java/com/ruoyi/web/service/archive/ArchiveAnalytics.java
create mode 100644 ruoyi-admin/src/main/java/com/ruoyi/web/service/archive/ArchivePersonnel.java
create mode 100644 ruoyi-admin/src/main/java/com/ruoyi/web/service/archive/ArchiveReview.java
create mode 100644 ruoyi-admin/src/main/java/com/ruoyi/web/service/assistant/AssistantNoticeContent.java
create mode 100644 ruoyi-admin/src/test/java/com/ruoyi/web/service/archive/ArchiveAnalyticsTest.java
create mode 100644 ruoyi-admin/src/test/java/com/ruoyi/web/service/archive/ArchiveReviewTest.java
create mode 100644 ruoyi-admin/src/test/java/com/ruoyi/web/service/assistant/AssistantNoticeContentTest.java
create mode 100644 ruoyi-admin/src/test/java/com/ruoyi/web/service/assistant/AssistantNotificationBroadcastTest.java
create mode 100644 ruoyi-ui-vue3/public/static/assistant-guides/feedback-1.svg
create mode 100644 ruoyi-ui-vue3/public/static/assistant-guides/feedback-2.svg
create mode 100644 ruoyi-ui-vue3/public/static/assistant-guides/feedback-3.svg
create mode 100644 ruoyi-ui-vue3/src/components/BusinessAssistant/AssistantNoticeContent.vue
create mode 100644 ruoyi-ui-vue3/src/components/BusinessAssistant/AssistantNotificationPreview.vue
create mode 100644 ruoyi-ui-vue3/src/utils/assistant-notice.js
create mode 100644 ruoyi-ui-vue3/src/utils/assistant-notification.js
create mode 100644 ruoyi-ui-vue3/src/views/archive/ArchiveLaborRates.vue
create mode 100644 ruoyi-ui-vue3/src/views/archive/ArchiveReview.vue
create mode 100644 ruoyi-ui-vue3/src/views/archive/archive-cost-validation.js
create mode 100644 ruoyi-ui-vue3/src/views/archive/archive-workflow.js
create mode 100644 ruoyi-ui-vue3/src/views/archive/cost-analysis.vue
create mode 100644 ruoyi-ui-vue3/tests/runtime/archive-analysis.spec.js
create mode 100644 ruoyi-ui-vue3/tests/runtime/archive-cost-select.spec.js
create mode 100644 ruoyi-ui-vue3/tests/runtime/archive-cost-validation.spec.js
create mode 100644 ruoyi-ui-vue3/tests/runtime/archive-review.spec.js
create mode 100644 ruoyi-ui-vue3/tests/runtime/archive-workflow.spec.js
create mode 100644 ruoyi-ui-vue3/tests/runtime/assistant-notice.spec.js
create mode 100644 ruoyi-ui-vue3/tests/runtime/assistant-notification.spec.js
create mode 100644 ruoyi-ui-vue3/tests/ui/archive-workflow/analysis-data.mjs
create mode 100644 ruoyi-ui-vue3/tests/ui/archive-workflow/index.html
create mode 100644 ruoyi-ui-vue3/tests/ui/archive-workflow/mock-api.mjs
create mode 100644 ruoyi-ui-vue3/tests/ui/archive-workflow/responsive.html
create mode 100644 ruoyi-ui-vue3/tests/ui/archive-workflow/vite.config.mjs
create mode 100644 ruoyi-ui-vue3/tests/ui/purchase-paste-editor/index.html
create mode 100644 ruoyi-ui-vue3/tests/ui/purchase-paste-editor/vite.config.mjs
create mode 100644 ruoyi-ui-vue3/tests/unit/purchase-paste-issues.test.mjs
create mode 100644 sql/projectdev/20261026_archive_cost_analysis.sql
diff --git a/mobile-app/src/core/assistant-display.ts b/mobile-app/src/core/assistant-display.ts
index 3b0f402..0b1a0de 100644
--- a/mobile-app/src/core/assistant-display.ts
+++ b/mobile-app/src/core/assistant-display.ts
@@ -21,7 +21,10 @@ export function draftOutcome(draft:Row) {
}
export function draftReviewCount(draft:Row) {
- return (draft.rows||[]).reduce((total:number,row:Row)=>total+Math.max(1,row._referencePricePreview?.length||0),0);
+ return (draft.rows||[]).reduce((total:number,row:Row)=>total+Math.max(1,row._referencePricePreview?.length||0,draft.action==='notification.send'?Math.max(Number(row._notificationPreview?.recipientCount)||0,row._notificationPreview?.recipients?.length||0):0),0);
+}
+export function draftNeedsRichNoticeReview(draft:Row) {
+ return ['notice.create','notice.update'].includes(draft.action)&&(draft.rows||[]).some((row:Row)=>/
>(null),lock=useRef(false),alive=useRef(true),followLatest=useRef(true);
@@ -77,11 +77,13 @@ function DraftCard({draft,currentId,busy,onAction,onInspect}:{draft:Row;currentI
{(draft.errors||[]).map((e:string,j:number)=>{e})}
{(draft.rows||[]).slice(0,20).map((row:Row,j:number)=>第 {j+1} 行{(draft.fields||[]).filter((f:Row)=>!f.hidden).map((f:Row)=>{f.label}:{draftFieldText(row,f)})}{draft.action==='purchase.correctPrice'&&(row._quotePreview||[]).map((q:Row,k:number)=>{q.name} · 数量 {q.quantity}报价:{q.previousPrice??'未报价'} → {q.unitPrice};金额:{q.oldAmount??'未计价'} → {q.newAmount}{q.notice})})}
{(draft.rows||[]).flatMap((row:Row)=>row._referencePricePreview||[]).slice(0,20).map((row:Row,index:number)=>{row.name} · {row.spec} · 数量 {row.quantity}实际单价:{row.oldActualPrice??'未填写'} → {row.newActualPrice??'未填写'};实际金额:{row.oldActualAmount??'未填写'} → {row.newActualAmount??'未填写'}{row.clearQuote&&报价单价:{row.quotePrice??'未报价'} → {row.newQuotePrice??(row.changed?'清空(未报价)':'未报价')};报价金额:{row.oldQuoteAmount??'未报价'} → {row.newQuoteAmount??(row.changed?'清空(未报价)':'未报价')}}{row.notice};{row.clearQuote?'整批提交并同步金额与成本,清空不是0元':'不修改报价或成本'})}
+ {draft.action==='notification.send'&&(draft.rows||[]).slice(0,20).map((row:Row,index:number)=>row._notificationPreview&&{row._notificationPreview.scope} · 实际接收 {row._notificationPreview.recipientCount} 人{(row._notificationPreview.recipients||[]).slice(0,20).map((person:Row)=>{person.name||'未填写姓名'}({person.account}){row._notificationPreview.emailRequired?` · ${person.email}`:''})}{row._notificationPreview.notice})}
{(draft.rows||[]).filter((row:Row)=>row._historyPreview).slice(0,20).map((row:Row,index:number)=>{const h=row._historyPreview;return {h.name} · {h.spec}{(h.changes||[]).map((change:Row)=>{change.label} · 更正前:{change.beforeText??change.before??'未填写'}更正后:{change.afterText??change.after??'未填写'})}实际金额:{h.oldActualAmount??'未填写'} → {h.newActualAmount??'未填写'};报价金额:{h.oldAmount??'未计价'} → {h.newAmount??'未计价'}关联入库 {h.receiptCount||0} 条,成本来源 {h.costSourceCount||0} 条;实际收货数量不变。{h.createItem&&确认后匹配或新建物品档案。}{h.categoryUpdatesArchive&&类别更正会同步物品档案及其引用页面。}{h.priceImpact?.notice&&{h.priceImpact.notice}}{h.oldStatus!==h.newStatus&&采购状态将随需求数量重新核算,请在电脑端核对完整状态。}})}
{reviewCount>20&&此确认单超过 20 项,请在电脑端完整核对后办理;App 暂不开放截断确认。}
>}
{active&&<>需要更正时可继续在下方描述,原草稿由后端保留并重新核对。
-
");assertEquals(false,registry.prepare("notice.create",List.of(imageOnly)).get("ready"));
+ var oversized=row();oversized.put("noticeContent","字".repeat(19990));assertEquals(false,registry.prepare("notice.create",List.of(oversized)).get("ready"));verifyNoInteractions(controller,db);
+ doThrow(new ServiceException("无权限",403)).when(permissions).require(any(),anyString());assertThrows(ServiceException.class,()->registry.prepare("notice.create",List.of(row())));verifyNoInteractions(controller,db);
+ }
+}
diff --git a/ruoyi-admin/src/test/java/com/ruoyi/web/service/assistant/AssistantNotificationBroadcastTest.java b/ruoyi-admin/src/test/java/com/ruoyi/web/service/assistant/AssistantNotificationBroadcastTest.java
new file mode 100644
index 0000000..46867eb
--- /dev/null
+++ b/ruoyi-admin/src/test/java/com/ruoyi/web/service/assistant/AssistantNotificationBroadcastTest.java
@@ -0,0 +1,138 @@
+package com.ruoyi.web.service.assistant;
+
+import com.ruoyi.common.exception.ServiceException;
+import com.ruoyi.common.notification.NotificationGateway;
+import com.ruoyi.common.utils.SecurityUtils;
+import com.ruoyi.system.notification.NotificationMailSender;
+import java.util.*;
+import org.junit.jupiter.api.*;
+import org.mockito.MockedStatic;
+import org.mockito.ArgumentCaptor;
+import org.springframework.aop.framework.ProxyFactory;
+import org.springframework.jdbc.core.JdbcTemplate;
+import org.springframework.jdbc.datasource.DriverManagerDataSource;
+import org.springframework.jdbc.datasource.DataSourceTransactionManager;
+import org.springframework.test.util.ReflectionTestUtils;
+import org.springframework.transaction.annotation.AnnotationTransactionAttributeSource;
+import org.springframework.transaction.interceptor.TransactionInterceptor;
+import static org.junit.jupiter.api.Assertions.*;
+import static org.mockito.Mockito.*;
+
+/** Synthetic H2 accounts only; gateway and SMTP are mocked. Never touches a running environment. */
+class AssistantNotificationBroadcastTest {
+ AssistantNotificationService service; JdbcTemplate db; NotificationGateway gateway; NotificationMailSender mail;
+ MockedStatic security;
+ @BeforeEach void setup() {
+ security=mockStatic(SecurityUtils.class);security.when(SecurityUtils::isAdmin).thenReturn(true);security.when(SecurityUtils::getUserId).thenReturn(1L);
+ var source=new DriverManagerDataSource("jdbc:h2:mem:notification_"+UUID.randomUUID()+";MODE=MySQL;DATABASE_TO_LOWER=TRUE", "sa", "");
+ // Keep the in-memory database alive across JdbcTemplate connections until teardown.
+ source.setUrl(source.getUrl()+";DB_CLOSE_DELAY=-1");db=new JdbcTemplate(source);
+ db.execute("create table sys_user(user_id bigint primary key,user_name varchar(80),nick_name varchar(80),email varchar(160),status char(1),del_flag char(1))");
+ db.execute("create table sys_role(role_id bigint primary key,role_name varchar(80),role_key varchar(80),status char(1),del_flag char(1))");
+ db.execute("create table sys_user_role(user_id bigint,role_id bigint)");
+ db.execute("create table queued_probe(event_key varchar(128) primary key)");
+ gateway=mock(NotificationGateway.class);mail=mock(NotificationMailSender.class);when(mail.ready()).thenReturn(true);
+ when(gateway.publish(any())).thenAnswer(call->{NotificationGateway.Command c=call.getArgument(0);return new NotificationGateway.Receipt(c.eventKey(),false,c.userIds().size(),0,0);});
+ var target=new AssistantNotificationService();ReflectionTestUtils.setField(target,"db",db);ReflectionTestUtils.setField(target,"notifications",gateway);ReflectionTestUtils.setField(target,"mail",mail);ReflectionTestUtils.setField(target,"enabled",true);
+ var proxy=new ProxyFactory(target);proxy.setProxyTargetClass(true);proxy.addAdvice(new TransactionInterceptor(new DataSourceTransactionManager(source),new AnnotationTransactionAttributeSource()));service=(AssistantNotificationService)proxy.getProxy();
+ }
+ @AfterEach void cleanup(){security.close();db.execute("shutdown");}
+ Map row(String mode) {return new LinkedHashMap<>(Map.of("recipientMode",mode,"channel","INBOX","title","模拟功能说明","content","这是虚构测试正文,不会发送真实通知。","_executionKey","isolated-broadcast-command"));}
+ void users(int count) {
+ var records=new ArrayList();for(long id=1;id<=count;id++)records.add(new Object[]{id,"test"+id,"模拟用户"+id,"test"+id+"@example.invalid","0","0"});
+ db.batchUpdate("insert into sys_user values(?,?,?,?,?,?)",records);
+ }
+ void role(long id,String status){db.update("insert into sys_role values(?,?,?,?,'0')",id,"模拟角色"+id,"synthetic_"+id,status);}
+ Map confirmed(Map row){row.put("recipientVersion",service.preview(row).get("recipientVersion"));return row;}
+ @Test void allMeansEveryActiveUndeletedAccountIncludingSenderAndNoEmailRequirement() {
+ users(4);db.update("update sys_user set status='1' where user_id=2");db.update("update sys_user set del_flag='2' where user_id=3");db.update("update sys_user set email='' where user_id=4");
+ var plan=service.preview(row("ALL"));assertEquals(2,plan.get("recipientCount"));assertEquals(List.of(1L,4L),AssistantConversationService.maps(plan.get("recipients")).stream().map(u->u.get("id")).toList());
+ assertFalse(plan.toString().contains("@example"));verifyNoInteractions(gateway,mail);
+ }
+ @Test void rolesAreUnionedDeduplicatedAndOnlyActiveAccountsRemain() {
+ users(4);role(10,"0");role(11,"0");db.update("insert into sys_user_role values(1,10),(1,11),(2,11),(3,10),(4,11)");db.update("update sys_user set status='1' where user_id=3");db.update("update sys_user set del_flag='2' where user_id=4");
+ var values=row("ROLES");values.put("roleIds",List.of(10L,11L,10L));values.put("userIds",List.of(999L));var result=service.send(confirmed(values));
+ assertEquals(2,result.get("recipientCount"));var capture=ArgumentCaptor.forClass(NotificationGateway.Command.class);verify(gateway).publish(capture.capture());assertEquals(Set.of(1L,2L),capture.getValue().userIds());assertTrue(capture.getValue().roleIds().isEmpty());
+ }
+ @Test void missingDisabledDeletedAndEmptyRolesBlockWithoutPublishing() {
+ users(1);role(10,"1");role(11,"0");role(12,"0");db.update("update sys_role set del_flag='2' where role_id=12");
+ for(long id:List.of(10L,11L,12L,999L)){var values=row("ROLES");values.put("roleIds",List.of(id));assertThrows(ServiceException.class,()->service.preview(values));}
+ assertThrows(ServiceException.class,()->service.preview(row("ROLES")));verifyNoInteractions(gateway);
+ }
+ @Test void limitsNeverSilentlyTruncateTheAudience() {
+ users(5001);assertTrue(assertThrows(ServiceException.class,()->service.preview(row("ALL"))).getMessage().contains("不会截断"));
+ var roles=row("ROLES");roles.put("roleIds",java.util.stream.LongStream.rangeClosed(1,21).boxed().toList());assertThrows(ServiceException.class,()->service.preview(roles));verifyNoInteractions(gateway);
+ }
+ @Test void fiveThousandRecipientsCanBePreviewedCompletely() {
+ users(5000);var plan=service.preview(row("ALL"));assertEquals(5000,AssistantConversationService.maps(plan.get("recipients")).size());assertEquals(25,plan.get("batchCount"));verifyNoInteractions(gateway);
+ }
+ @Test void groupSendRequiresTheServerPreviewAndDetectsBodyAndChannelChanges() {
+ users(1);var values=row("ALL");assertThrows(ServiceException.class,()->service.send(values));confirmed(values);values.put("content","另一个正文");assertThrows(ServiceException.class,()->service.send(values));confirmed(values);values.put("channel","BOTH");assertThrows(ServiceException.class,()->service.send(values));verifyNoInteractions(gateway);
+ }
+ @Test void addedRemovedAndDisabledMembersRequireFreshConfirmation() {
+ users(3);role(10,"0");db.update("insert into sys_user_role values(1,10),(2,10)");var values=row("ROLES");values.put("roleIds",List.of(10L));confirmed(values);
+ db.update("insert into sys_user_role values(3,10)");assertThrows(ServiceException.class,()->service.send(values));confirmed(values);
+ db.update("delete from sys_user_role where user_id=2");assertThrows(ServiceException.class,()->service.send(values));confirmed(values);
+ db.update("update sys_user set status='1' where user_id=3");assertThrows(ServiceException.class,()->service.send(values));verifyNoInteractions(gateway);
+ }
+ @Test void allAudienceChangesRequireReconfirmationToo() {
+ users(2);var values=confirmed(row("ALL"));db.update("update sys_user set del_flag='2' where user_id=2");assertThrows(ServiceException.class,()->service.send(values));verifyNoInteractions(gateway);
+ }
+ @Test void multipartSendUsesExactFrozenIdsAndStableDistinctKeys() {
+ users(401);var values=confirmed(row("ALL"));var result=service.send(values);service.send(values);
+ assertEquals(401,result.get("recipientCount"));assertEquals(401,result.get("inboxDelivered"));assertEquals(3,result.get("batchCount"));
+ var capture=ArgumentCaptor.forClass(NotificationGateway.Command.class);verify(gateway,times(6)).publish(capture.capture());var commands=capture.getAllValues();
+ assertEquals(List.of(200,200,1),commands.subList(0,3).stream().map(c->c.userIds().size()).toList());var ids=new HashSet();
+ for(int i=0;i<3;i++){var c=commands.get(i);assertEquals(c,commands.get(i+3));assertTrue(c.roleIds().isEmpty());for(long id:c.userIds())assertTrue(ids.add(id));}
+ assertEquals(401,ids.size());assertEquals(3,commands.subList(0,3).stream().map(NotificationGateway.Command::eventKey).distinct().count());
+ }
+ @Test void laterBatchFailureRollsBackEarlierEnqueues() {
+ users(201);var values=confirmed(row("ALL"));doAnswer(call->{NotificationGateway.Command c=call.getArgument(0);if(c.eventKey().endsWith(":2"))throw new ServiceException("模拟第二批失败");db.update("insert into queued_probe values(?)",c.eventKey());return new NotificationGateway.Receipt("synthetic",false,200,0,0);}).when(gateway).publish(any());
+ assertThrows(ServiceException.class,()->service.send(values));assertEquals(0,db.queryForObject("select count(*) from queued_probe",Integer.class));
+ }
+ @Test void sharedMailboxDoesNotSplitAcrossEventsAndMissingEmailStopsTheWholeBatch() {
+ users(202);db.update("update sys_user set email='shared@example.invalid' where user_id in(1,202)");var values=row("ALL");values.put("channel","BOTH");service.send(confirmed(values));
+ var capture=ArgumentCaptor.forClass(NotificationGateway.Command.class);verify(gateway,times(2)).publish(capture.capture());assertEquals(1,capture.getAllValues().stream().filter(c->c.userIds().contains(1L)&&c.userIds().contains(202L)).count());
+ clearInvocations(gateway);confirmed(values);db.update("update sys_user set email='' where user_id=201");assertThrows(ServiceException.class,()->service.send(values));verifyNoInteractions(gateway);
+ }
+ @Test void oversizedSharedMailboxCannotBypassPerEventLimit() {
+ users(201);db.update("update sys_user set email='shared@example.invalid'");var values=row("ALL");values.put("channel","EMAIL");assertThrows(ServiceException.class,()->service.preview(values));verifyNoInteractions(gateway);
+ }
+ @Test void ordinaryAccountsCannotExpandOrSendAnyScope() {
+ security.when(SecurityUtils::isAdmin).thenReturn(false);for(String mode:List.of("ALL","ROLES","USERS")){assertThrows(ServiceException.class,()->service.preview(row(mode)));assertThrows(ServiceException.class,()->service.send(row(mode)));}verifyNoInteractions(gateway,mail);
+ }
+ @Test void legacySelectionDefaultsToUsersAndRoleOnlyInputInfersRoles() {
+ assertEquals("USERS",AssistantNotificationService.selectionInput(Map.of("userIds",List.of(7L))).get("recipientMode"));assertEquals("ROLES",AssistantNotificationService.selectionInput(Map.of("roleIds",List.of(10L))).get("recipientMode"));assertFalse(AssistantNotificationService.selectionInput(Map.of("recipientMode","ALL","userIds",List.of(7L),"roleIds",List.of(10L))).containsKey("roleIds"));
+ }
+ BusinessActionRegistry registry() {
+ var login=new com.ruoyi.common.core.domain.model.LoginUser();login.setPermissions(Set.of("*:*:*"));security.when(SecurityUtils::getLoginUser).thenReturn(login);
+ var context=mock(org.springframework.context.ApplicationContext.class);var extra=new AssistantExtendedActions();ReflectionTestUtils.setField(extra,"assistantNotifications",service);when(context.getBean(AssistantExtendedActions.class)).thenReturn(extra);
+ var guard=mock(AssistantPermissionGuard.class);when(guard.allows(any())).thenReturn(true);
+ return new BusinessActionRegistry(context,new com.fasterxml.jackson.databind.ObjectMapper(),db,mock(jakarta.validation.Validator.class),guard);
+ }
+ @Test void registryBuildsAuthoritativePreviewAndIgnoresForgedClientDerivedFields() {
+ users(2);var registry=registry();var values=row("ALL");values.put("userIds",List.of(999L));values.put("recipientVersion","forged");values.put("_notificationPreview",Map.of("recipients",List.of(999L)));
+ var prepared=registry.prepare("notification.send",List.of(values));assertEquals(true,prepared.get("ready"),prepared.toString());var checked=AssistantConversationService.maps(prepared.get("rows")).get(0);
+ assertNotEquals("forged",checked.get("recipientVersion"));assertFalse(checked.containsKey("userIds"));assertEquals(2,((Map,?>)checked.get("_notificationPreview")).get("recipientCount"));
+ var version=AssistantConversationService.maps(prepared.get("fields")).stream().filter(f->"recipientVersion".equals(f.get("key"))).findFirst().orElseThrow();assertEquals(true,version.get("readonly"));assertEquals(true,version.get("hidden"));
+ checked.put("_executionKey","isolated-registry-execution");registry.execute("notification.send",checked);verify(gateway).publish(any());clearInvocations(gateway);
+ db.update("update sys_user set status='1' where user_id=2");assertThrows(ServiceException.class,()->registry.execute("notification.send",checked));verifyNoInteractions(gateway);
+ }
+ @Test void modelFollowupContextRetainsMessageAndScopeWithoutLeakingExpandedRecipients() {
+ var value=row("ROLES");value.put("roleIds",List.of("模拟角色"));value.put("_notificationPreview",Map.of("recipients",List.of(Map.of("name","not-for-model"))));value.put("_snapshot",Map.of("messageRecipients",value.get("_notificationPreview")));value.put("recipientVersion","opaque-token");
+ var task=Map.of("action","notification.send","rows",List.of(value));var compact=AssistantModelClient.notificationModelTask(task);String json=com.alibaba.fastjson2.JSON.toJSONString(compact);
+ assertTrue(json.contains("模拟功能说明"));assertTrue(json.contains("模拟角色"));assertFalse(json.contains("not-for-model"));assertFalse(json.contains("opaque-token"));assertTrue(value.containsKey("_snapshot"));
+ }
+ @Test void onlyUnambiguousSingleNotificationScopeFollowupsUseFieldOnlyExtraction() {
+ var task=Map.of("action","notification.send","status","WAIT_CONFIRM","rows",List.of(Map.of("title","原标题")));
+ for(String text:List.of("给项目经理角色发送","改成给项目经理角色发送,正文不变","改成给所有人","只给全员发送"))assertTrue(AssistantModelClient.notificationRecipientEdit(text,task),text);
+ for(String text:List.of("另外给项目经理角色发送","给所有人发通知,告诉他们怎么用反馈","给项目经理角色发送,正文改成明天开会"))assertFalse(AssistantModelClient.notificationRecipientEdit(text,task),text);
+ assertFalse(AssistantModelClient.notificationRecipientEdit("给项目经理角色发送",Map.of("action","notification.send","status","SUCCEEDED","rows",task.get("rows"))));
+ }
+ @Test void missingDraftRoleFollowupRetainsOnlyTheImmediatelyPreviousExplicitNotificationRequest() {
+ var history=List.