package com.ruoyi.zhushi.controller;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.zhushi.entity.DkCheckInRecordDTO;
import com.ruoyi.zhushi.service.DkRecordService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 打卡控制台
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/dk/record")
@Slf4j
public class DkRecordController extends BaseController {


    @Autowired
    private DkRecordService dkRecordService;


    // 主页面查询
    @GetMapping("/list")
    public TableDataInfo<DkCheckInRecordDTO> list(DkCheckInRecordDTO dkCheckInRecordDTO, PageQuery pageQuery) {
        return dkRecordService.queryPageList(dkCheckInRecordDTO, pageQuery);
    }

    /**
     * 导出结果列表
     */
    @PostMapping("/export")
    public void export(DkCheckInRecordDTO bo, HttpServletResponse response) {
        List<DkCheckInRecordDTO> list = dkRecordService.queryList(bo);
        ExcelUtil.exportExcel(list, "打卡结果", DkCheckInRecordDTO.class, response);
    }


    @PostMapping("/exportNew")
    public void exportNew(DkCheckInRecordDTO bo, HttpServletResponse response) {
        dkRecordService.exportNew(bo, response);
    }
}
