package com.ruoyi.web.controller.manage;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.manage.domain.ParameterSet;
import com.ruoyi.manage.service.IParameterSetService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 参数设置Controller
 *
 * @author boman
 * @date 2025-06-18
 */
@RestController
@RequestMapping("/manage/parameterSet")
public class ParameterSetController extends BaseController {
    @Autowired
    private IParameterSetService parameterSetService;

    /**
     * 查询参数设置列表
     */
    @PreAuthorize("@ss.hasPermi('manage:parameterSet:list')")
    @GetMapping("/list")
    public TableDataInfo list(ParameterSet parameterSet) {
        startPage();
        List<ParameterSet> list = parameterSetService.selectParameterSetList(parameterSet);
        return getDataTable(list);
    }

    /**
     * 导出参数设置列表
     */
    @PreAuthorize("@ss.hasPermi('manage:parameterSet:export')")
    @Log(title = "参数设置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ParameterSet parameterSet) {
        List<ParameterSet> list = parameterSetService.selectParameterSetList(parameterSet);
        ExcelUtil<ParameterSet> util = new ExcelUtil<ParameterSet>(ParameterSet.class);
        util.exportExcel(response, list, "参数设置数据");
    }

    /**
     * 获取参数设置详细信息
     */
    @PreAuthorize("@ss.hasPermi('manage:parameterSet:query')")
    @GetMapping(value = "/{parameterId}")
    public AjaxResult getInfo(@PathVariable("parameterId") Long parameterId) {
        return success(parameterSetService.selectParameterSetByParameterId(parameterId));
    }

    /**
     * 新增参数设置
     */
    @PreAuthorize("@ss.hasPermi('manage:parameterSet:add')")
    @Log(title = "参数设置", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ParameterSet parameterSet) {
        return parameterSetService.insertParameterSet(parameterSet);
    }

    /**
     * 修改参数设置
     */
    @PreAuthorize("@ss.hasPermi('manage:parameterSet:edit')")
    @Log(title = "参数设置", businessType = BusinessType.UPDATE)
    @PostMapping("/put")
    public AjaxResult edit(@RequestBody ParameterSet parameterSet) {
        return parameterSetService.updateParameterSet(parameterSet);
    }

    /**
     * 删除参数设置
     */
    @PreAuthorize("@ss.hasPermi('manage:parameterSet:remove')")
    @Log(title = "参数设置", businessType = BusinessType.DELETE)
    @GetMapping("/delete/{parameterIds}")
    public AjaxResult remove(@PathVariable Long[] parameterIds) {
        return toAjax(parameterSetService.deleteParameterSetByParameterIds(parameterIds));
    }
}
