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.UserForbidLog;
import com.ruoyi.cai.dto.admin.vo.UserForbidLogAdminVo;
import com.ruoyi.cai.service.UserForbidLogService;
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 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-01-18
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/cai/userForbidLog")
public class UserForbidLogController extends BaseController {

    private final UserForbidLogService userForbidLogService;

    /**
     * 查询封禁记录列表
     */
    @SaCheckPermission("cai:userForbidLog:list")
    @GetMapping("/list")
    public TableDataInfo<UserForbidLogAdminVo> list(UserForbidLogAdminVo bo, PageQuery pageQuery) {
        Page<UserForbidLogAdminVo> page = userForbidLogService.pageAdmin(pageQuery,bo);
        return TableDataInfo.build(page);
    }

    /**
     * 获取封禁记录详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("cai:userForbidLog:query")
    @GetMapping("/{id}")
    public R<UserForbidLog> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long id) {
        return R.ok(userForbidLogService.getById(id));
    }

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