石墨消解仪后端服务
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

55 lines
2.0 KiB

package com.iflytop.gd.app.controller;
import com.iflytop.gd.app.model.dto.CmdDTO;
import com.iflytop.gd.common.result.Result;
import com.iflytop.gd.app.service.cmd.CommandHandler;
import com.iflytop.gd.app.service.cmd.CommandHandlerRegistry;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.concurrent.CompletableFuture;
@Tag(name = "前端调试指令")
@RestController
@RequestMapping("/api/debug/cmd")
@RequiredArgsConstructor
@Slf4j
public class CmdDebugController {
private final CommandHandlerRegistry registry;
@Operation(summary = "前端调试指令")
@PostMapping
public Result<?> controlMethod(@RequestBody CmdDTO cmdDTO) {
String cmdId = cmdDTO.getCmdId();
String cmdCode = cmdDTO.getCmdCode();
try {
CommandHandler commandHandler = registry.getHandler(cmdCode);
if (commandHandler == null) {
log.error("未找到对应的业务指令");
return Result.failed();
}
log.info("业务指令开始执行");
CompletableFuture<Void> future = commandHandler.handle(cmdDTO);
future.whenComplete((v, ex) -> {
if (ex != null) {
log.error("执行业务指令发生异常: {}", cmdDTO, ex);
} else {
log.info("业务指令执行成功");
}
log.info("业务指令执行结束");
});
} catch (Exception e) {
log.error("执行业务指令发生异常: {}", cmdDTO, e);
return Result.failed(e.getMessage());
}
return Result.success();
}
}