Merge branch 'refs/heads/feature/REQ-2090' into 1.3.1-SNAPSHOT
This commit is contained in:
commit
35beb6fbfc
@ -11,23 +11,25 @@ import org.springframework.context.ApplicationEvent;
|
||||
*/
|
||||
@Slf4j
|
||||
public class ApiLogEvent extends ApplicationEvent {
|
||||
private String uniqueId;
|
||||
private String traceId;
|
||||
private String apiUrl;
|
||||
private Object requestBody;
|
||||
|
||||
private Object responseBody;
|
||||
private Double takeTime;
|
||||
private String type;
|
||||
|
||||
public ApiLogEvent(String uniqueId, String apiUrl, Object requestBody, Object responseBody, Double takeTime) {
|
||||
super(uniqueId);
|
||||
public ApiLogEvent(String traceId, String apiUrl, Object requestBody, Object responseBody, Double takeTime, String type) {
|
||||
super(traceId);
|
||||
this.traceId = traceId;
|
||||
this.apiUrl = apiUrl;
|
||||
this.requestBody = requestBody;
|
||||
this.responseBody = responseBody;
|
||||
this.takeTime = takeTime;
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public String getUniqueId() {
|
||||
return uniqueId;
|
||||
public String getTraceId() {
|
||||
return traceId;
|
||||
}
|
||||
|
||||
public String getApiUrl() {
|
||||
@ -45,4 +47,8 @@ public class ApiLogEvent extends ApplicationEvent {
|
||||
public Double getTakeTime() {
|
||||
return takeTime;
|
||||
}
|
||||
|
||||
public String getType() {
|
||||
return type;
|
||||
}
|
||||
}
|
||||
|
||||
@ -37,11 +37,12 @@ public class ApiLogListener implements ApplicationListener<ApiLogEvent> {
|
||||
return;
|
||||
}
|
||||
ExtAxApiLog apiLog = new ExtAxApiLog();
|
||||
apiLog.setUniqueId(event.getUniqueId());
|
||||
apiLog.setTraceId(event.getTraceId());
|
||||
apiLog.setApiUrl(event.getApiUrl());
|
||||
apiLog.setRequestBody(JSON.toJSONString(event.getRequestBody()));
|
||||
apiLog.setResponseBody(JSON.toJSONString(event.getResponseBody()));
|
||||
apiLog.setTakeTime(event.getTakeTime());
|
||||
apiLog.setType(event.getType());
|
||||
apiLogService.insert(apiLog);
|
||||
}
|
||||
}
|
||||
|
||||
@ -115,8 +115,7 @@ public class CustomCarbonCopyUserSelectorCmd implements Command<List<BpmnTaskDel
|
||||
break;
|
||||
case approver_relation:
|
||||
assigners.addAll(getApproverRelationUser(carbon, carbonCopyObjectType,
|
||||
(DelegateExecution) list.get(0),
|
||||
processEngineConfiguration, processInstanceId));
|
||||
(DelegateExecution) list.get(0), processEngineConfiguration, processInstanceId));
|
||||
break;
|
||||
case specify_user:
|
||||
assigners.addAll(JSON.parseArray(carbon.getSpecifyValue(), BpmnTaskDelegateAssigner.class));
|
||||
@ -173,8 +172,7 @@ public class CustomCarbonCopyUserSelectorCmd implements Command<List<BpmnTaskDel
|
||||
.parameter("processInstanceId", processInstanceId)
|
||||
.list().stream()
|
||||
.collect(Collectors.toMap(HistoricVariableInstance::getVariableName,
|
||||
Function.identity(),
|
||||
(s, t) -> s));
|
||||
Function.identity(), (s, t) -> s));
|
||||
vos.forEach(vo -> {
|
||||
HistoricVariableInstance assginerSnapshot =
|
||||
variableInstanceMap.getOrDefault(INTERNAL_TASK_RELATION_ASSIGNEE_INFO + vo.getTaskId(),
|
||||
|
||||
@ -19,9 +19,9 @@ import lombok.ToString;
|
||||
public class ExtAxApiLog extends BaseEntity<ExtAxDict> {
|
||||
|
||||
/**
|
||||
* 唯一标识
|
||||
* 日志跟踪 ID
|
||||
*/
|
||||
private String uniqueId;
|
||||
private String traceId;
|
||||
|
||||
/**
|
||||
* 请求 API
|
||||
@ -43,4 +43,8 @@ public class ExtAxApiLog extends BaseEntity<ExtAxDict> {
|
||||
*/
|
||||
private Double takeTime;
|
||||
|
||||
/**
|
||||
* 函数类型
|
||||
*/
|
||||
private String type;
|
||||
}
|
||||
|
||||
@ -753,57 +753,65 @@ public class BpmnProcessInstanceServiceImpl implements BpmnProcessInstanceServic
|
||||
node.setNodeMode(GENERAL);
|
||||
node.setId(i.getId()).setName(i.getName());
|
||||
if (i instanceof UserTask) {
|
||||
UserTask userTask = (UserTask) i;
|
||||
node.setFormKey(userTask.getFormKey());
|
||||
// 设置审批模式,
|
||||
if (userTask.getBehavior() instanceof MultiInstanceActivityBehavior) {
|
||||
MultiInstanceActivityBehavior behavior =
|
||||
(MultiInstanceActivityBehavior) userTask.getBehavior();
|
||||
node.setNodeMode(Objects.equals(AND_SIGN_EXPRESSION,
|
||||
behavior.getCompletionCondition()) ?
|
||||
AND : OR);
|
||||
} else {
|
||||
node.setNodeMode(BpmnFlowNodeMode.GENERAL);
|
||||
}
|
||||
|
||||
if (Objects.equals(node.getApprovalMethod(), human)) {
|
||||
// 推测当前节点的审批人,并且如果审批人为空,也会根据审批人为空的策略去找人
|
||||
List<BpmnTaskDelegateAssigner> forecastAssigners =
|
||||
springProcessEngineConfiguration.getCommandExecutor()
|
||||
.execute(new CustomForecastUserTaskAssigneeCmd(processInstanceId,
|
||||
userTask, engineExecutionStartListener));
|
||||
node.setForecastAssigners(forecastAssigners);
|
||||
if (CollectionUtils.isEmpty(forecastAssigners)) {
|
||||
getApproverEmptyHandleType(userTask).ifPresent(emptyHandleType -> {
|
||||
switch (emptyHandleType) {
|
||||
case autoPassed:
|
||||
node.setApprovalMethod(autoPassed);
|
||||
break;
|
||||
case autoRejection:
|
||||
node.setApprovalMethod(autoRejection);
|
||||
break;
|
||||
default:
|
||||
node.setNodeMode(EXCEPTIONAL);
|
||||
break;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
parseUserTask(processInstanceId, (UserTask) i, node);
|
||||
} else if (i instanceof ServiceTask) {
|
||||
// ServiceTask 主要作用于抄送
|
||||
ServiceTask serviceTask = (ServiceTask) i;
|
||||
node.setId(serviceTask.getId()).setName(serviceTask.getName());
|
||||
getCarbonCopyConfigs(serviceTask).ifPresent(carbons ->
|
||||
node.setForecastAssigners(springProcessEngineConfiguration.getCommandExecutor()
|
||||
.execute(new CustomCarbonCopyUserSelectorCmd(processInstanceId, carbons,
|
||||
serviceTask, engineExecutionStartListener,
|
||||
historicTaskInstanceConverter, serviceVersion))));
|
||||
parseServiceTask(processInstanceId, (ServiceTask) i, node);
|
||||
}
|
||||
resultList.add(node);
|
||||
});
|
||||
return resultList;
|
||||
}
|
||||
|
||||
private void parseServiceTask(String processInstanceId, ServiceTask i, ProcessNodeDetailVO node) {
|
||||
// ServiceTask 主要作用于抄送
|
||||
ServiceTask serviceTask = i;
|
||||
node.setId(serviceTask.getId()).setName(serviceTask.getName());
|
||||
getCarbonCopyConfigs(serviceTask).ifPresent(carbons ->
|
||||
node.setForecastAssigners(springProcessEngineConfiguration.getCommandExecutor()
|
||||
.execute(new CustomCarbonCopyUserSelectorCmd(processInstanceId, carbons,
|
||||
serviceTask, engineExecutionStartListener,
|
||||
historicTaskInstanceConverter, serviceVersion))));
|
||||
}
|
||||
|
||||
private void parseUserTask(String processInstanceId, UserTask i, ProcessNodeDetailVO node) {
|
||||
UserTask userTask = i;
|
||||
node.setFormKey(userTask.getFormKey());
|
||||
// 设置审批模式,
|
||||
if (userTask.getBehavior() instanceof MultiInstanceActivityBehavior) {
|
||||
MultiInstanceActivityBehavior behavior =
|
||||
(MultiInstanceActivityBehavior) userTask.getBehavior();
|
||||
node.setNodeMode(Objects.equals(AND_SIGN_EXPRESSION,
|
||||
behavior.getCompletionCondition()) ?
|
||||
AND : OR);
|
||||
} else {
|
||||
node.setNodeMode(BpmnFlowNodeMode.GENERAL);
|
||||
}
|
||||
|
||||
if (Objects.equals(node.getApprovalMethod(), human)) {
|
||||
// 推测当前节点的审批人,并且如果审批人为空,也会根据审批人为空的策略去找人
|
||||
List<BpmnTaskDelegateAssigner> forecastAssigners =
|
||||
springProcessEngineConfiguration.getCommandExecutor()
|
||||
.execute(new CustomForecastUserTaskAssigneeCmd(processInstanceId,
|
||||
userTask, engineExecutionStartListener));
|
||||
node.setForecastAssigners(forecastAssigners);
|
||||
if (CollectionUtils.isEmpty(forecastAssigners)) {
|
||||
getApproverEmptyHandleType(userTask).ifPresent(emptyHandleType -> {
|
||||
switch (emptyHandleType) {
|
||||
case autoPassed:
|
||||
node.setApprovalMethod(autoPassed);
|
||||
break;
|
||||
case autoRejection:
|
||||
node.setApprovalMethod(autoRejection);
|
||||
break;
|
||||
default:
|
||||
node.setNodeMode(EXCEPTIONAL);
|
||||
break;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getTenantIds() {
|
||||
NativeHistoricProcessInstanceQuery query = historyService.createNativeHistoricProcessInstanceQuery();
|
||||
|
||||
@ -2,11 +2,12 @@ DROP TABLE IF EXISTS `EXT_AX_API_LOG`;
|
||||
CREATE TABLE IF NOT EXISTS EXT_AX_API_LOG
|
||||
(
|
||||
`id` bigint NOT NULL AUTO_INCREMENT COMMENT '主键',
|
||||
`unique_id` varchar(100) NOT NULL DEFAULT '' COMMENT '唯一标识',
|
||||
`trace_id` varchar(100) NOT NULL DEFAULT '' COMMENT '唯一标识',
|
||||
`api_url` varchar(2000) NOT NULL DEFAULT '' COMMENT '请求 API',
|
||||
`request_body` text NOT NULL COMMENT '请求参数',
|
||||
`response_body` text NOT NULL COMMENT '响应参数',
|
||||
`take_time` decimal(5, 2) NOT NULL COMMENT '执行耗时',
|
||||
`type` varchar(10) NOT NULL DEFAULT '' COMMENT '函数类型',
|
||||
`create_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
|
||||
`update_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
|
||||
`is_delete` bigint NOT NULL DEFAULT '0' COMMENT '是否删除',
|
||||
|
||||
@ -1,19 +0,0 @@
|
||||
package cn.axzo.workflow.server.aspect;
|
||||
|
||||
import org.aspectj.lang.annotation.Aspect;
|
||||
import org.aspectj.lang.annotation.Pointcut;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* Controller 方法执行耗时
|
||||
*
|
||||
* @author wangli
|
||||
* @since 2024/1/18 18:02
|
||||
*/
|
||||
@Aspect
|
||||
@Component
|
||||
public class ControllerTimingAspect {
|
||||
|
||||
@Pointcut("within(@org.springframework.web.bind.annotation.RestController *)")
|
||||
public void controllerMethods() {}
|
||||
}
|
||||
@ -3,7 +3,6 @@ package cn.axzo.workflow.server.common.aspectj;
|
||||
import cn.axzo.workflow.core.common.event.ApiLogEvent;
|
||||
import cn.axzo.workflow.server.common.annotation.EnvConfig;
|
||||
import cn.axzo.workflow.server.common.annotation.ErrorReporter;
|
||||
import cn.hutool.core.util.IdUtil;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.aspectj.lang.JoinPoint;
|
||||
@ -12,14 +11,19 @@ import org.aspectj.lang.Signature;
|
||||
import org.aspectj.lang.annotation.AfterThrowing;
|
||||
import org.aspectj.lang.annotation.Around;
|
||||
import org.aspectj.lang.annotation.Aspect;
|
||||
import org.slf4j.MDC;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.context.ApplicationEventPublisher;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.StopWatch;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.Arrays;
|
||||
|
||||
import static cn.azxo.framework.common.constatns.Constants.CTX_LOG_ID_MDC;
|
||||
|
||||
/**
|
||||
* 异常错误信息报告器
|
||||
*
|
||||
@ -44,20 +48,60 @@ public class ErrorReportAspect {
|
||||
*
|
||||
* @param joinPoint 切点
|
||||
*/
|
||||
@Around("@within(org.springframework.web.bind.annotation.RestController)")
|
||||
public Object doAround(ProceedingJoinPoint joinPoint) throws Throwable {
|
||||
@Around("@within(org.springframework.web.bind.annotation.RestController) || @within(org.springframework.stereotype.Service)")
|
||||
public Object doControllerAround(ProceedingJoinPoint joinPoint) throws Throwable {
|
||||
getTargetAnnotation(joinPoint);
|
||||
|
||||
Signature signature = joinPoint.getSignature();
|
||||
StopWatch watch = new StopWatch("running task time");
|
||||
StopWatch watch = new StopWatch("running controller time");
|
||||
watch.start(signature.toShortString());
|
||||
Object result = joinPoint.proceed();
|
||||
watch.stop();
|
||||
log.info("StopWatch '" + watch.getLastTaskName() + "': running time = " + watch.getTotalTimeSeconds() + " s");
|
||||
|
||||
ApiLogEvent event = new ApiLogEvent(IdUtil.fastSimpleUUID(), signature.toShortString(), joinPoint.getArgs(), result, watch.getTotalTimeSeconds());
|
||||
ApiLogEvent event = new ApiLogEvent(MDC.get(CTX_LOG_ID_MDC),
|
||||
signature.toShortString(),
|
||||
joinPoint.getArgs(),
|
||||
result,
|
||||
watch.getTotalTimeSeconds(),
|
||||
getType(joinPoint));
|
||||
|
||||
applicationEventPublisher.publishEvent(event);
|
||||
return result;
|
||||
}
|
||||
|
||||
private String getType(ProceedingJoinPoint joinPoint) {
|
||||
if (isController(joinPoint)) {
|
||||
return "Controller";
|
||||
} else if (isService(joinPoint)) {
|
||||
return "Service";
|
||||
} else {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
private Boolean isController(ProceedingJoinPoint joinPoint) {
|
||||
return getTargetAnnotation(joinPoint).isAnnotationPresent(RestController.class);
|
||||
}
|
||||
|
||||
private Boolean isService(ProceedingJoinPoint joinPoint) {
|
||||
return getTargetAnnotation(joinPoint).isAnnotationPresent(Service.class);
|
||||
}
|
||||
|
||||
private Class getTargetAnnotation(ProceedingJoinPoint joinPoint) {
|
||||
return joinPoint.getTarget().getClass();
|
||||
}
|
||||
|
||||
@Around("@within(org.springframework.stereotype.Service)")
|
||||
public Object doServiceAround(ProceedingJoinPoint joinPoint) throws Throwable {
|
||||
Signature signature = joinPoint.getSignature();
|
||||
StopWatch watch = new StopWatch("running service time");
|
||||
watch.start(signature.toShortString());
|
||||
Object result = joinPoint.proceed();
|
||||
watch.stop();
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 拦截异常操作
|
||||
*
|
||||
|
||||
Loading…
Reference in New Issue
Block a user