package com.ruoyi.web.controller.ss;

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

import com.ruoyi.ss.access.domain.AccessQuery;
import com.ruoyi.ss.access.domain.AccessVO;
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.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.ss.access.domain.Access;
import com.ruoyi.ss.access.service.AccessService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 第三方API秘钥对Controller
 *
 * @author ruoyi
 * @date 2024-07-17
 */
@RestController
@RequestMapping("/ss/access")
public class AccessController extends BaseController
{
    @Autowired
    private AccessService accessService;

    /**
     * 查询第三方API秘钥对列表
     */
    @PreAuthorize("@ss.hasPermi('ss:access:list')")
    @GetMapping("/list")
    public TableDataInfo list(AccessQuery query)
    {
        startPage();
        List<AccessVO> list = accessService.selectAccessList(query);
        return getDataTable(list);
    }

    /**
     * 导出第三方API秘钥对列表
     */
    @PreAuthorize("@ss.hasPermi('ss:access:export')")
    @Log(title = "第三方API秘钥对", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AccessQuery query)
    {
        List<AccessVO> list = accessService.selectAccessList(query);
        ExcelUtil<AccessVO> util = new ExcelUtil<AccessVO>(AccessVO.class);
        util.exportExcel(response, list, "第三方API秘钥对数据");
    }

    /**
     * 获取第三方API秘钥对详细信息
     */
    @PreAuthorize("@ss.hasPermi('ss:access:query')")
    @GetMapping(value = "/{accessId}")
    public AjaxResult getInfo(@PathVariable("accessId") Long accessId)
    {
        return success(accessService.selectAccessByAccessId(accessId));
    }

    /**
     * 新增第三方API秘钥对
     */
    @PreAuthorize("@ss.hasPermi('ss:access:add')")
    @Log(title = "第三方API秘钥对", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Access access)
    {
        return toAjax(accessService.insertAccess(access));
    }

    /**
     * 修改第三方API秘钥对
     */
    @PreAuthorize("@ss.hasPermi('ss:access:edit')")
    @Log(title = "第三方API秘钥对", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Access access)
    {
        return toAjax(accessService.updateAccess(access));
    }

    /**
     * 删除第三方API秘钥对
     */
    @PreAuthorize("@ss.hasPermi('ss:access:remove')")
    @Log(title = "第三方API秘钥对", businessType = BusinessType.DELETE)
	@DeleteMapping("/{accessIds}")
    public AjaxResult remove(@PathVariable List<Long> accessIds)
    {
        return toAjax(accessService.deleteAccessByAccessIds(accessIds));
    }
}
