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
62 lines
2.0 KiB
package com.qyft.ms.app.controller;
|
|
|
|
import com.qyft.ms.app.device.spray.SprayTaskExecutor;
|
|
import com.qyft.ms.app.model.dto.TimeSetDTO;
|
|
import com.qyft.ms.app.model.vo.TimeResponseVO;
|
|
import com.qyft.ms.app.service.PositionService;
|
|
import com.qyft.ms.app.service.SysSettingsService;
|
|
import com.qyft.ms.app.service.SystemService;
|
|
import com.qyft.ms.system.common.result.Result;
|
|
import io.swagger.v3.oas.annotations.Operation;
|
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
|
import jakarta.validation.Valid;
|
|
import lombok.RequiredArgsConstructor;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
import java.time.Instant;
|
|
import java.time.ZoneId;
|
|
|
|
@Tag(name = "系统接口")
|
|
@RestController
|
|
@RequestMapping("/api/sys")
|
|
@RequiredArgsConstructor
|
|
@Slf4j
|
|
public class SystemController {
|
|
private final PositionService positionService;
|
|
private final SysSettingsService sysSettingsService;
|
|
private final SprayTaskExecutor sprayTaskExecutor;
|
|
private final SystemService systemService;
|
|
|
|
@Operation(summary = "还原出厂配置")
|
|
@GetMapping("/reset")
|
|
public Result<?> resetFactorySettings() {
|
|
try {
|
|
positionService.resetToFactorySettings();
|
|
sysSettingsService.resetToFactorySettings();
|
|
sprayTaskExecutor.init();
|
|
return Result.success();
|
|
} catch (Exception e) {
|
|
log.error("还原出厂配置失败", e);
|
|
return Result.failed();
|
|
}
|
|
}
|
|
|
|
@Operation(summary = "设置系统时间")
|
|
@PostMapping("/datetime")
|
|
public Result<?> setDatetime(@Valid @RequestBody TimeSetDTO timeSetDTO) {
|
|
systemService.setSystemTime(timeSetDTO.getEpochMilli(), timeSetDTO.getZone());
|
|
return Result.success();
|
|
}
|
|
|
|
@Operation(summary = "获取系统时间")
|
|
@GetMapping("/datetime")
|
|
public Result<?> getDatetime() {
|
|
long epochMilli = systemService.getCurrentEpochMilli();
|
|
ZoneId systemZone = ZoneId.systemDefault();
|
|
return Result.success(new TimeResponseVO(epochMilli, systemZone));
|
|
}
|
|
|
|
|
|
|
|
}
|