package com.pdaaphm.system.controller;

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.pdaaphm.common.annotation.Log;
import com.pdaaphm.common.core.controller.BaseController;
import com.pdaaphm.common.core.domain.AjaxResult;
import com.pdaaphm.common.enums.BusinessType;
import com.pdaaphm.system.domain.AlgConfig;
import com.pdaaphm.system.service.IAlgConfigService;
import com.pdaaphm.common.utils.poi.ExcelUtil;
import com.pdaaphm.common.core.page.TableDataInfo;

/**
 * 算法配置Controller
 * 
 * @author Allen
 * @date 2024-08-19
 */
@RestController
@RequestMapping("/system/algConfig")
public class AlgConfigController extends BaseController
{
    @Autowired
    private IAlgConfigService algConfigService;

    /**
     * 查询算法配置列表
     */
    @PreAuthorize("@ss.hasPermi('system:algConfig:list')")
    @GetMapping("/list")
    public TableDataInfo list(AlgConfig algConfig)
    {
        startPage();
        List<AlgConfig> list = algConfigService.selectAlgConfigList(algConfig);
        return getDataTable(list);
    }

    /**
     * 导出算法配置列表
     */
    @PreAuthorize("@ss.hasPermi('system:algConfig:export')")
    @Log(title = "算法配置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AlgConfig algConfig)
    {
        List<AlgConfig> list = algConfigService.selectAlgConfigList(algConfig);
        ExcelUtil<AlgConfig> util = new ExcelUtil<AlgConfig>(AlgConfig.class);
        util.exportExcel(response, list, "算法配置数据");
    }

    /**
     * 获取算法配置详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:algConfig:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(algConfigService.selectAlgConfigById(id));
    }

    /**
     * 新增算法配置
     */
    @PreAuthorize("@ss.hasPermi('system:algConfig:add')")
    @Log(title = "算法配置", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AlgConfig algConfig)
    {
        return toAjax(algConfigService.insertAlgConfig(algConfig));
    }

    /**
     * 修改算法配置
     */
    @PreAuthorize("@ss.hasPermi('system:algConfig:edit')")
    @Log(title = "算法配置", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AlgConfig algConfig)
    {
        return toAjax(algConfigService.updateAlgConfig(algConfig));
    }

    /**
     * 删除算法配置
     */
    @PreAuthorize("@ss.hasPermi('system:algConfig:remove')")
    @Log(title = "算法配置", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(algConfigService.deleteAlgConfigByIds(ids));
    }

    @GetMapping("/getAlgConfigByType/{type}")
    public AjaxResult getAlgConfigByType(@PathVariable String type)
    {
        return success(algConfigService.getAlgConfigByType(type));
    }
}
