package com.pm.web.controller.kltj;

import com.pm.common.core.controller.BaseController;
import com.pm.common.core.domain.AjaxResult;
import com.pm.common.core.page.TableDataInfo;
import com.pm.kltj.service.IPeopleFlowService;
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 com.pm.common.utils.poi.ExcelUtilPageData;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/subsystem/peopleflow")
public class PeopleFlowController extends BaseController {

    @Autowired
    private IPeopleFlowService peopleFlowService;

    /**
     * 查询客流设备列表
     */
    @GetMapping("/devices")
    public AjaxResult listDevices() {
        List<Map<String, Object>> list = peopleFlowService.selectDeviceList();
        return AjaxResult.success(list);
    }

    /**
     * 查询客流统计数据列表
     */
    @GetMapping("/list")
    public TableDataInfo list() {
        startPage();
        List<Map<String, Object>> list = peopleFlowService.selectFlowDataList(getPageData());
        return getDataTable(list);
    }

    /**
     * 导出客流统计数据
     */
    @PostMapping("/export")
    public void export(HttpServletResponse response) {
        List<Map<String, Object>> list = peopleFlowService.selectFlowDataList(getPageData());
        String filename = "客流统计数据";
        String[] titles = {
            "时间,stat_time",
            "设备名称,device_name",
            "区域名称,area_name",
            "楼栋名称,building_name",
            "楼层名称,floor_name",
            "进入人数,enter_count",
            "离开人数,exit_count",
            "当前人数,current_count",
            "峰值人数,peak_count",
            "峰值时间,peak_time",
            "占用率(%),occupancy_rate",
            "平均停留时间(分钟),avg_stay_time"
        };
        ExcelUtilPageData.exportXLSX(response, null, null, filename, titles, list);
    }
}