增加mom平台通用模块
master
xs 1 week ago
parent 09718780a7
commit 6b7f7c443f

@ -0,0 +1,37 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<groupId>org.dromara</groupId>
<artifactId>ruoyi-common</artifactId>
<version>${revision}</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>hwmom-common-mom</artifactId>
<description>
hwmom-common-mom 通用功能
</description>
<dependencies>
<dependency>
<groupId>org.dromara</groupId>
<artifactId>ruoyi-common-satoken</artifactId>
</dependency>
<dependency>
<groupId>org.dromara</groupId>
<artifactId>ruoyi-common-json</artifactId>
</dependency>
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-spring-boot-starter</artifactId>
<scope>provided</scope>
</dependency>
</dependencies>
</project>

@ -0,0 +1,43 @@
package org.dromara.common.annotation;
import org.dromara.common.enums.OperatorType;
import java.lang.annotation.*;
/**
*
*
* @author xins
*/
@Target({ElementType.PARAMETER, ElementType.METHOD})
@Retention(RetentionPolicy.RUNTIME)
@Documented
public @interface DataSyncPublish {
/**
*
*/
String tableName() default "";
/**
*
*/
OperatorType operatorType() default OperatorType.INSERT;
// /**
// * 是否保存请求的参数
// */
// boolean isSaveRequestData() default true;
//
// /**
// * 是否保存响应的参数
// */
// boolean isSaveResponseData() default true;
//
//
// /**
// * 排除指定的请求参数
// */
// String[] excludeParamNames() default {};
}

@ -0,0 +1,215 @@
package org.dromara.common.aspect;
import cn.hutool.core.lang.Dict;
import cn.hutool.core.map.MapUtil;
import cn.hutool.core.util.ArrayUtil;
import cn.hutool.core.util.ObjectUtil;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.time.StopWatch;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.AfterThrowing;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.dromara.common.annotation.DataSyncPublish;
import org.dromara.common.json.utils.JsonUtils;
import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.validation.BindingResult;
import org.springframework.web.multipart.MultipartFile;
import java.util.Collection;
import java.util.Map;
import java.util.StringJoiner;
/**
*
*
* @author xins
*/
@Slf4j
@Aspect
@AutoConfiguration
public class DataSyncPublishAspect {
/**
*
*/
public static final String[] EXCLUDE_PROPERTIES = { "password", "oldPassword", "newPassword", "confirmPassword" };
/**
* key
*/
private static final ThreadLocal<StopWatch> KEY_CACHE = new ThreadLocal<>();
/**
*
*/
@Before(value = "@annotation(dataSyncPublish)")
public void doBefore(JoinPoint joinPoint, DataSyncPublish dataSyncPublish) {
StopWatch stopWatch = new StopWatch();
KEY_CACHE.set(stopWatch);
stopWatch.start();
}
/**
*
*
* @param joinPoint
*/
@AfterReturning(pointcut = "@annotation(dataSyncPublish)", returning = "jsonResult")
public void doAfterReturning(JoinPoint joinPoint, DataSyncPublish dataSyncPublish, Object jsonResult) {
handleDataSyncPublish(joinPoint, dataSyncPublish, null, jsonResult);
}
/**
*
*
* @param joinPoint
* @param e
*/
@AfterThrowing(value = "@annotation(dataSyncPublish)", throwing = "e")
public void doAfterThrowing(JoinPoint joinPoint, DataSyncPublish dataSyncPublish, Exception e) {
handleDataSyncPublish(joinPoint, dataSyncPublish, e, null);
}
protected void handleDataSyncPublish(final JoinPoint joinPoint, DataSyncPublish dataSyncPublish, final Exception e, Object jsonResult) {
try {
System.out.println("dbname:"+dataSyncPublish.tableName());
System.out.println("operationType:"+dataSyncPublish.operatorType().ordinal());
String params = this.argsArrayToString(joinPoint.getArgs());
System.out.println("params:"+params);
// // *========数据库日志=========*//
// OperLogEvent operLog = new OperLogEvent();
// operLog.setTenantId(LoginHelper.getTenantId());
// operLog.setStatus(BusinessStatus.SUCCESS.ordinal());
// // 请求的地址
// String ip = ServletUtils.getClientIP();
// operLog.setOperIp(ip);
// operLog.setOperUrl(StringUtils.substring(ServletUtils.getRequest().getRequestURI(), 0, 255));
// LoginUser loginUser = LoginHelper.getLoginUser();
// operLog.setOperName(loginUser.getUsername());
// operLog.setDeptName(loginUser.getDeptName());
//
// if (e != null) {
// operLog.setStatus(BusinessStatus.FAIL.ordinal());
// operLog.setErrorMsg(StringUtils.substring(e.getMessage(), 0, 2000));
// }
// // 设置方法名称
// String className = joinPoint.getTarget().getClass().getName();
// String methodName = joinPoint.getSignature().getName();
// operLog.setMethod(className + "." + methodName + "()");
// // 设置请求方式
// operLog.setRequestMethod(ServletUtils.getRequest().getMethod());
// // 处理设置注解上的参数
// getControllerMethodDescription(joinPoint, controllerLog, operLog, jsonResult);
// // 设置消耗时间
// StopWatch stopWatch = KEY_CACHE.get();
// stopWatch.stop();
// operLog.setCostTime(stopWatch.getTime());
// // 发布事件保存数据库
// SpringUtils.context().publishEvent(operLog);
} catch (Exception exp) {
// 记录本地异常日志
log.error("异常信息:{}", exp.getMessage());
exp.printStackTrace();
} finally {
KEY_CACHE.remove();
}
}
/**
* Controller
*
* @param log
* @param operLog
* @throws Exception
*/
// public void getControllerMethodDescription(JoinPoint joinPoint, DataSyncPublish dataSyncPublish, Object jsonResult) throws Exception {
// // 设置action动作
// operLog.setBusinessType(log.businessType().ordinal());
// // 设置标题
// operLog.setTitle(log.title());
// // 设置操作人类别
// operLog.setOperatorType(log.operatorType().ordinal());
// // 是否需要保存request参数和值
// if (log.isSaveRequestData()) {
// // 获取参数的信息,传入到数据库中。
// setRequestValue(joinPoint, operLog, log.excludeParamNames());
// }
// // 是否需要保存response参数和值
// if (log.isSaveResponseData() && ObjectUtil.isNotNull(jsonResult)) {
// operLog.setJsonResult(StringUtils.substring(JsonUtils.toJsonString(jsonResult), 0, 2000));
// }
// }
/**
* log
*
* @param operLog
* @throws Exception
*/
// private void setRequestValue(JoinPoint joinPoint, OperLogEvent operLog, String[] excludeParamNames) throws Exception {
// Map<String, String> paramsMap = ServletUtils.getParamMap(ServletUtils.getRequest());
// String requestMethod = operLog.getRequestMethod();
// if (MapUtil.isEmpty(paramsMap) && StringUtils.equalsAny(requestMethod, HttpMethod.PUT.name(), HttpMethod.POST.name(), HttpMethod.DELETE.name())) {
// String params = argsArrayToString(joinPoint.getArgs(), excludeParamNames);
// operLog.setOperParam(StringUtils.substring(params, 0, 2000));
// } else {
// MapUtil.removeAny(paramsMap, EXCLUDE_PROPERTIES);
// MapUtil.removeAny(paramsMap, excludeParamNames);
// operLog.setOperParam(StringUtils.substring(JsonUtils.toJsonString(paramsMap), 0, 2000));
// }
// }
/**
*
*/
private String argsArrayToString(Object[] paramsArray) {
StringJoiner params = new StringJoiner(" ");
if (ArrayUtil.isEmpty(paramsArray)) {
return params.toString();
}
for (Object o : paramsArray) {
if (ObjectUtil.isNotNull(o) && !isFilterObject(o)) {
String str = JsonUtils.toJsonString(o);
Dict dict = JsonUtils.parseMap(str);
if (MapUtil.isNotEmpty(dict)) {
MapUtil.removeAny(dict, EXCLUDE_PROPERTIES);
str = JsonUtils.toJsonString(dict);
}
params.add(str);
}
}
return params.toString();
}
/**
*
*
* @param o
* @return truefalse
*/
@SuppressWarnings("rawtypes")
public boolean isFilterObject(final Object o) {
Class<?> clazz = o.getClass();
if (clazz.isArray()) {
return MultipartFile.class.isAssignableFrom(clazz.getComponentType());
} else if (Collection.class.isAssignableFrom(clazz)) {
Collection collection = (Collection) o;
for (Object value : collection) {
return value instanceof MultipartFile;
}
} else if (Map.class.isAssignableFrom(clazz)) {
Map map = (Map) o;
for (Object value : map.values()) {
return value instanceof MultipartFile;
}
}
return o instanceof MultipartFile || o instanceof HttpServletRequest || o instanceof HttpServletResponse
|| o instanceof BindingResult;
}
}

@ -0,0 +1,23 @@
package org.dromara.common.enums;
/**
*
*
* @author xins
*/
public enum OperatorType {
/**
*
*/
INSERT,
/**
*
*/
UPDATE,
/**
*
*/
DELETE
}

@ -0,0 +1,34 @@
package org.dromara.common.event;
import lombok.Data;
import java.io.Serial;
import java.io.Serializable;
/**
*
*
* @author xins
*/
@Data
public class DataSyncPublishEvent implements Serializable {
@Serial
private static final long serialVersionUID = 1L;
/**
*
*/
private String tableName;
/**
*
*/
private String operationType;
/**
* createtimeupdatetime
*/
private String filterTime;
}

@ -0,0 +1,29 @@
package org.dromara.common.event;
import cn.hutool.core.bean.BeanUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboReference;
import org.dromara.system.api.RemoteLogService;
import org.dromara.system.api.domain.bo.RemoteOperLogBo;
import org.springframework.context.event.EventListener;
import org.springframework.stereotype.Component;
@Component
@Slf4j
public class DataSyncPublishListener {
@DubboReference
private RemoteLogService remoteLogService;
/**
*
*/
@EventListener
public void dataSyncPublish(DataSyncPublishEvent dataSyncPublishEvent) {
// tableName,类型时间删除的id
}
}

@ -45,6 +45,7 @@
<module>ruoyi-common-nacos</module> <module>ruoyi-common-nacos</module>
<module>ruoyi-common-bus</module> <module>ruoyi-common-bus</module>
<module>ruoyi-common-sse</module> <module>ruoyi-common-sse</module>
<module>hwmom-common-mom</module>
</modules> </modules>
<artifactId>ruoyi-common</artifactId> <artifactId>ruoyi-common</artifactId>

Loading…
Cancel
Save