package com.ruoyi.abuwx.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.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.abuwx.domain.CardPassword;
import com.ruoyi.abuwx.service.ICardPasswordService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 卡密管理Controller
 *
 * @author lujie
 * @date 2025-01-07
 */
@RestController
@RequestMapping("/card/password")
public class CardPasswordController extends BaseController {
    @Autowired
    private ICardPasswordService cardPasswordService;

    /**
     * 查询卡密管理列表
     */
    @PreAuthorize("@ss.hasPermi('card:password:list')")
    @GetMapping("/list")
    public TableDataInfo list(CardPassword cardPassword) {
        startPage();
        List<CardPassword> list = cardPasswordService.selectCardPasswordList(cardPassword);
        return getDataTable(list);
    }

    /**
     * 导出卡密管理列表
     */
    @PreAuthorize("@ss.hasPermi('card:password:export')")
    @Log(title = "卡密管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CardPassword cardPassword) {
        List<CardPassword> list = cardPasswordService.selectCardPasswordList(cardPassword);
        ExcelUtil<CardPassword> util = new ExcelUtil<CardPassword>(CardPassword.class);
        util.exportExcel(response, list, "卡密管理数据");
    }

    /**
     * 获取卡密管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('card:password:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(cardPasswordService.selectCardPasswordById(id));
    }

    /**
     * 新增卡密管理
     */
    @PreAuthorize("@ss.hasPermi('card:password:add')")
    @Log(title = "卡密管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CardPassword cardPassword) {
        return toAjax(cardPasswordService.insertCardPassword(cardPassword));
    }

    /**
     * 修改卡密管理
     */
    @PreAuthorize("@ss.hasPermi('card:password:edit')")
    @Log(title = "卡密管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CardPassword cardPassword) {
        return toAjax(cardPasswordService.updateCardPassword(cardPassword));
    }

    /**
     * 删除卡密管理
     */
    @PreAuthorize("@ss.hasPermi('card:password:remove')")
    @Log(title = "卡密管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(cardPasswordService.deleteCardPasswordByIds(ids));
    }
}
