package com.ff.common.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.ff.base.annotation.Log;
import com.ff.base.core.controller.BaseController;
import com.ff.base.core.domain.AjaxResult;
import com.ff.base.enums.BusinessType;
import com.ff.common.domain.TenantSecretKey;
import com.ff.common.service.ITenantSecretKeyService;
import com.ff.base.utils.poi.ExcelUtil;
import com.ff.base.core.page.TableDataInfo;

/**
 * 用户租户密钥Controller
 *
 * @author shi
 * @date 2025-02-11
 */
@RestController
@RequestMapping("/common/key")
public class TenantSecretKeyController extends BaseController
{
    @Autowired
    private ITenantSecretKeyService tenantSecretKeyService;

    /**
     * 查询用户租户密钥列表
     */
    @PreAuthorize("@ss.hasPermi('common:key:list')")
    @GetMapping("/list")
    public TableDataInfo list(TenantSecretKey tenantSecretKey)
    {
        startPage();
        List<TenantSecretKey> list = tenantSecretKeyService.selectTenantSecretKeyList(tenantSecretKey);
        return getDataTable(list);
    }

    /**
     * 导出用户租户密钥列表
     */
    @PreAuthorize("@ss.hasPermi('common:key:export')")
    @Log(title = "用户租户密钥", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TenantSecretKey tenantSecretKey)
    {
        List<TenantSecretKey> list = tenantSecretKeyService.selectTenantSecretKeyList(tenantSecretKey);
        ExcelUtil<TenantSecretKey> util = new ExcelUtil<TenantSecretKey>(TenantSecretKey.class);
        util.exportExcel(response, list, "用户租户密钥数据");
    }

    /**
     * 获取用户租户密钥详细信息
     */
    @PreAuthorize("@ss.hasPermi('common:key:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(tenantSecretKeyService.selectTenantSecretKeyById(id));
    }

    /**
     * 新增用户租户密钥
     */
    @PreAuthorize("@ss.hasPermi('common:key:add')")
    @Log(title = "用户租户密钥", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TenantSecretKey tenantSecretKey)
    {
        return toAjax(tenantSecretKeyService.insertTenantSecretKey(tenantSecretKey));
    }

    /**
     * 修改用户租户密钥
     */
    @PreAuthorize("@ss.hasPermi('common:key:edit')")
    @Log(title = "用户租户密钥", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TenantSecretKey tenantSecretKey)
    {
        return toAjax(tenantSecretKeyService.updateTenantSecretKey(tenantSecretKey));
    }

    /**
     * 删除用户租户密钥
     */
    @PreAuthorize("@ss.hasPermi('common:key:remove')")
    @Log(title = "用户租户密钥", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(tenantSecretKeyService.deleteTenantSecretKeyByIds(ids));
    }
}
