From f4c5428321c2b510a49983db5c4f5b45bd6671d8 Mon Sep 17 00:00:00 2001 From: wen <1455474577@qq.com> Date: Tue, 23 Nov 2021 17:58:54 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E4=BA=8C=E7=BB=B4=E7=A0=81?= =?UTF-8?q?=E5=9C=BA=E7=AB=99=E4=B8=8B=E8=BD=BD=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/XhpcDownCodeController.java | 12 -- .../station/service/IXhpcDownCodeService.java | 4 - .../service/XhpcDownCodeServiceImpl.java | 166 +----------------- .../station/utils/img/DownMaterialUtil.java | 145 +-------------- .../resources/mapper/XhpcDownCodeMapper.xml | 21 ++- 5 files changed, 18 insertions(+), 330 deletions(-) diff --git a/xhpc-modules/xhpc-charging-station/src/main/java/com/xhpc/charging/station/controller/XhpcDownCodeController.java b/xhpc-modules/xhpc-charging-station/src/main/java/com/xhpc/charging/station/controller/XhpcDownCodeController.java index 63d0aa77..a8f8b18d 100644 --- a/xhpc-modules/xhpc-charging-station/src/main/java/com/xhpc/charging/station/controller/XhpcDownCodeController.java +++ b/xhpc-modules/xhpc-charging-station/src/main/java/com/xhpc/charging/station/controller/XhpcDownCodeController.java @@ -54,16 +54,4 @@ public class XhpcDownCodeController extends BaseController { return AjaxResult.success(environment.getProperty("img.getUrl") + s); } - -// @GetMapping(value = "/downMaterialByPileId1") -// public void downMaterialBy1(@RequestParam Long pileId) throws Exception { -// -// iXhpcDownCodeService.downMaterialBy11(pileId); -// } -// -// @GetMapping(value = "/downMaterialByStationId1") -// public void downMaterialByStationId1(@RequestParam Long stationId) throws Exception{ -// -// iXhpcDownCodeService.downMaterialByStationId11(stationId); -// } } diff --git a/xhpc-modules/xhpc-charging-station/src/main/java/com/xhpc/charging/station/service/IXhpcDownCodeService.java b/xhpc-modules/xhpc-charging-station/src/main/java/com/xhpc/charging/station/service/IXhpcDownCodeService.java index 42ec749c..a56c42aa 100644 --- a/xhpc-modules/xhpc-charging-station/src/main/java/com/xhpc/charging/station/service/IXhpcDownCodeService.java +++ b/xhpc-modules/xhpc-charging-station/src/main/java/com/xhpc/charging/station/service/IXhpcDownCodeService.java @@ -17,8 +17,4 @@ public interface IXhpcDownCodeService { String downMaterialBy(Long pileId) throws Exception; String downMaterialByStationId(Long stationId) throws Exception; -// -// void downMaterialBy11(Long pileId) throws Exception; -// -// void downMaterialByStationId11(Long stationId) throws Exception; } diff --git a/xhpc-modules/xhpc-charging-station/src/main/java/com/xhpc/charging/station/service/XhpcDownCodeServiceImpl.java b/xhpc-modules/xhpc-charging-station/src/main/java/com/xhpc/charging/station/service/XhpcDownCodeServiceImpl.java index 5cefac05..e416ffd8 100644 --- a/xhpc-modules/xhpc-charging-station/src/main/java/com/xhpc/charging/station/service/XhpcDownCodeServiceImpl.java +++ b/xhpc-modules/xhpc-charging-station/src/main/java/com/xhpc/charging/station/service/XhpcDownCodeServiceImpl.java @@ -26,7 +26,6 @@ import java.util.Map; @Service public class XhpcDownCodeServiceImpl implements IXhpcDownCodeService { - @Autowired private XhpcDownCodeMapper xhpcDownCodeMapper; @@ -107,7 +106,7 @@ public class XhpcDownCodeServiceImpl implements IXhpcDownCodeService { workbook.write(fos); workbook.close(); fos.close(); - String left = "https://xhpc-bucket1.oss-cn-hangzhou.aliyuncs.com/"; + String left = environment.getProperty("img.imgPrefix"); List imgUrls = xhpcDownCodeMapper.selectUrlsByPile(pileId); List list1 = DownMaterialUtil.getDownLoadUrls(left,imgUrls); System.out.println(list1); @@ -125,9 +124,9 @@ public class XhpcDownCodeServiceImpl implements IXhpcDownCodeService { @Override public String downMaterialByStationId(Long stationId) throws Exception { + //查找场站下方有图片的终端的相关的信息 List> list = xhpcDownCodeMapper.selectExcelDataByStationId(stationId); - System.out.println(list); - File file1 = new File("Material"); + File file1 = new File(environment.getProperty("img.url"), "Material"); File file2 = new File(file1, "pictures"); if (file1.exists()) { delFile(file1); @@ -179,7 +178,9 @@ public class XhpcDownCodeServiceImpl implements IXhpcDownCodeService { } } //5、写入 + //更改nocos上的输出位置 OutputStream fos = new FileOutputStream(environment.getProperty("img.url") + "/data.xls"); + workbook.write(fos); workbook.close(); fos.close(); @@ -197,163 +198,6 @@ public class XhpcDownCodeServiceImpl implements IXhpcDownCodeService { return "Material"+l+".zip"; } - public void deleteFiles(File file){ - if (file.isDirectory()) { - File[] files=file.listFiles(); - if (null != files) { - for (File value : files) { - if (value.isDirectory()) { - deleteFiles(value); - } else { - //System.out.println("里层文件:" + value.getName() + "--------" + value.delete()); - } - } - } - } - //System.out.println("外层文件:"+file.getName()+"--------"+file.delete()); - } - //test -// public void downMaterialBy11(Long pileId) throws Exception { -// -// -// List> list = xhpcDownCodeMapper.selectExcelDataByPileId(pileId); -// System.out.println(list); -// File file1 = new File("Material"); -// File file2 = new File(file1, "pictures"); -// if(file1.exists()){ -// delFile(file1); -// } -// boolean flag = file1.mkdir(); -// if(! flag) { -// System.out.println(file1.getName()+"文件夹创建失败!"); -// return; -// } -// boolean flag1 = file2.mkdir(); -// if(! flag1){ -// System.out.println(file2.getName() + "文件夹创建失败"); -// } -// //1、创建excel文档对象 -// HSSFWorkbook workbook = new HSSFWorkbook(); -// //2、创建sheet页 -// HSSFSheet sheet = workbook.createSheet("第一页"); -// //3、创建头部第一行 -// HSSFRow headRow = sheet.createRow(0); -// HSSFCell cell; -// String[] header = new String[] {"终端名称","归属电站","终端编码","电桩编码","终端类型(1直流(慢) 2交流(快)","电桩功率(KM)"}; -// for (int i = 0; i < header.length; i++) { -// cell = headRow.createCell(i); -// cell.setCellValue(header[i]); -// } -// //4、填写数据 -// HSSFRow dataRow; -// HSSFCell dataCell; -// String[] values = {"tName", "sName", "tSN", "psn", "type", "power"}; -// int valuesLength = values.length; -// for(int i = 1; i <= list.size(); i ++){ -// Map map = list.get(i - 1); -// if(null != map) { -// dataRow = sheet.createRow(i); -// for(int j = 0; j < valuesLength; j ++){ -// if(null != map.get(values[j])){ -// dataCell = dataRow.createCell(j); -// String s = String.valueOf(map.get(values[j])); -// dataCell.setCellValue(s); -// } -// } -// } -// } -// System.out.println(list); -// //5、写入 -// OutputStream fos = new FileOutputStream(file1.getAbsoluteFile() + "\\data.xls"); -// workbook.write(fos); -// workbook.close(); -// fos.close(); -// String left = "https://xhpc-bucket1.oss-cn-hangzhou.aliyuncs.com/"; -// List imgUrls = xhpcDownCodeMapper.selectUrlsByPile(pileId); -// List list1 = DownMaterialUtil.getDownLoadUrls(left,imgUrls); -// System.out.println(list1); -// DownMaterialUtil.saveImageToDisk1(list1,file2,imgUrls); -// File file = new File(file1.getAbsolutePath()); -// DownMaterialUtil.fileToZip(file); -// System.out.println("success"); -// } -// -// @Override -// public void downMaterialByStationId11(Long stationId) throws Exception { -// -// List> list = xhpcDownCodeMapper.selectExcelDataByStationId(stationId); -// System.out.println(list); -// File file1 = new File("Material"); -// File file2 = new File(file1, "pictures"); -// if (file1.exists()) { -// delFile(file1); -// } -// boolean flag = file1.mkdir(); -// if (!flag) { -// System.out.println(file1.getName() + "文件夹创建失败!"); -// } -// boolean flag1 = file2.mkdir(); -// if (!flag1) { -// System.out.println(file2.getName() + "文件夹创建失败"); -// } -// //1、创建excel文档对象 -// HSSFWorkbook workbook = new HSSFWorkbook(); -// //2、创建sheet页 -// HSSFSheet sheet = workbook.createSheet("第一页"); -// //3、创建头部第一行 -// HSSFRow headRow = sheet.createRow(0); -// HSSFCell cell; -// String[] header = new String[]{"终端名称", "归属电站", "终端编码", "电桩编码", "终端类型(1直流(快) 2交流(慢)", "电桩功率(KM)"}; -// for (int i = 0; i < header.length; i++) { -// cell = headRow.createCell(i); -// cell.setCellValue(header[i]); -// } -// //4、填写数据 -// HSSFRow dataRow; -// HSSFCell dataCell; -// String[] values = {"tName", "sName", "tSN", "psn", "type", "power"}; -// int valuesLength = values.length; -// for (int i = 1; i <= list.size(); i++) { -// Map map = list.get(i - 1); -// if (null != map) { -// dataRow = sheet.createRow(i); -// for (int j = 0; j < valuesLength; j++) { -// if (null != map.get(values[j])) { -// dataCell = dataRow.createCell(j); -// String s = String.valueOf(map.get(values[j])); -// if (j==4) { -// if("1".equals(s)){ -// dataCell.setCellValue("直流"); -// }else{ -// dataCell.setCellValue("交流"); -// } -// }else{ -// dataCell.setCellValue(s); -// } -// } -// } -// } -// } -// //5、写入 -// OutputStream fos = new FileOutputStream(file1.getAbsoluteFile() + "\\data.xls"); -// workbook.write(fos); -// workbook.close(); -// fos.close(); -// String left = "https://xhpc-bucket1.oss-cn-hangzhou.aliyuncs.com/"; -// List imgUrls = xhpcDownCodeMapper.selectUrlsByStation(stationId); -// List list1 = DownMaterialUtil.getDownLoadUrls(left, imgUrls); -// DownMaterialUtil.saveImageToDisk1(list1, file2, imgUrls); -// File file = new File(file1.getAbsolutePath()); -// DownMaterialUtil.fileToZip(file); -// System.out.println("success"); -// File file = new File(file1); -// //储存路径 -// long l = System.currentTimeMillis(); -// String url=environment.getProperty("img.url")+l; -// -// DownMaterialUtil.fileToZip(file,url); -// } - static boolean delFile(File file) { if (!file.exists()) { diff --git a/xhpc-modules/xhpc-charging-station/src/main/java/com/xhpc/charging/station/utils/img/DownMaterialUtil.java b/xhpc-modules/xhpc-charging-station/src/main/java/com/xhpc/charging/station/utils/img/DownMaterialUtil.java index a67f95b0..87dc9e02 100644 --- a/xhpc-modules/xhpc-charging-station/src/main/java/com/xhpc/charging/station/utils/img/DownMaterialUtil.java +++ b/xhpc-modules/xhpc-charging-station/src/main/java/com/xhpc/charging/station/utils/img/DownMaterialUtil.java @@ -1,10 +1,8 @@ package com.xhpc.charging.station.utils.img; -import javax.servlet.http.HttpServletResponse; import java.io.*; import java.net.HttpURLConnection; import java.net.URL; -import java.net.URLEncoder; import java.util.ArrayList; import java.util.List; import java.util.Objects; @@ -43,7 +41,6 @@ public class DownMaterialUtil { } return inputStream; } - public static void saveImageToDisk(List urls, File file, List imgNames) { for(int i = 0; i < urls.size(); i ++) { @@ -71,8 +68,8 @@ public class DownMaterialUtil { } } catch (IOException e) { e.printStackTrace(); + System.out.println("下载出错了"); } finally { - try { inputStream.close(); } catch (IOException e) { @@ -85,74 +82,9 @@ public class DownMaterialUtil { e.printStackTrace(); } } - System.out.println("success"); } } } - -// public static void saveImageToDisk1(List urls, File file, List imgNames) { -// -// for (int i = 0; i < urls.size(); i++) { -// InputStream inputStream = getInputStream(urls.get(i)); -// if(null == inputStream) continue; -// System.out.println(inputStream); -// byte[] data = new byte[1024]; -// int len = 0; -// FileOutputStream fileOutputStream = null; -// try { -// String str = imgNames.get(i); -// int poke = 0; -// for (int j = str.length() - 1; j >= 0; j--) { -// if (str.charAt(j) == 47) { -// poke = j; -// break; -// } -// } -// String real = str.substring(poke + 1); -// System.out.println(real); -// System.out.println(file.getName() + "\\" + real); -// fileOutputStream = new FileOutputStream(file.getAbsoluteFile() + "\\" + real); -// while ((len = inputStream.read(data)) != -1) { -// fileOutputStream.write(data, 0, len); -// } -// } catch (IOException e) { -// e.printStackTrace(); -// } finally { -// -// try { -// inputStream.close(); -// } catch (IOException e) { -// e.printStackTrace(); -// } -// if (fileOutputStream != null) { -// try { -// fileOutputStream.close(); -// } catch (IOException e) { -// e.printStackTrace(); -// } -// } -// System.out.println("success"); -// } -// } -// } - - public static void fileToZip(File sourceFile) throws Exception { - - if (!sourceFile.exists()) { - throw new RuntimeException("不存在"); - } - if (!sourceFile.isDirectory()) { - throw new RuntimeException("不是文件夹"); - } - //zip文件生成位置 - File zipFile = new File(sourceFile.getAbsolutePath() + ".zip"); - FileOutputStream fos = new FileOutputStream(zipFile); - ZipOutputStream zos = new ZipOutputStream(new BufferedOutputStream(fos)); - fileToZip(zos, sourceFile, ""); - zos.close(); - fos.close(); - } - public static void fileToZip(File sourceFile, String url) throws Exception { if (!sourceFile.exists()) { @@ -195,45 +127,6 @@ public class DownMaterialUtil { fis.close(); } } - - public static void saveToFile(String targetUrl,String destUrl) { - - FileOutputStream fos = null; - BufferedInputStream bis = null; - HttpURLConnection httpUrl = null; - URL url = null; - int BUFFER_SIZE = 1024; - byte[] buf = new byte[BUFFER_SIZE]; - int size = 0; - try { - url = new URL(targetUrl); - httpUrl = (HttpURLConnection) url.openConnection(); - httpUrl.connect(); - bis = new BufferedInputStream(httpUrl.getInputStream()); - fos = new FileOutputStream(destUrl); - while ((size = bis.read(buf)) != -1) { - fos.write(buf, 0, size); - } - fos.flush(); - } catch (IOException | ClassCastException ignored) { - } finally { - try { - if(null != fos) { - fos.close(); - } - if(null != bis) { - bis.close(); - } - if(null != httpUrl) { - httpUrl.disconnect(); - } - } catch (IOException e) { - e.printStackTrace(); - } - } - } - - public static List getDownLoadUrls(String left, List imgUrl){ List res = new ArrayList<>(); for (String s : imgUrl) { @@ -241,40 +134,4 @@ public class DownMaterialUtil { } return res; } - - /** - * 以流的形式下载文件 - * - * @param file - * @param response - * @return - */ - public static HttpServletResponse downloadZip(File file, HttpServletResponse response) { - try { - // 以流的形式下载文件。 - InputStream fis = new BufferedInputStream(new FileInputStream(file.getPath())); - byte[] buffer = new byte[fis.available()]; - fis.read(buffer); - fis.close(); - // 清空response - response.reset(); - OutputStream toClient = new BufferedOutputStream(response.getOutputStream()); - response.setContentType("application/octet-stream"); - //如果输出的是中文名的文件,在此处就要用URLEncoder.encode方法进行处理 - response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode(file.getName(), "UTF-8")); - toClient.write(buffer); - toClient.flush(); - toClient.close(); - } catch (IOException ex) { - ex.printStackTrace(); - } finally { - try { - File f = new File(file.getPath()); -// f.delete(); - } catch (Exception e) { - e.printStackTrace(); - } - } - return response; - } } diff --git a/xhpc-modules/xhpc-charging-station/src/main/resources/mapper/XhpcDownCodeMapper.xml b/xhpc-modules/xhpc-charging-station/src/main/resources/mapper/XhpcDownCodeMapper.xml index 83e625d3..d300adf1 100644 --- a/xhpc-modules/xhpc-charging-station/src/main/resources/mapper/XhpcDownCodeMapper.xml +++ b/xhpc-modules/xhpc-charging-station/src/main/resources/mapper/XhpcDownCodeMapper.xml @@ -11,7 +11,7 @@ on xcs.operator_id = xo.operator_id left join xhpc_terminal as xt on xcs.charging_station_id = xt.charging_station_id - where xo.status = 0 and xo.del_flag = 0 + where xo.del_flag = 0 and xcs.name like concat('%',#{stationName},'%') @@ -39,14 +39,17 @@