/**
 * 20241029 ©WANGKANG 1686617586@qq.com
 */

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.AlgorithmModelTrackVo;
import com.taais.biz.domain.bo.AlgorithmModelTrackBo;
import com.taais.biz.service.IAlgorithmModelTrackService;

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

/**
 * 算法模型配置Controller
 *
 * @author wangkang
 * 2024-09-26
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/demo/AlgorithmModelTrack")
public class AlgorithmModelTrackController extends BaseController {
    @Resource
    private IAlgorithmModelTrackService algorithmModelTrackService;

    /**
     * 查询算法模型配置列表
     */
    @SaCheckPermission("demo:AlgorithmModelTrack:list")
    @GetMapping("/list")
    public CommonResult<PageResult<AlgorithmModelTrackVo>> list(AlgorithmModelTrackBo algorithmModelTrackBo) {
        return CommonResult.success(algorithmModelTrackService.selectPage(algorithmModelTrackBo));
    }

    /**
     * 导出算法模型配置列表
     */
    @SaCheckPermission("demo:AlgorithmModelTrack:export")
    @Log(title = "算法模型配置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AlgorithmModelTrackBo algorithmModelTrackBo) {
        List<AlgorithmModelTrackVo> list = algorithmModelTrackService.selectList(algorithmModelTrackBo);
        ExcelUtil.exportExcel(list, "算法模型配置", AlgorithmModelTrackVo.class, response);
    }

    /**
     * 获取算法模型配置详细信息
     */
    @SaCheckPermission("demo:AlgorithmModelTrack:query")
    @GetMapping(value = "/{id}")
    public CommonResult<AlgorithmModelTrackVo> getInfo(@PathVariable Long id) {
        return CommonResult.success(algorithmModelTrackService.selectById(id));
    }

    /**
     * 新增算法模型配置
     */
    @SaCheckPermission("demo:AlgorithmModelTrack:add")
    @Log(title = "算法模型配置", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping
    public CommonResult<String> add(@Validated @RequestBody AlgorithmModelTrackBo algorithmModelTrackBo) {
        return algorithmModelTrackService.insert(algorithmModelTrackBo);
    }

    /**
     * 修改算法模型配置
     */
    @SaCheckPermission("demo:AlgorithmModelTrack:edit")
    @Log(title = "算法模型配置", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping
    public CommonResult<Void> edit(@Validated @RequestBody AlgorithmModelTrackBo algorithmModelTrackBo) {
        Boolean updated = algorithmModelTrackService.update(algorithmModelTrackBo);
        if (!updated) {
            return CommonResult.fail("修改算法模型配置记录失败!");
        }
        return CommonResult.success();
    }

    /**
     * 删除算法模型配置
     */
    @SaCheckPermission("demo:AlgorithmModelTrack:remove")
    @Log(title = "算法模型配置", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public CommonResult<Void> remove(@PathVariable Long[] ids) {
        boolean deleted = algorithmModelTrackService.deleteByIds(ids);
        if (!deleted) {
            return CommonResult.fail("删除算法模型配置记录失败!");
        }
        return CommonResult.success();
    }

    @GetMapping("/enums")
    public CommonResult<List<Object>> enums() {
        return CommonResult.success(algorithmModelTrackService.enums());
    }
}
