/**
 * 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.AlgorithmConfigTrackVo;
import com.taais.biz.domain.bo.AlgorithmConfigTrackBo;
import com.taais.biz.service.IAlgorithmConfigTrackService;

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

/**
 * 算法配置Controller
 *
 * @author wangkang
 * 2024-09-26
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/demo/AlgorithmConfigTrack")
public class AlgorithmConfigTrackController extends BaseController {
    @Resource
    private IAlgorithmConfigTrackService algorithmConfigTrackService;

    /**
     * 查询算法配置列表
     */
    @SaCheckPermission("demo:AlgorithmConfigTrack:list")
    @GetMapping("/list")
    public CommonResult<PageResult<AlgorithmConfigTrackVo>> list(AlgorithmConfigTrackBo algorithmConfigTrackBo) {
        return CommonResult.success(algorithmConfigTrackService.selectPage(algorithmConfigTrackBo));
    }

    /**
     * 导出算法配置列表
     */
    @SaCheckPermission("demo:AlgorithmConfigTrack:export")
    @Log(title = "算法配置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AlgorithmConfigTrackBo algorithmConfigTrackBo) {
        List<AlgorithmConfigTrackVo> list = algorithmConfigTrackService.selectList(algorithmConfigTrackBo);
        ExcelUtil.exportExcel(list, "算法配置", AlgorithmConfigTrackVo.class, response);
    }

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

    /**
     * 新增算法配置
     */
    @SaCheckPermission("demo:AlgorithmConfigTrack:add")
    @Log(title = "算法配置", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping
    public CommonResult<Void> add(@Validated @RequestBody AlgorithmConfigTrackBo algorithmConfigTrackBo) {
        boolean inserted = algorithmConfigTrackService.insert(algorithmConfigTrackBo);
        if (!inserted) {
            return CommonResult.fail("新增算法配置记录失败！");
        }
        return CommonResult.success();
    }

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

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

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