package com.cyl.manager.staff.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.cyl.h5.pojo.vo.StaffAnswerRecordVO;
import com.cyl.manager.staff.domain.Staff;
import com.cyl.manager.staff.domain.StaffAnswerRecord;
import com.cyl.manager.staff.domain.dto.StaffAnswerAuditDTO;
import com.cyl.manager.staff.domain.vo.StaffVO;
import com.cyl.manager.staff.service.IStaffAnswerRecordService;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/staff/answer/record")
public class StaffAnswerRecordController {

    @Autowired
    private IStaffAnswerRecordService staffAnswerRecordService;

    /**
     * 查询答题信息列表
     */
    @GetMapping("/page")
    public AjaxResult list(@ApiParam(value = "当前页数", required = true, defaultValue = "1") @RequestParam Long currentPage,
                           @ApiParam(value = "每页数据量", required = true, defaultValue = "10") @RequestParam Long pageSize,
                           @ApiParam(value = "查询条件", required = false) StaffAnswerRecord record)
    {
        IPage<StaffAnswerRecord> page = new Page<>(currentPage, pageSize);
        IPage<StaffAnswerRecord> result =
                staffAnswerRecordService
                        .page(page, Wrappers.query(record).lambda().orderByDesc(StaffAnswerRecord::getCreateTime));
        return AjaxResult.successData(result);
    }

    /**
     * 审核
     */
    @PostMapping("/audit")
    public AjaxResult audit(@RequestBody StaffAnswerAuditDTO auditDTO)
    {
        return AjaxResult.successData(staffAnswerRecordService.audit(auditDTO));
    }

    /**
     * 查询单条记录
     */
    @GetMapping("/getById")
    public AjaxResult getById( @ApiParam(value = "id", required = true) @RequestParam Long id) {
        return AjaxResult.successData(staffAnswerRecordService.getById(id));
    }
}
