luodangjia
2024-10-08 4c96637a005891c709662ae84edd072ad9a4a57d
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;
@@ -143,8 +140,10 @@
    @ApiOperation(tags = {"后台-充电枪"},value = "结束充电")
    @PutMapping(value = "/stopCharging")
    public AjaxResult<String> stopCharging(@RequestParam("id") String id) {
        // 根据充电枪id 查询最新的一笔订单
        String data = chargingOrderClient.queryOrderByGunId(id).getData();
        // 硬件 结束充电
        chargingOrderClient.stopCharging(id);
        chargingOrderClient.stopCharging(data);
        return AjaxResult.success();
    }
    
@@ -162,7 +161,7 @@
            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();
@@ -174,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();
        }