35 changed files with 135 additions and 65 deletions
-
4src/main/java/com/iflytop/sgs/app/cmd/debug/DebugDoorCloseCommand.java
-
4src/main/java/com/iflytop/sgs/app/cmd/debug/DebugDoorOpenCommand.java
-
4src/main/java/com/iflytop/sgs/app/cmd/debug/DebugDoorStopCommand.java
-
4src/main/java/com/iflytop/sgs/app/cmd/debug/DebugFanStartCommand.java
-
4src/main/java/com/iflytop/sgs/app/cmd/debug/DebugFanStopCommand.java
-
4src/main/java/com/iflytop/sgs/app/cmd/debug/DebugHeaterStartCommand.java
-
4src/main/java/com/iflytop/sgs/app/cmd/debug/DebugHeaterStopCommand.java
-
4src/main/java/com/iflytop/sgs/app/cmd/debug/DebugLiquidMotorMoveByCommand.java
-
4src/main/java/com/iflytop/sgs/app/cmd/debug/DebugLiquidMotorMoveToCommand.java
-
4src/main/java/com/iflytop/sgs/app/cmd/debug/DebugLiquidMotorOriginCommand.java
-
4src/main/java/com/iflytop/sgs/app/cmd/debug/DebugLiquidMotorStopCommand.java
-
4src/main/java/com/iflytop/sgs/app/cmd/debug/DebugLiquidPumpAddCommand.java
-
4src/main/java/com/iflytop/sgs/app/cmd/debug/DebugLiquidPumpMoveByCommand.java
-
4src/main/java/com/iflytop/sgs/app/cmd/debug/DebugLiquidPumpReduceCommand.java
-
4src/main/java/com/iflytop/sgs/app/cmd/debug/DebugLiquidPumpStartCommand.java
-
4src/main/java/com/iflytop/sgs/app/cmd/debug/DebugLiquidPumpStopCommand.java
-
4src/main/java/com/iflytop/sgs/app/cmd/debug/DebugLiquidValveOpenThickCommand.java
-
4src/main/java/com/iflytop/sgs/app/cmd/debug/DebugLiquidValveOpenThinCommand.java
-
4src/main/java/com/iflytop/sgs/app/cmd/debug/DebugLiquidValveOpenVacantCommand.java
-
4src/main/java/com/iflytop/sgs/app/cmd/debug/DebugLiquidValveOpenWasteCommand.java
-
4src/main/java/com/iflytop/sgs/app/cmd/debug/DebugLiquidValveOpenWaterCommand.java
-
4src/main/java/com/iflytop/sgs/app/cmd/debug/DebugMotorXMoveByCommand.java
-
4src/main/java/com/iflytop/sgs/app/cmd/debug/DebugMotorXMoveToCommand.java
-
4src/main/java/com/iflytop/sgs/app/cmd/debug/DebugMotorXOriginCommand.java
-
4src/main/java/com/iflytop/sgs/app/cmd/debug/DebugMotorXStopCommand.java
-
4src/main/java/com/iflytop/sgs/app/cmd/debug/DebugMotorZMoveByCommand.java
-
4src/main/java/com/iflytop/sgs/app/cmd/debug/DebugMotorZMoveToCommand.java
-
4src/main/java/com/iflytop/sgs/app/cmd/debug/DebugMotorZOriginCommand.java
-
4src/main/java/com/iflytop/sgs/app/cmd/debug/DebugMotorZStopCommand.java
-
4src/main/java/com/iflytop/sgs/app/cmd/debug/step/DebugDisabledAllMotorCommand.java
-
4src/main/java/com/iflytop/sgs/app/cmd/debug/step/DebugEnableAllMotorCommand.java
-
4src/main/java/com/iflytop/sgs/app/cmd/debug/step/DebugStopAllMotorCommand.java
-
59src/main/java/com/iflytop/sgs/app/core/CommandDebugHandlerRegistry.java
-
1src/main/java/com/iflytop/sgs/app/service/api/SystemConfigService.java
-
12src/main/java/com/iflytop/sgs/common/annotation/CommandDebugMapping.java
@ -0,0 +1,59 @@ |
|||||
|
package com.iflytop.sgs.app.core; |
||||
|
|
||||
|
import com.iflytop.sgs.common.annotation.CommandDebugMapping; |
||||
|
import com.iflytop.sgs.common.annotation.CommandMapping; |
||||
|
import com.iflytop.sgs.common.cmd.CommandHandler; |
||||
|
import com.iflytop.sgs.common.exception.AppException; |
||||
|
import com.iflytop.sgs.common.exception.UnSupportCommandException; |
||||
|
import com.iflytop.sgs.common.result.ResultCode; |
||||
|
import io.micrometer.common.lang.NonNull; |
||||
|
import jakarta.annotation.PostConstruct; |
||||
|
import jakarta.validation.constraints.NotNull; |
||||
|
import org.springframework.aop.support.AopUtils; |
||||
|
import org.springframework.beans.BeansException; |
||||
|
import org.springframework.context.ApplicationContext; |
||||
|
import org.springframework.context.ApplicationContextAware; |
||||
|
import org.springframework.stereotype.Component; |
||||
|
|
||||
|
import java.util.HashMap; |
||||
|
import java.util.Map; |
||||
|
|
||||
|
@Component |
||||
|
public class CommandDebugHandlerRegistry implements ApplicationContextAware { |
||||
|
|
||||
|
private final Map<String, CommandHandler> handlerMap = new HashMap<>(); |
||||
|
private ApplicationContext applicationContext; |
||||
|
|
||||
|
@Override |
||||
|
public void setApplicationContext(@NonNull ApplicationContext applicationContext) throws BeansException { |
||||
|
this.applicationContext = applicationContext; |
||||
|
} |
||||
|
|
||||
|
@PostConstruct |
||||
|
public void init() { |
||||
|
Map<String, Object> beans = applicationContext.getBeansWithAnnotation(CommandDebugMapping.class); |
||||
|
for (Object bean : beans.values()) { |
||||
|
// 获取实际目标类,而不是代理类 |
||||
|
Class<?> targetClass = AopUtils.getTargetClass(bean); |
||||
|
CommandDebugMapping mapping = targetClass.getAnnotation(CommandDebugMapping.class); |
||||
|
if (mapping != null && bean instanceof CommandHandler) { |
||||
|
String mappingKey = mapping.value(); |
||||
|
handlerMap.put(mappingKey, (CommandHandler) bean); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 通过模块名称和命令名称获取命令处理器 |
||||
|
* |
||||
|
* @param commandName 命令名称 |
||||
|
* @return 命令处理器 |
||||
|
* @throws UnSupportCommandException |
||||
|
*/ |
||||
|
public CommandHandler getCommandHandler(@NotNull String commandName) throws UnSupportCommandException { |
||||
|
if (!handlerMap.containsKey(commandName)) { |
||||
|
throw new AppException(ResultCode.COMMAND_NOT_FOUND); |
||||
|
} |
||||
|
return handlerMap.get(commandName); |
||||
|
} |
||||
|
} |
@ -0,0 +1,12 @@ |
|||||
|
package com.iflytop.sgs.common.annotation; |
||||
|
|
||||
|
import java.lang.annotation.ElementType; |
||||
|
import java.lang.annotation.Retention; |
||||
|
import java.lang.annotation.RetentionPolicy; |
||||
|
import java.lang.annotation.Target; |
||||
|
|
||||
|
@Retention(RetentionPolicy.RUNTIME) |
||||
|
@Target(ElementType.TYPE) |
||||
|
public @interface CommandDebugMapping { |
||||
|
String value(); |
||||
|
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue