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.GuardTotal;
import com.ruoyi.cai.service.GuardTotalService;
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 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 2023-12-31
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/cai/guardTotal")
public class GuardTotalController extends BaseController {

    private final GuardTotalService guardTotalService;

    /**
     * 查询用户守护累计列表
     */
    @SaCheckPermission("cai:guardTotal:list")
    @GetMapping("/list")
    public TableDataInfo<GuardTotal> list(GuardTotal bo, PageQuery pageQuery) {
        Page<GuardTotal> page = guardTotalService.page(pageQuery.build(),
                Wrappers.lambdaQuery(bo).orderByDesc(GuardTotal::getCreateTime));
        return TableDataInfo.build(page);
    }

    /**
     * 获取用户守护累计详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("cai:guardTotal:query")
    @GetMapping("/{id}")
    public R<GuardTotal> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long id) {
        return R.ok(guardTotalService.getById(id));
    }
}
