| | |
| | | package com.ruoyi.chargingPile.controller; |
| | | |
| | | |
| | | import cn.hutool.core.img.ImgUtil; |
| | | import cn.hutool.core.io.FileUtil; |
| | | import com.ruoyi.chargingPile.api.dto.TChargingGunDTO; |
| | | import com.ruoyi.chargingPile.api.model.TChargingGun; |
| | |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | | import javax.annotation.Resource; |
| | | import javax.servlet.ServletOutputStream; |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import java.awt.image.BufferedImage; |
| | | import java.io.BufferedReader; |
| | | import java.io.FileInputStream; |
| | | import java.io.FileReader; |
| | | import java.io.PrintWriter; |
| | | import java.net.URLEncoder; |
| | | import java.util.Arrays; |
| | |
| | | public void downloadQRCode(@PathVariable Integer id, HttpServletResponse response){ |
| | | try { |
| | | TChargingGun chargingGun = chargingGunService.getById(id); |
| | | response.setContentType("image/jpeg"); |
| | | response.setHeader("Content-Disposition","attachment; filename=" + URLEncoder.encode(chargingGun.getName(), "UTF-8") + ".jpeg"); |
| | | String fileName = URLEncoder.encode(chargingGun.getCode(), "UTF-8") + ".jpg"; |
| | | response.setContentType("application/force-download"); |
| | | response.addHeader("Content-Disposition", "attachment;fileName=" + fileName); |
| | | String url = "https://www.baidu.com?id=" + id; |
| | | String filePath = ""; |
| | | String filePath = "D://" + fileName; |
| | | QRCodeUtils.encode(url, filePath); |
| | | FileInputStream inputStream = new FileInputStream(filePath); |
| | | PrintWriter out = response.getWriter(); |
| | | ServletOutputStream out = response.getOutputStream(); |
| | | int len = 0; |
| | | byte[] buf = new byte[1024]; |
| | | while ((len = inputStream.read(buf, 0, 1024)) != -1) { |
| | | out.println(buf); |
| | | out.write(buf); |
| | | } |
| | | out.flush(); |
| | | out.close(); |