package com.pdaaphm.biz.controller;

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

import com.pdaaphm.biz.dto.SubAlgorithmDTO;
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.AlgorithmIoField;
import com.pdaaphm.biz.service.IAlgorithmIoFieldService;
import com.pdaaphm.common.utils.poi.ExcelUtil;
import com.pdaaphm.common.core.page.TableDataInfo;

/**
 * 算法输入输出字段Controller
 *
 * @author xlk
 * @date 2023-07-26
 */
@RestController
@RequestMapping("/conf/field")
public class AlgorithmIoFieldController extends BaseController
{
    @Autowired
    private IAlgorithmIoFieldService algorithmIoFieldService;

    /**
     * 查询算法输入输出字段列表
     */
    @PreAuthorize("@ss.hasPermi('conf:field:list')")
    @GetMapping("/list")
    public TableDataInfo list(AlgorithmIoField algorithmIoField)
    {
        startPage();
        List<AlgorithmIoField> list = algorithmIoFieldService.selectAlgorithmIoFieldList(algorithmIoField);
        return getDataTable(list);
    }

    /**
     * 导出算法输入输出字段列表
     */
    @PreAuthorize("@ss.hasPermi('conf:field:export')")
    @Log(title = "算法输入输出字段", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AlgorithmIoField algorithmIoField)
    {
        List<AlgorithmIoField> list = algorithmIoFieldService.selectAlgorithmIoFieldList(algorithmIoField);
        ExcelUtil<AlgorithmIoField> util = new ExcelUtil<AlgorithmIoField>(AlgorithmIoField.class);
        util.exportExcel(response, list, "算法输入输出字段数据");
    }

    /**
     * 获取算法输入输出字段详细信息
     */
    @PreAuthorize("@ss.hasPermi('conf:field:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(algorithmIoFieldService.selectAlgorithmIoFieldById(id));
    }

    /**
     * 新增算法输入输出字段
     */
    @PreAuthorize("@ss.hasPermi('conf:field:add')")
    @Log(title = "算法输入输出字段", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AlgorithmIoField algorithmIoField)
    {
        return toAjax(algorithmIoFieldService.insertAlgorithmIoField(algorithmIoField));
    }

    /**
     * 修改算法输入输出字段
     */
    @PreAuthorize("@ss.hasPermi('conf:field:edit')")
    @Log(title = "算法输入输出字段", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AlgorithmIoField algorithmIoField)
    {
        return toAjax(algorithmIoFieldService.updateAlgorithmIoField(algorithmIoField));
    }

    /**
     * 删除算法输入输出字段
     */
    @PreAuthorize("@ss.hasPermi('conf:field:remove')")
    @Log(title = "算法输入输出字段", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(algorithmIoFieldService.deleteAlgorithmIoFieldByIds(ids));
    }

    @GetMapping(value = "/getIoSubList/{subTypeId}/{algoId}")
    public AjaxResult getIoSubList(@PathVariable("subTypeId") Long subTypeId, @PathVariable("subTypeId") Long algoId) {
        List<SubAlgorithmDTO> map = algorithmIoFieldService.getIoSubList(subTypeId, algoId);
        return success(map);
    }
}
