package com.fastbee.data.controller.userRecharge;

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

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.fastbee.common.core.controller.BaseController;
import com.fastbee.common.core.domain.AjaxResult;
import com.fastbee.rechargecard.domain.UserRechargeCards;
import com.fastbee.rechargecard.service.IUserRechargeCardsService;
import com.fastbee.common.utils.poi.ExcelUtil;
import com.fastbee.common.core.page.TableDataInfo;

/**
 * 用户充值卡Controller
 *
 * @author kerwincui
 */
@RestController
@RequestMapping("/rechargecard/cards")
@Api(tags = "用户充值卡")
public class UserRechargeCardsController extends BaseController
{
    @Autowired
    private IUserRechargeCardsService userRechargeCardsService;


    /**
     * 测试
     */
    @PreAuthorize("@ss.hasPermi('rechargecard:cards:query')")
    @GetMapping(value = "/test/{id}")
    @ApiOperation("获取用户充值卡详细信息")
    public AjaxResult test(@PathVariable("id") Long id)
    {
        return success(userRechargeCardsService.test(id));
        //return success(id);
    }

    /**
     * 查询用户充值卡列表
     */
    @PreAuthorize("@ss.hasPermi('rechargecard:cards:list')")
    @GetMapping("/list")
    @ApiOperation("查询用户充值卡列表")
    public TableDataInfo list(UserRechargeCards userRechargeCards)
    {
        startPage();
        List<UserRechargeCards> list = userRechargeCardsService.selectUserRechargeCardsList(userRechargeCards);
        return getDataTable(list);
    }

    /**
     * 导出用户充值卡列表
     */
    @ApiOperation("导出用户充值卡列表")
    @PreAuthorize("@ss.hasPermi('rechargecard:cards:export')")
    @PostMapping("/export")
    public void export(HttpServletResponse response, UserRechargeCards userRechargeCards)
    {
        List<UserRechargeCards> list = userRechargeCardsService.selectUserRechargeCardsList(userRechargeCards);
        ExcelUtil<UserRechargeCards> util = new ExcelUtil<UserRechargeCards>(UserRechargeCards.class);
        util.exportExcel(response, list, "用户充值卡数据");
    }

    /**
     * 获取用户充值卡详细信息
     */
    @PreAuthorize("@ss.hasPermi('rechargecard:cards:query')")
    @GetMapping(value = "/{id}")
    @ApiOperation("获取用户充值卡详细信息")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(userRechargeCardsService.selectUserRechargeCardsById(id));
        //return success(id);
    }

    /**
     * 新增用户充值卡
     */
    @PreAuthorize("@ss.hasPermi('rechargecard:cards:add')")
    @PostMapping
    @ApiOperation("新增用户充值卡")
    public AjaxResult add(@RequestBody UserRechargeCards userRechargeCards)
    {
        return toAjax(userRechargeCardsService.insertUserRechargeCards(userRechargeCards));
    }

    /**
     * 修改用户充值卡
     */
    @PreAuthorize("@ss.hasPermi('rechargecard:cards:edit')")
    @PutMapping
    @ApiOperation("修改用户充值卡")
    public AjaxResult edit(@RequestBody UserRechargeCards userRechargeCards)
    {
        return toAjax(userRechargeCardsService.updateUserRechargeCards(userRechargeCards));
    }

    /**
     * 删除用户充值卡
     */
    @PreAuthorize("@ss.hasPermi('rechargecard:cards:remove')")
    @DeleteMapping("/{ids}")
    @ApiOperation("删除用户充值卡")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(userRechargeCardsService.deleteUserRechargeCardsByIds(ids));
    }
}
