医院废弃物信息化管理平台
“mitao”
2026-04-21 2f18b3a28054c3917010f95ba84f7425280a2622
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package cn.besteam.common.aspect;
 
import cn.besteam.common.aspect.annotation.LockApi;
import com.baomidou.lock.LockExecutor;
import com.baomidou.lock.LockInfo;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.aspectj.lang.reflect.MethodSignature;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
 
import java.lang.reflect.Method;
 
/**
 * 系统日志,切面处理类
 *
 * @author chenqilong
 * @since 2019/4/19
 */
@Aspect
@Component
public class LockApiAspect {
 
    @Autowired
    private LockExecutor lockExecutor;
 
    private LockKeyGenerator lockKeyGenerator = new LockKeyGenerator();
 
    @Pointcut("@annotation(cn.besteam.common.aspect.annotation.LockApi)")
    public void lockPointCut() {
 
    }
 
    @Around("lockPointCut()")
    public Object around(ProceedingJoinPoint point) throws Throwable {
 
        LockInfo lockInfo = null;
        try {
            MethodSignature signature = (MethodSignature) point.getSignature();
            Method method = signature.getMethod();
            LockApi lockApi = method.getAnnotation(LockApi.class);
            String keyName = lockKeyGenerator.getKeyName(point, lockApi);
            lockInfo = lockExecutor.tryLock(keyName, lockApi.expire(), lockApi.tryTimeout());
            if (null != lockInfo) {
                return point.proceed();
            }
            return null;
        } finally {
            if (null != lockInfo) {
                lockExecutor.releaseLock(lockInfo);
            }
        }
    }
 
}