package com.usky.fire.controller.web;


import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.usky.common.core.bean.ApiResult;
import com.usky.common.core.bean.CommonPage;
import com.usky.fire.domain.DataRt;
import com.usky.fire.service.DataRtService;
import com.usky.fire.service.vo.RealTimeStatus;
import com.usky.fire.service.vo.DataRtVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

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

/**
 * <p>
 * 实时数据表 前端控制器
 * </p>
 *
 * @author JCB
 * @since 2022-08-24
 */
@RestController
@RequestMapping("/dataRt")
public class DataRtController {

    @Autowired
    private DataRtService dataRtService;

    /**
     * 物联网实时数据-列表查询
     *
     * @param deviceCode 设备编号
     * @param systemType 系统类型(1.火灾自动报警系统 2.自动喷水灭火系统 3.消防给水及消火栓系统 4.防排烟系统 5.电气火灾系统 6.消防视频监控系统)
     * @param pageNum    当前页
     * @param pageSize   每页条数
     * @return
     */
    @GetMapping("dataRtList")
    public ApiResult<CommonPage<DataRt>> dataRtList(@RequestParam(value = "deviceCode", required = false) String deviceCode,
                                                    @RequestParam(value = "systemType") Integer systemType,
                                                    @RequestParam(value = "pageNum", required = false, defaultValue = "1") Integer pageNum,
                                                    @RequestParam(value = "pageSize", required = false, defaultValue = "10") Integer pageSize) {
        return ApiResult.success(dataRtService.dataRtList(deviceCode, systemType, pageNum, pageSize));
    }

    /**
     * 设备管理实时数据-列表查询
     *
     * @param deviceCode 设备编号
     * @param systemType 系统类型(2.自动喷水灭火系统 3.消防给水及消火栓系统 4.防排烟系统 5.电气火灾系统)
     * @param pageNum          当前页
     * @param pageSize         每页条数
     * @return
     */
    @GetMapping("deviceDataRtList")
    public ApiResult<CommonPage<DataRtVo>> deviceDataRtList(@RequestParam(value = "deviceCode", required = false) String deviceCode,
                                          @RequestParam(value = "systemType") Integer systemType,
                                          @RequestParam(value = "pageNum", required = false, defaultValue = "1") Integer pageNum,
                                          @RequestParam(value = "pageSize", required = false, defaultValue = "10") Integer pageSize) {
        return ApiResult.success(dataRtService.deviceDataRtList(deviceCode, systemType, pageNum, pageSize));
    }

    /**
     * 物联网实时数据-导出
     *
     * @param response
     * @param deviceCode  设备编号
     * @param systemType  系统类型(1.火灾自动报警系统 2.自动喷水灭火系统 3.消防给水及消火栓系统 4.防排烟系统 5.电气火灾系统 6.消防视频监控系统)
     * @param exportTitle 标题
     * @throws IOException
     */
    @PostMapping("dataRtListExport")
    public void export(HttpServletResponse response,
                       @RequestParam(value = "deviceCode", required = false) String deviceCode,
                       @RequestParam(value = "systemType") Integer systemType,
                       @RequestParam(value = "exportTitle") String exportTitle) throws IOException {
        List<DataRt> list = dataRtService.dataRtListOne(deviceCode, systemType);
        ExcelUtil<DataRt> util = new ExcelUtil<DataRt>(DataRt.class);
        util.exportExcel(response, list, exportTitle, exportTitle);
    }

    /**
     * 实时监控与工况-设备实时状态
     *
     * @param deviceCode 设备编号
     * @return
     */
    @GetMapping("deviceInfoData")
    public ApiResult<RealTimeStatus> deviceInfoData(@RequestParam(value = "deviceCode") String deviceCode) {
       return ApiResult.success(dataRtService.deviceInfoData(deviceCode));
    }


}

