puzhibing
2024-10-08 66794a3e6b3feb01d4b6ae5710a0725b525a99dd
ruoyi-service/ruoyi-chargingPile/src/main/java/com/ruoyi/chargingPile/controller/TChargingGunController.java
@@ -39,10 +39,7 @@
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.io.*;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.Arrays;
@@ -158,13 +155,13 @@
    public void downloadQRCode(@PathVariable Integer id, HttpServletResponse response){
        try {
            TChargingGun chargingGun = chargingGunService.getById(id);
            TChargingPile chargingPile = chargingPileService.getById(chargingGun.getId());
            TChargingPile chargingPile = chargingPileService.getById(chargingGun.getChargingPileId());
            String code = chargingPile.getCode() + chargingGun.getCode();
            String fileName = URLEncoder.encode(code, "UTF-8") + ".jpg";
            response.setContentType("application/force-download");
            response.addHeader("Content-Disposition", "attachment;fileName=" + fileName);
            String url = "https://mxcd.zhinenganguan.com?No=" + code;
            String filePath = fileUploadConfig.getLocation();
            String filePath = fileUploadConfig.getLocation() + fileName;
            QRCodeUtils.encode(url, filePath);
            FileInputStream inputStream = new FileInputStream(filePath);
            ServletOutputStream out = response.getOutputStream();
@@ -176,6 +173,17 @@
            out.flush();
            out.close();
            inputStream.close();
            //清楚服务器上的文件
//            Process process = null;
//            try {
//                process = Runtime.getRuntime().exec("sudo rm -rf " + filePath);
//            } catch (IOException e) {
//                throw new RuntimeException(e);
//            }
//            if (process != null) {
//                process.destroy();
//            }
        }catch (Exception e){
            e.printStackTrace();
        }