Initial commit: reorganized source tree

- backend/: 13 Maven modules (cw-elevator-application, cloudwalk-cloud, intelligent-cwoscomponent, ninca-crk, etc.)
- frontend/: 4 Vue projects (elevator-front, cwos-portal, alarm-front, front_acs) + decompiled + scripts
- scripts/: build, test-env, tools (Docker Compose, service templates, API parity)
- docs/: AGENTS.md, superpowers specs, architecture docs
- .gitignore: standard Java/Maven exclusions

Moved from legacy maven-*/ root layout to backend/ organized structure.
This commit is contained in:
hpd840321
2026-05-09 09:00:12 +08:00
commit 7b2bd307f1
7260 changed files with 612980 additions and 0 deletions
@@ -0,0 +1,65 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.18.RELEASE</version>
<relativePath/>
</parent>
<groupId>cn.cloudwalk.intelligent</groupId>
<artifactId>cloudwalk-intelligent-component-lock</artifactId>
<version>1.1.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>cloudwalk-intelligent-component-lock</name>
<description>源码来自 反1 zip。Redisson 2.x 与 Spring Boot 2.1 由显式版本约束。</description>
<properties>
<java.version>1.8</java.version>
<redisson.version>2.15.2</redisson.version>
<guava.version>28.2-jre</guava.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-autoconfigure</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-aop</artifactId>
</dependency>
<dependency>
<groupId>org.redisson</groupId>
<artifactId>redisson</artifactId>
<version>${redisson.version}</version>
</dependency>
<dependency>
<groupId>org.redisson</groupId>
<artifactId>redisson-spring-boot-starter</artifactId>
<version>${redisson.version}</version>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>${guava.version}</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
</project>
@@ -0,0 +1,18 @@
package cn.cloudwalk.intelligent.lock;
import cn.cloudwalk.intelligent.lock.locks.LockFactory;
import cn.cloudwalk.intelligent.lock.properties.LockProperties;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration
@EnableConfigurationProperties({ LockProperties.class })
@ConditionalOnProperty(prefix = "intelligent.lock", name = { "enable" }, havingValue = "true")
public class IntelligentLockConfiguration {
@Bean
public LockFactory lockFactory() {
return new LockFactory();
}
}
@@ -0,0 +1,26 @@
package cn.cloudwalk.intelligent.lock.annotation;
import cn.cloudwalk.intelligent.lock.common.enums.LockType;
import cn.cloudwalk.intelligent.lock.locks.handler.LockAcquireTimeoutStrategy;
import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
@Documented
@Retention(RetentionPolicy.RUNTIME)
@Target({ ElementType.METHOD })
public @interface RequiredLock {
String name() default "DEFAULT-LOCK";
LockType lockType() default LockType.REENTRANT;
long lockWaitTime() default -1L;
long leaseTime() default -1L;
LockAcquireTimeoutStrategy lockAcquireTimeoutStrategy() default LockAcquireTimeoutStrategy.FAIL_FAST;
String customAcquireTimeoutHandleMethod() default "";
}
@@ -0,0 +1,132 @@
package cn.cloudwalk.intelligent.lock.aop;
import cn.cloudwalk.intelligent.lock.annotation.RequiredLock;
import cn.cloudwalk.intelligent.lock.common.exception.AcquireLockTimeoutException;
import cn.cloudwalk.intelligent.lock.common.model.LockInfo;
import cn.cloudwalk.intelligent.lock.common.util.ExpressionParseUtil;
import cn.cloudwalk.intelligent.lock.locks.Lock;
import cn.cloudwalk.intelligent.lock.locks.LockFactory;
import cn.cloudwalk.intelligent.lock.properties.LockProperties;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.AfterThrowing;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;
@Aspect
@Component
@Order(-999)
public class LockAspect {
private static final Logger logger = LoggerFactory.getLogger(LockAspect.class);
@Autowired
private LockFactory lockFactory;
@Autowired
private LockProperties lockProperties;
private ThreadLocal<Lock> currentThreadLock = new ThreadLocal<>();
private ThreadLocal<LockResult> currentThreadLockResult = new ThreadLocal<>();
@Around("@annotation(requiredLock)")
public Object around(ProceedingJoinPoint joinPoint, RequiredLock requiredLock) throws Throwable {
LockInfo lockInfo = getLockInfo(joinPoint, requiredLock);
this.currentThreadLockResult.set(new LockResult(lockInfo, Boolean.valueOf(false)));
Lock lock = this.lockFactory.create(lockInfo);
boolean isAcquired = lock.acquire();
if (!isAcquired) {
if (logger.isWarnEnabled()) {
logger.warn("获取锁等待超时({})", lockInfo.getName());
}
if (StringUtils.isEmpty(requiredLock.customAcquireTimeoutHandleMethod())) {
requiredLock.lockAcquireTimeoutStrategy().handle(lockInfo, lock, (JoinPoint) joinPoint);
}
throw new AcquireLockTimeoutException(String.format("获取锁(%s)超时(%dms)",
new Object[] { lockInfo.getName(), Long.valueOf(lockInfo.getLockWaitTime()) }));
}
this.currentThreadLock.set(lock);
((LockResult) this.currentThreadLockResult.get()).setLocked(Boolean.valueOf(true));
return joinPoint.proceed();
}
@AfterReturning("@annotation(requiredLock)")
public void afterReturning(JoinPoint joinPoint, RequiredLock requiredLock) throws Throwable {
releaseLock();
flushThreadLocal();
}
@AfterThrowing(value = "@annotation(requiredLock)", throwing = "throwable")
public void afterThrowing(JoinPoint joinPoint, RequiredLock requiredLock, Throwable throwable) throws Throwable {
releaseLock();
flushThreadLocal();
throw throwable;
}
private void flushThreadLocal() {
this.currentThreadLock.remove();
this.currentThreadLockResult.remove();
}
private LockInfo getLockInfo(ProceedingJoinPoint joinPoint, RequiredLock lock) {
long lockWaitTime = (lock.lockWaitTime() < 0L) ? this.lockProperties.getDefaultWaitTime().longValue()
: lock.lockWaitTime();
long leaseTime = (lock.leaseTime() <= 0L) ? -1L : lock.leaseTime();
String lockName = parseLockName(joinPoint, lock.name());
return new LockInfo(lock.lockType(), lockName, lockWaitTime, leaseTime);
}
private String parseLockName(ProceedingJoinPoint joinPoint, String name) {
return (String) ExpressionParseUtil.parse(joinPoint, name, String.class);
}
private void releaseLock() throws Throwable {
LockResult lockResult = this.currentThreadLockResult.get();
if (lockResult.getLocked().booleanValue()) {
boolean releaseRes = ((Lock) this.currentThreadLock.get()).unlock();
lockResult.setLocked(Boolean.valueOf(false));
if (!releaseRes)
;
}
}
private class LockResult {
private LockInfo lockInfo;
private Boolean isLocked;
public LockResult(LockInfo lockInfo, Boolean isLocked) {
this.lockInfo = lockInfo;
this.isLocked = isLocked;
}
public LockInfo getLockInfo() {
return this.lockInfo;
}
public void setLockInfo(LockInfo lockInfo) {
this.lockInfo = lockInfo;
}
public Boolean getLocked() {
return this.isLocked;
}
public void setLocked(Boolean locked) {
this.isLocked = locked;
}
}
}
@@ -0,0 +1,7 @@
package cn.cloudwalk.intelligent.lock.common.enums;
public enum LockType {
REENTRANT,
REDLOCK;
}
@@ -0,0 +1,7 @@
package cn.cloudwalk.intelligent.lock.common.exception;
public class AcquireLockTimeoutException extends RuntimeException {
public AcquireLockTimeoutException(String message) {
super(message);
}
}
@@ -0,0 +1,11 @@
package cn.cloudwalk.intelligent.lock.common.exception;
public class LockOperationException extends RuntimeException {
public LockOperationException(String message) {
super(message);
}
public LockOperationException(String message, Throwable cause) {
super(message, cause);
}
}
@@ -0,0 +1,49 @@
package cn.cloudwalk.intelligent.lock.common.model;
import cn.cloudwalk.intelligent.lock.common.enums.LockType;
public class LockInfo {
private LockType type;
private String name;
private long lockWaitTime;
private long leaseTime;
public LockInfo(LockType type, String name, long lockWaitTime, long leaseTime) {
this.type = type;
this.name = name;
this.lockWaitTime = lockWaitTime;
this.leaseTime = leaseTime;
}
public LockType getType() {
return this.type;
}
public void setType(LockType type) {
this.type = type;
}
public String getName() {
return this.name;
}
public void setName(String name) {
this.name = name;
}
public long getLockWaitTime() {
return this.lockWaitTime;
}
public void setLockWaitTime(long lockWaitTime) {
this.lockWaitTime = lockWaitTime;
}
public long getLeaseTime() {
return this.leaseTime;
}
public void setLeaseTime(long leaseTime) {
this.leaseTime = leaseTime;
}
}
@@ -0,0 +1,32 @@
package cn.cloudwalk.intelligent.lock.common.util;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.reflect.MethodSignature;
import org.springframework.core.LocalVariableTableParameterNameDiscoverer;
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.util.StringUtils;
public class ExpressionParseUtil {
private static ExpressionParser parser = (ExpressionParser) new SpelExpressionParser();
public static <T> T parse(ProceedingJoinPoint joinPoint, String spel, Class<T> clazz) {
String[] parameterNames = (new LocalVariableTableParameterNameDiscoverer())
.getParameterNames(((MethodSignature) joinPoint.getSignature()).getMethod());
Object[] values = joinPoint.getArgs();
StandardEvaluationContext standardEvaluationContext = new StandardEvaluationContext();
for (int i = 0; i < parameterNames.length; i++) {
standardEvaluationContext.setVariable(parameterNames[i], values[i]);
}
if (StringUtils.isEmpty(spel)) {
return null;
}
Expression expression = parser.parseExpression(spel);
return (T) expression.getValue((EvaluationContext) standardEvaluationContext, clazz);
}
}
@@ -0,0 +1,7 @@
package cn.cloudwalk.intelligent.lock.locks;
public interface Lock {
boolean acquire();
boolean unlock();
}
@@ -0,0 +1,14 @@
package cn.cloudwalk.intelligent.lock.locks;
import cn.cloudwalk.intelligent.lock.common.model.LockInfo;
import org.redisson.api.RedissonClient;
import org.springframework.beans.factory.annotation.Autowired;
public class LockFactory {
@Autowired
private RedissonClient redissonClient;
public Lock create(LockInfo lockInfo) {
return new ReentrantLock(lockInfo, this.redissonClient);
}
}
@@ -0,0 +1,39 @@
package cn.cloudwalk.intelligent.lock.locks;
import cn.cloudwalk.intelligent.lock.common.exception.LockOperationException;
import cn.cloudwalk.intelligent.lock.common.model.LockInfo;
import java.util.concurrent.TimeUnit;
import org.redisson.api.RLock;
import org.redisson.api.RedissonClient;
public class ReentrantLock implements Lock {
private LockInfo lockInfo;
private RLock rLock;
private RedissonClient redissonClient;
public ReentrantLock(LockInfo lockInfo, RedissonClient redissonClient) {
this.lockInfo = lockInfo;
this.redissonClient = redissonClient;
}
public boolean acquire() {
try {
this.rLock = this.redissonClient.getLock(this.lockInfo.getName());
return this.rLock.tryLock(this.lockInfo.getLockWaitTime(), this.lockInfo.getLeaseTime(),
TimeUnit.MILLISECONDS);
} catch (Exception e) {
throw new LockOperationException("获取锁操作异常", e);
}
}
public boolean unlock() {
if (this.rLock.isHeldByCurrentThread()) {
try {
return ((Boolean) this.rLock.forceUnlockAsync().get()).booleanValue();
} catch (Exception e) {
throw new LockOperationException("释放锁操作异常", e);
}
}
return false;
}
}
@@ -0,0 +1,9 @@
package cn.cloudwalk.intelligent.lock.locks.handler;
import cn.cloudwalk.intelligent.lock.common.model.LockInfo;
import cn.cloudwalk.intelligent.lock.locks.Lock;
import org.aspectj.lang.JoinPoint;
public interface LockAcquireTimeoutHandler {
void handle(LockInfo paramLockInfo, Lock paramLock, JoinPoint paramJoinPoint);
}
@@ -0,0 +1,46 @@
package cn.cloudwalk.intelligent.lock.locks.handler;
import cn.cloudwalk.intelligent.lock.common.exception.AcquireLockTimeoutException;
import cn.cloudwalk.intelligent.lock.common.model.LockInfo;
import cn.cloudwalk.intelligent.lock.locks.Lock;
import java.util.concurrent.TimeUnit;
import org.aspectj.lang.JoinPoint;
public enum LockAcquireTimeoutStrategy implements LockAcquireTimeoutHandler {
NO_OPERATION {
public void handle(LockInfo lockInfo, Lock lock, JoinPoint joinPoint) {
}
},
FAIL_FAST {
public void handle(LockInfo lockInfo, Lock lock, JoinPoint joinPoint) {
throw new AcquireLockTimeoutException(String.format("获取锁(%s)超时(%dms)",
new Object[] { lockInfo.getName(), Long.valueOf(lockInfo.getLockWaitTime())
}));
}
},
KEEP_ACQUIRE {
private static final long DEFAULT_INTERVAL = 100L;
private static final long DEFAULT_MAX_INTERVAL = 180000L;
public void handle(LockInfo lockInfo, Lock lock, JoinPoint joinPoint) {
long interval = 100L;
while (!lock.acquire()) {
if (interval > 180000L) {
throw new AcquireLockTimeoutException(
String.format("获取锁(%s)阻塞时间过长", new Object[] { lockInfo.getName() }));
}
try {
TimeUnit.MILLISECONDS.sleep(interval);
interval <<= 1L;
} catch (InterruptedException e) {
throw new AcquireLockTimeoutException(String.format("获取锁(%s)失)", new Object[0]));
}
}
}
};
}
@@ -0,0 +1,17 @@
package cn.cloudwalk.intelligent.lock.properties;
import org.springframework.boot.context.properties.ConfigurationProperties;
@ConfigurationProperties(prefix = "intelligent.lock.config")
public class LockProperties {
public static final String PREFIX = "intelligent.lock.config";
private Long defaultWaitTime = Long.valueOf(15000L);
public void setDefaultWaitTime(Long defaultWaitTime) {
this.defaultWaitTime = defaultWaitTime;
}
public Long getDefaultWaitTime() {
return this.defaultWaitTime;
}
}