package com.solution.web.controller.algo;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.solution.common.annotation.Log;
import com.solution.common.core.controller.BaseController;
import com.solution.common.core.domain.AjaxResult;
import com.solution.common.enums.BusinessType;
import com.solution.algo.domain.SysAlgoConfig;
import com.solution.algo.service.ISysAlgoConfigService;
import com.solution.common.utils.poi.ExcelUtil;
import com.solution.common.core.page.TableDataInfo;

/**
 * 动态规则配置Controller
 * 
 * @author zouju
 * @date 2026-02-05
 */
@RestController
@RequestMapping("/algo/algo")
public class SysAlgoConfigController extends BaseController
{
    @Autowired
    private ISysAlgoConfigService sysAlgoConfigService;

    /**
     * 查询动态规则配置列表
     */
    @PreAuthorize("@ss.hasPermi('algo:algo:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysAlgoConfig sysAlgoConfig)
    {
        startPage();
        List<SysAlgoConfig> list = sysAlgoConfigService.selectSysAlgoConfigList(sysAlgoConfig);
        return getDataTable(list);
    }

    /**
     * 导出动态规则配置列表
     */
    @PreAuthorize("@ss.hasPermi('algo:algo:export')")
    @Log(title = "动态规则配置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysAlgoConfig sysAlgoConfig)
    {
        List<SysAlgoConfig> list = sysAlgoConfigService.selectSysAlgoConfigList(sysAlgoConfig);
        ExcelUtil<SysAlgoConfig> util = new ExcelUtil<SysAlgoConfig>(SysAlgoConfig.class);
        util.exportExcel(response, list, "动态规则配置数据");
    }

    /**
     * 获取动态规则配置详细信息
     */
    @PreAuthorize("@ss.hasPermi('algo:algo:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(sysAlgoConfigService.selectSysAlgoConfigById(id));
    }

    /**
     * 新增动态规则配置
     */
    @PreAuthorize("@ss.hasPermi('algo:algo:add')")
    @Log(title = "动态规则配置", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysAlgoConfig sysAlgoConfig)
    {
        return toAjax(sysAlgoConfigService.insertSysAlgoConfig(sysAlgoConfig));
    }

    /**
     * 修改动态规则配置
     */
    @PreAuthorize("@ss.hasPermi('algo:algo:edit')")
    @Log(title = "动态规则配置", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysAlgoConfig sysAlgoConfig)
    {
        return toAjax(sysAlgoConfigService.updateSysAlgoConfig(sysAlgoConfig));
    }

    /**
     * 删除动态规则配置
     */
    @PreAuthorize("@ss.hasPermi('algo:algo:remove')")
    @Log(title = "动态规则配置", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(sysAlgoConfigService.deleteSysAlgoConfigByIds(ids));
    }
}
