package com.ruoyi.cai.controller.admin;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ruoyi.cai.domain.AccountCash;
import com.ruoyi.cai.dto.admin.vo.AccountCashAdminVo;
import com.ruoyi.cai.service.AccountCashService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.core.validate.AddGroup;
import com.ruoyi.common.core.validate.EditGroup;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.util.Arrays;
import java.util.List;

/**
 * 用户提现记录
 *
 * @author 77
 * @date 2023-12-21
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/cai/accountCash")
public class AccountCashController extends BaseController {

    private final AccountCashService accountCashService;

    /**
     * 查询用户提现记录列表
     */
    @SaCheckPermission("cai:accountCash:list")
    @GetMapping("/list")
    public TableDataInfo<AccountCashAdminVo> list(AccountCashAdminVo bo, PageQuery pageQuery) {
        Page<AccountCashAdminVo> page = accountCashService.pageAdmin(pageQuery, bo);
        return TableDataInfo.build(page);
    }

    /**
     * 导出用户提现记录列表
     */
    @SaCheckPermission("cai:accountCash:export")
    @Log(title = "用户提现记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(AccountCash bo, HttpServletResponse response) {
        List<AccountCash> list = accountCashService.list(Wrappers.lambdaQuery(bo));
        ExcelUtil.exportExcel(list, "用户提现记录", AccountCash.class, response);
    }

    /**
     * 获取用户提现记录详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("cai:accountCash:query")
    @GetMapping("/{id}")
    public R<AccountCash> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Integer id) {
        return R.ok(accountCashService.getById(id));
    }

    /**
     * 新增用户提现记录
     */
    @SaCheckPermission("cai:accountCash:add")
    @Log(title = "用户提现记录", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody AccountCash bo) {
        return toAjax(accountCashService.save(bo));
    }

    /**
     * 修改用户提现记录
     */
    @SaCheckPermission("cai:accountCash:edit")
    @Log(title = "用户提现记录", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody AccountCash bo) {
        return toAjax(accountCashService.updateById(bo));
    }

    /**
     * 删除用户提现记录
     *
     * @param ids 主键串
     */
    @SaCheckPermission("cai:accountCash:remove")
    @Log(title = "用户提现记录", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Integer[] ids) {
        return toAjax(accountCashService.removeBatchByIds(Arrays.asList(ids)));
    }
}
