/*
 * Author: Zev
 * 生成controller
 */
package com.tofly.gpsboot.controller.sign;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.haiqiu.tools.excel.utils.ExcelUtils;
import com.tofly.common.core.entity.ResultRespone;

import com.tofly.common.log.annotation.ToFlyAppLog;
import com.tofly.gpsboot.controller.BaseController;
import com.tofly.pojo.plan.dto.PdasignhisDto;
import com.tofly.pojo.plan.vo.AttendanceReportVo;
import com.tofly.pojo.plan.vo.PdasignhisVo;
import com.tofly.pojo.plan.Pdasignhis;
import com.tofly.gpsboot.service.sign.PdasignhisService;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.ModelAttribute;

import java.util.List;

/**
 * 上下班签到历史信息
 *
 * @author admin
 * @date Thu Mar 18 00:00:00 CST 2021
 */
@RestController
@RequestMapping("/pdasignhis")
@Api(tags="上下班签到历史信息")
public class PdasignhisController extends BaseController<Pdasignhis, PdasignhisVo> {
    @Autowired
    private PdasignhisService service;
    @Autowired
    public PdasignhisController(PdasignhisService service) {
        init(service);
    }

    @GetMapping("/page")
    @ApiOperation(value = "分页查询")
    @ToFlyAppLog(title = "分页查询上下班签到历史信息")
    public ResultRespone<Page<PdasignhisVo>> getPdasignhisPage(Page page, @ModelAttribute PdasignhisDto parDto) {
        ResultRespone<Page<PdasignhisVo>> rest = new ResultRespone<>();
        Page<PdasignhisVo> buildPage = service.getPdaSignHisPage(page, parDto);
        rest.setResult(buildPage);
        return rest;
    }

    @GetMapping("/attendanceReport")
    @ApiOperation(value = "考勤报表")
    @ToFlyAppLog(title = "考勤报表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "startTime", value = "开始时间（yyyy-MM-dd HH:mm:ss）", required = true, dataType = "String"),
            @ApiImplicitParam(name = "endTime", value = "结束时间（yyyy-MM-dd HH:mm:ss）", required = true, dataType = "String"),
            @ApiImplicitParam(name = "deptIds", value = "部门ID 多个用,隔开", dataType = "String"),
            @ApiImplicitParam(name = "isExport", value = "是否导出（0否1是）", dataType = "String"),
    })
    public ResultRespone<List<AttendanceReportVo>> attendanceReport(String startTime, String endTime, String deptIds, String isExport) {
        List<AttendanceReportVo> attendanceReportVoList = service.attendanceReport(startTime, endTime, deptIds);
        if (StringUtils.isNotBlank(isExport) && isExport.equals("1")) {
            ExcelUtils.getListToExcel(AttendanceReportVo.class, attendanceReportVoList, "考勤报表");
        }
        return ResultRespone.success(attendanceReportVoList);
    }
}
