package com.taais.biz.controller;

import java.util.List;

import lombok.RequiredArgsConstructor;
import jakarta.servlet.http.HttpServletResponse;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.taais.common.core.core.domain.CommonResult;
import com.taais.common.excel.utils.ExcelUtil;
import com.taais.common.log.annotation.Log;
import com.taais.common.log.enums.BusinessType;
import com.taais.common.web.annotation.RepeatSubmit;
import com.taais.common.web.core.BaseController;
import jakarta.annotation.Resource;
import com.taais.biz.domain.vo.AlgorithmDataProcessVo;
import com.taais.biz.domain.bo.AlgorithmDataProcessBo;
import com.taais.biz.service.IAlgorithmDataProcessService;

import com.taais.common.core.core.page.PageResult;

/**
 * 算法数据处理Controller
 *
 * @author 0
 * 2024-06-14
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/task/dataProcess")
public class AlgorithmDataProcessController extends BaseController {
    @Resource
    private IAlgorithmDataProcessService algorithmDataProcessService;

    /**
     * 查询算法数据处理列表
     */
    @SaCheckPermission("task:dataProcess:list")
    @GetMapping("/list")
    public CommonResult<PageResult<AlgorithmDataProcessVo>> list(AlgorithmDataProcessBo algorithmDataProcessBo) {
        return CommonResult.success(algorithmDataProcessService.selectPage(algorithmDataProcessBo));
    }

    /**
     * 导出算法数据处理列表
     */
    @SaCheckPermission("task:dataProcess:export")
    @Log(title = "算法数据处理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AlgorithmDataProcessBo algorithmDataProcessBo) {
        List<AlgorithmDataProcessVo> list = algorithmDataProcessService.selectList(algorithmDataProcessBo);
        ExcelUtil.exportExcel(list, "算法数据处理", AlgorithmDataProcessVo.class, response);
    }

    /**
     * 获取算法数据处理详细信息
     */
    @SaCheckPermission("task:dataProcess:query")
    @GetMapping(value = "/{id}")
    public CommonResult<AlgorithmDataProcessVo> getInfo(@PathVariable Long id) {
        return CommonResult.success(algorithmDataProcessService.selectById(id));
    }

    /**
     * 新增算法数据处理
     */
    @SaCheckPermission("task:dataProcess:add")
    @Log(title = "算法数据处理", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping
    public CommonResult<Void> add(@Validated @RequestBody AlgorithmDataProcessBo algorithmDataProcessBo) {
        boolean inserted = algorithmDataProcessService.insert(algorithmDataProcessBo);
        if (!inserted) {
            return CommonResult.fail("新增算法数据处理记录失败！");
        }
        return CommonResult.success();
    }

    /**
     * 修改算法数据处理
     */
    @SaCheckPermission("task:dataProcess:edit")
    @Log(title = "算法数据处理", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping
    public CommonResult<Void> edit(@Validated @RequestBody AlgorithmDataProcessBo algorithmDataProcessBo) {
        Boolean updated = algorithmDataProcessService.update(algorithmDataProcessBo);
        if (!updated) {
            return CommonResult.fail("修改算法数据处理记录失败!");
        }
        return CommonResult.success();
    }

    /**
     * 删除算法数据处理
     */
    @SaCheckPermission("task:dataProcess:remove")
    @Log(title = "算法数据处理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public CommonResult<Void> remove(@PathVariable Long[] ids) {
        boolean deleted = algorithmDataProcessService.deleteByIds(ids);
        if (!deleted) {
            return CommonResult.fail("删除算法数据处理记录失败!");
        }
        return CommonResult.success();
    }
}
