-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/dev' into dev
- Loading branch information
Showing
35 changed files
with
1,665 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
86 changes: 86 additions & 0 deletions
86
antflow-base/src/main/java/org/openoa/base/aspect/ExceptionLoggingAspect.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
10
antflow-base/src/main/java/org/openoa/base/constant/MsgTopics.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
antflow-base/src/main/java/org/openoa/base/constant/enums/BusinessCallbackEnum.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
49 changes: 49 additions & 0 deletions
49
...ow-base/src/main/java/org/openoa/base/constant/enums/ProcessBusinessCallBackTypeEnum.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
antflow-base/src/main/java/org/openoa/base/entity/MethodReplayEntity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
|
||
} |
7 changes: 7 additions & 0 deletions
7
antflow-base/src/main/java/org/openoa/base/interf/BpmBusinessProcessService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
6 changes: 6 additions & 0 deletions
6
antflow-base/src/main/java/org/openoa/base/interf/BusinessCallBackAdaptor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
15 changes: 15 additions & 0 deletions
15
antflow-base/src/main/java/org/openoa/base/interf/MethodReplay.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
|
||
} |
26 changes: 26 additions & 0 deletions
26
antflow-base/src/main/java/org/openoa/base/mapper/MethodReplayMapper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
38 changes: 38 additions & 0 deletions
38
antflow-base/src/main/java/org/openoa/base/service/BaseSendMqMsgAdaptor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); | ||
} | ||
} |
Oops, something went wrong.