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

36 lines
1.3 KiB

3 months ago
3 months ago
3 months ago
  1. package com.iflytop.gd.app.controller;
  2. import com.iflytop.gd.app.core.CommandHandlerRegistry;
  3. import com.iflytop.gd.app.model.dto.CmdDTO;
  4. import com.iflytop.gd.common.cmd.CommandHandler;
  5. import com.iflytop.gd.common.result.Result;
  6. import io.swagger.v3.oas.annotations.Operation;
  7. import io.swagger.v3.oas.annotations.tags.Tag;
  8. import jakarta.validation.Valid;
  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. @Tag(name = "前端业务指令")
  16. @RestController
  17. @RequestMapping("/api/cmd")
  18. @RequiredArgsConstructor
  19. @Slf4j
  20. public class CmdController {
  21. private final CommandHandlerRegistry registry;
  22. @Operation(summary = "前端统一调用一个接口")
  23. @PostMapping
  24. public Result<?> controlMethod(@Valid @RequestBody CmdDTO cmdDTO) throws Exception {
  25. String commandName = cmdDTO.getCommand();
  26. CommandHandler commandHandler = registry.getCommandHandler(commandName);
  27. log.info("业务指令开始执行");
  28. commandHandler.handle(cmdDTO);
  29. return Result.success();
  30. }
  31. }