package beilv.web.controller.vipCardLog;

import beilv.common.annotation.Log;
import beilv.common.core.controller.BaseController;
import beilv.common.core.domain.AjaxResult;
import beilv.common.core.page.TableDataInfo;
import beilv.common.enums.BusinessType;
import beilv.common.utils.poi.ExcelUtil;
import beilv.vipCardLog.domain.VipCardLog;
import beilv.vipCardLog.service.IVipCardLogService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 充值记录Controller
 *
 * @author LG
 * @date 2025-11-12
 */
@Controller
@RequestMapping("/system/vipCardLog")
public class VipCardLogController extends BaseController {
    private String prefix = "system/vipCardLog";

    @Autowired
    private IVipCardLogService vipCardLogService;

    @RequiresPermissions("system:vipCardLog:view")
    @GetMapping()
    public String vipCardLog() {
        return prefix + "/vipCardLog";
    }

    /**
     * 查询充值记录列表
     */
    @RequiresPermissions("system:vipCardLog:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(VipCardLog vipCardLog) {
        startPage();
        List<VipCardLog> list = vipCardLogService.selectVipCardLogList(vipCardLog);
        return getDataTable(list);
    }

    /**
     * 导出充值记录列表
     */
    @RequiresPermissions("system:vipCardLog:export")
    @Log(title = "充值记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(VipCardLog vipCardLog) {
        List<VipCardLog> list = vipCardLogService.selectVipCardLogList(vipCardLog);
        ExcelUtil<VipCardLog> util = new ExcelUtil<VipCardLog>(VipCardLog.class);
        return util.exportExcel(list, "充值记录数据");
    }

    /**
     * 新增充值记录
     */
    @RequiresPermissions("system:vipCardLog:add")
    @GetMapping("/add")
    public String add() {
        return prefix + "/add";
    }

    /**
     * 新增保存充值记录
     */
    @RequiresPermissions("system:vipCardLog:add")
    @Log(title = "充值记录", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(VipCardLog vipCardLog) {
        return toAjax(vipCardLogService.insertVipCardLog(vipCardLog));
    }

    /**
     * 修改充值记录
     */
    @RequiresPermissions("system:vipCardLog:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap) {
        VipCardLog vipCardLog = vipCardLogService.selectVipCardLogById(id);
        mmap.put("vipCardLog", vipCardLog);
        return prefix + "/edit";
    }

    /**
     * 修改保存充值记录
     */
    @RequiresPermissions("system:vipCardLog:edit")
    @Log(title = "充值记录", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(VipCardLog vipCardLog) {
        return toAjax(vipCardLogService.updateVipCardLog(vipCardLog));
    }

    /**
     * 删除充值记录
     */
    @RequiresPermissions("system:vipCardLog:remove")
    @Log(title = "充值记录", businessType = BusinessType.DELETE)
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String ids) {
        return toAjax(vipCardLogService.deleteVipCardLogByIds(ids));
    }


    /**
     * 订单页面退款
     * @param vipCardLog
     * @return
     */
    @PostMapping("/refund")
    @ResponseBody
    public AjaxResult refund(VipCardLog vipCardLog){
        return vipCardLogService.refundById(vipCardLog, false, true);
    }
}
