|
| 1 | +package com.cy.index.controller; |
| 2 | + |
| 3 | +import com.cy.index.data.AppData; |
| 4 | +import com.cy.index.service.BaiduIndex2ExcelService; |
| 5 | +import com.cy.index.util.DateUtil; |
| 6 | +import org.springframework.stereotype.Controller; |
| 7 | +import org.springframework.web.bind.annotation.GetMapping; |
| 8 | + |
| 9 | +import javax.annotation.Resource; |
| 10 | +import javax.servlet.ServletOutputStream; |
| 11 | +import javax.servlet.http.HttpServletResponse; |
| 12 | +import java.io.IOException; |
| 13 | +import java.nio.charset.StandardCharsets; |
| 14 | +import java.util.Date; |
| 15 | + |
| 16 | +/** |
| 17 | + * 指数控制器 |
| 18 | + */ |
| 19 | +@Controller |
| 20 | +public class IndexController { |
| 21 | + |
| 22 | + @Resource |
| 23 | + private BaiduIndex2ExcelService baiduIndex2ExcelService; |
| 24 | + |
| 25 | + @GetMapping("downloadExcel") |
| 26 | + public void downloadExcel(String word, Date startDate, Date endDate, HttpServletResponse response) throws IOException { |
| 27 | + response.setContentType("multipart/form-data"); |
| 28 | + response.setCharacterEncoding("utf-8"); |
| 29 | + String fileName = new String(("百度指数-" + word + "-" + DateUtil.getDateString(startDate) + "-" + DateUtil.getDateString(endDate)) |
| 30 | + .getBytes(), StandardCharsets.ISO_8859_1); |
| 31 | + response.setHeader("Content-disposition", "attachment;filename=" + fileName + ".xlsx"); |
| 32 | + ServletOutputStream out = response.getOutputStream(); |
| 33 | + baiduIndex2ExcelService.downloadIndexExcel(word, startDate, endDate, out); |
| 34 | + } |
| 35 | + |
| 36 | + @GetMapping("bduss") |
| 37 | + public String bduss(String bduss) { |
| 38 | + AppData.bduss = bduss; |
| 39 | + return "downloadIndex"; |
| 40 | + } |
| 41 | + |
| 42 | + @GetMapping("/index.html") |
| 43 | + public String toIndex() { |
| 44 | + return "index"; |
| 45 | + } |
| 46 | +} |
0 commit comments