package com.zyc.web.controller.api;

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

/**
 * API接口清单Controller
 * 
 * @author zyc
 * @date 2024-12-26
 */
@RestController
@RequestMapping("/system/ApiInterfaceController")
public class ApiInterfaceController extends BaseController
{
    @Autowired
    private IApiInterfaceService apiInterfaceService;

    /**
     * 查询API接口清单列表
     */
    @PreAuthorize("@ss.hasPermi('system:interface:list')")
    @GetMapping("/list")
    public TableDataInfo list(ApiInterface apiInterface)
    {
        startPage();
        List<ApiInterface> list = apiInterfaceService.selectApiInterfaceList(apiInterface);
        return getDataTable(list);
    }

    /**
     * 导出API接口清单列表
     */
    @PreAuthorize("@ss.hasPermi('system:interface:export')")
    @Log(title = "API接口清单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ApiInterface apiInterface)
    {
        List<ApiInterface> list = apiInterfaceService.selectApiInterfaceList(apiInterface);
        ExcelUtil<ApiInterface> util = new ExcelUtil<ApiInterface>(ApiInterface.class);
        util.exportExcel(response, list, "API接口清单数据");
    }

    /**
     * 获取API接口清单详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:interface:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Integer id)
    {
        return success(apiInterfaceService.selectApiInterfaceById(id));
    }

    /**
     * 新增API接口清单
     */
    @PreAuthorize("@ss.hasPermi('system:interface:add')")
    @Log(title = "API接口清单", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ApiInterface apiInterface)
    {
        return toAjax(apiInterfaceService.insertApiInterface(apiInterface));
    }

    /**
     * 修改API接口清单
     */
    @PreAuthorize("@ss.hasPermi('system:interface:edit')")
    @Log(title = "API接口清单", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ApiInterface apiInterface)
    {
        return toAjax(apiInterfaceService.updateApiInterface(apiInterface));
    }

    /**
     * 删除API接口清单
     */
    @PreAuthorize("@ss.hasPermi('system:interface:remove')")
    @Log(title = "API接口清单", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Integer[] ids)
    {
        return toAjax(apiInterfaceService.deleteApiInterfaceByIds(ids));
    }
}
