package cn.iocoder.yudao.module.pms.controller.admin.ly.controller;

import cn.iocoder.yudao.module.pms.controller.admin.ly.util.ExcelExportUtil;
import cn.iocoder.yudao.module.pms.dal.mysql.TDDeviceMapper;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.sql.Timestamp;

import static cn.iocoder.yudao.framework.common.util.date.DateUtils.generateTimestamp;

@RestController
@RequestMapping("/rq/ly")
public class LyController {

    @Resource
    private ExcelExportUtil excelExportUtil;

    @Resource
    private TDDeviceMapper tdDeviceMapper;

    /**
     * 导出设备数据
     */
    @GetMapping("/export")
    public void export(
            @RequestParam String deviceCode,
            @RequestParam String beginTime,
            @RequestParam String endTime,
            @RequestParam(required = false) String identity,
            HttpServletResponse response
    ) {
        Timestamp start1 = generateTimestamp(beginTime);
        Timestamp end1 = generateTimestamp(endTime);
        // 异步导出，避免阻塞HTTP请求
        excelExportUtil.exportDeviceDataSync(response, deviceCode, start1, end1, identity);
    }
}