package com.yiqi.admin.controller.recharge;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import com.yiqi.common.constant.UrlConstants;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
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.yiqi.common.annotation.Log;
import com.yiqi.common.core.controller.BaseController;
import com.yiqi.common.core.domain.AjaxResult;
import com.yiqi.common.enums.BusinessType;
import com.yiqi.recharge.domain.RechargeCardVersion;
import com.yiqi.recharge.service.IRechargeCardVersionService;
import com.yiqi.common.utils.poi.ExcelUtil;
import com.yiqi.common.core.page.TableDataInfo;

/**
 * 充值卡版本Controller
 *
 * @author 小黑
 * @date 2023-08-29
 */
@Api(tags = "管理后台 - 充值卡版本")
@RestController
@RequestMapping(UrlConstants.managerApi + "/recharge/cardVersion")
public class RechargeCardVersionController extends BaseController {
    @Autowired
    private IRechargeCardVersionService rechargeCardVersionService;

    /**
     * 查询充值卡版本列表
     */
    @PreAuthorize("@ss.hasPermi('recharge:cardVersion:list')")
    @GetMapping("/list")
    @ApiOperation(value = "查询充值卡版本列表")
    public TableDataInfo list(RechargeCardVersion rechargeCardVersion) {
        startPage();
        List<RechargeCardVersion> list = rechargeCardVersionService.selectRechargeCardVersionList(rechargeCardVersion);
        return getDataTable(list);
    }

    /**
     * 导出充值卡版本列表
     */
    @PreAuthorize("@ss.hasPermi('recharge:cardVersion:export')")
    @Log(title = "充值卡版本", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ApiOperation(value = "导出充值卡版本列表")
    public void export(HttpServletResponse response, RechargeCardVersion rechargeCardVersion) {
        List<RechargeCardVersion> list = rechargeCardVersionService.selectRechargeCardVersionList(rechargeCardVersion);
        ExcelUtil<RechargeCardVersion> util = new ExcelUtil<RechargeCardVersion>(RechargeCardVersion. class);
        util.exportExcel(response, list, "充值卡版本数据");
    }

    /**
     * 获取充值卡版本详细信息
     */
    @PreAuthorize("@ss.hasPermi('recharge:cardVersion:query')")
    @GetMapping(value = "/{id}")
    @ApiOperation(value = "获取充值卡版本详细信息")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(rechargeCardVersionService.selectRechargeCardVersionById(id));
    }

    /**
     * 新增充值卡版本
     */
    @PreAuthorize("@ss.hasPermi('recharge:cardVersion:add')")
    @Log(title = "充值卡版本", businessType = BusinessType.INSERT)
    @PostMapping
    @ApiOperation(value = "新增充值卡版本")
    public AjaxResult add(@RequestBody RechargeCardVersion rechargeCardVersion) {
        rechargeCardVersion.setCreateById(getUserId());
        rechargeCardVersion.setCreateBy(getUsername());
        return toAjax(rechargeCardVersionService.insertRechargeCardVersion(rechargeCardVersion));
    }

    /**
     * 修改充值卡版本
     */
    @PreAuthorize("@ss.hasPermi('recharge:cardVersion:edit')")
    @Log(title = "充值卡版本", businessType = BusinessType.UPDATE)
    @PutMapping
    @ApiOperation(value = "修改充值卡版本")
    public AjaxResult edit(@RequestBody RechargeCardVersion rechargeCardVersion) {
        rechargeCardVersion.setUpdateById(getUserId());
        rechargeCardVersion.setUpdateBy(getUsername());
        return toAjax(rechargeCardVersionService.updateRechargeCardVersion(rechargeCardVersion));
    }

    /**
     * 删除充值卡版本
     */
    @PreAuthorize("@ss.hasPermi('recharge:cardVersion:remove')")
    @Log(title = "充值卡版本", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    @ApiOperation(value = "删除充值卡版本")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(rechargeCardVersionService.deleteRechargeCardVersionByIds(ids));
    }

    /**
     * 修改充值卡版本状态
     */
    @PreAuthorize("@ss.hasPermi('recharge:cardVersion:edit')")
    @Log(title = "充值卡版本", businessType = BusinessType.UPDATE)
    @PostMapping(value = "updateStatus")
    @ApiOperation(value = "修改充值卡版本状态")
    public AjaxResult updateRechargeCardVersionStatus(@RequestBody RechargeCardVersion rechargeCardVersion) {
        return toAjax(rechargeCardVersionService.updateRechargeCardVersionStatus(rechargeCardVersion));
    }
}
