推送订阅更改

This commit is contained in:
chenxing
2026-08-19 17:35:55 +08:00
parent 4c67ec0ed0
commit a91dacd442
3 changed files with 36 additions and 7 deletions
@@ -22,4 +22,6 @@ public class DataSyncEvent {
private List<Integer> groupIds;
/** 用户事件携带的受影响用户 id 列表 */
private List<Integer> userIds;
/** 组维度的关联事件(如删除用户=解除组关系)携带的组 id */
private Integer groupId;
}
@@ -239,7 +239,8 @@ public class SysUserService implements ISysUserService {
}
}
// 业务语义:从组移除 = 对子应用即删除(不论是否真删账户),统一推送 DELETE_USER
publishUserEvent(PushInterfaceType.DELETE_USER, userIds);
// 因是「解除组关系」,需携带 (userId, groupId) 供子应用精确处理
publishUserEvent(PushInterfaceType.DELETE_USER, userIds, groupId);
}
@Override
@@ -1019,4 +1020,16 @@ public class SysUserService implements ISysUserService {
e.setUserIds(userIds);
eventPublisher.publishEvent(e);
}
/** 组维度的用户事件(如 DELETE_USER=解除组关系),额外携带组 id */
private void publishUserEvent(PushInterfaceType type, List<Integer> userIds, Integer groupId) {
if (userIds == null || userIds.isEmpty()) {
return;
}
DataSyncEvent e = new DataSyncEvent();
e.setType(type);
e.setUserIds(userIds);
e.setGroupId(groupId);
eventPublisher.publishEvent(e);
}
}
@@ -70,8 +70,9 @@ public class PushDispatcher {
if (type == PushInterfaceType.DELETE_GROUP || type == PushInterfaceType.DELETE_USER) {
List<Integer> ids = (type == PushInterfaceType.DELETE_GROUP)
? event.getGroupIds() : event.getUserIds();
Integer groupId = event.getGroupId();
for (ApplicationInfo app : applicationInfoRepository.findByPushEnabled(1)) {
dispatchDeleteToOne(app, type, ids, "auto");
dispatchDeleteToOne(app, type, ids, groupId, "auto");
}
return;
}
@@ -188,7 +189,8 @@ public class PushDispatcher {
// ===================== 核心 =====================
/** 删除类事件专用投递:跳过 DB 重载与范围过滤,直接用事件携带的 id 构建删除体。 */
private void dispatchDeleteToOne(ApplicationInfo app, PushInterfaceType type, List<Integer> ids, String triggerType) {
private void dispatchDeleteToOne(ApplicationInfo app, PushInterfaceType type, List<Integer> ids,
Integer groupId, String triggerType) {
if (app.getPushEnabled() == null || app.getPushEnabled() != 1) {
return;
}
@@ -199,20 +201,32 @@ public class PushDispatcher {
if (ids == null || ids.isEmpty()) {
return;
}
for (Object bodyObj : buildDeleteBodies(type, ids)) {
for (Object bodyObj : buildDeleteBodies(type, ids, groupId)) {
sendMessage(app, type, bodyObj, triggerType);
}
}
/** 删除类接口 body 形态:DELETE_GROUP 每个 id 一条 {id};DELETE_USER 整体一条数组 [id,...]。 */
private List<Object> buildDeleteBodies(PushInterfaceType type, List<Integer> ids) {
/**
* 删除类接口 body 形态:<br>
* DELETE_GROUP:每个 id 一条 {@code {id}};<br>
* DELETE_USER:因是「解除组关系」,每行携带 {@code {userId, groupId}}(整体一条数组)。
*/
private List<Object> buildDeleteBodies(PushInterfaceType type, List<Integer> ids, Integer groupId) {
if (type == PushInterfaceType.DELETE_GROUP) {
return ids.stream()
.map(id -> Collections.singletonMap("id", id))
.collect(Collectors.toList());
}
if (type == PushInterfaceType.DELETE_USER) {
return Collections.singletonList(new ArrayList<>(ids));
// 单组维度批量移出,所有 userId 共享同一 groupId
return ids.stream()
.map(userId -> {
Map<String, Integer> item = new LinkedHashMap<>();
item.put("userId", userId);
item.put("groupId", groupId);
return item;
})
.collect(Collectors.toList());
}
return Collections.emptyList();
}