|
|
|
@@ -0,0 +1,63 @@ |
|
|
|
package com.ruoyi.platform.annotations.aspect; |
|
|
|
|
|
|
|
import com.ruoyi.common.core.web.domain.AjaxResult; |
|
|
|
import com.ruoyi.common.redis.service.RedisService; |
|
|
|
import org.aspectj.lang.ProceedingJoinPoint; |
|
|
|
import org.aspectj.lang.annotation.Around; |
|
|
|
import org.aspectj.lang.annotation.Aspect; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.stereotype.Component; |
|
|
|
|
|
|
|
import java.lang.reflect.Field; |
|
|
|
import java.lang.reflect.InvocationTargetException; |
|
|
|
import java.lang.reflect.Method; |
|
|
|
|
|
|
|
@Aspect |
|
|
|
@Component |
|
|
|
public class ModelApprovalAspect { |
|
|
|
// |
|
|
|
// // 注入审批服务(假设已存在) |
|
|
|
// private final ApprovalService approvalService; |
|
|
|
// |
|
|
|
// public ModelApprovalAspect(ApprovalService approvalService) { |
|
|
|
// this.approvalService = approvalService; |
|
|
|
// } |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private RedisService redisService; |
|
|
|
|
|
|
|
@Around("@annotation(com.ruoyi.platform.annotations.NeedApproval)") |
|
|
|
public Object checkApproval(ProceedingJoinPoint joinPoint) throws Throwable { |
|
|
|
// 获取方法参数,第一个参数是模型对象 |
|
|
|
Object[] args = joinPoint.getArgs(); |
|
|
|
if (args.length == 0) { |
|
|
|
return joinPoint.proceed(); |
|
|
|
} |
|
|
|
|
|
|
|
Object model = args[0]; |
|
|
|
|
|
|
|
try { |
|
|
|
Method getIsPublic = model.getClass().getMethod("getIsPublic"); |
|
|
|
Method getName = model.getClass().getMethod("getName"); |
|
|
|
Method getId = model.getClass().getMethod("getId"); |
|
|
|
boolean isPublic = (boolean) getIsPublic.invoke(model); |
|
|
|
String name = (String) getIsPublic.invoke(getName); |
|
|
|
int id = (int) getIsPublic.invoke(getId); |
|
|
|
|
|
|
|
if (isPublic) { |
|
|
|
Class<?> modelClass = model.getClass(); |
|
|
|
Field isApproved = modelClass.getDeclaredField("isApproved"); |
|
|
|
isApproved.setAccessible(false); |
|
|
|
redisService.setCacheObject("ModelApproval_"+name+"_"+id, model); |
|
|
|
// 公共模型,提交审批并阻止原方法执行 |
|
|
|
// approvalService.submitForApproval(model); |
|
|
|
return AjaxResult.success("模型已提交审批"); |
|
|
|
} else { |
|
|
|
// 个人模型,直接放行 |
|
|
|
return joinPoint.proceed(); |
|
|
|
} |
|
|
|
} catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) { |
|
|
|
return joinPoint.proceed(); |
|
|
|
} |
|
|
|
} |
|
|
|
} |