package com.ruoyi.xq.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
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.enums.BusinessType;
import com.ruoyi.xq.domain.CardAuthRecord;
import com.ruoyi.xq.dto.admin.authRecord.CardAuthRecordAdminVo;
import com.ruoyi.xq.service.CardAuthRecordService;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.util.Arrays;

/**
 * 实名认证管理
 *
 * @author 77
 * @date 2024-04-29
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/xq/cardAuthRecord")
public class CardAuthRecordController extends BaseController {

    private final CardAuthRecordService cardAuthRecordService;

    /**
     * 查询实名认证管理列表
     */
    @SaCheckPermission("xq:cardAuthRecord:list")
    @GetMapping("/list")
    public TableDataInfo<CardAuthRecordAdminVo> list(CardAuthRecordAdminVo bo, PageQuery pageQuery) {
        Page<CardAuthRecordAdminVo> page = cardAuthRecordService.pageAdmin(pageQuery, bo);
        return TableDataInfo.build(page);
    }

    /**
     * 获取实名认证管理详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("xq:cardAuthRecord:query")
    @GetMapping("/{id}")
    public R<CardAuthRecord> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long id) {
        return R.ok(cardAuthRecordService.getById(id));
    }

    /**
     * 新增实名认证管理
     */
    @SaCheckPermission("xq:cardAuthRecord:add")
    @Log(title = "实名认证管理", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@RequestBody CardAuthRecord bo) {
        return toAjax(cardAuthRecordService.save(bo));
    }

    /**
     * 修改实名认证管理
     */
    @SaCheckPermission("xq:cardAuthRecord:edit")
    @Log(title = "实名认证管理", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@RequestBody CardAuthRecord bo) {
        return toAjax(cardAuthRecordService.refreshUserCardByAdmin(bo.getId()));
    }

    /**
     * 删除实名认证管理
     *
     * @param ids 主键串
     */
    @SaCheckPermission("xq:cardAuthRecord:remove")
    @Log(title = "实名认证管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] ids) {
        return toAjax(cardAuthRecordService.removeBatchByIds(Arrays.asList(ids)));
    }
}
