package org.eco.als.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.hutool.core.util.StrUtil;
import jakarta.annotation.Resource;
import lombok.RequiredArgsConstructor;
import org.eco.als.domain.bo.AlgorithmBo;
import org.eco.als.domain.bo.TaskBo;
import org.eco.als.service.IAlgorithmService;
import org.eco.common.core.core.domain.CommonResult;
import org.eco.common.log.annotation.Log;
import org.eco.common.log.enums.BusinessType;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 算法相关控制
 *
 * @Author: GaoKun Wang
 * @Date: 2024/7/30
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/als/algorithm")
public class AlgorithmController {
    @Resource
    private IAlgorithmService algorithmService;

    /**
     * 执行预处理
     *
     * @param algorithmBo 入参
     * @return org.eco.common.core.core.domain.CommonResult<java.lang.String> 结果
     **/
    @SaCheckPermission("als:algorithm:execute")
    @Log(title = "执行预处理算法", businessType = BusinessType.EXECUTE)
    @PostMapping("/execute/pro")
    public CommonResult<String> executePro(@Validated @RequestBody AlgorithmBo algorithmBo) {
        return StrUtil.isBlank(algorithmService.executePro(algorithmBo)) ? CommonResult.fail() : CommonResult.success();
    }

    /**
     * 执行虚警抑制
     *
     * @param algorithmBo 入参
     * @return org.eco.common.core.core.domain.CommonResult<java.lang.String> 结果
     **/
    @SaCheckPermission("als:algorithm:execute")
    @Log(title = "执行虚警抑制算法", businessType = BusinessType.EXECUTE)
    @PostMapping("/execute/falseAlarm")
    public CommonResult<String> executeFalseAlarm(@Validated @RequestBody AlgorithmBo algorithmBo) {
        return StrUtil.isBlank(algorithmService.executeFalseAlarm(algorithmBo)) ? CommonResult.fail() : CommonResult.success();
    }

    /**
     * 执行古战诊断
     *
     * @param algorithmBo 入参
     * @return org.eco.common.core.core.domain.CommonResult<java.lang.String> 结果
     **/
    @SaCheckPermission("als:algorithm:execute")
    @Log(title = "执行故障诊断算法", businessType = BusinessType.EXECUTE)
    @PostMapping("/execute/fault")
    public CommonResult<String> executeFault(@Validated @RequestBody AlgorithmBo algorithmBo) {
        return StrUtil.isBlank(algorithmService.executeFault(algorithmBo)) ? CommonResult.fail() : CommonResult.success();
    }

    /**
     * 执行任务管理
     *
     * @param taskBo 入参
     * @return org.eco.common.core.core.domain.CommonResult<java.lang.String> 结果
     **/
    @SaCheckPermission("als:algorithm:execute")
    @Log(title = "执行任务", businessType = BusinessType.EXECUTE)
    @PostMapping("/execute/task")
    public CommonResult<String> batchExecute(@Validated @RequestBody TaskBo taskBo) {
        return StrUtil.isBlank(algorithmService.batchExecute(taskBo)) ? CommonResult.fail() : CommonResult.success();
    }
    /**
     * 获取数据参数名称
     *
     * @param ossId 入参数据
     * @return org.eco.common.core.core.domain.CommonResult<java.lang.String> 结果
     **/
    @Log(title = "获取数据参数名称", businessType = BusinessType.EXECUTE)
    @GetMapping("/{ossId}")
    public CommonResult<List<String>> getDataHeader(@PathVariable Long ossId) {
        return CommonResult.success(algorithmService.getDataHeader(ossId));
    }
    /**
     * 获取数据根据OssId
     *
     * @param ossId 入参数据
     * @return org.eco.common.core.core.domain.CommonResult<java.lang.String> 结果
     **/
    @Log(title = "获取数据参数名称", businessType = BusinessType.EXECUTE)
    @GetMapping("/data/{ossId}")
    public CommonResult<String> getDataByOssId(@PathVariable Long ossId) {
        return CommonResult.success(algorithmService.getDataByOssId(ossId), "");
    }
    /**
     * 获取曲线数据根据OssId
     *
     * @param ossId 入参数据
     * @return org.eco.common.core.core.domain.CommonResult<java.lang.String> 结果
     **/
    @Log(title = "获取数据参数名称", businessType = BusinessType.EXECUTE)
    @GetMapping("/playback/data/{ossId}")
    public CommonResult<String> getPlaybackDataByOssId(@PathVariable Long ossId) {
        return CommonResult.success(algorithmService.getDataByOssId(ossId), "");
    }
}
