package com.pdaaphm.biz.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.biz.domain.SubAlgorithm;
import com.pdaaphm.biz.service.ISubAlgorithmService;
import com.pdaaphm.common.utils.poi.ExcelUtil;
import com.pdaaphm.common.core.page.TableDataInfo;

/**
 * 子算法Controller
 * 
 * @author xlk
 * @date 2023-07-26
 */
@RestController
@RequestMapping("/algoManager/subAlgorithm")
public class SubAlgorithmController extends BaseController
{
    @Autowired
    private ISubAlgorithmService subAlgorithmService;

    /**
     * 查询子算法列表
     */
    @PreAuthorize("@ss.hasPermi('algoManager:subAlgorithm:list')")
    @GetMapping("/list")
    public TableDataInfo list(SubAlgorithm subAlgorithm)
    {
        startPage();
        List<SubAlgorithm> list = subAlgorithmService.selectSubAlgorithmList(subAlgorithm);
        return getDataTable(list);
    }

    /**
     * 导出子算法列表
     */
    @PreAuthorize("@ss.hasPermi('algoManager:subAlgorithm:export')")
    @Log(title = "子算法", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SubAlgorithm subAlgorithm)
    {
        List<SubAlgorithm> list = subAlgorithmService.selectSubAlgorithmList(subAlgorithm);
        ExcelUtil<SubAlgorithm> util = new ExcelUtil<SubAlgorithm>(SubAlgorithm.class);
        util.exportExcel(response, list, "子算法数据");
    }

    /**
     * 获取子算法详细信息
     */
    @PreAuthorize("@ss.hasPermi('algoManager:subAlgorithm:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(subAlgorithmService.selectSubAlgorithmById(id));
    }

    /**
     * 新增子算法
     */
    @PreAuthorize("@ss.hasPermi('algoManager:subAlgorithm:add')")
    @Log(title = "子算法", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SubAlgorithm subAlgorithm)
    {
        return toAjax(subAlgorithmService.insertSubAlgorithm(subAlgorithm));
    }

    /**
     * 修改子算法
     */
    @PreAuthorize("@ss.hasPermi('algoManager:subAlgorithm:edit')")
    @Log(title = "子算法", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SubAlgorithm subAlgorithm)
    {
        return toAjax(subAlgorithmService.updateSubAlgorithm(subAlgorithm));
    }

    /**
     * 删除子算法
     */
    @PreAuthorize("@ss.hasPermi('algoManager:subAlgorithm:remove')")
    @Log(title = "子算法", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(subAlgorithmService.deleteSubAlgorithmByIds(ids));
    }
}
