package com.bonus.system.att.controller;

import com.bonus.common.core.utils.poi.ExcelUtil;
import com.bonus.common.core.web.controller.BaseController;
import com.bonus.common.core.web.domain.AjaxResult;
import com.bonus.common.core.web.page.TableDataInfo;
import com.bonus.common.log.annotation.Log;
import com.bonus.common.log.annotation.SysLog;
import com.bonus.common.log.enums.BusinessType;
import com.bonus.common.log.enums.OperaType;
import com.bonus.common.security.annotation.RequiresPermissions;
import com.bonus.system.att.entity.*;
import com.bonus.system.att.service.AttDetailByMonthService;
import com.bonus.system.att.service.AttExceptionHandleService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

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

/**
 * 轮休临时外出异常数据
 *
 * @author hongchao
 */
@RestController
@RequestMapping("/attExceptionHandle")
@Slf4j
public class AttExceptionHandleController extends BaseController {

    @Resource(name = "attExceptionHandle")
    private AttExceptionHandleService attExceptionHandle;

    @RequiresPermissions("att:exception:query")
    @GetMapping("/list")
    @Log(title = "异常处理->轮休临时外出异常数据->列表查询", businessType = BusinessType.QUERY)
    public TableDataInfo list(AttExceptionBean data) {
        startPage();
//        List<AttExceptionBean> list = attExceptionHandle.selectAttExceptionList(data);
        return attExceptionHandle.selectAttExceptionList(data);
    }

    @RequiresPermissions("att:exception:query")
    @GetMapping("/getDetailException")
    @Log(title = "异常处理->轮休临时外出异常报表->列表查询", businessType = BusinessType.QUERY)
    public TableDataInfo getDetailException(AttExceptionBean data) {
        startPage();
        List<AttExceptionBean> list = attExceptionHandle.getDetailException(data);
        return getDataTable(list);
    }

    @RequiresPermissions("att:exception:query")
    @GetMapping("/getDetailExceptionRest")
    @Log(title = "异常处理->轮休异常报表未申请详情->列表查询", businessType = BusinessType.QUERY)
    public TableDataInfo getDetailExceptionRest(AttDetailLeaveBean data) {
        startPage();
        List<AttDetailLeaveBean> list = attExceptionHandle.getDetailExceptionRest(data);
        return getDataTable(list);
    }

    @RequiresPermissions("att:exception:query")
    @GetMapping("/getDetailExceptionOut")
    @Log(title = "异常处理->临时外出异常报表未申请详情->列表查询", businessType = BusinessType.QUERY)
    public TableDataInfo getDetailExceptionOut(AttDetailLeaveBean data) {
        startPage();
        List<AttDetailLeaveBean> list = attExceptionHandle.getDetailExceptionOut(data);
        return getDataTable(list);
    }

    @RequiresPermissions("att:exception:query")
    @GetMapping("/getDetailExceptionAll")
    @Log(title = "异常处理->轮休和临时外出异常报表未申请详情->列表查询", businessType = BusinessType.QUERY)
    public TableDataInfo getDetailExceptionAll(AttDetailLeaveBean data) {
        startPage();
        List<AttDetailLeaveBean> list = attExceptionHandle.getDetailExceptionAll(data);
        return getDataTable(list);
    }

    @RequiresPermissions("att:exception:query")
    @GetMapping("/export")
    public void export(HttpServletResponse response, AttExceptionBean data) {
        try{
            List<AttExceptionBean> list = attExceptionHandle.getDetailException(data);
            ExcelUtil<AttExceptionBean> util = new ExcelUtil<AttExceptionBean>(AttExceptionBean.class);
            util.exportExcel(response, list, "轮休临时外出异常报表");
        }catch (Exception e){
            log.error(e.toString(),e);
        }
    }

    /**
     * 审批提醒
     * @param vo
     * @return
     */
    @PostMapping("/examineRemind")
    @Log(title = "异常处理->临时外出异常报表->审批提醒", businessType = BusinessType.QUERY)
    public AjaxResult examineRemind(@Validated @RequestBody AttExRemindBean vo) {
        return attExceptionHandle.examineRemind(vo);
    }
}
