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.

62 lines
2.0 KiB

  1. package com.qyft.ms.app.controller;
  2. import com.qyft.ms.app.device.spray.SprayTaskExecutor;
  3. import com.qyft.ms.app.model.dto.TimeSetDTO;
  4. import com.qyft.ms.app.model.vo.TimeResponseVO;
  5. import com.qyft.ms.app.service.PositionService;
  6. import com.qyft.ms.app.service.SysSettingsService;
  7. import com.qyft.ms.app.service.SystemService;
  8. import com.qyft.ms.system.common.result.Result;
  9. import io.swagger.v3.oas.annotations.Operation;
  10. import io.swagger.v3.oas.annotations.tags.Tag;
  11. import jakarta.validation.Valid;
  12. import lombok.RequiredArgsConstructor;
  13. import lombok.extern.slf4j.Slf4j;
  14. import org.springframework.web.bind.annotation.*;
  15. import java.time.Instant;
  16. import java.time.ZoneId;
  17. @Tag(name = "系统接口")
  18. @RestController
  19. @RequestMapping("/api/sys")
  20. @RequiredArgsConstructor
  21. @Slf4j
  22. public class SystemController {
  23. private final PositionService positionService;
  24. private final SysSettingsService sysSettingsService;
  25. private final SprayTaskExecutor sprayTaskExecutor;
  26. private final SystemService systemService;
  27. @Operation(summary = "还原出厂配置")
  28. @GetMapping("/reset")
  29. public Result<?> resetFactorySettings() {
  30. try {
  31. positionService.resetToFactorySettings();
  32. sysSettingsService.resetToFactorySettings();
  33. sprayTaskExecutor.init();
  34. return Result.success();
  35. } catch (Exception e) {
  36. log.error("还原出厂配置失败", e);
  37. return Result.failed();
  38. }
  39. }
  40. @Operation(summary = "设置系统时间")
  41. @PostMapping("/datetime")
  42. public Result<?> setDatetime(@Valid @RequestBody TimeSetDTO timeSetDTO) {
  43. systemService.setSystemTime(timeSetDTO.getEpochMilli(), timeSetDTO.getZone());
  44. return Result.success();
  45. }
  46. @Operation(summary = "获取系统时间")
  47. @GetMapping("/datetime")
  48. public Result<?> getDatetime() {
  49. long epochMilli = systemService.getCurrentEpochMilli();
  50. ZoneId systemZone = ZoneId.systemDefault();
  51. return Result.success(new TimeResponseVO(epochMilli, systemZone));
  52. }
  53. }