10 changed files with 220 additions and 7 deletions
-
30src/main/java/com/iflytop/colortitration/app/command/debug/BeepCloseCommand.java
-
44src/main/java/com/iflytop/colortitration/app/command/debug/BeepOpenCommand.java
-
30src/main/java/com/iflytop/colortitration/app/command/debug/LightCloseCommand.java
-
45src/main/java/com/iflytop/colortitration/app/command/debug/LightOpenCommand.java
-
24src/main/java/com/iflytop/colortitration/app/core/command/DeviceCommandGenerator.java
-
13src/main/java/com/iflytop/colortitration/common/base/IBaseEnum.java
-
2src/main/java/com/iflytop/colortitration/common/command/DeviceCommandParams.java
-
19src/main/java/com/iflytop/colortitration/common/enums/BeepMode.java
-
4src/main/java/com/iflytop/colortitration/common/enums/Device.java
-
16src/main/java/com/iflytop/colortitration/common/enums/TricolorLightColor.java
@ -0,0 +1,30 @@ |
|||
package com.iflytop.colortitration.app.command.debug; |
|||
|
|||
import com.iflytop.colortitration.app.core.command.BaseCommandHandler; |
|||
import com.iflytop.colortitration.app.core.command.DeviceCommand; |
|||
import com.iflytop.colortitration.app.core.command.DeviceCommandGenerator; |
|||
import com.iflytop.colortitration.app.model.dto.CommandDTO; |
|||
import com.iflytop.colortitration.app.service.DeviceCommandService; |
|||
import lombok.RequiredArgsConstructor; |
|||
import lombok.extern.slf4j.Slf4j; |
|||
import org.springframework.stereotype.Component; |
|||
|
|||
import java.util.concurrent.CompletableFuture; |
|||
|
|||
/** |
|||
* 蜂鸣器关闭 |
|||
*/ |
|||
@Slf4j |
|||
@Component |
|||
@RequiredArgsConstructor |
|||
public class BeepCloseCommand extends BaseCommandHandler { |
|||
private final DeviceCommandService deviceCommandService; |
|||
@Override |
|||
public CompletableFuture<Void> handle(CommandDTO commandDTO) { |
|||
return runAsync(() -> { |
|||
DeviceCommand deviceCommand = DeviceCommandGenerator.beepClose(); |
|||
deviceCommandService.sendCommand(commandDTO.getCommandId(), commandDTO.getCommand(), deviceCommand); |
|||
}); |
|||
} |
|||
} |
|||
|
@ -0,0 +1,44 @@ |
|||
package com.iflytop.colortitration.app.command.debug; |
|||
|
|||
import com.iflytop.colortitration.app.core.command.BaseCommandHandler; |
|||
import com.iflytop.colortitration.app.core.command.DeviceCommand; |
|||
import com.iflytop.colortitration.app.core.command.DeviceCommandGenerator; |
|||
import com.iflytop.colortitration.app.model.dto.CommandDTO; |
|||
import com.iflytop.colortitration.app.service.DeviceCommandService; |
|||
import com.iflytop.colortitration.common.base.IBaseEnum; |
|||
import com.iflytop.colortitration.common.enums.BeepMode; |
|||
import com.iflytop.colortitration.common.exception.AppException; |
|||
import com.iflytop.colortitration.common.result.ResultCode; |
|||
import lombok.RequiredArgsConstructor; |
|||
import lombok.extern.slf4j.Slf4j; |
|||
import org.apache.commons.lang3.StringUtils; |
|||
import org.springframework.stereotype.Component; |
|||
|
|||
import java.util.concurrent.CompletableFuture; |
|||
|
|||
/** |
|||
* 蜂鸣器开启 |
|||
*/ |
|||
@Slf4j |
|||
@Component |
|||
@RequiredArgsConstructor |
|||
public class BeepOpenCommand extends BaseCommandHandler { |
|||
private final DeviceCommandService deviceCommandService; |
|||
|
|||
@Override |
|||
public CompletableFuture<Void> handle(CommandDTO commandDTO) { |
|||
String modeStr = commandDTO.getStringParam("mode"); |
|||
if (StringUtils.isEmpty(modeStr)) { |
|||
throw new AppException(ResultCode.INVALID_PARAMETER);//参数缺失 |
|||
} |
|||
if (!IBaseEnum.contains(BeepMode.class, modeStr)) { |
|||
throw new AppException(ResultCode.PARAMETER_TYPE_MISMATCH);//参数类型不匹配 |
|||
} |
|||
BeepMode mode = BeepMode.valueOf(modeStr); |
|||
return runAsync(() -> { |
|||
DeviceCommand deviceCommand = DeviceCommandGenerator.beepOpen(mode); |
|||
deviceCommandService.sendCommand(commandDTO.getCommandId(), commandDTO.getCommand(), deviceCommand); |
|||
}); |
|||
} |
|||
} |
|||
|
@ -0,0 +1,30 @@ |
|||
package com.iflytop.colortitration.app.command.debug; |
|||
|
|||
import com.iflytop.colortitration.app.core.command.BaseCommandHandler; |
|||
import com.iflytop.colortitration.app.core.command.DeviceCommand; |
|||
import com.iflytop.colortitration.app.core.command.DeviceCommandGenerator; |
|||
import com.iflytop.colortitration.app.model.dto.CommandDTO; |
|||
import com.iflytop.colortitration.app.service.DeviceCommandService; |
|||
import lombok.RequiredArgsConstructor; |
|||
import lombok.extern.slf4j.Slf4j; |
|||
import org.springframework.stereotype.Component; |
|||
|
|||
import java.util.concurrent.CompletableFuture; |
|||
|
|||
/** |
|||
* 指示灯关闭 |
|||
*/ |
|||
@Slf4j |
|||
@Component |
|||
@RequiredArgsConstructor |
|||
public class LightCloseCommand extends BaseCommandHandler { |
|||
private final DeviceCommandService deviceCommandService; |
|||
@Override |
|||
public CompletableFuture<Void> handle(CommandDTO commandDTO) { |
|||
return runAsync(() -> { |
|||
DeviceCommand deviceCommand = DeviceCommandGenerator.tricolorLightClose(); |
|||
deviceCommandService.sendCommand(commandDTO.getCommandId(), commandDTO.getCommand(), deviceCommand); |
|||
}); |
|||
} |
|||
} |
|||
|
@ -0,0 +1,45 @@ |
|||
package com.iflytop.colortitration.app.command.debug; |
|||
|
|||
import com.iflytop.colortitration.app.core.command.BaseCommandHandler; |
|||
import com.iflytop.colortitration.app.core.command.DeviceCommand; |
|||
import com.iflytop.colortitration.app.core.command.DeviceCommandGenerator; |
|||
import com.iflytop.colortitration.app.model.dto.CommandDTO; |
|||
import com.iflytop.colortitration.app.service.DeviceCommandService; |
|||
import com.iflytop.colortitration.common.base.IBaseEnum; |
|||
import com.iflytop.colortitration.common.enums.BeepMode; |
|||
import com.iflytop.colortitration.common.enums.TricolorLightColor; |
|||
import com.iflytop.colortitration.common.exception.AppException; |
|||
import com.iflytop.colortitration.common.result.ResultCode; |
|||
import lombok.RequiredArgsConstructor; |
|||
import lombok.extern.slf4j.Slf4j; |
|||
import org.apache.commons.lang3.StringUtils; |
|||
import org.springframework.stereotype.Component; |
|||
|
|||
import java.util.concurrent.CompletableFuture; |
|||
|
|||
/** |
|||
* 指示灯开启 |
|||
*/ |
|||
@Slf4j |
|||
@Component |
|||
@RequiredArgsConstructor |
|||
public class LightOpenCommand extends BaseCommandHandler { |
|||
private final DeviceCommandService deviceCommandService; |
|||
|
|||
@Override |
|||
public CompletableFuture<Void> handle(CommandDTO commandDTO) { |
|||
String colorStr = commandDTO.getStringParam("color"); |
|||
if (StringUtils.isEmpty(colorStr)) { |
|||
throw new AppException(ResultCode.INVALID_PARAMETER);//参数缺失 |
|||
} |
|||
if (!IBaseEnum.contains(TricolorLightColor.class, colorStr)) { |
|||
throw new AppException(ResultCode.PARAMETER_TYPE_MISMATCH);//参数类型不匹配 |
|||
} |
|||
TricolorLightColor color = TricolorLightColor.valueOf(colorStr); |
|||
return runAsync(() -> { |
|||
DeviceCommand deviceCommand = DeviceCommandGenerator.tricolorLightOpen(color); |
|||
deviceCommandService.sendCommand(commandDTO.getCommandId(), commandDTO.getCommand(), deviceCommand); |
|||
}); |
|||
} |
|||
} |
|||
|
@ -0,0 +1,19 @@ |
|||
package com.iflytop.colortitration.common.enums; |
|||
|
|||
|
|||
import com.iflytop.colortitration.common.base.IBaseEnum; |
|||
|
|||
public enum BeepMode implements IBaseEnum { |
|||
alarm, // 报警音 |
|||
info; //提示音 |
|||
|
|||
@Override |
|||
public Object getValue() { |
|||
return null; |
|||
} |
|||
|
|||
@Override |
|||
public String getLabel() { |
|||
return ""; |
|||
} |
|||
} |
@ -1,5 +1,17 @@ |
|||
package com.iflytop.colortitration.common.enums; |
|||
|
|||
public enum TricolorLightColor { |
|||
RED, GREEN, BLUE |
|||
import com.iflytop.colortitration.common.base.IBaseEnum; |
|||
|
|||
public enum TricolorLightColor implements IBaseEnum { |
|||
RED, GREEN, BLUE; |
|||
|
|||
@Override |
|||
public Object getValue() { |
|||
return null; |
|||
} |
|||
|
|||
@Override |
|||
public String getLabel() { |
|||
return ""; |
|||
} |
|||
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue