【新增】增加事件广播方法单数据新增、更新以及删除

This commit is contained in:
王鹏
2024-12-01 13:39:00 +08:00
committed by 小诺
parent 28b24b6336
commit 9297dad472
3 changed files with 116 additions and 0 deletions

View File

@@ -13,6 +13,7 @@
package vip.xiaonuo.common.listener;
import cn.hutool.json.JSONArray;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import vip.xiaonuo.common.exception.CommonException;
@@ -144,6 +145,19 @@ public class CommonDataChangeEventCenter {
}
}
/**
* 执行添加事件发布,数据
*
* @author 每天一点
* @date 2023/3/3 10:22
**/
public static void doAddWithData(String dataType, JSONObject jsonObject) {
for (CommonDataChangeListener listener : listenerList) {
listener.doAddWithDataId(dataType, JSONUtil.parseObj(jsonObject).getStr("id"));
listener.doAddWithData(dataType, jsonObject);
}
}
// --------- 事件发布-更新 --------- //
/**
@@ -159,6 +173,19 @@ public class CommonDataChangeEventCenter {
}
}
/**
* 执行更新事件发布,数据
*
* @author 每天一点
* @date 2023/3/3 10:22
**/
public static void doUpdateWithData(String dataType, JSONObject jsonObject) {
for (CommonDataChangeListener listener : listenerList) {
listener.doUpdateWithDataId(dataType, JSONUtil.parseObj(jsonObject).getStr("id"));
listener.doUpdateWithData(dataType, jsonObject);
}
}
// --------- 事件发布-删除 --------- //
/**
@@ -172,4 +199,16 @@ public class CommonDataChangeEventCenter {
listener.doDeleteWithDataIdList(dataType, dataIdList);
}
}
/**
* 执行删除事件发布ID
*
* @author 每天一点
* @date 2023/3/3 10:22
**/
public static void doDeleteWithDataId(String dataType, String dataId) {
for (CommonDataChangeListener listener : listenerList) {
listener.doDeleteWithDataId(dataType, dataId);
}
}
}

View File

@@ -13,6 +13,7 @@
package vip.xiaonuo.common.listener;
import cn.hutool.json.JSONArray;
import cn.hutool.json.JSONObject;
import java.util.List;
@@ -24,6 +25,16 @@ import java.util.List;
**/
public interface CommonDataChangeListener {
/**
* 执行添加ID
*
* @param dataType 数据类型如USER、ORG自行定义
* @param dataId 被添加的数据ID
* @author 每天一点
* @date 2023/3/3 10:24
**/
void doAddWithDataId(String dataType, String dataId);
/**
* 执行添加ID集合
*
@@ -34,6 +45,16 @@ public interface CommonDataChangeListener {
**/
void doAddWithDataIdList(String dataType, List<String> dataIdList);
/**
* 执行添加,数据
*
* @param dataType 数据类型如USER、ORG自行定义
* @param jsonObject 被添加的数据
* @author 每天一点
* @date 2023/3/3 10:24
**/
void doAddWithData(String dataType, JSONObject jsonObject);
/**
* 执行添加,数据集合
*
@@ -44,6 +65,16 @@ public interface CommonDataChangeListener {
**/
void doAddWithDataList(String dataType, JSONArray jsonArray);
/**
* 执行更新ID
*
* @param dataType 数据类型如USER、ORG自行定义
* @param dataId 被更新的数据ID
* @author xuyuxiang
* @date 2023/3/3 10:24
**/
void doUpdateWithDataId(String dataType, String dataId);
/**
* 执行更新ID集合
*
@@ -54,6 +85,16 @@ public interface CommonDataChangeListener {
**/
void doUpdateWithDataIdList(String dataType, List<String> dataIdList);
/**
* 执行更新,数据
*
* @param dataType 数据类型如USER、ORG自行定义
* @param jsonObject 被更新的数据
* @author xuyuxiang
* @date 2023/3/3 10:24
**/
void doUpdateWithData(String dataType, JSONObject jsonObject);
/**
* 执行更新,数据集合
*
@@ -64,6 +105,16 @@ public interface CommonDataChangeListener {
**/
void doUpdateWithDataList(String dataType, JSONArray jsonArray);
/**
* 执行删除ID
*
* @param dataType 数据类型如USER、ORG自行定义
* @param dataId 被删除的数据ID
* @author xuyuxiang
* @date 2023/3/3 10:24
**/
void doDeleteWithDataId(String dataType, String dataId);
/**
* 执行删除ID集合
*

View File

@@ -14,6 +14,7 @@ package vip.xiaonuo.sys.core.listener;
import cn.dev33.satoken.stp.StpUtil;
import cn.hutool.json.JSONArray;
import cn.hutool.json.JSONObject;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Component;
import vip.xiaonuo.auth.core.pojo.SaBaseLoginUser;
@@ -38,6 +39,11 @@ public class SysDataChangeListener implements CommonDataChangeListener {
@Resource
private CommonCacheOperator commonCacheOperator;
@Override
public void doAddWithDataId(String dataType, String dataId) {
// 此处可做额外处理
}
@Override
public void doAddWithDataIdList(String dataType, List<String> dataIdList) {
// 如果检测到机构增加,则将机构的数据缓存清除
@@ -56,11 +62,21 @@ public class SysDataChangeListener implements CommonDataChangeListener {
}
}
@Override
public void doAddWithData(String dataType, JSONObject jsonObject) {
// 此处可做额外处理
}
@Override
public void doAddWithDataList(String dataType, JSONArray jsonArray) {
// 此处可做额外处理
}
@Override
public void doUpdateWithDataId(String dataType, String dataId) {
// 此处可做额外处理
}
@Override
public void doUpdateWithDataIdList(String dataType, List<String> dataIdList) {
// 如果检测到机构更新,则将机构的数据缓存清除
@@ -73,11 +89,21 @@ public class SysDataChangeListener implements CommonDataChangeListener {
}
}
@Override
public void doUpdateWithData(String dataType, JSONObject jsonObject) {
// 此处可做额外处理
}
@Override
public void doUpdateWithDataList(String dataType, JSONArray jsonArray) {
// 此处可做额外处理
}
@Override
public void doDeleteWithDataId(String dataType, String dataId) {
// 此处可做额外处理
}
@Override
public void doDeleteWithDataIdList(String dataType, List<String> dataIdList) {
// 如果检测到机构增加,则将机构的数据缓存清除