石墨消解仪后端服务
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.

47 lines
1.8 KiB

  1. package com.iflytop.gd.debug.controller;
  2. import com.iflytop.gd.app.model.dto.CmdDTO;
  3. import com.iflytop.gd.app.service.exceptions.UnSupportCommandException;
  4. import com.iflytop.gd.common.result.Result;
  5. import com.iflytop.gd.app.service.cmd.CommandHandler;
  6. import com.iflytop.gd.app.service.cmd.CommandHandlerRegistry;
  7. import io.swagger.v3.oas.annotations.Operation;
  8. import io.swagger.v3.oas.annotations.tags.Tag;
  9. import lombok.RequiredArgsConstructor;
  10. import lombok.extern.slf4j.Slf4j;
  11. import org.springframework.web.bind.annotation.PostMapping;
  12. import org.springframework.web.bind.annotation.RequestBody;
  13. import org.springframework.web.bind.annotation.RequestMapping;
  14. import org.springframework.web.bind.annotation.RestController;
  15. import java.util.concurrent.CompletableFuture;
  16. @Tag(name = "前端调试指令")
  17. @RestController
  18. @RequestMapping("/api/debug/cmd")
  19. @RequiredArgsConstructor
  20. @Slf4j
  21. public class CmdDebugController {
  22. private final CommandHandlerRegistry registry;
  23. @Operation(summary = "前端调试指令")
  24. @PostMapping
  25. public Result<?> controlMethod(@RequestBody CmdDTO cmdDTO) {
  26. String moduleName = cmdDTO.getModuleName();
  27. String commandName = cmdDTO.getCommandName();
  28. try {
  29. CommandHandler commandHandler = registry.getCommandHandler(moduleName, commandName);
  30. log.info("业务指令开始执行");
  31. commandHandler.handle(cmdDTO);
  32. } catch (UnSupportCommandException exception) {
  33. log.error("未找到对应的业务指令");
  34. return Result.failed(exception.getMessage());
  35. } catch (Exception e) {
  36. log.error("执行业务指令发生异常: {}", cmdDTO, e);
  37. return Result.failed(e.getMessage());
  38. }
  39. return Result.success();
  40. }
  41. }