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.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.xq.domain.UserVisitor;
import com.ruoyi.xq.service.UserVisitorService;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.constraints.NotNull;

/**
 * 用户来访记录
 *
 * @author 77
 * @date 2024-03-18
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/xq/userVisitor")
public class UserVisitorController extends BaseController {

    private final UserVisitorService userVisitorService;

    /**
     * 查询用户来访记录列表
     */
    @SaCheckPermission("xq:userVisitor:list")
    @GetMapping("/list")
    public TableDataInfo<UserVisitor> list(UserVisitor bo, PageQuery pageQuery) {
        Page<UserVisitor> page = userVisitorService.page(pageQuery.build(), Wrappers.lambdaQuery(bo));
        return TableDataInfo.build(page);
    }

    /**
     * 获取用户来访记录详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("xq:userVisitor:query")
    @GetMapping("/{id}")
    public R<UserVisitor> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long id) {
        return R.ok(userVisitorService.getById(id));
    }
}
