zhibing.pu
2024-08-26 8d19fa0775f455ddabc54e4d128308013f9a6bb8
ruoyi-service/ruoyi-chargingPile/src/main/java/com/ruoyi/chargingPile/controller/TChargingGunController.java
@@ -1,6 +1,8 @@
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 com.ruoyi.chargingPile.api.model.TChargingPile;
@@ -8,6 +10,7 @@
import com.ruoyi.chargingPile.api.vo.TChargingGunVO;
import com.ruoyi.chargingPile.service.TChargingGunService;
import com.ruoyi.chargingPile.service.TChargingPileService;
import com.ruoyi.chargingPile.util.QRCodeUtils;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.domain.BaseDelete;
@@ -21,7 +24,15 @@
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;
import java.util.List;
/**
@@ -103,8 +114,9 @@
    @Log(title = "批量删除充电枪", businessType = BusinessType.DELETE,operatorType = OperatorType.MANAGE)
    @ApiOperation(tags = {"后台-充电枪"},value = "批量删除充电枪")
    @DeleteMapping(value = "/deleteByIds")
    public AjaxResult<Boolean> deleteByIds(@RequestBody BaseDelete baseDelete) {
        return AjaxResult.ok(chargingGunService.removeByIds(baseDelete.getIds()));
    public AjaxResult<Boolean> deleteByIds(@RequestParam String ids) {
        String[] split = ids.split(",");
        return AjaxResult.ok(chargingGunService.removeByIds(Arrays.asList(split)));
    }
    /**
@@ -112,8 +124,8 @@
     */
    @Log(title = "结束充电", businessType = BusinessType.UPDATE,operatorType = OperatorType.MANAGE)
    @ApiOperation(tags = {"后台-充电枪"},value = "结束充电")
    @PostMapping(value = "/stopCharging")
    public AjaxResult<String> stopCharging() {
    @PutMapping(value = "/stopCharging")
    public AjaxResult<String> stopCharging(@RequestParam("id") Integer id) {
        // TODO 硬件 结束充电
        return AjaxResult.success();
    }
@@ -123,7 +135,27 @@
    @ApiOperation(tags = {"管理后台-充电桩信息"},value = "下载二维码")
    @GetMapping(value = "/downloadQRCode/{id}")
    public void downloadQRCode(@PathVariable Integer id, HttpServletResponse response){
        // todo 待完善
        try {
            TChargingGun chargingGun = chargingGunService.getById(id);
            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 = "D://" + fileName;
            QRCodeUtils.encode(url, filePath);
            FileInputStream inputStream = new FileInputStream(filePath);
            ServletOutputStream out = response.getOutputStream();
            int len = 0;
            byte[] buf = new byte[1024];
            while ((len = inputStream.read(buf, 0, 1024)) != -1) {
                out.write(buf);
            }
            out.flush();
            out.close();
            inputStream.close();
        }catch (Exception e){
            e.printStackTrace();
        }
    }