package com.tofly.xrtygis.custom.controller;

import com.tofly.xrtygis.em.Constant;
import com.tofly.xrtygis.em.ExcelExportFileTypeEnum;
import com.tofly.xrtygis.strategy.ExcelStrategyContext;
import com.tofly.xrtygis.util.ExcelUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
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;

/**
 * @author 陈浩
 * @date 2021/4/17
 */
@RestController
@RequestMapping("/export")
@AllArgsConstructor
@Api(tags = "数据导出相关")
public class ExportAboutController {

    private final ExcelStrategyContext excelStrategyContext;

    @ApiOperation(value = "scada数据EXCEL导出")
    @GetMapping("/exportHistory")
    public void exportHistory(HttpServletResponse response, String templateServiceType, String templateFlag, String dto) {
        // 根据templateServiceType,templateFlag获取对应模板数据
        ExcelExportFileTypeEnum excelExportFileTypeEnum = ExcelExportFileTypeEnum.getExcelExportFileTypeEnum(templateServiceType, templateFlag);
        if (null == excelExportFileTypeEnum) {
            return;
        }
        // 从模型类型枚举根据templateServiceType获取策略对应模板数据
        List<Map<String, Object>> dataList = excelStrategyContext.getExportData(templateServiceType, templateFlag, dto);
        ExcelUtil.export(dataList.get(0), excelExportFileTypeEnum, Constant.FILE_PATH_TEST_EXPORT_EXCEL, response);
    }
}
