package com.persagy.server.datacenter.services.graphtype

import org.apache.poi.xssf.usermodel.XSSFWorkbook
import org.springframework.stereotype.Service
import java.io.IOException
import javax.servlet.http.HttpServletResponse

/**
 * @author wx  <zhangweixin></zhangweixin>@sagacloud.com>
 * @date 2021/3/1 10:35
 */
@Service
class DownloadsService {

    @Throws(IOException::class)
    fun downloadsEquip(response: HttpServletResponse) {
        val workbook = XSSFWorkbook(DownloadsService::class.java.classLoader.getResourceAsStream("excel/信息点汇总表(汇总)帮助文档.xlsx"))
        response.characterEncoding = "utf-8"
        response.contentType = "application/octet-stream"
        val downloadFileName = String("help-document.xlsx".toByteArray(charset("gbk")), charset("iso8859-1"))
        response.setHeader("Content-Disposition", "attachment;fileName="
                + downloadFileName)
        response.flushBuffer()
        workbook.write(response.outputStream)
    }
}