package cn.iocoder.yudao.module.system.controller.admin.tool;


import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.module.system.controller.admin.robot.vo.RobotInformationSaveReqVO;
import cn.iocoder.yudao.module.system.controller.admin.tool.dto.SendMsgToMqttDTO;
import cn.iocoder.yudao.module.system.service.tool.ToolsService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.annotation.security.PermitAll;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import javax.validation.constraints.NotBlank;

import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

@Tag(name = "管理后台 - 工具类(限技术人员使用)")
@RestController
@RequestMapping("/system/tools")
@Validated
public class ToolsController {

    @Resource
    private ToolsService toolsService;

    @PostMapping("/pp/cleanAgv")
    @Operation(summary = "路径规划---清除交管")
    @PermitAll
    public CommonResult<String> cleanAgv(@Valid @RequestParam @NotBlank(message = "请传机器人编号") String robotNo) {
        return success(toolsService.cleanAgv(robotNo));
    }

    @PostMapping("/closeTaskDetail")
    @Operation(summary = "关闭任务(同步路径规划和车机)-不改变数据库任务状态")
    @PermitAll
    public CommonResult<String> closeTaskDetail(@Valid @RequestParam @NotBlank(message = "请传任务id") String taskDetailId) {
        return success(toolsService.closeTaskDetail(taskDetailId));
    }

    @GetMapping("/robot/updateWarnCode")
    @Operation(summary = "机器人---下载告警码值映射文件")
    @PermitAll
    public CommonResult<String> updateWarnCode() {
        return success(toolsService.updateWarnCode());
    }

    @PostMapping("/robot/simulationPose")
    @Operation(summary = "机器人---仿真环境--初始化点位")
    @PermitAll
    public CommonResult<String> simulationPose() {
        toolsService.simulationPose();
        return success("同步完成");
    }

    @PostMapping("/sendMsgToMQTT")
    @Operation(summary = "发送消息给MQTT")
    @PermitAll
    public CommonResult<String> sendMsgToMQTT( @RequestBody SendMsgToMqttDTO dto) {
        toolsService.sendMsgToMQTT(dto);
        return success("发送完成");
    }
}
