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.AlgorithmSubType;
import com.pdaaphm.biz.service.IAlgorithmSubTypeService;
import com.pdaaphm.common.utils.poi.ExcelUtil;
import com.pdaaphm.common.core.page.TableDataInfo;

/**
 * 算法子类型Controller
 * 
 * @author allen
 * @date 2023-07-26
 */
@RestController
@RequestMapping("/conf/subType")
public class AlgorithmSubTypeController extends BaseController
{
    @Autowired
    private IAlgorithmSubTypeService algorithmSubTypeService;

    /**
     * 查询算法子类型列表
     */
    @PreAuthorize("@ss.hasPermi('conf:subType:list')")
    @GetMapping("/list")
    public TableDataInfo list(AlgorithmSubType algorithmSubType)
    {
        startPage();
        List<AlgorithmSubType> list = algorithmSubTypeService.selectAlgorithmSubTypeList(algorithmSubType);
        return getDataTable(list);
    }

    /**
     * 导出算法子类型列表
     */
    @PreAuthorize("@ss.hasPermi('conf:subType:export')")
    @Log(title = "算法子类型", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AlgorithmSubType algorithmSubType)
    {
        List<AlgorithmSubType> list = algorithmSubTypeService.selectAlgorithmSubTypeList(algorithmSubType);
        ExcelUtil<AlgorithmSubType> util = new ExcelUtil<AlgorithmSubType>(AlgorithmSubType.class);
        util.exportExcel(response, list, "算法子类型数据");
    }

    /**
     * 获取算法子类型详细信息
     */
    @PreAuthorize("@ss.hasPermi('conf:subType:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(algorithmSubTypeService.selectAlgorithmSubTypeById(id));
    }

    /**
     * 新增算法子类型
     */
    @PreAuthorize("@ss.hasPermi('conf:subType:add')")
    @Log(title = "算法子类型", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AlgorithmSubType algorithmSubType)
    {
        return toAjax(algorithmSubTypeService.insertAlgorithmSubType(algorithmSubType));
    }

    /**
     * 修改算法子类型
     */
    @PreAuthorize("@ss.hasPermi('conf:subType:edit')")
    @Log(title = "算法子类型", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AlgorithmSubType algorithmSubType)
    {
        return toAjax(algorithmSubTypeService.updateAlgorithmSubType(algorithmSubType));
    }

    /**
     * 删除算法子类型
     */
    @PreAuthorize("@ss.hasPermi('conf:subType:remove')")
    @Log(title = "算法子类型", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(algorithmSubTypeService.deleteAlgorithmSubTypeByIds(ids));
    }
}
