| | |
| | | |
| | | |
| | | import cn.gistack.sm.sjztmd.word.service.ISjztmdService; |
| | | import cn.gistack.sm.sjztmd.word.util.ExcelUtil; |
| | | import cn.gistack.sm.sjztmd.word.util.WordUtil; |
| | | import cn.gistack.sm.sjztmd.word.vo.TbWordVO; |
| | | import cn.gistack.sm.sjztmd.word.vo.*; |
| | | import com.deepoove.poi.XWPFTemplate; |
| | | import io.swagger.annotations.Api; |
| | | import lombok.AllArgsConstructor; |
| | |
| | | |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import java.io.*; |
| | | import java.net.URLEncoder; |
| | | import java.text.SimpleDateFormat; |
| | | import java.util.Date; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | | /** |
| | |
| | | .body(resource); // 将InputStreamResource对象作为响应体 |
| | | } |
| | | |
| | | @GetMapping("/download/eightFloodInfo") |
| | | public ResponseEntity eightFloodInfo() throws Exception{ |
| | | @GetMapping("/download/overFloodInfo") |
| | | public ResponseEntity overFloodInfo() throws Exception{ |
| | | String time = new SimpleDateFormat("yyyy-MM-dd").format(new Date()); |
| | | |
| | | String fileName = time+ "全省水库防汛情况.docx"; |
| | | byte[] data = WordUtil.GetEightFloodInfo(); |
| | | String fileNameURL = URLEncoder.encode(fileName, "UTF-8"); |
| | | //获取总览、大中库、明细数据 |
| | | List<TotalInfo> totalList = sjztmdService.getTotalInfo(); |
| | | List<DzkInfo> dzkList = sjztmdService.getDzkInfo(); |
| | | List<OverDetail> overDetailList = sjztmdService.getOverDetailInfo(); |
| | | List<SzInfo> szInfoList = sjztmdService.getSzInfo(); |
| | | |
| | | byte[] data = WordUtil.GetOverInfo(totalList,dzkList,overDetailList,szInfoList); |
| | | |
| | | // 创建响应实体并设置响应头,将输出流作为响应体返回给客户端 |
| | | InputStreamResource resource = new InputStreamResource(new ByteArrayInputStream(data)); |
| | |
| | | // 将临时文件添加到响应中,以便用户下载 |
| | | return ResponseEntity.ok() |
| | | .contentType(MediaType.APPLICATION_OCTET_STREAM) // 设置响应的内容类型为二进制流(octet stream) |
| | | .header("Content-Disposition", "attachment; filename=\"" + fileName) // 设置响应的Content-Disposition头,以便浏览器提示用户下载文件 |
| | | .header("Content-Disposition", "attachment; filename=\"" + fileNameURL) // 设置响应的Content-Disposition头,以便浏览器提示用户下载文件 |
| | | .body(resource); // 将InputStreamResource对象作为响应体 |
| | | } |
| | | |
| | | @GetMapping("/download/getOverFloodInfoExcel") |
| | | public void getOverFloodInfoExcel(HttpServletResponse response) throws Exception { |
| | | |
| | | //获取总览、大中库、明细数据 |
| | | List<TotalInfo> totalList = sjztmdService.getTotalInfo(); |
| | | List<DzkInfo> dzkList = sjztmdService.getDzkInfo(); |
| | | List<OverDetail> overDetailList = sjztmdService.getOverDetailInfo(); |
| | | |
| | | ExcelUtil.generateExcel(response,totalList,dzkList,overDetailList); |
| | | } |
| | | |
| | | } |