package com.ard.web.controller.route;
|
|
import com.ard.common.core.domain.AjaxResult;
|
import com.ard.work.config.RouteStateMachineService;
|
import com.ard.work.domain.enums.RouteEvent;
|
import com.ard.work.domain.enums.RouteState;
|
import io.swagger.annotations.Api;
|
import io.swagger.annotations.ApiImplicitParam;
|
import io.swagger.annotations.ApiImplicitParams;
|
import io.swagger.annotations.ApiOperation;
|
import lombok.RequiredArgsConstructor;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.web.bind.annotation.*;
|
|
@Api(tags = "航线状态机")
|
@RestController
|
@RequestMapping("/api/route")
|
@RequiredArgsConstructor
|
public class RouteController {
|
|
@Autowired
|
private RouteStateMachineService stateMachineService;
|
|
/**
|
* 发送航线事件
|
*/
|
@ApiOperation("航线状态测试")
|
@ApiImplicitParams({
|
@ApiImplicitParam(name = "boxSn", value = "设备编号", required = true, dataType = "String", paramType = "path"),
|
@ApiImplicitParam(name = "event", value = "事件", required = true, dataType = "RouteEvent", paramType = "query")
|
})
|
@PostMapping("/{boxSn}/event")
|
public AjaxResult sendRouteEvent(
|
@PathVariable String boxSn,
|
@RequestParam RouteEvent event) {
|
boolean success = stateMachineService.sendEvent(boxSn, event);
|
if (success) {
|
RouteState currentState = stateMachineService.getCurrentState(boxSn);
|
return AjaxResult.success("事件执行成功,设备" + boxSn + "当前状态:" + currentState);
|
} else {
|
return AjaxResult.error("事件执行失败(状态流转不允许),设备" + boxSn + "当前状态:" +
|
stateMachineService.getCurrentState(boxSn));
|
}
|
|
}
|
|
/**
|
* 获取设备当前航线状态
|
*/
|
@ApiOperation("获取设备当前航线状态")
|
@GetMapping("/{boxSn}/state")
|
public RouteState getRouteState(@PathVariable String boxSn) {
|
return stateMachineService.getCurrentState(boxSn);
|
}
|
|
/**
|
* 重置设备航线状态
|
*/
|
@ApiOperation("重置设备航线状态")
|
@PostMapping("/{boxSn}/reset")
|
public String resetRouteState(@PathVariable String boxSn) {
|
stateMachineService.resetStateMachine(boxSn);
|
return "设备" + boxSn + "航线状态已重置为:" + RouteState.IDLE;
|
}
|
}
|