package com.pm.web.controller.fkxt;

import com.pm.common.core.controller.BaseController;
import com.pm.common.core.domain.AjaxResult;
import com.pm.common.core.page.TableDataInfo;
import com.pm.common.utils.poi.ExcelUtilPageData;
import com.pm.fkxt.service.IVisitorService;
import org.springframework.beans.factory.annotation.Autowired;
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;
import java.util.Map;

@RestController
@RequestMapping("/subsystem/visitor")
public class VisitorController extends BaseController {

    @Autowired
    private IVisitorService visitorService;

    /**
     * 查询访客登记信息列表
     */
    @GetMapping("/list")
    public TableDataInfo visitorList() {
        startPage();
        List<Map<String, Object>> list = visitorService.selectVisitorInfoList(getPageData());
        return getDataTable(list);
    }

    /**
     * 导出访客登记信息
     */
    @PostMapping("/export")
    public void exportVisitor(HttpServletResponse response) {
        List<Map<String, Object>> list = visitorService.selectVisitorInfoList(getPageData());
        String filename = "访客登记信息";
        String[] titles = {
            "访客ID,visitor_id",
            "访客姓名,visitor_name",
            "访客电话,visitor_phone",
            "身份证号,id_card",
            "访客单位,company",
            "访问目的,visit_purpose",
            "被访人姓名,visited_person",
            "被访部门,visited_dept",
            "被访人电话,visited_phone",
            "预约时间,appointment_time",
            "访问开始时间,visit_start_time",
            "访问结束时间,visit_end_time",
            "实际开始时间,actual_start_time",
            "实际结束时间,actual_end_time",
            "访问状态,visit_status",
            "访客卡号,card_no",
            "入场门禁,entry_gate",
            "出场门禁,exit_gate",
            "审批状态,approval_status",
            "审批人,approver",
            "审批时间,approval_time"
        };
        ExcelUtilPageData.exportXLSX(response, null, null, filename, titles, list);
    }

    /**
     * 查询门禁刷卡记录列表
     */
    @GetMapping("/access")
    public TableDataInfo accessList() {
        startPage();
        List<Map<String, Object>> list = visitorService.selectAccessRecordList(getPageData());
        return getDataTable(list);
    }

    /**
     * 导出门禁刷卡记录
     */
    @PostMapping("/access/export")
    public void exportAccess(HttpServletResponse response) {
        List<Map<String, Object>> list = visitorService.selectAccessRecordList(getPageData());
        String filename = "门禁刷卡记录";
        String[] titles = {
            "记录ID,record_id",
            "访客ID,visitor_id",
            "访客姓名,visitor_name",
            "卡号,card_no",
            "门禁ID,gate_id",
            "门禁名称,gate_name",
            "门禁位置,gate_location",
            "刷卡时间,swipe_time",
            "刷卡类型,swipe_type",
            "刷卡结果,swipe_result",
            "设备序列号,device_sn",
            "失败原因,fail_reason",
            "体温,temperature",
            "口罩检测,mask_detection",
            "抓拍照片,photo_url"
        };
        ExcelUtilPageData.exportXLSX(response, null, null, filename, titles, list);
    }
}