package com.yfd.platform.modules.patroltask.controller;

import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import com.yfd.platform.config.ResponseResult;
import com.yfd.platform.modules.patroltask.domain.TaskTodo;
import com.yfd.platform.modules.patroltask.service.DockTaskService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.io.UnsupportedEncodingException;

/**
 * @Date: 2024/7/5 14:02
 * @Description:
 */
@RestController
@RequestMapping("/dock/task")
@Api(value = "TaskTodoController", tags = "机巢服务接口")
@Slf4j
public class DockTaskController {

    @Resource
    private DockTaskService dockTaskService;

    @PostMapping("/sendMediaFileUrl")
    @ApiOperation("机巢服务发送文件路径")
    public synchronized ResponseResult sendMediaFileUrl(@RequestBody String params) throws Exception {
        JSONObject jsonObject = JSONUtil.parseObj(params);
        String url = jsonObject.getStr("url");
        String jobId = jsonObject.getStr("jobId");
        String fileName = jsonObject.getStr("fileName");
        log.info(params);
        // 保存无人机文件
        dockTaskService.saveMediaFile(jobId, fileName, url);
        return ResponseResult.success();
    }


    @GetMapping("/sendTaskResultData")
    @ApiOperation("发送任务数据到分析主机")
    public synchronized ResponseResult sendTaskResultData(String taskTodoId) throws Exception {
        dockTaskService.sendTaskResultData(taskTodoId);
        return ResponseResult.success();
    }
}
