package com.playlet.web.controller.system;

import java.util.List;

import com.playlet.common.core.domain.Result;
import com.playlet.system.domain.PlayletUserWithdrawalPassword;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
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 com.playlet.common.annotation.Log;
import com.playlet.common.enums.BusinessType;
import com.playlet.system.domain.PlayletUserWithdrawDepositRecord;
import com.playlet.system.service.IPlayletUserWithdrawDepositRecordService;
import com.playlet.common.core.controller.BaseController;
import com.playlet.common.core.domain.AjaxResult;
import com.playlet.common.utils.poi.ExcelUtil;
import com.playlet.common.core.page.TableDataInfo;

/**
 * @Date: 2024-03-29 23:59
 * @Author: 但星霖
 * @Version: v1.0
 * @Description: 用户交易记录Controller
 */
@Controller
@RequestMapping("/system/userWithdrawRecord")
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class PlayletUserWithdrawDepositRecordController extends BaseController {
    private String prefix = "system/record";

    private final IPlayletUserWithdrawDepositRecordService playletUserWithdrawDepositRecordService;

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

    /**
     * 查询用户交易记录列表
     */
    @RequiresPermissions("system:record:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(PlayletUserWithdrawDepositRecord playletUserWithdrawDepositRecord) {
        startPage();
        List<PlayletUserWithdrawDepositRecord> list = playletUserWithdrawDepositRecordService.selectPlayletUserWithdrawDepositRecordList(playletUserWithdrawDepositRecord);
        return getDataTable(list);
    }

    /**
     * 导出用户交易记录列表
     */
    @RequiresPermissions("system:record:export")
    @Log(title = "用户交易记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(PlayletUserWithdrawDepositRecord playletUserWithdrawDepositRecord) {
        List<PlayletUserWithdrawDepositRecord> list = playletUserWithdrawDepositRecordService.selectPlayletUserWithdrawDepositRecordList(playletUserWithdrawDepositRecord);
        ExcelUtil<PlayletUserWithdrawDepositRecord> util = new ExcelUtil<PlayletUserWithdrawDepositRecord>(PlayletUserWithdrawDepositRecord.class);
        return util.exportExcel(list, "用户交易记录数据");
    }

    /**
     * 新增用户交易记录
     */
    @GetMapping("/add")
    public String add() {
        return prefix + "/add";
    }

    /**
     * 新增保存用户交易记录
     */
    @RequiresPermissions("system:record:add")
    @Log(title = "用户交易记录", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(PlayletUserWithdrawDepositRecord playletUserWithdrawDepositRecord) {
        return toAjax(playletUserWithdrawDepositRecordService.insertPlayletUserWithdrawDepositRecord(playletUserWithdrawDepositRecord));
    }

    /**
     * 修改用户交易记录
     */
    @RequiresPermissions("system:record:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap) {
        PlayletUserWithdrawDepositRecord playletUserWithdrawDepositRecord = playletUserWithdrawDepositRecordService.selectPlayletUserWithdrawDepositRecordById(id);
        mmap.put("playletUserWithdrawDepositRecord", playletUserWithdrawDepositRecord);
        return prefix + "/edit";
    }

    /**
     * 修改保存用户交易记录
     */
    @RequiresPermissions("system:record:edit")
    @Log(title = "用户交易记录", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(PlayletUserWithdrawDepositRecord playletUserWithdrawDepositRecord) {
        return toAjax(playletUserWithdrawDepositRecordService.updatePlayletUserWithdrawDepositRecord(playletUserWithdrawDepositRecord));
    }

    /**
     * 删除用户交易记录
     */
    @RequiresPermissions("system:record:remove")
    @Log(title = "用户交易记录", businessType = BusinessType.DELETE)
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String ids) {
        return toAjax(playletUserWithdrawDepositRecordService.deletePlayletUserWithdrawDepositRecordByIds(ids));
    }

    @ResponseBody
    @PostMapping("/recordCallbackUpdate")
    public Result<Boolean> recordCallbackUpdate(@RequestBody PlayletUserWithdrawDepositRecord playletUserWithdrawalPassword) {
        return Result.success(playletUserWithdrawDepositRecordService.recordCallbackUpdate(playletUserWithdrawalPassword.getWithdrawOrder(), playletUserWithdrawalPassword.getStatus()));
    }


}
