Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/dev' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
ldhnet committed Oct 21, 2024
2 parents 8867eb5 + 85adda8 commit 2af0058
Show file tree
Hide file tree
Showing 35 changed files with 1,665 additions and 1 deletion.
6 changes: 6 additions & 0 deletions antflow-base/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,12 @@
<version>3.1.4</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjweaver</artifactId>
<version>1.9.22</version>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<plugins>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
package org.openoa.base.aspect;

import com.alibaba.fastjson.JSON;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.reflect.MethodSignature;
import org.openoa.base.constant.StringConstants;
import org.openoa.base.entity.MethodReplayEntity;
import org.openoa.base.interf.MethodReplay;
import org.openoa.base.mapper.MethodReplayMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import org.springframework.util.ClassUtils;

import java.lang.reflect.Method;
import java.nio.charset.StandardCharsets;
import java.util.zip.CRC32;

@Aspect
@Component
@Slf4j
public class ExceptionLoggingAspect {

@Autowired
private MethodReplayMapper methodReplayMapper;
@Value("${methodreplay.on:true}")
private boolean methodReplayOn;

@Around("@annotation(methodReplay)")
public Object aroundMethodExecution(ProceedingJoinPoint joinPoint, MethodReplay methodReplay) throws Throwable {
Object result;
try {
result = joinPoint.proceed();
} catch (Exception e) {

if(methodReplayOn){
// 如果抓取到异常就记录 类全路径 方法名 参数 异常信息 当前时间 全都存表

// 获取类全路径
String className = joinPoint.getTarget().getClass().getName();
if(ClassUtils.isCglibProxy(joinPoint.getTarget())){
className=ClassUtils.getUserClass(joinPoint.getTarget()).getName();
}
// 获取方法名
String methodName = joinPoint.getSignature().getName();
// 获取参数类型
MethodSignature signature = (MethodSignature) joinPoint.getSignature();
Method method = signature.getMethod();
Class<?>[] parameterTypes = method.getParameterTypes();
// 获取参数
Object[] args = joinPoint.getArgs();
// 打印类全路径、方法名和参数
log.info("MethodReplay接受到异常,Class name:{},Method name:{},parameterTypes:{}, Arguments:{}", className, methodName, JSON.toJSONString(parameterTypes), JSON.toJSONString(args));
// 入库
MethodReplayEntity methodReplayEntity = new MethodReplayEntity();
methodReplayEntity.setProjectName(StringConstants.PROJECT_NAME);
methodReplayEntity.setClassName(className);
methodReplayEntity.setMethodName(methodName);
methodReplayEntity.setParamType(JSON.toJSONString(parameterTypes));
methodReplayEntity.setArgs(JSON.toJSONString(args));
String message=e.getMessage();
if(message.length()>100){
message=message.substring(0,100);
}
methodReplayEntity.setErrorMsg(message);
methodReplayEntity.setAlreadyReplayTimes(0);
methodReplayEntity.setMaxReplayTimes(methodReplay.maxReplayTimes());
String sum=StringConstants.PROJECT_NAME + className + methodName + methodReplayEntity.getParamType() + methodReplayEntity.getArgs();
CRC32 crc32=new CRC32();
crc32.update(sum.getBytes(StandardCharsets.UTF_8));
methodReplayEntity.setId(crc32.getValue());
MethodReplayEntity exist = methodReplayMapper.selectById(methodReplayEntity);
if (exist == null) {
methodReplayMapper.insert(methodReplayEntity);
}
}
throw e;
}
return result;
}


}
10 changes: 10 additions & 0 deletions antflow-base/src/main/java/org/openoa/base/constant/MsgTopics.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package org.openoa.base.constant;

public interface MsgTopics {

/**
* 工作流状态变化发送消息topic
*/
String WORKFLOW_EVENT_PUSH="oa_workflow_event_push";

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package org.openoa.base.constant;

import org.activiti.engine.impl.pvm.runtime.StartingExecution;

/**
* @Classname StringConstant
* @Description TODO
Expand All @@ -24,4 +26,5 @@ public class StringConstants {
public static final String ADAPTOR_FACTORY_BEANNAME="jimuAdaptorFactory";

public static final String TASK_ASSIGNEE_NAME="assigneeName";
public static final String PROJECT_NAME="antFlow";
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package org.openoa.base.constant.enums;

import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.EnumUtils;
import org.openoa.base.interf.BusinessCallBackAdaptor;
import org.openoa.base.service.BusinessCallBackFace;

import java.lang.reflect.Method;
import java.util.*;

/**
* @Author tylerzhou
*/
@Slf4j
public enum BusinessCallbackEnum {
PROCESS_EVENT_CALLBACK(1, ProcessBusinessCallBackTypeEnum.class, "流程类回调枚举"),
;
@Getter
private final Integer code;
@Getter
private final Class<? extends BusinessCallBackFace> clsz;
@Getter
private final String desc;

BusinessCallbackEnum(Integer code, Class<? extends BusinessCallBackFace> clsz, String desc) {
this.code = code;
this.clsz = clsz;
this.desc = desc;
}
public static Map<BusinessCallbackEnum, List<BusinessCallBackAdaptor>>getAllAdaptorsByType(){

Map<BusinessCallbackEnum,List<BusinessCallBackAdaptor>> allAdaptorsOfType=new HashMap<>();
for (BusinessCallbackEnum businessCallbackEnum : BusinessCallbackEnum.values()) {
Class<? extends BusinessCallBackFace> clsz = businessCallbackEnum.getClsz();

BusinessCallBackFace businessCallBackFace = null;
try {
businessCallBackFace= clsz.getEnumConstants()[0];
Set<Class<BusinessCallBackAdaptor>> allAdaptors = businessCallBackFace.getAllAdaptors();
List<BusinessCallBackAdaptor>businessCallBackAdaptors=new ArrayList<>();
for (Class<BusinessCallBackAdaptor> adaptor : allAdaptors) {
BusinessCallBackAdaptor businessCallBackAdaptor = adaptor.newInstance();
businessCallBackAdaptors.add(businessCallBackAdaptor);
}
allAdaptorsOfType.put(businessCallbackEnum,businessCallBackAdaptors);
}catch (Exception ex){
log.error("error occur while creating instance by reflection");
}
}
return allAdaptorsOfType;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package org.openoa.base.constant.enums;


import lombok.Getter;
import org.openoa.base.interf.BusinessCallBackAdaptor;
import org.openoa.base.service.BusinessCallBackFace;
import org.openoa.base.service.ProcessEventSendMessageAdaptor;

import java.util.HashSet;
import java.util.Objects;
import java.util.Set;

/**
* @Author tylerzhou
*/
public enum ProcessBusinessCallBackTypeEnum implements BusinessCallBackFace {
Send_MQ_Message(1, ProcessEventSendMessageAdaptor.class,"发送事件消息到mq队列")
,;
@Getter
private Integer code;

private Class<? extends BusinessCallBackAdaptor> clsz;
@Getter
private String desc;

ProcessBusinessCallBackTypeEnum(Integer code, Class<? extends BusinessCallBackAdaptor>clsz, String desc){
this.code = code;
this.clsz = clsz;
this.desc = desc;
}

@Override
public Class<? extends BusinessCallBackAdaptor> getClsz() {
return this.clsz;
}

public static ProcessBusinessCallBackTypeEnum getEnumByCode(Integer code){
for (ProcessBusinessCallBackTypeEnum callBackTypeEnum : ProcessBusinessCallBackTypeEnum.values()) {
if(Objects.equals(callBackTypeEnum.getCode(), code)){
return callBackTypeEnum;
}
}
return null;
}
@Override
public BusinessCallBackAdaptor getAdaptorByCode(Integer code) {
return null;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package org.openoa.base.entity;

import lombok.Data;

@Data
public class MethodReplayEntity {

private Long id;
private String projectName;
private String className;
private String methodName;
private String paramType;
private String args;
private String nowTime;
private String errorMsg;
private Integer alreadyReplayTimes;
private Integer maxReplayTimes;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package org.openoa.base.interf;

import org.openoa.base.entity.BpmBusinessProcess;

public interface BpmBusinessProcessService {
BpmBusinessProcess getBpmBusinessProcess(String processCode);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package org.openoa.base.interf;

public interface BusinessCallBackAdaptor<R,P> {
void doCallBack(P param);
R formattedValue(P value);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package org.openoa.base.interf;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
public @interface MethodReplay {

// 最大重放次数
int maxReplayTimes() default 3;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package org.openoa.base.mapper;

import org.apache.ibatis.annotations.Mapper;
import org.openoa.base.entity.MethodReplayEntity;
import org.openoa.base.vo.MethodReplayDTO;

import java.util.List;

/**
* @author duggle.du
*/
@Mapper
public interface MethodReplayMapper {

int insert(MethodReplayEntity methodReplayEntity);

List<MethodReplayEntity> select(MethodReplayDTO methodReplayDTO);

int addAlreadyReplayTimes(MethodReplayEntity methodReplayEntity);

int delete(MethodReplayEntity methodReplayEntity);

MethodReplayEntity selectById(MethodReplayEntity methodReplayEntity);

void deleteByIds(MethodReplayDTO methodReplayDTO);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package org.openoa.base.service;

import com.alibaba.fastjson.JSON;
import org.apache.commons.lang3.NotImplementedException;
import org.openoa.base.interf.BusinessCallBackAdaptor;
import org.openoa.base.util.SpringBeanUtils;

/**
* @Author tylerzhou
* Date on 2021/8/20
*/
public abstract class BaseSendMqMsgAdaptor<R, P> implements BusinessCallBackAdaptor<R, P> {

@Override
public void doCallBack(P param) {
R r = formattedValue(param);
if (r==null) {
return;
}
sendMqMessage(r);
}

private void sendMqMessage(R value) {
if (value==null) {
return;
}
String message = JSON.toJSONString(value);
//todo
throw new NotImplementedException("send mq message method not implemented yet at the moment");
}

protected abstract String getTopicName();

protected String getUserName() {
//todo
throw new NotImplementedException("not implemented yet");
}
}
Loading

0 comments on commit 2af0058

Please sign in to comment.