|
@@ -6,14 +6,27 @@ import org.aspectj.lang.ProceedingJoinPoint;
|
|
import org.aspectj.lang.annotation.Around;
|
|
import org.aspectj.lang.annotation.Around;
|
|
import org.aspectj.lang.annotation.Aspect;
|
|
import org.aspectj.lang.annotation.Aspect;
|
|
import org.aspectj.lang.annotation.Pointcut;
|
|
import org.aspectj.lang.annotation.Pointcut;
|
|
|
|
+import org.aspectj.lang.reflect.MethodSignature;
|
|
|
|
+import org.springblade.business.vo.AddContractTreeNodeVO;
|
|
|
|
+import org.springblade.business.vo.ArgType;
|
|
|
|
+import org.springblade.business.vo.CopyContractTreeNodeVO;
|
|
|
|
+import org.springblade.common.utils.BaseUtils;
|
|
import org.springblade.core.tool.utils.BeanUtil;
|
|
import org.springblade.core.tool.utils.BeanUtil;
|
|
import org.springblade.core.tool.utils.Func;
|
|
import org.springblade.core.tool.utils.Func;
|
|
import org.springframework.data.redis.core.StringRedisTemplate;
|
|
import org.springframework.data.redis.core.StringRedisTemplate;
|
|
|
|
+import org.springframework.expression.EvaluationContext;
|
|
|
|
+import org.springframework.expression.Expression;
|
|
|
|
+import org.springframework.expression.ExpressionParser;
|
|
|
|
+import org.springframework.expression.spel.standard.SpelExpressionParser;
|
|
|
|
+import org.springframework.expression.spel.support.StandardEvaluationContext;
|
|
import org.springframework.jdbc.core.JdbcTemplate;
|
|
import org.springframework.jdbc.core.JdbcTemplate;
|
|
import org.springframework.stereotype.Component;
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
|
|
+import java.lang.reflect.Method;
|
|
|
|
+import java.lang.reflect.Parameter;
|
|
import java.util.List;
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
import java.util.Map;
|
|
|
|
+import java.util.Objects;
|
|
|
|
|
|
/**
|
|
/**
|
|
* @author yangyj
|
|
* @author yangyj
|
|
@@ -32,36 +45,59 @@ public class TreeCodeUpdateAspect {
|
|
|
|
|
|
@Around("p()")
|
|
@Around("p()")
|
|
public Object around(ProceedingJoinPoint joinPoint) throws Throwable {
|
|
public Object around(ProceedingJoinPoint joinPoint) throws Throwable {
|
|
- Object result = null;
|
|
|
|
- try {
|
|
|
|
- Object[] args = joinPoint.getArgs();
|
|
|
|
- Map<String,Object> paramsMap= BeanUtil.toMap(args[0]);
|
|
|
|
- String tcu= this.redisTemplate.opsForValue().get("tcu");
|
|
|
|
- if(paramsMap.containsKey("contractId")){
|
|
|
|
- if(Func.isNotBlank(tcu)){
|
|
|
|
- tcu=tcu+","+paramsMap.get("contractId");
|
|
|
|
- }
|
|
|
|
- }else if(paramsMap.containsKey("needCopyPrimaryKeyId")){
|
|
|
|
- List<Map<String,Object>> listMap= jdbcTemplate.queryForList("select contract_id contractId from m_wbs_tree_contract where p_key_id ="+paramsMap.get("needCopyPrimaryKeyId"));
|
|
|
|
- if(listMap.size()>0){
|
|
|
|
- if(Func.isNotBlank(tcu)){
|
|
|
|
- tcu=tcu+","+listMap.get(0).get("contractId");
|
|
|
|
- }else{
|
|
|
|
- tcu=listMap.get(0).get("contractId").toString();
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- if(tcu!=null) {
|
|
|
|
- this.redisTemplate.opsForValue().set("tcu", tcu);
|
|
|
|
- }
|
|
|
|
- result= joinPoint.proceed();
|
|
|
|
- }catch (Exception e){
|
|
|
|
- e.printStackTrace();
|
|
|
|
- }
|
|
|
|
- /*System.out.println("treeCode刷新标识:执行一次就+1,后台定时检查到超阈值则执行刷新");*/
|
|
|
|
- return result;
|
|
|
|
|
|
+ tcuCache(joinPoint);
|
|
|
|
+ /*System.out.println("treeCode刷新标识:每隔三十秒监控到标识则执行刷新");*/
|
|
|
|
+ return joinPoint.proceed();
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
+ private void tcuCache(ProceedingJoinPoint jp){
|
|
|
|
+ try{
|
|
|
|
+ String tcu= this.redisTemplate.opsForValue().get("tcu");
|
|
|
|
+ String contractId=getContractId(jp);
|
|
|
|
+ if(Func.isNotBlank(tcu)){
|
|
|
|
+ tcu=tcu+","+contractId;
|
|
|
|
+ }else{
|
|
|
|
+ tcu=contractId;
|
|
|
|
+ }
|
|
|
|
+ if(tcu!=null) {
|
|
|
|
+ this.redisTemplate.opsForValue().set("tcu", tcu);
|
|
|
|
+ }
|
|
|
|
+ }catch (Exception e){
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private String getContractId(ProceedingJoinPoint jp){
|
|
|
|
+ String value = null;
|
|
|
|
+ Object[] args = jp.getArgs();
|
|
|
|
+ MethodSignature signature = (MethodSignature) jp.getSignature();
|
|
|
|
+ Method method = signature.getMethod();
|
|
|
|
+ TreeCodeUpdate annotation = method.getAnnotation(TreeCodeUpdate.class);
|
|
|
|
+ if (args.length > 0) {
|
|
|
|
+ value = spEl(method,args,annotation.value());
|
|
|
|
+ if(value!=null) {
|
|
|
|
+ if (ArgType.PKD.equals(annotation.type())) {
|
|
|
|
+ List<Map<String, Object>> listMap = jdbcTemplate.queryForList("select contract_id contractId from m_wbs_tree_contract where p_key_id =" + value);
|
|
|
|
+ if (listMap.size() > 0) {
|
|
|
|
+ value= listMap.get(0).get("contractId").toString();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return value;
|
|
|
|
+ }
|
|
|
|
+ /**解析spEL表达式*/
|
|
|
|
+ private String spEl(Method method ,Object[] args,String el){
|
|
|
|
+ ExpressionParser parser = new SpelExpressionParser();
|
|
|
|
+ EvaluationContext context = new StandardEvaluationContext();
|
|
|
|
+ for (int i=0;i<method.getParameterCount();i++) {
|
|
|
|
+ Parameter parameter = method.getParameters()[i];
|
|
|
|
+ context.setVariable(parameter.getName(),args[i]);
|
|
|
|
+ }
|
|
|
|
+ return Func.toStr(parser.parseExpression(el).getValue(context));
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
|
|
}
|
|
}
|